]> git.saurik.com Git - apple/xnu.git/blobdiff - pexpert/i386/fakePPCDeviceTree.c
xnu-792.18.15.tar.gz
[apple/xnu.git] / pexpert / i386 / fakePPCDeviceTree.c
index fd767a69bdde425dfc75984ff5e3ad22aff2316b..c0ec5547e36366c3faf53f72667d8433465136ea 100644 (file)
 /*
  * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
  *
- * @APPLE_LICENSE_HEADER_START@
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  * 
- * The contents of this file constitute Original Code as defined in and
- * are subject to the Apple Public Source License Version 1.1 (the
- * "License").  You may not use this file except in compliance with the
- * License.  Please obtain a copy of the License at
- * http://www.apple.com/publicsource and read it before using this file.
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. The rights granted to you under the License
+ * may not be used to create, or enable the creation or redistribution of,
+ * unlawful or unlicensed copies of an Apple operating system, or to
+ * circumvent, violate, or enable the circumvention or violation of, any
+ * terms of an Apple operating system software license agreement.
  * 
- * This Original Code and all software distributed under the License are
- * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
+ * 
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
- * License for the specific language governing rights and limitations
- * under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
  * 
- * @APPLE_LICENSE_HEADER_END@
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
  */
 
 #include <pexpert/protos.h>
 
 #include "fakePPCStructs.h"
 
-boot_args fakePPCBootArgs = {
-       0, // Revision
-        kBootArgsVersion, // Version
-        "",     // CommandLine
-        0,      // PhysicalDRAM
-        0,      // machine_type
-        0,      // deviceTreeP
-        0,      // deviceTreeLength
-        0,      // topOfKernelData
-};
-
-void * createdt(dt_init *template, long *retSize)
+boot_args fakePPCBootArgs = { .Version = kBootArgsVersion };
+
+void * createdt(dt_init * template, long * retSize)
 {
-    dt_init *  next;
-    int        size, allocSize;
+    dt_init *    next;
+    size_t       size, allocSize;
     vm_address_t out, saveout;
-    void *     source;
+    void *       source;
     
     // calc size of expanded data
-    for( next = template, allocSize = 0;
-       next;
-       next++) {
-
-       if( next->nodeInit.zero == 0) {
-           if( next->nodeInit.nProps == 0)
-               break;
-           allocSize += 2 * sizeof( long);
-       } else
-           allocSize += (32 + 4 + 3 + next->propInit.length) & (-4);
+    for ( next = template, allocSize = 0;
+          next;
+          next++ )
+    {
+        if ( next->nodeInit.zero == 0 )
+        {
+            if( next->nodeInit.nProps == 0) break;
+            allocSize += 2 * sizeof( long);
+        }
+        else if ( next->dataInit.one == 1 )
+        {
+            allocSize += *(next->dataInit.length);
+        }
+        else if ( next->stringInit.two == 2 )
+        {
+            dt_data *dp = (dt_data *)(next->stringInit.data);
+            allocSize += (32 + 4 + 3 + dp->length) & (-4);
+        }
+        else
+        {
+            allocSize += (32 + 4 + 3 + next->propInit.length) & (-4);
+        }
     }
-    saveout = out = kalloc( allocSize);
+    saveout = out = (vm_address_t) kalloc(allocSize);
+    if ( out == 0 ) return 0;
 
     // copy out
-    for( next = template;
-       next;
-       next++) {
-
-       if( next->nodeInit.zero == 0) {
-
-           if( next->nodeInit.nProps == 0)
-               break;
-           source = &next->nodeInit.nProps;
-           size = 2 * sizeof( long);
-
-       } else {
-
-           bcopy( next->propInit.name, out, 32);
-           out += 32;
-           size = next->propInit.length;
-           *(long *)out = size;
-           out += sizeof( long);
-           if( size == 4)
-               source = &next->propInit.value;
-           else {
-               source = next->propInit.value;
-               size = (size + 3) & (-4);
-           }
-       }
-        bcopy( source, out, size);
-       out += size;
+    for ( next = template; next; next++)
+    {
+        if ( next->nodeInit.zero == 0 )
+        {
+            if ( next->nodeInit.nProps == 0 ) break;
+            source = &next->nodeInit.nProps;
+            size = 2 * sizeof( long);
+        }
+        else if ( next->dataInit.one == 1 )
+        {
+            *((long *)next->dataInit.address) = out;
+            source = 0;
+            size   = *(next->dataInit.length);
+        }
+        else if ( next->stringInit.two == 2 )
+        {
+            dt_data *dp = (dt_data *)next->stringInit.data;
+            bcopy( (void *)(uintptr_t)next->stringInit.name, (void *)out, 32);
+            out += 32;
+            size = dp->length;
+            *(long *)out = size;
+            out += sizeof(long);
+            source = (char *)dp->address;
+            size = (size + 3) & (-4);
+        }
+        else
+        {
+            bcopy( (void *)(uintptr_t)next->propInit.name, (void *)out, 32);
+            out += 32;
+            size = next->propInit.length;
+            *(long *)out = size;
+            out += sizeof(long);
+            if ( size == 4 )
+                source = &next->propInit.value;
+            else {
+                source = next->propInit.value;
+                size = (size + 3) & (-4);
+            }
+        }
+        if ( source )
+            bcopy(source, (void *)out, size);
+        else
+            bzero((void *)out, size);
+        out += size;
     }
 
     if( allocSize != (out - saveout))
         printf("WARNING: DT corrupt (%x)\n", (out - saveout) - allocSize);
 
     *retSize = allocSize;
-    return( (void *)saveout);
+    return( (void *)saveout );
 }
 
 unsigned char *nptr;
@@ -111,14 +138,14 @@ typedef struct node_t {
 } node_t;
 
 
-int indent = 0;
+unsigned int indent = 0;
 
 void printdt()
 {
     node_t *nodeptr = (node_t *)nptr;
-    long num_props    = nodeptr->nProperties;
-    long len;
-    int i, j;
+    unsigned long num_props    = nodeptr->nProperties;
+    unsigned long len;
+    unsigned int i, j;
     unsigned char *sptr;
 
     nptr = (unsigned char *)&nodeptr->props;
@@ -129,7 +156,7 @@ void printdt()
         printf("'");
         printf("%s", nptr);
         nptr+=32;
-        len = *((long*)nptr);
+        len = *((unsigned long*)nptr);
         nptr += 4;
         printf("'\t\t(%ld)  '", len);
         sptr = nptr;