]> git.saurik.com Git - apple/libpthread.git/blob - src/pthread_asm.s
libpthread-105.1.4.tar.gz
[apple/libpthread.git] / src / pthread_asm.s
1 /*
2 * Copyright (c) 2012 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 #if defined(__x86_64__)
25
26 #include <mach/i386/syscall_sw.h>
27
28 .text
29 .align 2, 0x90
30 .globl ___pthread_set_self
31 ___pthread_set_self:
32 movl $0, %esi // 0 as the second argument
33 movl $ SYSCALL_CONSTRUCT_MDEP(3), %eax // Machine-dependent syscall number 3
34 MACHDEP_SYSCALL_TRAP
35 ret
36
37 #ifndef VARIANT_DYLD
38
39 .align 2, 0x90
40 .globl _start_wqthread
41 _start_wqthread:
42 // This routine is never called directly by user code, jumped from kernel
43 push %rbp
44 mov %rsp,%rbp
45 sub $24,%rsp // align the stack
46 call __pthread_wqthread
47 leave
48 ret
49
50 .align 2, 0x90
51 .globl _thread_start
52 _thread_start:
53 // This routine is never called directly by user code, jumped from kernel
54 push %rbp
55 mov %rsp,%rbp
56 sub $24,%rsp // align the stack
57 call __pthread_start
58 leave
59 ret
60
61 #endif
62
63 #elif defined(__i386__)
64
65 #include <mach/i386/syscall_sw.h>
66
67 .text
68 .align 2, 0x90
69 .globl ___pthread_set_self
70 ___pthread_set_self:
71 pushl 4(%esp)
72 pushl $0
73 movl $3,%eax
74 MACHDEP_SYSCALL_TRAP
75 addl $8,%esp
76 ret
77
78 #ifndef VARIANT_DYLD
79
80 .align 2, 0x90
81 .globl _start_wqthread
82 _start_wqthread:
83 // This routine is never called directly by user code, jumped from kernel
84 push %ebp
85 mov %esp,%ebp
86 sub $28,%esp // align the stack
87 mov %edi,16(%esp) //arg5
88 mov %edx,12(%esp) //arg4
89 mov %ecx,8(%esp) //arg3
90 mov %ebx,4(%esp) //arg2
91 mov %eax,(%esp) //arg1
92 call __pthread_wqthread
93 leave
94 ret
95
96 .align 2, 0x90
97 .globl _thread_start
98 _thread_start:
99 // This routine is never called directly by user code, jumped from kernel
100 push %ebp
101 mov %esp,%ebp
102 sub $28,%esp // align the stack
103 mov %esi,20(%esp) //arg6
104 mov %edi,16(%esp) //arg5
105 mov %edx,12(%esp) //arg4
106 mov %ecx,8(%esp) //arg3
107 mov %ebx,4(%esp) //arg2
108 mov %eax,(%esp) //arg1
109 call __pthread_start
110 leave
111 ret
112
113 #endif
114
115 #elif defined(__arm__)
116
117 #include <mach/arm/syscall_sw.h>
118
119 .text
120 .align 2
121 .globl ___pthread_set_self
122 ___pthread_set_self:
123 /* fast trap for thread_set_cthread */
124 mov r3, #2
125 mov r12, #0x80000000
126 swi #SWI_SYSCALL
127 bx lr
128
129 #ifndef VARIANT_DYLD
130
131 // This routine is never called directly by user code, jumped from kernel
132 // args 0 to 3 are already in the regs 0 to 3
133 // should set stack with the 2 extra args before calling pthread_wqthread()
134 // arg4 is in r[4]
135 // arg5 is in r[5]
136
137 .text
138 .align 2
139 .globl _start_wqthread
140 _start_wqthread:
141 stmfd sp!, {r4, r5}
142 bl __pthread_wqthread
143 // Stackshots will show the routine that happens to link immediately following
144 // _start_wqthread. So we add an extra instruction (nop) to make stackshots
145 // more readable.
146 nop
147
148 .text
149 .align 2
150 .globl _thread_start
151 _thread_start:
152 stmfd sp!, {r4, r5}
153 bl __pthread_start
154 // See above
155 nop
156
157 #endif
158
159 #else
160 #error Unsupported architecture
161 #endif