]> git.saurik.com Git - apple/xnu.git/blobdiff - pexpert/gen/bootargs.c
xnu-1699.22.73.tar.gz
[apple/xnu.git] / pexpert / gen / bootargs.c
index d7d0a3cd4f7548d6318b38fa40414022cb51f878..6ca4fa102ab25a9afd0e105f5dba9ef944c56139 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);
+#if !CONFIG_EMBEDDED
+static int argstrcpy(char *from, char *to);
+#endif 
+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);
 
-int argstrcpy2(char *from,char *to, unsigned maxlen);
+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,
@@ -50,6 +61,7 @@ PE_parse_boot_arg(
 
        return PE_parse_boot_argn(arg_string, arg_ptr, max_len);
 }
+#endif
 
 boolean_t
 PE_parse_boot_argn(
@@ -67,9 +79,13 @@ PE_parse_boot_argn(
        args = PE_boot_args();
        if (*args == '\0') return FALSE;
 
+#if CONFIG_EMBEDDED
+       if (max_len == -1) return FALSE;
+#endif
+
        arg_found = FALSE;
 
-       while(isargsep(*args)) args++;
+       while(*args && isargsep(*args)) args++;
 
        while (*args)
        {
@@ -91,11 +107,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;
@@ -111,14 +127,16 @@ PE_parse_boot_argn(
                        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 - 1);
-                                       else if(max_len == -1)
+#if !CONFIG_EMBEDDED
+                                       else if(max_len == -1) // unreachable on embedded
                                                argstrcpy(++cp, (char *)arg_ptr);
+#endif
                                        arg_found = TRUE;
                                        break;
                        }
@@ -135,7 +153,8 @@ gotit:
        return(arg_found);
 }
 
-boolean_t isargsep(
+static boolean_t
+isargsep(
        char c)
 {
        if (c == ' ' || c == '\0' || c == '\t')
@@ -144,7 +163,8 @@ boolean_t isargsep(
                return(FALSE);
 }
 
-int
+#if !CONFIG_EMBEDDED
+static int
 argstrcpy(
        char *from, 
        char *to)
@@ -158,8 +178,9 @@ argstrcpy(
        *to = 0;
        return(i);
 }
+#endif
 
-int
+static int
 argstrcpy2(
        char *from, 
        char *to,
@@ -175,7 +196,33 @@ 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)
@@ -258,3 +305,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;
+}