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