Search
lxdream.org :: lxdream/src/sh4/sh4core.in
lxdream 0.9.1
released Jun 29
Download Now
filename src/sh4/sh4core.in
changeset 669:ab344e42bca9
prev641:afb9a42c61c6
next671:a530ea88eebd
author nkeynes
date Mon May 12 10:00:13 2008 +0000 (11 years ago)
permissions -rw-r--r--
last change Cleanup most of the -Wall warnings (getting a bit sloppy...)
Convert FP code to use fixed banks rather than indirect pointer
(3-4% faster this way now)
file annotate diff log raw
nkeynes@359
     1
/**
nkeynes@586
     2
 * $Id$
nkeynes@359
     3
 * 
nkeynes@359
     4
 * SH4 emulation core, and parent module for all the SH4 peripheral
nkeynes@359
     5
 * modules.
nkeynes@359
     6
 *
nkeynes@359
     7
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@359
     8
 *
nkeynes@359
     9
 * This program is free software; you can redistribute it and/or modify
nkeynes@359
    10
 * it under the terms of the GNU General Public License as published by
nkeynes@359
    11
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@359
    12
 * (at your option) any later version.
nkeynes@359
    13
 *
nkeynes@359
    14
 * This program is distributed in the hope that it will be useful,
nkeynes@359
    15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@359
    16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@359
    17
 * GNU General Public License for more details.
nkeynes@359
    18
 */
nkeynes@359
    19
nkeynes@359
    20
#define MODULE sh4_module
nkeynes@586
    21
#include <assert.h>
nkeynes@359
    22
#include <math.h>
nkeynes@359
    23
#include "dream.h"
nkeynes@430
    24
#include "dreamcast.h"
nkeynes@430
    25
#include "eventq.h"
nkeynes@430
    26
#include "mem.h"
nkeynes@430
    27
#include "clock.h"
nkeynes@430
    28
#include "syscall.h"
nkeynes@359
    29
#include "sh4/sh4core.h"
nkeynes@359
    30
#include "sh4/sh4mmio.h"
nkeynes@359
    31
#include "sh4/intc.h"
nkeynes@359
    32
nkeynes@359
    33
#define SH4_CALLTRACE 1
nkeynes@359
    34
nkeynes@359
    35
#define MAX_INT 0x7FFFFFFF
nkeynes@359
    36
#define MIN_INT 0x80000000
nkeynes@359
    37
#define MAX_INTF 2147483647.0
nkeynes@359
    38
#define MIN_INTF -2147483648.0
nkeynes@359
    39
nkeynes@359
    40
/********************** SH4 Module Definition ****************************/
nkeynes@359
    41
nkeynes@359
    42
uint32_t sh4_run_slice( uint32_t nanosecs ) 
nkeynes@359
    43
{
nkeynes@359
    44
    int i;
nkeynes@359
    45
    sh4r.slice_cycle = 0;
nkeynes@359
    46
nkeynes@359
    47
    if( sh4r.sh4_state != SH4_STATE_RUNNING ) {
nkeynes@617
    48
	sh4_sleep_run_slice(nanosecs);
nkeynes@359
    49
    }
nkeynes@359
    50
nkeynes@359
    51
    if( sh4_breakpoint_count == 0 ) {
nkeynes@359
    52
	for( ; sh4r.slice_cycle < nanosecs; sh4r.slice_cycle += sh4_cpu_period ) {
nkeynes@359
    53
	    if( SH4_EVENT_PENDING() ) {
nkeynes@359
    54
		if( sh4r.event_types & PENDING_EVENT ) {
nkeynes@359
    55
		    event_execute();
nkeynes@359
    56
		}
nkeynes@359
    57
		/* Eventq execute may (quite likely) deliver an immediate IRQ */
nkeynes@359
    58
		if( sh4r.event_types & PENDING_IRQ ) {
nkeynes@359
    59
		    sh4_accept_interrupt();
nkeynes@359
    60
		}
nkeynes@359
    61
	    }
nkeynes@359
    62
	    if( !sh4_execute_instruction() ) {
nkeynes@359
    63
		break;
nkeynes@359
    64
	    }
nkeynes@359
    65
	}
nkeynes@359
    66
    } else {
nkeynes@359
    67
	for( ;sh4r.slice_cycle < nanosecs; sh4r.slice_cycle += sh4_cpu_period ) {
nkeynes@359
    68
	    if( SH4_EVENT_PENDING() ) {
nkeynes@359
    69
		if( sh4r.event_types & PENDING_EVENT ) {
nkeynes@359
    70
		    event_execute();
nkeynes@359
    71
		}
nkeynes@359
    72
		/* Eventq execute may (quite likely) deliver an immediate IRQ */
nkeynes@359
    73
		if( sh4r.event_types & PENDING_IRQ ) {
nkeynes@359
    74
		    sh4_accept_interrupt();
nkeynes@359
    75
		}
nkeynes@359
    76
	    }
nkeynes@359
    77
                 
nkeynes@359
    78
	    if( !sh4_execute_instruction() )
nkeynes@359
    79
		break;
nkeynes@359
    80
#ifdef ENABLE_DEBUG_MODE
nkeynes@359
    81
	    for( i=0; i<sh4_breakpoint_count; i++ ) {
nkeynes@359
    82
		if( sh4_breakpoints[i].address == sh4r.pc ) {
nkeynes@359
    83
		    break;
nkeynes@359
    84
		}
nkeynes@359
    85
	    }
nkeynes@359
    86
	    if( i != sh4_breakpoint_count ) {
nkeynes@359
    87
		dreamcast_stop();
nkeynes@359
    88
		if( sh4_breakpoints[i].type == BREAK_ONESHOT )
nkeynes@359
    89
		    sh4_clear_breakpoint( sh4r.pc, BREAK_ONESHOT );
nkeynes@359
    90
		break;
nkeynes@359
    91
	    }
nkeynes@359
    92
#endif	
nkeynes@359
    93
	}
nkeynes@359
    94
    }
nkeynes@359
    95
nkeynes@359
    96
    /* If we aborted early, but the cpu is still technically running,
nkeynes@359
    97
     * we're doing a hard abort - cut the timeslice back to what we
nkeynes@359
    98
     * actually executed
nkeynes@359
    99
     */
nkeynes@359
   100
    if( sh4r.slice_cycle != nanosecs && sh4r.sh4_state == SH4_STATE_RUNNING ) {
nkeynes@359
   101
	nanosecs = sh4r.slice_cycle;
nkeynes@359
   102
    }
nkeynes@359
   103
    if( sh4r.sh4_state != SH4_STATE_STANDBY ) {
nkeynes@359
   104
	TMU_run_slice( nanosecs );
nkeynes@359
   105
	SCIF_run_slice( nanosecs );
nkeynes@359
   106
    }
nkeynes@359
   107
    return nanosecs;
nkeynes@359
   108
}
nkeynes@359
   109
nkeynes@359
   110
/********************** SH4 emulation core  ****************************/
nkeynes@359
   111
nkeynes@359
   112
#define UNDEF(ir) return sh4_raise_slot_exception(EXC_ILLEGAL, EXC_SLOT_ILLEGAL)
nkeynes@359
   113
#define UNIMP(ir) do{ ERROR( "Halted on unimplemented instruction at %08x, opcode = %04x", sh4r.pc, ir ); dreamcast_stop(); return FALSE; }while(0)
nkeynes@359
   114
nkeynes@359
   115
#if(SH4_CALLTRACE == 1)
nkeynes@359
   116
#define MAX_CALLSTACK 32
nkeynes@359
   117
static struct call_stack {
nkeynes@359
   118
    sh4addr_t call_addr;
nkeynes@359
   119
    sh4addr_t target_addr;
nkeynes@359
   120
    sh4addr_t stack_pointer;
nkeynes@359
   121
} call_stack[MAX_CALLSTACK];
nkeynes@359
   122
nkeynes@359
   123
static int call_stack_depth = 0;
nkeynes@359
   124
int sh4_call_trace_on = 0;
nkeynes@359
   125
nkeynes@430
   126
static inline void trace_call( sh4addr_t source, sh4addr_t dest ) 
nkeynes@359
   127
{
nkeynes@359
   128
    if( call_stack_depth < MAX_CALLSTACK ) {
nkeynes@359
   129
	call_stack[call_stack_depth].call_addr = source;
nkeynes@359
   130
	call_stack[call_stack_depth].target_addr = dest;
nkeynes@359
   131
	call_stack[call_stack_depth].stack_pointer = sh4r.r[15];
nkeynes@359
   132
    }
nkeynes@359
   133
    call_stack_depth++;
nkeynes@359
   134
}
nkeynes@359
   135
nkeynes@430
   136
static inline void trace_return( sh4addr_t source, sh4addr_t dest )
nkeynes@359
   137
{
nkeynes@359
   138
    if( call_stack_depth > 0 ) {
nkeynes@359
   139
	call_stack_depth--;
nkeynes@359
   140
    }
nkeynes@359
   141
}
nkeynes@359
   142
nkeynes@359
   143
void fprint_stack_trace( FILE *f )
nkeynes@359
   144
{
nkeynes@359
   145
    int i = call_stack_depth -1;
nkeynes@359
   146
    if( i >= MAX_CALLSTACK )
nkeynes@359
   147
	i = MAX_CALLSTACK - 1;
nkeynes@359
   148
    for( ; i >= 0; i-- ) {
nkeynes@359
   149
	fprintf( f, "%d. Call from %08X => %08X, SP=%08X\n", 
nkeynes@359
   150
		 (call_stack_depth - i), call_stack[i].call_addr,
nkeynes@359
   151
		 call_stack[i].target_addr, call_stack[i].stack_pointer );
nkeynes@359
   152
    }
nkeynes@359
   153
}
nkeynes@359
   154
nkeynes@359
   155
#define TRACE_CALL( source, dest ) trace_call(source, dest)
nkeynes@359
   156
#define TRACE_RETURN( source, dest ) trace_return(source, dest)
nkeynes@359
   157
#else
nkeynes@359
   158
#define TRACE_CALL( dest, rts ) 
nkeynes@359
   159
#define TRACE_RETURN( source, dest )
nkeynes@359
   160
#endif
nkeynes@359
   161
nkeynes@586
   162
#define MEM_READ_BYTE( addr, val ) memtmp = mmu_vma_to_phys_read(addr); if( memtmp == MMU_VMA_ERROR ) { return TRUE; } else { val = sh4_read_byte(memtmp); }
nkeynes@586
   163
#define MEM_READ_WORD( addr, val ) memtmp = mmu_vma_to_phys_read(addr); if( memtmp == MMU_VMA_ERROR ) { return TRUE; } else { val = sh4_read_word(memtmp); }
nkeynes@586
   164
#define MEM_READ_LONG( addr, val ) memtmp = mmu_vma_to_phys_read(addr); if( memtmp == MMU_VMA_ERROR ) { return TRUE; } else { val = sh4_read_long(memtmp); }
nkeynes@586
   165
