Posted: Wed Jul 18, 2007 5:23 pm
Yet another problem
In the "kernel", I have defined my gdt as follows:
While I'm STILL in real mode, I copy the ds base address into the respective fields in gdt_data:
I did the same for the code segment...After turning on pm, I am able to jump to protected mode like this:
Where enter_32 simply looks like this:
This works well. Alas, it all starts to hang again as soon as I do something so trivial as this:
Is there anything wrong with how Im setting up the data segment descriptor?
In the "kernel", I have defined my gdt as follows:
Code: Select all
gdt:
gdt_null:
dd 0
dd 0
;(1)
gdt_code:
dw 0ffffh ;limit of the segment
cbase1: dw 0 ;base address of segment
cbase2: db 0 ;still belonging to base address of segment
db 10011010b ;1 for "segment is present"
;00 for "privilege 0"
;1 for "data or code segment"
;1 for "code segment"
;0 for "unconforming"
;1 for readable
;0 (access flag set by cpu on 1st access)
db 11001111b ;1 for page-granularity
;1 for 32 bit code segment
;0 (reserved bit)
;0 (available to system programmers)
;1111b for last bits of segment limit
db 0 ;last byte of base address
;(2)
gdt_data:
dw 0fffh ;limit of the segment
dbase1: dw 0 ;base address of segment
dbase2: db 0 ;still belonging to base address of segment
db 10010010b ;1 for "segment is present"
;00 for "privilege 0"
;1 for "data or code segment"
;0 for "data segment"
;0 for "expand downward"
;1 for writable
;0 (access flag set by cpu on 1st access)
db 11001111b ;1 for page-granularity
;1 for 32-bit stack pointer
;0 (reserved bit)
;0 (available to system programmers)
;1111b for last bits of segment limit
db 0 ;last byte of base address
Code: Select all
mov ax, ds
movzx eax, ax
shl eax, 4 ;eax now contains linear address of real mode ds
mov ebx, eax ;move the linear address
mov [dbase1], bx ;of the real mode ds
shr ebx, 16 ;into the base fields of
mov [dbase2], bl ;the 32-bit data segment in the gdt
Code: Select all
jmp 08h:enter_32 ;jump into 32-bit segment!
Code: Select all
enter_32:
jmp 018h:return_16 (where the 3rd descriptor in the gdt is a 16 bit pm segment
Code: Select all
enter_32:
mov [realdata], ds ;ds still contains RM data segment
mov ax, 010h ;copy the 32-bit data segment selector
mov [stacksegment_16], ss ;make a backup of the ss register
mov ds, ax ;into ds
mov ax, [realdata] ;undo what
mov ds, ax ;you just did
jmp 018h:return_16 (where the 3rd descriptor in the gdt is a 16 bit pm segment