boo-os/kernel.asm

324 lines
6.6 KiB
NASM
Raw Normal View History

2021-11-09 02:19:34 +00:00
@ $00000:
label vbuf:
@ $4B000:
$CB000 ; Set Instruction Pointer to $5B000
2021-11-09 02:19:34 +00:00
label RAX:
$0000000 ; RAX
$0000000 ; R2 - Temp Scratch
$0000000 ; R3 - Temp Scratch
2021-11-13 06:03:26 +00:00
label ARG1
2021-11-09 02:19:34 +00:00
$0000000 ; R4 - ARG 1
$0000000 ; R5 - ARG 2
$0000000 ; R6 - ARG 3
$0000000 ; R7 - ARG 4
$0000000 ; R8 - ARG 5
$0000000 ; RX
$0000000 ; RY
label R(B):
2021-11-09 02:19:34 +00:00
$0000000 ; RVBUF (RY * 640) + RX
label R(c):
$0000001 ; Ghost Post
@ $4B040:
label CycleCount:
$0000000; Cycles
label KeyPressedState:
$0000000; The ID of a Key Being Pressed (If Any)
2021-11-09 02:19:34 +00:00
@ $4B0C0:
2021-11-13 06:03:26 +00:00
hlt
import display.asm ; setpos
import charset.asm ; charset + hex strings
import strings.asm ; draw_char, draw_string
import util.asm ; print_addr
import graphics.asm; draw_vline, draw_hline, draw_rect
2021-11-09 02:19:34 +00:00
; Common Strings
data ascii boo_os_version Boo OS v0.0.1
2021-11-12 23:37:02 +00:00
data ascii prompt [sarah@boo] >
2021-11-09 02:19:34 +00:00
data ascii Welcome !@#$%^&*()_+=-0987654321
data ascii Introspection We Can Now Do Introspection:
data ascii label_rax RAX:
data ascii label_rip RIP:
data ascii label_cycles Instruction Count:
data ascii label_keypress Current Key Pressed:
data image boo_os.png booos.png
data image boo_os_small.png booos-small.png
data image wallpaper.png wallpaper.png
data ascii quit_label QUIT
2021-11-13 23:27:56 +00:00
data ascii jump_label JUMP
data ascii diss_label DISS
2021-11-12 23:37:02 +00:00
data buffer command_line_input 64
data buffers 48 terminal 64
meta
2021-11-12 23:37:02 +00:00
; strcmp compares 2 strings in a byte-by-byte manner, incrementing ptrs as it goes. Returns 1 if both bytes
; point to 0. Returns 0 (fail) if it encounters 2 different bytes
2021-11-13 06:03:26 +00:00
; clobbers $1 $2 $3 $4 $5
label strcmp:
2021-11-13 06:03:26 +00:00
loadi $3 $0
label strcmp_loop:
2021-11-12 23:37:02 +00:00
rload $4 $1
rload $5 $2
2021-11-13 06:03:26 +00:00
jeq +3 ; if either of these differ then return 0 to indicate these strings don't match
loadi $1 0
ret
2021-11-13 06:03:26 +00:00
loadi $2 0
jneq +3 ; if both are 0 then we have reached the end of the string
loadi $1 1
ret
2021-11-13 06:03:26 +00:00
inc $4
inc $5
2021-11-13 06:03:26 +00:00
inc $3
tx $1 $3 ;check expected length
tx $2 $6 ;check max length
jneq +3 ; if expected_length == max_length
loadi $1 1 ; return true
ret
jmp strcmp_loop
2021-11-12 23:37:02 +00:00
label shift_terminal:
2021-11-13 23:27:56 +00:00
; copy terminal 0 to terminal 1
loadi $4 terminal[2] ;src
bcopy $4 terminal[3] ; dest
2021-11-12 23:37:02 +00:00
; copy terminal 0 to terminal 1
loadi $4 terminal[1] ;src
bcopy $4 terminal[2] ; dest
; copy terminal 0 to terminal 1
loadi $4 terminal[0] ;src
bcopy $4 terminal[1] ; dest
; copy command line to terminal 0
loadi $4 command_line_input ;src
bcopy $4 terminal[0] ; dest
bzero command_line_input
ret
2021-11-13 23:27:56 +00:00
data ascii diss_load LOAD
data ascii diss_call CALL
data ascii diss_unknown UNKNOWN
label _disassemble_cmd:
loadi $1 $20
bappend $1 command_line_input ; space
loadi $1 1c ; 28 bits
shift $4 $1 $2 ;
loadi $5 diss_unknown
loadi $1 $3
jneq +2
loadi $5 diss_load
loadi $1 $C
jneq +2
loadi $5 diss_call
label _disassemble_cmd_inner:
rload $5 $1
loadi $2 0
jneq +2
ret
bappend $1 command_line_input
inc $5
jmp _disassemble_cmd_inner
2021-11-13 06:03:26 +00:00
label disassemble:
2021-11-13 23:27:56 +00:00
call string_to_num
; $1 contains a actual address we want to diss
loadi $2 $FFFFFF;
jlt +2
ret
rload $1 $8 ;
call shift_terminal
bzero command_line_input
loadi $6 7
label _disassemble_inner:
tx $4 $8 ; temp store for command
loadi $5 4 ; number of bits to shift
mul $6 $5 $5 ; number of bits to shift command >> (count * 8) (3*8, 2*8, 1*8, 0*8)
shift $4 $5 $1 ; do the actual shift
loadi $5 $00000F
and $1 $5 $4
; clobbers 1 2 3 4
call num_to_char;
bappend $4 command_line_input
tx $1 $6
loadi $2 0
jneq +4
tx $4 $8
call _disassemble_cmd
ret
dec $6
jmp _disassemble_inner
label jump:
2021-11-13 06:03:26 +00:00
call string_to_num
ijmp $1 ;;lol
ret
label do_shell:
loadi $4 @command_line_input
loadi $5 quit_label
loadi $6 4
call strcmp
loadi $2 1
jneq +2 ; if the command is QUIT, then hlt the machine!! A shell is born
hlt
loadi $4 @command_line_input
loadi $5 diss_label
loadi $6 4
call strcmp
loadi $2 1
2021-11-13 23:27:56 +00:00
jneq +6 ; if the command is QUIT, then hlt the machine!! A shell is born
2021-11-13 06:03:26 +00:00
loadi $4 @command_line_input
loadi $5 5
add $4 $5 $4
call disassemble
2021-11-13 23:27:56 +00:00
ret
loadi $4 @command_line_input
loadi $5 jump_label
loadi $6 4
call strcmp
loadi $2 1
jneq +5 ; if the command is QUIT, then hlt the machine!! A shell is born
loadi $4 @command_line_input
loadi $5 5
add $4 $5 $4
call jump
2021-11-13 06:03:26 +00:00
ret
label handle_keypress:
; Check for Backspace
loadi $1 $7F
tx $2 $4
jneq +3
bdelete $4 command_line_input
ret
; Check for Return
loadi $1 $0A
tx $2 $4
2021-11-13 06:03:26 +00:00
jneq +4
call do_shell
2021-11-12 23:37:02 +00:00
call shift_terminal
ret
2021-11-09 02:19:34 +00:00
bappend $4 command_line_input
ret
2021-11-09 02:19:34 +00:00
; Kernel Begins
@ $CB000:
loadi $9 $0; 640-64
loadi $A $0; 480-64
2021-11-09 02:19:34 +00:00
call set_pos
loadi $4 wallpaper.png
call draw_image
2021-11-09 02:19:34 +00:00
loadi $4 $0
loadi $5 $0
loadi $6 $280
loadi $7 $10
loadi $8 $222222
call draw_filled_rect
2021-11-09 02:19:34 +00:00
loadi $9 $5;
loadi $A $5;
2021-11-09 02:19:34 +00:00
call set_pos
loadi $4 boo_os_version
call draw_string;
2021-11-09 02:19:34 +00:00
loadi $9 $1A0;
loadi $A $5;
call set_pos
loadi $4 label_cycles
2021-11-09 02:19:34 +00:00
call draw_string;
loadi $4 $4B000
loadi $2 $40
add $2 $4 $4
call print_addr
2021-11-09 02:19:34 +00:00
loadi $9 1;
loadi $A 20;
call set_pos
2021-11-12 23:37:02 +00:00
2021-11-09 02:19:34 +00:00
loadi $1 0
load $2 KeyPressedState
store $1 KeyPressedState
jeq +3
tx $4 $2
call handle_keypress
2021-11-13 23:27:56 +00:00
; print some shell history
loadi $9 5;
loadi $A 180;
call set_pos
loadi $4 @terminal[3]
call draw_string;
loadi $9 5;
loadi $A 190;
call set_pos
loadi $4 @terminal[2]
call draw_string;
2021-11-12 23:37:02 +00:00
loadi $9 5;
loadi $A 1A0;
2021-11-09 02:19:34 +00:00
call set_pos
2021-11-12 23:37:02 +00:00
loadi $4 @terminal[1]
call draw_string;
loadi $9 5;
loadi $A 1B0;
call set_pos
loadi $4 @terminal[0]
2021-11-09 02:19:34 +00:00
call draw_string;
2021-11-12 23:37:02 +00:00
loadi $9 5;
loadi $A 1C0;
call set_pos
2021-11-12 23:37:02 +00:00
loadi $4 prompt
call draw_string;
loadi $9 70;
loadi $A 1C0;
call set_pos
loadi $4 @command_line_input
call draw_string;
2021-11-09 02:19:34 +00:00
updsp
clr
jmp $CB000;