#define MEM_WRITE_BYTE( addr, val ) memtmp = mmu_vma_to_phys_write(addr); if( memtmp == MMU_VMA_ERROR ) { return TRUE; } else { sh4_write_byte(memtmp, val); }
nkeynes@586
   166
#define MEM_WRITE_WORD( addr, val ) memtmp = mmu_vma_to_phys_write(addr); if( memtmp == MMU_VMA_ERROR ) { return TRUE; } else { sh4_write_word(memtmp, val); }
nkeynes@586
   167
#define MEM_WRITE_LONG( addr, val ) memtmp = mmu_vma_to_phys_write(addr); if( memtmp == MMU_VMA_ERROR ) { return TRUE; } else { sh4_write_long(memtmp, val); }
nkeynes@359
   168
nkeynes@359
   169
#define FP_WIDTH (IS_FPU_DOUBLESIZE() ? 8 : 4)
nkeynes@359
   170
nkeynes@359
   171
#define MEM_FP_READ( addr, reg ) sh4_read_float( addr, reg );
nkeynes@359
   172
#define MEM_FP_WRITE( addr, reg ) sh4_write_float( addr, reg );
nkeynes@359
   173
nkeynes@359
   174
#define CHECKPRIV() if( !IS_SH4_PRIVMODE() ) return sh4_raise_slot_exception( EXC_ILLEGAL, EXC_SLOT_ILLEGAL )
nkeynes@367
   175
#define CHECKRALIGN16(addr) if( (addr)&0x01 ) return sh4_raise_exception( EXC_DATA_ADDR_READ )
nkeynes@367
   176
#define CHECKRALIGN32(addr) if( (addr)&0x03 ) return sh4_raise_exception( EXC_DATA_ADDR_READ )
nkeynes@367
   177
#define CHECKWALIGN16(addr) if( (addr)&0x01 ) return sh4_raise_exception( EXC_DATA_ADDR_WRITE )
nkeynes@367
   178
#define CHECKWALIGN32(addr) if( (addr)&0x03 ) return sh4_raise_exception( EXC_DATA_ADDR_WRITE )
nkeynes@359
   179
nkeynes@367
   180
#define CHECKFPUEN() if( !IS_FPU_ENABLED() ) { if( ir == 0xFFFD ) { UNDEF(ir); } else { return sh4_raise_slot_exception( EXC_FPU_DISABLED, EXC_SLOT_FPU_DISABLED ); } }
nkeynes@359
   181
#define CHECKDEST(p) if( (p) == 0 ) { ERROR( "%08X: Branch/jump to NULL, CPU halted", sh4r.pc ); dreamcast_stop(); return FALSE; }
nkeynes@359
   182
#define CHECKSLOTILLEGAL() if(sh4r.in_delay_slot) return sh4_raise_exception(EXC_SLOT_ILLEGAL)
nkeynes@359
   183
nkeynes@359
   184
static void sh4_write_float( uint32_t addr, int reg )
nkeynes@359
   185
{
nkeynes@359
   186
    if( IS_FPU_DOUBLESIZE() ) {
nkeynes@359
   187
	if( reg & 1 ) {
nkeynes@359
   188
	    sh4_write_long( addr, *((uint32_t *)&XF((reg)&0x0E)) );
nkeynes@359
   189
	    sh4_write_long( addr+4, *((uint32_t *)&XF(reg)) );
nkeynes@359
   190
	} else {
nkeynes@359
   191
	    sh4_write_long( addr, *((uint32_t *)&FR(reg)) ); 
nkeynes@359
   192
	    sh4_write_long( addr+4, *((uint32_t *)&FR((reg)|0x01)) );
nkeynes@359
   193
	}
nkeynes@359
   194
    } else {
nkeynes@359
   195
	sh4_write_long( addr, *((uint32_t *)&FR((reg))) );
nkeynes@359
   196
    }
nkeynes@359
   197
}
nkeynes@359
   198
nkeynes@359
   199
static void sh4_read_float( uint32_t addr, int reg )
nkeynes@359
   200
{
nkeynes@359
   201
    if( IS_FPU_DOUBLESIZE() ) {
nkeynes@359
   202
	if( reg & 1 ) {
nkeynes@359
   203
	    *((uint32_t *)&XF((reg) & 0x0E)) = sh4_read_long(addr);
nkeynes@359
   204
	    *((uint32_t *)&XF(reg)) = sh4_read_long(addr+4);
nkeynes@359
   205
	} else {
nkeynes@359
   206
	    *((uint32_t *)&FR(reg)) = sh4_read_long(addr);
nkeynes@359
   207
	    *((uint32_t *)&FR((reg) | 0x01)) = sh4_read_long(addr+4);
nkeynes@359
   208
	}
nkeynes@359
   209
    } else {
nkeynes@359
   210
	*((uint32_t *)&FR(reg)) = sh4_read_long(addr);
nkeynes@359
   211
    }
nkeynes@359
   212
}
nkeynes@359
   213
nkeynes@359
   214
