From 523322dc13a2599014e26780518bf06277a57e30 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Wed, 29 Nov 2017 11:34:58 -0500 Subject: add print[i,h] and normalize load addresses --- boot.asm | 11 +++++++- console.asm | 2 -- disk.asm | 8 +++--- kernel.asm | 54 +++++++++++++++++++++++++++++++------ stdio.asm | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 148 insertions(+), 16 deletions(-) diff --git a/boot.asm b/boot.asm index d6ddfa1..f17cd76 100644 --- a/boot.asm +++ b/boot.asm @@ -4,7 +4,7 @@ jmp start CR equ 0Dh LF equ 0Ah -K_CS_ADDR equ 007eh +K_CS_ADDR equ 07E0h start: mov ax, 07c0h @@ -67,6 +67,15 @@ start: pop bp mov dx, [drive0] ; the kernel will need the boot drive number + + ;cli ; disable interrupts + ;mov ax, K_CS_ADDR ; get code segment + ;mov ds, ax ; set data segment + ;mov es, ax ; set extra segment + ;mov ax, 0800h + ;mov ss, ax ; set stack segment + ;mov sp, 0ffffh ; set stack pointer (~64k) + jmp K_CS_ADDR:0000h ; jump to kernel address cli ; disable interrupts diff --git a/console.asm b/console.asm index f992705..9f88a28 100644 --- a/console.asm +++ b/console.asm @@ -136,13 +136,11 @@ console_driver: .handle_CR: mov dl, 0 ; set column zero - ; fall through .handle_LF: inc dh ; increment row jmp .return - .return: push dx call setcursor diff --git a/disk.asm b/disk.asm index 3e43c48..2a10b35 100644 --- a/disk.asm +++ b/disk.asm @@ -76,10 +76,10 @@ disk_read: ; data drive0: dw 0 -msg_disk_reset: db "Drive reset successful.", CR, LF, 0 -msg_disk_read: db "Sector read successful.", CR, LF, 0 +msg_disk_reset: db "Drive reset successful.", CR, 0 +msg_disk_read: db "Sector read successful.", CR, 0 -error_msg_disk_reset: db "Drive reset failed!", CR, LF, 0 -error_msg_disk_read: db "Drive read failed!", CR, LF, 0 +error_msg_disk_reset: db "Drive reset failed!", CR, 0 +error_msg_disk_read: db "Drive read failed!", CR, 0 %endif ; _DISK_ASM diff --git a/kernel.asm b/kernel.asm index f613460..801404b 100644 --- a/kernel.asm +++ b/kernel.asm @@ -11,10 +11,10 @@ jmp kmain kmain: cli ; disable interrupts - mov ax, cs ; get code segment (i.e. far jump address in bootloader) + mov ax, cs ; get code segment mov ds, ax ; set data segment mov es, ax ; set extra segment - mov ax, 06000h + mov ax, 8000h mov ss, ax ; set stack segment mov sp, 0ffffh ; set stack pointer (~64k) sti ; enable interrupts @@ -30,9 +30,47 @@ kmain: xor si, si xor bp, bp + push msg_entry_point + call puts + add sp, 2 + + push cs + call printh + + mov al, ':' + call putc + + mov ax, kmain + push ax + call printh + add sp, 4 + mov al, CR + call putc + + ;--- stack + + push msg_entry_point_stack + call puts + add sp, 2 + + push ss + call printh + + mov al, ':' + call putc + + push sp + call printh + add sp, 4 + + mov al, CR + call putc push banner call puts + add sp, 2 + + .mainloop: call kbd_read @@ -63,15 +101,15 @@ panic: ; data -kernel_address: dd 0 ; format DS:ADDR -banner: db "+========================+", CR, LF - db "| Welcome to MINOS 0.0.1 |", CR, LF - db "+========================+", CR, LF - db CR, LF, 0 +msg_entry_point: db 'Loaded at ', 0 +msg_entry_point_stack: db 'Stack at ', 0 +banner: db "+========================+", CR + db "| Welcome to MINOS 0.0.1 |", CR + db "+========================+", CR + db CR, 0 ; Error messages error_msg_panic: db "PANIC: ", 0 - times 512 * 16 db 0 dw 0xefbe diff --git a/stdio.asm b/stdio.asm index e6f7290..2e61afc 100644 --- a/stdio.asm +++ b/stdio.asm @@ -17,7 +17,7 @@ puts: lodsb ; load byte at [si] into al or al, 0 ; 0 | 0 = 0 (detect null terminator) je .end - int 10h ; BIOS video service + call putc jmp .loop .end: popa @@ -25,4 +25,91 @@ puts: pop bp ret + +printi: + push bp + mov bp, sp + + mov ax, [bp + 4] ; integer WORD + mov cx, 0 ; counter + cmp ax, 0 + je .write_no_pop + +.divide: + xor dx, dx + mov di, 10 ; divisor + div di + + push dx + inc cx + cmp ax, 0 + jne .divide + + jmp .write + +.write_no_pop: + or al, 30h + call putc + jmp .return + +.write: + pop ax + + or al, 30h + call putc + dec cx + jne .write + +.return: + mov sp, bp + pop bp + ret + +printh: + push bp + mov bp, sp + + mov ax, [bp + 4] ; integer WORD + mov cx, 0 ; counter + cmp ax, 0 + je .write_no_pop + +.divide: + xor dx, dx + mov di, 16 ; divisor + div di + + push dx + inc cx + cmp ax, 0 + jne .divide + + jmp .write + +.write_no_pop: + or al, 30h + call putc + jmp .return + +.write: + pop ax + cmp al, 10 + jge .alpha + + or al, 30h + jmp .decimal + +.alpha: + sub al, 10 + add al, 'A' + +.decimal: + call putc + dec cx + jne .write + +.return: + mov sp, bp + pop bp + ret %endif -- cgit