1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
|
/*
* SH4 emulation
*
* Copyright (c) 2005 Samuel Tardieu
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "exec.h"
static inline void set_t(void)
{
env->sr |= SR_T;
}
static inline void clr_t(void)
{
env->sr &= ~SR_T;
}
static inline void cond_t(int cond)
{
if (cond)
set_t();
else
clr_t();
}
void OPPROTO op_cmp_eq_imm_T0(void)
{
cond_t((int32_t) T0 == (int32_t) PARAM1);
RETURN();
}
void OPPROTO op_bf_s(void)
{
env->delayed_pc = PARAM1;
if (!(env->sr & SR_T)) {
env->flags |= DELAY_SLOT_TRUE;
}
RETURN();
}
void OPPROTO op_bt_s(void)
{
env->delayed_pc = PARAM1;
if (env->sr & SR_T) {
env->flags |= DELAY_SLOT_TRUE;
}
RETURN();
}
void OPPROTO op_store_flags(void)
{
env->flags &= DELAY_SLOT_TRUE;
env->flags |= PARAM1;
RETURN();
}
void OPPROTO op_bra(void)
{
env->delayed_pc = PARAM1;
RETURN();
}
void OPPROTO op_braf_T0(void)
{
env->delayed_pc = PARAM1 + T0;
RETURN();
}
void OPPROTO op_bsr(void)
{
env->pr = PARAM1;
env->delayed_pc = PARAM2;
RETURN();
}
void OPPROTO op_bsrf_T0(void)
{
env->pr = PARAM1;
env->delayed_pc = PARAM1 + T0;
RETURN();
}
void OPPROTO op_jsr_T0(void)
{
env->pr = PARAM1;
env->delayed_pc = T0;
RETURN();
}
void OPPROTO op_rts(void)
{
env->delayed_pc = env->pr;
RETURN();
}
void OPPROTO op_ldtlb(void)
{
helper_ldtlb();
RETURN();
}
void OPPROTO op_frchg(void)
{
env->fpscr ^= FPSCR_FR;
RETURN();
}
void OPPROTO op_fschg(void)
{
env->fpscr ^= FPSCR_SZ;
RETURN();
}
void OPPROTO op_rte(void)
{
env->sr = env->ssr;
env->delayed_pc = env->spc;
RETURN();
}
void OPPROTO op_addc_T0_T1(void)
{
helper_addc_T0_T1();
RETURN();
}
void OPPROTO op_addv_T0_T1(void)
{
helper_addv_T0_T1();
RETURN();
}
void OPPROTO op_cmp_eq_T0_T1(void)
{
cond_t(T1 == T0);
RETURN();
}
void OPPROTO op_cmp_ge_T0_T1(void)
{
cond_t((int32_t) T1 >= (int32_t) T0);
RETURN();
}
void OPPROTO op_cmp_gt_T0_T1(void)
{
cond_t((int32_t) T1 > (int32_t) T0);
RETURN();
}
void OPPROTO op_cmp_hi_T0_T1(void)
{
cond_t((uint32_t) T1 > (uint32_t) T0);
RETURN();
}
void OPPROTO op_cmp_hs_T0_T1(void)
{
cond_t((uint32_t) T1 >= (uint32_t) T0);
RETURN();
}
void OPPROTO op_cmp_str_T0_T1(void)
{
cond_t((T0 & 0x000000ff) == (T1 & 0x000000ff) ||
(T0 & 0x0000ff00) == (T1 & 0x0000ff00) ||
(T0 & 0x00ff0000) == (T1 & 0x00ff0000) ||
(T0 & 0xff000000) == (T1 & 0xff000000));
RETURN();
}
void OPPROTO op_tst_T0_T1(void)
{
cond_t((T1 & T0) == 0);
RETURN();
}
void OPPROTO op_div0s_T0_T1(void)
{
if (T1 & 0x80000000)
env->sr |= SR_Q;
else
env->sr &= ~SR_Q;
if (T0 & 0x80000000)
env->sr |= SR_M;
else
env->sr &= ~SR_M;
cond_t((T1 ^ T0) & 0x80000000);
RETURN();
}
void OPPROTO op_div1_T0_T1(void)
{
helper_div1_T0_T1();
RETURN();
}
void OPPROTO op_dmulsl_T0_T1(void)
{
helper_dmulsl_T0_T1();
RETURN();
}
void OPPROTO op_dmulul_T0_T1(void)
{
helper_dmulul_T0_T1();
RETURN();
}
void OPPROTO op_macl_T0_T1(void)
{
helper_macl_T0_T1();
RETURN();
}
void OPPROTO op_macw_T0_T1(void)
{
helper_macw_T0_T1();
RETURN();
}
void OPPROTO op_mull_T0_T1(void)
{
env->macl = (T0 * T1) & 0xffffffff;
RETURN();
}
void OPPROTO op_mulsw_T0_T1(void)
{
env->macl = (int32_t)(int16_t) T0 *(int32_t)(int16_t) T1;
RETURN();
}
void OPPROTO op_muluw_T0_T1(void)
{
env->macl = (uint32_t)(uint16_t) T0 *(uint32_t)(uint16_t) T1;
RETURN();
}
void OPPROTO op_negc_T0(void)
{
helper_negc_T0();
RETURN();
}
void OPPROTO op_shad_T0_T1(void)
{
if ((T0 & 0x80000000) == 0)
T1 <<= (T0 & 0x1f);
else if ((T0 & 0x1f) == 0)
T1 = (T1 & 0x80000000)? 0xffffffff : 0;
else
T1 = ((int32_t) T1) >> ((~T0 & 0x1f) + 1);
RETURN();
}
void OPPROTO op_shld_T0_T1(void)
{
if ((T0 & 0x80000000) == 0)
T1 <<= (T0 & 0x1f);
else if ((T0 & 0x1f) == 0)
T1 = 0;
else
T1 = ((uint32_t) T1) >> ((~T0 & 0x1f) + 1);
RETURN();
}
void OPPROTO op_subc_T0_T1(void)
{
helper_subc_T0_T1();
RETURN();
}
void OPPROTO op_subv_T0_T1(void)
{
helper_subv_T0_T1();
RETURN();
}
void OPPROTO op_trapa(void)
{
env->tra = PARAM1 << 2;
env->exception_index = 0x160;
do_raise_exception();
RETURN();
}
void OPPROTO op_cmp_pl_T0(void)
{
cond_t((int32_t) T0 > 0);
RETURN();
}
void OPPROTO op_cmp_pz_T0(void)
{
cond_t((int32_t) T0 >= 0);
RETURN();
}
void OPPROTO op_jmp_T0(void)
{
env->delayed_pc = T0;
RETURN();
}
void OPPROTO op_ldcl_rMplus_rN_bank(void)
{
env->gregs[PARAM2] = env->gregs[PARAM1];
env->gregs[PARAM1] += 4;
RETURN();
}
void OPPROTO op_ldc_T0_sr(void)
{
env->sr = T0 & 0x700083f3;
RETURN();
}
void OPPROTO op_stc_sr_T0(void)
{
T0 = env->sr;
RETURN();
}
#define LDSTOPS(target,load,store) \
void OPPROTO op_##load##_T0_##target (void) \
{ env ->target = T0; RETURN(); \
} \
void OPPROTO op_##store##_##target##_T0 (void) \
{ T0 = env->target; RETURN(); \
} \
LDSTOPS(gbr, ldc, stc)
LDSTOPS(vbr, ldc, stc)
LDSTOPS(ssr, ldc, stc)
LDSTOPS(spc, ldc, stc)
LDSTOPS(sgr, ldc, stc)
LDSTOPS(dbr, ldc, stc)
LDSTOPS(mach, lds, sts)
LDSTOPS(macl, lds, sts)
LDSTOPS(pr, lds, sts)
LDSTOPS(fpul, lds, sts)
void OPPROTO op_lds_T0_fpscr(void)
{
env->fpscr = T0 & 0x003fffff;
env->fp_status.float_rounding_mode = T0 & 0x01 ?
float_round_to_zero : float_round_nearest_even;
RETURN();
}
void OPPROTO op_sts_fpscr_T0(void)
{
T0 = env->fpscr & 0x003fffff;
RETURN();
}
void OPPROTO op_rotcl_Rn(void)
{
helper_rotcl(&env->gregs[PARAM1]);
RETURN();
}
void OPPROTO op_rotcr_Rn(void)
{
helper_rotcr(&env->gregs[PARAM1]);
RETURN();
}
void OPPROTO op_rotl_Rn(void)
{
cond_t(env->gregs[PARAM1] & 0x80000000);
env->gregs[PARAM1] = (env->gregs[PARAM1] << 1) | (env->sr & SR_T);
RETURN();
}
void OPPROTO op_rotr_Rn(void)
{
cond_t(env->gregs[PARAM1] & 1);
env->gregs[PARAM1] = (env->gregs[PARAM1] >> 1) |
((env->sr & SR_T) ? 0x80000000 : 0);
RETURN();
}
void OPPROTO op_shal_Rn(void)
{
cond_t(env->gregs[PARAM1] & 0x80000000);
env->gregs[PARAM1] <<= 1;
RETURN();
}
void OPPROTO op_shar_Rn(void)
{
cond_t(env->gregs[PARAM1] & 1);
*(int32_t *)&env->gregs[PARAM1] >>= 1;
RETURN();
}
void OPPROTO op_shlr_Rn(void)
{
cond_t(env->gregs[PARAM1] & 1);
env->gregs[PARAM1] >>= 1;
RETURN();
}
void OPPROTO op_fmov_frN_FT0(void)
{
FT0 = env->fregs[PARAM1];
RETURN();
}
void OPPROTO op_fmov_drN_DT0(void)
{
CPU_DoubleU d;
d.l.upper = *(uint32_t *)&env->fregs[PARAM1];
d.l.lower = *(uint32_t *)&env->fregs[PARAM1 + 1];
DT0 = d.d;
RETURN();
}
void OPPROTO op_fmov_frN_FT1(void)
{
FT1 = env->fregs[PARAM1];
RETURN();
}
void OPPROTO op_fmov_drN_DT1(void)
{
CPU_DoubleU d;
d.l.upper = *(uint32_t *)&env->fregs[PARAM1];
d.l.lower = *(uint32_t *)&env->fregs[PARAM1 + 1];
DT1 = d.d;
RETURN();
}
void OPPROTO op_fmov_FT0_frN(void)
{
env->fregs[PARAM1] = FT0;
RETURN();
}
void OPPROTO op_fmov_DT0_drN(void)
{
CPU_DoubleU d;
d.d = DT0;
*(uint32_t *)&env->fregs[PARAM1] = d.l.upper;
*(uint32_t *)&env->fregs[PARAM1 + 1] = d.l.lower;
RETURN();
}
void OPPROTO op_fadd_FT(void)
{
FT0 = float32_add(FT0, FT1, &env->fp_status);
RETURN();
}
void OPPROTO op_fadd_DT(void)
{
DT0 = float64_add(DT0, DT1, &env->fp_status);
RETURN();
}
void OPPROTO op_fsub_FT(void)
{
FT0 = float32_sub(FT0, FT1, &env->fp_status);
RETURN();
}
void OPPROTO op_fsub_DT(void)
{
DT0 = float64_sub(DT0, DT1, &env->fp_status);
RETURN();
}
void OPPROTO op_fmul_FT(void)
{
FT0 = float32_mul(FT0, FT1, &env->fp_status);
RETURN();
}
void OPPROTO op_fmul_DT(void)
{
DT0 = float64_mul(DT0, DT1, &env->fp_status);
RETURN();
}
void OPPROTO op_fdiv_FT(void)
{
FT0 = float32_div(FT0, FT1, &env->fp_status);
RETURN();
}
void OPPROTO op_fdiv_DT(void)
{
DT0 = float64_div(DT0, DT1, &env->fp_status);
RETURN();
}
void OPPROTO op_fcmp_eq_FT(void)
{
cond_t(float32_compare(FT0, FT1, &env->fp_status) == 0);
RETURN();
}
void OPPROTO op_fcmp_eq_DT(void)
{
cond_t(float64_compare(DT0, DT1, &env->fp_status) == 0);
RETURN();
}
void OPPROTO op_fcmp_gt_FT(void)
{
cond_t(float32_compare(FT0, FT1, &env->fp_status) == 1);
RETURN();
}
void OPPROTO op_fcmp_gt_DT(void)
{
cond_t(float64_compare(DT0, DT1, &env->fp_status) == 1);
RETURN();
}
void OPPROTO op_float_FT(void)
{
FT0 = int32_to_float32(env->fpul, &env->fp_status);
RETURN();
}
void OPPROTO op_float_DT(void)
{
DT0 = int32_to_float64(env->fpul, &env->fp_status);
RETURN();
}
void OPPROTO op_ftrc_FT(void)
{
env->fpul = float32_to_int32_round_to_zero(FT0, &env->fp_status);
RETURN();
}
void OPPROTO op_ftrc_DT(void)
{
env->fpul = float64_to_int32_round_to_zero(DT0, &env->fp_status);
RETURN();
}
void OPPROTO op_fneg_frN(void)
{
env->fregs[PARAM1] = float32_chs(env->fregs[PARAM1]);
RETURN();
}
void OPPROTO op_fabs_FT(void)
{
FT0 = float32_abs(FT0);
RETURN();
}
void OPPROTO op_fabs_DT(void)
{
DT0 = float64_abs(DT0);
RETURN();
}
void OPPROTO op_fcnvsd_FT_DT(void)
{
DT0 = float32_to_float64(FT0, &env->fp_status);
RETURN();
}
void OPPROTO op_fcnvds_DT_FT(void)
{
FT0 = float64_to_float32(DT0, &env->fp_status);
RETURN();
}
void OPPROTO op_fsqrt_FT(void)
{
FT0 = float32_sqrt(FT0, &env->fp_status);
RETURN();
}
void OPPROTO op_fsqrt_DT(void)
{
DT0 = float64_sqrt(DT0, &env->fp_status);
RETURN();
}
void OPPROTO op_fmov_T0_frN(void)
{
*(uint32_t *)&env->fregs[PARAM1] = T0;
RETURN();
}
void OPPROTO op_dt_rN(void)
{
cond_t((--env->gregs[PARAM1]) == 0);
RETURN();
}
void OPPROTO op_tst_imm_rN(void)
{
cond_t((env->gregs[PARAM2] & PARAM1) == 0);
RETURN();
}
void OPPROTO op_movl_fpul_FT0(void)
{
FT0 = *(float32 *)&env->fpul;
RETURN();
}
void OPPROTO op_movl_FT0_fpul(void)
{
*(float32 *)&env->fpul = FT0;
RETURN();
}
void OPPROTO op_jT(void)
{
if (env->sr & SR_T)
GOTO_LABEL_PARAM(1);
RETURN();
}
void OPPROTO op_jdelayed(void)
{
if (env->flags & DELAY_SLOT_TRUE) {
env->flags &= ~DELAY_SLOT_TRUE;
GOTO_LABEL_PARAM(1);
}
RETURN();
}
void OPPROTO op_movl_delayed_pc_PC(void)
{
env->pc = env->delayed_pc;
RETURN();
}
void OPPROTO op_tst_imm_T0(void)
{
cond_t((T0 & PARAM1) == 0);
RETURN();
}
void OPPROTO op_raise_illegal_instruction(void)
{
env->exception_index = 0x180;
do_raise_exception();
RETURN();
}
void OPPROTO op_raise_slot_illegal_instruction(void)
{
env->exception_index = 0x1a0;
do_raise_exception();
RETURN();
}
void OPPROTO op_debug(void)
{
env->exception_index = EXCP_DEBUG;
cpu_loop_exit();
}
void OPPROTO op_sleep(void)
{
env->halted = 1;
env->exception_index = EXCP_HLT;
cpu_loop_exit();
}
/* Load and store */
#define MEMSUFFIX _raw
#include "op_mem.c"
#undef MEMSUFFIX
#if !defined(CONFIG_USER_ONLY)
#define MEMSUFFIX _user
#include "op_mem.c"
#undef MEMSUFFIX
#define MEMSUFFIX _kernel
#include "op_mem.c"
#undef MEMSUFFIX
#endif
|