]> git.saurik.com Git - apple/xnu.git/blob - pexpert/i386/fakePPCDeviceTree.c
xnu-124.13.tar.gz
[apple/xnu.git] / pexpert / i386 / fakePPCDeviceTree.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22
23 #include <pexpert/protos.h>
24
25 #include "fakePPCStructs.h"
26
27 boot_args fakePPCBootArgs = {
28 0, // Revision
29 kBootArgsVersion, // Version
30 "", // CommandLine
31 0, // PhysicalDRAM
32 0, // machine_type
33 0, // deviceTreeP
34 0, // deviceTreeLength
35 0, // topOfKernelData
36 };
37
38 void * createdt(dt_init *template, long *retSize)
39 {
40 dt_init * next;
41 int size, allocSize;
42 vm_address_t out, saveout;
43 void * source;
44
45 // calc size of expanded data
46 for( next = template, allocSize = 0;
47 next;
48 next++) {
49
50 if( next->nodeInit.zero == 0) {
51 if( next->nodeInit.nProps == 0)
52 break;
53 allocSize += 2 * sizeof( long);
54 } else
55 allocSize += (32 + 4 + 3 + next->propInit.length) & (-4);
56 }
57 saveout = out = kalloc( allocSize);
58
59 // copy out
60 for( next = template;
61 next;
62 next++) {
63
64 if( next->nodeInit.zero == 0) {
65
66 if( next->nodeInit.nProps == 0)
67 break;
68 source = &next->nodeInit.nProps;
69 size = 2 * sizeof( long);
70
71 } else {
72
73 bcopy( next->propInit.name, out, 32);
74 out += 32;
75 size = next->propInit.length;
76 *(long *)out = size;
77 out += sizeof( long);
78 if( size == 4)
79 source = &next->propInit.value;
80 else {
81 source = next->propInit.value;
82 size = (size + 3) & (-4);
83 }
84 }
85 bcopy( source, out, size);
86 out += size;
87 }
88
89 if( allocSize != (out - saveout))
90 printf("WARNING: DT corrupt (%x)\n", (out - saveout) - allocSize);
91
92 *retSize = allocSize;
93 return( (void *)saveout);
94 }
95
96 unsigned char *nptr;
97
98 #define kPropNameLength 32
99
100 typedef struct property_t {
101 char name[kPropNameLength]; // NUL terminated property name
102 unsigned long length; // Length (bytes) of folloing prop value
103 unsigned long *value; // Variable length value of property
104 } property_t;
105
106 typedef struct node_t {
107 unsigned long nProperties; // Number of props[] elements (0 => end)
108 unsigned long nChildren; // Number of children[] elements
109 property_t *props; // array size == nProperties
110 struct node_t *children; // array size == nChildren
111 } node_t;
112
113
114 int indent = 0;
115
116 void printdt()
117 {
118 node_t *nodeptr = (node_t *)nptr;
119 long num_props = nodeptr->nProperties;
120 long len;
121 int i, j;
122 unsigned char *sptr;
123
124 nptr = (unsigned char *)&nodeptr->props;
125 for (i=0; i < num_props; i++)
126 {
127 for (j = 0; j < indent; j++)
128 printf(" ");
129 printf("'");
130 printf("%s", nptr);
131 nptr+=32;
132 len = *((long*)nptr);
133 nptr += 4;
134 printf("'\t\t(%ld) '", len);
135 sptr = nptr;
136 for (j = 0; j < len; j++)
137 printf("%2.2x", *nptr++);
138 printf("'\t('%s')\n", sptr);
139 if (len % 4)
140 nptr += (4 - (len % 4));
141 }
142 for (i=0; i<nodeptr->nChildren; i++)
143 {
144 indent++;
145 printdt();
146 indent--;
147 }
148 }
149