sh: Move to an application outside of the kernel

Fixes issue #3
This commit is contained in:
Ry 2023-01-21 00:17:10 -08:00
parent 9a0208fe96
commit 9e256a7e3c
16 changed files with 154 additions and 104 deletions

View File

@ -13,6 +13,9 @@ base_image:
base_image/kernel.fxf: kernel/main.asm base_image/kernel.fxf: kernel/main.asm
$(FOX32ASM) $< $@ $(FOX32ASM) $< $@
base_image/sh.fxf: applications/sh/main.asm
$(FOX32ASM) $< $@
base_image/barclock.fxf: applications/barclock/main.asm base_image/barclock.fxf: applications/barclock/main.asm
$(FOX32ASM) $< $@ $(FOX32ASM) $< $@
@ -36,6 +39,7 @@ bootloader/bootloader.bin: bootloader/main.asm
FILES = \ FILES = \
base_image/kernel.fxf \ base_image/kernel.fxf \
base_image/sh.fxf \
base_image/barclock.fxf \ base_image/barclock.fxf \
base_image/terminal.fxf \ base_image/terminal.fxf \
base_image/foxpaint.fxf \ base_image/foxpaint.fxf \

View File

@ -50,10 +50,10 @@ shell_parse_command:
shell_invalid_command_string: data.str "invalid command or FXF binary" data.8 10 data.8 0 shell_invalid_command_string: data.str "invalid command or FXF binary" data.8 10 data.8 0
; all commands ; all commands
#include "shell/commands/clear.asm" #include "commands/clear.asm"
#include "shell/commands/dir.asm" #include "commands/dir.asm"
#include "shell/commands/disk.asm" #include "commands/disk.asm"
#include "shell/commands/diskrm.asm" #include "commands/diskrm.asm"
#include "shell/commands/exit.asm" #include "commands/exit.asm"
#include "shell/commands/help.asm" #include "commands/help.asm"
#include "shell/commands/type.asm" #include "commands/type.asm"

View File

@ -38,7 +38,7 @@ launch_fxf_name_loop_done:
mov r0, launch_fxf_name mov r0, launch_fxf_name
movz.8 r1, [shell_current_disk] movz.8 r1, [shell_current_disk]
mov r2, launch_fxf_struct mov r2, launch_fxf_struct
call ryfs_open call open
cmp r0, 0 cmp r0, 0
ifz ret ifz ret

View File

