2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 #include <pexpert/protos.h>
31 #include "fakePPCStructs.h"
33 boot_args fakePPCBootArgs
= { .Version
= kBootArgsVersion
};
35 void * createdt(dt_init
* template, long * retSize
)
38 size_t size
, allocSize
;
39 vm_address_t out
, saveout
;
42 // calc size of expanded data
43 for ( next
= template, allocSize
= 0;
47 if ( next
->nodeInit
.zero
== 0 )
49 if( next
->nodeInit
.nProps
== 0) break;
50 allocSize
+= 2 * sizeof( long);
52 else if ( next
->dataInit
.one
== 1 )
54 allocSize
+= *(next
->dataInit
.length
);
56 else if ( next
->stringInit
.two
== 2 )
58 dt_data
*dp
= (dt_data
*)(next
->stringInit
.data
);
59 allocSize
+= (32 + 4 + 3 + dp
->length
) & (-4);
63 allocSize
+= (32 + 4 + 3 + next
->propInit
.length
) & (-4);
66 saveout
= out
= (vm_address_t
) kalloc(allocSize
);
67 if ( out
== 0 ) return 0;
70 for ( next
= template; next
; next
++)
72 if ( next
->nodeInit
.zero
== 0 )
74 if ( next
->nodeInit
.nProps
== 0 ) break;
75 source
= &next
->nodeInit
.nProps
;
76 size
= 2 * sizeof( long);
78 else if ( next
->dataInit
.one
== 1 )
80 *((long *)next
->dataInit
.address
) = out
;
82 size
= *(next
->dataInit
.length
);
84 else if ( next
->stringInit
.two
== 2 )
86 dt_data
*dp
= (dt_data
*)next
->stringInit
.data
;
87 bcopy( (void *)(uintptr_t)next
->stringInit
.name
, (void *)out
, 32);
92 source
= (char *)dp
->address
;
93 size
= (size
+ 3) & (-4);
97 bcopy( (void *)(uintptr_t)next
->propInit
.name
, (void *)out
, 32);
99 size
= next
->propInit
.length
;
103 source
= &next
->propInit
.value
;
105 source
= next
->propInit
.value
;
106 size
= (size
+ 3) & (-4);
110 bcopy(source
, (void *)out
, size
);
112 bzero((void *)out
, size
);
116 if( allocSize
!= (out
- saveout
))
117 printf("WARNING: DT corrupt (%x)\n", (out
- saveout
) - allocSize
);
119 *retSize
= allocSize
;
120 return( (void *)saveout
);
125 #define kPropNameLength 32
127 typedef 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
133 typedef 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
141 unsigned int indent
= 0;
145 node_t
*nodeptr
= (node_t
*)nptr
;
146 unsigned long num_props
= nodeptr
->nProperties
;
151 nptr
= (unsigned char *)&nodeptr
->props
;
152 for (i
=0; i
< num_props
; i
++)
154 for (j
= 0; j
< indent
; j
++)
159 len
= *((unsigned long*)nptr
);
161 printf("'\t\t(%ld) '", len
);
163 for (j
= 0; j
< len
; j
++)
164 printf("%2.2x", *nptr
++);
165 printf("'\t('%s')\n", sptr
);
167 nptr
+= (4 - (len
% 4));
169 for (i
=0; i
<nodeptr
->nChildren
; i
++)