]>
git.saurik.com Git - apple/xnu.git/blob - pexpert/gen/bootargs.c
6ca4fa102ab25a9afd0e105f5dba9ef944c56139
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
);
49 #if !defined(__LP64__) && !defined(__arm__)
52 const char *arg_string
,
58 /* Limit arg size to 4 byte when no size is given */
62 return PE_parse_boot_argn(arg_string
, arg_ptr
, max_len
);
68 const char *arg_string
,
76 boolean_t arg_boolean
;
79 args
= PE_boot_args();
80 if (*args
== '\0') return FALSE
;
83 if (max_len
== -1) return FALSE
;
88 while(*args
&& isargsep(*args
)) args
++;
98 while (!isargsep (*cp
) && *cp
!= '=')
100 if (*cp
!= '=' && !arg_boolean
)
106 if (strncmp(args
, arg_string
, i
) ||
107 (i
!=strlen(arg_string
)))
110 argnumcpy(1, arg_ptr
, max_len
);
114 while (*cp
&& isargsep (*cp
))
116 if (*cp
== '=' && c
!= '=') {
120 if ('_' == *arg_string
) /* Force a string copy if the argument name begins with an underscore */
122 int hacklen
= 17 > max_len
? 17 : max_len
;
123 argstrcpy2 (++cp
, (char *)arg_ptr
, hacklen
- 1); /* Hack - terminate after 16 characters */
127 switch (getval(cp
, &val
))
130 argnumcpy(val
, arg_ptr
, max_len
);
134 if(max_len
> 0) //max_len of 0 performs no copy at all
135 argstrcpy2(++cp
, (char *)arg_ptr
, max_len
- 1);
137 else if(max_len
== -1) // unreachable on embedded
138 argstrcpy(++cp
, (char *)arg_ptr
);
146 /* Skip over current arg */
147 while(!isargsep(*args
)) args
++;
149 /* Skip leading white space (catch end of args) */
150 while(*args
&& isargsep(*args
)) args
++;
160 if (c
== ' ' || c
== '\0' || c
== '\t')
174 while (!isargsep(*from
)) {
191 while (!isargsep(*from
) && i
< maxlen
) {
199 static int argnumcpy(int val
, void *to
, unsigned maxlen
)
203 /* No write-back, caller just wants to know if arg was found */
209 *(int16_t *)to
= val
;
212 /* Unlikely in practice */
213 ((struct i24
*)to
)->i24
= val
;
217 *(int32_t *)to
= val
;
230 unsigned int radix
, intval
;
253 case '0': case '1': case '2': case '3':
254 case '4': case '5': case '6': case '7':
264 } else if (intval
>= radix
) {
272 ((c
>= '0') && (c
<= ('9' - (10 - radix
))))) {
274 } else if ((radix
== 16) &&
275 ((c
>= '0') && (c
<= '9'))) {
277 } else if ((radix
== 16) &&
278 ((c
>= 'a') && (c
<= 'f'))) {
280 } else if ((radix
== 16) &&
281 ((c
>= 'A') && (c
<= 'F'))) {
283 } else if (c
== 'k' || c
== 'K') {
286 } else if (c
== 'm' || c
== 'M') {
289 } else if (c
== 'g' || c
== 'G') {
290 sign
*= 1024 * 1024 * 1024;
300 if (!isargsep(c
) && !isargsep(*s
))
302 *val
= intval
* sign
;
310 PE_imgsrc_mount_supported()
317 const char *property_name
,
319 unsigned int max_property
)
322 void **property_data
;
323 unsigned int property_size
;
326 * Look for the property using the PE DT support.
328 if (kSuccess
== DTLookupEntry(NULL
, "/defaults", &dte
)) {
331 * We have a /defaults node, look for the named property.
333 if (kSuccess
!= DTGetProperty(dte
, property_name
, (void **)&property_data
, &property_size
))
337 * This would be a fine place to do smart argument size management for 32/64
338 * translation, but for now we'll insist that callers know how big their
339 * default values are.
341 if (property_size
> max_property
)
345 * Copy back the precisely-sized result.
347 memcpy(property_ptr
, property_data
, property_size
);
352 * Look for the property using I/O Kit's DT support.
354 return IODTGetDefault(property_name
, property_ptr
, max_property
) ? FALSE
: TRUE
;