summaryrefslogtreecommitdiff
path: root/rt/_myrrt-plan9.s
blob: 4b76fdfe5465a46c2fcf1721f099a722ac4997f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#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, sys$tosptr(SB)
	LEAQ	16(SP), AX
	MOVQ	AX, _privates(SB)
	MOVL	$NPRIVATES, _nprivates(SB)

	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

	XORQ	BP,BP
	CALL	__init__(SB)
	CALL	main(SB)
	POPQ	DX
	POPQ	R13

exitloop:
	MOVQ	$0,8(SP)
	MOVQ	$8,RARG
	SYSCALL
	JMP		exitloop

TEXT	_rt$abort_oob(SB),1,$0
broke:
	XORQ	AX,AX
	MOVQ	$1234,(AX)
	JMP		broke

GLOBL	argv0(SB), $8
GLOBL	sys$tosptr(SB), $8
GLOBL	_privates(SB), $8
GLOBL	_nprivates(SB), $4