ref: 59d77e008cc4a36eeb2a9d255a32866901b6ccb1
parent: 26f202d8488fa681de64153830846a3544bf9bdb
author: Ori Bernstein <[email protected]>
date: Wed Dec 31 20:07:39 EST 2014
Get args[:][:] set up on plan 9.
--- a/libstd/wait+plan9.myr
+++ b/libstd/wait+plan9.myr
@@ -90,4 +90,3 @@
const pidhash = {x; -> inthash(x castto(int32))}
const pideq = {a, b; -> a == b}
-
--- a/rt/_myrrt-plan9.s
+++ b/rt/_myrrt-plan9.s
@@ -1,17 +1,70 @@
#define NPRIVATES 16
+/*
+ * counts the length of the string pointed to
+ * by %r8, returning len in %r9. Does not modify
+ * any registers outside of %r9
+ */
+TEXT cstrlen(SB),$0
+ XORQ R9,R9
+ JMP .lentest
+.lenloop:
+ INCQ R9
+.lentest:
+ CMPB 0(R8)(R9*1),$0
+ JNE .lenloop
+ RET
+/*
+ * iterate over the strings for argc, and put
+ * them into the args array.
+ *
+ * argc in %rax, argv in %rbx, dest vector in %rcx
+ */
+TEXT cvt(SB),$0
+ JMP .cvttest
+.cvtloop:
+ SUBQ $1,AX
+ MOVQ (BX),R8
+ CALL cstrlen(SB)
+ MOVQ R8,(CX)
+ MOVQ R9,8(CX)
+ ADDQ $8,BX
+ ADDQ $16,CX
+.cvttest:
+ TESTQ AX,AX
+ JNE .cvtloop
+.cvtdone:
+ RET
+
+
TEXT _main(SB), 1, $(2*8+NPRIVATES*8)
MOVQ AX, _tos(SB)
LEAQ 16(SP), AX
MOVQ AX, _privates(SB)
MOVL $NPRIVATES, _nprivates(SB)
- MOVL inargc-8(FP), RARG
- LEAQ inargv+0(FP), AX
- MOVQ AX, 8(SP)
+
+ MOVL inargc-8(FP), R13
+ LEAQ inargv+0(FP), R14
+ MOVQ R13, AX
+ IMULQ $16,AX
+ SUBQ AX,SP
+ MOVQ SP,DX
+
+ MOVQ R13, AX
+ MOVQ R14, BX
+ MOVQ SP, CX
+ CALL cvt(SB)
+ PUSHQ R13
+ PUSHQ DX
+
CALL main(SB)
+ POPQ DX
+ POPQ R13
+
exitloop:
- MOVQ $0,estatus+0(FP)
+ MOVQ $0,(SP)
MOVQ $8,RARG
+ POPQ AX
SYSCALL
JMP exitloop
--- a/rt/common.s
+++ b/rt/common.s
@@ -8,9 +8,9 @@
xorq %r9,%r9
jmp .lentest
- .lenloop:
+.lenloop:
incq %r9
- .lentest:
+.lentest:
cmpb $0,(%r8,%r9)
jne .lenloop
ret
--- a/rt/start-linux.s
+++ b/rt/start-linux.s
@@ -31,7 +31,7 @@
/* stack allocate sizeof(byte[:])*(argc + len(envp)) */
movq (%rbp),%rax
leaq 16(%rbp,%rax,8), %rbx /* argp = argv + 8*argc + 8 */
- call count
+ call count
addq %r9,%rax
imulq $16,%rax
subq %rax,%rsp
@@ -40,7 +40,7 @@
/* stack allocate sizeof(byte[:])*(argc + len(envp)) */
movq (%rbp),%rax
leaq 16(%rbp,%rax,8), %rbx /* argp = argv + 8*argc + 8 */
- call count
+ call count
addq %r9,%rax
imulq $16,%rax
subq %rax,%rsp