2009-06-16 21:26:07 +08:00
|
|
|
/****************************************************************************
|
|
|
|
* include/nxflat.h
|
|
|
|
*
|
2024-10-02 21:59:15 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
2021-02-03 18:33:49 +08:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2009-06-16 21:26:07 +08:00
|
|
|
*
|
2021-02-03 18:33:49 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2009-06-16 21:26:07 +08:00
|
|
|
*
|
2021-02-03 18:33:49 +08:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2009-06-16 21:26:07 +08:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __INCLUDE_NXFLAT_H
|
|
|
|
#define __INCLUDE_NXFLAT_H
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
2009-12-15 07:32:23 +08:00
|
|
|
|
2009-06-16 21:26:07 +08:00
|
|
|
#include <sys/types.h>
|
2009-12-15 07:32:23 +08:00
|
|
|
#include <stdint.h>
|
2009-06-16 21:26:07 +08:00
|
|
|
|
|
|
|
/****************************************************************************
|
2009-06-18 06:13:21 +08:00
|
|
|
* Pre-processor Definitions
|
2009-06-16 21:26:07 +08:00
|
|
|
****************************************************************************/
|
|
|
|
|
2009-06-27 01:46:51 +08:00
|
|
|
#define NXFLAT_MAX_STRING_SIZE 64 /* Largest size of string (w/zterminator) */
|
|
|
|
#define NXFLAT_MAGIC "NxFT" /* NXFLAT magic number */
|
2009-06-16 21:26:07 +08:00
|
|
|
|
2009-06-18 06:13:21 +08:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
2009-06-16 21:26:07 +08:00
|
|
|
/****************************************************************************
|
|
|
|
* The NXFLAT file header
|
|
|
|
*
|
|
|
|
* The elements within this structure are stored in network order (i.e.,
|
|
|
|
* ntohs() and ntohl() should be used to access fields within the
|
|
|
|
* header.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
struct nxflat_hdr_s
|
|
|
|
{
|
2009-06-18 20:18:41 +08:00
|
|
|
/* The "magic number" identifying the file type. This field should contain
|
|
|
|
* "NxFT". NOTE that there is no other versioning information other than
|
2009-06-18 02:45:48 +08:00
|
|
|
* this magic number.
|
2009-06-16 21:26:07 +08:00
|
|
|
*/
|
|
|
|
|
2009-06-27 01:46:51 +08:00
|
|
|
char h_magic[4];
|
2009-06-16 21:26:07 +08:00
|
|
|
|
|
|
|
/* The following fields provide the memory map for the nxflat binary.
|
|
|
|
*
|
2009-06-26 01:44:35 +08:00
|
|
|
* h_entry - Offset to the first executable insruction from
|
2009-06-16 21:26:07 +08:00
|
|
|
* the beginning of the file.
|
|
|
|
* h_datastart - Offset to the beginning of the data segment from
|
|
|
|
* the beginning of the file. This field can also
|
|
|
|
* interpreted as the size of the ISpace segment.
|
|
|
|
* h_dataend - Offset to the end of the data segment from the
|
|
|
|
* beginning of the file.
|
|
|
|
* h_bssend - Offset to the end of bss segment from the beginning
|
|
|
|
* of the file.
|
|
|
|
*
|
|
|
|
* The text segment can be considered to be the contiguous (unrelocated)
|
|
|
|
* address space range from address zero through (but not including)
|
|
|
|
* h_datastart.
|
|
|
|
*
|
|
|
|
* The size of the data/bss segment includes (as a minimum) the data
|
|
|
|
* and bss regions (bss_end - data_start) as well as the size of the
|
|
|
|
* stack. At run time, this region will also include program arguments
|
2020-02-23 16:50:23 +08:00
|
|
|
* and environment variables.
|
2014-04-14 04:32:20 +08:00
|
|
|
*
|
2009-06-16 21:26:07 +08:00
|
|
|
* The bss segment is data_end through bss_end.
|
|
|
|
*/
|
|
|
|
|
2009-12-15 07:32:23 +08:00
|
|
|
uint32_t h_entry;
|
|
|
|
uint32_t h_datastart;
|
|
|
|
uint32_t h_dataend;
|
|
|
|
uint32_t h_bssend;
|
2009-06-16 21:26:07 +08:00
|
|
|
|
|
|
|
/* Size of stack, in bytes */
|
|
|
|
|
2009-12-15 07:32:23 +08:00
|
|
|
uint32_t h_stacksize;
|
2009-06-16 21:26:07 +08:00
|
|
|
|
2009-06-23 06:12:19 +08:00
|
|
|
/* Relocation entries:
|
|
|
|
*
|
2009-06-16 21:26:07 +08:00
|
|
|
* h_relocstart - Offset to the beginning of an array of relocation
|
|
|
|
* records (struct nxflat_reloc). The offset is
|
|
|
|
* relative to the start of the file
|
|
|
|
*/
|
|
|
|
|
2009-12-15 07:32:23 +08:00
|
|
|
uint32_t h_relocstart; /* Offset of relocation records */
|
2009-06-16 21:26:07 +08:00
|
|
|
|
2009-06-23 06:12:19 +08:00
|
|
|
/* Imported symbol table (NOTE no symbols are exported):
|
2009-06-16 21:26:07 +08:00
|
|
|
*
|
|
|
|
* h_importsymbols - Offset to the beginning of an array of imported
|
2009-06-27 01:46:51 +08:00
|
|
|
* symbol structures (struct nxflat_import_s). The
|
2009-06-16 21:26:07 +08:00
|
|
|
* h_importsymbols offset is relative to the
|
|
|
|
* beginning of the file. Each entry of the
|
2009-12-15 07:32:23 +08:00
|
|
|
* array contains an uint32_t offset (again from
|
2009-06-16 21:26:07 +08:00
|
|
|
* the beginning of the file) to the name of
|
|
|
|
* a symbol string. This string is null-terminated.
|
|
|
|
*/
|
|
|
|
|
2009-12-15 07:32:23 +08:00
|
|
|
uint32_t h_importsymbols; /* Offset to list of imported symbols */
|
2009-06-25 20:44:55 +08:00
|
|
|
|
|
|
|
/* 16-bit counts
|
|
|
|
*
|
2020-02-23 16:50:23 +08:00
|
|
|
* h_reloccount - The number of relocation records in the array
|
2009-06-25 20:44:55 +08:00
|
|
|
* h_importcount - The number of records in the h_importsymbols array.
|
|
|
|
*/
|
|
|
|
|
2009-12-15 07:32:23 +08:00
|
|
|
uint16_t h_reloccount; /* Number of relocation records */
|
|
|
|
uint16_t h_importcount; /* Number of imported symbols */
|
2009-06-16 21:26:07 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* NXFLAT Relocation types.
|
|
|
|
*
|
2009-06-18 06:13:21 +08:00
|
|
|
* The relocation records are an array of the following type.
|
2009-06-16 21:26:07 +08:00
|
|
|
****************************************************************************/
|
|
|
|
|
2009-06-18 06:13:21 +08:00
|
|
|
struct nxflat_reloc_s
|
|
|
|
{
|
2009-12-15 07:32:23 +08:00
|
|
|
uint32_t r_info; /* Bit-encoded relocation info */
|
2009-06-18 06:13:21 +08:00
|
|
|
};
|
|
|
|
|
2009-06-19 05:17:53 +08:00
|
|
|
/* Pack the type and the offset into one 32-bit value */
|
|
|
|
|
2009-12-15 07:32:23 +08:00
|
|
|
#define NXFLAT_RELOC(t,o) (((uint32_t)((t) & 3) << 30) | ((o) & 0x3fffffff))
|
2009-06-19 05:17:53 +08:00
|
|
|
|
2009-06-18 06:13:21 +08:00
|
|
|
/* The top three bits of the relocation info is the relocation type (see the
|
|
|
|
* NXFLAT_RELOC_TYPE_* definitions below. This is an unsigned value.
|
|
|
|
*/
|
|
|
|
|
2009-12-15 07:32:23 +08:00
|
|
|
#define NXFLAT_RELOC_TYPE(r) ((uint32_t)(r) >> 30)
|
2009-06-18 06:13:21 +08:00
|
|
|
|
2021-02-03 16:42:38 +08:00
|
|
|
/* The bottom 28 bits of the relocation info is the (non-negative) offset
|
|
|
|
* into the D-Space that needs the fixup.
|
2009-06-18 06:13:21 +08:00
|
|
|
*/
|
|
|
|
|
2009-12-15 07:32:23 +08:00
|
|
|
#define NXFLAT_RELOC_OFFSET(r) ((uint32_t)(r) & 0x3fffffff)
|
2009-06-18 06:13:21 +08:00
|
|
|
|
2009-06-23 06:12:19 +08:00
|
|
|
/* These are possible values for the relocation type:
|
|
|
|
*
|
|
|
|
* NXFLAT_RELOC_TYPE_REL32I Meaning: Object file contains a 32-bit offset
|
2009-06-24 04:22:50 +08:00
|
|
|
* into I-Space at the offset.
|
2021-02-03 16:42:38 +08:00
|
|
|
* Fixup: Add mapped I-Space address to the
|
|
|
|
* offset.
|
2009-06-23 06:12:19 +08:00
|
|
|
* NXFLAT_RELOC_TYPE_REL32D Meaning: Object file contains a 32-bit offset
|
2009-06-24 04:22:50 +08:00
|
|
|
* into D-Space at the offset.
|
2009-06-23 06:12:19 +08:00
|
|
|
* Fixup: Add allocated D-Space address to the
|
|
|
|
* offset.
|
2009-06-24 04:22:50 +08:00
|
|
|
* NXFLAT_RELOC_TYPE_REL32ID Meaning: Object file contains a 32-bit offset
|
|
|
|
* into I-Space at the offset that will
|
|
|
|
* unfortunately be references relative
|
|
|
|
* to the GOT
|
|
|
|
* Fixup: Add allocated the mapped I-Space
|
|
|
|
* address MINUS the allocated D-Space
|
|
|
|
* address to the offset.
|
2009-06-23 06:12:19 +08:00
|
|
|
*/
|
2009-06-18 06:13:21 +08:00
|
|
|
|
2009-06-23 06:12:19 +08:00
|
|
|
#define NXFLAT_RELOC_TYPE_REL32I 0
|
|
|
|
#define NXFLAT_RELOC_TYPE_REL32D 1
|
2009-06-24 04:22:50 +08:00
|
|
|
#undef NXFLAT_RELOC_TYPE_REL32ID /* May not need */
|
2009-06-24 02:55:57 +08:00
|
|
|
#define NXFLAT_RELOC_TYPE_NUM 2 /* Number of relocation types */
|
2009-06-16 21:26:07 +08:00
|
|
|
|
|
|
|
/****************************************************************************
|
2014-04-14 04:32:20 +08:00
|
|
|
* NXFLAT Imported symbol type
|
2009-06-16 21:26:07 +08:00
|
|
|
*
|
|
|
|
* The imported symbols are an array of the following type. The fields
|
|
|
|
* in each element are stored in native machine order.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
struct nxflat_import_s
|
|
|
|
{
|
2009-12-15 07:32:23 +08:00
|
|
|
uint32_t i_funcname; /* Offset to name of imported function */
|
|
|
|
uint32_t i_funcaddress; /* Resolved address of imported function */
|
2009-06-16 21:26:07 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* __INCLUDE_NXFLAT_H */
|