@ -1,90 +1,8 @@
; shell routines ; fox32os shell
const CURSOR: 0x8A const CURSOR: 0x8A
const REDRAW_LINE: 0xFE const REDRAW_LINE: 0xFE
; create a new shell task
; inputs:
; r0: task ID
; r1: pointer to stream struct
; outputs:
; none
new_shell_task:
push r0
push r1
push r2
push r3
push r4
push r10
; allocate a 64KiB stack and push the pointer to the stream struct to it
push r0
push r1
mov r0, 65536
call allocate_memory
add r0, 65532
pop r1
mov [r0], r1
mov r10, r0
pop r0
; then start the task
mov r1, shell_task ; initial instruction pointer
mov r2, r10 ; initial stack pointer
mov r3, 0 ; pointer to task code block to free when task ends
; (zero since we don't want to free any code blocks when the task ends)
mov r4, r10 ; pointer to task stack block to free when task ends
sub r4, 65536 ; point to the start of the stack block that we allocated above
call new_task
pop r10
pop r4
pop r3
pop r2
pop r1
pop r0
ret
; print a character to the terminal
; inputs:
; r0: ASCII character
; outputs:
; none
print_character_to_terminal:
push r1
push r2
mov.8 [shell_char_buffer], r0
mov r1, [shell_terminal_stream_struct_ptr]
mov r2, shell_char_buffer
call write
pop r2
pop r1
ret
; print a string to the terminal
; inputs:
; r0: pointer to null-terminated string
; outputs:
; none
print_str_to_terminal:
push r0
push r2
mov r1, [shell_terminal_stream_struct_ptr]
mov r2, r0
print_str_to_terminal_loop:
call write
inc r2
cmp.8 [r2], 0x00
ifnz jmp print_str_to_terminal_loop
pop r2
pop r0
ret
shell_task:
pop [shell_terminal_stream_struct_ptr] pop [shell_terminal_stream_struct_ptr]
shell_task_return: shell_task_return:
call shell_clear_buffer call shell_clear_buffer
@ -309,6 +227,45 @@ shell_clear_buffer:
pop r0 pop r0
ret ret
; print a character to the terminal
; inputs:
; r0: ASCII character
; outputs:
; none
print_character_to_terminal:
push r1
push r2
mov.8 [shell_char_buffer], r0
mov r1, [shell_terminal_stream_struct_ptr]
mov r2, shell_char_buffer
call write
pop r2
pop r1
ret
; print a string to the terminal
; inputs:
; r0: pointer to null-terminated string
; outputs:
; none
print_str_to_terminal:
push r0
push r2
mov r1, [shell_terminal_stream_struct_ptr]
mov r2, r0
print_str_to_terminal_loop:
call write
inc r2
cmp.8 [r2], 0x00
ifnz jmp print_str_to_terminal_loop
pop r2
pop r0
ret
shell_text_buf_bottom: data.fill 0, 512 shell_text_buf_bottom: data.fill 0, 512
shell_text_buf_top: shell_text_buf_top:
shell_text_buf_ptr: data.32 0 ; pointer to the current input character shell_text_buf_ptr: data.32 0 ; pointer to the current input character
@ -321,5 +278,9 @@ shell_prompt: data.str "> " data.8 CURSOR data.8 0
shell_terminal_stream_struct_ptr: data.32 0 shell_terminal_stream_struct_ptr: data.32 0
shell_char_buffer: data.32 0 shell_char_buffer: data.32 0
#include "shell/commands/commands.asm" #include "commands/commands.asm"
#include "shell/launch.asm" #include "launch.asm"
; include system defs
#include "../../../fox32rom/fox32rom.def"
#include "../../fox32os.def"

View File

@ -1,5 +1,6 @@
; terminal ; terminal
; create the window
mov r0, window_struct mov r0, window_struct
mov r1, window_title mov r1, window_title
mov r2, 320 mov r2, 320
@ -10,6 +11,7 @@
mov r7, 0 mov r7, 0
call new_window call new_window
; start an instance of sh.fxf
call get_unused_task_id call get_unused_task_id
mov.8 [shell_task_id], r0 mov.8 [shell_task_id], r0
mov r1, stream_struct mov r1, stream_struct
@ -103,6 +105,7 @@ stream_struct:
data.32 stream_write_to_terminal data.32 stream_write_to_terminal
#include "stream.asm" #include "stream.asm"
#include "task.asm"
#include "text.asm" #include "text.asm"
; include system defs ; include system defs

View File

@ -0,0 +1,69 @@
; sh.fxf launching routines
; start an instance of sh.fxf
; inputs:
; r0: task ID
; r1: pointer to stream struct
; outputs:
; none
new_shell_task:
push r0
push r1
; open the file
mov r0, sh_fxf_name
mov r1, 0
mov r2, sh_fxf_struct
call open
cmp r0, 0
ifz jmp sh_fxf_missing
; allocate memory for the binary
mov r0, sh_fxf_struct
call ryfs_get_size
call allocate_memory
cmp r0, 0
ifz jmp sh_fxf_missing
mov [sh_fxf_binary_ptr], r0
; read the file into memory
mov r0, sh_fxf_struct
mov r1, [sh_fxf_binary_ptr]
call ryfs_read_whole_file
; allocate a 64KiB stack
mov r0, 65536
call allocate_memory
cmp r0, 0
ifz jmp sh_fxf_missing
mov [sh_fxf_stack_ptr], r0
; push the stream struct pointer to the shell's stack
add r0, 65532
pop r1
mov [r0], r1
mov r10, r0
; relocate the binary
mov r0, [sh_fxf_binary_ptr]
call parse_fxf_binary
; then start the task
mov r1, r0 ; initial instruction pointer
pop r0 ; task ID
mov r2, r10 ; initial stack pointer
mov r3, [sh_fxf_binary_ptr] ; pointer to task code block to free when task ends
mov r4, [sh_fxf_stack_ptr] ; pointer to task stack block to free when task ends
call new_task
ret
sh_fxf_missing:
mov r0, sh_fxf_missing_str
call print_str_to_terminal
rjmp 0
sh_fxf_name: data.str "sh fxf"
sh_fxf_struct: data.fill 0, 8
sh_fxf_missing_str: data.str "sh could not be launched!" data.8 0
sh_fxf_binary_ptr: data.32 0
sh_fxf_stack_ptr: data.32 0

View File

@ -11,6 +11,27 @@ const MOVE_CURSOR: 0xF1
const REDRAW_LINE: 0xFE const REDRAW_LINE: 0xFE
const REDRAW: 0xFF const REDRAW: 0xFF
; print a string to the terminal
; inputs:
; r0: pointer to null-terminated string
; outputs:
; none
print_str_to_terminal:
push r0
push r1
mov r1, r0
print_str_to_terminal_loop:
movz.8 r0, [r1]
call print_character_to_terminal
inc r1
cmp.8 [r1], 0x00
ifnz jmp print_str_to_terminal_loop
pop r1
pop r0
ret
; print a single character to the terminal ; print a single character to the terminal
; inputs: ; inputs:
; r0: ASCII character or control character ; r0: ASCII character or control character

View File

@ -36,12 +36,9 @@ tell: jmp [0x00000D18]
read: jmp [0x00000D1C] read: jmp [0x00000D1C]
write: jmp [0x00000D20] write: jmp [0x00000D20]
; shell jump table
new_shell_task: jmp [0x00000E10]
; widget jump table ; widget jump table
draw_widgets_to_window: jmp [0x00000F10] draw_widgets_to_window: jmp [0x00000E10]
handle_widget_click: jmp [0x00000F14] handle_widget_click: jmp [0x00000E14]
; event types ; event types
const EVENT_TYPE_BUTTON_CLICK: 0x80000000 const EVENT_TYPE_BUTTON_CLICK: 0x80000000

View File

@ -53,12 +53,8 @@ jump_table:
data.32 read data.32 read
data.32 write data.32 write
; shell jump table
org.pad 0x00000610
data.32 new_shell_task
; widget jump table ; widget jump table
org.pad 0x00000710 org.pad 0x00000610
data.32 draw_widgets_to_window data.32 draw_widgets_to_window
data.32 handle_widget_click data.32 handle_widget_click
jump_table_end: jump_table_end:
@ -302,7 +298,6 @@ get_os_version:
#include "allocator.asm" #include "allocator.asm"
#include "fxf/fxf.asm" #include "fxf/fxf.asm"
#include "shell/shell.asm"
#include "task.asm" #include "task.asm"
#include "widget/widget.asm" #include "widget/widget.asm"
#include "window/window.asm" #include "window/window.asm"