Skip to contentSkip to conversation

Bootstrap code with egcs

DISCUSSION Benjamin Herrenschmidt 3 participants 4 messages Feb 13, 1999 – Feb 15, 1999

lore
Share & tools
lore
#0 lore raw

Hi !

I'm in the process of improving the way BootX boots and adding support for NuBus PowerMacs. However, I need to write some PPC bootstrap code that will take control before the kernel is actually entered. Part of it is PPC asm, but I want some C code too.

The Mac-hosted tools I have (CodeWarrior and MrC) can only, to my knowledge, produce PEF (or XCOFF), so the boostrap code needs a complex relocation before beeing entered, and I have to handle a TOC which is not what I want in this boostrap.

I was wondering what kind of options are available with egcs for generating code that is suitable for bootstraps, if possible, relocatable code (datas are PC relative).

The bootstrap will be entered with both data and instructions MMUs disabled, so the logical-physical mapping will be 1:1. The boostreap itself will be made contiguous and resident somewhere in this physical memory by BootX along with some memory for a small stack, and eventually some datas. It will be passed a map of the physical RAM, a map of the kernel pages (scattered in memory) and will take care of putting the kernel pages back contiguously in physical mem before entering the kernel.

I'm not very experienced with egcs, ELF format, etc... so some details about how I can generate an easy-to-relocate code (I can use a RELOC macro all the time like prom.c does if fixed link address is used) and how I must parse the resulting ELF (I beleive the way I parse the kernel header) would help. (By details I mean which tools with which option, I don't know the gnu toolchain very well).

Thanks in advance !

Signature · 11 lines
           E-Mail: <mailto:[email protected]>
BenH.      Web   : <http://calvaweb.calvacom.fr/bh40/>





[[ This message was sent via the linuxppc-dev mailing list. Replies are ]]
[[ not forced back to the list, so be sure to  Cc linuxppc-dev  if your ]]
[[ reply is of general interest. To unsubscribe from linuxppc-dev, send ]]
[[ the message 'unsubscribe' to [email protected] ]]
#1 lore raw
Quoted 7 lines · Benjamin Herrenschmidt

Hi !

I'm in the process of improving the way BootX boots and adding support for NuBus PowerMacs. However, I need to write some PPC bootstrap code that will take control before the kernel is actually entered. Part of it is PPC asm, but I want some C code too.

Using the standard PowerPC GCC Linux compiler, if you use the -mrelocatable switch, and call __eabi immediately in the startup code after setting up the stack, it will generate position independent code. The -mrelocatable switch tells the compiler to put all non-call addresses used in a table, that the __eabi function fixes up to the appropriate address. The text and data section must be loaded at the same relative location to each other. If you configured the compiler for powerpc-eabi instead of powerpc-linux, it would generate the __eabi call automatically for the main function, but since the Linux compiler doesn't do this, you need to do it by hand.

Note, all modules linked together must be compiled with the -mrelocatable option, including those being assembled (and the assembler will check whether you did any relocations that can't be fixed up). For libraries there is the -mrelocatable-lib that allow the modules to be linked with either normal code or -mrelocatable code (but I think there are some bfd/linker changes that haven't been released yet that affect the linking of -mrelocatable-lib modules).

Signature · 8 lines
Michael Meissner, Cygnus Solutions (Massachusetts office)
4th floor, 955 Massachusetts Avenue, Cambridge, MA 02139, USA
[email protected],	617-354-5416 (office),	617-354-7161 (fax)

[[ This message was sent via the linuxppc-dev mailing list. Replies are ]]
[[ not forced back to the list, so be sure to  Cc linuxppc-dev  if your ]]
[[ reply is of general interest. To unsubscribe from linuxppc-dev, send ]]
[[ the message 'unsubscribe' to [email protected] ]]
#2 lore raw

On Sat, Feb 13, 1999, Michael Meissner <[email protected]> wrote:

Thanks for the reply !

Quoted 7 lines

Using the standard PowerPC GCC Linux compiler, if you use the -mrelocatable switch, and call __eabi immediately in the startup code after setting up the stack, it will generate position independent code. The -mrelocatable switch tells the compiler to put all non-call addresses used in a table, that the __eabi function fixes up to the appropriate address. The text and data section
must be loaded at the same relative location to each other. If you

configured

Quoted 3 lines

the compiler for powerpc-eabi instead of powerpc-linux, it would generate the __eabi call automatically for the main function, but since the Linux compiler doesn't do this, you need to do it by hand.

Ok. That is what I need.

Quoted 7 lines

Note, all modules linked together must be compiled with the -mrelocatable option, including those being assembled (and the assembler will check whether you did any relocations that can't be fixed up). For libraries there is the -mrelocatable-lib that allow the modules to be linked with either normal code or -mrelocatable code (but I think there are some bfd/linker changes that haven't been released yet that affect the linking of -mrelocatable-lib modules).

I won't link against any existing library, just a couple of .c files and eventually some assembly code.

Signature · 10 lines
           E-Mail: <mailto:[email protected]>
BenH.      Web   : <http://calvaweb.calvacom.fr/bh40/>




[[ This message was sent via the linuxppc-dev mailing list. Replies are ]]
[[ not forced back to the list, so be sure to  Cc linuxppc-dev  if your ]]
[[ reply is of general interest. To unsubscribe from linuxppc-dev, send ]]
[[ the message 'unsubscribe' to [email protected] ]]
#3 lore raw
Quoted 12 lines · Benjamin Herrenschmidt

On Sat, Feb 13, 1999, Michael Meissner <[email protected]> wrote:

Thanks for the reply !

Quoted 7 lines

Using the standard PowerPC GCC Linux compiler, if you use the -mrelocatable switch, and call __eabi immediately in the startup code after setting up the stack, it will generate position independent code. The -mrelocatable switch tells the compiler to put all non-call addresses used in a table, that the __eabi function fixes up to the appropriate address. The text and data section
must be loaded at the same relative location to each other. If you

Quoted 6 lines

configured

Quoted 3 lines

the compiler for powerpc-eabi instead of powerpc-linux, it would generate the __eabi call automatically for the main function, but since the Linux compiler doesn't do this, you need to do it by hand.

Ok. That is what I need.

Note that this not exactl ywhat I do in my prepboot code, I wrote directly the relocation code in assembly (with the help of a few linker tricks) because I did not know about __eabi.

The other problem I had to solve (and I donn't know if a call to __eabi would work) is that I need to relocate twice:
- the 1st time just after the loaded image is given control.
- the 2nd time after a minimal startup code has been executed which determines memory layout and moves itself to the highest possible address (because in some machines the initial image loaded at low addresses where I want to put the kernel).

The code between both relocation has to be very carefully written because it has very little stack space and it basically can't do any pointer manipulation.

Gabriel.

[[ This message was sent via the linuxppc-dev mailing list. Replies are ]] [[ not forced back to the list, so be sure to Cc linuxppc-dev if your ]] [[ reply is of general interest. To unsubscribe from linuxppc-dev, send ]] [[ the message 'unsubscribe' to [email protected] ]]