linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* Bootstrap code with egcs
@ 1999-02-13  4:23 Benjamin Herrenschmidt
  1999-02-14  1:53 ` Michael Meissner
  0 siblings, 1 reply; 4+ messages in thread
From: Benjamin Herrenschmidt @ 1999-02-13  4:23 UTC (permalink / raw)
  To: linuxppc-dev


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 !


-- 
           E-Mail: <mailto:bh40@calva.net>
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 linuxppc-dev-request@lists.linuxppc.org ]]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Bootstrap code with egcs
  1999-02-13  4:23 Bootstrap code with egcs Benjamin Herrenschmidt
@ 1999-02-14  1:53 ` Michael Meissner
  1999-02-14 14:22   ` Benjamin Herrenschmidt
  0 siblings, 1 reply; 4+ messages in thread
From: Michael Meissner @ 1999-02-14  1:53 UTC (permalink / raw)
  To: Benjamin Herrenschmidt; +Cc: linuxppc-dev


On Sat, Feb 13, 1999 at 05:23:26AM +0100, Benjamin Herrenschmidt wrote:
> 
> 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).

-- 
Michael Meissner, Cygnus Solutions (Massachusetts office)
4th floor, 955 Massachusetts Avenue, Cambridge, MA 02139, USA
meissner@cygnus.com,	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 linuxppc-dev-request@lists.linuxppc.org ]]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Bootstrap code with egcs
  1999-02-14  1:53 ` Michael Meissner
@ 1999-02-14 14:22   ` Benjamin Herrenschmidt
  1999-02-15  9:39     ` Gabriel Paubert
  0 siblings, 1 reply; 4+ messages in thread
From: Benjamin Herrenschmidt @ 1999-02-14 14:22 UTC (permalink / raw)
  To: Michael Meissner, linuxppc-dev


On Sat, Feb 13, 1999, Michael Meissner <meissner@cygnus.com> wrote:

Thanks for the reply !

>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.

Ok. That is what I need.

>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.

-- 
           E-Mail: <mailto:bh40@calva.net>
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 linuxppc-dev-request@lists.linuxppc.org ]]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Bootstrap code with egcs
  1999-02-14 14:22   ` Benjamin Herrenschmidt
@ 1999-02-15  9:39     ` Gabriel Paubert
  0 siblings, 0 replies; 4+ messages in thread
From: Gabriel Paubert @ 1999-02-15  9:39 UTC (permalink / raw)
  To: Benjamin Herrenschmidt; +Cc: Michael Meissner, linuxppc-dev




On Sun, 14 Feb 1999, Benjamin Herrenschmidt wrote:

> 
> On Sat, Feb 13, 1999, Michael Meissner <meissner@cygnus.com> wrote:
> 
> Thanks for the reply !
> 
> >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.
> 
> 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 linuxppc-dev-request@lists.linuxppc.org ]]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1999-02-15  9:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1999-02-13  4:23 Bootstrap code with egcs Benjamin Herrenschmidt
1999-02-14  1:53 ` Michael Meissner
1999-02-14 14:22   ` Benjamin Herrenschmidt
1999-02-15  9:39     ` Gabriel Paubert

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).