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