]> git.saurik.com Git - apple/xnu.git/blob - libsyscall/custom/custom.s
xnu-1456.1.26.tar.gz
[apple/xnu.git] / libsyscall / custom / custom.s
1 /*
2 * Copyright (c) 1999-2007 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_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. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28 /* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved.
29 */
30
31 #include "SYS.h"
32
33 #if defined(__ppc__) || defined(__ppc64__)
34
35 /* We use mode-independent "g" opcodes such as "srgi", and/or
36 * mode-independent macros such as MI_GET_ADDRESS. These expand
37 * into word operations when targeting __ppc__, and into doubleword
38 * operations when targeting __ppc64__.
39 */
40 #include <architecture/ppc/mode_independent_asm.h>
41
42 .globl _errno
43
44 MI_ENTRY_POINT(cerror)
45 MI_PUSH_STACK_FRAME
46 MI_GET_ADDRESS(r12,_errno)
47 stw r3,0(r12) /* save syscall return code in global */
48 MI_CALL_EXTERNAL(_cthread_set_errno_self)
49 li r3,-1 /* then bug return value */
50 li r4,-1 /* in case we're returning a long-long in 32-bit mode, etc */
51 MI_POP_STACK_FRAME_AND_RETURN
52
53
54 .globl _processor_facilities_used
55 .align 2
56 _processor_facilities_used:
57 li r0,0x7FF3
58 sc
59 blr
60
61 #elif defined(__i386__)
62
63 .globl _errno
64
65 LABEL(cerror)
66 REG_TO_EXTERN(%eax, _errno)
67 mov %esp,%edx
68 andl $0xfffffff0,%esp
69 subl $16,%esp
70 movl %edx,4(%esp)
71 movl %eax,(%esp)
72 CALL_EXTERN(_cthread_set_errno_self)
73 movl 4(%esp),%esp
74 movl $-1,%eax
75 movl $-1,%edx /* in case a 64-bit value is returned */
76 ret
77
78 .private_extern __sysenter_trap
79 ALIGN
80 __sysenter_trap:
81 popl %edx
82 movl %esp, %ecx
83 sysenter
84
85 #elif defined(__x86_64__)
86
87 .globl _errno
88
89 LABEL(cerror)
90 REG_TO_EXTERN(%rax, _errno)
91 mov %rsp,%rdx
92 andq $-16,%rsp
93 subq $16,%rsp
94 // Preserve the original stack
95 movq %rdx,(%rsp)
96 movq %rax,%rdi
97 CALL_EXTERN(_cthread_set_errno_self)
98 // Restore the original stack
99 movq (%rsp),%rsp
100 movq $-1,%rax
101 movq $-1,%rdx /* in case a 128-bit value is returned */
102 ret
103
104 #else
105 #error Unsupported architecture
106 #endif
107
108 #if defined(__i386__) || defined(__x86_64__)
109
110 .globl _i386_get_ldt
111 ALIGN
112 _i386_get_ldt:
113 movl $6,%eax
114 MACHDEP_SYSCALL_TRAP
115 jnb 2f
116 jmp cerror
117 2: ret
118
119
120 .globl _i386_set_ldt
121 ALIGN
122 _i386_set_ldt:
123 movl $5,%eax
124 MACHDEP_SYSCALL_TRAP
125 jnb 2f
126 jmp cerror
127 2: ret
128
129 #endif