1 /*
2 * HT Editor
3 * srt.cc
4 *
5 * Copyright (C) 2001, 2002 Stefan Weyergraf
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #include "atom.h"
22 #include "htiobox.h"
23 #include "srt.h"
24 #include "symmath.h"
25
26 /* FIXME: ... find a better way ... */
27 #include "srt_x86.h"
28
29 #define ATOM_SYM_INT_REG MAGIC32("SRT\x00")
30 #define ATOM_SYM_INT_MEM MAGIC32("SRT\x01")
31
32 /*
33 * CLASS state_mod
34 */
35
~state_mod()36 state_mod::~state_mod()
37 {
38 if (ismem) {
39 dest.mem.addr->done();
40 delete dest.mem.addr;
41 }
42 if (isbool) {
43 value.boolean->done();
44 delete value.boolean;
45 } else {
46 value.integer->done();
47 delete value.integer;
48 }
49 }
50
51 /*
52 * CLASS sym_int_reg
53 */
54
sym_int_reg(uint r)55 sym_int_reg::sym_int_reg(uint r)
56 {
57 regidx = r;
58 }
59
compare_eq(sym_int_token * t)60 bool sym_int_reg::compare_eq(sym_int_token *t)
61 {
62 sym_int_reg *s = (sym_int_reg*)t;
63 return (regidx == s->regidx);
64 }
65
clone() const66 Object *sym_int_reg::clone() const
67 {
68 return new sym_int_reg(regidx);
69 }
70
evaluate(uint * i)71 bool sym_int_reg::evaluate(uint *i)
72 {
73 return false;
74 }
75
nstrfy(char * buf,int n)76 int sym_int_reg::nstrfy(char *buf, int n)
77 {
78 return sprintf(buf, "reg%d", regidx);
79 }
80
getObjectID() const81 ObjectID sym_int_reg::getObjectID() const
82 {
83 return ATOM_SYM_INT_REG;
84 }
85
86 /*
87 * CLASS sym_int_mem
88 */
89
90
sym_int_mem(sym_int_token * a,uint s,srt_endian e)91 sym_int_mem::sym_int_mem(sym_int_token *a, uint s, srt_endian e)
92 {
93 addr = a;
94 size = s;
95 endian = e;
96 }
97
compare_eq(sym_int_token * t)98 bool sym_int_mem::compare_eq(sym_int_token *t)
99 {
100 return false;
101 }
102
clone() const103 Object *sym_int_mem::clone() const
104 {
105 return new sym_int_mem((sym_int*)addr->clone(), size, endian);
106 }
107
evaluate(uint * i)108 bool sym_int_mem::evaluate(uint *i)
109 {
110 return false;
111 }
112
nstrfy(char * buf,int n)113 int sym_int_mem::nstrfy(char *buf, int n)
114 {
115 int l = 0;
116 l += sprintf(buf+l, "%s%d[", srt_endian_to_str(endian), size);
117 l += addr->nstrfy(buf+l, n-l);
118 buf[l++] = ']';
119 buf[l] = 0;
120 return l;
121 }
122
getObjectID() const123 ObjectID sym_int_mem::getObjectID() const
124 {
125 return ATOM_SYM_INT_MEM;
126 }
127
128 /***/
129
srt_endian_to_str(srt_endian endian)130 char *srt_endian_to_str(srt_endian endian)
131 {
132 switch (endian) {
133 case srte_be: return "be";
134 case srte_le: return "le";
135 }
136 return "?";
137 }
138
test_srt(Analyser * analy,Address * addr)139 void test_srt(Analyser *analy, Address *addr)
140 {
141 /* FIXME: ... find a better way ... */
142 ObjectID a = analy->disasm->getObjectID();
143 if (a == ATOM_DISASM_X86) {
144 srt_x86(analy, addr);
145 }
146 }
147
148