xref: /xnu-8792.41.9/libsyscall/custom/custom.s (revision 5c2921b07a2480ab43ec66f5b9e41cb872bc554f)
1*5c2921b0SApple OSS Distributions/*
2*5c2921b0SApple OSS Distributions * Copyright (c) 1999-2015 Apple Inc. All rights reserved.
3*5c2921b0SApple OSS Distributions *
4*5c2921b0SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*5c2921b0SApple OSS Distributions *
6*5c2921b0SApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code
7*5c2921b0SApple OSS Distributions * as defined in and that are subject to the Apple Public Source License
8*5c2921b0SApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in
9*5c2921b0SApple OSS Distributions * compliance with the License. The rights granted to you under the License
10*5c2921b0SApple OSS Distributions * may not be used to create, or enable the creation or redistribution of,
11*5c2921b0SApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to
12*5c2921b0SApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any
13*5c2921b0SApple OSS Distributions * terms of an Apple operating system software license agreement.
14*5c2921b0SApple OSS Distributions *
15*5c2921b0SApple OSS Distributions * Please obtain a copy of the License at
16*5c2921b0SApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*5c2921b0SApple OSS Distributions *
18*5c2921b0SApple OSS Distributions * The Original Code and all software distributed under the License are
19*5c2921b0SApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*5c2921b0SApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*5c2921b0SApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*5c2921b0SApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*5c2921b0SApple OSS Distributions * Please see the License for the specific language governing rights and
24*5c2921b0SApple OSS Distributions * limitations under the License.
25*5c2921b0SApple OSS Distributions *
26*5c2921b0SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*5c2921b0SApple OSS Distributions */
28*5c2921b0SApple OSS Distributions/* Copyright (c) 1992 NeXT Computer, Inc.  All rights reserved.
29*5c2921b0SApple OSS Distributions */
30*5c2921b0SApple OSS Distributions
31*5c2921b0SApple OSS Distributions#include "SYS.h"
32*5c2921b0SApple OSS Distributions
33*5c2921b0SApple OSS Distributions#if defined(__i386__)
34*5c2921b0SApple OSS Distributions
35*5c2921b0SApple OSS Distributions/*
36*5c2921b0SApple OSS Distributions * i386 needs custom assembly to transform the return from syscalls
37*5c2921b0SApple OSS Distributions * into a proper stack for a function call out to cerror{,_nocancel}.
38*5c2921b0SApple OSS Distributions */
39*5c2921b0SApple OSS Distributions
40*5c2921b0SApple OSS DistributionsLABEL(tramp_cerror)
41*5c2921b0SApple OSS Distributions	mov		%esp, %edx
42*5c2921b0SApple OSS Distributions	andl	$0xfffffff0, %esp
43*5c2921b0SApple OSS Distributions	subl	$16, %esp
44*5c2921b0SApple OSS Distributions	movl	%edx, 4(%esp)
45*5c2921b0SApple OSS Distributions	movl	%eax, (%esp)
46*5c2921b0SApple OSS Distributions	CALL_EXTERN(_cerror)
47*5c2921b0SApple OSS Distributions	movl	4(%esp), %esp
48*5c2921b0SApple OSS Distributions	ret
49*5c2921b0SApple OSS Distributions
50*5c2921b0SApple OSS DistributionsLABEL(tramp_cerror_nocancel)
51*5c2921b0SApple OSS Distributions	mov		%esp, %edx
52*5c2921b0SApple OSS Distributions	andl	$0xfffffff0, %esp
53*5c2921b0SApple OSS Distributions	subl	$16, %esp
54*5c2921b0SApple OSS Distributions	movl	%edx, 4(%esp)
55*5c2921b0SApple OSS Distributions	movl	%eax, (%esp)
56*5c2921b0SApple OSS Distributions	CALL_EXTERN(_cerror_nocancel)
57*5c2921b0SApple OSS Distributions	movl	4(%esp), %esp
58*5c2921b0SApple OSS Distributions	ret
59*5c2921b0SApple OSS Distributions
60*5c2921b0SApple OSS DistributionsLABEL(__sysenter_trap)
61*5c2921b0SApple OSS Distributions	popl %edx
62*5c2921b0SApple OSS Distributions	movl %esp, %ecx
63*5c2921b0SApple OSS Distributions	sysenter
64*5c2921b0SApple OSS Distributions
65*5c2921b0SApple OSS Distributions	.globl _i386_get_ldt
66*5c2921b0SApple OSS Distributions	ALIGN
67*5c2921b0SApple OSS Distributions_i386_get_ldt:
68*5c2921b0SApple OSS Distributions	movl    $6,%eax
69*5c2921b0SApple OSS Distributions	MACHDEP_SYSCALL_TRAP
70*5c2921b0SApple OSS Distributions	jnb		2f
71*5c2921b0SApple OSS Distributions	jmp		tramp_cerror
72*5c2921b0SApple OSS Distributions2:	ret
73*5c2921b0SApple OSS Distributions
74*5c2921b0SApple OSS Distributions
75*5c2921b0SApple OSS Distributions	.globl _i386_set_ldt
76*5c2921b0SApple OSS Distributions	ALIGN
77*5c2921b0SApple OSS Distributions_i386_set_ldt:
78*5c2921b0SApple OSS Distributions	movl    $5,%eax
79*5c2921b0SApple OSS Distributions	MACHDEP_SYSCALL_TRAP
80*5c2921b0SApple OSS Distributions	jnb		2f
81*5c2921b0SApple OSS Distributions	jmp		tramp_cerror
82*5c2921b0SApple OSS Distributions2:	ret
83*5c2921b0SApple OSS Distributions
84*5c2921b0SApple OSS Distributions	ALIGN
85*5c2921b0SApple OSS Distributions	.globl __thread_set_tsd_base
86*5c2921b0SApple OSS Distributions__thread_set_tsd_base:
87*5c2921b0SApple OSS Distributions	pushl   4(%esp)
88*5c2921b0SApple OSS Distributions	pushl   $0
89*5c2921b0SApple OSS Distributions	movl    $3,%eax
90*5c2921b0SApple OSS Distributions	MACHDEP_SYSCALL_TRAP
91*5c2921b0SApple OSS Distributions	addl    $8,%esp
92*5c2921b0SApple OSS Distributions	ret
93*5c2921b0SApple OSS Distributions
94*5c2921b0SApple OSS Distributions#elif defined(__x86_64__)
95*5c2921b0SApple OSS Distributions
96*5c2921b0SApple OSS Distributions	.globl _i386_get_ldt
97*5c2921b0SApple OSS Distributions	ALIGN
98*5c2921b0SApple OSS Distributions_i386_get_ldt:
99*5c2921b0SApple OSS Distributions	movl    $SYSCALL_CONSTRUCT_MDEP(6), %eax
100*5c2921b0SApple OSS Distributions	MACHDEP_SYSCALL_TRAP
101*5c2921b0SApple OSS Distributions	jnb		2f
102*5c2921b0SApple OSS Distributions	movq	%rax, %rdi
103*5c2921b0SApple OSS Distributions	jmp		_cerror
104*5c2921b0SApple OSS Distributions2:	ret
105*5c2921b0SApple OSS Distributions
106*5c2921b0SApple OSS Distributions
107*5c2921b0SApple OSS Distributions	.globl _i386_set_ldt
108*5c2921b0SApple OSS Distributions	ALIGN
109*5c2921b0SApple OSS Distributions_i386_set_ldt:
110*5c2921b0SApple OSS Distributions	movl    $SYSCALL_CONSTRUCT_MDEP(5), %eax
111*5c2921b0SApple OSS Distributions	MACHDEP_SYSCALL_TRAP
112*5c2921b0SApple OSS Distributions	jnb		2f
113*5c2921b0SApple OSS Distributions	movq	%rax, %rdi
114*5c2921b0SApple OSS Distributions	jmp		_cerror
115*5c2921b0SApple OSS Distributions2:	ret
116*5c2921b0SApple OSS Distributions
117*5c2921b0SApple OSS Distributions	ALIGN
118*5c2921b0SApple OSS Distributions	.globl __thread_set_tsd_base
119*5c2921b0SApple OSS Distributions__thread_set_tsd_base:
120*5c2921b0SApple OSS Distributions	movl	$0, %esi	// 0 as the second argument
121*5c2921b0SApple OSS Distributions	movl    $ SYSCALL_CONSTRUCT_MDEP(3), %eax	// Machine-dependent syscall number 3
122*5c2921b0SApple OSS Distributions	MACHDEP_SYSCALL_TRAP
123*5c2921b0SApple OSS Distributions	ret
124*5c2921b0SApple OSS Distributions
125*5c2921b0SApple OSS Distributions#elif defined(__arm__)
126*5c2921b0SApple OSS Distributions
127*5c2921b0SApple OSS Distributions	.align 2
128*5c2921b0SApple OSS Distributions	.globl __thread_set_tsd_base
129*5c2921b0SApple OSS Distributions__thread_set_tsd_base:
130*5c2921b0SApple OSS Distributions	mov	r3, #2
131*5c2921b0SApple OSS Distributions	mov	r12, #0x80000000
132*5c2921b0SApple OSS Distributions	swi	#SWI_SYSCALL
133*5c2921b0SApple OSS Distributions	bx	lr
134*5c2921b0SApple OSS Distributions
135*5c2921b0SApple OSS Distributions#elif defined(__arm64__)
136*5c2921b0SApple OSS Distributions
137*5c2921b0SApple OSS Distributions	.align 2
138*5c2921b0SApple OSS Distributions	.globl __thread_set_tsd_base
139*5c2921b0SApple OSS Distributions__thread_set_tsd_base:
140*5c2921b0SApple OSS Distributions	mov	x3, #2
141*5c2921b0SApple OSS Distributions	mov	x16, #0x80000000
142*5c2921b0SApple OSS Distributions	svc 	#SWI_SYSCALL
143*5c2921b0SApple OSS Distributions	ret
144*5c2921b0SApple OSS Distributions
145*5c2921b0SApple OSS Distributions#else
146*5c2921b0SApple OSS Distributions#error unknown architecture
147*5c2921b0SApple OSS Distributions#endif
148*5c2921b0SApple OSS Distributions
149*5c2921b0SApple OSS Distributions.subsections_via_symbols
150