]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/loose_ends.c
b0cd27fffdea95a0cd901f63905aa54f6ab5336c
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@
26 * Mach Operating System
27 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
28 * All Rights Reserved.
30 * Permission to use, copy, modify and distribute this software and its
31 * documentation is hereby granted, provided that both the copyright
32 * notice and this permission notice appear in all copies of the
33 * software, derivative works or modified versions, and any portions
34 * thereof, and that both notices appear in supporting documentation.
36 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
37 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
38 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
40 * Carnegie Mellon requests users of this software to return to
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
52 #include <mach_assert.h>
55 #include <mach/boolean.h>
56 #include <mach/i386/vm_types.h>
57 #include <mach/i386/vm_param.h>
58 #include <kern/kern_types.h>
59 #include <kern/misc_protos.h>
60 #include <i386/misc_protos.h>
63 * Should be rewritten in asm anyway.
68 * copy 'size' bytes from physical to physical address
69 * the caller must validate the physical ranges
71 * if flush_action == 0, no cache flush necessary
72 * if flush_action == 1, flush the source
73 * if flush_action == 2, flush the dest
74 * if flush_action == 3, flush both source and dest
77 kern_return_t
copyp2p(vm_offset_t source
, vm_offset_t dest
, unsigned int size
, unsigned int flush_action
) {
79 switch(flush_action
) {
81 flush_dcache(source
, size
, 1);
84 flush_dcache(dest
, size
, 1);
87 flush_dcache(source
, size
, 1);
88 flush_dcache(dest
, size
, 1);
92 bcopy_phys((char *)source
, (char *)dest
, size
); /* Do a physical copy */
94 switch(flush_action
) {
96 flush_dcache(source
, size
, 1);
99 flush_dcache(dest
, size
, 1);
102 flush_dcache(source
, size
, 1);
103 flush_dcache(dest
, size
, 1);
112 * Copies data from a physical page to a virtual page. This is used to
113 * move data from the kernel to user state.
118 copyp2v(char *from
, char *to
, unsigned int size
) {
120 return(copyout(phystokv(from
), to
, size
));
124 * bcopy_phys - like bcopy but copies from/to physical addresses.
125 * this is trivial since all phys mem is mapped into
126 * kernel virtual space
130 bcopy_phys(const char *from
, char *to
, vm_size_t bytes
)
132 bcopy((char *)phystokv(from
), (char *)phystokv(to
), bytes
);
137 * ovbcopy - like bcopy, but recognizes overlapping ranges and handles
145 vm_size_t bytes
) /* num bytes to copy */
147 /* Assume that bcopy copies left-to-right (low addr first). */
148 if (from
+ bytes
<= to
|| to
+ bytes
<= from
|| to
== from
)
149 bcopy_no_overwrite(from
, to
, bytes
); /* non-overlapping or no-op*/
151 bcopy_no_overwrite(from
, to
, bytes
); /* overlapping but OK */
153 /* to > from: overlapping, and must copy right-to-left. */
165 vm_size_t bytes
) /* num bytes to copy */
167 ovbcopy(from
, to
, bytes
);
188 register char *s1
, *s2
;
193 return (*--s1
- *--s2
);
199 * strlen returns the number of characters in "string" preceeding
200 * the terminating null character.
205 register const char *string
)
207 register const char *ret
= string
;
209 while (*string
++ != '\0')
211 return string
- 1 - ret
;
214 #include <libkern/OSAtomic.h>
226 newValue
= (oldValue
+ delt
);
227 } while (!OSCompareAndSwap((UInt32
)oldValue
,
228 (UInt32
)newValue
, (UInt32
*)dest
));
243 newValue
= (oldValue
- delt
);
244 } while (!OSCompareAndSwap((UInt32
)oldValue
,
245 (UInt32
)newValue
, (UInt32
*)dest
));
260 newValue
= (oldValue
| mask
);
261 } while (!OSCompareAndSwap((UInt32
)oldValue
,
262 (UInt32
)newValue
, (UInt32
*)dest
));
277 newValue
= (oldValue
& mask
);
278 } while (!OSCompareAndSwap((UInt32
)oldValue
,
279 (UInt32
)newValue
, (UInt32
*)dest
));
285 hw_compare_and_store(
290 return OSCompareAndSwap((UInt32
)oldval
, (UInt32
)newval
, (UInt32
*)dest
);
296 * Machine-dependent routine to fill in an array with up to callstack_max
297 * levels of return pc information.
299 void machine_callstack(
301 vm_size_t callstack_max
)
305 #endif /* MACH_ASSERT */