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