kernel/vfs: Add :serial named stream

This commit is contained in:
Ry 2023-04-02 13:08:55 -07:00
parent d3c75a7c9c
commit 3870289252
2 changed files with 62 additions and 0 deletions

55
kernel/vfs/serial.asm Normal file
View File

@ -0,0 +1,55 @@
; serial vfs stream routines
serial_vfs_stream_name: data.strz "serial"
; open a serial port stream
; inputs:
; r2: file struct: pointer to a blank file struct (stream)
; outputs:
; r0: non-zero
open_stream_serial:
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], serial_stream_read ; write file_read_call
add r2, 4
mov [r2], serial_stream_write ; write file_write_call
add r2, 4
mov [r2], 0 ; 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 the serial port
; inputs:
; r0: seek offset (unused)
; outputs:
; r0: byte
serial_stream_read:
in r0, 0
ret
; write a byte to the serial port
; inputs:
; r0: pointer to source buffer
; r1: seek offset (unused)
; outputs:
; none
serial_stream_write:
movz.8 r1, [r0]
out 0, r1
ret

View File

@ -50,6 +50,12 @@ open_stream:
ifz pop r1 ifz pop r1
ifz jmp open_stream_fb ifz jmp open_stream_fb
; serial
mov r1, serial_vfs_stream_name
call compare_string
ifz pop r1
ifz jmp open_stream_serial
pop r1 pop r1
mov r0, 0 mov r0, 0
ret ret
@ -302,3 +308,4 @@ convert_filename_output_string: data.fill 0, 12
; named streams ; named streams
#include "vfs/fb.asm" #include "vfs/fb.asm"
#include "vfs/serial.asm"