]> git.saurik.com Git - apple/xnu.git/blame - pexpert/i386/fakePPCDeviceTree.c
xnu-792.25.20.tar.gz
[apple/xnu.git] / pexpert / i386 / fakePPCDeviceTree.c
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
6601e61a 4 * @APPLE_LICENSE_HEADER_START@
1c79356b 5 *
6601e61a
A
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.
8f6c56a5 11 *
6601e61a
A
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
8f6c56a5
A
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
6601e61a
A
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.
8f6c56a5 19 *
6601e61a 20 * @APPLE_LICENSE_HEADER_END@
1c79356b
A
21 */
22
23#include <pexpert/protos.h>
24
25#include "fakePPCStructs.h"
26
91447636 27boot_args fakePPCBootArgs = { .Version = kBootArgsVersion };
1c79356b 28
0b4e3aa0 29void * createdt(dt_init * template, long * retSize)
1c79356b 30{
0b4e3aa0 31 dt_init * next;
91447636 32 size_t size, allocSize;
1c79356b 33 vm_address_t out, saveout;
0b4e3aa0 34 void * source;
1c79356b
A
35
36 // calc size of expanded data
0b4e3aa0
A
37 for ( next = template, allocSize = 0;
38 next;
39 next++ )
40 {
41 if ( next->nodeInit.zero == 0 )
42 {
43 if( next->nodeInit.nProps == 0) break;
44 allocSize += 2 * sizeof( long);
45 }
46 else if ( next->dataInit.one == 1 )
47 {
48 allocSize += *(next->dataInit.length);
49 }
91447636
A
50 else if ( next->stringInit.two == 2 )
51 {
52 dt_data *dp = (dt_data *)(next->stringInit.data);
53 allocSize += (32 + 4 + 3 + dp->length) & (-4);
54 }
0b4e3aa0
A
55 else
56 {
57 allocSize += (32 + 4 + 3 + next->propInit.length) & (-4);
58 }
1c79356b 59 }
91447636 60 saveout = out = (vm_address_t) kalloc(allocSize);
0b4e3aa0 61 if ( out == 0 ) return 0;
1c79356b
A
62
63 // copy out
0b4e3aa0
A
64 for ( next = template; next; next++)
65 {
66 if ( next->nodeInit.zero == 0 )
67 {
68 if ( next->nodeInit.nProps == 0 ) break;
69 source = &next->nodeInit.nProps;
70 size = 2 * sizeof( long);
71 }
72 else if ( next->dataInit.one == 1 )
73 {
91447636 74 *((long *)next->dataInit.address) = out;
0b4e3aa0
A
75 source = 0;
76 size = *(next->dataInit.length);
77 }
91447636
A
78 else if ( next->stringInit.two == 2 )
79 {
80 dt_data *dp = (dt_data *)next->stringInit.data;
81 bcopy( (void *)(uintptr_t)next->stringInit.name, (void *)out, 32);
82 out += 32;
83 size = dp->length;
84 *(long *)out = size;
85 out += sizeof(long);
86 source = (char *)dp->address;
87 size = (size + 3) & (-4);
88 }
0b4e3aa0
A
89 else
90 {
91447636 91 bcopy( (void *)(uintptr_t)next->propInit.name, (void *)out, 32);
0b4e3aa0
A
92 out += 32;
93 size = next->propInit.length;
94 *(long *)out = size;
95 out += sizeof(long);
96 if ( size == 4 )
97 source = &next->propInit.value;
98 else {
99 source = next->propInit.value;
100 size = (size + 3) & (-4);
101 }
102 }
103 if ( source )
104 bcopy(source, (void *)out, size);
105 else
106 bzero((void *)out, size);
107 out += size;
1c79356b
A
108 }
109
110 if( allocSize != (out - saveout))
111 printf("WARNING: DT corrupt (%x)\n", (out - saveout) - allocSize);
112
113 *retSize = allocSize;
0b4e3aa0 114 return( (void *)saveout );
1c79356b
A
115}
116
117unsigned char *nptr;
118
119#define kPropNameLength 32
120
121typedef struct property_t {
122 char name[kPropNameLength]; // NUL terminated property name
123 unsigned long length; // Length (bytes) of folloing prop value
124 unsigned long *value; // Variable length value of property
125} property_t;
126
127typedef struct node_t {
128 unsigned long nProperties; // Number of props[] elements (0 => end)
129 unsigned long nChildren; // Number of children[] elements
130 property_t *props; // array size == nProperties
131 struct node_t *children; // array size == nChildren
132} node_t;
133
134
91447636 135unsigned int indent = 0;
1c79356b
A
136
137void printdt()
138{
139 node_t *nodeptr = (node_t *)nptr;
91447636
A
140 unsigned long num_props = nodeptr->nProperties;
141 unsigned long len;
142 unsigned int i, j;
1c79356b
A
143 unsigned char *sptr;
144
145 nptr = (unsigned char *)&nodeptr->props;
146 for (i=0; i < num_props; i++)
147 {
148 for (j = 0; j < indent; j++)
149 printf(" ");
150 printf("'");
151 printf("%s", nptr);
152 nptr+=32;
91447636 153 len = *((unsigned long*)nptr);
1c79356b
A
154 nptr += 4;
155 printf("'\t\t(%ld) '", len);
156 sptr = nptr;
157 for (j = 0; j < len; j++)
158 printf("%2.2x", *nptr++);
159 printf("'\t('%s')\n", sptr);
160 if (len % 4)
161 nptr += (4 - (len % 4));
162 }
163 for (i=0; i<nodeptr->nChildren; i++)
164 {
165 indent++;
166 printdt();
167 indent--;
168 }
169}
170