Root/
Source at commit 2381 created 10 years 21 days ago. By ifabio, Apply patch: (Credits to Thomas Jansen aka tja) - Reading options from all devices during boot. The options for the boot menu are only read from the devices rd(0,0) or bt(0,0). Consequently, boot menu options (e.g. "Quiet Boot", "Timeout", etc.) in plists on other devices (like most users have) are ignored. This patch extends the list of paths to search for the options plist on all devices that can be found. | |
---|---|
1 | /*␊ |
2 | * Copyright (c) 1999-2003 Apple Computer, Inc. All rights reserved.␊ |
3 | *␊ |
4 | * @APPLE_LICENSE_HEADER_START@␊ |
5 | * ␊ |
6 | * Portions Copyright (c) 1999-2003 Apple Computer, Inc. All Rights␊ |
7 | * Reserved. This file contains Original Code and/or Modifications of␊ |
8 | * Original Code as defined in and that are subject to the Apple Public␊ |
9 | * Source License Version 2.0 (the "License"). You may not use this file␊ |
10 | * except in compliance with the License. Please obtain a copy of the␊ |
11 | * License at http://www.apple.com/publicsource and read it before using␊ |
12 | * this file.␊ |
13 | * ␊ |
14 | * The Original Code and all software distributed under the License are␊ |
15 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER␊ |
16 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,␊ |
17 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,␊ |
18 | * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the␊ |
19 | * License for the specific language governing rights and limitations␊ |
20 | * under the License.␊ |
21 | * ␊ |
22 | * @APPLE_LICENSE_HEADER_END@␊ |
23 | */␊ |
24 | /* string operations */␊ |
25 | ␊ |
26 | #include "libsa.h"␊ |
27 | ␊ |
28 | void * memset(void * dst, int val, size_t len)␊ |
29 | {␊ |
30 | asm volatile ( "rep; stosb"␊ |
31 | : "=c" (len), "=D" (dst)␊ |
32 | : "0" (len), "1" (dst), "a" (val)␊ |
33 | : "memory" );␊ |
34 | ␊ |
35 | return dst;␊ |
36 | }␊ |
37 | ␊ |
38 | #if 0␊ |
39 | void * memcpy(void * dst, const void * src, size_t len)␊ |
40 | {␊ |
41 | asm volatile ( "rep; movsb"␊ |
42 | : "=c" (len), "=D" (dst), "=S" (src)␊ |
43 | : "0" (len), "1" (dst), "2" (src)␊ |
44 | : "memory" );␊ |
45 | ␊ |
46 | return dst;␊ |
47 | }␊ |
48 | ␊ |
49 | void bcopy(const void * src, void * dst, size_t len)␊ |
50 | {␊ |
51 | ␉memcpy(dst, src, len);␊ |
52 | }␊ |
53 | ␊ |
54 | void bzero(void * dst, size_t len)␊ |
55 | {␊ |
56 | memset(dst, 0, len);␊ |
57 | }␊ |
58 | ␊ |
59 | #else␊ |
60 | void * memcpy(void * dst, const void * src, size_t len)␊ |
61 | {␊ |
62 | asm volatile ( "cld \n\t"␊ |
63 | "movl %%ecx, %%edx \n\t"␊ |
64 | "shrl $2, %%ecx \n\t"␊ |
65 | "rep; movsl \n\t"␊ |
66 | "movl %%edx, %%ecx \n\t"␊ |
67 | "andl $3, %%ecx \n\t"␊ |
68 | "rep; movsb \n\t"␊ |
69 | : "=D" (dst)␊ |
70 | : "c" (len), "D" (dst), "S" (src)␊ |
71 | : "memory", "%edx" );␊ |
72 | ␊ |
73 | return dst;␊ |
74 | }␊ |
75 | ␊ |
76 | void bcopy(const void * src, void * dst, size_t len)␊ |
77 | {␊ |
78 | asm volatile ( "cld \n\t"␊ |
79 | "movl %%ecx, %%edx \n\t"␊ |
80 | "shrl $2, %%ecx \n\t"␊ |
81 | "rep; movsl \n\t"␊ |
82 | "movl %%edx, %%ecx \n\t"␊ |
83 | "andl $3, %%ecx \n\t"␊ |
84 | "rep; movsb \n\t"␊ |
85 | :␊ |
86 | : "c" (len), "D" (dst), "S" (src)␊ |
87 | : "memory", "%edx" );␊ |
88 | }␊ |
89 | ␊ |
90 | void bzero(void * dst, size_t len)␊ |
91 | {␊ |
92 | asm volatile ( "xorl %%eax, %%eax \n\t"␊ |
93 | "cld \n\t"␊ |
94 | "movl %%ecx, %%edx \n\t"␊ |
95 | "shrl $2, %%ecx \n\t"␊ |
96 | "rep; stosl \n\t"␊ |
97 | "movl %%edx, %%ecx \n\t"␊ |
98 | "andl $3, %%ecx \n\t"␊ |
99 | "rep; stosb \n\t"␊ |
100 | : ␊ |
101 | : "c" (len), "D" (dst)␊ |
102 | : "memory", "%eax" );␊ |
103 | }␊ |
104 | #endif␊ |
105 | ␊ |
106 | /* #if DONT_USE_GCC_BUILT_IN_STRLEN */␊ |
107 | ␊ |
108 | #define tolower(c) ((int)((c) & ~0x20))␊ |
109 | #define toupper(c) ((int)((c) | 0x20))␊ |
110 | ␊ |
111 | size_t strlen(const char * s)␊ |
112 | {␊ |
113 | ␉int n = 0;␊ |
114 | ␉while (*s++) n++;␊ |
115 | ␉return(n);␊ |
116 | }␊ |
117 | ␊ |
118 | /*#endif*/␊ |
119 | ␊ |
120 | /* NOTE: Moved from ntfs.c */␊ |
121 | int␊ |
122 | memcmp(const void *p1, const void *p2, size_t len)␊ |
123 | {␊ |
124 | while (len--) {␊ |
125 | if (*(const char*)(p1++) != *(const char*)(p2++))␊ |
126 | return -1;␊ |
127 | }␊ |
128 | return 0;␊ |
129 | }␊ |
130 | ␊ |
131 | int␊ |
132 | strcmp(const char * s1, const char * s2)␊ |
133 | {␊ |
134 | ␉while (*s1 && (*s1 == *s2)) {␊ |
135 | ␉␉s1++;␊ |
136 | ␉␉s2++;␊ |
137 | ␉}␊ |
138 | ␉return (*s1 - *s2);␊ |
139 | }␊ |
140 | ␊ |
141 | int strncmp(const char * s1, const char * s2, size_t len)␊ |
142 | {␊ |
143 | ␉register int n = len;␊ |
144 | ␉while (--n >= 0 && *s1 == *s2++)␊ |
145 | ␉␉if (*s1++ == '\0')␊ |
146 | ␉␉␉return(0);␊ |
147 | ␉return(n<0 ? 0 : *s1 - *--s2);␊ |
148 | }␊ |
149 | ␊ |
150 | char *␊ |
151 | strcpy(char * s1, const char * s2)␊ |
152 | {␊ |
153 | ␉register char *ret = s1;␊ |
154 | ␉while ((*s1++ = *s2++))␊ |
155 | ␉␉continue;␊ |
156 | ␉return ret;␊ |
157 | }␊ |
158 | ␊ |
159 | char *␊ |
160 | strncpy(char * s1, const char * s2, size_t n)␊ |
161 | {␊ |
162 | ␉register char *ret = s1;␊ |
163 | ␉while (n && (*s1++ = *s2++))␊ |
164 | ␉␉n--;␊ |
165 | ␉return ret;␊ |
166 | }␊ |
167 | ␊ |
168 | char *␊ |
169 | strstr(const char *in, const char *str)␊ |
170 | {␊ |
171 | char c;␊ |
172 | size_t len;␊ |
173 | ␊ |
174 | c = *str++;␊ |
175 | if (!c)␊ |
176 | return (char *) in;␉// Trivial empty string case␊ |
177 | ␊ |
178 | len = strlen(str);␊ |
179 | do {␊ |
180 | char sc;␊ |
181 | ␊ |
182 | do {␊ |
183 | sc = *in++;␊ |
184 | if (!sc)␊ |
185 | return (char *) 0;␊ |
186 | } while (sc != c);␊ |
187 | } while (strncmp(in, str, len) != 0);␊ |
188 | ␊ |
189 | return (char *) (in - 1);␊ |
190 | }␊ |
191 | ␊ |
192 | int␊ |
193 | ptol(const char *str)␊ |
194 | {␊ |
195 | ␉register int c = *str;␊ |
196 | ␊ |
197 | ␉if (c <= '7' && c >= '0')␊ |
198 | ␉␉c -= '0';␊ |
199 | ␉else if (c <= 'h' && c >= 'a')␊ |
200 | ␉␉c -= 'a';␊ |
201 | ␉else c = 0;␊ |
202 | ␉return c;␊ |
203 | }␊ |
204 | ␊ |
205 | int␊ |
206 | atoi(const char *str)␊ |
207 | {␊ |
208 | ␉register int sum = 0;␊ |
209 | ␉while (*str == ' ' || *str == '\t')␊ |
210 | ␉␉str++;␊ |
211 | ␉while (*str >= '0' && *str <= '9') {␊ |
212 | ␉␉sum *= 10;␊ |
213 | ␉␉sum += *str++ - '0';␊ |
214 | ␉}␊ |
215 | ␉return sum;␊ |
216 | }␊ |
217 | ␊ |
218 | char *strncat(char *s1, const char *s2, size_t n)␊ |
219 | {␊ |
220 | ␉register char *ret = s1;␊ |
221 | ␉while (*s1)␊ |
222 | ␉␉s1++;␊ |
223 | ␉while (n-- && *s2)␊ |
224 | ␉␉*s1++ = *s2++;␊ |
225 | ␉*s1 = '\0';␊ |
226 | ␉return ret;␊ |
227 | }␊ |
228 | ␊ |
229 | char *strcat(char *s1, const char *s2)␊ |
230 | {␊ |
231 | ␉return(strncat(s1, s2, strlen(s2)));␊ |
232 | }␊ |
233 | ␊ |
234 | char *strdup(const char *s1)␊ |
235 | {␊ |
236 | ␉return strcpy(malloc(strlen(s1) + 1), s1);␊ |
237 | }␊ |
238 | ␊ |
239 | #if STRNCASECMP␊ |
240 | int strncasecmp(const char *s1, const char *s2, size_t len)␊ |
241 | {␊ |
242 | ␉register int n = len;␊ |
243 | ␉while (--n >= 0 && tolower(*s1) == tolower(*s2++))␊ |
244 | ␉␉if (*s1++ == '\0')␊ |
245 | ␉␉␉return(0);␊ |
246 | ␉return(n<0 ? 0 : tolower(*s1) - tolower(*--s2));␊ |
247 | }␊ |
248 | #endif␊ |
249 | ␊ |
250 | char* strchr(const char *str, int c)␊ |
251 | {␊ |
252 | do␊ |
253 | {␊ |
254 | if(*str == c)␊ |
255 | return (char*)str;␊ |
256 | }␊ |
257 | while(*(str++));␊ |
258 | ␊ |
259 | return 0;␊ |
260 | } ␊ |
261 | ␊ |
262 | char* strbreak(const char *str, char **next, long *len)␊ |
263 | {␊ |
264 | char *start = (char*)str, *end;␊ |
265 | bool quoted = false;␊ |
266 | ␊ |
267 | if ( !start || !len )␊ |
268 | return 0;␊ |
269 | ␊ |
270 | *len = 0;␊ |
271 | ␊ |
272 | while ( isspace(*start) )␊ |
273 | start++;␊ |
274 | ␊ |
275 | if (*start == '"')␊ |
276 | {␊ |
277 | start++;␊ |
278 | ␊ |
279 | end = strchr(start, '"');␊ |
280 | if(end)␊ |
281 | quoted = true;␊ |
282 | else␊ |
283 | end = strchr(start, '\0');␊ |
284 | }␊ |
285 | else␊ |
286 | {␊ |
287 | for ( end = start; *end && !isspace(*end); end++ )␊ |
288 | {}␊ |
289 | }␊ |
290 | ␊ |
291 | *len = end - start;␊ |
292 | ␊ |
293 | if(next)␊ |
294 | *next = quoted ? end+1 : end;␊ |
295 | ␊ |
296 | return start;␊ |
297 | }␊ |
298 | ␊ |
299 | /* COPYRIGHT NOTICE: checksum8 from AppleSMBIOS */␊ |
300 | uint8_t checksum8( void * start, unsigned int length )␊ |
301 | {␊ |
302 | uint8_t csum = 0;␊ |
303 | uint8_t * cp = (uint8_t *) start;␊ |
304 | unsigned int i;␊ |
305 | ␊ |
306 | for ( i = 0; i < length; i++)␊ |
307 | csum += *cp++;␊ |
308 | ␊ |
309 | return csum;␊ |
310 | }␊ |
311 | ␊ |
312 |