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