Skip to content
Snippets Groups Projects
Commit 14a9ce27 authored by Recolic Keghart's avatar Recolic Keghart
Browse files

kernel working

parent 58da7e98
No related branches found
No related tags found
No related merge requests found
[bits 16]
[org 0x7c00]
mov [_boot_drive_id], dl
; Load the kernel image from boot disk, disk offset 512B to 64KB.
KERN_ADDR equ 0x7e00
mov ah, 0x02
mov dl, [_boot_drive_id]
mov ch, 0
mov dh, 0
mov cl, 2 ; from the second one,
mov al, 127 ; read 127 sectors in total.
mov bx, KERN_ADDR
int 0x13 ; Set carry on error, and set AL to sectors that actual read.
KERN_ADDR equ 0x7e00
jc disk_io_error
mov dl, 0x7f
cmp dl, al
jne disk_io_error
; kernel successfully loaded now!
mov bx, _motd_kern_ok
call println_bios
jmp _init_prot_mode
mov [_boot_drive_id], dl
jmp _load_kern
; jmp _init_prot_mode
%include "./str.16.inc"
......@@ -60,6 +44,35 @@ gdt_desc:
CODE_SEG_OFFSET equ gdt_entry_1 - gdt_begin
DATA_SEG_OFFSET equ gdt_entry_2 - gdt_begin
_load_kern:
; Load the kernel image from boot disk, disk offset 512B to 64KB.
; This is a 16bit real mode function.
mov ah, 0x02
mov dl, [_boot_drive_id]
mov ch, 0
mov dh, 0
mov cl, 2 ; from the second one,
mov al, 127 ; read 127 sectors in total.
mov bx, KERN_ADDR
int 0x13 ; Set carry on error, and set AL to sectors that actual read.
jc disk_io_error
mov dl, 0x7f
cmp dl, al
jne disk_io_error
; kernel successfully loaded now!
mov bx, _motd_kern_ok
call println_bios
jmp _init_prot_mode
disk_io_error:
mov bx, _motd_disk_error
call println_bios
jmp _stall
_init_prot_mode:
cli
lgdt [gdt_desc]
......@@ -85,24 +98,24 @@ _prot_begin:
mov ebx, _motd_32
call println_vga
; Enter the kernel. This should never return.
call KERN_ADDR
; Kernel returns.
mov ebx, _motd_endk
call println_vga
_stall:
jmp $
disk_io_error:
mov ebx, _motd_disk_error
call println_vga
jmp _stall
_motd_disk_error:
db 'DISK_IO_ERROR', 0x0
_motd_32:
db '[ENTER X86 MODE SUCC]', 0x0
db '[LOAD KERN SUCC] [ENTER X86 MODE SUCC]', 0x0
_motd_kern_ok:
db '[ENTER X86 MODE SUCC] [LOAD KERN SUCC]', 0x0
db '[LOAD KERN SUCC]', 0x0
_motd_endk:
db '[ENTER X86 MODE SUCC] [LOAD KERN SUCC] [KERN EXITED]', 0x0
db '[LOAD KERN SUCC] [ENTER X86 MODE SUCC] [KERN EXITED]', 0x0
_boot_drive_id:
db 0x0
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment