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