]>
git.saurik.com Git - apple/xnu.git/blob - pexpert/gen/bootargs.c
2 * Copyright (c) 2000-2008 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 #include <pexpert/pexpert.h>
29 #include <pexpert/device_tree.h>
31 static boolean_t
isargsep( char c
);
33 static int argstrcpy(char *from
, char *to
);
35 static int argstrcpy2(char *from
,char *to
, unsigned maxlen
);
36 static int argnumcpy(int val
, void *to
, unsigned maxlen
);
37 static int getval(char *s
, int *val
);
39 extern int IODTGetDefault(const char *key
, void *infoAddr
, unsigned int infoSize
);
50 #if !defined(__LP64__) && !defined(__arm__)
53 const char *arg_string
,
59 /* Limit arg size to 4 byte when no size is given */
63 return PE_parse_boot_argn(arg_string
, arg_ptr
, max_len
);
69 const char *arg_string
,
77 boolean_t arg_boolean
;
80 args
= PE_boot_args();
81 if (*args
== '\0') return FALSE
;
84 if (max_len
== -1) return FALSE
;
89 while(*args
&& isargsep(*args
)) args
++;
99 while (!isargsep (*cp
) && *cp
!= '=')
101 if (*cp
!= '=' && !arg_boolean
)
107 if (strncmp(args
, arg_string
, i
) ||
108 (i
!=strlen(arg_string
)))
111 argnumcpy(1, arg_ptr
, max_len
);
115 while (*cp
&& isargsep (*cp
))
117 if (*cp
== '=' && c
!= '=') {
121 if ('_' == *arg_string
) /* Force a string copy if the argument name begins with an underscore */
123 int hacklen
= 17 > max_len
? 17 : max_len
;
124 argstrcpy2 (++cp
, (char *)arg_ptr
, hacklen
- 1); /* Hack - terminate after 16 characters */
128 switch (getval(cp
, &val
))
131 argnumcpy(val
, arg_ptr
, max_len
);
135 if(max_len
> 0) //max_len of 0 performs no copy at all
136 argstrcpy2(++cp
, (char *)arg_ptr
, max_len
- 1);
138 else if(max_len
== -1) // unreachable on embedded
139 argstrcpy(++cp
, (char *)arg_ptr
);
147 /* Skip over current arg */
148 while(!isargsep(*args
)) args
++;
150 /* Skip leading white space (catch end of args) */
151 while(*args
&& isargsep(*args
)) args
++;
161 if (c
== ' ' || c
== '\0' || c
== '\t')
175 while (!isargsep(*from
)) {
192 while (!isargsep(*from
) && i
< maxlen
) {
200 static int argnumcpy(int val
, void *to
, unsigned maxlen
)
204 /* No write-back, caller just wants to know if arg was found */
210 *(int16_t *)to
= val
;
213 /* Unlikely in practice */
214 ((struct i24
*)to
)->i24
= val
;
218 *(int32_t *)to
= val
;
231 unsigned int radix
, intval
;
254 case '0': case '1': case '2': case '3':
255 case '4': case '5': case '6': case '7':
265 } else if (intval
>= radix
) {
273 ((c
>= '0') && (c
<= ('9' - (10 - radix
))))) {
275 } else if ((radix
== 16) &&
276 ((c
>= '0') && (c
<= '9'))) {
278 } else if ((radix
== 16) &&
279 ((c
>= 'a') && (c
<= 'f'))) {
281 } else if ((radix
== 16) &&
282 ((c
>= 'A') && (c
<= 'F'))) {
284 } else if (c
== 'k' || c
== 'K') {
287 } else if (c
== 'm' || c
== 'M') {
290 } else if (c
== 'g' || c
== 'G') {
291 sign
*= 1024 * 1024 * 1024;
301 if (!isargsep(c
) && !isargsep(*s
))
303 *val
= intval
* sign
;
311 PE_imgsrc_mount_supported()
318 const char *property_name
,
320 unsigned int max_property
)
323 void **property_data
;
324 unsigned int property_size
;
327 * Look for the property using the PE DT support.
329 if (kSuccess
== DTLookupEntry(NULL
, "/defaults", &dte
)) {
332 * We have a /defaults node, look for the named property.
334 if (kSuccess
!= DTGetProperty(dte
, property_name
, (void **)&property_data
, &property_size
))
338 * This would be a fine place to do smart argument size management for 32/64
339 * translation, but for now we'll insist that callers know how big their
340 * default values are.
342 if (property_size
> max_property
)
346 * Copy back the precisely-sized result.
348 memcpy(property_ptr
, property_data
, property_size
);
353 * Look for the property using I/O Kit's DT support.
355 return IODTGetDefault(property_name
, property_ptr
, max_property
) ? FALSE
: TRUE
;