]>
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>
64 #include <i386/param.h>
65 #include <i386/misc_protos.h>
67 #define value_64bit(value) ((value) & 0xFFFFFFFF00000000LL)
68 #define low32(x) ((unsigned int)((x) & 0x00000000FFFFFFFFLL))
71 * Should be rewritten in asm anyway.
76 bzero_phys(addr64_t p
, uint32_t len
)
78 bzero((char *)phystokv(low32(p
)), len
);
82 * copy 'size' bytes from physical to physical address
83 * the caller must validate the physical ranges
85 * if flush_action == 0, no cache flush necessary
86 * if flush_action == 1, flush the source
87 * if flush_action == 2, flush the dest
88 * if flush_action == 3, flush both source and dest
91 extern void flush_dcache(vm_offset_t addr
, unsigned count
, int phys
);
93 kern_return_t
copyp2p(vm_offset_t source
, vm_offset_t dest
, unsigned int size
, unsigned int flush_action
) {
95 switch(flush_action
) {
97 flush_dcache(source
, size
, 1);
100 flush_dcache(dest
, size
, 1);
103 flush_dcache(source
, size
, 1);
104 flush_dcache(dest
, size
, 1);
108 bcopy_phys((addr64_t
)source
, (addr64_t
)dest
, (vm_size_t
)size
); /* Do a physical copy */
110 switch(flush_action
) {
112 flush_dcache(source
, size
, 1);
115 flush_dcache(dest
, size
, 1);
118 flush_dcache(source
, size
, 1);
119 flush_dcache(dest
, size
, 1);
129 * Copies data from a physical page to a virtual page. This is used to
130 * move data from the kernel to user state.
135 copyp2v(char *from
, char *to
, unsigned int size
) {
137 return(copyout(phystokv(from
), to
, size
));
142 * Copies data from a virtual page to a physical page. This is used to
143 * move data from the user address space into the kernel.
148 copyv2p(char *from
, char *to
, unsigned int size
) {
150 return(copyin(from
, phystokv(to
), size
));
155 * bcopy_phys - like bcopy but copies from/to physical addresses.
156 * this is trivial since all phys mem is mapped into
157 * kernel virtual space
161 bcopy_phys(addr64_t from
, addr64_t to
, vm_size_t bytes
)
163 /* this will die horribly if we ever run off the end of a page */
164 if ( value_64bit(from
) || value_64bit(to
)) panic("bcopy_phys: 64 bit value");
165 bcopy((char *)phystokv(low32(from
)),
166 (char *)phystokv(low32(to
)), bytes
);
171 * ovbcopy - like bcopy, but recognizes overlapping ranges and handles
179 vm_size_t bytes
) /* num bytes to copy */
181 /* Assume that bcopy copies left-to-right (low addr first). */
182 if (from
+ bytes
<= to
|| to
+ bytes
<= from
|| to
== from
)
183 bcopy_no_overwrite(from
, to
, bytes
); /* non-overlapping or no-op*/
185 bcopy_no_overwrite(from
, to
, bytes
); /* overlapping but OK */
187 /* to > from: overlapping, and must copy right-to-left. */
199 vm_size_t bytes
) /* num bytes to copy */
201 ovbcopy(from
, to
, bytes
);
222 register char *s1
, *s2
;
227 return (*--s1
- *--s2
);
233 * strlen returns the number of characters in "string" preceeding
234 * the terminating null character.
239 register const char *string
)
241 register const char *ret
= string
;
243 while (*string
++ != '\0')
245 return string
- 1 - ret
;
248 #include <libkern/OSAtomic.h>
260 newValue
= (oldValue
+ delt
);
261 } while (!OSCompareAndSwap((UInt32
)oldValue
,
262 (UInt32
)newValue
, (UInt32
*)dest
));
277 newValue
= (oldValue
- delt
);
278 } while (!OSCompareAndSwap((UInt32
)oldValue
,
279 (UInt32
)newValue
, (UInt32
*)dest
));
294 newValue
= (oldValue
| mask
);
295 } while (!OSCompareAndSwap((UInt32
)oldValue
,
296 (UInt32
)newValue
, (UInt32
*)dest
));
311 newValue
= (oldValue
& mask
);
312 } while (!OSCompareAndSwap((UInt32
)oldValue
,
313 (UInt32
)newValue
, (UInt32
*)dest
));
319 hw_compare_and_store(
324 return OSCompareAndSwap((UInt32
)oldval
, (UInt32
)newval
, (UInt32
*)dest
);
330 * Machine-dependent routine to fill in an array with up to callstack_max
331 * levels of return pc information.
333 void machine_callstack(
335 vm_size_t callstack_max
)
339 #endif /* MACH_ASSERT */
344 void fillPage(ppnum_t pa
, unsigned int fill
)
346 unsigned int *addr
= (unsigned int *)phystokv(i386_ptob(pa
));
348 int cnt
= NBPG
/sizeof(unsigned int);
350 for (i
= 0; i
< cnt
; i
++ )
354 #define cppvPHYS (cppvPsnk|cppvPsrc)
356 kern_return_t
copypv(addr64_t source
, addr64_t sink
, unsigned int size
, int which
)
360 if (value_64bit(source
) | value_64bit(sink
)) panic("copypv: 64 bit value");
362 src32
= (char *)low32(source
);
363 dst32
= (char *)low32(sink
);
365 if (which
& cppvFsrc
) flush_dcache(source
, size
, 1); /* If requested, flush source before move */
366 if (which
& cppvFsnk
) flush_dcache(sink
, size
, 1); /* If requested, flush sink before move */
368 switch (which
& cppvPHYS
) {
372 * both destination and source are physical
374 bcopy_phys(source
, sink
, (vm_size_t
)size
);
379 * destination is physical, source is virtual
381 if (which
& cppvKmap
)
383 * source is kernel virtual
385 bcopy(src32
, (char *)phystokv(dst32
), size
);
388 * source is user virtual
390 copyin(src32
, (char *)phystokv(dst32
), size
);
395 * source is physical, destination is virtual
397 if (which
& cppvKmap
)
399 * destination is kernel virtual
401 bcopy((char *)phystokv(src32
), dst32
, size
);
404 * destination is user virtual
406 copyout((char *)phystokv(src32
), dst32
, size
);
410 panic("copypv: both virtual");
413 if (which
& cppvFsrc
) flush_dcache(source
, size
, 1); /* If requested, flush source before move */
414 if (which
& cppvFsnk
) flush_dcache(sink
, size
, 1); /* If requested, flush sink before move */
420 void flush_dcache64(addr64_t addr
, unsigned count
, int phys
)
424 void invalidate_icache64(addr64_t addr
, unsigned cnt
, int phys
)
429 void switch_to_serial_console(void)
433 addr64_t vm_last_addr
;
436 mapping_set_mod(ppnum_t pn
)