64-Bit bootloader

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Fudlite
Posts: 2
Joined: Tue Sep 21, 2010 9:23 am

64-Bit bootloader

Post 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
Fudlite
Posts: 2
Joined: Tue Sep 21, 2010 9:23 am

Re: 64-Bit bootloader

Post by Fudlite »

That's probably what I'll end up doing lol :wink:
StephanvanSchaik
Member
Member
Posts: 127
Joined: Sat Sep 29, 2007 5:43 pm
Location: Amsterdam, The Netherlands

Re: 64-Bit bootloader

Post 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.
StephanvanSchaik
Member
Member
Posts: 127
Joined: Sat Sep 29, 2007 5:43 pm
Location: Amsterdam, The Netherlands

Re: 64-Bit bootloader

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