Add stdin cat
This commit is contained in:
+27
-6
@@ -2,7 +2,7 @@
|
||||
cat_buf: .space 4096
|
||||
|
||||
.section .text
|
||||
.globl cat_file, open_fd
|
||||
.globl cat_file, open_fd, cat_stdin
|
||||
|
||||
# Cat out the given file to stdout
|
||||
# @param[in] a0: ptr to null-terminated file str.
|
||||
@@ -17,12 +17,12 @@ cat_file:
|
||||
addi sp, sp, 8
|
||||
|
||||
mv t0, a1 # put fd in t0
|
||||
beqz a0, .LReadBlock # if we don't have an error, jump to reading
|
||||
beqz a0, .LReadFileBlock # if we don't have an error, jump to reading
|
||||
li a0, 1
|
||||
j .LRet
|
||||
j .LCatFileRet
|
||||
|
||||
|
||||
.LReadBlock:
|
||||
.LReadFileBlock:
|
||||
mv a0, t0
|
||||
la a1, cat_buf
|
||||
li a2, 4096
|
||||
@@ -35,16 +35,37 @@ cat_file:
|
||||
la a1, cat_buf
|
||||
li a7, 64
|
||||
ecall
|
||||
j .LReadBlock
|
||||
j .LReadFileBlock
|
||||
|
||||
.LCloseFD:
|
||||
mv a0, t0
|
||||
li a7, 57 # close fd
|
||||
ecall
|
||||
|
||||
.LRet:
|
||||
.LCatFileRet:
|
||||
ret
|
||||
|
||||
# Cat out stdin to stdout
|
||||
# @param[in] a0: Not used.
|
||||
# @param[out] a0: result code.
|
||||
cat_stdin:
|
||||
.LReadStdinBlock:
|
||||
li a0, 0
|
||||
la a1, cat_buf
|
||||
li a2, 4096
|
||||
li a7, 63
|
||||
ecall
|
||||
blez a0, .LCatStdinRet # if we haven't read any bytes, EOF, close FD
|
||||
mv a2, a0 # move bytes read into bytes needed to write
|
||||
|
||||
li a0, 1
|
||||
la a1, cat_buf
|
||||
li a7, 64
|
||||
ecall
|
||||
j .LReadStdinBlock
|
||||
|
||||
.LCatStdinRet:
|
||||
ret
|
||||
|
||||
# Open fd
|
||||
# @param[in] a0: ptr to null-terminated file str.
|
||||
|
||||
Reference in New Issue
Block a user