The Pedigree Project 0.1
x86_common/Disassembler.cc
1/*
2 * Copyright (c) 2008-2014, Pedigree Developers
3 *
4 * Please see the CONTRIB file in the root of the source tree for a full
5 * list of contributors.
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
20#include "Disassembler.h"
21#include "pedigree/kernel/debugger/libudis86/udis86.h"
22#include "pedigree/kernel/processor/types.h"
23#include "pedigree/kernel/utilities/StaticString.h"
24
25X86Disassembler::X86Disassembler() : m_Location(0), m_Mode(32), m_Obj() {
26 ud_init(&m_Obj);
27 ud_set_mode(&m_Obj, m_Mode);
28 ud_set_syntax(&m_Obj, UD_SYN_INTEL);
29 ud_set_pc(&m_Obj, m_Location);
30 ud_set_input_buffer(&m_Obj, reinterpret_cast<uint8_t*>(m_Location), 4096);
31}
32
33X86Disassembler::~X86Disassembler() {}
34
35void X86Disassembler::setLocation(uintptr_t nLocation) {
36 m_Location = nLocation;
37 ud_set_mode(&m_Obj, m_Mode);
38 ud_set_pc(&m_Obj, m_Location);
39 ud_set_input_buffer(&m_Obj, reinterpret_cast<uint8_t*>(m_Location), 4096);
40 ud_disassemble(&m_Obj);
41}
42
44 return m_Location;
45}
46
47void X86Disassembler::setMode(size_t nMode) {
48 if (nMode == 32 || nMode == 64)
49 m_Mode = nMode;
50 ud_set_mode(&m_Obj, m_Mode);
51}
52
54 text += ud_insn_asm(&m_Obj);
55
56 ud_disassemble(&m_Obj);
57 m_Location = ud_insn_off(&m_Obj);
58}
void setLocation(uintptr_t location)
void disassemble(LargeStaticString &text)
void setMode(size_t mode)