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