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). I have almost the exact same code, but mine dosn?t work! My code looks like this:
-----------------------------------
Code:
Code: Select all
;..........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 [ds:0xB8000], 'P'
mov byte [ds:0xB8001], 1Bh ; Assign a color code
mov byte [ds:0xB8002], 'm'
mov byte [ds:0xB8003], 1Bh ; Assign a color code
mov byte [ds:0xB8004], 'o'
mov byte [ds:0xB8005], 1Bh ; Assign a color code
mov byte [ds:0xB8006], 'd'
mov byte [ds:0xB8007], 1Bh ; Assign a color code
mov byte [ds: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
;*************************************************************************
I have tested all sorts of things, but i just can?t get it to work. It seems that it need that [ORG 07c00] to work correctly...
Sorry for this big posting...
Thanks in advance
/ Christoffer