optimize print_string, fix boot and kernel entry

This commit is contained in:
'mr software' 2022-11-02 18:37:37 -07:00
parent 187cd0fbd4
commit bbd12ac117
5 changed files with 60 additions and 60 deletions

View File

@ -1,5 +1,5 @@
NUMSEG equ 1 ; TODO build system should calculate this value
NUMSEG equ 4; TODO build system should calculate this value
; might be good to move one of these into the high memory area
K_ADDR equ 0x500 ; kernel load address
KERNEL_SEG equ 0x50
STACK_SEG equ 0x1050

View File

@ -5,7 +5,7 @@
[org 0x7C00]
[bits 16]
mov ax, K_ADDR >> 4
mov ax, KERNEL_SEG
push ax ; setup for ds
mov es, ax
mov gs, ax
@ -13,7 +13,7 @@ mov fs, ax
xor cx, cx
mov ds, cx
mov word [0x21*4], 2 ; see kernel_entry
mov word [0x21*4], 2 ; see kjmp in kernel.s
mov word [0x21*4+2], ax
mov ax, 0x200 | NUMSEG
@ -34,7 +34,7 @@ push ds
push ax
retf
; TODO we have lots of space for init code here
; TODO filesystem and reserve space for mbr partition table
times 510 - ($-$$) db 0
dw 0xAA55

View File

@ -45,7 +45,13 @@ tmp: dw 0
retcode: dw 0
verify: db 0
rdin_echo:; ah=01h
; AH = 01h
; read a character from stdin and print it to stdout
; inputs:
; none
; outputs:
; AL: character read from stdin
rdin_echo:
push ax
mov ah, 8
int 0x21
@ -133,11 +139,11 @@ setint:
shl ax, 2
mov di, ax
xor ax, ax
push ds
mov ds, ax
mov word [di], dx
mov word [di+2], ds
pop ds
push es
mov es, ax
mov word es:[di], dx
mov word es:[di+2], ds
pop es
popa
ret

View File

@ -1,6 +1,10 @@
%include "config.s"
kernel_entry: ; MUST be a short jump due to loader config
kjmp: ; MUST be a short jump due to loader config
jmp kernel_entry
%include "int21.s"
kernel_entry:
mov si, hello_string
mov bl, 0x70
call print_string
@ -8,5 +12,4 @@ kernel_entry: ; MUST be a short jump due to loader config
hello_string: db "hello world!", 13, 10, '$'
%include "int21.s"
%include "vga.s"

View File

@ -5,11 +5,7 @@
; outputs:
; none
print_string:
push ax
push bx
push cx
push dx
push bp
pusha
push es
; get cursor position in DX
@ -20,27 +16,22 @@ print_string:
; calculate string length by iterating over it until we reach '$'
; this sucks but we have to do it because the bios expects to be passed the string length directly
xor cx, cx
push si
mov bp, si
jmp .start_loop
.size_loop:
inc cx
inc si
.start_loop:
cmp byte [si], '$'
jnz .size_loop
pop si
mov bp, si
; print string and update cursor position
mov ax, ds
mov es, ax
mov ah, 0x13
mov al, 0x01
mov ax, 0x1301
mov bh, 0x00
int 0x10
pop es
pop bp
pop dx
pop cx
pop bx
pop ax
popa
ret