Search
lxdream.org :: lxdream/src/sh4/sh4core.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/sh4/sh4core.c
changeset 374:8f80a795513e
prev369:4b4223e7d720
next378:f10fbdd4e24b
author nkeynes
date Tue Sep 11 02:14:46 2007 +0000 (13 years ago)
permissions -rw-r--r--
last change Cache the pointer to the last FR bank (speeds fp ops up by about 10%)
Implement experimental fix for FLOAT/FTRC
Make read/write sr functions non-static (share with translator)
Much more translator WIP
file annotate diff log raw
nkeynes@23
     1
/**
nkeynes@374
     2
 * $Id: sh4core.c,v 1.44 2007-09-11 02:14:46 nkeynes Exp $
nkeynes@23
     3
 * 
nkeynes@23
     4
 * SH4 emulation core, and parent module for all the SH4 peripheral
nkeynes@23
     5
 * modules.
nkeynes@23
     6
 *
nkeynes@23
     7
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@23
     8
 *
nkeynes@23
     9
 * This program is free software; you can redistribute it and/or modify
nkeynes@23
    10
 * it under the terms of the GNU General Public License as published by
nkeynes@23
    11
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@23
    12
 * (at your option) any later version.
nkeynes@23
    13
 *
nkeynes@23
    14
 * This program is distributed in the hope that it will be useful,
nkeynes@23
    15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@23
    16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@23
    17
 * GNU General Public License for more details.
nkeynes@23
    18
 */
nkeynes@23
    19
nkeynes@35
    20
#define MODULE sh4_module
nkeynes@1
    21
#include <math.h>
nkeynes@1
    22
#include "dream.h"
nkeynes@84
    23
#include "sh4/sh4core.h"
nkeynes@84
    24
#include "sh4/sh4mmio.h"
nkeynes@84
    25
#include "sh4/intc.h"
nkeynes@1
    26
#include "mem.h"
nkeynes@23
    27
#include "clock.h"
nkeynes@102
    28
#include "syscall.h"
nkeynes@1
    29
nkeynes@157
    30
#define SH4_CALLTRACE 1
nkeynes@157
    31
nkeynes@123
    32
#define MAX_INT 0x7FFFFFFF
nkeynes@123
    33
#define MIN_INT 0x80000000
nkeynes@123
    34
#define MAX_INTF 2147483647.0
nkeynes@123
    35
#define MIN_INTF -2147483648.0
nkeynes@123
    36
nkeynes@246
    37
#define EXV_EXCEPTION    0x100  /* General exception vector */
nkeynes@246
    38
#define EXV_TLBMISS      0x400  /* TLB-miss exception vector */
nkeynes@246
    39
#define EXV_INTERRUPT    0x600  /* External interrupt vector */
nkeynes@27
    40
nkeynes@23
    41
/********************** SH4 Module Definition ****************************/
nkeynes@23
    42
nkeynes@23
    43
void sh4_init( void );
nkeynes@23
    44
void sh4_reset( void );
nkeynes@30
    45
uint32_t sh4_run_slice( uint32_t );
nkeynes@23
    46
void sh4_start( void );
nkeynes@23
    47
void sh4_stop( void );
nkeynes@23
    48
void sh4_save_state( FILE *f );
nkeynes@23
    49
int sh4_load_state( FILE *f );
nkeynes@359
    50
void sh4_accept_interrupt( void );
nkeynes@16
    51
nkeynes@15
    52
struct dreamcast_module sh4_module = { "SH4", sh4_init, sh4_reset, 
nkeynes@23
    53
				       NULL, sh4_run_slice, sh4_stop,
nkeynes@23
    54
				       sh4_save_state, sh4_load_state };
nkeynes@15
    55
nkeynes@1
    56
struct sh4_registers sh4r;
nkeynes@1
    57
nkeynes@1
    58
void sh4_init(void)
nkeynes@1
    59
{
nkeynes@1
    60
    register_io_regions( mmio_list_sh4mmio );
nkeynes@312
    61
    MMU_init();
nkeynes@27
    62
    sh4_reset();
nkeynes@1
    63
}
nkeynes@1
    64
nkeynes@1
    65
void sh4_reset(void)
nkeynes@1
    66
{
nkeynes@19
    67
    /* zero everything out, for the sake of having a consistent state. */
nkeynes@19
    68
    memset( &sh4r, 0, sizeof(sh4r) );
nkeynes@27
    69
nkeynes@27
    70
    /* Resume running if we were halted */
nkeynes@27
    71
    sh4r.sh4_state = SH4_STATE_RUNNING;
nkeynes@27
    72
nkeynes@1
    73
    sh4r.pc    = 0xA0000000;
nkeynes@1
    74
    sh4r.new_pc= 0xA0000002;
nkeynes@1
    75
    sh4r.vbr   = 0x00000000;
nkeynes@1
    76
    sh4r.fpscr = 0x00040001;
nkeynes@1
    77
    sh4r.sr    = 0x700000F0;
nkeynes@374
    78
    sh4r.fr_bank = &sh4r.fr[0][0];
nkeynes@27
    79
nkeynes@27
    80
    /* Mem reset will do this, but if we want to reset _just_ the SH4... */
nkeynes@27
    81
    MMIO_WRITE( MMU, EXPEVT, EXC_POWER_RESET );
nkeynes@27
    82
nkeynes@27
    83
    /* Peripheral modules */
nkeynes@260
    84
    CPG_reset();
nkeynes@157
    85
    INTC_reset();
nkeynes@312
    86
    MMU_reset();
nkeynes@157
    87
    TMU_reset();
nkeynes@32
    88
    SCIF_reset();
nkeynes@1
    89
}
nkeynes@1
    90
nkeynes@43
    91
static struct breakpoint_struct sh4_breakpoints[MAX_BREAKPOINTS];
nkeynes@43
    92
static int sh4_breakpoint_count = 0;
nkeynes@235
    93
static uint16_t *sh4_icache = NULL;
nkeynes@235
    94
static uint32_t sh4_icache_addr = 0;
nkeynes@43
    95
nkeynes@43
    96
void sh4_set_breakpoint( uint32_t pc, int type )
nkeynes@43
    97
{
nkeynes@43
    98
    sh4_breakpoints[sh4_breakpoint_count].address = pc;
nkeynes@43
    99
    sh4_breakpoints[sh4_breakpoint_count].type = type;
nkeynes@43
   100
    sh4_breakpoint_count++;
nkeynes@43
   101
}
nkeynes@43
   102
nkeynes@43
   103
gboolean sh4_clear_breakpoint( uint32_t pc, int type )
nkeynes@43
   104
{
nkeynes@43
   105
    int i;
nkeynes@43
   106
nkeynes@43
   107
    for( i=0; i<sh4_breakpoint_count; i++ ) {
nkeynes@43
   108
	if( sh4_breakpoints[i].address == pc && 
nkeynes@43
   109
	    sh4_breakpoints[i].type == type ) {
nkeynes@43
   110
	    while( ++i < sh4_breakpoint_count ) {
nkeynes@43
   111
		sh4_breakpoints[i-1].address = sh4_breakpoints[i].address;
nkeynes@43
   112
		sh4_breakpoints[i-1].type = sh4_breakpoints[i].type;
nkeynes@43
   113
	    }
nkeynes@43
   114
	    sh4_breakpoint_count--;
nkeynes@43
   115
	    return TRUE;
nkeynes@43
   116
	}
nkeynes@43
   117
    }
nkeynes@43
   118
    return FALSE;
nkeynes@43
   119
}
nkeynes@43
   120
nkeynes@43
   121
int sh4_get_breakpoint( uint32_t pc )
nkeynes@43
   122
{
nkeynes@43
   123
    int i;
nkeynes@43
   124
    for( i=0; i<sh4_breakpoint_count; i++ ) {
nkeynes@43
   125
	if( sh4_breakpoints[i].address == pc )
nkeynes@43
   126
	    return sh4_breakpoints[i].type;
nkeynes@43
   127
    }
nkeynes@43
   128
    return 0;
nkeynes@43
   129
}
nkeynes@43
   130
nkeynes@30
   131
uint32_t sh4_run_slice( uint32_t nanosecs ) 
nkeynes@1
   132
{
nkeynes@23
   133
    int i;
nkeynes@265
   134
    sh4r.slice_cycle = 0;
nkeynes@23
   135
nkeynes@27
   136
    if( sh4r.sh4_state != SH4_STATE_RUNNING ) {
nkeynes@265
   137
	if( sh4r.event_pending < nanosecs ) {
nkeynes@265
   138
	    sh4r.sh4_state = SH4_STATE_RUNNING;
nkeynes@265
   139
	    sh4r.slice_cycle = sh4r.event_pending;
nkeynes@265
   140
	}
nkeynes@23
   141
    }
nkeynes@27
   142
nkeynes@235
   143
    if( sh4_breakpoint_count == 0 ) {
nkeynes@265
   144
	for( ; sh4r.slice_cycle < nanosecs; sh4r.slice_cycle += sh4_cpu_period ) {
nkeynes@265
   145
	    if( SH4_EVENT_PENDING() ) {
nkeynes@265
   146
		if( sh4r.event_types & PENDING_EVENT ) {
nkeynes@265
   147
		    event_execute();
nkeynes@265
   148
		}
nkeynes@265
   149
		/* Eventq execute may (quite likely) deliver an immediate IRQ */
nkeynes@265
   150
		if( sh4r.event_types & PENDING_IRQ ) {
nkeynes@265
   151
		    sh4_accept_interrupt();
nkeynes@265
   152
		}
nkeynes@265
   153
	    }
nkeynes@235
   154
	    if( !sh4_execute_instruction() ) {
nkeynes@43
   155
		break;
nkeynes@43
   156
	    }
nkeynes@43
   157
	}
nkeynes@235
   158
    } else {
nkeynes@265
   159
	for( ;sh4r.slice_cycle < nanosecs; sh4r.slice_cycle += sh4_cpu_period ) {
nkeynes@265
   160
	    if( SH4_EVENT_PENDING() ) {
nkeynes@265
   161
		if( sh4r.event_types & PENDING_EVENT ) {
nkeynes@265
   162
		    event_execute();
nkeynes@265
   163
		}
nkeynes@265
   164
		/* Eventq execute may (quite likely) deliver an immediate IRQ */
nkeynes@265
   165
		if( sh4r.event_types & PENDING_IRQ ) {
nkeynes@265
   166
		    sh4_accept_interrupt();
nkeynes@265
   167
		}
nkeynes@265
   168
	    }
nkeynes@265
   169
                 
nkeynes@235
   170
	    if( !sh4_execute_instruction() )
nkeynes@235
   171
		break;
nkeynes@235
   172
#ifdef ENABLE_DEBUG_MODE
nkeynes@235
   173
	    for( i=0; i<sh4_breakpoint_count; i++ ) {
nkeynes@235
   174
		if( sh4_breakpoints[i].address == sh4r.pc ) {
nkeynes@235
   175
		    break;
nkeynes@235
   176
		}
nkeynes@235
   177
	    }
nkeynes@235
   178
	    if( i != sh4_breakpoint_count ) {
nkeynes@235
   179
		dreamcast_stop();
nkeynes@235
   180
		if( sh4_breakpoints[i].type == BREAK_ONESHOT )
nkeynes@235
   181
		    sh4_clear_breakpoint( sh4r.pc, BREAK_ONESHOT );
nkeynes@235
   182
		break;
nkeynes@235
   183
	    }
nkeynes@235
   184
#endif	
nkeynes@43
   185
	}
nkeynes@27
   186
    }
nkeynes@30
   187
nkeynes@30
   188
    /* If we aborted early, but the cpu is still technically running,
nkeynes@30
   189
     * we're doing a hard abort - cut the timeslice back to what we
nkeynes@30
   190
     * actually executed
nkeynes@30
   191
     */
nkeynes@53
   192
    if( sh4r.slice_cycle != nanosecs && sh4r.sh4_state == SH4_STATE_RUNNING ) {
nkeynes@53
   193
	nanosecs = sh4r.slice_cycle;
nkeynes@27
   194
    }
nkeynes@27
   195
    if( sh4r.sh4_state != SH4_STATE_STANDBY ) {
nkeynes@30
   196
	TMU_run_slice( nanosecs );
nkeynes@30
   197
	SCIF_run_slice( nanosecs );
nkeynes@27
   198
    }
nkeynes@30
   199
    return nanosecs;
nkeynes@1
   200
}
nkeynes@1
   201
nkeynes@1
   202
void sh4_stop(void)
nkeynes@1
   203
{
nkeynes@27
   204
nkeynes@1
   205
}
nkeynes@1
   206
nkeynes@23
   207
void sh4_save_state( FILE *f )
nkeynes@16
   208
{
nkeynes@16
   209
    fwrite( &sh4r, sizeof(sh4r), 1, f );
nkeynes@312
   210
    MMU_save_state( f );
nkeynes@157
   211
    INTC_save_state( f );
nkeynes@53
   212
    TMU_save_state( f );
nkeynes@23
   213
    SCIF_save_state( f );
nkeynes@16
   214
}
nkeynes@16
   215
nkeynes@23
   216
int sh4_load_state( FILE * f )
nkeynes@16
   217
{
nkeynes@18
   218
    fread( &sh4r, sizeof(sh4r), 1, f );
nkeynes@312
   219
    MMU_load_state( f );
nkeynes@157
   220
    INTC_load_state( f );
nkeynes@53
   221
    TMU_load_state( f );
nkeynes@23
   222
    return SCIF_load_state( f );
nkeynes@16
   223
}
nkeynes@16
   224
nkeynes@23
   225
/********************** SH4 emulation core  ****************************/
nkeynes@23
   226
nkeynes@23
   227
void sh4_set_pc( int pc )
nkeynes@23
   228
{
nkeynes@23
   229
    sh4r.pc = pc;
nkeynes@23
   230
    sh4r.new_pc = pc+2;
nkeynes@23
   231
}
nkeynes@23
   232
nkeynes@246
   233
#define UNDEF(ir) return sh4_raise_slot_exception(EXC_ILLEGAL, EXC_SLOT_ILLEGAL)
nkeynes@27
   234
#define UNIMP(ir) do{ ERROR( "Halted on unimplemented instruction at %08x, opcode = %04x", sh4r.pc, ir ); dreamcast_stop(); return FALSE; }while(0)
nkeynes@1
   235
nkeynes@157
   236
#if(SH4_CALLTRACE == 1)
nkeynes@157
   237
#define MAX_CALLSTACK 32
nkeynes@157
   238
static struct call_stack {
nkeynes@157
   239
    sh4addr_t call_addr;
nkeynes@157
   240
    sh4addr_t target_addr;
nkeynes@157
   241
    sh4addr_t stack_pointer;
nkeynes@157
   242
} call_stack[MAX_CALLSTACK];
nkeynes@157
   243
nkeynes@157
   244
static int call_stack_depth = 0;
nkeynes@157
   245
int sh4_call_trace_on = 0;
nkeynes@157
   246
nkeynes@157
   247
static inline trace_call( sh4addr_t source, sh4addr_t dest ) 
nkeynes@157
   248
{
nkeynes@157
   249
    if( call_stack_depth < MAX_CALLSTACK ) {
nkeynes@157
   250
	call_stack[call_stack_depth].call_addr = source;
nkeynes@157
   251
	call_stack[call_stack_depth].target_addr = dest;
nkeynes@157
   252
	call_stack[call_stack_depth].stack_pointer = sh4r.r[15];
nkeynes@157
   253
    }
nkeynes@157
   254
    call_stack_depth++;
nkeynes@157
   255
}
nkeynes@157
   256
nkeynes@157
   257
static inline trace_return( sh4addr_t source, sh4addr_t dest )
nkeynes@157
   258
{
nkeynes@157
   259
    if( call_stack_depth > 0 ) {
nkeynes@157
   260
	call_stack_depth--;
nkeynes@157
   261
    }
nkeynes@157
   262
}
nkeynes@157
   263
nkeynes@157
   264
void fprint_stack_trace( FILE *f )
nkeynes@157
   265
{
nkeynes@157
   266
    int i = call_stack_depth -1;
nkeynes@157
   267
    if( i >= MAX_CALLSTACK )
nkeynes@157
   268
	i = MAX_CALLSTACK - 1;
nkeynes@157
   269
    for( ; i >= 0; i-- ) {
nkeynes@157
   270
	fprintf( f, "%d. Call from %08X => %08X, SP=%08X\n", 
nkeynes@157
   271
		 (call_stack_depth - i), call_stack[i].call_addr,
nkeynes@157
   272
		 call_stack[i].target_addr, call_stack[i].stack_pointer );
nkeynes@157
   273
    }
nkeynes@157
   274
}
nkeynes@157
   275
nkeynes@157
   276
#define TRACE_CALL( source, dest ) trace_call(source, dest)
nkeynes@157
   277
#define TRACE_RETURN( source, dest ) trace_return(source, dest)
nkeynes@157
   278
#else
nkeynes@157
   279
#define TRACE_CALL( dest, rts ) 
nkeynes@157
   280
#define TRACE_RETURN( source, dest )
nkeynes@157
   281
#endif
nkeynes@157
   282
nkeynes@246
   283
#define RAISE( x, v ) do{			\
nkeynes@1
   284
    if( sh4r.vbr == 0 ) { \
nkeynes@1
   285
        ERROR( "%08X: VBR not initialized while raising exception %03X, halting", sh4r.pc, x ); \
nkeynes@104
   286
        dreamcast_stop(); return FALSE;	\
nkeynes@1
   287
    } else { \
nkeynes@246
   288
        sh4r.spc = sh4r.pc;	\
nkeynes@1
   289
        sh4r.ssr = sh4_read_sr(); \
nkeynes@1
   290
        sh4r.sgr = sh4r.r[15]; \
nkeynes@1
   291
        MMIO_WRITE(MMU,EXPEVT,x); \
nkeynes@1
   292
        sh4r.pc = sh4r.vbr + v; \
nkeynes@1
   293
        sh4r.new_pc = sh4r.pc + 2; \
nkeynes@374
   294
        sh4_write_sr( sh4r.ssr |SR_MD|SR_BL|SR_RB ); \
nkeynes@246
   295
	if( sh4r.in_delay_slot ) { \
nkeynes@246
   296
	    sh4r.in_delay_slot = 0; \
nkeynes@246
   297
	    sh4r.spc -= 2; \
nkeynes@246
   298
	} \
nkeynes@1
   299
    } \
nkeynes@27
   300
    return TRUE; } while(0)
nkeynes@229
   301
nkeynes@10
   302
