Protected Mode Question
Posted: Wed Aug 14, 2002 11:24 am
Does the CS and other segment registers have to be set up before you enter pmode or can it be after entering pmode?
example:
cli
lgdt [gdt_ptr]
mov ax,LINEAR_DATA_SEL ; I'm talking about this
mov ds,ax
mov es,ax
mov ss,ax
mov fs,ax
mov gs,ax ; here!
mov eax,cr0
or eax,0x1
mov cro,eax
jmp LINEAR_CODE_SEL: gdt_done
[bits 32]
[gdt_done:
; now in pmode
gdt: ; our descriptors
; NULL descriptor
dw 0 ; limit 15:0
dw 0 ; base 15:0
db 0 ; base 23:16
db 0 ; type
db 0 ; limit 19:16, flags
db 0 ; base 31:24
; unused descriptor
dw 0
dw 0
db 0
db 0
db 0
db 0
; data segment descriptor
LINEAR_DATA_SEL equ $-gdt
dw 0FFFFh ; limit 0xFFFF (1 meg, 4 gig)
dw 0 ; base for this ine is always 0
db 0
db 92h ; present, ring 0, data, expand-up, writable
db 0CFh ; page-granular (4 gig limit), 32-bit
db 0
; code segment descriptor
LINEAR_CODE_SEL equ $-gdt
dw 0FFFFh
dw 0 ; base gets set above
db 0
db 9Ah ; present,ring 0,code,non-conforming,readable
db 0CFh ; page-granular (4 gig limit), 32-bit
db 0
gdt_end:
gdt_ptr:
dw gdt_end - gdt - 1 ; GDT limit
dd gdt ; linear, physical address of GDT
example:
cli
lgdt [gdt_ptr]
mov ax,LINEAR_DATA_SEL ; I'm talking about this
mov ds,ax
mov es,ax
mov ss,ax
mov fs,ax
mov gs,ax ; here!
mov eax,cr0
or eax,0x1
mov cro,eax
jmp LINEAR_CODE_SEL: gdt_done
[bits 32]
[gdt_done:
; now in pmode
gdt: ; our descriptors
; NULL descriptor
dw 0 ; limit 15:0
dw 0 ; base 15:0
db 0 ; base 23:16
db 0 ; type
db 0 ; limit 19:16, flags
db 0 ; base 31:24
; unused descriptor
dw 0
dw 0
db 0
db 0
db 0
db 0
; data segment descriptor
LINEAR_DATA_SEL equ $-gdt
dw 0FFFFh ; limit 0xFFFF (1 meg, 4 gig)
dw 0 ; base for this ine is always 0
db 0
db 92h ; present, ring 0, data, expand-up, writable
db 0CFh ; page-granular (4 gig limit), 32-bit
db 0
; code segment descriptor
LINEAR_CODE_SEL equ $-gdt
dw 0FFFFh
dw 0 ; base gets set above
db 0
db 9Ah ; present,ring 0,code,non-conforming,readable
db 0CFh ; page-granular (4 gig limit), 32-bit
db 0
gdt_end:
gdt_ptr:
dw gdt_end - gdt - 1 ; GDT limit
dd gdt ; linear, physical address of GDT