]> git.saurik.com Git - apple/xnu.git/blob - osfmk/ppc/misc.c
xnu-344.49.tar.gz
[apple/xnu.git] / osfmk / ppc / misc.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /*
26 * @OSF_COPYRIGHT@
27 */
28 #include <debug.h>
29 #include <mach_debug.h>
30
31 #include <mach/ppc/thread_status.h>
32 #include <mach/vm_types.h>
33 #include <kern/thread.h>
34 #include <kern/misc_protos.h>
35 #include <ppc/proc_reg.h>
36 #include <ppc/pmap.h>
37 #include <ppc/misc_protos.h>
38 #include <ppc/exception.h>
39
40 /*
41 * copyin/out_multiple - the assembler copyin/out functions jump to C for
42 * help when the copyin lies over a segment boundary. The C breaks
43 * down the copy into two sub-copies and re-calls the assembler with
44 * these sub-copies. Very rare occurrance. Warning: These functions are
45 * called whilst active_thread->thread_recover is still set.
46 */
47
48 extern boolean_t copyin_multiple(const char *src,
49 char *dst,
50 vm_size_t count);
51
52 boolean_t copyin_multiple(const char *src,
53 char *dst,
54 vm_size_t count)
55 {
56 const char *midpoint;
57 vm_size_t first_count;
58 boolean_t first_result;
59
60 /* Assert that we've been called because of a segment boundary,
61 * this function is more expensive than the assembler, and should
62 * only be called in this difficult case.
63 */
64 assert(((vm_offset_t)src & 0xF0000000) !=
65 ((vm_offset_t)(src + count -1) & 0xF0000000));
66
67 /* TODO NMGS define sensible constants for segments, and apply
68 * to C and assembler (assembler is much harder)
69 */
70 midpoint = (const char*) ((vm_offset_t)(src + count) & 0xF0000000);
71 first_count = (midpoint - src);
72
73 first_result = copyin(src, dst, first_count);
74
75 /* If there was an error, stop now and return error */
76 if (first_result != 0)
77 return first_result;
78
79 /* otherwise finish the job and return result */
80 return copyin(midpoint, dst + first_count, count-first_count);
81 }
82
83 extern int copyout_multiple(const char *src, char *dst, vm_size_t count);
84
85 int copyout_multiple(const char *src, char *dst, vm_size_t count)
86 {
87 char *midpoint;
88 vm_size_t first_count;
89 boolean_t first_result;
90
91 /* Assert that we've been called because of a segment boundary,
92 * this function is more expensive than the assembler, and should
93 * only be called in this difficult case. For copyout, the
94 * segment boundary is on the dst
95 */
96 assert(((vm_offset_t)dst & 0xF0000000) !=
97 ((vm_offset_t)(dst + count - 1) & 0xF0000000));
98
99 /* TODO NMGS define sensible constants for segments, and apply
100 * to C and assembler (assembler is much harder)
101 */
102 midpoint = (char *) ((vm_offset_t)(dst + count) & 0xF0000000);
103 first_count = (midpoint - dst);
104
105 first_result = copyout(src, dst, first_count);
106
107 /* If there was an error, stop now and return error */
108 if (first_result != 0)
109 return first_result;
110
111 /* otherwise finish the job and return result */
112
113 return copyout(src + first_count, midpoint, count-first_count);
114 }
115