Search
lxdream.org :: lxdream/src/sh4/sh4dasm.in
lxdream 0.9.1
released Jun 29
Download Now
filename src/sh4/sh4dasm.in
changeset 561:533f6b478071
prev496:5c5c98f3bdd5
next569:a1c49e1e8776
author nkeynes
date Tue Jan 01 05:08:38 2008 +0000 (12 years ago)
branchlxdream-mmu
permissions -rw-r--r--
last change Enable Id keyword on all source files
file annotate diff log raw
nkeynes@359
     1
/**
nkeynes@561
     2
 * $Id$
nkeynes@359
     3
 * 
nkeynes@359
     4
 * SH4 CPU definition and disassembly functions
nkeynes@359
     5
 *
nkeynes@359
     6
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@359
     7
 *
nkeynes@359
     8
 * This program is free software; you can redistribute it and/or modify
nkeynes@359
     9
 * it under the terms of the GNU General Public License as published by
nkeynes@359
    10
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@359
    11
 * (at your option) any later version.
nkeynes@359
    12
 *
nkeynes@359
    13
 * This program is distributed in the hope that it will be useful,
nkeynes@359
    14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@359
    15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@359
    16
 * GNU General Public License for more details.
nkeynes@359
    17
 */
nkeynes@359
    18
nkeynes@359
    19
#include "sh4core.h"
nkeynes@359
    20
#include "sh4dasm.h"
nkeynes@359
    21
#include "mem.h"
nkeynes@359
    22
nkeynes@359
    23
#define UNIMP(ir) snprintf( buf, len, "???     " )
nkeynes@359
    24
nkeynes@359
    25
nkeynes@359
    26
const struct reg_desc_struct sh4_reg_map[] = 
nkeynes@359
    27
  { {"R0", REG_INT, &sh4r.r[0]}, {"R1", REG_INT, &sh4r.r[1]},
nkeynes@359
    28
    {"R2", REG_INT, &sh4r.r[2]}, {"R3", REG_INT, &sh4r.r[3]},
nkeynes@359
    29
    {"R4", REG_INT, &sh4r.r[4]}, {"R5", REG_INT, &sh4r.r[5]},
nkeynes@359
    30
    {"R6", REG_INT, &sh4r.r[6]}, {"R7", REG_INT, &sh4r.r[7]},
nkeynes@359
    31
    {"R8", REG_INT, &sh4r.r[8]}, {"R9", REG_INT, &sh4r.r[9]},
nkeynes@359
    32
    {"R10",REG_INT, &sh4r.r[10]}, {"R11",REG_INT, &sh4r.r[11]},
nkeynes@359
    33
    {"R12",REG_INT, &sh4r.r[12]}, {"R13",REG_INT, &sh4r.r[13]},
nkeynes@359
    34
    {"R14",REG_INT, &sh4r.r[14]}, {"R15",REG_INT, &sh4r.r[15]},
nkeynes@359
    35
    {"SR", REG_INT, &sh4r.sr}, {"GBR", REG_INT, &sh4r.gbr},
nkeynes@359
    36
    {"SSR",REG_INT, &sh4r.ssr}, {"SPC", REG_INT, &sh4r.spc},
nkeynes@359
    37
    {"SGR",REG_INT, &sh4r.sgr}, {"DBR", REG_INT, &sh4r.dbr},
nkeynes@359
    38
    {"VBR",REG_INT, &sh4r.vbr},
nkeynes@359
    39
    {"PC", REG_INT, &sh4r.pc}, {"PR", REG_INT, &sh4r.pr},
nkeynes@359
    40
    {"MACL",REG_INT, &sh4r.mac},{"MACH",REG_INT, ((uint32_t *)&sh4r.mac)+1},
nkeynes@359
    41
    {"FPUL", REG_INT, &sh4r.fpul}, {"FPSCR", REG_INT, &sh4r.fpscr},
nkeynes@359
    42
    {NULL, 0, NULL} };
nkeynes@359
    43
nkeynes@359
    44
nkeynes@359
    45
const struct cpu_desc_struct sh4_cpu_desc = 
nkeynes@359
    46
    { "SH4", sh4_disasm_instruction, sh4_execute_instruction, mem_has_page, 
nkeynes@359
    47
      sh4_set_breakpoint, sh4_clear_breakpoint, sh4_get_breakpoint, 2,
nkeynes@359
    48
      (char *)&sh4r, sizeof(sh4r), sh4_reg_map,
nkeynes@359
    49
      &sh4r.pc };
nkeynes@359
    50
nkeynes@359
    51
