kernel/vfs: Named streams for all disks and overlay framebuffers

This commit is contained in:
Ry 2023-07-13 16:05:17 -07:00
parent b6ab015acb
commit ca802706f4
7 changed files with 625 additions and 11 deletions

93
kernel/vfs/disk0.asm Normal file
View File

@ -0,0 +1,93 @@
; disk vfs stream routines
disk0_vfs_stream_name: data.strz "disk0"
; open a disk id 0 stream
; inputs:
; r2: file struct: pointer to a blank file struct (stream)
; outputs:
; r0: non-zero
open_stream_disk0:
push r2
mov.8 [r2], 0 ; write file_reserved_1
inc r2
mov.16 [r2], 0 ; write file_reserved_2
add r2, 2
mov [r2], 0 ; write file_seek_offset
add r2, 4
mov.8 [r2], 1 ; write file_system_type
inc r2
mov [r2], disk0_stream_read ; write file_read_call
add r2, 4
mov [r2], disk0_stream_write ; write file_write_call
add r2, 4
in [r2], 0x80001000 ; write file_size
add r2, 4
mov [r2], 0 ; write file_reserved_3
add r2, 4
mov [r2], 0 ; write file_reserved_4
add r2, 4
mov [r2], 0 ; write file_reserved_5
pop r2
mov r0, 1
ret
; read a byte from disk 0
; inputs:
; r0: seek offset
; outputs:
; r0: byte
disk0_stream_read:
push r1
push r2
push r0
div r0, 512
mov r1, 0
mov r2, TEMP_SECTOR_BUF
call read_sector
pop r0
rem r0, 512
add r0, TEMP_SECTOR_BUF
movz.8 r0, [r0]
pop r2
pop r1
ret
; write a byte to disk 0
; inputs:
; r0: pointer to source buffer
; r1: seek offset
; outputs:
; none
disk0_stream_write:
push r0
push r1
push r2
push r0
push r1
div r1, 512
mov r0, r1
mov r1, 0
mov r2, TEMP_SECTOR_BUF
call read_sector
pop r1
pop r0
push r1
rem r1, 512
add r1, TEMP_SECTOR_BUF
mov.8 [r1], [r0]
pop r0
div r0, 512
mov r1, 0
mov r2, TEMP_SECTOR_BUF
call write_sector
pop r2
pop r1
pop r0
ret

93
kernel/vfs/disk1.asm Normal file
View File

@ -0,0 +1,93 @@
; disk vfs stream routines
disk1_vfs_stream_name: data.strz "disk1"
; open a disk id 1 stream
; inputs:
; r2: file struct: pointer to a blank file struct (stream)
; outputs:
; r0: non-zero
open_stream_disk1:
push r2
mov.8 [r2], 0 ; write file_reserved_1
inc r2
mov.16 [r2], 0 ; write file_reserved_2
add r2, 2
mov [r2], 0 ; write file_seek_offset
add r2, 4
mov.8 [r2], 1 ; write file_system_type
inc r2
mov [r2], disk1_stream_read ; write file_read_call
add r2, 4
mov [r2], disk1_stream_write ; write file_write_call
add r2, 4
in [r2], 0x80001001 ; write file_size
add r2, 4
mov [r2], 0 ; write file_reserved_3
add r2, 4
mov [r2], 0 ; write file_reserved_4
add r2, 4
mov [r2], 0 ; write file_reserved_5
pop r2
mov r0, 1
ret
; read a byte from disk 1
; inputs:
; r0: seek offset
; outputs:
; r0: byte
disk1_stream_read:
push r1
push r2
push r0
div r0, 512
mov r1, 1
mov r2, TEMP_SECTOR_BUF
call read_sector
pop r0
rem r0, 512
add r0, TEMP_SECTOR_BUF
movz.8 r0, [r0]
pop r2
pop r1
ret
; write a byte to disk 1
; inputs:
; r0: pointer to source buffer
; r1: seek offset
; outputs:
; none
disk1_stream_write:
push r0
push r1
push r2
push r0
push r1
div r1, 512
mov r0, r1
mov r1, 1
mov r2, TEMP_SECTOR_BUF
call read_sector
pop r1
pop r0
push r1
rem r1, 512
add r1, TEMP_SECTOR_BUF
mov.8 [r1], [r0]
pop r0
div r0, 512
mov r1, 1
mov r2, TEMP_SECTOR_BUF
call write_sector
pop r2
pop r1
pop r0
ret

