Problems with PMode

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
Vladaz

Problems with PMode

Post 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?
Vladaz

Re:Problems with PMode

Post by Vladaz »

boot.asm
Curufir

Re:Problems with PMode

Post 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.

Code: Select all

   jmp 0:0x8000
You have something totally confused here, I'm not surprised Bochs doesn't like it.
Vladaz

Re:Problems with PMode

Post 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? ???
oswizard

Re:Problems with PMode

Post 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
Vladaz

Re:Problems with PMode

Post by Vladaz »

It still reboots, even when I changed it :-[
oswizard

Re:Problems with PMode

Post by oswizard »

In boot.asm:

Code: Select all

gdtr:
   dw gdt_end-gdt
   dd gdt
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
oswizard

Re:Problems with PMode

Post 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.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re:Problems with PMode

Post 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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Post Reply