wip: load kernel from FAT

This commit is contained in:
d0p1 🏳️‍⚧️ 2020-05-27 18:36:29 +02:00
parent 3d4615d276
commit 7455b79585
3 changed files with 96 additions and 47 deletions

View file

@ -1,7 +1,9 @@
all: stupid.img all: stupid.img kern.bin
stupid.img: floppy.bin kern.bin stupid.img: floppy.bin kern.bin
cat $^ /dev/zero | dd of=$@ bs=512 count=2880 mkdosfs -F 12 -C $@ 1440
dd status=noxfer conv=notrunc if=floppy.bin of=$@
mcopy -i $@ kern.bin ::kern.sys
floppy.bin: boot/floppy.s floppy.bin: boot/floppy.s
nasm -fbin -o $@ $^ nasm -fbin -o $@ $^
@ -10,10 +12,10 @@ kern.bin: kern/kernel.s
nasm -fbin -o $@ $^ nasm -fbin -o $@ $^
clean: clean:
rm floppy.bin kern.bin rm -rf floppy.bin kern.bin
fclean: fclean: clean
rm stupid.img rm -rf stupid.img
re: fclean all re: fclean all

View file

@ -9,24 +9,64 @@
;; ----------------------------------------------------------- ;; -----------------------------------------------------------
db "StupidOS" db "StupidOS"
dw 512 ; bytes per sector bpb_bytes_per_sector dw 512 ; bytes per sector
db 1 ; sector per cluster bpb_sectors_per_cluster db 1 ; sector per cluster
dw 1 ; reserved sector bpb_reserved_sectors dw 1 ; reserved sector
db 2 ; number of FATs bpb_number_of_fats db 2 ; number of FATs
dw 224 ; root entries bpb_root_entries dw 224 ; root entries
dw 2400 ; total sector bpb_total_sectors dw 2880 ; total sector
db 0xF9 ; media descriptor type bpb_media db 0xF0 ; media descriptor type
dw 7 ; sectors per FAT bpb_sectors_per_fat dw 9 ; sectors per FAT
dw 15 ; sectors per track bpb_sectors_per_track dw 18 ; sectors per track
dw 2 ; heads per cylinder bpb_heads_per_cylinder dw 2 ; heads per cylinder
dd 0 ; hidden sectors bpb_hidden_sectors dd 0 ; hidden sectors
dd 0 ; total sector big bpb_total_sector_big dd 0 ; total sector big
db 0 ; drive number bpb_drive_number db 0 ; drive number
db 0 ; unused bpb_unused db 0 ; unused
db 0x29 ; drive signature (0x29 = floppy) bpb_signature db 0x29 ; drive signature (0x29 = floppy)
dd 0x00000000 ; serial number (ignore) bpb_serial_number dd 0x00000000 ; serial number (ignore)
db 'STUPID DISK' ; volume label bpb_volume_label db 'STUPID DISK' ; volume label
db 'FAT12 ' ; filesystem type bpb_filesystem db 'FAT12 ' ; filesystem type
;; -----------------------------------------------------------
;; entry
;; -----------------------------------------------------------
entry:
xor ax, ax
mov ds, ax
mov si, msg_boot
call boot_print
mov si, msg_copyright
call boot_print
reset_disk:
xor ah, ah
xor dl, dl
int 0x13
jc reset_disk
;; load kernel from FAT
;; store size of root dir in cx
xor cx, cx
xor dx, dx
mov ax, 0x0020
mul word [bpb_root_entries]
div word [bpb_bytes_per_sector]
xchg ax, cx
;; store loc of root directory in ax
mov al, byte [bpb_number_of_fats]
mul word [bpb_sectors_per_fat]
add ax, word [bpb_reserved_sectors]
;; mov word [datasec], ax
;; mov word [datasec], cx
mov bx, 0x0200
hang:
jmp hang
cli
hlt
;; ----------------------------------------------------------- ;; -----------------------------------------------------------
;; Print string using bios interrupt ;; Print string using bios interrupt
@ -45,36 +85,42 @@ boot_print:
popa popa
ret ret
fatal_error:
pusha
mov cx, si
mov si, msg_error
call boot_print
mov si, cx
call boot_print
mov si, msg_press_any_key
call boot_print
xor ax, ax
int 0x16 ; wait keypressed
int 0x19 ; reboot
popa
ret
disk_read_sector:
pusha
popa
ret
;; ----------------------------------------------------------- ;; -----------------------------------------------------------
;; Variables ;; Variables
;; ----------------------------------------------------------- ;; -----------------------------------------------------------
copyright db "Copyright (c) d0p1", 13, 10, 0 msg_boot db "StupidOS - Bootloader", 13, 10, 0
err_disk_reset db "Error reseting disk..retry", 13, 10, 0 msg_copyright db "Copyright (c) d0p1", 13, 10, 0
msg_press_any_key db "Press any key...", 13, 10, 0
msg_error db "[ERROR] ", 0
err_kern_not_found db "KERNEL.BIN not found...", 13, 10, 0
kernel_filename db "KERNEL BIN"
;; ----------------------------------------------------------- ;; -----------------------------------------------------------
;; entry ;; End
;; ----------------------------------------------------------- ;; -----------------------------------------------------------
entry:
xor ax, ax
mov ds, ax
mov si, copyright
call boot_print
reset_disk:
xor ah, ah
xor dl, dl
int 0x13
jnc .reset_disk_end
mov si, err_disk_reset
call boot_print
jmp reset_disk
.reset_disk_end:
hang:
jmp hang
cli
hlt
times 510-($-$$) db 0 times 510-($-$$) db 0
db 0x55 db 0x55
db 0xAA db 0xAA

View file

@ -0,0 +1 @@
[BITS 16]