1 /* generate instructions for Z8KSIM
3 Copyright 1992, 1993, 2002 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
61 #include "../opcodes/z8k-opc.h"
68 struct opcode_value
*next
;
74 static char *reg_names
[] =
75 {"bad", "src", "dst", "aux_a", "aux_b", "aux_r", "aux_x"};
77 #define IS_DST(x) ((x & 0xf) == 2)
78 #define IS_SRC(x) ((x & 0xf)==1)
79 #define SIZE_ADDRESS (BIG ? 8 : 4) /* number of nibbles in a ptr*/
85 static char *current_size
;
86 static char *current_name
;
87 static char current_word0
[40];
88 static char current_byte0
[40];
89 static char current_byte1
[40];
94 struct opcode_value
*list
[NOPS
];
96 static opcode_entry_type
*
100 static short *z8k_inv_list
= NULL
;
101 const nr_z8k_inv_list_elements
= 1 << 16;
102 if (z8k_inv_list
== NULL
)
104 /* Initialize the list to 0xff == -1 */
105 z8k_inv_list
= calloc (nr_z8k_inv_list_elements
, sizeof (short));
106 memset (z8k_inv_list
, 0xff, nr_z8k_inv_list_elements
* sizeof (short));
108 /* Entry empty? Fill it in. */
109 if (z8k_inv_list
[what
] == -1)
114 unsigned short instr_nibl
;
115 unsigned short tabl_datum
, datum_class
, datum_value
;
116 char instr_nibbles
[8];
118 opcode_entry_type
*ptr
= z8k_table
;
122 instr_nibbles
[3] = (what
>> 0) & 0xf;
123 instr_nibbles
[2] = (what
>> 4) & 0xf;
124 instr_nibbles
[1] = (what
>> 8) & 0xf;
125 instr_nibbles
[0] = (what
>> 12) & 0xf;
127 /* Assume it won't be found. */
128 z8k_inv_list
[what
] = -2;
133 for (nibl_index
= 0; nibl_index
< 4 && nibl_matched
; nibl_index
++)
135 instr_nibl
= instr_nibbles
[nibl_index
];
137 tabl_datum
= ptr
->byte_info
[nibl_index
];
138 datum_class
= tabl_datum
& CLASS_MASK
;
139 datum_value
= ~CLASS_MASK
& tabl_datum
;
144 if (datum_value
!= (instr_nibl
& ~0x2))
151 if (datum_value
!= instr_nibl
)
155 if (!((~instr_nibl
) & 0x4))
159 if (!(instr_nibl
& 0x4))
163 if (!((~instr_nibl
) & 0x8))
167 if (!(instr_nibl
& 0x8))
171 if (!((~instr_nibl
) & 0x8))
176 if (!(instr_nibl
& 0x8))
190 z8k_inv_list
[what
] = ptr
->idx
;
196 if (z8k_inv_list
[what
] >= 0)
197 return z8k_table
+ z8k_inv_list
[what
];
208 return "((iwords_0>>8) & 0xf)";
210 return "((ibytes_1 >> 4) & 0xf)";
212 return "((ibytes_1) & 0xf)";
214 return "((ibytes_2>>4) & 0xf)";
216 return "((ibytes_2) & 0xf)";
218 return "((ibytes_3 >> 4) & 0xf)";
220 return "((ibytes_3) & 0xf)";
249 return reg_names
[x
& 0xf];
255 return BIG
? "14" : "15";
262 return BIG
? "segmem" : "unsegmem";
272 if (strncmp (p
, a
, strlen (a
)) == 0)
285 sprintf (d
, "%s", y
);
316 return "((iwords_0<<16) | (iwords_1))";
318 return "((iwords_1<<16) | (iwords_2))";
320 return "((iwords_2<<16) | (iwords_3))";
346 emit (string
, a1
, a2
, a3
, a4
, a5
)
375 else if (match ("<iptr>"))
382 sub ("(((iwords_1 << 8) | (iwords_2)) & 0x7fffff)");
385 sub ("fail(context,124)");
397 sub ("fail(context,123)");
402 else if (match ("<name>"))
406 else if (match ("<size>"))
410 else if (match ("<insn_4>"))
414 else if (match ("<insn_16>"))
416 sub (insn_16 (nibs
));
418 else if (match ("<insn_32>"))
420 sub (insn_32 (nibs
));
422 else if (match ("iwords_0"))
426 else if (match ("ibytes_0"))
430 else if (match ("<ibytes_1>"))
434 else if (match ("<next_size>"))
436 if (strcmp (current_size
, "word") == 0)
438 if (strcmp (current_size
, "byte") == 0)
440 else if (strcmp (current_size
, "long") == 0)
445 else if (match ("<addr_type>"))
448 sub ("unsigned long");
450 sub ("unsigned short");
453 else if (match ("<c_size>"))
455 if (strcmp (current_size
, "word") == 0)
457 else if (strcmp (current_size
, "byte") == 0)
459 else if (strcmp (current_size
, "long") == 0)
465 else if (match ("<pc>"))
469 else if (match ("<mem>"))
473 else if (match ("<sp>"))
477 else if (match ("<ptr_size>"))
481 else if (match ("<ptr_mode>"))
485 else if (match ("<insn_8>"))
490 sub ("(iwords_0&0xff)");
493 sub ("(iwords_1>>8)");
496 sub ("(iwords_1&0xff)");
499 sub ("(iwords_2>>8)");
502 sub ("(/* WHO */iwords_3&0xff)");
519 indent
-= indent_dec
;
520 for (i
= 0; i
< indent
; i
++)
522 indent
+= indent_inc
;
523 printf (buffer
, a1
, a2
, a3
, a4
, a5
);
527 /* fetch the lvalues of the operands */
530 opcode_entry_type
*p
;
534 int done_one_imm8
= 0;
536 /* int done_read = 4;*/
541 switch (*s
& CLASS_MASK
)
544 emit ("register unsigned int imm_src=(<insn_4>& 2)?2:1;\n");
548 /* Just ignore these, we've already decoded this bit */
553 /* this nibble tells us which register to use as an arg,
554 if we've already gobbled the nibble we know what to use */
556 int regname
= *s
& 0xf;
558 emit ("register unsigned int reg_%s=<insn_4>;\n",
565 emit ("register unsigned base_%s=<iptr>;\n", reg_n (*s
));
567 nibs
+= SIZE_ADDRESS
;
572 emit ("register unsigned int imm_src=<insn_4>&0x2;\n");
576 emit ("register unsigned int imm_src=<insn_4>;\n");
580 /* Work out the size of the think to fetch */
583 switch (*s
& ~CLASS_MASK
)
586 emit ("register unsigned imm_src=<insn_16>;\n");
590 emit ("register unsigned int imm_src= %s;\n", insn_32 (nibs
));
594 emit ("register unsigned int imm_src=<insn_4>;\n");
598 emit ("register unsigned int imm_src = - <insn_4>;\n");
602 emit ("register unsigned int imm_src=<insn_4> & 0x2;\n");
607 emit ("register unsigned int imm_src=(<insn_4> + 1);\n");
611 emit ("register unsigned int imm_src=1;\n");
614 emit ("register unsigned int imm_src=2;\n");
617 emit ("register unsigned int imm_src=-<insn_8>;\n");
623 emit ("register unsigned int imm_src=<insn_8>;\n");
629 emit ("register int fail%d=fail(context,1);\n", nibs
);
635 /* We can't use `(char)' since char might be unsigned.
636 We can't use `(signed char)' because the compiler might be K&R.
637 This seems safe, since it only assumes that bytes are 8
639 emit ("register unsigned int oplval_dst=((ibytes_1 << (sizeof (int) * 8 - 8)) >> (sizeof (int) * 8 - 9)) + pc;\n");
641 /* Original code: fails if characters are unsigned. */
642 emit ("register unsigned int oplval_dst=(((char)ibytes_1)<<1) + pc;\n");
647 emit ("register unsigned int op_cc=<insn_4>;\n");
651 emit ("register int FAIL%d=fail(context,2);\n", nibs
);
655 /* work out how to fetch the immediate value */
663 info_special (p
, getdst
, nostore
, before
, nosrc
)
664 opcode_entry_type
*p
;
776 /* calculate the lvalues required for the opcode */
779 opcode_entry_type
*p
;
781 /* emit code to work out lvalues, if any */
782 unsigned int *i
= p
->arg_info
;
786 current_name
= reg_n (*i
);
787 current_size
= size_name (p
->type
);
788 switch (*i
& CLASS_MASK
)
792 emit ("register <addr_type> oplval_<name>= ((base_<name> + (short)get_word_reg(context,reg_<name>)) & 0xffff) + (base_<name> & ~0xffff);\n");
795 /* Indirect register */
796 emit ("register int oplval_<name> = get_<ptr_mode>_reg(context,reg_<name>);\n");
799 emit ("register int oplval_<name>=base_<name>;\n");
808 emit ("register int oplval_<name> = get_<ptr_mode>_reg(context,reg_<name>) + (short)(imm_src);\n");
811 emit ("register int oplval_<name> = get_<ptr_mode>_reg(context,reg_<name>)\n");
812 emit (" + get_word_reg(context,reg_aux_x);\n");
819 /* emit code to fetch the args from calculated lvalues */
822 info_fetch (p
, getdst
)
823 opcode_entry_type
*p
;
826 unsigned int *i
= p
->arg_info
;
833 current_name
= reg_n (*i
);
834 current_size
= size_name (p
->type
);
835 switch (*i
& CLASS_MASK
)
842 if (!getdst
&& IS_DST (*i
))
844 emit ("register int op_<name>= get_<size>_<mem>_da(context,oplval_<name>);\n");
850 if (p
->opcode
== OPC_out
||
851 p
->opcode
== OPC_outb
||
852 p
->opcode
== OPC_sout
||
853 p
->opcode
== OPC_soutb
)
855 /* The imm is a dest here */
856 emit ("register int op_dst = imm_src;\n");
860 emit ("register int op_src = imm_src;\n");
865 if (!getdst
&& IS_DST (*i
))
867 had_src
|= IS_SRC (*i
);
868 emit ("UDItype op_<name> ;\n");
872 if (!getdst
&& IS_DST (*i
))
874 had_src
|= IS_SRC (*i
);
875 emit ("register int op_<name> = get_word_reg(context,reg_<name>);\n");
879 if (!getdst
&& IS_DST (*i
))
881 had_src
|= IS_SRC (*i
);
882 emit ("register int op_<name> = get_long_reg(context,reg_<name>);\n");
885 if (!getdst
&& IS_DST (*i
))
887 had_src
|= IS_SRC (*i
);
888 emit ("register int op_<name> = get_byte_reg(context,reg_<name>);\n");
896 normal_flags (p
, s
, neg
)
897 opcode_entry_type
*p
;
901 emit ("NORMAL_FLAGS(context,%d, tmp, op_dst, op_src,%d); \n", p
->type
,neg
);
905 test_normal_flags (p
, s
, opt
)
906 opcode_entry_type
*p
;
913 emit ("context->broken_flags = TST_FLAGS;\n");
914 emit ("context->size = %d;\n", p
->type
);
918 emit ("TEST_NORMAL_FLAGS(context,%d, tmp); \n", p
->type
);
924 optimize_normal_flags (p
, s
,neg
)
925 opcode_entry_type
*p
;
930 emit ("context->broken_flags = CMP_FLAGS;\n");
932 emit ("NORMAL_FLAGS(context,%d, tmp, op_dst, op_src,%d); \n", p
->type
, neg
);
939 opcode_entry_type
*p
;
942 emit ("if(op_cc == 8 || COND(context,op_cc)) pc = oplval_dst;\n");
947 opcode_entry_type
*p
;
949 emit ("if(op_cc == 8 || COND(context,op_cc)) pc = oplval_dst;\n");
954 opcode_entry_type
*p
;
956 emit ("if(op_cc == 8 || COND(context,op_cc))\n{\n");
957 emit ("pc = get_<ptr_mode>_<mem>_ir(context,<sp>);\n");
958 emit ("put_<ptr_mode>_reg(context,<sp>, get_<ptr_mode>_reg(context,<sp>) + <ptr_size>);\n");
964 opcode_entry_type
*p
;
966 emit ("put_<ptr_mode>_reg(context,<sp>,tmp = get_<ptr_mode>_reg(context,<sp>) - <ptr_size>);\n");
967 emit ("put_<ptr_mode>_<mem>_da(context,tmp, pc);\n");
968 emit ("pc = oplval_dst;\n");
973 opcode_entry_type
*p
;
975 emit ("tmp = op_src;\n");
976 emit ("oplval_dst -= %d;\n", p
->type
/ 8);
977 emit ("put_<ptr_mode>_reg(context,reg_dst, oplval_dst);\n");
982 opcode_entry_type
*p
;
984 emit ("tmp = op_src;\n");
985 emit ("put_<ptr_mode>_reg(context,reg_src, oplval_src + %d);\n", p
->type
/ 8);
990 opcode_entry_type
*p
;
992 emit ("tmp = op_src;\n");
998 emit ("support_call(context,imm_src);\n");
1004 emit ("pc -=2; \n");
1005 emit ("context->exception = SIM_BREAKPOINT;\n");
1010 opcode_entry_type
*p
;
1014 int dinc
= (size
/ 8) * inc
;
1016 current_size
= size_name (size
);
1018 emit ("int type = %s;\n", insn_4 (7));
1019 emit ("int rs = get_<ptr_mode>_reg(context,reg_src);\n");
1020 emit ("int rd = get_<ptr_mode>_reg(context,reg_dst);\n");
1021 emit ("int rr = get_word_reg(context,reg_aux_r);\n");
1023 emit ("put_<size>_<mem>_da(context,rd, get_<size>_<mem>_da(context,rs));\n");
1024 emit ("rd += %d;\n", dinc
);
1025 emit ("rs += %d;\n", dinc
);
1027 emit ("context->cycles += 9;\n");
1028 emit ("} while (!type && rr != 0 && context->exception <= 1);\n");
1029 emit ("if (context->exception>1) pc -=4;\n");
1030 emit ("put_<ptr_mode>_reg(context,reg_src, rs);\n");
1031 emit ("put_<ptr_mode>_reg(context,reg_dst, rd);\n");
1032 emit ("put_word_reg(context,reg_aux_r, rr);\n");
1039 opcode_entry_type
*p
;
1043 /* We can't use `(char)' since char might be unsigned.
1044 We can't use `(signed char)' because the compiler might be K&R.
1045 This seems safe, since it only assumes that bytes are 8 bits. */
1046 emit ("op_src = (op_src << (sizeof (int) * 8 - 8)) >> (sizeof (int) * 8 - 8);\n");
1048 /* Original code: fails if characters are unsigned. */
1049 emit ("op_src = (char)op_src;\n");
1051 emit ("if (op_src < 0) \n");
1053 emit ("op_src = -op_src;\n");
1054 emit ("op_dst = (%s <c_size>)op_dst;\n", arith
? "" : "unsigned");
1055 emit ("tmp = (%s op_dst) >> op_src;\n", arith
? "" : "(unsigned)");
1056 emit ("context->carry = op_dst >> (op_src-1);\n", p
->type
);
1060 emit ("tmp = op_dst << op_src;\n");
1061 emit ("context->carry = op_dst >> (%d - op_src);\n", p
->type
);
1063 emit ("context->zero = (<c_size>)tmp == 0;\n");
1064 emit ("context->sign = (int)((<c_size>)tmp) < 0;\n");
1065 emit ("context->overflow = ((int)tmp < 0) != ((int)op_dst < 0);\n");
1066 emit ("context->cycles += 3*op_src;\n");
1067 emit ("context->broken_flags = 0;\n");
1072 rotate (p
, through_carry
, size
, left
)
1073 opcode_entry_type
*p
;
1081 emit ("while (op_src--) {\n");
1082 emit ("int rotbit;\n");
1083 emit ("rotbit = op_dst & 1;\n");
1084 emit ("op_dst = ((unsigned)op_dst) >> 1;\n");
1088 emit ("op_dst |= context->carry << %d;\n", size
- 1);
1092 emit ("op_dst |= rotbit << %d;\n", size
- 1);
1094 emit ("context->carry = rotbit;\n");
1099 emit ("while (op_src--) {\n");
1100 emit ("int rotbit;\n");
1102 emit ("rotbit = (op_dst >> (%d))&1;\n", size
- 1);
1103 emit ("op_dst <<=1;\n");
1106 emit ("if (context->carry) op_dst |=1;\n");
1110 emit ("if (rotbit) op_dst |= 1;\n");
1112 emit ("context->carry = rotbit;\n");
1115 emit ("tmp = (<c_size>)op_dst;\n");
1116 emit ("context->zero = tmp == 0;\n");
1117 emit ("context->sign = (int)tmp < 0;\n");
1118 emit ("context->overflow = ((int)tmp < 0) != ((int)op_dst < 0);\n");
1119 emit ("context->cycles += 3*op_src;\n");
1120 emit ("context->broken_flags = 0;\n");
1126 opcode_entry_type
*p
;
1128 emit ("if (op_src==0)\n");
1130 emit ("context->exception = SIM_DIV_ZERO;\n");
1137 emit ("op_dst.low = (int)get_long_reg(context,reg_dst+2);\n");
1138 emit ("op_dst.high = (int)get_long_reg(context,reg_dst+0);\n");
1140 emit ("tmp = (((long long)op_dst.high << 32) + (op_dst.low)) / (int)op_src;\n");
1142 emit ("tmp = (long)op_dst.low / (int)op_src;\n");
1144 emit ("put_long_reg(context,reg_dst+2, tmp);\n");
1146 emit ("put_long_reg(context,reg_dst, (((long long)op_dst.high << 32) + (op_dst.low)) %% (int)op_src);\n");
1148 emit ("put_long_reg(context,reg_dst, (int)op_dst.low %% (int)op_src);\n");
1151 emit ("context->zero = op_src == 0 || (op_dst.low==0 && op_dst.high==0);\n");
1155 emit ("tmp = (long)op_dst / (short)op_src;\n");
1156 emit ("put_word_reg(context,reg_dst+1, tmp);\n");
1157 emit ("put_word_reg(context,reg_dst, (long) op_dst %% (short)op_src);\n");
1158 emit ("context->zero = op_src == 0 || op_dst==0;\n");
1161 emit ("context->sign = (int)tmp < 0;\n");
1162 emit ("context->overflow =(tmp & 0x%x) != 0;\n",
1163 ~((1 << (p
->type
)) - 1));
1164 emit ("context->carry = (tmp & 0x%x) != 0;\n",
1172 opcode_entry_type
*p
;
1174 emit("context->zero = (op_dst & (1<<op_src))==0;\n");
1175 emit("context->broken_flags = 0;\n");
1179 opcode_entry_type
*p
;
1183 emit (" tmp = op_dst | (1<< op_src);\n");
1185 emit (" tmp = op_dst & ~(1<< op_src);\n");
1190 opcode_entry_type
*p
;
1195 emit ("op_dst.low = get_long_reg(context,reg_dst+2);\n");
1196 emit ("tmp = op_dst.low * op_src;\n");
1197 emit ("put_long_reg(context,reg_dst+2, tmp);\n");
1198 emit ("put_long_reg(context,reg_dst, 0);\n");
1202 emit ("op_dst = get_word_reg(context,reg_dst+1);\n");
1203 emit ("tmp = op_dst * op_src;\n");
1204 emit ("put_long_reg(context,reg_dst, tmp);\n");
1207 emit ("context->sign = (int)tmp < 0;\n");
1208 emit ("context->overflow =0;\n");
1209 emit ("context->carry = (tmp & 0x%x) != 0;\n", ~((1 << (p
->type
)) - 1));
1210 emit ("context->zero = tmp == 0;\n");
1216 opcode_entry_type
*p
;
1218 /* Fetch the ls part of the src */
1219 current_size
= size_name (p
->type
* 2);
1223 emit ("tmp= get_long_reg(context,reg_dst+2);\n");
1224 emit ("if (tmp & (1<<%d)) {\n", p
->type
- 1);
1225 emit ("put_long_reg(context,reg_dst, 0xffffffff);\n");
1229 emit ("put_long_reg(context,reg_dst, 0);\n");
1234 emit ("tmp= get_<size>_reg(context,reg_dst);\n");
1235 emit ("if (tmp & (1<<%d)) {\n", p
->type
- 1);
1236 emit ("tmp |= 0x%x;\n", ~((1 << p
->type
) - 1));
1241 emit ("tmp &= 0x%x;\n", ((1 << p
->type
) - 1));
1243 emit ("put_<size>_reg(context,reg_dst, tmp);\n");
1249 /* Load up the flags */
1250 emit(" COND (context, 0x0b);\n");
1253 emit ("{ int on =1;\n ");
1255 emit ("{ int on =0;\n ");
1257 emit ("if (imm_src & 1)\n");
1258 emit ("PSW_OVERFLOW = on;\n");
1260 emit ("if (imm_src & 2)\n");
1261 emit ("PSW_SIGN = on;\n");
1263 emit ("if (imm_src & 4)\n");
1264 emit ("PSW_ZERO = on;\n");
1266 emit ("if (imm_src & 8)\n");
1267 emit ("PSW_CARRY = on;\n");
1272 /* emit code to perform operation */
1275 opcode_entry_type
*p
;
1281 emit ("tmp = 0;\n");
1286 emit ("tmp = op_src; \n");
1289 emit ("put_<size>_reg(context,reg_src, op_dst);\n");
1293 emit ("put_<size>_mem_da(context, oplval_src, op_dst);\n");
1298 normal_flags (p
, "op_src += COND(context,7);tmp = op_dst + op_src ;",0);
1301 normal_flags (p
, "op_src += COND(context,7);tmp = op_dst - op_src ;",1);
1307 test_normal_flags (p
, "tmp = ~ op_dst", 1);
1311 test_normal_flags (p
, "tmp = op_dst & op_src", 1);
1315 test_normal_flags (p
, "tmp = op_dst ^ op_src", 1);
1319 test_normal_flags (p
, "tmp = op_dst | op_src", 1);
1339 rotate (p
, 0, 16, 1);
1342 rotate (p
, 0, 8, 1);
1345 rotate (p
, 0, 16, 0);
1348 rotate (p
, 0, 8, 0);
1351 rotate (p
, 1, 16, 0);
1354 rotate (p
, 1, 8, 0);
1357 rotate (p
, 1, 16, 1);
1360 rotate (p
, 1, 8, 1);
1373 optimize_normal_flags (p
, "tmp = op_dst + op_src",0);
1378 test_normal_flags (p
, "tmp = op_dst", 0);
1383 normal_flags (p
, "tmp = op_dst - op_src",1);
1388 emit ("int op_src = -op_dst;\n");
1389 emit ("op_dst = 0;\n");
1390 optimize_normal_flags (p
, "tmp = op_dst + op_src;\n",1);
1399 optimize_normal_flags (p
, "tmp = op_dst - op_src",1);
1421 emit ("if(op_cc == 8 || COND(context,op_cc)) put_word_reg(context,reg_dst, 1);\n");
1424 emit ("tmp = oplval_src; \n");
1425 /*(((oplval_src) & 0xff0000) << 8) | (oplval_src & 0xffff); \n");*/
1482 emit ("tmp = fail(context,%d);\n", p
->opcode
);
1487 /* emit code to store result in calculated lvalue */
1491 opcode_entry_type
*p
;
1493 unsigned int *i
= p
->arg_info
;
1497 current_name
= reg_n (*i
);
1498 current_size
= size_name (p
->type
);
1502 switch (*i
& CLASS_MASK
)
1505 emit ("put_<ptr_mode>_reg(context,reg_<name>, tmp);\n");
1507 case CLASS_REG_LONG
:
1508 case CLASS_REG_WORD
:
1509 case CLASS_REG_BYTE
:
1511 emit ("put_<size>_reg(context,reg_<name>,tmp);\n");
1519 emit ("put_<size>_<mem>_da(context,oplval_<name>, tmp);\n");
1535 mangle (p
, shortcut
, value
)
1536 opcode_entry_type
*p
;
1546 emit ("/\052 %s \052/\n", p
->nicename
);
1549 emit ("int <fop>_%04x(context,pc)\n", value
);
1553 emit ("int <fop>_%d(context,pc,iwords0)\n", p
->idx
);
1554 emit ("int iwords0;\n");
1556 emit ("sim_state_type *context;\n");
1559 emit ("register unsigned int tmp;\n");
1562 emit ("register unsigned int iwords0 = 0x%x;\n", value
);
1565 /* work out how much bigger this opcode could be because it's large
1572 for (i
= 0; i
< 4; i
++)
1574 if ((p
->arg_info
[i
] & CLASS_MASK
) == CLASS_DA
1575 || (p
->arg_info
[i
] & CLASS_MASK
) == CLASS_X
)
1583 printf (" /* Length %d */ \n", p
->length
+ extra
);
1584 switch (p
->length
+ extra
)
1587 emit ("pc += 2\n;");
1590 emit ("register unsigned int iwords1 = get_word_mem_da(context,pc+2);\n");
1591 emit ("pc += 4;\n");
1595 emit ("register unsigned int iwords1 = get_word_mem_da(context,pc+2);\n");
1596 emit ("register unsigned int iwords2 = get_word_mem_da(context,pc+4);\n");
1597 emit ("pc += 6;\n");
1600 emit ("register unsigned int iwords1 = get_word_mem_da(context,pc+2);\n");
1601 emit ("register unsigned int iwords2 = get_word_mem_da(context,pc+4);\n");
1602 emit ("register unsigned int iwords3 = get_word_mem_da(context,pc+6);\n");
1603 emit ("pc += 8;\n");
1609 emit ("context->cycles += %d;\n", p
->cycles
);
1613 info_special (p
, &getdst
, &nostore
, &before
, &nosrc
);
1618 info_fetch (p
, getdst
);
1632 emit ("return pc;\n");
1641 /* find the table entry */
1642 opcode_entry_type
*p
= z8k_table
+ i
;
1650 add_to_list (ptr
, value
)
1651 struct opcode_value
**ptr
;
1654 struct opcode_value
*prev
;
1657 *ptr
= (struct opcode_value
*) malloc (sizeof (struct opcode_value
));
1660 (*ptr
)->next
= prev
;
1667 opcode_entry_type
*p
= lookup_inst (i
);
1671 add_to_list (&list
[p
->idx
], i
);
1682 for (i
= 1; i
< ac
; i
++)
1684 if (strcmp (av
[i
], "-1") == 0)
1686 if (strcmp (av
[i
], "-2") == 0)
1688 if (strcmp (av
[i
], "-3") == 0)
1690 if (strcmp (av
[i
], "-b3") == 0)
1698 /* First work out which opcodes use which bit patterns,
1699 build a list of all matching bit pattens */
1700 for (i
= 0; i
< 1 << 16; i
++)
1705 for (i
= 0; i
< NOPS
; i
++)
1707 struct opcode_value
*p
;
1713 printf (" %04x,", p
->n
);
1725 /* Do the shortcuts */
1726 printf (" /* SHORTCUTS */\n");
1727 for (i
= 0; quick
[i
]; i
++)
1731 mangle (lookup_inst (t
), 1, t
);
1736 printf (" /* NOT -SHORTCUTS */\n");
1737 for (i
= 0; i
< NOPS
; i
++)
1741 one_instruction (i
);
1745 emit ("int <fop>_%d(context,pc)\n", i
);
1746 printf ("sim_state_type *context;\n");
1747 printf ("int pc;\n");
1748 emit ("{ <fop>_bad1();return pc; }\n");
1751 emit ("int <fop>_bad() ;\n");
1753 /* Write the jump table */
1754 emit ("int (*(<fop>_table[]))() = {");
1756 for (i
= 0; i
< NOPS
; i
++)
1760 emit ("<fop>_%d\n", i
);
1769 /* Static - since it's too be to be automatic on the apollo */
1770 static int big
[64 * 1024];
1772 for (i
= 0; i
< 64 * 1024; i
++)
1775 for (i
= 0; quick
[i
]; i
++)
1779 printf ("extern int <fop>_%04x();\n", quick
[i
]);
1785 for (i
= 0; i
< NOPS
; i
++)
1788 printf ("extern int fop_%d();\n", i
);
1792 printf ("extern int fop_bad();\n");
1794 printf ("struct op_info op_info_table[] = {\n");
1795 for (i
= 0; i
< 1 << 16; i
++)
1797 opcode_entry_type
*p
= lookup_inst (i
);
1804 printf ("<fop>_%04x", i
);
1810 printf ("%d", p
->idx
);
1816 printf (" /* %04x %s */\n", i
, p
->nicename
);
1844 return "fail(context,123)";
1848 /* work out if the opcode only wants lvalues */
1851 opcode_entry_type
*p
;
1866 info_len_in_words (o
)
1867 opcode_entry_type
*o
;
1869 unsigned int *p
= o
->byte_info
;
1874 switch (*p
& CLASS_MASK
)
1885 nibs
+= SIZE_ADDRESS
;
1888 switch (*p
& ~CLASS_MASK
)
1902 case ARG_IMMNMINUS1
:
1915 switch (*p
& ~CLASS_MASK
)
1935 case CLASS_BIT_1OR2
:
1942 emit ("don't know %x\n", *p
);
1947 return nibs
/ 4; /* return umber of words */
This page took 0.069875 seconds and 4 git commands to generate.