93
kernel/vfs/disk2.asm Normal file
View File

@ -0,0 +1,93 @@
; disk vfs stream routines
disk2_vfs_stream_name: data.strz "disk2"
; open a disk id 2 stream
; inputs:
; r2: file struct: pointer to a blank file struct (stream)
; outputs:
; r0: non-zero
open_stream_disk2:
push r2
mov.8 [r2], 0 ; write file_reserved_1
inc r2
mov.16 [r2], 0 ; write file_reserved_2
add r2, 2
mov [r2], 0 ; write file_seek_offset
add r2, 4
mov.8 [r2], 1 ; write file_system_type
inc r2
mov [r2], disk2_stream_read ; write file_read_call
add r2, 4
mov [r2], disk2_stream_write ; write file_write_call
add r2, 4
in [r2], 0x80001002 ; write file_size
add r2, 4
mov [r2], 0 ; write file_reserved_3
add r2, 4
mov [r2], 0 ; write file_reserved_4
add r2, 4
mov [r2], 0 ; write file_reserved_5
pop r2
mov r0, 1
ret
; read a byte from disk 2
; inputs:
; r0: seek offset
; outputs:
; r0: byte
disk2_stream_read:
push r1
push r2
push r0
div r0, 512
mov r1, 2
mov r2, TEMP_SECTOR_BUF
call read_sector
pop r0
rem r0, 512
add r0, TEMP_SECTOR_BUF
movz.8 r0, [r0]
pop r2
pop r1
ret
; write a byte to disk 2
; inputs:
; r0: pointer to source buffer
; r1: seek offset
; outputs:
; none
disk2_stream_write:
push r0
push r1
push r2
push r0
push r1
div r1, 512
mov r0, r1
mov r1, 2
mov r2, TEMP_SECTOR_BUF
call read_sector
pop r1
pop r0
push r1
rem r1, 512
add r1, TEMP_SECTOR_BUF
mov.8 [r1], [r0]
pop r0
div r0, 512
mov r1, 2
mov r2, TEMP_SECTOR_BUF
call write_sector
pop r2
pop r1
pop r0
ret

93
kernel/vfs/disk3.asm Normal file
View File

@ -0,0 +1,93 @@
; disk vfs stream routines
disk3_vfs_stream_name: data.strz "disk3"
; open a disk id 3 stream
; inputs:
; r2: file struct: pointer to a blank file struct (stream)
; outputs:
; r0: non-zero
open_stream_disk3:
push r2
mov.8 [r2], 0 ; write file_reserved_1
inc r2
mov.16 [r2], 0 ; write file_reserved_2
add r2, 2
mov [r2], 0 ; write file_seek_offset
add r2, 4
mov.8 [r2], 1 ; write file_system_type
inc r2
mov [r2], disk3_stream_read ; write file_read_call
add r2, 4
mov [r2], disk3_stream_write ; write file_write_call
add r2, 4
in [r2], 0x80001003 ; write file_size
add r2, 4
mov [r2], 0 ; write file_reserved_3
add r2, 4
mov [r2], 0 ; write file_reserved_4
add r2, 4
mov [r2], 0 ; write file_reserved_5
pop r2
mov r0, 1
ret
; read a byte from disk 3
; inputs:
; r0: seek offset
; outputs:
; r0: byte
disk3_stream_read:
push r1
push r2
push r0
div r0, 512
mov r1, 3
mov r2, TEMP_SECTOR_BUF
call read_sector
pop r0
rem r0, 512
add r0, TEMP_SECTOR_BUF
movz.8 r0, [r0]
pop r2
pop r1
ret
; write a byte to disk 3
; inputs:
; r0: pointer to source buffer
; r1: seek offset
; outputs:
; none
disk3_stream_write:
push r0
push r1
push r2
push r0
push r1
div r1, 512
mov r0, r1
mov r1, 3
mov r2, TEMP_SECTOR_BUF
call read_sector
pop r1
pop r0
push r1
rem r1, 512
add r1, TEMP_SECTOR_BUF
mov.8 [r1], [r0]
pop r0
div r0, 512
mov r1, 3
mov r2, TEMP_SECTOR_BUF
call write_sector
pop r2
pop r1
pop r0
ret

