]>
git.saurik.com Git - apple/xnu.git/blob - pexpert/gen/bootargs.c
d4d8e3caa99b53e94e55216214e0fa112d1eb76c
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
);
32 static int argstrcpy(char *from
, char *to
);
33 static int argstrcpy2(char *from
,char *to
, unsigned maxlen
);
34 static int argnumcpy(int val
, void *to
, unsigned maxlen
);
35 static int getval(char *s
, int *val
);
37 extern int IODTGetDefault(const char *key
, void *infoAddr
, unsigned int infoSize
);
48 #if !defined(__LP64__) && !defined(__arm__)
51 const char *arg_string
,
57 return PE_parse_boot_argn(arg_string
, arg_ptr
, max_len
);
63 const char *arg_string
,
71 boolean_t arg_boolean
;
74 args
= PE_boot_args();
75 if (*args
== '\0') return FALSE
;
80 while(*args
&& isargsep(*args
)) args
++;
90 while (!isargsep (*cp
) && *cp
!= '=')
92 if (*cp
!= '=' && !arg_boolean
)
98 if (strncmp(args
, arg_string
, i
) ||
99 (i
!=strlen(arg_string
)))
102 argnumcpy(1, arg_ptr
, max_len
);
106 while (*cp
&& isargsep (*cp
))
108 if (*cp
== '=' && c
!= '=') {
112 if ('_' == *arg_string
) /* Force a string copy if the argument name begins with an underscore */
114 int hacklen
= 17 > max_len
? 17 : max_len
;
115 argstrcpy2 (++cp
, (char *)arg_ptr
, hacklen
- 1); /* Hack - terminate after 16 characters */
119 switch (getval(cp
, &val
))
122 argnumcpy(val
, arg_ptr
, max_len
);
126 if(max_len
> 0) //max_len of 0 performs no copy at all
127 argstrcpy2(++cp
, (char *)arg_ptr
, max_len
- 1);
128 else if(max_len
== -1) // unreachable on embedded
129 argstrcpy(++cp
, (char *)arg_ptr
);
136 /* Skip over current arg */
137 while(!isargsep(*args
)) args
++;
139 /* Skip leading white space (catch end of args) */
140 while(*args
&& isargsep(*args
)) args
++;
150 if (c
== ' ' || c
== '\0' || c
== '\t')
163 while (!isargsep(*from
)) {
179 while (!isargsep(*from
) && i
< maxlen
) {
187 static int argnumcpy(int val
, void *to
, unsigned maxlen
)
191 /* No write-back, caller just wants to know if arg was found */
197 *(int16_t *)to
= val
;
200 /* Unlikely in practice */
201 ((struct i24
*)to
)->i24
= val
;
205 *(int32_t *)to
= val
;
218 unsigned int radix
, intval
;
241 case '0': case '1': case '2': case '3':
242 case '4': case '5': case '6': case '7':
252 } else if (intval
>= radix
) {
260 ((c
>= '0') && (c
<= ('9' - (10 - radix
))))) {
262 } else if ((radix
== 16) &&
263 ((c
>= '0') && (c
<= '9'))) {
265 } else if ((radix
== 16) &&
266 ((c
>= 'a') && (c
<= 'f'))) {
268 } else if ((radix
== 16) &&
269 ((c
>= 'A') && (c
<= 'F'))) {
271 } else if (c
== 'k' || c
== 'K') {
274 } else if (c
== 'm' || c
== 'M') {
277 } else if (c
== 'g' || c
== 'G') {
278 sign
*= 1024 * 1024 * 1024;
288 if (!isargsep(c
) && !isargsep(*s
))
290 *val
= intval
* sign
;
298 PE_imgsrc_mount_supported()
305 const char *property_name
,
307 unsigned int max_property
)
310 void **property_data
;
311 unsigned int property_size
;
314 * Look for the property using the PE DT support.
316 if (kSuccess
== DTLookupEntry(NULL
, "/defaults", &dte
)) {
319 * We have a /defaults node, look for the named property.
321 if (kSuccess
!= DTGetProperty(dte
, property_name
, (void **)&property_data
, &property_size
))
325 * This would be a fine place to do smart argument size management for 32/64
326 * translation, but for now we'll insist that callers know how big their
327 * default values are.
329 if (property_size
> max_property
)
333 * Copy back the precisely-sized result.
335 memcpy(property_ptr
, property_data
, property_size
);
340 * Look for the property using I/O Kit's DT support.
342 return IODTGetDefault(property_name
, property_ptr
, max_property
) ? FALSE
: TRUE
;