Build the kernel as an FXF binary and boot using the new boot mechanism

main
Ry 2022-10-27 22:49:55 -07:00
parent cc40cce81b
commit a7064075e7
5 changed files with 121 additions and 14 deletions

1
.gitignore vendored
View File

@ -1,7 +1,6 @@
**/.vscode/
**/system.bin
**/*.fxf
**/wallpaper.inc
**/wallpapr.raw

View File

@ -0,0 +1,38 @@
; fox32os bootloader
org 0x00000800
const LOAD_ADDRESS: 0x03000000
; open kernel.fxf
mov r0, kernel_file_name
movz.8 r1, 0
mov r2, kernel_file_struct
call [0xF0045008] ; ryfs_open
cmp r0, 0
ifz jmp error
; load it into memory
mov r0, kernel_file_struct
mov r1, LOAD_ADDRESS
call [0xF0045014] ; ryfs_read_whole_file
; relocate it and off we go!!
mov r0, LOAD_ADDRESS
call fxf_reloc
jmp r0
error:
mov r0, error_str
movz.8 r1, 16
movz.8 r2, 16
mov r3, 0xFFFFFFFF
movz.8 r4, 0
call [0xF0042004] ; draw_str_to_background
rjmp 0
kernel_file_name: data.str "kernel fxf" data.8 0
kernel_file_struct: data.32 0 data.32 0
error_str: data.str "failed to open kernel.fxf" data.8 0
#include "reloc.asm"

View File

@ -0,0 +1,58 @@
; FXF relocation routines
const FXF_CODE_SIZE: 0x00000004
const FXF_CODE_PTR: 0x00000008
const FXF_RELOC_SIZE: 0x0000000C
const FXF_RELOC_PTR: 0x00000010
; relocate a FXF binary
; inputs:
; r0: pointer to memory buffer containing a FXF binary
; outputs:
; r0: relocation address
fxf_reloc:
; calculate relocation address
mov r5, r0
add r5, FXF_CODE_PTR
mov r5, [r5]
add r5, r0
; get the number of entries in the reloc table
mov r1, r0
add r1, FXF_RELOC_SIZE
mov r1, [r1]
div r1, 4
mov r31, r1
; get the pointer to the table
mov r1, r0
add r1, FXF_RELOC_PTR
mov r1, [r1]
add r1, r0
; get the pointer to the code
mov r2, r0
add r2, FXF_CODE_PTR
mov r2, [r2]
add r2, r0
; loop over the reloc table entries and relocate the code
fxf_reloc_loop:
; get the reloc table entry
mov r3, [r1]
; point to the location in the code
mov r4, r2
add r4, r3
; relocate
add [r4], r5
; increment the reloc table pointer
add r1, 4
loop fxf_reloc_loop
; return relocation address
mov r0, r5
ret

View File

@ -7,11 +7,17 @@ mkdir -p base_image
# if fox32os.img doesn't exist, then create it
if [ ! -f fox32os.img ]; then
echo "fox32os.img not found, creating it"
meta/ryfs/ryfs.py -s 16777216 -l fox32os create fox32os.img
echo "assembling bootloader"
../fox32asm/target/release/fox32asm bootloader/main.asm bootloader/bootloader.bin
meta/ryfs/ryfs.py -s 16777216 -l fox32os -b bootloader/bootloader.bin create fox32os.img
rm bootloader/bootloader.bin
fi
echo "assembling kernel"
../fox32asm/target/release/fox32asm kernel/main.asm base_image/system.bin
../fox32asm/target/release/fox32asm kernel/main.asm base_image/kernel.fxf
echo "assembling launcher"
../fox32asm/target/release/fox32asm launcher/main.asm base_image/launcher.fxf

View File

@ -1,10 +1,8 @@
; fox32os kernel
org 0x00000800
const FOX32OS_VERSION_MAJOR: 0
const FOX32OS_VERSION_MINOR: 1
const FOX32OS_VERSION_PATCH: 0
const FOX32OS_VERSION_PATCH: 1
const SYSTEM_STACK: 0x01FFF800
const BACKGROUND_COLOR: 0xFF674764
@ -12,17 +10,17 @@ const TEXT_COLOR: 0xFFFFFFFF
jmp entry
jump_table:
; system jump table
org.pad 0x00000810
org.pad 0x00000010
jump_table:
data.32 get_os_version
; FXF jump table
org.pad 0x00000910
org.pad 0x00000110
data.32 parse_fxf_binary
; task jump table
org.pad 0x00000A10
org.pad 0x00000210
data.32 new_task
data.32 yield_task
data.32 end_current_task
@ -31,12 +29,12 @@ jump_table:
data.32 is_task_id_used
; memory jump table
org.pad 0x00000B10
org.pad 0x00000310
data.32 allocate_memory
data.32 free_memory
; window jump table
org.pad 0x00000C10
org.pad 0x00000410
data.32 new_window
data.32 destroy_window
data.32 new_window_event
@ -48,7 +46,7 @@ jump_table:
data.32 start_dragging_window
; VFS jump table
org.pad 0x00000D10
org.pad 0x00000510
data.32 open
data.32 seek
data.32 tell
@ -56,8 +54,9 @@ jump_table:
data.32 write
; shell jump table
org.pad 0x00000E10
org.pad 0x00000610
data.32 new_shell_task
jump_table_end:
; initialization code
entry:
@ -81,6 +80,13 @@ entry:
mov r12, FOX32OS_VERSION_PATCH
call draw_format_str_to_background
; copy the jump table to 0x00000810
mov r0, jump_table
mov r1, 0x00000810
mov r2, jump_table_end
sub r2, jump_table
call copy_memory_bytes
; check if a disk is inserted as disk 1
; if so, skip checking startup.cfg and just run disk 1
in r31, 0x80001001