]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_OSREFERENCE_HEADER_START@ | |
5 | * | |
6 | * This file contains Original Code and/or Modifications of Original Code | |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. The rights granted to you under the | |
10 | * License may not be used to create, or enable the creation or | |
11 | * redistribution of, unlawful or unlicensed copies of an Apple operating | |
12 | * system, or to circumvent, violate, or enable the circumvention or | |
13 | * violation of, any terms of an Apple operating system software license | |
14 | * agreement. | |
15 | * | |
16 | * Please obtain a copy of the License at | |
17 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
18 | * file. | |
19 | * | |
20 | * The Original Code and all software distributed under the License are | |
21 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
22 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
23 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
24 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
25 | * Please see the License for the specific language governing rights and | |
26 | * limitations under the License. | |
27 | * | |
28 | * @APPLE_LICENSE_OSREFERENCE_HEADER_END@ | |
29 | */ | |
30 | ||
31 | #include <pexpert/protos.h> | |
32 | ||
33 | #include "fakePPCStructs.h" | |
34 | ||
35 | boot_args fakePPCBootArgs = { .Version = kBootArgsVersion }; | |
36 | ||
37 | void * createdt(dt_init * template, long * retSize) | |
38 | { | |
39 | dt_init * next; | |
40 | size_t size, allocSize; | |
41 | vm_address_t out, saveout; | |
42 | void * source; | |
43 | ||
44 | // calc size of expanded data | |
45 | for ( next = template, allocSize = 0; | |
46 | next; | |
47 | next++ ) | |
48 | { | |
49 | if ( next->nodeInit.zero == 0 ) | |
50 | { | |
51 | if( next->nodeInit.nProps == 0) break; | |
52 | allocSize += 2 * sizeof( long); | |
53 | } | |
54 | else if ( next->dataInit.one == 1 ) | |
55 | { | |
56 | allocSize += *(next->dataInit.length); | |
57 | } | |
58 | else if ( next->stringInit.two == 2 ) | |
59 | { | |
60 | dt_data *dp = (dt_data *)(next->stringInit.data); | |
61 | allocSize += (32 + 4 + 3 + dp->length) & (-4); | |
62 | } | |
63 | else | |
64 | { | |
65 | allocSize += (32 + 4 + 3 + next->propInit.length) & (-4); | |
66 | } | |
67 | } | |
68 | saveout = out = (vm_address_t) kalloc(allocSize); | |
69 | if ( out == 0 ) return 0; | |
70 | ||
71 | // copy out | |
72 | for ( next = template; next; next++) | |
73 | { | |
74 | if ( next->nodeInit.zero == 0 ) | |
75 | { | |
76 | if ( next->nodeInit.nProps == 0 ) break; | |
77 | source = &next->nodeInit.nProps; | |
78 | size = 2 * sizeof( long); | |
79 | } | |
80 | else if ( next->dataInit.one == 1 ) | |
81 | { | |
82 | *((long *)next->dataInit.address) = out; | |
83 | source = 0; | |
84 | size = *(next->dataInit.length); | |
85 | } | |
86 | else if ( next->stringInit.two == 2 ) | |
87 | { | |
88 | dt_data *dp = (dt_data *)next->stringInit.data; | |
89 | bcopy( (void *)(uintptr_t)next->stringInit.name, (void *)out, 32); | |
90 | out += 32; | |
91 | size = dp->length; | |
92 | *(long *)out = size; | |
93 | out += sizeof(long); | |
94 | source = (char *)dp->address; | |
95 | size = (size + 3) & (-4); | |
96 | } | |
97 | else | |
98 | { | |
99 | bcopy( (void *)(uintptr_t)next->propInit.name, (void *)out, 32); | |
100 | out += 32; | |
101 | size = next->propInit.length; | |
102 | *(long *)out = size; | |
103 | out += sizeof(long); | |
104 | if ( size == 4 ) | |
105 | source = &next->propInit.value; | |
106 | else { | |
107 | source = next->propInit.value; | |
108 | size = (size + 3) & (-4); | |
109 | } | |
110 | } | |
111 | if ( source ) | |
112 | bcopy(source, (void *)out, size); | |
113 | else | |
114 | bzero((void *)out, size); | |
115 | out += size; | |
116 | } | |
117 | ||
118 | if( allocSize != (out - saveout)) | |
119 | printf("WARNING: DT corrupt (%x)\n", (out - saveout) - allocSize); | |
120 | ||
121 | *retSize = allocSize; | |
122 | return( (void *)saveout ); | |
123 | } | |
124 | ||
125 | unsigned char *nptr; | |
126 | ||
127 | #define kPropNameLength 32 | |
128 | ||
129 | typedef struct property_t { | |
130 | char name[kPropNameLength]; // NUL terminated property name | |
131 | unsigned long length; // Length (bytes) of folloing prop value | |
132 | unsigned long *value; // Variable length value of property | |
133 | } property_t; | |
134 | ||
135 | typedef struct node_t { | |
136 | unsigned long nProperties; // Number of props[] elements (0 => end) | |
137 | unsigned long nChildren; // Number of children[] elements | |
138 | property_t *props; // array size == nProperties | |
139 | struct node_t *children; // array size == nChildren | |
140 | } node_t; | |
141 | ||
142 | ||
143 | unsigned int indent = 0; | |
144 | ||
145 | void printdt() | |
146 | { | |
147 | node_t *nodeptr = (node_t *)nptr; | |
148 | unsigned long num_props = nodeptr->nProperties; | |
149 | unsigned long len; | |
150 | unsigned int i, j; | |
151 | unsigned char *sptr; | |
152 | ||
153 | nptr = (unsigned char *)&nodeptr->props; | |
154 | for (i=0; i < num_props; i++) | |
155 | { | |
156 | for (j = 0; j < indent; j++) | |
157 | printf(" "); | |
158 | printf("'"); | |
159 | printf("%s", nptr); | |
160 | nptr+=32; | |
161 | len = *((unsigned long*)nptr); | |
162 | nptr += 4; | |
163 | printf("'\t\t(%ld) '", len); | |
164 | sptr = nptr; | |
165 | for (j = 0; j < len; j++) | |
166 | printf("%2.2x", *nptr++); | |
167 | printf("'\t('%s')\n", sptr); | |
168 | if (len % 4) | |
169 | nptr += (4 - (len % 4)); | |
170 | } | |
171 | for (i=0; i<nodeptr->nChildren; i++) | |
172 | { | |
173 | indent++; | |
174 | printdt(); | |
175 | indent--; | |
176 | } | |
177 | } | |
178 |