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 ; 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 STACK_SEG equ 0x1050

View File

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

View File

@ -45,7 +45,13 @@ tmp: dw 0
retcode: dw 0 retcode: dw 0
verify: db 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 push ax
mov ah, 8 mov ah, 8
int 0x21 int 0x21
@ -133,11 +139,11 @@ setint:
shl ax, 2 shl ax, 2
mov di, ax mov di, ax
xor ax, ax xor ax, ax
push ds push es
mov ds, ax mov es, ax
mov word [di], dx mov word es:[di], dx
mov word [di+2], ds mov word es:[di+2], ds
pop ds pop es
popa popa
ret ret

View File

@ -1,6 +1,10 @@
%include "config.s" %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 si, hello_string
mov bl, 0x70 mov bl, 0x70
call print_string 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, '$' hello_string: db "hello world!", 13, 10, '$'
%include "int21.s"
%include "vga.s" %include "vga.s"

View File

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