#define MEM_READ_BYTE( addr ) sh4_read_byte(addr)
nkeynes@10
   303
#define MEM_READ_WORD( addr ) sh4_read_word(addr)
nkeynes@10
   304
#define MEM_READ_LONG( addr ) sh4_read_long(addr)
nkeynes@10
   305
#define MEM_WRITE_BYTE( addr, val ) sh4_write_byte(addr, val)
nkeynes@10
   306
#define MEM_WRITE_WORD( addr, val ) sh4_write_word(addr, val)
nkeynes@10
   307
#define MEM_WRITE_LONG( addr, val ) sh4_write_long(addr, val)
nkeynes@1
   308
nkeynes@1
   309
#define FP_WIDTH (IS_FPU_DOUBLESIZE() ? 8 : 4)
nkeynes@1
   310
nkeynes@124
   311
#define MEM_FP_READ( addr, reg ) sh4_read_float( addr, reg );
nkeynes@124
   312
#define MEM_FP_WRITE( addr, reg ) sh4_write_float( addr, reg );
nkeynes@84
   313
nkeynes@246
   314
#define CHECKPRIV() if( !IS_SH4_PRIVMODE() ) return sh4_raise_slot_exception( EXC_ILLEGAL, EXC_SLOT_ILLEGAL )
nkeynes@367
   315
#define CHECKRALIGN16(addr) if( (addr)&0x01 ) return sh4_raise_exception( EXC_DATA_ADDR_READ )
nkeynes@367
   316
#define CHECKRALIGN32(addr) if( (addr)&0x03 ) return sh4_raise_exception( EXC_DATA_ADDR_READ )
nkeynes@367
   317
#define CHECKWALIGN16(addr) if( (addr)&0x01 ) return sh4_raise_exception( EXC_DATA_ADDR_WRITE )
nkeynes@367
   318
#define CHECKWALIGN32(addr) if( (addr)&0x03 ) return sh4_raise_exception( EXC_DATA_ADDR_WRITE )
nkeynes@208
   319
nkeynes@367
   320
#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@84
   321
#define CHECKDEST(p) if( (p) == 0 ) { ERROR( "%08X: Branch/jump to NULL, CPU halted", sh4r.pc ); dreamcast_stop(); return FALSE; }
nkeynes@246
   322
#define CHECKSLOTILLEGAL() if(sh4r.in_delay_slot) return sh4_raise_exception(EXC_SLOT_ILLEGAL)
nkeynes@1
   323
nkeynes@1
   324
static void sh4_switch_banks( )
nkeynes@1
   325
{
nkeynes@1
   326
    uint32_t tmp[8];
nkeynes@1
   327
nkeynes@1
   328
    memcpy( tmp, sh4r.r, sizeof(uint32_t)*8 );
nkeynes@1
   329
    memcpy( sh4r.r, sh4r.r_bank, sizeof(uint32_t)*8 );
nkeynes@1
   330
    memcpy( sh4r.r_bank, tmp, sizeof(uint32_t)*8 );
nkeynes@1
   331
}
nkeynes@1
   332
nkeynes@374
   333
void sh4_write_sr( uint32_t newval )
nkeynes@1
   334
{
nkeynes@1
   335
    if( (newval ^ sh4r.sr) & SR_RB )
nkeynes@1
   336
        sh4_switch_banks();
nkeynes@1
   337
    sh4r.sr = newval;
nkeynes@1
   338
    sh4r.t = (newval&SR_T) ? 1 : 0;
nkeynes@1
   339
    sh4r.s = (newval&SR_S) ? 1 : 0;
nkeynes@1
   340
    sh4r.m = (newval&SR_M) ? 1 : 0;
nkeynes@1
   341
    sh4r.q = (newval&SR_Q) ? 1 : 0;
nkeynes@1
   342
    intc_mask_changed();
nkeynes@1
   343
}
nkeynes@1
   344
nkeynes@124
   345
static void sh4_write_float( uint32_t addr, int reg )
nkeynes@124
   346
{
nkeynes@124
   347
    if( IS_FPU_DOUBLESIZE() ) {
nkeynes@124
   348
	if( reg & 1 ) {
nkeynes@124
   349
	    sh4_write_long( addr, *((uint32_t *)&XF((reg)&0x0E)) );
nkeynes@124
   350
	    sh4_write_long( addr+4, *((uint32_t *)&XF(reg)) );
nkeynes@124
   351
	} else {
nkeynes@124
   352
	    sh4_write_long( addr, *((uint32_t *)&FR(reg)) ); 
nkeynes@124
   353
	    sh4_write_long( addr+4, *((uint32_t *)&FR((reg)|0x01)) );
nkeynes@124
   354
	}
nkeynes@124
   355
    } else {
nkeynes@124
   356
	sh4_write_long( addr, *((uint32_t *)&FR((reg))) );
nkeynes@124
   357
    }
nkeynes@124
   358
}
nkeynes@124
   359
nkeynes@124
   360
static void sh4_read_float( uint32_t addr, int reg )
nkeynes@124
   361
{
nkeynes@124
   362
    if( IS_FPU_DOUBLESIZE() ) {
nkeynes@124
   363
	if( reg & 1 ) {
nkeynes@124
   364
	    *((uint32_t *)&XF((reg) & 0x0E)) = sh4_read_long(addr);
nkeynes@124
   365
	    *((uint32_t *)&XF(reg)) = sh4_read_long(addr+4);
nkeynes@124
   366
	} else {
nkeynes@124
   367
	    *((uint32_t *)&FR(reg)) = sh4_read_long(addr);
nkeynes@124
   368
	    *((uint32_t *)&FR((reg) | 0x01)) = sh4_read_long(addr+4);
nkeynes@124
   369
	}
nkeynes@124
   370
    } else {
nkeynes@124
   371
	*((uint32_t *)&FR(reg)) = sh4_read_long(addr);
nkeynes@124
   372
    }
nkeynes@124
   373
}
nkeynes@124
   374
nkeynes@374
   375
uint32_t sh4_read_sr( void )
nkeynes@1
   376
{
nkeynes@1
   377
    /* synchronize sh4r.sr with the various bitflags */
nkeynes@1
   378
    sh4r.sr &= SR_MQSTMASK;
nkeynes@1
   379
    if( sh4r.t ) sh4r.sr |= SR_T;
nkeynes@1
   380
    if( sh4r.s ) sh4r.sr |= SR_S;
nkeynes@1
   381
    if( sh4r.m ) sh4r.sr |= SR_M;
nkeynes@1
   382
    if( sh4r.q ) sh4r.sr |= SR_Q;
nkeynes@1
   383
    return sh4r.sr;
nkeynes@1
   384
}
nkeynes@246
   385
nkeynes@246
   386
/**
nkeynes@246
   387
 * Raise a general CPU exception for the specified exception code.
nkeynes@246
   388
 * (NOT for TRAPA or TLB exceptions)
nkeynes@246
   389
 */
nkeynes@246
   390
gboolean sh4_raise_exception( int code )
nkeynes@1
   391
{
nkeynes@246
   392
    RAISE( code, EXV_EXCEPTION );
nkeynes@246
   393
}
nkeynes@246
   394
nkeynes@246
   395
gboolean sh4_raise_slot_exception( int normal_code, int slot_code ) {
nkeynes@246
   396
    if( sh4r.in_delay_slot ) {
nkeynes@246
   397
	return sh4_raise_exception(slot_code);
nkeynes@246
   398
    } else {
nkeynes@246
   399
	return sh4_raise_exception(normal_code);
nkeynes@246
   400
    }
nkeynes@246
   401
}
nkeynes@246
   402
nkeynes@246
   403
gboolean sh4_raise_tlb_exception( int code )
nkeynes@246
   404
{
nkeynes@246
   405
    RAISE( code, EXV_TLBMISS );
nkeynes@1
   406
}
nkeynes@1
   407
nkeynes@359
   408
void sh4_accept_interrupt( void )
nkeynes@1
   409
{
nkeynes@1
   410
    uint32_t code = intc_accept_interrupt();
nkeynes@1
   411
    sh4r.ssr = sh4_read_sr();
nkeynes@1
   412
    sh4r.spc = sh4r.pc;
nkeynes@1
   413
    sh4r.sgr = sh4r.r[15];
nkeynes@374
   414
    sh4_write_sr( sh4r.ssr|SR_BL|SR_MD|SR_RB );
nkeynes@1
   415
    MMIO_WRITE( MMU, INTEVT, code );
nkeynes@1
   416
    sh4r.pc = sh4r.vbr + 0x600;
nkeynes@1
   417
    sh4r.new_pc = sh4r.pc + 2;
nkeynes@92
   418
    //    WARN( "Accepting interrupt %03X, from %08X => %08X", code, sh4r.spc, sh4r.pc );
nkeynes@1
   419
}
nkeynes@1
   420
nkeynes@27
   421
