New modbuf for multiple flags #4

Merged
Lexzach merged 3 commits from mod-buf into master 2026-09-15 00:57:38 +00:00
2 changed files with 9 additions and 44 deletions
Showing only changes of commit 685a5ba81d - Show all commits
+7 -43
View File
@@ -1,14 +1,12 @@
.data .data
cat_buf: .space 4096
endings_buf: .space 4097
mod_buf_0: .space 36864 mod_buf_0: .space 36864
mod_buf_1: .space 36864 mod_buf_1: .space 36864
.section .text .section .text
.globl cat_file, open_fd, cat_stdin .globl cat_file, open_fd
# Cat out the given file to stdout # 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. # @param[out] a0: result code.
cat_file: cat_file:
addi sp, sp, -32 addi sp, sp, -32
@@ -21,7 +19,12 @@ cat_file:
li s1, 1 li s1, 1
li s2, 0 li s2, 0
beqz a0, 1f
call open_fd call open_fd
j 2f
1:
li s0, 0 # stdin fd
2:
mv s0, a1 # put fd in s0 mv s0, a1 # put fd in s0
@@ -84,45 +87,6 @@ cat_file:
addi sp, sp, 32 addi sp, sp, 32
ret 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 # Open fd
# @param[in] a0: ptr to null-terminated file str. # @param[in] a0: ptr to null-terminated file str.
# @param[out] a0: result code. (0-exists 1-doesn't exist) # @param[out] a0: result code. (0-exists 1-doesn't exist)
+2 -1
View File
@@ -74,7 +74,8 @@ _start:
j .LMainReturnOk j .LMainReturnOk
.LProcessStdin: .LProcessStdin:
call cat_stdin li a0, 0
call cat_file
j .LMainReturnOk j .LMainReturnOk
.LReturnFileErr: .LReturnFileErr: