gcc q

gcc q

Shachar Shemesh shachar at shemesh.biz
Mon Aug 23 10:44:56 IDT 2010


Erez D wrote:
>
>
>     Is that before or instead of the usual initializations?
>
> before.
> i just want to run a hardware registers initialization function.

Okay. I'm going to assume that you are writing code that is meant to run 
directly on the hardware, no external OS. Also, I'm assuming you have a 
means to actually load that code into the CPU's address space (nor 
flash, loader, etc.)

If those assumptions are true, and you are working with a GNU toolchain 
(or derivative), then you, most likely, have a linker control file (also 
known as a "linker script"). If you are not sure, search for an 
invocation of the linker phase with the -T or --script options. This 
file will explicitly know where to place code so that it is executed 
first thing on startup, and will probably be placing the compiler's 
startup code there. You will need to do two things:
1. Supply your hardware initialization code, preferably written in 
assembly, mapped into a custom section.
2. Modify the linker script to load that section into the CPU's startup 
point, and only load your compiler's output after it (or elsewhere - 
details depend on your precise hardware).

If your "hardware registers initialization function" is written in C, 
you will need to figure out what your ABI is, and set it up from your 
assembly stub. Also, check your hardware docs to see whether the 
hardware has any guarantees it makes about register values etc., and 
check whether the compiler's startup code relies on those. If so, you 
might need to make sure your stub's exit code does the right thing.

Good luck. Also, there are consultants (ahem) that would be happy to 
charge you in order to work out the details for you.

Shachar

-- 
Shachar Shemesh
Lingnu Open Source Consulting Ltd.
http://www.lingnu.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.cs.huji.ac.il/pipermail/linux-il/attachments/20100823/abe485ac/attachment.html>


More information about the Linux-il mailing list