Initial bootloader and kernel loader
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
.section .multiboot
|
||||
.align 4
|
||||
.long 0x1BADB002
|
||||
.long 0x0
|
||||
.long -(0x1BADB002)
|
||||
|
||||
.section .text
|
||||
.global _start
|
||||
.type _start, @function
|
||||
|
||||
_start:
|
||||
cli
|
||||
call kernel_main
|
||||
|
||||
.hang:
|
||||
hlt
|
||||
jmp .hang
|
||||
@@ -0,0 +1,54 @@
|
||||
[org 0x7C00]
|
||||
bits 16
|
||||
|
||||
KERNEL_OFFSET equ 0x1000
|
||||
|
||||
start:
|
||||
cli
|
||||
mov [BOOT_DRIVE], dl
|
||||
|
||||
xor ax, ax
|
||||
mov ds, ax
|
||||
mov es, ax
|
||||
mov ss, ax
|
||||
mov sp, 0x7C00
|
||||
sti
|
||||
|
||||
call load_kernel
|
||||
|
||||
jmp KERNEL_OFFSET
|
||||
|
||||
; -----------------------
|
||||
; Зчитування kernel
|
||||
; -----------------------
|
||||
|
||||
load_kernel:
|
||||
mov bx, KERNEL_OFFSET ; куди завантажити
|
||||
mov dh, 5 ; кількість секторів (тимчасово 5)
|
||||
|
||||
mov dl, [BOOT_DRIVE]
|
||||
mov ah, 0x02 ; BIOS read sector
|
||||
mov al, dh ; скільки секторів
|
||||
mov ch, 0x00 ; cylinder
|
||||
mov dh, 0x00 ; head
|
||||
mov cl, 0x02 ; сектор 2 (після bootloader)
|
||||
int 0x13
|
||||
|
||||
jc disk_error
|
||||
ret
|
||||
|
||||
disk_error:
|
||||
mov si, error_msg
|
||||
.print:
|
||||
lodsb
|
||||
cmp al, 0
|
||||
je $
|
||||
mov ah, 0x0E
|
||||
int 0x10
|
||||
jmp .print
|
||||
|
||||
BOOT_DRIVE db 0
|
||||
error_msg db "Disk read error!", 0
|
||||
|
||||
times 510 - ($ - $$) db 0
|
||||
dw 0xAA55
|
||||
@@ -0,0 +1,19 @@
|
||||
[org 0x1000]
|
||||
bits 16
|
||||
|
||||
start:
|
||||
mov si, message
|
||||
|
||||
.print:
|
||||
lodsb
|
||||
cmp al, 0
|
||||
je .hang
|
||||
mov ah, 0x0E
|
||||
int 0x10
|
||||
jmp .print
|
||||
|
||||
.hang:
|
||||
hlt
|
||||
jmp .hang
|
||||
|
||||
message db "Kernel loaded successfully!", 0
|
||||
@@ -0,0 +1,16 @@
|
||||
#include <stddef.h>
|
||||
|
||||
void kernel_main(void) {
|
||||
volatile char *video = (volatile char*) 0xB8000;
|
||||
|
||||
const char *msg = "LiteOS kernel started";
|
||||
|
||||
for (size_t i = 0; msg[i] != '\0'; i++) {
|
||||
video[i * 2] = msg[i];
|
||||
video[i * 2 + 1] = 0x07; // світло-сірий текст
|
||||
}
|
||||
|
||||
while (1) {
|
||||
__asm__("hlt");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user