The ELF loader is basically functional (needs more testing)
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5265 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
parent
49ed90be32
commit
2fc26f191d
@ -3522,3 +3522,5 @@
|
|||||||
* configs/stm32f4discovery/elf and configs/stm32f4discovery/scripts/gnu-elf.ld
|
* configs/stm32f4discovery/elf and configs/stm32f4discovery/scripts/gnu-elf.ld
|
||||||
Add a configuration for testing the ARM ELF loader.
|
Add a configuration for testing the ARM ELF loader.
|
||||||
* binfmt/libelf: Can't use fstat(). NuttX does not yet support it. Damn!
|
* binfmt/libelf: Can't use fstat(). NuttX does not yet support it. Damn!
|
||||||
|
* binfmt/libelf: The basic ELF module execution appears fully functional.
|
||||||
|
|
||||||
|
@ -218,8 +218,8 @@ int arch_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym,
|
|||||||
* The branch target is encoded in these bits:
|
* The branch target is encoded in these bits:
|
||||||
*
|
*
|
||||||
* S = upper_insn[10]
|
* S = upper_insn[10]
|
||||||
* imm10 = upper_insn[9:0]
|
* imm10 = upper_insn[0:9]
|
||||||
* imm11 = lower_insn[10:0]
|
* imm11 = lower_insn[0:10]
|
||||||
* J1 = lower_insn[13]
|
* J1 = lower_insn[13]
|
||||||
* J2 = lower_insn[11]
|
* J2 = lower_insn[11]
|
||||||
*/
|
*/
|
||||||
@ -227,7 +227,7 @@ int arch_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym,
|
|||||||
upper_insn = (uint32_t)(*(uint16_t*)addr);
|
upper_insn = (uint32_t)(*(uint16_t*)addr);
|
||||||
lower_insn = (uint32_t)(*(uint16_t*)(addr + 2));
|
lower_insn = (uint32_t)(*(uint16_t*)(addr + 2));
|
||||||
|
|
||||||
bvdbg("Performing JUMP24 [%d] link at addr=%08lx [%04x %04x] to sym=%p st_value=%08lx\n",
|
bvdbg("Performing THM_JUMP24 [%d] link at addr=%08lx [%04x %04x] to sym=%p st_value=%08lx\n",
|
||||||
ELF32_R_TYPE(rel->r_info), (long)addr, (int)upper_insn, (int)lower_insn,
|
ELF32_R_TYPE(rel->r_info), (long)addr, (int)upper_insn, (int)lower_insn,
|
||||||
sym, (long)sym->st_value);
|
sym, (long)sym->st_value);
|
||||||
|
|
||||||
@ -235,9 +235,9 @@ int arch_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym,
|
|||||||
*
|
*
|
||||||
* offset[24] = S
|
* offset[24] = S
|
||||||
* offset[23] = ~(J1 ^ S)
|
* offset[23] = ~(J1 ^ S)
|
||||||
* offset[22 = ~(J2 ^ S)]
|
* offset[22] = ~(J2 ^ S)]
|
||||||
* offset[21:12] = imm10
|
* offset[12:21] = imm10
|
||||||
* offset[11:1] = imm11
|
* offset[1:11] = imm11
|
||||||
* offset[0] = 0
|
* offset[0] = 0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -245,11 +245,12 @@ int arch_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym,
|
|||||||
J1 = (lower_insn >> 13) & 1;
|
J1 = (lower_insn >> 13) & 1;
|
||||||
J2 = (lower_insn >> 11) & 1;
|
J2 = (lower_insn >> 11) & 1;
|
||||||
|
|
||||||
offset = (S << 24) |
|
offset = (S << 24) | /* S - > offset[24] */
|
||||||
((~(J1 ^ S) & 1) << 23) |
|
((~(J1 ^ S) & 1) << 23) | /* J1 -> offset[23] */
|
||||||
((~(J2 ^ S) & 1) << 22) |
|
((~(J2 ^ S) & 1) << 22) | /* J2 -> offset[22] */
|
||||||
((upper_insn & 0x03ff) << 12) |
|
((upper_insn & 0x03ff) << 12) | /* imm10 -> offset[12:21] */
|
||||||
((lower_insn & 0x07ff) << 1);
|
((lower_insn & 0x07ff) << 1); /* imm11 -> offset[1:11] */
|
||||||
|
/* 0 -> offset[0] */
|
||||||
|
|
||||||
/* Sign extend */
|
/* Sign extend */
|
||||||
|
|
||||||
@ -374,31 +375,31 @@ int arch_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym,
|
|||||||
* 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
|
* 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
|
||||||
* +---+---------------------------------------------------------+
|
* +---+---------------------------------------------------------+
|
||||||
* |OP | | 32-Bit Instructions
|
* |OP | | 32-Bit Instructions
|
||||||
* +---+--+-------+--------------+-------------------------------+
|
* +---+----------+--------------+-------------------------------+
|
||||||
* |0 |1 | imm3 | Rd | imm8 | MOVT Instruction
|
* |0 | imm3 | Rd | imm8 | MOVT Instruction
|
||||||
* +---+--+-------+--------------+-------------------------------+
|
* +---+----------+--------------+-------------------------------+
|
||||||
*
|
*
|
||||||
* The 16-bit immediate value is encoded in these bits:
|
* The 16-bit immediate value is encoded in these bits:
|
||||||
*
|
*
|
||||||
* i = imm16[11] = upper_insn[10]
|
* i = imm16[11] = upper_insn[10]
|
||||||
* imm4 = imm16[12:15] = upper_insn[3:0]
|
* imm4 = imm16[12:15] = upper_insn[3:0]
|
||||||
* imm3 = imm16[9:11] = lower_insn[14:12]
|
* imm3 = imm16[8:10] = lower_insn[14:12]
|
||||||
* imm8 = imm16[0:8] = lower_insn[7:0]
|
* imm8 = imm16[0:7] = lower_insn[7:0]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
upper_insn = (uint32_t)(*(uint16_t*)addr);
|
upper_insn = (uint32_t)(*(uint16_t*)addr);
|
||||||
lower_insn = (uint32_t)(*(uint16_t*)(addr + 2));
|
lower_insn = (uint32_t)(*(uint16_t*)(addr + 2));
|
||||||
|
|
||||||
bvdbg("Performing MOVx [%d] link at addr=%08lx [%04x %04x] to sym=%p st_value=%08lx\n",
|
bvdbg("Performing THM_MOVx [%d] link at addr=%08lx [%04x %04x] to sym=%p st_value=%08lx\n",
|
||||||
ELF32_R_TYPE(rel->r_info), (long)addr, (int)upper_insn, (int)lower_insn,
|
ELF32_R_TYPE(rel->r_info), (long)addr, (int)upper_insn, (int)lower_insn,
|
||||||
sym, (long)sym->st_value);
|
sym, (long)sym->st_value);
|
||||||
|
|
||||||
/* Extract the 16-bit offset from the 32-bit instruction */
|
/* Extract the 16-bit offset from the 32-bit instruction */
|
||||||
|
|
||||||
offset = ((upper_insn & 0x000f) << 12) |
|
offset = ((upper_insn & 0x000f) << 12) | /* imm4 -> imm16[8:10] */
|
||||||
((upper_insn & 0x0400) << 1) |
|
((upper_insn & 0x0400) << 1) | /* i -> imm16[11] */
|
||||||
((lower_insn & 0x7000) >> 4) |
|
((lower_insn & 0x7000) >> 4) | /* imm3 -> imm16[8:10] */
|
||||||
(lower_insn & 0x00ff);
|
(lower_insn & 0x00ff); /* imm8 -> imm16[0:7] */
|
||||||
|
|
||||||
/* Sign extend */
|
/* Sign extend */
|
||||||
|
|
||||||
@ -406,8 +407,8 @@ int arch_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym,
|
|||||||
|
|
||||||
/* And perform the relocation */
|
/* And perform the relocation */
|
||||||
|
|
||||||
bvdbg(" S=%d J1=%d J2=%d offset=%08lx branch target=%08lx\n",
|
bvdbg(" offset=%08lx branch target=%08lx\n",
|
||||||
S, J1, J2, (long)offset, offset + sym->st_value);
|
(long)offset, offset + sym->st_value);
|
||||||
|
|
||||||
offset += sym->st_value;
|
offset += sym->st_value;
|
||||||
|
|
||||||
|
@ -636,9 +636,11 @@ config ARCH_BOARD_STM32_CUSTOM_CLOCKCONFIG
|
|||||||
config STM32_CCMEXCLUDE
|
config STM32_CCMEXCLUDE
|
||||||
bool "Exclude CCM SRAM from the heap"
|
bool "Exclude CCM SRAM from the heap"
|
||||||
depends on STM32_STM32F20XX || STM32_STM32F40XX
|
depends on STM32_STM32F20XX || STM32_STM32F40XX
|
||||||
default y if ARCH_DMA
|
default y if ARCH_DMA || ELF
|
||||||
---help---
|
---help---
|
||||||
Exclude CCM SRAM from the HEAP because it cannot be used for DMA.
|
Exclude CCM SRAM from the HEAP because (1) it cannot be used for DMA
|
||||||
|
and (2) it appears to be impossible to execute ELF modules from CCM
|
||||||
|
RAM.
|
||||||
|
|
||||||
config STM32_FSMC_SRAM
|
config STM32_FSMC_SRAM
|
||||||
bool "External SRAM on FSMC"
|
bool "External SRAM on FSMC"
|
||||||
|
@ -142,7 +142,10 @@ static int elf_relocate(FAR struct elf_loadinfo_s *loadinfo, int relidx,
|
|||||||
int ret;
|
int ret;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* Examine each relocation in the section */
|
/* Examine each relocation in the section. 'relsec' is the section
|
||||||
|
* containing the relations. 'dstsec' is the section containing the data
|
||||||
|
* to be relocated.
|
||||||
|
*/
|
||||||
|
|
||||||
for (i = 0; i < relsec->sh_size / sizeof(Elf32_Rel); i++)
|
for (i = 0; i < relsec->sh_size / sizeof(Elf32_Rel); i++)
|
||||||
{
|
{
|
||||||
|
@ -154,6 +154,7 @@ int elf_init(FAR const char *filename, FAR struct elf_loadinfo_s *loadinfo)
|
|||||||
/* Get the length of the file. */
|
/* Get the length of the file. */
|
||||||
|
|
||||||
ret = elf_filelen(loadinfo, filename);
|
ret = elf_filelen(loadinfo, filename);
|
||||||
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
bdbg("elf_filelen failed: %d\n", ret);
|
bdbg("elf_filelen failed: %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -1007,6 +1007,10 @@ Where <subdir> is one of the following:
|
|||||||
3. By default, this project assumes that you are *NOT* using the DFU
|
3. By default, this project assumes that you are *NOT* using the DFU
|
||||||
bootloader.
|
bootloader.
|
||||||
|
|
||||||
|
4. This configuration requires that you have the genromfs tool installed
|
||||||
|
on your system and that you have the full path to the installed genromfs
|
||||||
|
executable in PATH variable (see apps/examples/README.txt)
|
||||||
|
|
||||||
ostest:
|
ostest:
|
||||||
------
|
------
|
||||||
This configuration directory, performs a simple OS test using
|
This configuration directory, performs a simple OS test using
|
||||||
|
@ -160,6 +160,7 @@ LDNXFLATFLAGS = -e main -s 2048
|
|||||||
|
|
||||||
# ELF module definitions
|
# ELF module definitions
|
||||||
|
|
||||||
|
CELFFLAGS = $(CFLAGS) -mlong-calls
|
||||||
LDELFFLAGS = -r -e main
|
LDELFFLAGS = -r -e main
|
||||||
ifeq ($(WINTOOL),y)
|
ifeq ($(WINTOOL),y)
|
||||||
LDELFFLAGS += -T "${shell cygpath -w $(TOPDIR)/configs/$(CONFIG_ARCH_BOARD)/scripts/gnu-elf.ld}"
|
LDELFFLAGS += -T "${shell cygpath -w $(TOPDIR)/configs/$(CONFIG_ARCH_BOARD)/scripts/gnu-elf.ld}"
|
||||||
|
@ -179,7 +179,7 @@ CONFIG_STM32_USART2=y
|
|||||||
CONFIG_STM32_JTAG_SW_ENABLE=y
|
CONFIG_STM32_JTAG_SW_ENABLE=y
|
||||||
# CONFIG_STM32_FORCEPOWER is not set
|
# CONFIG_STM32_FORCEPOWER is not set
|
||||||
# CONFIG_ARCH_BOARD_STM32_CUSTOM_CLOCKCONFIG is not set
|
# CONFIG_ARCH_BOARD_STM32_CUSTOM_CLOCKCONFIG is not set
|
||||||
# CONFIG_STM32_CCMEXCLUDE is not set
|
CONFIG_STM32_CCMEXCLUDE=y
|
||||||
|
|
||||||
#
|
#
|
||||||
# USB Host Configuration
|
# USB Host Configuration
|
||||||
@ -251,7 +251,7 @@ CONFIG_SDCLONE_DISABLE=y
|
|||||||
# CONFIG_SCHED_WAITPID is not set
|
# CONFIG_SCHED_WAITPID is not set
|
||||||
# CONFIG_SCHED_ATEXIT is not set
|
# CONFIG_SCHED_ATEXIT is not set
|
||||||
# CONFIG_SCHED_ONEXIT is not set
|
# CONFIG_SCHED_ONEXIT is not set
|
||||||
CONFIG_USER_ENTRYPOINT="ostest_main"
|
CONFIG_USER_ENTRYPOINT="elf_main"
|
||||||
CONFIG_DISABLE_OS_API=y
|
CONFIG_DISABLE_OS_API=y
|
||||||
# CONFIG_DISABLE_CLOCK is not set
|
# CONFIG_DISABLE_CLOCK is not set
|
||||||
# CONFIG_DISABLE_POSIX_TIMERS is not set
|
# CONFIG_DISABLE_POSIX_TIMERS is not set
|
||||||
@ -387,6 +387,7 @@ CONFIG_ELF_ALIGN_LOG2=2
|
|||||||
CONFIG_ELF_STACKSIZE=2048
|
CONFIG_ELF_STACKSIZE=2048
|
||||||
CONFIG_ELF_BUFFERSIZE=128
|
CONFIG_ELF_BUFFERSIZE=128
|
||||||
CONFIG_ELF_BUFFERINCR=32
|
CONFIG_ELF_BUFFERINCR=32
|
||||||
|
# CONFIG_ELF_CONSTRUCTORS is not set
|
||||||
CONFIG_SYMTAB_ORDEREDBYNAME=y
|
CONFIG_SYMTAB_ORDEREDBYNAME=y
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -409,7 +410,7 @@ CONFIG_ARCH_LOWPUTC=y
|
|||||||
CONFIG_LIB_SENDFILE_BUFSIZE=512
|
CONFIG_LIB_SENDFILE_BUFSIZE=512
|
||||||
# CONFIG_ARCH_ROMGETC is not set
|
# CONFIG_ARCH_ROMGETC is not set
|
||||||
# CONFIG_ARCH_OPTIMIZED_FUNCTIONS is not set
|
# CONFIG_ARCH_OPTIMIZED_FUNCTIONS is not set
|
||||||
# CONFIG_HAVE_CXX is not set
|
CONFIG_HAVE_CXX=y
|
||||||
# CONFIG_HAVE_CXXINITIALIZE is not set
|
# CONFIG_HAVE_CXXINITIALIZE is not set
|
||||||
# CONFIG_CXX_NEWLONG is not set
|
# CONFIG_CXX_NEWLONG is not set
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user