xref: /haiku/src/add-ons/kernel/debugger/disasm/x86/disasm_arch.cpp (revision b06a48ab8f30b45916a9c157b992827779182163)
1 /*
2  * Copyright 2008, François Revol, revol@free.fr
3  * Distributed under the terms of the MIT License.
4  */
5 
6 #include <OS.h>
7 #include <KernelExport.h>
8 
9 #include "disasm_arch.h"
10 #include "udis86.h"
11 
12 static ud_t sUDState;
13 static void (*sSyntax)(ud_t *) = UD_SYN_ATT;
14 static unsigned int sVendor = UD_VENDOR_INTEL;
15 
16 extern "C" void
17 disasm_arch_assert(const char *condition)
18 {
19 	kprintf("assert: %s\n", condition);
20 }
21 
22 
23 status_t
24 disasm_arch_dump_insns(addr_t where, size_t length, int count)
25 {
26 	//status_t err;
27 	int i;
28 
29 	ud_set_input_buffer(&sUDState, (unsigned char *)where, length);
30 	ud_set_mode(&sUDState, 32);
31 	ud_set_pc(&sUDState, (uint64_t)where);
32 	ud_set_syntax(&sUDState, sSyntax);
33 	ud_set_vendor(&sUDState, sVendor);
34 	for (i = 0; i < count; i++) {
35 		int ret;
36 		ret = ud_disassemble(&sUDState);
37 		if (ret < 1)
38 			break;
39 		// TODO: dig operands and lookup symbols
40 		kprintf("0x%08lx: %16.16s\t%s\n",
41 			(uint32)(/*where +*/ ud_insn_off(&sUDState)),
42 			ud_insn_hex(&sUDState),
43 			ud_insn_asm(&sUDState));
44 	}
45 	return B_OK;
46 }
47 
48 
49 status_t
50 disasm_arch_init()
51 {
52 	ud_init(&sUDState);
53 	// XXX: check for AMD and set sVendor;
54 	return B_OK;
55 }
56 
57 status_t
58 disasm_arch_fini()
59 {
60 	return B_OK;
61 }
62 
63 
64