132
kernel/vfs/ofb.asm Normal file
View File

@ -0,0 +1,132 @@
; overlay framebuffer vfs stream routines
overlay_vfs_stream_name: data.strz "ofb"
; open an overlay framebuffer stream
; inputs:
; r0: pointer to null-terminated string "ofbXX" where XX is 0 - 31
; r2: file struct: pointer to a blank file struct (stream)
; outputs:
; r0: non-zero
open_stream_ofb:
push r1
push r2
add r0, 3
mov r1, 10
call string_to_int
mov.8 [r2], r0 ; write file_overlay
inc r2
mov.16 [r2], 0 ; write file_reserved_2
add r2, 2
mov [r2], 0 ; write file_seek_offset
add r2, 4
mov.8 [r2], 1 ; write file_system_type
inc r2
mov [r2], ofb_stream_read ; write file_read_call
add r2, 4
mov [r2], ofb_stream_write ; write file_write_call
add r2, 4
or r0, 0x80000100
in r0, r0
mov r1, r0
srl r1, 16
mul r1, r0
mov [r2], r1 ; write file_size
add r2, 4
mov [r2], 0 ; write file_reserved_3
add r2, 4
mov [r2], 0 ; write file_reserved_4
add r2, 4
mov [r2], 0 ; write file_reserved_5
pop r2
pop r1
mov r0, 1
ret
; read a byte from an overlay framebuffer
; inputs:
; r0: seek offset
; r1: pointer to file struct + 8
; outputs:
; r0: byte
ofb_stream_read:
push r1
push r2
; get overlay framebuffer pointer in r2
sub r1, 8 ; point to file_overlay (file_reserved_1)
movz.8 r1, [r1]
or r1, 0x80000200
in r2, r1
; get overlay size in r1
sub r1, 0x100
in r1, r1
push r0
mov r0, r1
srl r0, 16
and r1, 0x0000FFFF
mul r1, r0
mul r0, 4
pop r0
; ensure the seek offset is less than the overlay size
cmp r0, r1
ifgteq mov r0, r1
ifgteq dec r0
; fetch the byte
add r0, r2
movz.8 r0, [r0]
pop r2
pop r1
ret
; write a byte to an overlay framebuffer
; inputs:
; r0: pointer to source buffer
; r1: seek offset
; r3: pointer to file struct + 12
; outputs:
; none
ofb_stream_write:
push r1
push r2
push r3
push r4
; get overlay framebuffer pointer in r2
sub r3, 12 ; point to file_overlay (file_reserved_1)
movz.8 r3, [r3]
or r3, 0x80000200
in r2, r3
; get overlay size in r4
sub r3, 0x100
in r4, r3
push r0
mov r0, r4
srl r0, 16
and r4, 0x0000FFFF
mul r4, r0
mul r4, 4
pop r0
; ensure the seek offset is less than the overlay size
cmp r1, r4
ifgteq mov r1, r4
ifgteq dec r1
; write the byte
add r2, r1
mov.8 [r2], [r0]
pop r4
pop r3
pop r2
pop r1
ret

67
kernel/vfs/romdisk.asm Normal file
View File

