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
= { .Version
= kBootArgsVersion
};
29 void * createdt(dt_init
* template, long * retSize
)
32 size_t size
, allocSize
;
33 vm_address_t out
, saveout
;
36 // calc size of expanded data
37 for ( next
= template, allocSize
= 0;
41 if ( next
->nodeInit
.zero
== 0 )
43 if( next
->nodeInit
.nProps
== 0) break;
44 allocSize
+= 2 * sizeof( long);
46 else if ( next
->dataInit
.one
== 1 )
48 allocSize
+= *(next
->dataInit
.length
);
50 else if ( next
->stringInit
.two
== 2 )
52 dt_data
*dp
= (dt_data
*)(next
->stringInit
.data
);
53 allocSize
+= (32 + 4 + 3 + dp
->length
) & (-4);
57 allocSize
+= (32 + 4 + 3 + next
->propInit
.length
) & (-4);
60 saveout
= out
= (vm_address_t
) kalloc(allocSize
);
61 if ( out
== 0 ) return 0;
64 for ( next
= template; next
; next
++)
66 if ( next
->nodeInit
.zero
== 0 )
68 if ( next
->nodeInit
.nProps
== 0 ) break;
69 source
= &next
->nodeInit
.nProps
;
70 size
= 2 * sizeof( long);
72 else if ( next
->dataInit
.one
== 1 )
74 *((long *)next
->dataInit
.address
) = out
;
76 size
= *(next
->dataInit
.length
);
78 else if ( next
->stringInit
.two
== 2 )
80 dt_data
*dp
= (dt_data
*)next
->stringInit
.data
;
81 bcopy( (void *)(uintptr_t)next
->stringInit
.name
, (void *)out
, 32);
86 source
= (char *)dp
->address
;
87 size
= (size
+ 3) & (-4);
91 bcopy( (void *)(uintptr_t)next
->propInit
.name
, (void *)out
, 32);
93 size
= next
->propInit
.length
;
97 source
= &next
->propInit
.value
;
99 source
= next
->propInit
.value
;
100 size
= (size
+ 3) & (-4);
104 bcopy(source
, (void *)out
, size
);
106 bzero((void *)out
, size
);
110 if( allocSize
!= (out
- saveout
))
111 printf("WARNING: DT corrupt (%x)\n", (out
- saveout
) - allocSize
);
113 *retSize
= allocSize
;
114 return( (void *)saveout
);
119 #define kPropNameLength 32
121 typedef 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
127 typedef 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
135 unsigned int indent
= 0;
139 node_t
*nodeptr
= (node_t
*)nptr
;
140 unsigned long num_props
= nodeptr
->nProperties
;
145 nptr
= (unsigned char *)&nodeptr
->props
;
146 for (i
=0; i
< num_props
; i
++)
148 for (j
= 0; j
< indent
; j
++)
153 len
= *((unsigned long*)nptr
);
155 printf("'\t\t(%ld) '", len
);
157 for (j
= 0; j
< len
; j
++)
158 printf("%2.2x", *nptr
++);
159 printf("'\t('%s')\n", sptr
);
161 nptr
+= (4 - (len
% 4));
163 for (i
=0; i
<nodeptr
->nChildren
; i
++)