gdt and pmode problem
Posted: Tue Mar 23, 2010 11:36 am
hi
i have a problem while installing gdt and in far jmp to set cs.
i think my first problem is gdt install: this is my code
Stage2
gdt.inc
i have tried bootldr with bochs.
first of all i'd like to know why setting segment at begin of stage2 it doesn't continue to execute the remaining code (i loaded stage2 to 0x500, but setting segments to 0x50, it does nothing. without set segments, it works normally)
about gdt i think there's an addressing problem with gdt code because trying to put gdt code directly in stage2 code, i get this from bochs:
instead, putting gdt code to gdt.inc and including it in stage2
i get this:
i think that when it tries to jmp to this segment, why gdt is not loaded, it triple faults...
thanks
i have a problem while installing gdt and in far jmp to set cs.
i think my first problem is gdt install: this is my code
Stage2
Code: Select all
org 0x500 ; loaded to first real mode unused address
bits 16
jmp main
;*******************************************
; Global Description Table (GDT) Predef
;*******************************************
gdt_data_begin:
; first null desc
dd 0x0
dd 0x0
; Code Descriptor
dw 0xffff
dw 0x0
db 0x0
db 10011010b ; access byte
db 11001111b ; granularity byte
db 0x0
; Data Descriptor
dw 0xffff
dw 0x0
db 0x0
db 10010010b ; access byte
db 11001111b ; granularity byte
db 0x0
gdt_data_end:
lgdt_param:
dw gdt_data_end - gdt_data_begin - 1 ; gdt limit
dd gdt_data_begin ; first descriptor addr
%include "includes\stdio.inc"
%include "includes\gdt.inc"
welcome.msg db 13,10,"Preparing to load operating system ...",13,10,0
main:
cli
;mov ax, 0x050
;mov ds, ax
;mov es, ax
;mov fs, ax
;mov gs, ax
;;
; setting stack
mov ax, 0x9000
mov ss, ax
mov sp, 0xffff
sti
mov si, welcome.msg
call puts16
call InstallGDT ; installing descriptors table
cli
;hlt
mov eax, cr0
or eax, 1
mov cr0, eax ; PMODE
jmp 8h:Stage3 ;0x700 i have tried to far jmp directly to 0x700, without label and it didnt work ; jmp to fix cs
times 512 - ($-$$)
;***********************************************
; Stage3
;***********************************************
bits 32 ; protected mode
Stage3:
mov ax, 0x10 ; data descriptor
mov ds, ax
mov es, ax
mov ss, ax
mov esp, 0x90000 ; stack pointer 0x90000 to 0xFFFFF
hlt
Code: Select all
bits 16
InstallGDT:
pusha
cli
lgdt [lgdt_param] ; loading gdt
sti
popa
ret
first of all i'd like to know why setting segment at begin of stage2 it doesn't continue to execute the remaining code (i loaded stage2 to 0x500, but setting segments to 0x50, it does nothing. without set segments, it works normally)
about gdt i think there's an addressing problem with gdt code because trying to put gdt code directly in stage2 code, i get this from bochs:
Code: Select all
00015692314e[CPU0 ] check_cs(0x0008): not a valid code segment !
00015692314e[CPU0 ] interrupt(): gate descriptor is not valid sys seg (vector=0x0d)
00015692314e[CPU0 ] interrupt(): gate descriptor is not valid sys seg (vector=0x08)
and after
00015692314i[CPU0 ] 0x0000000000008195>> jmp far 0008:0700 : EA00070800
00015692314e[CPU0 ] exception(): 3rd (13) exception with no resolution, shutdown status is 00h, resetting
Code: Select all
bits 16
%ifndef
%define __GDT_INC_
;*******************************************
; InstallGDT ()
;*******************************************
InstallGDT:
pusha
cli
lgdt [lgdt_param] ; loading gdt
sti
popa
ret
;*******************************************
; Global Description Table (GDT) Predef
;*******************************************
; null desc
gdt_data_begin:
dd 0x0
dd 0x0
; Code Descriptor
dw 0xffff
dw 0x0
db 0x0
db 10011010b ; access byte
db 11001111b
db 0x0
; Data Descriptor
dw 0xffff
dw 0x0
db 0x0
db 10010010b ; access byte
db 11001111b ; granularity byte
db 0x0
gdt_data_end:
; Parametro per LGDT, una word con la dimensione del gdt e il gdt
lgdt_param:
dw gdt_data_end - gdt_data_begin - 1 ; gdt limit
dd gdt_data_begin ; first descriptor addr
%endif
Code: Select all
00015645378e[CPU0 ] jump_protected: gate type 0 unsupported
00015645378e[CPU0 ] interrupt(): gate descriptor is not valid sys seg (vector=0x0d)
00015645378e[CPU0 ] interrupt(): gate descriptor is not valid sys seg (vector=0x08)
and after
00015645378i[CPU0 ] 0x000000000000819d>> jmp far 0008:05a2 : EAA2050800
00015645378e[CPU0 ] exception(): 3rd (13) exception with no resolution, shutdown status is 00h, resetting
thanks