Get test FS working

This commit is contained in:
pjht 2023-10-08 10:55:28 -05:00
parent 263555b151
commit 8c0e2af93b
Signed by: pjht
GPG Key ID: 7B5F6AFBEC7EE78E
3 changed files with 123 additions and 133 deletions

146
init.z80
View File

@ -11,30 +11,25 @@ ld d, h
ld c, 8 ld c, 8
bp_call_sf: bp_call_sf:
call set_frame call set_frame
ld iy, vfs_name ; Load and run the initrd driver
call run_file
vfs_loaded:
call yield ; Yield to let the initrd driver initialize
vfs_returned:
ld iy, initrd_driver_name ; Load and run the initrd driver
call run_file
initrd_driver_loaded:
call yield ; Yield to let the initrd driver initialize
initrd_driver_returned:
ld iy, initrd_fs_name ; Load and run the initrd fs driver
call run_file
initrd_fs_loaded:
fs_init_wait_loop:
call yield ; Yield to let the initrd driver initialize
yield_done:
call get_free_mailbox ; Initialize a mailbox call get_free_mailbox ; Initialize a mailbox
ld (mailbox_num), hl ld (mailbox_num), hl
ld de, 1 ld iy, vfs_name ; Load and run the VFS
call run_file
vfs_loaded:
call yield ; Yield to let the VFS initialize
vfs_returned:
ld iy, test_fs_name ; Load and run the test fs
call run_file
test_fs_loaded:
test_fs_init_wait_loop:
call yield ; Yield to let the test fs initialize
yield_done:
ld de, 3
call proc_map_get call proc_map_get
ld a, l ld a, l
cp 0 cp 0
jp z, fs_init_wait_loop jp z, test_fs_init_wait_loop
fs_ready: test_fs_initialized:
call get_free_frame ; Set up a message frame at 0xA000 call get_free_frame ; Set up a message frame at 0xA000
ld a, c ld a, c
ld (msg_phys_addr), a ld (msg_phys_addr), a
@ -45,41 +40,6 @@ pop de
ld c, 0xA ld c, 0xA
call set_frame call set_frame
frame_done: frame_done:
; Set up a register FS message to the VFS for "a" at mailbox 1
ld hl, (mailbox_num)
ld (0xA000), hl
ld a, 0x0 ; Register FS operation
ld (0xA002), a
ld a, 0x61 ; 'a'
ld (0xA003), a
ld a, 0x0 ; '\0'
ld (0xA004), a
ld a, 0x1
ld (0xA011), a
ld a, 0x0
ld (0xA012), a
push de
push bc
ld de, 2 ; Get the mailbox number for the VFS
call proc_map_get
pmg_done:
pop bc
pop de
ld c, b ; Send the message
ld ix, 0x0000
call mb_send
loop:
call yield
loop_yield_done:
ld hl, (mailbox_num)
call mb_read ; Read a message
mb_read_done:
ld a, b ; Loop if there is no message
cp 0
jp nz, loop
ld a, (0xA001)
ld c, a
register_done:
; Set up a mount message to the VFS for "" on "/" with fs "a" at mailbox 1 ; Set up a mount message to the VFS for "" on "/" with fs "a" at mailbox 1
ld hl, (mailbox_num) ld hl, (mailbox_num)
ld (0xA000), hl ld (0xA000), hl
@ -113,85 +73,10 @@ call mb_read ; Read a message
mount_mb_read_done: mount_mb_read_done:
ld a, b ; Loop if there is no message ld a, b ; Loop if there is no message
cp 0 cp 0
jp nz, loop jp nz, mount_loop
ld a, (0xA001) ld a, (0xA001)
ld c, a ld c, a
mount_done: mount_done:
; Set up an open message to the initrd FS for "init.elf"
; ld hl, (mailbox_num)
; ld (0xA000), hl
; ld a, 0x0 ; Open operation
; ld (0xA002), a
; ld a, 0x69 ; i
; ld (0xA003), a
; ld a, 0x6e ; n
; ld (0xA004), a
; ld a, 0x69 ; i
; ld (0xA005), a
; ld a, 0x74 ; t
; ld (0xA006), a
; ld a, 0x2e ; .
; ld (0xA007), a
; ld a, 0x65 ; e
; ld (0xA008), a
; ld a, 0x6c ; l
; ld (0xA009), a
; ld a, 0x66 ; f
; ld (0xA00a), a
; ld a, 0x0 ; NUL
; ld (0xA00b), a
; push de
; push bc
; ld de, 1 ; Get the mailbox number for the initrd driver
; call proc_map_get
; pmg_done:
; pop bc
; pop de
; ld c, b ; Send the message
; ld ix, 0x0000
; call mb_send
; loop:
; call yield
; loop_yield_done:
; ld hl, (mailbox_num)
; call mb_read ; Read a message
; mb_read_done:
; ld a, b ; Loop if there is no message
; cp 0
; jp nz, loop
; ld a, (0xA001)
; ld c, a
; open_done:
; ; Set up a read message to the initrd FS for init.elf starting at 0x10 and reading 0x50 bytes
; ld hl, (mailbox_num)
; ld (0xA000), hl
; ld a, 0x1 ; Read operation
; ld (0xA002), a
; ld a, c ; FD
; ld (0xA003), a
; ld hl, 0x10
; ld (0xA004), hl ; File offset
; ld hl, 0x50
; ld (0xA006), hl ; Read length
; ld de, 1 ; Get the mailbox number for the initrd driver
; call proc_map_get
; read_pmg_done:
; ld a, (msg_phys_addr)
; ld c, a
; ld de, (msg_phys_addr+1)
; ld ix, 0x0000
; call mb_send
; read_loop:
; call yield
; read_loop_yield_done:
; ld hl, (mailbox_num)
; call mb_read ; Read a message
; read_mb_read_done:
; ld a, b ; Loop if there is no message
; cp 0
; jp nz, read_loop
halt halt
mailbox_num: .ds.b 2 mailbox_num: .ds.b 2
@ -201,6 +86,7 @@ msg_phys_addr: .ds.b 3
vfs_name: .asciz "vfs.elf" vfs_name: .asciz "vfs.elf"
initrd_driver_name: .asciz "initrd_driver.elf" initrd_driver_name: .asciz "initrd_driver.elf"
initrd_fs_name: .asciz "initrd_fs.elf" initrd_fs_name: .asciz "initrd_fs.elf"
test_fs_name: .asciz "test_fs.elf"
; Loads and starts the ELF file with the name pointed to by IY ; Loads and starts the ELF file with the name pointed to by IY
run_file: run_file:

