diff options
author | Ori Bernstein <ori@eigenstate.org> | 2015-01-01 01:07:39 -0800 |
---|---|---|
committer | Ori Bernstein <ori@eigenstate.org> | 2015-01-01 01:07:39 -0800 |
commit | 4f1ea224da009a6174db526eabb4ddb3fdac5558 (patch) | |
tree | 24a2a141a60c60749ef649005e70a39cf107f37b /rt | |
parent | fc13f8699b5f3702525fcf5a2692b1800763aa53 (diff) | |
download | mc-4f1ea224da009a6174db526eabb4ddb3fdac5558.tar.gz |
Get args[:][:] set up on plan 9.
Diffstat (limited to 'rt')
-rw-r--r-- | rt/_myrrt-plan9.s | 61 | ||||
-rw-r--r-- | rt/common.s | 4 | ||||
-rw-r--r-- | rt/start-linux.s | 4 |
3 files changed, 61 insertions, 8 deletions
diff --git a/rt/_myrrt-plan9.s b/rt/_myrrt-plan9.s index 31e8011..a1b7964 100644 --- 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 diff --git a/rt/common.s b/rt/common.s index 7eb2aeb..ee202b7 100644 --- a/rt/common.s +++ b/rt/common.s @@ -8,9 +8,9 @@ cstrlen: xorq %r9,%r9 jmp .lentest - .lenloop: +.lenloop: incq %r9 - .lentest: +.lentest: cmpb $0,(%r8,%r9) jne .lenloop ret diff --git a/rt/start-linux.s b/rt/start-linux.s index 0313fba..7583466 100644 --- a/rt/start-linux.s +++ b/rt/start-linux.s @@ -31,7 +31,7 @@ _start: /* 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 @@ _start: /* 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 |