]> git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/loose_ends.c
abf2750bec38d158547404513626334728235d47
[apple/xnu.git] / osfmk / i386 / loose_ends.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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.
11 *
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
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /*
23 * @OSF_COPYRIGHT@
24 */
25 /*
26 * Mach Operating System
27 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
28 * All Rights Reserved.
29 *
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.
35 *
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.
39 *
40 * Carnegie Mellon requests users of this software to return to
41 *
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
46 *
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
49 */
50 /*
51 */
52 #include <mach_assert.h>
53
54 #include <string.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>
61
62 /*
63 * Should be rewritten in asm anyway.
64 */
65
66 /*
67 * bcopy_phys - like bcopy but copies from/to physical addresses.
68 * this is trivial since all phys mem is mapped into
69 * kernel virtual space
70 */
71
72 void
73 bcopy_phys(const char *from, char *to, vm_size_t bytes)
74 {
75 bcopy((char *)phystokv(from), (char *)phystokv(to), bytes);
76 }
77
78
79 /*
80 * ovbcopy - like bcopy, but recognizes overlapping ranges and handles
81 * them correctly.
82 */
83
84 void
85 ovbcopy(
86 const char *from,
87 char *to,
88 vm_size_t bytes) /* num bytes to copy */
89 {
90 /* Assume that bcopy copies left-to-right (low addr first). */
91 if (from + bytes <= to || to + bytes <= from || to == from)
92 bcopy_no_overwrite(from, to, bytes); /* non-overlapping or no-op*/
93 else if (from > to)
94 bcopy_no_overwrite(from, to, bytes); /* overlapping but OK */
95 else {
96 /* to > from: overlapping, and must copy right-to-left. */
97 from += bytes - 1;
98 to += bytes - 1;
99 while (bytes-- > 0)
100 *to-- = *from--;
101 }
102 }
103
104 void
105 bcopy(
106 const char *from,
107 char *to,
108 vm_size_t bytes) /* num bytes to copy */
109 {
110 ovbcopy(from, to, bytes);
111 }
112
113 int bcmp(
114 const char *a,
115 const char *b,
116 vm_size_t len)
117 {
118 if (len == 0)
119 return 0;
120
121 do
122 if (*a++ != *b++)
123 break;
124 while (--len);
125
126 return len;
127 }
128
129 int
130 memcmp(s1, s2, n)
131 register char *s1, *s2;
132 register n;
133 {
134 while (--n >= 0)
135 if (*s1++ != *s2++)
136 return (*--s1 - *--s2);
137 return (0);
138 }
139
140 /*
141 * Abstract:
142 * strlen returns the number of characters in "string" preceeding
143 * the terminating null character.
144 */
145
146 size_t
147 strlen(
148 register const char *string)
149 {
150 register const char *ret = string;
151
152 while (*string++ != '\0')
153 continue;
154 return string - 1 - ret;
155 }
156
157 #if MACH_ASSERT
158
159 /*
160 * Machine-dependent routine to fill in an array with up to callstack_max
161 * levels of return pc information.
162 */
163 void machine_callstack(
164 natural_t *buf,
165 vm_size_t callstack_max)
166 {
167 }
168
169 #endif /* MACH_ASSERT */