gboolean sh4_execute_instruction( void )
nkeynes@1
   422
{
nkeynes@84
   423
    uint32_t pc;
nkeynes@2
   424
    unsigned short ir;
nkeynes@1
   425
    uint32_t tmp;
nkeynes@123
   426
    float ftmp;
nkeynes@123
   427
    double dtmp;
nkeynes@1
   428
    
nkeynes@1
   429
#define R0 sh4r.r[0]
nkeynes@2
   430
    pc = sh4r.pc;
nkeynes@84
   431
    if( pc > 0xFFFFFF00 ) {
nkeynes@84
   432
	/* SYSCALL Magic */
nkeynes@102
   433
	syscall_invoke( pc );
nkeynes@104
   434
	sh4r.in_delay_slot = 0;
nkeynes@84
   435
	pc = sh4r.pc = sh4r.pr;
nkeynes@84
   436
	sh4r.new_pc = sh4r.pc + 2;
nkeynes@84
   437
    }
nkeynes@208
   438
    CHECKRALIGN16(pc);
nkeynes@235
   439
nkeynes@235
   440
    /* Read instruction */
nkeynes@235
   441
    uint32_t pageaddr = pc >> 12;
nkeynes@235
   442
    if( sh4_icache != NULL && pageaddr == sh4_icache_addr ) {
nkeynes@235
   443
	ir = sh4_icache[(pc&0xFFF)>>1];
nkeynes@235
   444
    } else {
nkeynes@235
   445
	sh4_icache = (uint16_t *)mem_get_page(pc);
nkeynes@235
   446
	if( ((uint32_t)sh4_icache) < MAX_IO_REGIONS ) {
nkeynes@235
   447
	    /* If someone's actually been so daft as to try to execute out of an IO
nkeynes@235
   448
	     * region, fallback on the full-blown memory read
nkeynes@235
   449
	     */
nkeynes@235
   450
	    sh4_icache = NULL;
nkeynes@235
   451
	    ir = MEM_READ_WORD(pc);
nkeynes@235
   452
	} else {
nkeynes@235
   453
	    sh4_icache_addr = pageaddr;
nkeynes@235
   454
	    ir = sh4_icache[(pc&0xFFF)>>1];
nkeynes@235
   455
	}
nkeynes@235
   456
    }
nkeynes@359
   457
        switch( (ir&0xF000) >> 12 ) {
nkeynes@359
   458
            case 0x0:
nkeynes@359
   459
                switch( ir&0xF ) {
nkeynes@359
   460
                    case 0x2:
nkeynes@359
   461
                        switch( (ir&0x80) >> 7 ) {
nkeynes@359
   462
                            case 0x0:
nkeynes@359
   463
                                switch( (ir&0x70) >> 4 ) {
nkeynes@359
   464
                                    case 0x0:
nkeynes@359
   465
                                        { /* STC SR, Rn */
nkeynes@359
   466
                                        uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   467
                                        CHECKPRIV();
nkeynes@359
   468
                                        sh4r.r[Rn] = sh4_read_sr();
nkeynes@359
   469
                                        }
nkeynes@359
   470
                                        break;
nkeynes@359
   471
                                    case 0x1:
nkeynes@359
   472
                                        { /* STC GBR, Rn */
nkeynes@359
   473
                                        uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   474
                                        CHECKPRIV();
nkeynes@359
   475
                                        sh4r.r[Rn] = sh4r.gbr;
nkeynes@359
   476
                                        }
nkeynes@359
   477
                                        break;
nkeynes@359
   478
                                    case 0x2:
nkeynes@359
   479
                                        { /* STC VBR, Rn */
nkeynes@359
   480
                                        uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   481
                                        CHECKPRIV();
nkeynes@359
   482
                                        sh4r.r[Rn] = sh4r.vbr;
nkeynes@359
   483
                                        }
nkeynes@359
   484
                                        break;
nkeynes@359
   485
                                    case 0x3:
nkeynes@359
   486
                                        { /* STC SSR, Rn */
nkeynes@359
   487
                                        uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   488
                                        CHECKPRIV();
nkeynes@359
   489
                                        sh4r.r[Rn] = sh4r.ssr;
nkeynes@359
   490
                                        }
nkeynes@359
   491
                                        break;
nkeynes@359
   492
                                    case 0x4:
nkeynes@359
   493
                                        { /* STC SPC, Rn */
nkeynes@359
   494
                                        uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   495
                                        CHECKPRIV();
nkeynes@359
   496
                                        sh4r.r[Rn] = sh4r.spc;
nkeynes@359
   497
                                        }
nkeynes@359
   498
                                        break;
nkeynes@359
   499
                                    default:
nkeynes@359
   500
                                        UNDEF();
nkeynes@359
   501
                                        break;
nkeynes@359
   502
                                }
nkeynes@359
   503
                                break;
nkeynes@359
   504
                            case 0x1:
nkeynes@359
   505
                                { /* STC Rm_BANK, Rn */
nkeynes@359
   506
                                uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm_BANK = ((ir>>4)&0x7); 
nkeynes@359
   507
                                CHECKPRIV();
nkeynes@359
   508
                                sh4r.r[Rn] = sh4r.r_bank[Rm_BANK];
nkeynes@359
   509
                                }
nkeynes@359
   510
                                break;
nkeynes@359
   511
                        }
nkeynes@359
   512
                        break;
nkeynes@359
   513
                    case 0x3:
nkeynes@359
   514
                        switch( (ir&0xF0) >> 4 ) {
nkeynes@359
   515
                            case 0x0:
nkeynes@359
   516
                                { /* BSRF Rn */
nkeynes@359
   517
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   518
                                CHECKSLOTILLEGAL();
nkeynes@359
   519
                                CHECKDEST( pc + 4 + sh4r.r[Rn] );
nkeynes@359
   520
                                sh4r.in_delay_slot = 1;
nkeynes@359
   521
                                sh4r.pr = sh4r.pc + 4;
nkeynes@359
   522
                                sh4r.pc = sh4r.new_pc;
nkeynes@359
   523
                                sh4r.new_pc = pc + 4 + sh4r.r[Rn];
nkeynes@359
   524
                                TRACE_CALL( pc, sh4r.new_pc );
nkeynes@359
   525
                                return TRUE;
nkeynes@359
   526
                                }
nkeynes@359
   527
                                break;
nkeynes@359
   528
                            case 0x2:
nkeynes@359
   529
                                { /* BRAF Rn */
nkeynes@359
   530
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   531
                                CHECKSLOTILLEGAL();
nkeynes@359
   532
                                CHECKDEST( pc + 4 + sh4r.r[Rn] );
nkeynes@359
   533
                                sh4r.in_delay_slot = 1;
nkeynes@359
   534
                                sh4r.pc = sh4r.new_pc;
nkeynes@359
   535
                                sh4r.new_pc = pc + 4 + sh4r.r[Rn];
nkeynes@359
   536
                                return TRUE;
nkeynes@359
   537
                                }
nkeynes@359
   538
                                break;
nkeynes@359
   539
                            case 0x8:
nkeynes@359
   540
                                { /* PREF @Rn */
nkeynes@359
   541
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   542
                                tmp = sh4r.r[Rn];
nkeynes@359
   543
                                if( (tmp & 0xFC000000) == 0xE0000000 ) {
nkeynes@369
   544
                           	 sh4_flush_store_queue(tmp);
nkeynes@359
   545
                                }
nkeynes@359
   546
                                }
nkeynes@359
   547
                                break;
nkeynes@359
   548
                            case 0x9:
nkeynes@359
   549
                                { /* OCBI @Rn */
nkeynes@359
   550
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   551
                                }
nkeynes@359
   552
                                break;
nkeynes@359
   553
                            case 0xA:
nkeynes@359
   554
                                { /* OCBP @Rn */
nkeynes@359
   555
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   556
                                }
nkeynes@359
   557
                                break;
nkeynes@359
   558
                            case 0xB:
nkeynes@359
   559
                                { /* OCBWB @Rn */
nkeynes@359
   560
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   561
                                }
nkeynes@359
   562
                                break;
nkeynes@359
   563
                            case 0xC:
nkeynes@359
   564
                                { /* MOVCA.L R0, @Rn */
nkeynes@359
   565
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   566
                                tmp = sh4r.r[Rn];
nkeynes@359
   567
                                CHECKWALIGN32(tmp);
nkeynes@359
   568
                                MEM_WRITE_LONG( tmp, R0 );
nkeynes@359
   569
                                }
nkeynes@359
   570
                                break;
nkeynes@359
   571
                            default:
nkeynes@359
   572
                                UNDEF();
nkeynes@359
   573
                                break;
nkeynes@359
   574
                        }
nkeynes@359
   575
                        break;
nkeynes@359
   576
                    case 0x4:
nkeynes@359
   577
                        { /* MOV.B Rm, @(R0, Rn) */
nkeynes@359
   578
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   579
                        MEM_WRITE_BYTE( R0 + sh4r.r[Rn], sh4r.r[Rm] );
nkeynes@359
   580
                        }
nkeynes@359
   581
                        break;
nkeynes@359
   582
                    case 0x5:
nkeynes@359
   583
                        { /* MOV.W Rm, @(R0, Rn) */
nkeynes@359
   584
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   585
                        CHECKWALIGN16( R0 + sh4r.r[Rn] );
nkeynes@359
   586
                        MEM_WRITE_WORD( R0 + sh4r.r[Rn], sh4r.r[Rm] );
nkeynes@359
   587
                        }
nkeynes@359
   588
                        break;
nkeynes@359
   589
                    case 0x6:
nkeynes@359
   590
                        { /* MOV.L Rm, @(R0, Rn) */
nkeynes@359
   591
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   592
                        CHECKWALIGN32( R0 + sh4r.r[Rn] );
nkeynes@359
   593
                        MEM_WRITE_LONG( R0 + sh4r.r[Rn], sh4r.r[Rm] );
nkeynes@359
   594
                        }
nkeynes@359
   595
                        break;
nkeynes@359
   596
                    case 0x7:
nkeynes@359
   597
                        { /* MUL.L Rm, Rn */
nkeynes@359
   598
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   599
                        sh4r.mac = (sh4r.mac&0xFFFFFFFF00000000LL) |
nkeynes@359
   600
                                               (sh4r.r[Rm] * sh4r.r[Rn]);
nkeynes@359
   601
                        }
nkeynes@359
   602
                        break;
nkeynes@359
   603
                    case 0x8:
nkeynes@359
   604
                        switch( (ir&0xFF0) >> 4 ) {
nkeynes@359
   605
                            case 0x0:
nkeynes@359
   606
                                { /* CLRT */
nkeynes@359
   607
                                sh4r.t = 0;
nkeynes@359
   608
                                }
nkeynes@359
   609
                                break;
nkeynes@359
   610
                            case 0x1:
nkeynes@359
   611
                                { /* SETT */
nkeynes@359
   612
                                sh4r.t = 1;
nkeynes@359
   613
                                }
nkeynes@359
   614
                                break;
nkeynes@359
   615
                            case 0x2:
nkeynes@359
   616
                                { /* CLRMAC */
nkeynes@359
   617
                                sh4r.mac = 0;
nkeynes@359
   618
                                }
nkeynes@359
   619
                                break;
nkeynes@359
   620
                            case 0x3:
nkeynes@359
   621
                                { /* LDTLB */
nkeynes@359
   622
                                /* TODO */
nkeynes@359
   623
                                }
nkeynes@359
   624
                                break;
nkeynes@359
   625
                            case 0x4:
nkeynes@359
   626
                                { /* CLRS */
nkeynes@359
   627
                                sh4r.s = 0;
nkeynes@359
   628
                                }
nkeynes@359
   629
                                break;
nkeynes@359
   630
                            case 0x5:
nkeynes@359
   631
                                { /* SETS */
nkeynes@359
   632
                                sh4r.s = 1;
nkeynes@359
   633
                                }
nkeynes@359
   634
                                break;
nkeynes@359
   635
                            default:
nkeynes@359
   636
                                UNDEF();
nkeynes@359
   637
                                break;
nkeynes@359
   638
                        }
nkeynes@359
   639
                        break;
nkeynes@359
   640
                    case 0x9:
nkeynes@359
   641
                        switch( (ir&0xF0) >> 4 ) {
nkeynes@359
   642
                            case 0x0:
nkeynes@359
   643
                                { /* NOP */
nkeynes@359
   644
                                /* NOP */
nkeynes@359
   645
                                }
nkeynes@359
   646
                                break;
nkeynes@359
   647
                            case 0x1:
nkeynes@359
   648
                                { /* DIV0U */
nkeynes@359
   649
                                sh4r.m = sh4r.q = sh4r.t = 0;
nkeynes@359
   650
                                }
nkeynes@359
   651
                                break;
nkeynes@359
   652
                            case 0x2:
nkeynes@359
   653
                                { /* MOVT Rn */
nkeynes@359
   654
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   655
                                sh4r.r[Rn] = sh4r.t;
nkeynes@359
   656
                                }
nkeynes@359
   657
                                break;
nkeynes@359
   658
                            default:
nkeynes@359
   659
                                UNDEF();
nkeynes@359
   660
                                break;
nkeynes@359
   661
                        }
nkeynes@359
   662
                        break;
nkeynes@359
   663
                    case 0xA:
nkeynes@359
   664
                        switch( (ir&0xF0) >> 4 ) {
nkeynes@359
   665
                            case 0x0:
nkeynes@359
   666
                                { /* STS MACH, Rn */
nkeynes@359
   667
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   668
                                sh4r.r[Rn] = (sh4r.mac>>32);
nkeynes@359
   669
                                }
nkeynes@359
   670
                                break;
nkeynes@359
   671
                            case 0x1:
nkeynes@359
   672
                                { /* STS MACL, Rn */
nkeynes@359
   673
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   674
                                sh4r.r[Rn] = (uint32_t)sh4r.mac;
nkeynes@359
   675
                                }
nkeynes@359
   676
                                break;
nkeynes@359
   677
                            case 0x2:
nkeynes@359
   678
                                { /* STS PR, Rn */
nkeynes@359
   679
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   680
                                sh4r.r[Rn] = sh4r.pr;
nkeynes@359
   681
                                }
nkeynes@359
   682
                                break;
nkeynes@359
   683
                            case 0x3:
nkeynes@359
   684
                                { /* STC SGR, Rn */
nkeynes@359
   685
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   686
                                CHECKPRIV();
nkeynes@359
   687
                                sh4r.r[Rn] = sh4r.sgr;
nkeynes@359
   688
                                }
nkeynes@359
   689
                                break;
nkeynes@359
   690
                            case 0x5:
nkeynes@359
   691
                                { /* STS FPUL, Rn */
nkeynes@359
   692
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   693
                                sh4r.r[Rn] = sh4r.fpul;
nkeynes@359
   694
                                }
nkeynes@359
   695
                                break;
nkeynes@359
   696
                            case 0x6:
nkeynes@359
   697
                                { /* STS FPSCR, Rn */
nkeynes@359
   698
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   699
                                sh4r.r[Rn] = sh4r.fpscr;
nkeynes@359
   700
                                }
nkeynes@359
   701
                                break;
nkeynes@359
   702
                            case 0xF:
nkeynes@359
   703
                                { /* STC DBR, Rn */
nkeynes@359
   704
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   705
                                CHECKPRIV(); sh4r.r[Rn] = sh4r.dbr;
nkeynes@359
   706
                                }
nkeynes@359
   707
                                break;
nkeynes@359
   708
                            default:
nkeynes@359
   709
                                UNDEF();
nkeynes@359
   710
                                break;
nkeynes@359
   711
                        }
nkeynes@359
   712
                        break;
nkeynes@359
   713
                    case 0xB:
nkeynes@359
   714
                        switch( (ir&0xFF0) >> 4 ) {
nkeynes@359
   715
                            case 0x0:
nkeynes@359
   716
                                { /* RTS */
nkeynes@359
   717
                                CHECKSLOTILLEGAL();
nkeynes@359
   718
                                CHECKDEST( sh4r.pr );
nkeynes@359
   719
                                sh4r.in_delay_slot = 1;
nkeynes@359
   720
                                sh4r.pc = sh4r.new_pc;
nkeynes@359
   721
                                sh4r.new_pc = sh4r.pr;
nkeynes@359
   722
                                TRACE_RETURN( pc, sh4r.new_pc );
nkeynes@359
   723
                                return TRUE;
nkeynes@359
   724
                                }
nkeynes@359
   725
                                break;
nkeynes@359
   726
                            case 0x1:
nkeynes@359
   727
                                { /* SLEEP */
nkeynes@359
   728
                                if( MMIO_READ( CPG, STBCR ) & 0x80 ) {
nkeynes@359
   729
                            	sh4r.sh4_state = SH4_STATE_STANDBY;
nkeynes@359
   730
                                } else {
nkeynes@359
   731
                            	sh4r.sh4_state = SH4_STATE_SLEEP;
nkeynes@359
   732
                                }
nkeynes@359
   733
                                return FALSE; /* Halt CPU */
nkeynes@359
   734
                                }
nkeynes@359
   735
                                break;
nkeynes@359
   736
                            case 0x2:
nkeynes@359
   737
                                { /* RTE */
nkeynes@359
   738
                                CHECKPRIV();
nkeynes@359
   739
                                CHECKDEST( sh4r.spc );
nkeynes@359
   740
                                CHECKSLOTILLEGAL();
nkeynes@359
   741
                                sh4r.in_delay_slot = 1;
nkeynes@359
   742
                                sh4r.pc = sh4r.new_pc;
nkeynes@359
   743
                                sh4r.new_pc = sh4r.spc;
nkeynes@374
   744
                                sh4_write_sr( sh4r.ssr );
nkeynes@359
   745
                                return TRUE;
nkeynes@359
   746
                                }
nkeynes@359
   747
                                break;
nkeynes@359
   748
                            default:
nkeynes@359
   749
                                UNDEF();
nkeynes@359
   750
                                break;
nkeynes@359
   751
                        }
nkeynes@359
   752
                        break;
nkeynes@359
   753
                    case 0xC:
nkeynes@359
   754
                        { /* MOV.B @(R0, Rm), Rn */
nkeynes@359
   755
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   756
                        sh4r.r[Rn] = MEM_READ_BYTE( R0 + sh4r.r[Rm] );
nkeynes@359
   757
                        }
nkeynes@359
   758
                        break;
nkeynes@359
   759
                    case 0xD:
nkeynes@359
   760
                        { /* MOV.W @(R0, Rm), Rn */
nkeynes@359
   761
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   762
                        CHECKRALIGN16( R0 + sh4r.r[Rm] );
nkeynes@359
   763
                                           sh4r.r[Rn] = MEM_READ_WORD( R0 + sh4r.r[Rm] );
nkeynes@359
   764
                        }
nkeynes@359
   765
                        break;
nkeynes@359
   766
                    case 0xE:
nkeynes@359
   767
                        { /* MOV.L @(R0, Rm), Rn */
nkeynes@359
   768
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   769
                        CHECKRALIGN32( R0 + sh4r.r[Rm] );
nkeynes@359
   770
                                           sh4r.r[Rn] = MEM_READ_LONG( R0 + sh4r.r[Rm] );
nkeynes@359
   771
                        }
nkeynes@359
   772
                        break;
nkeynes@359
   773
                    case 0xF:
nkeynes@359
   774
                        { /* MAC.L @Rm+, @Rn+ */
nkeynes@359
   775
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   776
                        CHECKRALIGN32( sh4r.r[Rm] );
nkeynes@359
   777
                        CHECKRALIGN32( sh4r.r[Rn] );
nkeynes@359
   778
                        int64_t tmpl = SIGNEXT32(MEM_READ_LONG(sh4r.r[Rn]));
nkeynes@359
   779
                        sh4r.r[Rn] += 4;
nkeynes@359
   780
                        tmpl = tmpl * SIGNEXT32(MEM_READ_LONG(sh4r.r[Rm])) + sh4r.mac;
nkeynes@359
   781
                        sh4r.r[Rm] += 4;
nkeynes@359
   782
                        if( sh4r.s ) {
nkeynes@359
   783
                            /* 48-bit Saturation. Yuch */
nkeynes@359
   784
                            if( tmpl < (int64_t)0xFFFF800000000000LL )
nkeynes@359
   785
                                tmpl = 0xFFFF800000000000LL;
nkeynes@359
   786
                            else if( tmpl > (int64_t)0x00007FFFFFFFFFFFLL )
nkeynes@359
   787
                                tmpl = 0x00007FFFFFFFFFFFLL;
nkeynes@359
   788
                        }
nkeynes@359
   789
                        sh4r.mac = tmpl;
nkeynes@359
   790
                        }
nkeynes@359
   791
                        break;
nkeynes@359
   792
                    default:
nkeynes@359
   793
                        UNDEF();
nkeynes@359
   794
                        break;
nkeynes@359
   795
                }
nkeynes@359
   796
                break;
nkeynes@359
   797
            case 0x1:
nkeynes@359
   798
                { /* MOV.L Rm, @(disp, Rn) */
nkeynes@359
   799
                uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); uint32_t disp = (ir&0xF)<<2; 
nkeynes@359
   800
                tmp = sh4r.r[Rn] + disp;
nkeynes@359
   801
                CHECKWALIGN32( tmp );
nkeynes@359
   802
                MEM_WRITE_LONG( tmp, sh4r.r[Rm] );
nkeynes@359
   803
                }
nkeynes@359
   804
                break;
nkeynes@359
   805
            case 0x2:
nkeynes@359
   806
                switch( ir&0xF ) {
nkeynes@359
   807
                    case 0x0:
nkeynes@359
   808
                        { /* MOV.B Rm, @Rn */
nkeynes@359
   809
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   810
                        MEM_WRITE_BYTE( sh4r.r[Rn], sh4r.r[Rm] );
nkeynes@359
   811
                        }
nkeynes@359
   812
                        break;
nkeynes@359
   813
                    case 0x1:
nkeynes@359
   814
                        { /* MOV.W Rm, @Rn */
nkeynes@359
   815
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   816
                        CHECKWALIGN16( sh4r.r[Rn] ); MEM_WRITE_WORD( sh4r.r[Rn], sh4r.r[Rm] );
nkeynes@359
   817
                        }
nkeynes@359
   818
                        break;
nkeynes@359
   819
                    case 0x2:
nkeynes@359
   820
                        { /* MOV.L Rm, @Rn */
nkeynes@359
   821
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   822
                        CHECKWALIGN32( sh4r.r[Rn] ); MEM_WRITE_LONG( sh4r.r[Rn], sh4r.r[Rm] );
nkeynes@359
   823
                        }
nkeynes@359
   824
                        break;
nkeynes@359
   825
                    case 0x4:
nkeynes@359
   826
                        { /* MOV.B Rm, @-Rn */
nkeynes@359
   827
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   828
                        sh4r.r[Rn] --; MEM_WRITE_BYTE( sh4r.r[Rn], sh4r.r[Rm] );
nkeynes@359
   829
                        }
nkeynes@359
   830
                        break;
nkeynes@359
   831
                    case 0x5:
nkeynes@359
   832
                        { /* MOV.W Rm, @-Rn */
nkeynes@359
   833
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   834
                        sh4r.r[Rn] -= 2; CHECKWALIGN16( sh4r.r[Rn] ); MEM_WRITE_WORD( sh4r.r[Rn], sh4r.r[Rm] );
nkeynes@359
   835
                        }
nkeynes@359
   836
                        break;
nkeynes@359
   837
                    case 0x6:
nkeynes@359
   838
                        { /* MOV.L Rm, @-Rn */
nkeynes@359
   839
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   840
                        sh4r.r[Rn] -= 4; CHECKWALIGN32( sh4r.r[Rn] ); MEM_WRITE_LONG( sh4r.r[Rn], sh4r.r[Rm] );
nkeynes@359
   841
                        }
nkeynes@359
   842
                        break;
nkeynes@359
   843
                    case 0x7:
nkeynes@359
   844
                        { /* DIV0S Rm, Rn */
nkeynes@359
   845
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   846
                        sh4r.q = sh4r.r[Rn]>>31;
nkeynes@359
   847
                        sh4r.m = sh4r.r[Rm]>>31;
nkeynes@359
   848
                        sh4r.t = sh4r.q ^ sh4r.m;
nkeynes@359
   849
                        }
nkeynes@359
   850
                        break;
nkeynes@359
   851
                    case 0x8:
nkeynes@359
   852
                        { /* TST Rm, Rn */
nkeynes@359
   853
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   854
                        sh4r.t = (sh4r.r[Rn]&sh4r.r[Rm] ? 0 : 1);
nkeynes@359
   855
                        }
nkeynes@359
   856
                        break;
nkeynes@359
   857
                    case 0x9:
nkeynes@359
   858
                        { /* AND Rm, Rn */
nkeynes@359
   859
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   860
                        sh4r.r[Rn] &= sh4r.r[Rm];
nkeynes@359
   861
                        }
nkeynes@359
   862
                        break;
nkeynes@359
   863
                    case 0xA:
nkeynes@359
   864
                        { /* XOR Rm, Rn */
nkeynes@359
   865
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   866
                        sh4r.r[Rn] ^= sh4r.r[Rm];
nkeynes@359
   867
                        }
nkeynes@359
   868
                        break;
nkeynes@359
   869
                    case 0xB:
nkeynes@359
   870
                        { /* OR Rm, Rn */
nkeynes@359
   871
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   872
                        sh4r.r[Rn] |= sh4r.r[Rm];
nkeynes@359
   873
                        }
nkeynes@359
   874
                        break;
nkeynes@359
   875
                    case 0xC:
nkeynes@359
   876
                        { /* CMP/STR Rm, Rn */
nkeynes@359
   877
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   878
                        /* set T = 1 if any byte in RM & RN is the same */
nkeynes@359
   879
                        tmp = sh4r.r[Rm] ^ sh4r.r[Rn];
nkeynes@359
   880
                        sh4r.t = ((tmp&0x000000FF)==0 || (tmp&0x0000FF00)==0 ||
nkeynes@359
   881
                                 (tmp&0x00FF0000)==0 || (tmp&0xFF000000)==0)?1:0;
nkeynes@359
   882
                        }
nkeynes@359
   883
                        break;
nkeynes@359
   884
                    case 0xD:
nkeynes@359
   885
                        { /* XTRCT Rm, Rn */
nkeynes@359
   886
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   887
                        sh4r.r[Rn] = (sh4r.r[Rn]>>16) | (sh4r.r[Rm]<<16);
nkeynes@359
   888
                        }
nkeynes@359
   889
                        break;
nkeynes@359
   890
                    case 0xE:
nkeynes@359
   891
                        { /* MULU.W Rm, Rn */
nkeynes@359
   892
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   893
                        sh4r.mac = (sh4r.mac&0xFFFFFFFF00000000LL) |
nkeynes@359
   894
                                   (uint32_t)((sh4r.r[Rm]&0xFFFF) * (sh4r.r[Rn]&0xFFFF));
nkeynes@359
   895
                        }
nkeynes@359
   896
                        break;
nkeynes@359
   897
                    case 0xF:
nkeynes@359
   898
                        { /* MULS.W Rm, Rn */
nkeynes@359
   899
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   900
                        sh4r.mac = (sh4r.mac&0xFFFFFFFF00000000LL) |
nkeynes@359
   901
                                   (uint32_t)(SIGNEXT32(sh4r.r[Rm]&0xFFFF) * SIGNEXT32(sh4r.r[Rn]&0xFFFF));
nkeynes@359
   902
                        }
nkeynes@359
   903
                        break;
nkeynes@359
   904
                    default:
nkeynes@359
   905
                        UNDEF();
nkeynes@359
   906
                        break;
nkeynes@359
   907
                }
nkeynes@359
   908
                break;
nkeynes@359
   909
            case 0x3:
nkeynes@359
   910
                switch( ir&0xF ) {
nkeynes@359
   911
                    case 0x0:
nkeynes@359
   912
                        { /* CMP/EQ Rm, Rn */
nkeynes@359
   913
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   914
                        sh4r.t = ( sh4r.r[Rm] == sh4r.r[Rn] ? 1 : 0 );
nkeynes@359
   915
                        }
nkeynes@359
   916
                        break;
nkeynes@359
   917
                    case 0x2:
nkeynes@359
   918
                        { /* CMP/HS Rm, Rn */
nkeynes@359
   919
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   920
                        sh4r.t = ( sh4r.r[Rn] >= sh4r.r[Rm] ? 1 : 0 );
nkeynes@359
   921
                        }
nkeynes@359
   922
                        break;
nkeynes@359
   923
                    case 0x3:
nkeynes@359
   924
                        { /* CMP/GE Rm, Rn */
nkeynes@359
   925
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   926
                        sh4r.t = ( ((int32_t)sh4r.r[Rn]) >= ((int32_t)sh4r.r[Rm]) ? 1 : 0 );
nkeynes@359
   927
                        }
nkeynes@359
   928
                        break;
nkeynes@359
   929
                    case 0x4:
nkeynes@359
   930
                        { /* DIV1 Rm, Rn */
nkeynes@359
   931
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   932
                        /* This is just from the sh4p manual with some
nkeynes@359
   933
                         * simplifications (someone want to check it's correct? :)
nkeynes@359
   934
                         * Why they couldn't just provide a real DIV instruction...
nkeynes@359
   935
                         */
nkeynes@359
   936
                        uint32_t tmp0, tmp1, tmp2, dir;
nkeynes@359
   937
                    
nkeynes@359
   938
                        dir = sh4r.q ^ sh4r.m;
nkeynes@359
   939
                        sh4r.q = (sh4r.r[Rn] >> 31);
nkeynes@359
   940
                        tmp2 = sh4r.r[Rm];
nkeynes@359
   941
                        sh4r.r[Rn] = (sh4r.r[Rn] << 1) | sh4r.t;
nkeynes@359
   942
                        tmp0 = sh4r.r[Rn];
nkeynes@359
   943
                        if( dir ) {
nkeynes@359
   944
                             sh4r.r[Rn] += tmp2;
nkeynes@359
   945
                             tmp1 = (sh4r.r[Rn]<tmp0 ? 1 : 0 );
nkeynes@359
   946
                        } else {
nkeynes@359
   947
                             sh4r.r[Rn] -= tmp2;
nkeynes@359
   948
                             tmp1 = (sh4r.r[Rn]>tmp0 ? 1 : 0 );
nkeynes@359
   949
                        }
nkeynes@359
   950
                        sh4r.q ^= sh4r.m ^ tmp1;
nkeynes@359
   951
                        sh4r.t = ( sh4r.q == sh4r.m ? 1 : 0 );
nkeynes@359
   952
                        }
nkeynes@359
   953
                        break;
nkeynes@359
   954
                    case 0x5:
nkeynes@359
   955
                        { /* DMULU.L Rm, Rn */
nkeynes@359
   956
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   957
                        sh4r.mac = ((uint64_t)sh4r.r[Rm]) * ((uint64_t)sh4r.r[Rn]);
nkeynes@359
   958
                        }
nkeynes@359
   959
                        break;
nkeynes@359
   960
                    case 0x6:
nkeynes@359
   961
                        { /* CMP/HI Rm, Rn */
nkeynes@359
   962
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   963
                        sh4r.t = ( sh4r.r[Rn] > sh4r.r[Rm] ? 1 : 0 );
nkeynes@359
   964
                        }
nkeynes@359
   965
                        break;
nkeynes@359
   966
                    case 0x7:
nkeynes@359
   967
                        { /* CMP/GT Rm, Rn */
nkeynes@359
   968
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   969
                        sh4r.t = ( ((int32_t)sh4r.r[Rn]) > ((int32_t)sh4r.r[Rm]) ? 1 : 0 );
nkeynes@359
   970
                        }
nkeynes@359
   971
                        break;
nkeynes@359
   972
                    case 0x8:
nkeynes@359
   973
                        { /* SUB Rm, Rn */
nkeynes@359
   974
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   975
                        sh4r.r[Rn] -= sh4r.r[Rm];
nkeynes@359
   976
                        }
nkeynes@359
   977
                        break;
nkeynes@359
   978
                    case 0xA:
nkeynes@359
   979
                        { /* SUBC Rm, Rn */
nkeynes@359
   980
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   981
                        tmp = sh4r.r[Rn];
nkeynes@359
   982
                        sh4r.r[Rn] = sh4r.r[Rn] - sh4r.r[Rm] - sh4r.t;
nkeynes@359
   983
                        sh4r.t = (sh4r.r[Rn] > tmp || (sh4r.r[Rn] == tmp && sh4r.t == 1));
nkeynes@359
   984
                        }
nkeynes@359
   985
                        break;
nkeynes@359
   986
                    case 0xB:
nkeynes@359
   987
                        UNIMP(ir); /* SUBV Rm, Rn */
nkeynes@359
   988
                        break;
nkeynes@359
   989
                    case 0xC:
nkeynes@359
   990
                        { /* ADD Rm, Rn */
nkeynes@359
   991
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   992
                        sh4r.r[Rn] += sh4r.r[Rm];
nkeynes@359
   993
                        }
nkeynes@359
   994
                        break;
nkeynes@359
   995
                    case 0xD:
nkeynes@359
   996
                        { /* DMULS.L Rm, Rn */
nkeynes@359
   997
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   998
                        sh4r.mac = SIGNEXT32(sh4r.r[Rm]) * SIGNEXT32(sh4r.r[Rn]);
nkeynes@359
   999
                        }
nkeynes@359
  1000
                        break;
nkeynes@359
  1001
                    case 0xE:
nkeynes@359
  1002
                        { /* ADDC Rm, Rn */
nkeynes@359
  1003
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  1004
                        tmp = sh4r.r[Rn];
nkeynes@359
  1005
                        sh4r.r[Rn] += sh4r.r[Rm] + sh4r.t;
nkeynes@359
  1006
                        sh4r.t = ( sh4r.r[Rn] < tmp || (sh4r.r[Rn] == tmp && sh4r.t != 0) ? 1 : 0 );
nkeynes@359
  1007
                        }
nkeynes@359
  1008
                        break;
nkeynes@359
  1009
                    case 0xF:
nkeynes@359
  1010
                        { /* ADDV Rm, Rn */
nkeynes@359
  1011
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  1012
                        tmp = sh4r.r[Rn] + sh4r.r[Rm];
nkeynes@359
  1013
                        sh4r.t = ( (sh4r.r[Rn]>>31) == (sh4r.r[Rm]>>31) && ((sh4r.r[Rn]>>31) != (tmp>>31)) );
nkeynes@359
  1014
                        sh4r.r[Rn] = tmp;
nkeynes@359
  1015
                        }
nkeynes@359
  1016
                        break;
nkeynes@359
  1017
                    default:
nkeynes@359
  1018
                        UNDEF();
nkeynes@359
  1019
                        break;
nkeynes@359
  1020
                }
nkeynes@359
  1021
                break;
nkeynes@359
  1022
            case 0x4:
nkeynes@359
  1023
                switch( ir&0xF ) {
nkeynes@359
  1024
                    case 0x0:
nkeynes@359
  1025
                        switch( (ir&0xF0) >> 4 ) {
nkeynes@359
  1026
                            case 0x0:
nkeynes@359
  1027
                                { /* SHLL Rn */
nkeynes@359
  1028
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1029
                                sh4r.t = sh4r.r[Rn] >> 31; sh4r.r[Rn] <<= 1;
nkeynes@359
  1030
                                }
nkeynes@359
  1031
                                break;
nkeynes@359
  1032
                            case 0x1:
nkeynes@359
  1033
                                { /* DT Rn */
nkeynes@359
  1034
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1035
                                sh4r.r[Rn] --;
nkeynes@359
  1036
                                sh4r.t = ( sh4r.r[Rn] == 0 ? 1 : 0 );
nkeynes@359
  1037
                                }
nkeynes@359
  1038
                                break;
nkeynes@359
  1039
                            case 0x2:
nkeynes@359
  1040
                                { /* SHAL Rn */
nkeynes@359
  1041
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1042
                                sh4r.t = sh4r.r[Rn] >> 31;
nkeynes@359
  1043
                                sh4r.r[Rn] <<= 1;
nkeynes@359
  1044
                                }
nkeynes@359
  1045
                                break;
nkeynes@359
  1046
                            default:
nkeynes@359
  1047
                                UNDEF();
nkeynes@359
  1048
                                break;
nkeynes@359
  1049
                        }
nkeynes@359
  1050
                        break;
nkeynes@359
  1051
                    case 0x1:
nkeynes@359
  1052
                        switch( (ir&0xF0) >> 4 ) {
nkeynes@359
  1053
                            case 0x0:
nkeynes@359
  1054
                                { /* SHLR Rn */
nkeynes@359
  1055
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1056
                                sh4r.t = sh4r.r[Rn] & 0x00000001; sh4r.r[Rn] >>= 1;
nkeynes@359
  1057
                                }
nkeynes@359
  1058
                                break;
nkeynes@359
  1059
                            case 0x1:
nkeynes@359
  1060
                                { /* CMP/PZ Rn */
nkeynes@359
  1061
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1062
                                sh4r.t = ( ((int32_t)sh4r.r[Rn]) >= 0 ? 1 : 0 );
nkeynes@359
  1063
                                }
nkeynes@359
  1064
                                break;
nkeynes@359
  1065
                            case 0x2:
nkeynes@359
  1066
                                { /* SHAR Rn */
nkeynes@359
  1067
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1068
                                sh4r.t = sh4r.r[Rn] & 0x00000001;
nkeynes@359
  1069
                                sh4r.r[Rn] = ((int32_t)sh4r.r[Rn]) >> 1;
nkeynes@359
  1070
                                }
nkeynes@359
  1071
                                break;
nkeynes@359
  1072
                            default:
nkeynes@359
  1073
                                UNDEF();
nkeynes@359
  1074
                                break;
nkeynes@359
  1075
                        }
nkeynes@359
  1076
                        break;
nkeynes@359
  1077
                    case 0x2:
nkeynes@359
  1078
                        switch( (ir&0xF0) >> 4 ) {
nkeynes@359
  1079
                            case 0x0:
nkeynes@359
  1080
                                { /* STS.L MACH, @-Rn */
nkeynes@359
  1081
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1082
                                sh4r.r[Rn] -= 4;
nkeynes@359
  1083
                                CHECKWALIGN32( sh4r.r[Rn] );
nkeynes@359
  1084
                                MEM_WRITE_LONG( sh4r.r[Rn], (sh4r.mac>>32) );
nkeynes@359
  1085
                                }
nkeynes@359
  1086
                                break;
nkeynes@359
  1087
                            case 0x1:
nkeynes@359
  1088
                                { /* STS.L MACL, @-Rn */
nkeynes@359
  1089
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1090
                                sh4r.r[Rn] -= 4;
nkeynes@359
  1091
                                CHECKWALIGN32( sh4r.r[Rn] );
nkeynes@359
  1092
                                MEM_WRITE_LONG( sh4r.r[Rn], (uint32_t)sh4r.mac );
nkeynes@359
  1093
                                }
nkeynes@359
  1094
                                break;
nkeynes@359
  1095
                            case 0x2:
nkeynes@359
  1096
                                { /* STS.L PR, @-Rn */
nkeynes@359
  1097
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1098
                                sh4r.r[Rn] -= 4;
nkeynes@359
  1099
                                CHECKWALIGN32( sh4r.r[Rn] );
nkeynes@359
  1100
                                MEM_WRITE_LONG( sh4r.r[Rn], sh4r.pr );
nkeynes@359
  1101
                                }
nkeynes@359
  1102
                                break;
nkeynes@359
  1103
                            case 0x3:
nkeynes@359
  1104
                                { /* STC.L SGR, @-Rn */
nkeynes@359
  1105
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1106
                                CHECKPRIV();
nkeynes@359
  1107
                                sh4r.r[Rn] -= 4;
nkeynes@359
  1108
                                CHECKWALIGN32( sh4r.r[Rn] );
nkeynes@359
  1109
                                MEM_WRITE_LONG( sh4r.r[Rn], sh4r.sgr );
nkeynes@359
  1110
                                }
nkeynes@359
  1111
                                break;
nkeynes@359
  1112
                            case 0x5:
nkeynes@359
  1113
                                { /* STS.L FPUL, @-Rn */
nkeynes@359
  1114
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1115
                                sh4r.r[Rn] -= 4;
nkeynes@359
  1116
                                CHECKWALIGN32( sh4r.r[Rn] );
nkeynes@359
  1117
                                MEM_WRITE_LONG( sh4r.r[Rn], sh4r.fpul );
nkeynes@359
  1118
                                }
nkeynes@359
  1119
                                break;
nkeynes@359
  1120
                            case 0x6:
nkeynes@359
  1121
                                { /* STS.L FPSCR, @-Rn */
nkeynes@359
  1122
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1123
                                sh4r.r[Rn] -= 4;
nkeynes@359
  1124
                                CHECKWALIGN32( sh4r.r[Rn] );
nkeynes@359
  1125
                                MEM_WRITE_LONG( sh4r.r[Rn], sh4r.fpscr );
nkeynes@359
  1126
                                }
nkeynes@359
  1127
                                break;
nkeynes@359
  1128
                            case 0xF:
nkeynes@359
  1129
                                { /* STC.L DBR, @-Rn */
nkeynes@359
  1130
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1131
                                CHECKPRIV();
nkeynes@359
  1132
                                sh4r.r[Rn] -= 4;
nkeynes@359
  1133
                                CHECKWALIGN32( sh4r.r[Rn] );
nkeynes@359
  1134
                                MEM_WRITE_LONG( sh4r.r[Rn], sh4r.dbr );
nkeynes@359
  1135
                                }
nkeynes@359
  1136
                                break;
nkeynes@359
  1137
                            default:
nkeynes@359
  1138
                                UNDEF();
nkeynes@359
  1139
                                break;
nkeynes@359
  1140
                        }
nkeynes@359
  1141
                        break;
nkeynes@359
  1142
                    case 0x3:
nkeynes@359
  1143
                        switch( (ir&0x80) >> 7 ) {
nkeynes@359
  1144
                            case 0x0:
nkeynes@359
  1145
                                switch( (ir&0x70) >> 4 ) {
nkeynes@359
  1146
                                    case 0x0:
nkeynes@359
  1147
                                        { /* STC.L SR, @-Rn */
nkeynes@359
  1148
                                        uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1149
                                        CHECKPRIV();
nkeynes@359
  1150
                                        sh4r.r[Rn] -= 4;
nkeynes@359
  1151
                                        CHECKWALIGN32( sh4r.r[Rn] );
nkeynes@359
  1152
                                        MEM_WRITE_LONG( sh4r.r[Rn], sh4_read_sr() );
nkeynes@359
  1153
                                        }
nkeynes@359
  1154
                                        break;
nkeynes@359
  1155
                                    case 0x1:
nkeynes@359
  1156
                                        { /* STC.L GBR, @-Rn */
nkeynes@359
  1157
                                        uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1158
                                        sh4r.r[Rn] -= 4;
nkeynes@359
  1159
                                        CHECKWALIGN32( sh4r.r[Rn] );
nkeynes@359
  1160
                                        MEM_WRITE_LONG( sh4r.r[Rn], sh4r.gbr );
nkeynes@359
  1161
                                        }
nkeynes@359
  1162
                                        break;
nkeynes@359
  1163
                                    case 0x2:
nkeynes@359
  1164
                                        { /* STC.L VBR, @-Rn */
nkeynes@359
  1165
                                        uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1166
                                        CHECKPRIV();
nkeynes@359
  1167
                                        sh4r.r[Rn] -= 4;
nkeynes@359
  1168
                                        CHECKWALIGN32( sh4r.r[Rn] );
nkeynes@359
  1169
                                        MEM_WRITE_LONG( sh4r.r[Rn], sh4r.vbr );
nkeynes@359
  1170
                                        }
nkeynes@359
  1171
                                        break;
nkeynes@359
  1172
                                    case 0x3:
nkeynes@359
  1173
                                        { /* STC.L SSR, @-Rn */
nkeynes@359
  1174
                                        uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1175
                                        CHECKPRIV();
nkeynes@359
  1176
                                        sh4r.r[Rn] -= 4;
nkeynes@359
  1177
                                        CHECKWALIGN32( sh4r.r[Rn] );
nkeynes@359
  1178
                                        MEM_WRITE_LONG( sh4r.r[Rn], sh4r.ssr );
nkeynes@359
  1179
                                        }
nkeynes@359
  1180
                                        break;
nkeynes@359
  1181
                                    case 0x4:
nkeynes@359
  1182
                                        { /* STC.L SPC, @-Rn */
nkeynes@359
  1183
                                        uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1184
                                        CHECKPRIV();
nkeynes@359
  1185
                                        sh4r.r[Rn] -= 4;
nkeynes@359
  1186
                                        CHECKWALIGN32( sh4r.r[Rn] );
nkeynes@359
  1187
                                        MEM_WRITE_LONG( sh4r.r[Rn], sh4r.spc );
nkeynes@359
  1188
                                        }
nkeynes@359
  1189
                                        break;
nkeynes@359
  1190
                                    default:
nkeynes@359
  1191
                                        UNDEF();
nkeynes@359
  1192
                                        break;
nkeynes@359
  1193
                                }
nkeynes@359
  1194
                                break;
nkeynes@359
  1195
                            case 0x1:
nkeynes@359
  1196
                                { /* STC.L Rm_BANK, @-Rn */
nkeynes@359
  1197
                                uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm_BANK = ((ir>>4)&0x7); 
nkeynes@359
  1198
                                CHECKPRIV();
nkeynes@359
  1199
                                sh4r.r[Rn] -= 4;
nkeynes@359
  1200
                                CHECKWALIGN32( sh4r.r[Rn] );
nkeynes@359
  1201
                                MEM_WRITE_LONG( sh4r.r[Rn], sh4r.r_bank[Rm_BANK] );
nkeynes@359
  1202
                                }
nkeynes@359
  1203
                                break;
nkeynes@359
  1204
                        }
nkeynes@359
  1205
                        break;
nkeynes@359
  1206
                    case 0x4:
nkeynes@359
  1207
                        switch( (ir&0xF0) >> 4 ) {
nkeynes@359
  1208
                            case 0x0:
nkeynes@359
  1209
                                { /* ROTL Rn */
nkeynes@359
  1210
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1211
                                sh4r.t = sh4r.r[Rn] >> 31;
nkeynes@359
  1212
                                sh4r.r[Rn] <<= 1;
nkeynes@359
  1213
                                sh4r.r[Rn] |= sh4r.t;
nkeynes@359
  1214
                                }
nkeynes@359
  1215
                                break;
nkeynes@359
  1216
                            case 0x2:
nkeynes@359
  1217
                                { /* ROTCL Rn */
nkeynes@359
  1218
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1219
                                tmp = sh4r.r[Rn] >> 31;
nkeynes@359
  1220
                                sh4r.r[Rn] <<= 1;
nkeynes@359
  1221
                                sh4r.r[Rn] |= sh4r.t;
nkeynes@359
  1222
                                sh4r.t = tmp;
nkeynes@359
  1223
                                }
nkeynes@359
  1224
                                break;
nkeynes@359
  1225
                            default:
nkeynes@359
  1226
                                UNDEF();
nkeynes@359
  1227
                                break;
nkeynes@359
  1228
                        }
nkeynes@359
  1229
                        break;
nkeynes@359
  1230
                    case 0x5:
nkeynes@359
  1231
                        switch( (ir&0xF0) >> 4 ) {
nkeynes@359
  1232
                            case 0x0:
nkeynes@359
  1233
                                { /* ROTR Rn */
nkeynes@359
  1234
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1235
                                sh4r.t = sh4r.r[Rn] & 0x00000001;
nkeynes@359
  1236
                                sh4r.r[Rn] >>= 1;
nkeynes@359
  1237
                                sh4r.r[Rn] |= (sh4r.t << 31);
nkeynes@359
  1238
                                }
nkeynes@359
  1239
                                break;
nkeynes@359
  1240
                            case 0x1:
nkeynes@359
  1241
                                { /* CMP/PL Rn */
nkeynes@359
  1242
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1243
                                sh4r.t = ( ((int32_t)sh4r.r[Rn]) > 0 ? 1 : 0 );
nkeynes@359
  1244
                                }
nkeynes@359
  1245
                                break;
nkeynes@359
  1246
                            case 0x2:
nkeynes@359
  1247
                                { /* ROTCR Rn */
nkeynes@359
  1248
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1249
                                tmp = sh4r.r[Rn] & 0x00000001;
nkeynes@359
  1250
                                sh4r.r[Rn] >>= 1;
nkeynes@359
  1251
                                sh4r.r[Rn] |= (sh4r.t << 31 );
nkeynes@359
  1252
                                sh4r.t = tmp;
nkeynes@359
  1253
                                }
nkeynes@359
  1254
                                break;
nkeynes@359
  1255
                            default:
nkeynes@359
  1256
                                UNDEF();
nkeynes@359
  1257
                                break;
nkeynes@359
  1258
                        }
nkeynes@359
  1259
                        break;
nkeynes@359
  1260
                    case 0x6:
nkeynes@359
  1261
                        switch( (ir&0xF0) >> 4 ) {
nkeynes@359
  1262
                            case 0x0:
nkeynes@359
  1263
                                { /* LDS.L @Rm+, MACH */
nkeynes@359
  1264
                                uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  1265
                                CHECKRALIGN32( sh4r.r[Rm] );
nkeynes@359
  1266
                                sh4r.mac = (sh4r.mac & 0x00000000FFFFFFFF) |
nkeynes@359
  1267
                                           (((uint64_t)MEM_READ_LONG(sh4r.r[Rm]))<<32);
nkeynes@359
  1268
                                sh4r.r[Rm] += 4;
nkeynes@359
  1269
                                }
nkeynes@359
  1270
                                break;
nkeynes@359
  1271
                            case 0x1:
nkeynes@359
  1272
                                { /* LDS.L @Rm+, MACL */
nkeynes@359
  1273
                                uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  1274
                                CHECKRALIGN32( sh4r.r[Rm] );
nkeynes@359
  1275
                                sh4r.mac = (sh4r.mac & 0xFFFFFFFF00000000LL) |
nkeynes@359
  1276
                                           (uint64_t)((uint32_t)MEM_READ_LONG(sh4r.r[Rm]));
nkeynes@359
  1277
                                sh4r.r[Rm] += 4;
nkeynes@359
  1278
                                }
nkeynes@359
  1279
                                break;
nkeynes@359
  1280
                            case 0x2:
nkeynes@359
  1281
                                { /* LDS.L @Rm+, PR */
nkeynes@359
  1282
                                uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  1283
                                CHECKRALIGN32( sh4r.r[Rm] );
nkeynes@359
  1284
                                sh4r.pr = MEM_READ_LONG( sh4r.r[Rm] );
nkeynes@359
  1285
                                sh4r.r[Rm] += 4;
nkeynes@359
  1286
                                }
nkeynes@359
  1287
                                break;
nkeynes@359
  1288
                            case 0x3:
nkeynes@359
  1289
                                { /* LDC.L @Rm+, SGR */
nkeynes@359
  1290
                                uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  1291
                                CHECKPRIV();
nkeynes@359
  1292
                                CHECKRALIGN32( sh4r.r[Rm] );
nkeynes@359
  1293
                                sh4r.sgr = MEM_READ_LONG(sh4r.r[Rm]);
nkeynes@359
  1294
                                sh4r.r[Rm] +=4;
nkeynes@359
  1295
                                }
nkeynes@359
  1296
                                break;
nkeynes@359
  1297
                            case 0x5:
nkeynes@359
  1298
                                { /* LDS.L @Rm+, FPUL */
nkeynes@359
  1299
                                uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  1300
                                CHECKRALIGN32( sh4r.r[Rm] );
nkeynes@359
  1301
                                sh4r.fpul = MEM_READ_LONG(sh4r.r[Rm]);
nkeynes@359
  1302
                                sh4r.r[Rm] +=4;
nkeynes@359
  1303
                                }
nkeynes@359
  1304
                                break;
nkeynes@359
  1305
                            case 0x6:
nkeynes@359
  1306
                                { /* LDS.L @Rm+, FPSCR */
nkeynes@359
  1307
                                uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  1308
                                CHECKRALIGN32( sh4r.r[Rm] );
nkeynes@359
  1309
                                sh4r.fpscr = MEM_READ_LONG(sh4r.r[Rm]);
nkeynes@359
  1310
                                sh4r.r[Rm] +=4;
nkeynes@374
  1311
                                sh4r.fr_bank = &sh4r.fr[(sh4r.fpscr&FPSCR_FR)>>21][0];
nkeynes@359
  1312
                                }
nkeynes@359
  1313
                                break;
nkeynes@359
  1314
                            case 0xF:
nkeynes@359
  1315
                                { /* LDC.L @Rm+, DBR */
nkeynes@359
  1316
                                uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  1317
                                CHECKPRIV();
nkeynes@359
  1318
                                CHECKRALIGN32( sh4r.r[Rm] );
nkeynes@359
  1319
                                sh4r.dbr = MEM_READ_LONG(sh4r.r[Rm]);
nkeynes@359
  1320
                                sh4r.r[Rm] +=4;
nkeynes@359
  1321
                                }
nkeynes@359
  1322
                                break;
nkeynes@359
  1323
                            default:
nkeynes@359
  1324
                                UNDEF();
nkeynes@359
  1325
                                break;
nkeynes@359
  1326
                        }
nkeynes@359
  1327
                        break;
nkeynes@359
  1328
                    case 0x7:
nkeynes@359
  1329
                        switch( (ir&0x80) >> 7 ) {
nkeynes@359
  1330
                            case 0x0:
nkeynes@359
  1331
                                switch( (ir&0x70) >> 4 ) {
nkeynes@359
  1332
                                    case 0x0:
nkeynes@359
  1333
                                        { /* LDC.L @Rm+, SR */
nkeynes@359
  1334
                                        uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  1335
                                        CHECKSLOTILLEGAL();
nkeynes@359
  1336
                                        CHECKPRIV();
nkeynes@359
  1337
                                        CHECKWALIGN32( sh4r.r[Rm] );
nkeynes@374
  1338
                                        sh4_write_sr( MEM_READ_LONG(sh4r.r[Rm]) );
nkeynes@359
  1339
                                        sh4r.r[Rm] +=4;
nkeynes@359
  1340
                                        }
nkeynes@359
  1341
                                        break;
nkeynes@359
  1342
                                    case 0x1:
nkeynes@359
  1343
                                        { /* LDC.L @Rm+, GBR */
nkeynes@359
  1344
                                        uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  1345
                                        CHECKRALIGN32( sh4r.r[Rm] );
nkeynes@359
  1346
                                        sh4r.gbr = MEM_READ_LONG(sh4r.r[Rm]);
nkeynes@359
  1347
                                        sh4r.r[Rm] +=4;
nkeynes@359
  1348
                                        }
nkeynes@359
  1349
                                        break;
nkeynes@359
  1350
                                    case 0x2:
nkeynes@359
  1351
                                        { /* LDC.L @Rm+, VBR */
nkeynes@359
  1352
                                        uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  1353
                                        CHECKPRIV();
nkeynes@359
  1354
                                        CHECKRALIGN32( sh4r.r[Rm] );
nkeynes@359
  1355
                                        sh4r.vbr = MEM_READ_LONG(sh4r.r[Rm]);
nkeynes@359
  1356
                                        sh4r.r[Rm] +=4;
nkeynes@359
  1357
                                        }
nkeynes@359
  1358
                                        break;
nkeynes@359
  1359
                                    case 0x3:
nkeynes@359
  1360
                                        { /* LDC.L @Rm+, SSR */
nkeynes@359
  1361
                                        uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  1362
                                        CHECKPRIV();
nkeynes@359
  1363
                                        CHECKRALIGN32( sh4r.r[Rm] );
nkeynes@359
  1364
                                        sh4r.ssr = MEM_READ_LONG(sh4r.r[Rm]);
nkeynes@359
  1365
                                        sh4r.r[Rm] +=4;
nkeynes@359
  1366
                                        }
nkeynes@359
  1367
                                        break;
nkeynes@359
  1368
                                    case 0x4:
nkeynes@359
  1369
                                        { /* LDC.L @Rm+, SPC */
nkeynes@359
  1370
                                        uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  1371
                                        CHECKPRIV();
nkeynes@359
  1372
                                        CHECKRALIGN32( sh4r.r[Rm] );
nkeynes@359
  1373
                                        sh4r.spc = MEM_READ_LONG(sh4r.r[Rm]);
nkeynes@359
  1374
                                        sh4r.r[Rm] +=4;
nkeynes@359
  1375
                                        }
nkeynes@359
  1376
                                        break;
nkeynes@359
  1377
                                    default:
nkeynes@359
  1378
                                        UNDEF();
nkeynes@359
  1379
                                        break;
nkeynes@359
  1380
                                }
nkeynes@359
  1381
                                break;
nkeynes@359
  1382
                            case 0x1:
nkeynes@359
  1383
                                { /* LDC.L @Rm+, Rn_BANK */
nkeynes@359
  1384
                                uint32_t Rm = ((ir>>8)&0xF); uint32_t Rn_BANK = ((ir>>4)&0x7); 
nkeynes@359
  1385
                                CHECKPRIV();
nkeynes@359
  1386
                                CHECKRALIGN32( sh4r.r[Rm] );
nkeynes@359
  1387
                                sh4r.r_bank[Rn_BANK] = MEM_READ_LONG( sh4r.r[Rm] );
nkeynes@359
  1388
                                sh4r.r[Rm] += 4;
nkeynes@359
  1389
                                }
nkeynes@359
  1390
                                break;
nkeynes@359
  1391
                        }
nkeynes@359
  1392
                        break;
nkeynes@359
  1393
                    case 0x8:
nkeynes@359
  1394
                        switch( (ir&0xF0) >> 4 ) {
nkeynes@359
  1395
                            case 0x0:
nkeynes@359
  1396
                                { /* SHLL2 Rn */
nkeynes@359
  1397
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1398
                                sh4r.r[Rn] <<= 2;
nkeynes@359
  1399
                                }
nkeynes@359
  1400
                                break;
nkeynes@359
  1401
                            case 0x1:
nkeynes@359
  1402
                                { /* SHLL8 Rn */
nkeynes@359
  1403
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1404
                                sh4r.r[Rn] <<= 8;
nkeynes@359
  1405
                                }
nkeynes@359
  1406
                                break;
nkeynes@359
  1407
                            case 0x2:
nkeynes@359
  1408
                                { /* SHLL16 Rn */
nkeynes@359
  1409
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1410
                                sh4r.r[Rn] <<= 16;
nkeynes@359
  1411
                                }
nkeynes@359
  1412
                                break;
nkeynes@359
  1413
                            default:
nkeynes@359
  1414
                                UNDEF();
nkeynes@359
  1415
                                break;
nkeynes@359
  1416
                        }
nkeynes@359
  1417
                        break;
nkeynes@359
  1418
                    case 0x9:
nkeynes@359
  1419
                        switch( (ir&0xF0) >> 4 ) {
nkeynes@359
  1420
                            case 0x0:
nkeynes@359
  1421
                                { /* SHLR2 Rn */
nkeynes@359
  1422
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1423
                                sh4r.r[Rn] >>= 2;
nkeynes@359
  1424
                                }
nkeynes@359
  1425
                                break;
nkeynes@359
  1426
                            case 0x1:
nkeynes@359
  1427
                                { /* SHLR8 Rn */
nkeynes@359
  1428
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1429
                                sh4r.r[Rn] >>= 8;
nkeynes@359
  1430
                                }
nkeynes@359
  1431
                                break;
nkeynes@359
  1432
                            case 0x2:
nkeynes@359
  1433
                                { /* SHLR16 Rn */
nkeynes@359
  1434
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1435
                                sh4r.r[Rn] >>= 16;
nkeynes@359
  1436
                                }
nkeynes@359
  1437
                                break;
nkeynes@359
  1438
                            default:
nkeynes@359
  1439
                                UNDEF();
nkeynes@359
  1440
                                break;
nkeynes@359
  1441
                        }
nkeynes@359
  1442
                        break;
nkeynes@359
  1443
                    case 0xA:
nkeynes@359
  1444
                        switch( (ir&0xF0) >> 4 ) {
nkeynes@359
  1445
                            case 0x0:
nkeynes@359
  1446
                                { /* LDS Rm, MACH */
nkeynes@359
  1447
                                uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  1448
                                sh4r.mac = (sh4r.mac & 0x00000000FFFFFFFF) |
nkeynes@359
  1449
                                           (((uint64_t)sh4r.r[Rm])<<32);
nkeynes@359
  1450
                                }
nkeynes@359
  1451
                                break;
nkeynes@359
  1452
                            case 0x1:
nkeynes@359
  1453
                                { /* LDS Rm, MACL */
nkeynes@359
  1454
                                uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  1455
                                sh4r.mac = (sh4r.mac & 0xFFFFFFFF00000000LL) |
nkeynes@359
  1456
                                           (uint64_t)((uint32_t)(sh4r.r[Rm]));
nkeynes@359
  1457
                                }
nkeynes@359
  1458
                                break;
nkeynes@359
  1459
                            case 0x2:
nkeynes@359
  1460
                                { /* LDS Rm, PR */
nkeynes@359
  1461
                                uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  1462
                                sh4r.pr = sh4r.r[Rm];
nkeynes@359
  1463
                                }
nkeynes@359
  1464
                                break;
nkeynes@359
  1465
                            case 0x3:
nkeynes@359
  1466
                                { /* LDC Rm, SGR */
nkeynes@359
  1467
                                uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  1468
                                CHECKPRIV();
nkeynes@359
  1469
                                sh4r.sgr = sh4r.r[Rm];
nkeynes@359
  1470
                                }
nkeynes@359
  1471
                                break;
nkeynes@359
  1472
                            case 0x5:
nkeynes@359
  1473
                                { /* LDS Rm, FPUL */
nkeynes@359
  1474
                                uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  1475
                                sh4r.fpul = sh4r.r[Rm];
nkeynes@359
  1476
                                }
nkeynes@359
  1477
                                break;
nkeynes@359
  1478
                            case 0x6:
nkeynes@359
  1479
                                { /* LDS Rm, FPSCR */
nkeynes@359
  1480
                                uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@374
  1481
                                sh4r.fpscr = sh4r.r[Rm]; 
nkeynes@374
  1482
                                sh4r.fr_bank = &sh4r.fr[(sh4r.fpscr&FPSCR_FR)>>21][0];
nkeynes@359
  1483
                                }
nkeynes@359
  1484
                                break;
nkeynes@359
  1485
                            case 0xF:
nkeynes@359
  1486
                                { /* LDC Rm, DBR */
nkeynes@359
  1487
                                uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  1488
                                CHECKPRIV();
nkeynes@359
  1489
                                sh4r.dbr = sh4r.r[Rm];
nkeynes@359
  1490
                                }
nkeynes@359
  1491
                                break;
nkeynes@359
  1492
                            default:
nkeynes@359
  1493
                                UNDEF();
nkeynes@359
  1494
                                break;
nkeynes@359
  1495
                        }
nkeynes@359
  1496
                        break;
nkeynes@359
  1497
                    case 0xB:
nkeynes@359
  1498
                        switch( (ir&0xF0) >> 4 ) {
nkeynes@359
  1499
                            case 0x0:
nkeynes@359
  1500
                                { /* JSR @Rn */
nkeynes@359
  1501
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1502
                                CHECKDEST( sh4r.r[Rn] );
nkeynes@359
  1503
                                CHECKSLOTILLEGAL();
nkeynes@359
  1504
                                sh4r.in_delay_slot = 1;
nkeynes@359
  1505
                                sh4r.pc = sh4r.new_pc;
nkeynes@359
  1506
                                sh4r.new_pc = sh4r.r[Rn];
nkeynes@359
  1507
                                sh4r.pr = pc + 4;
nkeynes@359
  1508
                                TRACE_CALL( pc, sh4r.new_pc );
nkeynes@359
  1509
                                return TRUE;
nkeynes@359
  1510
                                }
nkeynes@359
  1511
                                break;
nkeynes@359
  1512
                            case 0x1:
nkeynes@359
  1513
                                { /* TAS.B @Rn */
nkeynes@359
  1514
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1515
                                tmp = MEM_READ_BYTE( sh4r.r[Rn] );
nkeynes@359
  1516
                                sh4r.t = ( tmp == 0 ? 1 : 0 );
nkeynes@359
  1517
                                MEM_WRITE_BYTE( sh4r.r[Rn], tmp | 0x80 );
nkeynes@359
  1518
                                }
nkeynes@359
  1519
                                break;
nkeynes@359
  1520
                            case 0x2:
nkeynes@359
  1521
                                { /* JMP @Rn */
nkeynes@359
  1522
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1523
                                CHECKDEST( sh4r.r[Rn] );
nkeynes@359
  1524
                                CHECKSLOTILLEGAL();
nkeynes@359
  1525
                                sh4r.in_delay_slot = 1;
nkeynes@359
  1526
                                sh4r.pc = sh4r.new_pc;
nkeynes@359
  1527
                                sh4r.new_pc = sh4r.r[Rn];
nkeynes@359
  1528
                                return TRUE;
nkeynes@359
  1529
                                }
nkeynes@359
  1530
                                break;
nkeynes@359
  1531
                            default:
nkeynes@359
  1532
                                UNDEF();
nkeynes@359
  1533
                                break;
nkeynes@359
  1534
                        }
nkeynes@359
  1535
                        break;
nkeynes@359
  1536
                    case 0xC:
nkeynes@359
  1537
                        { /* SHAD Rm, Rn */
nkeynes@359
  1538
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  1539
                        tmp = sh4r.r[Rm];
nkeynes@359
  1540
                        if( (tmp & 0x80000000) == 0 ) sh4r.r[Rn] <<= (tmp&0x1f);
nkeynes@359
  1541
                        else if( (tmp & 0x1F) == 0 )  
nkeynes@359
  1542
                            sh4r.r[Rn] = ((int32_t)sh4r.r[Rn]) >> 31;
nkeynes@359
  1543
                        else 
nkeynes@359
  1544
                    	sh4r.r[Rn] = ((int32_t)sh4r.r[Rn]) >> (((~sh4r.r[Rm]) & 0x1F)+1);
nkeynes@359
  1545
                        }
nkeynes@359
  1546
                        break;
nkeynes@359
  1547
                    case 0xD:
nkeynes@359
  1548
                        { /* SHLD Rm, Rn */
nkeynes@359
  1549
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  1550
                        tmp = sh4r.r[Rm];
nkeynes@359
  1551
                        if( (tmp & 0x80000000) == 0 ) sh4r.r[Rn] <<= (tmp&0x1f);
nkeynes@359
  1552
                        else if( (tmp & 0x1F) == 0 ) sh4r.r[Rn] = 0;
nkeynes@359
  1553
                        else sh4r.r[Rn] >>= (((~tmp) & 0x1F)+1);
nkeynes@359
  1554
                        }
nkeynes@359
  1555
                        break;
nkeynes@359
  1556
                    case 0xE:
nkeynes@359
  1557
                        switch( (ir&0x80) >> 7 ) {
nkeynes@359
  1558
                            case 0x0:
nkeynes@359
  1559
                                switch( (ir&0x70) >> 4 ) {
nkeynes@359
  1560
                                    case 0x0:
nkeynes@359
  1561
                                        { /* LDC Rm, SR */
nkeynes@359
  1562
                                        uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  1563
                                        CHECKSLOTILLEGAL();
nkeynes@359
  1564
                                        CHECKPRIV();
nkeynes@374
  1565
                                        sh4_write_sr( sh4r.r[Rm] );
nkeynes@359
  1566
                                        }
nkeynes@359
  1567
                                        break;
nkeynes@359
  1568
                                    case 0x1:
nkeynes@359
  1569
                                        { /* LDC Rm, GBR */
nkeynes@359
  1570
                                        uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  1571
                                        sh4r.gbr = sh4r.r[Rm];
nkeynes@359
  1572
                                        }
nkeynes@359
  1573
                                        break;
nkeynes@359
  1574
                                    case 0x2:
nkeynes@359
  1575
                                        { /* LDC Rm, VBR */
nkeynes@359
  1576
                                        uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  1577
                                        CHECKPRIV();
nkeynes@359
  1578
                                        sh4r.vbr = sh4r.r[Rm];
nkeynes@359
  1579
                                        }
nkeynes@359
  1580
                                        break;
nkeynes@359
  1581
                                    case 0x3:
nkeynes@359
  1582
                                        { /* LDC Rm, SSR */
nkeynes@359
  1583
                                        uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  1584
                                        CHECKPRIV();
nkeynes@359
  1585
                                        sh4r.ssr = sh4r.r[Rm];
nkeynes@359
  1586
                                        }
nkeynes@359
  1587
                                        break;
nkeynes@359
  1588
                                    case 0x4:
nkeynes@359
  1589
                                        { /* LDC Rm, SPC */
nkeynes@359
  1590
                                        uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  1591
                                        CHECKPRIV();
nkeynes@359
  1592
                                        sh4r.spc = sh4r.r[Rm];
nkeynes@359
  1593
                                        }
nkeynes@359
  1594
                                        break;
nkeynes@359
  1595
                                    default:
nkeynes@359
  1596
                                        UNDEF();
nkeynes@359
  1597
                                        break;
nkeynes@359
  1598
                                }
nkeynes@359
  1599
                                break;
nkeynes@359
  1600
                            case 0x1:
nkeynes@359
  1601
                                { /* LDC Rm, Rn_BANK */
nkeynes@359
  1602
                                uint32_t Rm = ((ir>>8)&0xF); uint32_t Rn_BANK = ((ir>>4)&0x7); 
nkeynes@359
  1603
                                CHECKPRIV();
nkeynes@359
  1604
                                sh4r.r_bank[Rn_BANK] = sh4r.r[Rm];
nkeynes@359
  1605
                                }
nkeynes@359
  1606
                                break;
nkeynes@359
  1607
                        }
nkeynes@359
  1608
                        break;
nkeynes@359
  1609
                    case 0xF:
nkeynes@359
  1610
                        { /* MAC.W @Rm+, @Rn+ */
nkeynes@359
  1611
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  1612
                        CHECKRALIGN16( sh4r.r[Rn] );
nkeynes@359
  1613
                        CHECKRALIGN16( sh4r.r[Rm] );
nkeynes@359
  1614
                        int32_t stmp = SIGNEXT16(MEM_READ_WORD(sh4r.r[Rn]));
nkeynes@359
  1615
                        sh4r.r[Rn] += 2;
nkeynes@359
  1616
                        stmp = stmp * SIGNEXT16(MEM_READ_WORD(sh4r.r[Rm]));
nkeynes@359
  1617
                        sh4r.r[Rm] += 2;
nkeynes@359
  1618
                        if( sh4r.s ) {
nkeynes@359
  1619
                    	int64_t tmpl = (int64_t)((int32_t)sh4r.mac) + (int64_t)stmp;
nkeynes@359
  1620
                    	if( tmpl > (int64_t)0x000000007FFFFFFFLL ) {
nkeynes@359
  1621
                    	    sh4r.mac = 0x000000017FFFFFFFLL;
nkeynes@359
  1622
                    	} else if( tmpl < (int64_t)0xFFFFFFFF80000000LL ) {
nkeynes@359
  1623
                    	    sh4r.mac = 0x0000000180000000LL;
nkeynes@359
  1624
                    	} else {
nkeynes@359
  1625
                    	    sh4r.mac = (sh4r.mac & 0xFFFFFFFF00000000LL) |
nkeynes@359
  1626
                    		((uint32_t)(sh4r.mac + stmp));
nkeynes@359
  1627
                    	}
nkeynes@359
  1628
                        } else {
nkeynes@359
  1629
                    	sh4r.mac += SIGNEXT32(stmp);
nkeynes@359
  1630
                        }
nkeynes@359
  1631
                        }
nkeynes@359
  1632
                        break;
nkeynes@359
  1633
                }
nkeynes@359
  1634
                break;
nkeynes@359
  1635
            case 0x5:
nkeynes@359
  1636
                { /* MOV.L @(disp, Rm), Rn */
nkeynes@359
  1637
                uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); uint32_t disp = (ir&0xF)<<2; 
nkeynes@359
  1638
                tmp = sh4r.r[Rm] + disp;
nkeynes@359
  1639
                CHECKRALIGN32( tmp );
nkeynes@359
  1640
                sh4r.r[Rn] = MEM_READ_LONG( tmp );
nkeynes@359
  1641
                }
