2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 #include <pexpert/protos.h>
26 #include "fakePPCStructs.h"
28 boot_args fakePPCBootArgs
= { .Version
= kBootArgsVersion
};
30 void * createdt(dt_init
* template, long * retSize
)
33 size_t size
, allocSize
;
34 vm_address_t out
, saveout
;
37 // calc size of expanded data
38 for ( next
= template, allocSize
= 0;
42 if ( next
->nodeInit
.zero
== 0 )
44 if( next
->nodeInit
.nProps
== 0) break;
45 allocSize
+= 2 * sizeof( long);
47 else if ( next
->dataInit
.one
== 1 )
49 allocSize
+= *(next
->dataInit
.length
);
51 else if ( next
->stringInit
.two
== 2 )
53 dt_data
*dp
= (dt_data
*)(next
->stringInit
.data
);
54 allocSize
+= (32 + 4 + 3 + dp
->length
) & (-4);
58 allocSize
+= (32 + 4 + 3 + next
->propInit
.length
) & (-4);
61 saveout
= out
= (vm_address_t
) kalloc(allocSize
);
62 if ( out
== 0 ) return 0;
65 for ( next
= template; next
; next
++)
67 if ( next
->nodeInit
.zero
== 0 )
69 if ( next
->nodeInit
.nProps
== 0 ) break;
70 source
= &next
->nodeInit
.nProps
;
71 size
= 2 * sizeof( long);
73 else if ( next
->dataInit
.one
== 1 )
75 *((long *)next
->dataInit
.address
) = out
;
77 size
= *(next
->dataInit
.length
);
79 else if ( next
->stringInit
.two
== 2 )
81 dt_data
*dp
= (dt_data
*)next
->stringInit
.data
;
82 bcopy( (void *)(uintptr_t)next
->stringInit
.name
, (void *)out
, 32);
87 source
= (char *)dp
->address
;
88 size
= (size
+ 3) & (-4);
92 bcopy( (void *)(uintptr_t)next
->propInit
.name
, (void *)out
, 32);
94 size
= next
->propInit
.length
;
98 source
= &next
->propInit
.value
;
100 source
= next
->propInit
.value
;
101 size
= (size
+ 3) & (-4);
105 bcopy(source
, (void *)out
, size
);
107 bzero((void *)out
, size
);
111 if( allocSize
!= (out
- saveout
))
112 printf("WARNING: DT corrupt (%x)\n", (out
- saveout
) - allocSize
);
114 *retSize
= allocSize
;
115 return( (void *)saveout
);
120 #define kPropNameLength 32
122 typedef struct property_t
{
123 char name
[kPropNameLength
]; // NUL terminated property name
124 unsigned long length
; // Length (bytes) of folloing prop value
125 unsigned long *value
; // Variable length value of property
128 typedef struct node_t
{
129 unsigned long nProperties
; // Number of props[] elements (0 => end)
130 unsigned long nChildren
; // Number of children[] elements
131 property_t
*props
; // array size == nProperties
132 struct node_t
*children
; // array size == nChildren
136 unsigned int indent
= 0;
140 node_t
*nodeptr
= (node_t
*)nptr
;
141 unsigned long num_props
= nodeptr
->nProperties
;
146 nptr
= (unsigned char *)&nodeptr
->props
;
147 for (i
=0; i
< num_props
; i
++)
149 for (j
= 0; j
< indent
; j
++)
154 len
= *((unsigned long*)nptr
);
156 printf("'\t\t(%ld) '", len
);
158 for (j
= 0; j
< len
; j
++)
159 printf("%2.2x", *nptr
++);
160 printf("'\t('%s')\n", sptr
);
162 nptr
+= (4 - (len
% 4));
164 for (i
=0; i
<nodeptr
->nChildren
; i
++)