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