gboolean sh4_execute_instruction( void )
nkeynes@359
   215
{
nkeynes@359
   216
    uint32_t pc;
nkeynes@359
   217
    unsigned short ir;
nkeynes@359
   218
    uint32_t tmp;
nkeynes@359
   219
    float ftmp;
nkeynes@359
   220
    double dtmp;
nkeynes@586
   221
    int64_t memtmp; // temporary holder for memory reads
nkeynes@359
   222
    
nkeynes@359
   223
#define R0 sh4r.r[0]
nkeynes@359
   224
    pc = sh4r.pc;
nkeynes@359
   225
    if( pc > 0xFFFFFF00 ) {
nkeynes@359
   226
	/* SYSCALL Magic */
nkeynes@359
   227
	syscall_invoke( pc );
nkeynes@359
   228
	sh4r.in_delay_slot = 0;
nkeynes@359
   229
	pc = sh4r.pc = sh4r.pr;
nkeynes@359
   230
	sh4r.new_pc = sh4r.pc + 2;
nkeynes@359
   231
    }
nkeynes@359
   232
    CHECKRALIGN16(pc);
nkeynes@359
   233
nkeynes@359
   234
    /* Read instruction */
nkeynes@586
   235
    if( !IS_IN_ICACHE(pc) ) {
nkeynes@586
   236
	if( !mmu_update_icache(pc) ) {
nkeynes@586
   237
	    // Fault - look for the fault handler
nkeynes@586
   238
	    if( !mmu_update_icache(sh4r.pc) ) {
nkeynes@586
   239
		// double fault - halt
nkeynes@586
   240
		ERROR( "Double fault - halting" );
nkeynes@586
   241
		dreamcast_stop();
nkeynes@586
   242
		return FALSE;
nkeynes@586
   243
	    }
nkeynes@359
   244
	}
nkeynes@586
   245
	pc = sh4r.pc;
nkeynes@359
   246
    }
nkeynes@586
   247
    assert( IS_IN_ICACHE(pc) );
nkeynes@586
   248
    ir = *(uint16_t *)GET_ICACHE_PTR(sh4r.pc);
nkeynes@359
   249
%%
nkeynes@359
   250
AND Rm, Rn {: sh4r.r[Rn] &= sh4r.r[Rm]; :}
nkeynes@359
   251
AND #imm, R0 {: R0 &= imm; :}
nkeynes@586
   252
 AND.B #imm, @(R0, GBR) {: MEM_READ_BYTE(R0+sh4r.gbr, tmp); MEM_WRITE_BYTE( R0 + sh4r.gbr, imm & tmp ); :}
nkeynes@359
   253
NOT Rm, Rn {: sh4r.r[Rn] = ~sh4r.r[Rm]; :}
nkeynes@359
   254
OR Rm, Rn {: sh4r.r[Rn] |= sh4r.r[Rm]; :}
nkeynes@359
   255
OR #imm, R0  {: R0 |= imm; :}
nkeynes@586
   256
 OR.B #imm, @(R0, GBR) {: MEM_READ_BYTE(R0+sh4r.gbr, tmp); MEM_WRITE_BYTE( R0 + sh4r.gbr, imm | tmp ); :}
nkeynes@359
   257
TAS.B @Rn {:
nkeynes@586
   258
    MEM_READ_BYTE( sh4r.r[Rn], tmp );
nkeynes@359
   259
    sh4r.t = ( tmp == 0 ? 1 : 0 );
nkeynes@359
   260
    MEM_WRITE_BYTE( sh4r.r[Rn], tmp | 0x80 );
nkeynes@359
   261
:}
nkeynes@359
   262
TST Rm, Rn {: sh4r.t = (sh4r.r[Rn]&sh4r.r[Rm] ? 0 : 1); :}
nkeynes@359
   263
TST #imm, R0 {: sh4r.t = (R0 & imm ? 0 : 1); :}
nkeynes@586
   264
 TST.B #imm, @(R0, GBR) {: MEM_READ_BYTE(R0+sh4r.gbr, tmp); sh4r.t = ( tmp & imm ? 0 : 1 ); :}
nkeynes@359
   265
XOR Rm, Rn {: sh4r.r[Rn] ^= sh4r.r[Rm]; :}
nkeynes@359
   266
XOR #imm, R0 {: R0 ^= imm; :}
nkeynes@586
   267
 XOR.B #imm, @(R0, GBR) {: MEM_READ_BYTE(R0+sh4r.gbr, tmp); MEM_WRITE_BYTE( R0 + sh4r.gbr, imm ^ tmp ); :}
nkeynes@359
   268
XTRCT Rm, Rn {: sh4r.r[Rn] = (sh4r.r[Rn]>>16) | (sh4r.r[Rm]<<16); :}
nkeynes@359
   269
nkeynes@359
   270
ROTL Rn {:
nkeynes@359
   271
    sh4r.t = sh4r.r[Rn] >> 31;
nkeynes@359
   272
    sh4r.r[Rn] <<= 1;
nkeynes@359
   273
    sh4r.r[Rn] |= sh4r.t;
nkeynes@359
   274
:}
nkeynes@359
   275
ROTR Rn {:
nkeynes@359
   276
    sh4r.t = sh4r.r[Rn] & 0x00000001;
nkeynes@359
   277
    sh4r.r[Rn] >>= 1;
nkeynes@359
   278
    sh4r.r[Rn] |= (sh4r.t << 31);
nkeynes@359
   279
:}
nkeynes@359
   280
ROTCL Rn {:
nkeynes@359
   281
    tmp = sh4r.r[Rn] >> 31;
nkeynes@359
   282
    sh4r.r[Rn] <<= 1;
nkeynes@359
   283
    sh4r.r[Rn] |= sh4r.t;
nkeynes@359
   284
    sh4r.t = tmp;
nkeynes@359
   285
:}
nkeynes@359
   286
ROTCR Rn {:
nkeynes@359
   287
    tmp = sh4r.r[Rn] & 0x00000001;
nkeynes@359
   288
    sh4r.r[Rn] >>= 1;
nkeynes@359
   289
    sh4r.r[Rn] |= (sh4r.t << 31 );
nkeynes@359
   290
    sh4r.t = tmp;
nkeynes@359
   291
:}
nkeynes@359
   292
SHAD Rm, Rn {:
nkeynes@359
   293
    tmp = sh4r.r[Rm];
nkeynes@359
   294
    if( (tmp & 0x80000000) == 0 ) sh4r.r[Rn] <<= (tmp&0x1f);
nkeynes@359
   295
    else if( (tmp & 0x1F) == 0 )  
nkeynes@359
   296
        sh4r.r[Rn] = ((int32_t)sh4r.r[Rn]) >> 31;
nkeynes@359
   297
    else 
nkeynes@359
   298
	sh4r.r[Rn] = ((int32_t)sh4r.r[Rn]) >> (((~sh4r.r[Rm]) & 0x1F)+1);
nkeynes@359
   299
:}
nkeynes@359
   300
SHLD Rm, Rn {:
nkeynes@359
   301
    tmp = sh4r.r[Rm];
nkeynes@359
   302
    if( (tmp & 0x80000000) == 0 ) sh4r.r[Rn] <<= (tmp&0x1f);
nkeynes@359
   303
    else if( (tmp & 0x1F) == 0 ) sh4r.r[Rn] = 0;
nkeynes@359
   304
    else sh4r.r[Rn] >>= (((~tmp) & 0x1F)+1);
nkeynes@359
   305
:}
nkeynes@359
   306
SHAL Rn {:
nkeynes@359
   307
    sh4r.t = sh4r.r[Rn] >> 31;
nkeynes@359
   308
    sh4r.r[Rn] <<= 1;
nkeynes@359
   309
:}
nkeynes@359
   310
SHAR Rn {:
nkeynes@359
   311
    sh4r.t = sh4r.r[Rn] & 0x00000001;
nkeynes@359
   312
    sh4r.r[Rn] = ((int32_t)sh4r.r[Rn]) >> 1;
nkeynes@359
   313
:}
nkeynes@359
   314
SHLL Rn {: sh4r.t = sh4r.r[Rn] >> 31; sh4r.r[Rn] <<= 1; :}
nkeynes@359
   315
SHLR Rn {: sh4r.t = sh4r.r[Rn] & 0x00000001; sh4r.r[Rn] >>= 1; :}
nkeynes@359
   316
SHLL2 Rn {: sh4r.r[Rn] <<= 2; :}
nkeynes@359
   317
SHLR2 Rn {: sh4r.r[Rn] >>= 2; :}
nkeynes@359
   318
SHLL8 Rn {: sh4r.r[Rn] <<= 8; :}
nkeynes@359
   319
SHLR8 Rn {: sh4r.r[Rn] >>= 8; :}
nkeynes@359
   320
SHLL16 Rn {: sh4r.r[Rn] <<= 16; :}
nkeynes@359
   321
SHLR16 Rn {: sh4r.r[Rn] >>= 16; :}
nkeynes@359
   322
nkeynes@359
   323
EXTU.B Rm, Rn {: sh4r.r[Rn] = sh4r.r[Rm]&0x000000FF; :}
nkeynes@359
   324
EXTU.W Rm, Rn {: sh4r.r[Rn] = sh4r.r[Rm]&0x0000FFFF; :}
nkeynes@359
   325
EXTS.B Rm, Rn {: sh4r.r[Rn] = SIGNEXT8( sh4r.r[Rm]&0x000000FF ); :}
nkeynes@359
   326
EXTS.W Rm, Rn {: sh4r.r[Rn] = SIGNEXT16( sh4r.r[Rm]&0x0000FFFF ); :}
nkeynes@359
   327
SWAP.B Rm, Rn {: sh4r.r[Rn] = (sh4r.r[Rm]&0xFFFF0000) | ((sh4r.r[Rm]&0x0000FF00)>>8) | ((sh4r.r[Rm]&0x000000FF)<<8); :}
nkeynes@359
   328
SWAP.W Rm, Rn {: sh4r.r[Rn] = (sh4r.r[Rm]>>16) | (sh4r.r[Rm]<<16); :}
nkeynes@359
   329
nkeynes@359
   330
CLRT {: sh4r.t = 0; :}
nkeynes@359
   331
SETT {: sh4r.t = 1; :}
nkeynes@359
   332
CLRMAC {: sh4r.mac = 0; :}
nkeynes@550
   333
LDTLB {: MMU_ldtlb(); :}
nkeynes@359
   334
CLRS {: sh4r.s = 0; :}
nkeynes@359
   335
SETS {: sh4r.s = 1; :}
nkeynes@359
   336
MOVT Rn {: sh4r.r[Rn] = sh4r.t; :}
nkeynes@359
   337
NOP {: /* NOP */ :}
nkeynes@359
   338
nkeynes@359
   339
PREF @Rn {:
nkeynes@359
   340
     tmp = sh4r.r[Rn];
nkeynes@359
   341
     if( (tmp & 0xFC000000) == 0xE0000000 ) {
nkeynes@369
   342
	 sh4_flush_store_queue(tmp);
nkeynes@359
   343
     }
nkeynes@359
   344
:}
nkeynes@359
   345
OCBI @Rn {: :}
nkeynes@359
   346
OCBP @Rn {: :}
nkeynes@359
   347
OCBWB @Rn {: :}
nkeynes@359
   348
MOVCA.L R0, @Rn {:
nkeynes@359
   349
    tmp = sh4r.r[Rn];
nkeynes@359
   350
    CHECKWALIGN32(tmp);
nkeynes@359
   351
    MEM_WRITE_LONG( tmp, R0 );
nkeynes@359
   352
:}
nkeynes@359
   353
MOV.B Rm, @(R0, Rn) {: MEM_WRITE_BYTE( R0 + sh4r.r[Rn], sh4r.r[Rm] ); :}
nkeynes@359
   354
MOV.W Rm, @(R0, Rn) {: 
nkeynes@359
   355
    CHECKWALIGN16( R0 + sh4r.r[Rn] );
nkeynes@359
   356
    MEM_WRITE_WORD( R0 + sh4r.r[Rn], sh4r.r[Rm] );
nkeynes@359
   357
:}
nkeynes@359
   358
MOV.L Rm, @(R0, Rn) {:
nkeynes@359
   359
    CHECKWALIGN32( R0 + sh4r.r[Rn] );
nkeynes@359
   360
    MEM_WRITE_LONG( R0 + sh4r.r[Rn], sh4r.r[Rm] );
nkeynes@359
   361
:}
nkeynes@586
   362
MOV.B @(R0, Rm), Rn {: MEM_READ_BYTE( R0 + sh4r.r[Rm], sh4r.r[Rn] ); :}
nkeynes@359
   363
MOV.W @(R0, Rm), Rn {: CHECKRALIGN16( R0 + sh4r.r[Rm] );
nkeynes@586
   364
    MEM_READ_WORD( R0 + sh4r.r[Rm], sh4r.r[Rn] );
nkeynes@359
   365
:}
nkeynes@359
   366
MOV.L @(R0, Rm), Rn {: CHECKRALIGN32( R0 + sh4r.r[Rm] );
nkeynes@586
   367
    MEM_READ_LONG( R0 + sh4r.r[Rm], sh4r.r[Rn] );
nkeynes@359
   368
:}
nkeynes@359
   369
MOV.L Rm, @(disp, Rn) {:
nkeynes@359
   370
    tmp = sh4r.r[Rn] + disp;
nkeynes@359
   371
    CHECKWALIGN32( tmp );
nkeynes@359
   372
    MEM_WRITE_LONG( tmp, sh4r.r[Rm] );
nkeynes@359
   373
:}
nkeynes@359
   374
MOV.B Rm, @Rn {: MEM_WRITE_BYTE( sh4r.r[Rn], sh4r.r[Rm] ); :}
nkeynes@359
   375
MOV.W Rm, @Rn {: CHECKWALIGN16( sh4r.r[Rn] ); MEM_WRITE_WORD( sh4r.r[Rn], sh4r.r[Rm] ); :}
nkeynes@359
   376
MOV.L Rm, @Rn {: CHECKWALIGN32( sh4r.r[Rn] ); MEM_WRITE_LONG( sh4r.r[Rn], sh4r.r[Rm] ); :}
nkeynes@587
   377
 MOV.B Rm, @-Rn {: MEM_WRITE_BYTE( sh4r.r[Rn]-1, sh4r.r[Rm] ); sh4r.r[Rn]--; :}
nkeynes@587
   378
 MOV.W Rm, @-Rn {: CHECKWALIGN16( sh4r.r[Rn] ); MEM_WRITE_WORD( sh4r.r[Rn]-2, sh4r.r[Rm] ); sh4r.r[Rn] -= 2; :}
nkeynes@587
   379
 MOV.L Rm, @-Rn {: CHECKWALIGN32( sh4r.r[Rn] ); MEM_WRITE_LONG( sh4r.r[Rn]-4, sh4r.r[Rm] ); sh4r.r[Rn] -= 4; :}
nkeynes@359
   380
MOV.L @(disp, Rm), Rn {:
nkeynes@359
   381
    tmp = sh4r.r[Rm] + disp;
nkeynes@359
   382
    CHECKRALIGN32( tmp );
nkeynes@586
   383
    MEM_READ_LONG( tmp, sh4r.r[Rn] );
nkeynes@359
   384
:}
nkeynes@586
   385
MOV.B @Rm, Rn {: MEM_READ_BYTE( sh4r.r[Rm], sh4r.r[Rn] ); :}
nkeynes@586
   386
 MOV.W @Rm, Rn {: CHECKRALIGN16( sh4r.r[Rm] ); MEM_READ_WORD( sh4r.r[Rm], sh4r.r[Rn] ); :}
nkeynes@586
   387
 MOV.L @Rm, Rn {: CHECKRALIGN32( sh4r.r[Rm] ); MEM_READ_LONG( sh4r.r[Rm], sh4r.r[Rn] ); :}
nkeynes@359
   388
MOV Rm, Rn {: sh4r.r[Rn] = sh4r.r[Rm]; :}
nkeynes@586
   389
 MOV.B @Rm+, Rn {: MEM_READ_BYTE( sh4r.r[Rm], sh4r.r[Rn] ); sh4r.r[Rm] ++; :}
nkeynes@586
   390
 MOV.W @Rm+, Rn {: CHECKRALIGN16( sh4r.r[Rm] ); MEM_READ_WORD( sh4r.r[Rm], sh4r.r[Rn] ); sh4r.r[Rm] += 2; :}
nkeynes@586
   391
 MOV.L @Rm+, Rn {: CHECKRALIGN32( sh4r.r[Rm] ); MEM_READ_LONG( sh4r.r[Rm], sh4r.r[Rn] ); sh4r.r[Rm] += 4; :}
nkeynes@359
   392
MOV.L @(disp, PC), Rn {:
nkeynes@359
   393
    CHECKSLOTILLEGAL();
nkeynes@359
   394
    tmp = (pc&0xFFFFFFFC) + disp + 4;
nkeynes@586
   395
    MEM_READ_LONG( tmp, sh4r.r[Rn] );
nkeynes@359
   396
:}
nkeynes@359
   397
MOV.B R0, @(disp, GBR) {: MEM_WRITE_BYTE( sh4r.gbr + disp, R0 ); :}
nkeynes@359
   398
MOV.W R0, @(disp, GBR) {:
nkeynes@359
   399
    tmp = sh4r.gbr + disp;
nkeynes@359
   400
    CHECKWALIGN16( tmp );
nkeynes@359
   401
    MEM_WRITE_WORD( tmp, R0 );
nkeynes@359
   402
:}
nkeynes@359
   403
MOV.L R0, @(disp, GBR) {:
nkeynes@359
   404
    tmp = sh4r.gbr + disp;
nkeynes@359
   405
    CHECKWALIGN32( tmp );
nkeynes@359
   406
    MEM_WRITE_LONG( tmp, R0 );
nkeynes@359
   407
:}
nkeynes@586
   408
 MOV.B @(disp, GBR), R0 {: MEM_READ_BYTE( sh4r.gbr + disp, R0 ); :}
nkeynes@359
   409
MOV.W @(disp, GBR), R0 {: 
nkeynes@359
   410
    tmp = sh4r.gbr + disp;
nkeynes@359
   411
    CHECKRALIGN16( tmp );
nkeynes@586
   412
    MEM_READ_WORD( tmp, R0 );
nkeynes@359
   413
:}
nkeynes@359
   414
MOV.L @(disp, GBR), R0 {:
nkeynes@359
   415
    tmp = sh4r.gbr + disp;
nkeynes@359
   416
    CHECKRALIGN32( tmp );
nkeynes@586
   417
    MEM_READ_LONG( tmp, R0 );
nkeynes@359
   418
:}
nkeynes@359
   419
MOV.B R0, @(disp, Rn) {: MEM_WRITE_BYTE( sh4r.r[Rn] + disp, R0 ); :}
nkeynes@359
   420
MOV.W R0, @(disp, Rn) {: 
nkeynes@359
   421
    tmp = sh4r.r[Rn] + disp;
nkeynes@359
   422
    CHECKWALIGN16( tmp );
nkeynes@359
   423
    MEM_WRITE_WORD( tmp, R0 );
nkeynes@359
   424
:}
nkeynes@586
   425
 MOV.B @(disp, Rm), R0 {: MEM_READ_BYTE( sh4r.r[Rm] + disp, R0 ); :}
nkeynes@359
   426
MOV.W @(disp, Rm), R0 {: 
nkeynes@359
   427
    tmp = sh4r.r[Rm] + disp;
nkeynes@359
   428
    CHECKRALIGN16( tmp );
nkeynes@586
   429
    MEM_READ_WORD( tmp, R0 );
nkeynes@359
   430
:}
nkeynes@359
   431
MOV.W @(disp, PC), Rn {:
nkeynes@359
   432
    CHECKSLOTILLEGAL();
nkeynes@359
   433
    tmp = pc + 4 + disp;
nkeynes@586
   434
    MEM_READ_WORD( tmp, sh4r.r[Rn] );
nkeynes@359
   435
:}
nkeynes@359
   436
MOVA @(disp, PC), R0 {:
nkeynes@359
   437
    CHECKSLOTILLEGAL();
nkeynes@359
   438
    R0 = (pc&0xFFFFFFFC) + disp + 4;
nkeynes@359
   439
:}
nkeynes@359
   440
MOV #imm, Rn {:  sh4r.r[Rn] = imm; :}
nkeynes@359
   441
nkeynes@359
   442
CMP/EQ #imm, R0 {: sh4r.t = ( R0 == imm ? 1 : 0 ); :}
nkeynes@359
   443
CMP/EQ Rm, Rn {: sh4r.t = ( sh4r.r[Rm] == sh4r.r[Rn] ? 1 : 0 ); :}
nkeynes@359
   444
CMP/GE Rm, Rn {: sh4r.t = ( ((int32_t)sh4r.r[Rn]) >= ((int32_t)sh4r.r[Rm]) ? 1 : 0 ); :}
nkeynes@359
   445
CMP/GT Rm, Rn {: sh4r.t = ( ((int32_t)sh4r.r[Rn]) > ((int32_t)sh4r.r[Rm]) ? 1 : 0 ); :}
nkeynes@359
   446
CMP/HI Rm, Rn {: sh4r.t = ( sh4r.r[Rn] > sh4r.r[Rm] ? 1 : 0 ); :}
nkeynes@359
   447
CMP/HS Rm, Rn {: sh4r.t = ( sh4r.r[Rn] >= sh4r.r[Rm] ? 1 : 0 ); :}
nkeynes@359
   448
CMP/PL Rn {: sh4r.t = ( ((int32_t)sh4r.r[Rn]) > 0 ? 1 : 0 ); :}
nkeynes@359
   449
CMP/PZ Rn {: sh4r.t = ( ((int32_t)sh4r.r[Rn]) >= 0 ? 1 : 0 ); :}
nkeynes@359
   450
CMP/STR Rm, Rn {: 
nkeynes@359
   451
    /* set T = 1 if any byte in RM & RN is the same */
nkeynes@359
   452
    tmp = sh4r.r[Rm] ^ sh4r.r[Rn];
nkeynes@359
   453
    sh4r.t = ((tmp&0x000000FF)==0 || (tmp&0x0000FF00)==0 ||
nkeynes@359
   454
             (tmp&0x00FF0000)==0 || (tmp&0xFF000000)==0)?1:0;
nkeynes@359
   455
:}
nkeynes@359
   456
nkeynes@359
   457
ADD Rm, Rn {: sh4r.r[Rn] += sh4r.r[Rm]; :}
nkeynes@359
   458
ADD #imm, Rn {: sh4r.r[Rn] += imm; :}
nkeynes@359
   459
ADDC Rm, Rn {:
nkeynes@359
   460
    tmp = sh4r.r[Rn];
nkeynes@359
   461
    sh4r.r[Rn] += sh4r.r[Rm] + sh4r.t;
nkeynes@359
   462
    sh4r.t = ( sh4r.r[Rn] < tmp || (sh4r.r[Rn] == tmp && sh4r.t != 0) ? 1 : 0 );
nkeynes@359
   463
:}
nkeynes@359
   464
ADDV Rm, Rn {:
nkeynes@359
   465
    tmp = sh4r.r[Rn] + sh4r.r[Rm];
nkeynes@359
   466
    sh4r.t = ( (sh4r.r[Rn]>>31) == (sh4r.r[Rm]>>31) && ((sh4r.r[Rn]>>31) != (tmp>>31)) );
nkeynes@359
   467
    sh4r.r[Rn] = tmp;
nkeynes@359
   468
:}
nkeynes@359
   469
DIV0U {: sh4r.m = sh4r.q = sh4r.t = 0; :}
nkeynes@359
   470
DIV0S Rm, Rn {: 
nkeynes@359
   471
    sh4r.q = sh4r.r[Rn]>>31;
nkeynes@359
   472
    sh4r.m = sh4r.r[Rm]>>31;
nkeynes@359
   473
    sh4r.t = sh4r.q ^ sh4r.m;
nkeynes@359
   474
:}
nkeynes@359
   475
DIV1 Rm, Rn {:
nkeynes@384
   476
    /* This is derived from the sh4 manual with some simplifications */
nkeynes@359
   477
    uint32_t tmp0, tmp1, tmp2, dir;
nkeynes@359
   478
nkeynes@359
   479
    dir = sh4r.q ^ sh4r.m;
nkeynes@359
   480
    sh4r.q = (sh4r.r[Rn] >> 31);
nkeynes@359
   481
    tmp2 = sh4r.r[Rm];
nkeynes@359
   482
    sh4r.r[Rn] = (sh4r.r[Rn] << 1) | sh4r.t;
nkeynes@359
   483
    tmp0 = sh4r.r[Rn];
nkeynes@359
   484
    if( dir ) {
nkeynes@359
   485
         sh4r.r[Rn] += tmp2;
nkeynes@359
   486
         tmp1 = (sh4r.r[Rn]<tmp0 ? 1 : 0 );
nkeynes@359
   487
    } else {
nkeynes@359
   488
         sh4r.r[Rn] -= tmp2;
nkeynes@359
   489
         tmp1 = (sh4r.r[Rn]>tmp0 ? 1 : 0 );
nkeynes@359
   490
    }
nkeynes@359
   491
    sh4r.q ^= sh4r.m ^ tmp1;
nkeynes@359
   492
    sh4r.t = ( sh4r.q == sh4r.m ? 1 : 0 );
nkeynes@359
   493
:}
nkeynes@359
   494
DMULS.L Rm, Rn {: sh4r.mac = SIGNEXT32(sh4r.r[Rm]) * SIGNEXT32(sh4r.r[Rn]); :}
nkeynes@359
   495
DMULU.L Rm, Rn {: sh4r.mac = ((uint64_t)sh4r.r[Rm]) * ((uint64_t)sh4r.r[Rn]); :}
nkeynes@359
   496
DT Rn {:
nkeynes@359
   497
    sh4r.r[Rn] --;
nkeynes@359
   498
    sh4r.t = ( sh4r.r[Rn] == 0 ? 1 : 0 );
nkeynes@359
   499
:}
nkeynes@359
   500
MAC.W @Rm+, @Rn+ {:
nkeynes@587
   501
    int32_t stmp;
nkeynes@587
   502
    if( Rm == Rn ) {
nkeynes@587
   503
	CHECKRALIGN16(sh4r.r[Rn]);
nkeynes@587
   504
	MEM_READ_WORD( sh4r.r[Rn], tmp );
nkeynes@587
   505
	stmp = SIGNEXT16(tmp);
nkeynes@587
   506
	MEM_READ_WORD( sh4r.r[Rn]+2, tmp );
nkeynes@587
   507
	stmp *= SIGNEXT16(tmp);
nkeynes@587
   508
	sh4r.r[Rn] += 4;
nkeynes@587
   509
    } else {
nkeynes@587
   510
	CHECKRALIGN16( sh4r.r[Rn] );
nkeynes@587
   511
	CHECKRALIGN16( sh4r.r[Rm] );
nkeynes@587
   512
	MEM_READ_WORD(sh4r.r[Rn], tmp);
nkeynes@587
   513
	stmp = SIGNEXT16(tmp);
nkeynes@587
   514
	MEM_READ_WORD(sh4r.r[Rm], tmp);
nkeynes@587
   515
	stmp = stmp * SIGNEXT16(tmp);
nkeynes@587
   516
	sh4r.r[Rn] += 2;
nkeynes@587
   517
	sh4r.r[Rm] += 2;
nkeynes@587
   518
    }
nkeynes@359
   519
    if( sh4r.s ) {
nkeynes@359
   520
	int64_t tmpl = (int64_t)((int32_t)sh4r.mac) + (int64_t)stmp;
nkeynes@359
   521
	if( tmpl > (int64_t)0x000000007FFFFFFFLL ) {
nkeynes@359
   522
	    sh4r.mac = 0x000000017FFFFFFFLL;
nkeynes@359
   523
	} else if( tmpl < (int64_t)0xFFFFFFFF80000000LL ) {
nkeynes@359
   524
	    sh4r.mac = 0x0000000180000000LL;
nkeynes@359
   525
	} else {
nkeynes@359
   526
	    sh4r.mac = (sh4r.mac & 0xFFFFFFFF00000000LL) |
nkeynes@359
   527
		((uint32_t)(sh4r.mac + stmp));
nkeynes@359
   528
	}
nkeynes@359
   529
    } else {
nkeynes@359
   530
	sh4r.mac += SIGNEXT32(stmp);
nkeynes@359
   531
    }
nkeynes@359
   532
:}
nkeynes@359
   533
MAC.L @Rm+, @Rn+ {:
nkeynes@587
   534
    int64_t tmpl;
nkeynes@587
   535
    if( Rm == Rn ) {
nkeynes@587
   536
	CHECKRALIGN32( sh4r.r[Rn] );
nkeynes@587
   537
	MEM_READ_LONG(sh4r.r[Rn], tmp);
nkeynes@587
   538
	tmpl = SIGNEXT32(tmp);
nkeynes@587
   539
	MEM_READ_LONG(sh4r.r[Rn]+4, tmp);
nkeynes@587
   540
	tmpl = tmpl * SIGNEXT32(tmp) + sh4r.mac;
nkeynes@587
   541
	sh4r.r[Rn] += 8;
nkeynes@587
   542
    } else {
nkeynes@587
   543
	CHECKRALIGN32( sh4r.r[Rm] );
nkeynes@587
   544
	CHECKRALIGN32( sh4r.r[Rn] );
nkeynes@587
   545
	MEM_READ_LONG(sh4r.r[Rn], tmp);
nkeynes@587
   546
	tmpl = SIGNEXT32(tmp);
nkeynes@587
   547
	MEM_READ_LONG(sh4r.r[Rm], tmp);
nkeynes@587
   548
	tmpl = tmpl * SIGNEXT32(tmp) + sh4r.mac;
nkeynes@587
   549
	sh4r.r[Rn] += 4;
nkeynes@587
   550
	sh4r.r[Rm] += 4;
nkeynes@587
   551
    }
nkeynes@359
   552
    if( sh4r.s ) {
nkeynes@359
   553
        /* 48-bit Saturation. Yuch */
nkeynes@359
   554
        if( tmpl < (int64_t)0xFFFF800000000000LL )
nkeynes@359
   555
            tmpl = 0xFFFF800000000000LL;
nkeynes@359
   556
        else if( tmpl > (int64_t)0x00007FFFFFFFFFFFLL )
nkeynes@359
   557
            tmpl = 0x00007FFFFFFFFFFFLL;
nkeynes@359
   558
    }
nkeynes@359
   559
    sh4r.mac = tmpl;
nkeynes@359
   560
:}
nkeynes@359
   561
MUL.L Rm, Rn {: sh4r.mac = (sh4r.mac&0xFFFFFFFF00000000LL) |
nkeynes@359
   562
                        (sh4r.r[Rm] * sh4r.r[Rn]); :}
nkeynes@359
   563
MULU.W Rm, Rn {:
nkeynes@359
   564
    sh4r.mac = (sh4r.mac&0xFFFFFFFF00000000LL) |
nkeynes@359
   565
               (uint32_t)((sh4r.r[Rm]&0xFFFF) * (sh4r.r[Rn]&0xFFFF));
nkeynes@359
   566
:}
nkeynes@359
   567
MULS.W Rm, Rn {:
nkeynes@359
   568
    sh4r.mac = (sh4r.mac&0xFFFFFFFF00000000LL) |
nkeynes@359
   569
               (uint32_t)(SIGNEXT32(sh4r.r[Rm]&0xFFFF) * SIGNEXT32(sh4r.r[Rn]&0xFFFF));
nkeynes@359
   570
:}
nkeynes@359
   571
NEGC Rm, Rn {:
nkeynes@359
   572
    tmp = 0 - sh4r.r[Rm];
nkeynes@359
   573
    sh4r.r[Rn] = tmp - sh4r.t;
nkeynes@359
   574
    sh4r.t = ( 0<tmp || tmp<sh4r.r[Rn] ? 1 : 0 );
nkeynes@359
   575
:}
nkeynes@359
   576
NEG Rm, Rn {: sh4r.r[Rn] = 0 - sh4r.r[Rm]; :}
nkeynes@359
   577
SUB Rm, Rn {: sh4r.r[Rn] -= sh4r.r[Rm]; :}
nkeynes@359
   578
SUBC Rm, Rn {: 
nkeynes@359
   579
    tmp = sh4r.r[Rn];
nkeynes@359
   580
    sh4r.r[Rn] = sh4r.r[Rn] - sh4r.r[Rm] - sh4r.t;
nkeynes@359
   581
    sh4r.t = (sh4r.r[Rn] > tmp || (sh4r.r[Rn] == tmp && sh4r.t == 1));
nkeynes@359
   582
:}
nkeynes@359
   583
nkeynes@359
   584
BRAF Rn {:
nkeynes@359
   585
     CHECKSLOTILLEGAL();
nkeynes@359
   586
     CHECKDEST( pc + 4 + sh4r.r[Rn] );
nkeynes@359
   587
     sh4r.in_delay_slot = 1;
nkeynes@359
   588
     sh4r.pc = sh4r.new_pc;
nkeynes@359
   589
     sh4r.new_pc = pc + 4 + sh4r.r[Rn];
nkeynes@359
   590
     return TRUE;
nkeynes@359
   591
:}
nkeynes@359
   592
BSRF Rn {:
nkeynes@359
   593
     CHECKSLOTILLEGAL();
nkeynes@359
   594
     CHECKDEST( pc + 4 + sh4r.r[Rn] );
nkeynes@359
   595
     sh4r.in_delay_slot = 1;
nkeynes@359
   596
     sh4r.pr = sh4r.pc + 4;
nkeynes@359
   597
     sh4r.pc = sh4r.new_pc;
nkeynes@359
   598
     sh4r.new_pc = pc + 4 + sh4r.r[Rn];
nkeynes@359
   599
     TRACE_CALL( pc, sh4r.new_pc );
nkeynes@359
   600
     return TRUE;
nkeynes@359
   601
:}
nkeynes@359
   602
BT disp {:
nkeynes@359
   603
    CHECKSLOTILLEGAL();
nkeynes@359
   604
    if( sh4r.t ) {
nkeynes@359
   605
        CHECKDEST( sh4r.pc + disp + 4 )
nkeynes@359
   606
        sh4r.pc += disp + 4;
nkeynes@359
   607
        sh4r.new_pc = sh4r.pc + 2;
nkeynes@359
   608
        return TRUE;
nkeynes@359
   609
    }
nkeynes@359
   610
:}
nkeynes@359
   611
BF disp {:
nkeynes@359
   612
    CHECKSLOTILLEGAL();
nkeynes@359
   613
    if( !sh4r.t ) {
nkeynes@359
   614
        CHECKDEST( sh4r.pc + disp + 4 )
nkeynes@359
   615
        sh4r.pc += disp + 4;
nkeynes@359
   616
        sh4r.new_pc = sh4r.pc + 2;
nkeynes@359
   617
        return TRUE;
nkeynes@359
   618
    }
nkeynes@359
   619
:}
nkeynes@359
   620
BT/S disp {:
nkeynes@359
   621
    CHECKSLOTILLEGAL();
nkeynes@359
   622
    if( sh4r.t ) {
nkeynes@359
   623
        CHECKDEST( sh4r.pc + disp + 4 )
nkeynes@359
   624
        sh4r.in_delay_slot = 1;
nkeynes@359
   625
        sh4r.pc = sh4r.new_pc;
nkeynes@359
   626
        sh4r.new_pc = pc + disp + 4;
nkeynes@359
   627
        sh4r.in_delay_slot = 1;
nkeynes@359
   628
        return TRUE;
nkeynes@359
   629
    }
nkeynes@359
   630
:}
nkeynes@359
   631
BF/S disp {:
nkeynes@359
   632
    CHECKSLOTILLEGAL();
nkeynes@359
   633
    if( !sh4r.t ) {
nkeynes@359
   634
        CHECKDEST( sh4r.pc + disp + 4 )
nkeynes@359
   635
        sh4r.in_delay_slot = 1;
nkeynes@359
   636
        sh4r.pc = sh4r.new_pc;
nkeynes@359
   637
        sh4r.new_pc = pc + disp + 4;
nkeynes@359
   638
        return TRUE;
nkeynes@359
   639
    }
nkeynes@359
   640
:}
nkeynes@359
   641
BRA disp {:
nkeynes@359
   642
    CHECKSLOTILLEGAL();
nkeynes@359
   643
    CHECKDEST( sh4r.pc + disp + 4 );
nkeynes@359
   644
    sh4r.in_delay_slot = 1;
nkeynes@359
   645
    sh4r.pc = sh4r.new_pc;
nkeynes@359
   646
    sh4r.new_pc = pc + 4 + disp;
nkeynes@359
   647
    return TRUE;
nkeynes@359
   648
:}
nkeynes@359
   649
BSR disp {:
nkeynes@359
   650
    CHECKDEST( sh4r.pc + disp + 4 );
nkeynes@359
   651
    CHECKSLOTILLEGAL();
nkeynes@359
   652
    sh4r.in_delay_slot = 1;
nkeynes@359
   653
    sh4r.pr = pc + 4;
nkeynes@359
   654
    sh4r.pc = sh4r.new_pc;
nkeynes@359
   655
    sh4r.new_pc = pc + 4 + disp;
nkeynes@359
   656
    TRACE_CALL( pc, sh4r.new_pc );
nkeynes@359
   657
    return TRUE;
nkeynes@359
   658
:}
nkeynes@359
   659
TRAPA #imm {:
nkeynes@359
   660
    CHECKSLOTILLEGAL();
nkeynes@359
   661
    sh4r.pc += 2;
nkeynes@586
   662
    sh4_raise_trap( imm );
nkeynes@586
   663
    return TRUE;
nkeynes@359
   664
:}
nkeynes@359
   665
