Annotation of XNU/pexpert/i386/fakePPCDeviceTree.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
                      3:  *
                      4:  * @APPLE_LICENSE_HEADER_START@
                      5:  * 
                      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.
                     11:  * 
                     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
                     18:  * under the License.
                     19:  * 
                     20:  * @APPLE_LICENSE_HEADER_END@
                     21:  */
                     22: 
                     23: #include <pexpert/protos.h>
                     24: 
                     25: #include "fakePPCStructs.h"
                     26: 
                     27: void PE_pause(int);
                     28: 
                     29: boot_args fakePPCBootArgs = {
                     30:        0, // Revision
                     31:         kBootArgsVersion, // Version
                     32:         "",     // CommandLine
                     33:         0,      // PhysicalDRAM
                     34:         0,      // machine_type
                     35:         0,      // deviceTreeP
                     36:         0,      // deviceTreeLength
                     37:         0,      // topOfKernelData
                     38: };
                     39: 
                     40: void * createdt(dt_init *template, long *retSize)
                     41: {
                     42:     dt_init *  next;
                     43:     int        size, allocSize;
                     44:     vm_address_t out, saveout;
                     45:     void *     source;
                     46:     
                     47:     // calc size of expanded data
                     48:     for( next = template, allocSize = 0;
                     49:        next;
                     50:        next++) {
                     51: 
                     52:        if( next->nodeInit.zero == 0) {
                     53:            if( next->nodeInit.nProps == 0)
                     54:                break;
                     55:            allocSize += 2 * sizeof( long);
                     56:        } else
                     57:            allocSize += (32 + 4 + 3 + next->propInit.length) & (-4);
                     58:     }
                     59:     saveout = out = kalloc( allocSize);
                     60: 
                     61:     // copy out
                     62:     for( next = template;
                     63:        next;
                     64:        next++) {
                     65: 
                     66:        if( next->nodeInit.zero == 0) {
                     67: 
                     68:            if( next->nodeInit.nProps == 0)
                     69:                break;
                     70:            source = &next->nodeInit.nProps;
                     71:            size = 2 * sizeof( long);
                     72: 
                     73:        } else {
                     74: 
                     75:            bcopy( next->propInit.name, out, 32);
                     76:            out += 32;
                     77:            size = next->propInit.length;
                     78:            *(long *)out = size;
                     79:            out += sizeof( long);
                     80:            if( size == 4)
                     81:                source = &next->propInit.value;
                     82:            else {
                     83:                source = next->propInit.value;
                     84:                size = (size + 3) & (-4);
                     85:            }
                     86:        }
                     87:         bcopy( source, out, size);
                     88:        out += size;
                     89:     }
                     90: 
                     91:     if( allocSize != (out - saveout))
                     92:         printf("WARNING: DT corrupt (%x)\n", (out - saveout) - allocSize);
                     93: 
                     94:     *retSize = allocSize;
                     95:     return( (void *)saveout);
                     96: }
                     97: 
                     98: unsigned char *nptr;
                     99: 
                    100: #define kPropNameLength 32
                    101: 
                    102: typedef struct property_t {
                    103:     char                name[kPropNameLength];  // NUL terminated property name
                    104:     unsigned long       length;         // Length (bytes) of folloing prop value
                    105:     unsigned long       *value;         // Variable length value of property
                    106: } property_t;
                    107: 
                    108: typedef struct node_t {
                    109:     unsigned long       nProperties;    // Number of props[] elements (0 => end)
                    110:     unsigned long       nChildren;      // Number of children[] elements
                    111:     property_t *props;      // array size == nProperties
                    112:     struct node_t   *children;     // array size == nChildren
                    113: } node_t;
                    114: 
                    115: 
                    116: int indent = 0;
                    117: 
                    118: void printdt()
                    119: {
                    120:     node_t *nodeptr = (node_t *)nptr;
                    121:     long num_props    = nodeptr->nProperties;
                    122:     long len;
                    123:     int i, j;
                    124:     unsigned char *sptr;
                    125: 
                    126:     nptr = (unsigned char *)&nodeptr->props;
                    127:     for (i=0; i < num_props; i++)
                    128:     {
                    129:         for (j = 0; j < indent; j++)
                    130:             printf("    ");
                    131:         printf("'");
                    132:         printf("%s", nptr);
                    133:         nptr+=32;
                    134:         len = *((long*)nptr);
                    135:         nptr += 4;
                    136:         printf("'\t\t(%ld)  '", len);
                    137:         sptr = nptr;
                    138:         for (j = 0; j < len; j++)
                    139:             printf("%2.2x", *nptr++);
                    140:         printf("'\t('%s')\n", sptr);
                    141:         if (len % 4)
                    142:             nptr += (4 - (len % 4));
                    143:        PE_pause(20);
                    144:     }
                    145:     for (i=0; i<nodeptr->nChildren; i++)
                    146:     {
                    147:         indent++;
                    148:         printdt();
                    149:         indent--;
                    150:     }
                    151: }
                    152: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.