]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/loose_ends.c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
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
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.
23 * @APPLE_LICENSE_HEADER_END@
29 * Mach Operating System
30 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
31 * All Rights Reserved.
33 * Permission to use, copy, modify and distribute this software and its
34 * documentation is hereby granted, provided that both the copyright
35 * notice and this permission notice appear in all copies of the
36 * software, derivative works or modified versions, and any portions
37 * thereof, and that both notices appear in supporting documentation.
39 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
40 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
41 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
43 * Carnegie Mellon requests users of this software to return to
45 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
46 * School of Computer Science
47 * Carnegie Mellon University
48 * Pittsburgh PA 15213-3890
50 * any improvements or extensions that they make and grant Carnegie Mellon
51 * the rights to redistribute these changes.
55 #include <mach_assert.h>
58 #include <mach/boolean.h>
59 #include <mach/i386/vm_types.h>
60 #include <mach/i386/vm_param.h>
61 #include <kern/kern_types.h>
62 #include <kern/misc_protos.h>
63 #include <i386/misc_protos.h>
66 * Should be rewritten in asm anyway.
71 * copy 'size' bytes from physical to physical address
72 * the caller must validate the physical ranges
74 * if flush_action == 0, no cache flush necessary
75 * if flush_action == 1, flush the source
76 * if flush_action == 2, flush the dest
77 * if flush_action == 3, flush both source and dest
80 kern_return_t
copyp2p(vm_offset_t source
, vm_offset_t dest
, unsigned int size
, unsigned int flush_action
) {
82 switch(flush_action
) {
84 flush_dcache(source
, size
, 1);
87 flush_dcache(dest
, size
, 1);
90 flush_dcache(source
, size
, 1);
91 flush_dcache(dest
, size
, 1);
95 bcopy_phys((char *)source
, (char *)dest
, size
); /* Do a physical copy */
97 switch(flush_action
) {
99 flush_dcache(source
, size
, 1);
102 flush_dcache(dest
, size
, 1);
105 flush_dcache(source
, size
, 1);
106 flush_dcache(dest
, size
, 1);
115 * Copies data from a physical page to a virtual page. This is used to
116 * move data from the kernel to user state.
121 copyp2v(char *from
, char *to
, unsigned int size
) {
123 return(copyout(phystokv(from
), to
, size
));
127 * bcopy_phys - like bcopy but copies from/to physical addresses.
128 * this is trivial since all phys mem is mapped into
129 * kernel virtual space
133 bcopy_phys(const char *from
, char *to
, vm_size_t bytes
)
135 bcopy((char *)phystokv(from
), (char *)phystokv(to
), bytes
);
140 * ovbcopy - like bcopy, but recognizes overlapping ranges and handles
148 vm_size_t bytes
) /* num bytes to copy */
150 /* Assume that bcopy copies left-to-right (low addr first). */
151 if (from
+ bytes
<= to
|| to
+ bytes
<= from
|| to
== from
)
152 bcopy_no_overwrite(from
, to
, bytes
); /* non-overlapping or no-op*/
154 bcopy_no_overwrite(from
, to
, bytes
); /* overlapping but OK */
156 /* to > from: overlapping, and must copy right-to-left. */
168 vm_size_t bytes
) /* num bytes to copy */
170 ovbcopy(from
, to
, bytes
);
191 register char *s1
, *s2
;
196 return (*--s1
- *--s2
);
202 * strlen returns the number of characters in "string" preceeding
203 * the terminating null character.
208 register const char *string
)
210 register const char *ret
= string
;
212 while (*string
++ != '\0')
214 return string
- 1 - ret
;
217 #include <libkern/OSAtomic.h>
229 newValue
= (oldValue
+ delt
);
230 } while (!OSCompareAndSwap((UInt32
)oldValue
,
231 (UInt32
)newValue
, (UInt32
*)dest
));
246 newValue
= (oldValue
- delt
);
247 } while (!OSCompareAndSwap((UInt32
)oldValue
,
248 (UInt32
)newValue
, (UInt32
*)dest
));
263 newValue
= (oldValue
| mask
);
264 } while (!OSCompareAndSwap((UInt32
)oldValue
,
265 (UInt32
)newValue
, (UInt32
*)dest
));
280 newValue
= (oldValue
& mask
);
281 } while (!OSCompareAndSwap((UInt32
)oldValue
,
282 (UInt32
)newValue
, (UInt32
*)dest
));
288 hw_compare_and_store(
293 return OSCompareAndSwap((UInt32
)oldval
, (UInt32
)newval
, (UInt32
*)dest
);
299 * Machine-dependent routine to fill in an array with up to callstack_max
300 * levels of return pc information.
302 void machine_callstack(
304 vm_size_t callstack_max
)
308 #endif /* MACH_ASSERT */
314 /* These all need to be implemented somewhere */
316 void fillPage(ppnum_t pa
, unsigned int fill
)
325 ppnum_t
pmap_find_phys(pmap_t pmap
, addr64_t va
)
330 kern_return_t
copypv(addr64_t source
, addr64_t sink
, unsigned int size
, int which
)
335 void mapping_set_mod(ppnum_t pa
)
339 void flush_dcache64(addr64_t addr
, unsigned count
, int phys
)
343 void invalidate_icache64(addr64_t addr
, unsigned cnt
, int phys
)