1 /* Simulation code for the CR16 processor.
2 Copyright (C) 2008-2022 Free Software Foundation, Inc.
3 Contributed by M Ranga Swami Reddy <MR.Swami.Reddy@nsc.com>
5 This file is part of GDB, the GNU debugger.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 /* This must come before any other includes. */
28 #include "opcode/cr16.h"
30 static void write_header (void);
31 static void write_opcodes (void);
32 static void write_template (void);
35 main (int argc
, char *argv
[])
37 if ((argc
> 1) && (strcmp (argv
[1],"-h") == 0))
39 else if ((argc
> 1) && (strcmp (argv
[1],"-t") == 0))
52 /* Start searching from end of instruction table. */
53 const inst
*instruction
= &cr16_instruction
[NUMOPCODES
- 1];
55 /* Loop over instruction table until a full match is found. */
56 for ( ; i
< NUMOPCODES
; i
++)
57 printf("void OP_%lX_%X (SIM_DESC, SIM_CPU *);\t\t/* %s */\n",
58 cr16_instruction
[i
].match
, (32 - cr16_instruction
[i
].match_bits
),
59 cr16_instruction
[i
].mnemonic
);
63 /* write_template creates a file all required functions,
64 ready to be filled out. */
69 int i
= 0,j
, k
, flags
;
71 printf ("#include \"defs.h\"\n");
72 printf ("#include \"sim-main.h\"\n");
73 printf ("#include \"simops.h\"\n\n");
75 for ( ; i
< NUMOPCODES
; i
++)
77 if (cr16_instruction
[i
].size
!= 0)
79 printf ("/* %s */\nvoid\nOP_%lX_%X (SIM_DESC sd, SIM_CPU *cpu)\n{\n",
80 cr16_instruction
[i
].mnemonic
, cr16_instruction
[i
].match
,
81 (32 - cr16_instruction
[i
].match_bits
));
87 if (cr16_instruction
[i
].operands
[k
].op_type
== dummy
)
95 printf ("printf(\" %s\\n\");\n",cr16_instruction
[i
].mnemonic
);
98 printf ("printf(\" %s\\t%%x\\n\",OP[0]);\n",cr16_instruction
[i
].mnemonic
);
101 printf ("printf(\" %s\\t%%x,%%x\\n\",OP[0],OP[1]);\n",cr16_instruction
[i
].mnemonic
);
104 printf ("printf(\" %s\\t%%x,%%x,%%x\\n\",OP[0],OP[1],OP[2]);\n",cr16_instruction
[i
].mnemonic
);
107 fprintf (stderr
,"Too many operands: %d\n",j
);
120 check_opcodes( long op
)
124 for (i
=0;i
<curop
;i
++)
125 if (Opcodes
[i
] == op
)
126 fprintf(stderr
,"DUPLICATE OPCODES: %lx\n", op
);
135 /* write out opcode table. */
136 printf ("#include \"defs.h\"\n");
137 printf ("#include \"sim-main.h\"\n");
138 printf ("#include \"simops.h\"\n\n");
139 printf ("struct simops Simops[] = {\n");
141 for (i
= NUMOPCODES
-1; i
>= 0; --i
)
143 if (cr16_instruction
[i
].size
!= 0)
145 printf (" { \"%s\", %u, %d, %ld, %u, \"OP_%lX_%X\", OP_%lX_%X, ",
146 cr16_instruction
[i
].mnemonic
, cr16_instruction
[i
].size
,
147 cr16_instruction
[i
].match_bits
, cr16_instruction
[i
].match
,
148 cr16_instruction
[i
].flags
, ((BIN(cr16_instruction
[i
].match
, cr16_instruction
[i
].match_bits
))>>(cr16_instruction
[i
].match_bits
)),
149 (32 - cr16_instruction
[i
].match_bits
),
150 ((BIN(cr16_instruction
[i
].match
, cr16_instruction
[i
].match_bits
))>>(cr16_instruction
[i
].match_bits
)), (32 - cr16_instruction
[i
].match_bits
));
155 if (cr16_instruction
[i
].operands
[k
].op_type
== dummy
)
165 int optype
= cr16_instruction
[i
].operands
[k
].op_type
;
166 int shift
= cr16_instruction
[i
].operands
[k
].shift
;
172 printf ("%d,%d",optype
, shift
);
181 printf (" { \"NULL\",1,8,0,0,\"OP_0_20\",OP_0_20,0,{{0,0},{0,0},{0,0},{0,0}}},\n};\n");