diff options
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | Makefile | 12 | ||||
-rw-r--r-- | README.adoc | 4 | ||||
-rw-r--r-- | TODO | 8 | ||||
-rw-r--r-- | print.asm | 44 | ||||
-rw-r--r-- | printb.asm | 36 |
6 files changed, 107 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3d4322a --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +print +printb +boot.img diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c9438a6 --- /dev/null +++ b/Makefile @@ -0,0 +1,12 @@ +boot.img: print printb + cat print printb > boot.img + +print: print.asm + nasm -Wall print.asm + +printb: printb.asm + nasm -Wall printb.asm + +.PHONY: run +run: boot.img + qemu-system-i386 -drive file=boot.img,format=raw,index=0,if=floppy diff --git a/README.adoc b/README.adoc new file mode 100644 index 0000000..9ee985a --- /dev/null +++ b/README.adoc @@ -0,0 +1,4 @@ +== Assembly Stuff + +Trying to do some low-level i386 assembly. I apparently succeeded loading some +data from a virtual floppy disk. Maybe, one day, I'll try to do more. @@ -0,0 +1,8 @@ +* boot loader, loading a few sectors into memory +* output from loadable +* setting up things to transition to protected mode + * defining a software interrupt in order to call a print() function +* setting up things to transition to long mode + * defining a syscall on order to call a print() function +* writing minimal program in C +* writing a minimal scheduler and running two programs at the same time diff --git a/print.asm b/print.asm new file mode 100644 index 0000000..97acd8b --- /dev/null +++ b/print.asm @@ -0,0 +1,44 @@ +org 7C00h + +jmp _start + +hello: db 'Hello from the first stage!', 0x0A, 0x0D, 0x0 + +_start: + +; print hello message + +mov ah, 0x0E +xor esi, esi +xor edi, edi +mov si, hello +cld + +.loop: +lodsb +cmp al, 0x00 +je .out +int 0x10 +jmp .loop +.out: + +; load sectors from disk and jump there + +mov ah, 0x02 ; load sectory from disk +mov al, 0x01 ; load one sector +xor ch, ch ; cylinder number +mov cl, 0x02 ; start from sector 2 +xor dh, dh ; head number +xor dl, dl ; drive number + +mov bx, 0x0500 ; start address (see jmp) + ; 0x00000500 to 0x00007BFF, from Overview at http://wiki.osdev.org/Memory_Map_%28x86%29 +int 0x13 + +jmp 0x0500 + +jmp $ + +; stolen from: https://en.wikibooks.org/wiki/X86_Assembly/Bootloaders +times 0200h - 2 - ($ - $$) db 0 ;Zerofill up to 510 bytes +dw 0AA55h ;Boot Sector signature diff --git a/printb.asm b/printb.asm new file mode 100644 index 0000000..a8fa788 --- /dev/null +++ b/printb.asm @@ -0,0 +1,36 @@ +org 0x0500 + + +SECTION .data +boot: db 'Welcome to the second stage!', 0x0A, 0x0D, 0x00 +foo: db 'What a nice message this is!', 0x0A, 0x0D, 0x00 + +SECTION .text + + +jmp start + +print: + push ax + cld + mov ah, 0x0E + + .loop: + lodsb + cmp al, 0x00 + je .out + int 0x10 + jmp .loop + .out: + pop ax + ret + +start: + mov si, boot + call print + + mov si, foo + call print + +; maybe to something here... +; e.g.: how to keep CPU from spinning at 100% |