RTS {: 
nkeynes@359
   666
    CHECKSLOTILLEGAL();
nkeynes@359
   667
    CHECKDEST( sh4r.pr );
nkeynes@359
   668
    sh4r.in_delay_slot = 1;
nkeynes@359
   669
    sh4r.pc = sh4r.new_pc;
nkeynes@359
   670
    sh4r.new_pc = sh4r.pr;
nkeynes@359
   671
    TRACE_RETURN( pc, sh4r.new_pc );
nkeynes@359
   672
    return TRUE;
nkeynes@359
   673
:}
nkeynes@359
   674
SLEEP {:
nkeynes@359
   675
    if( MMIO_READ( CPG, STBCR ) & 0x80 ) {
nkeynes@359
   676
	sh4r.sh4_state = SH4_STATE_STANDBY;
nkeynes@359
   677
    } else {
nkeynes@359
   678
	sh4r.sh4_state = SH4_STATE_SLEEP;
nkeynes@359
   679
    }
nkeynes@359
   680
    return FALSE; /* Halt CPU */
nkeynes@359
   681
:}
nkeynes@359
   682
RTE {:
nkeynes@359
   683
    CHECKPRIV();
nkeynes@359
   684
    CHECKDEST( sh4r.spc );
nkeynes@359
   685
    CHECKSLOTILLEGAL();
nkeynes@359
   686
    sh4r.in_delay_slot = 1;
nkeynes@359
   687
    sh4r.pc = sh4r.new_pc;
nkeynes@359
   688
    sh4r.new_pc = sh4r.spc;
nkeynes@374
   689
    sh4_write_sr( sh4r.ssr );
nkeynes@359
   690
    return TRUE;
nkeynes@359
   691
:}
nkeynes@359
   692
