aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore3
-rwxr-xr-xboot.asm117
-rwxr-xr-xmakefile12
3 files changed, 132 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..bc15830
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+*.bin
+*.iso
+*.flp
diff --git a/boot.asm b/boot.asm
new file mode 100755
index 0000000..e687586
--- /dev/null
+++ b/boot.asm
@@ -0,0 +1,117 @@
+[org 0x7c00]
+
+;main code-----------------------------------------------------
+
+mov bp, 0x8000
+mov sp, bp
+
+mov si, msg
+call print
+
+mov bx, 0x9000 ;where to load (ES:BX)
+mov dh, 0x02
+mov dl, [boot_drive]
+call disk_load
+
+mov dx, [0x9000]
+call print_hex
+
+mov dx, [0x9200]
+call print_hex
+
+;hang--------------------------
+cli
+jmp $
+
+;functions-----------------------------------------------------
+
+;print-------------------------------------------
+print:
+pusha
+mov ah, 0x0e ;teletype output
+a:
+mov al, [si] ;char to print
+cmp al, 0x0
+je b
+int 0x10
+inc si
+jmp a
+b:
+popa
+ret
+
+;print_hex---------------------------------------
+print_hex:
+pusha
+;manipulate hex_out----------
+mov bx, dx
+shr bx, 12
+and bx, 0x000f
+mov bx, [hex + bx]
+mov [hex_out + 2], bl
+
+mov bx, dx
+shr bx, 8
+and bx, 0x000f
+mov bx, [hex + bx]
+mov [hex_out + 3], bl
+
+mov bx, dx
+shr bx, 4
+and bx, 0x000f
+mov bx, [hex + bx]
+mov [hex_out + 4], bl
+
+mov bx, dx
+shr bx, 0
+and bx, 0x000f
+mov bx, [hex + bx]
+mov [hex_out + 5], bl
+;end of manipulation---------
+mov si, hex_out
+call print
+popa
+ret
+
+;load to memory------------------------------------------------
+disk_load:
+pusha
+push dx ;save to cmp later
+;dh-num_sec, dl-floppy/hdd/cd
+mov ah, 0x02 ;read sectors from drive
+mov al, dh ;number of sectors to read
+mov dh, 0x00 ;head
+mov ch, 0x00 ;cylinder
+mov cl, 0x02 ;sector (second sector)
+int 0x13
+
+jc disk_err
+pop dx
+cmp dh, al
+jne disk_err
+
+popa
+ret
+
+disk_err:
+mov si, lerr
+call print
+mov dx, ax
+call print_hex
+cli
+jmp $
+
+;data----------------------------------------------------------
+msg: db "Data loaded from boot drive:", 0x0a, 0x0d, 0x0
+hex_out: db "0x0000", 0x0a, 0x0d, 0x0
+hex: db "0123456789ABCDEF"
+lerr: db "Error: INT 13H -> AX: ", 0x0
+boot_drive: db 0x80 ;floppy-iso(0x00) or hdd-qemu(0x80)
+
+;boot number---------------------------------------------------
+times 510-($-$$) db 0
+dw 0xaa55
+
+;other sectors-------------------------------------------------
+times 256 dw 0xb10c
+times 256 dw 0xcafe
diff --git a/makefile b/makefile
new file mode 100755
index 0000000..f181ac6
--- /dev/null
+++ b/makefile
@@ -0,0 +1,12 @@
+boot.bin: boot.asm
+ nasm -f bin boot.asm -o boot.bin
+all: boot.bin
+ truncate boot.bin -s 1200k
+ mkisofs -o boot.iso -b boot.bin ./
+ dd if=boot.bin of=boot.flp bs=512 count=2880
+clean:
+ rm boot.bin
+ rm boot.iso
+ rm boot.flp
+run: boot.bin
+ qemu-system-x86_64 boot.bin