diff options
Diffstat (limited to 'opcodes/z8kgen.c')
-rw-r--r-- | opcodes/z8kgen.c | 274 |
1 files changed, 130 insertions, 144 deletions
diff --git a/opcodes/z8kgen.c b/opcodes/z8kgen.c index df72791425..9e46809772 100644 --- a/opcodes/z8kgen.c +++ b/opcodes/z8kgen.c @@ -36,7 +36,7 @@ struct op }; #define iswhite(x) ((x) == ' ' || (x) == '\t') -struct op opt[] = +static struct op opt[] = { {"------", 2, 8, "0011 0110 0000 0000", "bpt", 0}, /* Breakpoint used by the simulator. */ {"------", 10, 8, "0000 1111 0000 1100", "brk", 0}, /* Breakpoint used by real hardware. @@ -265,8 +265,8 @@ struct op opt[] = {"------", 7, 8, "0010 0000 ssN0 dddd", "ldb rbd,@rs", 0}, {"------", 9, 8, "0110 0000 0000 dddd address_src", "ldb rbd,address_src", 0}, {"------", 10, 8, "0110 0000 ssN0 dddd address_src", "ldb rbd,address_src(rs)", 0}, - {"------", 7, 8, "0010 0000 0000 dddd imm8 imm8", "ldb rbd,imm8", 0}, {"------", 5, 8, "1100 dddd imm8", "ldb rbd,imm8", 0}, + {"------", 7, 8, "0010 0000 0000 dddd imm8 imm8", "ldb rbd,imm8", 0}, {"------", 3, 8, "1010 0000 ssss dddd", "ldb rbd,rbs", 0}, {"------", 14, 8, "0011 0000 ssN0 dddd imm16", "ldb rbd,rs(imm16)", 0}, {"------", 14, 8, "0111 0000 ssN0 dddd 0000 xxxx 0000 0000", "ldb rbd,rs(rx)", 0}, @@ -552,7 +552,7 @@ struct op opt[] = }; static int -count () +count (void) { struct op *p = opt; int r = 0; @@ -567,9 +567,7 @@ count () } static int -func (a, b) - struct op *a; - struct op *b; +func (struct op *a, struct op *b) { return strcmp ((a)->name, (b)->name); } @@ -588,7 +586,7 @@ struct tok_struct int length; }; -struct tok_struct args[] = +static struct tok_struct args[] = { {"address_src(rs)", "CLASS_X+(ARG_RS)",}, {"address_dst(rd)", "CLASS_X+(ARG_RD)",}, @@ -649,7 +647,7 @@ struct tok_struct args[] = {0, 0} }; -struct tok_struct toks[] = +static struct tok_struct toks[] = { {"0000", "CLASS_BIT+0", 1}, {"0001", "CLASS_BIT+1", 1}, @@ -728,11 +726,8 @@ struct tok_struct toks[] = {0, 0} }; -char * -translate (table, x, length) - struct tok_struct *table; - char *x; - int *length; +static char * +translate (struct tok_struct *table, char *x, int *length) { int found; @@ -760,9 +755,7 @@ translate (table, x, length) } static void -chewbits (bits, length) - char *bits; - int *length; +chewbits (char *bits, int *length) { int n = 0; @@ -788,8 +781,7 @@ chewbits (bits, length) } static int -chewname (name) - char **name; +chewname (char **name) { char *n; int nargs = 0; @@ -830,9 +822,7 @@ chewname (name) } static void -sub (x, c) - char *x; - char c; +sub (char *x, char c) { while (*x) { @@ -851,8 +841,7 @@ sub (x, c) #define D(x) ((x) == '1' || (x) =='0') #define M(y) (strncmp(y,x,4)==0) static void -printmangled (x) - char *x; +printmangled (char *x) { return; while (*x) @@ -886,8 +875,7 @@ printmangled (x) /*#define WORK_TYPE*/ static void -print_type (n) - struct op *n; +print_type (struct op *n) { #ifdef WORK_TYPE while (*s && !iswhite (*s)) @@ -913,7 +901,7 @@ print_type (n) } static void -internal () +internal (void) { int c = count (); struct op *new = (struct op *) xmalloc (sizeof (struct op) * c); @@ -921,7 +909,7 @@ internal () memcpy (new, p, c * sizeof (struct op)); /* Sort all names in table alphabetically. */ - qsort (new, c, sizeof (struct op), func); + qsort (new, c, sizeof (struct op), (int (*)(const void *, const void *))func); p = new; while (p->flags && p->flags[0] != '*') @@ -966,7 +954,7 @@ internal () } static void -gas () +gas (void) { int c = count (); struct op *p = opt; @@ -977,129 +965,129 @@ gas () memcpy (new, p, c * sizeof (struct op)); /* Sort all names in table alphabetically. */ - qsort (new, c, sizeof (struct op), func); + qsort (new, c, sizeof (struct op), (int (*)(const void *, const void *))func); printf ("/* DO NOT EDIT! -*- buffer-read-only: t -*-\n"); printf (" This file is automatically generated by z8kgen. */\n\n"); - printf ("#define ARG_MASK 0x0f\n"); - - printf ("#define ARG_SRC 0x01\n"); - printf ("#define ARG_DST 0x02\n"); - - printf ("#define ARG_RS 0x01\n"); - printf ("#define ARG_RD 0x02\n"); - printf ("#define ARG_RA 0x03\n"); - printf ("#define ARG_RB 0x04\n"); - printf ("#define ARG_RR 0x05\n"); - printf ("#define ARG_RX 0x06\n"); - - printf ("#define ARG_IMM4 0x01\n"); - printf ("#define ARG_IMM8 0x02\n"); - printf ("#define ARG_IMM16 0x03\n"); - printf ("#define ARG_IMM32 0x04\n"); - printf ("#define ARG_IMMN 0x05\n"); - printf ("#define ARG_IMMNMINUS1 0x05\n"); - printf ("#define ARG_IMM_1 0x06\n"); - printf ("#define ARG_IMM_2 0x07\n"); - printf ("#define ARG_DISP16 0x08\n"); - printf ("#define ARG_NIM8 0x09\n"); - printf ("#define ARG_IMM2 0x0a\n"); - printf ("#define ARG_IMM1OR2 0x0b\n"); - - printf ("#define ARG_DISP12 0x0b\n"); - printf ("#define ARG_NIM4 0x0c\n"); - printf ("#define ARG_DISP8 0x0c\n"); - printf ("#define ARG_IMM4M1 0x0d\n"); - - printf ("#define CLASS_X 0x10\n"); - printf ("#define CLASS_BA 0x20\n"); - printf ("#define CLASS_DA 0x30\n"); - printf ("#define CLASS_BX 0x40\n"); - printf ("#define CLASS_DISP 0x50\n"); - printf ("#define CLASS_IMM 0x60\n"); - printf ("#define CLASS_CC 0x70\n"); - printf ("#define CLASS_CTRL 0x80\n"); - printf ("#define CLASS_IGNORE 0x90\n"); - printf ("#define CLASS_ADDRESS 0xd0\n"); - printf ("#define CLASS_0CCC 0xe0\n"); - printf ("#define CLASS_1CCC 0xf0\n"); - printf ("#define CLASS_0DISP7 0x100\n"); - printf ("#define CLASS_1DISP7 0x200\n"); - printf ("#define CLASS_01II 0x300\n"); - printf ("#define CLASS_00II 0x400\n"); - printf ("#define CLASS_BIT 0x500\n"); - printf ("#define CLASS_FLAGS 0x600\n"); - printf ("#define CLASS_IR 0x700\n"); + printf ("#define ARG_MASK 0x0f\n"); + + printf ("#define ARG_SRC 0x01\n"); + printf ("#define ARG_DST 0x02\n"); + + printf ("#define ARG_RS 0x01\n"); + printf ("#define ARG_RD 0x02\n"); + printf ("#define ARG_RA 0x03\n"); + printf ("#define ARG_RB 0x04\n"); + printf ("#define ARG_RR 0x05\n"); + printf ("#define ARG_RX 0x06\n"); + + printf ("#define ARG_IMM4 0x01\n"); + printf ("#define ARG_IMM8 0x02\n"); + printf ("#define ARG_IMM16 0x03\n"); + printf ("#define ARG_IMM32 0x04\n"); + printf ("#define ARG_IMMN 0x05\n"); + printf ("#define ARG_IMMNMINUS1 0x05\n"); + printf ("#define ARG_IMM_1 0x06\n"); + printf ("#define ARG_IMM_2 0x07\n"); + printf ("#define ARG_DISP16 0x08\n"); + printf ("#define ARG_NIM8 0x09\n"); + printf ("#define ARG_IMM2 0x0a\n"); + printf ("#define ARG_IMM1OR2 0x0b\n"); + + printf ("#define ARG_DISP12 0x0b\n"); + printf ("#define ARG_NIM4 0x0c\n"); + printf ("#define ARG_DISP8 0x0c\n"); + printf ("#define ARG_IMM4M1 0x0d\n"); + + printf ("#define CLASS_X 0x10\n"); + printf ("#define CLASS_BA 0x20\n"); + printf ("#define CLASS_DA 0x30\n"); + printf ("#define CLASS_BX 0x40\n"); + printf ("#define CLASS_DISP 0x50\n"); + printf ("#define CLASS_IMM 0x60\n"); + printf ("#define CLASS_CC 0x70\n"); + printf ("#define CLASS_CTRL 0x80\n"); + printf ("#define CLASS_IGNORE 0x90\n"); + printf ("#define CLASS_ADDRESS 0xd0\n"); + printf ("#define CLASS_0CCC 0xe0\n"); + printf ("#define CLASS_1CCC 0xf0\n"); + printf ("#define CLASS_0DISP7 0x100\n"); + printf ("#define CLASS_1DISP7 0x200\n"); + printf ("#define CLASS_01II 0x300\n"); + printf ("#define CLASS_00II 0x400\n"); + printf ("#define CLASS_BIT 0x500\n"); + printf ("#define CLASS_FLAGS 0x600\n"); + printf ("#define CLASS_IR 0x700\n"); printf ("#define CLASS_IRO 0x800\n"); printf ("#define CLASS_DISP8 0x900\n"); printf ("#define CLASS_BIT_1OR2 0xa00\n"); - printf ("#define CLASS_REG 0x7000\n"); - printf ("#define CLASS_REG_BYTE 0x2000\n"); - printf ("#define CLASS_REG_WORD 0x3000\n"); - printf ("#define CLASS_REG_QUAD 0x4000\n"); - printf ("#define CLASS_REG_LONG 0x5000\n"); - printf ("#define CLASS_REGN0 0x8000\n"); - printf ("#define CLASS_PR 0x10000\n"); + printf ("#define CLASS_REG 0x7000\n"); + printf ("#define CLASS_REG_BYTE 0x2000\n"); + printf ("#define CLASS_REG_WORD 0x3000\n"); + printf ("#define CLASS_REG_QUAD 0x4000\n"); + printf ("#define CLASS_REG_LONG 0x5000\n"); + printf ("#define CLASS_REGN0 0x8000\n"); + printf ("#define CLASS_PR 0x10000\n"); printf ("#define CLASS_MASK 0x1fff0\n"); - printf ("#define OPC_adc 0\n"); - printf ("#define OPC_adcb 1\n"); - printf ("#define OPC_add 2\n"); - printf ("#define OPC_addb 3\n"); - printf ("#define OPC_addl 4\n"); - printf ("#define OPC_and 5\n"); - printf ("#define OPC_andb 6\n"); - printf ("#define OPC_bit 7\n"); - printf ("#define OPC_bitb 8\n"); - printf ("#define OPC_call 9\n"); - printf ("#define OPC_calr 10\n"); - printf ("#define OPC_clr 11\n"); - printf ("#define OPC_clrb 12\n"); - printf ("#define OPC_com 13\n"); - printf ("#define OPC_comb 14\n"); - printf ("#define OPC_comflg 15\n"); - printf ("#define OPC_cp 16\n"); - printf ("#define OPC_cpb 17\n"); - printf ("#define OPC_cpd 18\n"); - printf ("#define OPC_cpdb 19\n"); - printf ("#define OPC_cpdr 20\n"); - printf ("#define OPC_cpdrb 21\n"); - printf ("#define OPC_cpi 22\n"); - printf ("#define OPC_cpib 23\n"); - printf ("#define OPC_cpir 24\n"); - printf ("#define OPC_cpirb 25\n"); - printf ("#define OPC_cpl 26\n"); - printf ("#define OPC_cpsd 27\n"); - printf ("#define OPC_cpsdb 28\n"); - printf ("#define OPC_cpsdr 29\n"); - printf ("#define OPC_cpsdrb 30\n"); - printf ("#define OPC_cpsi 31\n"); - printf ("#define OPC_cpsib 32\n"); - printf ("#define OPC_cpsir 33\n"); - printf ("#define OPC_cpsirb 34\n"); - printf ("#define OPC_dab 35\n"); - printf ("#define OPC_dbjnz 36\n"); - printf ("#define OPC_dec 37\n"); - printf ("#define OPC_decb 38\n"); - printf ("#define OPC_di 39\n"); - printf ("#define OPC_div 40\n"); - printf ("#define OPC_divl 41\n"); - printf ("#define OPC_djnz 42\n"); - printf ("#define OPC_ei 43\n"); - printf ("#define OPC_ex 44\n"); - printf ("#define OPC_exb 45\n"); - printf ("#define OPC_exts 46\n"); - printf ("#define OPC_extsb 47\n"); - printf ("#define OPC_extsl 48\n"); - printf ("#define OPC_halt 49\n"); - printf ("#define OPC_in 50\n"); - printf ("#define OPC_inb 51\n"); - printf ("#define OPC_inc 52\n"); - printf ("#define OPC_incb 53\n"); - printf ("#define OPC_ind 54\n"); - printf ("#define OPC_indb 55\n"); + printf ("#define OPC_adc 0\n"); + printf ("#define OPC_adcb 1\n"); + printf ("#define OPC_add 2\n"); + printf ("#define OPC_addb 3\n"); + printf ("#define OPC_addl 4\n"); + printf ("#define OPC_and 5\n"); + printf ("#define OPC_andb 6\n"); + printf ("#define OPC_bit 7\n"); + printf ("#define OPC_bitb 8\n"); + printf ("#define OPC_call 9\n"); + printf ("#define OPC_calr 10\n"); + printf ("#define OPC_clr 11\n"); + printf ("#define OPC_clrb 12\n"); + printf ("#define OPC_com 13\n"); + printf ("#define OPC_comb 14\n"); + printf ("#define OPC_comflg 15\n"); + printf ("#define OPC_cp 16\n"); + printf ("#define OPC_cpb 17\n"); + printf ("#define OPC_cpd 18\n"); + printf ("#define OPC_cpdb 19\n"); + printf ("#define OPC_cpdr 20\n"); + printf ("#define OPC_cpdrb 21\n"); + printf ("#define OPC_cpi 22\n"); + printf ("#define OPC_cpib 23\n"); + printf ("#define OPC_cpir 24\n"); + printf ("#define OPC_cpirb 25\n"); + printf ("#define OPC_cpl 26\n"); + printf ("#define OPC_cpsd 27\n"); + printf ("#define OPC_cpsdb 28\n"); + printf ("#define OPC_cpsdr 29\n"); + printf ("#define OPC_cpsdrb 30\n"); + printf ("#define OPC_cpsi 31\n"); + printf ("#define OPC_cpsib 32\n"); + printf ("#define OPC_cpsir 33\n"); + printf ("#define OPC_cpsirb 34\n"); + printf ("#define OPC_dab 35\n"); + printf ("#define OPC_dbjnz 36\n"); + printf ("#define OPC_dec 37\n"); + printf ("#define OPC_decb 38\n"); + printf ("#define OPC_di 39\n"); + printf ("#define OPC_div 40\n"); + printf ("#define OPC_divl 41\n"); + printf ("#define OPC_djnz 42\n"); + printf ("#define OPC_ei 43\n"); + printf ("#define OPC_ex 44\n"); + printf ("#define OPC_exb 45\n"); + printf ("#define OPC_exts 46\n"); + printf ("#define OPC_extsb 47\n"); + printf ("#define OPC_extsl 48\n"); + printf ("#define OPC_halt 49\n"); + printf ("#define OPC_in 50\n"); + printf ("#define OPC_inb 51\n"); + printf ("#define OPC_inc 52\n"); + printf ("#define OPC_incb 53\n"); + printf ("#define OPC_ind 54\n"); + printf ("#define OPC_indb 55\n"); printf ("#define OPC_indr 56\n"); printf ("#define OPC_indrb 57\n"); printf ("#define OPC_ini 58\n"); @@ -1322,9 +1310,7 @@ gas () } int -main (ac, av) - int ac; - char **av; +main (int ac, char **av) { struct op *p = opt; |