Search
lxdream.org :: lxdream/src/sh4/sh4x86.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/sh4/sh4x86.c
changeset 527:14c9489f647e
prev526:ba3da45b5754
next532:43653e748030
author nkeynes
date Sun Nov 18 11:12:44 2007 +0000 (12 years ago)
permissions -rw-r--r--
last change x86-64 translator work-in-progress
file annotate diff log raw
nkeynes@359
     1
/**
nkeynes@526
     2
 * $Id: sh4x86.in,v 1.20 2007-11-08 11:54:16 nkeynes Exp $
nkeynes@359
     3
 * 
nkeynes@359
     4
 * SH4 => x86 translation. This version does no real optimization, it just
nkeynes@359
     5
 * outputs straight-line x86 code - it mainly exists to provide a baseline
nkeynes@359
     6
 * to test the optimizing versions against.
nkeynes@359
     7
 *
nkeynes@359
     8
 * Copyright (c) 2007 Nathan Keynes.
nkeynes@359
     9
 *
nkeynes@359
    10
 * This program is free software; you can redistribute it and/or modify
nkeynes@359
    11
 * it under the terms of the GNU General Public License as published by
nkeynes@359
    12
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@359
    13
 * (at your option) any later version.
nkeynes@359
    14
 *
nkeynes@359
    15
 * This program is distributed in the hope that it will be useful,
nkeynes@359
    16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@359
    17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@359
    18
 * GNU General Public License for more details.
nkeynes@359
    19
 */
nkeynes@359
    20
nkeynes@368
    21
#include <assert.h>
nkeynes@388
    22
#include <math.h>
nkeynes@368
    23
nkeynes@380
    24
#ifndef NDEBUG
nkeynes@380
    25
#define DEBUG_JUMPS 1
nkeynes@380
    26
#endif
nkeynes@380
    27
nkeynes@417
    28
#include "sh4/xltcache.h"
nkeynes@368
    29
#include "sh4/sh4core.h"
nkeynes@368
    30
#include "sh4/sh4trans.h"
nkeynes@388
    31
#include "sh4/sh4mmio.h"
nkeynes@368
    32
#include "sh4/x86op.h"
nkeynes@368
    33
#include "clock.h"
nkeynes@368
    34
nkeynes@368
    35
#define DEFAULT_BACKPATCH_SIZE 4096
nkeynes@368
    36
nkeynes@368
    37
/** 
nkeynes@368
    38
 * Struct to manage internal translation state. This state is not saved -
nkeynes@368
    39
 * it is only valid between calls to sh4_translate_begin_block() and
nkeynes@368
    40
 * sh4_translate_end_block()
nkeynes@368
    41
 */
nkeynes@368
    42
struct sh4_x86_state {
nkeynes@368
    43
    gboolean in_delay_slot;
nkeynes@368
    44
    gboolean priv_checked; /* true if we've already checked the cpu mode. */
nkeynes@368
    45
    gboolean fpuen_checked; /* true if we've already checked fpu enabled. */
nkeynes@409
    46
    gboolean branch_taken; /* true if we branched unconditionally */
nkeynes@408
    47
    uint32_t block_start_pc;
nkeynes@417
    48
    int tstate;
nkeynes@368
    49
nkeynes@368
    50
    /* Allocated memory for the (block-wide) back-patch list */
nkeynes@368
    51
    uint32_t **backpatch_list;
nkeynes@368
    52
    uint32_t backpatch_posn;
nkeynes@368
    53
    uint32_t backpatch_size;
nkeynes@368
    54
};
nkeynes@368
    55
nkeynes@417
    56
#define TSTATE_NONE -1
nkeynes@417
    57
#define TSTATE_O    0
nkeynes@417
    58
#define TSTATE_C    2
nkeynes@417
    59
#define TSTATE_E    4
nkeynes@417
    60
#define TSTATE_NE   5
nkeynes@417
    61
#define TSTATE_G    0xF
nkeynes@417
    62
#define TSTATE_GE   0xD
nkeynes@417
    63
#define TSTATE_A    7
nkeynes@417
    64
#define TSTATE_AE   3
nkeynes@417
    65
nkeynes@417
    66
/** Branch if T is set (either in the current cflags, or in sh4r.t) */
nkeynes@417
    67
#define JT_rel8(rel8,label) if( sh4_x86.tstate == TSTATE_NONE ) { \
nkeynes@417
    68
	CMP_imm8s_sh4r( 1, R_T ); sh4_x86.tstate = TSTATE_E; } \
nkeynes@417
    69
    OP(0x70+sh4_x86.tstate); OP(rel8); \
nkeynes@417
    70
    MARK_JMP(rel8,label)
nkeynes@417
    71
/** Branch if T is clear (either in the current cflags or in sh4r.t) */
nkeynes@417
    72
#define JF_rel8(rel8,label) if( sh4_x86.tstate == TSTATE_NONE ) { \
nkeynes@417
    73
	CMP_imm8s_sh4r( 1, R_T ); sh4_x86.tstate = TSTATE_E; } \
nkeynes@417
    74
    OP(0x70+ (sh4_x86.tstate^1)); OP(rel8); \
nkeynes@417
    75
    MARK_JMP(rel8, label)
nkeynes@417
    76
nkeynes@417
    77
nkeynes@368
    78
#define EXIT_DATA_ADDR_READ 0
nkeynes@368
    79
#define EXIT_DATA_ADDR_WRITE 7
nkeynes@368
    80
#define EXIT_ILLEGAL 14
nkeynes@368
    81
#define EXIT_SLOT_ILLEGAL 21
nkeynes@368
    82
#define EXIT_FPU_DISABLED 28
nkeynes@368
    83
#define EXIT_SLOT_FPU_DISABLED 35
nkeynes@368
    84
nkeynes@368
    85
static struct sh4_x86_state sh4_x86;
nkeynes@368
    86
nkeynes@388
    87
static uint32_t max_int = 0x7FFFFFFF;
nkeynes@388
    88
static uint32_t min_int = 0x80000000;
nkeynes@394
    89
static uint32_t save_fcw; /* save value for fpu control word */
nkeynes@394
    90
static uint32_t trunc_fcw = 0x0F7F; /* fcw value for truncation mode */
nkeynes@386
    91
nkeynes@368
    92
void sh4_x86_init()
nkeynes@368
    93
{
nkeynes@368
    94
    sh4_x86.backpatch_list = malloc(DEFAULT_BACKPATCH_SIZE);
nkeynes@368
    95
    sh4_x86.backpatch_size = DEFAULT_BACKPATCH_SIZE / sizeof(uint32_t *);
nkeynes@368
    96
}
nkeynes@368
    97
nkeynes@368
    98
nkeynes@368
    99
static void sh4_x86_add_backpatch( uint8_t *ptr )
nkeynes@368
   100
{
nkeynes@368
   101
    if( sh4_x86.backpatch_posn == sh4_x86.backpatch_size ) {
nkeynes@368
   102
	sh4_x86.backpatch_size <<= 1;
nkeynes@368
   103
	sh4_x86.backpatch_list = realloc( sh4_x86.backpatch_list, sh4_x86.backpatch_size * sizeof(uint32_t *) );
nkeynes@368
   104
	assert( sh4_x86.backpatch_list != NULL );
nkeynes@368
   105
    }
nkeynes@368
   106
    sh4_x86.backpatch_list[sh4_x86.backpatch_posn++] = (uint32_t *)ptr;
nkeynes@368
   107
}
nkeynes@368
   108
nkeynes@368
   109
static void sh4_x86_do_backpatch( uint8_t *reloc_base )
nkeynes@368
   110
{
nkeynes@368
   111
    unsigned int i;
nkeynes@368
   112
    for( i=0; i<sh4_x86.backpatch_posn; i++ ) {
nkeynes@374
   113
	*sh4_x86.backpatch_list[i] += (reloc_base - ((uint8_t *)sh4_x86.backpatch_list[i]) - 4);
nkeynes@368
   114
    }
nkeynes@368
   115
}
nkeynes@368
   116
nkeynes@359
   117
/**
nkeynes@359
   118
 * Emit an instruction to load an SH4 reg into a real register
nkeynes@359
   119
 */
nkeynes@359
   120
static inline void load_reg( int x86reg, int sh4reg ) 
nkeynes@359
   121
{
nkeynes@359
   122
    /* mov [bp+n], reg */
nkeynes@361
   123
    OP(0x8B);
nkeynes@361
   124
    OP(0x45 + (x86reg<<3));
nkeynes@359
   125
    OP(REG_OFFSET(r[sh4reg]));
nkeynes@359
   126
}
nkeynes@359
   127
nkeynes@374
   128
static inline void load_reg16s( int x86reg, int sh4reg )
nkeynes@368
   129
{
nkeynes@374
   130
    OP(0x0F);
nkeynes@374
   131
    OP(0xBF);
nkeynes@374
   132
    MODRM_r32_sh4r(x86reg, REG_OFFSET(r[sh4reg]));
nkeynes@368
   133
}
nkeynes@368
   134
nkeynes@374
   135
static inline void load_reg16u( int x86reg, int sh4reg )
nkeynes@368
   136
{
nkeynes@374
   137
    OP(0x0F);
nkeynes@374
   138
    OP(0xB7);
nkeynes@374
   139
    MODRM_r32_sh4r(x86reg, REG_OFFSET(r[sh4reg]));
nkeynes@374
   140
nkeynes@368
   141
}
nkeynes@368
   142
nkeynes@380
   143
#define load_spreg( x86reg, regoff ) MOV_sh4r_r32( regoff, x86reg )
nkeynes@380
   144
#define store_spreg( x86reg, regoff ) MOV_r32_sh4r( x86reg, regoff )
nkeynes@359
   145
/**
nkeynes@359
   146
 * Emit an instruction to load an immediate value into a register
nkeynes@359
   147
 */
nkeynes@359
   148
static inline void load_imm32( int x86reg, uint32_t value ) {
nkeynes@359
   149
    /* mov #value, reg */
nkeynes@359
   150
    OP(0xB8 + x86reg);
nkeynes@359
   151
    OP32(value);
nkeynes@359
   152
}
nkeynes@359
   153
nkeynes@359
   154
/**
nkeynes@527
   155
 * Load an immediate 64-bit quantity (note: x86-64 only)
nkeynes@527
   156
 */
nkeynes@527
   157
static inline void load_imm64( int x86reg, uint32_t value ) {
nkeynes@527
   158
    /* mov #value, reg */
nkeynes@527
   159
    REXW();
nkeynes@527
   160
    OP(0xB8 + x86reg);
nkeynes@527
   161
    OP64(value);
nkeynes@527
   162
}
nkeynes@527
   163
nkeynes@527
   164
nkeynes@527
   165
/**
nkeynes@359
   166
 * Emit an instruction to store an SH4 reg (RN)
nkeynes@359
   167
 */
nkeynes@359
   168
void static inline store_reg( int x86reg, int sh4reg ) {
nkeynes@359
   169
    /* mov reg, [bp+n] */
nkeynes@361
   170
    OP(0x89);
nkeynes@361
   171
    OP(0x45 + (x86reg<<3));
nkeynes@359
   172
    OP(REG_OFFSET(r[sh4reg]));
nkeynes@359
   173
}
nkeynes@374
   174
nkeynes@374
   175
#define load_fr_bank(bankreg) load_spreg( bankreg, REG_OFFSET(fr_bank))
nkeynes@374
   176
nkeynes@375
   177
/**
nkeynes@375
   178
 * Load an FR register (single-precision floating point) into an integer x86
nkeynes@375
   179
 * register (eg for register-to-register moves)
nkeynes@375
   180
 */
nkeynes@375
   181
void static inline load_fr( int bankreg, int x86reg, int frm )
nkeynes@375
   182
{
nkeynes@375
   183
    OP(0x8B); OP(0x40+bankreg+(x86reg<<3)); OP((frm^1)<<2);
nkeynes@375
   184
}
nkeynes@375
   185
nkeynes@375
   186
/**
nkeynes@375
   187
 * Store an FR register (single-precision floating point) into an integer x86
nkeynes@375
   188
 * register (eg for register-to-register moves)
nkeynes@375
   189
 */
nkeynes@375
   190
void static inline store_fr( int bankreg, int x86reg, int frn )
nkeynes@375
   191
{
nkeynes@375
   192
    OP(0x89);  OP(0x40+bankreg+(x86reg<<3)); OP((frn^1)<<2);
nkeynes@375
   193
}
nkeynes@375
   194
nkeynes@375
   195
nkeynes@375
   196
/**
nkeynes@375
   197
 * Load a pointer to the back fp back into the specified x86 register. The
nkeynes@375
   198
 * bankreg must have been previously loaded with FPSCR.
nkeynes@388
   199
 * NB: 12 bytes
nkeynes@375
   200
 */
nkeynes@374
   201
static inline void load_xf_bank( int bankreg )
nkeynes@374
   202
{
nkeynes@386
   203
    NOT_r32( bankreg );
nkeynes@374
   204
    SHR_imm8_r32( (21 - 6), bankreg ); // Extract bit 21 then *64 for bank size
nkeynes@374
   205
    AND_imm8s_r32( 0x40, bankreg );    // Complete extraction
nkeynes@374
   206
    OP(0x8D); OP(0x44+(bankreg<<3)); OP(0x28+bankreg); OP(REG_OFFSET(fr)); // LEA [ebp+bankreg+disp], bankreg
nkeynes@374
   207
}
nkeynes@374
   208
nkeynes@375
   209
/**
nkeynes@386
   210
 * Update the fr_bank pointer based on the current fpscr value.
nkeynes@386
   211
 */
nkeynes@386
   212
static inline void update_fr_bank( int fpscrreg )
nkeynes@386
   213
{
nkeynes@386
   214
    SHR_imm8_r32( (21 - 6), fpscrreg ); // Extract bit 21 then *64 for bank size
nkeynes@386
   215
    AND_imm8s_r32( 0x40, fpscrreg );    // Complete extraction
nkeynes@386
   216
    OP(0x8D); OP(0x44+(fpscrreg<<3)); OP(0x28+fpscrreg); OP(REG_OFFSET(fr)); // LEA [ebp+fpscrreg+disp], fpscrreg
nkeynes@386
   217
    store_spreg( fpscrreg, REG_OFFSET(fr_bank) );
nkeynes@386
   218
}
nkeynes@386
   219
/**
nkeynes@377
   220
 * Push FPUL (as a 32-bit float) onto the FPU stack
nkeynes@377
   221
 */
nkeynes@377
   222
static inline void push_fpul( )
nkeynes@377
   223
{
nkeynes@377
   224
    OP(0xD9); OP(0x45); OP(R_FPUL);
nkeynes@377
   225
}
nkeynes@377
   226
nkeynes@377
   227
/**
nkeynes@377
   228
 * Pop FPUL (as a 32-bit float) from the FPU stack
nkeynes@377
   229
 */
nkeynes@377
   230
static inline void pop_fpul( )
nkeynes@377
   231
{
nkeynes@377
   232
    OP(0xD9); OP(0x5D); OP(R_FPUL);
nkeynes@377
   233
}
nkeynes@377
   234
nkeynes@377
   235
/**
nkeynes@375
   236
 * Push a 32-bit float onto the FPU stack, with bankreg previously loaded
nkeynes@375
   237
 * with the location of the current fp bank.
nkeynes@375
   238
 */
nkeynes@374
   239
static inline void push_fr( int bankreg, int frm ) 
nkeynes@374
   240
{
nkeynes@374
   241
    OP(0xD9); OP(0x40 + bankreg); OP((frm^1)<<2);  // FLD.S [bankreg + frm^1*4]
nkeynes@374
   242
}
nkeynes@374
   243
nkeynes@375
   244
/**
nkeynes@375
   245
 * Pop a 32-bit float from the FPU stack and store it back into the fp bank, 
nkeynes@375
   246
 * with bankreg previously loaded with the location of the current fp bank.
nkeynes@375
   247
 */
nkeynes@374
   248
static inline void pop_fr( int bankreg, int frm )
nkeynes@374
   249
{
nkeynes@374
   250
    OP(0xD9); OP(0x58 + bankreg); OP((frm^1)<<2); // FST.S [bankreg + frm^1*4]
nkeynes@374
   251
}
nkeynes@374
   252
nkeynes@375
   253
/**
nkeynes@375
   254
 * Push a 64-bit double onto the FPU stack, with bankreg previously loaded
nkeynes@375
   255
 * with the location of the current fp bank.
nkeynes@375
   256
 */
nkeynes@374
   257
static inline void push_dr( int bankreg, int frm )
nkeynes@374
   258
{
nkeynes@377
   259
    OP(0xDD); OP(0x40 + bankreg); OP(frm<<2); // FLD.D [bankreg + frm*4]
nkeynes@374
   260
}
nkeynes@374
   261
nkeynes@374
   262
static inline void pop_dr( int bankreg, int frm )
nkeynes@374
   263
{
nkeynes@377
   264
    OP(0xDD); OP(0x58 + bankreg); OP(frm<<2); // FST.D [bankreg + frm*4]
nkeynes@374
   265
}
nkeynes@374
   266
nkeynes@527
   267
#if SH4_TRANSLATOR == TARGET_X86_64
nkeynes@527
   268
/* X86-64 has different calling conventions... */
nkeynes@527
   269
/**
nkeynes@527
   270
 * Note: clobbers EAX to make the indirect call - this isn't usually
nkeynes@527
   271
 * a problem since the callee will usually clobber it anyway.
nkeynes@527
   272
 * Size: 12 bytes
nkeynes@527
   273
 */
nkeynes@527
   274
#define CALL_FUNC0_SIZE 12
nkeynes@527
   275
static inline void call_func0( void *ptr )
nkeynes@527
   276
{
nkeynes@527
   277
    load_imm64(R_EAX, (uint64_t)ptr);
nkeynes@527
   278
    CALL_r32(R_EAX);
nkeynes@527
   279
}
nkeynes@527
   280
nkeynes@527
   281
#define CALL_FUNC1_SIZE 14
nkeynes@527
   282
static inline void call_func1( void *ptr, int arg1 )
nkeynes@527
   283
{
nkeynes@527
   284
    MOV_r32_r32(arg1, R_EDI);
nkeynes@527
   285
    call_func0(ptr);
nkeynes@527
   286
}
nkeynes@527
   287
nkeynes@527
   288
#define CALL_FUNC2_SIZE 16
nkeynes@527
   289
static inline void call_func2( void *ptr, int arg1, int arg2 )
nkeynes@527
   290
{
nkeynes@527
   291
    MOV_r32_r32(arg1, R_EDI);
nkeynes@527
   292
    MOV_r32_r32(arg2, R_ESI);
nkeynes@527
   293
    call_func0(ptr);
nkeynes@527
   294
}
nkeynes@527
   295
nkeynes@527
   296
#define MEM_WRITE_DOUBLE_SIZE 39
nkeynes@527
   297
/**
nkeynes@527
   298
 * Write a double (64-bit) value into memory, with the first word in arg2a, and
nkeynes@527
   299
 * the second in arg2b
nkeynes@527
   300
 */
nkeynes@527
   301
static inline void MEM_WRITE_DOUBLE( int addr, int arg2a, int arg2b )
nkeynes@527
   302
{
nkeynes@527
   303
/*
nkeynes@527
   304
    MOV_r32_r32( addr, R_EDI );
nkeynes@527
   305
    MOV_r32_r32( arg2b, R_ESI );
nkeynes@527
   306
    REXW(); SHL_imm8_r32( 32, R_ESI );
nkeynes@527
   307
    REXW(); MOVZX_r16_r32( arg2a, arg2a );
nkeynes@527
   308
    REXW(); OR_r32_r32( arg2a, R_ESI );
nkeynes@527
   309
    call_func0(sh4_write_quad);
nkeynes@527
   310
*/
nkeynes@527
   311
    PUSH_r32(arg2b);
nkeynes@527
   312
    PUSH_r32(addr);
nkeynes@527
   313
    call_func2(sh4_write_long, addr, arg2a);
nkeynes@527
   314
    POP_r32(addr);
nkeynes@527
   315
    POP_r32(arg2b);
nkeynes@527
   316
    ADD_imm8s_r32(4, addr);
nkeynes@527
   317
    call_func2(sh4_write_long, addr, arg2b);
nkeynes@527
   318
}
nkeynes@527
   319
nkeynes@527
   320
#define MEM_READ_DOUBLE_SIZE 35
nkeynes@527
   321
/**
nkeynes@527
   322
 * Read a double (64-bit) value from memory, writing the first word into arg2a
nkeynes@527
   323
 * and the second into arg2b. The addr must not be in EAX
nkeynes@527
   324
 */
