summaryrefslogtreecommitdiff
path: root/lib/thread/start+osx-x64.s
blob: 081ed45412284ad08a2c5e7b93a130b3a6ea095c (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
# The entry point for thread start, registered with bsdthread_register
#      %rdi: pthread (0, for us)
#      %rsi: mach thread port (ignored)
#      %rdx: func
#      %rcx: env
#      %r8: stack
#      %r9: flags (= 0)
#      %rsp: stack - C_64_REDZONE_LEN (= stack - 128)
.globl _thread$start
_thread$start:
	/* call the function */
	movq	%r8, %rsp	/* set up stack */
	movq	%rcx,%rdi
        callq    *%rdx		/* call function */
	
/*
const thread.exit	: (stacksz : std.size -> void)
*/
.globl _thread$exit
_thread$exit:
	/* munmap(base, size) */
	movq	$0x2000049,%rax	/* munmap */
	movq	%gs:0x08,%rdi	/* base */
	movq	%gs:0x10,%rsi	/* stksz */
	syscall

	/* exit the thread */
	movq	$0x2000169, %rax	/* Sysbsdthread_terminate */
	movq	$0, %rdi	/* stack */
	movq	$0, %rsi	/* len */
	movq	$0, %rdx	/* sem */
	syscall