-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
DSPSymbols.cpp
88 lines (75 loc) · 1.82 KB
/
DSPSymbols.cpp
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
// Copyright 2009 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "Core/HW/DSPLLE/DSPSymbols.h"
#include <map>
#include <string>
#include <vector>
#include "Common/CommonTypes.h"
#include "Common/Logging/Log.h"
#include "Core/DSP/DSPCore.h"
#include "Core/DSP/DSPDisassembler.h"
namespace DSP::Symbols
{
static std::map<u16, int> addr_to_line;
static std::map<int, u16> line_to_addr;
static std::vector<std::string> lines;
static int line_counter = 0;
int Addr2Line(u16 address) // -1 for not found
{
std::map<u16, int>::iterator iter = addr_to_line.find(address);
if (iter != addr_to_line.end())
return iter->second;
else
return -1;
}
int Line2Addr(int line) // -1 for not found
{
std::map<int, u16>::iterator iter = line_to_addr.find(line);
if (iter != line_to_addr.end())
return iter->second;
else
return -1;
}
const char* GetLineText(int line)
{
if (line >= 0 && line < (int)lines.size())
{
return lines[line].c_str();
}
else
{
return "----";
}
}
void AutoDisassembly(const SDSP& dsp, u16 start_addr, u16 end_addr)
{
AssemblerSettings settings;
settings.show_pc = true;
settings.show_hex = true;
DSPDisassembler disasm(settings);
u16 addr = start_addr;
const u16* ptr = (start_addr >> 15) != 0 ? dsp.irom : dsp.iram;
constexpr size_t size = DSP_IROM_SIZE;
static_assert(size == DSP_IRAM_SIZE);
while (addr < end_addr)
{
line_to_addr[line_counter] = addr;
addr_to_line[addr] = line_counter;
std::string buf;
if (!disasm.DisassembleOpcode(ptr, size, &addr, buf))
{
ERROR_LOG_FMT(DSPLLE, "disasm failed at {:04x}", addr);
break;
}
lines.push_back(buf);
line_counter++;
}
}
void Clear()
{
addr_to_line.clear();
line_to_addr.clear();
lines.clear();
line_counter = 0;
}
} // namespace DSP::Symbols