Add support for a "romdisk"

This commit is contained in:
Ry 2023-03-04 21:23:14 -08:00
parent 9cfb010116
commit bec78c9a10
3 changed files with 73 additions and 3 deletions

View File

@ -22,12 +22,26 @@ start_boot_process:
mov r0, 0 ; booting from disk id 0 mov r0, 0 ; booting from disk id 0
jmp 0x00000800 jmp 0x00000800
; load the boot sector of the romdisk and jump to it
; inputs:
; none
; outputs:
; none (returns if romdisk is not bootable)
start_boot_process_from_romdisk:
; read sector 0 to 0x800 ; read sector 0 to 0x800
out r1, 0x00000800 mov r0, 0
out r0, 0 mov r1, 4
mov r2, 0x00000800
call read_sector
; check for the bootable magic bytes
cmp [0x000009FC], 0x523C334C
ifnz ret
; now clean up and jump to the loaded binary ; now clean up and jump to the loaded binary
call boot_cleanup call boot_cleanup
mov rsp, SYSTEM_STACK ; reset stack pointer
mov r0, 4 ; booting from disk id 4
jmp 0x00000800 jmp 0x00000800
; clean up the system's state before jumping to the loaded binary ; clean up the system's state before jumping to the loaded binary

View File

@ -10,6 +10,9 @@ const TEMP_SECTOR_BUF: 0x01FFF808
; outputs: ; outputs:
; none ; none
read_sector: read_sector:
cmp.8 r1, 4
ifz jmp read_romdisk_sector
push r3 push r3
push r4 push r4
@ -23,6 +26,49 @@ read_sector:
pop r3 pop r3
ret ret
; read a sector from the romdisk into the specified memory buffer
; inputs:
; r0: sector number
; r2: sector buffer (512 bytes)
; outputs:
; none
read_romdisk_sector:
push r0
push r1
push r2
; source pointer
mul r0, 512
add r0, romdisk_image
; destination pointer
mov r1, r2
; copy 512 bytes
mov r2, 512
call copy_memory_bytes
pop r2
pop r1
pop r0
ret
; check if a RYFS image is included as a romdisk
; inputs:
; none
; outputs:
; Z flag: set if available, reset if not
is_romdisk_available:
push r0
mov r0, romdisk_image
add r0, 514
cmp.16 [r0], 0x5952
pop r0
ret
; write a sector from the specified memory buffer ; write a sector from the specified memory buffer
; inputs: ; inputs:
; r0: sector number ; r0: sector number
@ -31,6 +77,9 @@ read_sector:
; outputs: ; outputs:
; none ; none
write_sector: write_sector:
cmp.8 r1, 4
ifz ret
push r3 push r3
push r4 push r4
@ -42,4 +91,4 @@ write_sector:
pop r4 pop r4
pop r3 pop r3
ret ret

View File

@ -161,6 +161,9 @@ event_loop:
cmp r0, 0 cmp r0, 0
ifnz call start_boot_process ifnz call start_boot_process
call is_romdisk_available
ifz call start_boot_process_from_romdisk
jmp event_loop jmp event_loop
get_rom_version: get_rom_version:
@ -394,5 +397,9 @@ bottom_bar_patterns:
data.32 0xFFFFFFFF data.32 0xFFFFFFFF
data.32 0xFF674764 data.32 0xFF674764
romdisk_image:
#include_bin_optional "romdisk.img"
romdisk_image_end:
; pad out to 512 KiB ; pad out to 512 KiB
org.pad 0xF0080000 org.pad 0xF0080000