1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate * CDDL HEADER START
3*0Sstevel@tonic-gate *
4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*0Sstevel@tonic-gate * with the License.
8*0Sstevel@tonic-gate *
9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate * and limitations under the License.
13*0Sstevel@tonic-gate *
14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate *
20*0Sstevel@tonic-gate * CDDL HEADER END
21*0Sstevel@tonic-gate */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate * Copyright 1996-2002 Sun Microsystems, Inc. All rights reserved.
24*0Sstevel@tonic-gate * Use is subject to license terms.
25*0Sstevel@tonic-gate */
26*0Sstevel@tonic-gate
27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
28*0Sstevel@tonic-gate
29*0Sstevel@tonic-gate #include <unistd.h>
30*0Sstevel@tonic-gate #include <math.h>
31*0Sstevel@tonic-gate #include "stabs.h"
32*0Sstevel@tonic-gate
33*0Sstevel@tonic-gate void forth_do_sou(struct tdesc *tdp, struct node *np);
34*0Sstevel@tonic-gate void forth_do_enum(struct tdesc *tdp, struct node *np);
35*0Sstevel@tonic-gate void forth_do_intrinsic(struct tdesc *tdp, struct node *np);
36*0Sstevel@tonic-gate
37*0Sstevel@tonic-gate static void switch_on_type(struct mlist *mlp, struct tdesc *tdp,
38*0Sstevel@tonic-gate char *format, int level);
39*0Sstevel@tonic-gate
40*0Sstevel@tonic-gate static void print_intrinsic(struct mlist *mlp, struct tdesc *tdp,
41*0Sstevel@tonic-gate char *format, int level);
42*0Sstevel@tonic-gate static void print_forward(struct mlist *mlp, struct tdesc *tdp,
43*0Sstevel@tonic-gate char *format, int level);
44*0Sstevel@tonic-gate static void print_pointer(struct mlist *mlp, struct tdesc *tdp,
45*0Sstevel@tonic-gate char *format, int level);
46*0Sstevel@tonic-gate static void print_array(struct mlist *mlp, struct tdesc *tdp,
47*0Sstevel@tonic-gate char *format, int level);
48*0Sstevel@tonic-gate static void print_function(struct mlist *mlp, struct tdesc *tdp,
49*0Sstevel@tonic-gate char *format, int level);
50*0Sstevel@tonic-gate static void print_union(struct mlist *mlp, struct tdesc *tdp,
51*0Sstevel@tonic-gate char *format, int level);
52*0Sstevel@tonic-gate static void print_enum(struct mlist *mlp, struct tdesc *tdp,
53*0Sstevel@tonic-gate char *format, int level);
54*0Sstevel@tonic-gate static void print_forward(struct mlist *mlp, struct tdesc *tdp,
55*0Sstevel@tonic-gate char *format, int level);
56*0Sstevel@tonic-gate static void print_typeof(struct mlist *mlp, struct tdesc *tdp,
57*0Sstevel@tonic-gate char *format, int level);
58*0Sstevel@tonic-gate static void print_struct(struct mlist *mlp, struct tdesc *tdp,
59*0Sstevel@tonic-gate char *format, int level);
60*0Sstevel@tonic-gate static void print_volatile(struct mlist *mlp, struct tdesc *tdp,
61*0Sstevel@tonic-gate char *format, int level);
62*0Sstevel@tonic-gate
63*0Sstevel@tonic-gate void
forth_do_intrinsic(struct tdesc * tdp,struct node * np)64*0Sstevel@tonic-gate forth_do_intrinsic(struct tdesc *tdp, struct node *np)
65*0Sstevel@tonic-gate {
66*0Sstevel@tonic-gate }
67*0Sstevel@tonic-gate
68*0Sstevel@tonic-gate void
forth_do_sou(struct tdesc * tdp,struct node * np)69*0Sstevel@tonic-gate forth_do_sou(struct tdesc *tdp, struct node *np)
70*0Sstevel@tonic-gate {
71*0Sstevel@tonic-gate struct mlist *mlp;
72*0Sstevel@tonic-gate struct child *chp;
73*0Sstevel@tonic-gate char *format;
74*0Sstevel@tonic-gate
75*0Sstevel@tonic-gate printf("\n");
76*0Sstevel@tonic-gate printf("vocabulary %s-words\n", np->name);
77*0Sstevel@tonic-gate printf("h# %x constant %s-sz\n", tdp->size, np->name);
78*0Sstevel@tonic-gate printf("%x ' %s-words c-struct .%s\n",
79*0Sstevel@tonic-gate tdp->size, np->name, np->name);
80*0Sstevel@tonic-gate printf("also %s-words definitions\n\n", np->name);
81*0Sstevel@tonic-gate
82*0Sstevel@tonic-gate /*
83*0Sstevel@tonic-gate * Run thru all the fields of a struct and print them out
84*0Sstevel@tonic-gate */
85*0Sstevel@tonic-gate for (mlp = tdp->data.members.back; mlp != NULL; mlp = mlp->prev) {
86*0Sstevel@tonic-gate /*
87*0Sstevel@tonic-gate * If there's a child list, only print those members.
88*0Sstevel@tonic-gate */
89*0Sstevel@tonic-gate if (np->child) {
90*0Sstevel@tonic-gate if (mlp->name == NULL)
91*0Sstevel@tonic-gate continue;
92*0Sstevel@tonic-gate chp = find_child(np, mlp->name);
93*0Sstevel@tonic-gate if (chp == NULL)
94*0Sstevel@tonic-gate continue;
95*0Sstevel@tonic-gate format = chp->format;
96*0Sstevel@tonic-gate } else
97*0Sstevel@tonic-gate format = NULL;
98*0Sstevel@tonic-gate if (mlp->fdesc == NULL)
99*0Sstevel@tonic-gate continue;
100*0Sstevel@tonic-gate switch_on_type(mlp, mlp->fdesc, format, 0);
101*0Sstevel@tonic-gate }
102*0Sstevel@tonic-gate printf("\nkdbg-words definitions\n");
103*0Sstevel@tonic-gate printf("previous\n\n");
104*0Sstevel@tonic-gate printf("\\ end %s section\n\n", np->name);
105*0Sstevel@tonic-gate }
106*0Sstevel@tonic-gate
107*0Sstevel@tonic-gate void
forth_do_enum(struct tdesc * tdp,struct node * np)108*0Sstevel@tonic-gate forth_do_enum(struct tdesc *tdp, struct node *np)
109*0Sstevel@tonic-gate {
110*0Sstevel@tonic-gate int nelem = 0;
111*0Sstevel@tonic-gate struct elist *elp;
112*0Sstevel@tonic-gate
113*0Sstevel@tonic-gate printf("\n");
114*0Sstevel@tonic-gate for (elp = tdp->data.emem; elp != NULL; elp = elp->next) {
115*0Sstevel@tonic-gate printf("here ,\" %s\" %x\n", elp->name, elp->number);
116*0Sstevel@tonic-gate nelem++;
117*0Sstevel@tonic-gate }
118*0Sstevel@tonic-gate printf("%x c-enum .%s\n", nelem, np->name);
119*0Sstevel@tonic-gate }
120*0Sstevel@tonic-gate
121*0Sstevel@tonic-gate static void
switch_on_type(struct mlist * mlp,struct tdesc * tdp,char * format,int level)122*0Sstevel@tonic-gate switch_on_type(struct mlist *mlp, struct tdesc *tdp, char *format, int level)
123*0Sstevel@tonic-gate {
124*0Sstevel@tonic-gate switch (tdp->type) {
125*0Sstevel@tonic-gate case INTRINSIC:
126*0Sstevel@tonic-gate print_intrinsic(mlp, tdp, format, level);
127*0Sstevel@tonic-gate break;
128*0Sstevel@tonic-gate case POINTER:
129*0Sstevel@tonic-gate print_pointer(mlp, tdp, format, level);
130*0Sstevel@tonic-gate break;
131*0Sstevel@tonic-gate case ARRAY:
132*0Sstevel@tonic-gate print_array(mlp, tdp, format, level);
133*0Sstevel@tonic-gate break;
134*0Sstevel@tonic-gate case FUNCTION:
135*0Sstevel@tonic-gate print_function(mlp, tdp, format, level);
136*0Sstevel@tonic-gate break;
137*0Sstevel@tonic-gate case UNION:
138*0Sstevel@tonic-gate print_union(mlp, tdp, format, level);
139*0Sstevel@tonic-gate break;
140*0Sstevel@tonic-gate case ENUM:
141*0Sstevel@tonic-gate print_enum(mlp, tdp, format, level);
142*0Sstevel@tonic-gate break;
143*0Sstevel@tonic-gate case FORWARD:
144*0Sstevel@tonic-gate print_forward(mlp, tdp, format, level);
145*0Sstevel@tonic-gate break;
146*0Sstevel@tonic-gate case TYPEOF:
147*0Sstevel@tonic-gate print_typeof(mlp, tdp, format, level);
148*0Sstevel@tonic-gate break;
149*0Sstevel@tonic-gate case STRUCT:
150*0Sstevel@tonic-gate print_struct(mlp, tdp, format, level);
151*0Sstevel@tonic-gate break;
152*0Sstevel@tonic-gate case VOLATILE:
153*0Sstevel@tonic-gate print_volatile(mlp, tdp, format, level);
154*0Sstevel@tonic-gate break;
155*0Sstevel@tonic-gate default:
156*0Sstevel@tonic-gate fprintf(stderr, "Switch to Unknown type\n");
157*0Sstevel@tonic-gate error = B_TRUE;
158*0Sstevel@tonic-gate break;
159*0Sstevel@tonic-gate }
160*0Sstevel@tonic-gate }
161*0Sstevel@tonic-gate
162*0Sstevel@tonic-gate static void
print_forward(struct mlist * mlp,struct tdesc * tdp,char * format,int level)163*0Sstevel@tonic-gate print_forward(struct mlist *mlp, struct tdesc *tdp, char *format, int level)
164*0Sstevel@tonic-gate {
165*0Sstevel@tonic-gate fprintf(stderr, "%s never defined\n", mlp->name);
166*0Sstevel@tonic-gate error = B_TRUE;
167*0Sstevel@tonic-gate }
168*0Sstevel@tonic-gate
169*0Sstevel@tonic-gate static void
print_typeof(struct mlist * mlp,struct tdesc * tdp,char * format,int level)170*0Sstevel@tonic-gate print_typeof(struct mlist *mlp, struct tdesc *tdp, char *format, int level)
171*0Sstevel@tonic-gate {
172*0Sstevel@tonic-gate switch_on_type(mlp, tdp->data.tdesc, format, level);
173*0Sstevel@tonic-gate }
174*0Sstevel@tonic-gate
175*0Sstevel@tonic-gate static void
print_volatile(struct mlist * mlp,struct tdesc * tdp,char * format,int level)176*0Sstevel@tonic-gate print_volatile(struct mlist *mlp, struct tdesc *tdp, char *format, int level)
177*0Sstevel@tonic-gate {
178*0Sstevel@tonic-gate switch_on_type(mlp, tdp->data.tdesc, format, level);
179*0Sstevel@tonic-gate }
180*0Sstevel@tonic-gate
181*0Sstevel@tonic-gate static void
print_intrinsic(struct mlist * mlp,struct tdesc * tdp,char * format,int level)182*0Sstevel@tonic-gate print_intrinsic(struct mlist *mlp, struct tdesc *tdp, char *format, int level)
183*0Sstevel@tonic-gate {
184*0Sstevel@tonic-gate format = convert_format(format, ".x");
185*0Sstevel@tonic-gate
186*0Sstevel@tonic-gate if (level != 0) {
187*0Sstevel@tonic-gate switch (tdp->size) {
188*0Sstevel@tonic-gate case 1:
189*0Sstevel@tonic-gate printf("' c@ ' %s", format);
190*0Sstevel@tonic-gate break;
191*0Sstevel@tonic-gate case 2:
192*0Sstevel@tonic-gate printf("' w@ ' %s", format);
193*0Sstevel@tonic-gate break;
194*0Sstevel@tonic-gate case 4:
195*0Sstevel@tonic-gate printf("' l@ ' %s", format);
196*0Sstevel@tonic-gate break;
197*0Sstevel@tonic-gate case 8:
198*0Sstevel@tonic-gate printf("' x@ ' %s", format);
199*0Sstevel@tonic-gate break;
200*0Sstevel@tonic-gate }
201*0Sstevel@tonic-gate /*
202*0Sstevel@tonic-gate * Check for bit field.
203*0Sstevel@tonic-gate */
204*0Sstevel@tonic-gate } else if (mlp->size != 0 &&
205*0Sstevel@tonic-gate ((mlp->size % 8) != 0 || (mlp->offset % mlp->size) != 0)) {
206*0Sstevel@tonic-gate int offset, shift, mask;
207*0Sstevel@tonic-gate
208*0Sstevel@tonic-gate offset = (mlp->offset / 32) * 4;
209*0Sstevel@tonic-gate shift = 32 - ((mlp->offset % 32) + mlp->size);
210*0Sstevel@tonic-gate mask = ((int)pow(2, mlp->size) - 1) << shift;
211*0Sstevel@tonic-gate printf("' %s %x %x %x bits-field %s\n",
212*0Sstevel@tonic-gate format, shift, mask, offset, mlp->name);
213*0Sstevel@tonic-gate } else if (mlp->name != NULL) {
214*0Sstevel@tonic-gate switch (tdp->size) {
215*0Sstevel@tonic-gate case 1:
216*0Sstevel@tonic-gate printf("' %s %x byte-field %s\n",
217*0Sstevel@tonic-gate format, mlp->offset / 8, mlp->name);
218*0Sstevel@tonic-gate break;
219*0Sstevel@tonic-gate case 2:
220*0Sstevel@tonic-gate printf("' %s %x short-field %s\n",
221*0Sstevel@tonic-gate format, mlp->offset / 8, mlp->name);
222*0Sstevel@tonic-gate break;
223*0Sstevel@tonic-gate case 4:
224*0Sstevel@tonic-gate printf("' %s %x long-field %s\n",
225*0Sstevel@tonic-gate format, mlp->offset / 8, mlp->name);
226*0Sstevel@tonic-gate break;
227*0Sstevel@tonic-gate case 8:
228*0Sstevel@tonic-gate printf("' %s %x ext-field %s\n",
229*0Sstevel@tonic-gate format, mlp->offset / 8, mlp->name);
230*0Sstevel@tonic-gate break;
231*0Sstevel@tonic-gate }
232*0Sstevel@tonic-gate }
233*0Sstevel@tonic-gate }
234*0Sstevel@tonic-gate
235*0Sstevel@tonic-gate static void
print_pointer(struct mlist * mlp,struct tdesc * tdp,char * format,int level)236*0Sstevel@tonic-gate print_pointer(struct mlist *mlp, struct tdesc *tdp, char *format, int level)
237*0Sstevel@tonic-gate {
238*0Sstevel@tonic-gate format = convert_format(format, ".x");
239*0Sstevel@tonic-gate if (level != 0) {
240*0Sstevel@tonic-gate switch (tdp->size) {
241*0Sstevel@tonic-gate case 1:
242*0Sstevel@tonic-gate printf("' c@ ' %s", format);
243*0Sstevel@tonic-gate break;
244*0Sstevel@tonic-gate case 2:
245*0Sstevel@tonic-gate printf("' w@ ' %s", format);
246*0Sstevel@tonic-gate break;
247*0Sstevel@tonic-gate case 4:
248*0Sstevel@tonic-gate printf("' l@ ' %s", format);
249*0Sstevel@tonic-gate break;
250*0Sstevel@tonic-gate case 8:
251*0Sstevel@tonic-gate printf("' x@ ' %s", format);
252*0Sstevel@tonic-gate break;
253*0Sstevel@tonic-gate }
254*0Sstevel@tonic-gate } else {
255*0Sstevel@tonic-gate printf("' %s %x ptr-field %s\n",
256*0Sstevel@tonic-gate format, mlp->offset / 8, mlp->name);
257*0Sstevel@tonic-gate }
258*0Sstevel@tonic-gate }
259*0Sstevel@tonic-gate
260*0Sstevel@tonic-gate static void
print_array(struct mlist * mlp,struct tdesc * tdp,char * format,int level)261*0Sstevel@tonic-gate print_array(struct mlist *mlp, struct tdesc *tdp, char *format, int level)
262*0Sstevel@tonic-gate {
263*0Sstevel@tonic-gate struct ardef *ap = tdp->data.ardef;
264*0Sstevel@tonic-gate int items, inc, limit;
265*0Sstevel@tonic-gate
266*0Sstevel@tonic-gate if (level > 0) {
267*0Sstevel@tonic-gate printf("' noop ' .x");
268*0Sstevel@tonic-gate } else {
269*0Sstevel@tonic-gate items = ap->indices->range_end - ap->indices->range_start + 1;
270*0Sstevel@tonic-gate inc = (mlp->size / items) / 8;
271*0Sstevel@tonic-gate limit = mlp->size / 8;
272*0Sstevel@tonic-gate switch_on_type(mlp, ap->contents, format, level + 1);
273*0Sstevel@tonic-gate printf(" %x %x %x array-field", limit, inc, mlp->offset / 8);
274*0Sstevel@tonic-gate printf(" %s\n", mlp->name);
275*0Sstevel@tonic-gate }
276*0Sstevel@tonic-gate }
277*0Sstevel@tonic-gate
278*0Sstevel@tonic-gate static void
print_function(struct mlist * mlp,struct tdesc * tdp,char * format,int level)279*0Sstevel@tonic-gate print_function(struct mlist *mlp, struct tdesc *tdp, char *format, int level)
280*0Sstevel@tonic-gate {
281*0Sstevel@tonic-gate fprintf(stderr, "function in struct %s\n", tdp->name);
282*0Sstevel@tonic-gate error = B_TRUE;
283*0Sstevel@tonic-gate }
284*0Sstevel@tonic-gate
285*0Sstevel@tonic-gate static void
print_struct(struct mlist * mlp,struct tdesc * tdp,char * format,int level)286*0Sstevel@tonic-gate print_struct(struct mlist *mlp, struct tdesc *tdp, char *format, int level)
287*0Sstevel@tonic-gate {
288*0Sstevel@tonic-gate format = convert_format(format, ".x");
289*0Sstevel@tonic-gate if (level != 0)
290*0Sstevel@tonic-gate printf("' noop ' %s", format);
291*0Sstevel@tonic-gate else {
292*0Sstevel@tonic-gate printf("' %s %x struct-field %s\n",
293*0Sstevel@tonic-gate format, mlp->offset / 8, mlp->name);
294*0Sstevel@tonic-gate }
295*0Sstevel@tonic-gate }
296*0Sstevel@tonic-gate
297*0Sstevel@tonic-gate static void
print_union(struct mlist * mlp,struct tdesc * tdp,char * format,int level)298*0Sstevel@tonic-gate print_union(struct mlist *mlp, struct tdesc *tdp, char *format, int level)
299*0Sstevel@tonic-gate {
300*0Sstevel@tonic-gate format = convert_format(format, ".x");
301*0Sstevel@tonic-gate if (level != 0)
302*0Sstevel@tonic-gate printf("' noop ' %s", format);
303*0Sstevel@tonic-gate else {
304*0Sstevel@tonic-gate printf("' %s %x struct-field %s\n",
305*0Sstevel@tonic-gate format, mlp->offset / 8, mlp->name);
306*0Sstevel@tonic-gate }
307*0Sstevel@tonic-gate }
308*0Sstevel@tonic-gate
309*0Sstevel@tonic-gate static void
print_enum(struct mlist * mlp,struct tdesc * tdp,char * format,int level)310*0Sstevel@tonic-gate print_enum(struct mlist *mlp, struct tdesc *tdp, char *format, int level)
311*0Sstevel@tonic-gate {
312*0Sstevel@tonic-gate format = convert_format(format, ".d");
313*0Sstevel@tonic-gate
314*0Sstevel@tonic-gate if (level != 0)
315*0Sstevel@tonic-gate printf("' l@ ' %s", format);
316*0Sstevel@tonic-gate else
317*0Sstevel@tonic-gate printf("' %s %x long-field %s\n",
318*0Sstevel@tonic-gate format, mlp->offset / 8, mlp->name);
319*0Sstevel@tonic-gate }
320