building

This is an old revision of the document!


Bare metal applications do not use a C library.

QEMU emulation

As read in balau82.wordpress.com (great blog):

The QEMU emulator is written especially to emulate Linux guest systems; for this reason its startup procedure is implemented specifically: the -kernel option loads a binary file (usually a Linux kernel) inside the system memory starting at address 0x00010000. The emulator starts the execution at address 0x00000000, where few instructions (already in place) are used to jump at the beginning of the kernel image. The interrupt table of ARM cores, usually placed at address 0x00000000, is not present, and the peripheral interrupts are disabled at startup, as needed to boot a Linux kernel.

The ARM9 architecture begins to execute code at a determined address, that could be 0 (usually allocated to RAM) or 0xFFFF0000 (usually allocated to Read Only Memory). We must put some special code at that particular address: the interrupt vector table.

  • Interrupt vector table (startup.s)
.section INTERRUPT_VECTOR, "x"
.global _Reset
_Reset:
 B Reset_Handler /* Reset */
 B . /* Undefined */
 B . /* SWI */
 B . /* Prefetch Abort */
 B . /* Data Abort */
 B . /* reserved */
 B . /* IRQ */
 B . /* FIQ */

Reset_Handler:
LDR sp, =stack_top
 BL c_entry
 B .

* A C file containing a function c_entry
  • A linker script
ENTRY(_Reset)
SECTIONS
{
 . = 0x0;
 .text : {
 startup.o (INTERRUPT_VECTOR)
 *(.text)
 }
 .data : { *(.data) }
 .bss : { *(.bss) }
 . = . + 0x1000; /* 4kB of stack memory */
 stack_top = .;
}
  • building.1314192861.txt.gz
  • Last modified: 15 years ago
  • by admin