JMP @Rn {:
nkeynes@359
   693
    CHECKDEST( sh4r.r[Rn] );
nkeynes@359
   694
    CHECKSLOTILLEGAL();
nkeynes@359
   695
    sh4r.in_delay_slot = 1;
nkeynes@359
   696
    sh4r.pc = sh4r.new_pc;
nkeynes@359
   697
    sh4r.new_pc = sh4r.r[Rn];
nkeynes@359
   698
    return TRUE;
nkeynes@359
   699
:}
nkeynes@359
   700
JSR @Rn {:
nkeynes@359
   701
    CHECKDEST( sh4r.r[Rn] );
nkeynes@359
   702
    CHECKSLOTILLEGAL();
nkeynes@359
   703
    sh4r.in_delay_slot = 1;
nkeynes@359
   704
    sh4r.pc = sh4r.new_pc;
nkeynes@359
   705
    sh4r.new_pc = sh4r.r[Rn];
nkeynes@359
   706
    sh4r.pr = pc + 4;
nkeynes@359
   707
    TRACE_CALL( pc, sh4r.new_pc );
nkeynes@359
   708
    return TRUE;
nkeynes@359
   709
:}
nkeynes@359
   710
STS MACH, Rn {: sh4r.r[Rn] = (sh4r.mac>>32); :}
nkeynes@359
   711
