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