Moving OS from Grub 32 bit bootloader to Pure64 0.5.0

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
User avatar
brain
Member
Member
Posts: 234
Joined: Thu Nov 05, 2009 5:04 pm
Location: UK
Contact:

Moving OS from Grub 32 bit bootloader to Pure64 0.5.0

Post by brain »

Hi all,

I've had my eye on Pure64 for some time now as a viable replacement for Grub 32 bit which i am currently using to boot my 32 bit kernel. As i see it, it would save me a whole whack of coding and debugging in migrating my 32 bit OS to 64 bit, giving me a leg up on the mundane parts.

Apart from the obvious stuff such as if i enable SMP to ensure my locking mechanisms are up to par, can anyone see any pros or cons i may have missed in attempting this migration (beyond the obvious things i have found by good old RTFM, maybe from your own personal experiences of such an endevour)?

Bear in mind my OS is generally in a state that means portability to 64 bit shouldnt be too difficult in terms of code change but theres enough code there to keep me busy for a while testing and adjusting everything.

NB: I do have my own 64 bit boot trampoline (for grub) but it is nowhere near as advanced as Pure64 nor does it do the SMP part, so this saves me lots of time i simply do not have to develop these features myself as a busy person with a family.

Advice would as always be welcomed.
User avatar
KernelDeveloper
Posts: 15
Joined: Tue Mar 13, 2012 11:25 am
Location: Earth
Contact:

Re: Moving OS from Grub 32 bit bootloader to Pure64 0.5.0

Post by KernelDeveloper »

You can move from 32bit to 64bit but the kernel would be useless until you utlize 64bit registers, etc.

For example, you hav coded your code with ebx,eax,etc but when you move to 64 there will be 64 bit registers as RAX,RBX,RCX,RDX and also many other changes.

What I mean is you would make no difference in 32 and 64 if you don't update your 32bit code to 64bit code.
No one is perfect in the world!!! :)

Make sure you visit this:
http://tinyurl.com/kerneldeveloper
User avatar
brain
Member
Member
Posts: 234
Joined: Thu Nov 05, 2009 5:04 pm
Location: UK
Contact:

Re: Moving OS from Grub 32 bit bootloader to Pure64 0.5.0

Post by brain »

Well 99% of the code is C, so simply rebuilding with an x64 cross compiler will sort that, somewhere I also have paging code for x64 and assembly code for x64 IDT handling. These will definitely be required. Thanks for the reply, though :-)
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Moving OS from Grub 32 bit bootloader to Pure64 0.5.0

Post by bluemoon »

KernelDeveloper, In fact there are much more to consider when porting to 64-bit. It's not just registers, paging and IDTs.
To name a few major issues,
1) Do you plan for first milestone to just run compatible mode applications but utilize 48-bit addressing in kernel? (This is not trivial as it seems, you need to verify all interfaces to be 32/64 compatible)

2) Do you like to host a 32-bit compatible environment (API level wrapper or another 32-bit kernel instance) within 64-bit kernel?

But from my observation brain is elite enough to handle those issues.

To the original question, my choice is write a 32-bit stub for the 64-bit kernel until things(ie. the boot loaders) get stabilized for 64-bit systems.
It's very possible that before you even ported your kernel to 64, Grub, Pure64 and bababa will get update and may involve major changes and break your boot logic.
User avatar
brain
Member
Member
Posts: 234
Joined: Thu Nov 05, 2009 5:04 pm
Location: UK
Contact:

Re: Moving OS from Grub 32 bit bootloader to Pure64 0.5.0

Post by brain »

bluemoon wrote: 1) Do you plan for first milestone to just run compatible mode applications but utilize 48-bit addressing in kernel? (This is not trivial as it seems, you need to verify all interfaces to be 32/64 compatible)
Yes this is the general first milestone,to make this work i would have to check through all my drivers and code for 64 bit compliance. For the most part i have not been assuming pointer sizes, but for some code this was unfortunately neccessary (e.g. bios memory map handling etc) so these would need to be addressed.
bluemoon wrote: 2) Do you like to host a 32-bit compatible environment (API level wrapper or another 32-bit kernel instance) within 64-bit kernel?
I don't really plan to do this, or need it (most of the userland code is interpreted inside a sandbox) so this does cut down on development time and issues.
bluemoon wrote: But from my observation brain is elite enough to handle those issues.

To the original question, my choice is write a 32-bit stub for the 64-bit kernel until things(ie. the boot loaders) get stabilized for 64-bit systems.
It's very possible that before you even ported your kernel to 64, Grub, Pure64 and bababa will get update and may involve major changes and break your boot logic.
Thanks for the advice :) I do think it is quite likely that one or the other could change in the interim, in fact i am a little tempted to add fat32 support to pure64 if i am to use it, as i do not support fat16 in my OS (only fat32) and it seems the less backwards of two options...
User avatar
IanSeyler
Member
Member
Posts: 326
Joined: Mon Jul 28, 2008 9:46 am
Location: Ontario, Canada
Contact:

Re: Moving OS from Grub 32 bit bootloader to Pure64 0.5.0

Post by IanSeyler »

While I do agree that Pure64 is awesome (I may be biased though), you may want to check out Hydrogen if you are already used to GRUB. Hydrogen is based on the ideas of Pure64. Keep in mind that Pure64 only supports loading a kernel from a FAT16-formatted hard drive.

-Ian
BareMetal OS - http://www.returninfinity.com/
Mono-tasking 64-bit OS for x86-64 based computers, written entirely in Assembly
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Moving OS from Grub 32 bit bootloader to Pure64 0.5.0

Post by bluemoon »

brain wrote:for some code this was unfortunately neccessary (e.g. bios memory map handling etc)
The BIOS memory map comes in 64-bit. I use the same routine to parse the structure in both 32-bit and 64-bit compiles:
In order to reject memory address higher than page table size could allow, I do a checking like:

Code: Select all

  uint64_t phy_address = XXXX;
  if ( phy_address >SIZE_MAX ) { ... }
This filter out address>4G in 32-bit compiles (I do without PAE), while allow full address in 64-bit compiles.
User avatar
brain
Member
Member
Posts: 234
Joined: Thu Nov 05, 2009 5:04 pm
Location: UK
Contact:

Re: Moving OS from Grub 32 bit bootloader to Pure64 0.5.0

Post by brain »

ReturnInfinity wrote:While I do agree that Pure64 is awesome (I may be biased though), you may want to check out Hydrogen if you are already used to GRUB. Hydrogen is based on the ideas of Pure64. Keep in mind that Pure64 only supports loading a kernel from a FAT16-formatted hard drive.

-Ian
Wow. just. wow. I am sold, will definitely use hydrogen. It looks like it has all the bits that pure64 was missing by being a stage 2 loader and I am able to control a lot more of its operation so its all good :-) I will let you know how it goes.

Thanks bluemoon, I did know the fields are 64 bit but what I mean is my code currently throws away the top 32 bits of the values, there are lots of iffy bits of old code like this to keep me busy for ages...
Post Reply