2023-01-29 11:03:53 -06:00
|
|
|
.global _start
|
|
|
|
_start:
|
2024-01-07 10:11:53 -06:00
|
|
|
|
2023-01-29 11:03:53 -06:00
|
|
|
call get_free_mailbox ; Get a mailbox
|
2024-01-07 10:11:53 -06:00
|
|
|
sr_mb_got:
|
2023-09-03 10:03:51 -05:00
|
|
|
ld (sec_read_mailbox_num), hl
|
|
|
|
call get_free_mailbox ; Get a mailbox
|
2024-01-07 10:11:53 -06:00
|
|
|
mb_got:
|
2023-02-05 11:05:59 -06:00
|
|
|
ld (mailbox_num), hl
|
2023-01-29 11:03:53 -06:00
|
|
|
ld de, 1
|
2023-09-03 10:03:51 -05:00
|
|
|
call get_free_frame ; Set up a frame to send messages at 0xA000
|
|
|
|
ld a, c
|
|
|
|
ld (msg_frame_phys), a
|
|
|
|
ld a, l
|
|
|
|
ld (msg_frame_phys+1), a
|
|
|
|
ld a, h
|
|
|
|
ld (msg_frame_phys+2), a
|
2023-01-29 11:03:53 -06:00
|
|
|
ld b, c
|
|
|
|
ld e, l
|
|
|
|
ld d, h
|
2023-09-03 10:03:51 -05:00
|
|
|
ld c, 0xA
|
2023-01-29 11:03:53 -06:00
|
|
|
call set_frame
|
2023-09-03 10:03:51 -05:00
|
|
|
call get_free_frame ; Set up a frame for the file mapping at 0x8000
|
2023-01-29 11:03:53 -06:00
|
|
|
ld b, c
|
|
|
|
ld e, l
|
|
|
|
ld d, h
|
2023-09-03 10:03:51 -05:00
|
|
|
ld c, 0x8
|
2023-01-29 11:03:53 -06:00
|
|
|
call set_frame
|
2024-01-07 10:11:53 -06:00
|
|
|
ld hl, 0xA000
|
|
|
|
ld a, (msg_frame_phys)
|
|
|
|
ld c, a
|
|
|
|
ld de, (msg_frame_phys+1)
|
|
|
|
call libvfs_init
|
2023-01-29 11:03:53 -06:00
|
|
|
ld c, 0
|
|
|
|
ld de, 1
|
2023-09-03 10:03:51 -05:00
|
|
|
ld hl, 0x8000
|
2023-02-05 11:04:40 -06:00
|
|
|
initrd_read_loop:
|
2023-01-29 11:03:53 -06:00
|
|
|
push bc
|
|
|
|
push de
|
|
|
|
push hl
|
2023-09-03 10:03:51 -05:00
|
|
|
; FM SECL SECH
|
|
|
|
ld hl, 0xA000
|
2023-01-29 11:03:53 -06:00
|
|
|
call read_sector
|
2024-01-07 10:11:53 -06:00
|
|
|
rl_read_sector_done:
|
2023-01-29 11:03:53 -06:00
|
|
|
pop de
|
|
|
|
push de
|
2023-09-03 10:03:51 -05:00
|
|
|
; FM SECL SECH
|
2023-01-29 11:03:53 -06:00
|
|
|
ld b, 0 ; Load the filename length in BC
|
2023-09-03 10:03:51 -05:00
|
|
|
ld a, (0xA000)
|
|
|
|
cp 0
|
|
|
|
jp z, initrd_read_done
|
2023-01-29 11:03:53 -06:00
|
|
|
ld c, a
|
2023-09-03 10:03:51 -05:00
|
|
|
ld hl, 0xA001 ; Read the name + null terminator into the mapping list
|
2023-01-29 11:03:53 -06:00
|
|
|
ldir
|
|
|
|
ld a, (hl)
|
|
|
|
ld (de), a
|
|
|
|
inc hl
|
2023-09-03 10:03:51 -05:00
|
|
|
pop de ; Restore the value of DE before reading the name in
|
|
|
|
; SECL SECH
|
|
|
|
dbg_label:
|
|
|
|
ld a, e ; Add 0x20 to DE
|
2023-01-29 11:03:53 -06:00
|
|
|
add a, 0x20
|
|
|
|
ld e, a
|
|
|
|
ld a, d
|
|
|
|
adc a, 0x0
|
|
|
|
ld d, a
|
2024-01-07 10:11:53 -06:00
|
|
|
ld a, (hl) ; Write the file length to the mapping list
|
2023-01-29 11:03:53 -06:00
|
|
|
ld (de), a
|
|
|
|
inc hl
|
|
|
|
inc de
|
|
|
|
ld a, (hl)
|
|
|
|
ld (de), a
|
|
|
|
inc hl
|
|
|
|
inc de
|
2023-09-03 10:03:51 -05:00
|
|
|
ld l, e
|
2023-01-29 11:03:53 -06:00
|
|
|
ld h, d
|
2023-09-03 10:03:51 -05:00
|
|
|
pop iy
|
|
|
|
; SECH
|
2023-01-29 11:03:53 -06:00
|
|
|
pop bc
|
2023-09-03 10:03:51 -05:00
|
|
|
; (EMPTY)
|
|
|
|
push de
|
|
|
|
; FM
|
|
|
|
push bc
|
|
|
|
; SECH FM
|
|
|
|
ld e, iyl
|
|
|
|
ld d, iyh
|
|
|
|
ld (hl), e ; Write the starting block of the file to the mapping list
|
2023-01-29 11:03:53 -06:00
|
|
|
inc hl
|
|
|
|
ld (hl), d
|
|
|
|
inc hl
|
|
|
|
ld (hl), c
|
|
|
|
inc hl
|
|
|
|
; Advance to the next header
|
|
|
|
ld b, 0 ; Load the filename length in BC
|
2023-09-03 10:03:51 -05:00
|
|
|
ld a, (0xA000)
|
2023-01-29 11:03:53 -06:00
|
|
|
ld c, a
|
2023-09-03 10:03:51 -05:00
|
|
|
ld hl, 0xA004
|
2023-01-29 11:03:53 -06:00
|
|
|
add hl, bc ; Add the filename length to get the pointer to the
|
|
|
|
; # of blocks in the file in HL
|
|
|
|
ld c, (hl) ; Read the # of blocks into BC
|
|
|
|
inc hl
|
|
|
|
ld b, (hl)
|
|
|
|
ld l, c ; Move it into HL
|
|
|
|
ld h, b
|
|
|
|
inc hl ; Add 1 to account for the header sector
|
|
|
|
pop bc
|
2023-09-03 10:03:51 -05:00
|
|
|
; FM
|
2023-01-29 11:03:53 -06:00
|
|
|
add hl, de ; 24-bit add of HL to C:DE
|
|
|
|
ld e, l
|
|
|
|
ld d, h
|
|
|
|
ld a, c
|
|
|
|
adc a, 0
|
|
|
|
ld c, a
|
2023-09-03 10:03:51 -05:00
|
|
|
pop hl
|
|
|
|
; (empty)
|
|
|
|
inc hl
|
|
|
|
inc hl
|
|
|
|
inc hl
|
2023-02-05 11:04:40 -06:00
|
|
|
jp initrd_read_loop
|
2023-09-03 10:03:51 -05:00
|
|
|
initrd_read_done:
|
2024-01-07 10:11:53 -06:00
|
|
|
ld hl, (mailbox_num)
|
|
|
|
ld ix, initrd_fs_name
|
|
|
|
call libvfs_register_fs
|
2023-09-03 10:03:51 -05:00
|
|
|
ld de, 1
|
|
|
|
ld hl, (mailbox_num)
|
|
|
|
pms_call:
|
2023-01-29 11:03:53 -06:00
|
|
|
call proc_map_set ; Register ourselves as ID 1
|
|
|
|
msg_loop:
|
|
|
|
call yield
|
2023-09-03 10:03:51 -05:00
|
|
|
yield_back:
|
2023-01-29 11:03:53 -06:00
|
|
|
ld hl, (mailbox_num)
|
2023-09-03 10:03:51 -05:00
|
|
|
call mb_read
|
|
|
|
mb_read_done:
|
|
|
|
ld a, b
|
|
|
|
cp 1
|
|
|
|
jp z, msg_loop
|
|
|
|
msg_read:
|
2023-01-29 11:03:53 -06:00
|
|
|
push bc
|
|
|
|
push de
|
|
|
|
push hl
|
|
|
|
ld b, c
|
|
|
|
ld c, 0xB
|
|
|
|
call set_frame
|
2023-09-03 10:03:51 -05:00
|
|
|
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
|
2024-01-07 10:11:53 -06:00
|
|
|
cp 0x2
|
|
|
|
jp z, mount
|
2023-09-03 10:03:51 -05:00
|
|
|
operation_done:
|
|
|
|
pop hl
|
2023-01-29 11:03:53 -06:00
|
|
|
pop ix
|
|
|
|
pop de
|
|
|
|
pop bc
|
|
|
|
call mb_send
|
|
|
|
jp msg_loop
|
|
|
|
|
2024-01-07 10:11:53 -06:00
|
|
|
mount:
|
|
|
|
jp operation_done
|
|
|
|
|
2023-09-03 10:03:51 -05:00
|
|
|
; de = start of file map list
|
|
|
|
; c = 0
|
|
|
|
; while (1) {
|
|
|
|
; if (*de == 0) {
|
|
|
|
; (0xB000) = 1;
|
|
|
|
; return
|
|
|
|
; }
|
|
|
|
; if (strcmp(de, 0xB003) == 0) {
|
|
|
|
; (0xB000) = 0;
|
|
|
|
; (0xB001) = c;
|
|
|
|
; return;
|
|
|
|
; }
|
|
|
|
; }
|
|
|
|
open:
|
|
|
|
ld de, 0x8000
|
|
|
|
ld c, 0
|
|
|
|
open_find_loop:
|
|
|
|
ld a, (de)
|
|
|
|
cp 0
|
|
|
|
jp nz, open_not_end
|
|
|
|
ld a, 1
|
|
|
|
ld (0xB000), a
|
|
|
|
jp operation_done
|
|
|
|
open_not_end:
|
|
|
|
ld ix, 0xB003
|
|
|
|
push de
|
|
|
|
pop iy
|
|
|
|
call strcmp
|
|
|
|
cp 0
|
|
|
|
jp nz, open_not_match
|
|
|
|
ld a, c
|
2024-01-07 10:11:53 -06:00
|
|
|
ld (0xB000), a
|
|
|
|
ld a, 0
|
2023-09-03 10:03:51 -05:00
|
|
|
ld (0xB001), a
|
2024-01-07 10:16:57 -06:00
|
|
|
ld (0xB002), a
|
|
|
|
ld (0xB003), a
|
2023-09-03 10:03:51 -05:00
|
|
|
jp operation_done
|
|
|
|
open_not_match:
|
|
|
|
inc c
|
|
|
|
push de
|
|
|
|
pop hl
|
|
|
|
ld de, 0x25
|
|
|
|
add hl, de
|
|
|
|
push hl
|
|
|
|
pop de
|
|
|
|
jp open_find_loop
|
|
|
|
|
|
|
|
read:
|
|
|
|
ld a, (0xB003)
|
|
|
|
ld l, a
|
|
|
|
ld h, 0
|
|
|
|
push hl
|
|
|
|
pop ix
|
|
|
|
add hl, hl
|
|
|
|
add hl, hl
|
|
|
|
push hl
|
|
|
|
pop de
|
|
|
|
add ix, de
|
|
|
|
add hl, hl
|
|
|
|
add hl, hl
|
|
|
|
add hl, hl
|
|
|
|
push hl
|
|
|
|
pop de
|
|
|
|
add ix, de
|
|
|
|
ld de, 0x8020
|
|
|
|
add ix, de
|
|
|
|
ld d, (ix+2)
|
|
|
|
ld e, 0x0
|
2024-01-07 10:11:53 -06:00
|
|
|
ld hl, (0xB005)
|
2023-09-03 10:03:51 -05:00
|
|
|
add hl, de
|
|
|
|
ld bc, 0x100
|
|
|
|
add hl, bc
|
|
|
|
ld c, l
|
|
|
|
ld b, h
|
2024-01-07 10:11:53 -06:00
|
|
|
ld de, (0xB007)
|
2023-09-03 10:03:51 -05:00
|
|
|
call read_bytes
|
|
|
|
ld de, 0xB000
|
|
|
|
ld hl, 0xA000
|
2024-01-07 10:11:53 -06:00
|
|
|
ld bc, (0xB007)
|
2023-09-03 10:03:51 -05:00
|
|
|
ldir
|
|
|
|
jp operation_done
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
strcmp:
|
|
|
|
strcmp_loop:
|
|
|
|
ld a, (ix+0)
|
|
|
|
ld b, (iy+0)
|
|
|
|
cp b
|
|
|
|
jp nz, strcmp_different
|
|
|
|
cp 0
|
|
|
|
ret z
|
|
|
|
inc ix
|
|
|
|
inc iy
|
|
|
|
jp strcmp_loop
|
|
|
|
strcmp_different:
|
|
|
|
ld a, 1
|
|
|
|
ret
|
|
|
|
|
|
|
|
sec_read_mailbox_num: .ds.b 2
|
2023-01-29 11:03:53 -06:00
|
|
|
mailbox_num: .ds.b 2
|
2023-09-03 10:03:51 -05:00
|
|
|
msg_frame_phys: .ds.b 3
|
2023-01-29 11:03:53 -06:00
|
|
|
|
2023-09-03 10:03:51 -05:00
|
|
|
; Given a sector number in C:DE, reads the sector off disk into 0xA000
|
2023-01-29 11:03:53 -06:00
|
|
|
read_sector:
|
|
|
|
; Set up a read message to the driver starting at the sector in register E and reading
|
|
|
|
; 0x100 bytes
|
|
|
|
ld a, 0x0
|
|
|
|
ld (0xA000), a
|
|
|
|
ld a, e
|
|
|
|
ld (0xA001), a
|
|
|
|
ld a, 0x00
|
|
|
|
ld (0xA002), a
|
|
|
|
ld a, 0x1
|
|
|
|
ld (0xA003), a
|
2023-09-03 10:03:51 -05:00
|
|
|
ld hl, (sec_read_mailbox_num)
|
2023-01-29 11:03:53 -06:00
|
|
|
ld (0xA004), hl
|
|
|
|
ld de, 0 ; Get the mailbox number for the initrd driver
|
|
|
|
call proc_map_get
|
2023-09-03 10:03:51 -05:00
|
|
|
read_sec_pmg_done:
|
|
|
|
ld a, (msg_frame_phys)
|
|
|
|
ld c, a
|
|
|
|
ld de, (msg_frame_phys + 1)
|
|
|
|
ld ix, 0
|
2023-01-29 11:03:53 -06:00
|
|
|
call mb_send
|
2023-09-03 10:03:51 -05:00
|
|
|
read_sec_msg_sent:
|
2023-01-29 11:03:53 -06:00
|
|
|
loop:
|
|
|
|
call yield
|
2023-09-03 10:03:51 -05:00
|
|
|
ld hl, (sec_read_mailbox_num)
|
|
|
|
read_sector_done:
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
; Given a byte offset in BC, and a byte length in DE no more than 0x1000, reads the data off disk into 0xA000
|
|
|
|
read_bytes:
|
|
|
|
; Set up a read message to the driver starting at the sector in register E and reading
|
|
|
|
; 0x100 bytes
|
|
|
|
ld (0xA000), bc
|
|
|
|
ld (0xA002), de
|
|
|
|
ld hl, (sec_read_mailbox_num)
|
|
|
|
ld (0xA004), hl
|
|
|
|
ld de, 0 ; Get the mailbox number for the initrd driver
|
|
|
|
call proc_map_get
|
|
|
|
read_bytes_pmg_done:
|
|
|
|
ld a, (msg_frame_phys)
|
|
|
|
ld c, a
|
|
|
|
ld de, (msg_frame_phys + 1)
|
|
|
|
ld ix, 0
|
|
|
|
call mb_send
|
|
|
|
read_bytes_msg_sent:
|
|
|
|
read_bytes_loop:
|
|
|
|
call yield
|
|
|
|
ld hl, (sec_read_mailbox_num)
|
|
|
|
|
2023-01-29 11:03:53 -06:00
|
|
|
call mb_read ; Read a message
|
|
|
|
ld a, b ; Loop if there is no message
|
|
|
|
cp 0
|
2023-09-03 10:03:51 -05:00
|
|
|
jp nz, read_bytes_loop
|
|
|
|
read_bytes_done:
|
2023-01-29 11:03:53 -06:00
|
|
|
ret
|
2024-01-07 10:11:53 -06:00
|
|
|
|
|
|
|
initrd_fs_name: .asciz "initrd"
|