]> git.saurik.com Git - apple/xnu.git/blobdiff - pexpert/gen/bootargs.c
xnu-2422.1.72.tar.gz
[apple/xnu.git] / pexpert / gen / bootargs.c
index 2d7f80b3f6f1026f5c0dceebee987e8644ec121e..d4d8e3caa99b53e94e55216214e0fa112d1eb76c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2008 Apple Inc. All rights reserved.
  *
  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  * 
  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
  */
 #include <pexpert/pexpert.h>
+#include <pexpert/device_tree.h>
 
-extern boolean_t isargsep( char c);
-extern int argstrcpy(char *from, char *to);
-extern int getval(char *s, int *val);
+static boolean_t isargsep( char c);
+static int argstrcpy(char *from, char *to);
+static int argstrcpy2(char *from,char *to, unsigned maxlen);
+static int argnumcpy(int val, void *to, unsigned maxlen);
+static int getval(char *s, int *val);
+
+extern int IODTGetDefault(const char *key, void *infoAddr, unsigned int infoSize);
+
+
+struct i24 {
+       int32_t i24 : 24;
+       int32_t _pad : 8;
+};
 
 #define        NUM     0
 #define        STR     1
 
+#if !defined(__LP64__) && !defined(__arm__)
 boolean_t 
 PE_parse_boot_arg(
        const char  *arg_string,
        void            *arg_ptr)
 {
-       return PE_parse_boot_argn(arg_string, arg_ptr, -1);
+       int max_len = -1;
+
+
+       return PE_parse_boot_argn(arg_string, arg_ptr, max_len);
 }
+#endif
 
 boolean_t
 PE_parse_boot_argn(
@@ -50,7 +66,7 @@ PE_parse_boot_argn(
 {
        char *args;
        char *cp, c;
-       int i;
+       uintptr_t i;
        int val;
        boolean_t arg_boolean;
        boolean_t arg_found;
@@ -58,9 +74,10 @@ PE_parse_boot_argn(
        args = PE_boot_args();
        if (*args == '\0') return FALSE;
 
+
        arg_found = FALSE;
 
-       while(isargsep(*args)) args++;
+       while(*args && isargsep(*args)) args++;
 
        while (*args)
        {
@@ -82,11 +99,11 @@ PE_parse_boot_argn(
                    (i!=strlen(arg_string)))
                        goto gotit;
                if (arg_boolean) {
-                       *(unsigned int *)arg_ptr = TRUE;
+                       argnumcpy(1, arg_ptr, max_len);
                        arg_found = TRUE;
                        break;
                } else {
-                       while (isargsep (*cp))
+                       while (*cp && isargsep (*cp))
                                cp++;
                        if (*cp == '=' && c != '=') {
                                args = cp+1;
@@ -94,21 +111,21 @@ PE_parse_boot_argn(
                        }
                        if ('_' == *arg_string) /* Force a string copy if the argument name begins with an underscore */
                        {
-                               int hacklen = 16 > max_len ? 16 : max_len;
-                               argstrcpy2 (++cp, (char *)arg_ptr, hacklen); /* Hack - terminate after 16 characters */
+                               int hacklen = 17 > max_len ? 17 : max_len;
+                               argstrcpy2 (++cp, (char *)arg_ptr, hacklen - 1); /* Hack - terminate after 16 characters */
                                arg_found = TRUE;
                                break;
                        }
                        switch (getval(cp, &val)) 
                        {
                                case NUM:
-                                       *(unsigned int *)arg_ptr = val;
+                                       argnumcpy(val, arg_ptr, max_len);
                                        arg_found = TRUE;
                                        break;
                                case STR:
                                        if(max_len > 0) //max_len of 0 performs no copy at all
-                                               argstrcpy2(++cp, (char *)arg_ptr, max_len);
-                                       else if(max_len == -1)
+                                               argstrcpy2(++cp, (char *)arg_ptr, max_len - 1);
+                                       else if(max_len == -1) // unreachable on embedded
                                                argstrcpy(++cp, (char *)arg_ptr);
                                        arg_found = TRUE;
                                        break;
@@ -126,7 +143,8 @@ gotit:
        return(arg_found);
 }
 
-boolean_t isargsep(
+static boolean_t
+isargsep(
        char c)
 {
        if (c == ' ' || c == '\0' || c == '\t')
@@ -135,7 +153,7 @@ boolean_t isargsep(
                return(FALSE);
 }
 
-int
+static int
 argstrcpy(
        char *from, 
        char *to)
@@ -150,13 +168,13 @@ argstrcpy(
        return(i);
 }
 
-int
+static int
 argstrcpy2(
        char *from, 
        char *to,
        unsigned maxlen)
 {
-       int i = 0;
+       unsigned int i = 0;
 
        while (!isargsep(*from) && i < maxlen) {
                i++;
@@ -166,13 +184,39 @@ argstrcpy2(
        return(i);
 }
 
-int
+static int argnumcpy(int val, void *to, unsigned maxlen)
+{
+       switch (maxlen) {
+               case 0:
+                       /* No write-back, caller just wants to know if arg was found */
+                       break;
+               case 1:
+                       *(int8_t *)to = val;
+                       break;
+               case 2:
+                       *(int16_t *)to = val;
+                       break;
+               case 3:
+                       /* Unlikely in practice */
+                       ((struct i24 *)to)->i24 = val;
+                       break;
+               case 4:
+               default:
+                       *(int32_t *)to = val;
+                       maxlen = 4;
+                       break;
+       }
+
+       return (int)maxlen;
+}
+
+static int
 getval(
        char *s, 
        int *val)
 {
        unsigned int radix, intval;
-        char c;
+    unsigned char c;
        int sign = 1;
 
        if (*s == '=') {
@@ -249,3 +293,51 @@ getval(
        *val = 1;
        return (NUM);
 }
+
+boolean_t 
+PE_imgsrc_mount_supported()
+{
+       return TRUE;
+}
+
+boolean_t
+PE_get_default(
+       const char      *property_name,
+       void            *property_ptr,
+       unsigned int max_property)
+{
+       DTEntry         dte;
+       void            **property_data;
+       unsigned int property_size;
+
+       /*
+        * Look for the property using the PE DT support.
+        */
+       if (kSuccess == DTLookupEntry(NULL, "/defaults", &dte)) {
+
+               /*
+                * We have a /defaults node, look for the named property.
+                */
+               if (kSuccess != DTGetProperty(dte, property_name, (void **)&property_data, &property_size))
+                       return FALSE;
+
+               /*
+                * This would be a fine place to do smart argument size management for 32/64
+                * translation, but for now we'll insist that callers know how big their
+                * default values are.
+                */
+               if (property_size > max_property)
+                       return FALSE;
+
+               /*
+                * Copy back the precisely-sized result.
+                */
+               memcpy(property_ptr, property_data, property_size);
+               return TRUE;
+       }
+
+       /*
+        * Look for the property using I/O Kit's DT support.
+        */
+       return IODTGetDefault(property_name, property_ptr, max_property) ? FALSE : TRUE;
+}