Some computers reboots when enabling paging in long mode

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
kemosparc
Member
Member
Posts: 207
Joined: Tue Oct 29, 2013 1:13 pm

Some computers reboots when enabling paging in long mode

Post by kemosparc »

Hi,

I have written a small 64-bit kernel with my own custom 2 stages boot loader. I switch to protected mode and then to long mode.

I can boot with my kernel until loading ISRs as well as setting PIT timer and it works fine as designed on all emulation/virtualization environment: Bochs, QEMU/KVM, and Virtual Box.

I tried my OS from a USB boot on a couple of real physical hardware machines such as Lenovo Thinkpads T61P, W500, and W510 and they all worked fine.

When I try to boot with the same USB on Lenovo desktop tower machines (More than one model), the computer keeps on rebooting. I have put some halt statements and kept on incrementing them in the code until I found out that as soon as I enable paging with the following instructions it reboots:

Code: Select all

    mov eax, cr0
    or eax, 1 << 31
    mov cr0, eax
I looked at the forum and searched google and the only advice I got is to make sure that A20 is enabled. I did that by the following code

Code: Select all

mov ax, 0x2401
int 0x15

in al, 0x92
test al, 2
jnz after

or al, 2
and al, 0xFE
out 0x92, al
jmp done:

after:
    call print_a20_ok
done:
It prints the okay message which indicates that the A20 is enabled.

I cannot figure out the reason behind the problem and it is very difficult to debug on real hardware.

Please if anyone is familiar with that or has any clue what my problem can be or even how to tackle it, please let me know.

Thanks
Karim.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Some computers reboots when enabling paging in long mode

Post by Combuster »

Testing for a set bit in the Fast A20 register does not indicate that A20 is actually enabled - it typically means that Fast A20 isn't supported altogether. In other words: always probe the actual status of A20 instead of relying on averages. That said, a check for actual long mode support could reveal its own share of misconceptions.

On another note, a key difference between real hardware and emulated hardware is the state of RAM during boot - it is likely to contain garbage at startup, rather than zeroes which you might expect somewhere.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
kemosparc
Member
Member
Posts: 207
Joined: Tue Oct 29, 2013 1:13 pm

Re: Some computers reboots when enabling paging in long mode

Post by kemosparc »

Hi,

Can you please direct me on how to "actually probe the status on A20" ?

For the RAM comment, do I need to fill in zeros in all memory I identity map?

Thanks
Karim
kemosparc
Member
Member
Posts: 207
Joined: Tue Oct 29, 2013 1:13 pm

Re: Some computers reboots when enabling paging in long mode

Post by kemosparc »

Hi Combuster,

Your second comment was the lead to my solution.

Basically, I identity tab 4 GB, and I only nullified the first 16 KiB, the rest of the pages tables were not nullified before setting it up.

When, I did that it worked.

I will try it on other desktops tomorrow when I have access to machines.

Thanks for the comment.
Karim.
kemosparc
Member
Member
Posts: 207
Joined: Tue Oct 29, 2013 1:13 pm

[UPDATE]Some computers reboots when enabling paging in long

Post by kemosparc »

Hi,

Although the modifications I did fixed the problem with some computers, yet I have discovered that all i-core7 computers does not boot and still have the problem!!!

Any suggection or help please ?

Thanks
Karim.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Some computers reboots when enabling paging in long mode

Post by Combuster »

There's a classic debugging trick for this one: exaggerate the problem.

Have your bootloader fill up all the ram with garbage (typically, 0xcc's) before loading anything, then see if you can reproduce the problem on an emulator where you can get proper dumps on anything.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
kemosparc
Member
Member
Posts: 207
Joined: Tue Oct 29, 2013 1:13 pm

Re: Some computers reboots when enabling paging in long mode

Post by kemosparc »

I think that the problem has ro do with UFEI boot !!

Anything I should consider regarding that ??

Thanks
Karim.
Post Reply