I'm still quite early in the development of my kernel. Which I wanted to build from the ground up and run in protected mode. After writing a bootloader succesfully enabling the A20 line and loading the kernel (both has been succesfully tested in bochs). I decided to move to the kernel as quickly as possible and make the kernel responsible for strting PM. After creating a GDT I decided to firt test whether this would work before moving on. As follows the GDT and kernel test code:
Code: Select all
GDT:
;####Null-Descriptor####
dw 0x0000
dw 0x0000
db 0x00
db 0x00
db 0x00
db 0x00
;####Code Ring 0####
dw 0xFFFF ;Limit
dw 0x0000 ;Base
db 0x00 ;Base
db 0x9A ;Present, Code|Execute/Read
db 0xCF ;Granu,32bits|Limit
db 0x00 ;Base
;####Data Ring 0####
dw 0xFFFF ;Limit
dw 0x0000 ;Base
db 0x00 ;Base
db 0x92 ;Present, Data|R/W E-up
db 0xCF ;Granu,32bits|Limit
db 0x00 ;Base
;####Code Ring 3####
dw 0xFFFF ;Limit
dw 0x0000 ;Base
db 0x00 ;Base
db 0xFA ;Present, Code|Execute/Read
db 0xCF ;Granu,32bits|Limit
db 0x00 ;Base
;####Data Ring 3####
dw 0xFFFF ;Limit
dw 0x0000 ;Base
db 0x00 ;Base
db 0xF2 ;Present, Data|R/W E-up
db 0xCF ;Granu,32bits|Limit
db 0x00 ;Base
;####Task State Segment####
dw 103 ;Limit
dw 0 ;Base
db 0 ;Base
db 0x89 ;Ring 0, Present, Non-Busy
db 0x00 ;BS
db 0xC0 ;Base
GDTEND:
Code: Select all
[ORG 0x00020000]
[BITS 16]
main:
mov ax,0xB800
mov es,ax
mov byte[es:0],'b'
cli
xor ax,ax
mov ds,ax
lgdt [GDTDESC]
mov eax,cr0
or eax,1
mov cr0,eax
jmp 0x08:enter_pmode
[BITS 32]
enter_pmode:
mov ax, 0x08
mov cs, ax
mov ax, 0x10
mov ds, ax
mov ss, ax
mov esp,0x90000
.print_char:
mov byte[ds:0x0B8002],'a'
mov byte[ds:0x0B8003],0x7F
.hang:
jmp .hang
%include "d:\vinitech\mik\gdt006.asm"
GDTDESC:
dw (GDTEND - GDT - 1)
dd GDT