Skip to content

Commit

Permalink
kernel: Add :ramdisk stream
Browse files Browse the repository at this point in the history
  • Loading branch information
ry755 committed May 5, 2024
1 parent 72a5282 commit 524bd75
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 0 deletions.
1 change: 1 addition & 0 deletions kernel/main.asm
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ jump_table:
data.32 get_size
data.32 create
data.32 delete
data.32 copy

; widget jump table
org.pad 0x00000610
Expand Down
94 changes: 94 additions & 0 deletions kernel/vfs/ramdisk.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
; disk vfs stream routines

ramdisk_vfs_stream_name: data.strz "ramdisk"

; open a disk id 5 stream
; inputs:
; r2: file struct: pointer to a blank file struct (stream)
; outputs:
; r0: non-zero
open_stream_ramdisk:
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], ramdisk_stream_read ; write file_read_call
add r2, 4
mov [r2], ramdisk_stream_write ; write file_write_call
add r2, 4
mov [r2], 0x00800000 ; 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 5
; inputs:
; r0: seek offset
; outputs:
; r0: byte
ramdisk_stream_read:
push r1
push r2

push r0
div r0, 512
mov r1, 5
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 5
; inputs:
; r0: pointer to source buffer
; r1: seek offset
; outputs:
; none
ramdisk_stream_write:
push r1
push r2
push r3

push r0
push r1
push r1
div r1, 512
mov r0, r1
mov r1, 5
mov r2, TEMP_SECTOR_BUF
call read_sector
pop r1
pop r3
pop r0
rem r1, 512
add r1, TEMP_SECTOR_BUF
mov.8 [r1], [r0]
mov r0, r3
div r0, 512
mov r1, 5
mov r2, TEMP_SECTOR_BUF
call write_sector

pop r3
pop r2
pop r1
ret
39 changes: 39 additions & 0 deletions kernel/vfs/vfs.asm
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ open_stream:
ifz pop r1
ifz jmp open_stream_ofb

; ramdisk
mov r1, ramdisk_vfs_stream_name
call compare_string
ifz pop r1
ifz jmp open_stream_ramdisk

; romdisk
mov r1, romdisk_vfs_stream_name
call compare_string
Expand Down Expand Up @@ -129,6 +135,38 @@ delete:
ifz ret
jmp ryfs_delete

; copy a file's contents
; inputs:
; r0: source file struct: pointer to a filled file struct
; r1: destination file struct: pointer to a filled file struct
; outputs:
; none
copy:
mov [copy_source_struct_ptr], r0
mov [copy_dest_struct_ptr], r1
call get_size
mov [copy_buffer_size], r0
call allocate_memory
mov [copy_buffer_ptr], r0

mov r0, [copy_buffer_size]
mov r1, [copy_source_struct_ptr]
mov r2, [copy_buffer_ptr]
call read
mov r0, [copy_buffer_size]
mov r1, [copy_dest_struct_ptr]
mov r2, [copy_buffer_ptr]
call write

mov r0, [copy_buffer_ptr]
call free_memory

ret
copy_source_struct_ptr: data.32 0
copy_dest_struct_ptr: data.32 0
copy_buffer_ptr: data.32 0
copy_buffer_size: data.32 0

; seek specified file to the specified offset
; inputs:
; r0: byte offset
Expand Down Expand Up @@ -394,5 +432,6 @@ convert_filename_output_string: data.fill 0, 12
#include "vfs/disk3.asm"
#include "vfs/fb.asm"
#include "vfs/ofb.asm"
#include "vfs/ramdisk.asm"
#include "vfs/romdisk.asm"
#include "vfs/serial.asm"

0 comments on commit 524bd75

Please sign in to comment.