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