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))
145 if (datum_value
!= instr_nibl
)
149 if (!((~instr_nibl
) & 0x4))
153 if (!(instr_nibl
& 0x4))
157 if (!((~instr_nibl
) & 0x8))
161 if (!(instr_nibl
& 0x8))
165 if (!((~instr_nibl
) & 0x8))
170 if (!(instr_nibl
& 0x8))
193 if (z8k_inv_list
[what
] < 0)
195 return z8k_table
+ z8k_inv_list
[what
];
206 return "((iwords_0>>8) & 0xf)";
208 return "((ibytes_1 >> 4) & 0xf)";
210 return "((ibytes_1) & 0xf)";
212 return "((ibytes_2>>4) & 0xf)";
214 return "((ibytes_2) & 0xf)";
216 return "((ibytes_3 >> 4) & 0xf)";
218 return "((ibytes_3) & 0xf)";
247 return reg_names
[x
& 0xf];
253 return BIG
? "14" : "15";
260 return BIG
? "segmem" : "unsegmem";
270 if (strncmp (p
, a
, strlen (a
)) == 0)
283 sprintf (d
, "%s", y
);
314 return "((iwords_0<<16) | (iwords_1))";
316 return "((iwords_1<<16) | (iwords_2))";
318 return "((iwords_2<<16) | (iwords_3))";
344 emit (string
, a1
, a2
, a3
, a4
, a5
)
373 else if (match ("<iptr>"))
380 sub ("(((iwords_1 << 8) | (iwords_2)) & 0x7fffff)");
383 sub ("fail(context,124)");
395 sub ("fail(context,123)");
400 else if (match ("<name>"))
404 else if (match ("<size>"))
408 else if (match ("<insn_4>"))
412 else if (match ("<insn_16>"))
414 sub (insn_16 (nibs
));
416 else if (match ("<insn_32>"))
418 sub (insn_32 (nibs
));
420 else if (match ("iwords_0"))
424 else if (match ("ibytes_0"))
428 else if (match ("<ibytes_1>"))
432 else if (match ("<next_size>"))
434 if (strcmp (current_size
, "word") == 0)
436 if (strcmp (current_size
, "byte") == 0)
438 else if (strcmp (current_size
, "long") == 0)
443 else if (match ("<addr_type>"))
446 sub ("unsigned long");
448 sub ("unsigned short");
451 else if (match ("<c_size>"))
453 if (strcmp (current_size
, "word") == 0)
455 else if (strcmp (current_size
, "byte") == 0)
457 else if (strcmp (current_size
, "long") == 0)
463 else if (match ("<pc>"))
467 else if (match ("<mem>"))
471 else if (match ("<sp>"))
475 else if (match ("<ptr_size>"))
479 else if (match ("<ptr_mode>"))
483 else if (match ("<insn_8>"))
488 sub ("(iwords_0&0xff)");
491 sub ("(iwords_1>>8)");
494 sub ("(iwords_1&0xff)");
497 sub ("(iwords_2>>8)");
500 sub ("(/* WHO */iwords_3&0xff)");
517 indent
-= indent_dec
;
518 for (i
= 0; i
< indent
; i
++)
520 indent
+= indent_inc
;
521 printf (buffer
, a1
, a2
, a3
, a4
, a5
);
525 /* fetch the lvalues of the operands */
528 opcode_entry_type
*p
;
532 int done_one_imm8
= 0;
534 /* int done_read = 4;*/
539 switch (*s
& CLASS_MASK
)
542 emit ("register unsigned int imm_src=(<insn_4>& 2)?2:1;\n");
546 /* Just ignore these, we've already decoded this bit */
551 /* this nibble tells us which register to use as an arg,
552 if we've already gobbled the nibble we know what to use */
554 int regname
= *s
& 0xf;
556 emit ("register unsigned int reg_%s=<insn_4>;\n",
563 emit ("register unsigned base_%s=<iptr>;\n", reg_n (*s
));
565 nibs
+= SIZE_ADDRESS
;
570 emit ("register unsigned int imm_src=<insn_4>&0x2;\n");
574 emit ("register unsigned int imm_src=<insn_4>;\n");
578 /* Work out the size of the think to fetch */
581 switch (*s
& ~CLASS_MASK
)
584 emit ("register unsigned imm_src=<insn_16>;\n");
588 emit ("register unsigned int imm_src= %s;\n", insn_32 (nibs
));
592 emit ("register unsigned int imm_src=<insn_4>;\n");
596 emit ("register unsigned int imm_src = - <insn_4>;\n");
600 emit ("register unsigned int imm_src=<insn_4> & 0x2;\n");
605 emit ("register unsigned int imm_src=(<insn_4> + 1);\n");
609 emit ("register unsigned int imm_src=1;\n");
612 emit ("register unsigned int imm_src=2;\n");
615 emit ("register unsigned int imm_src=-<insn_8>;\n");
621 emit ("register unsigned int imm_src=<insn_8>;\n");
627 emit ("register int fail%d=fail(context,1);\n", nibs
);
633 /* We can't use `(char)' since char might be unsigned.
634 We can't use `(signed char)' because the compiler might be K&R.
635 This seems safe, since it only assumes that bytes are 8
637 emit ("register unsigned int oplval_dst=((ibytes_1 << (sizeof (int) * 8 - 8)) >> (sizeof (int) * 8 - 9)) + pc;\n");
639 /* Original code: fails if characters are unsigned. */
640 emit ("register unsigned int oplval_dst=(((char)ibytes_1)<<1) + pc;\n");
645 emit ("register unsigned int op_cc=<insn_4>;\n");
649 emit ("register int FAIL%d=fail(context,2);\n", nibs
);
653 /* work out how to fetch the immediate value */
661 info_special (p
, getdst
, nostore
, before
, nosrc
)
662 opcode_entry_type
*p
;
774 /* calculate the lvalues required for the opcode */
777 opcode_entry_type
*p
;
779 /* emit code to work out lvalues, if any */
780 unsigned int *i
= p
->arg_info
;
784 current_name
= reg_n (*i
);
785 current_size
= size_name (p
->type
);
786 switch (*i
& CLASS_MASK
)
790 emit ("register <addr_type> oplval_<name>= ((base_<name> + (short)get_word_reg(context,reg_<name>)) & 0xffff) + (base_<name> & ~0xffff);\n");
793 /* Indirect register */
794 emit ("register int oplval_<name> = get_<ptr_mode>_reg(context,reg_<name>);\n");
797 emit ("register int oplval_<name>=base_<name>;\n");
806 emit ("register int oplval_<name> = get_<ptr_mode>_reg(context,reg_<name>) + (short)(imm_src);\n");
809 emit ("register int oplval_<name> = get_<ptr_mode>_reg(context,reg_<name>)\n");
810 emit (" + get_word_reg(context,reg_aux_x);\n");
817 /* emit code to fetch the args from calculated lvalues */
820 info_fetch (p
, getdst
)
821 opcode_entry_type
*p
;
824 unsigned int *i
= p
->arg_info
;
831 current_name
= reg_n (*i
);
832 current_size
= size_name (p
->type
);
833 switch (*i
& CLASS_MASK
)
840 if (!getdst
&& IS_DST (*i
))
842 emit ("register int op_<name>= get_<size>_<mem>_da(context,oplval_<name>);\n");
848 if (p
->opcode
== OPC_out
||
849 p
->opcode
== OPC_outb
||
850 p
->opcode
== OPC_sout
||
851 p
->opcode
== OPC_soutb
)
853 /* The imm is a dest here */
854 emit ("register int op_dst = imm_src;\n");
858 emit ("register int op_src = imm_src;\n");
863 if (!getdst
&& IS_DST (*i
))
865 had_src
|= IS_SRC (*i
);
866 emit ("UDItype op_<name> ;\n");
870 if (!getdst
&& IS_DST (*i
))
872 had_src
|= IS_SRC (*i
);
873 emit ("register int op_<name> = get_word_reg(context,reg_<name>);\n");
877 if (!getdst
&& IS_DST (*i
))
879 had_src
|= IS_SRC (*i
);
880 emit ("register int op_<name> = get_long_reg(context,reg_<name>);\n");
883 if (!getdst
&& IS_DST (*i
))
885 had_src
|= IS_SRC (*i
);
886 emit ("register int op_<name> = get_byte_reg(context,reg_<name>);\n");
894 normal_flags (p
, s
, neg
)
895 opcode_entry_type
*p
;
899 emit ("NORMAL_FLAGS(context,%d, tmp, op_dst, op_src,%d); \n", p
->type
,neg
);
903 test_normal_flags (p
, s
, opt
)
904 opcode_entry_type
*p
;
911 emit ("context->broken_flags = TST_FLAGS;\n");
912 emit ("context->size = %d;\n", p
->type
);
916 emit ("TEST_NORMAL_FLAGS(context,%d, tmp); \n", p
->type
);
922 optimize_normal_flags (p
, s
,neg
)
923 opcode_entry_type
*p
;
928 emit ("context->broken_flags = CMP_FLAGS;\n");
930 emit ("NORMAL_FLAGS(context,%d, tmp, op_dst, op_src,%d); \n", p
->type
, neg
);
937 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)) pc = oplval_dst;\n");
952 opcode_entry_type
*p
;
954 emit ("if(op_cc == 8 || COND(context,op_cc))\n{\n");
955 emit ("pc = get_<ptr_mode>_<mem>_ir(context,<sp>);\n");
956 emit ("put_<ptr_mode>_reg(context,<sp>, get_<ptr_mode>_reg(context,<sp>) + <ptr_size>);\n");
962 opcode_entry_type
*p
;
964 emit ("put_<ptr_mode>_reg(context,<sp>,tmp = get_<ptr_mode>_reg(context,<sp>) - <ptr_size>);\n");
965 emit ("put_<ptr_mode>_<mem>_da(context,tmp, pc);\n");
966 emit ("pc = oplval_dst;\n");
971 opcode_entry_type
*p
;
973 emit ("tmp = op_src;\n");
974 emit ("oplval_dst -= %d;\n", p
->type
/ 8);
975 emit ("put_<ptr_mode>_reg(context,reg_dst, oplval_dst);\n");
980 opcode_entry_type
*p
;
982 emit ("tmp = op_src;\n");
983 emit ("put_<ptr_mode>_reg(context,reg_src, oplval_src + %d);\n", p
->type
/ 8);
988 opcode_entry_type
*p
;
990 emit ("tmp = op_src;\n");
996 emit ("support_call(context,imm_src);\n");
1002 emit ("pc -=2; \n");
1003 emit ("context->exception = SIM_BREAKPOINT;\n");
1008 opcode_entry_type
*p
;
1012 int dinc
= (size
/ 8) * inc
;
1014 current_size
= size_name (size
);
1016 emit ("int type = %s;\n", insn_4 (7));
1017 emit ("int rs = get_<ptr_mode>_reg(context,reg_src);\n");
1018 emit ("int rd = get_<ptr_mode>_reg(context,reg_dst);\n");
1019 emit ("int rr = get_word_reg(context,reg_aux_r);\n");
1021 emit ("put_<size>_<mem>_da(context,rd, get_<size>_<mem>_da(context,rs));\n");
1022 emit ("rd += %d;\n", dinc
);
1023 emit ("rs += %d;\n", dinc
);
1025 emit ("context->cycles += 9;\n");
1026 emit ("} while (!type && rr != 0 && context->exception <= 1);\n");
1027 emit ("if (context->exception>1) pc -=4;\n");
1028 emit ("put_<ptr_mode>_reg(context,reg_src, rs);\n");
1029 emit ("put_<ptr_mode>_reg(context,reg_dst, rd);\n");
1030 emit ("put_word_reg(context,reg_aux_r, rr);\n");
1037 opcode_entry_type
*p
;
1041 /* We can't use `(char)' since char might be unsigned.
1042 We can't use `(signed char)' because the compiler might be K&R.
1043 This seems safe, since it only assumes that bytes are 8 bits. */
1044 emit ("op_src = (op_src << (sizeof (int) * 8 - 8)) >> (sizeof (int) * 8 - 8);\n");
1046 /* Original code: fails if characters are unsigned. */
1047 emit ("op_src = (char)op_src;\n");
1049 emit ("if (op_src < 0) \n");
1051 emit ("op_src = -op_src;\n");
1052 emit ("op_dst = (%s <c_size>)op_dst;\n", arith
? "" : "unsigned");
1053 emit ("tmp = (%s op_dst) >> op_src;\n", arith
? "" : "(unsigned)");
1054 emit ("context->carry = op_dst >> (op_src-1);\n", p
->type
);
1058 emit ("tmp = op_dst << op_src;\n");
1059 emit ("context->carry = op_dst >> (%d - op_src);\n", p
->type
);
1061 emit ("context->zero = (<c_size>)tmp == 0;\n");
1062 emit ("context->sign = (int)((<c_size>)tmp) < 0;\n");
1063 emit ("context->overflow = ((int)tmp < 0) != ((int)op_dst < 0);\n");
1064 emit ("context->cycles += 3*op_src;\n");
1065 emit ("context->broken_flags = 0;\n");
1070 rotate (p
, through_carry
, size
, left
)
1071 opcode_entry_type
*p
;
1079 emit ("while (op_src--) {\n");
1080 emit ("int rotbit;\n");
1081 emit ("rotbit = op_dst & 1;\n");
1082 emit ("op_dst = ((unsigned)op_dst) >> 1;\n");
1086 emit ("op_dst |= context->carry << %d;\n", size
- 1);
1090 emit ("op_dst |= rotbit << %d;\n", size
- 1);
1092 emit ("context->carry = rotbit;\n");
1097 emit ("while (op_src--) {\n");
1098 emit ("int rotbit;\n");
1100 emit ("rotbit = (op_dst >> (%d))&1;\n", size
- 1);
1101 emit ("op_dst <<=1;\n");
1104 emit ("if (context->carry) op_dst |=1;\n");
1108 emit ("if (rotbit) op_dst |= 1;\n");
1110 emit ("context->carry = rotbit;\n");
1113 emit ("tmp = (<c_size>)op_dst;\n");
1114 emit ("context->zero = tmp == 0;\n");
1115 emit ("context->sign = (int)tmp < 0;\n");
1116 emit ("context->overflow = ((int)tmp < 0) != ((int)op_dst < 0);\n");
1117 emit ("context->cycles += 3*op_src;\n");
1118 emit ("context->broken_flags = 0;\n");
1124 opcode_entry_type
*p
;
1126 emit ("if (op_src==0)\n");
1128 emit ("context->exception = SIM_DIV_ZERO;\n");
1135 emit ("op_dst.low = (int)get_long_reg(context,reg_dst+2);\n");
1136 emit ("op_dst.high = (int)get_long_reg(context,reg_dst+0);\n");
1138 emit ("tmp = (((long long)op_dst.high << 32) + (op_dst.low)) / (int)op_src;\n");
1140 emit ("tmp = (long)op_dst.low / (int)op_src;\n");
1142 emit ("put_long_reg(context,reg_dst+2, tmp);\n");
1144 emit ("put_long_reg(context,reg_dst, (((long long)op_dst.high << 32) + (op_dst.low)) %% (int)op_src);\n");
1146 emit ("put_long_reg(context,reg_dst, (int)op_dst.low %% (int)op_src);\n");
1149 emit ("context->zero = op_src == 0 || (op_dst.low==0 && op_dst.high==0);\n");
1153 emit ("tmp = (long)op_dst / (short)op_src;\n");
1154 emit ("put_word_reg(context,reg_dst+1, tmp);\n");
1155 emit ("put_word_reg(context,reg_dst, (long) op_dst %% (short)op_src);\n");
1156 emit ("context->zero = op_src == 0 || op_dst==0;\n");
1159 emit ("context->sign = (int)tmp < 0;\n");
1160 emit ("context->overflow =(tmp & 0x%x) != 0;\n",
1161 ~((1 << (p
->type
)) - 1));
1162 emit ("context->carry = (tmp & 0x%x) != 0;\n",
1170 opcode_entry_type
*p
;
1172 emit("context->zero = (op_dst & (1<<op_src))==0;\n");
1173 emit("context->broken_flags = 0;\n");
1177 opcode_entry_type
*p
;
1181 emit (" tmp = op_dst | (1<< op_src);\n");
1183 emit (" tmp = op_dst & ~(1<< op_src);\n");
1188 opcode_entry_type
*p
;
1193 emit ("op_dst.low = get_long_reg(context,reg_dst+2);\n");
1194 emit ("tmp = op_dst.low * op_src;\n");
1195 emit ("put_long_reg(context,reg_dst+2, tmp);\n");
1196 emit ("put_long_reg(context,reg_dst, 0);\n");
1200 emit ("op_dst = get_word_reg(context,reg_dst+1);\n");
1201 emit ("tmp = op_dst * op_src;\n");
1202 emit ("put_long_reg(context,reg_dst, tmp);\n");
1205 emit ("context->sign = (int)tmp < 0;\n");
1206 emit ("context->overflow =0;\n");
1207 emit ("context->carry = (tmp & 0x%x) != 0;\n", ~((1 << (p
->type
)) - 1));
1208 emit ("context->zero = tmp == 0;\n");
1214 opcode_entry_type
*p
;
1216 /* Fetch the ls part of the src */
1217 current_size
= size_name (p
->type
* 2);
1221 emit ("tmp= get_long_reg(context,reg_dst+2);\n");
1222 emit ("if (tmp & (1<<%d)) {\n", p
->type
- 1);
1223 emit ("put_long_reg(context,reg_dst, 0xffffffff);\n");
1227 emit ("put_long_reg(context,reg_dst, 0);\n");
1232 emit ("tmp= get_<size>_reg(context,reg_dst);\n");
1233 emit ("if (tmp & (1<<%d)) {\n", p
->type
- 1);
1234 emit ("tmp |= 0x%x;\n", ~((1 << p
->type
) - 1));
1239 emit ("tmp &= 0x%x;\n", ((1 << p
->type
) - 1));
1241 emit ("put_<size>_reg(context,reg_dst, tmp);\n");
1247 /* Load up the flags */
1248 emit(" COND (context, 0x0b);\n");
1251 emit ("{ int on =1;\n ");
1253 emit ("{ int on =0;\n ");
1255 emit ("if (imm_src & 1)\n");
1256 emit ("PSW_OVERFLOW = on;\n");
1258 emit ("if (imm_src & 2)\n");
1259 emit ("PSW_SIGN = on;\n");
1261 emit ("if (imm_src & 4)\n");
1262 emit ("PSW_ZERO = on;\n");
1264 emit ("if (imm_src & 8)\n");
1265 emit ("PSW_CARRY = on;\n");
1270 /* emit code to perform operation */
1273 opcode_entry_type
*p
;
1279 emit ("tmp = 0;\n");
1284 emit ("tmp = op_src; \n");
1287 emit ("put_<size>_reg(context,reg_src, op_dst);\n");
1291 emit ("put_<size>_mem_da(context, oplval_src, op_dst);\n");
1296 normal_flags (p
, "op_src += COND(context,7);tmp = op_dst + op_src ;",0);
1299 normal_flags (p
, "op_src += COND(context,7);tmp = op_dst - op_src ;",1);
1305 test_normal_flags (p
, "tmp = ~ op_dst", 1);
1309 test_normal_flags (p
, "tmp = op_dst & op_src", 1);
1313 test_normal_flags (p
, "tmp = op_dst ^ op_src", 1);
1317 test_normal_flags (p
, "tmp = op_dst | op_src", 1);
1337 rotate (p
, 0, 16, 1);
1340 rotate (p
, 0, 8, 1);
1343 rotate (p
, 0, 16, 0);
1346 rotate (p
, 0, 8, 0);
1349 rotate (p
, 1, 16, 0);
1352 rotate (p
, 1, 8, 0);
1355 rotate (p
, 1, 16, 1);
1358 rotate (p
, 1, 8, 1);
1371 optimize_normal_flags (p
, "tmp = op_dst + op_src",0);
1376 test_normal_flags (p
, "tmp = op_dst", 0);
1381 normal_flags (p
, "tmp = op_dst - op_src",1);
1386 emit ("int op_src = -op_dst;\n");
1387 emit ("op_dst = 0;\n");
1388 optimize_normal_flags (p
, "tmp = op_dst + op_src;\n",1);
1397 optimize_normal_flags (p
, "tmp = op_dst - op_src",1);
1419 emit ("if(op_cc == 8 || COND(context,op_cc)) put_word_reg(context,reg_dst, 1);\n");
1422 emit ("tmp = oplval_src; \n");
1423 /*(((oplval_src) & 0xff0000) << 8) | (oplval_src & 0xffff); \n");*/
1480 emit ("tmp = fail(context,%d);\n", p
->opcode
);
1485 /* emit code to store result in calculated lvalue */
1489 opcode_entry_type
*p
;
1491 unsigned int *i
= p
->arg_info
;
1495 current_name
= reg_n (*i
);
1496 current_size
= size_name (p
->type
);
1500 switch (*i
& CLASS_MASK
)
1503 emit ("put_<ptr_mode>_reg(context,reg_<name>, tmp);\n");
1505 case CLASS_REG_LONG
:
1506 case CLASS_REG_WORD
:
1507 case CLASS_REG_BYTE
:
1509 emit ("put_<size>_reg(context,reg_<name>,tmp);\n");
1517 emit ("put_<size>_<mem>_da(context,oplval_<name>, tmp);\n");
1533 mangle (p
, shortcut
, value
)
1534 opcode_entry_type
*p
;
1544 emit ("/\052 %s \052/\n", p
->nicename
);
1547 emit ("int <fop>_%04x(context,pc)\n", value
);
1551 emit ("int <fop>_%d(context,pc,iwords0)\n", p
->idx
);
1552 emit ("int iwords0;\n");
1554 emit ("sim_state_type *context;\n");
1557 emit ("register unsigned int tmp;\n");
1560 emit ("register unsigned int iwords0 = 0x%x;\n", value
);
1563 /* work out how much bigger this opcode could be because it's large
1570 for (i
= 0; i
< 4; i
++)
1572 if ((p
->arg_info
[i
] & CLASS_MASK
) == CLASS_DA
1573 || (p
->arg_info
[i
] & CLASS_MASK
) == CLASS_X
)
1581 printf (" /* Length %d */ \n", p
->length
+ extra
);
1582 switch (p
->length
+ extra
)
1585 emit ("pc += 2\n;");
1588 emit ("register unsigned int iwords1 = get_word_mem_da(context,pc+2);\n");
1589 emit ("pc += 4;\n");
1593 emit ("register unsigned int iwords1 = get_word_mem_da(context,pc+2);\n");
1594 emit ("register unsigned int iwords2 = get_word_mem_da(context,pc+4);\n");
1595 emit ("pc += 6;\n");
1598 emit ("register unsigned int iwords1 = get_word_mem_da(context,pc+2);\n");
1599 emit ("register unsigned int iwords2 = get_word_mem_da(context,pc+4);\n");
1600 emit ("register unsigned int iwords3 = get_word_mem_da(context,pc+6);\n");
1601 emit ("pc += 8;\n");
1607 emit ("context->cycles += %d;\n", p
->cycles
);
1611 info_special (p
, &getdst
, &nostore
, &before
, &nosrc
);
1616 info_fetch (p
, getdst
);
1630 emit ("return pc;\n");
1639 /* find the table entry */
1640 opcode_entry_type
*p
= z8k_table
+ i
;
1648 add_to_list (ptr
, value
)
1649 struct opcode_value
**ptr
;
1652 struct opcode_value
*prev
;
1655 *ptr
= (struct opcode_value
*) malloc (sizeof (struct opcode_value
));
1658 (*ptr
)->next
= prev
;
1665 opcode_entry_type
*p
= lookup_inst (i
);
1669 add_to_list (&list
[p
->idx
], i
);
1682 for (i
= 1; i
< ac
; i
++)
1684 if (strcmp (av
[i
], "-m") == 0)
1686 if (strcmp (av
[i
], "-1") == 0)
1688 if (strcmp (av
[i
], "-2") == 0)
1690 if (strcmp (av
[i
], "-3") == 0)
1692 if (strcmp (av
[i
], "-b3") == 0)
1704 printf ("short int z8k_inv_list[] = {\n");
1706 for (i
= 0; i
< 1 << 16; i
++)
1708 opcode_entry_type
*p
= lookup_inst (i
);
1716 printf ("\n /*%04x %s */", i
, p
? p
->nicename
: "");
1725 printf ("%d", p
->idx
);
1728 if ((i
& 0x3f) == 0 && DIRTY_HACK
)
1730 printf ("\n#ifdef __GNUC__\n");
1732 printf("short int int_list%d[] = {\n", i
);
1735 printf ("#endif\n");
1746 /* First work out which opcodes use which bit patterns,
1747 build a list of all matching bit pattens */
1748 for (i
= 0; i
< 1 << 16; i
++)
1753 for (i
= 0; i
< NOPS
; i
++)
1755 struct opcode_value
*p
;
1761 printf (" %04x,", p
->n
);
1773 /* Do the shortcuts */
1774 printf (" /* SHORTCUTS */\n");
1775 for (i
= 0; quick
[i
]; i
++)
1779 mangle (z8k_table
+ z8k_inv_list
[t
],
1786 printf (" /* NOT -SHORTCUTS */\n");
1787 for (i
= 0; i
< NOPS
; i
++)
1791 one_instruction (i
);
1795 emit ("int <fop>_%d(context,pc)\n", i
);
1796 printf ("sim_state_type *context;\n");
1797 printf ("int pc;\n");
1798 emit ("{ <fop>_bad1();return pc; }\n");
1801 emit ("int <fop>_bad() ;\n");
1803 /* Write the jump table */
1804 emit ("int (*(<fop>_table[]))() = {");
1806 for (i
= 0; i
< NOPS
; i
++)
1810 emit ("<fop>_%d\n", i
);
1812 if ((i
& 0x3f) == 0 && DIRTY_HACK
)
1814 printf ("#ifdef __GNUC__\n");
1816 emit ("int (*(<fop>_table%d[]))() = {\n", i
);
1819 printf ("#endif\n");
1829 /* Static - since it's too be to be automatic on the apollo */
1830 static int big
[64 * 1024];
1832 for (i
= 0; i
< 64 * 1024; i
++)
1835 for (i
= 0; quick
[i
]; i
++)
1839 printf ("extern int <fop>_%04x();\n", quick
[i
]);
1845 for (i
= 0; i
< NOPS
; i
++)
1848 printf ("extern int fop_%d();\n", i
);
1852 printf ("extern int fop_bad();\n");
1854 printf ("struct op_info op_info_table[] = {\n");
1855 for (i
= 0; i
< 1 << 16; i
++)
1857 int inv
= z8k_inv_list
[i
];
1858 opcode_entry_type
*p
= z8k_table
+ inv
;
1865 printf ("<fop>_%04x", i
);
1877 printf (" /* %04x %s */\n", i
, p
->nicename
);
1884 if ((i
& 0x3f) == 0 && DIRTY_HACK
)
1886 printf ("#ifdef __GNUC__\n");
1888 printf ("struct op_info op_info_table%d[] = {\n", i
);
1892 printf ("#endif\n");
1916 return "fail(context,123)";
1920 /* work out if the opcode only wants lvalues */
1923 opcode_entry_type
*p
;
1938 info_len_in_words (o
)
1939 opcode_entry_type
*o
;
1941 unsigned int *p
= o
->byte_info
;
1946 switch (*p
& CLASS_MASK
)
1957 nibs
+= SIZE_ADDRESS
;
1960 switch (*p
& ~CLASS_MASK
)
1974 case ARG_IMMNMINUS1
:
1987 switch (*p
& ~CLASS_MASK
)
2007 case CLASS_BIT_1OR2
:
2014 emit ("don't know %x\n", *p
);
2019 return nibs
/ 4; /* return umber of words */
This page took 0.08433 seconds and 4 git commands to generate.