uint32_t sh4_disasm_instruction( uint32_t pc, char *buf, int len, char *opcode )
nkeynes@359
    52
{
nkeynes@359
    53
    uint16_t ir = sh4_read_word(pc);
nkeynes@359
    54
nkeynes@359
    55
#define UNDEF(ir) snprintf( buf, len, "????    " );
nkeynes@359
    56
#define RN(ir) ((ir&0x0F00)>>8)
nkeynes@359
    57
#define RN_BANK(ir) ((ir&0x0070)>>4)
nkeynes@359
    58
#define RM(ir) ((ir&0x00F0)>>4)
nkeynes@359
    59
#define DISP4(ir) (ir&0x000F) /* 4-bit displacements are *not* sign extended */
nkeynes@359
    60
#define DISP8(ir) (ir&0x00FF)
nkeynes@359
    61
#define PCDISP8(ir) SIGNEXT8(ir&0x00FF)
nkeynes@359
    62
#define UIMM8(ir) (ir&0x00FF)
nkeynes@359
    63
#define IMM8(ir) SIGNEXT8(ir&0x00FF)
nkeynes@359
    64
#define DISP12(ir) SIGNEXT12(ir&0x0FFF)
nkeynes@359
    65
#define FVN(ir) ((ir&0x0C00)>>10)
nkeynes@359
    66
#define FVM(ir) ((ir&0x0300)>>8)
nkeynes@359
    67
nkeynes@359
    68
    sprintf( opcode, "%02X %02X", ir&0xFF, ir>>8 );
nkeynes@359
    69
nkeynes@359
    70
%%
nkeynes@359
    71
ADD Rm, Rn       {: snprintf( buf, len, "ADD     R%d, R%d", Rm, Rn ); :}
nkeynes@359
    72
ADD #imm, Rn     {: snprintf( buf, len, "ADD     #%d, R%d", imm, Rn ); :}
nkeynes@359
    73
ADDC Rm, Rn      {: snprintf( buf, len, "ADDC    R%d, R%d", Rm, Rn ); :}
nkeynes@359
    74
ADDV Rm, Rn      {: snprintf( buf, len, "ADDV    R%d, R%d", Rm, Rn ); :}
nkeynes@359
    75
AND Rm, Rn       {: snprintf( buf, len, "AND     R%d, R%d", Rm, Rn ); :}
nkeynes@359
    76
AND #imm, R0     {: snprintf( buf, len, "ADD     #%d, R0", imm ); :}
nkeynes@359
    77
AND.B #imm, @(R0, GBR) {: snprintf( buf, len, "AND.B   #%d, @(R0, GBR)", imm ); :}
nkeynes@359
    78
BF disp          {: snprintf( buf, len, "BF      $%xh", disp+pc+4 ); :}
nkeynes@359
    79
BF/S disp        {: snprintf( buf, len, "BF/S    $%xh", disp+pc+4 ); :}
nkeynes@359
    80
BRA disp         {: snprintf( buf, len, "BRA     $%xh", disp+pc+4 ); :}
nkeynes@359
    81
BRAF Rn          {: snprintf( buf, len, "BRAF    R%d", Rn ); :}
nkeynes@359
    82
BSR disp         {: snprintf( buf, len, "BSR     $%xh", disp+pc+4 ); :}
nkeynes@359
    83
BSRF Rn          {: snprintf( buf, len, "BSRF    R%d", Rn ); :}
nkeynes@359
    84
BT disp          {: snprintf( buf, len, "BT      $%xh", disp+pc+4 ); :}
nkeynes@359
    85
BT/S disp        {: snprintf( buf, len, "BT/S    $%xh", disp+pc+4 ); :}
nkeynes@359
    86
CLRMAC           {: snprintf( buf, len, "CLRMAC  " ); :}
nkeynes@359
    87
CLRS             {: snprintf( buf, len, "CLRS    " ); :}
nkeynes@359
    88
CLRT             {: snprintf( buf, len, "CLRT    " ); :}
nkeynes@359
    89
CMP/EQ Rm, Rn    {: snprintf( buf, len, "CMP/EQ  R%d, R%d", Rm, Rn ); :}
nkeynes@359
    90
CMP/EQ #imm, R0  {: snprintf( buf, len, "CMP/EQ  #%d, R0", imm ); :}
nkeynes@359
    91
CMP/GE Rm, Rn    {: snprintf( buf, len, "CMP/GE  R%d, R%d", Rm, Rn ); :}
nkeynes@359
    92
CMP/GT Rm, Rn    {: snprintf( buf, len, "CMP/GT  R%d, R%d", Rm, Rn ); :}
nkeynes@359
    93
CMP/HI Rm, Rn    {: snprintf( buf, len, "CMP/HI  R%d, R%d", Rm, Rn ); :}
nkeynes@359
    94
CMP/HS Rm, Rn    {: snprintf( buf, len, "CMP/HS  R%d, R%d", Rm, Rn ); :}
nkeynes@359
    95
CMP/PL Rn        {: snprintf( buf, len, "CMP/PL  R%d", Rn ); :}
nkeynes@359
    96
CMP/PZ Rn        {: snprintf( buf, len, "CMP/PZ  R%d", Rn ); :}
nkeynes@359
    97
CMP/STR Rm, Rn   {: snprintf( buf, len, "CMP/STR R%d, R%d", Rm, Rn ); :}
nkeynes@359
    98
DIV0S Rm, Rn     {: snprintf( buf, len, "DIV0S   R%d, R%d", Rm, Rn ); :}
nkeynes@359
    99
DIV0U            {: snprintf( buf, len, "DIV0U   " ); :}
nkeynes@359
   100
DIV1 Rm, Rn      {: snprintf( buf, len, "DIV1    R%d, R%d", Rm, Rn ); :}
nkeynes@359
   101
DMULS.L Rm, Rn   {: snprintf( buf, len, "DMULS.L R%d, R%d", Rm, Rn ); :}
nkeynes@359
   102
DMULU.L RM, Rn   {: snprintf( buf, len, "DMULU.L R%d, R%d", Rm, Rn ); :}
nkeynes@359
   103
DT Rn            {: snprintf( buf, len, "DT      R%d", Rn ); :}
nkeynes@359
   104
EXTS.B Rm, Rn    {: snprintf( buf, len, "EXTS.B  R%d, R%d", Rm, Rn ); :}
nkeynes@359
   105
EXTS.W Rm, Rn    {: snprintf( buf, len, "EXTS.W  R%d, R%d", Rm, Rn ); :}
nkeynes@359
   106
EXTU.B Rm, Rn    {: snprintf( buf, len, "EXTU.B  R%d, R%d", Rm, Rn ); :}
nkeynes@359
   107
EXTU.W Rm, Rn    {: snprintf( buf, len, "EXTU.W  R%d, R%d", Rm, Rn ); :}
nkeynes@359
   108
FABS FRn         {: snprintf( buf, len, "FABS    FR%d", FRn ); :}
nkeynes@359
   109
FADD FRm, FRn    {: snprintf( buf, len, "FADD    FR%d, FR%d", FRm, FRn ); :}
nkeynes@359
   110
FCMP/EQ FRm, FRn {: snprintf( buf, len, "FCMP/EQ FR%d, FR%d", FRm, FRn ); :}
nkeynes@359
   111
FCMP/GT FRm, FRn {: snprintf( buf, len, "FCMP/QT FR%d, FR%d", FRm, FRn ); :}
nkeynes@359
   112
FCNVDS FRm, FPUL {: snprintf( buf, len, "FCNVDS  FR%d, FPUL", FRm ); :}
nkeynes@359
   113
FCNVSD FPUL, FRn {: snprintf( buf, len, "FCNVSD  FPUL, FR%d", FRn ); :}
nkeynes@359
   114
FDIV FRm, FRn    {: snprintf( buf, len, "FDIV    FR%d, FR%d", FRm, FRn ); :}
nkeynes@359
   115
FIPR FVm, FVn    {: snprintf( buf, len, "FIPR    FV%d, FV%d", FVm, FVn ); :}
nkeynes@359
   116
FLDS FRm, FPUL   {: snprintf( buf, len, "FLDS    FR%d, FPUL", FRm ); :}
nkeynes@359
   117
FLDI0 FRn        {: snprintf( buf, len, "FLDI0   FR%d", FRn ); :}
nkeynes@359
   118
FLDI1 FRn        {: snprintf( buf, len, "FLDI1   FR%d", FRn ); :}
nkeynes@359
   119
FLOAT FPUL, FRn  {: snprintf( buf, len, "FLOAT   FPUL, FR%d", FRn ); :}
nkeynes@359
   120
FMAC FR0, FRm, FRn {: snprintf( buf, len, "FMAC    FR0, FR%d, FR%d", FRm, FRn ); :}
nkeynes@359
   121
FMOV FRm, FRn    {: snprintf( buf, len, "FMOV    FR%d, FR%d", FRm, FRn ); :}
nkeynes@359
   122
FMOV FRm, @Rn    {: snprintf( buf, len, "FMOV    FR%d, @R%d", FRm, Rn ); :}
nkeynes@359
   123
FMOV FRm, @-Rn   {: snprintf( buf, len, "FMOV    FR%d, @-R%d", FRm, Rn ); :}
nkeynes@359
   124
FMOV FRm, @(R0, Rn) {: snprintf( buf, len, "FMOV    FR%d, @(R0, R%d)", FRm, Rn ); :}
nkeynes@359
   125
FMOV @Rm, FRn    {: snprintf( buf, len, "FMOV    @R%d, FR%d", Rm, FRn ); :}
nkeynes@359
   126
FMOV @Rm+, FRn   {: snprintf( buf, len, "FMOV    @R%d+, FR%d", Rm, FRn ); :}
nkeynes@359
   127
FMOV @(R0, Rm), FRn {: snprintf( buf, len, "FMOV    @(R0, R%d), FR%d", Rm, FRn ); :}
nkeynes@430
   128
FMUL FRm, FRn    {: snprintf( buf, len, "FMUL    FR%d, FR%d", FRm, FRn ); :}
nkeynes@359
   129
FNEG FRn         {: snprintf( buf, len, "FNEG    FR%d", FRn ); :}
nkeynes@359
   130
FRCHG            {: snprintf( buf, len, "FRCHG   " ); :}
nkeynes@359
   131
FSCA FPUL, FRn   {: snprintf( buf, len, "FSCA    FPUL, FR%d", FRn ); :}
nkeynes@359
   132
FSCHG            {: snprintf( buf, len, "FSCHG   " ); :}
nkeynes@359
   133
FSQRT FRn        {: snprintf( buf, len, "FSQRT   FR%d", FRn ); :}
nkeynes@359
   134
FSRRA FRn        {: snprintf( buf, len, "FSRRA   FR%d", FRn ); :}
nkeynes@359
   135
FSTS FPUL, FRn   {: snprintf( buf, len, "FSTS    FPUL, FR%d", FRn ); :}
nkeynes@430
   136
FSUB FRm, FRn    {: snprintf( buf, len, "FSUB    FR%d, FR%d", FRm, FRn ); :}
nkeynes@359
   137
FTRC FRm, FPUL   {: snprintf( buf, len, "FTRC    FR%d, FPUL", FRm ); :}
nkeynes@359
   138
FTRV XMTRX, FVn  {: snprintf( buf, len, "FTRV    XMTRX, FV%d", FVn ); :}
nkeynes@359
   139
JMP @Rn          {: snprintf( buf, len, "JMP     @R%d", Rn ); :}
nkeynes@359
   140
JSR @Rn          {: snprintf( buf, len, "JSR     @R%d", Rn ); :}
nkeynes@359
   141
LDC Rm, GBR      {: snprintf( buf, len, "LDC     R%d, GBR", Rm ); :}
nkeynes@359
   142
LDC Rm, SR       {: snprintf( buf, len, "LDC     R%d, SR", Rm ); :}
nkeynes@359
   143
LDC Rm, VBR      {: snprintf( buf, len, "LDC     R%d, VBR", Rm ); :}
nkeynes@359
   144
LDC Rm, SSR      {: snprintf( buf, len, "LDC     R%d, SSR", Rm ); :}
nkeynes@359
   145
LDC Rm, SGR      {: snprintf( buf, len, "LDC     R%d, SGR", Rm ); :}
nkeynes@359
   146
LDC Rm, SPC      {: snprintf( buf, len, "LDC     R%d, SPC", Rm ); :}
nkeynes@359
   147
LDC Rm, DBR      {: snprintf( buf, len, "LDC     R%d, DBR", Rm ); :}
nkeynes@359
   148
LDC Rm, Rn_BANK  {: snprintf( buf, len, "LDC     R%d, R%d_BANK", Rm, Rn_BANK ); :}
nkeynes@359
   149
LDS Rm, FPSCR    {: snprintf( buf, len, "LDS     R%d, FPSCR", Rm ); :}
nkeynes@359
   150
LDS Rm, FPUL     {: snprintf( buf, len, "LDS     R%d, FPUL", Rm ); :}
nkeynes@359
   151
LDS Rm, MACH     {: snprintf( buf, len, "LDS     R%d, MACH", Rm ); :}
nkeynes@359
   152
LDS Rm, MACL     {: snprintf( buf, len, "LDS     R%d, MACL", Rm ); :}
nkeynes@359
   153
LDS Rm, PR       {: snprintf( buf, len, "LDS     R%d, PR", Rm ); :}
nkeynes@359
   154
LDC.L @Rm+, GBR  {: snprintf( buf, len, "LDC.L   @R%d+, GBR", Rm ); :}
nkeynes@359
   155
LDC.L @Rm+, SR   {: snprintf( buf, len, "LDC.L   @R%d+, SR", Rm ); :}
nkeynes@359
   156
LDC.L @Rm+, VBR  {: snprintf( buf, len, "LDC.L   @R%d+, VBR", Rm ); :}
nkeynes@359
   157
LDC.L @Rm+, SSR  {: snprintf( buf, len, "LDC.L   @R%d+, SSR", Rm ); :}
nkeynes@359
   158
LDC.L @Rm+, SGR  {: snprintf( buf, len, "LDC.L   @R%d+, SGR", Rm ); :}
nkeynes@359
   159
LDC.L @Rm+, SPC  {: snprintf( buf, len, "LDC.L   @R%d+, SPC", Rm ); :}
nkeynes@359
   160
LDC.L @Rm+, DBR  {: snprintf( buf, len, "LDC.L   @R%d+, DBR", Rm ); :}
nkeynes@359
   161
LDC.L @Rm+, Rn_BANK{: snprintf( buf, len, "LDC.L   @R%d+, @R%d+_BANK", Rm, Rn_BANK ); :}
nkeynes@359
   162
LDS.L @Rm+, FPSCR{: snprintf( buf, len, "LDS.L   @R%d+, FPSCR", Rm ); :}
nkeynes@359
   163
LDS.L @Rm+, FPUL {: snprintf( buf, len, "LDS.L   @R%d+, FPUL", Rm ); :}
nkeynes@359
   164
LDS.L @Rm+, MACH {: snprintf( buf, len, "LDS.L   @R%d+, MACH", Rm ); :}
nkeynes@359
   165
LDS.L @Rm+, MACL {: snprintf( buf, len, "LDS.L   @R%d+, MACL", Rm ); :}
nkeynes@359
   166
LDS.L @Rm+, PR   {: snprintf( buf, len, "LDS.L   @R%d+, PR", Rm ); :}
nkeynes@359
   167
LDTLB            {: snprintf( buf, len, "LDTLB   " ); :}
nkeynes@359
   168
MAC.L @Rm+, @Rn+ {: snprintf( buf, len, "MAC.L   @R%d+, @R%d+", Rm, Rn ); :}
nkeynes@359
   169
MAC.W @Rm+, @Rn+ {: snprintf( buf, len, "MAC.W   @R%d+, @R%d+", Rm, Rn ); :}
nkeynes@359
   170
MOV Rm, Rn       {: snprintf( buf, len, "MOV     R%d, R%d", Rm, Rn ); :}
nkeynes@359
   171
MOV #imm, Rn     {: snprintf( buf, len, "MOV     #%d, R%d", imm, Rn ); :}
nkeynes@359
   172
MOV.B Rm, @Rn    {: snprintf( buf, len, "MOV.B   R%d, @R%d", Rm, Rn ); :}
nkeynes@359
   173
MOV.B Rm, @-Rn   {: snprintf( buf, len, "MOV.B   R%d, @-R%d", Rm, Rn ); :}
nkeynes@359
   174
MOV.B Rm, @(R0, Rn) {: snprintf( buf, len, "MOV.B   R%d, @(R0, R%d)", Rm, Rn ); :}
nkeynes@359
   175
MOV.B R0, @(disp, GBR) {: snprintf( buf, len, "MOV.B   R0, @(%d, GBR)", disp ); :}
nkeynes@359
   176
MOV.B R0, @(disp, Rn)  {: snprintf( buf, len, "MOV.B   R0, @(%d, R%d)", disp, Rn ); :}
nkeynes@359
   177
MOV.B @Rm, Rn    {: snprintf( buf, len, "MOV.B   @R%d, R%d", Rm, Rn ); :}
nkeynes@359
   178
MOV.B @Rm+, Rn   {: snprintf( buf, len, "MOV.B   @R%d+, R%d", Rm, Rn ); :}
nkeynes@359
   179
MOV.B @(R0, Rm), Rn {: snprintf( buf, len, "MOV.B   @(R0, R%d), R%d", Rm, Rn ); :}
nkeynes@359
   180
MOV.B @(disp, GBR), R0{: snprintf( buf, len, "MOV.B   @(%d, GBR), R0", disp ); :}
nkeynes@359
   181
MOV.B @(disp, Rm), R0 {: snprintf( buf, len, "MOV.B   @(%d, R%d), R0", disp, Rm ); :}
nkeynes@359
   182
MOV.L Rm, @Rn    {: snprintf( buf, len, "MOV.L   R%d, @R%d", Rm, Rn ); :}
nkeynes@359
   183
MOV.L Rm, @-Rn   {: snprintf( buf, len, "MOV.L   R%d, @-R%d", Rm, Rn ); :}
nkeynes@359
   184
MOV.L Rm, @(R0, Rn) {: snprintf( buf, len, "MOV.L   R%d, @(R0, R%d)", Rm, Rn ); :}
nkeynes@359
   185
MOV.L R0, @(disp, GBR) {: snprintf( buf, len, "MOV.L   R0, @(%d, GBR)", disp ); :}
nkeynes@359
   186
MOV.L Rm, @(disp, Rn) {: snprintf( buf, len, "MOV.L   R%d, @(%d, R%d)", Rm, disp, Rn ); :}
nkeynes@359
   187
MOV.L @Rm, Rn    {: snprintf( buf, len, "MOV.L   @R%d, R%d", Rm, Rn ); :}
nkeynes@359
   188
MOV.L @Rm+, Rn   {: snprintf( buf, len, "MOV.L   @R%d+, R%d", Rm, Rn ); :}
nkeynes@359
   189
MOV.L @(R0, Rm), Rn {: snprintf( buf, len, "MOV.L   @(R0, R%d), R%d", Rm, Rn ); :}
nkeynes@359
   190
MOV.L @(disp, GBR), R0 {: snprintf( buf, len, "MOV.L   @(%d, GBR), R0",disp ); :}
nkeynes@359
   191
MOV.L @(disp, PC), Rn  {: snprintf( buf, len, "MOV.L   @($%xh), R%d ; <- #%08x", disp + (pc & 0xFFFFFFFC) + 4, Rn, sh4_read_long(disp+(pc&0xFFFFFFFC)+4) ); :}
nkeynes@496
   192
MOV.L @(disp, Rm), Rn  {: snprintf( buf, len, "MOV.L   @(%d, R%d), R%d", disp, Rm, Rn ); :}
nkeynes@359
   193
MOV.W Rm, @Rn    {: snprintf( buf, len, "MOV.W   R%d, @R%d", Rm, Rn ); :}
nkeynes@359
   194
MOV.W Rm, @-Rn   {: snprintf( buf, len, "MOV.W   R%d, @-R%d", Rm, Rn ); :}
nkeynes@359
   195
MOV.W Rm, @(R0, Rn) {: snprintf( buf, len, "MOV.W   R%d, @(R0, R%d)", Rm, Rn ); :}
nkeynes@359
   196
MOV.W R0, @(disp, GBR) {: snprintf( buf, len, "MOV.W   R0, @(%d, GBR)", disp); :}
nkeynes@430
   197
MOV.W R0, @(disp, Rn)  {: snprintf( buf, len, "MOV.W   R0, @(%d, R%d)", disp, Rn ); :}
nkeynes@359
   198
MOV.W @Rm, Rn    {: snprintf( buf, len, "MOV.W   @R%d, R%d", Rm, Rn ); :}
nkeynes@359
   199
MOV.W @Rm+, Rn   {: snprintf( buf, len, "MOV.W   @R%d+, R%d", Rm, Rn ); :}
nkeynes@359
   200
MOV.W @(R0, Rm), Rn {: snprintf( buf, len, "MOV.W   @(R0, R%d), R%d", Rm, Rn ); :}
nkeynes@359
   201
MOV.W @(disp, GBR), R0 {: snprintf( buf, len, "MOV.W   @(%d, GBR), R0", disp ); :}
nkeynes@359
   202
MOV.W @(disp, PC), Rn  {: snprintf( buf, len, "MOV.W   @($%xh), R%d ; <- #%08x", disp + pc + 4, Rn, sh4_read_word(disp+pc+4) ); :}
nkeynes@359
   203
MOV.W @(disp, Rm), R0  {: snprintf( buf, len, "MOV.W   @(%d, R%d), R0", disp, Rm ); :}
nkeynes@359
   204
MOVA @(disp, PC), R0   {: snprintf( buf, len, "MOVA    @($%xh), R0", disp + (pc&0xFFFFFFFC) + 4 ); :}
nkeynes@359
   205
MOVCA.L R0, @Rn  {: snprintf( buf, len, "MOVCA.L R0, @R%d", Rn ); :}
nkeynes@359
   206
MOVT Rn          {: snprintf( buf, len, "MOVT    R%d", Rn ); :}
nkeynes@359
   207
MUL.L Rm, Rn     {: snprintf( buf, len, "MUL.L   R%d, R%d", Rm, Rn ); :}
nkeynes@359
   208
MULS.W Rm, Rn    {: snprintf( buf, len, "MULS.W  R%d, R%d", Rm, Rn ); :}
nkeynes@359
   209
MULU.W Rm, Rn    {: snprintf( buf, len, "MULU.W  R%d, R%d", Rm, Rn ); :}
nkeynes@359
   210
NEG Rm, Rn       {: snprintf( buf, len, "NEG     R%d, R%d", Rm, Rn ); :}
nkeynes@359
   211
NEGC Rm, Rn      {: snprintf( buf, len, "NEGC    R%d, R%d", Rm, Rn ); :}
nkeynes@359
   212
NOP              {: snprintf( buf, len, "NOP     " ); :}
nkeynes@359
   213
NOT Rm, Rn       {: snprintf( buf, len, "NOT     R%d, R%d", Rm, Rn ); :}
nkeynes@359
   214
OCBI @Rn         {: snprintf( buf, len, "OCBI    @R%d", Rn ); :}
nkeynes@359
   215
OCBP @Rn         {: snprintf( buf, len, "OCBP    @R%d", Rn ); :}
nkeynes@359
   216
OCBWB @Rn        {: snprintf( buf, len, "OCBWB   @R%d", Rn ); :}
nkeynes@359
   217
OR Rm, Rn        {: snprintf( buf, len, "OR      R%d, R%d", Rm, Rn ); :}
nkeynes@359
   218
OR #imm, R0      {: snprintf( buf, len, "OR      #%d, R0", imm ); :}
nkeynes@359
   219
OR.B #imm, @(R0, GBR) {: snprintf( buf, len, "OR.B    #%d, @(R0, GBR)", imm ); :}
nkeynes@359
   220
PREF @Rn         {: snprintf( buf, len, "PREF    R%d", Rn ); :}
nkeynes@359
   221
ROTCL Rn         {: snprintf( buf, len, "ROTCL   R%d", Rn ); :}
nkeynes@359
   222
ROTCR Rn         {: snprintf( buf, len, "ROTCR   R%d", Rn ); :}
nkeynes@359
   223
ROTL Rn          {: snprintf( buf, len, "ROTL    R%d", Rn ); :}
nkeynes@359
   224
ROTR Rn          {: snprintf( buf, len, "ROTR    R%d", Rn ); :}
nkeynes@359
   225
RTE              {: snprintf( buf, len, "RTE     " ); :}
nkeynes@359
   226
RTS              {: snprintf( buf, len, "RTS     " ); :}
nkeynes@359
   227
SETS             {: snprintf( buf, len, "SETS    " ); :}
nkeynes@359
   228
SETT             {: snprintf( buf, len, "SETT    " ); :}
nkeynes@359
   229
SHAD Rm, Rn      {: snprintf( buf, len, "SHAD    R%d, R%d", Rm, Rn ); :}
nkeynes@359
   230
SHAL Rn          {: snprintf( buf, len, "SHAL    R%d", Rn ); :}
nkeynes@359
   231
SHAR Rn          {: snprintf( buf, len, "SHAR    R%d", Rn ); :}
nkeynes@359
   232
SHLD Rm, Rn      {: snprintf( buf, len, "SHLD    R%d, R%d", Rm, Rn ); :}
nkeynes@359
   233
SHLL Rn          {: snprintf( buf, len, "SHLL    R%d", Rn ); :}
nkeynes@359
   234
SHLL2 Rn         {: snprintf( buf, len, "SHLL2   R%d", Rn ); :}
nkeynes@359
   235
SHLL8 Rn         {: snprintf( buf, len, "SHLL8   R%d", Rn ); :}
nkeynes@359
   236
SHLL16 Rn        {: snprintf( buf, len, "SHLL16  R%d", Rn ); :}
nkeynes@359
   237
SHLR Rn          {: snprintf( buf, len, "SHLR    R%d", Rn ); :}
nkeynes@359
   238
SHLR2 Rn         {: snprintf( buf, len, "SHLR2   R%d", Rn ); :}
nkeynes@359
   239
SHLR8 Rn         {: snprintf( buf, len, "SHLR8   R%d", Rn ); :}
nkeynes@359
   240
SHLR16 Rn        {: snprintf( buf, len, "SHLR16  R%d", Rn ); :}
nkeynes@359
   241
SLEEP            {: snprintf( buf, len, "SLEEP   " ); :}
nkeynes@359
   242
STC SR, Rn       {: snprintf( buf, len, "STC     SR, R%d", Rn ); :}
nkeynes@359
   243
STC GBR, Rn      {: snprintf( buf, len, "STC     GBR, R%d", Rn ); :}
nkeynes@359
   244
STC VBR, Rn      {: snprintf( buf, len, "STC     VBR, R%d", Rn ); :}
nkeynes@359
   245
STC SSR, Rn      {: snprintf( buf, len, "STC     SSR, R%d", Rn ); :}
nkeynes@359
   246
STC SPC, Rn      {: snprintf( buf, len, "STC     SPC, R%d", Rn ); :}
nkeynes@359
   247
STC SGR, Rn      {: snprintf( buf, len, "STC     SGR, R%d", Rn ); :}
nkeynes@359
   248
STC DBR, Rn      {: snprintf( buf, len, "STC     DBR, R%d", Rn ); :}
nkeynes@359
   249
STC Rm_BANK, Rn  {: snprintf( buf, len, "STC     R%d_BANK, R%d", Rm_BANK, Rn ); :}
nkeynes@359
   250
STS FPSCR, Rn    {: snprintf( buf, len, "STS     FPSCR, R%d", Rn ); :}
nkeynes@359
   251
STS FPUL, Rn     {: snprintf( buf, len, "STS     FPUL, R%d", Rn ); :}
nkeynes@359
   252
STS MACH, Rn     {: snprintf( buf, len, "STS     MACH, R%d", Rn ); :}
nkeynes@359
   253
STS MACL, Rn     {: snprintf( buf, len, "STS     MACL, R%d", Rn ); :}
nkeynes@359
   254
STS PR, Rn       {: snprintf( buf, len, "STS     PR, R%d", Rn ); :}
nkeynes@359
   255
STC.L SR, @-Rn   {: snprintf( buf, len, "STC.L   SR, @-R%d", Rn ); :}
nkeynes@359
   256
STC.L GBR, @-Rn  {: snprintf( buf, len, "STC.L   GBR, @-R%d", Rn ); :}
nkeynes@359
   257
STC.L VBR, @-Rn  {: snprintf( buf, len, "STC.L   VBR, @-R%d", Rn ); :}
nkeynes@359
   258
STC.L SSR, @-Rn  {: snprintf( buf, len, "STC.L   SSR, @-R%d", Rn ); :}
nkeynes@359
   259
STC.L SPC, @-Rn  {: snprintf( buf, len, "STC.L   SPC, @-R%d", Rn ); :}
nkeynes@359
   260
STC.L SGR, @-Rn  {: snprintf( buf, len, "STC.L   SGR, @-R%d", Rn ); :}
nkeynes@359
   261
STC.L DBR, @-Rn  {: snprintf( buf, len, "STC.L    DBR, @-R%d", Rn ); :}
nkeynes@359
   262
STC.L Rm_BANK, @-Rn {: snprintf( buf, len, "STC.L   @-R%d_BANK, @-R%d", Rm_BANK, Rn ); :}
nkeynes@359
   263
STS.L FPSCR, @-Rn{: snprintf( buf, len, "STS.L   FPSCR, @-R%d", Rn ); :}
nkeynes@359
   264
STS.L FPUL, @-Rn {: snprintf( buf, len, "STS.L   FPUL, @-R%d", Rn ); :}
nkeynes@359
   265
STS.L MACH, @-Rn {: snprintf( buf, len, "STS.L   MACH, @-R%d", Rn ); :}
nkeynes@359
   266
STS.L MACL, @-Rn {: snprintf( buf, len, "STS.L   MACL, @-R%d", Rn ); :}
nkeynes@359
   267
STS.L PR, @-Rn   {: snprintf( buf, len, "STS.L   PR, @-R%d", Rn ); :}
nkeynes@359
   268
SUB Rm, Rn       {: snprintf( buf, len, "SUB     R%d, R%d", Rm, Rn ); :}
nkeynes@359
   269
SUBC Rm, Rn      {: snprintf( buf, len, "SUBC    R%d, R%d", Rm, Rn ); :}
nkeynes@359
   270
SUBV Rm, Rn      {: snprintf( buf, len, "SUBV    R%d, R%d", Rm, Rn ); :}
nkeynes@359
   271
SWAP.B Rm, Rn    {: snprintf( buf, len, "SWAP.B  R%d, R%d", Rm, Rn ); :}
nkeynes@359
   272
SWAP.W Rm, Rn    {: snprintf( buf, len, "SWAP.W  R%d, R%d", Rm, Rn ); :}
nkeynes@359
   273
TAS.B @Rn        {: snprintf( buf, len, "TAS.B   R%d", Rn ); :}
nkeynes@359
   274
TRAPA #imm       {: snprintf( buf, len, "TRAPA   #%d", imm ); :}
nkeynes@359
   275
TST Rm, Rn       {: snprintf( buf, len, "TST     R%d, R%d", Rm, Rn ); :}
nkeynes@359
   276
TST #imm, R0     {: snprintf( buf, len, "TST     #%d, R0", imm ); :}
nkeynes@359
   277
TST.B #imm, @(R0, GBR) {: snprintf( buf, len, "TST.B   #%d, @(R0, GBR)", imm ); :}
nkeynes@359
   278
XOR Rm, Rn       {: snprintf( buf, len, "XOR     R%d, R%d", Rm, Rn ); :}
nkeynes@359
   279
XOR #imm, R0     {: snprintf( buf, len, "XOR     #%d, R0", imm ); :}
nkeynes@359
   280
XOR.B #imm, @(R0, GBR) {: snprintf( buf, len, "XOR.B   #%d, @(R0, GBR)", imm ); :}
nkeynes@359
   281
XTRCT Rm, Rn     {: snprintf( buf, len, "XTRCT   R%d, R%d", Rm, Rn ); :}
nkeynes@359
   282
UNDEF            {: snprintf( buf, len, "UNDEF   " ); :}
nkeynes@359
   283
%%
nkeynes@359
   284
    return pc+2;
nkeynes@359
   285
}
nkeynes@359
   286
nkeynes@359
   287
nkeynes@359
   288
void sh4_disasm_region( const gchar *filename, int from, int to )
nkeynes@359
   289
{
nkeynes@359
   290
    int pc;
nkeynes@359
   291
    char buf[80];
nkeynes@359
   292
    char opcode[16];
nkeynes@359
   293
    FILE *f;
nkeynes@359
   294
    
nkeynes@359
   295
    f = fopen( filename, "w" );
nkeynes@359
   296
    for( pc = from; pc < to; pc+=2 ) {
nkeynes@359
   297
        buf[0] = '\0';
nkeynes@359
   298
        sh4_disasm_instruction( pc,
nkeynes@359
   299
                                buf, sizeof(buf), opcode );
nkeynes@359
   300
        fprintf( f, "  %08x:  %s  %s\n", pc, opcode, buf );
nkeynes@359
   301
    }
nkeynes@359
   302
    fclose(f);
nkeynes@359
   303
}
.