[Prev][Next][Index][Thread]

Re: kernel and paging



At 17:16 9/17/99, Giuseppe Lettieri wrote:
>We need to link and execute the whole kernel at a given linear address (we
>don't use segments), with paging enabled so that we don't care where the
>kernel
>image actually resides in physical memory.
>Is there an easy way to do this? Can we still use a multiboot compliant loader
>(we are currently using FreeBSD boot loader) or do we need a different one?

The Multiboot standard requires the loader to transfer control to the
kernel with paging disabled.  So it is the kernel's responsibility to set
up paging (most bootloaders I know of work this way... multiboot loaders
all do, IIRC LILO does it too).  There are a few solutions I can think of:

- Write your own bootloader that sets up paging; or find an existing loader
  that does setup paging but can still load ELF kernels.
- Create a simple "loader kernel" to setup the machine state (paging and other
  stuff) and then load your real kernel and execute it.  Then the real kernel
  can be relocated at your fixed address.  This is useful anyway for a micro-
  kernel like system, because then you can load all of the different modules
  correctly on boot.
- Write a piece of assembly code as your startup code which sets up the
  machine state, and make sure it doesn't rely on where it is loaded in memory
  (indirect jumps etc.)  This is how Linux works (you could steal some code
  from linux/arch/i386/boot/).  You'll have to use a linker script in order
  to fool the multiboot loader into thinking that it should load it in low
  memory.  This can be tricky, I have an example if you want it.  Unfortunately,
  most versions of GRUB that I have seen have a bug that prevents this from
  working; but it is very easily fixed (change one line of code.)  I dunno about
  the FreeBSD loader, I've never used it.
- Put all the initialisation code in a different section in the ELF file.
  Then write a linker script that relocates the init section to be identity
  mapped, and the .text section to be at the linear address you want, while
  fooling the loader to load it in low memory (see previous point).  The
  advantage of this one is that you can use C code to initialise the kernel.

The advantage of the last two points is that you can put everything into one
ELF binary.  The disadvantage is that you cannot use the OSKit to setup the
machine state (even with the last option, this is probably not possible because
the OSKit will be relocated into the text section and will thus not be
accessible until you've actually setup paging.

The second option is probably the simplest.

Hope this helps (and that I haven't said too much nonsense ;)),
Ramon