Start working on the kernel
This commit is contained in:
parent
95d6cf1c4e
commit
ca070d672e
2
Makefile
2
Makefile
|
@ -22,7 +22,7 @@ nor86.krn: kernel.asm
|
||||||
nasm -MD $@.d -d F$(FLOPPY) -fbin -o $@ $<
|
nasm -MD $@.d -d F$(FLOPPY) -fbin -o $@ $<
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f *.bin *.img *.bin.d *.krn
|
rm -f *.bin *.img *.bin.d *.krn *.krn.d
|
||||||
|
|
||||||
run: nor86.img
|
run: nor86.img
|
||||||
qemu-system-i386 -fda $<
|
qemu-system-i386 -fda $<
|
||||||
|
|
|
@ -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
|
33
hexprint.inc
33
hexprint.inc
|
@ -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'
|
|
50
kernel.asm
50
kernel.asm
|
@ -1,18 +1,50 @@
|
||||||
cpu 8086
|
cpu 8086
|
||||||
org 0x500
|
org 0x500
|
||||||
|
|
||||||
mov si, string
|
greet:
|
||||||
loop:
|
mov si, kernel_greeting
|
||||||
lodsb
|
call printz
|
||||||
test al, al
|
|
||||||
jz hang
|
|
||||||
|
|
||||||
mov ah, 0xe
|
mov al, dl
|
||||||
int 0x10
|
add al, '0'
|
||||||
jmp loop
|
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:
|
hang:
|
||||||
hlt
|
hlt
|
||||||
jmp hang
|
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
|
||||||
|
|
|
@ -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
|
|
@ -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
|
Loading…
Reference in New Issue