4 // in/out address in r0, trashes all temp regs
\r
5 static void CheckPc(void)
\r
7 #if USE_CHECKPC_CALLBACK
\r
8 ot(";@ Check Memory Base+pc\n");
\r
10 ot(" ldr pc,[r7,#0x64] ;@ Call checkpc()\n");
\r
15 // Push 32-bit value in r1 - trashes r0-r3,r12,lr
\r
18 ot(";@ Push r1 onto stack\n");
\r
19 ot(" ldr r0,[r7,#0x3c]\n");
\r
20 ot(" sub r0,r0,#4 ;@ Predecrement A7\n");
\r
21 ot(" str r0,[r7,#0x3c] ;@ Save A7\n");
\r
26 // Push SR - trashes r0-r3,r12,lr
\r
27 void OpPushSr(int high)
\r
29 ot(";@ Push SR:\n");
\r
31 ot(" ldr r0,[r7,#0x3c]\n");
\r
32 ot(" sub r0,r0,#2 ;@ Predecrement A7\n");
\r
33 ot(" str r0,[r7,#0x3c] ;@ Save A7\n");
\r
38 // Pop SR - trashes r0-r3
\r
39 static void PopSr(int high)
\r
42 ot(" ldr r0,[r7,#0x3c]\n");
\r
43 ot(" add r1,r0,#2 ;@ Postincrement A7\n");
\r
44 ot(" str r1,[r7,#0x3c] ;@ Save A7\n");
\r
50 // Pop PC - trashes r0-r3
\r
54 ot(" ldr r0,[r7,#0x3c]\n");
\r
55 ot(" add r1,r0,#4 ;@ Postincrement A7\n");
\r
56 ot(" str r1,[r7,#0x3c] ;@ Save A7\n");
\r
58 ot(" ldr r1,[r7,#0x60] ;@ Get Memory base\n");
\r
59 ot(" add r0,r0,r1 ;@ Memory Base+PC\n");
\r
62 #if EMULATE_ADDRESS_ERRORS_JUMP
\r
65 ot(" bic r4,r0,#1\n");
\r
74 if (op!=use) { OpUse(op,use); return 0; } // Use existing handler
\r
77 ot(" and r0,r8,#0xf ;@ Get trap number\n");
\r
78 ot(" orr r0,r0,#0x20 ;@ 32+n\n");
\r
79 ot(" bl Exception\n");
\r
82 Cycles=38; OpEnd(0x10);
\r
87 // --------------------- Opcodes 0x4e50+ ---------------------
\r
95 if (op!=use) { OpUse(op,use); return 0; } // Use existing handler
\r
101 EaCalc(11, 7, 8, 2, 1);
\r
102 EaRead(11, 1, 8, 2, 7, 1);
\r
105 ot(" ldr r0,[r7,#0x3c] ;@ Get A7\n");
\r
106 ot(" sub r0,r0,#4 ;@ A7-=4\n");
\r
107 ot(" mov r8,r0 ;@ abuse r8\n");
\r
108 if(reg==7) ot(" mov r1,r0\n");
\r
111 ot(";@ Write An to Stack\n");
\r
114 ot(";@ Save to An\n");
\r
116 EaWrite(11,8, 8, 2, 7, 1);
\r
118 ot(";@ Get offset:\n");
\r
119 EaCalc(0,0,0x3c,1); // abused r8 is ok because of imm EA
\r
120 EaRead(0,0,0x3c,1,0);
\r
122 ot(" add r8,r8,r0 ;@ Add offset to A7\n");
\r
123 ot(" str r8,[r7,#0x3c]\n");
\r
131 // --------------------- Opcodes 0x4e58+ ---------------------
\r
137 if (op!=use) { OpUse(op,use); return 0; } // Use existing handler
\r
142 EaCalc(11, 0xf, 8, 2, 1);
\r
143 EaRead(11, 0, 8, 2, 0xf, 1);
\r
145 ot(" add r8,r0,#4 ;@ A7+=4, abuse r8\n");
\r
147 ot(";@ Pop An from stack:\n");
\r
150 ot(" str r8,[r7,#0x3c] ;@ Save A7\n");
\r
152 ot(";@ An = value from stack:\n");
\r
153 EaWrite(11, 0, 8, 2, 7, 1);
\r
160 // --------------------- Opcodes 0x4e70+ ---------------------
\r
161 // 01001110 01110ttt
\r
166 type=op&7; // reset/nop/stop/rte/rtd/rts/trapv/rtr
\r
177 OpStart(op,0x10,0,0,1); Cycles=20;
\r
180 ot(" ldr r1,[r7,#0x44] ;@ reload SR high\n");
\r
182 #if EMULATE_ADDRESS_ERRORS_JUMP || EMULATE_ADDRESS_ERRORS_IO || EMULATE_HALT
\r
183 ot(" ldr r1,[r7,#0x58]\n");
\r
184 ot(" bic r1,r1,#0x0c ;@ clear 'not processing instruction' and 'doing addr error' bits\n");
\r
185 ot(" str r1,[r7,#0x58]\n");
\r
187 #if EMULATE_ADDRESS_ERRORS_JUMP
\r
188 ot(" tst r4,#1 ;@ address error?\n");
\r
189 ot(" bne ExceptionAddressError_r_prg_r4\n");
\r
191 opend_check_interrupt = 1;
\r
192 opend_check_trace = 1;
\r
197 OpStart(op,0x10); Cycles=16;
\r
199 #if EMULATE_ADDRESS_ERRORS_JUMP
\r
200 ot(" tst r4,#1 ;@ address error?\n");
\r
201 ot(" bne ExceptionAddressError_r_prg_r4\n");
\r
207 OpStart(op,0x10,0,1); Cycles=4;
\r
208 ot(" tst r10,#0x10000000\n");
\r
209 ot(" subne r5,r5,#%i\n",34);
\r
210 ot(" movne r0,#7 ;@ TRAPV exception\n");
\r
211 ot(" blne Exception\n");
\r
212 opend_op_changes_cycles = 1;
\r
217 OpStart(op,0x10); Cycles=20;
\r
220 #if EMULATE_ADDRESS_ERRORS_JUMP
\r
221 ot(" tst r4,#1 ;@ address error?\n");
\r
222 ot(" bne ExceptionAddressError_r_prg_r4\n");
\r
232 // --------------------- Opcodes 0x4e80+ ---------------------
\r
233 // Emit a Jsr/Jmp opcode, 01001110 1meeeeee
\r
241 // See if we can do this opcode:
\r
242 if (EaCanRead(sea,-1)==0) return 1;
\r
245 if (op!=use) { OpUse(op,use); return 0; } // Use existing handler
\r
247 OpStart(op,(op&0x40)?0:0x10);
\r
249 ot(" ldr r11,[r7,#0x60] ;@ Get Memory base\n");
\r
251 EaCalc(12,0x003f,sea,0);
\r
253 ot(";@ Jump - Get new PC from r12\n");
\r
254 ot(" add r0,r12,r11 ;@ Memory Base + New PC\n");
\r
259 ot(" ldr r2,[r7,#0x3c]\n");
\r
260 ot(" sub r1,r4,r11 ;@ r1 = Old PC\n");
\r
262 #if EMULATE_ADDRESS_ERRORS_JUMP
\r
263 // jsr prefetches next instruction before pushing old PC,
\r
264 // according to http://pasti.fxatari.com/68kdocs/68kPrefetch.html
\r
265 ot(" mov r4,r0\n");
\r
266 ot(" tst r4,#1 ;@ address error?\n");
\r
267 ot(" bne ExceptionAddressError_r_prg_r4\n");
\r
269 ot(" bic r4,r0,#1\n");
\r
274 ot(";@ Push old PC onto stack\n");
\r
275 ot(" sub r0,r2,#4 ;@ Predecrement A7\n");
\r
276 ot(" str r0,[r7,#0x3c] ;@ Save A7\n");
\r
280 Cycles=(op&0x40) ? 4 : 12;
\r
281 Cycles+=Ea_add_ns((op&0x40) ? g_jmp_cycle_table : g_jsr_cycle_table, sea);
\r
283 OpEnd((op&0x40)?0:0x10);
\r
288 // --------------------- Opcodes 0x50c8+ ---------------------
\r
290 // ARM version of 68000 condition codes:
\r
291 static char *Cond[16]=
\r
293 "", "", "hi","ls","cc","cs","ne","eq",
\r
294 "vc","vs","pl","mi","ge","lt","gt","le"
\r
297 // Emit a Dbra opcode, 0101cccc 11001nnn vv
\r
303 use=op&~7; // Use same handler
\r
306 if (op!=use) { OpUse(op,use); return 0; } // Use existing handler
\r
315 ot(" tst r10,#0x60000000 ;@ hi: !C && !Z\n");
\r
316 ot(" beq DbraTrue\n\n");
\r
319 ot(" tst r10,#0x60000000 ;@ ls: C || Z\n");
\r
320 ot(" bne DbraTrue\n\n");
\r
323 ot(";@ Is the condition true?\n");
\r
324 ot(" msr cpsr_flg,r10 ;@ ARM flags = 68000 flags\n");
\r
325 ot(";@ If so, don't dbra\n");
\r
326 ot(" b%s DbraTrue\n\n",Cond[cc]);
\r
332 ot(";@ Decrement Dn.w\n");
\r
333 ot(" and r1,r8,#0x0007\n");
\r
334 ot(" mov r1,r1,lsl #2\n");
\r
335 ot(" ldrsh r0,[r7,r1]\n");
\r
336 ot(" sub r0,r0,#1\n");
\r
337 ot(" strh r0,[r7,r1]\n");
\r
340 ot(";@ Check if Dn.w is -1\n");
\r
341 ot(" cmn r0,#1\n");
\r
343 #if (USE_CHECKPC_CALLBACK && USE_CHECKPC_DBRA) || EMULATE_ADDRESS_ERRORS_JUMP
\r
344 ot(" beq DbraMin1\n");
\r
347 ot(";@ Get Branch offset:\n");
\r
348 ot(" ldrsh r0,[r4]\n");
\r
349 ot(" add r0,r4,r0 ;@ r0 = New PC\n");
\r
351 #if EMULATE_ADDRESS_ERRORS_JUMP
\r
352 ot(" mov r4,r0\n");
\r
353 ot(" tst r4,#1 ;@ address error?\n");
\r
354 ot(" bne ExceptionAddressError_r_prg_r4\n");
\r
356 ot(" bic r4,r0,#1\n");
\r
360 ot(";@ Get Branch offset:\n");
\r
361 ot(" ldrnesh r0,[r4]\n");
\r
362 ot(" addeq r4,r4,#2 ;@ Skip branch offset\n");
\r
363 ot(" subeq r5,r5,#4 ;@ additional cycles\n");
\r
364 ot(" addne r4,r4,r0 ;@ r4 = New PC\n");
\r
365 ot(" bic r4,r4,#1\n"); // we do not emulate address errors
\r
372 //if (cc==0||cc>=2)
\r
375 ot(";@ condition true:\n");
\r
376 ot("DbraTrue%s\n", ms?"":":");
\r
377 ot(" add r4,r4,#2 ;@ Skip branch offset\n");
\r
383 #if (USE_CHECKPC_CALLBACK && USE_CHECKPC_DBRA) || EMULATE_ADDRESS_ERRORS_JUMP
\r
386 ot(";@ Dn.w is -1:\n");
\r
387 ot("DbraMin1%s\n", ms?"":":");
\r
388 ot(" add r4,r4,#2 ;@ Skip branch offset\n");
\r
398 // --------------------- Opcodes 0x6000+ ---------------------
\r
399 // Emit a Branch opcode 0110cccc nn (cccc=condition)
\r
400 int OpBranch(int op)
\r
402 int size=0,use=0,checkpc=0;
\r
407 offset=(char)(op&0xff);
\r
410 // Special offsets:
\r
411 if (offset==0) size=1;
\r
412 if (offset==-1) size=2;
\r
414 if (size==2) size=0; // 000 model does not support long displacement
\r
415 if (size) use=op; // 16-bit or 32-bit
\r
416 else use=(op&0xff00)+1; // Use same opcode for all 8-bit branches
\r
418 if (op!=use) { OpUse(op,use); return 0; } // Use existing handler
\r
419 OpStart(op,size?0x10:0);
\r
420 Cycles=10; // Assume branch taken
\r
428 ot(" tst r10,#0x60000000 ;@ hi: !C && !Z\n");
\r
429 ot(" bne BccDontBranch%i\n\n",8<<size);
\r
432 ot(" tst r10,#0x60000000 ;@ ls: C || Z\n");
\r
433 ot(" beq BccDontBranch%i\n\n",8<<size);
\r
436 ot(";@ Is the condition true?\n");
\r
437 ot(" msr cpsr_flg,r10 ;@ ARM flags = 68000 flags\n");
\r
438 ot(" b%s BccDontBranch%i\n\n",Cond[cc^1],8<<size);
\r
446 ot(" ldrsh r11,[r4] ;@ Fetch Branch offset\n");
\r
450 ot(" ldrh r2,[r4] ;@ Fetch Branch offset\n");
\r
451 ot(" ldrh r11,[r4,#2]\n");
\r
452 ot(" orr r11,r11,r2,lsl #16\n");
\r
457 ot(" mov r11,r8,asl #24 ;@ Shift 8-bit signed offset up...\n\n");
\r
458 asr_r11=",asr #24";
\r
461 ot(";@ Branch taken - Add on r0 to PC\n");
\r
465 ot(";@ Bsr - remember old PC\n");
\r
466 ot(" ldr r12,[r7,#0x60] ;@ Get Memory base\n");
\r
467 ot(" ldr r2,[r7,#0x3c]\n");
\r
468 ot(" sub r1,r4,r12 ;@ r1 = Old PC\n");
\r
469 if (size) ot(" add r1,r1,#%d\n",1<<size);
\r
471 ot(";@ Push r1 onto stack\n");
\r
472 ot(" sub r0,r2,#4 ;@ Predecrement A7\n");
\r
473 ot(" str r0,[r7,#0x3c] ;@ Save A7\n");
\r
476 Cycles=18; // always 18
\r
479 ot(" add r0,r4,r11%s ;@ r4 = New PC\n",asr_r11);
\r
481 #if USE_CHECKPC_CALLBACK && USE_CHECKPC_OFFSETBITS_8
\r
482 if (offset!=0 && offset!=-1) checkpc=1;
\r
484 #if USE_CHECKPC_CALLBACK && USE_CHECKPC_OFFSETBITS_16
\r
485 if (offset==0) checkpc=1;
\r
487 #if USE_CHECKPC_CALLBACK
\r
488 if (offset==-1) checkpc=1;
\r
490 if (checkpc) CheckPc();
\r
491 #if EMULATE_ADDRESS_ERRORS_JUMP
\r
492 ot(" mov r4,r0\n");
\r
493 ot(" tst r4,#1 ;@ address error?\n");
\r
494 ot(" bne ExceptionAddressError_r_prg_r4\n");
\r
496 ot(" bic r4,r0,#1\n");
\r
500 OpEnd(size?0x10:0);
\r
502 // since all "DontBranch" code is same for every size, output only once
\r
503 if (cc>=2&&(op&0xff00)==0x6200)
\r
505 ot("BccDontBranch%i%s\n", 8<<size, ms?"":":");
\r
506 if (size) ot(" add r4,r4,#%d\n",1<<size);
\r
507 Cycles+=(size==1) ? 2 : -2; // Branch not taken
\r