98
test_fs.z80 Normal file
View File

@ -0,0 +1,98 @@
.global _start
_start:
call get_free_mailbox
ld (mailbox_num), hl
call get_free_frame ; Set up a frame for sending messages at 0x8000
ld a, c
ld (msg_phys_addr), a
ld (msg_phys_addr+1), hl
ld b, c
ld e, l
ld d, h
ld c, 8
call set_frame
setup_msg:
ld hl, (mailbox_num)
ld (0x8000), hl
ld a, 0x0 ; Register FS operation
ld (0x8002), a
ld a, 0x61 ; 'a'
ld (0x8003), a
ld a, 0x0 ; '\0'
ld (0x8004), a
ld (0x8011), hl
push de
push bc
ld de, 2 ; Get the mailbox number for the VFS
call proc_map_get
pmg_done:
pop bc
pop de
ld c, b ; Send the message
ld ix, 0x0000
call mb_send
loop:
call yield
loop_yield_done:
ld hl, (mailbox_num)
call mb_read ; Read a message
reg_fs_mb_read_done:
ld a, b ; Loop if there is no message
cp 0
jp nz, loop
ld hl, (mailbox_num)
ld de, 3
call proc_map_set
msg_loop:
call yield
yield_back:
ld hl, (mailbox_num)
call mb_read
mb_read_done:
ld a, b
cp 1
jp z, msg_loop
msg_read:
push bc
push de
push hl
ld b, c
ld c, 0xB
call set_frame
set_frame_done:
ld hl, (0xB000) ; Load destination mailbox into HL and save it on the stack
push hl
ld hl, 0xB002
; Handling code goes here
ld a, (hl)
inc hl
cp 0x0
jp z, open
cp 0x1
jp z, read
cp 0x2
jp z, mount
operation_done:
pop hl
pop ix
pop de
pop bc
call mb_send
jp msg_loop
open:
jp z, operation_done
read:
jp z, operation_done
mount:
jp z, operation_done
mailbox_num: .ds.b 2
msg_phys_addr: .ds.b 2

12
vfs.z80
View File

@ -56,6 +56,8 @@ cp 0x0
jp z, register_fs jp z, register_fs
cp 0x1 cp 0x1
jp z, mount jp z, mount
cp 0x2
jp z, open
operation_done: operation_done:
pop hl pop hl
pop ix pop ix
@ -150,11 +152,13 @@ ld d, (hl)
ld (ix), e ld (ix), e
ld (ix+1), d ld (ix+1), d
push ix push ix
ld hl, (fs_mailbox_num)
ld (0x8000), hl
ld a, 0x2 ld a, 0x2
ld (0x8000), a ld (0x8002), a
push de push de
ld hl, 0xB0FF ld hl, 0xB0FF
ld de, 0x8001 ld de, 0x8003
ld bc, 256 ld bc, 256
ldir ldir
ld a, (send_page_addr) ld a, (send_page_addr)
@ -201,7 +205,9 @@ ld a, (ix)
sub b sub b
ret ret
; TODO open
open:
jp operation_done
vfs_mailbox_num: .ds.b 2 vfs_mailbox_num: .ds.b 2