nkeynes@359
  1642
                break;
nkeynes@359
  1643
            case 0x6:
nkeynes@359
  1644
                switch( ir&0xF ) {
nkeynes@359
  1645
                    case 0x0:
nkeynes@359
  1646
                        { /* MOV.B @Rm, Rn */
nkeynes@359
  1647
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  1648
                        sh4r.r[Rn] = MEM_READ_BYTE( sh4r.r[Rm] );
nkeynes@359
  1649
                        }
nkeynes@359
  1650
                        break;
nkeynes@359
  1651
                    case 0x1:
nkeynes@359
  1652
                        { /* MOV.W @Rm, Rn */
nkeynes@359
  1653
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  1654
                        CHECKRALIGN16( sh4r.r[Rm] ); sh4r.r[Rn] = MEM_READ_WORD( sh4r.r[Rm] );
nkeynes@359
  1655
                        }
nkeynes@359
  1656
                        break;
nkeynes@359
  1657
                    case 0x2:
nkeynes@359
  1658
                        { /* MOV.L @Rm, Rn */
nkeynes@359
  1659
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  1660
                        CHECKRALIGN32( sh4r.r[Rm] ); sh4r.r[Rn] = MEM_READ_LONG( sh4r.r[Rm] );
nkeynes@359
  1661
                        }
nkeynes@359
  1662
                        break;
nkeynes@359
  1663
                    case 0x3:
nkeynes@359
  1664
                        { /* MOV Rm, Rn */
nkeynes@359
  1665
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  1666
                        sh4r.r[Rn] = sh4r.r[Rm];
nkeynes@359
  1667
                        }
nkeynes@359
  1668
                        break;
nkeynes@359
  1669
                    case 0x4:
nkeynes@359
  1670
                        { /* MOV.B @Rm+, Rn */
nkeynes@359
  1671
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  1672
                        sh4r.r[Rn] = MEM_READ_BYTE( sh4r.r[Rm] ); sh4r.r[Rm] ++;
nkeynes@359
  1673
                        }
nkeynes@359
  1674
                        break;
nkeynes@359
  1675
                    case 0x5:
nkeynes@359
  1676
                        { /* MOV.W @Rm+, Rn */
nkeynes@359
  1677
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  1678
                        CHECKRALIGN16( sh4r.r[Rm] ); sh4r.r[Rn] = MEM_READ_WORD( sh4r.r[Rm] ); sh4r.r[Rm] += 2;
nkeynes@359
  1679
                        }
nkeynes@359
  1680
                        break;
nkeynes@359
  1681
                    case 0x6:
nkeynes@359
  1682
                        { /* MOV.L @Rm+, Rn */
nkeynes@359
  1683
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  1684
                        CHECKRALIGN32( sh4r.r[Rm] ); sh4r.r[Rn] = MEM_READ_LONG( sh4r.r[Rm] ); sh4r.r[Rm] += 4;
nkeynes@359
  1685
                        }
nkeynes@359
  1686
                        break;
nkeynes@359
  1687
                    case 0x7:
nkeynes@359
  1688
                        { /* NOT Rm, Rn */
nkeynes@359
  1689
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  1690
                        sh4r.r[Rn] = ~sh4r.r[Rm];
nkeynes@359
  1691
                        }
nkeynes@359
  1692
                        break;
nkeynes@359
  1693
                    case 0x8:
nkeynes@359
  1694
                        { /* SWAP.B Rm, Rn */
nkeynes@359
  1695
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  1696
                        sh4r.r[Rn] = (sh4r.r[Rm]&0xFFFF0000) | ((sh4r.r[Rm]&0x0000FF00)>>8) | ((sh4r.r[Rm]&0x000000FF)<<8);
nkeynes@359
  1697
                        }
nkeynes@359
  1698
                        break;
nkeynes@359
  1699
                    case 0x9:
nkeynes@359
  1700
                        { /* SWAP.W Rm, Rn */
nkeynes@359
  1701
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  1702
                        sh4r.r[Rn] = (sh4r.r[Rm]>>16) | (sh4r.r[Rm]<<16);
nkeynes@359
  1703
                        }
nkeynes@359
  1704
                        break;
nkeynes@359
  1705
                    case 0xA:
nkeynes@359
  1706
                        { /* NEGC Rm, Rn */
nkeynes@359
  1707
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  1708
                        tmp = 0 - sh4r.r[Rm];
nkeynes@359
  1709
                        sh4r.r[Rn] = tmp - sh4r.t;
nkeynes@359
  1710
                        sh4r.t = ( 0<tmp || tmp<sh4r.r[Rn] ? 1 : 0 );
nkeynes@359
  1711
                        }
nkeynes@359
  1712
                        break;
nkeynes@359
  1713
                    case 0xB:
nkeynes@359
  1714
                        { /* NEG Rm, Rn */
nkeynes@359
  1715
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  1716
                        sh4r.r[Rn] = 0 - sh4r.r[Rm];
nkeynes@359
  1717
                        }
nkeynes@359
  1718
                        break;
nkeynes@359
  1719
                    case 0xC:
nkeynes@359
  1720
                        { /* EXTU.B Rm, Rn */
nkeynes@359
  1721
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  1722
                        sh4r.r[Rn] = sh4r.r[Rm]&0x000000FF;
nkeynes@359
  1723
                        }
nkeynes@359
  1724
                        break;
nkeynes@359
  1725
                    case 0xD:
nkeynes@359
  1726
                        { /* EXTU.W Rm, Rn */
nkeynes@359
  1727
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  1728
                        sh4r.r[Rn] = sh4r.r[Rm]&0x0000FFFF;
nkeynes@359
  1729
                        }
nkeynes@359
  1730
                        break;
nkeynes@359
  1731
                    case 0xE:
nkeynes@359
  1732
                        { /* EXTS.B Rm, Rn */
nkeynes@359
  1733
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  1734
                        sh4r.r[Rn] = SIGNEXT8( sh4r.r[Rm]&0x000000FF );
nkeynes@359
  1735
                        }
nkeynes@359
  1736
                        break;
nkeynes@359
  1737
                    case 0xF:
nkeynes@359
  1738
                        { /* EXTS.W Rm, Rn */
nkeynes@359
  1739
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  1740
                        sh4r.r[Rn] = SIGNEXT16( sh4r.r[Rm]&0x0000FFFF );
nkeynes@359
  1741
                        }
nkeynes@359
  1742
                        break;
nkeynes@359
  1743
                }
