Qemu crashes when enabling paging

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
Qeroq
Member
Member
Posts: 52
Joined: Wed Aug 25, 2010 6:35 am
Location: Bonn, Germany

Qemu crashes when enabling paging

Post by Qeroq »

Hello,
since I started to work on an OS project of mine, called Carbon [1], I've always been using bochs for testing; now I wanted to try qemu first, before running on real hardware, but I ran into qemu crashing when setting the paging bit in CR0, after having loaded the PML4, in order to switch from protected to long mode in my loader (see loader/src/boot.s in the github repo).

To narrow down what could be causing the problem, I installed a IDT and several handlers and checked whether an interrupt is raised on enabling paging, but it wasn't.

As qemu is not as verbose as bochs on what is causing it to crash, I couldn't figure it out, yet. Would be nice, if someone checked the code.

Greeting,
Farok

[1] https://github.com/farok/Carbon
https://github.com/qero/Hydrogen (Loader for AMD64 kernels running on top of GRUB2)
Nable
Member
Member
Posts: 453
Joined: Tue Nov 08, 2011 11:35 am

Re: Qemu crashes when enabling paging

Post by Nable »

Code: Select all

  mov eax, cr0 ; Enable paging
  or eax, 1 << 31
  mov cr0, eax
I've never seen (and afaik it's not possible) when anybody enables paging w/o protected mode.
So, you should set both 0 and 31 bits (CR0.PE and CR0.PG) at the same time.

Also, why do you use so much calls? Why don't you keep you code simple? I don't know how is it nowadays but several years ago KolibriOS kernel code was (ok, many parts of the code) a good example of IA-32 assembly code. Ok, you use long mode, then it's better to look at the x86_64 linux kernel bootloader. AT&T mnemonics can lead (as for me) to eyes bleeding but the code is very concise, it won't take much time to understand.
Qeroq
Member
Member
Posts: 52
Joined: Wed Aug 25, 2010 6:35 am
Location: Bonn, Germany

Re: Qemu crashes when enabling paging

Post by Qeroq »

Its booted using multiboot directly into protected mode, which requires CR0.PE to be set; as I take the value of CR0, OR with CR0.PG and write it back again, CR0.PE remains set.

I actually find it much clearer when using the calls like this, having the details out of my sight, but that's how I think of it.

Edit: More extensive google studies gave the result that my probelm is an exact duplicate of http://forum.osdev.org/viewtopic.php?f=1&t=20439; choosing qemu-system-x86_64 over vanilla qemu did the thing #-o
https://github.com/qero/Hydrogen (Loader for AMD64 kernels running on top of GRUB2)
Post Reply