Search
lxdream.org :: lxdream/src/sh4/sh4core.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/sh4/sh4core.c
changeset 53:f2981805b929
prev43:0cf3e339cc59
next84:b993a8d8fbf3
author nkeynes
date Thu Dec 29 12:52:29 2005 +0000 (14 years ago)
permissions -rw-r--r--
last change Rewrite timer to be more accurate, also support cycle precision in the future
file annotate diff log raw
nkeynes@23
     1
/**
nkeynes@53
     2
 * $Id: sh4core.c,v 1.17 2005-12-29 12:52:29 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@1
    23
#include "sh4core.h"
nkeynes@1
    24
#include "sh4mmio.h"
nkeynes@1
    25
#include "mem.h"
nkeynes@23
    26
#include "clock.h"
nkeynes@1
    27
#include "intc.h"
nkeynes@1
    28
nkeynes@27
    29
/* CPU-generated exception code/vector pairs */
nkeynes@27
    30
#define EXC_POWER_RESET  0x000 /* vector special */
nkeynes@27
    31
#define EXC_MANUAL_RESET 0x020
nkeynes@27
    32
#define EXC_SLOT_ILLEGAL 0x1A0
nkeynes@27
    33
#define EXC_ILLEGAL      0x180
nkeynes@27
    34
#define EXV_ILLEGAL      0x100
nkeynes@27
    35
#define EXC_TRAP         0x160
nkeynes@27
    36
#define EXV_TRAP         0x100
nkeynes@27
    37
#define EXC_FPDISABLE    0x800
nkeynes@27
    38
#define EXV_FPDISABLE    0x100
nkeynes@27
    39
nkeynes@23
    40
/********************** SH4 Module Definition ****************************/
nkeynes@23
    41
nkeynes@23
    42
void sh4_init( void );
nkeynes@23
    43
void sh4_reset( void );
nkeynes@30
    44
uint32_t sh4_run_slice( uint32_t );
nkeynes@23
    45
void sh4_start( void );
nkeynes@23
    46
void sh4_stop( void );
nkeynes@23
    47
void sh4_save_state( FILE *f );
nkeynes@23
    48
int sh4_load_state( FILE *f );
nkeynes@16
    49
nkeynes@15
    50
struct dreamcast_module sh4_module = { "SH4", sh4_init, sh4_reset, 
nkeynes@23
    51
				       NULL, sh4_run_slice, sh4_stop,
nkeynes@23
    52
				       sh4_save_state, sh4_load_state };
nkeynes@15
    53
nkeynes@1
    54
struct sh4_registers sh4r;
nkeynes@1
    55
nkeynes@1
    56
void sh4_init(void)
nkeynes@1
    57
{
nkeynes@1
    58
    register_io_regions( mmio_list_sh4mmio );
nkeynes@10
    59
    mmu_init();
nkeynes@27
    60
    sh4_reset();
nkeynes@1
    61
}
nkeynes@1
    62
nkeynes@1
    63
void sh4_reset(void)
nkeynes@1
    64
{
nkeynes@19
    65
    /* zero everything out, for the sake of having a consistent state. */
nkeynes@19
    66
    memset( &sh4r, 0, sizeof(sh4r) );
nkeynes@27
    67
nkeynes@27
    68
    /* Resume running if we were halted */
nkeynes@27
    69
    sh4r.sh4_state = SH4_STATE_RUNNING;
nkeynes@27
    70
nkeynes@1
    71
    sh4r.pc    = 0xA0000000;
nkeynes@1
    72
    sh4r.new_pc= 0xA0000002;
nkeynes@1
    73
    sh4r.vbr   = 0x00000000;
nkeynes@1
    74
    sh4r.fpscr = 0x00040001;
nkeynes@1
    75
    sh4r.sr    = 0x700000F0;
nkeynes@27
    76
nkeynes@27
    77
    /* Mem reset will do this, but if we want to reset _just_ the SH4... */
nkeynes@27
    78
    MMIO_WRITE( MMU, EXPEVT, EXC_POWER_RESET );
nkeynes@27
    79
nkeynes@27
    80
    /* Peripheral modules */
nkeynes@1
    81
    intc_reset();
nkeynes@32
    82
    SCIF_reset();
nkeynes@1
    83
}
nkeynes@1
    84
nkeynes@43
    85
static struct breakpoint_struct sh4_breakpoints[MAX_BREAKPOINTS];
nkeynes@43
    86
static int sh4_breakpoint_count = 0;
nkeynes@43
    87
nkeynes@43
    88
void sh4_set_breakpoint( uint32_t pc, int type )
nkeynes@43
    89
{
nkeynes@43
    90
    sh4_breakpoints[sh4_breakpoint_count].address = pc;
nkeynes@43
    91
    sh4_breakpoints[sh4_breakpoint_count].type = type;
nkeynes@43
    92
    sh4_breakpoint_count++;
nkeynes@43
    93
}
nkeynes@43
    94
nkeynes@43
    95
gboolean sh4_clear_breakpoint( uint32_t pc, int type )
nkeynes@43
    96
{
nkeynes@43
    97
    int i;
nkeynes@43
    98
nkeynes@43
    99
    for( i=0; i<sh4_breakpoint_count; i++ ) {
nkeynes@43
   100
	if( sh4_breakpoints[i].address == pc && 
nkeynes@43
   101
	    sh4_breakpoints[i].type == type ) {
nkeynes@43
   102
	    while( ++i < sh4_breakpoint_count ) {
nkeynes@43
   103
		sh4_breakpoints[i-1].address = sh4_breakpoints[i].address;
nkeynes@43
   104
		sh4_breakpoints[i-1].type = sh4_breakpoints[i].type;
nkeynes@43
   105
	    }
nkeynes@43
   106
	    sh4_breakpoint_count--;
nkeynes@43
   107
	    return TRUE;
nkeynes@43
   108
	}
nkeynes@43
   109
    }
nkeynes@43
   110
    return FALSE;
nkeynes@43
   111
}
nkeynes@43
   112
nkeynes@43
   113
int sh4_get_breakpoint( uint32_t pc )
nkeynes@43
   114
{
nkeynes@43
   115
    int i;
nkeynes@43
   116
    for( i=0; i<sh4_breakpoint_count; i++ ) {
nkeynes@43
   117
	if( sh4_breakpoints[i].address == pc )
nkeynes@43
   118
	    return sh4_breakpoints[i].type;
nkeynes@43
   119
    }
nkeynes@43
   120
    return 0;
nkeynes@43
   121
}
nkeynes@43
   122
nkeynes@30
   123
uint32_t sh4_run_slice( uint32_t nanosecs ) 
nkeynes@1
   124
{
nkeynes@30
   125
    int target = sh4r.icount + nanosecs / sh4_cpu_period;
nkeynes@27
   126
    int start = sh4r.icount;
nkeynes@23
   127
    int i;
nkeynes@23
   128
nkeynes@27
   129
    if( sh4r.sh4_state != SH4_STATE_RUNNING ) {
nkeynes@27
   130
	if( sh4r.int_pending != 0 )
nkeynes@27
   131
	    sh4r.sh4_state = SH4_STATE_RUNNING;;
nkeynes@23
   132
    }
nkeynes@27
   133
nkeynes@53
   134
    for( sh4r.slice_cycle = 0; sh4r.slice_cycle < nanosecs; sh4r.slice_cycle += sh4_cpu_period ) {
nkeynes@27
   135
	if( !sh4_execute_instruction() )
nkeynes@27
   136
	    break;
nkeynes@43
   137
#ifdef ENABLE_DEBUG_MODE
nkeynes@43
   138
	for( i=0; i<sh4_breakpoint_count; i++ ) {
nkeynes@43
   139
	    if( sh4_breakpoints[i].address == sh4r.pc ) {
nkeynes@43
   140
		break;
nkeynes@43
   141
	    }
nkeynes@43
   142
	}
nkeynes@43
   143
	if( i != sh4_breakpoint_count ) {
nkeynes@43
   144
	    dreamcast_stop();
nkeynes@43
   145
	    if( sh4_breakpoints[i].type == BREAK_ONESHOT )
nkeynes@43
   146
		sh4_clear_breakpoint( sh4r.pc, BREAK_ONESHOT );
nkeynes@43
   147
	    break;
nkeynes@43
   148
	}
nkeynes@43
   149
#endif	
nkeynes@27
   150
    }
nkeynes@30
   151
nkeynes@30
   152
    /* If we aborted early, but the cpu is still technically running,
nkeynes@30
   153
     * we're doing a hard abort - cut the timeslice back to what we
nkeynes@30
   154
     * actually executed
nkeynes@30
   155
     */
nkeynes@53
   156
    if( sh4r.slice_cycle != nanosecs && sh4r.sh4_state == SH4_STATE_RUNNING ) {
nkeynes@53
   157
	nanosecs = sh4r.slice_cycle;
nkeynes@27
   158
    }
nkeynes@27
   159
    if( sh4r.sh4_state != SH4_STATE_STANDBY ) {
nkeynes@30
   160
	TMU_run_slice( nanosecs );
nkeynes@30
   161
	SCIF_run_slice( nanosecs );
nkeynes@27
   162
    }
nkeynes@53
   163
    sh4r.icount += sh4r.slice_cycle / sh4_cpu_period;
nkeynes@30
   164
    return nanosecs;
nkeynes@1
   165
}
nkeynes@1
   166
nkeynes@1
   167
void sh4_stop(void)
nkeynes@1
   168
{
nkeynes@27
   169
nkeynes@1
   170
}
nkeynes@1
   171
nkeynes@23
   172
void sh4_save_state( FILE *f )
nkeynes@16
   173
{
nkeynes@16
   174
    fwrite( &sh4r, sizeof(sh4r), 1, f );
nkeynes@53
   175
    TMU_save_state( f );
nkeynes@23
   176
    SCIF_save_state( f );
nkeynes@16
   177
}
nkeynes@16
   178
nkeynes@23
   179
int sh4_load_state( FILE * f )
nkeynes@16
   180
{
nkeynes@18
   181
    fread( &sh4r, sizeof(sh4r), 1, f );
nkeynes@53
   182
    TMU_load_state( f );
nkeynes@23
   183
    return SCIF_load_state( f );
nkeynes@16
   184
}
nkeynes@16
   185
nkeynes@23
   186
/********************** SH4 emulation core  ****************************/
nkeynes@23
   187
nkeynes@23
   188
void sh4_set_pc( int pc )
nkeynes@23
   189
{
nkeynes@23
   190
    sh4r.pc = pc;
nkeynes@23
   191
    sh4r.new_pc = pc+2;
nkeynes@23
   192
}
nkeynes@23
   193
nkeynes@27
   194
#define UNDEF(ir) do{ ERROR( "Raising exception on undefined instruction at %08x, opcode = %04x", sh4r.pc, ir ); RAISE( EXC_ILLEGAL, EXV_ILLEGAL ); }while(0)
nkeynes@27
   195
#define UNIMP(ir) do{ ERROR( "Halted on unimplemented instruction at %08x, opcode = %04x", sh4r.pc, ir ); dreamcast_stop(); return FALSE; }while(0)
nkeynes@1
   196
nkeynes@1
   197
