summaryrefslogtreecommitdiff
path: root/libstd/util+plan9-x64.s
blob: f4b8586fe546f5894a163a83ee2e4aee3760c83c (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
/*
 * Allocates a C string on the stack, for
 * use within system calls, which is the only
 * place the Myrddin stack should need nul-terminated
 * strings.
 *
 * This is in assembly, because for efficiency we
 * allocate the C strings on the stack, and don't adjust
 * SP when returning.
 */
TEXT sys$cstring+0(SB),$0
	/* save registers */
	MOVQ	SP,AX
	SUBQ	$40,SP
	MOVQ	BP,-8(AX)
	MOVQ	R15,-16(AX)
	MOVQ	SI,-24(AX)
	MOVQ	DI,-32(AX)
	MOVQ	CX,-40(AX)
	MOVQ	AX,BP

	MOVQ 	(BP),R15	/* ret addr */
	MOVQ	8(BP),SI	/* src */
	MOVQ	16(BP),CX	/* len */

	SUBQ	CX,SP		/* get stack */
	SUBQ	$1,SP		/* +1 for nul */
	MOVQ	SP,DI		/* dest */
	MOVQ	SP,AX		/* ret val */
	ANDQ	$(~15),SP	/* align */
	SUBQ	$32,SP		/* "unpop" the args and make room for return addr */

	CLD
	REP
	MOVSB
	MOVB	$0,(DI)		/* terminate */

	/* Restore registers */
	MOVQ	R15,0(SP)	/* place ret addr */
	MOVQ	-40(BP),CX
	MOVQ	-32(BP),DI
	MOVQ	-24(BP),SI
	MOVQ	-16(BP),R15
	MOVQ	-8(BP) ,BP
	RET

TEXT sys$alloca+0(SB),$0
	/* save registers */
	MOVQ	(SP),R10	/* ret addr */

	/* get stack space */
	SUBQ	DI,SP		/* get stack space */
	MOVQ	SP,AX		/* top of stack (return value) */
	ANDQ	$(~15),SP	/* align */
	SUBQ	$32,SP		/* "unpop" the args, and make room for ret addr */

	MOVQ	R10,(SP)	/* place ret addr */
	RET

GLOBL	sys$tosptr+0(SB),$8
DATA	sys$tosptr+0(SB)/8,$_tos+0(SB)
GLOBL	sys$curbrk+0(SB),$8
DATA	sys$curbrk+0(SB)/8,$end+0(SB)