OpenCores
URL https://opencores.org/ocsvn/eco32/eco32/trunk

Subversion Repositories eco32

[/] [eco32/] [trunk/] [monitor/] [monitor/] [common/] [disasm.c] - Blame information for rev 86

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 59 hellwig
/*
2
 * disasm.c -- disassembler
3
 */
4
 
5
 
6
#include "common.h"
7
#include "stdarg.h"
8
#include "romlib.h"
9
#include "instr.h"
10
#include "disasm.h"
11
 
12
 
13
static char instrBuffer[100];
14
 
15
 
16
static void disasmN(char *opName, Word immed) {
17
  if (immed == 0) {
18
    sprintf(instrBuffer, "%-7s", opName);
19
  } else {
20
    sprintf(instrBuffer, "%-7s %08X", opName, immed);
21
  }
22
}
23
 
24
 
25
static void disasmRH(char *opName, int r1, Half immed) {
26
  sprintf(instrBuffer, "%-7s $%d,%04X", opName, r1, immed);
27
}
28
 
29
 
30
static void disasmRHH(char *opName, int r1, Half immed) {
31
  sprintf(instrBuffer, "%-7s $%d,%08X", opName, r1, (Word) immed << 16);
32
}
33
 
34
 
35
static void disasmRRH(char *opName, int r1, int r2, Half immed) {
36
  sprintf(instrBuffer, "%-7s $%d,$%d,%04X", opName, r1, r2, immed);
37
}
38
 
39
 
40
static void disasmRRS(char *opName, int r1, int r2, Half immed) {
41
  sprintf(instrBuffer, "%-7s $%d,$%d,%s%04X", opName, r1, r2,
42
          SIGN(16) & immed ? "-" : "+",
43
          SIGN(16) & immed ? -(signed)SEXT16(immed) : SEXT16(immed));
44
}
45
 
46
 
47
static void disasmRRR(char *opName, int r1, int r2, int r3) {
48
  sprintf(instrBuffer, "%-7s $%d,$%d,$%d", opName, r1, r2, r3);
49
}
50
 
51
 
52
static void disasmRRB(char *opName, int r1, int r2, Half offset, Word locus) {
53
  sprintf(instrBuffer, "%-7s $%d,$%d,%08X", opName,
54
          r1, r2, (locus + 4) + (SEXT16(offset) << 2));
55
}
56
 
57
 
58
static void disasmJ(char *opName, Word offset, Word locus) {
59
  sprintf(instrBuffer, "%-7s %08X", opName,
60
          (locus + 4) + (SEXT26(offset) << 2));
61
}
62
 
63
 
64
static void disasmJR(char *opName, int r1) {
65
  sprintf(instrBuffer, "%-7s $%d", opName, r1);
66
}
67
 
68
 
69
char *disasm(Word instr, Word locus) {
70
  Byte opcode;
71
  Instr *ip;
72
 
73
  opcode = (instr >> 26) & 0x3F;
74
  ip = instrCodeTbl[opcode];
75
  if (ip == NULL) {
76
    disasmN("???", 0);
77
  } else {
78
    switch (ip->format) {
79
      case FORMAT_N:
80
        disasmN(ip->name, instr & 0x03FFFFFF);
81
        break;
82
      case FORMAT_RH:
83
        disasmRH(ip->name, (instr >> 16) & 0x1F, instr & 0x0000FFFF);
84
        break;
85
      case FORMAT_RHH:
86
        disasmRHH(ip->name, (instr >> 16) & 0x1F, instr & 0x0000FFFF);
87
        break;
88
      case FORMAT_RRH:
89
        disasmRRH(ip->name, (instr >> 16) & 0x1F,
90
                  (instr >> 21) & 0x1F, instr & 0x0000FFFF);
91
        break;
92
      case FORMAT_RRS:
93
        disasmRRS(ip->name, (instr >> 16) & 0x1F,
94
                  (instr >> 21) & 0x1F, instr & 0x0000FFFF);
95
        break;
96
      case FORMAT_RRR:
97
        disasmRRR(ip->name, (instr >> 11) & 0x1F,
98
                  (instr >> 21) & 0x1F, (instr >> 16) & 0x1F);
99
        break;
100
      case FORMAT_RRX:
101
        if ((opcode & 1) == 0) {
102
          /* the FORMAT_RRR variant */
103
          disasmRRR(ip->name, (instr >> 11) & 0x1F,
104
                    (instr >> 21) & 0x1F, (instr >> 16) & 0x1F);
105
        } else {
106
          /* the FORMAT_RRH variant */
107
          disasmRRH(ip->name, (instr >> 16) & 0x1F,
108
                    (instr >> 21) & 0x1F, instr & 0x0000FFFF);
109
        }
110
        break;
111
      case FORMAT_RRY:
112
        if ((opcode & 1) == 0) {
113
          /* the FORMAT_RRR variant */
114
          disasmRRR(ip->name, (instr >> 11) & 0x1F,
115
                    (instr >> 21) & 0x1F, (instr >> 16) & 0x1F);
116
        } else {
117
          /* the FORMAT_RRS variant */
118
          disasmRRS(ip->name, (instr >> 16) & 0x1F,
119
                    (instr >> 21) & 0x1F, instr & 0x0000FFFF);
120
        }
121
        break;
122
      case FORMAT_RRB:
123
        disasmRRB(ip->name, (instr >> 21) & 0x1F,
124
                  (instr >> 16) & 0x1F, instr & 0x0000FFFF, locus);
125
        break;
126
      case FORMAT_J:
127
        disasmJ(ip->name, instr & 0x03FFFFFF, locus);
128
        break;
129
      case FORMAT_JR:
130
        disasmJR(ip->name, (instr >> 21) & 0x1F);
131
        break;
132
      default:
133
        printf("illegal entry in instruction table\n");
134
        break;
135
    }
136
  }
137
  return instrBuffer;
138
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.