1 /* Copyright (C) 2001-2014 Free Software Foundation, Inc.
2 Written by Steve Chamberlain of Cygnus Support (steve@cygnus.com).
4 This file is part of GNU binutils.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
25 static char writecode;
29 static char *oldrepeat;
32 static char *names[] = {" ","[n]","[n][m]"};
33 static char *pnames[]= {"","*","**"};
35 static int yyerror (char *s);
36 extern int yylex (void);
49 %token <i> NUMBER UNIT
51 %type <s> attr_desc attr_id attr_type
58 printf("#ifdef SYSROFF_SWAP_IN\n");
61 printf("#ifdef SYSROFF_p\n");
66 printf("#ifdef SYSROFF_SWAP_OUT\n");
69 printf("#ifdef SYSROFF_PRINT\n");
70 printf("#include <stdio.h>\n");
71 printf("#include <stdlib.h>\n");
72 printf("#include <ansidecl.h>\n");
103 printf("\n\n\n#define IT_%s_CODE 0x%x\n", it,code);
104 printf("struct IT_%s;\n", it);
105 printf("extern void sysroff_swap_%s_in (struct IT_%s *);\n",
107 printf("extern void sysroff_swap_%s_out (FILE *, struct IT_%s *);\n",
109 printf("extern void sysroff_print_%s_out (struct IT_%s *);\n",
111 printf("struct IT_%s { \n", it);
114 printf("void sysroff_swap_%s_in (struct IT_%s * ptr)\n",$2,it);
116 printf("\tunsigned char raw[255];\n");
117 printf("\tint idx = 0;\n");
118 printf("\tint size;\n");
119 printf("\tmemset(raw,0,255);\n");
120 printf("\tmemset(ptr,0,sizeof(*ptr));\n");
121 printf("\tsize = fillup(raw);\n");
124 printf("void sysroff_swap_%s_out (FILE * ffile, struct IT_%s * ptr)\n",$2,it);
126 printf("\tunsigned char raw[255];\n");
127 printf("\tint idx = 16;\n");
128 printf("\tmemset (raw, 0, 255);\n");
129 printf("\tcode = IT_%s_CODE;\n", it);
132 printf("void sysroff_swap_%s_out (bfd * abfd, struct IT_%s * ptr)\n",$2, it);
134 printf("\tint idx = 0;\n");
137 printf("void sysroff_print_%s_out (struct IT_%s *ptr)\n",$2,it);
139 printf("itheader(\"%s\", IT_%s_CODE);\n",$2,$2);
155 printf("\tchecksum(ffile,raw, idx, IT_%s_CODE);\n", it);
169 it_field it_field_list
170 | cond_it_field it_field_list
171 | repeat_it_field it_field_list
175 repeat_it_field: '(' REPEAT NAME
182 printf("\tprintf(\"repeat %%d\\n\", %s);\n",$3);
184 printf("\tprintf(\"repeat %%d\\n\", %s[n]);\n",$3);
191 printf("\t{ int n; for (n = 0; n < %s; n++) {\n", $3);
194 printf("\t{ int m; for (m = 0; m < %s[n]; m++) {\n", $3);
222 cond_it_field: '(' COND NAME
230 printf("\tif (%s) {\n", $3);
249 '(' attr_desc '(' attr_type attr_size ')' attr_id
257 char *p = names[rdepth];
258 char *ptr = pnames[rdepth];
265 printf("\twriteBITS(ptr->%s%s,raw,&idx,%d);\n",
267 names[rdepth], size);
271 printf("\twrite%s(ptr->%s%s,raw,&idx,%d,ffile);\n",
274 names[rdepth],size/8);
283 printf("if (!ptr->%s) ptr->%s = (%s*)xcalloc(%s, sizeof(ptr->%s[0]));\n",
293 printf("if (!ptr->%s[n]) ptr->%s[n] = (%s**)xcalloc(%s[n], sizeof(ptr->%s[n][0]));\n",
305 printf("\tptr->%s%s = getBITS(raw,&idx, %d,size);\n",
311 printf("\tptr->%s%s = get%s(raw,&idx, %d,size);\n",
319 printf("\tput%s(raw,%d,%d,&idx,ptr->%s%s);\n", type,size/8,size%8,id,names[rdepth]);
323 printf("\t/* repeat %s */\n", repeat);
325 if (type[0] == 'I') {
326 printf("\tint %s%s; \t/* %s */\n",ptr,id, desc);
328 else if (type[0] =='C') {
329 printf("\tchar %s*%s;\t /* %s */\n",ptr,id, desc);
332 printf("\tbarray %s%s;\t /* %s */\n",ptr,id, desc);
336 printf("tabout();\n");
337 printf("\tprintf(\"/*%-30s*/ ptr->%s = \");\n", desc, id);
340 printf("\tprintf(\"%%d\\n\",ptr->%s%s);\n", id,p);
341 else if (type[0] == 'C')
342 printf("\tprintf(\"%%s\\n\",ptr->%s%s);\n", id,p);
344 else if (type[0] == 'B')
346 printf("\tpbarray(&ptr->%s%s);\n", id,p);
373 '(' NAME ')' { $$ = $2; }
378 | '(' enum_list ')' ;
382 enum_list '(' NAME NAME ')' {
386 printf("#define %s %s\n", $3,$4);
389 printf("if (ptr->%s%s == %s) { tabout(); printf(\"%s\\n\");}\n", name, names[rdepth],$4,$3);
400 -d write structure definitions for sysroff in host format
401 -i write functions to swap into sysroff format in
402 -o write functions to swap into sysroff format out
403 -c write code to print info in human form */
408 main (int ac, char **av)
412 writecode = av[1][1];
413 if (writecode == 'd')
415 printf("typedef struct { unsigned char *data; int len; } barray; \n");
416 printf("typedef int INT;\n");
417 printf("typedef char * CHARS;\n");
427 fprintf(stderr, "%s\n" , s);