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