nkeynes@359
  1744
                break;
nkeynes@359
  1745
            case 0x7:
nkeynes@359
  1746
                { /* ADD #imm, Rn */
nkeynes@359
  1747
                uint32_t Rn = ((ir>>8)&0xF); int32_t imm = SIGNEXT8(ir&0xFF); 
nkeynes@359
  1748
                sh4r.r[Rn] += imm;
nkeynes@359
  1749
                }
nkeynes@359
  1750
                break;
nkeynes@359
  1751
            case 0x8:
nkeynes@359
  1752
                switch( (ir&0xF00) >> 8 ) {
nkeynes@359
  1753
                    case 0x0:
nkeynes@359
  1754
                        { /* MOV.B R0, @(disp, Rn) */
nkeynes@359
  1755
                        uint32_t Rn = ((ir>>4)&0xF); uint32_t disp = (ir&0xF); 
nkeynes@359
  1756
                        MEM_WRITE_BYTE( sh4r.r[Rn] + disp, R0 );
nkeynes@359
  1757
                        }
nkeynes@359
  1758
                        break;
nkeynes@359
  1759
                    case 0x1:
nkeynes@359
  1760
                        { /* MOV.W R0, @(disp, Rn) */
nkeynes@359
  1761
                        uint32_t Rn = ((ir>>4)&0xF); uint32_t disp = (ir&0xF)<<1; 
nkeynes@359
  1762
                        tmp = sh4r.r[Rn] + disp;
nkeynes@359
  1763
                        CHECKWALIGN16( tmp );
nkeynes@359
  1764
                        MEM_WRITE_WORD( tmp, R0 );
nkeynes@359
  1765
                        }
nkeynes@359
  1766
                        break;
nkeynes@359
  1767
                    case 0x4:
nkeynes@359
  1768
                        { /* MOV.B @(disp, Rm), R0 */
nkeynes@359
  1769
                        uint32_t Rm = ((ir>>4)&0xF); uint32_t disp = (ir&0xF); 
nkeynes@359
  1770
                        R0 = MEM_READ_BYTE( sh4r.r[Rm] + disp );
nkeynes@359
  1771
                        }
nkeynes@359
  1772
                        break;
nkeynes@359
  1773
                    case 0x5:
nkeynes@359
  1774
                        { /* MOV.W @(disp, Rm), R0 */
nkeynes@359
  1775
                        uint32_t Rm = ((ir>>4)&0xF); uint32_t disp = (ir&0xF)<<1; 
nkeynes@359
  1776
                        tmp = sh4r.r[Rm] + disp;
nkeynes@359
  1777
                        CHECKRALIGN16( tmp );
nkeynes@359
  1778
                        R0 = MEM_READ_WORD( tmp );
nkeynes@359
  1779
                        }
nkeynes@359
  1780
                        break;
nkeynes@359
  1781
                    case 0x8:
nkeynes@359
  1782
                        { /* CMP/EQ #imm, R0 */
nkeynes@359
  1783
                        int32_t imm = SIGNEXT8(ir&0xFF); 
nkeynes@359
  1784
                        sh4r.t = ( R0 == imm ? 1 : 0 );
nkeynes@359
  1785
                        }
nkeynes@359
  1786
                        break;
nkeynes@359
  1787
                    case 0x9:
nkeynes@359
  1788
                        { /* BT disp */
nkeynes@359
  1789
                        int32_t disp = SIGNEXT8(ir&0xFF)<<1; 
nkeynes@359
  1790
                        CHECKSLOTILLEGAL();
nkeynes@359
  1791
                        if( sh4r.t ) {
nkeynes@359
  1792
                            CHECKDEST( sh4r.pc + disp + 4 )
nkeynes@359
  1793
                            sh4r.pc += disp + 4;
nkeynes@359
  1794
                            sh4r.new_pc = sh4r.pc + 2;
nkeynes@27
  1795
                            return TRUE;
nkeynes@359
  1796
                        }
nkeynes@359
  1797
                        }
nkeynes@359
  1798
                        break;
nkeynes@359
  1799
                    case 0xB:
nkeynes@359
  1800
                        { /* BF disp */
nkeynes@359
  1801
                        int32_t disp = SIGNEXT8(ir&0xFF)<<1; 
nkeynes@359
  1802
                        CHECKSLOTILLEGAL();
nkeynes@359
  1803
                        if( !sh4r.t ) {
nkeynes@359
  1804
                            CHECKDEST( sh4r.pc + disp + 4 )
nkeynes@359
  1805
                            sh4r.pc += disp + 4;
nkeynes@359
  1806
                            sh4r.new_pc = sh4r.pc + 2;
nkeynes@359
  1807
                            return TRUE;
nkeynes@359
  1808
                        }
nkeynes@359
  1809
                        }
nkeynes@359
  1810
                        break;
nkeynes@359
  1811
                    case 0xD:
nkeynes@359
  1812
                        { /* BT/S disp */
nkeynes@359
  1813
                        int32_t disp = SIGNEXT8(ir&0xFF)<<1; 
nkeynes@359
  1814
                        CHECKSLOTILLEGAL();
nkeynes@359
  1815
                        if( sh4r.t ) {
nkeynes@359
  1816
                            CHECKDEST( sh4r.pc + disp + 4 )
nkeynes@2
  1817
                            sh4r.in_delay_slot = 1;
nkeynes@1
  1818
                            sh4r.pc = sh4r.new_pc;
nkeynes@359
  1819
                            sh4r.new_pc = pc + disp + 4;
nkeynes@359
  1820
                            sh4r.in_delay_slot = 1;
nkeynes@27
  1821
                            return TRUE;
nkeynes@359
  1822
                        }
nkeynes@359
  1823
                        }
nkeynes@359
  1824
                        break;
nkeynes@359
  1825
                    case 0xF:
nkeynes@359
  1826
                        { /* BF/S disp */
nkeynes@359
  1827
                        int32_t disp = SIGNEXT8(ir&0xFF)<<1; 
nkeynes@359
  1828
                        CHECKSLOTILLEGAL();
nkeynes@359
  1829
                        if( !sh4r.t ) {
nkeynes@359
  1830
                            CHECKDEST( sh4r.pc + disp + 4 )
nkeynes@2
  1831
                            sh4r.in_delay_slot = 1;
nkeynes@1
  1832
                            sh4r.pc = sh4r.new_pc;
nkeynes@359
  1833
                            sh4r.new_pc = pc + disp + 4;
nkeynes@27
  1834
                            return TRUE;
nkeynes@359
  1835
                        }
nkeynes@359
  1836
                        }
nkeynes@359
  1837
                        break;
nkeynes@359
  1838
                    default:
nkeynes@359
  1839
                        UNDEF();
nkeynes@359
  1840
                        break;
nkeynes@359
  1841
                }
