diff --git a/kernel/boot.asm b/kernel/boot.asm index ab54ac6..429e47e 100644 --- a/kernel/boot.asm +++ b/kernel/boot.asm @@ -89,10 +89,7 @@ segmented_start: mov ecx, _rm_params ; put real mode params here (video mode etc...) sub ecx, VIRT_OFFSET - mov eax, cr0 - and eax, 0x7FFFFFFE ; leave PM - mov cr0, eax - jmp 0x0:0x5010 ; jump to rmmod + jmp 0xC0005010 ; jump to rmmod ;Next we enable paging with the first 4mb mapped 1:1 virtual:physical ; and with the 4mb starting at 0xC000_0000 mapped to the first 4mb physical. @@ -191,12 +188,12 @@ idle_loop: ; system idle loop gdtrbs32: dw gdt_endbs32-gdtbs32-1 dd gdtbs32-VIRT_OFFSET -gdtbs32: ;null descriptor +gdtbs32: ; 0 = null descriptor dd 0 dd 0 ;a base of 0x4000_0000, when added to 0xC000_0000 will produce 0x0000_0000 physical before paging in effect -KERNEL_CODE_BS32 equ $-gdtbs32 +KERNEL_CODE_BS32 equ $-gdtbs32 ; 8 db 0xff ;limit 7:0 db 0xff ;limit 15:8 db 0x00 ;base 7:0 @@ -206,7 +203,7 @@ KERNEL_CODE_BS32 equ $-gdtbs32 db 0xcf ;flags / limit 19:16 db 0x40 ;base 31:24 -KERNEL_DATA_BS32 equ $-gdtbs32 +KERNEL_DATA_BS32 equ $-gdtbs32 ; 16 db 0xff ;limit 7:0 db 0xff ;limit 15:8 db 0x00 ;base 7:0 @@ -216,6 +213,22 @@ KERNEL_DATA_BS32 equ $-gdtbs32 db 0xcf ;flags / limit 19:16 db 0x40 ;base 31:24 +KERNEL_CODE_BS6_ equ $-gdtbs32 ; 24 + dw 0xffff ;limit 15:0 + dw 0x0000 ;base 15:0 + db 0x00 ;base 23:16 + db 0x9A ;access ([P][DPL][1][Executable][Direction/Conforming][Writable/Readable][A]) + db 0x00 ;flags ([G][D/B][0][0]) / limit 19:16 + db 0x00 ;base 31:24 + +KERNEL_DATA_BS16 equ $-gdtbs32 ; 32 + dw 0xffff ;limit 15:0 + dw 0x0000 ;base 15:0 + db 0x00 ;base 23:16 + db 0x92 ;access ([P][DPL][1][Executable][Direction/Conforming][Writable/Readable][A]) + db 0x00 ;flags ([G][D/B][0][0]) / limit 19:16 + db 0x00 ;base 31:24 + gdt_endbs32: %include "gdt.inc" diff --git a/kernel/gdt.inc b/kernel/gdt.inc index 43524c3..1509092 100644 --- a/kernel/gdt.inc +++ b/kernel/gdt.inc @@ -6,11 +6,11 @@ gdtr: dw gdt_end-gdt-1 dd GDT_V -gdt: +gdt: ; 0 dd 0 dd 0 -KERNEL_CODE equ $-gdt +KERNEL_CODE equ $-gdt ; 8 dw 0xffff ;limit 15:0 dw 0x0000 ;base 15:0 db 0x00 ;base 23:16 @@ -18,7 +18,7 @@ KERNEL_CODE equ $-gdt db 0xCF ;flags ([G][D/B][0][0]) / limit 19:16 db 0x00 ;base 31:24 -KERNEL_DATA equ $-gdt +KERNEL_DATA equ $-gdt ; 16 dw 0xffff ;limit 15:0 dw 0x0000 ;base 15:0 db 0x00 ;base 23:16 @@ -27,7 +27,7 @@ KERNEL_DATA equ $-gdt db 0x00 ;base 31:24 -USER_CODE equ $-gdt +USER_CODE equ $-gdt ; 24 dw 0xffff ;limit 15:0 dw 0x0000 ;base 15:0 db 0x00 ;base 23:16 @@ -35,7 +35,7 @@ USER_CODE equ $-gdt db 0xCF ;flags ([G][D/B][0][0]) / limit 19:16 db 0x00 ;base 31:24 -USER_DATA equ $-gdt +USER_DATA equ $-gdt ; 32 dw 0xffff ;limit 15:0 dw 0x0000 ;base 15:0 db 0x00 ;base 23:16 @@ -43,7 +43,7 @@ USER_DATA equ $-gdt db 0xCF ;flags ([G][D/B][0][0]) / limit 19:16 db 0x00 ;base 31:24 -TSS0_SEG equ $-gdt +TSS0_SEG equ $-gdt ; 40 dw 0x67 ;limit 15:0 dw 0 ;base 15:0 db 0 ;base 23:16 diff --git a/rmmod/rmmod.asm b/rmmod/rmmod.asm index c0d7f33..e7b19ac 100644 --- a/rmmod/rmmod.asm +++ b/rmmod/rmmod.asm @@ -10,7 +10,7 @@ ; the bootstrap process will jump us to 0x0:0x5010 so we'd better be ready for it [org 0x5000] -[bits 16] +[bits 32] ;HOS module header, better be 16 bytes! dd 0x4D534F48 ; magic identifier "HOSM" dd 1 ; real mode module @@ -20,10 +20,16 @@ ; ebx = return address ; ecx = where to store real mode parameter table start: - jmp blah -blah: - jmp $ - jmp 0:start_refreshed + jmp 24:start_pm16 +[bits 16] +start_pm16: ; in 16-bit protected mode + mov ax, 32 + mov ss, ax + mov eax, cr0 + and eax, 0x7FFFFFFE + mov cr0, eax ; leave PM + + jmp 0:start_refreshed ; enter RM %include "conio.inc" %include "vesa.inc"