]>
Commit | Line | Data |
---|---|---|
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 | { | |
52 | if( next->nodeInit.nProps == 0) break; | |
53 | allocSize += 2 * sizeof( long); | |
54 | } | |
55 | else if ( next->dataInit.one == 1 ) | |
56 | { | |
57 | allocSize += *(next->dataInit.length); | |
58 | } | |
59 | else | |
60 | { | |
61 | allocSize += (32 + 4 + 3 + next->propInit.length) & (-4); | |
62 | } | |
63 | } | |
64 | saveout = out = kalloc(allocSize); | |
65 | if ( out == 0 ) return 0; | |
66 | ||
67 | // copy out | |
68 | for ( next = template; next; next++) | |
69 | { | |
70 | if ( next->nodeInit.zero == 0 ) | |
71 | { | |
72 | if ( next->nodeInit.nProps == 0 ) break; | |
73 | source = &next->nodeInit.nProps; | |
74 | size = 2 * sizeof( long); | |
75 | } | |
76 | else if ( next->dataInit.one == 1 ) | |
77 | { | |
78 | *(next->dataInit.address) = out; | |
79 | source = 0; | |
80 | size = *(next->dataInit.length); | |
81 | } | |
82 | else | |
83 | { | |
84 | bcopy( next->propInit.name, (void *)out, 32); | |
85 | out += 32; | |
86 | size = next->propInit.length; | |
87 | *(long *)out = size; | |
88 | out += sizeof(long); | |
89 | if ( size == 4 ) | |
90 | source = &next->propInit.value; | |
91 | else { | |
92 | source = next->propInit.value; | |
93 | size = (size + 3) & (-4); | |
94 | } | |
95 | } | |
96 | if ( source ) | |
97 | bcopy(source, (void *)out, size); | |
98 | else | |
99 | bzero((void *)out, size); | |
100 | out += size; | |
101 | } | |
102 | ||
103 | if( allocSize != (out - saveout)) | |
104 | printf("WARNING: DT corrupt (%x)\n", (out - saveout) - allocSize); | |
105 | ||
106 | *retSize = allocSize; | |
107 | return( (void *)saveout ); | |
108 | } | |
109 | ||
110 | unsigned char *nptr; | |
111 | ||
112 | #define kPropNameLength 32 | |
113 | ||
114 | typedef struct property_t { | |
115 | char name[kPropNameLength]; // NUL terminated property name | |
116 | unsigned long length; // Length (bytes) of folloing prop value | |
117 | unsigned long *value; // Variable length value of property | |
118 | } property_t; | |
119 | ||
120 | typedef struct node_t { | |
121 | unsigned long nProperties; // Number of props[] elements (0 => end) | |
122 | unsigned long nChildren; // Number of children[] elements | |
123 | property_t *props; // array size == nProperties | |
124 | struct node_t *children; // array size == nChildren | |
125 | } node_t; | |
126 | ||
127 | ||
128 | int indent = 0; | |
129 | ||
130 | void printdt() | |
131 | { | |
132 | node_t *nodeptr = (node_t *)nptr; | |
133 | long num_props = nodeptr->nProperties; | |
134 | long len; | |
135 | int i, j; | |
136 | unsigned char *sptr; | |
137 | ||
138 | nptr = (unsigned char *)&nodeptr->props; | |
139 | for (i=0; i < num_props; i++) | |
140 | { | |
141 | for (j = 0; j < indent; j++) | |
142 | printf(" "); | |
143 | printf("'"); | |
144 | printf("%s", nptr); | |
145 | nptr+=32; | |
146 | len = *((long*)nptr); | |
147 | nptr += 4; | |
148 | printf("'\t\t(%ld) '", len); | |
149 | sptr = nptr; | |
150 | for (j = 0; j < len; j++) | |
151 | printf("%2.2x", *nptr++); | |
152 | printf("'\t('%s')\n", sptr); | |
153 | if (len % 4) | |
154 | nptr += (4 - (len % 4)); | |
155 | } | |
156 | for (i=0; i<nodeptr->nChildren; i++) | |
157 | { | |
158 | indent++; | |
159 | printdt(); | |
160 | indent--; | |
161 | } | |
162 | } | |
163 |