nkeynes@359
  1842
                break;
nkeynes@359
  1843
            case 0x9:
nkeynes@359
  1844
                { /* MOV.W @(disp, PC), Rn */
nkeynes@359
  1845
                uint32_t Rn = ((ir>>8)&0xF); uint32_t disp = (ir&0xFF)<<1; 
nkeynes@359
  1846
                CHECKSLOTILLEGAL();
nkeynes@359
  1847
                tmp = pc + 4 + disp;
nkeynes@359
  1848
                sh4r.r[Rn] = MEM_READ_WORD( tmp );
nkeynes@359
  1849
                }
nkeynes@359
  1850
                break;
nkeynes@359
  1851
            case 0xA:
nkeynes@359
  1852
                { /* BRA disp */
nkeynes@359
  1853
                int32_t disp = SIGNEXT12(ir&0xFFF)<<1; 
nkeynes@359
  1854
                CHECKSLOTILLEGAL();
nkeynes@359
  1855
                CHECKDEST( sh4r.pc + disp + 4 );
nkeynes@359
  1856
                sh4r.in_delay_slot = 1;
nkeynes@359
  1857
                sh4r.pc = sh4r.new_pc;
nkeynes@359
  1858
                sh4r.new_pc = pc + 4 + disp;
nkeynes@359
  1859
                return TRUE;
nkeynes@359
  1860
                }
