Previous 15994 Revisions Next

r1037 Wednesday 26th September, 2007 at 18:17:11 UTC by Nathan Woods
Updated MIPS core to 0.119u1 (SVN is flaky)
[src/emu/cpu/mips]mdrcold.c mips3.c mips3.h mips3com.h mips3drc.c mips3fe.c* mips3fe.h*

src/emu/cpu/mips/mips3com.h
r1036r1037
1818***************************************************************************/
1919
2020/* core parameters */
21#define MIPS3_MIN_PAGE_SHIFT   12
22#define MIPS3_MIN_PAGE_SIZE      (1 << MIPS3_MIN_PAGE_SHIFT)
23#define MIPS3_MIN_PAGE_MASK      (MIPS3_MIN_PAGE_SIZE - 1)
24#define MIPS3_MAX_PADDR_SHIFT   32
21#define MIPS3_MIN_PAGE_SHIFT      12
22#define MIPS3_MIN_PAGE_SIZE         (1 << MIPS3_MIN_PAGE_SHIFT)
23#define MIPS3_MIN_PAGE_MASK         (MIPS3_MIN_PAGE_SIZE - 1)
24#define MIPS3_MAX_PADDR_SHIFT      32
2525
26/* cycle parameters */
27#define MIPS3_COUNT_READ_CYCLES      250
28#define MIPS3_CAUSE_READ_CYCLES      250
29
2630/* MIPS flavors */
2731enum _mips3_flavor
2832{
src/emu/cpu/mips/mips3.h
r1036r1037
121121};
122122
123123
124
124125/***************************************************************************
125126    INTERRUPT CONSTANTS
126127***************************************************************************/
r1036r1037
187188#define MIPS3DRC_STRICT_COP0      0x0002         /* validate all COP0 instructions */
188189#define MIPS3DRC_STRICT_COP1      0x0004         /* validate all COP1 instructions */
189190#define MIPS3DRC_STRICT_COP2      0x0008         /* validate all COP2 instructions */
190#define MIPS3DRC_DIRECT_RAM         0x0010         /* allow direct RAM access (no bankswitching!) */
191191#define MIPS3DRC_FLUSH_PC         0x0020         /* flush the PC value before each memory access */
192192#define MIPS3DRC_CHECK_OVERFLOWS   0x0040         /* actually check overflows on add/sub instructions */
193193
194194#define MIPS3DRC_COMPATIBLE_OPTIONS   (MIPS3DRC_STRICT_VERIFY | MIPS3DRC_STRICT_COP0 | MIPS3DRC_STRICT_COP1 | MIPS3DRC_STRICT_COP2 | MIPS3DRC_FLUSH_PC)
195#define MIPS3DRC_FASTEST_OPTIONS   (MIPS3DRC_DIRECT_RAM)
195#define MIPS3DRC_FASTEST_OPTIONS   (0)
196196
197197
198198
src/emu/cpu/mips/mips3fe.c
r0r1037
1/***************************************************************************
2
3    mips3fe.c
4
5    Front-end for MIPS3 recompiler
6
7***************************************************************************/
8
9#include <stddef.h>
10#include "cpuintrf.h"
11#include "mips3fe.h"
12
13
14/***************************************************************************
15    CONSTANTS
16***************************************************************************/
17
18#define MAX_STACK_DEPTH      100
19
20
21
22/***************************************************************************
23    TYPE DEFINITIONS
24***************************************************************************/
25
26typedef struct _pc_stack_entry pc_stack_entry;
27struct _pc_stack_entry
28{
29   UINT32      targetpc;
30   UINT32      srcpc;
31};
32
33
34
35/***************************************************************************
36    LOCAL VARAIBLES
37***************************************************************************/
38
39static mips3_opcode_desc *desc_free_list;
40static mips3_opcode_desc **desc_array;
41static UINT32 desc_array_size;
42static UINT32 dummy_nop = 0;
43
44
45
46/***************************************************************************
47    FUNCTION PROTOTYPES
48***************************************************************************/
49
50static int describe_one(mips3_state *mips, UINT32 curpc, mips3_opcode_desc *curdesc);
51static void describe_instruction(mips3_state *mips, UINT32 pc, UINT32 op, mips3_opcode_desc *desc);
52static void describe_instruction_special(mips3_state *mips, UINT32 pc, UINT32 op, mips3_opcode_desc *desc);
53static void describe_instruction_regimm(mips3_state *mips, UINT32 pc, UINT32 op, mips3_opcode_desc *desc);
54static void describe_instruction_idt(mips3_state *mips, UINT32 pc, UINT32 op, mips3_opcode_desc *desc);
55static void describe_instruction_cop0(mips3_state *mips, UINT32 pc, UINT32 op, mips3_opcode_desc *desc);
56static void describe_instruction_cop1(mips3_state *mips, UINT32 pc, UINT32 op, mips3_opcode_desc *desc);
57static void describe_instruction_cop1x(mips3_state *mips, UINT32 pc, UINT32 op, mips3_opcode_desc *desc);
58static void describe_instruction_cop2(mips3_state *mips, UINT32 pc, UINT32 op, mips3_opcode_desc *desc);
59
60
61
62/***************************************************************************
63    INLINE FUNCTIONS
64***************************************************************************/
65
66INLINE mips3_opcode_desc *desc_alloc(void)
67{
68   mips3_opcode_desc *desc = desc_free_list;
69
70   /* pull a description off of the free list or allocate a new one */
71   if (desc != NULL)
72      desc_free_list = desc->next;
73   else
74      desc = malloc_or_die(sizeof(*desc));
75   return desc;
76}
77
78
79INLINE void desc_free(mips3_opcode_desc *desc)
80{
81   /* just put ourselves on the free list */
82   desc->next = desc_free_list;
83   desc_free_list = desc;
84}
85
86
87INLINE void invalid_opcode(mips3_opcode_desc *desc)
88{
89   desc->flags |= IDESC_WILL_CAUSE_EXCEPTION | IDESC_END_SEQUENCE | IDESC_INVALID_OPCODE;
90}
91
92
93INLINE int is_fixed_mapped(UINT32 pc)
94{
95   return (pc >= 0x80000000 && pc < 0xc0000000);
96}
97
98
99
100/***************************************************************************
101    CORE IMPLEMENTATION
102***************************************************************************/
103
104/*-------------------------------------------------
105    mips3fe_init - initialization
106-------------------------------------------------*/
107
108void mips3fe_init(void)
109{
110   desc_free_list = NULL;
111   desc_array = NULL;
112   desc_array_size = 0;
113}
114
115
116/*-------------------------------------------------
117    mipsfe_exit - clean up after ourselves
118-------------------------------------------------*/
119
120void mips3fe_exit(void)
121{
122   /* free our free list of descriptions */
123   while (desc_free_list != NULL)
124   {
125      mips3_opcode_desc *freeme = desc_free_list;
126      desc_free_list = desc_free_list->next;
127      free(freeme);
128   }
129
130   /* free the description array */
131   if (desc_array != NULL)
132      free(desc_array);
133   desc_array_size = 0;
134}
135
136
137/*-------------------------------------------------
138    mips3fe_describe_sequence - describe a
139    sequence of instructions that falls within
140    the given range
141-------------------------------------------------*/
142
143mips3_opcode_desc *mips3fe_describe_sequence(mips3_state *mips, UINT32 startpc, UINT32 minpc, UINT32 maxpc)
144{
145   pc_stack_entry pcstack[MAX_STACK_DEPTH];
146   pc_stack_entry *pcstackptr = &pcstack[0];
147   mips3_opcode_desc *head, **tailptr;
148   int descnum, descend;
149
150   /* make sure our array is big enough */
151   if ((maxpc - minpc) / 4 + 10 > desc_array_size)
152   {
153      desc_array_size = (maxpc - minpc) / 4 + 10;
154      desc_array = realloc(desc_array, desc_array_size * sizeof(desc_array[0]));
155      memset(desc_array, 0, desc_array_size * sizeof(desc_array[0]));
156   }
157
158   /* add the initial PC to the stack */
159   pcstackptr->srcpc = 0;
160   pcstackptr->targetpc = startpc;
161   pcstackptr++;
162
163   /* loop while we still have a stack */
164   while (pcstackptr != &pcstack[0])
165   {
166      pc_stack_entry *curstack = --pcstackptr;
167      mips3_opcode_desc *prevdesc = NULL;
168      mips3_opcode_desc *curdesc;
169      UINT32 curpc;
170
171      /* if we've already hit this PC, just mark it a branch target and continue */
172      curdesc = desc_array[(curstack->targetpc - minpc) / 4];
173      if (curdesc != NULL)
174      {
175         curdesc->flags |= IDESC_IS_BRANCH_TARGET;
176
177         /* if the branch crosses a page boundary, mark the target as needing to revalidate */
178         if (!is_fixed_mapped(curdesc->pc) && ((curstack->srcpc ^ curdesc->pc) & ~0xfff) != 0)
179            curdesc->flags |= IDESC_VALIDATE_TLB | IDESC_CAN_CAUSE_EXCEPTION;
180
181         /* continue processing */
182         continue;
183      }
184
185      /* loop until we exit the block */
186      for (curpc = curstack->targetpc; curpc < maxpc && desc_array[(curpc - minpc) / 4] == NULL; curpc += 4)
187      {
188         /* describe one instruction */
189         desc_array[(curpc - minpc) / 4] = curdesc = desc_alloc();
190         if (!describe_one(mips, curpc, curdesc))
191            break;
192
193         /* first instruction in a block is always a branch target */
194         if (curpc == curstack->targetpc)
195            curdesc->flags |= IDESC_IS_BRANCH_TARGET;
196
197         /* first instruction in a block or page must always validate the TLB */
198         if (!is_fixed_mapped(curpc) && (curpc == startpc || (curpc & 0xfff) == 0))
199            curdesc->flags |= IDESC_VALIDATE_TLB | IDESC_CAN_CAUSE_EXCEPTION;
200
201         /* if we are a branch, add the branch target to our stack */
202         if ((curdesc->flags & IDESC_IS_BRANCH) && curdesc->targetpc >= minpc && curdesc->targetpc < maxpc && pcstackptr < &pcstack[MAX_STACK_DEPTH])
203         {
204            curdesc->flags |= IDESC_INTRABLOCK_BRANCH;
205            pcstackptr->srcpc = curdesc->pc;
206            pcstackptr->targetpc = curdesc->targetpc;
207            pcstackptr++;
208         }
209
210         /* we now become the previous desc */
211         prevdesc = curdesc;
212
213         /* if we're done, we're done */
214         if (curdesc->flags & IDESC_END_SEQUENCE)
215            break;
216
217         /* if this is a likely branch, advance an extra 4 */
218         if (curdesc->flags & IDESC_IS_LIKELY_BRANCH)
219            curpc += 4;
220      }
221   }
222
223   /* now build the list of descriptions in order */
224   head = NULL;
225   tailptr = &head;
226
227   /* first from startpc -> maxpc */
228   descend = (maxpc - minpc) / 4;
229   for (descnum = (startpc - minpc) / 4; descnum < descend; descnum++)
230      if (desc_array[descnum] != NULL)
231      {
232         /* if this is a likely branch and we need the delay slot, mark it as end-of-sequence */
233         if ((desc_array[descnum]->flags & IDESC_IS_LIKELY_BRANCH) && desc_array[descnum + 1] != NULL)
234            desc_array[descnum]->flags |= IDESC_END_SEQUENCE;
235
236         /* if the next instruction is a branch target, mark this instruction as end of sequence */
237         if (descnum != descend - 1 && desc_array[descnum + 1] != NULL && (desc_array[descnum + 1]->flags & IDESC_IS_BRANCH_TARGET))
238            desc_array[descnum]->flags |= IDESC_END_SEQUENCE;
239
240         /* if we are the last instruction, indicate end-of-sequence and redispatch */
241         if (descnum == descend - 1 || (descnum == descend - 2 && (desc_array[descnum]->flags & IDESC_IS_LIKELY_BRANCH)))
242            desc_array[descnum]->flags |= IDESC_REDISPATCH | IDESC_END_SEQUENCE;
243
244         /* add us to the end of the list */
245         *tailptr = desc_array[descnum];
246         tailptr = &desc_array[descnum]->next;
247         desc_array[descnum] = NULL;
248      }
249
250   /* then from minpc -> startpc */
251   descend = (startpc - minpc) / 4;
252   for (descnum = (minpc - minpc) / 4; descnum < descend; descnum++)
253      if (desc_array[descnum] != NULL)
254      {
255         /* if this is a likely branch and we need the delay slot, mark it as end-of-sequence */
256         if ((desc_array[descnum]->flags & IDESC_IS_LIKELY_BRANCH) && desc_array[descnum + 1] != NULL)
257            desc_array[descnum]->flags |= IDESC_END_SEQUENCE;
258
259         /* if the next instruction is a branch target, mark this instruction as end of sequence */
260         if (descnum != descend - 1 && desc_array[descnum + 1] != NULL && (desc_array[descnum + 1]->flags & IDESC_IS_BRANCH_TARGET))
261            desc_array[descnum]->flags |= IDESC_END_SEQUENCE;
262
263         /* if we are the last instruction, indicate return-to-start and redispatch */
264         if (descnum == descend - 1 || (descnum == descend - 2 && (desc_array[descnum]->flags & IDESC_IS_LIKELY_BRANCH)))
265            desc_array[descnum]->flags |= IDESC_RETURN_TO_START | IDESC_END_SEQUENCE;
266
267         /* add us to the end of the list */
268         *tailptr = desc_array[descnum];
269         tailptr = &desc_array[descnum]->next;
270         desc_array[descnum] = NULL;
271      }
272
273   return head;
274}
275
276
277/*-------------------------------------------------
278    mips3fe_release_descriptions - release a
279    list of descriptions
280-------------------------------------------------*/
281
282void mips3fe_release_descriptions(mips3_opcode_desc *desc)
283{
284   while (desc != NULL)
285   {
286      mips3_opcode_desc *freeme = desc;
287      if (desc->delay != NULL)
288         mips3fe_release_descriptions(desc->delay);
289      desc = desc->next;
290      desc_free(freeme);
291   }
292}
293
294
295
296/***************************************************************************
297    INSTRUCTION PARSERS
298***************************************************************************/
299
300/*-------------------------------------------------
301    describe_one - describe a single instruction
302-------------------------------------------------*/
303
304static int describe_one(mips3_state *mips, UINT32 curpc, mips3_opcode_desc *curdesc)
305{
306   /* fill in default values */
307   curdesc->next = NULL;
308   curdesc->delay = NULL;
309   curdesc->pc = curpc;
310   curdesc->targetpc = ~0;
311   curdesc->flags = 0;
312   curdesc->cycles = 1;
313   curdesc->intused = 0;
314   curdesc->intmod = 0;
315   curdesc->fpused = 0;
316   curdesc->fpmod = 0;
317
318   /* determine the physical PC and pointer to opcode for this instruction */
319   curdesc->physpc = curpc;
320   if (!mips3com_translate_address(mips, ADDRESS_SPACE_PROGRAM, &curdesc->physpc))
321   {
322      /* if we're not mapped, generate an exception */
323      curdesc->opptr = &dummy_nop;
324      curdesc->flags = IDESC_CAN_CAUSE_EXCEPTION | IDESC_END_SEQUENCE | IDESC_REDISPATCH;
325      return FALSE;
326   }
327   curdesc->opptr = memory_get_op_ptr(cpu_getactivecpu(), curdesc->physpc, FALSE);
328   assert(curdesc->opptr != NULL);
329
330   /* describe this instruction */
331   describe_instruction(mips, curpc, *curdesc->opptr, curdesc);
332
333   /* if we are a branch, describe the delay slot as well */
334   if (curdesc->flags & IDESC_IS_BRANCH)
335   {
336      curdesc->delay = desc_alloc();
337      describe_one(mips, curpc + 4, curdesc->delay);
338      curdesc->delay->flags |= IDESC_IN_DELAY_SLOT;
339      curdesc->delay->branch = curdesc;
340   }
341   return TRUE;
342}
343
344
345/*-------------------------------------------------
346    describe_instruction - build a description
347    of a single instruction
348-------------------------------------------------*/
349
350static void describe_instruction(mips3_state *mips, UINT32 pc, UINT32 op, mips3_opcode_desc *desc)
351{
352   /* parse the instruction */
353   switch (op >> 26)
354   {
355      case 0x00:   /* SPECIAL */
356         describe_instruction_special(mips, pc, op, desc);
357         break;
358
359      case 0x01:   /* REGIMM */
360         describe_instruction_regimm(mips, pc, op, desc);
361         break;
362
363      case 0x10:   /* COP0 */
364         describe_instruction_cop0(mips, pc, op, desc);
365         break;
366
367      case 0x11:   /* COP1 */
368         describe_instruction_cop1(mips, pc, op, desc);
369         break;
370
371      case 0x12:   /* COP2 */
372         describe_instruction_cop2(mips, pc, op, desc);
373         break;
374
375      case 0x13:   /* COP1X - MIPS IV */
376         if (mips->flavor < MIPS3_TYPE_MIPS_IV)
377         {
378            invalid_opcode(desc);
379            break;
380         }
381         describe_instruction_cop1x(mips, pc, op, desc);
382         break;
383
384      case 0x1c:   /* IDT-specific opcodes: mad/madu/mul on R4640/4650, msub on RC32364 */
385         describe_instruction_idt(mips, pc, op, desc);
386         break;
387
388      case 0x02:   /* J */
389         desc->flags |= IDESC_IS_UNCONDITIONAL_BRANCH | IDESC_END_SEQUENCE;
390         desc->targetpc = (pc & 0xf0000000) | (LIMMVAL << 2);
391         break;
392
393      case 0x03:   /* JAL */
394         desc->intmod |= REGFLAG_R(31);
395         desc->flags |= IDESC_IS_UNCONDITIONAL_BRANCH | IDESC_END_SEQUENCE;
396         desc->targetpc = (pc & 0xf0000000) | (LIMMVAL << 2);
397         break;
398
399      case 0x14:   /* BEQL */
400      case 0x15:   /* BNEL */
401         desc->flags |= IDESC_IS_LIKELY_BRANCH;
402         /* fall through */
403
404      case 0x04:   /* BEQ */
405      case 0x05:   /* BNE */
406         if (((op >> 26) == 0x04 || (op >> 26) == 0x14) && RSREG == RTREG)
407            desc->flags |= IDESC_IS_UNCONDITIONAL_BRANCH | IDESC_END_SEQUENCE;
408         else
409         {
410            desc->intused |= REGFLAG_R(RSREG) | REGFLAG_R(RTREG);
411            desc->flags |= IDESC_IS_CONDITIONAL_BRANCH;
412         }
413         desc->targetpc = pc + 4 + (SIMMVAL << 2);
414         break;
415
416      case 0x16:   /* BLEZL */
417      case 0x17:   /* BGTZL */
418         desc->flags |= IDESC_IS_LIKELY_BRANCH;
419         /* fall through */
420
421      case 0x06:   /* BLEZ */
422      case 0x07:   /* BGTZ */
423         if (((op >> 26) == 0x06 || (op >> 26) == 0x16) && RSREG == 0)
424            desc->flags |= IDESC_IS_UNCONDITIONAL_BRANCH | IDESC_END_SEQUENCE;
425         else
426         {
427            desc->intused |= REGFLAG_R(RSREG);
428            desc->flags |= IDESC_IS_CONDITIONAL_BRANCH;
429         }
430         desc->targetpc = pc + 4 + (SIMMVAL << 2);
431         break;
432
433      case 0x08:   /* ADDI */
434      case 0x18:   /* DADDI */
435         desc->intused |= REGFLAG_R(RSREG);
436         desc->intmod |= REGFLAG_R(RTREG);
437         desc->flags |= IDESC_CAN_CAUSE_EXCEPTION;
438         break;
439
440      case 0x09:   /* ADDIU */
441      case 0x0a:   /* SLTI */
442      case 0x0b:   /* SLTIU */
443      case 0x0c:   /* ANDI */
444      case 0x0d:   /* ORI */
445      case 0x0e:   /* XORI */
446      case 0x19:   /* DADDIU */
447         desc->intused |= REGFLAG_R(RSREG);
448         desc->intmod |= REGFLAG_R(RTREG);
449         break;
450
451      case 0x0f:   /* LUI */
452         desc->intmod |= REGFLAG_R(RTREG);
453         break;
454
455      case 0x1a:   /* LDL */
456      case 0x1b:   /* LDR */
457      case 0x20:   /* LB */
458      case 0x21:   /* LH */
459      case 0x22:   /* LWL */
460      case 0x23:   /* LW */
461      case 0x24:   /* LBU */
462      case 0x25:   /* LHU */
463      case 0x26:   /* LWR */
464      case 0x27:   /* LWU */
465      case 0x30:   /* LL */
466      case 0x34:   /* LLD */
467      case 0x37:   /* LD */
468         desc->intused |= REGFLAG_R(RSREG);
469         desc->intmod |= REGFLAG_R(RTREG);
470         desc->flags |= IDESC_READS_MEMORY | IDESC_CAN_CAUSE_EXCEPTION;
471         break;
472
473      case 0x28:   /* SB */
474      case 0x29:   /* SH */
475      case 0x2a:   /* SWL */
476      case 0x2b:   /* SW */
477      case 0x2c:   /* SDL */
478      case 0x2d:   /* SDR */
479      case 0x2e:   /* SWR */
480      case 0x38:   /* SC */
481      case 0x3c:   /* SCD */
482      case 0x3f:   /* SD */
483         desc->intused |= REGFLAG_R(RSREG) | REGFLAG_R(RTREG);
484         desc->flags |= IDESC_WRITES_MEMORY | IDESC_CAN_CAUSE_EXCEPTION;
485         break;
486
487      case 0x31:   /* LWC1 */
488      case 0x35:   /* LDC1 */
489         desc->intused |= REGFLAG_R(RSREG);
490         desc->fpmod |= REGFLAG_CPR1(RTREG);
491         desc->flags |= IDESC_READS_MEMORY | IDESC_CAN_CAUSE_EXCEPTION;
492         break;
493
494      case 0x39:   /* SWC1 */
495      case 0x3d:   /* SDC1 */
496         desc->intused |= REGFLAG_R(RSREG);
497         desc->fpused |= REGFLAG_CPR1(RTREG);
498         desc->flags |= IDESC_WRITES_MEMORY | IDESC_CAN_CAUSE_EXCEPTION;
499         break;
500
501      case 0x32:   /* LWC2 */
502      case 0x36:   /* LDC2 */
503         desc->intused |= REGFLAG_R(RSREG);
504         desc->flags |= IDESC_READS_MEMORY | IDESC_CAN_CAUSE_EXCEPTION;
505         break;
506
507      case 0x3a:   /* SWC2 */
508      case 0x3e:   /* SDC2 */
509         desc->intused |= REGFLAG_R(RSREG);
510         desc->flags |= IDESC_WRITES_MEMORY | IDESC_CAN_CAUSE_EXCEPTION;
511         break;
512
513      case 0x2f:   /* CACHE */
514         /* effective no-op */
515         break;
516
517      case 0x33:   /* PREF */
518         if (mips->flavor < MIPS3_TYPE_MIPS_IV)
519            invalid_opcode(desc);
520         else
521            ; /* effective no-op */
522         break;
523
524      default: /* anything else */
525         invalid_opcode(desc);
526         break;
527   }
528
529   /* remove any modifications of R0 */
530   desc->intmod &= ~REGFLAG_R(0);
531}
532
533
534/*-------------------------------------------------
535    describe_instruction_special - build a
536    description of a single instruction in the
537    'special' group
538-------------------------------------------------*/
539
540static void describe_instruction_special(mips3_state *mips, UINT32 pc, UINT32 op, mips3_opcode_desc *desc)
541{
542   switch (op & 63)
543   {
544      case 0x00:   /* SLL */
545      case 0x02:   /* SRL */
546      case 0x03:   /* SRA */
547      case 0x38:   /* DSLL */
548      case 0x3a:   /* DSRL */
549      case 0x3b:   /* DSRA */
550      case 0x3c:   /* DSLL32 */
551      case 0x3e:   /* DSRL32 */
552      case 0x3f:   /* DSRA32 */
553         desc->intused |= REGFLAG_R(RTREG);
554         desc->intmod |= REGFLAG_R(RDREG);
555         break;
556
557      case 0x0a:   /* MOVZ - MIPS IV */
558      case 0x0b:   /* MOVN - MIPS IV */
559         if (mips->flavor < MIPS3_TYPE_MIPS_IV)
560         {
561            invalid_opcode(desc);
562            break;
563         }
564      case 0x04:   /* SLLV */
565      case 0x06:   /* SRLV */
566      case 0x07:   /* SRAV */
567      case 0x14:   /* DSLLV */
568      case 0x16:   /* DSRLV */
569      case 0x17:   /* DSRAV */
570      case 0x21:   /* ADDU */
571      case 0x23:   /* SUBU */
572      case 0x24:   /* AND */
573      case 0x25:   /* OR */
574      case 0x26:   /* XOR */
575      case 0x27:   /* NOR */
576      case 0x2a:   /* SLT */
577      case 0x2b:   /* SLTU */
578      case 0x2d:   /* DADDU */
579      case 0x2f:   /* DSUBU */
580         desc->intused |= REGFLAG_R(RSREG) | REGFLAG_R(RTREG);
581         desc->intmod |= REGFLAG_R(RDREG);
582         break;
583
584      case 0x20:   /* ADD */
585      case 0x22:   /* SUB */
586      case 0x2c:   /* DADD */
587      case 0x2e:   /* DSUB */
588         desc->intused |= REGFLAG_R(RSREG) | REGFLAG_R(RTREG);
589         desc->intmod |= REGFLAG_R(RDREG);
590         desc->flags |= IDESC_CAN_CAUSE_EXCEPTION;
591         break;
592
593      case 0x30:   /* TGE */
594      case 0x31:   /* TGEU */
595      case 0x32:   /* TLT */
596      case 0x33:   /* TLTU */
597      case 0x34:   /* TEQ */
598      case 0x36:   /* TNE */
599         desc->intused |= REGFLAG_R(RSREG) | REGFLAG_R(RTREG);
600         desc->flags |= IDESC_CAN_CAUSE_EXCEPTION;
601         break;
602
603      case 0x01:   /* MOVF - MIPS IV */
604         if (mips->flavor < MIPS3_TYPE_MIPS_IV)
605         {
606            invalid_opcode(desc);
607            break;
608         }
609         desc->intused |= REGFLAG_R(RSREG);
610         desc->fpused |= REGFLAG_FCC;
611         desc->intmod |= REGFLAG_R(RDREG);
612         break;
613
614      case 0x08:   /* JR */
615         desc->intused |= REGFLAG_R(RSREG);
616         desc->flags |= IDESC_IS_UNCONDITIONAL_BRANCH | IDESC_END_SEQUENCE;
617         break;
618
619      case 0x09:   /* JALR */
620         desc->intused |= REGFLAG_R(RSREG);
621         desc->intmod |= REGFLAG_R(RDREG);
622         desc->flags |= IDESC_IS_UNCONDITIONAL_BRANCH | IDESC_END_SEQUENCE;
623         break;
624
625      case 0x10:   /* MFHI */
626         desc->intused |= REGFLAG_HI;
627         desc->intmod |= REGFLAG_R(RDREG);
628         break;
629
630      case 0x11:   /* MTHI */
631         desc->intused |= REGFLAG_R(RSREG);
632         desc->intmod |= REGFLAG_HI;
633         break;
634
635      case 0x12:   /* MFLO */
636         desc->intused |= REGFLAG_LO;
637         desc->intmod |= REGFLAG_R(RDREG);
638         break;
639
640      case 0x13:   /* MTLO */
641         desc->intused |= REGFLAG_R(RSREG);
642         desc->intmod |= REGFLAG_LO;
643         break;
644
645      case 0x18:   /* MULT */
646      case 0x19:   /* MULTU */
647         desc->intused |= REGFLAG_R(RSREG) | REGFLAG_R(RTREG);
648         desc->intmod |= REGFLAG_LO | REGFLAG_HI;
649         desc->cycles = 3;
650         break;
651
652      case 0x1a:   /* DIV */
653      case 0x1b:   /* DIVU */
654         desc->intused |= REGFLAG_R(RSREG) | REGFLAG_R(RTREG);
655         desc->intmod |= REGFLAG_LO | REGFLAG_HI;
656         desc->cycles = 35;
657         break;
658
659      case 0x1c:   /* DMULT */
660      case 0x1d:   /* DMULTU */
661         desc->intused |= REGFLAG_R(RSREG) | REGFLAG_R(RTREG);
662         desc->intmod |= REGFLAG_LO | REGFLAG_HI;
663         desc->cycles = 7;
664         break;
665
666      case 0x1e:   /* DDIV */
667      case 0x1f:   /* DDIVU */
668         desc->intused |= REGFLAG_R(RSREG) | REGFLAG_R(RTREG);
669         desc->intmod |= REGFLAG_LO | REGFLAG_HI;
670         desc->cycles = 67;
671         break;
672
673      case 0x0c:   /* SYSCALL */
674      case 0x0d:   /* BREAK */
675         desc->flags |= IDESC_WILL_CAUSE_EXCEPTION | IDESC_END_SEQUENCE;
676         break;
677
678      case 0x0f:   /* SYNC */
679         /* effective no-op */
680         break;
681
682      default:   /* anything else */
683         invalid_opcode(desc);
684         break;
685   }
686}
687
688
689/*-------------------------------------------------
690    describe_instruction_regimm - build a
691    description of a single instruction in the
692    'regimm' group
693-------------------------------------------------*/
694
695static void describe_instruction_regimm(mips3_state *mips, UINT32 pc, UINT32 op, mips3_opcode_desc *desc)
696{
697   switch (RTREG)
698   {
699      case 0x02:   /* BLTZL */
700      case 0x03:   /* BGEZL */
701         desc->flags |= IDESC_IS_LIKELY_BRANCH;
702         /* fall through */
703
704      case 0x00:   /* BLTZ */
705      case 0x01:   /* BGEZ */
706         if (RTREG == 0x01 && RSREG == 0)
707            desc->flags |= IDESC_IS_UNCONDITIONAL_BRANCH | IDESC_END_SEQUENCE;
708         else
709         {
710            desc->intused |= REGFLAG_R(RSREG);
711            desc->flags |= IDESC_IS_CONDITIONAL_BRANCH;
712         }
713         desc->targetpc = pc + 4 + (SIMMVAL << 2);
714         break;
715
716      case 0x08:   /* TGEI */
717      case 0x09:   /* TGEIU */
718      case 0x0a:   /* TLTI */
719      case 0x0b:   /* TLTIU */
720      case 0x0c:   /* TEQI */
721      case 0x0e:   /* TNEI */
722         desc->intused |= REGFLAG_R(RSREG);
723         desc->flags |= IDESC_CAN_CAUSE_EXCEPTION;
724         break;
725
726      case 0x12:   /* BLTZALL */
727      case 0x13:   /* BGEZALL */
728         desc->flags |= IDESC_IS_LIKELY_BRANCH;
729         /* fall through */
730
731      case 0x10:   /* BLTZAL */
732      case 0x11:   /* BGEZAL */
733         if (RTREG == 0x11 && RSREG == 0)
734            desc->flags |= IDESC_IS_UNCONDITIONAL_BRANCH | IDESC_END_SEQUENCE;
735         else
736         {
737            desc->intused |= REGFLAG_R(RSREG);
738            desc->flags |= IDESC_IS_CONDITIONAL_BRANCH;
739         }
740         desc->intmod |= REGFLAG_R(31);
741         desc->targetpc = pc + 4 + (SIMMVAL << 2);
742         break;
743
744      default:   /* anything else */
745         invalid_opcode(desc);
746         break;
747   }
748}
749
750
751/*-------------------------------------------------
752    describe_instruction_idt - build a
753    description of a single instruction in the
754    IDT-specific group
755-------------------------------------------------*/
756
757static void describe_instruction_idt(mips3_state *mips, UINT32 pc, UINT32 op, mips3_opcode_desc *desc)
758{
759   switch (op & 0x1f)
760   {
761      case 2: /* MUL */
762         desc->intused |= REGFLAG_R(RSREG) | REGFLAG_R(RTREG);
763         desc->intmod |= REGFLAG_R(RDREG);
764         desc->cycles = 3;
765         break;
766
767      default: /* anything else */
768         invalid_opcode(desc);
769         break;
770   }
771}
772
773
774/*-------------------------------------------------
775    describe_instruction_cop0 - build a
776    description of a single instruction in the
777    COP0 group
778-------------------------------------------------*/
779
780static void describe_instruction_cop0(mips3_state *mips, UINT32 pc, UINT32 op, mips3_opcode_desc *desc)
781{
782   /* any COP0 instruction can potentially cause an exception */
783   desc->flags |= IDESC_CAN_CAUSE_EXCEPTION;
784
785   switch (RSREG)
786   {
787      case 0x00:   /* MFCz */
788      case 0x01:   /* DMFCz */
789      case 0x02:   /* CFCz */
790         desc->intmod |= REGFLAG_R(RTREG);
791         break;
792
793      case 0x04:   /* MTCz */
794      case 0x05:   /* DMTCz */
795      case 0x06:   /* CTCz */
796         desc->intused |= REGFLAG_R(RTREG);
797         if (RSREG == 0x04 || RSREG == 0x05)
798         {
799            if (RDREG == COP0_Cause)
800               desc->flags |= IDESC_CAN_TRIGGER_SW_INT;
801            if (RDREG == COP0_Status)
802               desc->flags |= IDESC_CAN_EXPOSE_EXTERNAL_INT;
803         }
804         break;
805
806      case 0x08:   /* BC */
807         switch (RTREG)
808         {
809            case 0x00:   /* BCzF */
810            case 0x01:   /* BCzT */
811               desc->flags |= IDESC_IS_CONDITIONAL_BRANCH;
812               desc->targetpc = pc + 4 + (SIMMVAL << 2);
813               break;
814
815            default: /* anything else */
816               invalid_opcode(desc);
817               break;
818         }
819         break;
820
821      case 0x10:   case 0x11:   case 0x12:   case 0x13:   case 0x14:   case 0x15:   case 0x16:   case 0x17:
822      case 0x18:   case 0x19:   case 0x1a:   case 0x1b:   case 0x1c:   case 0x1d:   case 0x1e:   case 0x1f:   /* COP */
823         switch (op & 0x01ffffff)
824         {
825            case 0x01:   /* TLBR */
826            case 0x08:   /* TLBP */
827               break;
828
829            case 0x02:   /* TLBWI */
830            case 0x06:   /* TLBWR */
831               desc->flags |= IDESC_MODIFIES_TRANSLATION;
832               break;
833
834            case 0x18:   /* ERET */
835               desc->flags |= IDESC_IS_UNCONDITIONAL_BRANCH | IDESC_END_SEQUENCE;
836               break;
837
838            default: /* anything else */
839               invalid_opcode(desc);
840               break;
841         }
842         break;
843
844      default: /* anything else */
845         invalid_opcode(desc);
846         break;
847   }
848}
849
850
851/*-------------------------------------------------
852    describe_instruction_cop1 - build a
853    description of a single instruction in the
854    COP1 group
855-------------------------------------------------*/
856
857static void describe_instruction_cop1(mips3_state *mips, UINT32 pc, UINT32 op, mips3_opcode_desc *desc)
858{
859   /* any COP1 instruction can potentially cause an exception */
860//  desc->flags |= IDESC_CAN_CAUSE_EXCEPTION;
861
862   switch (RSREG)
863   {
864      case 0x00:   /* MFCz */
865      case 0x01:   /* DMFCz */
866         desc->fpused |= REGFLAG_CPR1(RDREG);
867         desc->intmod |= REGFLAG_R(RTREG);
868         break;
869
870      case 0x02:   /* CFCz */
871         desc->intmod |= REGFLAG_R(RTREG);
872         break;
873
874      case 0x04:   /* MTCz */
875      case 0x05:   /* DMTCz */
876         desc->intused |= REGFLAG_R(RTREG);
877         desc->fpmod |= REGFLAG_CPR1(RDREG);
878         break;
879
880      case 0x06:   /* CTCz */
881         desc->intused |= REGFLAG_R(RTREG);
882         break;
883
884      case 0x08:   /* BC */
885         switch (RTREG)
886         {
887            case 0x02:   /* BCzFL */
888            case 0x03:   /* BCzTL */
889               desc->flags |= IDESC_IS_LIKELY_BRANCH;
890               /* fall through */
891
892            case 0x00:   /* BCzF */
893            case 0x01:   /* BCzT */
894               desc->fpused |= REGFLAG_FCC;
895               desc->flags |= IDESC_IS_CONDITIONAL_BRANCH;
896               desc->targetpc = pc + 4 + (SIMMVAL << 2);
897               break;
898
899            default: /* anything else */
900               invalid_opcode(desc);
901               break;
902         }
903         break;
904
905      case 0x10:   case 0x11:   case 0x12:   case 0x13:   case 0x14:   case 0x15:   case 0x16:   case 0x17:
906      case 0x18:   case 0x19:   case 0x1a:   case 0x1b:   case 0x1c:   case 0x1d:   case 0x1e:   case 0x1f:   /* COP */
907         switch (op & 0x3f)
908         {
909            case 0x12:   /* MOVZ - MIPS IV */
910            case 0x13:   /* MOVN - MIPS IV */
911               if (mips->flavor < MIPS3_TYPE_MIPS_IV)
912               {
913                  invalid_opcode(desc);
914                  break;
915               }
916            case 0x00:   /* ADD */
917            case 0x01:   /* SUB */
918            case 0x02:   /* MUL */
919            case 0x03:   /* DIV */
920               desc->fpused |= REGFLAG_CPR1(FSREG) | REGFLAG_CPR1(FTREG);
921               desc->fpmod |= REGFLAG_CPR1(FDREG);
922               break;
923
924            case 0x15:   /* RECIP - MIPS IV */
925            case 0x16:   /* RSQRT - MIPS IV */
926               if (mips->flavor < MIPS3_TYPE_MIPS_IV)
927               {
928                  invalid_opcode(desc);
929                  break;
930               }
931            case 0x04:   /* SQRT */
932            case 0x05:   /* ABS */
933            case 0x06:   /* MOV */
934            case 0x07:   /* NEG */
935            case 0x08:   /* ROUND.L */
936            case 0x09:   /* TRUNC.L */
937            case 0x0a:   /* CEIL.L */
938            case 0x0b:   /* FLOOR.L */
939            case 0x0c:   /* ROUND.W */
940            case 0x0d:   /* TRUNC.W */
941            case 0x0e:   /* CEIL.W */
942            case 0x0f:   /* FLOOR.W */
943            case 0x20:   /* CVT.S */
944            case 0x21:   /* CVT.D */
945            case 0x24:   /* CVT.W */
946            case 0x25:   /* CVT.L */
947               desc->fpused |= REGFLAG_CPR1(FSREG);
948               desc->fpmod |= REGFLAG_CPR1(FDREG);
949               break;
950
951            case 0x11:   /* MOVT/F - MIPS IV */
952               if (mips->flavor < MIPS3_TYPE_MIPS_IV)
953               {
954                  invalid_opcode(desc);
955                  break;
956               }
957               desc->fpused |= REGFLAG_CPR1(FSREG) | REGFLAG_FCC;
958               desc->fpmod |= REGFLAG_CPR1(FDREG);
959               break;
960
961            case 0x30:   case 0x38:   /* C.F */
962            case 0x31:   case 0x39:   /* C.UN */
963               desc->fpmod |= REGFLAG_FCC;
964               break;
965
966            case 0x32:   case 0x3a:   /* C.EQ */
967            case 0x33:   case 0x3b:   /* C.UEQ */
968            case 0x34:   case 0x3c:   /* C.OLT */
969            case 0x35:   case 0x3d:   /* C.ULT */
970            case 0x36:   case 0x3e:   /* C.OLE */
971            case 0x37:   case 0x3f:   /* C.ULE */
972               desc->fpused |= REGFLAG_CPR1(FSREG) | REGFLAG_CPR1(FTREG);
973               desc->fpmod |= REGFLAG_FCC;
974               break;
975
976            default: /* anything else */
977               invalid_opcode(desc);
978               break;
979         }
980         break;
981
982      default: /* anything else */
983         invalid_opcode(desc);
984         break;
985   }
986}
987
988
989/*-------------------------------------------------
990    describe_instruction_cop1x - build a
991    description of a single instruction in the
992    COP1X group
993-------------------------------------------------*/
994
995static void describe_instruction_cop1x(mips3_state *mips, UINT32 pc, UINT32 op, mips3_opcode_desc *desc)
996{
997   /* any COP1 instruction can potentially cause an exception */
998//  desc->flags |= IDESC_CAN_CAUSE_EXCEPTION;
999
1000   switch (op & 0x3f)
1001   {
1002      case 0x00:   /* LWXC1 */
1003      case 0x01:   /* LDXC1 */
1004         desc->intused |= REGFLAG_R(RSREG) | REGFLAG_R(RTREG);
1005         desc->fpmod |= REGFLAG_CPR1(FDREG);
1006         desc->flags |= IDESC_READS_MEMORY;
1007         break;
1008
1009      case 0x02:   /* SWXC1 */
1010      case 0x03:   /* SDXC1 */
1011         desc->intused |= REGFLAG_R(RSREG) | REGFLAG_R(RTREG);
1012         desc->fpused |= REGFLAG_CPR1(FDREG);
1013         desc->flags |= IDESC_WRITES_MEMORY;
1014         break;
1015
1016      case 0x0f:   /* PREFX */
1017         /* effective no-op */
1018         break;
1019
1020      case 0x20:   case 0x21:   /* MADD */
1021      case 0x28:   case 0x29:   /* MSUB */
1022      case 0x30:   case 0x31:   /* NMADD */
1023      case 0x32:   case 0x39:   /* NMSUB */
1024         desc->fpused |= REGFLAG_CPR1(FSREG) | REGFLAG_CPR1(FTREG) | REGFLAG_CPR1(FRREG);
1025         desc->fpmod |= REGFLAG_CPR1(FDREG);
1026         break;
1027
1028      default: /* anything else */
1029         invalid_opcode(desc);
1030         break;
1031   }
1032}
1033
1034
1035/*-------------------------------------------------
1036    describe_instruction_cop2 - build a
1037    description of a single instruction in the
1038    COP2 group
1039-------------------------------------------------*/
1040
1041static void describe_instruction_cop2(mips3_state *mips, UINT32 pc, UINT32 op, mips3_opcode_desc *desc)
1042{
1043   /* any COP2 instruction can potentially cause an exception */
1044   desc->flags |= IDESC_CAN_CAUSE_EXCEPTION;
1045
1046   switch (RSREG)
1047   {
1048      case 0x00:   /* MFCz */
1049      case 0x01:   /* DMFCz */
1050      case 0x02:   /* CFCz */
1051         desc->intmod |= REGFLAG_R(RTREG);
1052         break;
1053
1054      case 0x04:   /* MTCz */
1055      case 0x05:   /* DMTCz */
1056      case 0x06:   /* CTCz */
1057         desc->intused |= REGFLAG_R(RTREG);
1058         break;
1059
1060      case 0x08:   /* BC */
1061         switch (RTREG)
1062         {
1063            case 0x00:   /* BCzF */
1064            case 0x01:   /* BCzT */
1065               desc->flags |= IDESC_IS_CONDITIONAL_BRANCH;
1066               desc->targetpc = pc + 4 + (SIMMVAL << 2);
1067               break;
1068
1069            default: /* anything else */
1070               invalid_opcode(desc);
1071               break;
1072         }
1073         break;
1074
1075      default: /* anything else */
1076         invalid_opcode(desc);
1077         break;
1078   }
1079}
src/emu/cpu/mips/mips3fe.h
r0r1037
1/***************************************************************************
2
3    mips3fe.h
4
5    Front-end for MIPS3 recompiler
6
7***************************************************************************/
8
9#ifndef __MIPS3FE_H__
10#define __MIPS3FE_H__
11
12#include "mips3com.h"
13
14
15/***************************************************************************
16    CONSTANTS
17***************************************************************************/
18
19/* register flags */
20#define REGFLAG_R(n)               ((UINT64)1 << (n))
21#define REGFLAG_HI                  (REGFLAG_R(32))
22#define REGFLAG_LO                  (REGFLAG_R(33))
23#define REGFLAG_CPR1(n)               ((UINT64)1 << (n))
24#define REGFLAG_FCC                  (REGFLAG_CPR1(32))
25
26/* instruction description flags */
27#define IDESC_IS_UNCONDITIONAL_BRANCH   0x00000001      /* instruction is unconditional branch */
28#define IDESC_IS_CONDITIONAL_BRANCH      0x00000002      /* instruction is conditional branch */
29#define IDESC_IS_LIKELY_BRANCH         0x00000004      /* instruction is likely branch */
30#define IDESC_CAN_TRIGGER_SW_INT      0x00000008      /* instruction can trigger a software interrupt */
31#define IDESC_CAN_EXPOSE_EXTERNAL_INT   0x00000010      /* instruction can expose an external interrupt */
32#define IDESC_CAN_CAUSE_EXCEPTION      0x00000020      /* instruction may generate exception */
33#define IDESC_WILL_CAUSE_EXCEPTION      0x00000040      /* instruction will generate exception */
34#define IDESC_INVALID_OPCODE         0x00000080      /* instruction is invalid */
35#define IDESC_READS_MEMORY            0x00000100      /* instruction reads memory */
36#define IDESC_WRITES_MEMORY            0x00000200      /* instruction writes memory */
37#define IDESC_VALIDATE_TLB            0x00000400      /* instruction must validate TLB */
38#define IDESC_MODIFIES_TRANSLATION      0x00000800      /* instruction modifies the TLB */
39#define IDESC_REDISPATCH            0x00001000      /* instruction must redispatch */
40#define IDESC_RETURN_TO_START         0x00002000      /* instruction must jump back to the beginning */
41#define IDESC_IS_BRANCH_TARGET         0x00004000      /* instruction is the target of a branch */
42#define IDESC_IN_DELAY_SLOT            0x00008000      /* instruction is in the delay slot of a branch */
43#define IDESC_INTRABLOCK_BRANCH         0x00010000      /* instruction branches within the block */
44#define IDESC_END_SEQUENCE            0x00020000      /* this is the last instruction in a sequence */
45
46/* pre-defined groups of flags */
47#define IDESC_IS_BRANCH               (IDESC_IS_UNCONDITIONAL_BRANCH | IDESC_IS_CONDITIONAL_BRANCH)
48
49
50
51/***************************************************************************
52    TYPE DEFINITIONS
53***************************************************************************/
54
55typedef struct _mips3_opcode_desc mips3_opcode_desc;
56struct _mips3_opcode_desc
57{
58   mips3_opcode_desc *next;               /* pointer to next description */
59   mips3_opcode_desc *delay;               /* pointer to delay slot description */
60   mips3_opcode_desc *branch;               /* pointer back to branch description for delay slots */
61
62   UINT32         pc;                     /* PC of this opcode */
63   UINT32         physpc;                  /* physical PC of this opcode */
64   UINT32         targetpc;               /* target PC if we are a branch */
65
66   UINT32 *      opptr;                  /* physical memory pointer */
67   UINT32         flags;                  /* opcode flags */
68   UINT32         cycles;                  /* number of cycles needed to execute */
69
70   UINT64         intused;               /* integer registers used */
71   UINT64         intmod;                  /* integer registers modified */
72   UINT64         fpused;                  /* FPU registers used */
73   UINT64         fpmod;                  /* FPU registers modified */
74};
75
76
77
78/***************************************************************************
79    FUNCTION PROTOTYPES
80***************************************************************************/
81
82void mips3fe_init(void);
83void mips3fe_exit(void);
84
85mips3_opcode_desc *mips3fe_describe_sequence(mips3_state *mips, UINT32 startpc, UINT32 minpc, UINT32 maxpc);
86void mips3fe_release_descriptions(mips3_opcode_desc *desc);
87
88#endif
src/emu/cpu/mips/mips3drc.c
r1036r1037
2929    DEBUGGING
3030***************************************************************************/
3131
32#define LOG_CODE         (0)
32#define LOG_CODE            (0)
3333
34#ifdef MAME_DEBUG
35#define COMPARE_AGAINST_C      (0)
36#else
37#define COMPARE_AGAINST_C      (0)
38#endif
3439
3540
41
3642/***************************************************************************
3743    CONFIGURATION
3844***************************************************************************/
3945
40#define MAX_INSTRUCTIONS   512
41#define CACHE_SIZE         (32 * 1024 * 1024)
46#define MAX_INSTRUCTIONS      512
47#define CACHE_SIZE            (32 * 1024 * 1024)
4248
4349
4450
r1036r1037
4652    MACROS
4753***************************************************************************/
4854
49#define SR         mips3.core->cpr[0][COP0_Status]
50#define IS_FR0      (!(SR & SR_FR))
51#define IS_FR1      (SR & SR_FR)
55#define SR                  mips3.core->cpr[0][COP0_Status]
56#define IS_FR0               (!(SR & SR_FR))
57#define IS_FR1               (SR & SR_FR)
5258
5359
5460
r1036r1037
6268{
6369   UINT32      pc;
6470   UINT32      op;
65   void *      base;
71   x86code *   base;
72   const char *string;
6673};
6774
6875
r1036r1037
113120   /* hotspots */
114121   UINT32         hotspot_select;
115122   hotspot_info   hotspot[MIPS3_MAX_HOTSPOTS];
123
124#if COMPARE_AGAINST_C
125   /* memory state */
126   UINT8         access_size;
127   UINT8         access_type;
128   offs_t         access_addr;
129   UINT64         access_data;
130   UINT64         access_mask;
131   memory_handlers   orighandler;
132#endif
116133};
117134
118135
r1036r1037
124141static void mips3drc_init(void);
125142static void mips3drc_exit(void);
126143
144#if COMPARE_AGAINST_C
145static void execute_c_version(void);
146static void compare_c_version(void);
147static void mips3c_init(mips3_flavor flavor, int bigendian, int index, int clock, const struct mips3_config *config, int (*irqcallback)(int));
148static void mips3c_reset(void);
149#endif
127150
128151
152
129153/***************************************************************************
130154    PRIVATE GLOBAL VARIABLES
131155***************************************************************************/
r1036r1037
142166    mips3_init - initialize the processor
143167-------------------------------------------------*/
144168
145void mips3_init(mips3_state *mips, mips3_flavor flavor, int bigendian, int index, int clock, const struct mips3_config *config, int (*irqcallback)(int))
169static void mips3_init(mips3_state *mips, mips3_flavor flavor, int bigendian, int index, int clock, const struct mips3_config *config, int (*irqcallback)(int))
146170{
147171   /* allocate a cache and memory for the core data in a single block */
148172   mips3.core = osd_alloc_executable(CACHE_SIZE + sizeof(*mips3.core));
r1036r1037
152176
153177   /* initialize the core */
154178   mips3com_init(mips3.core, flavor, bigendian, index, clock, config, irqcallback);
179#if COMPARE_AGAINST_C
180   mips3c_init(flavor, bigendian, index, clock, config, irqcallback);
181#endif
155182
156183   /* initialize the DRC to use the cache */
157184   mips3drc_init();
r1036r1037
167194   /* reset the common code and flush the cache */
168195   mips3com_reset(mips3.core);
169196   drc_cache_reset(mips3.drc);
197
198#if COMPARE_AGAINST_C
199   mips3c_reset();
200#endif
170201}
171202
172203
r1036r1037
198229
199230static void mips3_exit(void)
200231{
232   /* clean up the DRC */
201233   mips3drc_exit();
202
203   /* clean up the DRC */
204234   drc_exit(mips3.drc);
205235
206236   /* free the cache */
r1036r1037
256286
257287
258288
289
259290/***************************************************************************
260291    CODE LOGGING
261292***************************************************************************/
r1036r1037
294325    code_log_add_entry - add an entry to the log
295326-------------------------------------------------*/
296327
297INLINE void code_log_add_entry(UINT32 pc, UINT32 op, void *base)
328INLINE void code_log_add_entry(x86code *base, UINT32 pc, UINT32 op)
298329{
330   code_log_buffer[code_log_index].base = base;
299331   code_log_buffer[code_log_index].pc = pc;
300332   code_log_buffer[code_log_index].op = op;
333   code_log_buffer[code_log_index].string = NULL;
334   code_log_index++;
335}
336
337
338/*-------------------------------------------------
339    code_log_add_entry_string - add a string
340    entry to the log
341-------------------------------------------------*/
342
343INLINE void code_log_add_entry_string(x86code *base, const char *string, UINT32 param)
344{
301345   code_log_buffer[code_log_index].base = base;
346   code_log_buffer[code_log_index].string = string;
347   code_log_buffer[code_log_index].op = param;
348   code_log_buffer[code_log_index].pc = 0;
302349   code_log_index++;
303350}
304351
r1036r1037
307354    code_log - actually log some code
308355-------------------------------------------------*/
309356
310static void code_log(const char *label, x86code *start, x86code *stop)
357static void print_log_entry(code_log_entry *entry, x86code *cur, const char *x86buffer)
311358{
312   extern int i386_dasm_one(char *buffer, UINT32 eip, UINT8 *oprom, int mode);
313359   extern unsigned dasmmips3(char *buffer, unsigned pc, UINT32 op);
314   UINT8 *cur = start;
315360
361   /* if we have a match and a string, print it */
362   if (entry->string != NULL)
363   {
364      fprintf(logfile, "%p: %-50s ", cur, x86buffer);
365      fprintf(logfile, entry->string, entry->op);
366      fprintf(logfile, "\n");
367   }
368
369   /* otherwise, output with the original instruction to the right */
370   else
371   {
372      char buffer2[100];
373      dasmmips3(buffer2, entry->pc, entry->op);
374      fprintf(logfile, "%p: %-50s %08X: %s\n", cur, x86buffer, entry->pc, buffer2);
375   }
376}
377
378static void code_log(const char *label, x86code *start, x86code *stop)
379{
380   extern int i386_dasm_one(char *buffer, UINT32 eip, const UINT8 *oprom, int mode);
381   x86code *cur = start;
382   int data_remaining = 0;
383
316384   /* open the file, creating it if necessary */
317385   if (!open_logfile())
318386      return;
r1036r1037
322390   while (cur < stop)
323391   {
324392      char buffer[100];
393      int op, lastop;
325394      int bytes;
326      int op;
327395
328396      /* skip filler opcodes */
329397      if (*cur == 0xcc)
r1036r1037
334402
335403      /* disassemble this instruction */
336404#ifdef PTR64
337      bytes = i386_dasm_one(buffer, (UINT32)(FPTR)cur, cur, 64) & DASMFLAG_LENGTHMASK;
405      /* look for special signatures and output as data */
406      if (cur[0] == 0x90 && cur[1] == 0xcc && cur[2] == 0x90 && cur[3] == 0xcc &&
407         cur[4] == 0x90 && cur[5] == 0xcc && cur[6] == 0x90 && cur[7] == 0xcc)
408         data_remaining = 2;
409
410      /* handle data cases first */
411      if (data_remaining > 0)
412      {
413         UINT64 data = *(UINT64 *)cur;
414         data_remaining--;
415         sprintf(buffer, "dq      %08X%08X", (UINT32)(data >> 32), (UINT32)data);
416         bytes = 8;
417      }
418      else
419         bytes = i386_dasm_one(buffer, (UINT32)(FPTR)cur, cur, 64) & DASMFLAG_LENGTHMASK;
338420#else
339421      bytes = i386_dasm_one(buffer, (UINT32)cur, cur, 32) & DASMFLAG_LENGTHMASK;
340422#endif
341423
342424      /* look for a match in the registered opcodes */
425      lastop = -1;
343426      for (op = 0; op < code_log_index; op++)
344         if (code_log_buffer[op].base == (void *)cur)
345            break;
427         if (code_log_buffer[op].base == cur)
428         {
429            if (lastop != -1)
430               print_log_entry(&code_log_buffer[lastop], cur, "");
431            lastop = op;
432         }
346433
347434      /* if no match, just output the current instruction */
348      if (op == code_log_index)
435      if (lastop == -1)
349436         fprintf(logfile, "%p: %s\n", cur, buffer);
350437
351      /* otherwise, output with the original instruction to the right */
438      /* if we have a match and a string, print it */
352439      else
353      {
354         char buffer2[100];
355         dasmmips3(buffer2, code_log_buffer[op].pc, code_log_buffer[op].op);
356         fprintf(logfile, "%p: %-50s %08X: %s\n", cur, buffer, code_log_buffer[op].pc, buffer2);
357      }
440         print_log_entry(&code_log_buffer[lastop], cur, buffer);
358441
359442      /* advance past this instruction */
360443      cur += bytes;
r1036r1037
454537
455538#define code_log_reset()
456539#define code_log_add_entry(a,b,c)
540#define code_log_add_entry_string(a,b,c)
457541#define code_log(a,b,c)
458#define desc_log(a)
542#define desc_log(a,b)
459543
460544#endif
461545
r1036r1037
867951#include "mips3dsm.c"
868952#include "cpu/i386/i386dasm.c"
869953#endif
954
955
956
957/***************************************************************************
958    C CORE FOR COMPARISON
959***************************************************************************/
960
961#if COMPARE_AGAINST_C
962
963static UINT8 dummy_read_byte_32le(offs_t offs)
964{
965   if (mips3.access_type == 0)
966   {
967      mips3.access_type = 1;
968      mips3.access_size = 1;
969      mips3.access_addr = offs;
970      mips3.access_mask = 0;
971      mips3.access_data = program_read_byte_32le(offs);
972   }
973   else
974   {
975      assert(mips3.access_type == 1);
976      assert(mips3.access_size == 1);
977      assert(mips3.access_addr == offs);
978      assert(mips3.access_mask == 0);
979      mips3.access_type = 0;
980   }
981   return mips3.access_data;
982}
983
984static UINT16 dummy_read_word_32le(offs_t offs)
985{
986   if (mips3.access_type == 0)
987   {
988      mips3.access_type = 1;
989      mips3.access_size = 2;
990      mips3.access_addr = offs;
991      mips3.access_mask = 0;
992      mips3.access_data = program_read_word_32le(offs);
993   }
994   else
995   {
996      assert(mips3.access_type == 1);
997      assert(mips3.access_size == 2);
998      assert(mips3.access_addr == offs);
999      assert(mips3.access_mask == 0);
1000      mips3.access_type = 0;
1001   }
1002   return mips3.access_data;
1003}
1004
1005static UINT32 dummy_read_dword_32le(offs_t offs)
1006{
1007   if (mips3.access_type == 0)
1008   {
1009      mips3.access_type = 1;
1010      mips3.access_size = 4;
1011      mips3.access_addr = offs;
1012      mips3.access_mask = 0;
1013      mips3.access_data = program_read_dword_32le(offs);
1014   }
1015   else
1016   {
1017      assert(mips3.access_type == 1);
1018      assert(mips3.access_size == 4);
1019      assert(mips3.access_addr == offs);
1020      assert(mips3.access_mask == 0);
1021      mips3.access_type = 0;
1022   }
1023   return mips3.access_data;
1024}
1025
1026static UINT32 dummy_read_masked_32le(offs_t offs, UINT32 mask)
1027{
1028   if (mips3.access_type == 0)
1029   {
1030      mips3.access_type = 1;
1031      mips3.access_size = 4;
1032      mips3.access_addr = offs;
1033      mips3.access_mask = mask;
1034      mips3.access_data = program_read_masked_32le(offs, mask);
1035   }
1036   else
1037   {
1038      assert(mips3.access_type == 1);
1039      assert(mips3.access_size == 4);
1040      assert(mips3.access_addr == offs);
1041      assert(mips3.access_mask == mask);
1042      mips3.access_type = 0;
1043   }
1044   return mips3.access_data;
1045}
1046
1047static UINT64 dummy_read_qword_32le(offs_t offs)
1048{
1049   if (mips3.access_type == 0)
1050   {
1051      mips3.access_type = 1;
1052      mips3.access_size = 8;
1053      mips3.access_addr = offs;
1054      mips3.access_mask = 0;
1055      mips3.access_data = (*mips3.orighandler.readdouble)(offs);
1056   }
1057   else
1058   {
1059      assert(mips3.access_type == 1);
1060      assert(mips3.access_size == 8);
1061      assert(mips3.access_addr == offs);
1062      assert(mips3.access_mask == 0);
1063      mips3.access_type = 0;
1064   }
1065   return mips3.access_data;
1066}
1067
1068static UINT64 dummy_read_qword_masked_32le(offs_t offs, UINT64 mask)
1069{
1070   if (mips3.access_type == 0)
1071   {
1072      mips3.access_type = 1;
1073      mips3.access_size = 8;
1074      mips3.access_addr = offs;
1075      mips3.access_mask = mask;
1076      mips3.access_data = (*mips3.orighandler.readdouble_masked)(offs, mask);
1077   }
1078   else
1079   {
1080      assert(mips3.access_type == 1);
1081      assert(mips3.access_size == 8);
1082      assert(mips3.access_addr == offs);
1083      assert(mips3.access_mask == mask);
1084      mips3.access_type = 0;
1085   }
1086   return mips3.access_data;
1087}
1088
1089static void dummy_write_byte_32le(offs_t offs, UINT8 data)
1090{
1091   if (mips3.access_type == 0)
1092   {
1093      mips3.access_type = 2;
1094      mips3.access_size = 1;
1095      mips3.access_addr = offs;
1096      mips3.access_data = data;
1097      mips3.access_mask = 0;
1098   }
1099   else
1100   {
1101      assert(mips3.access_type == 2);
1102      assert(mips3.access_size == 1);
1103      assert(mips3.access_addr == offs);
1104      assert(mips3.access_data == data);
1105      assert(mips3.access_mask == 0);
1106      mips3.access_type = 0;
1107      program_write_byte_32le(offs, data);
1108   }
1109}
1110
1111static void dummy_write_word_32le(offs_t offs, UINT16 data)
1112{
1113   if (mips3.access_type == 0)
1114   {
1115      mips3.access_type = 2;
1116      mips3.access_size = 2;
1117      mips3.access_addr = offs;
1118      mips3.access_data = data;
1119      mips3.access_mask = 0;
1120   }
1121   else
1122   {
1123      assert(mips3.access_type == 2);
1124      assert(mips3.access_size == 2);
1125      assert(mips3.access_addr == offs);
1126      assert(mips3.access_data == data);
1127      assert(mips3.access_mask == 0);
1128      mips3.access_type = 0;
1129      program_write_word_32le(offs, data);
1130   }
1131}
1132
1133static void dummy_write_dword_32le(offs_t offs, UINT32 data)
1134{
1135   if (mips3.access_type == 0)
1136   {
1137      mips3.access_type = 2;
1138      mips3.access_size = 4;
1139      mips3.access_addr = offs;
1140      mips3.access_data = data;
1141      mips3.access_mask = 0;
1142   }
1143   else
1144   {
1145      assert(mips3.access_type == 2);
1146      assert(mips3.access_size == 4);
1147      assert(mips3.access_addr == offs);
1148      assert(mips3.access_data == data);
1149      assert(mips3.access_mask == 0);
1150      mips3.access_type = 0;
1151      program_write_dword_32le(offs, data);
1152   }
1153}
1154
1155static void dummy_write_masked_32le(offs_t offs, UINT32 data, UINT32 mask)
1156{
1157   if (mips3.access_type == 0)
1158   {
1159      mips3.access_type = 2;
1160      mips3.access_size = 4;
1161      mips3.access_addr = offs;
1162      mips3.access_data = data;
1163      mips3.access_mask = mask;
1164   }
1165   else
1166   {
1167      assert(mips3.access_type == 2);
1168      assert(mips3.access_size == 4);
1169      assert(mips3.access_addr == offs);
1170      assert(mips3.access_data == data);
1171      assert(mips3.access_mask == mask);
1172      mips3.access_type = 0;
1173      program_write_masked_32le(offs, data, mask);
1174   }
1175}
1176
1177static void dummy_write_qword_32le(offs_t offs, UINT64 data)
1178{
1179   if (mips3.access_type == 0)
1180   {
1181      mips3.access_type = 2;
1182      mips3.access_size = 8;
1183      mips3.access_addr = offs;
1184      mips3.access_data = data;
1185      mips3.access_mask = 0;
1186   }
1187   else
1188   {
1189      assert(mips3.access_type == 2);
1190      assert(mips3.access_size == 8);
1191      assert(mips3.access_addr == offs);
1192      assert(mips3.access_data == data);
1193      assert(mips3.access_mask == 0);
1194      mips3.access_type = 0;
1195      (*mips3.orighandler.writedouble)(offs, data);
1196   }
1197}
1198
1199static void dummy_write_qword_masked_32le(offs_t offs, UINT64 data, UINT64 mask)
1200{
1201   if (mips3.access_type == 0)
1202   {
1203      mips3.access_type = 2;
1204      mips3.access_size = 8;
1205      mips3.access_addr = offs;
1206      mips3.access_data = data;
1207      mips3.access_mask = mask;
1208   }
1209   else
1210   {
1211      assert(mips3.access_type == 2);
1212      assert(mips3.access_size == 8);
1213      assert(mips3.access_addr == offs);
1214      assert(mips3.access_data == data);
1215      assert(mips3.access_mask == mask);
1216      mips3.access_type = 0;
1217      (*mips3.orighandler.writedouble_masked)(offs, data, mask);
1218   }
1219}
1220
1221static const memory_handlers override_memory =
1222{
1223   dummy_read_byte_32le,
1224   dummy_read_word_32le,
1225   dummy_read_dword_32le,
1226   dummy_read_masked_32le,
1227   dummy_read_qword_32le,
1228   dummy_read_qword_masked_32le,
1229
1230   dummy_write_byte_32le,
1231   dummy_write_word_32le,
1232   dummy_write_dword_32le,
1233   dummy_write_masked_32le,
1234   dummy_write_qword_32le,
1235   dummy_write_qword_masked_32le
1236};
1237
1238#undef SR
1239
1240#define mips3            c_mips3
1241#define mips3_regs         c_mips3_regs
1242
1243#define mips3_get_context    c_mips3_get_context
1244#define mips3_set_context    c_mips3_set_context
1245#define mips3_reset       c_mips3_reset
1246#define mips3_translate    c_mips3_translate
1247#define mips3_dasm          c_mips3_dasm
1248#define mips3_execute       c_mips3_execute
1249#define mips3_set_info       c_mips3_set_info
1250#define mips3_get_info       c_mips3_get_info
1251
1252#define r4600be_init      c_r4600be_init
1253#define r4600le_init      c_r4600le_init
1254#define r4600be_get_info   c_r4600be_get_info
1255#define r4600le_get_info   c_r4600le_get_info
1256
1257#define r4650be_init      c_r4650be_init
1258#define r4650le_init      c_r4650le_init
1259#define r4650be_get_info   c_r4650be_get_info
1260#define r4650le_get_info   c_r4650le_get_info
1261
1262#define r4700be_init      c_r4700be_init
1263#define r4700le_init      c_r4700le_init
1264#define r4700be_get_info   c_r4700be_get_info
1265#define r4700le_get_info   c_r4700le_get_info
1266
1267#define r5000be_init      c_r5000be_init
1268#define r5000le_init      c_r5000le_init
1269#define r5000be_get_info   c_r5000be_get_info
1270#define r5000le_get_info   c_r5000le_get_info
1271
1272#define qed5271be_init      c_qed5271be_init
1273#define qed5271le_init      c_qed5271le_init
1274#define qed5271be_get_info   c_qed5271be_get_info
1275#define qed5271le_get_info   c_qed5271le_get_info
1276
1277#define rm7000be_init      c_rm7000be_init
1278#define rm7000le_init      c_rm7000le_init
1279#define rm7000be_get_info   c_rm7000be_get_info
1280#define rm7000le_get_info   c_rm7000le_get_info
1281
1282#include "mips3.c"
1283
1284#undef mips3
1285
1286static void mips3c_init(mips3_flavor flavor, int bigendian, int index, int clock, const struct mips3_config *config, int (*irqcallback)(int))
1287{
1288   mips3com_init(&c_mips3.core, flavor, bigendian, index, clock, config, irqcallback);
1289   mips3.orighandler = mips3.core->memory;
1290   mips3.core->memory = override_memory;
1291   c_mips3.core.memory = override_memory;
1292}
1293
1294static void mips3c_reset(void)
1295{
1296   c_mips3_reset();
1297}
1298
1299static void execute_c_version(void)
1300{
1301   int save_debug_mode = Machine->debug_mode;
1302   int i;
1303
1304   assert(mips3.access_type == 0);
1305
1306   c_mips3.core.cpr[0][COP0_Cause] = (c_mips3.core.cpr[0][COP0_Cause] & ~0xfc00) | (mips3.core->cpr[0][COP0_Cause] & 0xfc00);
1307   check_irqs();
1308
1309   assert(c_mips3.core.pc == mips3.core->pc);
1310   assert(c_mips3.core.hi == mips3.core->hi);
1311   assert(c_mips3.core.lo == mips3.core->lo);
1312   for (i = 0; i < 32; i++)
1313   {
1314      assert(c_mips3.core.r[i] == mips3.core->r[i]);
1315      assert(c_mips3.core.cpr[0][i] == mips3.core->cpr[0][i]);
1316      assert(c_mips3.core.ccr[0][i] == mips3.core->ccr[0][i]);
1317      assert(c_mips3.core.cpr[1][i] == mips3.core->cpr[1][i]);
1318      assert(c_mips3.core.ccr[1][i] == mips3.core->ccr[1][i]);
1319   }
1320   for (i = 0; i < 8; i++)
1321      assert(c_mips3.core.cf[1][i] == mips3.core->cf[1][i]);
1322   assert(c_mips3.core.count_zero_time == mips3.core->count_zero_time);
1323
1324   mips3.access_type = 0;
1325
1326   Machine->debug_mode = 0;
1327   c_mips3_execute(0);
1328   Machine->debug_mode = save_debug_mode;
1329}
1330
1331static void compare_c_version(void)
1332{
1333}
1334
1335#endif
src/emu/cpu/mips/mdrcold.c
r1036r1037
10151015   UINT32 op = cpu_readop32(physpc);
10161016   int cycles;
10171017
1018   code_log_add_entry(pc, op, drc->cache_top);
1018   code_log_add_entry(drc->cache_top, pc, op);
10191019
10201020   switch (op >> 26)
10211021   {
r1036r1037
10311031         return RECOMPILE_SUCCESSFUL_CP(0,0) | RECOMPILE_END_OF_STRING;
10321032
10331033      case 0x03:   /* JAL */
1034         cycles = recompile_delay_slot(drc, pc + 4);                              // <next instruction>
10351034         emit_mov_m64_imm32(DRCTOP, REGADDR(31), pc + 8);                        // mov  [31],pc + 8
1035         cycles = recompile_delay_slot(drc, pc + 4);                              // <next instruction>
10361036         append_branch_or_dispatch(drc, (pc & 0xf0000000) | (LIMMVAL << 2), 1+cycles);   // <branch or dispatch>
10371037         return RECOMPILE_SUCCESSFUL_CP(0,0) | RECOMPILE_END_OF_STRING;
10381038
r1036r1037
23792379         return RECOMPILE_SUCCESSFUL_CP(1+cycles,0) | RECOMPILE_END_OF_STRING | RECOMPILE_ADD_DISPATCH;
23802380
23812381      case 0x09:   /* JALR */
2382         cycles = recompile_delay_slot(drc, pc + 4);                              // <next instruction>
23832382         if (RDREG != 0)
23842383            emit_mov_m64_imm32(DRCTOP, REGADDR(RDREG), pc + 8);                     // mov  [rdreg],pc + 8
2384         cycles = recompile_delay_slot(drc, pc + 4);                              // <next instruction>
23852385         emit_mov_r32_m32(DRCTOP, REG_EDI, REGADDRLO(RSREG));                     // mov  edi,[rsreg].lo
23862386         return RECOMPILE_SUCCESSFUL_CP(1+cycles,0) | RECOMPILE_END_OF_STRING | RECOMPILE_ADD_DISPATCH;
23872387
r1036r1037
34473447            emit_cmp_m32_imm(DRCTOP, REGADDRHI(RSREG), 0);                        // cmp  [rsreg].hi,0
34483448            emit_jcc_near_link(DRCTOP, COND_GE, &link1);                        // jge  skip
34493449         }
3450
3451         cycles = recompile_delay_slot(drc, pc + 4);                              // <next instruction>
34523450         emit_mov_m64_imm32(DRCTOP, MABS(&mips3.core->r[31]), pc + 8);               // mov  [31],pc + 8
3451         cycles = recompile_delay_slot(drc, pc + 4);                              // <next instruction>
34533452         append_branch_or_dispatch(drc, pc + 4 + (SIMMVAL << 2), 1+cycles);            // <branch or dispatch>
34543453         resolve_link(DRCTOP, &link1);                                    // skip:
34553454         return RECOMPILE_SUCCESSFUL_CP(1,4);
r1036r1037
34573456      case 0x11:   /* BGEZAL */
34583457         if (RSREG == 0)
34593458         {
3460            cycles = recompile_delay_slot(drc, pc + 4);                           // <next instruction>
34613459            emit_mov_m64_imm32(DRCTOP, MABS(&mips3.core->r[31]), pc + 8);            // mov  [31],pc + 8
3460            cycles = recompile_delay_slot(drc, pc + 4);                           // <next instruction>
34623461            append_branch_or_dispatch(drc, pc + 4 + (SIMMVAL << 2), 1+cycles);         // <branch or dispatch>
34633462            return RECOMPILE_SUCCESSFUL_CP(0,0) | RECOMPILE_END_OF_STRING;
34643463         }
r1036r1037
34683467            emit_jcc_near_link(DRCTOP, COND_L, &link1);                           // jl   skip
34693468         }
34703469
3471         cycles = recompile_delay_slot(drc, pc + 4);                              // <next instruction>
34723470         emit_mov_m64_imm32(DRCTOP, MABS(&mips3.core->r[31]), pc + 8);               // mov  [31],pc + 8
3471         cycles = recompile_delay_slot(drc, pc + 4);                              // <next instruction>
34733472         append_branch_or_dispatch(drc, pc + 4 + (SIMMVAL << 2), 1+cycles);            // <branch or dispatch>
34743473         resolve_link(DRCTOP, &link1);                                    // skip:
34753474         return RECOMPILE_SUCCESSFUL_CP(1,4);
r1036r1037
34833482            emit_jcc_near_link(DRCTOP, COND_GE, &link1);                        // jge  skip
34843483         }
34853484
3486         cycles = recompile_delay_slot(drc, pc + 4);                              // <next instruction>
34873485         emit_mov_m64_imm32(DRCTOP, MABS(&mips3.core->r[31]), pc + 8);               // mov  [31],pc + 8
3486         cycles = recompile_delay_slot(drc, pc + 4);                              // <next instruction>
34883487         append_branch_or_dispatch(drc, pc + 4 + (SIMMVAL << 2), 1+cycles);            // <branch or dispatch>
34893488         resolve_link(DRCTOP, &link1);                                    // skip:
34903489         return RECOMPILE_SUCCESSFUL_CP(1,8);
r1036r1037
34923491      case 0x13:   /* BGEZALL */
34933492         if (RSREG == 0)
34943493         {
3495            cycles = recompile_delay_slot(drc, pc + 4);                           // <next instruction>
34963494            emit_mov_m64_imm32(DRCTOP, MABS(&mips3.core->r[31]), pc + 8);            // mov  [31],pc + 8
3495            cycles = recompile_delay_slot(drc, pc + 4);                           // <next instruction>
34973496            append_branch_or_dispatch(drc, pc + 4 + (SIMMVAL << 2), 1+cycles);         // <branch or dispatch>
34983497            return RECOMPILE_SUCCESSFUL_CP(0,0) | RECOMPILE_END_OF_STRING;
34993498         }
r1036r1037
35033502            emit_jcc_near_link(DRCTOP, COND_L, &link1);                           // jl   skip
35043503         }
35053504
3506         cycles = recompile_delay_slot(drc, pc + 4);                              // <next instruction>
35073505         emit_mov_m64_imm32(DRCTOP, MABS(&mips3.core->r[31]), pc + 8);               // mov  [31],pc + 8
3506         cycles = recompile_delay_slot(drc, pc + 4);                              // <next instruction>
35083507         append_branch_or_dispatch(drc, pc + 4 + (SIMMVAL << 2), 1+cycles);            // <branch or dispatch>
35093508         resolve_link(DRCTOP, &link1);                                    // skip:
35103509         return RECOMPILE_SUCCESSFUL_CP(1,8);
src/emu/cpu/mips/mips3.c
r1036r1037
5959#define FDVALL_FR1   (*(UINT64 *)&mips3.core.cpr[1][FDREG])
6060
6161#define ADDPC(x)   mips3.nextpc = mips3.core.pc + ((x) << 2)
62#define ADDPCL(x,l)   { mips3.nextpc = mips3.core.pc + ((x) << 2); mips3.core.r[l] = mips3.core.pc + 4; }
62#define ADDPCL(x,l)   { mips3.nextpc = mips3.core.pc + ((x) << 2); mips3.core.r[l] = (INT32)(mips3.core.pc + 4); }
6363#define ABSPC(x)   mips3.nextpc = (mips3.core.pc & 0xf0000000) | ((x) << 2)
64#define ABSPCL(x,l)   { mips3.nextpc = (mips3.core.pc & 0xf0000000) | ((x) << 2); mips3.core.r[l] = mips3.core.pc + 4; }
64#define ABSPCL(x,l)   { mips3.nextpc = (mips3.core.pc & 0xf0000000) | ((x) << 2); mips3.core.r[l] = (INT32)(mips3.core.pc + 4); }
6565#define SETPC(x)   mips3.nextpc = (x)
66#define SETPCL(x,l)   { mips3.nextpc = (x); mips3.core.r[l] = mips3.core.pc + 4; }
66#define SETPCL(x,l)   { mips3.nextpc = (x); mips3.core.r[l] = (INT32)(mips3.core.pc + 4); }
6767
6868#define HIVAL      (UINT32)mips3.core.hi
6969#define LOVAL      (UINT32)mips3.core.lo
r1036r1037
7272#define SR         mips3.core.cpr[0][COP0_Status]
7373#define CAUSE      mips3.core.cpr[0][COP0_Cause]
7474
75#define GET_FCC(n)   ((mips3.core.ccr[1][31] >> fcc_shift[n]) & 1)
76#define SET_FCC(n,v) (mips3.core.ccr[1][31] = (mips3.core.ccr[1][31] & ~(1 << fcc_shift[n])) | ((v) << fcc_shift[n]))
75#define GET_FCC(n)   (mips3.core.cf[1][n])
76#define SET_FCC(n,v) (mips3.core.cf[1][n] = (v))
7777
7878#define IS_FR0      (!(SR & SR_FR))
7979#define IS_FR1      (SR & SR_FR)
r1036r1037
476476   {
477477      /* it doesn't really take 250 cycles to read this register, but it helps speed */
478478      /* up loops that hammer on it */
479      if (mips3.core.icount >= 250)
480         mips3.core.icount -= 250;
479      if (mips3.core.icount >= MIPS3_COUNT_READ_CYCLES)
480         mips3.core.icount -= MIPS3_COUNT_READ_CYCLES;
481481      else
482482         mips3.core.icount = 0;
483483      return (UINT32)((activecpu_gettotalcycles64() - mips3.core.count_zero_time) / 2);
r1036r1037
486486   {
487487      /* it doesn't really take 250 cycles to read this register, but it helps speed */
488488      /* up loops that hammer on it */
489      if (mips3.core.icount >= 250)
490         mips3.core.icount -= 250;
489      if (mips3.core.icount >= MIPS3_CAUSE_READ_CYCLES)
490         mips3.core.icount -= MIPS3_CAUSE_READ_CYCLES;
491491      else
492492         mips3.core.icount = 0;
493493   }
r1036r1037
535535      }
536536
537537      case COP0_Count:
538         mips3.core.cpr[0][idx] = val;
538539         mips3.core.count_zero_time = activecpu_gettotalcycles64() - ((UINT64)(UINT32)val * 2);
539540         mips3com_update_cycle_counting(&mips3.core);
540541         break;
r1036r1037
686687
687688INLINE UINT64 get_cop1_creg(int idx)
688689{
690   if (idx == 31)
691   {
692      int i;
693
694      mips3.core.ccr[1][31] &= ~0xfe800000;
695      for (i = 0; i < 8; i++)
696         if (mips3.core.cf[1][i])
697            mips3.core.ccr[1][31] |= (UINT64)1 << fcc_shift[i];
698   }
689699   return mips3.core.ccr[1][idx];
690700}
691701
692702INLINE void set_cop1_creg(int idx, UINT64 val)
693703{
694704   mips3.core.ccr[1][idx] = val;
705   if (idx == 31)
706   {
707      int i;
708
709      for (i = 0; i < 8; i++)
710         mips3.core.cf[1][i] = (val >> fcc_shift[i]) & 1;
711   }
695712}
696713
697714INLINE void handle_cop1_fr0(UINT32 op)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team