1 /*  src/q68/q68-const.h: Constants used in MC68000 emulation
2     Copyright 2009 Andrew Church
3 
4     This file is part of Yabause.
5 
6     Yabause is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10 
11     Yabause is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15 
16     You should have received a copy of the GNU General Public License
17     along with Yabause; if not, write to the Free Software
18     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
19 */
20 
21 #ifndef Q68_CONST_H
22 #define Q68_CONST_H
23 
24 /*************************************************************************/
25 
26 /* Configuration constants */
27 
28 /* Maximum size in bytes of a 68k code block for translation */
29 #ifndef Q68_JIT_MAX_BLOCK_SIZE
30 # define Q68_JIT_MAX_BLOCK_SIZE 4096
31 #endif
32 
33 /* Size of pages used in checking for writes to already-translated code
34  * (1 page = 1<<Q68_JIT_PAGE_BITS bytes) */
35 #ifndef Q68_JIT_PAGE_BITS
36 # define Q68_JIT_PAGE_BITS 8
37 #endif
38 
39 /* Number of entries in JIT call stack */
40 #ifndef Q68_JIT_CALLSTACK_SIZE
41 # define Q68_JIT_CALLSTACK_SIZE 8
42 #endif
43 
44 /* Maximum number of translated code segments (should be prime) */
45 #ifndef Q68_JIT_TABLE_SIZE
46 # define Q68_JIT_TABLE_SIZE 1009
47 #endif
48 
49 /* Maximum total size of translated instructions, in bytes */
50 #ifndef Q68_JIT_DATA_LIMIT
51 # define Q68_JIT_DATA_LIMIT 2000000
52 #endif
53 
54 /* Block size by which to expand native code buffer when translating */
55 #ifndef Q68_JIT_BLOCK_EXPAND_SIZE
56 # define Q68_JIT_BLOCK_EXPAND_SIZE 1024
57 #endif
58 
59 /* Size of branch target cache, in instructions */
60 #ifndef Q68_JIT_BTCACHE_SIZE
61 # define Q68_JIT_BTCACHE_SIZE 128
62 #endif
63 
64 /* Size of unresolved branch list */
65 #ifndef Q68_JIT_UNRES_BRANCH_SIZE
66 # define Q68_JIT_UNRES_BRANCH_SIZE 10
67 #endif
68 
69 /* Number of entries in self-modifying code blacklist */
70 #ifndef Q68_JIT_BLACKLIST_SIZE
71 # define Q68_JIT_BLACKLIST_SIZE 5
72 #endif
73 
74 /* Expiration timeout for blacklist entries (unit: q68_jit_run() calls) */
75 #ifndef Q68_JIT_BLACKLIST_TIMEOUT
76 # define Q68_JIT_BLACKLIST_TIMEOUT 100000
77 #endif
78 
79 /*************************************************************************/
80 
81 /* Status register bits */
82 
83 #define SR_T    (1<<15) // Trace
84 #define SR_S    (1<<13) // Supervisor mode
85 #define SR_I2   (1<<10) // Interrupt mask level (bit 2)
86 #define SR_I1   (1<< 9) // Interrupt mask level (bit 2)
87 #define SR_I0   (1<< 8) // Interrupt mask level (bit 2)
88 #define SR_X    (1<< 4) // Extend
89 #define SR_N    (1<< 3) // Negative
90 #define SR_Z    (1<< 2) // Zero
91 #define SR_V    (1<< 1) // Overflow
92 #define SR_C    (1<< 0) // Carry
93 
94 #define SR_T_SHIFT  15
95 #define SR_S_SHIFT  13
96 #define SR_I2_SHIFT 10
97 #define SR_I1_SHIFT  9
98 #define SR_I0_SHIFT  8
99 #define SR_X_SHIFT   4
100 #define SR_N_SHIFT   3
101 #define SR_Z_SHIFT   2
102 #define SR_V_SHIFT   1
103 #define SR_C_SHIFT   0
104 
105 /* Macros to get and set the interrupt level bits */
106 #define SR_GET_I(state)     (((state)->SR >> SR_I0_SHIFT) & 7)
107 #define SR_SET_I(state,val)  ((state)->SR &= ~(7 << SR_I0_SHIFT), \
108                               (state)->SR |= ((val) & 7) << SR_I0_SHIFT)
109 
110 /*-----------------------------------------------------------------------*/
111 
112 /* Exception numbers */
113 
114 #define EX_INITIAL_SP            0
115 #define EX_INITIAL_PC            1
116 #define EX_BUS_ERROR             2
117 #define EX_ADDRESS_ERROR         3
118 #define EX_ILLEGAL_INSTRUCTION   4
119 #define EX_DIVIDE_BY_ZERO        5
120 #define EX_CHK                   6
121 #define EX_TRAPV                 7
122 #define EX_PRIVILEGE_VIOLATION   8
123 #define EX_TRACE                 9
124 #define EX_LINE_1010            10
125 #define EX_LINE_1111            11
126 
127 #define EX_SPURIOUS_INTERRUPT   24
128 #define EX_LEVEL_1_INTERRUPT    25
129 #define EX_LEVEL_2_INTERRUPT    26
130 #define EX_LEVEL_3_INTERRUPT    27
131 #define EX_LEVEL_4_INTERRUPT    28
132 #define EX_LEVEL_5_INTERRUPT    29
133 #define EX_LEVEL_6_INTERRUPT    30
134 #define EX_LEVEL_7_INTERRUPT    31
135 #define EX_TRAP                 32  // 16 vectors (EX_TRAP+0 .. EX_TRAP+15)
136 
137 /*-----------------------------------------------------------------------*/
138 
139 /* Bits in the fault status word for bus/address error exceptions */
140 
141 #define FAULT_STATUS_IN (1<<3)  // Instruction/Not (0 = instruction, 1 = not)
142 #define FAULT_STATUS_IN_INSN  (0)
143 #define FAULT_STATUS_IN_DATA  (FAULT_STATUS_IN)
144 
145 #define FAULT_STATUS_RW (1<<4)  // Read/Write (0 = write, 1 = read)
146 #define FAULT_STATUS_RW_READ  (FAULT_STATUS_RW)
147 #define FAULT_STATUS_RW_WRITE (0)
148 
149 /*-----------------------------------------------------------------------*/
150 
151 /* Condition codes for conditional instructions */
152 
153 #define COND_T    0
154 #define COND_F    1
155 #define COND_HI   2
156 #define COND_LS   3
157 #define COND_CC   4  // also HS
158 #define COND_CS   5  // also LO
159 #define COND_NE   6
160 #define COND_EQ   7
161 #define COND_VC   8
162 #define COND_VS   9
163 #define COND_PL  10
164 #define COND_MI  11
165 #define COND_GE  12
166 #define COND_LT  13
167 #define COND_GT  14
168 #define COND_LE  15
169 
170 /*-----------------------------------------------------------------------*/
171 
172 /* Size codes in opcode bits 6-7 */
173 
174 #define SIZE_B  0
175 #define SIZE_W  1
176 #define SIZE_L  2
177 
178 /* Macro to convert size codes to equivalent byte counts */
179 #define SIZE_TO_BYTES(size)  ((size) + 1 + ((size) == SIZE_L))
180 
181 /*-----------------------------------------------------------------------*/
182 
183 /* Effective address modes */
184 
185 #define EA_DATA_REG       0  // Data Register Direct
186 #define EA_ADDRESS_REG    1  // Address Register Direct
187 #define EA_INDIRECT       2  // Address Register Indirect
188 #define EA_POSTINCREMENT  3  // Address Register Indirect with Postincrement
189 #define EA_PREDECREMENT   4  // Address Register Indirect with Predecrement
190 #define EA_DISPLACEMENT   5  // Address Register Indirect with Displacement
191 #define EA_INDEX          6  // Address Register Indirect with Index
192 #define EA_MISC           7
193 
194 #define EA_MISC_ABSOLUTE_W   0  // Absolute Short
195 #define EA_MISC_ABSOLUTE_L   1  // Absolute Long
196 #define EA_MISC_PCREL        2  // Program Counter Indirect with Displacement
197 #define EA_MISC_PCREL_INDEX  3  // Program Counter Indirect with Index
198 #define EA_MISC_IMMEDIATE    4  // Immediate
199 
200 /* Macros to retrieve the mode and register number from an opcode */
201 #define EA_MODE(opcode) ((opcode)>>3 & 7)
202 #define EA_REG(opcode)  ((opcode)>>0 & 7)
203 
204 /*************************************************************************/
205 /*************************************************************************/
206 
207 #endif  // Q68_CONST_H
208 
209 /*
210  * Local variables:
211  *   c-file-style: "stroustrup"
212  *   c-file-offsets: ((case-label . *) (statement-case-intro . *))
213  *   indent-tabs-mode: nil
214  * End:
215  *
216  * vim: expandtab shiftwidth=4:
217  */
218