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

add kern loader, debugging

parent 1036cac9
No related branches found
No related tags found
No related merge requests found
default: assemble
bootloader:
$(MAKE) -C bootloader
kernel:
$(MAKE) -C kernel
.PHONY: bootloader kernel
build: bootloader kernel
assemble: build
......
[bits 16]
[org 0x7c00]
mov [_boot_drive_id], dl
jmp _init_prot_mode
gdt_begin:
......@@ -61,14 +62,45 @@ _prot_begin:
mov ebx, _motd_32
call println_vga
KERN_ADDR equ 0x1000
; Load the kernel image from boot disk, disk offset 512B to 64KB.
KERN_ADDR equ 0x7e00
mov ah, 0x02
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.
jmp _stall
jc disk_io_error
mov dl, 0x7f
cmp dl, al
jne disk_io_error
; kernel successfully loaded now!
mov ebx, _motd_kern_ok
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] [LOADING KERN..]', 0x0
db '[ENTER X86 MODE SUCC]', 0x0
_motd_kern_ok:
db '[ENTER X86 MODE SUCC] [LOAD KERN SUCC]', 0x0
_motd_endk:
db '[ENTER X86 MODE SUCC] [LOADING KERN..] [KERN EXITED]', 0x0
db '[ENTER X86 MODE SUCC] [LOAD KERN SUCC] [KERN EXITED]', 0x0
_boot_drive_id:
db 0x0
%include "./mbr_end.inc"
......
kernel:
gcc -ffreestanding -c kernel.c -o kernel.o # -m32
ld -o kernel.img -Ttext 0x1000 --oformat binary kernel.o # -m elf_i386
ld -o kernel.img -Ttext 0x7e00 --oformat binary kernel.o # -m elf_i386
# Sector 1 = bootloader, Sector 2 - (512B TO 64K) = kernel
truncate --size=65024 kernel.img
clean:
rm *.o *.img
......
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