nkeynes@359
  1861
                break;
nkeynes@359
  1862
            case 0xB:
nkeynes@359
  1863
                { /* BSR disp */
nkeynes@359
  1864
                int32_t disp = SIGNEXT12(ir&0xFFF)<<1; 
nkeynes@359
  1865
                CHECKDEST( sh4r.pc + disp + 4 );
nkeynes@359
  1866
                CHECKSLOTILLEGAL();
nkeynes@359
  1867
                sh4r.in_delay_slot = 1;
nkeynes@359
  1868
                sh4r.pr = pc + 4;
nkeynes@359
  1869
                sh4r.pc = sh4r.new_pc;
nkeynes@359
  1870
                sh4r.new_pc = pc + 4 + disp;
nkeynes@359
  1871
                TRACE_CALL( pc, sh4r.new_pc );
nkeynes@359
  1872
                return TRUE;
nkeynes@359
  1873
                }
nkeynes@359
  1874
                break;
nkeynes@359
  1875
            case 0xC:
nkeynes@359
  1876
                switch( (ir&0xF00) >> 8 ) {
nkeynes@359
  1877
                    case 0x0:
nkeynes@359
  1878
                        { /* MOV.B R0, @(disp, GBR) */
nkeynes@359
  1879
                        uint32_t disp = (ir&0xFF); 
nkeynes@359
  1880
                        MEM_WRITE_BYTE( sh4r.gbr + disp, R0 );
nkeynes@359
  1881
                        }
nkeynes@359
  1882
                        break;
nkeynes@359
  1883
                    case 0x1:
nkeynes@359
  1884
                        { /* MOV.W R0, @(disp, GBR) */
nkeynes@359
  1885
                        uint32_t disp = (ir&0xFF)<<1; 
nkeynes@359
  1886
                        tmp = sh4r.gbr + disp;
nkeynes@359
  1887
                        CHECKWALIGN16( tmp );
nkeynes@359
  1888
                        MEM_WRITE_WORD( tmp, R0 );
nkeynes@359
  1889
                        }
nkeynes@359
  1890
                        break;
nkeynes@359
  1891
                    case 0x2:
nkeynes@359
  1892
                        { /* MOV.L R0, @(disp, GBR) */
nkeynes@359
  1893
                        uint32_t disp = (ir&0xFF)<<2; 
nkeynes@359
  1894
                        tmp = sh4r.gbr + disp;
nkeynes@359
  1895
                        CHECKWALIGN32( tmp );
nkeynes@359
  1896
                        MEM_WRITE_LONG( tmp, R0 );
nkeynes@359
  1897
                        }
nkeynes@359
  1898
                        break;
nkeynes@359
  1899
                    case 0x3:
nkeynes@359
  1900
                        { /* TRAPA #imm */
nkeynes@359
  1901
                        uint32_t imm = (ir&0xFF); 
nkeynes@359
  1902
                        CHECKSLOTILLEGAL();
nkeynes@359
  1903
                        MMIO_WRITE( MMU, TRA, imm<<2 );
nkeynes@359
  1904
                        sh4r.pc += 2;
nkeynes@359
  1905
                        sh4_raise_exception( EXC_TRAP );
nkeynes@359
  1906
                        }
nkeynes@359
  1907
                        break;
nkeynes@359
  1908
                    case 0x4:
nkeynes@359
  1909
                        { /* MOV.B @(disp, GBR), R0 */
nkeynes@359
  1910
                        uint32_t disp = (ir&0xFF); 
nkeynes@359
  1911
                        R0 = MEM_READ_BYTE( sh4r.gbr + disp );
nkeynes@359
  1912
                        }
nkeynes@359
  1913
                        break;
nkeynes@359
  1914
                    case 0x5:
nkeynes@359
  1915
                        { /* MOV.W @(disp, GBR), R0 */
nkeynes@359
  1916
                        uint32_t disp = (ir&0xFF)<<1; 
nkeynes@359
  1917
                        tmp = sh4r.gbr + disp;
nkeynes@359
  1918
                        CHECKRALIGN16( tmp );
nkeynes@359
  1919
                        R0 = MEM_READ_WORD( tmp );
nkeynes@359
  1920
                        }
nkeynes@359
  1921
                        break;
nkeynes@359
  1922
                    case 0x6:
nkeynes@359
  1923
                        { /* MOV.L @(disp, GBR), R0 */
nkeynes@359
  1924
                        uint32_t disp = (ir&0xFF)<<2; 
nkeynes@359
  1925
                        tmp = sh4r.gbr + disp;
nkeynes@359
  1926
                        CHECKRALIGN32( tmp );
nkeynes@359
  1927
                        R0 = MEM_READ_LONG( tmp );
nkeynes@359
  1928
                        }
nkeynes@359
  1929
                        break;
nkeynes@359
  1930
                    case 0x7:
nkeynes@359
  1931
                        { /* MOVA @(disp, PC), R0 */
nkeynes@359
  1932
                        uint32_t disp = (ir&0xFF)<<2; 
nkeynes@359
  1933
                        CHECKSLOTILLEGAL();
nkeynes@359
  1934
                        R0 = (pc&0xFFFFFFFC) + disp + 4;
nkeynes@359
  1935
                        }
nkeynes@359
  1936
                        break;
nkeynes@359
  1937
                    case 0x8:
nkeynes@359
  1938
                        { /* TST #imm, R0 */
nkeynes@359
  1939
                        uint32_t imm = (ir&0xFF); 
nkeynes@359
  1940
                        sh4r.t = (R0 & imm ? 0 : 1);
nkeynes@359
  1941
                        }
nkeynes@359
  1942
                        break;
nkeynes@359
  1943
                    case 0x9:
nkeynes@359
  1944
                        { /* AND #imm, R0 */
nkeynes@359
  1945
                        uint32_t imm = (ir&0xFF); 
nkeynes@359
  1946
                        R0 &= imm;
nkeynes@359
  1947
                        }
nkeynes@359
  1948
                        break;
nkeynes@359
  1949
                    case 0xA:
nkeynes@359
  1950
                        { /* XOR #imm, R0 */
nkeynes@359
  1951
                        uint32_t imm = (ir&0xFF); 
nkeynes@359
  1952
                        R0 ^= imm;
nkeynes@359
  1953
                        }
nkeynes@359
  1954
                        break;
nkeynes@359
  1955
                    case 0xB:
nkeynes@359
  1956
                        { /* OR #imm, R0 */
nkeynes@359
  1957
                        uint32_t imm = (ir&0xFF); 
nkeynes@359
  1958
                        R0 |= imm;
nkeynes@359
  1959
                        }
nkeynes@359
  1960
                        break;
nkeynes@359
  1961
                    case 0xC:
nkeynes@359
  1962
                        { /* TST.B #imm, @(R0, GBR) */
nkeynes@359
  1963
                        uint32_t imm = (ir&0xFF); 
nkeynes@359
  1964
                        sh4r.t = ( MEM_READ_BYTE(R0 + sh4r.gbr) & imm ? 0 : 1 );
nkeynes@359
  1965
                        }
nkeynes@359
  1966
                        break;
nkeynes@359
  1967
                    case 0xD:
nkeynes@359
  1968
                        { /* AND.B #imm, @(R0, GBR) */
nkeynes@359
  1969
                        uint32_t imm = (ir&0xFF); 
nkeynes@359
  1970
                        MEM_WRITE_BYTE( R0 + sh4r.gbr, imm & MEM_READ_BYTE(R0 + sh4r.gbr) );
nkeynes@359
  1971
                        }
nkeynes@359
  1972
                        break;
nkeynes@359
  1973
                    case 0xE:
nkeynes@359
  1974
                        { /* XOR.B #imm, @(R0, GBR) */
nkeynes@359
  1975
                        uint32_t imm = (ir&0xFF); 
nkeynes@359
  1976
                        MEM_WRITE_BYTE( R0 + sh4r.gbr, imm ^ MEM_READ_BYTE(R0 + sh4r.gbr) );
nkeynes@359
  1977
                        }
nkeynes@359
  1978
                        break;
nkeynes@359
  1979
                    case 0xF:
nkeynes@359
  1980
                        { /* OR.B #imm, @(R0, GBR) */
nkeynes@359
  1981
                        uint32_t imm = (ir&0xFF); 
nkeynes@359
  1982
                        MEM_WRITE_BYTE( R0 + sh4r.gbr, imm | MEM_READ_BYTE(R0 + sh4r.gbr) );
nkeynes@359
  1983
                        }
nkeynes@359
  1984
                        break;
nkeynes@359
  1985
                }
nkeynes@359
  1986
                break;
nkeynes@359
  1987
            case 0xD:
nkeynes@359
  1988
                { /* MOV.L @(disp, PC), Rn */
nkeynes@359
  1989
                uint32_t Rn = ((ir>>8)&0xF); uint32_t disp = (ir&0xFF)<<2; 
nkeynes@359
  1990
                CHECKSLOTILLEGAL();
nkeynes@359
  1991
                tmp = (pc&0xFFFFFFFC) + disp + 4;
nkeynes@359
  1992
                sh4r.r[Rn] = MEM_READ_LONG( tmp );
nkeynes@359
  1993
                }
nkeynes@359
  1994
                break;
nkeynes@359
  1995
            case 0xE:
nkeynes@359
  1996
                { /* MOV #imm, Rn */
nkeynes@359
  1997
                uint32_t Rn = ((ir>>8)&0xF); int32_t imm = SIGNEXT8(ir&0xFF); 
nkeynes@359
  1998
                sh4r.r[Rn] = imm;
nkeynes@359
  1999
                }
nkeynes@359
  2000
                break;
nkeynes@359
  2001
            case 0xF:
