Report SIGBUS and halt simulation when ld/st detect a misaligned address.
[deliverable/binutils-gdb.git] / sim / d10v / gencode.c
CommitLineData
c906108c
SS
1#include "config.h"
2#include <stdio.h>
3#include <ctype.h>
4#include <limits.h>
5#include "ansidecl.h"
6#include "callback.h"
7#include "opcode/d10v.h"
8
9static void write_header PARAMS ((void));
10static void write_opcodes PARAMS ((void));
11static void write_template PARAMS ((void));
12
13int
14main (argc, argv)
15 int argc;
16 char *argv[];
17{
18 if ((argc > 1) && (strcmp (argv[1],"-h") == 0))
19 write_header();
20 else if ((argc > 1) && (strcmp (argv[1],"-t") == 0))
21 write_template ();
22 else
23 write_opcodes();
24 return 0;
25}
26
27
28static void
29write_header ()
30{
31 struct d10v_opcode *opcode;
32
33 for (opcode = (struct d10v_opcode *)d10v_opcodes; opcode->name; opcode++)
34 if (opcode->format != OPCODE_FAKE)
35 printf("void OP_%X PARAMS ((void));\t\t/* %s */\n",opcode->opcode, opcode->name);
36}
37
38
39/* write_template creates a file all required functions, ready */
40/* to be filled out */
41
42static void
43write_template ()
44{
45 struct d10v_opcode *opcode;
46 int i,j;
47
48 printf ("#include \"d10v_sim.h\"\n");
49 printf ("#include \"simops.h\"\n");
50
51 for (opcode = (struct d10v_opcode *)d10v_opcodes; opcode->name; opcode++)
52 {
53 if (opcode->format != OPCODE_FAKE)
54 {
55 printf("/* %s */\nvoid\nOP_%X ()\n{\n",opcode->name,opcode->opcode);
56
57 /* count operands */
58 j = 0;
59 for (i=0;i<6;i++)
60 {
61 int flags = d10v_operands[opcode->operands[i]].flags;
62 if ((flags & OPERAND_REG) || (flags & OPERAND_NUM) || (flags & OPERAND_ADDR))
63 j++;
64 }
65 switch (j)
66 {
67 case 0:
68 printf ("printf(\" %s\\n\");\n",opcode->name);
69 break;
70 case 1:
71 printf ("printf(\" %s\\t%%x\\n\",OP[0]);\n",opcode->name);
72 break;
73 case 2:
74 printf ("printf(\" %s\\t%%x,%%x\\n\",OP[0],OP[1]);\n",opcode->name);
75 break;
76 case 3:
77 printf ("printf(\" %s\\t%%x,%%x,%%x\\n\",OP[0],OP[1],OP[2]);\n",opcode->name);
78 break;
79 default:
80 fprintf (stderr,"Too many operands: %d\n",j);
81 }
82 printf ("}\n\n");
83 }
84 }
85}
86
87
88long Opcodes[512];
89static int curop=0;
90
91check_opcodes( long op)
92{
93 int i;
94
95 for (i=0;i<curop;i++)
96 if (Opcodes[i] == op)
97 fprintf(stderr,"DUPLICATE OPCODES: %x\n",op);
98}
99
100
101static void
102write_opcodes ()
103{
104 struct d10v_opcode *opcode;
105 int i, j;
106
107 /* write out opcode table */
108 printf ("#include \"d10v_sim.h\"\n");
109 printf ("#include \"simops.h\"\n\n");
110 printf ("struct simops Simops[] = {\n");
111
112 for (opcode = (struct d10v_opcode *)d10v_opcodes; opcode->name; opcode++)
113 {
114 if (opcode->format != OPCODE_FAKE)
115 {
116 printf (" { %ld,%d,%ld,%d,%d,%d,%d,OP_%X,", opcode->opcode,
117 (opcode->format & LONG_OPCODE) ? 1 : 0, opcode->mask, opcode->format,
118 opcode->cycles, opcode->unit, opcode->exec_type, opcode->opcode);
119
120 /* REMOVE ME */
121 check_opcodes (opcode->opcode);
122 Opcodes[curop++] = opcode->opcode;
123
124 j = 0;
125 for (i=0;i<6;i++)
126 {
127 int flags = d10v_operands[opcode->operands[i]].flags;
128 if ((flags & OPERAND_REG) || (flags & OPERAND_NUM) || (flags & OPERAND_ADDR))
129 j++;
130 }
131 printf ("%d,",j);
132
133 j = 0;
134 for (i=0;i<6;i++)
135 {
136 int flags = d10v_operands[opcode->operands[i]].flags;
137 int shift = d10v_operands[opcode->operands[i]].shift;
138 if ((flags & OPERAND_REG) || (flags & OPERAND_NUM)|| (flags & OPERAND_ADDR))
139 {
140 if (j == 0)
141 printf ("{");
142 else
143 printf (", ");
144 if ((flags & OPERAND_REG) && (opcode->format == LONG_L))
145 shift += 15;
146 printf ("%d,%d,%d",shift,d10v_operands[opcode->operands[i]].bits,flags);
147 j = 1;
148 }
149 }
150 if (j)
151 printf ("}");
152 printf ("},\n");
153 }
154 }
155 printf ("{ 0,0,0,0,0,0,0,(void (*)(void))0,0,{0,0,0}},\n};\n");
156}
This page took 0.042422 seconds and 4 git commands to generate.