diff --git a/bootsect.asm b/bootsect.asm index dd72fa6..de63d41 100644 --- a/bootsect.asm +++ b/bootsect.asm @@ -79,7 +79,7 @@ unreal: mov ebx, cr0 inc bl mov cr0, ebx ;pmode! - mov ax, 8 + mov ax, KERNEL_DATA mov es, ax mov ds, ax ;load segment limits dec bl @@ -203,7 +203,7 @@ movekernel_loop: cmp ecx, 0 jne movekernel_loop - jmp $ + jmp go_pm ;------------------------------------------------------ getCHSfromCluster: @@ -221,36 +221,6 @@ getCHSfromCluster: mov dh, dl ;head# (0-1) ret -;------------------------------------------------------ -;puthex: -; ;es:di points to video memory -; ;al holds hex value -; -; push ax -; mov ah, al -; shr ax, 4 -; and al, 0x0F -; add al, '0' -; cmp al, '9' -; jle puthex_goon1 -; add al, 'A'-'9'-1 -;puthex_goon1: -; stosb -; mov al, 7 -; stosb -; pop ax -; push ax -; and al, 0x0F -; add al, '0' -; cmp al, '9' -; jle puthex_goon2 -; add al, 'A'-'9'-1 -;puthex_goon2: -; stosb -; mov al, 7 -; stosb -; pop ax -; ret ;------------------------------------------------------- gdtr: @@ -259,8 +229,18 @@ gdtr: gdt: dd 0 dd 0 +KERNEL_CODE equ $-gdt + db 0xff ;limit 7:0 + db 0xff ;limit 15:8 + db 0x00 ;base 7:0 + db 0x00 ;base 15:8 + db 0x00 ;base 23:16 + db 0x9a ;access + db 0xcf ;flags / limit 19:16 + db 0x00 ;base 31:24 - db 0xff ;segment 8 = 4gb data +KERNEL_DATA equ $-gdt + db 0xff ;segment 16 = 4gb data db 0xff db 0x00 db 0x00 @@ -271,12 +251,28 @@ gdt: gdt_end: +go_pm: + xor ax, ax + mov ds, ax + lgdt [gdtr] + cli + mov eax, cr0 + inc eax + mov cr0, eax + + jmp KERNEL_CODE:pmode + +bits 32 +pmode: + mov ax, KERNEL_DATA + mov es, ax + mov ds, ax + jmp KERNEL_CODE:KERNEL_ADD + kernel: db "KERNEL BIN" k_count: dw 0 times 510-($-$$) db 0 - - db 0x55, 0xaa diff --git a/kernel.asm b/kernel.asm new file mode 100644 index 0000000..9cf4f4e --- /dev/null +++ b/kernel.asm @@ -0,0 +1,24 @@ + +bits 32 + +org 0x100000 + + mov esi, msg + mov edi, 0xb8000 + +msg_loop: + lodsb + or al, al + jz msg_done + stosb + mov al, 15 + stosb + jmp msg_loop + +msg_done: + + jmp $ + +msg: + db "This kernel is located at 0x100000!", 0 +