optimize print_string, fix boot and kernel entry
This commit is contained in:
parent
187cd0fbd4
commit
bbd12ac117
6
config.s
6
config.s
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
74
src/int21.s
74
src/int21.s
|
@ -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
|
||||||
|
@ -55,10 +61,10 @@ rdin_echo:; ah=01h
|
||||||
; AH = 4dh
|
; AH = 4dh
|
||||||
; get return code
|
; get return code
|
||||||
; inputs:
|
; inputs:
|
||||||
; none
|
; none
|
||||||
; outputs:
|
; outputs:
|
||||||
; AH: termination type (0 = normal, 1 = control-C abort, 2 = critical error abort, 3 = terminate and stay resident)
|
; AH: termination type (0 = normal, 1 = control-C abort, 2 = critical error abort, 3 = terminate and stay resident)
|
||||||
; AL: return code
|
; AL: return code
|
||||||
getret:
|
getret:
|
||||||
xor ax, ax
|
xor ax, ax
|
||||||
xchg [retcode], ax
|
xchg [retcode], ax
|
||||||
|
@ -67,10 +73,10 @@ getret:
|
||||||
; AH = 30h
|
; AH = 30h
|
||||||
; get the DOS version number
|
; get the DOS version number
|
||||||
; inputs:
|
; inputs:
|
||||||
; none
|
; none
|
||||||
; outputs:
|
; outputs:
|
||||||
; AL: major version
|
; AL: major version
|
||||||
; AH: minor version
|
; AH: minor version
|
||||||
getver:
|
getver:
|
||||||
mov ax, 8 ; if it is not zero indexed this indicates windows ME
|
mov ax, 8 ; if it is not zero indexed this indicates windows ME
|
||||||
xor bx, bx ; update: what does that comment mean
|
xor bx, bx ; update: what does that comment mean
|
||||||
|
@ -81,9 +87,9 @@ getver:
|
||||||
; AH = 54h
|
; AH = 54h
|
||||||
; get disk verify flag
|
; get disk verify flag
|
||||||
; inputs:
|
; inputs:
|
||||||
; none
|
; none
|
||||||
; outputs:
|
; outputs:
|
||||||
; AL: 0 if off, 1 if on
|
; AL: 0 if off, 1 if on
|
||||||
getverify:
|
getverify:
|
||||||
mov al, [verify]
|
mov al, [verify]
|
||||||
ret
|
ret
|
||||||
|
@ -91,9 +97,9 @@ getverify:
|
||||||
; AH = 2eh
|
; AH = 2eh
|
||||||
; set disk verify flag
|
; set disk verify flag
|
||||||
; inputs:
|
; inputs:
|
||||||
; AL: 0 if off, 1 if on
|
; AL: 0 if off, 1 if on
|
||||||
; outputs:
|
; outputs:
|
||||||
; none
|
; none
|
||||||
setverify:
|
setverify:
|
||||||
mov [verify], al
|
mov [verify], al
|
||||||
ret
|
ret
|
||||||
|
@ -101,9 +107,9 @@ setverify:
|
||||||
; AH = 35h
|
; AH = 35h
|
||||||
; get interrupt vector
|
; get interrupt vector
|
||||||
; inputs:
|
; inputs:
|
||||||
; AL: interrupt number
|
; AL: interrupt number
|
||||||
; outputs:
|
; outputs:
|
||||||
; ES:BX: current interrupt handler
|
; ES:BX: current interrupt handler
|
||||||
getint:
|
getint:
|
||||||
push ds
|
push ds
|
||||||
push di
|
push di
|
||||||
|
@ -123,29 +129,29 @@ getint:
|
||||||
; AH = 25h
|
; AH = 25h
|
||||||
; set interrupt vector
|
; set interrupt vector
|
||||||
; inputs:
|
; inputs:
|
||||||
; AL: interrupt number
|
; AL: interrupt number
|
||||||
; DS:DX: new interrupt handler
|
; DS:DX: new interrupt handler
|
||||||
; outputs:
|
; outputs:
|
||||||
; none
|
; none
|
||||||
setint:
|
setint:
|
||||||
pusha
|
pusha
|
||||||
xor ah, ah
|
xor ah, ah
|
||||||
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
|
||||||
|
|
||||||
; read from CMOS register
|
; read from CMOS register
|
||||||
; inputs:
|
; inputs:
|
||||||
; AL: register
|
; AL: register
|
||||||
; outputs:
|
; outputs:
|
||||||
; AL: value
|
; AL: value
|
||||||
; TODO: handle bcd here to abstract it from the kernel
|
; TODO: handle bcd here to abstract it from the kernel
|
||||||
rdcmos:
|
rdcmos:
|
||||||
cli
|
cli
|
||||||
|
@ -165,10 +171,10 @@ rdcmos:
|
||||||
|
|
||||||
; write to CMOS register
|
; write to CMOS register
|
||||||
; inputs:
|
; inputs:
|
||||||
; BL: value
|
; BL: value
|
||||||
; BH: register
|
; BH: register
|
||||||
; outputs:
|
; outputs:
|
||||||
; none
|
; none
|
||||||
wrcmos:
|
wrcmos:
|
||||||
cli
|
cli
|
||||||
push ax
|
push ax
|
||||||
|
@ -184,11 +190,11 @@ wrcmos:
|
||||||
; AH = 2ch
|
; AH = 2ch
|
||||||
; read system time from the CMOS
|
; read system time from the CMOS
|
||||||
; inputs:
|
; inputs:
|
||||||
; none
|
; none
|
||||||
; outputs:
|
; outputs:
|
||||||
; CH: hours
|
; CH: hours
|
||||||
; CL: minutes
|
; CL: minutes
|
||||||
; DH: seconds
|
; DH: seconds
|
||||||
gettime:
|
gettime:
|
||||||
push ax
|
push ax
|
||||||
xor dl, dl
|
xor dl, dl
|
||||||
|
@ -215,11 +221,11 @@ gettime:
|
||||||
; AH = 2dh
|
; AH = 2dh
|
||||||
; set system time in the CMOS
|
; set system time in the CMOS
|
||||||
; inputs:
|
; inputs:
|
||||||
; CH: hours
|
; CH: hours
|
||||||
; CL: minutes
|
; CL: minutes
|
||||||
; DH: seconds
|
; DH: seconds
|
||||||
; outputs:
|
; outputs:
|
||||||
; none
|
; none
|
||||||
settime:
|
settime:
|
||||||
push bx
|
push bx
|
||||||
mov bl, ch
|
mov bl, ch
|
||||||
|
|
|
@ -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"
|
||||||
|
|
27
src/vga.s
27
src/vga.s
|
@ -1,15 +1,11 @@
|
||||||
; print a string to the screen
|
; print a string to the screen
|
||||||
; inputs:
|
; inputs:
|
||||||
; DS:SI: pointer to '$'-terminated string
|
; DS:SI: pointer to '$'-terminated string
|
||||||
; BL: attribute
|
; BL: attribute
|
||||||
; 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
|
||||||
|
|
Loading…
Reference in New Issue