Page 1 of 1

64-Bit bootloader

Posted: Tue Sep 21, 2010 9:36 am
by Fudlite
Hi! I'm relatively new to bootloaders, and I'm looking for some help with an example bootloader that just attempts to go into 64-bit mode, and then runs the kernel. If it fails, then it just runs the 32-bit kernel in its place.

I know I'm probably asking a lot, but all the 64-bit bootloader tutorials I've seen around show random snippets, but nothing I've been able to make work.

My goal is to write a hybrid microkernel as a personal project, but I need to get the thing to load =P

Thanks very much!

Fud

Re: 64-Bit bootloader

Posted: Tue Sep 21, 2010 11:15 am
by Fudlite
That's probably what I'll end up doing lol :wink:

Re: 64-Bit bootloader

Posted: Tue Sep 21, 2010 4:16 pm
by StephanvanSchaik
Hi,

Generally, the boot process (I use) is as following:
  • Set up the segment registers and the stack pointer.
  • Store BIOS information.
  • Set up VGA.
  • Test if the CPU is at least a 80386.
  • Validate that the boot loader is entirely loaded, otherwise try it manually when possible.
  • Test if the CPU supports certain instructions I need.
  • Enable the A20 gate.
  • Enter unreal mode (real mode with 32-bit data descriptors).
  • Attempt to retrieve the memory regions.
  • Set up a minimal memory manager.
  • Parse the file system looking for KERNEL32 and KERNEL64 and load them both.
  • Test if the CPU is a 64-bit processor.
  • Prepare to jump to KERNEL64, when it was loaded i.e. exists.
  • Otherwise prepare to jump to KERNEL32.
Information dedicated to testing if a x86-processor is also a x86-64-processor, entering long mode and preparing the execution of the kernel can be found here.


Regards,
Stephan J.R. van Schaik.

Re: 64-Bit bootloader

Posted: Wed Sep 22, 2010 6:33 am
by StephanvanSchaik
berkus wrote:
StephanVanSchaik wrote:
  • Parse the file system looking for KERNEL32 and KERNEL64 and load them both.
  • Test if the CPU is a 64-bit processor.
Why not reverse these two and skip loading the not-needed kernel altogether?
Actually, this was what I was doing several months ago, but I am not using 64-bit at the moment and it took me some time to rethink what I exactly did in my older boot loaders. My new boot loader currently only supports 32-bit, but will use the exact method I described here since I am trying to merge both architectures into one file.


Regards,
Stephan J.R. van Schaik.