nkeynes@359
  2002
                switch( ir&0xF ) {
nkeynes@359
  2003
                    case 0x0:
nkeynes@359
  2004
                        { /* FADD FRm, FRn */
nkeynes@359
  2005
                        uint32_t FRn = ((ir>>8)&0xF); uint32_t FRm = ((ir>>4)&0xF); 
nkeynes@359
  2006
                        CHECKFPUEN();
nkeynes@359
  2007
                        if( IS_FPU_DOUBLEPREC() ) {
nkeynes@359
  2008
                    	DR(FRn) += DR(FRm);
nkeynes@359
  2009
                        } else {
nkeynes@359
  2010
                    	FR(FRn) += FR(FRm);
nkeynes@359
  2011
                        }
nkeynes@359
  2012
                        }
nkeynes@359
  2013
                        break;
nkeynes@359
  2014
                    case 0x1:
nkeynes@359
  2015
                        { /* FSUB FRm, FRn */
nkeynes@359
  2016
                        uint32_t FRn = ((ir>>8)&0xF); uint32_t FRm = ((ir>>4)&0xF); 
nkeynes@359
  2017
                        CHECKFPUEN();
nkeynes@359
  2018
                        if( IS_FPU_DOUBLEPREC() ) {
nkeynes@359
  2019
                    	DR(FRn) -= DR(FRm);
nkeynes@359
  2020
                        } else {
nkeynes@359
  2021
                    	FR(FRn) -= FR(FRm);
nkeynes@359
  2022
                        }
nkeynes@359
  2023
                        }
nkeynes@359
  2024
                        break;
nkeynes@359
  2025
                    case 0x2:
nkeynes@359
  2026
                        { /* FMUL FRm, FRn */
nkeynes@359
  2027
                        uint32_t FRn = ((ir>>8)&0xF); uint32_t FRm = ((ir>>4)&0xF); 
nkeynes@359
  2028
                        CHECKFPUEN();
nkeynes@359
  2029
                        if( IS_FPU_DOUBLEPREC() ) {
nkeynes@359
  2030
                    	DR(FRn) *= DR(FRm);
nkeynes@359
  2031
                        } else {
nkeynes@359
  2032
                    	FR(FRn) *= FR(FRm);
nkeynes@359
  2033
                        }
nkeynes@359
  2034
                        }
nkeynes@359
  2035
                        break;
nkeynes@359
  2036
                    case 0x3:
nkeynes@359
  2037
                        { /* FDIV FRm, FRn */
nkeynes@359
  2038
                        uint32_t FRn = ((ir>>8)&0xF); uint32_t FRm = ((ir>>4)&0xF); 
nkeynes@359
  2039
                        CHECKFPUEN();
nkeynes@359
  2040
                        if( IS_FPU_DOUBLEPREC() ) {
nkeynes@359
  2041
                    	DR(FRn) /= DR(FRm);
nkeynes@359
  2042
                        } else {
nkeynes@359
  2043
                    	FR(FRn) /= FR(FRm);
nkeynes@359
  2044
                        }
nkeynes@359
  2045
                        }
nkeynes@359
  2046
                        break;
nkeynes@359
  2047
                    case 0x4:
nkeynes@359
  2048
                        { /* FCMP/EQ FRm, FRn */
nkeynes@359
  2049
                        uint32_t FRn = ((ir>>8)&0xF); uint32_t FRm = ((ir>>4)&0xF); 
nkeynes@359
  2050
                        CHECKFPUEN();
nkeynes@359
  2051
                        if( IS_FPU_DOUBLEPREC() ) {
nkeynes@359
  2052
                    	sh4r.t = ( DR(FRn) == DR(FRm) ? 1 : 0 );
nkeynes@359
  2053
                        } else {
nkeynes@359
  2054
                    	sh4r.t = ( FR(FRn) == FR(FRm) ? 1 : 0 );
nkeynes@359
  2055
                        }
nkeynes@359
  2056
                        }
nkeynes@359
  2057
                        break;
nkeynes@359
  2058
                    case 0x5:
nkeynes@359
  2059
                        { /* FCMP/GT FRm, FRn */
nkeynes@359
  2060
                        uint32_t FRn = ((ir>>8)&0xF); uint32_t FRm = ((ir>>4)&0xF); 
nkeynes@359
  2061
                        CHECKFPUEN();
nkeynes@359
  2062
                        if( IS_FPU_DOUBLEPREC() ) {
nkeynes@359
  2063
                    	sh4r.t = ( DR(FRn) > DR(FRm) ? 1 : 0 );
nkeynes@359
  2064
                        } else {
nkeynes@359
  2065
                    	sh4r.t = ( FR(FRn) > FR(FRm) ? 1 : 0 );
nkeynes@359
  2066
                        }
nkeynes@359
  2067
                        }
nkeynes@359
  2068
                        break;
nkeynes@359
  2069
                    case 0x6:
nkeynes@359
  2070
                        { /* FMOV @(R0, Rm), FRn */
nkeynes@359
  2071
                        uint32_t FRn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  2072
                        MEM_FP_READ( sh4r.r[Rm] + R0, FRn );
nkeynes@359
  2073
                        }
nkeynes@359
  2074
                        break;
nkeynes@359
  2075
                    case 0x7:
nkeynes@359
  2076
                        { /* FMOV FRm, @(R0, Rn) */
nkeynes@359
  2077
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t FRm = ((ir>>4)&0xF); 
nkeynes@359
  2078
                        MEM_FP_WRITE( sh4r.r[Rn] + R0, FRm );
nkeynes@359
  2079
                        }
nkeynes@359
  2080
                        break;
nkeynes@359
  2081
                    case 0x8:
nkeynes@359
  2082
                        { /* FMOV @Rm, FRn */
nkeynes@359
  2083
                        uint32_t FRn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  2084
                        MEM_FP_READ( sh4r.r[Rm], FRn );
nkeynes@359
  2085
                        }
nkeynes@359
  2086
                        break;
nkeynes@359
  2087
                    case 0x9:
nkeynes@359
  2088
                        { /* FMOV @Rm+, FRn */
nkeynes@359
  2089
                        uint32_t FRn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  2090
                        MEM_FP_READ( sh4r.r[Rm], FRn ); sh4r.r[Rm] += FP_WIDTH;
nkeynes@359
  2091
                        }
nkeynes@359
  2092
                        break;
nkeynes@359
  2093
                    case 0xA:
nkeynes@359
  2094
                        { /* FMOV FRm, @Rn */
nkeynes@359
  2095
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t FRm = ((ir>>4)&0xF); 
nkeynes@359
  2096
                        MEM_FP_WRITE( sh4r.r[Rn], FRm );
nkeynes@359
  2097
                        }
nkeynes@359
  2098
                        break;
nkeynes@359
  2099
                    case 0xB:
nkeynes@359
  2100
                        { /* FMOV FRm, @-Rn */
nkeynes@359
  2101
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t FRm = ((ir>>4)&0xF); 
nkeynes@359
  2102
                        sh4r.r[Rn] -= FP_WIDTH; MEM_FP_WRITE( sh4r.r[Rn], FRm );
nkeynes@359
  2103
                        }
nkeynes@359
  2104
                        break;
nkeynes@359
  2105
                    case 0xC:
nkeynes@359
  2106
                        { /* FMOV FRm, FRn */
nkeynes@359
  2107
                        uint32_t FRn = ((ir>>8)&0xF); uint32_t FRm = ((ir>>4)&0xF); 
nkeynes@359
  2108
                        if( IS_FPU_DOUBLESIZE() )
nkeynes@359
  2109
                    	DR(FRn) = DR(FRm);
nkeynes@359
  2110
                        else
nkeynes@359
  2111
                    	FR(FRn) = FR(FRm);
nkeynes@359
  2112
                        }
nkeynes@359
  2113
                        break;
nkeynes@359
  2114
                    case 0xD:
nkeynes@359
  2115
                        switch( (ir&0xF0) >> 4 ) {
nkeynes@359
  2116
                            case 0x0:
nkeynes@359
  2117
                                { /* FSTS FPUL, FRn */
nkeynes@359
  2118
                                uint32_t FRn = ((ir>>8)&0xF); 
nkeynes@359
  2119
                                CHECKFPUEN(); FR(FRn) = FPULf;
nkeynes@359
  2120
                                }
nkeynes@359
  2121
                                break;
nkeynes@359
  2122
                            case 0x1:
nkeynes@359
  2123
                                { /* FLDS FRm, FPUL */
nkeynes@359
  2124
                                uint32_t FRm = ((ir>>8)&0xF); 
nkeynes@359
  2125
                                CHECKFPUEN(); FPULf = FR(FRm);
nkeynes@359
  2126
                                }
nkeynes@359
  2127
                                break;
nkeynes@359
  2128
                            case 0x2:
nkeynes@359
  2129
                                { /* FLOAT FPUL, FRn */
nkeynes@359
  2130
                                uint32_t FRn = ((ir>>8)&0xF); 
nkeynes@359
  2131
                                CHECKFPUEN();
nkeynes@374
  2132
                                if( IS_FPU_DOUBLEPREC() ) {
nkeynes@374
  2133
                            	if( FRn&1 ) { // No, really...
nkeynes@374
  2134
                            	    dtmp = (double)FPULi;
nkeynes@374
  2135
                            	    FR(FRn) = *(((float *)&dtmp)+1);
nkeynes@374
  2136
                            	} else {
nkeynes@374
  2137
                            	    DRF(FRn>>1) = (double)FPULi;
nkeynes@374
  2138
                            	}
nkeynes@374
  2139
                                } else {
nkeynes@359
  2140
                            	FR(FRn) = (float)FPULi;
nkeynes@359
  2141
                                }
nkeynes@374
  2142
                                }
nkeynes@359
  2143
                                break;
nkeynes@359
  2144
                            case 0x3:
nkeynes@359
  2145
                                { /* FTRC FRm, FPUL */
nkeynes@359
  2146
                                uint32_t FRm = ((ir>>8)&0xF); 
nkeynes@359
  2147
                                CHECKFPUEN();
nkeynes@359
  2148
                                if( IS_FPU_DOUBLEPREC() ) {
nkeynes@374
  2149
                            	if( FRm&1 ) {
nkeynes@374
  2150
                            	    dtmp = 0;
nkeynes@374
  2151
                            	    *(((float *)&dtmp)+1) = FR(FRm);
nkeynes@374
  2152
                            	} else {
nkeynes@374
  2153
                            	    dtmp = DRF(FRm>>1);
nkeynes@374
  2154
                            	}
nkeynes@359
  2155
                                    if( dtmp >= MAX_INTF )
nkeynes@359
  2156
                                        FPULi = MAX_INT;
nkeynes@359
  2157
                                    else if( dtmp <= MIN_INTF )
nkeynes@359
  2158
                                        FPULi = MIN_INT;
nkeynes@359
  2159
                                    else 
nkeynes@359
  2160
                                        FPULi = (int32_t)dtmp;
nkeynes@359
  2161
                                } else {
nkeynes@359
  2162
                            	ftmp = FR(FRm);
nkeynes@359
  2163
                            	if( ftmp >= MAX_INTF )
nkeynes@359
  2164
                            	    FPULi = MAX_INT;
nkeynes@359
  2165
                            	else if( ftmp <= MIN_INTF )
nkeynes@359
  2166
                            	    FPULi = MIN_INT;
nkeynes@359
  2167
                            	else
nkeynes@359
  2168
                            	    FPULi = (int32_t)ftmp;
nkeynes@359
  2169
                                }
nkeynes@359
  2170
                                }
nkeynes@359
  2171
                                break;
nkeynes@359
  2172
                            case 0x4:
nkeynes@359
  2173
                                { /* FNEG FRn */
nkeynes@359
  2174
                                uint32_t FRn = ((ir>>8)&0xF); 
nkeynes@359
  2175
                                CHECKFPUEN();
nkeynes@359
  2176
                                if( IS_FPU_DOUBLEPREC() ) {
nkeynes@359
  2177
                            	DR(FRn) = -DR(FRn);
nkeynes@359
  2178
                                } else {
nkeynes@359
  2179
                                    FR(FRn) = -FR(FRn);
nkeynes@359
  2180
                                }
nkeynes@359
  2181
                                }
nkeynes@359
  2182
                                break;
nkeynes@359
  2183
                            case 0x5:
nkeynes@359
  2184
                                { /* FABS FRn */
nkeynes@359
  2185
                                uint32_t FRn = ((ir>>8)&0xF); 
nkeynes@359
  2186
                                CHECKFPUEN();
nkeynes@359
  2187
                                if( IS_FPU_DOUBLEPREC() ) {
nkeynes@359
  2188
                            	DR(FRn) = fabs(DR(FRn));
nkeynes@359
  2189
                                } else {
nkeynes@359
  2190
                                    FR(FRn) = fabsf(FR(FRn));
nkeynes@359
  2191
                                }
nkeynes@359
  2192
                                }
nkeynes@359
  2193
                                break;
nkeynes@359
  2194
                            case 0x6:
nkeynes@359
  2195
                                { /* FSQRT FRn */
nkeynes@359
  2196
                                uint32_t FRn = ((ir>>8)&0xF); 
nkeynes@359
  2197
                                CHECKFPUEN();
nkeynes@359
  2198
                                if( IS_FPU_DOUBLEPREC() ) {
nkeynes@359
  2199
                            	DR(FRn) = sqrt(DR(FRn));
nkeynes@359
  2200
                                } else {
nkeynes@359
  2201
                                    FR(FRn) = sqrtf(FR(FRn));
nkeynes@359
  2202
                                }
nkeynes@359
  2203
                                }
nkeynes@359
  2204
                                break;
nkeynes@359
  2205
                            case 0x7:
nkeynes@359
  2206
                                { /* FSRRA FRn */
nkeynes@359
  2207
                                uint32_t FRn = ((ir>>8)&0xF); 
nkeynes@359
  2208
                                CHECKFPUEN();
nkeynes@359
  2209
                                if( !IS_FPU_DOUBLEPREC() ) {
nkeynes@359
  2210
                            	FR(FRn) = 1.0/sqrtf(FR(FRn));
nkeynes@359
  2211
                                }
nkeynes@359
  2212
                                }
nkeynes@359
  2213
                                break;
nkeynes@359
  2214
                            case 0x8:
nkeynes@359
  2215
                                { /* FLDI0 FRn */
nkeynes@359
  2216
                                uint32_t FRn = ((ir>>8)&0xF); 
nkeynes@359
  2217
                                CHECKFPUEN();
nkeynes@359
  2218
                                if( IS_FPU_DOUBLEPREC() ) {
nkeynes@359
  2219
                            	DR(FRn) = 0.0;
nkeynes@359
  2220
                                } else {
nkeynes@359
  2221
                                    FR(FRn) = 0.0;
nkeynes@359
  2222
                                }
nkeynes@359
  2223
                                }
nkeynes@359
  2224
                                break;
nkeynes@359
  2225
                            case 0x9:
nkeynes@359
  2226
                                { /* FLDI1 FRn */
nkeynes@359
  2227
                                uint32_t FRn = ((ir>>8)&0xF); 
nkeynes@359
  2228
                                CHECKFPUEN();
nkeynes@359
  2229
                                if( IS_FPU_DOUBLEPREC() ) {
nkeynes@359
  2230
                            	DR(FRn) = 1.0;
nkeynes@359
  2231
                                } else {
nkeynes@359
  2232
                                    FR(FRn) = 1.0;
nkeynes@359
  2233
                                }
nkeynes@359
  2234
                                }
nkeynes@359
  2235
                                break;
nkeynes@359
  2236
                            case 0xA:
nkeynes@359
  2237
                                { /* FCNVSD FPUL, FRn */
nkeynes@359
  2238
                                uint32_t FRn = ((ir>>8)&0xF); 
nkeynes@359
  2239
                                CHECKFPUEN();
nkeynes@359
  2240
                                if( IS_FPU_DOUBLEPREC() && !IS_FPU_DOUBLESIZE() ) {
nkeynes@359
  2241
                            	DR(FRn) = (double)FPULf;
nkeynes@359
  2242
                                }
nkeynes@359
  2243
                                }
nkeynes@359
  2244
                                break;
nkeynes@359
  2245
                            case 0xB:
nkeynes@359
  2246
                                { /* FCNVDS FRm, FPUL */
nkeynes@359
  2247
                                uint32_t FRm = ((ir>>8)&0xF); 
nkeynes@359
  2248
                                CHECKFPUEN();
nkeynes@359
  2249
                                if( IS_FPU_DOUBLEPREC() && !IS_FPU_DOUBLESIZE() ) {
nkeynes@359
  2250
                            	FPULf = (float)DR(FRm);
nkeynes@359
  2251
                                }
nkeynes@359
  2252
                                }
nkeynes@359
  2253
                                break;
nkeynes@359
  2254
                            case 0xE:
nkeynes@359
  2255
                                { /* FIPR FVm, FVn */
nkeynes@359
  2256
                                uint32_t FVn = ((ir>>10)&0x3); uint32_t FVm = ((ir>>8)&0x3); 
nkeynes@359
  2257
                                CHECKFPUEN();
nkeynes@359
  2258
                                if( !IS_FPU_DOUBLEPREC() ) {
nkeynes@359
  2259
                                    int tmp2 = FVn<<2;
nkeynes@359
  2260
                                    tmp = FVm<<2;
nkeynes@359
  2261
                                    FR(tmp2+3) = FR(tmp)*FR(tmp2) +
nkeynes@359
  2262
                                        FR(tmp+1)*FR(tmp2+1) +
nkeynes@359
  2263
                                        FR(tmp+2)*FR(tmp2+2) +
nkeynes@359
  2264
                                        FR(tmp+3)*FR(tmp2+3);
nkeynes@359
  2265
                                }
nkeynes@359
  2266
                                }
nkeynes@359
  2267
                                break;
nkeynes@359
  2268
                            case 0xF:
nkeynes@359
  2269
                                switch( (ir&0x100) >> 8 ) {
nkeynes@359
  2270
                                    case 0x0:
nkeynes@359
  2271
                                        { /* FSCA FPUL, FRn */
nkeynes@359
  2272
                                        uint32_t FRn = ((ir>>9)&0x7)<<1; 
nkeynes@359
  2273
                                        CHECKFPUEN();
nkeynes@359
  2274
                                        if( !IS_FPU_DOUBLEPREC() ) {
nkeynes@359
  2275
                                            float angle = (((float)(FPULi&0xFFFF))/65536.0) * 2 * M_PI;
nkeynes@359
  2276
                                            FR(FRn) = sinf(angle);
nkeynes@359
  2277
                                            FR((FRn)+1) = cosf(angle);
nkeynes@359
  2278
                                        }
nkeynes@359
  2279
                                        }
nkeynes@359
  2280
                                        break;
nkeynes@359
  2281
                                    case 0x1:
nkeynes@359
  2282
                                        switch( (ir&0x200) >> 9 ) {
nkeynes@359
  2283
                                            case 0x0:
nkeynes@359
  2284
                                                { /* FTRV XMTRX, FVn */
nkeynes@359
  2285
                                                uint32_t FVn = ((ir>>10)&0x3); 
nkeynes@359
  2286
                                                CHECKFPUEN();
nkeynes@359
  2287
                                                if( !IS_FPU_DOUBLEPREC() ) {
nkeynes@359
  2288
                                                    tmp = FVn<<2;
nkeynes@374
  2289
                                            	float *xf = &sh4r.fr[((~sh4r.fpscr)&FPSCR_FR)>>21][0];
nkeynes@359
  2290
                                                    float fv[4] = { FR(tmp), FR(tmp+1), FR(tmp+2), FR(tmp+3) };
nkeynes@374
  2291
                                                    FR(tmp) = xf[1] * fv[0] + xf[5]*fv[1] +
nkeynes@374
  2292
                                            	    xf[9]*fv[2] + xf[13]*fv[3];
nkeynes@374
  2293
                                                    FR(tmp+1) = xf[0] * fv[0] + xf[4]*fv[1] +
nkeynes@374
  2294
                                            	    xf[8]*fv[2] + xf[12]*fv[3];
nkeynes@374
  2295
                                                    FR(tmp+2) = xf[3] * fv[0] + xf[7]*fv[1] +
nkeynes@374
  2296
                                            	    xf[11]*fv[2] + xf[15]*fv[3];
nkeynes@374
  2297
                                                    FR(tmp+3) = xf[2] * fv[0] + xf[6]*fv[1] +
nkeynes@374
  2298
                                            	    xf[10]*fv[2] + xf[14]*fv[3];
nkeynes@359
  2299
                                                }
nkeynes@359
  2300
                                                }
nkeynes@359
  2301
                                                break;
nkeynes@359
  2302
                                            case 0x1:
nkeynes@359
  2303
                                                switch( (ir&0xC00) >> 10 ) {
nkeynes@359
  2304
                                                    case 0x0:
nkeynes@359
  2305
                                                        { /* FSCHG */
nkeynes@359
  2306
                                                        CHECKFPUEN(); sh4r.fpscr ^= FPSCR_SZ;
nkeynes@359
  2307
                                                        }
nkeynes@359
  2308
                                                        break;
nkeynes@359
  2309
                                                    case 0x2:
nkeynes@359
  2310
                                                        { /* FRCHG */
nkeynes@374
  2311
                                                        CHECKFPUEN(); 
nkeynes@374
  2312
                                                        sh4r.fpscr ^= FPSCR_FR; 
nkeynes@374
  2313
                                                        sh4r.fr_bank = &sh4r.fr[(sh4r.fpscr&FPSCR_FR)>>21][0];
nkeynes@359
  2314
                                                        }
nkeynes@359
  2315
                                                        break;
nkeynes@359
  2316
                                                    case 0x3:
nkeynes@359
  2317
                                                        { /* UNDEF */
nkeynes@359
  2318
                                                        UNDEF(ir);
nkeynes@359
  2319
                                                        }
nkeynes@359
  2320
                                                        break;
nkeynes@359
  2321
                                                    default:
nkeynes@359
  2322
                                                        UNDEF();
nkeynes@359
  2323
                                                        break;
nkeynes@359
  2324
                                                }
nkeynes@359
  2325
                                                break;
nkeynes@359
  2326
                                        }
nkeynes@359
  2327
                                        break;
nkeynes@359
  2328
                                }
nkeynes@359
  2329
                                break;
nkeynes@359
  2330
                            default:
nkeynes@359
  2331
                                UNDEF();
nkeynes@359
  2332
                                break;
nkeynes@359
  2333
                        }
nkeynes@359
  2334
                        break;
nkeynes@359
  2335
                    case 0xE:
nkeynes@359
  2336
                        { /* FMAC FR0, FRm, FRn */
nkeynes@359
  2337
                        uint32_t FRn = ((ir>>8)&0xF); uint32_t FRm = ((ir>>4)&0xF); 
nkeynes@359
  2338
                        CHECKFPUEN();
nkeynes@359
  2339
                        if( IS_FPU_DOUBLEPREC() ) {
nkeynes@359
  2340
                            DR(FRn) += DR(FRm)*DR(0);
nkeynes@359
  2341
                        } else {
nkeynes@359
  2342
                    	FR(FRn) += FR(FRm)*FR(0);
nkeynes@359
  2343
                        }
nkeynes@359
  2344
                        }
nkeynes@359
  2345
                        break;
nkeynes@359
  2346
                    default:
nkeynes@359
  2347
                        UNDEF();
nkeynes@359
  2348
                        break;
nkeynes@359
  2349
                }
nkeynes@359
  2350
                break;
nkeynes@359
  2351
        }
nkeynes@1
  2352
nkeynes@1
  2353
    sh4r.pc = sh4r.new_pc;
nkeynes@1
  2354
    sh4r.new_pc += 2;
nkeynes@2
  2355
    sh4r.in_delay_slot = 0;
nkeynes@273
  2356
    return TRUE;
nkeynes@1
  2357
}
.