env: fix strlen and add more comments
This commit is contained in:
parent
84ce44330c
commit
b267b3f0b2
31
env.s
31
env.s
@ -21,19 +21,22 @@ _start:
|
|||||||
addi s1, sp, 16 # add 8 for argc, 8 for the NULL at the end of argv
|
addi s1, sp, 16 # add 8 for argc, 8 for the NULL at the end of argv
|
||||||
|
|
||||||
# compute start of envp
|
# compute start of envp
|
||||||
# we could use a sh3add instruction
|
# we could use a sh3add instruction (from the bitmanip extension)
|
||||||
# but the tools i'm using don't support the bitmanip extension
|
# but it's not supported by the tools i'm using
|
||||||
#sh3add s1, sp, s0
|
#sh3add s1, sp, s0
|
||||||
sll t0, s0, 3 # argc*8
|
sll t0, s0, 3 # argc*8
|
||||||
add s1, s1, t0
|
add s1, s1, t0
|
||||||
|
|
||||||
# allocate space for an iovec
|
# allocate space for two iovecs on the stack
|
||||||
|
# an iovec is just a pointer and a length
|
||||||
addi sp, sp, -(8+8)*2
|
addi sp, sp, -(8+8)*2
|
||||||
|
|
||||||
|
# initialize the second iovec with "\n", 1
|
||||||
la t0, newline
|
la t0, newline
|
||||||
sd t0, 16(sp)
|
sd t0, 16(sp)
|
||||||
li t1, 1
|
li t1, 1
|
||||||
sd t1, 24(sp)
|
sd t1, 24(sp)
|
||||||
|
|
||||||
loop:
|
loop:
|
||||||
# check for null pointer, which signals the end of envp
|
# check for null pointer, which signals the end of envp
|
||||||
ld a1, 0(s1)
|
ld a1, 0(s1)
|
||||||
@ -46,28 +49,14 @@ loop:
|
|||||||
lbu t0, 0(t1)
|
lbu t0, 0(t1)
|
||||||
addi t1, t1, 1
|
addi t1, t1, 1
|
||||||
bnez t0, strlen
|
bnez t0, strlen
|
||||||
|
addi t1, t1, -1 # NUL
|
||||||
sub a2, t1, a1
|
sub a2, t1, a1
|
||||||
sd a2, 8(sp)
|
sd a2, 8(sp)
|
||||||
|
|
||||||
/*
|
|
||||||
# print string
|
|
||||||
li a7, 64
|
|
||||||
li a0, 1
|
|
||||||
# a1 already set to start of string
|
|
||||||
# a2 already set to string length
|
|
||||||
ecall
|
|
||||||
|
|
||||||
# print newline
|
|
||||||
li a7, 64
|
|
||||||
li a0, 1
|
|
||||||
la a1, newline
|
|
||||||
li a2, 1
|
|
||||||
ecall
|
|
||||||
*/
|
|
||||||
li a7, 66 # sys_writev
|
li a7, 66 # sys_writev
|
||||||
li a0, 1
|
li a0, 1 # stdout
|
||||||
mv a1, sp
|
mv a1, sp # pointer to iovec
|
||||||
li a2, 2
|
li a2, 2 # number of iovecs
|
||||||
ecall
|
ecall
|
||||||
bltz a0, write_error
|
bltz a0, write_error
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user