summaryrefslogtreecommitdiff
path: root/libstd/util.s
blob: f56ea42d5990b6d6f2174e47ac80b9e1a417bd86 (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
/*
 * 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
 * %rsp when returning.
 */
.globl std$cstring
.globl _std$cstring
_std$cstring:
std$cstring:
	movq (%rsp),%r15	/* ret addr */
	movq 8(%rsp),%rsi	/* src */
        movq %rsp,%rdi          /* dest */
	movq %rsp,%rax          /* ret val */
	movq 16(%rsp),%rcx	/* len */

        subq $16,%rsp           /* compensate for args */
	subq %rcx,%rsp          /* get stack */
        subq $1,%rsp            /* nul */
        andq $(~15),%rsp        /* align */

	cld
	rep movsb
        movb $0,(%rdi)          /* terminate */

	pushq %r15              /* ret addr */
	ret