2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
31 #include <pexpert/protos.h>
33 #include "fakePPCStructs.h"
35 boot_args fakePPCBootArgs
= { .Version
= kBootArgsVersion
};
37 void * createdt(dt_init
* template, long * retSize
)
40 size_t size
, allocSize
;
41 vm_address_t out
, saveout
;
44 // calc size of expanded data
45 for ( next
= template, allocSize
= 0;
49 if ( next
->nodeInit
.zero
== 0 )
51 if( next
->nodeInit
.nProps
== 0) break;
52 allocSize
+= 2 * sizeof( long);
54 else if ( next
->dataInit
.one
== 1 )
56 allocSize
+= *(next
->dataInit
.length
);
58 else if ( next
->stringInit
.two
== 2 )
60 dt_data
*dp
= (dt_data
*)(next
->stringInit
.data
);
61 allocSize
+= (32 + 4 + 3 + dp
->length
) & (-4);
65 allocSize
+= (32 + 4 + 3 + next
->propInit
.length
) & (-4);
68 saveout
= out
= (vm_address_t
) kalloc(allocSize
);
69 if ( out
== 0 ) return 0;
72 for ( next
= template; next
; next
++)
74 if ( next
->nodeInit
.zero
== 0 )
76 if ( next
->nodeInit
.nProps
== 0 ) break;
77 source
= &next
->nodeInit
.nProps
;
78 size
= 2 * sizeof( long);
80 else if ( next
->dataInit
.one
== 1 )
82 *((long *)next
->dataInit
.address
) = out
;
84 size
= *(next
->dataInit
.length
);
86 else if ( next
->stringInit
.two
== 2 )
88 dt_data
*dp
= (dt_data
*)next
->stringInit
.data
;
89 bcopy( (void *)(uintptr_t)next
->stringInit
.name
, (void *)out
, 32);
94 source
= (char *)dp
->address
;
95 size
= (size
+ 3) & (-4);
99 bcopy( (void *)(uintptr_t)next
->propInit
.name
, (void *)out
, 32);
101 size
= next
->propInit
.length
;
105 source
= &next
->propInit
.value
;
107 source
= next
->propInit
.value
;
108 size
= (size
+ 3) & (-4);
112 bcopy(source
, (void *)out
, size
);
114 bzero((void *)out
, size
);
118 if( allocSize
!= (out
- saveout
))
119 printf("WARNING: DT corrupt (%x)\n", (out
- saveout
) - allocSize
);
121 *retSize
= allocSize
;
122 return( (void *)saveout
);
127 #define kPropNameLength 32
129 typedef struct property_t
{
130 char name
[kPropNameLength
]; // NUL terminated property name
131 unsigned long length
; // Length (bytes) of folloing prop value
132 unsigned long *value
; // Variable length value of property
135 typedef struct node_t
{
136 unsigned long nProperties
; // Number of props[] elements (0 => end)
137 unsigned long nChildren
; // Number of children[] elements
138 property_t
*props
; // array size == nProperties
139 struct node_t
*children
; // array size == nChildren
143 unsigned int indent
= 0;
147 node_t
*nodeptr
= (node_t
*)nptr
;
148 unsigned long num_props
= nodeptr
->nProperties
;
153 nptr
= (unsigned char *)&nodeptr
->props
;
154 for (i
=0; i
< num_props
; i
++)
156 for (j
= 0; j
< indent
; j
++)
161 len
= *((unsigned long*)nptr
);
163 printf("'\t\t(%ld) '", len
);
165 for (j
= 0; j
< len
; j
++)
166 printf("%2.2x", *nptr
++);
167 printf("'\t('%s')\n", sptr
);
169 nptr
+= (4 - (len
% 4));
171 for (i
=0; i
<nodeptr
->nChildren
; i
++)