nkeynes@527
   325
static inline void MEM_READ_DOUBLE( int addr, int arg2a, int arg2b )
nkeynes@527
   326
{
nkeynes@527
   327
/*
nkeynes@527
   328
    MOV_r32_r32( addr, R_EDI );
nkeynes@527
   329
    call_func0(sh4_read_quad);
nkeynes@527
   330
    REXW(); MOV_r32_r32( R_EAX, arg2a );
nkeynes@527
   331
    REXW(); MOV_r32_r32( R_EAX, arg2b );
nkeynes@527
   332
    REXW(); SHR_imm8_r32( 32, arg2b );
nkeynes@527
   333
*/
nkeynes@527
   334
    PUSH_r32(addr);
nkeynes@527
   335
    call_func1(sh4_read_long, addr);
nkeynes@527
   336
    POP_r32(R_EDI);
nkeynes@527
   337
    PUSH_r32(R_EAX);
nkeynes@527
   338
    ADD_imm8s_r32(4, R_EDI);
nkeynes@527
   339
    call_func0(sh4_read_long);
nkeynes@527
   340
    MOV_r32_r32(R_EAX, arg2b);
nkeynes@527
   341
    POP_r32(arg2a);
nkeynes@527
   342
}
nkeynes@527
   343
nkeynes@527
   344
#define EXIT_BLOCK_SIZE 35
nkeynes@527
   345
/**
nkeynes@527
   346
 * Exit the block to an absolute PC
nkeynes@527
   347
 */
nkeynes@527
   348
void exit_block( sh4addr_t pc, sh4addr_t endpc )
nkeynes@527
   349
{
nkeynes@527
   350
    load_imm32( R_ECX, pc );                            // 5
nkeynes@527
   351
    store_spreg( R_ECX, REG_OFFSET(pc) );               // 3
nkeynes@527
   352
    REXW(); MOV_moff32_EAX( xlat_get_lut_entry(pc) );
nkeynes@527
   353
    REXW(); AND_imm8s_r32( 0xFC, R_EAX ); // 3
nkeynes@527
   354
    load_imm32( R_ECX, ((endpc - sh4_x86.block_start_pc)>>1)*sh4_cpu_period ); // 5
nkeynes@527
   355
    ADD_r32_sh4r( R_ECX, REG_OFFSET(slice_cycle) );     // 6
nkeynes@527
   356
    POP_r32(R_EBP);
nkeynes@527
   357
    RET();
nkeynes@527
   358
}
nkeynes@527
   359
nkeynes@527
   360
nkeynes@527
   361
/**
nkeynes@527
   362
 * Write the block trailer (exception handling block)
nkeynes@527
   363
 */
nkeynes@527
   364
void sh4_translate_end_block( sh4addr_t pc ) {
nkeynes@527
   365
    if( sh4_x86.branch_taken == FALSE ) {
nkeynes@527
   366
	// Didn't exit unconditionally already, so write the termination here
nkeynes@527
   367
	exit_block( pc, pc );
nkeynes@527
   368
    }
nkeynes@527
   369
    if( sh4_x86.backpatch_posn != 0 ) {
nkeynes@527
   370
	uint8_t *end_ptr = xlat_output;
nkeynes@527
   371
	// Exception termination. Jump block for various exception codes:
nkeynes@527
   372
	load_imm32( R_EDI, EXC_DATA_ADDR_READ );
nkeynes@527
   373
	JMP_rel8( 33, target1 );
nkeynes@527
   374
	load_imm32( R_EDI, EXC_DATA_ADDR_WRITE );
nkeynes@527
   375
	JMP_rel8( 26, target2 );
nkeynes@527
   376
	load_imm32( R_EDI, EXC_ILLEGAL );
nkeynes@527
   377
	JMP_rel8( 19, target3 );
nkeynes@527
   378
	load_imm32( R_EDI, EXC_SLOT_ILLEGAL ); 
nkeynes@527
   379
	JMP_rel8( 12, target4 );
nkeynes@527
   380
	load_imm32( R_EDI, EXC_FPU_DISABLED ); 
nkeynes@527
   381
	JMP_rel8( 5, target5 );
nkeynes@527
   382
	load_imm32( R_EDI, EXC_SLOT_FPU_DISABLED );
nkeynes@527
   383
	// target
nkeynes@527
   384
	JMP_TARGET(target1);
nkeynes@527
   385
	JMP_TARGET(target2);
nkeynes@527
   386
	JMP_TARGET(target3);
nkeynes@527
   387
	JMP_TARGET(target4);
nkeynes@527
   388
	JMP_TARGET(target5);
nkeynes@527
   389
	// Raise exception
nkeynes@527
   390
	load_spreg( R_ECX, REG_OFFSET(pc) );
nkeynes@527
   391
	ADD_r32_r32( R_EDX, R_ECX );
nkeynes@527
   392
	ADD_r32_r32( R_EDX, R_ECX );
nkeynes@527
   393
	store_spreg( R_ECX, REG_OFFSET(pc) );
nkeynes@527
   394
	MOV_moff32_EAX( &sh4_cpu_period );
nkeynes@527
   395
	MUL_r32( R_EDX );
nkeynes@527
   396
	ADD_r32_sh4r( R_EAX, REG_OFFSET(slice_cycle) );
nkeynes@527
   397
nkeynes@527
   398
	call_func0( sh4_raise_exception );
nkeynes@527
   399
	load_spreg( R_EAX, REG_OFFSET(pc) );
nkeynes@527
   400
	call_func1(xlat_get_code,R_EAX);
nkeynes@527
   401
	POP_r32(R_EBP);
nkeynes@527
   402
	RET();
nkeynes@527
   403
nkeynes@527
   404
	sh4_x86_do_backpatch( end_ptr );
nkeynes@527
   405
    }
nkeynes@527
   406
}
nkeynes@527
   407
nkeynes@527
   408
#else /* SH4_TRANSLATOR == TARGET_X86 */
nkeynes@527
   409
nkeynes@361
   410
/**
nkeynes@361
   411
 * Note: clobbers EAX to make the indirect call - this isn't usually
nkeynes@361
   412
 * a problem since the callee will usually clobber it anyway.
nkeynes@361
   413
 */
nkeynes@527
   414
#define CALL_FUNC0_SIZE 7
nkeynes@361
   415
static inline void call_func0( void *ptr )
nkeynes@361
   416
{
nkeynes@361
   417
    load_imm32(R_EAX, (uint32_t)ptr);
nkeynes@368
   418
    CALL_r32(R_EAX);
nkeynes@361
   419
}
nkeynes@361
   420
nkeynes@527
   421
#define CALL_FUNC1_SIZE 11
nkeynes@361
   422
static inline void call_func1( void *ptr, int arg1 )
nkeynes@361
   423
{
nkeynes@361
   424
    PUSH_r32(arg1);
nkeynes@361
   425
    call_func0(ptr);
nkeynes@377
   426
    ADD_imm8s_r32( 4, R_ESP );
nkeynes@361
   427
}
nkeynes@361
   428
nkeynes@527
   429
#define CALL_FUNC2_SIZE 12
nkeynes@361
   430
static inline void call_func2( void *ptr, int arg1, int arg2 )
nkeynes@361
   431
{
nkeynes@361
   432
    PUSH_r32(arg2);
nkeynes@361
   433
    PUSH_r32(arg1);
nkeynes@361
   434
    call_func0(ptr);
nkeynes@377
   435
    ADD_imm8s_r32( 8, R_ESP );
nkeynes@375
   436
}
nkeynes@375
   437
nkeynes@375
   438
/**
nkeynes@375
   439
 * Write a double (64-bit) value into memory, with the first word in arg2a, and
nkeynes@375
   440
 * the second in arg2b
nkeynes@375
   441
 * NB: 30 bytes
nkeynes@375
   442
 */
nkeynes@527
   443
#define MEM_WRITE_DOUBLE_SIZE 30
nkeynes@375
   444
static inline void MEM_WRITE_DOUBLE( int addr, int arg2a, int arg2b )
nkeynes@375
   445
{
nkeynes@375
   446
    ADD_imm8s_r32( 4, addr );
nkeynes@386
   447
    PUSH_r32(arg2b);
nkeynes@375
   448
    PUSH_r32(addr);
nkeynes@375
   449
    ADD_imm8s_r32( -4, addr );
nkeynes@386
   450
    PUSH_r32(arg2a);
nkeynes@375
   451
    PUSH_r32(addr);
nkeynes@375
   452
    call_func0(sh4_write_long);
nkeynes@377
   453
    ADD_imm8s_r32( 8, R_ESP );
nkeynes@375
   454
    call_func0(sh4_write_long);
nkeynes@377
   455
    ADD_imm8s_r32( 8, R_ESP );
nkeynes@375
   456
}
nkeynes@375
   457
nkeynes@375
   458
/**
nkeynes@375
   459
 * Read a double (64-bit) value from memory, writing the first word into arg2a
nkeynes@375
   460
 * and the second into arg2b. The addr must not be in EAX
nkeynes@375
   461
 * NB: 27 bytes
nkeynes@375
   462
 */
nkeynes@527
   463
#define MEM_READ_DOUBLE_SIZE 27
nkeynes@375
   464
static inline void MEM_READ_DOUBLE( int addr, int arg2a, int arg2b )
nkeynes@375
   465
{
nkeynes@375
   466
    PUSH_r32(addr);
nkeynes@375
   467
    call_func0(sh4_read_long);
nkeynes@375
   468
    POP_r32(addr);
nkeynes@375
   469
    PUSH_r32(R_EAX);
nkeynes@375
   470
    ADD_imm8s_r32( 4, addr );
nkeynes@375
   471
    PUSH_r32(addr);
nkeynes@375
   472
    call_func0(sh4_read_long);
nkeynes@377
   473
    ADD_imm8s_r32( 4, R_ESP );
nkeynes@375
   474
    MOV_r32_r32( R_EAX, arg2b );
nkeynes@375
   475
    POP_r32(arg2a);
nkeynes@361
   476
}
nkeynes@361
   477
nkeynes@527
   478
#define EXIT_BLOCK_SIZE 29
nkeynes@527
   479
/**
nkeynes@527
   480
 * Exit the block to an absolute PC
nkeynes@527
   481
 */
nkeynes@527
   482
void exit_block( sh4addr_t pc, sh4addr_t endpc )
nkeynes@527
   483
{
nkeynes@527
   484
    load_imm32( R_ECX, pc );                            // 5
nkeynes@527
   485
    store_spreg( R_ECX, REG_OFFSET(pc) );               // 3
nkeynes@527
   486
    MOV_moff32_EAX( xlat_get_lut_entry(pc) ); // 5
nkeynes@527
   487
    AND_imm8s_r32( 0xFC, R_EAX ); // 3
nkeynes@527
   488
    load_imm32( R_ECX, ((endpc - sh4_x86.block_start_pc)>>1)*sh4_cpu_period ); // 5
nkeynes@527
   489
    ADD_r32_sh4r( R_ECX, REG_OFFSET(slice_cycle) );     // 6
nkeynes@527
   490
    POP_r32(R_EBP);
nkeynes@527
   491
    RET();
nkeynes@527
   492
}
nkeynes@527
   493
nkeynes@527
   494
/**
nkeynes@527
   495
 * Write the block trailer (exception handling block)
nkeynes@527
   496
 */
nkeynes@527
   497
void sh4_translate_end_block( sh4addr_t pc ) {
nkeynes@527
   498
    if( sh4_x86.branch_taken == FALSE ) {
nkeynes@527
   499
	// Didn't exit unconditionally already, so write the termination here
nkeynes@527
   500
	exit_block( pc, pc );
nkeynes@527
   501
    }
nkeynes@527
   502
    if( sh4_x86.backpatch_posn != 0 ) {
nkeynes@527
   503
	uint8_t *end_ptr = xlat_output;
nkeynes@527
   504
	// Exception termination. Jump block for various exception codes:
nkeynes@527
   505
	PUSH_imm32( EXC_DATA_ADDR_READ );
nkeynes@527
   506
	JMP_rel8( 33, target1 );
nkeynes@527
   507
	PUSH_imm32( EXC_DATA_ADDR_WRITE );
nkeynes@527
   508
	JMP_rel8( 26, target2 );
nkeynes@527
   509
	PUSH_imm32( EXC_ILLEGAL );
nkeynes@527
   510
	JMP_rel8( 19, target3 );
nkeynes@527
   511
	PUSH_imm32( EXC_SLOT_ILLEGAL ); 
nkeynes@527
   512
	JMP_rel8( 12, target4 );
nkeynes@527
   513
	PUSH_imm32( EXC_FPU_DISABLED ); 
nkeynes@527
   514
	JMP_rel8( 5, target5 );
nkeynes@527
   515
	PUSH_imm32( EXC_SLOT_FPU_DISABLED );
nkeynes@527
   516
	// target
nkeynes@527
   517
	JMP_TARGET(target1);
nkeynes@527
   518
	JMP_TARGET(target2);
nkeynes@527
   519
	JMP_TARGET(target3);
nkeynes@527
   520
	JMP_TARGET(target4);
nkeynes@527
   521
	JMP_TARGET(target5);
nkeynes@527
   522
	// Raise exception
nkeynes@527
   523
	load_spreg( R_ECX, REG_OFFSET(pc) );
nkeynes@527
   524
	ADD_r32_r32( R_EDX, R_ECX );
nkeynes@527
   525
	ADD_r32_r32( R_EDX, R_ECX );
nkeynes@527
   526
	store_spreg( R_ECX, REG_OFFSET(pc) );
nkeynes@527
   527
	MOV_moff32_EAX( &sh4_cpu_period );
nkeynes@527
   528
	MUL_r32( R_EDX );
nkeynes@527
   529
	ADD_r32_sh4r( R_EAX, REG_OFFSET(slice_cycle) );
nkeynes@527
   530
nkeynes@527
   531
	call_func0( sh4_raise_exception );
nkeynes@527
   532
	ADD_imm8s_r32( 4, R_ESP );
nkeynes@527
   533
	load_spreg( R_EAX, REG_OFFSET(pc) );
nkeynes@527
   534
	call_func1(xlat_get_code,R_EAX);
nkeynes@527
   535
	POP_r32(R_EBP);
nkeynes@527
   536
	RET();
nkeynes@527
   537
nkeynes@527
   538
	sh4_x86_do_backpatch( end_ptr );
nkeynes@527
   539
    }
nkeynes@527
   540
}
nkeynes@527
   541
#endif
nkeynes@527
   542
nkeynes@368
   543
/* Exception checks - Note that all exception checks will clobber EAX */
nkeynes@416
   544
#define precheck() load_imm32(R_EDX, (pc-sh4_x86.block_start_pc-(sh4_x86.in_delay_slot?2:0))>>1)
nkeynes@416
   545
nkeynes@416
   546
#define check_priv( ) \
nkeynes@416
   547
    if( !sh4_x86.priv_checked ) { \
nkeynes@416
   548
	sh4_x86.priv_checked = TRUE;\
nkeynes@416
   549
	precheck();\
nkeynes@416
   550
	load_spreg( R_EAX, R_SR );\
nkeynes@416
   551
	AND_imm32_r32( SR_MD, R_EAX );\
nkeynes@416
   552
	if( sh4_x86.in_delay_slot ) {\
nkeynes@416
   553
	    JE_exit( EXIT_SLOT_ILLEGAL );\
nkeynes@416
   554
	} else {\
nkeynes@416
   555
	    JE_exit( EXIT_ILLEGAL );\
nkeynes@416
   556
	}\
nkeynes@416
   557
    }\
nkeynes@416
   558
nkeynes@416
   559
nkeynes@416
   560
static void check_priv_no_precheck()
nkeynes@368
   561
{
nkeynes@368
   562
    if( !sh4_x86.priv_checked ) {
nkeynes@368
   563
	sh4_x86.priv_checked = TRUE;
nkeynes@368
   564
	load_spreg( R_EAX, R_SR );
nkeynes@368
   565
	AND_imm32_r32( SR_MD, R_EAX );
nkeynes@368
   566
	if( sh4_x86.in_delay_slot ) {
nkeynes@368
   567
	    JE_exit( EXIT_SLOT_ILLEGAL );
nkeynes@368
   568
	} else {
nkeynes@368
   569
	    JE_exit( EXIT_ILLEGAL );
nkeynes@368
   570
	}
nkeynes@368
   571
    }
nkeynes@368
   572
}
nkeynes@368
   573
nkeynes@416
   574
#define check_fpuen( ) \
nkeynes@416
   575
    if( !sh4_x86.fpuen_checked ) {\
nkeynes@416
   576
	sh4_x86.fpuen_checked = TRUE;\
nkeynes@416
   577
	precheck();\
nkeynes@416
   578
	load_spreg( R_EAX, R_SR );\
nkeynes@416
   579
	AND_imm32_r32( SR_FD, R_EAX );\
nkeynes@416
   580
	if( sh4_x86.in_delay_slot ) {\
nkeynes@416
   581
	    JNE_exit(EXIT_SLOT_FPU_DISABLED);\
nkeynes@416
   582
	} else {\
nkeynes@416
   583
	    JNE_exit(EXIT_FPU_DISABLED);\
nkeynes@416
   584
	}\
nkeynes@416
   585
    }
nkeynes@416
   586
nkeynes@416
   587
static void check_fpuen_no_precheck()
nkeynes@368
   588
{
nkeynes@368
   589
    if( !sh4_x86.fpuen_checked ) {
nkeynes@368
   590
	sh4_x86.fpuen_checked = TRUE;
nkeynes@368
   591
	load_spreg( R_EAX, R_SR );
nkeynes@368
   592
	AND_imm32_r32( SR_FD, R_EAX );
nkeynes@368
   593
	if( sh4_x86.in_delay_slot ) {
nkeynes@368
   594
	    JNE_exit(EXIT_SLOT_FPU_DISABLED);
nkeynes@368
   595
	} else {
nkeynes@368
   596
	    JNE_exit(EXIT_FPU_DISABLED);
nkeynes@368
   597
	}
nkeynes@368
   598
    }
nkeynes@416
   599
nkeynes@368
   600
}
nkeynes@368
   601
nkeynes@368
   602
static void check_ralign16( int x86reg )
nkeynes@368
   603
{
nkeynes@368
   604
    TEST_imm32_r32( 0x00000001, x86reg );
nkeynes@368
   605
    JNE_exit(EXIT_DATA_ADDR_READ);
nkeynes@368
   606
}
nkeynes@368
   607
nkeynes@368
   608
static void check_walign16( int x86reg )
nkeynes@368
   609
{
nkeynes@368
   610
    TEST_imm32_r32( 0x00000001, x86reg );
nkeynes@368
   611
    JNE_exit(EXIT_DATA_ADDR_WRITE);
nkeynes@368
   612
}
nkeynes@368
   613
nkeynes@368
   614
static void check_ralign32( int x86reg )
nkeynes@368
   615
{
nkeynes@368
   616
    TEST_imm32_r32( 0x00000003, x86reg );
nkeynes@368
   617
    JNE_exit(EXIT_DATA_ADDR_READ);
nkeynes@368
   618
}
nkeynes@368
   619
static void check_walign32( int x86reg )
nkeynes@368
   620
{
nkeynes@368
   621
    TEST_imm32_r32( 0x00000003, x86reg );
nkeynes@368
   622
    JNE_exit(EXIT_DATA_ADDR_WRITE);
nkeynes@368
   623
}
nkeynes@368
   624
nkeynes@361
   625
#define UNDEF()
nkeynes@361
   626
#define MEM_RESULT(value_reg) if(value_reg != R_EAX) { MOV_r32_r32(R_EAX,value_reg); }
nkeynes@361
   627
#define MEM_READ_BYTE( addr_reg, value_reg ) call_func1(sh4_read_byte, addr_reg ); MEM_RESULT(value_reg)
nkeynes@361
   628
#define MEM_READ_WORD( addr_reg, value_reg ) call_func1(sh4_read_word, addr_reg ); MEM_RESULT(value_reg)
nkeynes@361
   629
#define MEM_READ_LONG( addr_reg, value_reg ) call_func1(sh4_read_long, addr_reg ); MEM_RESULT(value_reg)
nkeynes@361
   630
#define MEM_WRITE_BYTE( addr_reg, value_reg ) call_func2(sh4_write_byte, addr_reg, value_reg)
nkeynes@361
   631
#define MEM_WRITE_WORD( addr_reg, value_reg ) call_func2(sh4_write_word, addr_reg, value_reg)
nkeynes@361
   632
#define MEM_WRITE_LONG( addr_reg, value_reg ) call_func2(sh4_write_long, addr_reg, value_reg)
nkeynes@361
   633
