Move stdin to modbuf
This commit is contained in:
+7
-43
@@ -1,14 +1,12 @@
|
||||
.data
|
||||
cat_buf: .space 4096
|
||||
endings_buf: .space 4097
|
||||
mod_buf_0: .space 36864
|
||||
mod_buf_1: .space 36864
|
||||
|
||||
.section .text
|
||||
.globl cat_file, open_fd, cat_stdin
|
||||
.globl cat_file, open_fd
|
||||
|
||||
# Cat out the given file to stdout
|
||||
# @param[in] a0: ptr to null-terminated file str.
|
||||
# @param[in] a0: ptr to null-terminated file str. 0 = stdin
|
||||
# @param[out] a0: result code.
|
||||
cat_file:
|
||||
addi sp, sp, -32
|
||||
@@ -21,7 +19,12 @@ cat_file:
|
||||
li s1, 1
|
||||
li s2, 0
|
||||
|
||||
beqz a0, 1f
|
||||
call open_fd
|
||||
j 2f
|
||||
1:
|
||||
li s0, 0 # stdin fd
|
||||
2:
|
||||
|
||||
mv s0, a1 # put fd in s0
|
||||
|
||||
@@ -84,45 +87,6 @@ cat_file:
|
||||
addi sp, sp, 32
|
||||
ret
|
||||
|
||||
# Cat out stdin to stdout
|
||||
# @param[in] a0: Not used.
|
||||
# @param[out] a0: Not used.
|
||||
cat_stdin:
|
||||
addi sp, sp, -16
|
||||
sd ra, 0(sp)
|
||||
sd s0, 8(sp)
|
||||
|
||||
la t1, show_ends
|
||||
lb s0, 0(t1) # store if we show ends into s1
|
||||
|
||||
.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
|
||||
|
||||
beqz s0, .LNoEndingsStdinWrite
|
||||
mv a1, a0
|
||||
la a0, cat_buf
|
||||
call _add_endings
|
||||
j .LReadStdinBlock
|
||||
|
||||
.LNoEndingsStdinWrite:
|
||||
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:
|
||||
ld ra, 0(sp)
|
||||
ld s0, 8(sp)
|
||||
addi sp, sp, 16
|
||||
ret
|
||||
|
||||
# Open fd
|
||||
# @param[in] a0: ptr to null-terminated file str.
|
||||
# @param[out] a0: result code. (0-exists 1-doesn't exist)
|
||||
|
||||
+2
-1
@@ -74,7 +74,8 @@ _start:
|
||||
j .LMainReturnOk
|
||||
|
||||
.LProcessStdin:
|
||||
call cat_stdin
|
||||
li a0, 0
|
||||
call cat_file
|
||||
j .LMainReturnOk
|
||||
|
||||
.LReturnFileErr:
|
||||
|
||||
Reference in New Issue
Block a user