I can't jump to the protected mode.Where's the bug?
Posted: Mon Nov 05, 2012 11:02 am
Bochs showing a bug when I am jumping to the protected mode.
I use boot.asm to load head.bin like this:
and I debug boot.bin at 0x9000:0x100,that is really point to head.asm:
Here's segment.inc:
the problem came at the row jmp dword Selector_C:0 in head.asm, bochsdbg tell gate type 0 unsupported.
What's the bug in my code?
Thank you!!!!!
I use boot.asm to load head.bin like this:
Code: Select all
;boot.asm
BaseOfLoader equ 09000h
OffsetOfLoader equ 0100h
org 07c00h
;...
;...
jmp BaseOfLoader:OffsetOfLoader
Code: Select all
%include "segment.inc"
BaseOfLoader equ 09000h ;
BasePhyAddr equ BaseOfLoader*10h+0100h
;-----设置代码段、数据段描述符
LABEL_GDT: Descriptor 0, 0, 0 ; null gdt
LABEL_DESC_CR: Descriptor 0, 0fffffh, PST_C + F_D ; read-only code segment
LABEL_DESC_DRW: Descriptor 0, 0fffffh, PST_D_W + F_G + F_D ; writeable data segment
LABEL_DESC_VEDIO: Descriptor 0B8000h, 0fffffh, PST_D_W + F_G + F_D ; vedio segment
;set lgdt operand
GdtLen equ $ - LABEL_GDT
GdtPtr dw GdtLen - 1
dd BasePhyAddr + LABEL_GDT
;set segment seletor
Selector_C equ LABEL_DESC_CR-LABEL_GDT
Selector_D equ LABEL_DESC_DRW-LABEL_GDT
Selector_V equ LABEL_DESC_VEDIO-LABEL_GDT
START:
mov ax, 0B800h
mov gs, ax
mov ah, 0Fh
mov al, 'J'
mov bx, ax
mov [gs:((80 * 0 + 20) * 2)], bx
;-----Initialize hardware environment----
xor eax, eax
lgdt [GdtPtr]
cli
in al,0x92
or al,00000010b
out 0x92,al
xor eax, eax
mov eax, cr0
or eax, 1
mov cr0, eax
xor eax, eax
mov ax, cs
shl eax, 4
add eax, LABEL_PM_START
mov word [LABEL_DESC_CR + 2], ax
shr eax, 16
mov byte [LABEL_DESC_CR + 4], al
mov byte [LABEL_DESC_CR + 7], ah
jmp dword Selector_C:0
; jmp LABEL_PM_START:0
LABEL_PM_START:
mov ax, Selector_V
mov gs, ax
mov ah, 0Ch
mov al, 'M'
mov [gs:((80 * 7 + 40) * 2)], ax
jmp $
Code: Select all
;---G:Granularity
F_G equ 8000h ;Page size 4KB units
;---D/B:Default Operation Size (0=16-bit segment; 1=32-bit segment)
F_D equ 4000h ;32-bit segment
;---L:64-bit code segment(IA-32e mode only)
;---AVL:Available for use by system software(or reserved)
;---P:Segment present(always 1)
;---S:Descriptor type(0=system; 1=code or data)
;---Type:Segment type
;--------D:Data segment
;--------C:Code segment
;--------S:System descriptor
;--------E:Expand-down
;--------W:Write
;--------A:Accessed
;--------C:Conforming
;--------R:Read
PST_D equ 90h
PST_D_A equ 91h
PST_D_W equ 92h
PST_D_WA equ 93h
PST_D_E equ 94h
PST_D_EA equ 95h
PST_D_EW equ 96h
PST_D_EWA equ 97h
PST_C equ 98h
PST_C_A equ 99h
PST_C_R equ 9Ah
PST_C_RA equ 9Bh
PST_C_C equ 9Ch
PST_C_CA equ 9Dh
PST_C_CR equ 9Eh
PST_C_CRA equ 9Fh
PST_S_LDT equ 82h
PST_S_TaskGate equ 85h
PST_S_TSS equ 89h
PST_S_CallGate equ 8Ch
PST_S_IntGate equ 8Eh
PST_S_TrapGate equ 8Fh
F_DPL0 equ 00h
F_DPL1 equ 20h
F_DPL2 equ 40h
F_DPL3 equ 80h
;---Usage: Descriptor Base, Limit ,Attr
;---Base: dd
;---Limit: dd (lower 20 bytes available)
;---Attr: dw (lower 4 bits of higher byte are zero)
%macro Descriptor 3
dw %2 & 0FFFFh ;Limit(0-15)
dw %1 & 0FFFFh ;Base(0-15)
db (%1 >> 16) & 0FFh ;Base(16-23)
dw ((%2 >> 8) & 0F00h) | (%3 & 0F0FFh) ;Limit(16-19) + Attr
db (%1 >> 24) & 0FFh ;Base(24-31)
%endmacro
What's the bug in my code?
Thank you!!!!!