The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/pexpert/i386/fakePPCDeviceTree.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    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 boot_args fakePPCBootArgs = { .Version = kBootArgsVersion };
   28 
   29 void * createdt(dt_init * template, long * retSize)
   30 {
   31     dt_init *    next;
   32     size_t       size, allocSize;
   33     vm_address_t out, saveout;
   34     void *       source;
   35     
   36     // calc size of expanded data
   37     for ( next = template, allocSize = 0;
   38           next;
   39           next++ )
   40     {
   41         if ( next->nodeInit.zero == 0 )
   42         {
   43             if( next->nodeInit.nProps == 0) break;
   44             allocSize += 2 * sizeof( long);
   45         }
   46         else if ( next->dataInit.one == 1 )
   47         {
   48             allocSize += *(next->dataInit.length);
   49         }
   50         else if ( next->stringInit.two == 2 )
   51         {
   52             dt_data *dp = (dt_data *)(next->stringInit.data);
   53             allocSize += (32 + 4 + 3 + dp->length) & (-4);
   54         }
   55         else
   56         {
   57             allocSize += (32 + 4 + 3 + next->propInit.length) & (-4);
   58         }
   59     }
   60     saveout = out = (vm_address_t) kalloc(allocSize);
   61     if ( out == 0 ) return 0;
   62 
   63     // copy out
   64     for ( next = template; next; next++)
   65     {
   66         if ( next->nodeInit.zero == 0 )
   67         {
   68             if ( next->nodeInit.nProps == 0 ) break;
   69             source = &next->nodeInit.nProps;
   70             size = 2 * sizeof( long);
   71         }
   72         else if ( next->dataInit.one == 1 )
   73         {
   74             *((long *)next->dataInit.address) = out;
   75             source = 0;
   76             size   = *(next->dataInit.length);
   77         }
   78         else if ( next->stringInit.two == 2 )
   79         {
   80             dt_data *dp = (dt_data *)next->stringInit.data;
   81             bcopy( (void *)(uintptr_t)next->stringInit.name, (void *)out, 32);
   82             out += 32;
   83             size = dp->length;
   84             *(long *)out = size;
   85             out += sizeof(long);
   86             source = (char *)dp->address;
   87             size = (size + 3) & (-4);
   88         }
   89         else
   90         {
   91             bcopy( (void *)(uintptr_t)next->propInit.name, (void *)out, 32);
   92             out += 32;
   93             size = next->propInit.length;
   94             *(long *)out = size;
   95             out += sizeof(long);
   96             if ( size == 4 )
   97                 source = &next->propInit.value;
   98             else {
   99                 source = next->propInit.value;
  100                 size = (size + 3) & (-4);
  101             }
  102         }
  103         if ( source )
  104             bcopy(source, (void *)out, size);
  105         else
  106             bzero((void *)out, size);
  107         out += size;
  108     }
  109 
  110     if( allocSize != (out - saveout))
  111         printf("WARNING: DT corrupt (%x)\n", (out - saveout) - allocSize);
  112 
  113     *retSize = allocSize;
  114     return( (void *)saveout );
  115 }
  116 
  117 unsigned char *nptr;
  118 
  119 #define kPropNameLength 32
  120 
  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
  125 } property_t;
  126 
  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
  132 } node_t;
  133 
  134 
  135 unsigned int indent = 0;
  136 
  137 void printdt()
  138 {
  139     node_t *nodeptr = (node_t *)nptr;
  140     unsigned long num_props    = nodeptr->nProperties;
  141     unsigned long len;
  142     unsigned int i, j;
  143     unsigned char *sptr;
  144 
  145     nptr = (unsigned char *)&nodeptr->props;
  146     for (i=0; i < num_props; i++)
  147     {
  148         for (j = 0; j < indent; j++)
  149             printf("    ");
  150         printf("'");
  151         printf("%s", nptr);
  152         nptr+=32;
  153         len = *((unsigned long*)nptr);
  154         nptr += 4;
  155         printf("'\t\t(%ld)  '", len);
  156         sptr = nptr;
  157         for (j = 0; j < len; j++)
  158             printf("%2.2x", *nptr++);
  159         printf("'\t('%s')\n", sptr);
  160         if (len % 4)
  161             nptr += (4 - (len % 4));
  162     }
  163     for (i=0; i<nodeptr->nChildren; i++)
  164     {
  165         indent++;
  166         printdt();
  167         indent--;
  168     }
  169 }
  170 

Cache object: 1912265cb0f94a6f885fbebaa2df1745


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.