]> git.saurik.com Git - apple/xnu.git/blame - pexpert/i386/fakePPCDeviceTree.c
xnu-792.13.8.tar.gz
[apple/xnu.git] / pexpert / i386 / fakePPCDeviceTree.c
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
8ad349bb 4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
1c79356b 5 *
8ad349bb
A
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@
1c79356b
A
29 */
30
31#include <pexpert/protos.h>
32
33#include "fakePPCStructs.h"
34
91447636 35boot_args fakePPCBootArgs = { .Version = kBootArgsVersion };
1c79356b 36
0b4e3aa0 37void * createdt(dt_init * template, long * retSize)
1c79356b 38{
0b4e3aa0 39 dt_init * next;
91447636 40 size_t size, allocSize;
1c79356b 41 vm_address_t out, saveout;
0b4e3aa0 42 void * source;
1c79356b
A
43
44 // calc size of expanded data
0b4e3aa0
A
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 }
91447636
A
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 }
0b4e3aa0
A
63 else
64 {
65 allocSize += (32 + 4 + 3 + next->propInit.length) & (-4);
66 }
1c79356b 67 }
91447636 68 saveout = out = (vm_address_t) kalloc(allocSize);
0b4e3aa0 69 if ( out == 0 ) return 0;
1c79356b
A
70
71 // copy out
0b4e3aa0
A
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 {
91447636 82 *((long *)next->dataInit.address) = out;
0b4e3aa0
A
83 source = 0;
84 size = *(next->dataInit.length);
85 }
91447636
A
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 }
0b4e3aa0
A
97 else
98 {
91447636 99 bcopy( (void *)(uintptr_t)next->propInit.name, (void *)out, 32);
0b4e3aa0
A
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;
1c79356b
A
116 }
117
118 if( allocSize != (out - saveout))
119 printf("WARNING: DT corrupt (%x)\n", (out - saveout) - allocSize);
120
121 *retSize = allocSize;
0b4e3aa0 122 return( (void *)saveout );
1c79356b
A
123}
124
125unsigned char *nptr;
126
127#define kPropNameLength 32
128
129typedef 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
135typedef 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
91447636 143unsigned int indent = 0;
1c79356b
A
144
145void printdt()
146{
147 node_t *nodeptr = (node_t *)nptr;
91447636
A
148 unsigned long num_props = nodeptr->nProperties;
149 unsigned long len;
150 unsigned int i, j;
1c79356b
A
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;
91447636 161 len = *((unsigned long*)nptr);
1c79356b
A
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