diff options
author | Marvin Borner | 2020-06-20 16:28:14 +0200 |
---|---|---|
committer | Marvin Borner | 2020-06-20 16:28:14 +0200 |
commit | cdea72777ae088e865b1100436a7ece7d5877347 (patch) | |
tree | b1a697dfdf917f4649f6e386450813240cd47fd5 | |
parent | dcf6dca74b8baadb8fdade55aad9068a60c3d25e (diff) |
Added bootloader and basic ext2 parsing
-rwxr-xr-x | run | 9 | ||||
-rw-r--r-- | src/entry.asm | 89 |
2 files changed, 87 insertions, 11 deletions
@@ -101,15 +101,15 @@ make_build() { make_genext2fs /usr/local/bin/genext2fs -B 4096 -d disk/ -U -N 4096 -b 65536 build/disk.img - nasm ./src/entry.asm -f bin -o disk/boot/boot.bin + nasm src/entry.asm -f bin -o disk/boot/boot.bin cp build/melvix.bin disk/boot/ - dd if=disk/boot/boot.bin bs=512 of=build/disk.img + dd if=disk/boot/boot.bin of=build/disk.img conv=notrunc printf "Build finshed successfully!\n\n" } make_test() { - qemu_with_flags -hda ./build/disk.img + qemu_with_flags -hdb build/disk.img } make_disasm() { @@ -134,7 +134,7 @@ make_tidy() { } make_clean() { - rm -rf ./disk/bin/ ./build/ + rm -rf ./disk/bin/ ./disk/boot/ ./build/ } if [ "${mode}" = "cross" ]; then @@ -147,6 +147,7 @@ elif [ "${mode}" = "clean" ]; then make_clean elif [ "${mode}" = "test" ]; then make_cross + make_clean make_build make_sync & make_test diff --git a/src/entry.asm b/src/entry.asm index 7404ccc..0567f61 100644 --- a/src/entry.asm +++ b/src/entry.asm @@ -1,8 +1,36 @@ bits 16 - org 0x7c00 -jmp start +global _start +_start: + ; Clear screen + mov ax, 0x003 + int 0x10 + + ; Welcome user! + mov si, hello_msg + call print + + ; Check LBA support + mov ah, 0x41 + mov bx, 0x55AA + int 0x13 + jc lba_error + cmp bx, 0xAA55 + jnz lba_error + + ; Check disk and move dl + and dl, 0x80 + jz disk_error + mov [drive], dl + + ; Load stage two + mov bx, stage_two + mov [dest], bx + call disk_read + + ; JUMP + jmp stage_two print: mov ah, 0x0E @@ -16,15 +44,62 @@ print: print_end: ret -start: - mov ax, 0x003 - int 0x10 +disk_read: + mov si, packet ; Address of dap + mov ah, 0x42 ; Extended read + mov dl, [drive] ; Drive number + int 0x13 + jc disk_error + ret - mov si, hello +; Errors +disk_error: + mov si, disk_error_msg call print jmp $ +lba_error: + mov si, lba_error_msg + call print + jmp $ + +; Variables +hello_msg db "Welcome! Loading Melvix...", 0x0A, 0x0D, 0x00 +disk_error_msg db "Disk error!", 0x0a, 0x0d, 0x00 +lba_error_msg db "LBA error!", 0x0a, 0x0d, 0x00 +stage_two_msg db "Stage2 loaded", 0x0a, 0x0d, 0x00 +disk_success_msg db "Disk is valid", 0x0a, 0x0d, 0x00 +drive db 0 -hello db "Loading Melvix...", 0x0A, 0x0D, 0x00 +; Data +packet: + db 0x10 ; Packet size + db 0 ; Always 0 +count: + dw 4 ; Number of sectors to transfer +dest: + dw 0 ; Destination offset + dw 0 ; Destination segment +lba: + dd 1 ; LBA number + dd 0 ; More storage bytes +; End of boot sector times 510 - ($ - $$) db 0 dw 0xAA55 + +stage_two: + mov si, stage_two_msg + call print + + mov ax, [superblock +56] + cmp ax, 0xEF53 + jne disk_error + + mov si, disk_success_msg + call print + + jmp $ + + +times 1024 - ($ - $$) db 0 +superblock: |