Page 1 of 1
Switching to protected mode - pointer GDT not working
Posted: Wed Jun 29, 2011 10:54 am
by ThatGuy2244
My pointer to my GDT for switching to 32 - bit protected mode seems to not be working, I have isolated the problem to be:
Code: Select all
mov eax, 0
mov ax, ds
shl eax, 4
add eax, GDTStart
This is that part of my code that translates the segment:offset of my DOUBLE WORD pointer to my GDT structure into a linear address, but I can't find out whats wrong with it. Just in case it helps here is the rest of my GDT stuff:
Code: Select all
cli
mov eax, 0
mov ax, ds
shl eax, 4
add eax, GDTStart
mov [GDTInfo + 2], eax
lgdt [GDTInfo]
mov eax, cr0
or eax, 1
mov cr0, eax
mov ax, 0x10
mov ds, ax
mov ss, ax
mov es, ax
mov fs, ax
mov gs, ax
jmp 0x08:pmode
GDTInfo:
dw GDTEnd - GDTStart - 1
dd GDTStart
GDTStart:
dd 0x00000000 ;Descriptor 0 Null
dd 0x00000000
dw 0xffff ;Descriptor 1 Code
dw 0x0000
db 0x00
db 10011010b
db 11001111b
db 0x00
dw 0xffff ;Descriptor 2 Data
dw 0x0000
db 0x00
db 10010010b
db 11001111b
db 0x00
GDTEnd:
Re: Switching to protected mode - pointer GDT not working
Posted: Thu Jun 30, 2011 4:52 am
by thepowersgang
Is that the correct address? What is the value of DS at runtime, and what is the value of GDTStart?
Re: Switching to protected mode - pointer GDT not working
Posted: Thu Jun 30, 2011 7:42 am
by ThatGuy2244
thepowersgang wrote:Is that the correct address? What is the value of DS at runtime, and what is the value of GDTStart?
Yes I do know the value of DS at run time that's why I move ds into ax and the value of GDTStart does not matter I don't think as long as it is referenced correctly in 32-bit linear format.
Re: Switching to protected mode - pointer GDT not working
Posted: Thu Jun 30, 2011 4:48 pm
by ThatGuy2244
I don't know what you mean by hard facts, but if you mean the actual address number that the GDT is located, then I don't know that, but that should not matter because all my code is relative to my GDT and not based on static address. What I can tell you is that this file is a .COM file and is loaded by DOS to location 0x100 and before you think this is the solution to my problem earlier in my program I have "[org 0x100]" which automatically offsets all my addresses by 0x100 (in nasm).
Re: Switching to protected mode - pointer GDT not working
Posted: Thu Jun 30, 2011 5:15 pm
by bluemoon
ThatGuy2244 wrote:My pointer to my GDT for switching to 32 - bit protected mode seems to not be working
So what's the exact error? have you tried single stepping into the code to see how far it go, and perhaps dump register values?
GDB is your friend.
Re: Switching to protected mode - pointer GDT not working
Posted: Fri Jul 01, 2011 8:09 am
by Gigasoft
The GDT pointer looks fine to me, however, your segments both start at address 0, instead of the PSP address.
(By the way: you can use mov eax,ds, this automatically zero extends it.)
Re: Switching to protected mode - pointer GDT not working
Posted: Fri Jul 01, 2011 8:14 am
by Combuster
In other words:
jumps to somewhere in the IVT, and not where your program is loaded
Re: Switching to protected mode - pointer GDT not working
Posted: Fri Jul 01, 2011 8:45 am
by Chandra
Looks like OP needs PIC tips.
Re: Switching to protected mode - pointer GDT not working
Posted: Fri Jul 01, 2011 9:03 am
by ThatGuy2244
bluemoon wrote:ThatGuy2244 wrote:My pointer to my GDT for switching to 32 - bit protected mode seems to not be working
So what's the exact error? have you tried single stepping into the code to see how far it go, and perhaps dump register values?
GDB is your friend.
The exact error is "Illegal Descriptor type 0 for int 0" -- Note that this is an error given by the emulator (DOSBOX) and not the assembler.
Combuster wrote:In other words:
jumps to somewhere in the IVT, and not where your program is loaded
If I understand you correctly then you are implying that I have to convert the pmode pointer into a linear address (assuming that it is a seg:offset). I don't think I would have to do this because my pmode pointer is written for 32 bit code - meaning that it would be a linear address already.
Re: Switching to protected mode - pointer GDT not working
Posted: Fri Jul 01, 2011 9:11 am
by Combuster
I don't think I would have to do this because my pmode pointer is written for 32 bit code - meaning that it would be a linear address already.
You really haven't understood the point of your
previous thread haven't you? (And btw, why create a new one for the exact same problem)
Homework:
what is a virtual address?
what is a linear address?
what is a physical address?
How does the assembler know which of the three you want?
Why is "loaded to location 0x100" an insufficient remark?
Re: Switching to protected mode - pointer GDT not working
Posted: Fri Jul 01, 2011 11:49 am
by ThatGuy2244
I realize that 32 bit pointer are not linear, but do point in this case in a linear way since all my descriptors start at physical address 0.
Re: Switching to protected mode - pointer GDT not working
Posted: Fri Jul 01, 2011 12:05 pm
by Gigasoft
But the labels aren't relative to address 0, but to the old CS << 4. The assembler does not know the physical address where the file will be loaded. Your descriptors have to start at CS << 4, or else you have to add this every time you reference a label.
Re: Switching to protected mode - pointer GDT not working
Posted: Fri Jul 01, 2011 2:23 pm
by Combuster
ThatGuy2244 wrote:all my descriptors start at physical address 0.
They don't, not by far. What's the value of CS on line 1?
EDIT: and since you couldn't be bothered to do my first set of homework properly, here's more. I won't help you further with this problem until you at least attempted the entire sequence:
what's the value of CS on line 1 of your code? (use a debugger or print it to the screen)
what's the segment base of CS on line 1?
what is the IP on line 1?
calculate the linear address of the code on line 1. What is it?
how many bytes are the jump and the start of the code apart from another?
what is the value of cs after the jump?
what is the value of ip after the jump?
what is the segment base of cs after the jump?
calculate the linear address of the code jumped to. What is it?
How far is this place from the linear address at the start of your code?
Is this right? what have you learned?
Re: Switching to protected mode - pointer GDT not working
Posted: Fri Jul 01, 2011 7:39 pm
by bluemoon
ThatGuy2244 wrote:Combuster wrote:In other words:
jumps to somewhere in the IVT, and not where your program is loaded
If I understand you correctly then you are implying that I have to convert the pmode pointer into a linear address (assuming that it is a seg:offset). I don't think I would have to do this because my pmode pointer is written for 32 bit code - meaning that it would be a linear address already.
What's the point of asking question if you don't think other has point you to the issue?
The label pmode has the value of ORG + offset from beginning of code, in you .COM program and few lines of code it's probably has address lower than 1024, while the actual memory location is obviously different.