aboutsummaryrefslogtreecommitdiffstats
path: root/src/boot
diff options
context:
space:
mode:
authorkotorifan <kotorifan05@gmail.com>2026-02-01 22:18:34 +0100
committerkotorifan <kotorifan05@gmail.com>2026-02-04 09:01:10 +0100
commit9dbf9d0c21002983de556aa76a9d01124d556a90 (patch)
tree9e1a856377cfdbb3fe1b8da47634bd7a502d8d21 /src/boot
parent35f3e16135b371e11d540a8b6bd5395cb40b2c96 (diff)
downloadkotori-os-9dbf9d0c21002983de556aa76a9d01124d556a90.tar.gz
Enough for today
Diffstat (limited to 'src/boot')
-rw-r--r--src/boot/boot.stage1.asm88
-rw-r--r--src/boot/boot.stage2.asm3
2 files changed, 60 insertions, 31 deletions
diff --git a/src/boot/boot.stage1.asm b/src/boot/boot.stage1.asm
index 5fa3b7a..70e2f17 100644
--- a/src/boot/boot.stage1.asm
+++ b/src/boot/boot.stage1.asm
@@ -5,13 +5,19 @@
%include "boot.common.asm"
- %define READ_SECTORS_NUM 1
- %define BOOT_LOAD_ADDR 0x7c00
+ %define LOAD_ADDRESS 0x7C00
+ %define STAGE2_ADDRESS 0x7E00
+ %define RELOCATE_ADDRESS 0x0600
%define SECTOR_SIZE 512
+ %define OFFSET_RELOC (RELOCATE_ADDRESS - LOAD_ADDRESS)
+ %define STAGE2_SECTORS 8
+
global _start
_start:
+ jmp 0x0000:.setup_segments
+ .setup_segments:
;; Disable interrupts
cli
@@ -20,44 +26,65 @@ _start:
mov ds, ax
mov es, ax
mov ss, ax
+ mov gs, ax
- ;; Adjust Stack
- mov sp, _start
-
- clc
+ mov sp, LOAD_ADDRESS ; Adjust stack
- mov [drive], dl
- mov si, disk_addr_packet
- mov ah, 0x42 ; BIOS extended read function
- mov dl, [drive] ; Drive number
- int 0x13 ; BIOS disk services
- jc _disk_read_err
-
- mov si, disk_read_success_msg
- call _print_string
+ ;; Save disk
+ mov [drive], dl ; Get drive ID from BIOS
- jmp 0x0000:0x7e00
+ sti
+
+ mov si, LOAD_ADDRESS
+ mov di, RELOCATE_ADDRESS
+ mov cx, SECTOR_SIZE
+ cld
+ rep movsdb
+
+ jmp 0x0000:(next)
+_read_disk_real_mode:
+ .start:
+ cmp cx, 127
+ jbe .good_size
+ pusha
+ mov cx, 127
+ call _read_disk_real_mode
+ popa
+ add eax, 127
+ add dx, 127*512/16
+ sub cx, 127
+ jmp .start
-_disk_read_err:
+ .good_size:
+ mov [DAP.LBA_lower], ax
+ mov [DAP.num_sectors], cx
+ mov [DAP.buf_segment], dx
+ mov [DAP.buf_offset], bx
+ mov dl, [disk]
+ mov si, DAP
+ mov ah, 0x42
+ int 0x13
+ jc .disk_read_err
+ ret
+ .disk_read_err:
mov si, disk_read_err_msg
call _print_string
-
- hlt
- jmp _disk_read_err
+ .halt: hlt
+ jmp .halt
_print_string:
pusha
mov ah, 0x0e
mov bh, 0x00
-.print_loop:
+ .print_loop:
lodsb
test al, al
je .print_return
int 0x10
jmp .print_loop
-.print_return:
+ .print_return:
popa
ret
@@ -68,14 +95,17 @@ _end:
drive: db 0
disk_read_err_msg: db "Failed to read disk", 13, 10, 0
disk_read_success_msg: db "Read the disk successfully", 13, 10, 0
-disk_addr_packet:
- db 0x10
- db 0x00
- dw READ_SECTORS_NUM
- dw 0x7e00
- dw 0x0000
- dq 1
+boot_msg: db "Booting", 13, 10, 0
+DAP:
+ db 0x10
+ db 0
+ .num_sectors: dw 127
+ .buf_offset: dw 0x0
+ .buf_segment: dw 0x0
+ .LBA_lower: dd 0x0
+ .LBA_upper: dd 0x0
+
;; Padding and magic number
times 510 - ($ - $$) db 0
dw 0xaa55
diff --git a/src/boot/boot.stage2.asm b/src/boot/boot.stage2.asm
index 8f4885b..97a2d05 100644
--- a/src/boot/boot.stage2.asm
+++ b/src/boot/boot.stage2.asm
@@ -1,7 +1,7 @@
;; boot.stage2.asm
[bits 16]
- [org 0x7e00]
+ [org 0x0000]
%include "boot.stage2.a20.asm"
%include "boot.stage2.pm.asm"
@@ -11,4 +11,3 @@ _s2_entry:
call _enable_a20
call _enable_pm
[bits 32]
-