4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 1996-2002 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
33 void forth_do_sou(struct tdesc
*tdp
, struct node
*np
);
34 void forth_do_enum(struct tdesc
*tdp
, struct node
*np
);
35 void forth_do_intrinsic(struct tdesc
*tdp
, struct node
*np
);
37 static void switch_on_type(struct mlist
*mlp
, struct tdesc
*tdp
,
38 char *format
, int level
);
40 static void print_intrinsic(struct mlist
*mlp
, struct tdesc
*tdp
,
41 char *format
, int level
);
42 static void print_forward(struct mlist
*mlp
, struct tdesc
*tdp
,
43 char *format
, int level
);
44 static void print_pointer(struct mlist
*mlp
, struct tdesc
*tdp
,
45 char *format
, int level
);
46 static void print_array(struct mlist
*mlp
, struct tdesc
*tdp
,
47 char *format
, int level
);
48 static void print_function(struct mlist
*mlp
, struct tdesc
*tdp
,
49 char *format
, int level
);
50 static void print_union(struct mlist
*mlp
, struct tdesc
*tdp
,
51 char *format
, int level
);
52 static void print_enum(struct mlist
*mlp
, struct tdesc
*tdp
,
53 char *format
, int level
);
54 static void print_forward(struct mlist
*mlp
, struct tdesc
*tdp
,
55 char *format
, int level
);
56 static void print_typeof(struct mlist
*mlp
, struct tdesc
*tdp
,
57 char *format
, int level
);
58 static void print_struct(struct mlist
*mlp
, struct tdesc
*tdp
,
59 char *format
, int level
);
60 static void print_volatile(struct mlist
*mlp
, struct tdesc
*tdp
,
61 char *format
, int level
);
64 forth_do_intrinsic(struct tdesc
*tdp
, struct node
*np
)
69 forth_do_sou(struct tdesc
*tdp
, struct node
*np
)
76 printf("vocabulary %s-words\n", np
->name
);
77 printf("h# %x constant %s-sz\n", tdp
->size
, np
->name
);
78 printf("%x ' %s-words c-struct .%s\n",
79 tdp
->size
, np
->name
, np
->name
);
80 printf("also %s-words definitions\n\n", np
->name
);
83 * Run thru all the fields of a struct and print them out
85 for (mlp
= tdp
->data
.members
.back
; mlp
!= NULL
; mlp
= mlp
->prev
) {
87 * If there's a child list, only print those members.
90 if (mlp
->name
== NULL
)
92 chp
= find_child(np
, mlp
->name
);
98 if (mlp
->fdesc
== NULL
)
100 switch_on_type(mlp
, mlp
->fdesc
, format
, 0);
102 printf("\nkdbg-words definitions\n");
103 printf("previous\n\n");
104 printf("\\ end %s section\n\n", np
->name
);
108 forth_do_enum(struct tdesc
*tdp
, struct node
*np
)
114 for (elp
= tdp
->data
.emem
; elp
!= NULL
; elp
= elp
->next
) {
115 printf("here ,\" %s\" %x\n", elp
->name
, elp
->number
);
118 printf("%x c-enum .%s\n", nelem
, np
->name
);
122 switch_on_type(struct mlist
*mlp
, struct tdesc
*tdp
, char *format
, int level
)
126 print_intrinsic(mlp
, tdp
, format
, level
);
129 print_pointer(mlp
, tdp
, format
, level
);
132 print_array(mlp
, tdp
, format
, level
);
135 print_function(mlp
, tdp
, format
, level
);
138 print_union(mlp
, tdp
, format
, level
);
141 print_enum(mlp
, tdp
, format
, level
);
144 print_forward(mlp
, tdp
, format
, level
);
147 print_typeof(mlp
, tdp
, format
, level
);
150 print_struct(mlp
, tdp
, format
, level
);
153 print_volatile(mlp
, tdp
, format
, level
);
156 fprintf(stderr
, "Switch to Unknown type\n");
163 print_forward(struct mlist
*mlp
, struct tdesc
*tdp
, char *format
, int level
)
165 fprintf(stderr
, "%s never defined\n", mlp
->name
);
170 print_typeof(struct mlist
*mlp
, struct tdesc
*tdp
, char *format
, int level
)
172 switch_on_type(mlp
, tdp
->data
.tdesc
, format
, level
);
176 print_volatile(struct mlist
*mlp
, struct tdesc
*tdp
, char *format
, int level
)
178 switch_on_type(mlp
, tdp
->data
.tdesc
, format
, level
);
182 print_intrinsic(struct mlist
*mlp
, struct tdesc
*tdp
, char *format
, int level
)
184 format
= convert_format(format
, ".x");
189 printf("' c@ ' %s", format
);
192 printf("' w@ ' %s", format
);
195 printf("' l@ ' %s", format
);
198 printf("' x@ ' %s", format
);
202 * Check for bit field.
204 } else if (mlp
->size
!= 0 &&
205 ((mlp
->size
% 8) != 0 || (mlp
->offset
% mlp
->size
) != 0)) {
206 int offset
, shift
, mask
;
208 offset
= (mlp
->offset
/ 32) * 4;
209 shift
= 32 - ((mlp
->offset
% 32) + mlp
->size
);
210 mask
= ((int)pow(2, mlp
->size
) - 1) << shift
;
211 printf("' %s %x %x %x bits-field %s\n",
212 format
, shift
, mask
, offset
, mlp
->name
);
213 } else if (mlp
->name
!= NULL
) {
216 printf("' %s %x byte-field %s\n",
217 format
, mlp
->offset
/ 8, mlp
->name
);
220 printf("' %s %x short-field %s\n",
221 format
, mlp
->offset
/ 8, mlp
->name
);
224 printf("' %s %x long-field %s\n",
225 format
, mlp
->offset
/ 8, mlp
->name
);
228 printf("' %s %x ext-field %s\n",
229 format
, mlp
->offset
/ 8, mlp
->name
);
236 print_pointer(struct mlist
*mlp
, struct tdesc
*tdp
, char *format
, int level
)
238 format
= convert_format(format
, ".x");
242 printf("' c@ ' %s", format
);
245 printf("' w@ ' %s", format
);
248 printf("' l@ ' %s", format
);
251 printf("' x@ ' %s", format
);
255 printf("' %s %x ptr-field %s\n",
256 format
, mlp
->offset
/ 8, mlp
->name
);
261 print_array(struct mlist
*mlp
, struct tdesc
*tdp
, char *format
, int level
)
263 struct ardef
*ap
= tdp
->data
.ardef
;
264 int items
, inc
, limit
;
267 printf("' noop ' .x");
269 items
= ap
->indices
->range_end
- ap
->indices
->range_start
+ 1;
270 inc
= (mlp
->size
/ items
) / 8;
271 limit
= mlp
->size
/ 8;
272 switch_on_type(mlp
, ap
->contents
, format
, level
+ 1);
273 printf(" %x %x %x array-field", limit
, inc
, mlp
->offset
/ 8);
274 printf(" %s\n", mlp
->name
);
279 print_function(struct mlist
*mlp
, struct tdesc
*tdp
, char *format
, int level
)
281 fprintf(stderr
, "function in struct %s\n", tdp
->name
);
286 print_struct(struct mlist
*mlp
, struct tdesc
*tdp
, char *format
, int level
)
288 format
= convert_format(format
, ".x");
290 printf("' noop ' %s", format
);
292 printf("' %s %x struct-field %s\n",
293 format
, mlp
->offset
/ 8, mlp
->name
);
298 print_union(struct mlist
*mlp
, struct tdesc
*tdp
, char *format
, int level
)
300 format
= convert_format(format
, ".x");
302 printf("' noop ' %s", format
);
304 printf("' %s %x struct-field %s\n",
305 format
, mlp
->offset
/ 8, mlp
->name
);
310 print_enum(struct mlist
*mlp
, struct tdesc
*tdp
, char *format
, int level
)
312 format
= convert_format(format
, ".d");
315 printf("' l@ ' %s", format
);
317 printf("' %s %x long-field %s\n",
318 format
, mlp
->offset
/ 8, mlp
->name
);