nkeynes@416
   634
#define SLOTILLEGAL() precheck(); JMP_exit(EXIT_SLOT_ILLEGAL); sh4_x86.in_delay_slot = FALSE; return 1;
nkeynes@368
   635
nkeynes@368
   636
nkeynes@359
   637
nkeynes@359
   638
/**
nkeynes@359
   639
 * Emit the 'start of block' assembly. Sets up the stack frame and save
nkeynes@359
   640
 * SI/DI as required
nkeynes@359
   641
 */
nkeynes@408
   642
void sh4_translate_begin_block( sh4addr_t pc ) 
nkeynes@368
   643
{
nkeynes@368
   644
    PUSH_r32(R_EBP);
nkeynes@359
   645
    /* mov &sh4r, ebp */
nkeynes@359
   646
    load_imm32( R_EBP, (uint32_t)&sh4r );
nkeynes@368
   647
    
nkeynes@368
   648
    sh4_x86.in_delay_slot = FALSE;
nkeynes@368
   649
    sh4_x86.priv_checked = FALSE;
nkeynes@368
   650
    sh4_x86.fpuen_checked = FALSE;
nkeynes@409
   651
    sh4_x86.branch_taken = FALSE;
nkeynes@368
   652
    sh4_x86.backpatch_posn = 0;
nkeynes@408
   653
    sh4_x86.block_start_pc = pc;
nkeynes@417
   654
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@368
   655
}
nkeynes@359
   656
nkeynes@368
   657
/**
nkeynes@408
   658
 * Exit the block with sh4r.pc already written
nkeynes@416
   659
 * Bytes: 15
nkeynes@408
   660
 */
nkeynes@408
   661
void exit_block_pcset( pc )
nkeynes@408
   662
{
nkeynes@408
   663
    load_imm32( R_ECX, ((pc - sh4_x86.block_start_pc)>>1)*sh4_cpu_period ); // 5
nkeynes@408
   664
    ADD_r32_sh4r( R_ECX, REG_OFFSET(slice_cycle) );    // 6
nkeynes@417
   665
    load_spreg( R_EAX, REG_OFFSET(pc) );
nkeynes@417
   666
    call_func1(xlat_get_code,R_EAX);
nkeynes@408
   667
    POP_r32(R_EBP);
nkeynes@408
   668
    RET();
nkeynes@408
   669
}
nkeynes@408
   670
nkeynes@388
   671
extern uint16_t *sh4_icache;
nkeynes@388
   672
extern uint32_t sh4_icache_addr;
nkeynes@388
   673
nkeynes@359
   674
/**
nkeynes@359
   675
 * Translate a single instruction. Delayed branches are handled specially
nkeynes@359
   676
 * by translating both branch and delayed instruction as a single unit (as
nkeynes@359
   677
 * 
nkeynes@359
   678
 *
nkeynes@359
   679
 * @return true if the instruction marks the end of a basic block
nkeynes@359
   680
 * (eg a branch or 
nkeynes@359
   681
 */
nkeynes@526
   682
