forked from westerndigitalcorporation/swerv-ISS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInteractive.hpp
127 lines (101 loc) · 4.6 KB
/
Interactive.hpp
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
//
// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright 2018 Western Digital Corporation or its affiliates.
//
// This program is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
// Software Foundation, either version 3 of the License, or (at your option)
// any later version.
//
// 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, see <https://www.gnu.org/licenses/>.
//
#pragma once
#include <unordered_map>
#include "Hart.hpp"
namespace WdRiscv
{
/// Manage an interactive session. To use: Construct an instance
/// with one or more harts then invoke the interact method which
/// will read commands from the standard input and execute them
/// until the quit command is seen. URV (unsigned register value) is
/// either uint32_t or uint64_t depending on the integer register
/// width of the harts.
template <typename URV>
class Interactive
{
public:
/// Constructor.
Interactive(std::vector< Hart<URV>* >& harts);
/// Read commands from the standard input and execute them.
/// Instance traces go the the given traceFile (no instance
/// tracing if traceFile is NULL). Executed commands are logged to
/// the give commandLog file (no comand logging if commandLog is
/// NULL). Return true if all commands are executed successfully.
/// Return false otherwise.
bool interact(FILE* traceFile, FILE* commandLog);
/// Helper to interact: "until" command. Run until address.
bool untilCommand(Hart<URV>&, const std::string& line,
const std::vector<std::string>& tokens,
FILE* traceFile);
/// Helper to interact: "step" command. Single step.
bool stepCommand(Hart<URV>&, const std::string& line,
const std::vector<std::string>& tokens, FILE* traceFile);
/// Helper to interact: "peek" command. Examine a register/memory
/// location.
bool peekCommand(Hart<URV>&, const std::string& line,
const std::vector<std::string>& tokens);
/// Helper to interact: "poke" command. Set a register/memory
/// location.
bool pokeCommand(Hart<URV>&, const std::string& line,
const std::vector<std::string>& tokens);
/// Helper to interact: "disas" command. Disassemble.
bool disassCommand(Hart<URV>&, const std::string& line,
const std::vector<std::string>& tokens);
/// Helper to interact: "elf" command. Load ELF file.
bool elfCommand(Hart<URV>&, const std::string& line,
const std::vector<std::string>& tokens);
/// Helper to interact: "hex" command. Load HEX file.
bool hexCommand(Hart<URV>&, const std::string& line,
const std::vector<std::string>& tokens);
/// Helper to interact: "reset" command. Reset processor.
bool resetCommand(Hart<URV>&, const std::string& line,
const std::vector<std::string>& tokens);
/// Helper to interact: "replay_file" command. Define replay file.
bool replayFileCommand(const std::string& line,
const std::vector<std::string>& tokens,
std::ifstream& stream);
/// Helper to interact: "exception" command. Associate an
/// exception with the first subsequently executed instruction.
bool exceptionCommand(Hart<URV>&, const std::string& line,
const std::vector<std::string>& tokens);
/// Helper to interact: "load_finished" command. Mark an non-blocking
/// load instruction as completed.
bool loadFinishedCommand(Hart<URV>&, const std::string& line,
const std::vector<std::string>& tokens);
/// Helper to interact: "help" command.
void helpCommand(const std::vector<std::string>& tokens);
/// Helper to interact: "replay" command. Replay one or more
/// commands from the replay file.
bool replayCommand(unsigned& currentHartId,
const std::string& line,
const std::vector<std::string>& tokens,
FILE* traceFile, FILE* commandLog,
std::ifstream& replayStream, bool& done);
protected:
/// Helper to interact. Execute a user command.
bool executeLine(unsigned& currentHartId,
const std::string& inLine, FILE* traceFile,
FILE* commandLog,
std::ifstream& replayStream, bool& done);
private:
std::vector< Hart<URV>* >& harts_;
// Initial resets do not reset memory mapped registers.
bool resetMemoryMappedRegs_ = false;
};
}