@ -0,0 +1,67 @@
; disk vfs stream routines
romdisk_vfs_stream_name: data.strz "romdisk"
; open a disk id 4 stream
; inputs:
; r2: file struct: pointer to a blank file struct (stream)
; outputs:
; r0: non-zero
open_stream_romdisk:
push r2
mov.8 [r2], 0 ; write file_reserved_1
inc r2
mov.16 [r2], 0 ; write file_reserved_2
add r2, 2
mov [r2], 0 ; write file_seek_offset
add r2, 4
mov.8 [r2], 1 ; write file_system_type
inc r2
mov [r2], romdisk_stream_read ; write file_read_call
add r2, 4
mov [r2], romdisk_stream_write ; write file_write_call
add r2, 4
mov [r2], 65536 ; write file_size
add r2, 4
mov [r2], 0 ; write file_reserved_3
add r2, 4
mov [r2], 0 ; write file_reserved_4
add r2, 4
mov [r2], 0 ; write file_reserved_5
pop r2
mov r0, 1
ret
; read a byte from disk 4
; inputs:
; r0: seek offset
; outputs:
; r0: byte
romdisk_stream_read:
push r1
push r2
push r0
div r0, 512
mov r1, 4
mov r2, TEMP_SECTOR_BUF
call read_sector
pop r0
rem r0, 512
add r0, TEMP_SECTOR_BUF
movz.8 r0, [r0]
pop r2
pop r1
ret
; write a byte to disk 4
; inputs:
; r0: pointer to source buffer
; r1: seek offset
; outputs:
; none
romdisk_stream_write:
ret

View File

@ -1,5 +1,7 @@
; virtual filesystem routines
const TEMP_SECTOR_BUF: 0x01FFF808
; file struct for file:
; file_disk: 1 byte
; file_first_sector: 2 bytes
@ -44,12 +46,51 @@ open_stream:
inc r0
; disk0
mov r1, disk0_vfs_stream_name
call compare_string
ifz pop r1
ifz jmp open_stream_disk0
; disk1
mov r1, disk1_vfs_stream_name
call compare_string
ifz pop r1
ifz jmp open_stream_disk1
; disk2
mov r1, disk2_vfs_stream_name
call compare_string
ifz pop r1
ifz jmp open_stream_disk2
; disk3
mov r1, disk3_vfs_stream_name
call compare_string
ifz pop r1
ifz jmp open_stream_disk3
; fb
mov r1, framebuffer_vfs_stream_name
call compare_string
ifz pop r1
ifz jmp open_stream_fb
; ofb0 - ofb31
push r2
mov r1, overlay_vfs_stream_name
mov r2, 3
call compare_memory_bytes
pop r2
ifz pop r1
ifz jmp open_stream_ofb
; romdisk
mov r1, romdisk_vfs_stream_name
call compare_string
ifz pop r1
ifz jmp open_stream_romdisk
; serial
mov r1, serial_vfs_stream_name
call compare_string
@ -130,11 +171,7 @@ stream_read:
stream_read_loop:
call stream_read_char
push r0
push r2
call yield_task
pop r2
pop r0
call save_state_and_yield_task
inc r2
dec r0
@ -150,9 +187,9 @@ stream_read_char:
push r2
; call [file_read_call] with seek offset in r0
add r1, 2
add r1, 3
mov r0, [r1]
add r1, 6
add r1, 5
call [r1]
; put the result into [r2]
@ -160,7 +197,7 @@ stream_read_char:
mov.8 [r2], r0
; increment the seek offset
sub r1, 6
sub r1, 5
inc [r1]
pop r1
@ -208,14 +245,14 @@ stream_write_char:
; call [file_write_call] with pointer to src buf in r0 and seek offset in r1
mov r3, r1
add r3, 2
add r3, 3
mov r0, r2
mov r1, [r3]
add r3, 10
add r3, 9
call [r3]
; increment the seek offset
sub r3, 10
sub r3, 9
inc [r3]
pop r3
@ -307,5 +344,11 @@ convert_filename_fail:
convert_filename_output_string: data.fill 0, 12
; named streams
#include "vfs/disk0.asm"
#include "vfs/disk1.asm"
#include "vfs/disk2.asm"
#include "vfs/disk3.asm"
#include "vfs/fb.asm"
#include "vfs/ofb.asm"
#include "vfs/romdisk.asm"
#include "vfs/serial.asm"