STS.L MACH, @-Rn {:
nkeynes@587
   712
    CHECKWALIGN32( sh4r.r[Rn] );
nkeynes@587
   713
    MEM_WRITE_LONG( sh4r.r[Rn]-4, (sh4r.mac>>32) );
nkeynes@359
   714
    sh4r.r[Rn] -= 4;
nkeynes@359
   715
:}
nkeynes@359
   716
STC.L SR, @-Rn {:
nkeynes@359
   717
    CHECKPRIV();
nkeynes@587
   718
    CHECKWALIGN32( sh4r.r[Rn] );
nkeynes@587
   719
    MEM_WRITE_LONG( sh4r.r[Rn]-4, sh4_read_sr() );
nkeynes@359
   720
    sh4r.r[Rn] -= 4;
nkeynes@359
   721
:}
nkeynes@359
   722
LDS.L @Rm+, MACH {:
nkeynes@359
   723
    CHECKRALIGN32( sh4r.r[Rm] );
nkeynes@586
   724
    MEM_READ_LONG(sh4r.r[Rm], tmp);
nkeynes@359
   725
    sh4r.mac = (sh4r.mac & 0x00000000FFFFFFFF) |
nkeynes@586
   726
	(((uint64_t)tmp)<<32);
nkeynes@359
   727
    sh4r.r[Rm] += 4;
nkeynes@359
   728
:}
nkeynes@359
   729
LDC.L @Rm+, SR {:
nkeynes@359
   730
    CHECKSLOTILLEGAL();
nkeynes@359
   731
    CHECKPRIV();
nkeynes@359
   732
    CHECKWALIGN32( sh4r.r[Rm] );
nkeynes@586
   733
    MEM_READ_LONG(sh4r.r[Rm], tmp);
nkeynes@586
   734
    sh4_write_sr( tmp );
nkeynes@359
   735
    sh4r.r[Rm] +=4;
nkeynes@359
   736
:}
nkeynes@359
   737
LDS Rm, MACH {:
nkeynes@359
   738
    sh4r.mac = (sh4r.mac & 0x00000000FFFFFFFF) |
nkeynes@359
   739
               (((uint64_t)sh4r.r[Rm])<<32);
nkeynes@359
   740
:}
nkeynes@359
   741
LDC Rm, SR {:
nkeynes@359
   742
    CHECKSLOTILLEGAL();
nkeynes@359
   743
    CHECKPRIV();
nkeynes@374
   744
    sh4_write_sr( sh4r.r[Rm] );
nkeynes@359
   745
:}
nkeynes@359
   746
LDC Rm, SGR {:
nkeynes@359
   747
    CHECKPRIV();
nkeynes@359
   748
    sh4r.sgr = sh4r.r[Rm];
nkeynes@359
   749
:}
nkeynes@359
   750
LDC.L @Rm+, SGR {:
nkeynes@359
   751
    CHECKPRIV();
nkeynes@359
   752
    CHECKRALIGN32( sh4r.r[Rm] );
nkeynes@586
   753
    MEM_READ_LONG(sh4r.r[Rm], sh4r.sgr);
nkeynes@359
   754
    sh4r.r[Rm] +=4;
nkeynes@359
   755
:}
nkeynes@359
   756
STS MACL, Rn {: sh4r.r[Rn] = (uint32_t)sh4r.mac; :}
nkeynes@359
   757
STS.L MACL, @-Rn {:
nkeynes@587
   758
    CHECKWALIGN32( sh4r.r[Rn] );
nkeynes@587
   759
    MEM_WRITE_LONG( sh4r.r[Rn]-4, (uint32_t)sh4r.mac );
nkeynes@359
   760
    sh4r.r[Rn] -= 4;
nkeynes@359
   761
:}
nkeynes@359
   762
STC.L GBR, @-Rn {:
nkeynes@587
   763
    CHECKWALIGN32( sh4r.r[Rn] );
nkeynes@587
   764
    MEM_WRITE_LONG( sh4r.r[Rn]-4, sh4r.gbr );
nkeynes@359
   765
    sh4r.r[Rn] -= 4;
nkeynes@359
   766
:}
nkeynes@359
   767
LDS.L @Rm+, MACL {:
nkeynes@359
   768
    CHECKRALIGN32( sh4r.r[Rm] );
nkeynes@586
   769
    MEM_READ_LONG(sh4r.r[Rm], tmp);
nkeynes@359
   770
    sh4r.mac = (sh4r.mac & 0xFFFFFFFF00000000LL) |
nkeynes@586
   771
               (uint64_t)((uint32_t)tmp);
nkeynes@359
   772
    sh4r.r[Rm] += 4;
nkeynes@359
   773
:}
nkeynes@359
   774
LDC.L @Rm+, GBR {:
nkeynes@359
   775
    CHECKRALIGN32( sh4r.r[Rm] );
nkeynes@586
   776
    MEM_READ_LONG(sh4r.r[Rm], sh4r.gbr);
nkeynes@359
   777
    sh4r.r[Rm] +=4;
nkeynes@359
   778
:}
nkeynes@359
   779
LDS Rm, MACL {:
nkeynes@359
   780
    sh4r.mac = (sh4r.mac & 0xFFFFFFFF00000000LL) |
nkeynes@359
   781
               (uint64_t)((uint32_t)(sh4r.r[Rm]));
nkeynes@359
   782
:}
nkeynes@359
   783
LDC Rm, GBR {: sh4r.gbr = sh4r.r[Rm]; :}
nkeynes@359
   784
STS PR, Rn {: sh4r.r[Rn] = sh4r.pr; :}
nkeynes@359
   785
STS.L PR, @-Rn {:
nkeynes@587
   786
    CHECKWALIGN32( sh4r.r[Rn] );
nkeynes@587
   787
    MEM_WRITE_LONG( sh4r.r[Rn]-4, sh4r.pr );
nkeynes@359
   788
    sh4r.r[Rn] -= 4;
nkeynes@359
   789
:}
nkeynes@359
   790
STC.L VBR, @-Rn {:
nkeynes@359
   791
    CHECKPRIV();
nkeynes@587
   792
    CHECKWALIGN32( sh4r.r[Rn] );
nkeynes@587
   793
    MEM_WRITE_LONG( sh4r.r[Rn]-4, sh4r.vbr );
nkeynes@359
   794
    sh4r.r[Rn] -= 4;
nkeynes@359
   795
:}
nkeynes@359
   796
LDS.L @Rm+, PR {:
nkeynes@359
   797
    CHECKRALIGN32( sh4r.r[Rm] );
nkeynes@586
   798
    MEM_READ_LONG( sh4r.r[Rm], sh4r.pr );
nkeynes@359
   799
    sh4r.r[Rm] += 4;
nkeynes@359
   800
:}
nkeynes@359
   801
LDC.L @Rm+, VBR {:
nkeynes@359
   802
    CHECKPRIV();
nkeynes@359
   803
    CHECKRALIGN32( sh4r.r[Rm] );
nkeynes@586
   804
    MEM_READ_LONG(sh4r.r[Rm], sh4r.vbr);
nkeynes@359
   805
    sh4r.r[Rm] +=4;
nkeynes@359
   806
:}
nkeynes@359
   807
LDS Rm, PR {: sh4r.pr = sh4r.r[Rm]; :}
nkeynes@359
   808
LDC Rm, VBR {:
nkeynes@359
   809
    CHECKPRIV();
nkeynes@359
   810
    sh4r.vbr = sh4r.r[Rm];
nkeynes@359
   811
:}
nkeynes@359
   812
STC SGR, Rn {:
nkeynes@359
   813
    CHECKPRIV();
nkeynes@359
   814
    sh4r.r[Rn] = sh4r.sgr;
nkeynes@359
   815
:}
nkeynes@359
   816
STC.L SGR, @-Rn {:
nkeynes@359
   817
    CHECKPRIV();
nkeynes@587
   818
    CHECKWALIGN32( sh4r.r[Rn] );
nkeynes@587
   819
    MEM_WRITE_LONG( sh4r.r[Rn]-4, sh4r.sgr );
nkeynes@359
   820
    sh4r.r[Rn] -= 4;
nkeynes@359
   821
:}
nkeynes@359
   822
STC.L SSR, @-Rn {:
nkeynes@359
   823
    CHECKPRIV();
nkeynes@587
   824
    CHECKWALIGN32( sh4r.r[Rn] );
nkeynes@587
   825
    MEM_WRITE_LONG( sh4r.r[Rn]-4, sh4r.ssr );
nkeynes@359
   826
    sh4r.r[Rn] -= 4;
nkeynes@359
   827
:}
nkeynes@359
   828
LDC.L @Rm+, SSR {:
nkeynes@359
   829
    CHECKPRIV();
nkeynes@359
   830
    CHECKRALIGN32( sh4r.r[Rm] );
nkeynes@586
   831
    MEM_READ_LONG(sh4r.r[Rm], sh4r.ssr);
nkeynes@359
   832
    sh4r.r[Rm] +=4;
nkeynes@359
   833
:}
nkeynes@359
   834
