Add file not found err
This commit is contained in:
+38
-7
@@ -2,7 +2,7 @@
|
||||
cat_buf: .space 4096
|
||||
|
||||
.section .text
|
||||
.globl cat_file
|
||||
.globl cat_file, open_fd
|
||||
|
||||
# Fetch argument count
|
||||
# @param[in] a0: ptr to null-terminated file str.
|
||||
@@ -10,12 +10,17 @@ cat_buf: .space 4096
|
||||
cat_file:
|
||||
mv a1, a0 # since the function takes in a0, move it to a1 for syscall
|
||||
|
||||
li a0, -100 # relative/absolute path
|
||||
li a2, 0 # readonly
|
||||
li a7, 56 # open
|
||||
ecall
|
||||
addi sp, sp, -8
|
||||
sd ra, 0(sp)
|
||||
call open_fd
|
||||
ld ra, 0(sp)
|
||||
addi sp, sp, 8
|
||||
|
||||
mv t0, a1 # put fd in t0
|
||||
beqz a0, 1f # if we don't have an error, jump to reading
|
||||
li a0, 1
|
||||
j 2f
|
||||
|
||||
mv t0, a0 # put fd in t0
|
||||
|
||||
1:
|
||||
mv a0, t0
|
||||
@@ -23,7 +28,7 @@ cat_file:
|
||||
li a2, 4096
|
||||
li a7, 63
|
||||
ecall
|
||||
blez a0, 2f
|
||||
blez a0, 3f
|
||||
mv a2, a0 # move bytes read into bytes needed to write
|
||||
|
||||
li a0, 1
|
||||
@@ -32,7 +37,33 @@ cat_file:
|
||||
ecall
|
||||
j 1b
|
||||
|
||||
3:
|
||||
mv a0, t0
|
||||
li a7, 57 # close fd
|
||||
ecall
|
||||
|
||||
2:
|
||||
ret
|
||||
|
||||
|
||||
# Fetch argument count
|
||||
# @param[in] a0: ptr to null-terminated file str.
|
||||
# @param[out] a0: result code. (0-exists 1-doesn't exist)
|
||||
# @param[out] a1: fd.
|
||||
open_fd:
|
||||
mv a1, a0 # since the function takes in a0, move it to a1 for syscall
|
||||
|
||||
li a0, -100 # relative/absolute path
|
||||
li a2, 0 # readonly
|
||||
li a7, 56 # open
|
||||
ecall
|
||||
bltz a0, 1f # file doesn't exist
|
||||
mv a1, a0 # move fd to a1
|
||||
li a0, 0
|
||||
j 2f
|
||||
|
||||
1:
|
||||
li a0, 1
|
||||
|
||||
2:
|
||||
ret
|
||||
|
||||
Reference in New Issue
Block a user