uint32_t sh4_translate_instruction( sh4addr_t pc )
nkeynes@359
   683
{
nkeynes@388
   684
    uint32_t ir;
nkeynes@388
   685
    /* Read instruction */
nkeynes@388
   686
    uint32_t pageaddr = pc >> 12;
nkeynes@388
   687
    if( sh4_icache != NULL && pageaddr == sh4_icache_addr ) {
nkeynes@388
   688
	ir = sh4_icache[(pc&0xFFF)>>1];
nkeynes@388
   689
    } else {
nkeynes@388
   690
	sh4_icache = (uint16_t *)mem_get_page(pc);
nkeynes@527
   691
	if( ((uintptr_t)sh4_icache) < MAX_IO_REGIONS ) {
nkeynes@388
   692
	    /* If someone's actually been so daft as to try to execute out of an IO
nkeynes@388
   693
	     * region, fallback on the full-blown memory read
nkeynes@388
   694
	     */
nkeynes@388
   695
	    sh4_icache = NULL;
nkeynes@388
   696
	    ir = sh4_read_word(pc);
nkeynes@388
   697
	} else {
nkeynes@388
   698
	    sh4_icache_addr = pageaddr;
nkeynes@388
   699
	    ir = sh4_icache[(pc&0xFFF)>>1];
nkeynes@388
   700
	}
nkeynes@388
   701
    }
nkeynes@388
   702
nkeynes@359
   703
        switch( (ir&0xF000) >> 12 ) {
nkeynes@359
   704
            case 0x0:
nkeynes@359
   705
                switch( ir&0xF ) {
nkeynes@359
   706
                    case 0x2:
nkeynes@359
   707
                        switch( (ir&0x80) >> 7 ) {
nkeynes@359
   708
                            case 0x0:
nkeynes@359
   709
                                switch( (ir&0x70) >> 4 ) {
nkeynes@359
   710
                                    case 0x0:
nkeynes@359
   711
                                        { /* STC SR, Rn */
nkeynes@359
   712
                                        uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@386
   713
                                        check_priv();
nkeynes@374
   714
                                        call_func0(sh4_read_sr);
nkeynes@368
   715
                                        store_reg( R_EAX, Rn );
nkeynes@417
   716
                                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
   717
                                        }
nkeynes@359
   718
                                        break;
nkeynes@359
   719
                                    case 0x1:
nkeynes@359
   720
                                        { /* STC GBR, Rn */
nkeynes@359
   721
                                        uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   722
                                        load_spreg( R_EAX, R_GBR );
nkeynes@359
   723
                                        store_reg( R_EAX, Rn );
nkeynes@359
   724
                                        }
nkeynes@359
   725
                                        break;
nkeynes@359
   726
                                    case 0x2:
nkeynes@359
   727
                                        { /* STC VBR, Rn */
nkeynes@359
   728
                                        uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@386
   729
                                        check_priv();
nkeynes@359
   730
                                        load_spreg( R_EAX, R_VBR );
nkeynes@359
   731
                                        store_reg( R_EAX, Rn );
nkeynes@417
   732
                                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
   733
                                        }
nkeynes@359
   734
                                        break;
nkeynes@359
   735
                                    case 0x3:
nkeynes@359
   736
                                        { /* STC SSR, Rn */
nkeynes@359
   737
                                        uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@386
   738
                                        check_priv();
nkeynes@359
   739
                                        load_spreg( R_EAX, R_SSR );
nkeynes@359
   740
                                        store_reg( R_EAX, Rn );
nkeynes@417
   741
                                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
   742
                                        }
nkeynes@359
   743
                                        break;
nkeynes@359
   744
                                    case 0x4:
nkeynes@359
   745
                                        { /* STC SPC, Rn */
nkeynes@359
   746
                                        uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@386
   747
                                        check_priv();
nkeynes@359
   748
                                        load_spreg( R_EAX, R_SPC );
nkeynes@359
   749
                                        store_reg( R_EAX, Rn );
nkeynes@417
   750
                                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
   751
                                        }
nkeynes@359
   752
                                        break;
nkeynes@359
   753
                                    default:
nkeynes@359
   754
                                        UNDEF();
nkeynes@359
   755
                                        break;
nkeynes@359
   756
                                }
nkeynes@359
   757
                                break;
nkeynes@359
   758
                            case 0x1:
nkeynes@359
   759
                                { /* STC Rm_BANK, Rn */
nkeynes@359
   760
                                uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm_BANK = ((ir>>4)&0x7); 
nkeynes@386
   761
                                check_priv();
nkeynes@374
   762
                                load_spreg( R_EAX, REG_OFFSET(r_bank[Rm_BANK]) );
nkeynes@374
   763
                                store_reg( R_EAX, Rn );
nkeynes@417
   764
                                sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
   765
                                }
nkeynes@359
   766
                                break;
nkeynes@359
   767
                        }
nkeynes@359
   768
                        break;
nkeynes@359
   769
                    case 0x3:
nkeynes@359
   770
                        switch( (ir&0xF0) >> 4 ) {
nkeynes@359
   771
                            case 0x0:
nkeynes@359
   772
                                { /* BSRF Rn */
nkeynes@359
   773
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@374
   774
                                if( sh4_x86.in_delay_slot ) {
nkeynes@374
   775
                            	SLOTILLEGAL();
nkeynes@374
   776
                                } else {
nkeynes@408
   777
                            	load_imm32( R_ECX, pc + 4 );
nkeynes@408
   778
                            	store_spreg( R_ECX, R_PR );
nkeynes@408
   779
                            	ADD_sh4r_r32( REG_OFFSET(r[Rn]), R_ECX );
nkeynes@408
   780
                            	store_spreg( R_ECX, REG_OFFSET(pc) );
nkeynes@374
   781
                            	sh4_x86.in_delay_slot = TRUE;
nkeynes@417
   782
                            	sh4_x86.tstate = TSTATE_NONE;
nkeynes@526
   783
                            	sh4_translate_instruction( pc + 2 );
nkeynes@408
   784
                            	exit_block_pcset(pc+2);
nkeynes@409
   785
                            	sh4_x86.branch_taken = TRUE;
nkeynes@408
   786
                            	return 4;
nkeynes@374
   787
                                }
nkeynes@359
   788
                                }
nkeynes@359
   789
                                break;
nkeynes@359
   790
                            case 0x2:
nkeynes@359
   791
                                { /* BRAF Rn */
nkeynes@359
   792
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@374
   793
                                if( sh4_x86.in_delay_slot ) {
nkeynes@374
   794
                            	SLOTILLEGAL();
nkeynes@374
   795
                                } else {
nkeynes@408
   796
                            	load_reg( R_EAX, Rn );
nkeynes@408
   797
                            	ADD_imm32_r32( pc + 4, R_EAX );
nkeynes@408
   798
                            	store_spreg( R_EAX, REG_OFFSET(pc) );
nkeynes@374
   799
                            	sh4_x86.in_delay_slot = TRUE;
nkeynes@417
   800
                            	sh4_x86.tstate = TSTATE_NONE;
nkeynes@526
   801
                            	sh4_translate_instruction( pc + 2 );
nkeynes@408
   802
                            	exit_block_pcset(pc+2);
nkeynes@409
   803
                            	sh4_x86.branch_taken = TRUE;
nkeynes@408
   804
                            	return 4;
nkeynes@374
   805
                                }
nkeynes@359
   806
                                }
nkeynes@359
   807
                                break;
nkeynes@359
   808
                            case 0x8:
nkeynes@359
   809
                                { /* PREF @Rn */
nkeynes@359
   810
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@374
   811
                                load_reg( R_EAX, Rn );
nkeynes@374
   812
                                PUSH_r32( R_EAX );
nkeynes@374
   813
                                AND_imm32_r32( 0xFC000000, R_EAX );
nkeynes@374
   814
                                CMP_imm32_r32( 0xE0000000, R_EAX );
nkeynes@527
   815
                                JNE_rel8(CALL_FUNC0_SIZE, end);
nkeynes@374
   816
                                call_func0( sh4_flush_store_queue );
nkeynes@380
   817
                                JMP_TARGET(end);
nkeynes@377
   818
                                ADD_imm8s_r32( 4, R_ESP );
nkeynes@417
   819
                                sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
   820
                                }
nkeynes@359
   821
                                break;
nkeynes@359
   822
                            case 0x9:
nkeynes@359
   823
                                { /* OCBI @Rn */
nkeynes@359
   824
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   825
                                }
nkeynes@359
   826
                                break;
nkeynes@359
   827
                            case 0xA:
nkeynes@359
   828
                                { /* OCBP @Rn */
nkeynes@359
   829
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   830
                                }
nkeynes@359
   831
                                break;
nkeynes@359
   832
                            case 0xB:
nkeynes@359
   833
                                { /* OCBWB @Rn */
nkeynes@359
   834
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   835
                                }
nkeynes@359
   836
                                break;
nkeynes@359
   837
                            case 0xC:
nkeynes@359
   838
                                { /* MOVCA.L R0, @Rn */
nkeynes@359
   839
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@361
   840
                                load_reg( R_EAX, 0 );
nkeynes@361
   841
                                load_reg( R_ECX, Rn );
nkeynes@416
   842
                                precheck();
nkeynes@374
   843
                                check_walign32( R_ECX );
nkeynes@361
   844
                                MEM_WRITE_LONG( R_ECX, R_EAX );
nkeynes@417
   845
                                sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
   846
                                }
nkeynes@359
   847
                                break;
nkeynes@359
   848
                            default:
nkeynes@359
   849
                                UNDEF();
nkeynes@359
   850
                                break;
nkeynes@359
   851
                        }
nkeynes@359
   852
                        break;
nkeynes@359
   853
                    case 0x4:
nkeynes@359
   854
                        { /* MOV.B Rm, @(R0, Rn) */
nkeynes@359
   855
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   856
                        load_reg( R_EAX, 0 );
nkeynes@359
   857
                        load_reg( R_ECX, Rn );
nkeynes@359
   858
                        ADD_r32_r32( R_EAX, R_ECX );
nkeynes@359
   859
                        load_reg( R_EAX, Rm );
nkeynes@359
   860
                        MEM_WRITE_BYTE( R_ECX, R_EAX );
nkeynes@417
   861
                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
   862
                        }
nkeynes@359
   863
                        break;
nkeynes@359
   864
                    case 0x5:
nkeynes@359
   865
                        { /* MOV.W Rm, @(R0, Rn) */
nkeynes@359
   866
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@361
   867
                        load_reg( R_EAX, 0 );
nkeynes@361
   868
                        load_reg( R_ECX, Rn );
nkeynes@361
   869
                        ADD_r32_r32( R_EAX, R_ECX );
nkeynes@416
   870
                        precheck();
nkeynes@374
   871
                        check_walign16( R_ECX );
nkeynes@361
   872
                        load_reg( R_EAX, Rm );
nkeynes@361
   873
                        MEM_WRITE_WORD( R_ECX, R_EAX );
nkeynes@417
   874
                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
   875
                        }
nkeynes@359
   876
                        break;
nkeynes@359
   877
                    case 0x6:
nkeynes@359
   878
                        { /* MOV.L Rm, @(R0, Rn) */
nkeynes@359
   879
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@361
   880
                        load_reg( R_EAX, 0 );
nkeynes@361
   881
                        load_reg( R_ECX, Rn );
nkeynes@361
   882
                        ADD_r32_r32( R_EAX, R_ECX );
nkeynes@416
   883
                        precheck();
nkeynes@374
   884
                        check_walign32( R_ECX );
nkeynes@361
   885
                        load_reg( R_EAX, Rm );
nkeynes@361
   886
                        MEM_WRITE_LONG( R_ECX, R_EAX );
nkeynes@417
   887
                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
   888
                        }
nkeynes@359
   889
                        break;
nkeynes@359
   890
                    case 0x7:
nkeynes@359
   891
                        { /* MUL.L Rm, Rn */
nkeynes@359
   892
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@361
   893
                        load_reg( R_EAX, Rm );
nkeynes@361
   894
                        load_reg( R_ECX, Rn );
nkeynes@361
   895
                        MUL_r32( R_ECX );
nkeynes@361
   896
                        store_spreg( R_EAX, R_MACL );
nkeynes@417
   897
                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
   898
                        }
nkeynes@359
   899
                        break;
nkeynes@359
   900
                    case 0x8:
nkeynes@359
   901
                        switch( (ir&0xFF0) >> 4 ) {
nkeynes@359
   902
                            case 0x0:
nkeynes@359
   903
                                { /* CLRT */
nkeynes@374
   904
                                CLC();
nkeynes@374
   905
                                SETC_t();
nkeynes@417
   906
                                sh4_x86.tstate = TSTATE_C;
nkeynes@359
   907
                                }
nkeynes@359
   908
                                break;
nkeynes@359
   909
                            case 0x1:
nkeynes@359
   910
                                { /* SETT */
nkeynes@374
   911
                                STC();
nkeynes@374
   912
                                SETC_t();
nkeynes@417
   913
                                sh4_x86.tstate = TSTATE_C;
nkeynes@359
   914
                                }
nkeynes@359
   915
                                break;
nkeynes@359
   916
                            case 0x2:
nkeynes@359
   917
                                { /* CLRMAC */
nkeynes@374
   918
                                XOR_r32_r32(R_EAX, R_EAX);
nkeynes@374
   919
                                store_spreg( R_EAX, R_MACL );
nkeynes@374
   920
                                store_spreg( R_EAX, R_MACH );
nkeynes@417
   921
                                sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
   922
                                }
nkeynes@359
   923
                                break;
nkeynes@359
   924
                            case 0x3:
nkeynes@359
   925
                                { /* LDTLB */
nkeynes@359
   926
                                }
nkeynes@359
   927
                                break;
nkeynes@359
   928
                            case 0x4:
nkeynes@359
   929
                                { /* CLRS */
nkeynes@374
   930
                                CLC();
nkeynes@374
   931
                                SETC_sh4r(R_S);
nkeynes@417
   932
                                sh4_x86.tstate = TSTATE_C;
nkeynes@359
   933
                                }
nkeynes@359
   934
                                break;
nkeynes@359
   935
                            case 0x5:
nkeynes@359
   936
                                { /* SETS */
nkeynes@374
   937
                                STC();
nkeynes@374
   938
                                SETC_sh4r(R_S);
nkeynes@417
   939
                                sh4_x86.tstate = TSTATE_C;
nkeynes@359
   940
                                }
nkeynes@359
   941
                                break;
nkeynes@359
   942
                            default:
nkeynes@359
   943
                                UNDEF();
nkeynes@359
   944
                                break;
nkeynes@359
   945
                        }
nkeynes@359
   946
                        break;
nkeynes@359
   947
                    case 0x9:
nkeynes@359
   948
                        switch( (ir&0xF0) >> 4 ) {
nkeynes@359
   949
                            case 0x0:
nkeynes@359
   950
                                { /* NOP */
nkeynes@359
   951
                                /* Do nothing. Well, we could emit an 0x90, but what would really be the point? */
nkeynes@359
   952
                                }
nkeynes@359
   953
                                break;
nkeynes@359
   954
                            case 0x1:
nkeynes@359
   955
                                { /* DIV0U */
nkeynes@361
   956
                                XOR_r32_r32( R_EAX, R_EAX );
nkeynes@361
   957
                                store_spreg( R_EAX, R_Q );
nkeynes@361
   958
                                store_spreg( R_EAX, R_M );
nkeynes@361
   959
                                store_spreg( R_EAX, R_T );
nkeynes@417
   960
                                sh4_x86.tstate = TSTATE_C; // works for DIV1
nkeynes@359
   961
                                }
nkeynes@359
   962
                                break;
nkeynes@359
   963
                            case 0x2:
nkeynes@359
   964
                                { /* MOVT Rn */
nkeynes@359
   965
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   966
                                load_spreg( R_EAX, R_T );
nkeynes@359
   967
                                store_reg( R_EAX, Rn );
nkeynes@359
   968
                                }
nkeynes@359
   969
                                break;
nkeynes@359
   970
                            default:
nkeynes@359
   971
                                UNDEF();
nkeynes@359
   972
                                break;
nkeynes@359
   973
                        }
nkeynes@359
   974
                        break;
nkeynes@359
   975
                    case 0xA:
nkeynes@359
   976
                        switch( (ir&0xF0) >> 4 ) {
nkeynes@359
   977
                            case 0x0:
nkeynes@359
   978
                                { /* STS MACH, Rn */
nkeynes@359
   979
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   980
                                load_spreg( R_EAX, R_MACH );
nkeynes@359
   981
                                store_reg( R_EAX, Rn );
nkeynes@359
   982
                                }
nkeynes@359
   983
                                break;
nkeynes@359
   984
                            case 0x1:
nkeynes@359
   985
                                { /* STS MACL, Rn */
nkeynes@359
   986
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   987
                                load_spreg( R_EAX, R_MACL );
nkeynes@359
   988
                                store_reg( R_EAX, Rn );
nkeynes@359
   989
                                }
nkeynes@359
   990
                                break;
nkeynes@359
   991
                            case 0x2:
nkeynes@359
   992
                                { /* STS PR, Rn */
nkeynes@359
   993
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   994
                                load_spreg( R_EAX, R_PR );
nkeynes@359
   995
                                store_reg( R_EAX, Rn );
nkeynes@359
   996
                                }
nkeynes@359
   997
                                break;
nkeynes@359
   998
                            case 0x3:
nkeynes@359
   999
                                { /* STC SGR, Rn */
nkeynes@359
  1000
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@386
  1001
                                check_priv();
nkeynes@359
  1002
                                load_spreg( R_EAX, R_SGR );
nkeynes@359
  1003
                                store_reg( R_EAX, Rn );
nkeynes@417
  1004
                                sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1005
                                }
nkeynes@359
  1006
                                break;
nkeynes@359
  1007
                            case 0x5:
nkeynes@359
  1008
                                { /* STS FPUL, Rn */
nkeynes@359
  1009
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1010
                                load_spreg( R_EAX, R_FPUL );
nkeynes@359
  1011
                                store_reg( R_EAX, Rn );
nkeynes@359
  1012
                                }
nkeynes@359
  1013
                                break;
nkeynes@359
  1014
                            case 0x6:
nkeynes@359
  1015
                                { /* STS FPSCR, Rn */
nkeynes@359
  1016
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1017
                                load_spreg( R_EAX, R_FPSCR );
nkeynes@359
  1018
                                store_reg( R_EAX, Rn );
nkeynes@359
  1019
                                }
nkeynes@359
  1020
                                break;
nkeynes@359
  1021
                            case 0xF:
nkeynes@359
  1022
                                { /* STC DBR, Rn */
nkeynes@359
  1023
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@386
  1024
                                check_priv();
nkeynes@359
  1025
                                load_spreg( R_EAX, R_DBR );
nkeynes@359
  1026
                                store_reg( R_EAX, Rn );
nkeynes@417
  1027
                                sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1028
                                }
nkeynes@359
  1029
                                break;
nkeynes@359
  1030
                            default:
nkeynes@359
  1031
                                UNDEF();
nkeynes@359
  1032
                                break;
nkeynes@359
  1033
                        }
nkeynes@359
  1034
                        break;
nkeynes@359
  1035
                    case 0xB:
nkeynes@359
  1036
                        switch( (ir&0xFF0) >> 4 ) {
nkeynes@359
  1037
                            case 0x0:
nkeynes@359
  1038
                                { /* RTS */
nkeynes@374
  1039
                                if( sh4_x86.in_delay_slot ) {
nkeynes@374
  1040
                            	SLOTILLEGAL();
nkeynes@374
  1041
                                } else {
nkeynes@408
  1042
                            	load_spreg( R_ECX, R_PR );
nkeynes@408
  1043
                            	store_spreg( R_ECX, REG_OFFSET(pc) );
nkeynes@374
  1044
                            	sh4_x86.in_delay_slot = TRUE;
nkeynes@526
  1045
                            	sh4_translate_instruction(pc+2);
nkeynes@408
  1046
                            	exit_block_pcset(pc+2);
nkeynes@409
  1047
                            	sh4_x86.branch_taken = TRUE;
nkeynes@408
  1048
                            	return 4;
nkeynes@374
  1049
                                }
nkeynes@359
  1050
                                }
nkeynes@359
  1051
                                break;
nkeynes@359
  1052
                            case 0x1:
nkeynes@359
  1053
                                { /* SLEEP */
nkeynes@388
  1054
                                check_priv();
nkeynes@388
  1055
                                call_func0( sh4_sleep );
nkeynes@417
  1056
                                sh4_x86.tstate = TSTATE_NONE;
nkeynes@388
  1057
                                sh4_x86.in_delay_slot = FALSE;
nkeynes@408
  1058
                                return 2;
nkeynes@359
  1059
                                }
nkeynes@359
  1060
                                break;
nkeynes@359
  1061
                            case 0x2:
nkeynes@359
  1062
                                { /* RTE */
nkeynes@374
  1063
                                if( sh4_x86.in_delay_slot ) {
nkeynes@374
  1064
                            	SLOTILLEGAL();
nkeynes@374
  1065
                                } else {
nkeynes@408
  1066
                            	check_priv();
nkeynes@408
  1067
                            	load_spreg( R_ECX, R_SPC );
nkeynes@408
  1068
                            	store_spreg( R_ECX, REG_OFFSET(pc) );
nkeynes@374
  1069
                            	load_spreg( R_EAX, R_SSR );
nkeynes@374
  1070
                            	call_func1( sh4_write_sr, R_EAX );
nkeynes@374
  1071
                            	sh4_x86.in_delay_slot = TRUE;
nkeynes@377
  1072
                            	sh4_x86.priv_checked = FALSE;
nkeynes@377
  1073
                            	sh4_x86.fpuen_checked = FALSE;
nkeynes@417
  1074
                            	sh4_x86.tstate = TSTATE_NONE;
nkeynes@526
  1075
                            	sh4_translate_instruction(pc+2);
nkeynes@408
  1076
                            	exit_block_pcset(pc+2);
nkeynes@409
  1077
                            	sh4_x86.branch_taken = TRUE;
nkeynes@408
  1078
                            	return 4;
nkeynes@374
  1079
                                }
nkeynes@359
  1080
                                }
nkeynes@359
  1081
                                break;
nkeynes@359
  1082
                            default:
nkeynes@359
  1083
                                UNDEF();
nkeynes@359
  1084
                                break;
nkeynes@359
  1085
                        }
nkeynes@359
  1086
                        break;
nkeynes@359
  1087
                    case 0xC:
nkeynes@359
  1088
                        { /* MOV.B @(R0, Rm), Rn */
nkeynes@359
  1089
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  1090
                        load_reg( R_EAX, 0 );
nkeynes@359
  1091
                        load_reg( R_ECX, Rm );
nkeynes@359
  1092
                        ADD_r32_r32( R_EAX, R_ECX );
nkeynes@359
  1093
                        MEM_READ_BYTE( R_ECX, R_EAX );
nkeynes@359
  1094
                        store_reg( R_EAX, Rn );
nkeynes@417
  1095
                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1096
                        }
nkeynes@359
  1097
                        break;
nkeynes@359
  1098
                    case 0xD:
nkeynes@359
  1099
                        { /* MOV.W @(R0, Rm), Rn */
nkeynes@359
  1100
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@361
  1101
                        load_reg( R_EAX, 0 );
nkeynes@361
  1102
                        load_reg( R_ECX, Rm );
nkeynes@361
  1103
                        ADD_r32_r32( R_EAX, R_ECX );
nkeynes@416
  1104
                        precheck();
nkeynes@374
  1105
                        check_ralign16( R_ECX );
nkeynes@361
  1106
                        MEM_READ_WORD( R_ECX, R_EAX );
nkeynes@361
  1107
                        store_reg( R_EAX, Rn );
nkeynes@417
  1108
                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1109
                        }
nkeynes@359
  1110
                        break;
nkeynes@359
  1111
                    case 0xE:
nkeynes@359
  1112
                        { /* MOV.L @(R0, Rm), Rn */
nkeynes@359
  1113
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@361
  1114
                        load_reg( R_EAX, 0 );
nkeynes@361
  1115
                        load_reg( R_ECX, Rm );
nkeynes@361
  1116
                        ADD_r32_r32( R_EAX, R_ECX );
nkeynes@416
  1117
                        precheck();
nkeynes@374
  1118
                        check_ralign32( R_ECX );
nkeynes@361
  1119
                        MEM_READ_LONG( R_ECX, R_EAX );
nkeynes@361
  1120
                        store_reg( R_EAX, Rn );
nkeynes@417
  1121
                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1122
                        }
nkeynes@359
  1123
                        break;
nkeynes@359
  1124
                    case 0xF:
nkeynes@359
  1125
                        { /* MAC.L @Rm+, @Rn+ */
nkeynes@359
  1126
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@386
  1127
                        load_reg( R_ECX, Rm );
nkeynes@416
  1128
                        precheck();
nkeynes@386
  1129
                        check_ralign32( R_ECX );
nkeynes@386
  1130
                        load_reg( R_ECX, Rn );
nkeynes@386
  1131
                        check_ralign32( R_ECX );
nkeynes@386
  1132
                        ADD_imm8s_sh4r( 4, REG_OFFSET(r[Rn]) );
nkeynes@386
  1133
                        MEM_READ_LONG( R_ECX, R_EAX );
nkeynes@386
  1134
                        PUSH_r32( R_EAX );
nkeynes@386
  1135
                        load_reg( R_ECX, Rm );
nkeynes@386
  1136
                        ADD_imm8s_sh4r( 4, REG_OFFSET(r[Rm]) );
nkeynes@386
  1137
                        MEM_READ_LONG( R_ECX, R_EAX );
nkeynes@386
  1138
                        POP_r32( R_ECX );
nkeynes@386
  1139
                        IMUL_r32( R_ECX );
nkeynes@386
  1140
                        ADD_r32_sh4r( R_EAX, R_MACL );
nkeynes@386
  1141
                        ADC_r32_sh4r( R_EDX, R_MACH );
nkeynes@386
  1142
                    
nkeynes@386
  1143
                        load_spreg( R_ECX, R_S );
nkeynes@386
  1144
                        TEST_r32_r32(R_ECX, R_ECX);
nkeynes@527
  1145
                        JE_rel8( CALL_FUNC0_SIZE, nosat );
nkeynes@386
  1146
                        call_func0( signsat48 );
nkeynes@386
  1147
                        JMP_TARGET( nosat );
nkeynes@417
  1148
                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1149
                        }
nkeynes@359
  1150
                        break;
nkeynes@359
  1151
                    default:
nkeynes@359
  1152
                        UNDEF();
nkeynes@359
  1153
                        break;
nkeynes@359
  1154
                }
nkeynes@359
  1155
                break;
nkeynes@359
  1156
            case 0x1:
nkeynes@359
  1157
                { /* MOV.L Rm, @(disp, Rn) */
nkeynes@359
  1158
                uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); uint32_t disp = (ir&0xF)<<2; 
nkeynes@361
  1159
                load_reg( R_ECX, Rn );
nkeynes@361
  1160
                load_reg( R_EAX, Rm );
nkeynes@361
  1161
                ADD_imm32_r32( disp, R_ECX );
nkeynes@416
  1162
                precheck();
nkeynes@374
  1163
                check_walign32( R_ECX );
nkeynes@361
  1164
                MEM_WRITE_LONG( R_ECX, R_EAX );
nkeynes@417
  1165
                sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1166
                }
nkeynes@359
  1167
                break;
nkeynes@359
  1168
            case 0x2:
nkeynes@359
  1169
                switch( ir&0xF ) {
nkeynes@359
  1170
                    case 0x0:
nkeynes@359
  1171
                        { /* MOV.B Rm, @Rn */
nkeynes@359
  1172
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  1173
                        load_reg( R_EAX, Rm );
nkeynes@359
  1174
                        load_reg( R_ECX, Rn );
nkeynes@359
  1175
                        MEM_WRITE_BYTE( R_ECX, R_EAX );
nkeynes@417
  1176
                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1177
                        }
nkeynes@359
  1178
                        break;
nkeynes@359
  1179
                    case 0x1:
nkeynes@359
  1180
                        { /* MOV.W Rm, @Rn */
nkeynes@359
  1181
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@361
  1182
                        load_reg( R_ECX, Rn );
nkeynes@416
  1183
                        precheck();
nkeynes@374
  1184
                        check_walign16( R_ECX );
nkeynes@386
  1185
                        load_reg( R_EAX, Rm );
nkeynes@386
  1186
                        MEM_WRITE_WORD( R_ECX, R_EAX );
nkeynes@417
  1187
                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1188
                        }
nkeynes@359
  1189
                        break;
nkeynes@359
  1190
                    case 0x2:
nkeynes@359
  1191
                        { /* MOV.L Rm, @Rn */
nkeynes@359
  1192
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@361
  1193
                        load_reg( R_EAX, Rm );
nkeynes@361
  1194
                        load_reg( R_ECX, Rn );
nkeynes@416
  1195
                        precheck();
nkeynes@374
  1196
                        check_walign32(R_ECX);
nkeynes@361
  1197
                        MEM_WRITE_LONG( R_ECX, R_EAX );
nkeynes@417
  1198
                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1199
                        }
nkeynes@359
  1200
                        break;
nkeynes@359
  1201
                    case 0x4:
nkeynes@359
  1202
                        { /* MOV.B Rm, @-Rn */
nkeynes@359
  1203
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  1204
                        load_reg( R_EAX, Rm );
nkeynes@359
  1205
                        load_reg( R_ECX, Rn );
nkeynes@386
  1206
                        ADD_imm8s_r32( -1, R_ECX );
nkeynes@359
  1207
                        store_reg( R_ECX, Rn );
nkeynes@359
  1208
                        MEM_WRITE_BYTE( R_ECX, R_EAX );
nkeynes@417
  1209
                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1210
                        }
nkeynes@359
  1211
                        break;
nkeynes@359
  1212
                    case 0x5:
nkeynes@359
  1213
                        { /* MOV.W Rm, @-Rn */
nkeynes@359
  1214
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@361
  1215
                        load_reg( R_ECX, Rn );
nkeynes@416
  1216
                        precheck();
nkeynes@374
  1217
                        check_walign16( R_ECX );
nkeynes@361
  1218
                        load_reg( R_EAX, Rm );
nkeynes@361
  1219
                        ADD_imm8s_r32( -2, R_ECX );
nkeynes@386
  1220
                        store_reg( R_ECX, Rn );
nkeynes@361
  1221
                        MEM_WRITE_WORD( R_ECX, R_EAX );
nkeynes@417
  1222
                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1223
                        }
nkeynes@359
  1224
                        break;
nkeynes@359
  1225
                    case 0x6:
nkeynes@359
  1226
                        { /* MOV.L Rm, @-Rn */
nkeynes@359
  1227
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@361
  1228
                        load_reg( R_EAX, Rm );
nkeynes@361
  1229
                        load_reg( R_ECX, Rn );
nkeynes@416
  1230
                        precheck();
nkeynes@374
  1231
                        check_walign32( R_ECX );
nkeynes@361
  1232
                        ADD_imm8s_r32( -4, R_ECX );
nkeynes@361
  1233
                        store_reg( R_ECX, Rn );
nkeynes@361
  1234
                        MEM_WRITE_LONG( R_ECX, R_EAX );
nkeynes@417
  1235
                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1236
                        }
nkeynes@359
  1237
                        break;
nkeynes@359
  1238
                    case 0x7:
nkeynes@359
  1239
                        { /* DIV0S Rm, Rn */
nkeynes@359
  1240
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@361
  1241
                        load_reg( R_EAX, Rm );
nkeynes@386
  1242
                        load_reg( R_ECX, Rn );
nkeynes@361
  1243
                        SHR_imm8_r32( 31, R_EAX );
nkeynes@361
  1244
                        SHR_imm8_r32( 31, R_ECX );
nkeynes@361
  1245
                        store_spreg( R_EAX, R_M );
nkeynes@361
  1246
                        store_spreg( R_ECX, R_Q );
nkeynes@361
  1247
                        CMP_r32_r32( R_EAX, R_ECX );
nkeynes@386
  1248
                        SETNE_t();
nkeynes@417
  1249
                        sh4_x86.tstate = TSTATE_NE;
nkeynes@359
  1250
                        }
nkeynes@359
  1251
                        break;
nkeynes@359
  1252
                    case 0x8:
nkeynes@359
  1253
                        { /* TST Rm, Rn */
nkeynes@359
  1254
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@361
  1255
                        load_reg( R_EAX, Rm );
nkeynes@361
  1256
                        load_reg( R_ECX, Rn );
nkeynes@361
  1257
                        TEST_r32_r32( R_EAX, R_ECX );
nkeynes@361
  1258
                        SETE_t();
nkeynes@417
  1259
                        sh4_x86.tstate = TSTATE_E;
nkeynes@359
  1260
                        }
nkeynes@359
  1261
                        break;
nkeynes@359
  1262
                    case 0x9:
nkeynes@359
  1263
                        { /* AND Rm, Rn */
nkeynes@359
  1264
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  1265
                        load_reg( R_EAX, Rm );
nkeynes@359
  1266
                        load_reg( R_ECX, Rn );
nkeynes@359
  1267
                        AND_r32_r32( R_EAX, R_ECX );
nkeynes@359
  1268
                        store_reg( R_ECX, Rn );
nkeynes@417
  1269
                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1270
                        }
nkeynes@359
  1271
                        break;
nkeynes@359
  1272
                    case 0xA:
nkeynes@359
  1273
                        { /* XOR Rm, Rn */
nkeynes@359
  1274
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  1275
                        load_reg( R_EAX, Rm );
nkeynes@359
  1276
                        load_reg( R_ECX, Rn );
nkeynes@359
  1277
                        XOR_r32_r32( R_EAX, R_ECX );
nkeynes@359
  1278
                        store_reg( R_ECX, Rn );
nkeynes@417
  1279
                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1280
                        }
nkeynes@359
  1281
                        break;
nkeynes@359
  1282
                    case 0xB:
nkeynes@359
  1283
                        { /* OR Rm, Rn */
nkeynes@359
  1284
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  1285
                        load_reg( R_EAX, Rm );
nkeynes@359
  1286
                        load_reg( R_ECX, Rn );
nkeynes@359
  1287
                        OR_r32_r32( R_EAX, R_ECX );
nkeynes@359
  1288
                        store_reg( R_ECX, Rn );
nkeynes@417
  1289
                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1290
                        }
nkeynes@359
  1291
                        break;
nkeynes@359
  1292
                    case 0xC:
nkeynes@359
  1293
                        { /* CMP/STR Rm, Rn */
nkeynes@359
  1294
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@368
  1295
                        load_reg( R_EAX, Rm );
nkeynes@368
  1296
                        load_reg( R_ECX, Rn );
nkeynes@368
  1297
                        XOR_r32_r32( R_ECX, R_EAX );
nkeynes@368
  1298
                        TEST_r8_r8( R_AL, R_AL );
nkeynes@380
  1299
                        JE_rel8(13, target1);
nkeynes@368
  1300
                        TEST_r8_r8( R_AH, R_AH ); // 2
nkeynes@380
  1301
                        JE_rel8(9, target2);
nkeynes@368
  1302
                        SHR_imm8_r32( 16, R_EAX ); // 3
nkeynes@368
  1303
                        TEST_r8_r8( R_AL, R_AL ); // 2
nkeynes@380
  1304
                        JE_rel8(2, target3);
nkeynes@368
  1305
                        TEST_r8_r8( R_AH, R_AH ); // 2
nkeynes@380
  1306
                        JMP_TARGET(target1);
nkeynes@380
  1307
                        JMP_TARGET(target2);
nkeynes@380
  1308
                        JMP_TARGET(target3);
nkeynes@368
  1309
                        SETE_t();
nkeynes@417
  1310
                        sh4_x86.tstate = TSTATE_E;
nkeynes@359
  1311
                        }
nkeynes@359
  1312
                        break;
nkeynes@359
  1313
                    case 0xD:
nkeynes@359
  1314
                        { /* XTRCT Rm, Rn */
nkeynes@359
  1315
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@361
  1316
                        load_reg( R_EAX, Rm );
nkeynes@394
  1317
                        load_reg( R_ECX, Rn );
nkeynes@394
  1318
                        SHL_imm8_r32( 16, R_EAX );
nkeynes@394
  1319
                        SHR_imm8_r32( 16, R_ECX );
nkeynes@361
  1320
                        OR_r32_r32( R_EAX, R_ECX );
nkeynes@361
  1321
                        store_reg( R_ECX, Rn );
nkeynes@417
  1322
                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1323
                        }
nkeynes@359
  1324
                        break;
nkeynes@359
  1325
                    case 0xE:
nkeynes@359
  1326
                        { /* MULU.W Rm, Rn */
nkeynes@359
  1327
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@374
  1328
                        load_reg16u( R_EAX, Rm );
nkeynes@374
  1329
                        load_reg16u( R_ECX, Rn );
nkeynes@374
  1330
                        MUL_r32( R_ECX );
nkeynes@374
  1331
                        store_spreg( R_EAX, R_MACL );
nkeynes@417
  1332
                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1333
                        }
nkeynes@359
  1334
                        break;
nkeynes@359
  1335
                    case 0xF:
nkeynes@359
  1336
                        { /* MULS.W Rm, Rn */
nkeynes@359
  1337
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@374
  1338
                        load_reg16s( R_EAX, Rm );
nkeynes@374
  1339
                        load_reg16s( R_ECX, Rn );
nkeynes@374
  1340
                        MUL_r32( R_ECX );
nkeynes@374
  1341
                        store_spreg( R_EAX, R_MACL );
nkeynes@417
  1342
                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1343
                        }
nkeynes@359
  1344
                        break;
nkeynes@359
  1345
                    default:
nkeynes@359
  1346
                        UNDEF();
nkeynes@359
  1347
                        break;
nkeynes@359
  1348
                }
nkeynes@359
  1349
                break;
nkeynes@359
  1350
            case 0x3:
nkeynes@359
  1351
                switch( ir&0xF ) {
nkeynes@359
  1352
                    case 0x0:
nkeynes@359
  1353
                        { /* CMP/EQ Rm, Rn */
nkeynes@359
  1354
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  1355
                        load_reg( R_EAX, Rm );
nkeynes@359
  1356
                        load_reg( R_ECX, Rn );
nkeynes@359
  1357
                        CMP_r32_r32( R_EAX, R_ECX );
nkeynes@359
  1358
                        SETE_t();
nkeynes@417
  1359
                        sh4_x86.tstate = TSTATE_E;
nkeynes@359
  1360
                        }
nkeynes@359
  1361
                        break;
nkeynes@359
  1362
                    case 0x2:
nkeynes@359
  1363
                        { /* CMP/HS Rm, Rn */
nkeynes@359
  1364
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  1365
                        load_reg( R_EAX, Rm );
nkeynes@359
  1366
                        load_reg( R_ECX, Rn );
nkeynes@359
  1367
                        CMP_r32_r32( R_EAX, R_ECX );
nkeynes@359
  1368
                        SETAE_t();
nkeynes@417
  1369
                        sh4_x86.tstate = TSTATE_AE;
nkeynes@359
  1370
                        }
nkeynes@359
  1371
                        break;
nkeynes@359
  1372
                    case 0x3:
nkeynes@359
  1373
                        { /* CMP/GE Rm, Rn */
nkeynes@359
  1374
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  1375
                        load_reg( R_EAX, Rm );
nkeynes@359
  1376
                        load_reg( R_ECX, Rn );
nkeynes@359
  1377
                        CMP_r32_r32( R_EAX, R_ECX );
nkeynes@359
  1378
                        SETGE_t();
nkeynes@417
  1379
                        sh4_x86.tstate = TSTATE_GE;
nkeynes@359
  1380
                        }
nkeynes@359
  1381
                        break;
nkeynes@359
  1382
                    case 0x4:
nkeynes@359
  1383
                        { /* DIV1 Rm, Rn */
nkeynes@359
  1384
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@386
  1385
                        load_spreg( R_ECX, R_M );
nkeynes@386
  1386
                        load_reg( R_EAX, Rn );
nkeynes@417
  1387
                        if( sh4_x86.tstate != TSTATE_C ) {
nkeynes@417
  1388
                    	LDC_t();
nkeynes@417
  1389
                        }
nkeynes@386
  1390
                        RCL1_r32( R_EAX );
nkeynes@386
  1391
                        SETC_r8( R_DL ); // Q'
nkeynes@386
  1392
                        CMP_sh4r_r32( R_Q, R_ECX );
nkeynes@386
  1393
                        JE_rel8(5, mqequal);
nkeynes@386
  1394
                        ADD_sh4r_r32( REG_OFFSET(r[Rm]), R_EAX );
nkeynes@386
  1395
                        JMP_rel8(3, end);
nkeynes@380
  1396
                        JMP_TARGET(mqequal);
nkeynes@386
  1397
                        SUB_sh4r_r32( REG_OFFSET(r[Rm]), R_EAX );
nkeynes@386
  1398
                        JMP_TARGET(end);
nkeynes@386
  1399
                        store_reg( R_EAX, Rn ); // Done with Rn now
nkeynes@386
  1400
                        SETC_r8(R_AL); // tmp1
nkeynes@386
  1401
                        XOR_r8_r8( R_DL, R_AL ); // Q' = Q ^ tmp1
nkeynes@386
  1402
                        XOR_r8_r8( R_AL, R_CL ); // Q'' = Q' ^ M
nkeynes@386
  1403
                        store_spreg( R_ECX, R_Q );
nkeynes@386
  1404
                        XOR_imm8s_r32( 1, R_AL );   // T = !Q'
nkeynes@386
  1405
                        MOVZX_r8_r32( R_AL, R_EAX );
nkeynes@386
  1406
                        store_spreg( R_EAX, R_T );
nkeynes@417
  1407
                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1408
                        }
nkeynes@359
  1409
                        break;
nkeynes@359
  1410
                    case 0x5:
nkeynes@359
  1411
                        { /* DMULU.L Rm, Rn */
nkeynes@359
  1412
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@361
  1413
                        load_reg( R_EAX, Rm );
nkeynes@361
  1414
                        load_reg( R_ECX, Rn );
nkeynes@361
  1415
                        MUL_r32(R_ECX);
nkeynes@361
  1416
                        store_spreg( R_EDX, R_MACH );
nkeynes@417
  1417
                        store_spreg( R_EAX, R_MACL );    
nkeynes@417
  1418
                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1419
                        }
nkeynes@359
  1420
                        break;
nkeynes@359
  1421
                    case 0x6:
nkeynes@359
  1422
                        { /* CMP/HI Rm, Rn */
nkeynes@359
  1423
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  1424
                        load_reg( R_EAX, Rm );
nkeynes@359
  1425
                        load_reg( R_ECX, Rn );
nkeynes@359
  1426
                        CMP_r32_r32( R_EAX, R_ECX );
nkeynes@359
  1427
                        SETA_t();
nkeynes@417
  1428
                        sh4_x86.tstate = TSTATE_A;
nkeynes@359
  1429
                        }
nkeynes@359
  1430
                        break;
nkeynes@359
  1431
                    case 0x7:
nkeynes@359
  1432
                        { /* CMP/GT Rm, Rn */
nkeynes@359
  1433
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  1434
                        load_reg( R_EAX, Rm );
nkeynes@359
  1435
                        load_reg( R_ECX, Rn );
nkeynes@359
  1436
                        CMP_r32_r32( R_EAX, R_ECX );
nkeynes@359
  1437
                        SETG_t();
nkeynes@417
  1438
                        sh4_x86.tstate = TSTATE_G;
nkeynes@359
  1439
                        }
nkeynes@359
  1440
                        break;
nkeynes@359
  1441
                    case 0x8:
nkeynes@359
  1442
                        { /* SUB Rm, Rn */
nkeynes@359
  1443
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  1444
                        load_reg( R_EAX, Rm );
nkeynes@359
  1445
                        load_reg( R_ECX, Rn );
nkeynes@359
  1446
                        SUB_r32_r32( R_EAX, R_ECX );
nkeynes@359
  1447
                        store_reg( R_ECX, Rn );
nkeynes@417
  1448
                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1449
                        }
nkeynes@359
  1450
                        break;
nkeynes@359
  1451
                    case 0xA:
nkeynes@359
  1452
                        { /* SUBC Rm, Rn */
nkeynes@359
  1453
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  1454
                        load_reg( R_EAX, Rm );
nkeynes@359
  1455
                        load_reg( R_ECX, Rn );
nkeynes@417
  1456
                        if( sh4_x86.tstate != TSTATE_C ) {
nkeynes@417
  1457
                    	LDC_t();
nkeynes@417
  1458
                        }
nkeynes@359
  1459
                        SBB_r32_r32( R_EAX, R_ECX );
nkeynes@359
  1460
                        store_reg( R_ECX, Rn );
nkeynes@394
  1461
                        SETC_t();
nkeynes@417
  1462
                        sh4_x86.tstate = TSTATE_C;
nkeynes@359
  1463
                        }
nkeynes@359
  1464
                        break;
nkeynes@359
  1465
                    case 0xB:
nkeynes@359
  1466
                        { /* SUBV Rm, Rn */
nkeynes@359
  1467
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  1468
                        load_reg( R_EAX, Rm );
nkeynes@359
  1469
                        load_reg( R_ECX, Rn );
nkeynes@359
  1470
                        SUB_r32_r32( R_EAX, R_ECX );
nkeynes@359
  1471
                        store_reg( R_ECX, Rn );
nkeynes@359
  1472
                        SETO_t();
nkeynes@417
  1473
                        sh4_x86.tstate = TSTATE_O;
nkeynes@359
  1474
                        }
nkeynes@359
  1475
                        break;
nkeynes@359
  1476
                    case 0xC:
nkeynes@359
  1477
                        { /* ADD Rm, Rn */
nkeynes@359
  1478
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  1479
                        load_reg( R_EAX, Rm );
nkeynes@359
  1480
                        load_reg( R_ECX, Rn );
nkeynes@359
  1481
                        ADD_r32_r32( R_EAX, R_ECX );
nkeynes@359
  1482
                        store_reg( R_ECX, Rn );
nkeynes@417
  1483
                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1484
                        }
nkeynes@359
  1485
                        break;
nkeynes@359
  1486
                    case 0xD:
nkeynes@359
  1487
                        { /* DMULS.L Rm, Rn */
nkeynes@359
  1488
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@361
  1489
                        load_reg( R_EAX, Rm );
nkeynes@361
  1490
                        load_reg( R_ECX, Rn );
nkeynes@361
  1491
                        IMUL_r32(R_ECX);
nkeynes@361
  1492
                        store_spreg( R_EDX, R_MACH );
nkeynes@361
  1493
                        store_spreg( R_EAX, R_MACL );
nkeynes@417
  1494
                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1495
                        }
nkeynes@359
  1496
                        break;
nkeynes@359
  1497
                    case 0xE:
nkeynes@359
  1498
                        { /* ADDC Rm, Rn */
nkeynes@359
  1499
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@417
  1500
                        if( sh4_x86.tstate != TSTATE_C ) {
nkeynes@417
  1501
                    	LDC_t();
nkeynes@417
  1502
                        }
nkeynes@359
  1503
                        load_reg( R_EAX, Rm );
nkeynes@359
  1504
                        load_reg( R_ECX, Rn );
nkeynes@359
  1505
                        ADC_r32_r32( R_EAX, R_ECX );
nkeynes@359
  1506
                        store_reg( R_ECX, Rn );
nkeynes@359
  1507
                        SETC_t();
nkeynes@417
  1508
                        sh4_x86.tstate = TSTATE_C;
nkeynes@359
  1509
                        }
nkeynes@359
  1510
                        break;
nkeynes@359
  1511
                    case 0xF:
nkeynes@359
  1512
                        { /* ADDV Rm, Rn */
nkeynes@359
  1513
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  1514
                        load_reg( R_EAX, Rm );
nkeynes@359
  1515
                        load_reg( R_ECX, Rn );
nkeynes@359
  1516
                        ADD_r32_r32( R_EAX, R_ECX );
nkeynes@359
  1517
                        store_reg( R_ECX, Rn );
nkeynes@359
  1518
                        SETO_t();
nkeynes@417
  1519
                        sh4_x86.tstate = TSTATE_O;
nkeynes@359
  1520
                        }
nkeynes@359
  1521
                        break;
nkeynes@359
  1522
                    default:
nkeynes@359
  1523
                        UNDEF();
nkeynes@359
  1524
                        break;
nkeynes@359
  1525
                }
nkeynes@359
  1526
                break;
nkeynes@359
  1527
            case 0x4:
nkeynes@359
  1528
                switch( ir&0xF ) {
nkeynes@359
  1529
                    case 0x0:
nkeynes@359
  1530
                        switch( (ir&0xF0) >> 4 ) {
nkeynes@359
  1531
                            case 0x0:
nkeynes@359
  1532
                                { /* SHLL Rn */
nkeynes@359
  1533
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1534
                                load_reg( R_EAX, Rn );
nkeynes@359
  1535
                                SHL1_r32( R_EAX );
nkeynes@397
  1536
                                SETC_t();
nkeynes@359
  1537
                                store_reg( R_EAX, Rn );
nkeynes@417
  1538
                                sh4_x86.tstate = TSTATE_C;
nkeynes@359
  1539
                                }
nkeynes@359
  1540
                                break;
nkeynes@359
  1541
                            case 0x1:
nkeynes@359
  1542
                                { /* DT Rn */
nkeynes@359
  1543
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1544
                                load_reg( R_EAX, Rn );
nkeynes@386
  1545
                                ADD_imm8s_r32( -1, R_EAX );
nkeynes@359
  1546
                                store_reg( R_EAX, Rn );
nkeynes@359
  1547
                                SETE_t();
nkeynes@417
  1548
                                sh4_x86.tstate = TSTATE_E;
nkeynes@359
  1549
                                }
nkeynes@359
  1550
                                break;
nkeynes@359
  1551
                            case 0x2:
nkeynes@359
  1552
                                { /* SHAL Rn */
nkeynes@359
  1553
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1554
                                load_reg( R_EAX, Rn );
nkeynes@359
  1555
                                SHL1_r32( R_EAX );
nkeynes@397
  1556
                                SETC_t();
nkeynes@359
  1557
                                store_reg( R_EAX, Rn );
nkeynes@417
  1558
                                sh4_x86.tstate = TSTATE_C;
nkeynes@359
  1559
                                }
nkeynes@359
  1560
                                break;
nkeynes@359
  1561
                            default:
nkeynes@359
  1562
                                UNDEF();
nkeynes@359
  1563
                                break;
nkeynes@359
  1564
                        }
nkeynes@359
  1565
                        break;
nkeynes@359
  1566
                    case 0x1:
nkeynes@359
  1567
                        switch( (ir&0xF0) >> 4 ) {
nkeynes@359
  1568
                            case 0x0:
nkeynes@359
  1569
                                { /* SHLR Rn */
nkeynes@359
  1570
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1571
                                load_reg( R_EAX, Rn );
nkeynes@359
  1572
                                SHR1_r32( R_EAX );
nkeynes@397
  1573
                                SETC_t();
nkeynes@359
  1574
                                store_reg( R_EAX, Rn );
nkeynes@417
  1575
                                sh4_x86.tstate = TSTATE_C;
nkeynes@359
  1576
                                }
nkeynes@359
  1577
                                break;
nkeynes@359
  1578
                            case 0x1:
nkeynes@359
  1579
                                { /* CMP/PZ Rn */
nkeynes@359
  1580
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1581
                                load_reg( R_EAX, Rn );
nkeynes@359
  1582
                                CMP_imm8s_r32( 0, R_EAX );
nkeynes@359
  1583
                                SETGE_t();
nkeynes@417
  1584
                                sh4_x86.tstate = TSTATE_GE;
nkeynes@359
  1585
                                }
nkeynes@359
  1586
                                break;
nkeynes@359
  1587
                            case 0x2:
nkeynes@359
  1588
                                { /* SHAR Rn */
nkeynes@359
  1589
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1590
                                load_reg( R_EAX, Rn );
nkeynes@359
  1591
                                SAR1_r32( R_EAX );
nkeynes@397
  1592
                                SETC_t();
nkeynes@359
  1593
                                store_reg( R_EAX, Rn );
nkeynes@417
  1594
                                sh4_x86.tstate = TSTATE_C;
nkeynes@359
  1595
                                }
nkeynes@359
  1596
                                break;
nkeynes@359
  1597
                            default:
nkeynes@359
  1598
                                UNDEF();
nkeynes@359
  1599
                                break;
nkeynes@359
  1600
                        }
nkeynes@359
  1601
                        break;
nkeynes@359
  1602
                    case 0x2:
nkeynes@359
  1603
                        switch( (ir&0xF0) >> 4 ) {
nkeynes@359
  1604
                            case 0x0:
nkeynes@359
  1605
                                { /* STS.L MACH, @-Rn */
nkeynes@359
  1606
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1607
                                load_reg( R_ECX, Rn );
nkeynes@416
  1608
                                precheck();
nkeynes@395
  1609
                                check_walign32( R_ECX );
nkeynes@386
  1610
                                ADD_imm8s_r32( -4, R_ECX );
nkeynes@359
  1611
                                store_reg( R_ECX, Rn );
nkeynes@359
  1612
                                load_spreg( R_EAX, R_MACH );
nkeynes@359
  1613
                                MEM_WRITE_LONG( R_ECX, R_EAX );
nkeynes@417
  1614
                                sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1615
                                }
nkeynes@359
  1616
                                break;
nkeynes@359
  1617
                            case 0x1:
nkeynes@359
  1618
                                { /* STS.L MACL, @-Rn */
nkeynes@359
  1619
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1620
                                load_reg( R_ECX, Rn );
nkeynes@416
  1621
                                precheck();
nkeynes@395
  1622
                                check_walign32( R_ECX );
nkeynes@386
  1623
                                ADD_imm8s_r32( -4, R_ECX );
nkeynes@359
  1624
                                store_reg( R_ECX, Rn );
nkeynes@359
  1625
                                load_spreg( R_EAX, R_MACL );
nkeynes@359
  1626
                                MEM_WRITE_LONG( R_ECX, R_EAX );
nkeynes@417
  1627
                                sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1628
                                }
nkeynes@359
  1629
                                break;
nkeynes@359
  1630
                            case 0x2:
nkeynes@359
  1631
                                { /* STS.L PR, @-Rn */
nkeynes@359
  1632
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1633
                                load_reg( R_ECX, Rn );
nkeynes@416
  1634
                                precheck();
nkeynes@395
  1635
                                check_walign32( R_ECX );
nkeynes@386
  1636
                                ADD_imm8s_r32( -4, R_ECX );
nkeynes@359
  1637
                                store_reg( R_ECX, Rn );
nkeynes@359
  1638
                                load_spreg( R_EAX, R_PR );
nkeynes@359
  1639
                                MEM_WRITE_LONG( R_ECX, R_EAX );
nkeynes@417
  1640
                                sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1641
                                }
nkeynes@359
  1642
                                break;
nkeynes@359
  1643
                            case 0x3:
nkeynes@359
  1644
                                { /* STC.L SGR, @-Rn */
nkeynes@359
  1645
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@416
  1646
                                precheck();
nkeynes@416
  1647
                                check_priv_no_precheck();
nkeynes@359
  1648
                                load_reg( R_ECX, Rn );
nkeynes@395
  1649
                                check_walign32( R_ECX );
nkeynes@386
  1650
                                ADD_imm8s_r32( -4, R_ECX );
nkeynes@359
  1651
                                store_reg( R_ECX, Rn );
nkeynes@359
  1652
                                load_spreg( R_EAX, R_SGR );
nkeynes@359
  1653
                                MEM_WRITE_LONG( R_ECX, R_EAX );
nkeynes@417
  1654
                                sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1655
                                }
nkeynes@359
  1656
                                break;
nkeynes@359
  1657
                            case 0x5:
nkeynes@359
  1658
                                { /* STS.L FPUL, @-Rn */
nkeynes@359
  1659
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1660
                                load_reg( R_ECX, Rn );
nkeynes@416
  1661
                                precheck();
nkeynes@395
  1662
                                check_walign32( R_ECX );
nkeynes@386
  1663
                                ADD_imm8s_r32( -4, R_ECX );
nkeynes@359
  1664
                                store_reg( R_ECX, Rn );
nkeynes@359
  1665
                                load_spreg( R_EAX, R_FPUL );
nkeynes@359
  1666
                                MEM_WRITE_LONG( R_ECX, R_EAX );
nkeynes@417
  1667
                                sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1668
                                }
nkeynes@359
  1669
                                break;
nkeynes@359
  1670
                            case 0x6:
nkeynes@359
  1671
                                { /* STS.L FPSCR, @-Rn */
nkeynes@359
  1672
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1673
                                load_reg( R_ECX, Rn );
nkeynes@416
  1674
                                precheck();
nkeynes@395
  1675
                                check_walign32( R_ECX );
nkeynes@386
  1676
                                ADD_imm8s_r32( -4, R_ECX );
nkeynes@359
  1677
                                store_reg( R_ECX, Rn );
nkeynes@359
  1678
                                load_spreg( R_EAX, R_FPSCR );
nkeynes@359
  1679
                                MEM_WRITE_LONG( R_ECX, R_EAX );
nkeynes@417
  1680
                                sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1681
                                }
nkeynes@359
  1682
                                break;
nkeynes@359
  1683
                            case 0xF:
nkeynes@359
  1684
                                { /* STC.L DBR, @-Rn */
nkeynes@359
  1685
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@416
  1686
                                precheck();
nkeynes@416
  1687
                                check_priv_no_precheck();
nkeynes@359
  1688
                                load_reg( R_ECX, Rn );
nkeynes@395
  1689
                                check_walign32( R_ECX );
nkeynes@386
  1690
                                ADD_imm8s_r32( -4, R_ECX );
nkeynes@359
  1691
                                store_reg( R_ECX, Rn );
nkeynes@359
  1692
                                load_spreg( R_EAX, R_DBR );
nkeynes@359
  1693
                                MEM_WRITE_LONG( R_ECX, R_EAX );
nkeynes@417
  1694
                                sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1695
                                }
nkeynes@359
  1696
                                break;
nkeynes@359
  1697
                            default:
nkeynes@359
  1698
                                UNDEF();
nkeynes@359
  1699
                                break;
nkeynes@359
  1700
                        }
nkeynes@359
  1701
                        break;
nkeynes@359
  1702
                    case 0x3:
nkeynes@359
  1703
                        switch( (ir&0x80) >> 7 ) {
nkeynes@359
  1704
                            case 0x0:
nkeynes@359
  1705
                                switch( (ir&0x70) >> 4 ) {
nkeynes@359
  1706
                                    case 0x0:
nkeynes@359
  1707
                                        { /* STC.L SR, @-Rn */
nkeynes@359
  1708
                                        uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@416
  1709
                                        precheck();
nkeynes@416
  1710
                                        check_priv_no_precheck();
nkeynes@395
  1711
                                        call_func0( sh4_read_sr );
nkeynes@374
  1712
                                        load_reg( R_ECX, Rn );
nkeynes@395
  1713
                                        check_walign32( R_ECX );
nkeynes@386
  1714
                                        ADD_imm8s_r32( -4, R_ECX );
nkeynes@374
  1715
                                        store_reg( R_ECX, Rn );
nkeynes@374
  1716
                                        MEM_WRITE_LONG( R_ECX, R_EAX );
nkeynes@417
  1717
                                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1718
                                        }
nkeynes@359
  1719
                                        break;
nkeynes@359
  1720
                                    case 0x1:
nkeynes@359
  1721
                                        { /* STC.L GBR, @-Rn */
nkeynes@359
  1722
                                        uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1723
                                        load_reg( R_ECX, Rn );
nkeynes@416
  1724
                                        precheck();
nkeynes@395
  1725
                                        check_walign32( R_ECX );
nkeynes@386
  1726
                                        ADD_imm8s_r32( -4, R_ECX );
nkeynes@359
  1727
                                        store_reg( R_ECX, Rn );
nkeynes@359
  1728
                                        load_spreg( R_EAX, R_GBR );
nkeynes@359
  1729
                                        MEM_WRITE_LONG( R_ECX, R_EAX );
nkeynes@417
  1730
                                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1731
                                        }
nkeynes@359
  1732
                                        break;
nkeynes@359
  1733
                                    case 0x2:
nkeynes@359
  1734
                                        { /* STC.L VBR, @-Rn */
nkeynes@359
  1735
                                        uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@416
  1736
                                        precheck();
nkeynes@416
  1737
                                        check_priv_no_precheck();
nkeynes@359
  1738
                                        load_reg( R_ECX, Rn );
nkeynes@395
  1739
                                        check_walign32( R_ECX );
nkeynes@386
  1740
                                        ADD_imm8s_r32( -4, R_ECX );
nkeynes@359
  1741
                                        store_reg( R_ECX, Rn );
nkeynes@359
  1742
                                        load_spreg( R_EAX, R_VBR );
nkeynes@359
  1743
                                        MEM_WRITE_LONG( R_ECX, R_EAX );
nkeynes@417
  1744
                                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1745
                                        }
nkeynes@359
  1746
                                        break;
nkeynes@359
  1747
                                    case 0x3:
nkeynes@359
  1748
                                        { /* STC.L SSR, @-Rn */
nkeynes@359
  1749
                                        uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@416
  1750
                                        precheck();
nkeynes@416
  1751
                                        check_priv_no_precheck();
nkeynes@359
  1752
                                        load_reg( R_ECX, Rn );
nkeynes@395
  1753
                                        check_walign32( R_ECX );
nkeynes@386
  1754
                                        ADD_imm8s_r32( -4, R_ECX );
nkeynes@359
  1755
                                        store_reg( R_ECX, Rn );
nkeynes@359
  1756
                                        load_spreg( R_EAX, R_SSR );
nkeynes@359
  1757
                                        MEM_WRITE_LONG( R_ECX, R_EAX );
nkeynes@417
  1758
                                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1759
                                        }
nkeynes@359
  1760
                                        break;
nkeynes@359
  1761
                                    case 0x4:
nkeynes@359
  1762
                                        { /* STC.L SPC, @-Rn */
nkeynes@359
  1763
                                        uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@416
  1764
                                        precheck();
nkeynes@416
  1765
                                        check_priv_no_precheck();
nkeynes@359
  1766
                                        load_reg( R_ECX, Rn );
nkeynes@395
  1767
                                        check_walign32( R_ECX );
nkeynes@386
  1768
                                        ADD_imm8s_r32( -4, R_ECX );
nkeynes@359
  1769
                                        store_reg( R_ECX, Rn );
nkeynes@359
  1770
                                        load_spreg( R_EAX, R_SPC );
nkeynes@359
  1771
                                        MEM_WRITE_LONG( R_ECX, R_EAX );
nkeynes@417
  1772
                                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1773
                                        }
nkeynes@359
  1774
                                        break;
nkeynes@359
  1775
                                    default:
nkeynes@359
  1776
                                        UNDEF();
nkeynes@359
  1777
                                        break;
nkeynes@359
  1778
                                }
nkeynes@359
  1779
                                break;
nkeynes@359
  1780
                            case 0x1:
nkeynes@359
  1781
                                { /* STC.L Rm_BANK, @-Rn */
nkeynes@359
  1782
                                uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm_BANK = ((ir>>4)&0x7); 
nkeynes@416
  1783
                                precheck();
nkeynes@416
  1784
                                check_priv_no_precheck();
nkeynes@374
  1785
                                load_reg( R_ECX, Rn );
nkeynes@395
  1786
                                check_walign32( R_ECX );
nkeynes@386
  1787
                                ADD_imm8s_r32( -4, R_ECX );
nkeynes@374
  1788
                                store_reg( R_ECX, Rn );
nkeynes@374
  1789
                                load_spreg( R_EAX, REG_OFFSET(r_bank[Rm_BANK]) );
nkeynes@374
  1790
                                MEM_WRITE_LONG( R_ECX, R_EAX );
nkeynes@417
  1791
                                sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1792
                                }
nkeynes@359
  1793
                                break;
nkeynes@359
  1794
                        }
nkeynes@359
  1795
                        break;
nkeynes@359
  1796
                    case 0x4:
nkeynes@359
  1797
                        switch( (ir&0xF0) >> 4 ) {
nkeynes@359
  1798
                            case 0x0:
nkeynes@359
  1799
                                { /* ROTL Rn */
nkeynes@359
  1800
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1801
                                load_reg( R_EAX, Rn );
nkeynes@359
  1802
                                ROL1_r32( R_EAX );
nkeynes@359
  1803
                                store_reg( R_EAX, Rn );
nkeynes@359
  1804
                                SETC_t();
nkeynes@417
  1805
                                sh4_x86.tstate = TSTATE_C;
nkeynes@359
  1806
                                }
nkeynes@359
  1807
                                break;
nkeynes@359
  1808
                            case 0x2:
nkeynes@359
  1809
                                { /* ROTCL Rn */
nkeynes@359
  1810
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1811
                                load_reg( R_EAX, Rn );
nkeynes@417
  1812
                                if( sh4_x86.tstate != TSTATE_C ) {
nkeynes@417
  1813
                            	LDC_t();
nkeynes@417
  1814
                                }
nkeynes@359
  1815
                                RCL1_r32( R_EAX );
nkeynes@359
  1816
                                store_reg( R_EAX, Rn );
nkeynes@359
  1817
                                SETC_t();
nkeynes@417
  1818
                                sh4_x86.tstate = TSTATE_C;
nkeynes@359
  1819
                                }
nkeynes@359
  1820
                                break;
nkeynes@359
  1821
                            default:
nkeynes@359
  1822
                                UNDEF();
nkeynes@359
  1823
                                break;
nkeynes@359
  1824
                        }
nkeynes@359
  1825
                        break;
nkeynes@359
  1826
                    case 0x5:
nkeynes@359
  1827
                        switch( (ir&0xF0) >> 4 ) {
nkeynes@359
  1828
                            case 0x0:
nkeynes@359
  1829
                                { /* ROTR Rn */
nkeynes@359
  1830
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1831
                                load_reg( R_EAX, Rn );
nkeynes@359
  1832
                                ROR1_r32( R_EAX );
nkeynes@359
  1833
                                store_reg( R_EAX, Rn );
nkeynes@359
  1834
                                SETC_t();
nkeynes@417
  1835
                                sh4_x86.tstate = TSTATE_C;
nkeynes@359
  1836
                                }
nkeynes@359
  1837
                                break;
nkeynes@359
  1838
                            case 0x1:
nkeynes@359
  1839
                                { /* CMP/PL Rn */
nkeynes@359
  1840
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1841
                                load_reg( R_EAX, Rn );
nkeynes@359
  1842
                                CMP_imm8s_r32( 0, R_EAX );
nkeynes@359
  1843
                                SETG_t();
nkeynes@417
  1844
                                sh4_x86.tstate = TSTATE_G;
nkeynes@359
  1845
                                }
nkeynes@359
  1846
                                break;
nkeynes@359
  1847
                            case 0x2:
nkeynes@359
  1848
                                { /* ROTCR Rn */
nkeynes@359
  1849
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1850
                                load_reg( R_EAX, Rn );
nkeynes@417
  1851
                                if( sh4_x86.tstate != TSTATE_C ) {
nkeynes@417
  1852
                            	LDC_t();
nkeynes@417
  1853
                                }
nkeynes@359
  1854
                                RCR1_r32( R_EAX );
nkeynes@359
  1855
                                store_reg( R_EAX, Rn );
nkeynes@359
  1856
                                SETC_t();
nkeynes@417
  1857
                                sh4_x86.tstate = TSTATE_C;
nkeynes@359
  1858
                                }
nkeynes@359
  1859
                                break;
nkeynes@359
  1860
                            default:
nkeynes@359
  1861
                                UNDEF();
nkeynes@359
  1862
                                break;
nkeynes@359
  1863
                        }
nkeynes@359
  1864
                        break;
nkeynes@359
  1865
                    case 0x6:
nkeynes@359
  1866
                        switch( (ir&0xF0) >> 4 ) {
nkeynes@359
  1867
                            case 0x0:
nkeynes@359
  1868
                                { /* LDS.L @Rm+, MACH */
nkeynes@359
  1869
                                uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  1870
                                load_reg( R_EAX, Rm );
nkeynes@416
  1871
                                precheck();
nkeynes@395
  1872
                                check_ralign32( R_EAX );
nkeynes@359
  1873
                                MOV_r32_r32( R_EAX, R_ECX );
nkeynes@359
  1874
                                ADD_imm8s_r32( 4, R_EAX );
nkeynes@359
  1875
                                store_reg( R_EAX, Rm );
nkeynes@359
  1876
                                MEM_READ_LONG( R_ECX, R_EAX );
nkeynes@359
  1877
                                store_spreg( R_EAX, R_MACH );
nkeynes@417
  1878
                                sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1879
                                }
nkeynes@359
  1880
                                break;
nkeynes@359
  1881
                            case 0x1:
nkeynes@359
  1882
                                { /* LDS.L @Rm+, MACL */
nkeynes@359
  1883
                                uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  1884
                                load_reg( R_EAX, Rm );
nkeynes@416
  1885
                                precheck();
nkeynes@395
  1886
                                check_ralign32( R_EAX );
nkeynes@359
  1887
                                MOV_r32_r32( R_EAX, R_ECX );
nkeynes@359
  1888
                                ADD_imm8s_r32( 4, R_EAX );
nkeynes@359
  1889
                                store_reg( R_EAX, Rm );
nkeynes@359
  1890
                                MEM_READ_LONG( R_ECX, R_EAX );
nkeynes@359
  1891
                                store_spreg( R_EAX, R_MACL );
nkeynes@417
  1892
                                sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1893
                                }
nkeynes@359
  1894
                                break;
nkeynes@359
  1895
                            case 0x2:
nkeynes@359
  1896
                                { /* LDS.L @Rm+, PR */
nkeynes@359
  1897
                                uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  1898
                                load_reg( R_EAX, Rm );
nkeynes@416
  1899
                                precheck();
nkeynes@395
  1900
                                check_ralign32( R_EAX );
nkeynes@359
  1901
                                MOV_r32_r32( R_EAX, R_ECX );
nkeynes@359
  1902
                                ADD_imm8s_r32( 4, R_EAX );
nkeynes@359
  1903
                                store_reg( R_EAX, Rm );
nkeynes@359
  1904
                                MEM_READ_LONG( R_ECX, R_EAX );
nkeynes@359
  1905
                                store_spreg( R_EAX, R_PR );
nkeynes@417
  1906
                                sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1907
                                }
nkeynes@359
  1908
                                break;
nkeynes@359
  1909
                            case 0x3:
nkeynes@359
  1910
                                { /* LDC.L @Rm+, SGR */
nkeynes@359
  1911
                                uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@416
  1912
                                precheck();
nkeynes@416
  1913
                                check_priv_no_precheck();
nkeynes@359
  1914
                                load_reg( R_EAX, Rm );
nkeynes@395
  1915
                                check_ralign32( R_EAX );
nkeynes@359
  1916
                                MOV_r32_r32( R_EAX, R_ECX );
nkeynes@359
  1917
                                ADD_imm8s_r32( 4, R_EAX );
nkeynes@359
  1918
                                store_reg( R_EAX, Rm );
nkeynes@359
  1919
                                MEM_READ_LONG( R_ECX, R_EAX );
nkeynes@359
  1920
                                store_spreg( R_EAX, R_SGR );
nkeynes@417
  1921
                                sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1922
                                }
nkeynes@359
  1923
                                break;
nkeynes@359
  1924
                            case 0x5:
nkeynes@359
  1925
                                { /* LDS.L @Rm+, FPUL */
nkeynes@359
  1926
                                uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  1927
                                load_reg( R_EAX, Rm );
nkeynes@416
  1928
                                precheck();
nkeynes@395
  1929
                                check_ralign32( R_EAX );
nkeynes@359
  1930
                                MOV_r32_r32( R_EAX, R_ECX );
nkeynes@359
  1931
                                ADD_imm8s_r32( 4, R_EAX );
nkeynes@359
  1932
                                store_reg( R_EAX, Rm );
nkeynes@359
  1933
                                MEM_READ_LONG( R_ECX, R_EAX );
nkeynes@359
  1934
                                store_spreg( R_EAX, R_FPUL );
nkeynes@417
  1935
                                sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1936
                                }
nkeynes@359
  1937
                                break;
nkeynes@359
  1938
                            case 0x6:
nkeynes@359
  1939
                                { /* LDS.L @Rm+, FPSCR */
nkeynes@359
  1940
                                uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  1941
                                load_reg( R_EAX, Rm );
nkeynes@416
  1942
                                precheck();
nkeynes@395
  1943
                                check_ralign32( R_EAX );
nkeynes@359
  1944
                                MOV_r32_r32( R_EAX, R_ECX );
nkeynes@359
  1945
                                ADD_imm8s_r32( 4, R_EAX );
nkeynes@359
  1946
                                store_reg( R_EAX, Rm );
nkeynes@359
  1947
                                MEM_READ_LONG( R_ECX, R_EAX );
nkeynes@359
  1948
                                store_spreg( R_EAX, R_FPSCR );
nkeynes@386
  1949
                                update_fr_bank( R_EAX );
nkeynes@417
  1950
                                sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1951
                                }
nkeynes@359
  1952
                                break;
nkeynes@359
  1953
                            case 0xF:
nkeynes@359
  1954
                                { /* LDC.L @Rm+, DBR */
nkeynes@359
  1955
                                uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@416
  1956
                                precheck();
nkeynes@416
  1957
                                check_priv_no_precheck();
nkeynes@359
  1958
                                load_reg( R_EAX, Rm );
nkeynes@395
  1959
                                check_ralign32( R_EAX );
nkeynes@359
  1960
                                MOV_r32_r32( R_EAX, R_ECX );
nkeynes@359
  1961
                                ADD_imm8s_r32( 4, R_EAX );
nkeynes@359
  1962
                                store_reg( R_EAX, Rm );
nkeynes@359
  1963
                                MEM_READ_LONG( R_ECX, R_EAX );
nkeynes@359
  1964
                                store_spreg( R_EAX, R_DBR );
nkeynes@417
  1965
                                sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1966
                                }
nkeynes@359
  1967
                                break;
nkeynes@359
  1968
                            default:
nkeynes@359
  1969
                                UNDEF();
nkeynes@359
  1970
                                break;
nkeynes@359
  1971
                        }
nkeynes@359
  1972
                        break;
nkeynes@359
  1973
                    case 0x7:
nkeynes@359
  1974
                        switch( (ir&0x80) >> 7 ) {
nkeynes@359
  1975
                            case 0x0:
nkeynes@359
  1976
                                switch( (ir&0x70) >> 4 ) {
nkeynes@359
  1977
                                    case 0x0:
nkeynes@359
  1978
                                        { /* LDC.L @Rm+, SR */
nkeynes@359
  1979
                                        uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@386
  1980
                                        if( sh4_x86.in_delay_slot ) {
nkeynes@386
  1981
                                    	SLOTILLEGAL();
nkeynes@386
  1982
                                        } else {
nkeynes@416
  1983
                                    	precheck();
nkeynes@416
  1984
                                    	check_priv_no_precheck();
nkeynes@386
  1985
                                    	load_reg( R_EAX, Rm );
nkeynes@395
  1986
                                    	check_ralign32( R_EAX );
nkeynes@386
  1987
                                    	MOV_r32_r32( R_EAX, R_ECX );
nkeynes@386
  1988
                                    	ADD_imm8s_r32( 4, R_EAX );
nkeynes@386
  1989
                                    	store_reg( R_EAX, Rm );
nkeynes@386
  1990
                                    	MEM_READ_LONG( R_ECX, R_EAX );
nkeynes@386
  1991
                                    	call_func1( sh4_write_sr, R_EAX );
nkeynes@386
  1992
                                    	sh4_x86.priv_checked = FALSE;
nkeynes@386
  1993
                                    	sh4_x86.fpuen_checked = FALSE;
nkeynes@417
  1994
                                    	sh4_x86.tstate = TSTATE_NONE;
nkeynes@386
  1995
                                        }
nkeynes@359
  1996
                                        }
nkeynes@359
  1997
                                        break;
nkeynes@359
  1998
                                    case 0x1:
nkeynes@359
  1999
                                        { /* LDC.L @Rm+, GBR */
nkeynes@359
  2000
                                        uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  2001
                                        load_reg( R_EAX, Rm );
nkeynes@416
  2002
                                        precheck();
nkeynes@395
  2003
                                        check_ralign32( R_EAX );
nkeynes@359
  2004
                                        MOV_r32_r32( R_EAX, R_ECX );
nkeynes@359
  2005
                                        ADD_imm8s_r32( 4, R_EAX );
nkeynes@359
  2006
                                        store_reg( R_EAX, Rm );
nkeynes@359
  2007
                                        MEM_READ_LONG( R_ECX, R_EAX );
nkeynes@359
  2008
                                        store_spreg( R_EAX, R_GBR );
nkeynes@417
  2009
                                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  2010
                                        }
nkeynes@359
  2011
                                        break;
nkeynes@359
  2012
                                    case 0x2:
nkeynes@359
  2013
                                        { /* LDC.L @Rm+, VBR */
nkeynes@359
  2014
                                        uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@416
  2015
                                        precheck();
nkeynes@416
  2016
                                        check_priv_no_precheck();
nkeynes@359
  2017
                                        load_reg( R_EAX, Rm );
nkeynes@395
  2018
                                        check_ralign32( R_EAX );
nkeynes@359
  2019
                                        MOV_r32_r32( R_EAX, R_ECX );
nkeynes@359
  2020
                                        ADD_imm8s_r32( 4, R_EAX );
nkeynes@359
  2021
                                        store_reg( R_EAX, Rm );
nkeynes@359
  2022
                                        MEM_READ_LONG( R_ECX, R_EAX );
nkeynes@359
  2023
                                        store_spreg( R_EAX, R_VBR );
nkeynes@417
  2024
                                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  2025
                                        }
nkeynes@359
  2026
                                        break;
nkeynes@359
  2027
                                    case 0x3:
nkeynes@359
  2028
                                        { /* LDC.L @Rm+, SSR */
nkeynes@359
  2029
                                        uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@416
  2030
                                        precheck();
nkeynes@416
  2031
                                        check_priv_no_precheck();
nkeynes@359
  2032
                                        load_reg( R_EAX, Rm );
nkeynes@416
  2033
                                        check_ralign32( R_EAX );
nkeynes@359
  2034
                                        MOV_r32_r32( R_EAX, R_ECX );
nkeynes@359
  2035
                                        ADD_imm8s_r32( 4, R_EAX );
nkeynes@359
  2036
                                        store_reg( R_EAX, Rm );
nkeynes@359
  2037
                                        MEM_READ_LONG( R_ECX, R_EAX );
nkeynes@359
  2038
                                        store_spreg( R_EAX, R_SSR );
nkeynes@417
  2039
                                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  2040
                                        }
nkeynes@359
  2041
                                        break;
nkeynes@359
  2042
                                    case 0x4:
nkeynes@359
  2043
                                        { /* LDC.L @Rm+, SPC */
nkeynes@359
  2044
                                        uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@416
  2045
                                        precheck();
nkeynes@416
  2046
                                        check_priv_no_precheck();
nkeynes@359
  2047
                                        load_reg( R_EAX, Rm );
nkeynes@395
  2048
                                        check_ralign32( R_EAX );
nkeynes@359
  2049
                                        MOV_r32_r32( R_EAX, R_ECX );
nkeynes@359
  2050
                                        ADD_imm8s_r32( 4, R_EAX );
nkeynes@359
  2051
                                        store_reg( R_EAX, Rm );
nkeynes@359
  2052
                                        MEM_READ_LONG( R_ECX, R_EAX );
nkeynes@359
  2053
                                        store_spreg( R_EAX, R_SPC );
nkeynes@417
  2054
                                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  2055
                                        }
nkeynes@359
  2056
                                        break;
nkeynes@359
  2057
                                    default:
nkeynes@359
  2058
                                        UNDEF();
nkeynes@359
  2059
                                        break;
nkeynes@359
  2060
                                }
nkeynes@359
  2061
                                break;
nkeynes@359
  2062
                            case 0x1:
nkeynes@359
  2063
                                { /* LDC.L @Rm+, Rn_BANK */
nkeynes@359
  2064
                                uint32_t Rm = ((ir>>8)&0xF); uint32_t Rn_BANK = ((ir>>4)&0x7); 
nkeynes@416
  2065
                                precheck();
nkeynes@416
  2066
                                check_priv_no_precheck();
nkeynes@374
  2067
                                load_reg( R_EAX, Rm );
nkeynes@395
  2068
                                check_ralign32( R_EAX );
nkeynes@374
  2069
                                MOV_r32_r32( R_EAX, R_ECX );
nkeynes@374
  2070
                                ADD_imm8s_r32( 4, R_EAX );
nkeynes@374
  2071
                                store_reg( R_EAX, Rm );
nkeynes@374
  2072
                                MEM_READ_LONG( R_ECX, R_EAX );
nkeynes@374
  2073
                                store_spreg( R_EAX, REG_OFFSET(r_bank[Rn_BANK]) );
nkeynes@417
  2074
                                sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  2075
                                }
nkeynes@359
  2076
                                break;
nkeynes@359
  2077
                        }
nkeynes@359
  2078
                        break;
nkeynes@359
  2079
                    case 0x8:
nkeynes@359
  2080
                        switch( (ir&0xF0) >> 4 ) {
nkeynes@359
  2081
                            case 0x0:
nkeynes@359
  2082
                                { /* SHLL2 Rn */
nkeynes@359
  2083
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  2084
                                load_reg( R_EAX, Rn );
nkeynes@359
  2085
                                SHL_imm8_r32( 2, R_EAX );
nkeynes@359
  2086
                                store_reg( R_EAX, Rn );
nkeynes@417
  2087
                                sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  2088
                                }
nkeynes@359
  2089
                                break;
nkeynes@359
  2090
                            case 0x1:
nkeynes@359
  2091
                                { /* SHLL8 Rn */
nkeynes@359
  2092
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  2093
                                load_reg( R_EAX, Rn );
nkeynes@359
  2094
                                SHL_imm8_r32( 8, R_EAX );
nkeynes@359
  2095
                                store_reg( R_EAX, Rn );
nkeynes@417
  2096
                                sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  2097
                                }
nkeynes@359
  2098
                                break;
nkeynes@359
  2099
                            case 0x2:
nkeynes@359
  2100
                                { /* SHLL16 Rn */
nkeynes@359
  2101
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  2102
                                load_reg( R_EAX, Rn );
nkeynes@359
  2103
                                SHL_imm8_r32( 16, R_EAX );
nkeynes@359
  2104
                                store_reg( R_EAX, Rn );
nkeynes@417
  2105
                                sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  2106
                                }
nkeynes@359
  2107
                                break;
nkeynes@359
  2108
                            default:
nkeynes@359
  2109
                                UNDEF();
nkeynes@359
  2110
                                break;
nkeynes@359
  2111
                        }
nkeynes@359
  2112
                        break;
nkeynes@359
  2113
                    case 0x9:
nkeynes@359
  2114
                        switch( (ir&0xF0) >> 4 ) {
nkeynes@359
  2115
                            case 0x0:
nkeynes@359
  2116
                                { /* SHLR2 Rn */
nkeynes@359
  2117
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  2118
                                load_reg( R_EAX, Rn );
nkeynes@359
  2119
                                SHR_imm8_r32( 2, R_EAX );
nkeynes@359
  2120
                                store_reg( R_EAX, Rn );
nkeynes@417
  2121
                                sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  2122
                                }
nkeynes@359
  2123
                                break;
nkeynes@359
  2124
                            case 0x1:
nkeynes@359
  2125
                                { /* SHLR8 Rn */
nkeynes@359
  2126
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  2127
                                load_reg( R_EAX, Rn );
nkeynes@359
  2128
                                SHR_imm8_r32( 8, R_EAX );
nkeynes@359
  2129
                                store_reg( R_EAX, Rn );
nkeynes@417
  2130
                                sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  2131
                                }
nkeynes@359
  2132
                                break;
nkeynes@359
  2133
                            case 0x2:
nkeynes@359
  2134
                                { /* SHLR16 Rn */
nkeynes@359
  2135
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  2136
                                load_reg( R_EAX, Rn );
nkeynes@359
  2137
                                SHR_imm8_r32( 16, R_EAX );
nkeynes@359
  2138
                                store_reg( R_EAX, Rn );
nkeynes@417
  2139
                                sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  2140
                                }
nkeynes@359
  2141
                                break;
nkeynes@359
  2142
                            default:
nkeynes@359
  2143
                                UNDEF();
nkeynes@359
  2144
                                break;
nkeynes@359
  2145
                        }
nkeynes@359
  2146
                        break;
nkeynes@359
  2147
                    case 0xA:
nkeynes@359
  2148
                        switch( (ir&0xF0) >> 4 ) {
nkeynes@359
  2149
                            case 0x0:
nkeynes@359
  2150
                                { /* LDS Rm, MACH */
nkeynes@359
  2151
                                uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  2152
                                load_reg( R_EAX, Rm );
nkeynes@359
  2153
                                store_spreg( R_EAX, R_MACH );
nkeynes@359
  2154
                                }
nkeynes@359
  2155
                                break;
nkeynes@359
  2156
                            case 0x1:
nkeynes@359
  2157
                                { /* LDS Rm, MACL */
nkeynes@359
  2158
                                uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  2159
                                load_reg( R_EAX, Rm );
nkeynes@359
  2160
                                store_spreg( R_EAX, R_MACL );
nkeynes@359
  2161
                                }
nkeynes@359
  2162
                                break;
nkeynes@359
  2163
                            case 0x2:
nkeynes@359
  2164
                                { /* LDS Rm, PR */
nkeynes@359
  2165
                                uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  2166
                                load_reg( R_EAX, Rm );
nkeynes@359
  2167
                                store_spreg( R_EAX, R_PR );
nkeynes@359
  2168
                                }
nkeynes@359
  2169
                                break;
nkeynes@359
  2170
                            case 0x3:
nkeynes@359
  2171
                                { /* LDC Rm, SGR */
nkeynes@359
  2172
                                uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@386
  2173
                                check_priv();
nkeynes@359
  2174
                                load_reg( R_EAX, Rm );
nkeynes@359
  2175
                                store_spreg( R_EAX, R_SGR );
nkeynes@417
  2176
                                sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  2177
                                }
nkeynes@359
  2178
                                break;
nkeynes@359
  2179
                            case 0x5:
nkeynes@359
  2180
                                { /* LDS Rm, FPUL */
nkeynes@359
  2181
                                uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  2182
                                load_reg( R_EAX, Rm );
nkeynes@359
  2183
                                store_spreg( R_EAX, R_FPUL );
nkeynes@359
  2184
                                }
nkeynes@359
  2185
                                break;
nkeynes@359
  2186
                            case 0x6:
nkeynes@359
  2187
                                { /* LDS Rm, FPSCR */
nkeynes@359
  2188
                                uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  2189
                                load_reg( R_EAX, Rm );
nkeynes@359
  2190
                                store_spreg( R_EAX, R_FPSCR );
nkeynes@386
  2191
                                update_fr_bank( R_EAX );
nkeynes@417
  2192
                                sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  2193
                                }
nkeynes@359
  2194
                                break;
nkeynes@359
  2195
                            case 0xF:
nkeynes@359
  2196
                                { /* LDC Rm, DBR */
nkeynes@359
  2197
                                uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@386
  2198
                                check_priv();
nkeynes@359
  2199
                                load_reg( R_EAX, Rm );
nkeynes@359
  2200
                                store_spreg( R_EAX, R_DBR );
nkeynes@417
  2201
                                sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  2202
                                }
nkeynes@359
  2203
                                break;
nkeynes@359
  2204
                            default:
nkeynes@359
  2205
                                UNDEF();
nkeynes@359
  2206
                                break;
nkeynes@359
  2207
                        }
nkeynes@359
  2208
                        break;
nkeynes@359
  2209
                    case 0xB:
nkeynes@359
  2210
                        switch( (ir&0xF0) >> 4 ) {
nkeynes@359
  2211
                            case 0x0:
nkeynes@359
  2212
                                { /* JSR @Rn */
nkeynes@359
  2213
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@374
  2214
                                if( sh4_x86.in_delay_slot ) {
nkeynes@374
  2215
                            	SLOTILLEGAL();
nkeynes@374
  2216
                                } else {
nkeynes@374
  2217
                            	load_imm32( R_EAX, pc + 4 );
nkeynes@374
  2218
                            	store_spreg( R_EAX, R_PR );
nkeynes@408
  2219
                            	load_reg( R_ECX, Rn );
nkeynes@408
  2220
                            	store_spreg( R_ECX, REG_OFFSET(pc) );
nkeynes@374
  2221
                            	sh4_x86.in_delay_slot = TRUE;
nkeynes@526
  2222
                            	sh4_translate_instruction(pc+2);
nkeynes@408
  2223
                            	exit_block_pcset(pc+2);
nkeynes@409
  2224
                            	sh4_x86.branch_taken = TRUE;
nkeynes@408
  2225
                            	return 4;
nkeynes@374
  2226
                                }
nkeynes@359
  2227
                                }
nkeynes@359
  2228
                                break;
nkeynes@359
  2229
                            case 0x1:
nkeynes@359
  2230
                                { /* TAS.B @Rn */
nkeynes@359
  2231
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@361
  2232
                                load_reg( R_ECX, Rn );
nkeynes@361
  2233
                                MEM_READ_BYTE( R_ECX, R_EAX );
nkeynes@361
  2234
                                TEST_r8_r8( R_AL, R_AL );
nkeynes@361
  2235
                                SETE_t();
nkeynes@361
  2236
                                OR_imm8_r8( 0x80, R_AL );
nkeynes@386
  2237
                                load_reg( R_ECX, Rn );
nkeynes@361
  2238
                                MEM_WRITE_BYTE( R_ECX, R_EAX );
nkeynes@417
  2239
                                sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  2240
                                }
nkeynes@359
  2241
                                break;
nkeynes@359
  2242
                            case 0x2:
nkeynes@359
  2243
                                { /* JMP @Rn */
nkeynes@359
  2244
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@374
  2245
                                if( sh4_x86.in_delay_slot ) {
nkeynes@374
  2246
                            	SLOTILLEGAL();
nkeynes@374
  2247
                                } else {
nkeynes@408
  2248
                            	load_reg( R_ECX, Rn );
nkeynes@408
  2249
                            	store_spreg( R_ECX, REG_OFFSET(pc) );
nkeynes@374
  2250
                            	sh4_x86.in_delay_slot = TRUE;
nkeynes@526
  2251
                            	sh4_translate_instruction(pc+2);
nkeynes@408
  2252
                            	exit_block_pcset(pc+2);
nkeynes@409
  2253
                            	sh4_x86.branch_taken = TRUE;
nkeynes@408
  2254
                            	return 4;
nkeynes@374
  2255
                                }
nkeynes@359
  2256
                                }
nkeynes@359
  2257
                                break;
nkeynes@359
  2258
                            default:
nkeynes@359
  2259
                                UNDEF();
nkeynes@359
  2260
                                break;
nkeynes@359
  2261
                        }
nkeynes@359
  2262
                        break;
nkeynes@359
  2263
                    case 0xC:
nkeynes@359
  2264
                        { /* SHAD Rm, Rn */
nkeynes@359
  2265
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  2266
                        /* Annoyingly enough, not directly convertible */
nkeynes@361
  2267
                        load_reg( R_EAX, Rn );
nkeynes@361
  2268
                        load_reg( R_ECX, Rm );
nkeynes@361
  2269
                        CMP_imm32_r32( 0, R_ECX );
nkeynes@386
  2270
                        JGE_rel8(16, doshl);
nkeynes@361
  2271
                                        
nkeynes@361
  2272
                        NEG_r32( R_ECX );      // 2
nkeynes@361
  2273
                        AND_imm8_r8( 0x1F, R_CL ); // 3
nkeynes@386
  2274
                        JE_rel8( 4, emptysar);     // 2
nkeynes@361
  2275
                        SAR_r32_CL( R_EAX );       // 2
nkeynes@386
  2276
                        JMP_rel8(10, end);          // 2
nkeynes@386
  2277
                    
nkeynes@386
  2278
                        JMP_TARGET(emptysar);
nkeynes@386
  2279
                        SAR_imm8_r32(31, R_EAX );  // 3
nkeynes@386
  2280
                        JMP_rel8(5, end2);
nkeynes@386
  2281
                    
nkeynes@380
  2282
                        JMP_TARGET(doshl);
nkeynes@361
  2283
                        AND_imm8_r8( 0x1F, R_CL ); // 3
nkeynes@361
  2284
                        SHL_r32_CL( R_EAX );       // 2
nkeynes@380
  2285
                        JMP_TARGET(end);
nkeynes@386
  2286
                        JMP_TARGET(end2);
nkeynes@361
  2287
                        store_reg( R_EAX, Rn );
nkeynes@417
  2288
                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  2289
                        }
nkeynes@359
  2290
                        break;
nkeynes@359
  2291
                    case 0xD:
nkeynes@359
  2292
                        { /* SHLD Rm, Rn */
nkeynes@359
  2293
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@368
  2294
                        load_reg( R_EAX, Rn );
nkeynes@368
  2295
                        load_reg( R_ECX, Rm );
nkeynes@386
  2296
                        CMP_imm32_r32( 0, R_ECX );
nkeynes@386
  2297
                        JGE_rel8(15, doshl);
nkeynes@368
  2298
                    
nkeynes@386
  2299
                        NEG_r32( R_ECX );      // 2
nkeynes@386
  2300
                        AND_imm8_r8( 0x1F, R_CL ); // 3
nkeynes@386
  2301
                        JE_rel8( 4, emptyshr );
nkeynes@386
  2302
                        SHR_r32_CL( R_EAX );       // 2
nkeynes@386
  2303
                        JMP_rel8(9, end);          // 2
nkeynes@386
  2304
                    
nkeynes@386
  2305
                        JMP_TARGET(emptyshr);
nkeynes@386
  2306
                        XOR_r32_r32( R_EAX, R_EAX );
nkeynes@386
  2307
                        JMP_rel8(5, end2);
nkeynes@386
  2308
                    
nkeynes@386
  2309
                        JMP_TARGET(doshl);
nkeynes@386
  2310
                        AND_imm8_r8( 0x1F, R_CL ); // 3
nkeynes@386
  2311
                        SHL_r32_CL( R_EAX );       // 2
nkeynes@386
  2312
                        JMP_TARGET(end);
nkeynes@386
  2313
                        JMP_TARGET(end2);
nkeynes@368
  2314
                        store_reg( R_EAX, Rn );
nkeynes@417
  2315
                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  2316
                        }
nkeynes@359
  2317
                        break;
nkeynes@359
  2318
                    case 0xE:
nkeynes@359
  2319
                        switch( (ir&0x80) >> 7 ) {
nkeynes@359
  2320
                            case 0x0:
nkeynes@359
  2321
                                switch( (ir&0x70) >> 4 ) {
nkeynes@359
  2322
                                    case 0x0:
nkeynes@359
  2323
                                        { /* LDC Rm, SR */
nkeynes@359
  2324
                                        uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@386
  2325
                                        if( sh4_x86.in_delay_slot ) {
nkeynes@386
  2326
                                    	SLOTILLEGAL();
nkeynes@386
  2327
                                        } else {
nkeynes@386
  2328
                                    	check_priv();
nkeynes@386
  2329
                                    	load_reg( R_EAX, Rm );
nkeynes@386
  2330
                                    	call_func1( sh4_write_sr, R_EAX );
nkeynes@386
  2331
                                    	sh4_x86.priv_checked = FALSE;
nkeynes@386
  2332
                                    	sh4_x86.fpuen_checked = FALSE;
nkeynes@417
  2333
                                    	sh4_x86.tstate = TSTATE_NONE;
nkeynes@386
  2334
                                        }
nkeynes@359
  2335
                                        }
nkeynes@359
  2336
                                        break;
nkeynes@359
  2337
                                    case 0x1:
nkeynes@359
  2338
                                        { /* LDC Rm, GBR */
nkeynes@359
  2339
                                        uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  2340
                                        load_reg( R_EAX, Rm );
nkeynes@359
  2341
                                        store_spreg( R_EAX, R_GBR );
nkeynes@359
  2342
                                        }
nkeynes@359
  2343
                                        break;
nkeynes@359
  2344
                                    case 0x2:
nkeynes@359
  2345
                                        { /* LDC Rm, VBR */
nkeynes@359
  2346
                                        uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@386
  2347
                                        check_priv();
nkeynes@359
  2348
                                        load_reg( R_EAX, Rm );
nkeynes@359
  2349
                                        store_spreg( R_EAX, R_VBR );
nkeynes@417
  2350
                                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  2351
                                        }
nkeynes@359
  2352
                                        break;
nkeynes@359
  2353
                                    case 0x3:
nkeynes@359
  2354
                                        { /* LDC Rm, SSR */
nkeynes@359
  2355
                                        uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@386
  2356
                                        check_priv();
nkeynes@359
  2357
                                        load_reg( R_EAX, Rm );
nkeynes@359
  2358
                                        store_spreg( R_EAX, R_SSR );
nkeynes@417
  2359
                                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  2360
                                        }
nkeynes@359
  2361
                                        break;
nkeynes@359
  2362
                                    case 0x4:
nkeynes@359
  2363
                                        { /* LDC Rm, SPC */
nkeynes@359
  2364
                                        uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@386
  2365
                                        check_priv();
nkeynes@359
  2366
                                        load_reg( R_EAX, Rm );
nkeynes@359
  2367
                                        store_spreg( R_EAX, R_SPC );
nkeynes@417
  2368
                                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  2369
                                        }
nkeynes@359
  2370
                                        break;
nkeynes@359
  2371
                                    default:
nkeynes@359
  2372
                                        UNDEF();
nkeynes@359
  2373
                                        break;
nkeynes@359
  2374
                                }
nkeynes@359
  2375
                                break;
nkeynes@359
  2376
                            case 0x1:
nkeynes@359
  2377
                                { /* LDC Rm, Rn_BANK */
nkeynes@359
  2378
                                uint32_t Rm = ((ir>>8)&0xF); uint32_t Rn_BANK = ((ir>>4)&0x7); 
nkeynes@386
  2379
                                check_priv();
nkeynes@374
  2380
                                load_reg( R_EAX, Rm );
nkeynes@374
  2381
                                store_spreg( R_EAX, REG_OFFSET(r_bank[Rn_BANK]) );
nkeynes@417
  2382
                                sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  2383
                                }
nkeynes@359
  2384
                                break;
nkeynes@359
  2385
                        }
nkeynes@359
  2386
                        break;
nkeynes@359
  2387
                    case 0xF:
nkeynes@359
  2388
                        { /* MAC.W @Rm+, @Rn+ */
nkeynes@359
  2389
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@386
  2390
                        load_reg( R_ECX, Rm );
nkeynes@416
  2391
                        precheck();
nkeynes@386
  2392
                        check_ralign16( R_ECX );
nkeynes@386
  2393
                        load_reg( R_ECX, Rn );
nkeynes@386
  2394
                        check_ralign16( R_ECX );
nkeynes@386
  2395
                        ADD_imm8s_sh4r( 2, REG_OFFSET(r[Rn]) );
nkeynes@386
  2396
                        MEM_READ_WORD( R_ECX, R_EAX );
nkeynes@386
  2397
                        PUSH_r32( R_EAX );
nkeynes@386
  2398
                        load_reg( R_ECX, Rm );
nkeynes@386
  2399
                        ADD_imm8s_sh4r( 2, REG_OFFSET(r[Rm]) );
nkeynes@386
  2400
                        MEM_READ_WORD( R_ECX, R_EAX );
nkeynes@386
  2401
                        POP_r32( R_ECX );
nkeynes@386
  2402
                        IMUL_r32( R_ECX );
nkeynes@386
  2403
                    
nkeynes@386
  2404
                        load_spreg( R_ECX, R_S );
nkeynes@386
  2405
                        TEST_r32_r32( R_ECX, R_ECX );
nkeynes@386
  2406
                        JE_rel8( 47, nosat );
nkeynes@386
  2407
                    
nkeynes@386
  2408
                        ADD_r32_sh4r( R_EAX, R_MACL );  // 6
nkeynes@386
  2409
                        JNO_rel8( 51, end );            // 2
nkeynes@386
  2410
                        load_imm32( R_EDX, 1 );         // 5
nkeynes@386
  2411
                        store_spreg( R_EDX, R_MACH );   // 6
nkeynes@386
  2412
                        JS_rel8( 13, positive );        // 2
nkeynes@386
  2413
                        load_imm32( R_EAX, 0x80000000 );// 5
nkeynes@386
  2414
                        store_spreg( R_EAX, R_MACL );   // 6
nkeynes@386
  2415
                        JMP_rel8( 25, end2 );           // 2
nkeynes@386
  2416
                    
nkeynes@386
  2417
                        JMP_TARGET(positive);
nkeynes@386
  2418
                        load_imm32( R_EAX, 0x7FFFFFFF );// 5
nkeynes@386
  2419
                        store_spreg( R_EAX, R_MACL );   // 6
nkeynes@386
  2420
                        JMP_rel8( 12, end3);            // 2
nkeynes@386
  2421
                    
nkeynes@386
  2422
                        JMP_TARGET(nosat);
nkeynes@386
  2423
                        ADD_r32_sh4r( R_EAX, R_MACL );  // 6
nkeynes@386
  2424
                        ADC_r32_sh4r( R_EDX, R_MACH );  // 6
nkeynes@386
  2425
                        JMP_TARGET(end);
nkeynes@386
  2426
                        JMP_TARGET(end2);
nkeynes@386
  2427
                        JMP_TARGET(end3);
nkeynes@417
  2428
                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  2429
                        }
nkeynes@359
  2430
                        break;
nkeynes@359
  2431
                }
nkeynes@359
  2432
                break;
nkeynes@359
  2433
            case 0x5:
nkeynes@359
  2434
                { /* MOV.L @(disp, Rm), Rn */
nkeynes@359
  2435
                uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); uint32_t disp = (ir&0xF)<<2; 
nkeynes@361
  2436
                load_reg( R_ECX, Rm );
nkeynes@361
  2437
                ADD_imm8s_r32( disp, R_ECX );
nkeynes@416
  2438
                precheck();
nkeynes@374
  2439
                check_ralign32( R_ECX );
nkeynes@361
  2440
                MEM_READ_LONG( R_ECX, R_EAX );
nkeynes@361
  2441
                store_reg( R_EAX, Rn );
nkeynes@417
  2442
                sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  2443
                }
