env: use writev to add the newline
this allows us to print each line in a single, atomic write call, without modifying or buffering it.
This commit is contained in:
parent
e20f0c4b1e
commit
84ce44330c
17
env.s
17
env.s
@ -27,10 +27,18 @@ _start:
|
||||
sll t0, s0, 3 # argc*8
|
||||
add s1, s1, t0
|
||||
|
||||
# allocate space for an iovec
|
||||
addi sp, sp, -(8+8)*2
|
||||
|
||||
la t0, newline
|
||||
sd t0, 16(sp)
|
||||
li t1, 1
|
||||
sd t1, 24(sp)
|
||||
loop:
|
||||
# check for null pointer, which signals the end of envp
|
||||
ld a1, 0(s1)
|
||||
beqz a1, end
|
||||
sd a1, 0(sp)
|
||||
|
||||
# compute length of string
|
||||
mv t1, a1
|
||||
@ -39,7 +47,9 @@ loop:
|
||||
addi t1, t1, 1
|
||||
bnez t0, strlen
|
||||
sub a2, t1, a1
|
||||
sd a2, 8(sp)
|
||||
|
||||
/*
|
||||
# print string
|
||||
li a7, 64
|
||||
li a0, 1
|
||||
@ -53,6 +63,13 @@ loop:
|
||||
la a1, newline
|
||||
li a2, 1
|
||||
ecall
|
||||
*/
|
||||
li a7, 66 # sys_writev
|
||||
li a0, 1
|
||||
mv a1, sp
|
||||
li a2, 2
|
||||
ecall
|
||||
bltz a0, write_error
|
||||
|
||||
# increment envp and loop
|
||||
addi s1, s1, 8
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user