diff --git a/Makefile b/Makefile index 875d962..ca2dd96 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ nor86.krn: kernel.asm nasm -MD $@.d -d F$(FLOPPY) -fbin -o $@ $< clean: - rm -f *.bin *.img *.bin.d *.krn + rm -f *.bin *.img *.bin.d *.krn *.krn.d run: nor86.img qemu-system-i386 -fda $< diff --git a/console.inc b/console.inc new file mode 100644 index 0000000..4d3ddcb --- /dev/null +++ b/console.inc @@ -0,0 +1,39 @@ +; IN: +; ds:si = start of asciz string +printz: + push ax + push si + + .loop: + lodsb + test al, al + jz .end + + call printc + + jmp .loop + + .end: + + pop si + pop ax + ret + +; IN: +; al = cp437 character +printc: + push ax + + cmp al, 10 + jne .output + + mov ax, 0x0e0d + int 0x10 + mov al, 10 + + .output: + mov ah, 0xe + int 0x10 + + pop ax + ret diff --git a/hexprint.inc b/hexprint.inc deleted file mode 100644 index e75a3a7..0000000 --- a/hexprint.inc +++ /dev/null @@ -1,33 +0,0 @@ -hexprint16: - xchg ah, al - call hexprint8 - xchg ah, al - -hexprint8: - push ax - push bx - push cx - mov cl, al - xor bx, bx - - shr al, 1 - shr al, 1 - shr al, 1 - shr al, 1 - mov bl, al - mov al, [.digits + bx] - mov ah, 0xe - int 0x10 - - mov bl, 0xf - and bl, cl - mov al, [.digits + bx] - mov ah, 0xe - int 0x10 - - pop cx - pop bx - pop ax - ret - - .digits: db '0123456789abcdef' diff --git a/kernel.asm b/kernel.asm index 1f183b3..ef5eb81 100644 --- a/kernel.asm +++ b/kernel.asm @@ -1,18 +1,50 @@ cpu 8086 org 0x500 -mov si, string -loop: - lodsb - test al, al - jz hang +greet: + mov si, kernel_greeting + call printz - mov ah, 0xe - int 0x10 - jmp loop + mov al, dl + add al, '0' + call printc + mov al, 10 + call printc + +memsize: + ; Get and display memory size + int 0x12 + mov bx, buffer + call itoa + + mov si, bx + call printz + mov si, memsize_trailer + call printz + +floppies: + ; Get and display number of floppy disks + int 0x11 + times 6 shr ax, 1 + and ax, 3 + inc ax + + add al, '0' + call printc + + mov si, floppies_trailer + call printz hang: hlt jmp hang -string db "Nor86 kernel succesfully loaded", 13, 10, 0 +%include "console.inc" +%include "printhex.inc" +%include "strint.inc" + +kernel_greeting db "Nor86 kernel succesfully loaded", 10, "Loaded from disk ", 0 +memsize_trailer db "k RAM", 10, 0 +floppies_trailer db " floppy drive(s)", 10, 0 + +buffer times 256 db 0 diff --git a/printhex.inc b/printhex.inc new file mode 100644 index 0000000..7018ff0 --- /dev/null +++ b/printhex.inc @@ -0,0 +1,36 @@ +; IN: +; ax = hex value +printh16: + xchg ah, al + call printh8 + xchg ah, al + +; IN: +; al = hex value +printh8: + push ax + mov ah, al + + shr al, 1 + shr al, 1 + shr al, 1 + shr al, 1 + call .printh4 + + mov al, 0xf + and al, ah + call .printh4 + + pop ax + ret + + .printh4: + cmp al, 10 + jb .numeric + + add al, 'a' - 10 + jmp printc + + .numeric: + add al, '0' + jmp printc diff --git a/strint.inc b/strint.inc new file mode 100644 index 0000000..dd0bc60 --- /dev/null +++ b/strint.inc @@ -0,0 +1,33 @@ +; IN: +; ax = number to convert +; es:bx = storage buffer +; OUT: +; es:bx = start of converted number +itoa: + push ax + push cx + push dx + + mov cx, 10 + + add bx, 5 + mov byte [es:bx], 0 + + .convert_loop: + test ax, ax + jz .end + + xor dx, dx + div cx + + add dl, '0' + dec bx + mov byte [es:bx], dl + + jmp .convert_loop + + .end: + pop dx + pop cx + pop ax + ret