*/
+#include <ctype.h>
#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include "libiberty.h"
#define MAX_NR_STUFF 42
typedef struct
{
- char *defs;
- char *refs;
- char *name;
- char *code;
- char *stuff[MAX_NR_STUFF];
+ const char *defs;
+ const char *refs;
+ const char *name;
+ const char *code;
+ const char * const stuff[MAX_NR_STUFF];
int index;
} op;
-op tab[] =
+static op tab[] =
{
{ "n", "", "add #<imm>,<REG_N>", "0111nnnni8*1....",
},
{ "", "nm", "dmuls.l <REG_M>,<REG_N>", "0011nnnnmmmm1101",
- "dmul (1/*signed*/, R[n], R[m]);",
+ "dmul_s (R[n], R[m]);",
},
{ "", "nm", "dmulu.l <REG_M>,<REG_N>", "0011nnnnmmmm0101",
- "dmul (0/*unsigned*/, R[n], R[m]);",
+ "dmul_u (R[n], R[m]);",
},
{ "n", "n", "dt <REG_N>", "0100nnnn00010000",
/* sh2e */
{ "", "", "fabs <FREG_N>", "1111nnnn01011101",
- "FP_UNARY (n, fabs);",
- "/* FIXME: FR (n) &= 0x7fffffff; */",
+ " union",
+ " {",
+ " unsigned int i;",
+ " float f;",
+ " } u;",
+ " u.f = FR (n);",
+ " u.i &= 0x7fffffff;",
+ " SET_FR (n, u.f);",
},
/* sh2e */
/* sh2e */
{ "", "", "fneg <FREG_N>", "1111nnnn01001101",
- "FP_UNARY (n, -);",
+ " union",
+ " {",
+ " unsigned int i;",
+ " float f;",
+ " } u;",
+ " u.f = FR (n);",
+ " u.i ^= 0x80000000;",
+ " SET_FR (n, u.f);",
},
/* sh4a */
"WBAT (R[n] + R0, R[m]);",
},
{ "n", "nm", "mov.b <REG_M>,@-<REG_N>", "0010nnnnmmmm0100",
+ /* Allow for the case where m == n. */
+ "int t = R[m];",
"MA (1);",
"R[n] -= 1;",
- "WBAT (R[n], R[m]);",
+ "WBAT (R[n], t);",
},
{ "n", "n0", "mov.b R0,@<REG_N>+", "0100nnnn10001011",
"MA (1);",
"L (0);",
},
{ "n", "", "mov.l @(<disp>,PC),<REG_N>", "1101nnnni8p4....",
+ "RAISE_EXCEPTION_IF_IN_DELAY_SLOT ();",
"MA (1);",
"R[n] = RLAT ((PH2T (PC) & ~3) + 4 + i);",
"L (n);",
"WLAT (R0 + R[n], R[m]);",
},
{ "n", "nm", "mov.l <REG_M>,@-<REG_N>", "0010nnnnmmmm0110",
+ /* Allow for the case where m == n. */
+ "int t = R[m];",
"MA (1) ;",
"R[n] -= 4;",
- "WLAT (R[n], R[m]);",
+ "WLAT (R[n], t);",
},
{ "n", "n0", "mov.l R0,@<REG_N>+", "0100nnnn10101011",
"MA (1) ;",
"L (0);",
},
{ "n", "", "mov.w @(<disp>,PC),<REG_N>", "1001nnnni8p2....",
+ "RAISE_EXCEPTION_IF_IN_DELAY_SLOT ();",
"MA (1);",
"R[n] = RSWAT (PH2T (PC + 4 + i));",
"L (n);",
"WWAT (R0 + R[n], R[m]);",
},
{ "n", "mn", "mov.w <REG_M>,@-<REG_N>", "0010nnnnmmmm0101",
+ /* Allow for the case where m == n. */
+ "int t = R[m];",
"MA (1);",
"R[n] -= 2;",
- "WWAT (R[n], R[m]);",
+ "WWAT (R[n], t);",
},
{ "n", "0n", "mov.w R0,@<REG_N>+", "0100nnnn10011011",
"MA (1);",
},
{ "0", "", "mova @(<disp>,PC),R0", "11000111i8p4....",
+ "RAISE_EXCEPTION_IF_IN_DELAY_SLOT ();",
"R0 = ((i + 4 + PH2T (PC)) & ~0x3);",
},
},
{ "", "", "sleep", "0000000000011011",
- "nip += trap (0xc3, &R0, PC, memory, maskl, maskw, endianw);",
+ "nip += trap (sd, 0xc3, &R0, PC, memory, maskl, maskw, endianw);",
},
{ "n", "", "stc <CREG_M>,<REG_N>", "0000nnnnmmmm0010",
"long imm = 0xff & i;",
"RAISE_EXCEPTION_IF_IN_DELAY_SLOT ();",
"if (i < 20 || i == 33 || i == 34 || i == 0xc3)",
- " nip += trap (i, &R0, PC, memory, maskl, maskw, endianw);",
+ " nip += trap (sd, i, &R0, PC, memory, maskl, maskw, endianw);",
#if 0
"else {",
/* SH-[12] */
};
/* Tables of things to put into enums for sh-opc.h */
-static char *nibble_type_list[] =
+static
+const char * const nibble_type_list[] =
{
"HEX_0",
"HEX_1",
0
};
static
-char *arg_type_list[] =
+const char * const arg_type_list[] =
{
"A_END",
"A_BDISP12",
0,
};
-static void
-make_enum_list (name, s)
- char *name;
- char **s;
-{
- int i = 1;
- printf ("typedef enum {\n");
- while (*s)
- {
- printf ("\t%s,\n", *s);
- s++;
- i++;
- }
- printf ("} %s;\n", name);
-}
-
static int
-qfunc (a, b)
- op *a;
- op *b;
+qfunc (const void *va, const void *vb)
{
+ const op *a = va;
+ const op *b = vb;
char bufa[9];
char bufb[9];
int diff;
}
static void
-sorttab ()
+sorttab (void)
{
op *p = tab;
int len = 0;
}
static void
-gengastab ()
+gengastab (void)
{
op *p;
sorttab ();
static int warn_conflicts = 0;
static void
-conflict_warn (val, i)
- int val;
- int i;
+conflict_warn (int val, int i)
{
int ix, key;
int j = table[val];
fprintf (stderr, "Warning: opcode table conflict: 0x%04x (idx %d && %d)\n",
val, i, table[val]);
- for (ix = sizeof (tab) / sizeof (tab[0]); ix >= 0; ix--)
+ for (ix = ARRAY_SIZE (tab); ix >= 0; ix--)
if (tab[ix].index == i || tab[ix].index == j)
{
key = ((tab[ix].code[0] - '0') << 3) +
fprintf (stderr, " %s -- %s\n", tab[ix].code, tab[ix].name);
}
- for (ix = sizeof (movsxy_tab) / sizeof (movsxy_tab[0]); ix >= 0; ix--)
+ for (ix = ARRAY_SIZE (movsxy_tab); ix >= 0; ix--)
if (movsxy_tab[ix].index == i || movsxy_tab[ix].index == j)
{
key = ((movsxy_tab[ix].code[0] - '0') << 3) +
movsxy_tab[ix].code, movsxy_tab[ix].name);
}
- for (ix = sizeof (ppi_tab) / sizeof (ppi_tab[0]); ix >= 0; ix--)
+ for (ix = ARRAY_SIZE (ppi_tab); ix >= 0; ix--)
if (ppi_tab[ix].index == i || ppi_tab[ix].index == j)
{
key = ((ppi_tab[ix].code[0] - '0') << 3) +
right entries in 'table' with the opcode index. */
static void
-expand_opcode (val, i, s)
- int val;
- int i;
- char *s;
+expand_opcode (int val, int i, const char *s)
{
if (*s == 0)
{
statement entry. */
static void
-dumptable (name, size, start)
- char *name;
- int size;
- int start;
+dumptable (const char *name, int size, int start)
{
int lump = 256;
int online = 16;
static void
-filltable (p)
- op *p;
+filltable (op *p)
{
static int index = 1;
processing insns (ppi) for code 0xf800 (ppi nopx nopy). Copy the
latter tag to represent all combinations of ppi with ddt. */
static void
-expand_ppi_movxy ()
+expand_ppi_movxy (void)
{
int i;
}
static void
-gensim_caselist (p)
- op *p;
+gensim_caselist (op *p)
{
for (; p->name; p++)
{
int sextbit = -1;
int needm = 0;
int needn = 0;
-
- char *s = p->code;
+ const char *s = p->code;
printf (" /* %s %s */\n", p->name, p->code);
printf (" case %d: \n", p->index);
{
/* Do the refs. */
- char *r;
+ const char *r;
for (r = p->refs; *r; r++)
{
if (*r == 'f') printf (" CREF (15);\n");
{
/* Do the defs. */
- char *r;
+ const char *r;
for (r = p->defs; *r; r++)
{
if (*r == 'f') printf (" CDEF (15);\n");
}
static void
-gensim ()
+gensim (void)
{
printf ("{\n");
printf ("/* REG_xy = [r4, r5, r0, r1]. */\n");
}
static void
-gendefines ()
+gendefines (void)
{
op *p;
filltable (tab);
for (p = tab; p->name; p++)
{
- char *s = p->name;
+ const char *s = p->name;
printf ("#define OPC_");
while (*s) {
- if (isupper (*s))
- *s = tolower (*s);
if (isalpha (*s))
- printf ("%c", *s);
+ printf ("%c", tolower (*s));
if (*s == ' ')
printf ("_");
if (*s == '@')
NOTE: tail recursion optimization removed for simplicity. */
static void
-expand_ppi_code (val, i, s)
- int val;
- int i;
- char *s;
+expand_ppi_code (int val, int i, const char *s)
{
int j;
}
static void
-ppi_filltable ()
+ppi_filltable (void)
{
op *p;
ppi_index = 1;
}
static void
-ppi_gensim ()
+ppi_gensim (void)
{
op *p = ppi_tab;
printf (" (greater_equal = ~(overflow << 3 & res_grd) & DSR_MASK_G)\n");
printf ("\n");
printf ("static void\n");
- printf ("ppi_insn (iword)\n");
- printf (" int iword;\n");
+ printf ("ppi_insn (int iword)\n");
printf ("{\n");
printf (" /* 'ee' = [x0, x1, y0, a1] */\n");
printf (" static char e_tab[] = { 8, 9, 10, 5};\n");
int shift, j;
int cond = 0;
int havedecl = 0;
-
- char *s = p->code;
+ const char *s = p->code;
printf (" /* %s %s */\n", p->name, p->code);
printf (" case %d: \n", p->index);
printf (" DSR |= res_grd >> 7 & 1;\n");
printf (" case 2: /* Zero Value Mode */\n");
printf (" DSR |= DSR >> 6 & 1;\n");
- printf (" case 3: /* Overflow mode\n");
+ printf (" case 3: /* Overflow mode */\n");
printf (" DSR |= overflow >> 4;\n");
printf (" case 4: /* Signed Greater Than Mode */\n");
printf (" DSR |= DSR >> 7 & 1;\n");
- printf (" case 4: /* Signed Greater Than Or Equal Mode */\n");
+ printf (" case 5: /* Signed Greater Than Or Equal Mode */\n");
printf (" DSR |= greater_equal >> 7;\n");
printf (" }\n");
printf (" assign_z:\n");
}
int
-main (ac, av)
- int ac;
- char **av;
+main (int ac, char *av[])
{
/* Verify the table before anything else. */
{
/* Check that the code field contains 16 bits. */
if (strlen (p->code) != 16)
{
- fprintf (stderr, "Code `%s' length wrong (%d) for `%s'\n",
+ fprintf (stderr, "Code `%s' length wrong (%zu) for `%s'\n",
p->code, strlen (p->code), p->name);
abort ();
}