2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
23 #include <pexpert/protos.h>
25 #include "fakePPCStructs.h"
27 boot_args fakePPCBootArgs
= {
29 kBootArgsVersion
, // Version
31 {{0}}, // PhysicalDRAM
34 0, // deviceTreeLength
38 void * createdt(dt_init
* template, long * retSize
)
42 vm_address_t out
, saveout
;
45 // calc size of expanded data
46 for ( next
= template, allocSize
= 0;
50 if ( next
->nodeInit
.zero
== 0 )
52 if( next
->nodeInit
.nProps
== 0) break;
53 allocSize
+= 2 * sizeof( long);
55 else if ( next
->dataInit
.one
== 1 )
57 allocSize
+= *(next
->dataInit
.length
);
61 allocSize
+= (32 + 4 + 3 + next
->propInit
.length
) & (-4);
64 saveout
= out
= kalloc(allocSize
);
65 if ( out
== 0 ) return 0;
68 for ( next
= template; next
; next
++)
70 if ( next
->nodeInit
.zero
== 0 )
72 if ( next
->nodeInit
.nProps
== 0 ) break;
73 source
= &next
->nodeInit
.nProps
;
74 size
= 2 * sizeof( long);
76 else if ( next
->dataInit
.one
== 1 )
78 *(next
->dataInit
.address
) = out
;
80 size
= *(next
->dataInit
.length
);
84 bcopy( next
->propInit
.name
, (void *)out
, 32);
86 size
= next
->propInit
.length
;
90 source
= &next
->propInit
.value
;
92 source
= next
->propInit
.value
;
93 size
= (size
+ 3) & (-4);
97 bcopy(source
, (void *)out
, size
);
99 bzero((void *)out
, size
);
103 if( allocSize
!= (out
- saveout
))
104 printf("WARNING: DT corrupt (%x)\n", (out
- saveout
) - allocSize
);
106 *retSize
= allocSize
;
107 return( (void *)saveout
);
112 #define kPropNameLength 32
114 typedef struct property_t
{
115 char name
[kPropNameLength
]; // NUL terminated property name
116 unsigned long length
; // Length (bytes) of folloing prop value
117 unsigned long *value
; // Variable length value of property
120 typedef struct node_t
{
121 unsigned long nProperties
; // Number of props[] elements (0 => end)
122 unsigned long nChildren
; // Number of children[] elements
123 property_t
*props
; // array size == nProperties
124 struct node_t
*children
; // array size == nChildren
132 node_t
*nodeptr
= (node_t
*)nptr
;
133 long num_props
= nodeptr
->nProperties
;
138 nptr
= (unsigned char *)&nodeptr
->props
;
139 for (i
=0; i
< num_props
; i
++)
141 for (j
= 0; j
< indent
; j
++)
146 len
= *((long*)nptr
);
148 printf("'\t\t(%ld) '", len
);
150 for (j
= 0; j
< len
; j
++)
151 printf("%2.2x", *nptr
++);
152 printf("'\t('%s')\n", sptr
);
154 nptr
+= (4 - (len
% 4));
156 for (i
=0; i
<nodeptr
->nChildren
; i
++)