]>
Commit | Line | Data |
---|---|---|
b0d623f7 A |
1 | /* |
2 | * Copyright (c) 2000-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 | /* | |
29 | * @OSF_COPYRIGHT@ | |
30 | */ | |
31 | /* | |
32 | * Mach Operating System | |
33 | * Copyright (c) 1991,1990 Carnegie Mellon University | |
34 | * All Rights Reserved. | |
35 | * | |
36 | * Permission to use, copy, modify and distribute this software and its | |
37 | * documentation is hereby granted, provided that both the copyright | |
38 | * notice and this permission notice appear in all copies of the | |
39 | * software, derivative works or modified versions, and any portions | |
40 | * thereof, and that both notices appear in supporting documentation. | |
41 | * | |
42 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" | |
43 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR | |
44 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. | |
45 | * | |
46 | * Carnegie Mellon requests users of this software to return to | |
47 | * | |
48 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU | |
49 | * School of Computer Science | |
50 | * Carnegie Mellon University | |
51 | * Pittsburgh PA 15213-3890 | |
52 | * | |
53 | * any improvements or extensions that they make and grant Carnegie Mellon | |
54 | * the rights to redistribute these changes. | |
55 | */ | |
56 | ||
57 | #include <mach_rt.h> | |
58 | #include <platforms.h> | |
59 | #include <mach_kdb.h> | |
60 | #include <mach_kgdb.h> | |
61 | #include <mach_kdp.h> | |
62 | #include <stat_time.h> | |
63 | #include <mach_assert.h> | |
64 | ||
65 | #include <sys/errno.h> | |
66 | #include <i386/asm.h> | |
67 | #include <i386/cpuid.h> | |
68 | #include <i386/eflags.h> | |
69 | #include <i386/proc_reg.h> | |
70 | #include <i386/trap.h> | |
71 | #include <assym.s> | |
72 | #include <mach/exception_types.h> | |
73 | #include <config_dtrace.h> | |
74 | ||
75 | #define _ARCH_I386_ASM_HELP_H_ /* Prevent inclusion of user header */ | |
76 | #include <mach/i386/syscall_sw.h> | |
77 | ||
78 | #include <i386/mp.h> | |
79 | ||
80 | /* | |
81 | * Fault recovery. | |
82 | */ | |
83 | ||
84 | #ifdef __MACHO__ | |
85 | #define RECOVERY_SECTION .section __VECTORS, __recover | |
86 | #else | |
87 | #define RECOVERY_SECTION .text | |
88 | #define RECOVERY_SECTION .text | |
89 | #endif | |
90 | ||
91 | #define RECOVER_TABLE_START \ | |
92 | .align 3 ; \ | |
93 | .globl EXT(recover_table) ;\ | |
94 | LEXT(recover_table) ;\ | |
95 | .text | |
96 | ||
97 | #define RECOVER(addr) \ | |
98 | .align 3; \ | |
99 | .quad 9f ;\ | |
100 | .quad addr ;\ | |
101 | .text ;\ | |
102 | 9: | |
103 | ||
104 | #define RECOVER_TABLE_END \ | |
105 | .align 3 ;\ | |
106 | .globl EXT(recover_table_end) ;\ | |
107 | LEXT(recover_table_end) ;\ | |
108 | .text | |
109 | ||
110 | /* | |
111 | * Allocate recovery and table. | |
112 | */ | |
113 | RECOVERY_SECTION | |
114 | RECOVER_TABLE_START | |
115 | ||
b0d623f7 A |
116 | /* |
117 | * int rdmsr_carefully(uint32_t msr, uint32_t *lo, uint32_t *hi) | |
118 | */ | |
119 | ENTRY(rdmsr_carefully) | |
120 | movl %edi, %ecx | |
121 | movq %rdx, %rdi | |
122 | RECOVERY_SECTION | |
123 | RECOVER(rdmsr_fail) | |
124 | rdmsr | |
125 | movl %eax, (%rsi) | |
126 | movl %edx, (%rdi) | |
127 | xorl %eax, %eax | |
128 | ret | |
129 | ||
130 | rdmsr_fail: | |
131 | movq $1, %rax | |
132 | ret | |
133 | ||
134 | .globl EXT(thread_exception_return) | |
135 | .globl EXT(thread_bootstrap_return) | |
136 | LEXT(thread_bootstrap_return) | |
137 | #if CONFIG_DTRACE | |
138 | call EXT(dtrace_thread_bootstrap) | |
139 | #endif | |
140 | ||
141 | LEXT(thread_exception_return) | |
142 | cli | |
6d2010ae | 143 | xorl %ecx, %ecx /* don't check if we're in the PFZ */ |
b0d623f7 A |
144 | jmp EXT(return_from_trap) |
145 | ||
146 | /* | |
147 | * Copyin/out from user/kernel address space. | |
148 | * rdi: source address | |
149 | * rsi: destination address | |
150 | * rdx: byte count | |
151 | */ | |
152 | Entry(_bcopy) | |
153 | // TODO not pop regs; movq; think about 32 bit or 64 bit byte count | |
154 | xchgq %rdi, %rsi /* source %rsi, dest %rdi */ | |
155 | ||
156 | cld /* count up */ | |
157 | movl %edx,%ecx /* move by longwords first */ | |
158 | shrl $3,%ecx | |
159 | RECOVERY_SECTION | |
160 | RECOVER(_bcopy_fail) | |
161 | rep | |
162 | movsq /* move longwords */ | |
163 | ||
164 | movl %edx,%ecx /* now move remaining bytes */ | |
165 | andl $7,%ecx | |
166 | RECOVERY_SECTION | |
167 | RECOVER(_bcopy_fail) | |
168 | rep | |
169 | movsb | |
170 | ||
171 | xorl %eax,%eax /* return 0 for success */ | |
172 | ret /* and return */ | |
173 | ||
174 | _bcopy_fail: | |
175 | movl $(EFAULT),%eax /* return error for failure */ | |
176 | ret | |
177 | ||
6d2010ae A |
178 | Entry(pmap_safe_read) |
179 | RECOVERY_SECTION | |
180 | RECOVER(_pmap_safe_read_fail) | |
181 | movq (%rdi), %rcx | |
182 | mov %rcx, (%rsi) | |
183 | mov $1, %eax | |
184 | ret | |
185 | _pmap_safe_read_fail: | |
186 | xor %eax, %eax | |
187 | ret | |
188 | ||
b0d623f7 A |
189 | |
190 | ||
191 | /* | |
192 | * Copyin string from user/kern address space. | |
193 | * rdi: source address | |
194 | * rsi: destination address | |
195 | * rdx: max byte count | |
196 | * rcx: actual byte count (OUT) | |
197 | */ | |
198 | Entry(_bcopystr) | |
199 | pushq %rdi | |
200 | xchgq %rdi, %rsi /* source %rsi, dest %rdi */ | |
201 | ||
202 | xorl %eax,%eax /* set to 0 here so that high 24 bits */ | |
203 | /* are 0 for the cmpl against 0 */ | |
204 | 2: | |
205 | RECOVERY_SECTION | |
206 | RECOVER(_bcopystr_fail) /* copy bytes... */ | |
207 | movb (%rsi),%al | |
208 | incq %rsi | |
209 | testq %rdi,%rdi /* if kernel address is ... */ | |
210 | jz 3f /* not NULL */ | |
211 | movb %al,(%rdi) /* copy the byte */ | |
212 | incq %rdi | |
213 | 3: | |
214 | testl %eax,%eax /* did we just stuff the 0-byte? */ | |
215 | jz 4f /* yes, return 0 already in %eax */ | |
216 | decq %rdx /* decrement #bytes left in buffer */ | |
217 | jnz 2b /* buffer not full, copy another byte */ | |
218 | movl $(ENAMETOOLONG),%eax /* buffer full, no \0: ENAMETOOLONG */ | |
219 | 4: | |
220 | cmpq $0,%rcx /* get OUT len ptr */ | |
221 | jz _bcopystr_ret /* if null, just return */ | |
222 | subq (%rsp),%rsi | |
223 | movq %rsi,(%rcx) /* else set OUT arg to xfer len */ | |
224 | popq %rdi /* restore registers */ | |
225 | _bcopystr_ret: | |
226 | ret /* and return */ | |
227 | ||
228 | _bcopystr_fail: | |
229 | popq %rdi /* restore registers */ | |
230 | movl $(EFAULT),%eax /* return error for failure */ | |
231 | ret | |
232 | ||
b0d623f7 A |
233 | /* |
234 | * Done with recovery table. | |
235 | */ | |
236 | RECOVERY_SECTION | |
237 | RECOVER_TABLE_END | |
238 |