]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/ppc/misc.c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
33 #include <mach_debug.h>
35 #include <mach/ppc/thread_status.h>
36 #include <mach/vm_types.h>
37 #include <kern/thread.h>
38 #include <kern/misc_protos.h>
39 #include <ppc/proc_reg.h>
41 #include <ppc/misc_protos.h>
42 #include <ppc/exception.h>
45 * copyin/out_multiple - the assembler copyin/out functions jump to C for
46 * help when the copyin lies over a segment boundary. The C breaks
47 * down the copy into two sub-copies and re-calls the assembler with
48 * these sub-copies. Very rare occurrance. Warning: These functions are
49 * called whilst active_thread->thread_recover is still set.
52 extern boolean_t
copyin_multiple(const char *src
,
56 boolean_t
copyin_multiple(const char *src
,
61 vm_size_t first_count
;
62 boolean_t first_result
;
64 /* Assert that we've been called because of a segment boundary,
65 * this function is more expensive than the assembler, and should
66 * only be called in this difficult case.
68 assert(((vm_offset_t
)src
& 0xF0000000) !=
69 ((vm_offset_t
)(src
+ count
-1) & 0xF0000000));
71 /* TODO NMGS define sensible constants for segments, and apply
72 * to C and assembler (assembler is much harder)
74 midpoint
= (const char*) ((vm_offset_t
)(src
+ count
) & 0xF0000000);
75 first_count
= (midpoint
- src
);
77 first_result
= copyin(CAST_USER_ADDR_T(src
), dst
, first_count
);
79 /* If there was an error, stop now and return error */
80 if (first_result
!= 0)
83 /* otherwise finish the job and return result */
84 return copyin(CAST_USER_ADDR_T(midpoint
), dst
+ first_count
, count
-first_count
);
87 extern int copyout_multiple(const char *src
, char *dst
, vm_size_t count
);
89 int copyout_multiple(const char *src
, char *dst
, vm_size_t count
)
92 vm_size_t first_count
;
93 boolean_t first_result
;
95 /* Assert that we've been called because of a segment boundary,
96 * this function is more expensive than the assembler, and should
97 * only be called in this difficult case. For copyout, the
98 * segment boundary is on the dst
100 assert(((vm_offset_t
)dst
& 0xF0000000) !=
101 ((vm_offset_t
)(dst
+ count
- 1) & 0xF0000000));
103 /* TODO NMGS define sensible constants for segments, and apply
104 * to C and assembler (assembler is much harder)
106 midpoint
= (char *) ((vm_offset_t
)(dst
+ count
) & 0xF0000000);
107 first_count
= (midpoint
- dst
);
109 first_result
= copyout(src
, CAST_USER_ADDR_T(dst
), first_count
);
111 /* If there was an error, stop now and return error */
112 if (first_result
!= 0)
115 /* otherwise finish the job and return result */
117 return copyout(src
+ first_count
, CAST_USER_ADDR_T(midpoint
), count
-first_count
);