Protected mode + error (general protection error?) nr 13
Posted: Sat Feb 07, 2004 12:00 am
Hello!
I have tried to set Pmode in my kernel loader, 'loader.sys'.
Bochs says something about CPU panic nr 13 (general protection error?).
The code i based it on works just fine (but it´s from a bootsector), it looks like this:
-----------------------------------
[BITS 16] ; We need 16-bit intructions for Real mode
[ORG 0x7C00] ; The BIOS loads the boot sector into memory location 0x7C00
cli ; Disable interrupts, we want to be alone
xor ax, ax
mov ds, ax ; Set DS-register to 0 - used by lgdt
lgdt [gdt_desc] ; Load the GDT descriptor
mov eax, cr0 ; Copy the contents of CR0 into EAX
or eax, 1 ; Set bit 0
mov cr0, eax ; Copy the contents of EAX into CR0
jmp 08h:clear_pipe ; Jump to code segment, offset clear_pipe
[BITS 32] ; We now need 32-bit instructions
clear_pipe:
mov ax, 10h ; Save data segment identifyer
mov ds, ax ; Move a valid data segment into the data segment register
mov ss, ax ; Move a valid data segment into the stack segment register
mov esp, 090000h ; Move the stack pointer to 090000h
mov byte [ds:0B8000h], 'P' ; Move the ASCII-code of 'P' into first video memory
mov byte [ds:0B8001h], 1Bh ; Assign a color code
hang:
jmp hang ; Loop, self-jump
gdt: ; Address for the GDT
gdt_null: ; Null Segment
dd 0
dd 0
gdt_code: ; Code segment, read/execute, nonconforming
dw 0FFFFh
dw 0
db 0
db 10011010b
db 11001111b
db 0
gdt_data: ; Data segment, read/write, expand down
dw 0FFFFh
dw 0
db 0
db 10010010b
db 11001111b
db 0
gdt_end: ; Used to calculate the size of the GDT
gdt_desc: ; The GDT descriptor
dw gdt_end - gdt - 1 ; Limit (size)
dd gdt ; Address of the GDT
times 510-($-$$) db 0 ; Fill up the file with zeros
dw 0AA55h ; Boot sector identifyer
-----------------------------------
I have almost the exact same code, but mine dosn´t work! My code looks like this:
-----------------------------------
;..........here i set the A20-gate and lots of other stuff....
; Code to enter Protected Mode.
;-------------------------------
mov si, msgSetPmode ; Print
call DisplayMessage ; message.
cli ; Disable interrupts, we want to be alone
xor ax, ax
mov ds, ax ; Set DS-register to 0 - used by lgdt
lgdt [gdt_desc] ; Load the GDT descriptor
mov eax, cr0 ; Copy the contents of CR0 into EAX
or eax, 1 ; Set bit 0
mov cr0, eax ; Copy the contents of EAX into CR0
jmp CODE_SEL:start32 ; Jump to code segment, offset 32start
;*************************************************************************
[BITS 32]
start32:
; Fix segments.
;---------------
mov ax, DATA_SEL ; Save data segment identifyer
mov ds, ax ; Move a valid data segment into the data segment register
mov ss, ax ; Move a valid data segment into the stack segment register
mov esp, 090000h ; Move the stack pointer to 090000h
; Load 'kernel.sys' from the FAT12 floppy and go to it.
; (Right now i will just print 'Pmode' and hang.)
;-------------------------------------------------------
; Write a 'Pmode' at upper left corner.
;---------------------------------------
mov byte [gs:0xB8000], 'P'
mov byte [ds:0xB8001], 1Bh ; Assign a color code
mov byte [gs:0xB8002], 'm'
mov byte [ds:0xB8003], 1Bh ; Assign a color code
mov byte [gs:0xB8004], 'o'
mov byte [ds:0xB8005], 1Bh ; Assign a color code
mov byte [gs:0xB8006], 'd'
mov byte [ds:0xB8007], 1Bh ; Assign a color code
mov byte [gs:0xB8008], 'e'
mov byte [ds:0xB8009], 1Bh ; Assign a color code
; Hang.
;-------
hang:
jmp hang ; Loop, self-jump
; Global Descriptor Table (GDT).
;---------------------------------
gdt: ; Address for the GDT
gdt_null: ; Null Segment
dd 0
dd 0
CODE_SEL equ $-gdt
gdt_code: ; Code segment, read/execute, nonconforming
dw 0FFFFh
dw 0
db 0
db 10011010b
db 11001111b
db 0
DATA_SEL equ $-gdt
gdt_data: ; Data segment, read/write, expand down
dw 0FFFFh
dw 0
db 0
db 10010010b
db 11001111b
db 0
gdt_end: ; Used to calculate the size of the GDT
gdt_desc: ; The GDT descriptor
dw gdt_end - gdt - 1 ; Limit (size)
dd gdt ; Address of the GDT
;*************************************************************************
-------------------------------
So as you can see, it is almost the same.. I have tested al sorts of things, but i just can´t get it to work.
Sorry for this big posting...
Thanks in advance
/ Christoffer
I have tried to set Pmode in my kernel loader, 'loader.sys'.
Bochs says something about CPU panic nr 13 (general protection error?).
The code i based it on works just fine (but it´s from a bootsector), it looks like this:
-----------------------------------
[BITS 16] ; We need 16-bit intructions for Real mode
[ORG 0x7C00] ; The BIOS loads the boot sector into memory location 0x7C00
cli ; Disable interrupts, we want to be alone
xor ax, ax
mov ds, ax ; Set DS-register to 0 - used by lgdt
lgdt [gdt_desc] ; Load the GDT descriptor
mov eax, cr0 ; Copy the contents of CR0 into EAX
or eax, 1 ; Set bit 0
mov cr0, eax ; Copy the contents of EAX into CR0
jmp 08h:clear_pipe ; Jump to code segment, offset clear_pipe
[BITS 32] ; We now need 32-bit instructions
clear_pipe:
mov ax, 10h ; Save data segment identifyer
mov ds, ax ; Move a valid data segment into the data segment register
mov ss, ax ; Move a valid data segment into the stack segment register
mov esp, 090000h ; Move the stack pointer to 090000h
mov byte [ds:0B8000h], 'P' ; Move the ASCII-code of 'P' into first video memory
mov byte [ds:0B8001h], 1Bh ; Assign a color code
hang:
jmp hang ; Loop, self-jump
gdt: ; Address for the GDT
gdt_null: ; Null Segment
dd 0
dd 0
gdt_code: ; Code segment, read/execute, nonconforming
dw 0FFFFh
dw 0
db 0
db 10011010b
db 11001111b
db 0
gdt_data: ; Data segment, read/write, expand down
dw 0FFFFh
dw 0
db 0
db 10010010b
db 11001111b
db 0
gdt_end: ; Used to calculate the size of the GDT
gdt_desc: ; The GDT descriptor
dw gdt_end - gdt - 1 ; Limit (size)
dd gdt ; Address of the GDT
times 510-($-$$) db 0 ; Fill up the file with zeros
dw 0AA55h ; Boot sector identifyer
-----------------------------------
I have almost the exact same code, but mine dosn´t work! My code looks like this:
-----------------------------------
;..........here i set the A20-gate and lots of other stuff....
; Code to enter Protected Mode.
;-------------------------------
mov si, msgSetPmode ; Print
call DisplayMessage ; message.
cli ; Disable interrupts, we want to be alone
xor ax, ax
mov ds, ax ; Set DS-register to 0 - used by lgdt
lgdt [gdt_desc] ; Load the GDT descriptor
mov eax, cr0 ; Copy the contents of CR0 into EAX
or eax, 1 ; Set bit 0
mov cr0, eax ; Copy the contents of EAX into CR0
jmp CODE_SEL:start32 ; Jump to code segment, offset 32start
;*************************************************************************
[BITS 32]
start32:
; Fix segments.
;---------------
mov ax, DATA_SEL ; Save data segment identifyer
mov ds, ax ; Move a valid data segment into the data segment register
mov ss, ax ; Move a valid data segment into the stack segment register
mov esp, 090000h ; Move the stack pointer to 090000h
; Load 'kernel.sys' from the FAT12 floppy and go to it.
; (Right now i will just print 'Pmode' and hang.)
;-------------------------------------------------------
; Write a 'Pmode' at upper left corner.
;---------------------------------------
mov byte [gs:0xB8000], 'P'
mov byte [ds:0xB8001], 1Bh ; Assign a color code
mov byte [gs:0xB8002], 'm'
mov byte [ds:0xB8003], 1Bh ; Assign a color code
mov byte [gs:0xB8004], 'o'
mov byte [ds:0xB8005], 1Bh ; Assign a color code
mov byte [gs:0xB8006], 'd'
mov byte [ds:0xB8007], 1Bh ; Assign a color code
mov byte [gs:0xB8008], 'e'
mov byte [ds:0xB8009], 1Bh ; Assign a color code
; Hang.
;-------
hang:
jmp hang ; Loop, self-jump
; Global Descriptor Table (GDT).
;---------------------------------
gdt: ; Address for the GDT
gdt_null: ; Null Segment
dd 0
dd 0
CODE_SEL equ $-gdt
gdt_code: ; Code segment, read/execute, nonconforming
dw 0FFFFh
dw 0
db 0
db 10011010b
db 11001111b
db 0
DATA_SEL equ $-gdt
gdt_data: ; Data segment, read/write, expand down
dw 0FFFFh
dw 0
db 0
db 10010010b
db 11001111b
db 0
gdt_end: ; Used to calculate the size of the GDT
gdt_desc: ; The GDT descriptor
dw gdt_end - gdt - 1 ; Limit (size)
dd gdt ; Address of the GDT
;*************************************************************************
-------------------------------
So as you can see, it is almost the same.. I have tested al sorts of things, but i just can´t get it to work.
Sorry for this big posting...
Thanks in advance
/ Christoffer