📄 gencode.c
字号:
"if (i < 16)", " res = Sz << i;", "else if (i >= 128 - 16)", " res = Sz >> 128 - i;", "else", " {", " RAISE_EXCEPTION (SIGILL);", " return;", " }", "res &= 0xffff0000;", "res_grd = 0;", "goto logical;", }, { "","", "psha #<imm>,dz", "00010iiim32.zzzz", "int Sz = DSP_R (z);", "int Sz_grd = GET_DSP_GRD (z);", "", "if (i < 32)", " {", " if (i == 32)", " {", " res = 0;", " res_grd = Sz;", " }", " else", " {", " res = Sz << i;", " res_grd = Sz_grd << i | (unsigned) Sz >> 32 - i;", " }", " res_grd = SEXT (res_grd);", " carry = res_grd & 1;", " }", "else if (i >= 96)", " {", " i = 128 - i;", " if (i == 32)", " {", " res_grd = SIGN32 (Sz_grd);", " res = Sz_grd;", " }", " else", " {", " res = Sz >> i | Sz_grd << 32 - i;", " res_grd = Sz_grd >> i;", " }", " carry = Sz >> (i - 1) & 1;", " }", "else", " {", " RAISE_EXCEPTION (SIGILL);", " return;", " }", "COMPUTE_OVERFLOW;", "greater_equal = 0;", }, { "","", "pmuls Se,Sf,Dg", "0100eeffxxyygguu", "res = (DSP_R (e)) >> 16 * (DSP_R (f) >> 16) * 2;", "if (res == 0x80000000)", " res = 0x7fffffff;", "DSP_R (g) = res;", "DSP_GRD (g) = SIGN32 (res);", "return;", }, { "","", "psub Sx,Sy,Du pmuls Se,Sf,Dg", "0110eeffxxyygguu", "int Sx = DSP_R (x);", "int Sx_grd = GET_DSP_GRD (x);", "int Sy = DSP_R (y);", "int Sy_grd = SIGN32 (Sy);", "", "res = (DSP_R (e)) >> 16 * (DSP_R (f) >> 16) * 2;", "if (res == 0x80000000)", " res = 0x7fffffff;", "DSP_R (g) = res;", "DSP_GRD (g) = SIGN32 (res);", "", "z = u;", "res = Sx - Sy;", "carry = (unsigned) res > (unsigned) Sx;", "res_grd = Sx_grd - Sy_grd - carry;", "COMPUTE_OVERFLOW;", "ADD_SUB_GE;", }, { "","", "padd Sx,Sy,Du pmuls Se,Sf,Dg", "0111eeffxxyygguu", "int Sx = DSP_R (x);", "int Sx_grd = GET_DSP_GRD (x);", "int Sy = DSP_R (y);", "int Sy_grd = SIGN32 (Sy);", "", "res = (DSP_R (e)) >> 16 * (DSP_R (f) >> 16) * 2;", "if (res == 0x80000000)", " res = 0x7fffffff;", "DSP_R (g) = res;", "DSP_GRD (g) = SIGN32 (res);", "", "z = u;", "res = Sx + Sy;", "carry = (unsigned) res < (unsigned) Sx;", "res_grd = Sx_grd + Sy_grd + carry;", "COMPUTE_OVERFLOW;", }, { "","", "psubc Sx,Sy,Dz", "10100000xxyyzzzz", "int Sx = DSP_R (x);", "int Sx_grd = GET_DSP_GRD (x);", "int Sy = DSP_R (y);", "int Sy_grd = SIGN32 (Sy);", "", "res = Sx - Sy - (DSR & 1);", "carry = (unsigned) res > (unsigned) Sx || (res == Sx && Sy);", "res_grd = Sx_grd + Sy_grd + carry;", "COMPUTE_OVERFLOW;", "ADD_SUB_GE;", "DSR &= ~0xf1;\n", "if (res || res_grd)\n", " DSR |= greater_equal | res_grd >> 2 & DSR_MASK_N | overflow;\n", "else\n", " DSR |= DSR_MASK_Z | overflow;\n", "DSR |= carry;\n", "goto assign_z;\n", }, { "","", "paddc Sx,Sy,Dz", "10110000xxyyzzzz", "int Sx = DSP_R (x);", "int Sx_grd = GET_DSP_GRD (x);", "int Sy = DSP_R (y);", "int Sy_grd = SIGN32 (Sy);", "", "res = Sx + Sy + (DSR & 1);", "carry = (unsigned) res < (unsigned) Sx || (res == Sx && Sy);", "res_grd = Sx_grd + Sy_grd + carry;", "COMPUTE_OVERFLOW;", "ADD_SUB_GE;", "DSR &= ~0xf1;\n", "if (res || res_grd)\n", " DSR |= greater_equal | res_grd >> 2 & DSR_MASK_N | overflow;\n", "else\n", " DSR |= DSR_MASK_Z | overflow;\n", "DSR |= carry;\n", "goto assign_z;\n", }, { "","", "pcmp Sx,Sy", "10000100xxyy....", "int Sx = DSP_R (x);", "int Sx_grd = GET_DSP_GRD (x);", "int Sy = DSP_R (y);", "int Sy_grd = SIGN32 (Sy);", "", "z = 17; /* Ignore result. */", "res = Sx - Sy;", "carry = (unsigned) res > (unsigned) Sx;", "res_grd = Sx_grd - Sy_grd - carry;", "COMPUTE_OVERFLOW;", "ADD_SUB_GE;", }, { "","", "pwsb Sx,Sy,Dz", "10100100xxyyzzzz", }, { "","", "pwad Sx,Sy,Dz", "10110100xxyyzzzz", }, { "","", "pabs Sx,Dz", "10001000xx..zzzz", "res = DSP_R (x);", "res_grd = GET_DSP_GRD (x);", "if (res >= 0)", " carry = 0;", "else", " {", " res = -res;", " carry = (res != 0); /* The manual has a bug here. */", " res_grd = -res_grd - carry;", " }", "COMPUTE_OVERFLOW;", "/* ??? The re-computing of overflow after", " saturation processing is specific to pabs. */", "overflow = res_grd != SIGN32 (res) ? DSR_MASK_V : 0;", "ADD_SUB_GE;", }, { "","", "prnd Sx,Dz", "10011000xx..zzzz", "int Sx = DSP_R (x);", "int Sx_grd = GET_DSP_GRD (x);", "", "res = Sx + 0x8000;", "carry = (unsigned) res < (unsigned) Sx;", "res_grd = Sx_grd + carry;", "COMPUTE_OVERFLOW;", "ADD_SUB_GE;", }, { "","", "pabs Sy,Dz", "10101000..yyzzzz", "res = DSP_R (y);", "res_grd = 0;", "overflow = 0;", "greater_equal = DSR_MASK_G;", "if (res >= 0)", " carry = 0;", "else", " {", " res = -res;", " carry = 1;", " if (res < 0)", " {", " if (S)", " res = 0x7fffffff;", " else", " {", " overflow = DSR_MASK_V;", " greater_equal = 0;", " }", " }", " }", }, { "","", "prnd Sy,Dz", "10111000..yyzzzz", "int Sy = DSP_R (y);", "int Sy_grd = SIGN32 (Sy);", "", "res = Sy + 0x8000;", "carry = (unsigned) res < (unsigned) Sy;", "res_grd = Sy_grd + carry;", "COMPUTE_OVERFLOW;", "ADD_SUB_GE;", }, { "","", "(if cc) pshl Sx,Sy,Dz", "100000ccxxyyzzzz", "int Sx = DSP_R (x) & 0xffff0000;", "int Sy = DSP_R (y) >> 16 & 0x7f;", "", "if (Sy < 16)", " res = Sx << Sy;", "else if (Sy >= 128 - 16)", " res = Sx >> 128 - Sy;", "else", " {", " RAISE_EXCEPTION (SIGILL);", " return;", " }", "goto cond_logical;", }, { "","", "(if cc) psha Sx,Sy,Dz", "100100ccxxyyzzzz", "int Sx = DSP_R (x);", "int Sx_grd = GET_DSP_GRD (x);", "int Sy = DSP_R (y) >> 16 & 0x7f;", "", "if (Sy < 32)", " {", " if (Sy == 32)", " {", " res = 0;", " res_grd = Sx;", " }", " else", " {", " res = Sx << Sy;", " res_grd = Sx_grd << Sy | (unsigned) Sx >> 32 - Sy;", " }", " res_grd = SEXT (res_grd);", " carry = res_grd & 1;", " }", "else if (Sy >= 96)", " {", " Sy = 128 - Sy;", " if (Sy == 32)", " {", " res_grd = SIGN32 (Sx_grd);", " res = Sx_grd;", " }", " else", " {", " res = Sx >> Sy | Sx_grd << 32 - Sy;", " res_grd = Sx_grd >> Sy;", " }", " carry = Sx >> (Sy - 1) & 1;", " }", "else", " {", " RAISE_EXCEPTION (SIGILL);", " return;", " }", "COMPUTE_OVERFLOW;", "greater_equal = 0;", }, { "","", "(if cc) psub Sx,Sy,Dz", "101000ccxxyyzzzz", "int Sx = DSP_R (x);", "int Sx_grd = GET_DSP_GRD (x);", "int Sy = DSP_R (y);", "int Sy_grd = SIGN32 (Sy);", "", "res = Sx - Sy;", "carry = (unsigned) res > (unsigned) Sx;", "res_grd = Sx_grd - Sy_grd - carry;", "COMPUTE_OVERFLOW;", "ADD_SUB_GE;", }, { "","", "(if cc) padd Sx,Sy,Dz", "101100ccxxyyzzzz", "int Sx = DSP_R (x);", "int Sx_grd = GET_DSP_GRD (x);", "int Sy = DSP_R (y);", "int Sy_grd = SIGN32 (Sy);", "", "res = Sx + Sy;", "carry = (unsigned) res < (unsigned) Sx;", "res_grd = Sx_grd + Sy_grd + carry;", "COMPUTE_OVERFLOW;", "ADD_SUB_GE;", }, { "","", "(if cc) pand Sx,Sy,Dz", "100101ccxxyyzzzz", "res = DSP_R (x) & DSP_R (y);", "cond_logical:", "res &= 0xffff0000;", "res_grd = 0;", "if (iword & 0x200)\n", " goto assign_z;\n", "logical:", "carry = 0;", "overflow = 0;", "greater_equal = 0;", "DSR &= ~0xf1;\n", "if (res)\n", " DSR |= res >> 26 & DSR_MASK_N;\n", "else\n", " DSR |= DSR_MASK_Z;\n", "goto assign_dc;\n", }, { "","", "(if cc) pxor Sx,Sy,Dz", "101001ccxxyyzzzz", "res = DSP_R (x) ^ DSP_R (y);", "goto cond_logical;", }, { "","", "(if cc) por Sx,Sy,Dz", "101101ccxxyyzzzz", "res = DSP_R (x) | DSP_R (y);", "goto cond_logical;", }, { "","", "(if cc) pdec Sx,Dz", "100010ccxx..zzzz", "int Sx = DSP_R (x);", "int Sx_grd = GET_DSP_GRD (x);", "", "res = Sx - 0x10000;", "carry = res > Sx;", "res_grd = Sx_grd - carry;", "COMPUTE_OVERFLOW;", "ADD_SUB_GE;", "res &= 0xffff0000;", }, { "","", "(if cc) pinc Sx,Dz", "100110ccxx..zzzz", "int Sx = DSP_R (x);", "int Sx_grd = GET_DSP_GRD (x);", "", "res = Sx + 0x10000;", "carry = res < Sx;", "res_grd = Sx_grd + carry;", "COMPUTE_OVERFLOW;", "ADD_SUB_GE;", "res &= 0xffff0000;", }, { "","", "(if cc) pdec Sy,Dz", "101010cc..yyzzzz", "int Sy = DSP_R (y);", "int Sy_grd = SIGN32 (Sy);", "", "res = Sy - 0x10000;", "carry = res > Sy;", "res_grd = Sy_grd - carry;", "COMPUTE_OVERFLOW;", "ADD_SUB_GE;", "res &= 0xffff0000;", }, { "","", "(if cc) pinc Sy,Dz", "101110cc..yyzzzz", "int Sy = DSP_R (y);", "int Sy_grd = SIGN32 (Sy);", "", "res = Sy + 0x10000;", "carry = res < Sy;", "res_grd = Sy_grd + carry;", "COMPUTE_OVERFLOW;", "ADD_SUB_GE;", "res &= 0xffff0000;", }, { "","", "(if cc) pclr Dz", "100011cc....zzzz", "res = 0;", "res_grd = 0;", "carry = 0;", "overflow = 0;", "greater_equal = 1;", }, { "","", "(if cc) pdmsb Sx,Dz", "100111ccxx..zzzz", "unsigned Sx = DSP_R (x);", "int Sx_grd = GET_DSP_GRD (x);", "int i = 16;", "", "if (Sx_grd < 0)", " {", " Sx_grd = ~Sx_grd;", " Sx = ~Sx;", " }", "if (Sx_grd)", " {", " Sx = Sx_grd;", " res = -2;", " }", "else if (Sx)", " res = 30;", "else", " res = 31;", "do", " {", " if (Sx & ~0 << i)", " {", " res -= i;", " Sx >>= i;", " }", " }", "while (i >>= 1);", "res <<= 16;", "res_grd = SIGN32 (res);", "carry = 0;", "overflow = 0;", "ADD_SUB_GE;", }, { "","", "(if cc) pdmsb Sy,Dz", "101111cc..yyzzzz", "unsigned Sy = DSP_R (y);", "int i;", "", "if (Sy < 0)", " Sy = ~Sy;", "Sy <<= 1;", "res = 31;", "do", " {", " if (Sy & ~0 << i)", " {", " res -= i;", " Sy >>= i;", " }", " }", "while (i >>= 1);", "res <<= 16;", "res_grd = SIGN32 (res);", "carry = 0;", "overflow = 0;", "ADD_SUB_GE;", }, { "","", "(if cc) pneg Sx,Dz", "110010ccxx..zzzz", "int Sx = DSP_R (x);", "int Sx_grd = GET_DSP_GRD (x);", "", "res = 0 - Sx;", "carry = res != 0;", "res_grd = 0 - Sx_grd - carry;", "COMPUTE_OVERFLOW;", "ADD_SUB_GE;", }, { "","", "(if cc) pcopy Sx,Dz", "110110ccxx..zzzz", "res = DSP_R (x);", "res_grd = GET_DSP_GRD (x);", "carry = 0;", "COMPUTE_OVERFLOW;", "ADD_SUB_GE;", }, { "","", "(if cc) pneg Sy,Dz", "111010cc..yyzzzz", "int Sy = DSP_R (y);", "int Sy_grd = SIGN32 (Sy);", "", "res = 0 - Sy;", "carry = res != 0;", "res_grd = 0 - Sy_grd - carry;", "COMPUTE_OVERFLOW;", "ADD_SUB_GE;", }, { "","", "(if cc) pcopy Sy,Dz", "111110cc..yyzzzz", "res = DSP_R (y);", "res_grd = SIGN32 (res);", "carry = 0;", "COMPUTE_OVERFLOW;", "ADD_SUB_GE;", }, { "","", "(if cc) psts MACH,Dz", "110011cc....zzzz", "res = MACH;", "res_grd = SIGN32 (res);", "goto assign_z;", }, { "","", "(if cc) psts MACL,Dz", "110111cc....zzzz", "res = MACL;", "res_grd = SIGN32 (res);", "goto assign_z;", }, { "","", "(if cc) plds Dz,MACH", "111011cc....zzzz", "if (0xa05f >> z & 1)", " RAISE_EXCEPTION (SIGILL);", "else", " MACH = DSP_R (z);", "return;", }, { "","", "(if cc) plds Dz,MACL", "111111cc....zzzz", "if (0xa05f >> z & 1)", " RAISE_EXCEPTION (SIGILL);", "else", " MACL = DSP_R (z) = res;", "return;", }, {0, 0}};/* Tables of things to put into enums for sh-opc.h */static char *nibble_type_list[] ={ "HEX_0", "HEX_1", "HEX_2", "HEX_3", "HEX_4", "HEX_5", "HEX_6", "HEX_7", "HEX_8", "HEX_9", "HEX_A", "HEX_B", "HEX_C", "HEX_D", "HEX_E", "HEX_F", "REG_N", "REG_M", "BRANCH_12", "BRANCH_8", "DISP_8", "DISP_4", "IMM_4", "IMM_4BY2", "IMM_4BY4", "PCRELIMM_8BY2", "PCRELIMM_8BY4", "IMM_8", "IMM_8BY2", "IMM_8BY4", 0};staticchar *arg_type_list[] ={ "A_END", "A_BDISP12", "A_BDISP8", "A_DEC_M", "A_DEC_N", "A_DISP_GBR", "A_DISP_PC", "A_DISP_REG_M", "A_DISP_REG_N", "A_GBR", "A_IMM", "A_INC_M", "A_INC_N", "A_IND_M", "A_IND_N", "A_IND_R0_REG_M", "A_IND_R0_REG_N", "A_MACH", "A_MACL", "A_PR", "A_R0", "A_R0_GBR", "A_REG_M", "A_REG_N", "A_SR", "A_VBR", "A_SSR", "A_SPC", 0,};static voidmake_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 intqfunc (a, b) op *a; op *b;{ char bufa[9]; char bufb[9]; int diff; memcpy (bufa, a->code, 4); memcpy (bufa + 4, a->code + 12, 4); bufa[8] = 0; memcpy (bufb, b->code, 4); memcpy (bufb + 4, b->code + 12, 4); bufb[8] = 0; diff = strcmp (bufa, bufb); /* Stabilize the sort, so that later entries can override more general preceding entries. */ return diff ? diff : a - b;}static voidsorttab (){ op *p = tab; int len = 0; while (p->name) { p++; len++; } qsort (tab, len, sizeof (*p), qfunc);}static voidgengastab (){ op *p; sorttab (); for (p = tab; p->name; p++) { printf ("%s %-30s\n", p->code, p->name); }}/* Convert a string of 4 binary digits into an int */staticintbton (s) char *s;{ int n = 0; int v = 8; while (v) { if (*s == '1') n |= v; v >>= 1; s++; } return n;}static unsigned char table[1 << 16];/* Take an opcode expand all varying fields in it out and fill all the right entries in 'table' with the opcode index*/static void
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -