Debian Codegraph @

Externals/Bochs_disasm/dis_groups.cc

raw symbols SCIP
1 /////////////////////////////////////////////////////////////////////////
2 // $Id: dis_groups.cc 11885 2013-10-15 17:19:18Z sshwarts $
3 /////////////////////////////////////////////////////////////////////////
4 //
5 // Copyright (c) 2005-2011 Stanislav Shwartsman
6 // Written by Stanislav Shwartsman [sshwarts at sourceforge net]
7 //
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Lesser General Public
10 // License as published by the Free Software Foundation; either
11 // version 2 of the License, or (at your option) any later version.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
22 #include <stdio.h>
23 #include <assert.h>
24 #include "disasm.h"
25
26 /*
27 #if BX_DEBUGGER
28 #include "../bx_debug/debug.h"
29 #endif
30 */
31
32 void disassembler::Apw(const x86_insn *insn)
33 {
34 Bit16u imm16 = fetch_word();
35 Bit16u cs_selector = fetch_word();
36 dis_sprintf("0x%04x:%04x", (unsigned) cs_selector, (unsigned) imm16);
37 }
38
39 void disassembler::Apd(const x86_insn *insn)
40 {
41 Bit32u imm32 = fetch_dword();
42 Bit16u cs_selector = fetch_word();
43 dis_sprintf("0x%04x:%08x", (unsigned) cs_selector, (unsigned) imm32);
44 }
45
46 // 8-bit general purpose registers
47 void disassembler::AL_Reg(const x86_insn *insn) { dis_sprintf("%s", general_8bit_regname[rAX_REG]); }
48 void disassembler::CL_Reg(const x86_insn *insn) { dis_sprintf("%s", general_8bit_regname[rCX_REG]); }
49
50 // 16-bit general purpose registers
51 void disassembler::AX_Reg(const x86_insn *insn) {
52 dis_sprintf("%s", general_16bit_regname[rAX_REG]);
53 }
54
55 void disassembler::DX_Reg(const x86_insn *insn) {
56 dis_sprintf("%s", general_16bit_regname[rDX_REG]);
57 }
58
59 // 32-bit general purpose registers
60 void disassembler::EAX_Reg(const x86_insn *insn)
61 {
62 dis_sprintf("%s", general_32bit_regname[rAX_REG]);
63 }
64
65 // 64-bit general purpose registers
66 void disassembler::RAX_Reg(const x86_insn *insn)
67 {
68 dis_sprintf("%s", general_64bit_regname[rAX_REG]);
69 }
70
71 void disassembler::RCX_Reg(const x86_insn *insn)
72 {
73 dis_sprintf("%s", general_64bit_regname[rCX_REG]);
74 }
75
76 // segment registers
77 void disassembler::CS(const x86_insn *insn) { dis_sprintf("%s", segment_name[CS_REG]); }
78 void disassembler::DS(const x86_insn *insn) { dis_sprintf("%s", segment_name[DS_REG]); }
79 void disassembler::ES(const x86_insn *insn) { dis_sprintf("%s", segment_name[ES_REG]); }
80 void disassembler::SS(const x86_insn *insn) { dis_sprintf("%s", segment_name[SS_REG]); }
81 void disassembler::FS(const x86_insn *insn) { dis_sprintf("%s", segment_name[FS_REG]); }
82 void disassembler::GS(const x86_insn *insn) { dis_sprintf("%s", segment_name[GS_REG]); }
83
84 void disassembler::Sw(const x86_insn *insn) { dis_sprintf("%s", segment_name[insn->nnn]); }
85
86 // control register
87 void disassembler::Cd(const x86_insn *insn)
88 {
89 if (intel_mode)
90 dis_sprintf ("cr%d", insn->nnn);
91 else
92 dis_sprintf("%%cr%d", insn->nnn);
93 }
94
95 void disassembler::Cq(const x86_insn *insn) { Cd(insn); }
96
97 // debug register
98 void disassembler::Dd(const x86_insn *insn)
99 {
100 if (intel_mode)
101 dis_sprintf ("dr%d", insn->nnn);
102 else
103 dis_sprintf("%%dr%d", insn->nnn);
104 }
105
106 void disassembler::Dq(const x86_insn *insn) { Dd(insn); }
107
108 // 8-bit general purpose register
109 void disassembler::Reg8(const x86_insn *insn)
110 {
111 unsigned reg = (insn->b1 & 7) | insn->rex_b;
112
113 if (reg < 4 || insn->extend8b)
114 dis_sprintf("%s", general_8bit_regname_rex[reg]);
115 else
116 dis_sprintf("%s", general_8bit_regname[reg]);
117 }
118
119 // 16-bit general purpose register
120 void disassembler::RX(const x86_insn *insn)
121 {
122 dis_sprintf("%s", general_16bit_regname[(insn->b1 & 7) | insn->rex_b]);
123 }
124
125 // 32-bit general purpose register
126 void disassembler::ERX(const x86_insn *insn)
127 {
128 dis_sprintf("%s", general_32bit_regname[(insn->b1 & 7) | insn->rex_b]);
129 }
130
131 // 64-bit general purpose register
132 void disassembler::RRX(const x86_insn *insn)
133 {
134 dis_sprintf("%s", general_64bit_regname[(insn->b1 & 7) | insn->rex_b]);
135 }
136
137 // general purpose register or memory operand
138 void disassembler::Eb(const x86_insn *insn)
139 {
140 if (insn->mod == 3) {
141 if (insn->rm < 4 || insn->extend8b)
142 dis_sprintf("%s", general_8bit_regname_rex[insn->rm]);
143 else
144 dis_sprintf("%s", general_8bit_regname[insn->rm]);
145 }
146 else
147 (this->*resolve_modrm)(insn, B_SIZE);
148 }
149
150 void disassembler::Ew(const x86_insn *insn)
151 {
152 if (insn->mod == 3)
153 dis_sprintf("%s", general_16bit_regname[insn->rm]);
154 else
155 (this->*resolve_modrm)(insn, W_SIZE);
156 }
157
158 void disassembler::Ed(const x86_insn *insn)
159 {
160 if (insn->mod == 3)
161 dis_sprintf("%s", general_32bit_regname[insn->rm]);
162 else
163 (this->*resolve_modrm)(insn, D_SIZE);
164 }
165
166 void disassembler::Eq(const x86_insn *insn)
167 {
168 if (insn->mod == 3)
169 dis_sprintf("%s", general_64bit_regname[insn->rm]);
170 else
171 (this->*resolve_modrm)(insn, Q_SIZE);
172 }
173
174 void disassembler::Ey(const x86_insn *insn)
175 {
176 if (insn->os_64) Eq(insn);
177 else Ed(insn);
178 }
179
180 void disassembler::Ebd(const x86_insn *insn)
181 {
182 if (insn->mod == 3)
183 dis_sprintf("%s", general_32bit_regname[insn->rm]);
184 else
185 (this->*resolve_modrm)(insn, B_SIZE);
186 }
187
188 void disassembler::Ewd(const x86_insn *insn)
189 {
190 if (insn->mod == 3)
191 dis_sprintf("%s", general_32bit_regname[insn->rm]);
192 else
193 (this->*resolve_modrm)(insn, W_SIZE);
194 }
195
196 // general purpose register
197 void disassembler::Gb(const x86_insn *insn)
198 {
199 if (insn->nnn < 4 || insn->extend8b)
200 dis_sprintf("%s", general_8bit_regname_rex[insn->nnn]);
201 else
202 dis_sprintf("%s", general_8bit_regname[insn->nnn]);
203 }
204
205 void disassembler::Gw(const x86_insn *insn)
206 {
207 dis_sprintf("%s", general_16bit_regname[insn->nnn]);
208 }
209
210 void disassembler::Gd(const x86_insn *insn)
211 {
212 dis_sprintf("%s", general_32bit_regname[insn->nnn]);
213 }
214
215 void disassembler::Gq(const x86_insn *insn)
216 {
217 dis_sprintf("%s", general_64bit_regname[insn->nnn]);
218 }
219
220 void disassembler::Gy(const x86_insn *insn)
221 {
222 if (insn->os_64) Gq(insn);
223 else Gd(insn);
224 }
225
226 // vex encoded general purpose register
227 void disassembler::By(const x86_insn *insn)
228 {
229 if (insn->os_64)
230 dis_sprintf("%s", general_64bit_regname[insn->vex_vvv]);
231 else
232 dis_sprintf("%s", general_32bit_regname[insn->vex_vvv]);
233 }
234
235 // immediate
236 void disassembler::I1(const x86_insn *insn)
237 {
238 if (! intel_mode) dis_putc('$');
239 dis_putc ('1');
240 }
241
242 void disassembler::Ib(const x86_insn *insn)
243 {
244 if (! intel_mode) dis_putc('$');
245 dis_sprintf("0x%02x", (unsigned) fetch_byte());
246 }
247
248 void disassembler::Iw(const x86_insn *insn)
249 {
250 if (! intel_mode) dis_putc('$');
251 dis_sprintf("0x%04x", (unsigned) fetch_word());
252 }
253
254 void disassembler::IbIb(const x86_insn *insn)
255 {
256 Bit8u ib1 = fetch_byte();
257 Bit8u ib2 = fetch_byte();
258
259 if (intel_mode) {
260 dis_sprintf("0x%02x, 0x%02x", ib1, ib2);
261 }
262 else {
263 dis_sprintf("$0x%02x, $0x%02x", ib2, ib1);
264 }
265 }
266
267 void disassembler::IwIb(const x86_insn *insn)
268 {
269 Bit16u iw = fetch_word();
270 Bit8u ib = fetch_byte();
271
272 if (intel_mode) {
273 dis_sprintf("0x%04x, 0x%02x", iw, ib);
274 }
275 else {
276 dis_sprintf("$0x%02x, $0x%04x", ib, iw);
277 }
278 }
279
280 void disassembler::Id(const x86_insn *insn)
281 {
282 if (! intel_mode) dis_putc('$');
283 dis_sprintf("0x%08x", (unsigned) fetch_dword());
284 }
285
286 void disassembler::Iq(const x86_insn *insn)
287 {
288 Bit64u value = fetch_qword();
289
290 if (! intel_mode) dis_putc('$');
291 dis_sprintf("0x%08x%08x", GET32H(value), GET32L(value));
292 }
293
294 // sign extended immediate
295 void disassembler::sIbw(const x86_insn *insn)
296 {
297 if (! intel_mode) dis_putc('$');
298 Bit16u imm16 = (Bit8s) fetch_byte();
299 dis_sprintf("0x%04x", (unsigned) imm16);
300 }
301
302 // sign extended immediate
303 void disassembler::sIbd(const x86_insn *insn)
304 {
305 if (! intel_mode) dis_putc('$');
306 Bit32u imm32 = (Bit8s) fetch_byte();
307 dis_sprintf ("0x%08x", (unsigned) imm32);
308 }
309
310 // sign extended immediate
311 void disassembler::sIbq(const x86_insn *insn)
312 {
313 if (! intel_mode) dis_putc('$');
314 Bit64u imm64 = (Bit8s) fetch_byte();
315 dis_sprintf ("0x%08x%08x", GET32H(imm64), GET32L(imm64));
316 }
317
318 // sign extended immediate
319 void disassembler::sIdq(const x86_insn *insn)
320 {
321 if (! intel_mode) dis_putc('$');
322 Bit64u imm64 = (Bit32s) fetch_dword();
323 dis_sprintf ("0x%08x%08x", GET32H(imm64), GET32L(imm64));
324 }
325
326 // floating point
327 void disassembler::ST0(const x86_insn *insn)
328 {
329 if (intel_mode)
330 dis_sprintf ("st(0)");
331 else
332 dis_sprintf("%%st(0)");
333 }
334
335 void disassembler::STi(const x86_insn *insn)
336 {
337 if (intel_mode)
338 dis_sprintf ("st(%d)", insn->rm & 7);
339 else
340 dis_sprintf("%%st(%d)", insn->rm & 7);
341 }
342
343 // 16-bit general purpose register
344 void disassembler::Rw(const x86_insn *insn)
345 {
346 dis_sprintf("%s", general_16bit_regname[insn->rm]);
347 }
348
349 // 32-bit general purpose register
350 void disassembler::Rd(const x86_insn *insn)
351 {
352 dis_sprintf("%s", general_32bit_regname[insn->rm]);
353 }
354
355 // 64-bit general purpose register
356 void disassembler::Rq(const x86_insn *insn)
357 {
358 dis_sprintf("%s", general_64bit_regname[insn->rm]);
359 }
360
361 void disassembler::Ry(const x86_insn *insn)
362 {
363 if (insn->os_64) Rq(insn);
364 else Rd(insn);
365 }
366
367 // mmx register
368 void disassembler::Pq(const x86_insn *insn)
369 {
370 if (intel_mode)
371 dis_sprintf ("mm%d", insn->nnn & 0x7);
372 else
373 dis_sprintf("%%mm%d", insn->nnn & 0x7);
374 }
375
376 void disassembler::Nq(const x86_insn *insn)
377 {
378 if (intel_mode)
379 dis_sprintf ("mm%d", insn->rm & 0x7);
380 else
381 dis_sprintf("%%mm%d", insn->rm & 0x7);
382 }
383
384 void disassembler::Qd(const x86_insn *insn)
385 {
386 if (insn->mod == 3)
387 {
388 if (intel_mode)
389 dis_sprintf ("mm%d", insn->rm & 0x7);
390 else
391 dis_sprintf("%%mm%d", insn->rm & 0x7);
392 }
393 else
394 (this->*resolve_modrm)(insn, D_SIZE);
395 }
396
397 void disassembler::Qq(const x86_insn *insn)
398 {
399 if (insn->mod == 3)
400 {
401 if (intel_mode)
402 dis_sprintf ("mm%d", insn->rm & 0x7);
403 else
404 dis_sprintf("%%mm%d", insn->rm & 0x7);
405 }
406 else
407 (this->*resolve_modrm)(insn, Q_SIZE);
408 }
409
410 // xmm/ymm register
411 void disassembler::Udq(const x86_insn *insn)
412 {
413 dis_sprintf("%s%d", vector_reg_name[insn->vex_l], insn->rm);
414 }
415
416 void disassembler::Ups(const x86_insn *insn) { Udq(insn); }
417 void disassembler::Upd(const x86_insn *insn) { Udq(insn); }
418 void disassembler::Uq(const x86_insn *insn) { Udq(insn); }
419
420 void disassembler::Vq(const x86_insn *insn)
421 {
422 dis_sprintf("%s%d", vector_reg_name[insn->vex_l], insn->nnn);
423 }
424
425 void disassembler::Vdq(const x86_insn *insn) { Vq(insn); }
426 void disassembler::Vss(const x86_insn *insn) { Vq(insn); }
427 void disassembler::Vsd(const x86_insn *insn) { Vq(insn); }
428 void disassembler::Vps(const x86_insn *insn) { Vq(insn); }
429 void disassembler::Vpd(const x86_insn *insn) { Vq(insn); }
430
431 void disassembler::VIb(const x86_insn *insn)
432 {
433 unsigned vreg = fetch_byte() >> 4;
434 if (! insn->is_64) vreg &= 7;
435 dis_sprintf("%s%d", vector_reg_name[insn->vex_l], vreg);
436 }
437
438 void disassembler::Hdq(const x86_insn *insn)
439 {
440 dis_sprintf("%s%d", vector_reg_name[insn->vex_l], insn->vex_vvv);
441 }
442
443 void disassembler::Hps(const x86_insn *insn) { Hdq(insn); }
444 void disassembler::Hpd(const x86_insn *insn) { Hdq(insn); }
445 void disassembler::Hss(const x86_insn *insn) { Hdq(insn); }
446 void disassembler::Hsd(const x86_insn *insn) { Hdq(insn); }
447
448 void disassembler::Wb(const x86_insn *insn)
449 {
450 if (insn->mod == 3) Udq(insn);
451 else
452 (this->*resolve_modrm)(insn, B_SIZE);
453 }
454
455 void disassembler::Ww(const x86_insn *insn)
456 {
457 if (insn->mod == 3) Udq(insn);
458 else
459 (this->*resolve_modrm)(insn, W_SIZE);
460 }
461
462 void disassembler::Wd(const x86_insn *insn)
463 {
464 if (insn->mod == 3) Udq(insn);
465 else
466 (this->*resolve_modrm)(insn, D_SIZE);
467 }
468
469 void disassembler::Wq(const x86_insn *insn)
470 {
471 if (insn->mod == 3) Udq(insn);
472 else
473 (this->*resolve_modrm)(insn, Q_SIZE);
474 }
475
476 void disassembler::Wdq(const x86_insn *insn)
477 {
478 if (insn->mod == 3) Udq(insn);
479 else
480 (this->*resolve_modrm)(insn, XMM_SIZE + insn->vex_l);
481 }
482
483 void disassembler::Wsd(const x86_insn *insn) { Wq(insn); }
484 void disassembler::Wss(const x86_insn *insn) { Wd(insn); }
485 void disassembler::Wpd(const x86_insn *insn) { Wdq(insn); }
486 void disassembler::Wps(const x86_insn *insn) { Wdq(insn); }
487
488 // direct memory access
489 void disassembler::OP_O(const x86_insn *insn, unsigned size)
490 {
491 const char *seg;
492
493 if (insn->is_seg_override())
494 seg = segment_name[insn->seg_override];
495 else
496 seg = segment_name[DS_REG];
497
498 print_datasize(size);
499
500 if (insn->as_64) {
501 Bit64u imm64 = fetch_qword();
502 dis_sprintf("%s:0x%08x%08x", seg, GET32H(imm64), GET32L(imm64));
503 }
504 else if (insn->as_32) {
505 Bit32u imm32 = fetch_dword();
506 dis_sprintf("%s:0x%08x", seg, (unsigned) imm32);
507 }
508 else {
509 Bit16u imm16 = fetch_word();
510 dis_sprintf("%s:0x%04x", seg, (unsigned) imm16);
511 }
512 }
513
514 void disassembler::Ob(const x86_insn *insn) { OP_O(insn, B_SIZE); }
515 void disassembler::Ow(const x86_insn *insn) { OP_O(insn, W_SIZE); }
516 void disassembler::Od(const x86_insn *insn) { OP_O(insn, D_SIZE); }
517 void disassembler::Oq(const x86_insn *insn) { OP_O(insn, Q_SIZE); }
518
519 // memory operand
520 void disassembler::OP_M(const x86_insn *insn, unsigned size)
521 {
522 if(insn->mod == 3)
523 dis_sprintf("(bad)");
524 else
525 (this->*resolve_modrm)(insn, size);
526 }
527
528 void disassembler::Ma(const x86_insn *insn) { OP_M(insn, X_SIZE); }
529 void disassembler::Mp(const x86_insn *insn) { OP_M(insn, X_SIZE); }
530 void disassembler::Ms(const x86_insn *insn) { OP_M(insn, X_SIZE); }
531 void disassembler::Mx(const x86_insn *insn) { OP_M(insn, X_SIZE); }
532
533 void disassembler::Mb(const x86_insn *insn) { OP_M(insn, B_SIZE); }
534 void disassembler::Mw(const x86_insn *insn) { OP_M(insn, W_SIZE); }
535 void disassembler::Md(const x86_insn *insn) { OP_M(insn, D_SIZE); }
536 void disassembler::Mq(const x86_insn *insn) { OP_M(insn, Q_SIZE); }
537 void disassembler::Mt(const x86_insn *insn) { OP_M(insn, T_SIZE); }
538
539 void disassembler::Mdq(const x86_insn *insn) { OP_M(insn, XMM_SIZE + insn->vex_l); }
540 void disassembler::Mps(const x86_insn *insn) { OP_M(insn, XMM_SIZE + insn->vex_l); }
541 void disassembler::Mpd(const x86_insn *insn) { OP_M(insn, XMM_SIZE + insn->vex_l); }
542 void disassembler::Mss(const x86_insn *insn) { OP_M(insn, D_SIZE); }
543 void disassembler::Msd(const x86_insn *insn) { OP_M(insn, Q_SIZE); }
544
545 // gather VSib
546 void disassembler::VSib(const x86_insn *insn)
547 {
548 if(insn->mod == 3)
549 dis_sprintf("(bad)");
550 else
551 (this->*resolve_modrm)(insn, (XMM_SIZE + insn->vex_l) | VSIB_Index);
552 }
553
554 // string instructions
555 void disassembler::OP_X(const x86_insn *insn, unsigned size)
556 {
557 const char *rsi, *seg;
558
559 if (insn->as_64) {
560 rsi = general_64bit_regname[rSI_REG];
561 }
562 else {
563 if (insn->as_32)
564 rsi = general_32bit_regname[rSI_REG];
565 else
566 rsi = general_16bit_regname[rSI_REG];
567 }
568
569 if (insn->is_seg_override())
570 seg = segment_name[insn->seg_override];
571 else
572 seg = segment_name[DS_REG];
573
574 print_datasize(size);
575
576 if (intel_mode)
577 dis_sprintf("%s:[%s]", seg, rsi);
578 else
579 dis_sprintf("%s:(%s)", seg, rsi);
580 }
581
582 void disassembler::Xb(const x86_insn *insn) { OP_X(insn, B_SIZE); }
583 void disassembler::Xw(const x86_insn *insn) { OP_X(insn, W_SIZE); }
584 void disassembler::Xd(const x86_insn *insn) { OP_X(insn, D_SIZE); }
585 void disassembler::Xq(const x86_insn *insn) { OP_X(insn, Q_SIZE); }
586
587 void disassembler::OP_Y(const x86_insn *insn, unsigned size)
588 {
589 const char *rdi;
590
591 if (insn->as_64) {
592 rdi = general_64bit_regname[rDI_REG];
593 }
594 else {
595 if (insn->as_32)
596 rdi = general_32bit_regname[rDI_REG];
597 else
598 rdi = general_16bit_regname[rDI_REG];
599 }
600
601 print_datasize(size);
602
603 if (intel_mode)
604 dis_sprintf("%s:[%s]", segment_name[ES_REG], rdi);
605 else
606 dis_sprintf("%s:(%s)", segment_name[ES_REG], rdi);
607 }
608
609 void disassembler::Yb(const x86_insn *insn) { OP_Y(insn, B_SIZE); }
610 void disassembler::Yw(const x86_insn *insn) { OP_Y(insn, W_SIZE); }
611 void disassembler::Yd(const x86_insn *insn) { OP_Y(insn, D_SIZE); }
612 void disassembler::Yq(const x86_insn *insn) { OP_Y(insn, Q_SIZE); }
613
614 void disassembler::OP_sY(const x86_insn *insn, unsigned size)
615 {
616 const char *rdi, *seg;
617
618 if (insn->as_64) {
619 rdi = general_64bit_regname[rDI_REG];
620 }
621 else {
622 if (insn->as_32)
623 rdi = general_32bit_regname[rDI_REG];
624 else
625 rdi = general_16bit_regname[rDI_REG];
626 }
627
628 print_datasize(size);
629
630 if (insn->is_seg_override())
631 seg = segment_name[insn->seg_override];
632 else
633 seg = segment_name[DS_REG];
634
635 if (intel_mode)
636 dis_sprintf("%s:[%s]", seg, rdi);
637 else
638 dis_sprintf("%s:(%s)", seg, rdi);
639 }
640
641 void disassembler::sYq(const x86_insn *insn) { OP_sY(insn, Q_SIZE); }
642 void disassembler::sYdq(const x86_insn *insn) { OP_sY(insn, XMM_SIZE + insn->vex_l); }
643
644 #define BX_JUMP_TARGET_NOT_REQ ((bx_address)(-1))
645
646 // jump offset
647 void disassembler::Jb(const x86_insn *insn)
648 {
649 Bit8s imm8 = (Bit8s) fetch_byte();
650
651 if (insn->is_64) {
652 Bit64u imm64 = (Bit8s) imm8;
653
654 if (offset_mode_hex) {
655 dis_sprintf(".+0x%08x%08x", GET32H(imm64), GET32L(imm64));
656 }
657 else {
658 dis_sprintf(".%+d", (int) imm8);
659 }
660
661 if (db_cs_base != BX_JUMP_TARGET_NOT_REQ) {
662 Bit64u target = db_eip + imm64;
663 target += db_cs_base;
664 dis_sprintf(" (0x%08x%08x)", GET32H(target), GET32L(target));
665 }
666
667 return;
668 }
669
670 if (insn->os_32) {
671 Bit32u imm32 = (Bit8s) imm8;
672
673 if (offset_mode_hex) {
674 dis_sprintf(".+0x%08x", (unsigned) imm32);
675 }
676 else {
677 dis_sprintf(".%+d", (int) imm8);
678 }
679
680 if (db_cs_base != BX_JUMP_TARGET_NOT_REQ) {
681 Bit32u target = (Bit32u)(db_cs_base + db_eip + (Bit32s) imm32);
682 dis_sprintf(" (0x%08x)", target);
683 }
684 }
685 else {
686 Bit16u imm16 = (Bit8s) imm8;
687
688 if (offset_mode_hex) {
689 dis_sprintf(".+0x%04x", (unsigned) imm16);
690 }
691 else {
692 dis_sprintf(".%+d", (int) imm8);
693 }
694
695 if (db_cs_base != BX_JUMP_TARGET_NOT_REQ) {
696 Bit16u target = (Bit16u)((db_eip + (Bit16s) imm16) & 0xffff);
697 dis_sprintf(" (0x%08x)", target + db_cs_base);
698 }
699 }
700 }
701
702 void disassembler::Jw(const x86_insn *insn)
703 {
704 // Jw supported in 16-bit mode only
705 assert(! insn->is_64);
706
707 Bit16s imm16 = (Bit16s) fetch_word();
708
709 if (offset_mode_hex) {
710 dis_sprintf(".+0x%04x", (unsigned) (Bit16u) imm16);
711 }
712 else {
713 dis_sprintf(".%+d", (int) imm16);
714 }
715
716 if (db_cs_base != BX_JUMP_TARGET_NOT_REQ) {
717 Bit16u target = (db_eip + imm16) & 0xffff;
718 dis_sprintf(" (0x%08x)", target + db_cs_base);
719 }
720 }
721
722 void disassembler::Jd(const x86_insn *insn)
723 {
724 Bit32s imm32 = (Bit32s) fetch_dword();
725
726 if (insn->is_64) {
727 Bit64u imm64 = (Bit32s) imm32;
728
729 if (offset_mode_hex) {
730 dis_sprintf(".+0x%08x%08x", GET32H(imm64), GET32L(imm64));
731 }
732 else {
733 dis_sprintf(".%+d", (int) imm32);
734 }
735
736 if (db_cs_base != BX_JUMP_TARGET_NOT_REQ) {
737 Bit64u target = db_cs_base + db_eip + (Bit64s) imm64;
738 dis_sprintf(" (0x%08x%08x)", GET32H(target), GET32L(target));
739 }
740
741 return;
742 }
743
744 if (offset_mode_hex) {
745 dis_sprintf(".+0x%08x", (unsigned) imm32);
746 }
747 else {
748 dis_sprintf(".%+d", (int) imm32);
749 }
750
751 if (db_cs_base != BX_JUMP_TARGET_NOT_REQ) {
752 Bit32u target = (Bit32u)(db_cs_base + db_eip + (Bit32s) imm32);
753 dis_sprintf(" (0x%08x)", target);
754 }
755 }