trunk/src/emu/cpu/arcompact/arcompact_make.py
| r248581 | r248582 | |
| 1 | 1 | #!/usr/bin/python |
| 2 | 2 | |
| 3 | from __future__ import print_function |
| 3 | 4 | import sys |
| 4 | 5 | |
| 5 | 6 | def EmitGroup04_Handle_NZ_Flags(f, funcname, opname): |
| 6 | | print >>f, " if (result & 0x80000000) { STATUS32_SET_N; }" |
| 7 | | print >>f, " else { STATUS32_CLEAR_N; }" |
| 8 | | print >>f, " if (result == 0x00000000) { STATUS32_SET_Z; }" |
| 9 | | print >>f, " else { STATUS32_CLEAR_Z; }" |
| 7 | print(" if (result & 0x80000000) { STATUS32_SET_N; }", file=f) |
| 8 | print(" else { STATUS32_CLEAR_N; }", file=f) |
| 9 | print(" if (result == 0x00000000) { STATUS32_SET_Z; }", file=f) |
| 10 | print(" else { STATUS32_CLEAR_Z; }", file=f) |
| 10 | 11 | |
| 11 | 12 | def EmitGroup04_Handle_NZC_LSR1_Flags(f, funcname, opname): |
| 12 | | print >>f, " if (result & 0x80000000) { STATUS32_SET_N; }" |
| 13 | | print >>f, " else { STATUS32_CLEAR_N; }" |
| 14 | | print >>f, " if (result == 0x00000000) { STATUS32_SET_Z; }" |
| 15 | | print >>f, " else { STATUS32_CLEAR_Z; }" |
| 16 | | print >>f, " if (c == 0x00000001) { STATUS32_SET_C; }" |
| 17 | | print >>f, " else { STATUS32_CLEAR_C; }" |
| 13 | print(" if (result & 0x80000000) { STATUS32_SET_N; }", file=f) |
| 14 | print(" else { STATUS32_CLEAR_N; }", file=f) |
| 15 | print(" if (result == 0x00000000) { STATUS32_SET_Z; }", file=f) |
| 16 | print(" else { STATUS32_CLEAR_Z; }", file=f) |
| 17 | print(" if (c == 0x00000001) { STATUS32_SET_C; }", file=f) |
| 18 | print(" else { STATUS32_CLEAR_C; }", file=f) |
| 18 | 19 | |
| 19 | 20 | def EmitGroup04_Handle_NZCV_ADD_Flags(f, funcname, opname): |
| 20 | | print >>f, " if (result & 0x80000000) { STATUS32_SET_N; }" |
| 21 | | print >>f, " else { STATUS32_CLEAR_N; }" |
| 22 | | print >>f, " if (result == 0x00000000) { STATUS32_SET_Z; }" |
| 23 | | print >>f, " else { STATUS32_CLEAR_Z; }" |
| 24 | | print >>f, " if ((b & 0x80000000) == (c & 0x80000000))" |
| 25 | | print >>f, " {" |
| 26 | | print >>f, " if ((result & 0x80000000) != (b & 0x80000000))" |
| 27 | | print >>f, " {" |
| 28 | | print >>f, " STATUS32_SET_V;" |
| 29 | | print >>f, " }" |
| 30 | | print >>f, " else" |
| 31 | | print >>f, " {" |
| 32 | | print >>f, " STATUS32_CLEAR_V;" |
| 33 | | print >>f, " }" |
| 34 | | print >>f, " }" |
| 35 | | print >>f, " if (b < c)" |
| 36 | | print >>f, " {" |
| 37 | | print >>f, " STATUS32_SET_C;" |
| 38 | | print >>f, " }" |
| 39 | | print >>f, " else" |
| 40 | | print >>f, " {" |
| 41 | | print >>f, " STATUS32_CLEAR_C;" |
| 42 | | print >>f, " }" |
| 21 | print(" if (result & 0x80000000) { STATUS32_SET_N; }", file=f) |
| 22 | print(" else { STATUS32_CLEAR_N; }", file=f) |
| 23 | print(" if (result == 0x00000000) { STATUS32_SET_Z; }", file=f) |
| 24 | print(" else { STATUS32_CLEAR_Z; }", file=f) |
| 25 | print(" if ((b & 0x80000000) == (c & 0x80000000))", file=f) |
| 26 | print(" {", file=f) |
| 27 | print(" if ((result & 0x80000000) != (b & 0x80000000))", file=f) |
| 28 | print(" {", file=f) |
| 29 | print(" STATUS32_SET_V;", file=f) |
| 30 | print(" }", file=f) |
| 31 | print(" else", file=f) |
| 32 | print(" {", file=f) |
| 33 | print(" STATUS32_CLEAR_V;", file=f) |
| 34 | print(" }", file=f) |
| 35 | print(" }", file=f) |
| 36 | print(" if (b < c)", file=f) |
| 37 | print(" {", file=f) |
| 38 | print(" STATUS32_SET_C;", file=f) |
| 39 | print(" }", file=f) |
| 40 | print(" else", file=f) |
| 41 | print(" {", file=f) |
| 42 | print(" STATUS32_CLEAR_C;", file=f) |
| 43 | print(" }", file=f) |
| 43 | 44 | |
| 44 | 45 | |
| 45 | 46 | def EmitGroup04_no_Flags(f, funcname, opname): |
| 46 | | print >>f, " // no flag changes" |
| 47 | print(" // no flag changes", file=f) |
| 47 | 48 | |
| 48 | 49 | def EmitGroup04_unsupported_Flags(f, funcname, opname): |
| 49 | | print >>f, " arcompact_fatal(\"arcompact_handle%s (%s) (F set)\\n\"); // not yet supported" % (funcname, opname) |
| 50 | print(" arcompact_fatal(\"arcompact_handle%s (%s) (F set)\\n\"); // not yet supported" % (funcname, opname), file=f) |
| 50 | 51 | |
| 51 | 52 | def EmitGroup04_Flaghandler(f,funcname, opname, flagcondition, flaghandler): |
| 52 | 53 | if flagcondition == -1: |
| 53 | | print >>f, " if (F)" |
| 54 | | print >>f, " {" |
| 54 | print(" if (F)", file=f) |
| 55 | print(" {", file=f) |
| 55 | 56 | flaghandler(f, funcname, opname) |
| 56 | | print >>f, " }" |
| 57 | print(" }", file=f) |
| 57 | 58 | elif flagcondition == 0: |
| 58 | | print >>f, " if (0)" |
| 59 | | print >>f, " {" |
| 59 | print(" if (0)", file=f) |
| 60 | print(" {", file=f) |
| 60 | 61 | flaghandler(f, funcname, opname) |
| 61 | | print >>f, " }" |
| 62 | print(" }", file=f) |
| 62 | 63 | elif flagcondition == 1: |
| 63 | | print >>f, " if (1)" |
| 64 | | print >>f, " {" |
| 64 | print(" if (1)", file=f) |
| 65 | print(" {", file=f) |
| 65 | 66 | flaghandler(f, funcname, opname) |
| 66 | | print >>f, " }" |
| 67 | print(" }", file=f) |
| 67 | 68 | |
| 68 | 69 | def EmitGroup04_u5fragment(f,funcname, opname, opexecute, opwrite, opwrite_alt, ignore_a, breg_is_dst_only, flagcondition, flaghandler): |
| 69 | | print >>f, " int size = 4;" |
| 70 | print(" int size = 4;", file=f) |
| 70 | 71 | |
| 71 | 72 | if breg_is_dst_only == 0: |
| 72 | | print >>f, " UINT32 limm = 0;" |
| 73 | print(" UINT32 limm = 0;", file=f) |
| 73 | 74 | |
| 74 | | print >>f, "/* int got_limm = 0; */" |
| 75 | | print >>f, " " |
| 76 | | print >>f, " COMMON32_GET_breg;" |
| 75 | print("/* int got_limm = 0; */", file=f) |
| 76 | print(" ", file=f) |
| 77 | print(" COMMON32_GET_breg;", file=f) |
| 77 | 78 | |
| 78 | 79 | if flagcondition == -1: |
| 79 | | print >>f, " COMMON32_GET_F;" |
| 80 | print(" COMMON32_GET_F;", file=f) |
| 80 | 81 | |
| 81 | | print >>f, " COMMON32_GET_u6;" |
| 82 | print(" COMMON32_GET_u6;", file=f) |
| 82 | 83 | |
| 83 | 84 | if ignore_a == 0: |
| 84 | | print >>f, " COMMON32_GET_areg;" |
| 85 | print(" COMMON32_GET_areg;", file=f) |
| 85 | 86 | elif ignore_a == 1: |
| 86 | | print >>f, " //COMMON32_GET_areg; // areg is reserved / not used" |
| 87 | print(" //COMMON32_GET_areg; // areg is reserved / not used", file=f) |
| 87 | 88 | elif ignore_a == 2: |
| 88 | | print >>f, " //COMMON32_GET_areg; // areg bits already used as opcode select" |
| 89 | print(" //COMMON32_GET_areg; // areg bits already used as opcode select", file=f) |
| 89 | 90 | elif ignore_a == 3: |
| 90 | | print >>f, " //COMMON32_GET_areg; // areg bits already used as condition code select" |
| 91 | | print >>f, " " |
| 91 | print(" //COMMON32_GET_areg; // areg bits already used as condition code select", file=f) |
| 92 | print(" ", file=f) |
| 92 | 93 | |
| 93 | | print >>f, " UINT32 c;" |
| 94 | print(" UINT32 c;", file=f) |
| 94 | 95 | if breg_is_dst_only == 0: |
| 95 | | print >>f, " UINT32 b;" |
| 96 | | print >>f, " " |
| 97 | | print >>f, " /* is having b as LIMM valid here? LIMM vs. fixed u6 value makes no sense */" |
| 98 | | print >>f, " if (breg == LIMM_REG)" |
| 99 | | print >>f, " {" |
| 100 | | print >>f, " GET_LIMM_32;" |
| 101 | | print >>f, " size = 8;" |
| 102 | | print >>f, "/* got_limm = 1; */" |
| 103 | | print >>f, " b = limm;" |
| 104 | | print >>f, " }" |
| 105 | | print >>f, " else" |
| 106 | | print >>f, " {" |
| 107 | | print >>f, " b = m_regs[breg];" |
| 108 | | print >>f, " }" |
| 96 | print(" UINT32 b;", file=f) |
| 97 | print(" ", file=f) |
| 98 | print(" /* is having b as LIMM valid here? LIMM vs. fixed u6 value makes no sense */", file=f) |
| 99 | print(" if (breg == LIMM_REG)", file=f) |
| 100 | print(" {", file=f) |
| 101 | print(" GET_LIMM_32;", file=f) |
| 102 | print(" size = 8;", file=f) |
| 103 | print("/* got_limm = 1; */", file=f) |
| 104 | print(" b = limm;", file=f) |
| 105 | print(" }", file=f) |
| 106 | print(" else", file=f) |
| 107 | print(" {", file=f) |
| 108 | print(" b = m_regs[breg];", file=f) |
| 109 | print(" }", file=f) |
| 109 | 110 | |
| 110 | | print >>f, " " |
| 111 | | print >>f, " c = u;" |
| 112 | | print >>f, " " |
| 113 | | print >>f, " /* todo: if areg = LIMM then there is no result (but since that register can never be read, I guess it doesn't matter if we store it there anyway?) */" |
| 111 | print(" ", file=f) |
| 112 | print(" c = u;", file=f) |
| 113 | print(" ", file=f) |
| 114 | print(" /* todo: if areg = LIMM then there is no result (but since that register can never be read, I guess it doesn't matter if we store it there anyway?) */", file=f) |
| 114 | 115 | |
| 115 | 116 | def EmitGroup04(f,funcname, opname, opexecute, opwrite, opwrite_alt, ignore_a, breg_is_dst_only, flagcondition, flaghandler): |
| 116 | 117 | # the mode 0x00 handler |
| 117 | | print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p00(OPS_32)" % funcname |
| 118 | | print >>f, "{" |
| 119 | | print >>f, " int size = 4;" |
| 118 | print("ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p00(OPS_32)" % funcname, file=f) |
| 119 | print("{", file=f) |
| 120 | print(" int size = 4;", file=f) |
| 120 | 121 | |
| 121 | | print >>f, " UINT32 limm = 0;" |
| 122 | print(" UINT32 limm = 0;", file=f) |
| 122 | 123 | |
| 123 | | print >>f, " int got_limm = 0;" |
| 124 | | print >>f, " " |
| 125 | | print >>f, " COMMON32_GET_breg;" |
| 124 | print(" int got_limm = 0;", file=f) |
| 125 | print(" ", file=f) |
| 126 | print(" COMMON32_GET_breg;", file=f) |
| 126 | 127 | |
| 127 | 128 | if flagcondition == -1: |
| 128 | | print >>f, " COMMON32_GET_F;" |
| 129 | print(" COMMON32_GET_F;", file=f) |
| 129 | 130 | |
| 130 | | print >>f, " COMMON32_GET_creg;" |
| 131 | print(" COMMON32_GET_creg;", file=f) |
| 131 | 132 | |
| 132 | 133 | if ignore_a == 0: |
| 133 | | print >>f, " COMMON32_GET_areg;" |
| 134 | print(" COMMON32_GET_areg;", file=f) |
| 134 | 135 | elif ignore_a == 1: |
| 135 | | print >>f, " //COMMON32_GET_areg; // areg is reserved / not used" |
| 136 | print(" //COMMON32_GET_areg; // areg is reserved / not used", file=f) |
| 136 | 137 | elif ignore_a == 2: |
| 137 | | print >>f, " //COMMON32_GET_areg; // areg bits already used as opcode select" |
| 138 | print(" //COMMON32_GET_areg; // areg bits already used as opcode select", file=f) |
| 138 | 139 | |
| 139 | | print >>f, " " |
| 140 | print(" ", file=f) |
| 140 | 141 | |
| 141 | | print >>f, " UINT32 c;" |
| 142 | print(" UINT32 c;", file=f) |
| 142 | 143 | if breg_is_dst_only == 0: |
| 143 | | print >>f, " UINT32 b;" |
| 144 | | print >>f, " " |
| 145 | | print >>f, " if (breg == LIMM_REG)" |
| 146 | | print >>f, " {" |
| 147 | | print >>f, " GET_LIMM_32;" |
| 148 | | print >>f, " size = 8;" |
| 149 | | print >>f, " got_limm = 1;" |
| 150 | | print >>f, " b = limm;" |
| 151 | | print >>f, " }" |
| 152 | | print >>f, " else" |
| 153 | | print >>f, " {" |
| 154 | | print >>f, " b = m_regs[breg];" |
| 155 | | print >>f, " }" |
| 144 | print(" UINT32 b;", file=f) |
| 145 | print(" ", file=f) |
| 146 | print(" if (breg == LIMM_REG)", file=f) |
| 147 | print(" {", file=f) |
| 148 | print(" GET_LIMM_32;", file=f) |
| 149 | print(" size = 8;", file=f) |
| 150 | print(" got_limm = 1;", file=f) |
| 151 | print(" b = limm;", file=f) |
| 152 | print(" }", file=f) |
| 153 | print(" else", file=f) |
| 154 | print(" {", file=f) |
| 155 | print(" b = m_regs[breg];", file=f) |
| 156 | print(" }", file=f) |
| 156 | 157 | |
| 157 | | print >>f, " " |
| 158 | | print >>f, " if (creg == LIMM_REG)" |
| 159 | | print >>f, " {" |
| 160 | | print >>f, " if (!got_limm)" |
| 161 | | print >>f, " {" |
| 162 | | print >>f, " GET_LIMM_32;" |
| 163 | | print >>f, " size = 8;" |
| 164 | | print >>f, " }" |
| 165 | | print >>f, " c = limm;" |
| 166 | | print >>f, " }" |
| 167 | | print >>f, " else" |
| 168 | | print >>f, " {" |
| 169 | | print >>f, " c = m_regs[creg];" |
| 170 | | print >>f, " }" |
| 171 | | print >>f, " /* todo: is the limm, limm syntax valid? (it's pointless.) */" |
| 172 | | print >>f, " /* todo: if areg = LIMM then there is no result (but since that register can never be read, I guess it doesn't matter if we store it there anyway?) */" |
| 173 | | print >>f, " %s" % opexecute |
| 174 | | print >>f, " %s" % opwrite |
| 175 | | print >>f, " " |
| 158 | print(" ", file=f) |
| 159 | print(" if (creg == LIMM_REG)", file=f) |
| 160 | print(" {", file=f) |
| 161 | print(" if (!got_limm)", file=f) |
| 162 | print(" {", file=f) |
| 163 | print(" GET_LIMM_32;", file=f) |
| 164 | print(" size = 8;", file=f) |
| 165 | print(" }", file=f) |
| 166 | print(" c = limm;", file=f) |
| 167 | print(" }", file=f) |
| 168 | print(" else", file=f) |
| 169 | print(" {", file=f) |
| 170 | print(" c = m_regs[creg];", file=f) |
| 171 | print(" }", file=f) |
| 172 | print(" /* todo: is the limm, limm syntax valid? (it's pointless.) */", file=f) |
| 173 | print(" /* todo: if areg = LIMM then there is no result (but since that register can never be read, I guess it doesn't matter if we store it there anyway?) */", file=f) |
| 174 | print(" %s" % opexecute, file=f) |
| 175 | print(" %s" % opwrite, file=f) |
| 176 | print(" ", file=f) |
| 176 | 177 | EmitGroup04_Flaghandler(f,funcname,opname,flagcondition,flaghandler) |
| 177 | | print >>f, " return m_pc + (size >> 0);" |
| 178 | | print >>f, "}" |
| 179 | | print >>f, "" |
| 180 | | print >>f, "" |
| 178 | print(" return m_pc + (size >> 0);", file=f) |
| 179 | print("}", file=f) |
| 180 | print("", file=f) |
| 181 | print("", file=f) |
| 181 | 182 | # the mode 0x01 handler |
| 182 | | print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p01(OPS_32)" % funcname |
| 183 | | print >>f, "{" |
| 183 | print("ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p01(OPS_32)" % funcname, file=f) |
| 184 | print("{", file=f) |
| 184 | 185 | EmitGroup04_u5fragment(f,funcname, opname, opexecute, opwrite, opwrite_alt, ignore_a, breg_is_dst_only, flagcondition, flaghandler) |
| 185 | | print >>f, " %s" % opexecute |
| 186 | | print >>f, " %s" % opwrite |
| 187 | | print >>f, " " |
| 186 | print(" %s" % opexecute, file=f) |
| 187 | print(" %s" % opwrite, file=f) |
| 188 | print(" ", file=f) |
| 188 | 189 | EmitGroup04_Flaghandler(f,funcname,opname,flagcondition,flaghandler) |
| 189 | | print >>f, " return m_pc + (size >> 0);" |
| 190 | | print >>f, "}" |
| 191 | | print >>f, "" |
| 192 | | print >>f, "" |
| 190 | print(" return m_pc + (size >> 0);", file=f) |
| 191 | print("}", file=f) |
| 192 | print("", file=f) |
| 193 | print("", file=f) |
| 193 | 194 | # the mode 0x10 handler |
| 194 | | print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p10(OPS_32)" % funcname |
| 195 | print("ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p10(OPS_32)" % funcname, file=f) |
| 195 | 196 | if ignore_a == 2: |
| 196 | | print >>f, "{" |
| 197 | | print >>f, " int size = 4;" |
| 198 | | print >>f, " arcompact_fatal(\"illegal arcompact_handle%s_p10 (ares bits already used as opcode select, can't be used as s12) (%s)\\n\");" % (funcname, opname) |
| 199 | | print >>f, " return m_pc + (size >> 0);" |
| 200 | | print >>f, "}" |
| 197 | print("{", file=f) |
| 198 | print(" int size = 4;", file=f) |
| 199 | print(" arcompact_fatal(\"illegal arcompact_handle%s_p10 (ares bits already used as opcode select, can't be used as s12) (%s)\\n\");" % (funcname, opname), file=f) |
| 200 | print(" return m_pc + (size >> 0);", file=f) |
| 201 | print("}", file=f) |
| 201 | 202 | else: |
| 202 | | print >>f, "{" |
| 203 | | print >>f, " int size = 4;" |
| 203 | print("{", file=f) |
| 204 | print(" int size = 4;", file=f) |
| 204 | 205 | if breg_is_dst_only == 0: |
| 205 | | print >>f, " UINT32 limm = 0;" |
| 206 | print(" UINT32 limm = 0;", file=f) |
| 206 | 207 | |
| 207 | | print >>f, "/* int got_limm = 0; */" |
| 208 | | print >>f, " " |
| 209 | | print >>f, " COMMON32_GET_breg;" |
| 208 | print("/* int got_limm = 0; */", file=f) |
| 209 | print(" ", file=f) |
| 210 | print(" COMMON32_GET_breg;", file=f) |
| 210 | 211 | |
| 211 | 212 | if flagcondition == -1: |
| 212 | | print >>f, " COMMON32_GET_F;" |
| 213 | print(" COMMON32_GET_F;", file=f) |
| 213 | 214 | |
| 214 | | print >>f, " COMMON32_GET_s12;" |
| 215 | print(" COMMON32_GET_s12;", file=f) |
| 215 | 216 | |
| 216 | 217 | # areg can't be used here, it's used for s12 bits |
| 217 | 218 | |
| 218 | | print >>f, " " |
| 219 | | print >>f, " UINT32 c;" |
| 219 | print(" ", file=f) |
| 220 | print(" UINT32 c;", file=f) |
| 220 | 221 | if breg_is_dst_only == 0: |
| 221 | | print >>f, " UINT32 b;" |
| 222 | | print >>f, " " |
| 223 | | print >>f, " /* is having b as LIMM valid here? LIMM vs. fixed u6 value makes no sense */" |
| 224 | | print >>f, " if (breg == LIMM_REG)" |
| 225 | | print >>f, " {" |
| 226 | | print >>f, " GET_LIMM_32;" |
| 227 | | print >>f, " size = 8;" |
| 228 | | print >>f, "/* got_limm = 1; */" |
| 229 | | print >>f, " b = limm;" |
| 230 | | print >>f, " }" |
| 231 | | print >>f, " else" |
| 232 | | print >>f, " {" |
| 233 | | print >>f, " b = m_regs[breg];" |
| 234 | | print >>f, " }" |
| 222 | print(" UINT32 b;", file=f) |
| 223 | print(" ", file=f) |
| 224 | print(" /* is having b as LIMM valid here? LIMM vs. fixed u6 value makes no sense */", file=f) |
| 225 | print(" if (breg == LIMM_REG)", file=f) |
| 226 | print(" {", file=f) |
| 227 | print(" GET_LIMM_32;", file=f) |
| 228 | print(" size = 8;", file=f) |
| 229 | print("/* got_limm = 1; */", file=f) |
| 230 | print(" b = limm;", file=f) |
| 231 | print(" }", file=f) |
| 232 | print(" else", file=f) |
| 233 | print(" {", file=f) |
| 234 | print(" b = m_regs[breg];", file=f) |
| 235 | print(" }", file=f) |
| 235 | 236 | |
| 236 | | print >>f, " " |
| 237 | | print >>f, " c = (UINT32)S;" |
| 238 | | print >>f, " " |
| 239 | | print >>f, " /* todo: if areg = LIMM then there is no result (but since that register can never be read, I guess it doesn't matter if we store it there anyway?) */" |
| 240 | | print >>f, " %s" % opexecute |
| 241 | | print >>f, " %s" % opwrite_alt |
| 242 | | print >>f, " " |
| 237 | print(" ", file=f) |
| 238 | print(" c = (UINT32)S;", file=f) |
| 239 | print(" ", file=f) |
| 240 | print(" /* todo: if areg = LIMM then there is no result (but since that register can never be read, I guess it doesn't matter if we store it there anyway?) */", file=f) |
| 241 | print(" %s" % opexecute, file=f) |
| 242 | print(" %s" % opwrite_alt, file=f) |
| 243 | print(" ", file=f) |
| 243 | 244 | EmitGroup04_Flaghandler(f,funcname,opname,flagcondition,flaghandler) |
| 244 | | print >>f, " return m_pc + (size >> 0);" |
| 245 | | print >>f, "}" |
| 246 | | print >>f, "" |
| 247 | | print >>f, "" |
| 245 | print(" return m_pc + (size >> 0);", file=f) |
| 246 | print("}", file=f) |
| 247 | print("", file=f) |
| 248 | print("", file=f) |
| 248 | 249 | # the mode 0x11 m0 handler |
| 249 | | print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p11_m0(OPS_32)" % funcname |
| 250 | print("ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p11_m0(OPS_32)" % funcname, file=f) |
| 250 | 251 | if ignore_a == 2: |
| 251 | | print >>f, "{" |
| 252 | | print >>f, " int size = 4;" |
| 253 | | print >>f, " arcompact_fatal(\"illegal arcompact_handle%s_p11_m0 (ares bits already used as opcode select, can't be used as Q condition) (%s)\\n\");" % (funcname, opname) |
| 254 | | print >>f, " return m_pc + (size >> 0);" |
| 255 | | print >>f, "}" |
| 252 | print("{", file=f) |
| 253 | print(" int size = 4;", file=f) |
| 254 | print(" arcompact_fatal(\"illegal arcompact_handle%s_p11_m0 (ares bits already used as opcode select, can't be used as Q condition) (%s)\\n\");" % (funcname, opname), file=f) |
| 255 | print(" return m_pc + (size >> 0);", file=f) |
| 256 | print("}", file=f) |
| 256 | 257 | else: |
| 257 | | print >>f, "{" |
| 258 | | print >>f, " int size = 4;" |
| 259 | | print >>f, " arcompact_fatal(\"arcompact_handle%s_p11_m0 (%s)\\n\");" % (funcname, opname) |
| 260 | | print >>f, " return m_pc + (size >> 0);" |
| 261 | | print >>f, "}" |
| 262 | | print >>f, "" |
| 263 | | print >>f, "" |
| 258 | print("{", file=f) |
| 259 | print(" int size = 4;", file=f) |
| 260 | print(" arcompact_fatal(\"arcompact_handle%s_p11_m0 (%s)\\n\");" % (funcname, opname), file=f) |
| 261 | print(" return m_pc + (size >> 0);", file=f) |
| 262 | print("}", file=f) |
| 263 | print("", file=f) |
| 264 | print("", file=f) |
| 264 | 265 | # the mode 0x11 m1 handler |
| 265 | | print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p11_m1(OPS_32)" % funcname |
| 266 | print("ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p11_m1(OPS_32)" % funcname, file=f) |
| 266 | 267 | if ignore_a == 2: |
| 267 | | print >>f, "{" |
| 268 | | print >>f, " int size = 4;" |
| 269 | | print >>f, " arcompact_fatal(\"illegal arcompact_handle%s_p11_m1 (ares bits already used as opcode select, can't be used as Q condition) (%s)\\n\");" % (funcname, opname) |
| 270 | | print >>f, " return m_pc + (size >> 0);" |
| 271 | | print >>f, "}" |
| 268 | print("{", file=f) |
| 269 | print(" int size = 4;", file=f) |
| 270 | print(" arcompact_fatal(\"illegal arcompact_handle%s_p11_m1 (ares bits already used as opcode select, can't be used as Q condition) (%s)\\n\");" % (funcname, opname), file=f) |
| 271 | print(" return m_pc + (size >> 0);", file=f) |
| 272 | print("}", file=f) |
| 272 | 273 | else: |
| 273 | | print >>f, "{" |
| 274 | print("{", file=f) |
| 274 | 275 | EmitGroup04_u5fragment(f,funcname, opname, opexecute, opwrite, opwrite_alt, 3, breg_is_dst_only, flagcondition, flaghandler) |
| 275 | | print >>f, " COMMON32_GET_CONDITION;" |
| 276 | | print >>f, " if (!check_condition(condition))" |
| 277 | | print >>f, " return m_pc + (size>>0);" |
| 278 | | print >>f, "" |
| 279 | | print >>f, " %s" % opexecute |
| 280 | | print >>f, " %s" % opwrite_alt |
| 281 | | print >>f, " " |
| 276 | print(" COMMON32_GET_CONDITION;", file=f) |
| 277 | print(" if (!check_condition(condition))", file=f) |
| 278 | print(" return m_pc + (size>>0);", file=f) |
| 279 | print("", file=f) |
| 280 | print(" %s" % opexecute, file=f) |
| 281 | print(" %s" % opwrite_alt, file=f) |
| 282 | print(" ", file=f) |
| 282 | 283 | EmitGroup04_Flaghandler(f,funcname,opname,flagcondition,flaghandler) |
| 283 | | print >>f, " return m_pc + (size >> 0);" |
| 284 | | print >>f, "}" |
| 285 | | print >>f, "" |
| 286 | | print >>f, "" |
| 284 | print(" return m_pc + (size >> 0);", file=f) |
| 285 | print("}", file=f) |
| 286 | print("", file=f) |
| 287 | print("", file=f) |
| 287 | 288 | |
| 288 | 289 | |
| 289 | 290 | # xxx_S c, b, u3 format opcodes (note c is destination) |
| 290 | 291 | def EmitGroup0d(f,funcname, opname, opexecute, opwrite): |
| 291 | | print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s(OPS_16)" % funcname |
| 292 | | print >>f, "{" |
| 293 | | print >>f, " int u, breg, creg;" |
| 294 | | print >>f, "" |
| 295 | | print >>f, " COMMON16_GET_u3;" |
| 296 | | print >>f, " COMMON16_GET_breg;" |
| 297 | | print >>f, " COMMON16_GET_creg;" |
| 298 | | print >>f, "" |
| 299 | | print >>f, " REG_16BIT_RANGE(breg);" |
| 300 | | print >>f, " REG_16BIT_RANGE(creg);" |
| 301 | | print >>f, "" |
| 302 | | print >>f, " %s" % opexecute |
| 303 | | print >>f, " %s" % opwrite |
| 304 | | print >>f, "" |
| 305 | | print >>f, " return m_pc + (2 >> 0);" |
| 306 | | print >>f, "}" |
| 307 | | print >>f, "" |
| 308 | | print >>f, "" |
| 292 | print("ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s(OPS_16)" % funcname, file=f) |
| 293 | print("{", file=f) |
| 294 | print(" int u, breg, creg;", file=f) |
| 295 | print("", file=f) |
| 296 | print(" COMMON16_GET_u3;", file=f) |
| 297 | print(" COMMON16_GET_breg;", file=f) |
| 298 | print(" COMMON16_GET_creg;", file=f) |
| 299 | print("", file=f) |
| 300 | print(" REG_16BIT_RANGE(breg);", file=f) |
| 301 | print(" REG_16BIT_RANGE(creg);", file=f) |
| 302 | print("", file=f) |
| 303 | print(" %s" % opexecute, file=f) |
| 304 | print(" %s" % opwrite, file=f) |
| 305 | print("", file=f) |
| 306 | print(" return m_pc + (2 >> 0);", file=f) |
| 307 | print("}", file=f) |
| 308 | print("", file=f) |
| 309 | print("", file=f) |
| 309 | 310 | |
| 310 | 311 | |
| 311 | 312 | # xxx_S b <- b,c format opcodes |
| 312 | 313 | def EmitGroup0f(f,funcname, opname, opexecute, opwrite): |
| 313 | | print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s(OPS_16)"% funcname |
| 314 | | print >>f, "{" |
| 315 | | print >>f, " int breg, creg;" |
| 316 | | print >>f, "" |
| 317 | | print >>f, " COMMON16_GET_breg;" |
| 318 | | print >>f, " COMMON16_GET_creg;" |
| 319 | | print >>f, "" |
| 320 | | print >>f, " REG_16BIT_RANGE(breg);" |
| 321 | | print >>f, " REG_16BIT_RANGE(creg);" |
| 322 | | print >>f, "" |
| 323 | | print >>f, " %s" % opexecute |
| 324 | | print >>f, " %s" % opwrite |
| 325 | | print >>f, "" |
| 326 | | print >>f, " return m_pc + (2 >> 0);" |
| 327 | | print >>f, "}" |
| 328 | | print >>f, "" |
| 329 | | print >>f, "" |
| 314 | print("ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s(OPS_16)"% funcname, file=f) |
| 315 | print("{", file=f) |
| 316 | print(" int breg, creg;", file=f) |
| 317 | print("", file=f) |
| 318 | print(" COMMON16_GET_breg;", file=f) |
| 319 | print(" COMMON16_GET_creg;", file=f) |
| 320 | print("", file=f) |
| 321 | print(" REG_16BIT_RANGE(breg);", file=f) |
| 322 | print(" REG_16BIT_RANGE(creg);", file=f) |
| 323 | print("", file=f) |
| 324 | print(" %s" % opexecute, file=f) |
| 325 | print(" %s" % opwrite, file=f) |
| 326 | print("", file=f) |
| 327 | print(" return m_pc + (2 >> 0);", file=f) |
| 328 | print("}", file=f) |
| 329 | print("", file=f) |
| 330 | print("", file=f) |
| 330 | 331 | |
| 331 | 332 | |
| 332 | 333 | # xxx_S b, b, u5 format opcodes |
| 333 | 334 | def EmitGroup17(f,funcname, opname, opexecute): |
| 334 | | print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s(OPS_16)" % funcname |
| 335 | | print >>f, "{" |
| 336 | | print >>f, " int breg, u;" |
| 337 | | print >>f, " " |
| 338 | | print >>f, " COMMON16_GET_breg;" |
| 339 | | print >>f, " COMMON16_GET_u5;" |
| 340 | | print >>f, " " |
| 341 | | print >>f, " REG_16BIT_RANGE(breg);" |
| 342 | | print >>f, " " |
| 343 | | print >>f, " %s" % opexecute |
| 344 | | print >>f, " " |
| 345 | | print >>f, " return m_pc + (2 >> 0);" |
| 346 | | print >>f, "}" |
| 347 | | print >>f, "" |
| 348 | | print >>f, "" |
| 335 | print("ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s(OPS_16)" % funcname, file=f) |
| 336 | print("{", file=f) |
| 337 | print(" int breg, u;", file=f) |
| 338 | print(" ", file=f) |
| 339 | print(" COMMON16_GET_breg;", file=f) |
| 340 | print(" COMMON16_GET_u5;", file=f) |
| 341 | print(" ", file=f) |
| 342 | print(" REG_16BIT_RANGE(breg);", file=f) |
| 343 | print(" ", file=f) |
| 344 | print(" %s" % opexecute, file=f) |
| 345 | print(" ", file=f) |
| 346 | print(" return m_pc + (2 >> 0);", file=f) |
| 347 | print("}", file=f) |
| 348 | print("", file=f) |
| 349 | print("", file=f) |
| 349 | 350 | |
| 350 | 351 | |
| 351 | 352 | |
trunk/src/emu/cpu/h8/h8make.py
| r248581 | r248582 | |
| 1 | 1 | #!/usr/bin/python |
| 2 | 2 | |
| 3 | from __future__ import print_function |
| 4 | |
| 3 | 5 | USAGE = """ |
| 4 | 6 | Usage: |
| 5 | 7 | %s h8.lst <type> h8.inc (type = o/h/s20/s26) |
| r248581 | r248582 | |
| 45 | 47 | return False |
| 46 | 48 | |
| 47 | 49 | def save_full_one(f, t, name, source): |
| 48 | | print >>f, "void %s::%s_full()" % (t, name) |
| 49 | | print >>f, "{" |
| 50 | print("void %s::%s_full()" % (t, name), file=f) |
| 51 | print("{", file=f) |
| 50 | 52 | substate = 1 |
| 51 | 53 | for line in source: |
| 52 | 54 | if has_memory(line): |
| 53 | | print >>f, "\tif(icount <= bcount) { inst_substate = %d; return; }" % substate |
| 54 | | print >>f, line |
| 55 | print("\tif(icount <= bcount) { inst_substate = %d; return; }" % substate, file=f) |
| 56 | print(line, file=f) |
| 55 | 57 | substate += 1 |
| 56 | 58 | elif has_eat(line): |
| 57 | | print >>f, "\tif(icount) icount = bcount; inst_substate = %d; return;" % substate |
| 59 | print("\tif(icount) icount = bcount; inst_substate = %d; return;" % substate, file=f) |
| 58 | 60 | substate += 1 |
| 59 | 61 | else: |
| 60 | | print >>f, line |
| 61 | | print >>f, "}" |
| 62 | | print >>f |
| 62 | print(line, file=f) |
| 63 | print("}", file=f) |
| 64 | print("", file=f) |
| 63 | 65 | |
| 64 | 66 | def save_partial_one(f, t, name, source): |
| 65 | | print >>f, "void %s::%s_partial()" % (t, name) |
| 66 | | print >>f, "{" |
| 67 | | print >>f, "switch(inst_substate) {" |
| 68 | | print >>f, "case 0:" |
| 67 | print("void %s::%s_partial()" % (t, name), file=f) |
| 68 | print("{", file=f) |
| 69 | print("switch(inst_substate) {", file=f) |
| 70 | print("case 0:", file=f) |
| 69 | 71 | substate = 1 |
| 70 | 72 | for line in source: |
| 71 | 73 | if has_memory(line): |
| 72 | | print >>f, "\tif(icount <= bcount) { inst_substate = %d; return; }" % substate |
| 73 | | print >>f, "case %d:;" % substate |
| 74 | | print >>f, line |
| 74 | print("\tif(icount <= bcount) { inst_substate = %d; return; }" % substate, file=f) |
| 75 | print("case %d:;" % substate, file=f) |
| 76 | print(line, file=f) |
| 75 | 77 | substate += 1 |
| 76 | 78 | elif has_eat(line): |
| 77 | | print >>f, "\tif(icount) icount = bcount; inst_substate = %d; return;" % substate |
| 78 | | print >>f, "case %d:;" % substate |
| 79 | print("\tif(icount) icount = bcount; inst_substate = %d; return;" % substate, file=f) |
| 80 | print("case %d:;" % substate, file=f) |
| 79 | 81 | substate += 1 |
| 80 | 82 | else: |
| 81 | | print >>f, line |
| 82 | | print >>f, "\tbreak;" |
| 83 | | print >>f, "}" |
| 84 | | print >>f, "\tinst_substate = 0;" |
| 85 | | print >>f, "}" |
| 86 | | print >>f |
| 83 | print(line, file=f) |
| 84 | print("\tbreak;", file=f) |
| 85 | print("}", file=f) |
| 86 | print("\tinst_substate = 0;", file=f) |
| 87 | print("}", file=f) |
| 88 | print("", file=f) |
| 87 | 89 | |
| 88 | 90 | class Hash: |
| 89 | 91 | def __init__(self, premask): |
| r248581 | r248582 | |
| 185 | 187 | else: |
| 186 | 188 | flags = "%d" % size |
| 187 | 189 | |
| 188 | | print >>f, "\t{ %d, 0x%08x, 0x%08x, 0x%04x, 0x%04x, \"%s\", DASM_%s, DASM_%s, %s }, // %s" % ( slot, val, mask, val2, mask2, self.name, self.am1 if self.am1 != "-" else "none", self.am2 if self.am2 != "-" else "none", flags, "needed" if self.needed else "inherited") |
| 190 | print("\t{ %d, 0x%08x, 0x%08x, 0x%04x, 0x%04x, \"%s\", DASM_%s, DASM_%s, %s }, // %s" % ( slot, val, mask, val2, mask2, self.name, self.am1 if self.am1 != "-" else "none", self.am2 if self.am2 != "-" else "none", flags, "needed" if self.needed else "inherited"), file=f) |
| 189 | 191 | |
| 190 | 192 | class Special: |
| 191 | 193 | def __init__(self, val, name, otype, dtype): |
| r248581 | r248582 | |
| 244 | 246 | return True |
| 245 | 247 | |
| 246 | 248 | def source(self): |
| 247 | | start = self.pos / 2 |
| 249 | start = self.pos // 2 |
| 248 | 250 | end = start + self.skip |
| 249 | 251 | s = [] |
| 250 | 252 | for i in range(start, end+1): |
| r248581 | r248582 | |
| 345 | 347 | h = self.get(d.id) |
| 346 | 348 | |
| 347 | 349 | def save_dasm(self, f, dname): |
| 348 | | print >>f, "const %s::disasm_entry %s::disasm_entries[] = {" % (dname, dname) |
| 350 | print("const %s::disasm_entry %s::disasm_entries[] = {" % (dname, dname), file=f) |
| 349 | 351 | for opc in self.opcode_info: |
| 350 | 352 | if opc.enabled: |
| 351 | 353 | opc.save_dasm(f) |
| 352 | | print >>f, "\t{ 0, 0, 0, 0, 0, \"illegal\", 0, 0, 2 }," |
| 353 | | print >>f, "};" |
| 354 | | print >>f |
| 354 | print("\t{ 0, 0, 0, 0, 0, \"illegal\", 0, 0, 2 },", file=f) |
| 355 | print("};", file=f) |
| 356 | print("", file=f) |
| 355 | 357 | |
| 356 | 358 | def save_opcodes(self, f, t): |
| 357 | 359 | for opc in self.opcode_info: |
| r248581 | r248582 | |
| 370 | 372 | save_partial_one(f, t, "dispatch_" + dsp.name, dsp.source()) |
| 371 | 373 | |
| 372 | 374 | def save_exec(self, f, t, dtype, v): |
| 373 | | print >>f, "void %s::do_exec_%s()" % (t, v) |
| 374 | | print >>f, "{" |
| 375 | | print >>f, "\tswitch(inst_state >> 16) {" |
| 375 | print("void %s::do_exec_%s()" % (t, v), file=f) |
| 376 | print("{", file=f) |
| 377 | print("\tswitch(inst_state >> 16) {", file=f) |
| 376 | 378 | for i in range(0, len(self.dispatch_info)+2): |
| 377 | 379 | if i == 1: |
| 378 | | print >>f, "\tcase 0x01: {" |
| 379 | | print >>f, "\t\tswitch(inst_state & 0xffff) {" |
| 380 | print("\tcase 0x01: {", file=f) |
| 381 | print("\t\tswitch(inst_state & 0xffff) {", file=f) |
| 380 | 382 | for sta in self.states_info: |
| 381 | 383 | if sta.enabled: |
| 382 | | print >>f, "\t\tcase 0x%02x: state_%s_%s(); break;" % (sta.val & 0xffff, sta.name, v) |
| 383 | | print >>f, "\t\t}" |
| 384 | | print >>f, "\t\tbreak;" |
| 385 | | print >>f, "\t}" |
| 384 | print("\t\tcase 0x%02x: state_%s_%s(); break;" % (sta.val & 0xffff, sta.name, v), file=f) |
| 385 | print("\t\t}", file=f) |
| 386 | print("\t\tbreak;", file=f) |
| 387 | print("\t}", file=f) |
| 386 | 388 | else: |
| 387 | 389 | if i == 0 or self.dispatch_info[i-2].enabled: |
| 388 | | print >>f, "\tcase 0x%02x: {" % i |
| 390 | print("\tcase 0x%02x: {" % i, file=f) |
| 389 | 391 | h = self.get(i) |
| 390 | | print >>f, "\t\tswitch((inst_state >> 8) & 0x%02x) {" % h.mask |
| 392 | print("\t\tswitch((inst_state >> 8) & 0x%02x) {" % h.mask, file=f) |
| 391 | 393 | for val, h2 in sorted(h.d.items()): |
| 392 | 394 | if h2.enabled: |
| 393 | 395 | fmask = h2.premask | (h.mask ^ 0xff) |
| r248581 | r248582 | |
| 398 | 400 | s += 1 |
| 399 | 401 | while s & fmask: |
| 400 | 402 | s += s & fmask |
| 401 | | print >>f, "\t\t%s{" % c |
| 403 | print("\t\t%s{" % c, file=f) |
| 402 | 404 | if h2.mask == 0x00: |
| 403 | 405 | n = h2.d[0] |
| 404 | 406 | if n.is_dispatch(): |
| 405 | | print >>f, "\t\t\tdispatch_%s_%s();" % (n.name, v) |
| 407 | print("\t\t\tdispatch_%s_%s();" % (n.name, v), file=f) |
| 406 | 408 | else: |
| 407 | | print >>f, "\t\t\t%s_%s();" % (n.function_name(), v) |
| 408 | | print >>f, "\t\t\tbreak;" |
| 409 | print("\t\t\t%s_%s();" % (n.function_name(), v), file=f) |
| 410 | print("\t\t\tbreak;", file=f) |
| 409 | 411 | else: |
| 410 | | print >>f, "\t\t\tswitch(inst_state & 0x%02x) {" % h2.mask |
| 412 | print("\t\t\tswitch(inst_state & 0x%02x) {" % h2.mask, file=f) |
| 411 | 413 | if i == 0: |
| 412 | 414 | mpos = 1 |
| 413 | 415 | else: |
| r248581 | r248582 | |
| 427 | 429 | while s & fmask: |
| 428 | 430 | s += s & fmask |
| 429 | 431 | if n.is_dispatch(): |
| 430 | | print >>f, "\t\t\t%sdispatch_%s_%s(); break;" % (c, n.name, v) |
| 432 | print("\t\t\t%sdispatch_%s_%s(); break;" % (c, n.name, v), file=f) |
| 431 | 433 | else: |
| 432 | | print >>f, "\t\t\t%s%s_%s(); break;" % (c, n.function_name(), v) |
| 433 | | print >>f, "\t\t\tdefault: illegal(); break;" |
| 434 | | print >>f, "\t\t\t}" |
| 435 | | print >>f, "\t\t\tbreak;" |
| 436 | | print >>f, "\t\t}" |
| 437 | | print >>f, "\t\tdefault: illegal(); break;" |
| 438 | | print >>f, "\t\t}" |
| 439 | | print >>f, "\t\tbreak;" |
| 440 | | print >>f, "\t}" |
| 441 | | print >>f, "\t}" |
| 442 | | print >>f, "}" |
| 434 | print("\t\t\t%s%s_%s(); break;" % (c, n.function_name(), v), file=f) |
| 435 | print("\t\t\tdefault: illegal(); break;", file=f) |
| 436 | print("\t\t\t}", file=f) |
| 437 | print("\t\t\tbreak;", file=f) |
| 438 | print("\t\t}", file=f) |
| 439 | print("\t\tdefault: illegal(); break;", file=f) |
| 440 | print("\t\t}", file=f) |
| 441 | print("\t\tbreak;", file=f) |
| 442 | print("\t}", file=f) |
| 443 | print("\t}", file=f) |
| 444 | print("}", file=f) |
| 443 | 445 | |
| 444 | 446 | def main(argv): |
| 445 | 447 | if len(argv) != 4: |
| 446 | | print USAGE % argv[0] |
| 448 | print(USAGE % argv[0]) |
| 447 | 449 | return 1 |
| 448 | 450 | |
| 449 | 451 | dtype = name_to_type(argv[2]) |