]>
git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - sim/z8k/writecode.c
2 /* generate instructions for Z8KSIM
3 Copyright (C) 1992, 1993 Free Software Foundation, Inc.
5 This file is part of Z8KSIM
7 Z8KSIM 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 2, or (at your option)
12 Z8KSIM 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 Z8KZIM; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 /* This program generates the code which emulates each of the z8k
24 code goes into three files, tc-gen1.h, tc-gen2.h and tc-gen3.h.
25 which file being made depends upon the options
27 -1 tc-gen1.h contains the fully expanded code for some selected
28 opcodes, (those in the quick.c list)
30 -2 tc-gen2.h contains a list of pointers to functions, one for each
31 opcode. It points to functions in tc-gen3.h and tc-gen1.h
32 depending upon quick.c
34 -3 tc-gen3.h contains all the opcodes in unexpanded form.
36 -b3 tc-genb3.h same as -3 but for long pointers
38 -m regenerates list.c, which is an inverted list of opcodes to
39 pointers into the z8k dissassemble opcode table, it's just there
40 to makes things faster.
64 #include "../opcodes/z8k-opc.h"
68 #define DIRTY_HACK 0 /* Enable if your gcc can't cope with huge tables */
69 extern short z8k_inv_list
[];
73 struct opcode_value
*next
;
79 static char *reg_names
[] =
80 {"bad", "src", "dst", "aux_a", "aux_b", "aux_r", "aux_x"};
82 #define IS_DST(x) ((x & 0xf) == 2)
83 #define IS_SRC(x) ((x & 0xf)==1)
84 #define SIZE_ADDRESS (BIG ? 8 : 4) /* number of nibbles in a ptr*/
91 static char *current_size
;
92 static char *current_name
;
93 static char current_word0
[40];
94 static char current_byte0
[40];
95 static char current_byte1
[40];
100 struct opcode_value
*list
[NOPS
];
102 static opcode_entry_type
*
111 unsigned short instr_nibl
;
112 unsigned short tabl_datum
, datum_class
, datum_value
;
113 char instr_nibbles
[8];
115 opcode_entry_type
*ptr
= z8k_table
;
119 instr_nibbles
[3] = (what
>> 0) & 0xf;
120 instr_nibbles
[2] = (what
>> 4) & 0xf;
121 instr_nibbles
[1] = (what
>> 8) & 0xf;
122 instr_nibbles
[0] = (what
>> 12) & 0xf;
127 for (nibl_index
= 0; nibl_index
< 4 && nibl_matched
; nibl_index
++)
129 instr_nibl
= instr_nibbles
[nibl_index
];
131 tabl_datum
= ptr
->byte_info
[nibl_index
];
132 datum_class
= tabl_datum
& CLASS_MASK
;
133 datum_value
= ~CLASS_MASK
& tabl_datum
;
138 if (datum_value
!= (instr_nibl
& ~0x2))
143 if (datum_value
!= instr_nibl
)
147 if (!((~instr_nibl
) & 0x4))
151 if (!(instr_nibl
& 0x4))
155 if (!((~instr_nibl
) & 0x8))
159 if (!(instr_nibl
& 0x8))
163 if (!((~instr_nibl
) & 0x8))
168 if (!(instr_nibl
& 0x8))
191 if (z8k_inv_list
[what
] < 0)
193 return z8k_table
+ z8k_inv_list
[what
];
204 return "((iwords_0>>8) & 0xf)";
206 return "((ibytes_1 >> 4) & 0xf)";
208 return "((ibytes_1) & 0xf)";
210 return "((ibytes_2>>4) & 0xf)";
212 return "((ibytes_2) & 0xf)";
214 return "((ibytes_3 >> 4) & 0xf)";
216 return "((ibytes_3) & 0xf)";
245 return reg_names
[x
& 0xf];
251 return BIG
? "14" : "15";
258 return BIG
? "segmem" : "unsegmem";
268 if (strncmp (p
, a
, strlen (a
)) == 0)
281 sprintf (d
, "%s", y
);
312 return "((iwords_0<<16) | (iwords_1))";
314 return "((iwords_1<<16) | (iwords_2))";
316 return "((iwords_2<<16) | (iwords_3))";
342 emit (string
, a1
, a2
, a3
, a4
, a5
)
371 else if (match ("<iptr>"))
378 sub ("(((iwords_1 << 8) | (iwords_2)) & 0x7fffff)");
381 sub ("fail(context,124)");
393 sub ("fail(context,123)");
398 else if (match ("<name>"))
402 else if (match ("<size>"))
406 else if (match ("<insn_4>"))
410 else if (match ("<insn_16>"))
412 sub (insn_16 (nibs
));
414 else if (match ("<insn_32>"))
416 sub (insn_32 (nibs
));
418 else if (match ("iwords_0"))
422 else if (match ("ibytes_0"))
426 else if (match ("<ibytes_1>"))
430 else if (match ("<next_size>"))
432 if (strcmp (current_size
, "word") == 0)
434 if (strcmp (current_size
, "byte") == 0)
436 else if (strcmp (current_size
, "long") == 0)
441 else if (match ("<addr_type>"))
444 sub ("unsigned long");
446 sub ("unsigned short");
449 else if (match ("<c_size>"))
451 if (strcmp (current_size
, "word") == 0)
453 else if (strcmp (current_size
, "byte") == 0)
455 else if (strcmp (current_size
, "long") == 0)
461 else if (match ("<pc>"))
465 else if (match ("<mem>"))
469 else if (match ("<sp>"))
473 else if (match ("<ptr_size>"))
477 else if (match ("<ptr_mode>"))
481 else if (match ("<insn_8>"))
486 sub ("(iwords_0&0xff)");
489 sub ("(iwords_1>>8)");
492 sub ("(iwords_1&0xff)");
495 sub ("(iwords_2>>8)");
498 sub ("(/* WHO */iwords_3&0xff)");
515 indent
-= indent_dec
;
516 for (i
= 0; i
< indent
; i
++)
518 indent
+= indent_inc
;
519 printf (buffer
, a1
, a2
, a3
, a4
, a5
);
523 /* fetch the lvalues of the operands */
526 opcode_entry_type
*p
;
530 int done_one_imm8
= 0;
532 /* int done_read = 4;*/
537 switch (*s
& CLASS_MASK
)
540 emit ("register unsigned int imm_src=(<insn_4>& 2)?2:1;\n");
543 /* Just ignore these, we've already decoded this bit */
548 /* this nibble tells us which register to use as an arg,
549 if we've already gobbled the nibble we know what to use */
551 int regname
= *s
& 0xf;
553 emit ("register unsigned int reg_%s=<insn_4>;\n",
560 emit ("register unsigned base_%s=<iptr>;\n", reg_n (*s
));
562 nibs
+= SIZE_ADDRESS
;
567 emit ("register unsigned int imm_src=<insn_4>&0x2;\n");
571 emit ("register unsigned int imm_src=<insn_4>;\n");
575 /* Work out the size of the think to fetch */
578 switch (*s
& ~CLASS_MASK
)
581 emit ("register unsigned imm_src=<insn_16>;\n");
585 emit ("register unsigned int imm_src= %s;\n", insn_32 (nibs
));
589 emit ("register unsigned int imm_src=<insn_4>;\n");
593 emit ("register unsigned int imm_src=<insn_4> & 0x2;\n");
598 emit ("register unsigned int imm_src=(<insn_4> + 1);\n");
602 emit ("register unsigned int imm_src=1;\n");
605 emit ("register unsigned int imm_src=2;\n");
608 emit ("register unsigned int imm_src=-<insn_8>;\n");
614 emit ("register unsigned int imm_src=<insn_8>;\n");
620 emit ("register int fail%d=fail(context,1);\n", nibs
);
626 /* We can't use `(char)' since char might be unsigned.
627 We can't use `(signed char)' because the compiler might be K&R.
628 This seems safe, since it only assumes that bytes are 8
630 emit ("register unsigned int oplval_dst=((ibytes_1 << (sizeof (int) * 8 - 8)) >> (sizeof (int) * 8 - 9)) + pc;\n");
632 /* Original code: fails if characters are unsigned. */
633 emit ("register unsigned int oplval_dst=(((char)ibytes_1)<<1) + pc;\n");
638 emit ("register unsigned int op_cc=<insn_4>;\n");
642 emit ("register int FAIL%d=fail(context,2);\n", nibs
);
646 /* work out how to fetch the immediate value */
654 info_special (p
, getdst
, nostore
, before
, nosrc
)
655 opcode_entry_type
*p
;
767 /* calculate the lvalues required for the opcode */
770 opcode_entry_type
*p
;
772 /* emit code to work out lvalues, if any */
773 unsigned int *i
= p
->arg_info
;
777 current_name
= reg_n (*i
);
778 current_size
= size_name (p
->type
);
779 switch (*i
& CLASS_MASK
)
783 emit ("register <addr_type> oplval_<name>= ((base_<name> + (short)get_word_reg(context,reg_<name>)) & 0xffff) + (base_<name> & ~0xffff);\n");
786 /* Indirect register */
787 emit ("register int oplval_<name> = get_<ptr_mode>_reg(context,reg_<name>);\n");
790 emit ("register int oplval_<name>=base_<name>;\n");
799 emit ("register int oplval_<name> = get_<ptr_mode>_reg(context,reg_<name>) + (short)(imm_src);\n");
802 emit ("register int oplval_<name> = get_<ptr_mode>_reg(context,reg_<name>)\n");
803 emit (" + get_word_reg(context,reg_aux_x);\n");
810 /* emit code to fetch the args from calculated lvalues */
813 info_fetch (p
, getdst
)
814 opcode_entry_type
*p
;
817 unsigned int *i
= p
->arg_info
;
824 current_name
= reg_n (*i
);
825 current_size
= size_name (p
->type
);
826 switch (*i
& CLASS_MASK
)
833 if (!getdst
&& IS_DST (*i
))
835 emit ("register int op_<name>= get_<size>_<mem>_da(context,oplval_<name>);\n");
841 if (p
->opcode
== OPC_out
||
842 p
->opcode
== OPC_outb
||
843 p
->opcode
== OPC_sout
||
844 p
->opcode
== OPC_soutb
)
846 /* The imm is a dest here */
847 emit ("register int op_dst = imm_src;\n");
851 emit ("register int op_src = imm_src;\n");
856 if (!getdst
&& IS_DST (*i
))
858 had_src
|= IS_SRC (*i
);
859 emit ("UDItype op_<name> ;\n");
863 if (!getdst
&& IS_DST (*i
))
865 had_src
|= IS_SRC (*i
);
866 emit ("register int op_<name> = get_word_reg(context,reg_<name>);\n");
870 if (!getdst
&& IS_DST (*i
))
872 had_src
|= IS_SRC (*i
);
873 emit ("register int op_<name> = get_long_reg(context,reg_<name>);\n");
876 if (!getdst
&& IS_DST (*i
))
878 had_src
|= IS_SRC (*i
);
879 emit ("register int op_<name> = get_byte_reg(context,reg_<name>);\n");
887 normal_flags (p
, s
, neg
)
888 opcode_entry_type
*p
;
892 emit ("NORMAL_FLAGS(context,%d, tmp, op_dst, op_src,%d); \n", p
->type
,neg
);
896 test_normal_flags (p
, s
, opt
)
897 opcode_entry_type
*p
;
904 emit ("context->broken_flags = TST_FLAGS;\n");
905 emit ("context->size = %d;\n", p
->type
);
909 emit ("TEST_NORMAL_FLAGS(context,%d, tmp); \n", p
->type
);
915 optimize_normal_flags (p
, s
,neg
)
916 opcode_entry_type
*p
;
921 emit ("context->broken_flags = CMP_FLAGS;\n");
923 emit ("NORMAL_FLAGS(context,%d, tmp, op_dst, op_src,%d); \n", p
->type
, neg
);
930 opcode_entry_type
*p
;
933 emit ("if(op_cc == 8 || COND(context,op_cc)) pc = oplval_dst;\n");
938 opcode_entry_type
*p
;
940 emit ("if(op_cc == 8 || COND(context,op_cc)) pc = oplval_dst;\n");
945 opcode_entry_type
*p
;
947 emit ("if(op_cc == 8 || COND(context,op_cc))\n{\n");
948 emit ("pc = get_<ptr_mode>_<mem>_ir(context,<sp>);\n");
949 emit ("put_<ptr_mode>_reg(context,<sp>, get_<ptr_mode>_reg(context,<sp>) + <ptr_size>);\n");
955 opcode_entry_type
*p
;
957 emit ("put_<ptr_mode>_reg(context,<sp>,tmp = get_<ptr_mode>_reg(context,<sp>) - <ptr_size>);\n");
958 emit ("put_<ptr_mode>_<mem>_da(context,tmp, pc);\n");
959 emit ("pc = oplval_dst;\n");
964 opcode_entry_type
*p
;
966 emit ("tmp = op_src;\n");
967 emit ("oplval_dst -= %d;\n", p
->type
/ 8);
968 emit ("put_<ptr_mode>_reg(context,reg_dst, oplval_dst);\n");
973 opcode_entry_type
*p
;
975 emit ("tmp = op_src;\n");
976 emit ("put_<ptr_mode>_reg(context,reg_src, oplval_src + %d);\n", p
->type
/ 8);
981 opcode_entry_type
*p
;
983 emit ("tmp = op_src;\n");
989 emit ("support_call(context,imm_src);\n");
996 emit ("context->exception = SIM_BREAKPOINT;\n");
1001 opcode_entry_type
*p
;
1005 int dinc
= (size
/ 8) * inc
;
1007 current_size
= size_name (size
);
1009 emit ("int type = %s;\n", insn_4 (7));
1010 emit ("int rs = get_<ptr_mode>_reg(context,reg_src);\n");
1011 emit ("int rd = get_<ptr_mode>_reg(context,reg_dst);\n");
1012 emit ("int rr = get_word_reg(context,reg_aux_r);\n");
1014 emit ("put_<size>_<mem>_da(context,rd, get_<size>_<mem>_da(context,rs));\n");
1015 emit ("rd += %d;\n", dinc
);
1016 emit ("rs += %d;\n", dinc
);
1018 emit ("context->cycles += 9;\n");
1019 emit ("} while (!type && rr != 0 && context->exception <= 1);\n");
1020 emit ("if (context->exception>1) pc -=4;\n");
1021 emit ("put_<ptr_mode>_reg(context,reg_src, rs);\n");
1022 emit ("put_<ptr_mode>_reg(context,reg_dst, rd);\n");
1023 emit ("put_word_reg(context,reg_aux_r, rr);\n");
1030 opcode_entry_type
*p
;
1034 /* We can't use `(char)' since char might be unsigned.
1035 We can't use `(signed char)' because the compiler might be K&R.
1036 This seems safe, since it only assumes that bytes are 8 bits. */
1037 emit ("op_src = (op_src << (sizeof (int) * 8 - 8)) >> (sizeof (int) * 8 - 8);\n");
1039 /* Original code: fails if characters are unsigned. */
1040 emit ("op_src = (char)op_src;\n");
1042 emit ("if (op_src < 0) \n");
1044 emit ("op_src = -op_src;\n");
1045 emit ("op_dst = (%s <c_size>)op_dst;\n", arith
? "" : "unsigned");
1046 emit ("tmp = (%s op_dst) >> op_src;\n", arith
? "" : "(unsigned)");
1047 emit ("context->carry = op_dst >> (op_src-1);\n", p
->type
);
1051 emit ("tmp = op_dst << op_src;\n");
1052 emit ("context->carry = op_dst >> (%d - op_src);\n", p
->type
);
1054 emit ("context->zero = (<c_size>)tmp == 0;\n");
1055 emit ("context->sign = (int)((<c_size>)tmp) < 0;\n");
1056 emit ("context->overflow = ((int)tmp < 0) != ((int)op_dst < 0);\n");
1057 emit ("context->cycles += 3*op_src;\n");
1058 emit ("context->broken_flags = 0;\n");
1063 rotate (p
, through_carry
, size
, left
)
1064 opcode_entry_type
*p
;
1072 emit ("while (op_src--) {\n");
1073 emit ("int rotbit;\n");
1074 emit ("rotbit = op_dst & 1;\n");
1075 emit ("op_dst = ((unsigned)op_dst) >> 1;\n");
1079 emit ("op_dst |= context->carry << %d;\n", size
- 1);
1083 emit ("op_dst |= rotbit << %d;\n", size
- 1);
1085 emit ("context->carry = rotbit;\n");
1090 emit ("while (op_src--) {\n");
1091 emit ("int rotbit;\n");
1093 emit ("rotbit = (op_dst >> (%d))&1;\n", size
- 1);
1094 emit ("op_dst <<=1;\n");
1097 emit ("if (context->carry) op_dst |=1;\n");
1101 emit ("if (rotbit) op_dst |= 1;\n");
1103 emit ("context->carry = rotbit;\n");
1106 emit ("tmp = (<c_size>)op_dst;\n");
1107 emit ("context->zero = tmp == 0;\n");
1108 emit ("context->sign = (int)tmp < 0;\n");
1109 emit ("context->overflow = ((int)tmp < 0) != ((int)op_dst < 0);\n");
1110 emit ("context->cycles += 3*op_src;\n");
1111 emit ("context->broken_flags = 0;\n");
1117 opcode_entry_type
*p
;
1119 emit ("if (op_src==0)\n");
1121 emit ("context->exception = SIM_DIV_ZERO;\n");
1128 emit ("op_dst.low = (int)get_long_reg(context,reg_dst+2);\n");
1129 emit ("op_dst.high = (int)get_long_reg(context,reg_dst+0);\n");
1131 emit ("tmp = (((long long)op_dst.high << 32) + (op_dst.low)) / (int)op_src;\n");
1133 emit ("tmp = (long)op_dst.low / (int)op_src;\n");
1135 emit ("put_long_reg(context,reg_dst+2, tmp);\n");
1137 emit ("put_long_reg(context,reg_dst, (((long long)op_dst.high << 32) + (op_dst.low)) %% (int)op_src);\n");
1139 emit ("put_long_reg(context,reg_dst, (int)op_dst.low %% (int)op_src);\n");
1142 emit ("context->zero = op_src == 0 || (op_dst.low==0 && op_dst.high==0);\n");
1146 emit ("tmp = (long)op_dst / (short)op_src;\n");
1147 emit ("put_word_reg(context,reg_dst+1, tmp);\n");
1148 emit ("put_word_reg(context,reg_dst, (long) op_dst %% (short)op_src);\n");
1149 emit ("context->zero = op_src == 0 || op_dst==0;\n");
1152 emit ("context->sign = (int)tmp < 0;\n");
1153 emit ("context->overflow =(tmp & 0x%x) != 0;\n",
1154 ~((1 << (p
->type
)) - 1));
1155 emit ("context->carry = (tmp & 0x%x) != 0;\n",
1163 opcode_entry_type
*p
;
1165 emit("context->zero = (op_dst & (1<<op_src))==0;\n");
1166 emit("context->broken_flags = 0;\n");
1170 opcode_entry_type
*p
;
1174 emit (" tmp = op_dst | (1<< op_src);\n");
1176 emit (" tmp = op_dst & ~(1<< op_src);\n");
1181 opcode_entry_type
*p
;
1186 emit ("op_dst.low = get_long_reg(context,reg_dst+2);\n");
1187 emit ("tmp = op_dst.low * op_src;\n");
1188 emit ("put_long_reg(context,reg_dst+2, tmp);\n");
1189 emit ("put_long_reg(context,reg_dst, 0);\n");
1193 emit ("op_dst = get_word_reg(context,reg_dst+1);\n");
1194 emit ("tmp = op_dst * op_src;\n");
1195 emit ("put_long_reg(context,reg_dst, tmp);\n");
1198 emit ("context->sign = (int)tmp < 0;\n");
1199 emit ("context->overflow =0;\n");
1200 emit ("context->carry = (tmp & 0x%x) != 0;\n", ~((1 << (p
->type
)) - 1));
1201 emit ("context->zero = tmp == 0;\n");
1207 opcode_entry_type
*p
;
1209 /* Fetch the ls part of the src */
1210 current_size
= size_name (p
->type
* 2);
1214 emit ("tmp= get_long_reg(context,reg_dst+2);\n");
1215 emit ("if (tmp & (1<<%d)) {\n", p
->type
- 1);
1216 emit ("put_long_reg(context,reg_dst, 0xffffffff);\n");
1220 emit ("put_long_reg(context,reg_dst, 0);\n");
1225 emit ("tmp= get_<size>_reg(context,reg_dst);\n");
1226 emit ("if (tmp & (1<<%d)) {\n", p
->type
- 1);
1227 emit ("tmp |= 0x%x;\n", ~((1 << p
->type
) - 1));
1232 emit ("tmp &= 0x%x;\n", ((1 << p
->type
) - 1));
1234 emit ("put_<size>_reg(context,reg_dst, tmp);\n");
1240 /* Load up the flags */
1241 emit(" COND (context, 0x0b);\n");
1244 emit ("{ int on =1;\n ");
1246 emit ("{ int on =0;\n ");
1248 emit ("if (imm_src & 1)\n");
1249 emit ("PSW_OVERFLOW = on;\n");
1251 emit ("if (imm_src & 2)\n");
1252 emit ("PSW_SIGN = on;\n");
1254 emit ("if (imm_src & 4)\n");
1255 emit ("PSW_ZERO = on;\n");
1257 emit ("if (imm_src & 8)\n");
1258 emit ("PSW_CARRY = on;\n");
1263 /* emit code to perform operation */
1266 opcode_entry_type
*p
;
1272 emit ("tmp = 0;\n");
1277 emit ("tmp = op_src; \n");
1280 emit ("put_<size>_reg(context,reg_src, op_dst);\n");
1284 emit ("put_<size>_mem_da(context, oplval_src, op_dst);\n");
1289 normal_flags (p
, "op_src += COND(context,7);tmp = op_dst + op_src ;",0);
1292 normal_flags (p
, "op_src += COND(context,7);tmp = op_dst - op_src ;",1);
1298 test_normal_flags (p
, "tmp = ~ op_dst", 1);
1302 test_normal_flags (p
, "tmp = op_dst & op_src", 1);
1306 test_normal_flags (p
, "tmp = op_dst ^ op_src", 1);
1310 test_normal_flags (p
, "tmp = op_dst | op_src", 1);
1330 rotate (p
, 0, 16, 1);
1333 rotate (p
, 0, 8, 1);
1336 rotate (p
, 0, 16, 0);
1339 rotate (p
, 0, 8, 0);
1342 rotate (p
, 1, 16, 0);
1345 rotate (p
, 1, 8, 0);
1348 rotate (p
, 1, 16, 1);
1351 rotate (p
, 1, 8, 1);
1364 optimize_normal_flags (p
, "tmp = op_dst + op_src",0);
1369 test_normal_flags (p
, "tmp = op_dst", 0);
1374 normal_flags (p
, "tmp = op_dst - op_src",1);
1379 emit ("int op_src = -op_dst;\n");
1380 emit ("op_dst = 0;\n");
1381 optimize_normal_flags (p
, "tmp = op_dst + op_src;\n",1);
1390 optimize_normal_flags (p
, "tmp = op_dst - op_src",1);
1412 emit ("if(op_cc == 8 || COND(context,op_cc)) put_word_reg(context,reg_dst, 1);\n");
1415 emit ("tmp = oplval_src; \n");
1416 /*(((oplval_src) & 0xff0000) << 8) | (oplval_src & 0xffff); \n");*/
1473 emit ("tmp = fail(context,%d);\n", p
->opcode
);
1478 /* emit code to store result in calculated lvalue */
1482 opcode_entry_type
*p
;
1484 unsigned int *i
= p
->arg_info
;
1488 current_name
= reg_n (*i
);
1489 current_size
= size_name (p
->type
);
1493 switch (*i
& CLASS_MASK
)
1496 emit ("put_<ptr_mode>_reg(context,reg_<name>, tmp);\n");
1498 case CLASS_REG_LONG
:
1499 case CLASS_REG_WORD
:
1500 case CLASS_REG_BYTE
:
1502 emit ("put_<size>_reg(context,reg_<name>,tmp);\n");
1510 emit ("put_<size>_<mem>_da(context,oplval_<name>, tmp);\n");
1526 mangle (p
, shortcut
, value
)
1527 opcode_entry_type
*p
;
1537 emit ("/\052 %s \052/\n", p
->nicename
);
1540 emit ("int <fop>_%04x(context,pc)\n", value
);
1544 emit ("int <fop>_%d(context,pc,iwords0)\n", p
->idx
);
1545 emit ("int iwords0;\n");
1547 emit ("sim_state_type *context;\n");
1550 emit ("register unsigned int tmp;\n");
1553 emit ("register unsigned int iwords0 = 0x%x;\n", value
);
1556 /* work out how much bigger this opcode could be because it's large
1563 for (i
= 0; i
< 4; i
++)
1565 if ((p
->arg_info
[i
] & CLASS_MASK
) == CLASS_DA
1566 || (p
->arg_info
[i
] & CLASS_MASK
) == CLASS_X
)
1574 printf (" /* Length %d */ \n", p
->length
+ extra
);
1575 switch (p
->length
+ extra
)
1578 emit ("pc += 2\n;");
1581 emit ("register unsigned int iwords1 = get_word_mem_da(context,pc+2);\n");
1582 emit ("pc += 4;\n");
1586 emit ("register unsigned int iwords1 = get_word_mem_da(context,pc+2);\n");
1587 emit ("register unsigned int iwords2 = get_word_mem_da(context,pc+4);\n");
1588 emit ("pc += 6;\n");
1591 emit ("register unsigned int iwords1 = get_word_mem_da(context,pc+2);\n");
1592 emit ("register unsigned int iwords2 = get_word_mem_da(context,pc+4);\n");
1593 emit ("register unsigned int iwords3 = get_word_mem_da(context,pc+6);\n");
1594 emit ("pc += 8;\n");
1600 emit ("context->cycles += %d;\n", p
->cycles
);
1604 info_special (p
, &getdst
, &nostore
, &before
, &nosrc
);
1609 info_fetch (p
, getdst
);
1623 emit ("return pc;\n");
1632 /* find the table entry */
1633 opcode_entry_type
*p
= z8k_table
+ i
;
1641 add_to_list (ptr
, value
)
1642 struct opcode_value
**ptr
;
1645 struct opcode_value
*prev
;
1648 *ptr
= (struct opcode_value
*) malloc (sizeof (struct opcode_value
));
1651 (*ptr
)->next
= prev
;
1658 opcode_entry_type
*p
= lookup_inst (i
);
1662 add_to_list (&list
[p
->idx
], i
);
1675 for (i
= 1; i
< ac
; i
++)
1677 if (strcmp (av
[i
], "-m") == 0)
1679 if (strcmp (av
[i
], "-1") == 0)
1681 if (strcmp (av
[i
], "-2") == 0)
1683 if (strcmp (av
[i
], "-3") == 0)
1685 if (strcmp (av
[i
], "-b3") == 0)
1697 printf ("short int z8k_inv_list[] = {\n");
1699 for (i
= 0; i
< 1 << 16; i
++)
1701 opcode_entry_type
*p
= lookup_inst (i
);
1709 printf ("\n /*%04x %s */", i
, p
? p
->nicename
: "");
1718 printf ("%d", p
->idx
);
1721 if ((i
& 0x3f) == 0 && DIRTY_HACK
)
1723 printf ("\n#ifdef __GNUC__\n");
1725 printf("short int int_list%d[] = {\n", i
);
1728 printf ("#endif\n");
1739 /* First work out which opcodes use which bit patterns,
1740 build a list of all matching bit pattens */
1741 for (i
= 0; i
< 1 << 16; i
++)
1746 for (i
= 0; i
< NOPS
; i
++)
1748 struct opcode_value
*p
;
1754 printf (" %04x,", p
->n
);
1766 /* Do the shortcuts */
1767 printf (" /* SHORTCUTS */\n");
1768 for (i
= 0; quick
[i
]; i
++)
1772 mangle (z8k_table
+ z8k_inv_list
[t
],
1779 printf (" /* NOT -SHORTCUTS */\n");
1780 for (i
= 0; i
< NOPS
; i
++)
1784 one_instruction (i
);
1788 emit ("int <fop>_%d(context,pc)\n", i
);
1789 printf ("sim_state_type *context;\n");
1790 printf ("int pc;\n");
1791 emit ("{ <fop>_bad1();return pc; }\n");
1794 emit ("int <fop>_bad() ;\n");
1796 /* Write the jump table */
1797 emit ("int (*(<fop>_table[]))() = {");
1799 for (i
= 0; i
< NOPS
; i
++)
1803 emit ("<fop>_%d\n", i
);
1805 if ((i
& 0x3f) == 0 && DIRTY_HACK
)
1807 printf ("#ifdef __GNUC__\n");
1809 emit ("int (*(<fop>_table%d[]))() = {\n", i
);
1812 printf ("#endif\n");
1822 /* Static - since it's too be to be automatic on the apollo */
1823 static int big
[64 * 1024];
1825 for (i
= 0; i
< 64 * 1024; i
++)
1828 for (i
= 0; quick
[i
]; i
++)
1832 printf ("extern int <fop>_%04x();\n", quick
[i
]);
1838 for (i
= 0; i
< NOPS
; i
++)
1841 printf ("extern int fop_%d();\n", i
);
1845 printf ("extern int fop_bad();\n");
1847 printf ("struct op_info op_info_table[] = {\n");
1848 for (i
= 0; i
< 1 << 16; i
++)
1850 int inv
= z8k_inv_list
[i
];
1851 opcode_entry_type
*p
= z8k_table
+ inv
;
1858 printf ("<fop>_%04x", i
);
1870 printf (" /* %04x %s */\n", i
, p
->nicename
);
1877 if ((i
& 0x3f) == 0 && DIRTY_HACK
)
1879 printf ("#ifdef __GNUC__\n");
1881 printf ("struct op_info op_info_table%d[] = {\n", i
);
1885 printf ("#endif\n");
1909 return "fail(context,123)";
1913 /* work out if the opcode only wants lvalues */
1916 opcode_entry_type
*p
;
1931 info_len_in_words (o
)
1932 opcode_entry_type
*o
;
1934 unsigned int *p
= o
->byte_info
;
1939 switch (*p
& CLASS_MASK
)
1949 nibs
+= SIZE_ADDRESS
;
1952 switch (*p
& ~CLASS_MASK
)
1965 case ARG_IMMNMINUS1
:
1978 switch (*p
& ~CLASS_MASK
)
1998 case CLASS_BIT_1OR2
:
2005 emit ("don't know %x\n", *p
);
2010 return nibs
/ 4; /* return umber of words */