move to 64 bit OS

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.
Locked
teodori
Member
Member
Posts: 103
Joined: Wed Nov 14, 2012 4:55 pm

move to 64 bit OS

Post by teodori »

Hello,
I have written a very small and simple operating system with a bootloader. I load a few sectors into memory and jump to it, then I enable A20 gate, setup a GDT and IDT, set the CPU to 32 bit, and jump to it. I end up in my 32 bit kernel written in C language.

Now I want to do it in 64 bit.
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: move to 64 bit OS

Post by sortie »

Good to hear! Do you have any plans for how to port?
User avatar
zhiayang
Member
Member
Posts: 368
Joined: Tue Dec 27, 2011 7:57 am
Libera.chat IRC: zhiayang

Re: move to 64 bit OS

Post by zhiayang »

teodori wrote:Hello,
I have written a very small and simple operating system with a bootloader. I load a few sectors into memory and jump to it, then I enable A20 gate, setup a GDT and IDT, set the CPU to 32 bit, and jump to it. I end up in my 32 bit kernel written in C language.

Now I want to do it in 64 bit.
I'm not sure of the exact nature of this topic.

Is this a statement? Question? If (a), I think this sub forum is not the right one. Announcements, Job Openings (and something else) is the one to post in. Although, I suggest that more information should be included before posting there.


If this is a question on how to make the jump to 64-bit, you need to at least add a '?' somewhere in your post.
For starters, you might want to replace the 32-bit C kernel with a simpler, 32-bit ASM bootstrap. (As sortie's OS does)

The bootstrap has to...

1. Set up the PML4, PDPT, PD and PTs. (Don't enable paging)
2. Decide if your kernel will be higher or lower half. Map the memory accordingly.
3. Enable the LM bit, PAE bit and Paging bit at the same time. This will put you in compatibility mode.
4. Load a 64-bit GDT, and jump to a 64-bit code segment.
5. Mission accomplished. Long mode, activate!


You might want to read 'THE WIKI' for more information. In fact, that is what you should have done in the first place.
teodori
Member
Member
Posts: 103
Joined: Wed Nov 14, 2012 4:55 pm

Re: move to 64 bit OS

Post by teodori »

hm I need an example, my bochs machine is triple faulting all the time. I need it in AT&T assembly, not in Intel assembly, because I am using gas. Thank you
rdos
Member
Member
Posts: 3306
Joined: Wed Oct 01, 2008 1:55 pm

Re: move to 64 bit OS

Post by rdos »

requimrar wrote: 4. Load a 64-bit GDT, and jump to a 64-bit code segment.
If the GDT doesn't need to be above 4G, there is no need to load a 64-bit GDT.
User avatar
iansjack
Member
Member
Posts: 4711
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: move to 64 bit OS

Post by iansjack »

Chapter 14 of Volume 2 of the AMD Programmers Manual gives full instructions, including a well-commented example, of switching to long mode.

As for assembler syntax - learn to use both; the differences are easy enough to grasp.
User avatar
zhiayang
Member
Member
Posts: 368
Joined: Tue Dec 27, 2011 7:57 am
Libera.chat IRC: zhiayang

Re: move to 64 bit OS

Post by zhiayang »

teodori wrote:hm I need an example, my bochs machine is triple faulting all the time. I need it in AT&T assembly, not in Intel assembly, because I am using gas. Thank you
1. I don't mean to sound rude, but asking for code usually doesn't do you well.
2. Demands such as 'GNU syntax, not Intel syntax' also serve to annoy people.
3. Phrases such as 'I want' and 'I need' are not nice either.


Also, more information other than 'triple faulting all the time' is required for proper debugging. Set bochs *not* to reset on fault, and tell us what the ISR is. GPF probably means you're overwriting your own code or something, while PF usually means you didn't identity map (or failed to do properly) your kernel.

Code: Select all

// Enable PAE Paging
	mov %cr4, %eax
	orl $0x20, %eax						// Set PAE Bit
	mov %eax, %cr4


	// Enable Long Mode
	mov $0xC0000080, %ecx
	rdmsr
	orl $0x100, %eax
	wrmsr


	// Enable Paging, enter compatibility mode
	mov %cr0, %eax
	orl $0x80000000, %eax
	mov %eax, %cr0

	// Load Long Mode GDT
	mov GDT64Pointer, %eax
	lgdtl GDT64Pointer
teodori
Member
Member
Posts: 103
Joined: Wed Nov 14, 2012 4:55 pm

Re: move to 64 bit OS

Post by teodori »

Hello,
hm could anyone tell me how to setup those page tables please?
User avatar
Griwes
Member
Member
Posts: 374
Joined: Sat Jul 30, 2011 10:07 am
Libera.chat IRC: Griwes
Location: Wrocław/Racibórz, Poland
Contact:

Re: move to 64 bit OS

Post by Griwes »

RTFM.
Reaver Project :: Repository :: Ohloh project page
<klange> This is a horror story about what happens when you need a hammer and all you have is the skulls of the damned.
<drake1> as long as the lock is read and modified by atomic operations
Locked