x86-64 kernel

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
kan
Posts: 19
Joined: Sat Jan 22, 2005 12:00 am
Location: India

x86-64 kernel

Post by kan »

hi,
i want to develop kernel for x86-64 arch. Since initially GRUB loads kernel in 32bits protected mode,first part of my kernel has to be 32bit and then when i activate Long Mode, whatever instructions i execute have to be of 64bit kernel. So what i need is combination of 32bit and 64bit kernel.
So is it possible that i compile 32bit and 64bit kernel seperately and then link them together to form final kernel??
Considering i am using gcc , in what format should i compile my 64bit kernel in? i use elf32 format for my 32bit kernel part.
Secondly i don't want that , there should be two separate 32bit and 64bit kernel , in which case initial 32bit kernel loads 64bit kernel part after activating Long Mode. Because then i will have to write HDD,FDD,DMA drivers and etc unwanted stuff at initial stage! Coz drivers i write for 32bit kernel won't be usable for my 64bit kernel which is the real kernel part i am interested in.
Any Suggestions?? are most Welcomed!
Nothings Impossible :)
Phibred
Member
Member
Posts: 31
Joined: Sun Jun 26, 2005 11:00 pm
Location: Toronto, Ontario, Canada
Contact:

Re: x86-64 kernel

Post by Phibred »

Well, you could just write your own BootLoader, I find that it helped me get exactly what I wanted during my BIOS enabled stage :P.

Then again, I really do not know much about 64bit development, I am stuck in 32 bit land still. Well, its just an idea and you will probly get to learn a lot more writing your own start up.
It will come from the ashes of the old era.
-- James Vaughan
rexlunae
Member
Member
Posts: 134
Joined: Sun Oct 24, 2004 11:00 pm
Location: North Dakota, where the buffalo roam

Re: x86-64 kernel

Post by rexlunae »

kan wrote:Any Suggestions?? are most Welcomed!
GRUB supports the loading of modules. Basically, that means that it will load some specified files into memory before transferring control to your kernel. What I might suggest is that the "kernel" that you have GRUB load could just be a 32-bit loader which sets up long mode, and then have the real kernel loaded into memory as a module by GRUB, and have your 32-bit loader load it into the correct location in memory and start it.

This is definitely harder than using GRUB in 32-bit mode, but it's still easier than writing a bootloader to support everything that GRUB does.
Phibred
Member
Member
Posts: 31
Joined: Sun Jun 26, 2005 11:00 pm
Location: Toronto, Ontario, Canada
Contact:

Re: x86-64 kernel

Post by Phibred »

Very true, but I assume that this will be the first attempt at developing a kernel, so a good hard bootloader lession might be a good one to start with. And I am sure that most of the advanced features of GRUB won't be needed for a reletivly long time.
It will come from the ashes of the old era.
-- James Vaughan
rexlunae
Member
Member
Posts: 134
Joined: Sun Oct 24, 2004 11:00 pm
Location: North Dakota, where the buffalo roam

Re: x86-64 kernel

Post by rexlunae »

Phibred wrote:Very true, but I assume that this will be the first attempt at developing a kernel, so a good hard bootloader lession might be a good one to start with.
I don't see the point in that. Most of the things you need to do in a bootloader you also need to do in your OS, so even if you are looking for a learning experience, the OS should be plenty.
Phibred wrote:And I am sure that most of the advanced features of GRUB won't be needed for a reletivly long time.
That depends. If you are writing a microkernel with no hardware drivers built-in, the module loading capability may be essential nearly from day one. It's also easier to debug just your kernel, and not have to worry that the bootloader may do strange things and need a lot of additional debugging as well. And it's always nice to be able to load from a filesystem easily, especially if you already have OSes installed on your computer.
kan
Posts: 19
Joined: Sat Jan 22, 2005 12:00 am
Location: India

Re: x86-64 kernel

Post by kan »

hi,
hmmm,thank u for ur suggestions. i think a better approach would be to load 32bit kernel normally and 64bit kernel as module with help of GRUB.
But my main question is left unanswered! i.e Can we combine both 32bit and 64bit kernel together? and secondly can i compile and link 64bit kernel using existing file formats such as elf32 ...etc??????


I hope these questions get answered soon :(
Nothings Impossible :)
User avatar
carbonBased
Member
Member
Posts: 382
Joined: Sat Nov 20, 2004 12:00 am
Location: Wellesley, Ontario, Canada
Contact:

Re: x86-64 kernel

Post by carbonBased »

You can combine anything you want in an OS image... you could include a JPEG and a text file, if you wanted, it's your call. It's entirely possible to combine a 32-bit image and a 64-bit image together, you'll just have to make sure that the processor is in the right mode to execute the appropriate sections (several kernels in the past have done this with combined 16 and 32-bit images).

As per existing file formats... no, you can't use elf32. How would you represent a 64-bit offset with a 32-bit object format? You'll need elf64 tools.

Also, with all this talk of loading a stub via grub and the actual kernel as a module... why not just combine your stub into grub. In other words, update grub such that it puts the processor into long mode, then there's no need for work-arounds such as this.

--Jeff
rexlunae
Member
Member
Posts: 134
Joined: Sun Oct 24, 2004 11:00 pm
Location: North Dakota, where the buffalo roam

Re: x86-64 kernel

Post by rexlunae »

carbonBased wrote:Also, with all this talk of loading a stub via grub and the actual kernel as a module... why not just combine your stub into grub. In other words, update grub such that it puts the processor into long mode, then there's no need for work-arounds such as this.
True, a patch to get GRUB to support 64-bit kernels would be the cleanest solution. And I suppose it could be back-compatible. When loading elf32, set protected mode for a 32-bit kernel, when loading elf64, use long mode. Actually, it would be nice if GRUB would adopt an official patch for this.
Legend
Member
Member
Posts: 195
Joined: Tue Nov 02, 2004 12:00 am
Contact:

Re: x86-64 kernel

Post by Legend »

However, that would probably mean a new version of the multiboot standard! ;)
*post*
kan
Posts: 19
Joined: Sat Jan 22, 2005 12:00 am
Location: India

Re: x86-64 kernel

Post by kan »

thank u all, for ur suggestions. OS development is a really complicated process, though an interesting one!
Nothings Impossible :)
Post Reply