Skip to content

Commit

Permalink
kernel + sh: Theoretically support FXF binaries with a bss section
Browse files Browse the repository at this point in the history
  • Loading branch information
ry755 committed May 24, 2024
1 parent 96702b7 commit 70ee5cf
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 13 deletions.
27 changes: 27 additions & 0 deletions applications/sh/launch.asm
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
; FXF launcher helper routines

; FIXME: this should really use the `launch_fxf_from_open_file` routine
; it will need some work to ensure things like the debug prefix works though

; launch an FXF binary from a shell entry
; inputs:
; r0: pointer to FXF binary name
Expand Down Expand Up @@ -65,9 +68,32 @@ launch_fxf_name_loop_done:
cmp r0, 0
ifz ret

; if this is not FXF version 0, then there is a bss section
mov r0, 3
mov r1, launch_fxf_struct
call seek
mov r0, 1
mov r1, launch_fxf_struct
mov r2, launch_fxf_temp
call read
cmp.8 [launch_fxf_temp], 0
ifz mov [launch_fxf_temp], 0
ifz jmp launch_fxf_continue
mov r0, 0x14
mov r1, launch_fxf_struct
call seek
mov r0, 4
mov r1, launch_fxf_struct
mov r2, launch_fxf_temp
call read
launch_fxf_continue:
mov r0, 0
mov r1, launch_fxf_struct
call seek
; allocate memory for the binary
mov r0, launch_fxf_struct
call get_size
add r0, [launch_fxf_temp] ; add bss size found above
call allocate_memory
cmp r0, 0
ifz jmp allocate_error
Expand Down Expand Up @@ -164,6 +190,7 @@ launch_fxf_struct: data.fill 0, 32
launch_fxf_task_id: data.8 0
launch_fxf_binary_ptr: data.32 0
launch_fxf_stack_ptr: data.32 0
launch_fxf_temp: data.32 0

launch_fxf_yield_should_suspend: data.8 0
launch_fxf_debug_mode: data.8 0
Expand Down
17 changes: 9 additions & 8 deletions kernel/fxf/FXF specification.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
| Byte Range | Description |
| :-------------------: | -------------------------- |
| 0x00000000-0x00000002 | "FXF" magic bytes |
| 0x00000003 | header version (must be 0) |
| 0x00000004-0x00000007 | code size |
| 0x00000008-0x0000000B | pointer to code |
| 0x0000000C-0x0000000F | reloc table size |
| 0x00000010-0x00000013 | pointer to reloc table |
| Byte Range | Description |
| :-------------------: | --------------------------------------- |
| 0x00000000-0x00000002 | "FXF" magic bytes |
| 0x00000003 | header version (0 for no bss, else bss) |
| 0x00000004-0x00000007 | code size |
| 0x00000008-0x0000000B | pointer to code |
| 0x0000000C-0x0000000F | reloc table size |
| 0x00000010-0x00000013 | pointer to reloc table |
| 0x00000014-0x00000017 | bss allocation size (if version != 0) |
13 changes: 8 additions & 5 deletions kernel/fxf/fxf.asm
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@
; r0: relocation address or 0 on error
parse_fxf_binary:
push r1
mov r1, [r0]
cmp r1, [fxf_magic]
ifnz pop r1
push r2
mov r1, fxf_magic
mov r2, 3
call compare_memory_bytes
pop r2
pop r1
ifnz mov r0, 0
ifnz ret
pop r1

call fxf_reloc

ret

fxf_magic: data.strz "FXF"
fxf_magic: data.str "FXF"

#include "fxf/launch.asm"
#include "fxf/reloc.asm"
Expand All @@ -27,3 +29,4 @@ const FXF_CODE_SIZE: 0x00000004
const FXF_CODE_PTR: 0x00000008
const FXF_RELOC_SIZE: 0x0000000C
const FXF_RELOC_PTR: 0x00000010
const FXF_BSS_SIZE: 0x00000014
24 changes: 24 additions & 0 deletions kernel/fxf/launch.asm
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,32 @@ launch_fxf_from_disk:
cmp r0, 0
ifz jmp launch_fxf_from_disk_file_error
launch_fxf_from_open_file_1:
; if this is not FXF version 0, then there is a bss section
mov r0, 3
mov r1, [launch_fxf_struct_ptr]
call seek
mov r0, 1
mov r1, [launch_fxf_struct_ptr]
mov r2, launch_fxf_bss_size
call read
cmp.8 [launch_fxf_bss_size], 0
ifz mov [launch_fxf_bss_size], 0
ifz jmp launch_fxf_continue
mov r0, FXF_BSS_SIZE
mov r1, [launch_fxf_struct_ptr]
call seek
mov r0, 4
mov r1, [launch_fxf_struct_ptr]
mov r2, launch_fxf_bss_size
call read
launch_fxf_continue:
mov r0, 0
mov r1, [launch_fxf_struct_ptr]
call seek
; allocate memory for the binary
mov r0, [launch_fxf_struct_ptr]
call get_size
add r0, [launch_fxf_bss_size]
call allocate_memory
cmp r0, 0
ifz jmp launch_fxf_from_disk_allocate_error
Expand Down Expand Up @@ -165,6 +188,7 @@ launch_fxf_struct: data.fill 0, 32
launch_fxf_task_id: data.8 0
launch_fxf_binary_ptr: data.32 0
launch_fxf_stack_ptr: data.32 0
launch_fxf_bss_size: data.32 0
launch_fxf_allocate_error_string1: data.strz "Failed to allocate memory for a new task"
launch_fxf_allocate_error_string2: data.strz "The memory allocator seems to be in an"
launch_fxf_allocate_error_string3: data.strz "invalid state, a reboot is recommended"

0 comments on commit 70ee5cf

Please sign in to comment.