LDC Rm, SSR {:
nkeynes@359
   835
    CHECKPRIV();
nkeynes@359
   836
    sh4r.ssr = sh4r.r[Rm];
nkeynes@359
   837
:}
nkeynes@359
   838
STC.L SPC, @-Rn {:
nkeynes@359
   839
    CHECKPRIV();
nkeynes@587
   840
    CHECKWALIGN32( sh4r.r[Rn] );
nkeynes@587
   841
    MEM_WRITE_LONG( sh4r.r[Rn]-4, sh4r.spc );
nkeynes@359
   842
    sh4r.r[Rn] -= 4;
nkeynes@359
   843
:}
nkeynes@359
   844
LDC.L @Rm+, SPC {:
nkeynes@359
   845
    CHECKPRIV();
nkeynes@359
   846
    CHECKRALIGN32( sh4r.r[Rm] );
nkeynes@586
   847
    MEM_READ_LONG(sh4r.r[Rm], sh4r.spc);
nkeynes@359
   848
    sh4r.r[Rm] +=4;
nkeynes@359
   849
:}
nkeynes@359
   850
LDC Rm, SPC {:
nkeynes@359
   851
    CHECKPRIV();
nkeynes@359
   852
    sh4r.spc = sh4r.r[Rm];
nkeynes@359
   853
:}
nkeynes@626
   854
STS FPUL, Rn {: 
nkeynes@626
   855
    CHECKFPUEN();
nkeynes@669
   856
    sh4r.r[Rn] = FPULi; 
nkeynes@626
   857
:}
nkeynes@359
   858
STS.L FPUL, @-Rn {:
nkeynes@626
   859
    CHECKFPUEN();
nkeynes@587
   860
    CHECKWALIGN32( sh4r.r[Rn] );
nkeynes@669
   861
    MEM_WRITE_LONG( sh4r.r[Rn]-4, FPULi );
nkeynes@359
   862
    sh4r.r[Rn] -= 4;
nkeynes@359
   863
:}
nkeynes@359
   864
LDS.L @Rm+, FPUL {:
nkeynes@626
   865
    CHECKFPUEN();
nkeynes@359
   866
    CHECKRALIGN32( sh4r.r[Rm] );
nkeynes@669
   867
    MEM_READ_LONG(sh4r.r[Rm], FPULi);
nkeynes@359
   868
    sh4r.r[Rm] +=4;
nkeynes@359
   869
:}
nkeynes@626
   870
LDS Rm, FPUL {:
nkeynes@626
   871
    CHECKFPUEN();
nkeynes@669
   872
    FPULi = sh4r.r[Rm]; 
nkeynes@626
   873
:}
nkeynes@626
   874
STS FPSCR, Rn {: 
nkeynes@626
   875
    CHECKFPUEN();
nkeynes@626
   876
    sh4r.r[Rn] = sh4r.fpscr; 
nkeynes@626
   877
:}
nkeynes@359
   878
STS.L FPSCR, @-Rn {:
nkeynes@626
   879
    CHECKFPUEN();
nkeynes@587
   880
    CHECKWALIGN32( sh4r.r[Rn] );
nkeynes@587
   881
    MEM_WRITE_LONG( sh4r.r[Rn]-4, sh4r.fpscr );
nkeynes@359
   882
    sh4r.r[Rn] -= 4;
nkeynes@359
   883
:}
nkeynes@359
   884
LDS.L @Rm+, FPSCR {:
nkeynes@626
   885
    CHECKFPUEN();
nkeynes@359
   886
    CHECKRALIGN32( sh4r.r[Rm] );
nkeynes@669
   887
    MEM_READ_LONG(sh4r.r[Rm], tmp);
nkeynes@359
   888
    sh4r.r[Rm] +=4;
nkeynes@669
   889
    sh4_write_fpscr( tmp );
nkeynes@359
   890
:}
nkeynes@374
   891
LDS Rm, FPSCR {: 
nkeynes@626
   892
    CHECKFPUEN();
nkeynes@669
   893
    sh4_write_fpscr( sh4r.r[Rm] );
nkeynes@374
   894
:}
nkeynes@359
   895
STC DBR, Rn {: CHECKPRIV(); sh4r.r[Rn] = sh4r.dbr; :}
nkeynes@359
   896
STC.L DBR, @-Rn {:
nkeynes@359
   897
    CHECKPRIV();
nkeynes@587
   898
    CHECKWALIGN32( sh4r.r[Rn] );
nkeynes@587
   899
    MEM_WRITE_LONG( sh4r.r[Rn]-4, sh4r.dbr );
nkeynes@359
   900
    sh4r.r[Rn] -= 4;
nkeynes@359
   901
:}
nkeynes@359
   902
LDC.L @Rm+, DBR {:
nkeynes@359
   903
    CHECKPRIV();
nkeynes@359
   904
    CHECKRALIGN32( sh4r.r[Rm] );
nkeynes@586
   905
    MEM_READ_LONG(sh4r.r[Rm], sh4r.dbr);
nkeynes@359
   906
    sh4r.r[Rm] +=4;
nkeynes@359
   907
:}
nkeynes@359
   908
LDC Rm, DBR {:
nkeynes@359
   909
    CHECKPRIV();
nkeynes@359
   910
    sh4r.dbr = sh4r.r[Rm];
nkeynes@359
   911
:}
nkeynes@359
   912
STC.L Rm_BANK, @-Rn {:
nkeynes@359
   913
    CHECKPRIV();
nkeynes@587
   914
    CHECKWALIGN32( sh4r.r[Rn] );
nkeynes@587
   915
    MEM_WRITE_LONG( sh4r.r[Rn]-4, sh4r.r_bank[Rm_BANK] );
nkeynes@359
   916
    sh4r.r[Rn] -= 4;
nkeynes@359
   917
:}
nkeynes@359
   918
LDC.L @Rm+, Rn_BANK {:
nkeynes@359
   919
    CHECKPRIV();
nkeynes@359
   920
    CHECKRALIGN32( sh4r.r[Rm] );
nkeynes@586
   921
    MEM_READ_LONG( sh4r.r[Rm], sh4r.r_bank[Rn_BANK] );
nkeynes@359
   922
    sh4r.r[Rm] += 4;
nkeynes@359
   923
:}
nkeynes@359
   924
LDC Rm, Rn_BANK {:
nkeynes@359
   925
    CHECKPRIV();
nkeynes@359
   926
    sh4r.r_bank[Rn_BANK] = sh4r.r[Rm];
nkeynes@359
   927
:}
nkeynes@359
   928
STC SR, Rn {: 
nkeynes@359
   929
    CHECKPRIV();
nkeynes@359
   930
    sh4r.r[Rn] = sh4_read_sr();
nkeynes@359
   931
:}
nkeynes@359
   932
STC GBR, Rn {:
nkeynes@359
   933
    sh4r.r[Rn] = sh4r.gbr;
nkeynes@359
   934
:}
nkeynes@359
   935
STC VBR, Rn {:
nkeynes@359
   936
    CHECKPRIV();
nkeynes@359
   937
    sh4r.r[Rn] = sh4r.vbr;
nkeynes@359
   938
:}
nkeynes@359
   939
STC SSR, Rn {:
nkeynes@359
   940
    CHECKPRIV();
nkeynes@359
   941
    sh4r.r[Rn] = sh4r.ssr;
nkeynes@359
   942
:}
nkeynes@359
   943
STC SPC, Rn {:
nkeynes@359
   944
    CHECKPRIV();
nkeynes@359
   945
    sh4r.r[Rn] = sh4r.spc;
nkeynes@359
   946
:}
nkeynes@359
   947
STC Rm_BANK, Rn {:
nkeynes@359
   948
    CHECKPRIV();
nkeynes@359
   949
    sh4r.r[Rn] = sh4r.r_bank[Rm_BANK];
nkeynes@359
   950
:}
nkeynes@359
   951
nkeynes@359
   952
FADD FRm, FRn {:
nkeynes@359
   953
    CHECKFPUEN();
nkeynes@359
   954
    if( IS_FPU_DOUBLEPREC() ) {
nkeynes@359
   955
	DR(FRn) += DR(FRm);
nkeynes@359
   956
    } else {
nkeynes@359
   957
	FR(FRn) += FR(FRm);
nkeynes@359
   958
    }
nkeynes@359
   959
:}
nkeynes@359
   960
FSUB FRm, FRn {:
nkeynes@359
   961
    CHECKFPUEN();
nkeynes@359
   962
    if( IS_FPU_DOUBLEPREC() ) {
nkeynes@359
   963
	DR(FRn) -= DR(FRm);
nkeynes@359
   964
    } else {
nkeynes@359
   965
	FR(FRn) -= FR(FRm);
nkeynes@359
   966
    }
nkeynes@359
   967
:}
nkeynes@359
   968
nkeynes@359
   969
FMUL FRm, FRn {:
nkeynes@359
   970
    CHECKFPUEN();
nkeynes@359
   971
    if( IS_FPU_DOUBLEPREC() ) {
nkeynes@359
   972
	DR(FRn) *= DR(FRm);
nkeynes@359
   973
    } else {
nkeynes@359
   974
	FR(FRn) *= FR(FRm);
nkeynes@359
   975
    }
nkeynes@359
   976
:}
nkeynes@359
   977
nkeynes@359
   978
FDIV FRm, FRn {:
nkeynes@359
   979
    CHECKFPUEN();
nkeynes@359
   980
    if( IS_FPU_DOUBLEPREC() ) {
nkeynes@359
   981
	DR(FRn) /= DR(FRm);
nkeynes@359
   982
    } else {
nkeynes@359
   983
	FR(FRn) /= FR(FRm);
nkeynes@359
   984
    }
nkeynes@359
   985
:}
nkeynes@359
   986
nkeynes@359
   987
FCMP/EQ FRm, FRn {:
nkeynes@359
   988
    CHECKFPUEN();
nkeynes@359
   989
    if( IS_FPU_DOUBLEPREC() ) {
nkeynes@359
   990
	sh4r.t = ( DR(FRn) == DR(FRm) ? 1 : 0 );
nkeynes@359
   991
    } else {
nkeynes@359
   992
	sh4r.t = ( FR(FRn) == FR(FRm) ? 1 : 0 );
nkeynes@359
   993
    }
nkeynes@359
   994
:}
nkeynes@359
   995
nkeynes@359
   996
FCMP/GT FRm, FRn {:
nkeynes@359
   997
    CHECKFPUEN();
nkeynes@359
   998
    if( IS_FPU_DOUBLEPREC() ) {
nkeynes@359
   999
	sh4r.t = ( DR(FRn) > DR(FRm) ? 1 : 0 );
nkeynes@359
  1000
    } else {
nkeynes@359
  1001
	sh4r.t = ( FR(FRn) > FR(FRm) ? 1 : 0 );
nkeynes@359
  1002
    }
nkeynes@359
  1003
:}
nkeynes@359
  1004
