File: asm.cc

package info (click to toggle)
ht 0.5.0-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 3,388 kB
  • ctags: 9,064
  • sloc: cpp: 51,336; ansic: 11,954; sh: 2,742; yacc: 1,142; lex: 396; makefile: 178
file content (242 lines) | stat: -rw-r--r-- 4,160 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
/* 
 *	HT Editor
 *	asm.cc
 *
 *	Copyright (C) 1999, 2000, 2001 Stefan Weyergraf (stefan@weyergraf.de)
 *
 *	This program is free software; you can redistribute it and/or modify
 *	it under the terms of the GNU General Public License version 2 as
 *	published by the Free Software Foundation.
 *
 *	This program is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *	GNU General Public License for more details.
 *
 *	You should have received a copy of the GNU General Public License
 *	along with this program; if not, write to the Free Software
 *	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include "asm.h"
#include "common.h"
#include "global.h"
#include "htatom.h"
#include "htdebug.h"

#include <string.h>
#include <stdio.h>
#include <stdarg.h>

#include "alphadis.h"
#include "x86dis.h"

/*
 *	CLASS assembler
 */

assembler::assembler(bool b)
{
	codes = 0;
	bigendian = b;
}

assembler::~assembler()
{
}

asm_insn *assembler::alloc_insn()
{
	return NULL;
}

void assembler::deletecode(asm_code *code)
{
	asm_code **p=&codes, *c=codes;
	while (c) {
		if (c==code) {
			*p=c->next;
			delete c;
			return;
		}
		c=c->next;
		p=&(*p)->next;
	}
}

asm_code *assembler::encode(asm_insn *asm_insn, int _options, CPU_ADDR cur_address)
{
	free_asm_codes();
	error=0;
	options=_options;
	return 0;
}

void assembler::clearcode()
{
	code.size=0;
}

void assembler::emitbyte(byte b)
{
	code.data[code.size] = b;
	code.size++;
}

void assembler::emitword(word w)
{
	if (bigendian) {
		code.data[code.size+1] = (byte)w;
		code.data[code.size+0] = (byte)(w>>8);
	} else {
		code.data[code.size+0] = (byte)w;
		code.data[code.size+1] = (byte)(w>>8);
	}
	code.size += 2;
}

void assembler::emitdword(dword d)
{
	if (bigendian) {
		code.data[code.size+3] = (byte)d;
		code.data[code.size+2] = (byte)(d>>8);
		code.data[code.size+1] = (byte)(d>>16);
		code.data[code.size+0] = (byte)(d>>24);
	} else {
		code.data[code.size+0] = (byte)d;
		code.data[code.size+1] = (byte)(d>>8);
		code.data[code.size+2] = (byte)(d>>16);
		code.data[code.size+3] = (byte)(d>>24);
	}
	code.size += 4;
}

void assembler::free_asm_codes()
{
	while (codes) {
		asm_code *t=codes->next;
		delete codes;
		codes=t;
	}
}

char *assembler::get_error_msg()
{
	return error_msg;
}

char *assembler::get_name()
{
	return "generic asm";
}

void assembler::newcode()
{
	code.size=0;
}

asm_code *assembler::shortest(asm_code *codes)
{
	asm_code *best=0;
	dword bestv=0xffffffff;
	while (codes) {
		if (codes->size<bestv) {
			best=codes;
			bestv=codes->size;
		}
		codes=codes->next;
	};
	return best;
}

void assembler::pushcode()
{
	asm_code **t=&codes;
	while (*t) {
		t=&(*t)->next;
	}
	*t=new asm_code;

	memmove(*t, &code, sizeof code);
	(*t)->next=0;
}

int assembler::prepare_str(asm_insn *asm_insn, char *s)
{
	return 0;
}

void assembler::set_error_msg(char *format, ...)
{
	va_list arg;
	va_start(arg, format);
	vsprintf(error_msg, format, arg);
	va_end(arg);
	error=1;
}

void assembler::set_imm_eval_proc(int (*p)(void *context, char **s, dword *v), void *c)
{
	imm_eval_proc=p;
	imm_eval_context=c;
}

/*
 *	CLASS disassembler
 */

disassembler::disassembler()
{
}

disassembler::~disassembler()
{
}

char* (*addr_sym_func)(CPU_ADDR addr, int *symstrlen)=0;

dis_insn *disassembler::decode(byte *code, byte maxlen, CPU_ADDR cur_address)
{
	return 0;
}

int disassembler::getmaxopcodelength()
{
	return 0;
}

byte disassembler::getsize(dis_insn *disasm_insn)
{
	return 0;
}

char *disassembler::str(dis_insn *disasm_insn, int style)
{
	return strf(disasm_insn, style, DISASM_STRF_DEFAULT_FORMAT);
}

char *disassembler::strf(dis_insn *disasm_insn, int style, char *format)
{
	return 0;
}

bool disassembler::valid_insn(dis_insn *disasm_insn)
{
	return 0;
}

BUILDER(ATOM_DISASM_ALPHA, alphadis)
BUILDER(ATOM_DISASM_X86, x86dis)

bool init_asm()
{
	REGISTER(ATOM_DISASM_ALPHA, alphadis)
	REGISTER(ATOM_DISASM_X86, x86dis)
	return true;
}

void done_asm()
{
	UNREGISTER(ATOM_DISASM_ALPHA, alphadis)
	UNREGISTER(ATOM_DISASM_X86, x86dis)
}