Page 1 of 1
Problems with PMode
Posted: Wed Sep 15, 2004 1:06 pm
by Vladaz
Hello. I have PMode problem again. I started new brand OS project and something don't work. I attached my source code of my bootloader. When i emulate it with bochs, it writes me an error:
Bochs is exiting with the following message:
[CPU ] jump_protected: cs == 0
Can you help me? Can you tell me what i need to correct in my code?
Re:Problems with PMode
Posted: Wed Sep 15, 2004 1:41 pm
by Vladaz
boot.asm
Re:Problems with PMode
Posted: Wed Sep 15, 2004 7:36 pm
by Curufir
First you switch to Pmode
Code: Select all
mov eax, cr0
or eax, 1
mov cr0, eax
jmp code_selector:flush_pipe
Then you immediately try to load CS with the NULL selector.
You have something totally confused here, I'm not surprised Bochs doesn't like it.
Re:Problems with PMode
Posted: Tue Sep 21, 2004 1:04 pm
by Vladaz
Now i written my simple kernel that just shoud write a letter on the screen, but it does not do that. It just reboots.
There is my boot and kernel:
http://avnet.sytes.net/~vladas/boot.asm
http://avnet.sytes.net/~vladas/kernel.asm
can someone help me, please? ???
Re:Problems with PMode
Posted: Tue Sep 21, 2004 5:37 pm
by oswizard
In boot.asm:
Code: Select all
SectorLoader:
xor bx, bx
mov es, bx
mov bx, 0x8000
and
Code: Select all
flush_pipe:
jmp code_selector:0x80000
In the first, you are loading the kernel to 0000:8000 (0x00008000) and in pmode you are jumping to 0x000800000. Big difference!
Overall it looks pretty good. Everything else seems fine.
Good luck
Re:Problems with PMode
Posted: Thu Sep 23, 2004 12:09 pm
by Vladaz
It still reboots, even when I changed it :-[
Re:Problems with PMode
Posted: Thu Sep 23, 2004 8:49 pm
by oswizard
In boot.asm:
For the GDT, the limit must be gdt_end-gdt-1. It doesn't make too much sense, except that this allows a GDT with length 0xFFFF, really meaning 0x10000, but small enough to fit within a 16-bit word. I don't know if this would be enough to cause a reboot, though.
Good Luck
Re:Problems with PMode
Posted: Thu Sep 23, 2004 9:58 pm
by oswizard
From the NASM manual:
For example, the following code will generate the longword 0x00000104:
org 0x100
dd label
label:
Here the assembler will decide that the label "gdtr" is equal to ORG + offset, or 0x7C??. Because you set DS to 0 the instruction "lgdt [gdtr]" will try to load from DS base + offset, or 0x00?? (which is definately not where it should be).
Umm... if "gdtr" is equal to ORG+offset, wouldn't "lgdt [gdtr]" load from DS:ORG+offset, or 0000:7C00+offset? The bootloader I wrote has "org 0" with a CS and DS of 0x07C0, so a bootloader with CS and DS equal to 0x0000, the ORG would have to be 0x7C00.
Re:Problems with PMode
Posted: Fri Sep 24, 2004 9:17 pm
by Brendan
Hi,
Mike wrote:
Umm... if "gdtr" is equal to ORG+offset, wouldn't "lgdt [gdtr]" load from DS:ORG+offset, or 0000:7C00+offset? The bootloader I wrote has "org 0" with a CS and DS of 0x07C0, so a bootloader with CS and DS equal to 0x0000, the ORG would have to be 0x7C00.
Ooops - you're right. I made the mistake that I thought Vladaz was making, and messed everything up. There was no problem with the boot code, and my examples are wrong too :'(.
I should be more careful - thanks for noticing my mistake. I'll edit my last post so no-one tries to use it..
Cheers,
Brendan