]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/ppc/misc.c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
27 #include <mach_debug.h>
29 #include <mach/ppc/thread_status.h>
30 #include <mach/vm_types.h>
31 #include <kern/thread.h>
32 #include <kern/misc_protos.h>
33 #include <ppc/proc_reg.h>
35 #include <ppc/misc_protos.h>
36 #include <ppc/exception.h>
39 * copyin/out_multiple - the assembler copyin/out functions jump to C for
40 * help when the copyin lies over a segment boundary. The C breaks
41 * down the copy into two sub-copies and re-calls the assembler with
42 * these sub-copies. Very rare occurrance. Warning: These functions are
43 * called whilst active_thread->thread_recover is still set.
46 extern boolean_t
copyin_multiple(const char *src
,
50 boolean_t
copyin_multiple(const char *src
,
55 vm_size_t first_count
;
56 boolean_t first_result
;
58 /* Assert that we've been called because of a segment boundary,
59 * this function is more expensive than the assembler, and should
60 * only be called in this difficult case.
62 assert(((vm_offset_t
)src
& 0xF0000000) !=
63 ((vm_offset_t
)(src
+ count
-1) & 0xF0000000));
65 /* TODO NMGS define sensible constants for segments, and apply
66 * to C and assembler (assembler is much harder)
68 midpoint
= (const char*) ((vm_offset_t
)(src
+ count
) & 0xF0000000);
69 first_count
= (midpoint
- src
);
71 first_result
= copyin(CAST_USER_ADDR_T(src
), dst
, first_count
);
73 /* If there was an error, stop now and return error */
74 if (first_result
!= 0)
77 /* otherwise finish the job and return result */
78 return copyin(CAST_USER_ADDR_T(midpoint
), dst
+ first_count
, count
-first_count
);
81 extern int copyout_multiple(const char *src
, char *dst
, vm_size_t count
);
83 int copyout_multiple(const char *src
, char *dst
, vm_size_t count
)
86 vm_size_t first_count
;
87 boolean_t first_result
;
89 /* Assert that we've been called because of a segment boundary,
90 * this function is more expensive than the assembler, and should
91 * only be called in this difficult case. For copyout, the
92 * segment boundary is on the dst
94 assert(((vm_offset_t
)dst
& 0xF0000000) !=
95 ((vm_offset_t
)(dst
+ count
- 1) & 0xF0000000));
97 /* TODO NMGS define sensible constants for segments, and apply
98 * to C and assembler (assembler is much harder)
100 midpoint
= (char *) ((vm_offset_t
)(dst
+ count
) & 0xF0000000);
101 first_count
= (midpoint
- dst
);
103 first_result
= copyout(src
, CAST_USER_ADDR_T(dst
), first_count
);
105 /* If there was an error, stop now and return error */
106 if (first_result
!= 0)
109 /* otherwise finish the job and return result */
111 return copyout(src
+ first_count
, CAST_USER_ADDR_T(midpoint
), count
-first_count
);