Loading a higher half long mode kernel help
Posted: Fri Mar 26, 2010 12:20 pm
Hello, i have ben away from OS development for a while and have decided to come back and write a 64bit long mode kernel(just for fun ). I have read the AMD systems programmers manual and a few other sources and have just found the http://wiki.osdev.org/Creating_a_64-bit_kernel tutorial as well (which reasuringly suggested the plan i had been formulating for loading my kernel). Unfortuantly i am still a little unclear as to how to go about some of the technical details involved in initialising longmode and getting my code running in the highre half so am turning to the good people at this site for advice before spending hours running down blind alleys. My current plan is as follows(but if there is an easyer way to get an elf64 kernel running in the higher half pls let me know):
Ultimately i want a 64bit kernel running in the higher half of its VAS. To achieve this goal my plan is to use GRUB Legacy as my initial boot loader(since im already familiar with it), GRUB will load my own 32bit loader as a kernel and load my 64bit kernel as a module(along with other modules for drivers and the init process) . My 32 bit loader will do the initial prep work for long mode (Make a GDT,IDT and the initial long mode page table structures), process the boot modules by unpacking them into physical memory and mapping them appropriatly into the 64bit vas, Enable long mode by enabeling pageing and then activating long mode by doing a far jump to the 64bit code segment with the entry point of my 64 bit kernel (passing it the addresses of some systems information datastrucuters in registers).
I have almost got the above process working with two 32bit kernels and a 4GB address space and im now planning on making the necesary changes to maek it load the 64 bit kernel. The first thing i dont understand however is once ive doneall the long mode enabling stuff with the page tabels how i actually jump into my 64bit kernel? I know that to actually activate long mode i must do a far jump to a 64bit code segment but since the jump is being executed in protected mode i only have a 32bit offset and so cannot use the offset of my kernel in the higher half. Also since segment based addressing is ignored i cant do any tricks with the base address to overcome this problem. So is the only way to do this to include a tiny 64bit code stub in my 32bit loader that repeats the jump with a 64bit address or am i missing a trick?
Thanks for your time and apologies since this may be the first in a series of questions while i get my head round this
Pinky
Ultimately i want a 64bit kernel running in the higher half of its VAS. To achieve this goal my plan is to use GRUB Legacy as my initial boot loader(since im already familiar with it), GRUB will load my own 32bit loader as a kernel and load my 64bit kernel as a module(along with other modules for drivers and the init process) . My 32 bit loader will do the initial prep work for long mode (Make a GDT,IDT and the initial long mode page table structures), process the boot modules by unpacking them into physical memory and mapping them appropriatly into the 64bit vas, Enable long mode by enabeling pageing and then activating long mode by doing a far jump to the 64bit code segment with the entry point of my 64 bit kernel (passing it the addresses of some systems information datastrucuters in registers).
I have almost got the above process working with two 32bit kernels and a 4GB address space and im now planning on making the necesary changes to maek it load the 64 bit kernel. The first thing i dont understand however is once ive doneall the long mode enabling stuff with the page tabels how i actually jump into my 64bit kernel? I know that to actually activate long mode i must do a far jump to a 64bit code segment but since the jump is being executed in protected mode i only have a 32bit offset and so cannot use the offset of my kernel in the higher half. Also since segment based addressing is ignored i cant do any tricks with the base address to overcome this problem. So is the only way to do this to include a tiny 64bit code stub in my 32bit loader that repeats the jump with a 64bit address or am i missing a trick?
Thanks for your time and apologies since this may be the first in a series of questions while i get my head round this
Pinky