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 2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
33 void genassym_do_sou(struct tdesc
*tdp
, struct node
*np
);
34 void genassym_do_enum(struct tdesc
*tdp
, struct node
*np
);
35 void genassym_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
);
62 static int stabs_log2(unsigned int value
);
65 genassym_do_intrinsic(struct tdesc
*tdp
, struct node
*np
)
67 if (np
->format
!= NULL
) {
68 char *upper
= uc(np
->format
);
70 printf("#define\t%s 0x%x\n", upper
, tdp
->size
);
78 genassym_do_sou(struct tdesc
*tdp
, struct node
*np
)
84 if (np
->format
!= NULL
) {
85 char *upper
= uc(np
->format
);
88 printf("#define\t%s 0x%x\n", upper
, tdp
->size
);
90 if ((np
->format2
!= NULL
) &&
91 (l
= stabs_log2(tdp
->size
)) != -1) {
92 printf("#define\t%s 0x%x\n", np
->format2
, l
);
99 * Run thru all the fields of a struct and print them out
101 for (mlp
= tdp
->data
.members
.forw
; mlp
!= NULL
; mlp
= mlp
->next
) {
103 * If there's a child list, only print those members.
105 if (np
->child
!= NULL
) {
106 if (mlp
->name
== NULL
)
108 chp
= find_child(np
, mlp
->name
);
111 format
= uc(chp
->format
);
115 if (mlp
->fdesc
== NULL
)
117 switch_on_type(mlp
, mlp
->fdesc
, format
, 0);
124 genassym_do_enum(struct tdesc
*tdp
, struct node
*np
)
130 for (elp
= tdp
->data
.emem
; elp
!= NULL
; elp
= elp
->next
) {
131 printf("#define\tENUM_%s 0x%x\n", elp
->name
, elp
->number
);
134 printf("%x c-enum .%s\n", nelem
, np
->name
);
138 switch_on_type(struct mlist
*mlp
, struct tdesc
*tdp
, char *format
, int level
)
140 boolean_t allocated
= B_FALSE
;
142 if (format
== NULL
) {
144 format
= uc(mlp
->name
);
149 print_intrinsic(mlp
, tdp
, format
, level
);
152 print_pointer(mlp
, tdp
, format
, level
);
155 print_array(mlp
, tdp
, format
, level
);
158 print_function(mlp
, tdp
, format
, level
);
161 print_union(mlp
, tdp
, format
, level
);
164 print_enum(mlp
, tdp
, format
, level
);
167 print_forward(mlp
, tdp
, format
, level
);
170 print_typeof(mlp
, tdp
, format
, level
);
173 print_struct(mlp
, tdp
, format
, level
);
176 print_volatile(mlp
, tdp
, format
, level
);
179 fprintf(stderr
, "Switch to Unknown type\n");
189 print_forward(struct mlist
*mlp
, struct tdesc
*tdp
, char *format
, int level
)
191 fprintf(stderr
, "%s never defined\n", mlp
->name
);
196 print_typeof(struct mlist
*mlp
, struct tdesc
*tdp
, char *format
, int level
)
198 switch_on_type(mlp
, tdp
->data
.tdesc
, format
, level
);
202 print_volatile(struct mlist
*mlp
, struct tdesc
*tdp
, char *format
, int level
)
204 switch_on_type(mlp
, tdp
->data
.tdesc
, format
, level
);
208 print_intrinsic(struct mlist
*mlp
, struct tdesc
*tdp
,
209 char *format
, int level
)
214 printf("/* ' c@ ' %s */", format
);
217 printf("/* ' w@ ' %s */", format
);
220 printf("/* ' l@ ' %s */", format
);
223 printf("/* ' x@ ' %s */", format
);
227 * Check for bit field.
229 } else if (mlp
->size
!= 0 &&
230 ((mlp
->size
% 8) != 0 || (mlp
->offset
% mlp
->size
) != 0)) {
231 int offset
, shift
, mask
;
233 offset
= (mlp
->offset
/ 32) * 4;
234 shift
= 32 - ((mlp
->offset
% 32) + mlp
->size
);
235 mask
= ((int)pow(2, mlp
->size
) - 1) << shift
;
237 printf("#define\t%s_SHIFT 0x%x\n", format
, shift
);
238 printf("#define\t%s_MASK 0x%x\n", format
, mask
);
239 printf("#define\t%s_OFFSET 0x%x\n", format
, offset
);
240 } else if (mlp
->name
!= NULL
) {
241 printf("#define\t%s 0x%x\n", format
, mlp
->offset
/ 8);
246 print_pointer(struct mlist
*mlp
, struct tdesc
*tdp
, char *format
, int level
)
251 printf("/* ' c@ ' %s */", format
);
254 printf("/* ' w@ ' %s */", format
);
257 printf("/* ' l@ ' %s */", format
);
260 printf("/* ' x@ ' %s */", format
);
264 printf("#define\t%s 0x%x\n", format
, mlp
->offset
/ 8);
269 print_array(struct mlist
*mlp
, struct tdesc
*tdp
, char *format
, int level
)
271 struct ardef
*ap
= tdp
->data
.ardef
;
275 items
= ap
->indices
->range_end
- ap
->indices
->range_start
+ 1;
276 inc
= (mlp
->size
/ items
) / 8;
277 printf("#define\t%s 0x%x\n", format
, mlp
->offset
/ 8);
278 printf("#define\t%s_INCR 0x%x\n", format
, inc
);
283 print_function(struct mlist
*mlp
, struct tdesc
*tdp
, char *format
, int level
)
285 fprintf(stderr
, "function in struct %s\n", tdp
->name
);
290 print_struct(struct mlist
*mlp
, struct tdesc
*tdp
, char *format
, int level
)
293 printf("/* ' noop ' %s */", format
);
295 printf("#define\t%s 0x%x\n", format
, mlp
->offset
/ 8);
299 print_union(struct mlist
*mlp
, struct tdesc
*tdp
, char *format
, int level
)
302 printf("/* ' noop ' %s */", format
);
304 printf("#define\t%s 0x%x\n", format
, mlp
->offset
/ 8);
308 print_enum(struct mlist
*mlp
, struct tdesc
*tdp
, char *format
, int level
)
311 printf("/* ' l@ ' %s */", format
);
313 printf("#define\t%s 0x%x\n", format
, mlp
->offset
/ 8);
317 stabs_log2(unsigned int value
)
322 for (i
= 0; i
< sizeof (value
) * 8; i
++) {
323 if ((log
<< i
) == value
)