main
68kinst.h
1/*
2 Copyright 2013 Michael Pavone
3 This file is part of BlastEm.
4 BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text.
5*/
6#ifndef M68KINST_H_
7#define M68KINST_H_
8
9#include <stdint.h>
10
11#ifdef M68030
12#define M68020
13#endif
14#ifdef M68020
15#define M68010
16#endif
17
18typedef enum {
19 BIT_MOVEP_IMMED = 0,
20 MOVE_BYTE,
21 MOVE_LONG,
22 MOVE_WORD,
23 MISC,
24 QUICK_ARITH_LOOP,
25 BRANCH,
26 MOVEQ,
27 OR_DIV_SBCD,
28 SUB_SUBX,
29 A_LINE,
30 CMP_XOR,
31 AND_MUL_ABCD_EXG,
32 ADD_ADDX,
33 SHIFT_ROTATE,
34 F_LINE
35} m68k_optypes;
36
37typedef enum {
38 M68K_ABCD,
39 M68K_ADD,
40 M68K_ADDX,
41 M68K_AND,
42 M68K_ANDI_CCR,
43 M68K_ANDI_SR,
44 M68K_ASL,
45 M68K_ASR,
46 M68K_BCC,
47 M68K_BCHG,
48 M68K_BCLR,
49 M68K_BSET,
50 M68K_BSR,
51 M68K_BTST,
52 M68K_CHK,
53 M68K_CLR,
54 M68K_CMP,
55 M68K_DBCC,
56 M68K_DIVS,
57 M68K_DIVU,
58 M68K_EOR,
59 M68K_EORI_CCR,
60 M68K_EORI_SR,
61 M68K_EXG,
62 M68K_EXT,
63 M68K_ILLEGAL,
64 M68K_JMP,
65 M68K_JSR,
66 M68K_LEA,
67 M68K_LINK,
68 M68K_LSL,
69 M68K_LSR,
70 M68K_MOVE,
71 M68K_MOVE_CCR,
72 M68K_MOVE_FROM_SR,
73 M68K_MOVE_SR,
74 M68K_MOVE_USP,
75 M68K_MOVEM,
76 M68K_MOVEP,
77 M68K_MULS,
78 M68K_MULU,
79 M68K_NBCD,
80 M68K_NEG,
81 M68K_NEGX,
82 M68K_NOP,
83 M68K_NOT,
84 M68K_OR,
85 M68K_ORI_CCR,
86 M68K_ORI_SR,
87 M68K_PEA,
88 M68K_RESET,
89 M68K_ROL,
90 M68K_ROR,
91 M68K_ROXL,
92 M68K_ROXR,
93 M68K_RTE,
94 M68K_RTR,
95 M68K_RTS,
96 M68K_SBCD,
97 M68K_SCC,
98 M68K_STOP,
99 M68K_SUB,
100 M68K_SUBX,
101 M68K_SWAP,
102 M68K_TAS,
103 M68K_TRAP,
104 M68K_TRAPV,
105 M68K_TST,
106 M68K_UNLK,
107 M68K_INVALID,
108 M68K_A_LINE_TRAP,
109 M68K_F_LINE_TRAP,
110#ifdef M68010
111 M68K_BKPT,
112 M68K_MOVE_FROM_CCR,
113 M68K_MOVEC,
114 M68K_MOVES,
115 M68K_RTD,
116#endif
117#ifdef M68020
118 M68K_BFCHG,
119 M68K_BFCLR,
120 M68K_BFEXTS,
121 M68K_BFEXTU,
122 M68K_BFFFO,
123 M68K_BFINS,
124 M68K_BFSET,
125 M68K_BFTST,
126 M68K_CALLM,
127 M68K_CAS,
128 M68K_CAS2,
129 M68K_CHK2,
130 M68K_CMP2,
131 M68K_CP_BCC,
132 M68K_CP_DBCC,
133 M68K_CP_GEN,
134 M68K_CP_RESTORE,
135 M68K_CP_SAVE,
136 M68K_CP_SCC,
137 M68K_CP_TRAPCC,
138 M68K_DIVSL,
139 M68K_DIVUL,
140 M68K_EXTB,
141 M68K_PACK,
142 M68K_RTM,
143 M68K_TRAPCC,
144 M68K_UNPK,
145#endif
146} m68K_op;
147
148typedef enum {
149 VAR_NORMAL,
150 VAR_QUICK,
151 VAR_IMMEDIATE,
152 VAR_BYTE,
153 VAR_WORD,
154 VAR_LONG
155} m68K_variant;
156
157typedef enum {
158 OPSIZE_BYTE=0,
159 OPSIZE_WORD,
160 OPSIZE_LONG,
161 OPSIZE_INVALID,
162 OPSIZE_UNSIZED
163} m68K_opsizes;
164
165typedef enum {
166//actual addressing mode field values
167 MODE_REG = 0,
168 MODE_AREG,
169 MODE_AREG_INDIRECT,
170 MODE_AREG_POSTINC,
171 MODE_AREG_PREDEC,
172 MODE_AREG_DISPLACE,
173 MODE_AREG_INDEX_MEM, //bunch of relatively complicated modes
174 MODE_PC_INDIRECT_ABS_IMMED, //Modes that use the program counter, an absolute address or immediate value
175//expanded values
176 MODE_AREG_INDEX_DISP8,
177#ifdef M68020
178 MODE_AREG_INDEX_BASE_DISP,
179 MODE_AREG_PREINDEX,
180 MODE_AREG_POSTINDEX,
181 MODE_AREG_MEM_INDIRECT,
182 MODE_AREG_BASE_DISP,
183 MODE_INDEX_BASE_DISP,
184 MODE_PREINDEX,
185 MODE_POSTINDEX,
186 MODE_MEM_INDIRECT,
187 MODE_BASE_DISP,
188#endif
189 MODE_ABSOLUTE_SHORT,
190 MODE_ABSOLUTE,
191 MODE_PC_DISPLACE,
192 MODE_PC_INDEX_DISP8,
193#ifdef M68020
194 MODE_PC_INDEX_BASE_DISP,
195 MODE_PC_PREINDEX,
196 MODE_PC_POSTINDEX,
197 MODE_PC_MEM_INDIRECT,
198 MODE_PC_BASE_DISP,
199 MODE_ZPC_INDEX_BASE_DISP,
200 MODE_ZPC_PREINDEX,
201 MODE_ZPC_POSTINDEX,
202 MODE_ZPC_MEM_INDIRECT,
203 MODE_ZPC_BASE_DISP,
204#endif
205 MODE_IMMEDIATE,
206 MODE_IMMEDIATE_WORD,//used to indicate an immediate operand that only uses a single extension word even for a long operation
207 MODE_UNUSED
208} m68k_addr_modes;
209#ifdef M68020
210#define M68K_FLAG_BITFIELD 0x80
211#endif
212
213typedef enum {
214 COND_TRUE,
215 COND_FALSE,
216 COND_HIGH,
217 COND_LOW_SAME,
218 COND_CARRY_CLR,
219 COND_CARRY_SET,
220 COND_NOT_EQ,
221 COND_EQ,
222 COND_OVERF_CLR,
223 COND_OVERF_SET,
224 COND_PLUS,
225 COND_MINUS,
226 COND_GREATER_EQ,
227 COND_LESS,
228 COND_GREATER,
229 COND_LESS_EQ
230} m68K_condition;
231
232#ifdef M68010
233typedef enum {
234 CR_SFC,
235 CR_DFC,
236#ifdef M68020
237 CR_CACR,
238#endif
239 CR_USP,
240 CR_VBR,
241#ifdef M68020
242 CR_CAAR,
243 CR_MSP,
244 CR_ISP
245#endif
246} m68k_control_reg;
247
248#ifdef M68020
249#define MAX_HIGH_CR 0x804
250#define MAX_LOW_CR 0x002
251#else
252#define MAX_HIGH_CR 0x801
253#define MAX_LOW_CR 0x001
254#endif
255
256#endif
257
258typedef struct {
259#ifdef M68020
260 uint16_t bitfield;
261#endif
262 uint8_t addr_mode;
263 union {
264 struct {
265 uint8_t pri;
266 uint8_t sec;
267#ifdef M68020
268 uint8_t scale;
269 uint8_t disp_sizes;
270#endif
271 int32_t displacement;
272#ifdef M68020
273 int32_t outer_disp;
274#endif
275 } regs;
276 uint32_t immed;
277 } params;
278} m68k_op_info;
279
280typedef struct m68kinst {
281 uint8_t op;
282 uint8_t variant;
283 union {
284 uint8_t size;
285 uint8_t cond;
286 } extra;
287 uint8_t bytes;
288 uint32_t address;
289 m68k_op_info src;
290 m68k_op_info dst;
291} m68kinst;
292
293typedef enum {
294 VECTOR_RESET_STACK,
295 VECTOR_RESET_PC,
296 VECTOR_ACCESS_FAULT,
297 VECTOR_ADDRESS_ERROR,
298 VECTOR_ILLEGAL_INST,
299 VECTOR_INT_DIV_ZERO,
300 VECTOR_CHK,
301 VECTOR_TRAPV,
302 VECTOR_PRIV_VIOLATION,
303 VECTOR_TRACE,
304 VECTOR_LINE_1010,
305 VECTOR_LINE_1111,
306 VECTOR_COPROC_VIOLATION=13,
307 VECTOR_FORMAT_ERROR,
308 VECTOR_UNINIT_INTERRUPT,
309 VECTOR_SPURIOUS_INTERRUPT=24,
310 VECTOR_INT_1,
311 VECTOR_INT_2,
312 VECTOR_INT_3,
313 VECTOR_INT_4,
314 VECTOR_INT_5,
315 VECTOR_INT_6,
316 VECTOR_INT_7,
317 VECTOR_TRAP_0,
318 VECTOR_TRAP_1,
319 VECTOR_TRAP_2,
320 VECTOR_TRAP_3,
321 VECTOR_TRAP_4,
322 VECTOR_TRAP_5,
323 VECTOR_TRAP_6,
324 VECTOR_TRAP_7,
325 VECTOR_TRAP_8,
326 VECTOR_TRAP_9,
327 VECTOR_TRAP_10,
328 VECTOR_TRAP_11,
329 VECTOR_TRAP_12,
330 VECTOR_TRAP_13,
331 VECTOR_TRAP_14,
332 VECTOR_TRAP_15,
333 VECTOR_USER0 = 64
334} m68k_vector;
335
336typedef int (*format_label_fun)(char * dst, uint32_t address, void * data);
337
338uint16_t * m68k_decode(uint16_t * istream, m68kinst * dst, uint32_t address);
339uint32_t m68k_branch_target(m68kinst * inst, uint32_t *dregs, uint32_t *aregs);
340uint8_t m68k_is_branch(m68kinst * inst);
341uint8_t m68k_is_noncall_branch(m68kinst * inst);
342int m68k_disasm(m68kinst * decoded, char * dst);
343int m68k_disasm_labels(m68kinst * decoded, char * dst, format_label_fun label_fun, void * data);
344int m68k_default_label_fun(char * dst, uint32_t address, void * data);
345
346#endif
347