#define RAISE( x, v ) do{ \
nkeynes@1
   198
    if( sh4r.vbr == 0 ) { \
nkeynes@1
   199
        ERROR( "%08X: VBR not initialized while raising exception %03X, halting", sh4r.pc, x ); \
nkeynes@1
   200
        sh4_stop(); \
nkeynes@1
   201
    } else { \
nkeynes@1
   202
        sh4r.spc = sh4r.pc + 2; \
nkeynes@1
   203
        sh4r.ssr = sh4_read_sr(); \
nkeynes@1
   204
        sh4r.sgr = sh4r.r[15]; \
nkeynes@1
   205
        MMIO_WRITE(MMU,EXPEVT,x); \
nkeynes@1
   206
        sh4r.pc = sh4r.vbr + v; \
nkeynes@1
   207
        sh4r.new_pc = sh4r.pc + 2; \
nkeynes@1
   208
        sh4_load_sr( sh4r.ssr |SR_MD|SR_BL|SR_RB ); \
nkeynes@1
   209
    } \
nkeynes@27
   210
    return TRUE; } while(0)
nkeynes@1
   211
nkeynes@10
   212
#define MEM_READ_BYTE( addr ) sh4_read_byte(addr)
nkeynes@10
   213
#define MEM_READ_WORD( addr ) sh4_read_word(addr)
nkeynes@10
   214
#define MEM_READ_LONG( addr ) sh4_read_long(addr)
nkeynes@10
   215
#define MEM_WRITE_BYTE( addr, val ) sh4_write_byte(addr, val)
nkeynes@10
   216
#define MEM_WRITE_WORD( addr, val ) sh4_write_word(addr, val)
nkeynes@10
   217
#define MEM_WRITE_LONG( addr, val ) sh4_write_long(addr, val)
nkeynes@1
   218
nkeynes@1
   219
#define MEM_FP_READ( addr, reg ) if( IS_FPU_DOUBLESIZE() ) { \
nkeynes@10
   220
    ((uint32_t *)FR)[(reg)&0xE0] = sh4_read_long(addr); \
nkeynes@10
   221
    ((uint32_t *)FR)[(reg)|1] = sh4_read_long(addr+4); \
nkeynes@10
   222
} else ((uint32_t *)FR)[reg] = sh4_read_long(addr)
nkeynes@1
   223
nkeynes@1
   224
#define MEM_FP_WRITE( addr, reg ) if( IS_FPU_DOUBLESIZE() ) { \
nkeynes@10
   225
    sh4_write_long( addr, ((uint32_t *)FR)[(reg)&0xE0] ); \
nkeynes@10
   226
    sh4_write_long( addr+4, ((uint32_t *)FR)[(reg)|1] ); \
nkeynes@10
   227
} else sh4_write_long( addr, ((uint32_t *)FR)[reg] )
nkeynes@1
   228
nkeynes@1
   229
#define FP_WIDTH (IS_FPU_DOUBLESIZE() ? 8 : 4)
nkeynes@1
   230
nkeynes@1
   231
#define CHECK( x, c, v ) if( !x ) RAISE( c, v )
nkeynes@1
   232
#define CHECKPRIV() CHECK( IS_SH4_PRIVMODE(), EXC_ILLEGAL, EXV_ILLEGAL )
nkeynes@1
   233
#define CHECKFPUEN() CHECK( IS_FPU_ENABLED(), EXC_FPDISABLE, EXV_FPDISABLE )
nkeynes@1
   234
#define CHECKDEST(p) if( (p) == 0 ) { ERROR( "%08X: Branch/jump to NULL, CPU halted", sh4r.pc ); sh4_stop(); return; }
nkeynes@2
   235
#define CHECKSLOTILLEGAL() if(sh4r.in_delay_slot) { RAISE(EXC_SLOT_ILLEGAL,EXV_ILLEGAL); }
nkeynes@1
   236
nkeynes@1
   237
static void sh4_switch_banks( )
nkeynes@1
   238
{
nkeynes@1
   239
    uint32_t tmp[8];
nkeynes@1
   240
nkeynes@1
   241
    memcpy( tmp, sh4r.r, sizeof(uint32_t)*8 );
nkeynes@1
   242
    memcpy( sh4r.r, sh4r.r_bank, sizeof(uint32_t)*8 );
nkeynes@1
   243
    memcpy( sh4r.r_bank, tmp, sizeof(uint32_t)*8 );
nkeynes@1
   244
}
nkeynes@1
   245
nkeynes@1
   246
static void sh4_load_sr( uint32_t newval )
nkeynes@1
   247
{
nkeynes@1
   248
    if( (newval ^ sh4r.sr) & SR_RB )
nkeynes@1
   249
        sh4_switch_banks();
nkeynes@1
   250
    sh4r.sr = newval;
nkeynes@1
   251
    sh4r.t = (newval&SR_T) ? 1 : 0;
nkeynes@1
   252
    sh4r.s = (newval&SR_S) ? 1 : 0;
nkeynes@1
   253
    sh4r.m = (newval&SR_M) ? 1 : 0;
nkeynes@1
   254
    sh4r.q = (newval&SR_Q) ? 1 : 0;
nkeynes@1
   255
    intc_mask_changed();
nkeynes@1
   256
}
nkeynes@1
   257
nkeynes@1
   258
static uint32_t sh4_read_sr( void )
nkeynes@1
   259
{
nkeynes@1
   260
    /* synchronize sh4r.sr with the various bitflags */
nkeynes@1
   261
    sh4r.sr &= SR_MQSTMASK;
nkeynes@1
   262
    if( sh4r.t ) sh4r.sr |= SR_T;
nkeynes@1
   263
    if( sh4r.s ) sh4r.sr |= SR_S;
nkeynes@1
   264
    if( sh4r.m ) sh4r.sr |= SR_M;
nkeynes@1
   265
    if( sh4r.q ) sh4r.sr |= SR_Q;
nkeynes@1
   266
    return sh4r.sr;
nkeynes@1
   267
}
nkeynes@1
   268
/* function for external use */
nkeynes@1
   269
void sh4_raise_exception( int code, int vector )
nkeynes@1
   270
{
nkeynes@1
   271
    RAISE(code, vector);
nkeynes@1
   272
}
nkeynes@1
   273
nkeynes@1
   274
static void sh4_accept_interrupt( void )
nkeynes@1
   275
{
nkeynes@1
   276
    uint32_t code = intc_accept_interrupt();
nkeynes@1
   277
    sh4r.ssr = sh4_read_sr();
nkeynes@1
   278
    sh4r.spc = sh4r.pc;
nkeynes@1
   279
    sh4r.sgr = sh4r.r[15];
nkeynes@1
   280
    sh4_load_sr( sh4r.ssr|SR_BL|SR_MD|SR_RB );
nkeynes@1
   281
    MMIO_WRITE( MMU, INTEVT, code );
nkeynes@1
   282
    sh4r.pc = sh4r.vbr + 0x600;
nkeynes@1
   283
    sh4r.new_pc = sh4r.pc + 2;
nkeynes@2
   284
    WARN( "Accepting interrupt %03X, from %08X => %08X", code, sh4r.spc, sh4r.pc );
nkeynes@1
   285
}
nkeynes@1
   286
nkeynes@27
   287