nkeynes@359
  2444
                break;
nkeynes@359
  2445
            case 0x6:
nkeynes@359
  2446
                switch( ir&0xF ) {
nkeynes@359
  2447
                    case 0x0:
nkeynes@359
  2448
                        { /* MOV.B @Rm, Rn */
nkeynes@359
  2449
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  2450
                        load_reg( R_ECX, Rm );
nkeynes@359
  2451
                        MEM_READ_BYTE( R_ECX, R_EAX );
nkeynes@386
  2452
                        store_reg( R_EAX, Rn );
nkeynes@417
  2453
                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  2454
                        }
nkeynes@359
  2455
                        break;
nkeynes@359
  2456
                    case 0x1:
nkeynes@359
  2457
                        { /* MOV.W @Rm, Rn */
nkeynes@359
  2458
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@361
  2459
                        load_reg( R_ECX, Rm );
nkeynes@416
  2460
                        precheck();
nkeynes@374
  2461
                        check_ralign16( R_ECX );
nkeynes@361
  2462
                        MEM_READ_WORD( R_ECX, R_EAX );
nkeynes@361
  2463
                        store_reg( R_EAX, Rn );
nkeynes@417
  2464
                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  2465
                        }
nkeynes@359
  2466
                        break;
nkeynes@359
  2467
                    case 0x2:
nkeynes@359
  2468
                        { /* MOV.L @Rm, Rn */
nkeynes@359
  2469
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@361
  2470
                        load_reg( R_ECX, Rm );
nkeynes@416
  2471
                        precheck();
nkeynes@374
  2472
                        check_ralign32( R_ECX );
nkeynes@361
  2473
                        MEM_READ_LONG( R_ECX, R_EAX );
nkeynes@361
  2474
                        store_reg( R_EAX, Rn );
nkeynes@417
  2475
                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  2476
                        }
nkeynes@359
  2477
                        break;
nkeynes@359
  2478
                    case 0x3:
nkeynes@359
  2479
                        { /* MOV Rm, Rn */
nkeynes@359
  2480
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  2481
                        load_reg( R_EAX, Rm );
nkeynes@359
  2482
                        store_reg( R_EAX, Rn );
nkeynes@359
  2483
                        }
nkeynes@359
  2484
                        break;
nkeynes@359
  2485
                    case 0x4:
nkeynes@359
  2486
                        { /* MOV.B @Rm+, Rn */
nkeynes@359
  2487
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  2488
                        load_reg( R_ECX, Rm );
nkeynes@359
  2489
                        MOV_r32_r32( R_ECX, R_EAX );
nkeynes@359
  2490
                        ADD_imm8s_r32( 1, R_EAX );
nkeynes@359
  2491
                        store_reg( R_EAX, Rm );
nkeynes@359
  2492
                        MEM_READ_BYTE( R_ECX, R_EAX );
nkeynes@359
  2493
                        store_reg( R_EAX, Rn );
nkeynes@417
  2494
                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  2495
                        }
nkeynes@359
  2496
                        break;
nkeynes@359
  2497
                    case 0x5:
nkeynes@359
  2498
                        { /* MOV.W @Rm+, Rn */
nkeynes@359
  2499
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@361
  2500
                        load_reg( R_EAX, Rm );
nkeynes@416
  2501
                        precheck();
nkeynes@374
  2502
                        check_ralign16( R_EAX );
nkeynes@361
  2503
                        MOV_r32_r32( R_EAX, R_ECX );
nkeynes@361
  2504
                        ADD_imm8s_r32( 2, R_EAX );
nkeynes@361
  2505
                        store_reg( R_EAX, Rm );
nkeynes@361
  2506
                        MEM_READ_WORD( R_ECX, R_EAX );
nkeynes@361
  2507
                        store_reg( R_EAX, Rn );
nkeynes@417
  2508
                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  2509
                        }
nkeynes@359
  2510
                        break;
nkeynes@359
  2511
                    case 0x6:
nkeynes@359
  2512
                        { /* MOV.L @Rm+, Rn */
nkeynes@359
  2513
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@361
  2514
                        load_reg( R_EAX, Rm );
nkeynes@416
  2515
                        precheck();
nkeynes@386
  2516
                        check_ralign32( R_EAX );
nkeynes@361
  2517
                        MOV_r32_r32( R_EAX, R_ECX );
nkeynes@361
  2518
                        ADD_imm8s_r32( 4, R_EAX );
nkeynes@361
  2519
                        store_reg( R_EAX, Rm );
nkeynes@361
  2520
                        MEM_READ_LONG( R_ECX, R_EAX );
nkeynes@361
  2521
                        store_reg( R_EAX, Rn );
nkeynes@417
  2522
                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  2523
                        }
nkeynes@359
  2524
                        break;
nkeynes@359
  2525
                    case 0x7:
nkeynes@359
  2526
                        { /* NOT Rm, Rn */
nkeynes@359
  2527
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  2528
                        load_reg( R_EAX, Rm );
nkeynes@359
  2529
                        NOT_r32( R_EAX );
nkeynes@359
  2530
                        store_reg( R_EAX, Rn );
nkeynes@417
  2531
                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  2532
                        }
nkeynes@359
  2533
                        break;
nkeynes@359
  2534
                    case 0x8:
nkeynes@359
  2535
                        { /* SWAP.B Rm, Rn */
nkeynes@359
  2536
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  2537
                        load_reg( R_EAX, Rm );
nkeynes@359
  2538
                        XCHG_r8_r8( R_AL, R_AH );
nkeynes@359
  2539
                        store_reg( R_EAX, Rn );
nkeynes@359
  2540
                        }
nkeynes@359
  2541
                        break;
nkeynes@359
  2542
                    case 0x9:
nkeynes@359
  2543
                        { /* SWAP.W Rm, Rn */
nkeynes@359
  2544
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  2545
                        load_reg( R_EAX, Rm );
nkeynes@359
  2546
                        MOV_r32_r32( R_EAX, R_ECX );
nkeynes@359
  2547
                        SHL_imm8_r32( 16, R_ECX );
nkeynes@359
  2548
                        SHR_imm8_r32( 16, R_EAX );
nkeynes@359
  2549
                        OR_r32_r32( R_EAX, R_ECX );
nkeynes@359
  2550
                        store_reg( R_ECX, Rn );
nkeynes@417
  2551
                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  2552
                        }
nkeynes@359
  2553
                        break;
nkeynes@359
  2554
                    case 0xA:
nkeynes@359
  2555
                        { /* NEGC Rm, Rn */
nkeynes@359
  2556
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  2557
                        load_reg( R_EAX, Rm );
nkeynes@359
  2558
                        XOR_r32_r32( R_ECX, R_ECX );
nkeynes@359
  2559
                        LDC_t();
nkeynes@359
  2560
                        SBB_r32_r32( R_EAX, R_ECX );
nkeynes@359
  2561
                        store_reg( R_ECX, Rn );
nkeynes@359
  2562
                        SETC_t();
nkeynes@417
  2563
                        sh4_x86.tstate = TSTATE_C;
nkeynes@359
  2564
                        }
nkeynes@359
  2565
                        break;
nkeynes@359
  2566
                    case 0xB:
nkeynes@359
  2567
                        { /* NEG Rm, Rn */
nkeynes@359
  2568
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  2569
                        load_reg( R_EAX, Rm );
nkeynes@359
  2570
                        NEG_r32( R_EAX );
nkeynes@359
  2571
                        store_reg( R_EAX, Rn );
nkeynes@417
  2572
                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  2573
                        }
nkeynes@359
  2574
                        break;
nkeynes@359
  2575
                    case 0xC:
nkeynes@359
  2576
                        { /* EXTU.B Rm, Rn */
nkeynes@359
  2577
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@361
  2578
                        load_reg( R_EAX, Rm );
nkeynes@361
  2579
                        MOVZX_r8_r32( R_EAX, R_EAX );
nkeynes@361
  2580
                        store_reg( R_EAX, Rn );
nkeynes@359
  2581
                        }
nkeynes@359
  2582
                        break;
nkeynes@359
  2583
                    case 0xD:
nkeynes@359
  2584
                        { /* EXTU.W Rm, Rn */
nkeynes@359
  2585
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@361
  2586
                        load_reg( R_EAX, Rm );
nkeynes@361
  2587
                        MOVZX_r16_r32( R_EAX, R_EAX );
nkeynes@361
  2588
                        store_reg( R_EAX, Rn );
nkeynes@359
  2589
                        }
nkeynes@359
  2590
                        break;
nkeynes@359
  2591
                    case 0xE:
nkeynes@359
  2592
                        { /* EXTS.B Rm, Rn */
nkeynes@359
  2593
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  2594
                        load_reg( R_EAX, Rm );
nkeynes@359
  2595
                        MOVSX_r8_r32( R_EAX, R_EAX );
nkeynes@359
  2596
                        store_reg( R_EAX, Rn );
nkeynes@359
  2597
                        }
nkeynes@359
  2598
                        break;
nkeynes@359
  2599
                    case 0xF:
nkeynes@359
  2600
                        { /* EXTS.W Rm, Rn */
nkeynes@359
  2601
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@361
  2602
                        load_reg( R_EAX, Rm );
nkeynes@361
  2603
                        MOVSX_r16_r32( R_EAX, R_EAX );
nkeynes@361
  2604
                        store_reg( R_EAX, Rn );
nkeynes@359
  2605
                        }
nkeynes@359
  2606
                        break;
nkeynes@359
  2607
                }
