kernel/vfs: Support seeking in streams

This commit is contained in:
Ry 2023-03-30 18:14:16 -07:00
parent 713e447d7d
commit b6cde81d2b

View File

@ -9,7 +9,7 @@
; file struct for stream: ; file struct for stream:
; file_reserved_1: 1 byte ; file_reserved_1: 1 byte
; file_reserved_2: 2 bytes ; file_reserved_2: 2 bytes
; file_reserved_4: 4 bytes ; file_seek_offset: 4 bytes
; file_system_type: 1 byte (0x01 for stream) ; file_system_type: 1 byte (0x01 for stream)
; file_read_call: 4 bytes ; file_read_call: 4 bytes
; file_write_call: 4 bytes ; file_write_call: 4 bytes
@ -34,12 +34,7 @@ open:
; outputs: ; outputs:
; none ; none
seek: seek:
push r1 jmp ryfs_seek
add r1, 7
cmp.8 [r1], 0x00
pop r1
ifz jmp ryfs_seek
ret
; get the seek offset of the specified file ; get the seek offset of the specified file
; inputs: ; inputs:
@ -47,12 +42,7 @@ seek:
; outputs: ; outputs:
; r0: byte offset ; r0: byte offset
tell: tell:
push r0 jmp ryfs_tell
add r0, 7
cmp.8 [r0], 0x00
pop r0
ifz jmp ryfs_tell
ret
; read specified number of bytes into the specified buffer ; read specified number of bytes into the specified buffer
; inputs: ; inputs:
@ -100,8 +90,10 @@ stream_read_char:
push r1 push r1
push r2 push r2
; call [file_read_call] ; call [file_read_call] with seek offset in r0
add r1, 8 add r1, 2
mov r0, [r1]
add r1, 6
call [r1] call [r1]
; put the result into [r2] ; put the result into [r2]
@ -150,12 +142,17 @@ stream_write_loop:
stream_write_char: stream_write_char:
push r0 push r0
push r1 push r1
push r3
; call [file_write_call] with pointer to src buf in r0 ; call [file_write_call] with pointer to src buf in r0 and seek offset in r1
add r1, 12 mov r3, r1
add r3, 2
mov r0, r2 mov r0, r2
call [r1] mov r1, [r3]
add r3, 10
call [r3]
pop r3
pop r1 pop r1
pop r0 pop r0
ret ret