gboolean sh4_execute_instruction( void )
nkeynes@1
   288
{
nkeynes@2
   289
    int pc;
nkeynes@2
   290
    unsigned short ir;
nkeynes@1
   291
    uint32_t tmp;
nkeynes@1
   292
    uint64_t tmpl;
nkeynes@1
   293
    
nkeynes@1
   294
#define R0 sh4r.r[0]
nkeynes@1
   295
#define FR0 (FR[0])
nkeynes@1
   296
#define RN(ir) sh4r.r[(ir&0x0F00)>>8]
nkeynes@1
   297
#define RN_BANK(ir) sh4r.r_bank[(ir&0x0070)>>4]
nkeynes@1
   298
#define RM(ir) sh4r.r[(ir&0x00F0)>>4]
nkeynes@1
   299
#define DISP4(ir) (ir&0x000F) /* 4-bit displacements are *NOT* sign-extended */
nkeynes@1
   300
#define DISP8(ir) (ir&0x00FF)
nkeynes@1
   301
#define PCDISP8(ir) SIGNEXT8(ir&0x00FF)
nkeynes@1
   302
#define IMM8(ir) SIGNEXT8(ir&0x00FF)
nkeynes@1
   303
#define UIMM8(ir) (ir&0x00FF) /* Unsigned immmediate */
nkeynes@1
   304
#define DISP12(ir) SIGNEXT12(ir&0x0FFF)
nkeynes@2
   305
#define FVN(ir) ((ir&0x0C00)>>8)
nkeynes@2
   306
#define FVM(ir) ((ir&0x0300)>>6)
nkeynes@1
   307
#define FRN(ir) (FR[(ir&0x0F00)>>8])
nkeynes@1
   308
#define FRM(ir) (FR[(ir&0x00F0)>>4])
nkeynes@1
   309
#define FRNi(ir) (((uint32_t *)FR)[(ir&0x0F00)>>8])
nkeynes@1
   310
#define FRMi(ir) (((uint32_t *)FR)[(ir&0x00F0)>>4])
nkeynes@1
   311
#define DRN(ir) (((double *)FR)[(ir&0x0E00)>>9])
nkeynes@1
   312
#define DRM(ir) (((double *)FR)[(ir&0x00E0)>>5])
nkeynes@1
   313
#define DRNi(ir) (((uint64_t *)FR)[(ir&0x0E00)>>9])
nkeynes@1
   314
#define DRMi(ir) (((uint64_t *)FR)[(ir&0x00E0)>>5])
nkeynes@1
   315
#define FRNn(ir) ((ir&0x0F00)>>8)
nkeynes@1
   316
#define FRMn(ir) ((ir&0x00F0)>>4)
nkeynes@1
   317
#define FPULf   *((float *)&sh4r.fpul)
nkeynes@1
   318
#define FPULi    (sh4r.fpul)
nkeynes@1
   319
nkeynes@2
   320
    if( SH4_INT_PENDING() ) 
nkeynes@2
   321
        sh4_accept_interrupt();
nkeynes@1
   322
                 
nkeynes@2
   323
    pc = sh4r.pc;
nkeynes@2
   324
    ir = MEM_READ_WORD(pc);
nkeynes@1
   325
    sh4r.icount++;
nkeynes@1
   326
    
nkeynes@1
   327
    switch( (ir&0xF000)>>12 ) {
nkeynes@1
   328
        case 0: /* 0000nnnnmmmmxxxx */
nkeynes@1
   329
            switch( ir&0x000F ) {
nkeynes@1
   330
                case 2:
nkeynes@1
   331
                    switch( (ir&0x00F0)>>4 ) {
nkeynes@1
   332
                        case 0: /* STC     SR, Rn */
nkeynes@1
   333
                            CHECKPRIV();
nkeynes@1
   334
                            RN(ir) = sh4_read_sr();
nkeynes@1
   335
                            break;
nkeynes@1
   336
                        case 1: /* STC     GBR, Rn */
nkeynes@1
   337
                            RN(ir) = sh4r.gbr;
nkeynes@1
   338
                            break;
nkeynes@1
   339
                        case 2: /* STC     VBR, Rn */
nkeynes@1
   340
                            CHECKPRIV();
nkeynes@1
   341
                            RN(ir) = sh4r.vbr;
nkeynes@1
   342
                            break;
nkeynes@1
   343
                        case 3: /* STC     SSR, Rn */
nkeynes@1
   344
                            CHECKPRIV();
nkeynes@1
   345
                            RN(ir) = sh4r.ssr;
nkeynes@1
   346
                            break;
nkeynes@1
   347
                        case 4: /* STC     SPC, Rn */
nkeynes@1
   348
                            CHECKPRIV();
nkeynes@1
   349
                            RN(ir) = sh4r.spc;
nkeynes@1
   350
                            break;
nkeynes@1
   351
                        case 8: case 9: case 10: case 11: case 12: case 13:
nkeynes@1
   352
                        case 14: case 15:/* STC     Rm_bank, Rn */
nkeynes@1
   353
                            CHECKPRIV();
nkeynes@1
   354
                            RN(ir) = RN_BANK(ir);
nkeynes@1
   355
                            break;
nkeynes@1
   356
                        default: UNDEF(ir);
nkeynes@1
   357
                    }
nkeynes@1
   358
                    break;
nkeynes@1
   359
                case 3:
nkeynes@1
   360
                    switch( (ir&0x00F0)>>4 ) {
nkeynes@1
   361
                        case 0: /* BSRF    Rn */
nkeynes@1
   362
                            CHECKDEST( pc + 4 + RN(ir) );
nkeynes@2
   363
                            CHECKSLOTILLEGAL();
nkeynes@2
   364
                            sh4r.in_delay_slot = 1;
nkeynes@1
   365
                            sh4r.pr = sh4r.pc + 4;
nkeynes@1
   366
                            sh4r.pc = sh4r.new_pc;
nkeynes@1
   367
                            sh4r.new_pc = pc + 4 + RN(ir);
nkeynes@27
   368
                            return TRUE;
nkeynes@1
   369
                        case 2: /* BRAF    Rn */
nkeynes@1
   370
                            CHECKDEST( pc + 4 + RN(ir) );
nkeynes@2
   371
                            CHECKSLOTILLEGAL();
nkeynes@2
   372
                            sh4r.in_delay_slot = 1;
nkeynes@1
   373
                            sh4r.pc = sh4r.new_pc;
nkeynes@1
   374
                            sh4r.new_pc = pc + 4 + RN(ir);
nkeynes@27
   375
                            return TRUE;
nkeynes@1
   376
                        case 8: /* PREF    [Rn] */
nkeynes@2
   377
                            tmp = RN(ir);
nkeynes@2
   378
                            if( (tmp & 0xFC000000) == 0xE0000000 ) {
nkeynes@2
   379
                                /* Store queue operation */
nkeynes@2
   380
                                int queue = (tmp&0x20)>>2;
nkeynes@2
   381
                                int32_t *src = &sh4r.store_queue[queue];
nkeynes@2
   382
                                uint32_t hi = (MMIO_READ( MMU, (queue == 0 ? QACR0 : QACR1) ) & 0x1C) << 24;
nkeynes@2
   383
                                uint32_t target = tmp&0x03FFFFE0 | hi;
nkeynes@2
   384
                                mem_copy_to_sh4( target, src, 32 );
nkeynes@38
   385
				//                                WARN( "Executed SQ%c => %08X",
nkeynes@38
   386
				//                                      (queue == 0 ? '0' : '1'), target );
nkeynes@2
   387
                            }
nkeynes@2
   388
                            break;
nkeynes@1
   389
                        case 9: /* OCBI    [Rn] */
nkeynes@1
   390
                        case 10:/* OCBP    [Rn] */
nkeynes@1
   391
                        case 11:/* OCBWB   [Rn] */
nkeynes@1
   392
                            /* anything? */
nkeynes@1
   393
                            break;
nkeynes@1
   394
                        case 12:/* MOVCA.L R0, [Rn] */
nkeynes@1
   395
                            UNIMP(ir);
nkeynes@1
   396
                        default: UNDEF(ir);
nkeynes@1
   397
                    }
nkeynes@1
   398
                    break;
nkeynes@1
   399
                case 4: /* MOV.B   Rm, [R0 + Rn] */
nkeynes@1
   400
                    MEM_WRITE_BYTE( R0 + RN(ir), RM(ir) );
nkeynes@1
   401
                    break;
nkeynes@1
   402
                case 5: /* MOV.W   Rm, [R0 + Rn] */
nkeynes@1
   403
                    MEM_WRITE_WORD( R0 + RN(ir), RM(ir) );
nkeynes@1
   404
                    break;
nkeynes@1
   405
                case 6: /* MOV.L   Rm, [R0 + Rn] */
nkeynes@1
   406
                    MEM_WRITE_LONG( R0 + RN(ir), RM(ir) );
nkeynes@1
   407
                    break;
nkeynes@1
   408
                case 7: /* MUL.L   Rm, Rn */
nkeynes@2
   409
                    sh4r.mac = (sh4r.mac&0xFFFFFFFF00000000LL) |
nkeynes@1
   410
                        (RM(ir) * RN(ir));
nkeynes@1
   411
                    break;
nkeynes@1
   412
                case 8: 
nkeynes@1
   413
                    switch( (ir&0x0FF0)>>4 ) {
nkeynes@1
   414
                        case 0: /* CLRT    */
nkeynes@1
   415
                            sh4r.t = 0;
nkeynes@1
   416
                            break;
nkeynes@1
   417
                        case 1: /* SETT    */
nkeynes@1
   418
                            sh4r.t = 1;
nkeynes@1
   419
                            break;
nkeynes@1
   420
                        case 2: /* CLRMAC  */
nkeynes@1
   421
                            sh4r.mac = 0;
nkeynes@1
   422
                            break;
nkeynes@1
   423
                        case 3: /* LDTLB   */
nkeynes@1
   424
                            break;
nkeynes@1
   425
                        case 4: /* CLRS    */
nkeynes@1
   426
                            sh4r.s = 0;
nkeynes@1
   427
                            break;
nkeynes@1
   428
                        case 5: /* SETS    */
nkeynes@1
   429
                            sh4r.s = 1;
nkeynes@1
   430
                            break;
nkeynes@1
   431
                        default: UNDEF(ir);
nkeynes@1
   432
                    }
nkeynes@1
   433
                    break;
nkeynes@1
   434
                case 9: 
nkeynes@1
   435
                    if( (ir&0x00F0) == 0x20 ) /* MOVT    Rn */
nkeynes@1
   436
                        RN(ir) = sh4r.t;
nkeynes@1
   437
                    else if( ir == 0x0019 ) /* DIV0U   */
nkeynes@1
   438
                        sh4r.m = sh4r.q = sh4r.t = 0;
nkeynes@1
   439
                    else if( ir == 0x0009 )
nkeynes@1
   440
                        /* NOP     */;
nkeynes@1
   441
                    else UNDEF(ir);
nkeynes@1
   442
                    break;
nkeynes@1
   443
                case 10:
nkeynes@1
   444
                    switch( (ir&0x00F0) >> 4 ) {
nkeynes@1
   445
                        case 0: /* STS     MACH, Rn */
nkeynes@1
   446
                            RN(ir) = sh4r.mac >> 32;
nkeynes@1
   447
                            break;
nkeynes@1
   448
                        case 1: /* STS     MACL, Rn */
nkeynes@1
   449
                            RN(ir) = (uint32_t)sh4r.mac;
nkeynes@1
   450
                            break;
nkeynes@1
   451
                        case 2: /* STS     PR, Rn */
nkeynes@1
   452
                            RN(ir) = sh4r.pr;
nkeynes@1
   453
                            break;
nkeynes@1
   454
                        case 3: /* STC     SGR, Rn */
nkeynes@1
   455
                            CHECKPRIV();
nkeynes@1
   456
                            RN(ir) = sh4r.sgr;
nkeynes@1
   457
                            break;
nkeynes@1
   458
                        case 5:/* STS      FPUL, Rn */
nkeynes@1
   459
                            RN(ir) = sh4r.fpul;
nkeynes@1
   460
                            break;
nkeynes@1
   461
                        case 6: /* STS     FPSCR, Rn */
nkeynes@1
   462
                            RN(ir) = sh4r.fpscr;
nkeynes@1
   463
                            break;
nkeynes@1
   464
                        case 15:/* STC     DBR, Rn */
nkeynes@1
   465
                            CHECKPRIV();
nkeynes@1
   466
                            RN(ir) = sh4r.dbr;
nkeynes@1
   467
                            break;
nkeynes@1
   468
                        default: UNDEF(ir);
nkeynes@1
   469
                    }
nkeynes@1
   470
                    break;
nkeynes@1
   471
                case 11:
nkeynes@1
   472
                    switch( (ir&0x0FF0)>>4 ) {
nkeynes@1
   473
                        case 0: /* RTS     */
nkeynes@1
   474
                            CHECKDEST( sh4r.pr );
nkeynes@2
   475
                            CHECKSLOTILLEGAL();
nkeynes@2
   476
                            sh4r.in_delay_slot = 1;
nkeynes@1
   477
                            sh4r.pc = sh4r.new_pc;
nkeynes@1
   478
                            sh4r.new_pc = sh4r.pr;
nkeynes@27
   479
                            return TRUE;
nkeynes@1
   480
                        case 1: /* SLEEP   */
nkeynes@27
   481
			    if( MMIO_READ( CPG, STBCR ) & 0x80 ) {
nkeynes@27
   482
				sh4r.sh4_state = SH4_STATE_STANDBY;
nkeynes@27
   483
			    } else {
nkeynes@27
   484
				sh4r.sh4_state = SH4_STATE_SLEEP;
nkeynes@27
   485
			    }
nkeynes@27
   486
			    return FALSE; /* Halt CPU */
nkeynes@1
   487
                        case 2: /* RTE     */
nkeynes@1
   488
                            CHECKPRIV();
nkeynes@1
   489
                            CHECKDEST( sh4r.spc );
nkeynes@2
   490
                            CHECKSLOTILLEGAL();
nkeynes@2
   491
                            sh4r.in_delay_slot = 1;
nkeynes@1
   492
                            sh4r.pc = sh4r.new_pc;
nkeynes@1
   493
                            sh4r.new_pc = sh4r.spc;
nkeynes@1
   494
                            sh4_load_sr( sh4r.ssr );
nkeynes@27
   495
                            return TRUE;
nkeynes@1
   496
                        default:UNDEF(ir);
nkeynes@1
   497
                    }
nkeynes@1
   498
                    break;
nkeynes@1
   499
                case 12:/* MOV.B   [R0+R%d], R%d */
nkeynes@1
   500
                    RN(ir) = MEM_READ_BYTE( R0 + RM(ir) );
nkeynes@1
   501
                    break;
nkeynes@1
   502
                case 13:/* MOV.W   [R0+R%d], R%d */
nkeynes@1
   503
                    RN(ir) = MEM_READ_WORD( R0 + RM(ir) );
nkeynes@1
   504
                    break;
nkeynes@1
   505
                case 14:/* MOV.L   [R0+R%d], R%d */
nkeynes@1
   506
                    RN(ir) = MEM_READ_LONG( R0 + RM(ir) );
nkeynes@1
   507
                    break;
nkeynes@1
   508
                case 15:/* MAC.L   [Rm++], [Rn++] */
nkeynes@1
   509
                    tmpl = ( SIGNEXT32(MEM_READ_LONG(RM(ir))) *
nkeynes@1
   510
                                  SIGNEXT32(MEM_READ_LONG(RN(ir))) );
nkeynes@1
   511
                    if( sh4r.s ) {
nkeynes@1
   512
                        /* 48-bit Saturation. Yuch */
nkeynes@1
   513
                        tmpl += SIGNEXT48(sh4r.mac);
nkeynes@2
   514
                        if( tmpl < 0xFFFF800000000000LL )
nkeynes@2
   515
                            tmpl = 0xFFFF800000000000LL;
nkeynes@2
   516
                        else if( tmpl > 0x00007FFFFFFFFFFFLL )
nkeynes@2
   517
                            tmpl = 0x00007FFFFFFFFFFFLL;
nkeynes@2
   518
                        sh4r.mac = (sh4r.mac&0xFFFF000000000000LL) |
nkeynes@2
   519
                            (tmpl&0x0000FFFFFFFFFFFFLL);
nkeynes@1
   520
                    } else sh4r.mac = tmpl;
nkeynes@1
   521
                    
nkeynes@1
   522
                    RM(ir) += 4;
nkeynes@1
   523
                    RN(ir) += 4;
nkeynes@1
   524
                    
nkeynes@1
   525
                    break;
nkeynes@1
   526
                default: UNDEF(ir);
nkeynes@1
   527
            }
nkeynes@1
   528
            break;
nkeynes@1
   529
        case 1: /* 0001nnnnmmmmdddd */
nkeynes@1
   530
            /* MOV.L   Rm, [Rn + disp4*4] */
nkeynes@1
   531
            MEM_WRITE_LONG( RN(ir) + (DISP4(ir)<<2), RM(ir) );
nkeynes@1
   532
            break;
nkeynes@1
   533
        case 2: /* 0010nnnnmmmmxxxx */
nkeynes@1
   534
            switch( ir&0x000F ) {
nkeynes@1
   535
                case 0: /* MOV.B   Rm, [Rn] */
nkeynes@1
   536
                    MEM_WRITE_BYTE( RN(ir), RM(ir) );
nkeynes@1
   537
                    break;
nkeynes@1
   538
                case 1: /* MOV.W   Rm, [Rn] */
nkeynes@1
   539
                    MEM_WRITE_WORD( RN(ir), RM(ir) );
nkeynes@1
   540
                    break;
nkeynes@1
   541
                case 2: /* MOV.L   Rm, [Rn] */
nkeynes@1
   542
                    MEM_WRITE_LONG( RN(ir), RM(ir) );
nkeynes@1
   543
                    break;
nkeynes@1
   544
                case 3: UNDEF(ir);
nkeynes@1
   545
                    break;
nkeynes@1
   546
                case 4: /* MOV.B   Rm, [--Rn] */
nkeynes@1
   547
                    RN(ir) --;
nkeynes@1
   548
                    MEM_WRITE_BYTE( RN(ir), RM(ir) );
nkeynes@1
   549
                    break;
nkeynes@1
   550
                case 5: /* MOV.W   Rm, [--Rn] */
nkeynes@1
   551
                    RN(ir) -= 2;
nkeynes@1
   552
                    MEM_WRITE_WORD( RN(ir), RM(ir) );
nkeynes@1
   553
                    break;
nkeynes@1
   554
                case 6: /* MOV.L   Rm, [--Rn] */
nkeynes@1
   555
                    RN(ir) -= 4;
nkeynes@1
   556
                    MEM_WRITE_LONG( RN(ir), RM(ir) );
nkeynes@1
   557
                    break;
nkeynes@1
   558
                case 7: /* DIV0S   Rm, Rn */
nkeynes@1
   559
                    sh4r.q = RN(ir)>>31;
nkeynes@1
   560
                    sh4r.m = RM(ir)>>31;
nkeynes@1
   561
                    sh4r.t = sh4r.q ^ sh4r.m;
nkeynes@1
   562
                    break;
nkeynes@1
   563
                case 8: /* TST     Rm, Rn */
nkeynes@1
   564
                    sh4r.t = (RN(ir)&RM(ir) ? 0 : 1);
nkeynes@1
   565
                    break;
nkeynes@1
   566
                case 9: /* AND     Rm, Rn */
nkeynes@1
   567
                    RN(ir) &= RM(ir);
nkeynes@1
   568
                    break;
nkeynes@1
   569
                case 10:/* XOR     Rm, Rn */
nkeynes@1
   570
                    RN(ir) ^= RM(ir);
nkeynes@1
   571
                    break;
nkeynes@1
   572
                case 11:/* OR      Rm, Rn */
nkeynes@1
   573
                    RN(ir) |= RM(ir);
nkeynes@1
   574
                    break;
nkeynes@1
   575
                case 12:/* CMP/STR Rm, Rn */
nkeynes@1
   576
                    /* set T = 1 if any byte in RM & RN is the same */
nkeynes@1
   577
                    tmp = RM(ir) ^ RN(ir);
nkeynes@1
   578
                    sh4r.t = ((tmp&0x000000FF)==0 || (tmp&0x0000FF00)==0 ||
nkeynes@1
   579
                              (tmp&0x00FF0000)==0 || (tmp&0xFF000000)==0)?1:0;
nkeynes@1
   580
                    break;
nkeynes@1
   581
                case 13:/* XTRCT   Rm, Rn */
nkeynes@1
   582
                    RN(ir) = (RN(ir)>>16) | (RM(ir)<<16);
nkeynes@1
   583
                    break;
nkeynes@1
   584
                case 14:/* MULU.W  Rm, Rn */
nkeynes@2
   585
                    sh4r.mac = (sh4r.mac&0xFFFFFFFF00000000LL) |
nkeynes@1
   586
                        (uint32_t)((RM(ir)&0xFFFF) * (RN(ir)&0xFFFF));
nkeynes@1
   587
                    break;
nkeynes@1
   588
                case 15:/* MULS.W  Rm, Rn */
nkeynes@2
   589
                    sh4r.mac = (sh4r.mac&0xFFFFFFFF00000000LL) |
nkeynes@1
   590
                        (uint32_t)(SIGNEXT32(RM(ir)&0xFFFF) * SIGNEXT32(RN(ir)&0xFFFF));
nkeynes@1
   591
                    break;
nkeynes@1
   592
            }
nkeynes@1
   593
            break;
nkeynes@1
   594
        case 3: /* 0011nnnnmmmmxxxx */
nkeynes@1
   595
            switch( ir&0x000F ) {
nkeynes@1
   596
                case 0: /* CMP/EQ  Rm, Rn */
nkeynes@1
   597
                    sh4r.t = ( RM(ir) == RN(ir) ? 1 : 0 );
nkeynes@1
   598
                    break;
nkeynes@1
   599
                case 2: /* CMP/HS  Rm, Rn */
nkeynes@1
   600
                    sh4r.t = ( RN(ir) >= RM(ir) ? 1 : 0 );
nkeynes@1
   601
                    break;
nkeynes@1
   602
                case 3: /* CMP/GE  Rm, Rn */
nkeynes@1
   603
                    sh4r.t = ( ((int32_t)RN(ir)) >= ((int32_t)RM(ir)) ? 1 : 0 );
nkeynes@1
   604
                    break;
nkeynes@1
   605
                case 4: { /* DIV1    Rm, Rn */
nkeynes@1
   606
                    /* This is just from the sh4p manual with some
nkeynes@1
   607
                     * simplifications (someone want to check it's correct? :)
nkeynes@1
   608
                     * Why they couldn't just provide a real DIV instruction...
nkeynes@1
   609
                     * Please oh please let the translator batch these things
nkeynes@1
   610
                     * up into a single DIV... */
nkeynes@1
   611
                    uint32_t tmp0, tmp1, tmp2, dir;
nkeynes@1
   612
nkeynes@1
   613
                    dir = sh4r.q ^ sh4r.m;
nkeynes@1
   614
                    sh4r.q = (RN(ir) >> 31);
nkeynes@1
   615
                    tmp2 = RM(ir);
nkeynes@1
   616
                    RN(ir) = (RN(ir) << 1) | sh4r.t;
nkeynes@1
   617
                    tmp0 = RN(ir);
nkeynes@1
   618
                    if( dir ) {
nkeynes@1
   619
                        RN(ir) += tmp2;
nkeynes@1
   620
                        tmp1 = (RN(ir)<tmp0 ? 1 : 0 );
nkeynes@1
   621
                    } else {
nkeynes@1
   622
                        RN(ir) -= tmp2;
nkeynes@1
   623
                        tmp1 = (RN(ir)>tmp0 ? 1 : 0 );
nkeynes@1
   624
                    }
nkeynes@1
   625
                    sh4r.q ^= sh4r.m ^ tmp1;
nkeynes@1
   626
                    sh4r.t = ( sh4r.q == sh4r.m ? 1 : 0 );
nkeynes@1
   627
                    break; }
nkeynes@1
   628
                case 5: /* DMULU.L Rm, Rn */
nkeynes@1
   629
                    sh4r.mac = ((uint64_t)RM(ir)) * ((uint64_t)RN(ir));
nkeynes@1
   630
                    break;
nkeynes@1
   631
                case 6: /* CMP/HI  Rm, Rn */
nkeynes@1
   632
                    sh4r.t = ( RN(ir) > RM(ir) ? 1 : 0 );
nkeynes@1
   633
                    break;
nkeynes@1
   634
                case 7: /* CMP/GT  Rm, Rn */
nkeynes@1
   635
                    sh4r.t = ( ((int32_t)RN(ir)) > ((int32_t)RM(ir)) ? 1 : 0 );
nkeynes@1
   636
                    break;
nkeynes@1
   637
                case 8: /* SUB     Rm, Rn */
nkeynes@1
   638
                    RN(ir) -= RM(ir);
nkeynes@1
   639
                    break;
nkeynes@1
   640
                case 10:/* SUBC    Rm, Rn */
nkeynes@1
   641
                    tmp = RN(ir);
nkeynes@1
   642
                    RN(ir) = RN(ir) - RM(ir) - sh4r.t;
nkeynes@1
   643
                    sh4r.t = (RN(ir) > tmp || (RN(ir) == tmp && sh4r.t == 1));
nkeynes@1
   644
                    break;
nkeynes@1
   645
                case 11:/* SUBV    Rm, Rn */
nkeynes@1
   646
                    UNIMP(ir);
nkeynes@1
   647
                    break;
nkeynes@1
   648
                case 12:/* ADD     Rm, Rn */
nkeynes@1
   649
                    RN(ir) += RM(ir);
nkeynes@1
   650
                    break;
nkeynes@1
   651
                case 13:/* DMULS.L Rm, Rn */
nkeynes@1
   652
                    sh4r.mac = SIGNEXT32(RM(ir)) * SIGNEXT32(RN(ir));
nkeynes@1
   653
                    break;
nkeynes@1
   654
                case 14:/* ADDC    Rm, Rn */
nkeynes@1
   655
                    tmp = RN(ir);
nkeynes@1
   656
                    RN(ir) += RM(ir) + sh4r.t;
nkeynes@1
   657
                    sh4r.t = ( RN(ir) < tmp || (RN(ir) == tmp && sh4r.t != 0) ? 1 : 0 );
nkeynes@1
   658
                    break;
nkeynes@1
   659
                case 15:/* ADDV    Rm, Rn */
nkeynes@1
   660
                    UNIMP(ir);
nkeynes@1
   661
                    break;
nkeynes@1
   662
                default: UNDEF(ir);
nkeynes@1
   663
            }
nkeynes@1
   664
            break;
nkeynes@1
   665
        case 4: /* 0100nnnnxxxxxxxx */
nkeynes@1
   666
            switch( ir&0x00FF ) {
nkeynes@1
   667
                case 0x00: /* SHLL    Rn */
nkeynes@1
   668
                    sh4r.t = RN(ir) >> 31;
nkeynes@1
   669
                    RN(ir) <<= 1;
nkeynes@1
   670
                    break;
nkeynes@1
   671
                case 0x01: /* SHLR    Rn */
nkeynes@1
   672
                    sh4r.t = RN(ir) & 0x00000001;
nkeynes@1
   673
                    RN(ir) >>= 1;
nkeynes@1
   674
                    break;
nkeynes@1
   675
                case 0x02: /* STS.L   MACH, [--Rn] */
nkeynes@1
   676
                    RN(ir) -= 4;
nkeynes@1
   677
                    MEM_WRITE_LONG( RN(ir), (sh4r.mac>>32) );
nkeynes@1
   678
                    break;
nkeynes@1
   679
                case 0x03: /* STC.L   SR, [--Rn] */
nkeynes@1
   680
                    CHECKPRIV();
nkeynes@1
   681
                    RN(ir) -= 4;
nkeynes@1
   682
                    MEM_WRITE_LONG( RN(ir), sh4_read_sr() );
nkeynes@1
   683
                    break;
nkeynes@1
   684
                case 0x04: /* ROTL    Rn */
nkeynes@1
   685
                    sh4r.t = RN(ir) >> 31;
nkeynes@1
   686
                    RN(ir) <<= 1;
nkeynes@1
   687
                    RN(ir) |= sh4r.t;
nkeynes@1
   688
                    break;
nkeynes@1
   689
                case 0x05: /* ROTR    Rn */
nkeynes@1
   690
                    sh4r.t = RN(ir) & 0x00000001;
nkeynes@1
   691
                    RN(ir) >>= 1;
nkeynes@1
   692
                    RN(ir) |= (sh4r.t << 31);
nkeynes@1
   693
                    break;
nkeynes@1
   694
                case 0x06: /* LDS.L   [Rn++], MACH */
nkeynes@1
   695
                    sh4r.mac = (sh4r.mac & 0x00000000FFFFFFFF) |
nkeynes@1
   696
                        (((uint64_t)MEM_READ_LONG(RN(ir)))<<32);
nkeynes@1
   697
                    RN(ir) += 4;
nkeynes@1
   698
                    break;
nkeynes@1
   699
                case 0x07: /* LDC.L   [Rn++], SR */
nkeynes@1
   700
                    CHECKPRIV();
nkeynes@1
   701
                    sh4_load_sr( MEM_READ_LONG(RN(ir)) );
nkeynes@1
   702
                    RN(ir) +=4;
nkeynes@1
   703
                    break;
nkeynes@1
   704
                case 0x08: /* SHLL2   Rn */
nkeynes@1
   705
                    RN(ir) <<= 2;
nkeynes@1
   706
                    break;
nkeynes@1
   707
                case 0x09: /* SHLR2   Rn */
nkeynes@1
   708
                    RN(ir) >>= 2;
nkeynes@1
   709
                    break;
nkeynes@1
   710
                case 0x0A: /* LDS     Rn, MACH */
nkeynes@1
   711
                    sh4r.mac = (sh4r.mac & 0x00000000FFFFFFFF) |
nkeynes@1
   712
                        (((uint64_t)RN(ir))<<32);
nkeynes@1
   713
                    break;
nkeynes@1
   714
                case 0x0B: /* JSR     [Rn] */
nkeynes@1
   715
                    CHECKDEST( RN(ir) );
nkeynes@2
   716
                    CHECKSLOTILLEGAL();
nkeynes@2
   717
                    sh4r.in_delay_slot = 1;
nkeynes@1
   718
                    sh4r.pc = sh4r.new_pc;
nkeynes@1
   719
                    sh4r.new_pc = RN(ir);
nkeynes@1
   720
                    sh4r.pr = pc + 4;
nkeynes@27
   721
                    return TRUE;
nkeynes@1
   722
                case 0x0E: /* LDC     Rn, SR */
nkeynes@1
   723
                    CHECKPRIV();
nkeynes@1
   724
                    sh4_load_sr( RN(ir) );
nkeynes@1
   725
                    break;
nkeynes@1
   726
                case 0x10: /* DT      Rn */
nkeynes@1
   727
                    RN(ir) --;
nkeynes@1
   728
                    sh4r.t = ( RN(ir) == 0 ? 1 : 0 );
nkeynes@1
   729
                    break;
nkeynes@1
   730
                case 0x11: /* CMP/PZ  Rn */
nkeynes@1
   731
                    sh4r.t = ( ((int32_t)RN(ir)) >= 0 ? 1 : 0 );
nkeynes@1
   732
                    break;
nkeynes@1
   733
                case 0x12: /* STS.L   MACL, [--Rn] */
nkeynes@1
   734
                    RN(ir) -= 4;
nkeynes@1
   735
                    MEM_WRITE_LONG( RN(ir), (uint32_t)sh4r.mac );
nkeynes@1
   736
                    break;
nkeynes@1
   737
                case 0x13: /* STC.L   GBR, [--Rn] */
nkeynes@1
   738
                    RN(ir) -= 4;
nkeynes@1
   739
                    MEM_WRITE_LONG( RN(ir), sh4r.gbr );
nkeynes@1
   740
                    break;
nkeynes@1
   741
                case 0x15: /* CMP/PL  Rn */
nkeynes@1
   742
                    sh4r.t = ( ((int32_t)RN(ir)) > 0 ? 1 : 0 );
nkeynes@1
   743
                    break;
nkeynes@1
   744
                case 0x16: /* LDS.L   [Rn++], MACL */
nkeynes@2
   745
                    sh4r.mac = (sh4r.mac & 0xFFFFFFFF00000000LL) |
nkeynes@1
   746
                        (uint64_t)((uint32_t)MEM_READ_LONG(RN(ir)));
nkeynes@1
   747
                    RN(ir) += 4;
nkeynes@1
   748
                    break;
nkeynes@1
   749
                case 0x17: /* LDC.L   [Rn++], GBR */
nkeynes@1
   750
                    sh4r.gbr = MEM_READ_LONG(RN(ir));
nkeynes@1
   751
                    RN(ir) +=4;
nkeynes@1
   752
                    break;
nkeynes@1
   753
                case 0x18: /* SHLL8   Rn */
nkeynes@1
   754
                    RN(ir) <<= 8;
nkeynes@1
   755
                    break;
nkeynes@1
   756
                case 0x19: /* SHLR8   Rn */
nkeynes@1
   757
                    RN(ir) >>= 8;
nkeynes@1
   758
                    break;
nkeynes@1
   759
                case 0x1A: /* LDS     Rn, MACL */
nkeynes@2
   760
                    sh4r.mac = (sh4r.mac & 0xFFFFFFFF00000000LL) |
nkeynes@1
   761
                        (uint64_t)((uint32_t)(RN(ir)));
nkeynes@1
   762
                    break;
nkeynes@1
   763
                case 0x1B: /* TAS.B   [Rn] */
nkeynes@1
   764
                    tmp = MEM_READ_BYTE( RN(ir) );
nkeynes@1
   765
                    sh4r.t = ( tmp == 0 ? 1 : 0 );
nkeynes@1
   766
                    MEM_WRITE_BYTE( RN(ir), tmp | 0x80 );
nkeynes@1
   767
                    break;
nkeynes@1
   768
                case 0x1E: /* LDC     Rn, GBR */
nkeynes@1
   769
                    sh4r.gbr = RN(ir);
nkeynes@1
   770
                    break;
nkeynes@1
   771
                case 0x20: /* SHAL    Rn */
nkeynes@1
   772
                    sh4r.t = RN(ir) >> 31;
nkeynes@1
   773
                    RN(ir) <<= 1;
nkeynes@1
   774
                    break;
nkeynes@1
   775
                case 0x21: /* SHAR    Rn */
nkeynes@1
   776
                    sh4r.t = RN(ir) & 0x00000001;
nkeynes@1
   777
                    RN(ir) = ((int32_t)RN(ir)) >> 1;
nkeynes@1
   778
                    break;
nkeynes@1
   779
                case 0x22: /* STS.L   PR, [--Rn] */
nkeynes@1
   780
                    RN(ir) -= 4;
nkeynes@1
   781
                    MEM_WRITE_LONG( RN(ir), sh4r.pr );
nkeynes@1
   782
                    break;
nkeynes@1
   783
                case 0x23: /* STC.L   VBR, [--Rn] */
nkeynes@1
   784
                    CHECKPRIV();
nkeynes@1
   785
                    RN(ir) -= 4;
nkeynes@2
   786
                    MEM_WRITE_LONG( RN(ir), sh4r.vbr );
nkeynes@1
   787
                    break;
nkeynes@1
   788
                case 0x24: /* ROTCL   Rn */
nkeynes@1
   789
                    tmp = RN(ir) >> 31;
nkeynes@1
   790
                    RN(ir) <<= 1;
nkeynes@1
   791
                    RN(ir) |= sh4r.t;
nkeynes@1
   792
                    sh4r.t = tmp;
nkeynes@1
   793
                    break;
nkeynes@1
   794
                case 0x25: /* ROTCR   Rn */
nkeynes@1
   795
                    tmp = RN(ir) & 0x00000001;
nkeynes@1
   796
                    RN(ir) >>= 1;
nkeynes@1
   797
                    RN(ir) |= (sh4r.t << 31 );
nkeynes@1
   798
                    sh4r.t = tmp;
nkeynes@1
   799
                    break;
nkeynes@1
   800
                case 0x26: /* LDS.L   [Rn++], PR */
nkeynes@1
   801
                    sh4r.pr = MEM_READ_LONG( RN(ir) );
nkeynes@1
   802
                    RN(ir) += 4;
nkeynes@1
   803
                    break;
nkeynes@1
   804
                case 0x27: /* LDC.L   [Rn++], VBR */
nkeynes@1
   805
                    CHECKPRIV();
nkeynes@1
   806
                    sh4r.vbr = MEM_READ_LONG(RN(ir));
nkeynes@1
   807
                    RN(ir) +=4;
nkeynes@1
   808
                    break;
nkeynes@1
   809
                case 0x28: /* SHLL16  Rn */
nkeynes@1
   810
                    RN(ir) <<= 16;
nkeynes@1
   811
                    break;
nkeynes@1
   812
                case 0x29: /* SHLR16  Rn */
nkeynes@1
   813
                    RN(ir) >>= 16;
nkeynes@1
   814
                    break;
nkeynes@1
   815
                case 0x2A: /* LDS     Rn, PR */
nkeynes@1
   816
                    sh4r.pr = RN(ir);
nkeynes@1
   817
                    break;
nkeynes@1
   818
                case 0x2B: /* JMP     [Rn] */
nkeynes@1
   819
                    CHECKDEST( RN(ir) );
nkeynes@2
   820
                    CHECKSLOTILLEGAL();
nkeynes@2
   821
                    sh4r.in_delay_slot = 1;
nkeynes@1
   822
                    sh4r.pc = sh4r.new_pc;
nkeynes@1
   823
                    sh4r.new_pc = RN(ir);
nkeynes@27
   824
                    return TRUE;
nkeynes@1
   825
                case 0x2E: /* LDC     Rn, VBR */
nkeynes@1
   826
                    CHECKPRIV();
nkeynes@1
   827
                    sh4r.vbr = RN(ir);
nkeynes@1
   828
                    break;
nkeynes@1
   829
                case 0x32: /* STC.L   SGR, [--Rn] */
nkeynes@1
   830
                    CHECKPRIV();
nkeynes@1
   831
                    RN(ir) -= 4;
nkeynes@1
   832
                    MEM_WRITE_LONG( RN(ir), sh4r.sgr );
nkeynes@1
   833
                    break;
nkeynes@1
   834
                case 0x33: /* STC.L   SSR, [--Rn] */
nkeynes@1
   835
                    CHECKPRIV();
nkeynes@1
   836
                    RN(ir) -= 4;
nkeynes@1
   837
                    MEM_WRITE_LONG( RN(ir), sh4r.ssr );
nkeynes@1
   838
                    break;
nkeynes@1
   839
                case 0x37: /* LDC.L   [Rn++], SSR */
nkeynes@1
   840
                    CHECKPRIV();
nkeynes@1
   841
                    sh4r.ssr = MEM_READ_LONG(RN(ir));
nkeynes@1
   842
                    RN(ir) +=4;
nkeynes@1
   843
                    break;
nkeynes@1
   844
                case 0x3E: /* LDC     Rn, SSR */
nkeynes@1
   845
                    CHECKPRIV();
nkeynes@1
   846
                    sh4r.ssr = RN(ir);
nkeynes@1
   847
                    break;
nkeynes@1
   848
                case 0x43: /* STC.L   SPC, [--Rn] */
nkeynes@1
   849
                    CHECKPRIV();
nkeynes@1
   850
                    RN(ir) -= 4;
nkeynes@1
   851
                    MEM_WRITE_LONG( RN(ir), sh4r.spc );
nkeynes@1
   852
                    break;
nkeynes@1
   853
                case 0x47: /* LDC.L   [Rn++], SPC */
nkeynes@1
   854
                    CHECKPRIV();
nkeynes@1
   855
                    sh4r.spc = MEM_READ_LONG(RN(ir));
nkeynes@1
   856
                    RN(ir) +=4;
nkeynes@1
   857
                    break;
nkeynes@1
   858
                case 0x4E: /* LDC     Rn, SPC */
nkeynes@1
   859
                    CHECKPRIV();
nkeynes@1
   860
                    sh4r.spc = RN(ir);
nkeynes@1
   861
                    break;
nkeynes@1
   862
                case 0x52: /* STS.L   FPUL, [--Rn] */
nkeynes@1
   863
                    RN(ir) -= 4;
nkeynes@1
   864
                    MEM_WRITE_LONG( RN(ir), sh4r.fpul );
nkeynes@1
   865
                    break;
nkeynes@1
   866
                case 0x56: /* LDS.L   [Rn++], FPUL */
nkeynes@1
   867
                    sh4r.fpul = MEM_READ_LONG(RN(ir));
nkeynes@1
   868
                    RN(ir) +=4;
nkeynes@1
   869
                    break;
nkeynes@1
   870
                case 0x5A: /* LDS     Rn, FPUL */
nkeynes@1
   871
                    sh4r.fpul = RN(ir);
nkeynes@1
   872
                    break;
nkeynes@1
   873
                case 0x62: /* STS.L   FPSCR, [--Rn] */
nkeynes@1
   874
                    RN(ir) -= 4;
nkeynes@1
   875
                    MEM_WRITE_LONG( RN(ir), sh4r.fpscr );
nkeynes@1
   876
                    break;
nkeynes@1
   877
                case 0x66: /* LDS.L   [Rn++], FPSCR */
nkeynes@1
   878
                    sh4r.fpscr = MEM_READ_LONG(RN(ir));
nkeynes@1
   879
                    RN(ir) +=4;
nkeynes@1
   880
                    break;
nkeynes@1
   881
                case 0x6A: /* LDS     Rn, FPSCR */
nkeynes@1
   882
                    sh4r.fpscr = RN(ir);
nkeynes@1
   883
                    break;
nkeynes@1
   884
                case 0xF2: /* STC.L   DBR, [--Rn] */
nkeynes@1
   885
                    CHECKPRIV();
nkeynes@1
   886
                    RN(ir) -= 4;
nkeynes@1
   887
                    MEM_WRITE_LONG( RN(ir), sh4r.dbr );
nkeynes@1
   888
                    break;
nkeynes@1
   889
                case 0xF6: /* LDC.L   [Rn++], DBR */
nkeynes@1
   890
                    CHECKPRIV();
nkeynes@1
   891
                    sh4r.dbr = MEM_READ_LONG(RN(ir));
nkeynes@1
   892
                    RN(ir) +=4;
nkeynes@1
   893
                    break;
nkeynes@1
   894
                case 0xFA: /* LDC     Rn, DBR */
nkeynes@1
   895
                    CHECKPRIV();
nkeynes@1
   896
                    sh4r.dbr = RN(ir);
nkeynes@1
   897
                    break;
nkeynes@1
   898
                case 0x83: case 0x93: case 0xA3: case 0xB3: case 0xC3:
nkeynes@1
   899
                case 0xD3: case 0xE3: case 0xF3: /* STC.L   Rn_BANK, [--Rn] */
nkeynes@1
   900
                    CHECKPRIV();
nkeynes@1
   901
                    RN(ir) -= 4;
nkeynes@1
   902
                    MEM_WRITE_LONG( RN(ir), RN_BANK(ir) );
nkeynes@1
   903
                    break;
nkeynes@1
   904
                case 0x87: case 0x97: case 0xA7: case 0xB7: case 0xC7:
nkeynes@1
   905
                case 0xD7: case 0xE7: case 0xF7: /* LDC.L   [Rn++], Rn_BANK */
nkeynes@1
   906
                    CHECKPRIV();
nkeynes@1
   907
                    RN_BANK(ir) = MEM_READ_LONG( RN(ir) );
nkeynes@1
   908
                    RN(ir) += 4;
nkeynes@1
   909
                    break;
nkeynes@1
   910
                case 0x8E: case 0x9E: case 0xAE: case 0xBE: case 0xCE:
nkeynes@1
   911
                case 0xDE: case 0xEE: case 0xFE: /* LDC     Rm, Rn_BANK */
nkeynes@1
   912
                    CHECKPRIV();
nkeynes@1
   913
                    RN_BANK(ir) = RM(ir);
nkeynes@1
   914
                    break;
nkeynes@1
   915
                default:
nkeynes@1
   916
                    if( (ir&0x000F) == 0x0F ) {
nkeynes@1
   917
                        /* MAC.W   [Rm++], [Rn++] */
nkeynes@1
   918
                        tmp = SIGNEXT16(MEM_READ_WORD(RM(ir))) *
nkeynes@1
   919
                            SIGNEXT16(MEM_READ_WORD(RN(ir)));
nkeynes@1
   920
                        if( sh4r.s ) {
nkeynes@1
   921
                            /* FIXME */
nkeynes@1
   922
                            UNIMP(ir);
nkeynes@1
   923
                        } else sh4r.mac += SIGNEXT32(tmp);
nkeynes@1
   924
                        RM(ir) += 2;
nkeynes@1
   925
                        RN(ir) += 2;
nkeynes@1
   926
                    } else if( (ir&0x000F) == 0x0C ) {
nkeynes@1
   927
                        /* SHAD    Rm, Rn */
nkeynes@1
   928
                        tmp = RM(ir);
nkeynes@1
   929
                        if( (tmp & 0x80000000) == 0 ) RN(ir) <<= (tmp&0x1f);
nkeynes@9
   930
                        else if( (tmp & 0x1F) == 0 )  
nkeynes@9
   931
			  RN(ir) = ((int32_t)RN(ir)) >> 31;
nkeynes@9
   932
                        else 
nkeynes@9
   933
			  RN(ir) = ((int32_t)RN(ir)) >> (((~RM(ir)) & 0x1F)+1);
nkeynes@1
   934
                    } else if( (ir&0x000F) == 0x0D ) {
nkeynes@1
   935
                        /* SHLD    Rm, Rn */
nkeynes@1
   936
                        tmp = RM(ir);
nkeynes@1
   937
                        if( (tmp & 0x80000000) == 0 ) RN(ir) <<= (tmp&0x1f);
nkeynes@1
   938
                        else if( (tmp & 0x1F) == 0 ) RN(ir) = 0;
nkeynes@1
   939
                        else RN(ir) >>= (((~tmp) & 0x1F)+1);
nkeynes@1
   940
                    } else UNDEF(ir);
nkeynes@1
   941
            }
nkeynes@1
   942
            break;
nkeynes@1
   943
        case 5: /* 0101nnnnmmmmdddd */
nkeynes@1
   944
            /* MOV.L   [Rm + disp4*4], Rn */
nkeynes@1
   945
            RN(ir) = MEM_READ_LONG( RM(ir) + (DISP4(ir)<<2) );
nkeynes@1
   946
            break;
nkeynes@1
   947
        case 6: /* 0110xxxxxxxxxxxx */
nkeynes@1
   948
            switch( ir&0x000f ) {
nkeynes@1
   949
                case 0: /* MOV.B   [Rm], Rn */
nkeynes@1
   950
                    RN(ir) = MEM_READ_BYTE( RM(ir) );
nkeynes@1
   951
                    break;
nkeynes@1
   952
                case 1: /* MOV.W   [Rm], Rn */
nkeynes@1
   953
                    RN(ir) = MEM_READ_WORD( RM(ir) );
nkeynes@1
   954
                    break;
nkeynes@1
   955
                case 2: /* MOV.L   [Rm], Rn */
nkeynes@1
   956
                    RN(ir) = MEM_READ_LONG( RM(ir) );
nkeynes@1
   957
                    break;
nkeynes@1
   958
                case 3: /* MOV     Rm, Rn */
nkeynes@1
   959
                    RN(ir) = RM(ir);
nkeynes@1
   960
                    break;
nkeynes@1
   961
                case 4: /* MOV.B   [Rm++], Rn */
nkeynes@1
   962
                    RN(ir) = MEM_READ_BYTE( RM(ir) );
nkeynes@1
   963
                    RM(ir) ++;
nkeynes@1
   964
                    break;
nkeynes@1
   965
                case 5: /* MOV.W   [Rm++], Rn */
nkeynes@1
   966
                    RN(ir) = MEM_READ_WORD( RM(ir) );
nkeynes@1
   967
                    RM(ir) += 2;
nkeynes@1
   968
                    break;
nkeynes@1
   969
                case 6: /* MOV.L   [Rm++], Rn */
nkeynes@1
   970
                    RN(ir) = MEM_READ_LONG( RM(ir) );
nkeynes@1
   971
                    RM(ir) += 4;
nkeynes@1
   972
                    break;
nkeynes@1
   973
                case 7: /* NOT     Rm, Rn */
nkeynes@1
   974
                    RN(ir) = ~RM(ir);
nkeynes@1
   975
                    break;
nkeynes@1
   976
                case 8: /* SWAP.B  Rm, Rn */
nkeynes@1
   977
                    RN(ir) = (RM(ir)&0xFFFF0000) | ((RM(ir)&0x0000FF00)>>8) |
nkeynes@1
   978
                        ((RM(ir)&0x000000FF)<<8);
nkeynes@1
   979
                    break;
nkeynes@1
   980
                case 9: /* SWAP.W  Rm, Rn */
nkeynes@1
   981
                    RN(ir) = (RM(ir)>>16) | (RM(ir)<<16);
nkeynes@1
   982
                    break;
nkeynes@1
   983
                case 10:/* NEGC    Rm, Rn */
nkeynes@1
   984
                    tmp = 0 - RM(ir);
nkeynes@1
   985
                    RN(ir) = tmp - sh4r.t;
nkeynes@1
   986
                    sh4r.t = ( 0<tmp || tmp<RN(ir) ? 1 : 0 );
nkeynes@1
   987
                    break;
nkeynes@1
   988
                case 11:/* NEG     Rm, Rn */
nkeynes@1
   989
                    RN(ir) = 0 - RM(ir);
nkeynes@1
   990
                    break;
nkeynes@1
   991
                case 12:/* EXTU.B  Rm, Rn */
nkeynes@1
   992
                    RN(ir) = RM(ir)&0x000000FF;
nkeynes@1
   993
                    break;
nkeynes@1
   994
                case 13:/* EXTU.W  Rm, Rn */
nkeynes@1
   995
                    RN(ir) = RM(ir)&0x0000FFFF;
nkeynes@1
   996
                    break;
nkeynes@1
   997
                case 14:/* EXTS.B  Rm, Rn */
nkeynes@1
   998
                    RN(ir) = SIGNEXT8( RM(ir)&0x000000FF );
nkeynes@1
   999
                    break;
nkeynes@1
  1000
                case 15:/* EXTS.W  Rm, Rn */
nkeynes@1
  1001
                    RN(ir) = SIGNEXT16( RM(ir)&0x0000FFFF );
nkeynes@1
  1002
                    break;
nkeynes@1
  1003
            }
nkeynes@1
  1004
            break;
nkeynes@1
  1005
        case 7: /* 0111nnnniiiiiiii */
nkeynes@1
  1006
            /* ADD    imm8, Rn */
nkeynes@1
  1007
            RN(ir) += IMM8(ir);
nkeynes@1
  1008
            break;
nkeynes@1
  1009
        case 8: /* 1000xxxxxxxxxxxx */
nkeynes@1
  1010
            switch( (ir&0x0F00) >> 8 ) {
nkeynes@1
  1011
                case 0: /* MOV.B   R0, [Rm + disp4] */
nkeynes@1
  1012
                    MEM_WRITE_BYTE( RM(ir) + DISP4(ir), R0 );
nkeynes@1
  1013
                    break;
nkeynes@1
  1014
                case 1: /* MOV.W   R0, [Rm + disp4*2] */
nkeynes@1
  1015
                    MEM_WRITE_WORD( RM(ir) + (DISP4(ir)<<1), R0 );
nkeynes@1
  1016
                    break;
nkeynes@1
  1017
                case 4: /* MOV.B   [Rm + disp4], R0 */
nkeynes@1
  1018
                    R0 = MEM_READ_BYTE( RM(ir) + DISP4(ir) );
nkeynes@1
  1019
                    break;
nkeynes@1
  1020
                case 5: /* MOV.W   [Rm + disp4*2], R0 */
nkeynes@1
  1021
                    R0 = MEM_READ_WORD( RM(ir) + (DISP4(ir)<<1) );
nkeynes@1
  1022
                    break;
nkeynes@1
  1023
                case 8: /* CMP/EQ  imm, R0 */
nkeynes@1
  1024
                    sh4r.t = ( R0 == IMM8(ir) ? 1 : 0 );
nkeynes@1
  1025
                    break;
nkeynes@1
  1026
                case 9: /* BT      disp8 */
nkeynes@2
  1027
                    CHECKSLOTILLEGAL()
nkeynes@1
  1028
                    if( sh4r.t ) {
nkeynes@1
  1029
                        CHECKDEST( sh4r.pc + (PCDISP8(ir)<<1) + 4 )
nkeynes@1
  1030
                        sh4r.pc += (PCDISP8(ir)<<1) + 4;
nkeynes@1
  1031
                        sh4r.new_pc = sh4r.pc + 2;
nkeynes@27
  1032
                        return TRUE;
nkeynes@1
  1033
                    }
nkeynes@1
  1034
                    break;
nkeynes@1
  1035
                case 11:/* BF      disp8 */
nkeynes@2
  1036
                    CHECKSLOTILLEGAL()
nkeynes@1
  1037
                    if( !sh4r.t ) {
nkeynes@1
  1038
                        CHECKDEST( sh4r.pc + (PCDISP8(ir)<<1) + 4 )
nkeynes@1
  1039
                        sh4r.pc += (PCDISP8(ir)<<1) + 4;
nkeynes@1
  1040
                        sh4r.new_pc = sh4r.pc + 2;
nkeynes@27
  1041
                        return TRUE;
nkeynes@1
  1042
                    }
nkeynes@1
  1043
                    break;
nkeynes@1
  1044
                case 13:/* BT/S    disp8 */
nkeynes@2
  1045
                    CHECKSLOTILLEGAL()
nkeynes@1
  1046
                    if( sh4r.t ) {
nkeynes@1
  1047
                        CHECKDEST( sh4r.pc + (PCDISP8(ir)<<1) + 4 )
nkeynes@2
  1048
                        sh4r.in_delay_slot = 1;
nkeynes@1
  1049
                        sh4r.pc = sh4r.new_pc;
nkeynes@1
  1050
                        sh4r.new_pc = pc + (PCDISP8(ir)<<1) + 4;
nkeynes@2
  1051
                        sh4r.in_delay_slot = 1;
nkeynes@27
  1052
                        return TRUE;
nkeynes@1
  1053
                    }
nkeynes@1
  1054
                    break;
nkeynes@1
  1055
                case 15:/* BF/S    disp8 */
nkeynes@2
  1056
                    CHECKSLOTILLEGAL()
nkeynes@1
  1057
                    if( !sh4r.t ) {
nkeynes@1
  1058
                        CHECKDEST( sh4r.pc + (PCDISP8(ir)<<1) + 4 )
nkeynes@2
  1059
                        sh4r.in_delay_slot = 1;
nkeynes@1
  1060
                        sh4r.pc = sh4r.new_pc;
nkeynes@1
  1061
                        sh4r.new_pc = pc + (PCDISP8(ir)<<1) + 4;
nkeynes@27
  1062
                        return TRUE;
nkeynes@1
  1063
                    }
nkeynes@1
  1064
                    break;
nkeynes@1
  1065
                default: UNDEF(ir);
nkeynes@1
  1066
            }
nkeynes@1
  1067
            break;
nkeynes@1
  1068
        case 9: /* 1001xxxxxxxxxxxx */
nkeynes@1
  1069
            /* MOV.W   [disp8*2 + pc + 4], Rn */
nkeynes@1
  1070
            RN(ir) = MEM_READ_WORD( pc + 4 + (DISP8(ir)<<1) );
nkeynes@1
  1071
            break;
nkeynes@1
  1072
        case 10:/* 1010dddddddddddd */
nkeynes@1
  1073
            /* BRA     disp12 */
nkeynes@2
  1074
            CHECKDEST( sh4r.pc + (DISP12(ir)<<1) + 4 )
nkeynes@2
  1075
            CHECKSLOTILLEGAL()
nkeynes@2
  1076
            sh4r.in_delay_slot = 1;
nkeynes@1
  1077
            sh4r.pc = sh4r.new_pc;
nkeynes@1
  1078
            sh4r.new_pc = pc + 4 + (DISP12(ir)<<1);
nkeynes@27
  1079
            return TRUE;
nkeynes@1
  1080
        case 11:/* 1011dddddddddddd */
nkeynes@1
  1081
            /* BSR     disp12 */
nkeynes@1
  1082
            CHECKDEST( sh4r.pc + (DISP12(ir)<<1) + 4 )
nkeynes@2
  1083
            CHECKSLOTILLEGAL()
nkeynes@2
  1084
            sh4r.in_delay_slot = 1;
nkeynes@1
  1085
            sh4r.pr = pc + 4;
nkeynes@1
  1086
            sh4r.pc = sh4r.new_pc;
nkeynes@1
  1087
            sh4r.new_pc = pc + 4 + (DISP12(ir)<<1);
nkeynes@27
  1088
            return TRUE;
nkeynes@1
  1089
        case 12:/* 1100xxxxdddddddd */
nkeynes@1
  1090
        switch( (ir&0x0F00)>>8 ) {
nkeynes@1
  1091
                case 0: /* MOV.B  R0, [GBR + disp8] */
nkeynes@1
  1092
                    MEM_WRITE_BYTE( sh4r.gbr + DISP8(ir), R0 );
nkeynes@1
  1093
                    break;
nkeynes@1
  1094
                case 1: /* MOV.W  R0, [GBR + disp8*2] */
nkeynes@1
  1095
                    MEM_WRITE_WORD( sh4r.gbr + (DISP8(ir)<<1), R0 );
nkeynes@1
  1096
                    break;
nkeynes@1
  1097
                case  2: /*MOV.L   R0, [GBR + disp8*4] */
nkeynes@1
  1098
                    MEM_WRITE_LONG( sh4r.gbr + (DISP8(ir)<<2), R0 );
nkeynes@1
  1099
                    break;
nkeynes@1
  1100
                case 3: /* TRAPA   imm8 */
nkeynes@2
  1101
                    CHECKSLOTILLEGAL()
nkeynes@2
  1102
                    sh4r.in_delay_slot = 1;
nkeynes@1
  1103
                    MMIO_WRITE( MMU, TRA, UIMM8(ir) );
nkeynes@1
  1104
                    sh4r.pc = sh4r.new_pc;  /* RAISE ends the instruction */
nkeynes@1
  1105
                    sh4r.new_pc += 2;
nkeynes@1
  1106
                    RAISE( EXC_TRAP, EXV_TRAP );
nkeynes@1
  1107
                    break;
nkeynes@1
  1108
                case 4: /* MOV.B   [GBR + disp8], R0 */
nkeynes@1
  1109
                    R0 = MEM_READ_BYTE( sh4r.gbr + DISP8(ir) );
nkeynes@1
  1110
                    break;
nkeynes@1
  1111
                case 5: /* MOV.W   [GBR + disp8*2], R0 */
nkeynes@1
  1112
                    R0 = MEM_READ_WORD( sh4r.gbr + (DISP8(ir)<<1) );
nkeynes@1
  1113
                    break;
nkeynes@1
  1114
                case 6: /* MOV.L   [GBR + disp8*4], R0 */
nkeynes@1
  1115
                    R0 = MEM_READ_LONG( sh4r.gbr + (DISP8(ir)<<2) );
nkeynes@1
  1116
                    break;
nkeynes@1
  1117
                case 7: /* MOVA    disp8 + pc&~3 + 4, R0 */
nkeynes@1
  1118
                    R0 = (pc&0xFFFFFFFC) + (DISP8(ir)<<2) + 4;
nkeynes@1
  1119
                    break;
nkeynes@1
  1120
                case 8: /* TST     imm8, R0 */
nkeynes@1
  1121
                    sh4r.t = (R0 & UIMM8(ir) ? 0 : 1);
nkeynes@1
  1122
                    break;
nkeynes@1
  1123
                case 9: /* AND     imm8, R0 */
nkeynes@1
  1124
                    R0 &= UIMM8(ir);
nkeynes@1
  1125
                    break;
nkeynes@1
  1126
                case 10:/* XOR     imm8, R0 */
nkeynes@1
  1127
                    R0 ^= UIMM8(ir);
nkeynes@1
  1128
                    break;
nkeynes@1
  1129
                case 11:/* OR      imm8, R0 */
nkeynes@1
  1130
                    R0 |= UIMM8(ir);
nkeynes@1
  1131
                    break;
nkeynes@1
  1132
                case 12:/* TST.B   imm8, [R0+GBR] */
nkeynes@1
  1133
                    sh4r.t = ( MEM_READ_BYTE(R0 + sh4r.gbr) & UIMM8(ir) ? 0 : 1 );
nkeynes@1
  1134
                    break;
nkeynes@1
  1135
                case 13:/* AND.B   imm8, [R0+GBR] */
nkeynes@1
  1136
                    MEM_WRITE_BYTE( R0 + sh4r.gbr,
nkeynes@1
  1137
                                    UIMM8(ir) & MEM_READ_BYTE(R0 + sh4r.gbr) );
nkeynes@1
  1138
                    break;
nkeynes@1
  1139
                case 14:/* XOR.B   imm8, [R0+GBR] */
nkeynes@1
  1140
                    MEM_WRITE_BYTE( R0 + sh4r.gbr,
nkeynes@1
  1141
                                    UIMM8(ir) ^ MEM_READ_BYTE(R0 + sh4r.gbr) );
nkeynes@1
  1142
                    break;
nkeynes@1
  1143
                case 15:/* OR.B    imm8, [R0+GBR] */
nkeynes@1
  1144
                    MEM_WRITE_BYTE( R0 + sh4r.gbr,
nkeynes@1
  1145
                                    UIMM8(ir) | MEM_READ_BYTE(R0 + sh4r.gbr) );
nkeynes@1
  1146
                    break;
nkeynes@1
  1147
            }
nkeynes@1
  1148
            break;
nkeynes@1
  1149
        case 13:/* 1101nnnndddddddd */
nkeynes@1
  1150
            /* MOV.L   [disp8*4 + pc&~3 + 4], Rn */
nkeynes@1
  1151
            RN(ir) = MEM_READ_LONG( (pc&0xFFFFFFFC) + (DISP8(ir)<<2) + 4 );
nkeynes@1
  1152
            break;
nkeynes@1
  1153
        case 14:/* 1110nnnniiiiiiii */
nkeynes@1
  1154
            /* MOV     imm8, Rn */
nkeynes@1
  1155
            RN(ir) = IMM8(ir);
nkeynes@1
  1156
            break;
nkeynes@1
  1157
        case 15:/* 1111xxxxxxxxxxxx */
nkeynes@1
  1158
            CHECKFPUEN();
nkeynes@1
  1159
            switch( ir&0x000F ) {
nkeynes@1
  1160
                case 0: /* FADD    FRm, FRn */
nkeynes@1
  1161
                    FRN(ir) += FRM(ir);
nkeynes@1
  1162
                    break;
nkeynes@1
  1163
                case 1: /* FSUB    FRm, FRn */
nkeynes@1
  1164
                    FRN(ir) -= FRM(ir);
nkeynes@1
  1165
                    break;
nkeynes@1
  1166
                case 2: /* FMUL    FRm, FRn */
nkeynes@1
  1167
                    FRN(ir) = FRN(ir) * FRM(ir);
nkeynes@1
  1168
                    break;
nkeynes@1
  1169
                case 3: /* FDIV    FRm, FRn */
nkeynes@1
  1170
                    FRN(ir) = FRN(ir) / FRM(ir);
nkeynes@1
  1171
                    break;
nkeynes@1
  1172
                case 4: /* FCMP/EQ FRm, FRn */
nkeynes@1
  1173
                    sh4r.t = ( FRN(ir) == FRM(ir) ? 1 : 0 );
nkeynes@1
  1174
                    break;
nkeynes@1
  1175
                case 5: /* FCMP/GT FRm, FRn */
nkeynes@1
  1176
                    sh4r.t = ( FRN(ir) > FRM(ir) ? 1 : 0 );
nkeynes@1
  1177
                    break;
nkeynes@1
  1178
                case 6: /* FMOV.S  [Rm+R0], FRn */
nkeynes@1
  1179
                    MEM_FP_READ( RM(ir) + R0, FRNn(ir) );
nkeynes@1
  1180
                    break;
nkeynes@1
  1181
                case 7: /* FMOV.S  FRm, [Rn+R0] */
nkeynes@1
  1182
                    MEM_FP_WRITE( RN(ir) + R0, FRMn(ir) );
nkeynes@1
  1183
                    break;
nkeynes@1
  1184
                case 8: /* FMOV.S  [Rm], FRn */
nkeynes@1
  1185
                    MEM_FP_READ( RM(ir), FRNn(ir) );
nkeynes@1
  1186
                    break;
nkeynes@1
  1187
                case 9: /* FMOV.S  [Rm++], FRn */
nkeynes@1
  1188
                    MEM_FP_READ( RM(ir), FRNn(ir) );
nkeynes@1
  1189
                    RM(ir) += FP_WIDTH;
nkeynes@1
  1190
                    break;
nkeynes@1
  1191
                case 10:/* FMOV.S  FRm, [Rn] */
nkeynes@1
  1192
                    MEM_FP_WRITE( RN(ir), FRMn(ir) );
nkeynes@1
  1193
                    break;
nkeynes@1
  1194
                case 11:/* FMOV.S  FRm, [--Rn] */
nkeynes@1
  1195
                    RN(ir) -= FP_WIDTH;
nkeynes@1
  1196
                    MEM_FP_WRITE( RN(ir), FRMn(ir) );
nkeynes@1
  1197
                    break;
nkeynes@1
  1198
                case 12:/* FMOV    FRm, FRn */
nkeynes@1
  1199
                    if( IS_FPU_DOUBLESIZE() ) {
nkeynes@1
  1200
                        DRN(ir) = DRM(ir);
nkeynes@1
  1201
                    } else {
nkeynes@1
  1202
                        FRN(ir) = FRM(ir);
nkeynes@1
  1203
                    }
nkeynes@1
  1204
                    break;
nkeynes@1
  1205
                case 13:
nkeynes@1
  1206
                    switch( (ir&0x00F0) >> 4 ) {
nkeynes@1
  1207
                        case 0: /* FSTS    FPUL, FRn */
nkeynes@1
  1208
                            FRN(ir) = FPULf;
nkeynes@1
  1209
                            break;
nkeynes@1
  1210
                        case 1: /* FLDS    FRn, FPUL */
nkeynes@1
  1211
                            FPULf = FRN(ir);
nkeynes@1
  1212
                            break;
nkeynes@1
  1213
                        case 2: /* FLOAT   FPUL, FRn */
nkeynes@1
  1214
                            FRN(ir) = (float)FPULi;
nkeynes@1
  1215
                            break;
nkeynes@1
  1216
                        case 3: /* FTRC    FRn, FPUL */
nkeynes@1
  1217
                            FPULi = (uint32_t)FRN(ir);
nkeynes@1
  1218
                            /* FIXME: is this sufficient? */
nkeynes@1
  1219
                            break;
nkeynes@1
  1220
                        case 4: /* FNEG    FRn */
nkeynes@1
  1221
                            FRN(ir) = -FRN(ir);
nkeynes@1
  1222
                            break;
nkeynes@1
  1223
                        case 5: /* FABS    FRn */
nkeynes@1
  1224
                            FRN(ir) = fabsf(FRN(ir));
nkeynes@1
  1225
                            break;
nkeynes@1
  1226
                        case 6: /* FSQRT   FRn */
nkeynes@1
  1227
                            FRN(ir) = sqrtf(FRN(ir));
nkeynes@1
  1228
                            break;
nkeynes@2
  1229
                        case 7: /* FSRRA FRn */
nkeynes@2
  1230
                            FRN(ir) = 1.0/sqrtf(FRN(ir));
nkeynes@2
  1231
                            break;
nkeynes@1
  1232
                        case 8: /* FLDI0   FRn */
nkeynes@1
  1233
                            FRN(ir) = 0.0;
nkeynes@1
  1234
                            break;
nkeynes@1
  1235
                        case 9: /* FLDI1   FRn */
nkeynes@1
  1236
                            FRN(ir) = 1.0;
nkeynes@1
  1237
                            break;
nkeynes@1
  1238
                        case 10: /* FCNVSD FPUL, DRn */
nkeynes@1
  1239
                            if( IS_FPU_DOUBLEPREC() )
nkeynes@1
  1240
                                DRN(ir) = (double)FPULf;
nkeynes@1
  1241
                            else UNDEF(ir);
nkeynes@1
  1242
                            break;
nkeynes@1
  1243
                        case 11: /* FCNVDS DRn, FPUL */
nkeynes@1
  1244
                            if( IS_FPU_DOUBLEPREC() ) 
nkeynes@1
  1245
                                FPULf = (float)DRN(ir);
nkeynes@1
  1246
                            else UNDEF(ir);
nkeynes@1
  1247
                            break;
nkeynes@2
  1248
                        case 14:/* FIPR    FVm, FVn */
nkeynes@2
  1249
                            /* FIXME: This is not going to be entirely accurate
nkeynes@2
  1250
                             * as the SH4 instruction is less precise. Also
nkeynes@2
  1251
                             * need to check for 0s and infinities.
nkeynes@2
  1252
                             */
nkeynes@2
  1253
                        {
nkeynes@2
  1254
                            float *fr_bank = FR;
nkeynes@2
  1255
                            int tmp2 = FVN(ir);
nkeynes@2
  1256
                            tmp = FVM(ir);
nkeynes@2
  1257
                            fr_bank[tmp2+3] = fr_bank[tmp]*fr_bank[tmp2] +
nkeynes@2
  1258
                                fr_bank[tmp+1]*fr_bank[tmp2+1] +
nkeynes@2
  1259
                                fr_bank[tmp+2]*fr_bank[tmp2+2] +
nkeynes@2
  1260
                                fr_bank[tmp+3]*fr_bank[tmp2+3];
nkeynes@1
  1261
                            break;
nkeynes@2
  1262
                        }
nkeynes@1
  1263
                        case 15:
nkeynes@2
  1264
                            if( (ir&0x0300) == 0x0100 ) { /* FTRV    XMTRX,FVn */
nkeynes@2
  1265
                                float *fvout = FR+FVN(ir);
nkeynes@2
  1266
                                float *xm = XF;
nkeynes@2
  1267
                                float fv[4] = { fvout[0], fvout[1], fvout[2], fvout[3] };
nkeynes@2
  1268
                                fvout[0] = xm[0] * fv[0] + xm[4]*fv[1] +
nkeynes@2
  1269
                                    xm[8]*fv[2] + xm[12]*fv[3];
nkeynes@2
  1270
                                fvout[1] = xm[1] * fv[0] + xm[5]*fv[1] +
nkeynes@2
  1271
                                    xm[9]*fv[2] + xm[13]*fv[3];
nkeynes@2
  1272
                                fvout[2] = xm[2] * fv[0] + xm[6]*fv[1] +
nkeynes@2
  1273
                                    xm[10]*fv[2] + xm[14]*fv[3];
nkeynes@2
  1274
                                fvout[3] = xm[3] * fv[0] + xm[7]*fv[1] +
nkeynes@2
  1275
                                    xm[11]*fv[2] + xm[15]*fv[3];
nkeynes@2
  1276
                                break;
nkeynes@2
  1277
                            }
nkeynes@2
  1278
                            else if( (ir&0x0100) == 0 ) { /* FSCA    FPUL, DRn */
nkeynes@2
  1279
                                float angle = (((float)(short)(FPULi>>16)) +
nkeynes@2
  1280
                                               ((float)(FPULi&16)/65536.0)) *
nkeynes@2
  1281
                                    2 * M_PI;
nkeynes@2
  1282
                                int reg = FRNn(ir);
nkeynes@2
  1283
                                FR[reg] = sinf(angle);
nkeynes@2
  1284
                                FR[reg+1] = cosf(angle);
nkeynes@2
  1285
                                break;
nkeynes@2
  1286
                            }
nkeynes@2
  1287
                            else if( ir == 0xFBFD ) {
nkeynes@2
  1288
                                /* FRCHG   */
nkeynes@1
  1289
                                sh4r.fpscr ^= FPSCR_FR;
nkeynes@2
  1290
                                break;
nkeynes@2
  1291
                            }
nkeynes@2
  1292
                            else if( ir == 0xF3FD ) {
nkeynes@2
  1293
                                /* FSCHG   */
nkeynes@1
  1294
                                sh4r.fpscr ^= FPSCR_SZ;
nkeynes@2
  1295
                                break;
nkeynes@2
  1296
                            }
nkeynes@1
  1297
                        default: UNDEF(ir);
nkeynes@1
  1298
                    }
nkeynes@1
  1299
                    break;
nkeynes@1
  1300
                case 14:/* FMAC    FR0, FRm, FRn */
nkeynes@1
  1301
                    FRN(ir) += FRM(ir)*FR0;
nkeynes@1
  1302
                    break;
nkeynes@1
  1303
                default: UNDEF(ir);
nkeynes@1
  1304
            }
nkeynes@1
  1305
            break;
nkeynes@1
  1306
    }
nkeynes@1
  1307
    sh4r.pc = sh4r.new_pc;
nkeynes@1
  1308
    sh4r.new_pc += 2;
nkeynes@2
  1309
    sh4r.in_delay_slot = 0;
nkeynes@1
  1310
}
.