nkeynes@359
  2608
                break;
nkeynes@359
  2609
            case 0x7:
nkeynes@359
  2610
                { /* ADD #imm, Rn */
nkeynes@359
  2611
                uint32_t Rn = ((ir>>8)&0xF); int32_t imm = SIGNEXT8(ir&0xFF); 
nkeynes@359
  2612
                load_reg( R_EAX, Rn );
nkeynes@359
  2613
                ADD_imm8s_r32( imm, R_EAX );
nkeynes@359
  2614
                store_reg( R_EAX, Rn );
nkeynes@417
  2615
                sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  2616
                }
nkeynes@359
  2617
                break;
nkeynes@359
  2618
            case 0x8:
nkeynes@359
  2619
                switch( (ir&0xF00) >> 8 ) {
nkeynes@359
  2620
                    case 0x0:
nkeynes@359
  2621
                        { /* MOV.B R0, @(disp, Rn) */
nkeynes@359
  2622
                        uint32_t Rn = ((ir>>4)&0xF); uint32_t disp = (ir&0xF); 
nkeynes@359
  2623
                        load_reg( R_EAX, 0 );
nkeynes@359
  2624
                        load_reg( R_ECX, Rn );
nkeynes@359
  2625
                        ADD_imm32_r32( disp, R_ECX );
nkeynes@359
  2626
                        MEM_WRITE_BYTE( R_ECX, R_EAX );
nkeynes@417
  2627
                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  2628
                        }
nkeynes@359
  2629
                        break;
nkeynes@359
  2630
                    case 0x1:
nkeynes@359
  2631
                        { /* MOV.W R0, @(disp, Rn) */
nkeynes@359
  2632
                        uint32_t Rn = ((ir>>4)&0xF); uint32_t disp = (ir&0xF)<<1; 
nkeynes@361
  2633
                        load_reg( R_ECX, Rn );
nkeynes@361
  2634
                        load_reg( R_EAX, 0 );
nkeynes@361
  2635
                        ADD_imm32_r32( disp, R_ECX );
nkeynes@416
  2636
                        precheck();
nkeynes@374
  2637
                        check_walign16( R_ECX );
nkeynes@361
  2638
                        MEM_WRITE_WORD( R_ECX, R_EAX );
nkeynes@417
  2639
                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  2640
                        }
nkeynes@359
  2641
                        break;
nkeynes@359
  2642
                    case 0x4:
nkeynes@359
  2643
                        { /* MOV.B @(disp, Rm), R0 */
nkeynes@359
  2644
                        uint32_t Rm = ((ir>>4)&0xF); uint32_t disp = (ir&0xF); 
nkeynes@359
  2645
                        load_reg( R_ECX, Rm );
nkeynes@359
  2646
                        ADD_imm32_r32( disp, R_ECX );
nkeynes@359
  2647
                        MEM_READ_BYTE( R_ECX, R_EAX );
nkeynes@359
  2648
                        store_reg( R_EAX, 0 );
nkeynes@417
  2649
                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  2650
                        }
nkeynes@359
  2651
                        break;
nkeynes@359
  2652
                    case 0x5:
nkeynes@359
  2653
                        { /* MOV.W @(disp, Rm), R0 */
nkeynes@359
  2654
                        uint32_t Rm = ((ir>>4)&0xF); uint32_t disp = (ir&0xF)<<1; 
nkeynes@361
  2655
                        load_reg( R_ECX, Rm );
nkeynes@361
  2656
                        ADD_imm32_r32( disp, R_ECX );
nkeynes@416
  2657
                        precheck();
nkeynes@374
  2658
                        check_ralign16( R_ECX );
nkeynes@361
  2659
                        MEM_READ_WORD( R_ECX, R_EAX );
nkeynes@361
  2660
                        store_reg( R_EAX, 0 );
nkeynes@417
  2661
                        sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  2662
                        }
nkeynes@359
  2663
                        break;
nkeynes@359
  2664
                    case 0x8:
nkeynes@359
  2665
                        { /* CMP/EQ #imm, R0 */
nkeynes@359
  2666
                        int32_t imm = SIGNEXT8(ir&0xFF); 
nkeynes@359
  2667
                        load_reg( R_EAX, 0 );
nkeynes@359
  2668
                        CMP_imm8s_r32(imm, R_EAX);
nkeynes@359
  2669
                        SETE_t();
nkeynes@417
  2670
                        sh4_x86.tstate = TSTATE_E;
nkeynes@359
  2671
                        }
nkeynes@359
  2672
                        break;
nkeynes@359
  2673
                    case 0x9:
nkeynes@359
  2674
                        { /* BT disp */
nkeynes@359
  2675
                        int32_t disp = SIGNEXT8(ir&0xFF)<<1; 
nkeynes@374
  2676
                        if( sh4_x86.in_delay_slot ) {
nkeynes@374
  2677
                    	SLOTILLEGAL();
nkeynes@374
  2678
                        } else {
nkeynes@527
  2679
                    	JF_rel8( EXIT_BLOCK_SIZE, nottaken );
nkeynes@408
  2680
                    	exit_block( disp + pc + 4, pc+2 );
nkeynes@380
  2681
                    	JMP_TARGET(nottaken);
nkeynes@408
  2682
                    	return 2;
nkeynes@374
  2683
                        }
nkeynes@359
  2684
                        }
nkeynes@359
  2685
                        break;
nkeynes@359
  2686
                    case 0xB:
nkeynes@359
  2687
                        { /* BF disp */
nkeynes@359
  2688
                        int32_t disp = SIGNEXT8(ir&0xFF)<<1; 
nkeynes@374
  2689
                        if( sh4_x86.in_delay_slot ) {
nkeynes@374
  2690
                    	SLOTILLEGAL();
nkeynes@374
  2691
                        } else {
nkeynes@527
  2692
                    	JT_rel8( EXIT_BLOCK_SIZE, nottaken );
nkeynes@408
  2693
                    	exit_block( disp + pc + 4, pc+2 );
nkeynes@380
  2694
                    	JMP_TARGET(nottaken);
nkeynes@408
  2695
                    	return 2;
nkeynes@374
  2696
                        }
nkeynes@359
  2697
                        }
nkeynes@359
  2698
                        break;
nkeynes@359
  2699
                    case 0xD:
nkeynes@359
  2700
                        { /* BT/S disp */
nkeynes@359
  2701
                        int32_t disp = SIGNEXT8(ir&0xFF)<<1; 
nkeynes@374
  2702
                        if( sh4_x86.in_delay_slot ) {
nkeynes@374
  2703
                    	SLOTILLEGAL();
nkeynes@374
  2704
                        } else {
nkeynes@408
  2705
                    	sh4_x86.in_delay_slot = TRUE;
nkeynes@417
  2706
                    	if( sh4_x86.tstate == TSTATE_NONE ) {
nkeynes@417
  2707
                    	    CMP_imm8s_sh4r( 1, R_T );
nkeynes@417
  2708
                    	    sh4_x86.tstate = TSTATE_E;
nkeynes@417
  2709
                    	}
nkeynes@417
  2710
                    	OP(0x0F); OP(0x80+(sh4_x86.tstate^1)); uint32_t *patch = (uint32_t *)xlat_output; OP32(0); // JE rel32
nkeynes@526
  2711
                    	sh4_translate_instruction(pc+2);
nkeynes@408
  2712
                    	exit_block( disp + pc + 4, pc+4 );
nkeynes@408
  2713
                    	// not taken
nkeynes@408
  2714
                    	*patch = (xlat_output - ((uint8_t *)patch)) - 4;
nkeynes@526
  2715
                    	sh4_translate_instruction(pc+2);
nkeynes@408
  2716
                    	return 4;
nkeynes@374
  2717
                        }
nkeynes@359
  2718
                        }
nkeynes@359
  2719
                        break;
nkeynes@359
  2720
                    case 0xF:
nkeynes@359
  2721
                        { /* BF/S disp */
nkeynes@359
  2722
                        int32_t disp = SIGNEXT8(ir&0xFF)<<1;