hendrixjl
Posts: 50
Joined: Sun Nov 04, 2012 9:22 pm
Location: Huntsville, Alabama, USA

forcing _start to 0x00008000

Sun Jan 13, 2013 2:28 pm

I was doing a lot with a project that originated with dwelch67's
(https://github.com/dwelch67/raspberrypi
I'm finding it more and more difficult to keep _start as the first routine. I assume there is some way to do this in the linker script, but I can't figure it out. I have only the most basic script write now:

Code: Select all

MEMORY
{
    ram : ORIGIN = 0x8000, LENGTH = 0x10000
}

SECTIONS
{
    .text : { *(.text*) } > ram
    .bss : { *(.bss*) } > ram
}
Can anyone help?
Thanks,
John

dwelch67
Posts: 954
Joined: Sat May 26, 2012 5:32 pm

Re: forcing _start to 0x00008000

Sun Jan 13, 2013 4:48 pm

can you post the exact commands you are using? the make file, etc shows how to do it. nostartfiles keeps the linker from grabbing crt0, then the position on the command line (plus the linker script) control what order things go in the binary. make sure that your object with _start in it is the first file.

post what you have so far, and what your results are.

David

hendrixjl
Posts: 50
Joined: Sun Nov 04, 2012 9:22 pm
Location: Huntsville, Alabama, USA

Re: forcing _start to 0x00008000

Sun Jan 13, 2013 8:10 pm

So it is simply a matter of what is the first routine in the first object file that is linked?

I was letting eclipse generate the Makefiles and it does not seem to guarantee the order. There may be options on that.
I was hoping that something could be put in the linker script to guarantee order.
The controlled files are here (https://github.com/hendrixjl/rPi/tree/master/gpio_bare), but -as an eclipse project - it doesn't have a set make file. Of course, I could turn it into a makefile project, but I was hoping to avoid it.

dwelch67
Posts: 954
Joined: Sat May 26, 2012 5:32 pm

Re: forcing _start to 0x00008000

Sun Jan 13, 2013 10:26 pm

its not just the command line order. the linker script CAN reorder things as well. so it is a combination of the two

hendrixjl
Posts: 50
Joined: Sun Nov 04, 2012 9:22 pm
Location: Huntsville, Alabama, USA

Re: forcing _start to 0x00008000

Sun Jan 13, 2013 11:54 pm

How would the linker script re-order things? I.e., can you specify order in the linker script?

dwelch67
Posts: 954
Joined: Sat May 26, 2012 5:32 pm

Re: forcing _start to 0x00008000

Mon Jan 14, 2013 4:38 am

If the file that contains _start is in xyz.o, you can specify, in the linker script, that .text from xyz.o goes to address 0x976000 and all other .text goes to 0x8000, no matter where xyz.o is on the command line it has a very specific place in the output.

If you look at the baremetal directory in my github repo, which you have pointed out in your first post. About 2/3rds the way down you see this statement:

"Changing the order of the items on the linker command line has changed
where they are placed in the final binary. And in this case we
are in trouble, this is not working code we dont execute the bootstrap
code."

In there I show, both that changing the order of things on the command line changes where they land in the binary. Also, I show a linker script that specifies a file name, the position of that item in the linker script, and that it has called out a specific file, takes precedence over the command line order.

David

hendrixjl
Posts: 50
Joined: Sun Nov 04, 2012 9:22 pm
Location: Huntsville, Alabama, USA

Re: forcing _start to 0x00008000

Mon Jan 14, 2013 2:42 pm

Thanks a bunch! I read this a couple of months back and promptly forgot it.
John

User avatar
DavidS
Posts: 3800
Joined: Thu Dec 15, 2011 6:39 am
Location: USA
Contact: Website

Re: forcing _start to 0x00008000

Mon Jan 14, 2013 4:02 pm

I do not use GAS. Though being specific is very simple using ExtASM, OBJAsm, or even the BBC BASIC Assembler. The only trouble is that if you wish to link with objects compiled in GCC you will have to remember to specify AOF as the object format for GCC.
RPi = Way for me to have fun and save power.
100% Off Grid.
Household TTL Electricity Usage = 1.4KW/h per day.
500W Solar System, produces 2.8KW/h per day average.

Return to “Bare metal, Assembly language”