Posts: 9
Joined: Thu Aug 27, 2015 8:31 pm

How did GCC compiler know my start address is 0x8000 ?

Sat Oct 24, 2015 9:15 am

I am compiling for a bare metal code using GCC for my Raspberry Pi 2. When I see the compiled output, I saw that the code begins at address 0x8000. Below shown is my test.c file, compiler commandline option and the objdump.

Question: How did the compiler understand that the code should be placed at address 0x8000 ? Is it the start address for Cortex A7 which is present inside the Raspberry Pi 2 ?


Code: Select all

int main()
    volatile int i=0;
    i = i+1;

    return 0;

Code: Select all

arm-none-eabi-gcc -Wall -Werror -O2 -mfpu=neon-vfpv4 -mfloat-abi=hard -march=armv7-a -mtune=cortex-a7 -nostdlib test.c -o output.o

Code: Select all

output.o:     file format elf32-littlearm

Disassembly of section .text:

00008000 <main>:
    8000:	e24dd008 	sub	sp, sp, #8
    8004:	e3a00000 	mov	r0, #0
    8008:	e58d0004 	str	r0, [sp, #4]
    800c:	e59d3004 	ldr	r3, [sp, #4]
    8010:	e2833001 	add	r3, r3, #1
    8014:	e58d3004 	str	r3, [sp, #4]
    8018:	e28dd008 	add	sp, sp, #8
    801c:	e12fff1e 	bx	lr

Posts: 76
Joined: Sun Apr 15, 2012 2:23 pm

Re: How did GCC compiler know my start address is 0x8000 ?

Sat Oct 24, 2015 9:59 am

This would be where the default ARM linker script puts your code in your toolchain. This would be located at <your toolchain path>/arm-none-eabi/lib/ldscripts

If you want more control, which you normally want for bare metal coding, then you should provide your own linker script through the -T parameter to gcc. The Baking Pi tutorial provides a template ( ... ate.tar.gz) with a pretty simple linker script you can use as a starting point. The tutorial ... orials/os/ is also a good source of information, though you might want to look at old forum posts to get updates.

Posts: 4
Joined: Mon Nov 16, 2015 6:49 pm

Re: How did GCC compiler know my start address is 0x8000 ?

Mon Nov 16, 2015 10:45 pm

Here's example memmap file that I'm using for the -T option on the linker. I have the code starting at 0x208000. I have a large ram disk file that starts at 0x7000000. The ram disk is a large binary file that I included in a .s file with the following commands:

This took a while to figure out so I'm posting here in case it helps someone.

--- ramdisk.s

.section .data
.align 4
.incbin "ramdisk.img"

---- memmap

ram : ORIGIN = 0x208000, LENGTH = 0x100000

.text : { *(.text*) } > ram
.bss : { *(.bss*) } > ram
.data 0x7000000 : { *(.data*) }

Return to “Bare metal, Assembly language”