nkeynes@359
  1005
FMOV @(R0, Rm), FRn {: MEM_FP_READ( sh4r.r[Rm] + R0, FRn ); :}
nkeynes@359
  1006
FMOV FRm, @(R0, Rn) {: MEM_FP_WRITE( sh4r.r[Rn] + R0, FRm ); :}
nkeynes@359
  1007
FMOV @Rm, FRn {: MEM_FP_READ( sh4r.r[Rm], FRn ); :}
nkeynes@359
  1008
FMOV @Rm+, FRn {: MEM_FP_READ( sh4r.r[Rm], FRn ); sh4r.r[Rm] += FP_WIDTH; :}
nkeynes@359
  1009
FMOV FRm, @Rn {: MEM_FP_WRITE( sh4r.r[Rn], FRm ); :}
nkeynes@587
  1010
 FMOV FRm, @-Rn {: MEM_FP_WRITE( sh4r.r[Rn] - FP_WIDTH, FRm ); sh4r.r[Rn] -= FP_WIDTH; :}
nkeynes@359
  1011
FMOV FRm, FRn {: 
nkeynes@359
  1012
    if( IS_FPU_DOUBLESIZE() )
nkeynes@359
  1013
	DR(FRn) = DR(FRm);
nkeynes@359
  1014
    else
nkeynes@359
  1015
	FR(FRn) = FR(FRm);
nkeynes@359
  1016
:}
nkeynes@359
  1017
FSTS FPUL, FRn {: CHECKFPUEN(); FR(FRn) = FPULf; :}
nkeynes@359
  1018
FLDS FRm, FPUL {: CHECKFPUEN(); FPULf = FR(FRm); :}
nkeynes@359
  1019
FLOAT FPUL, FRn {: 
nkeynes@359
  1020
    CHECKFPUEN();
nkeynes@374
  1021
    if( IS_FPU_DOUBLEPREC() ) {
nkeynes@374
  1022
	if( FRn&1 ) { // No, really...
nkeynes@374
  1023
	    dtmp = (double)FPULi;
nkeynes@374
  1024
	    FR(FRn) = *(((float *)&dtmp)+1);
nkeynes@374
  1025
	} else {
nkeynes@374
  1026
	    DRF(FRn>>1) = (double)FPULi;
nkeynes@374
  1027
	}
nkeynes@374
  1028
    } else {
nkeynes@359
  1029
	FR(FRn) = (float)FPULi;
nkeynes@374
  1030
    }
nkeynes@359
  1031
:}
nkeynes@359
  1032
FTRC FRm, FPUL {:
nkeynes@359
  1033
    CHECKFPUEN();
nkeynes@359
  1034
    if( IS_FPU_DOUBLEPREC() ) {
nkeynes@374
  1035
	if( FRm&1 ) {
nkeynes@374
  1036
	    dtmp = 0;
nkeynes@374
  1037
	    *(((float *)&dtmp)+1) = FR(FRm);
nkeynes@374
  1038
	} else {
nkeynes@374
  1039
	    dtmp = DRF(FRm>>1);
nkeynes@374
  1040
	}
nkeynes@359
  1041
        if( dtmp >= MAX_INTF )
nkeynes@359
  1042
            FPULi = MAX_INT;
nkeynes@359
  1043
        else if( dtmp <= MIN_INTF )
nkeynes@359
  1044
            FPULi = MIN_INT;
nkeynes@359
  1045
        else 
nkeynes@359
  1046
            FPULi = (int32_t)dtmp;
nkeynes@359
  1047
    } else {
nkeynes@359
  1048
	ftmp = FR(FRm);
nkeynes@359
  1049
	if( ftmp >= MAX_INTF )
nkeynes@359
  1050
	    FPULi = MAX_INT;
nkeynes@359
  1051
	else if( ftmp <= MIN_INTF )
nkeynes@359
  1052
	    FPULi = MIN_INT;
nkeynes@359
  1053
	else
nkeynes@359
  1054
	    FPULi = (int32_t)ftmp;
nkeynes@359
  1055
    }
nkeynes@359
  1056
:}
nkeynes@359
  1057
FNEG FRn {:
nkeynes@359
  1058
    CHECKFPUEN();
nkeynes@359
  1059
    if( IS_FPU_DOUBLEPREC() ) {
nkeynes@359
  1060
	DR(FRn) = -DR(FRn);
nkeynes@359
  1061
    } else {
nkeynes@359
  1062
        FR(FRn) = -FR(FRn);
nkeynes@359
  1063
    }
nkeynes@359
  1064
:}
nkeynes@359
  1065
FABS FRn {:
nkeynes@359
  1066
    CHECKFPUEN();
nkeynes@359
  1067
    if( IS_FPU_DOUBLEPREC() ) {
nkeynes@359
  1068
	DR(FRn) = fabs(DR(FRn));
nkeynes@359
  1069
    } else {
nkeynes@359
  1070
        FR(FRn) = fabsf(FR(FRn));
nkeynes@359
  1071
    }
nkeynes@359
  1072
:}
nkeynes@359
  1073
FSQRT FRn {:
nkeynes@359
  1074
    CHECKFPUEN();
nkeynes@359
  1075
    if( IS_FPU_DOUBLEPREC() ) {
nkeynes@359
  1076
	DR(FRn) = sqrt(DR(FRn));
nkeynes@359
  1077
    } else {
nkeynes@359
  1078
        FR(FRn) = sqrtf(FR(FRn));
nkeynes@359
  1079
    }
nkeynes@359
  1080
:}
nkeynes@359
  1081
FLDI0 FRn {:
nkeynes@359
  1082
    CHECKFPUEN();
nkeynes@359
  1083
    if( IS_FPU_DOUBLEPREC() ) {
nkeynes@359
  1084
	DR(FRn) = 0.0;
nkeynes@359
  1085
    } else {
nkeynes@359
  1086
        FR(FRn) = 0.0;
nkeynes@359
  1087
    }
nkeynes@359
  1088
:}
nkeynes@359
  1089
FLDI1 FRn {:
nkeynes@359
  1090
    CHECKFPUEN();
nkeynes@359
  1091
    if( IS_FPU_DOUBLEPREC() ) {
nkeynes@359
  1092
	DR(FRn) = 1.0;
nkeynes@359
  1093
    } else {
nkeynes@359
  1094
        FR(FRn) = 1.0;
nkeynes@359
  1095
    }
nkeynes@359
  1096
:}
nkeynes@359
  1097
FMAC FR0, FRm, FRn {:
nkeynes@359
  1098
    CHECKFPUEN();
nkeynes@359
  1099
    if( IS_FPU_DOUBLEPREC() ) {
nkeynes@359
  1100
        DR(FRn) += DR(FRm)*DR(0);
nkeynes@359
  1101
    } else {
nkeynes@359
  1102
	FR(FRn) += FR(FRm)*FR(0);
nkeynes@359
  1103
    }
nkeynes@359
  1104
:}
nkeynes@374
  1105
FRCHG {: 
nkeynes@374
  1106
    CHECKFPUEN(); 
nkeynes@374
  1107
    sh4r.fpscr ^= FPSCR_FR; 
nkeynes@669
  1108
    sh4_switch_fr_banks();
nkeynes@374
  1109
:}
nkeynes@359
  1110
FSCHG {: CHECKFPUEN(); sh4r.fpscr ^= FPSCR_SZ; :}
nkeynes@359
  1111
FCNVSD FPUL, FRn {:
nkeynes@359
  1112
    CHECKFPUEN();
nkeynes@359
  1113
    if( IS_FPU_DOUBLEPREC() && !IS_FPU_DOUBLESIZE() ) {
nkeynes@359
  1114
	DR(FRn) = (double)FPULf;
nkeynes@359
  1115
    }
nkeynes@359
  1116
:}
nkeynes@359
  1117
FCNVDS FRm, FPUL {:
nkeynes@359
  1118
    CHECKFPUEN();
nkeynes@359
  1119
    if( IS_FPU_DOUBLEPREC() && !IS_FPU_DOUBLESIZE() ) {
nkeynes@359
  1120
	FPULf = (float)DR(FRm);
nkeynes@359
  1121
    }
nkeynes@359
  1122
:}
nkeynes@359
  1123
nkeynes@359
  1124
FSRRA FRn {:
nkeynes@359
  1125
    CHECKFPUEN();
nkeynes@359
  1126
    if( !IS_FPU_DOUBLEPREC() ) {
nkeynes@359
  1127
	FR(FRn) = 1.0/sqrtf(FR(FRn));
nkeynes@359
  1128
    }
nkeynes@359
  1129
:}
nkeynes@359
  1130
FIPR FVm, FVn {:
nkeynes@359
  1131
    CHECKFPUEN();
nkeynes@359
  1132
    if( !IS_FPU_DOUBLEPREC() ) {
nkeynes@359
  1133
        int tmp2 = FVn<<2;
nkeynes@359
  1134
        tmp = FVm<<2;
nkeynes@359
  1135
        FR(tmp2+3) = FR(tmp)*FR(tmp2) +
nkeynes@359
  1136
            FR(tmp+1)*FR(tmp2+1) +
nkeynes@359
  1137
            FR(tmp+2)*FR(tmp2+2) +
nkeynes@359
  1138
            FR(tmp+3)*FR(tmp2+3);
nkeynes@359
  1139
    }
nkeynes@359
  1140
:}
nkeynes@359
  1141
FSCA FPUL, FRn {:
nkeynes@359
  1142
    CHECKFPUEN();
nkeynes@359
  1143
    if( !IS_FPU_DOUBLEPREC() ) {
nkeynes@391
  1144
	sh4_fsca( FPULi, &(DRF(FRn>>1)) );
nkeynes@391
  1145
	/*
nkeynes@359
  1146
        float angle = (((float)(FPULi&0xFFFF))/65536.0) * 2 * M_PI;
nkeynes@359
  1147
        FR(FRn) = sinf(angle);
nkeynes@359
  1148
        FR((FRn)+1) = cosf(angle);
nkeynes@391
  1149
	*/
nkeynes@359
  1150
    }
nkeynes@359
  1151
:}
nkeynes@359
  1152
FTRV XMTRX, FVn {:
nkeynes@359
  1153
    CHECKFPUEN();
nkeynes@359
  1154
    if( !IS_FPU_DOUBLEPREC() ) {
nkeynes@669
  1155
	sh4_ftrv(&(DRF(FVn<<1)) );
nkeynes@359
  1156
    }
nkeynes@359
  1157
:}
nkeynes@359
  1158
UNDEF {:
nkeynes@359
  1159
    UNDEF(ir);
nkeynes@359
  1160
:}
nkeynes@359
  1161
%%
nkeynes@359
  1162
    sh4r.pc = sh4r.new_pc;
nkeynes@359
  1163
    sh4r.new_pc += 2;
nkeynes@359
  1164
    sh4r.in_delay_slot = 0;
nkeynes@359
  1165
    return TRUE;
nkeynes@359
  1166
}
.