* ========== Copyright Header Begin ==========================================
* Hypervisor Software File: forth.c
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* - Do no alter or remove copyright notices
* - Redistribution and use of this software in source and binary forms, with
* or without modification, are permitted provided that the following
* - Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistribution in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of Sun Microsystems, Inc. or the names of contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
* INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
* MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
* ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
* OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
* FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
* DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
* SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* You acknowledge that this software is not designed, licensed or
* intended for use in the design, construction, operation or maintenance of
* ========== Copyright Header End ============================================
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
#pragma ident "@(#)forth.c 1.2 07/06/07 SMI"
void forth_do_sou(struct tdesc
*tdp
, struct node
*np
);
void forth_do_enum(struct tdesc
*tdp
, struct node
*np
);
void forth_do_intrinsic(struct tdesc
*tdp
, struct node
*np
);
static void switch_on_type(struct mlist
*mlp
, struct tdesc
*tdp
,
char *format
, int level
);
static void print_intrinsic(struct mlist
*mlp
, struct tdesc
*tdp
,
char *format
, int level
);
static void print_forward(struct mlist
*mlp
, struct tdesc
*tdp
,
char *format
, int level
);
static void print_pointer(struct mlist
*mlp
, struct tdesc
*tdp
,
char *format
, int level
);
static void print_array(struct mlist
*mlp
, struct tdesc
*tdp
,
char *format
, int level
);
static void print_function(struct mlist
*mlp
, struct tdesc
*tdp
,
char *format
, int level
);
static void print_union(struct mlist
*mlp
, struct tdesc
*tdp
,
char *format
, int level
);
static void print_enum(struct mlist
*mlp
, struct tdesc
*tdp
,
char *format
, int level
);
static void print_forward(struct mlist
*mlp
, struct tdesc
*tdp
,
char *format
, int level
);
static void print_typeof(struct mlist
*mlp
, struct tdesc
*tdp
,
char *format
, int level
);
static void print_struct(struct mlist
*mlp
, struct tdesc
*tdp
,
char *format
, int level
);
static void print_volatile(struct mlist
*mlp
, struct tdesc
*tdp
,
char *format
, int level
);
forth_do_intrinsic(struct tdesc
*tdp
, struct node
*np
)
forth_do_sou(struct tdesc
*tdp
, struct node
*np
)
printf("vocabulary %s-words\n", np
->name
);
printf("h# %x constant %s-sz\n", tdp
->size
, np
->name
);
printf("%x ' %s-words c-struct .%s\n",
tdp
->size
, np
->name
, np
->name
);
printf("also %s-words definitions\n\n", np
->name
);
* Run thru all the fields of a struct and print them out
for (mlp
= tdp
->data
.members
.back
; mlp
!= NULL
; mlp
= mlp
->prev
) {
* If there's a child list, only print those members.
chp
= find_child(np
, mlp
->name
);
switch_on_type(mlp
, mlp
->fdesc
, format
, 0);
printf("\nkdbg-words definitions\n");
printf("\\ end %s section\n\n", np
->name
);
forth_do_enum(struct tdesc
*tdp
, struct node
*np
)
for (elp
= tdp
->data
.emem
; elp
!= NULL
; elp
= elp
->next
) {
printf("here ,\" %s\" %x\n", elp
->name
, elp
->number
);
printf("%x c-enum .%s\n", nelem
, np
->name
);
switch_on_type(struct mlist
*mlp
, struct tdesc
*tdp
, char *format
, int level
)
print_intrinsic(mlp
, tdp
, format
, level
);
print_pointer(mlp
, tdp
, format
, level
);
print_array(mlp
, tdp
, format
, level
);
print_function(mlp
, tdp
, format
, level
);
print_union(mlp
, tdp
, format
, level
);
print_enum(mlp
, tdp
, format
, level
);
print_forward(mlp
, tdp
, format
, level
);
print_typeof(mlp
, tdp
, format
, level
);
print_struct(mlp
, tdp
, format
, level
);
print_volatile(mlp
, tdp
, format
, level
);
fprintf(stderr
, "Switch to Unknown type\n");
print_forward(struct mlist
*mlp
, struct tdesc
*tdp
, char *format
, int level
)
fprintf(stderr
, "%s never defined\n", mlp
->name
);
print_typeof(struct mlist
*mlp
, struct tdesc
*tdp
, char *format
, int level
)
switch_on_type(mlp
, tdp
->data
.tdesc
, format
, level
);
print_volatile(struct mlist
*mlp
, struct tdesc
*tdp
, char *format
, int level
)
switch_on_type(mlp
, tdp
->data
.tdesc
, format
, level
);
print_intrinsic(struct mlist
*mlp
, struct tdesc
*tdp
, char *format
, int level
)
format
= convert_format(format
, ".x");
printf("' c@ ' %s", format
);
printf("' w@ ' %s", format
);
printf("' l@ ' %s", format
);
printf("' x@ ' %s", format
);
} else if (mlp
->size
!= 0 &&
((mlp
->size
% 8) != 0 || (mlp
->offset
% mlp
->size
) != 0)) {
offset
= (mlp
->offset
/ 32) * 4;
shift
= 32 - ((mlp
->offset
% 32) + mlp
->size
);
mask
= ((int)pow(2, mlp
->size
) - 1) << shift
;
printf("' %s %x %x %x bits-field %s\n",
format
, shift
, mask
, offset
, mlp
->name
);
} else if (mlp
->name
!= NULL
) {
printf("' %s %x byte-field %s\n",
format
, mlp
->offset
/ 8, mlp
->name
);
printf("' %s %x short-field %s\n",
format
, mlp
->offset
/ 8, mlp
->name
);
printf("' %s %x long-field %s\n",
format
, mlp
->offset
/ 8, mlp
->name
);
printf("' %s %x ext-field %s\n",
format
, mlp
->offset
/ 8, mlp
->name
);
print_pointer(struct mlist
*mlp
, struct tdesc
*tdp
, char *format
, int level
)
format
= convert_format(format
, ".x");
printf("' c@ ' %s", format
);
printf("' w@ ' %s", format
);
printf("' l@ ' %s", format
);
printf("' x@ ' %s", format
);
printf("' %s %x ptr-field %s\n",
format
, mlp
->offset
/ 8, mlp
->name
);
print_array(struct mlist
*mlp
, struct tdesc
*tdp
, char *format
, int level
)
struct ardef
*ap
= tdp
->data
.ardef
;
items
= ap
->indices
->range_end
- ap
->indices
->range_start
+ 1;
inc
= (mlp
->size
/ items
) / 8;
switch_on_type(mlp
, ap
->contents
, format
, level
+ 1);
printf(" %x %x %x array-field", limit
, inc
, mlp
->offset
/ 8);
printf(" %s\n", mlp
->name
);
print_function(struct mlist
*mlp
, struct tdesc
*tdp
, char *format
, int level
)
fprintf(stderr
, "function in struct %s\n", tdp
->name
);
print_struct(struct mlist
*mlp
, struct tdesc
*tdp
, char *format
, int level
)
format
= convert_format(format
, ".x");
printf("' noop ' %s", format
);
printf("' %s %x struct-field %s\n",
format
, mlp
->offset
/ 8, mlp
->name
);
print_union(struct mlist
*mlp
, struct tdesc
*tdp
, char *format
, int level
)
format
= convert_format(format
, ".x");
printf("' noop ' %s", format
);
printf("' %s %x struct-field %s\n",
format
, mlp
->offset
/ 8, mlp
->name
);
print_enum(struct mlist
*mlp
, struct tdesc
*tdp
, char *format
, int level
)
format
= convert_format(format
, ".d");
printf("' l@ ' %s", format
);
printf("' %s %x long-field %s\n",
format
, mlp
->offset
/ 8, mlp
->name
);