]>
git.saurik.com Git - apple/xnu.git/blob - pexpert/gen/bootargs.c
4c5b5f07d0a4e9684ba471ba5890dc62783cf9f5
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>
30 extern boolean_t
isargsep( char c
);
31 extern int argstrcpy(char *from
, char *to
);
32 extern int getval(char *s
, int *val
);
34 static int argstrcpy2(char *from
,char *to
, unsigned maxlen
);
39 #if !defined(__LP64__) && !defined(__arm__)
42 const char *arg_string
,
48 /* Limit arg size to 4 byte when no size is given */
52 return PE_parse_boot_argn(arg_string
, arg_ptr
, max_len
);
58 const char *arg_string
,
66 boolean_t arg_boolean
;
69 args
= PE_boot_args();
70 if (*args
== '\0') return FALSE
;
74 while(*args
&& isargsep(*args
)) args
++;
84 while (!isargsep (*cp
) && *cp
!= '=')
86 if (*cp
!= '=' && !arg_boolean
)
92 if (strncmp(args
, arg_string
, i
) ||
93 (i
!=strlen(arg_string
)))
96 *(unsigned int *)arg_ptr
= TRUE
;
100 while (*cp
&& isargsep (*cp
))
102 if (*cp
== '=' && c
!= '=') {
106 if ('_' == *arg_string
) /* Force a string copy if the argument name begins with an underscore */
108 int hacklen
= 17 > max_len
? 17 : max_len
;
109 argstrcpy2 (++cp
, (char *)arg_ptr
, hacklen
- 1); /* Hack - terminate after 16 characters */
113 switch (getval(cp
, &val
))
116 *(unsigned int *)arg_ptr
= val
;
120 if(max_len
> 0) //max_len of 0 performs no copy at all
121 argstrcpy2(++cp
, (char *)arg_ptr
, max_len
- 1);
122 else if(max_len
== -1)
123 argstrcpy(++cp
, (char *)arg_ptr
);
130 /* Skip over current arg */
131 while(!isargsep(*args
)) args
++;
133 /* Skip leading white space (catch end of args) */
134 while(*args
&& isargsep(*args
)) args
++;
143 if (c
== ' ' || c
== '\0' || c
== '\t')
156 while (!isargsep(*from
)) {
172 while (!isargsep(*from
) && i
< maxlen
) {
185 unsigned int radix
, intval
;
208 case '0': case '1': case '2': case '3':
209 case '4': case '5': case '6': case '7':
219 } else if (intval
>= radix
) {
227 ((c
>= '0') && (c
<= ('9' - (10 - radix
))))) {
229 } else if ((radix
== 16) &&
230 ((c
>= '0') && (c
<= '9'))) {
232 } else if ((radix
== 16) &&
233 ((c
>= 'a') && (c
<= 'f'))) {
235 } else if ((radix
== 16) &&
236 ((c
>= 'A') && (c
<= 'F'))) {
238 } else if (c
== 'k' || c
== 'K') {
241 } else if (c
== 'm' || c
== 'M') {
244 } else if (c
== 'g' || c
== 'G') {
245 sign
*= 1024 * 1024 * 1024;
255 if (!isargsep(c
) && !isargsep(*s
))
257 *val
= intval
* sign
;