fakePPCDeviceTree.c [plain text]
#include <pexpert/protos.h>
#include "fakePPCStructs.h"
boot_args fakePPCBootArgs = {
0, kBootArgsVersion, "", 0, 0, 0, 0, 0, };
void * createdt(dt_init * template, long * retSize)
{
dt_init * next;
int size, allocSize;
vm_address_t out, saveout;
void * source;
for ( next = template, allocSize = 0;
next;
next++ )
{
if ( next->nodeInit.zero == 0 )
{
if( next->nodeInit.nProps == 0) break;
allocSize += 2 * sizeof( long);
}
else if ( next->dataInit.one == 1 )
{
allocSize += *(next->dataInit.length);
}
else
{
allocSize += (32 + 4 + 3 + next->propInit.length) & (-4);
}
}
saveout = out = kalloc(allocSize);
if ( out == 0 ) return 0;
for ( next = template; next; next++)
{
if ( next->nodeInit.zero == 0 )
{
if ( next->nodeInit.nProps == 0 ) break;
source = &next->nodeInit.nProps;
size = 2 * sizeof( long);
}
else if ( next->dataInit.one == 1 )
{
*(next->dataInit.address) = out;
source = 0;
size = *(next->dataInit.length);
}
else
{
bcopy( next->propInit.name, (void *)out, 32);
out += 32;
size = next->propInit.length;
*(long *)out = size;
out += sizeof(long);
if ( size == 4 )
source = &next->propInit.value;
else {
source = next->propInit.value;
size = (size + 3) & (-4);
}
}
if ( source )
bcopy(source, (void *)out, size);
else
bzero((void *)out, size);
out += size;
}
if( allocSize != (out - saveout))
printf("WARNING: DT corrupt (%x)\n", (out - saveout) - allocSize);
*retSize = allocSize;
return( (void *)saveout );
}
unsigned char *nptr;
#define kPropNameLength 32
typedef struct property_t {
char name[kPropNameLength]; unsigned long length; unsigned long *value; } property_t;
typedef struct node_t {
unsigned long nProperties; unsigned long nChildren; property_t *props; struct node_t *children; } node_t;
int indent = 0;
void printdt()
{
node_t *nodeptr = (node_t *)nptr;
long num_props = nodeptr->nProperties;
long len;
int i, j;
unsigned char *sptr;
nptr = (unsigned char *)&nodeptr->props;
for (i=0; i < num_props; i++)
{
for (j = 0; j < indent; j++)
printf(" ");
printf("'");
printf("%s", nptr);
nptr+=32;
len = *((long*)nptr);
nptr += 4;
printf("'\t\t(%ld) '", len);
sptr = nptr;
for (j = 0; j < len; j++)
printf("%2.2x", *nptr++);
printf("'\t('%s')\n", sptr);
if (len % 4)
nptr += (4 - (len % 4));
}
for (i=0; i<nodeptr->nChildren; i++)
{
indent++;
printdt();
indent--;
}
}