Skip to content

Commit ff2bbd7

Browse files
authored
Support for xv6 (pdos) (#185)
2 parents a0acf10 + 391a009 commit ff2bbd7

44 files changed

Lines changed: 1597 additions & 363 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/cli/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ set(cli_SOURCES
1111
msgreport.cpp
1212
reporter.cpp
1313
tracer.cpp
14+
utilandtext.cpp
1415
)
1516
set(cli_HEADERS
1617
chariohandler.h
1718
msgreport.h
1819
reporter.h
1920
tracer.h
21+
utilandtext.h
2022
)
2123

2224
add_executable(cli

src/cli/main.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ void create_parser(QCommandLineParser &p) {
5252
p.addOption({ { "trace-pc", "tr-pc" }, "Print program counter register changes." });
5353
p.addOption({ { "trace-wrmem", "tr-wr" }, "Trace writes into memory." });
5454
p.addOption({ { "trace-rdmem", "tr-rd" }, "Trace reads from memory." });
55+
p.addOption({ { "trace-exception", "tr-excpt" }, "Trace exceptions." });
56+
p.addOption({ { "trace-mode-change", "tr-mode" }, "Trace mode changes." });
5557
p.addOption(
5658
{ { "trace-gp", "tr-gp" },
5759
"Print general purpose register changes. You can use * for "
@@ -120,6 +122,9 @@ void create_parser(QCommandLineParser &p) {
120122
p.addOption(
121123
{ { "isa-variant", "isavariant" }, "Instruction set to emulate (default RV32IMA)", "STR" });
122124
p.addOption({ "cycle-limit", "Limit execution to specified maximum clock cycles", "NUMBER" });
125+
p.addOption({ "enable-vm", "Enable virtual memory support." });
126+
p.addOption({ "enable-exception", "Enable exception delivery to the run code." });
127+
p.addOption({ "enable-interrupt", "Enable interrupts delivery to the run code." });
123128
}
124129

125130
void configure_cache(CacheConfig &cacheconf, const QStringList &cachearg, const QString &which) {
@@ -343,6 +348,7 @@ void configure_machine(QCommandLineParser &parser, MachineConfig &config) {
343348
config.modify_isa_word(flag, flag);
344349
}
345350
}
351+
config.set_vm_enabled(parser.isSet("enable-vm"));
346352
}
347353

348354
void configure_tracer(QCommandLineParser &p, Tracer &tr) {
@@ -375,6 +381,8 @@ void configure_tracer(QCommandLineParser &p, Tracer &tr) {
375381

376382
if (p.isSet("trace-rdmem")) { tr.trace_rdmem = true; }
377383
if (p.isSet("trace-wrmem")) { tr.trace_wrmem = true; }
384+
if (p.isSet("trace-exception")) { tr.trace_exception = true; }
385+
if (p.isSet("trace-mode-change")) { tr.trace_mode_change = true; }
378386

379387
QStringList clim = p.values("cycle-limit");
380388
if (!clim.empty()) {
@@ -527,6 +535,24 @@ void configure_osemu(QCommandLineParser &p, MachineConfig &config, Machine *mach
527535
exit(EXIT_FAILURE);
528536
}
529537
}
538+
539+
if (p.isSet("enable-exception")) {
540+
config.set_osemu_exception_stop(false);
541+
for (int excause = EXCAUSE_NONE + 1; excause < EXCAUSE_COUNT; excause++) {
542+
if (excause != EXCAUSE_INT_M && excause != EXCAUSE_INT_S) {
543+
machine->set_step_over_exception(static_cast<ExceptionCause>(excause), false);
544+
machine->set_stop_on_exception(static_cast<ExceptionCause>(excause), false);
545+
}
546+
}
547+
}
548+
if (p.isSet("enable-interrupt")) {
549+
config.set_osemu_interrupt_stop(false);
550+
machine->set_step_over_exception(EXCAUSE_INT_M, false);
551+
machine->set_step_over_exception(EXCAUSE_INT_S, false);
552+
machine->set_stop_on_exception(EXCAUSE_INT_M, false);
553+
machine->set_stop_on_exception(EXCAUSE_INT_S, false);
554+
}
555+
530556
const static machine::ExceptionCause ecall_variats[]
531557
= { machine::EXCAUSE_ECALL_ANY, machine::EXCAUSE_ECALL_M, machine::EXCAUSE_ECALL_S,
532558
machine::EXCAUSE_ECALL_U };

src/cli/reporter.cpp

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "reporter.h"
22

3+
#include "utilandtext.h"
4+
35
#include <cinttypes>
46

57
using namespace machine;
@@ -30,34 +32,6 @@ void Reporter::machine_exit() {
3032
}
3133
}
3234

33-
/* TODO: Decide whether this should be moved to machine to avoid duplication or kept aside as
34-
a visualization concern */
35-
constexpr const char *get_exception_name(ExceptionCause exception_cause) {
36-
switch (exception_cause) {
37-
case EXCAUSE_NONE: return "NONE";
38-
case EXCAUSE_INSN_FAULT: return "INSN_FAULT";
39-
case EXCAUSE_INSN_ILLEGAL: return "INSN_ILLEGAL";
40-
case EXCAUSE_BREAK: return "BREAK";
41-
case EXCAUSE_LOAD_MISALIGNED: return "LOAD_MISALIGNED";
42-
case EXCAUSE_LOAD_FAULT: return "LOAD_FAULT";
43-
case EXCAUSE_STORE_MISALIGNED: return "STORE_MISALIGNED";
44-
case EXCAUSE_STORE_FAULT: return "STORE_FAULT";
45-
case EXCAUSE_ECALL_U: return "ECALL_U";
46-
case EXCAUSE_ECALL_S: return "ECALL_S";
47-
case EXCAUSE_RESERVED_10: return "RESERVED_10";
48-
case EXCAUSE_ECALL_M: return "ECALL_M";
49-
case EXCAUSE_INSN_PAGE_FAULT: return "INSN_PAGE_FAULT";
50-
case EXCAUSE_LOAD_PAGE_FAULT: return "LOAD_PAGE_FAULT";
51-
case EXCAUSE_RESERVED_14: return "RESERVED_14";
52-
case EXCAUSE_STORE_PAGE_FAULT: return "STORE_PAGE_FAULT";
53-
// Simulator specific exception cause codes, alliases
54-
case EXCAUSE_HWBREAK: return "HWBREAK";
55-
case EXCAUSE_ECALL_ANY: return "ECALL_ANY";
56-
case EXCAUSE_INT: return "INT";
57-
default: UNREACHABLE
58-
}
59-
}
60-
6135
void Reporter::machine_exception_reached() {
6236
ExceptionCause excause = machine->get_exception_cause();
6337
printf("Machine stopped on %s exception.\n", get_exception_name(excause));

src/cli/tracer.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
#include "tracer.h"
22

3+
#include "utilandtext.h"
4+
35
#include <cinttypes>
46

57
using namespace machine;
68

79
Tracer::Tracer(Machine *machine) : core_state(machine->core()->get_state()) {
810
cycle_limit = 0;
11+
last_priv_lev = CSR::PrivilegeLevel::MACHINE;
912

1013
connect(machine->core(), &Core::step_done, this, &Tracer::step_output);
1114
}
@@ -49,6 +52,19 @@ void Tracer::step_output() {
4952
"MEM[%" PRIx64 "]: WR %" PRIx64 "\n", mem_wb.mem_addr.get_raw(),
5053
mem.mem_write_val.as_u64());
5154
}
55+
if (trace_exception) {
56+
if (mem_wb.excause != EXCAUSE_NONE) {
57+
printf("EXCEPTION %s\n", get_exception_name(mem_wb.excause));
58+
}
59+
}
60+
if (trace_mode_change) {
61+
if (last_priv_lev != core_state.current_privilege()) {
62+
printf(
63+
"MODE CHANGED from %s to %s\n", get_privilege_level_name(last_priv_lev),
64+
get_privilege_level_name(core_state.current_privilege()));
65+
last_priv_lev = core_state.current_privilege();
66+
}
67+
}
5268
if ((cycle_limit != 0) && (core_state.cycle_count >= cycle_limit)) {
5369
emit cycle_limit_reached();
5470
}

src/cli/tracer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ private slots:
2424

2525
private:
2626
const machine::CoreState &core_state;
27+
machine::CSR::PrivilegeLevel last_priv_lev;
2728

2829
public:
2930
std::array<bool, machine::REGISTER_COUNT> regs_to_trace = {};
3031
bool trace_fetch = false, trace_decode = false, trace_execute = false, trace_memory = false,
3132
trace_writeback = false, trace_pc = false, trace_wrmem = false, trace_rdmem = false,
32-
trace_regs_gp = false;
33+
trace_regs_gp = false, trace_exception = false, trace_mode_change = false;
3334
quint64 cycle_limit;
3435
};
3536

src/cli/utilandtext.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include "utilandtext.h"
2+
using namespace machine;
3+
4+
/* TODO: Decide whether this should be moved to machine to avoid duplication or kept aside as
5+
a visualization concern */
6+
const char *get_exception_name(ExceptionCause exception_cause) {
7+
switch (exception_cause) {
8+
case EXCAUSE_NONE: return "NONE";
9+
case EXCAUSE_INSN_FAULT: return "INSN_FAULT";
10+
case EXCAUSE_INSN_ILLEGAL: return "INSN_ILLEGAL";
11+
case EXCAUSE_BREAK: return "BREAK";
12+
case EXCAUSE_LOAD_MISALIGNED: return "LOAD_MISALIGNED";
13+
case EXCAUSE_LOAD_FAULT: return "LOAD_FAULT";
14+
case EXCAUSE_STORE_MISALIGNED: return "STORE_MISALIGNED";
15+
case EXCAUSE_STORE_FAULT: return "STORE_FAULT";
16+
case EXCAUSE_ECALL_U: return "ECALL_U";
17+
case EXCAUSE_ECALL_S: return "ECALL_S";
18+
case EXCAUSE_RESERVED_10: return "RESERVED_10";
19+
case EXCAUSE_ECALL_M: return "ECALL_M";
20+
case EXCAUSE_INSN_PAGE_FAULT: return "INSN_PAGE_FAULT";
21+
case EXCAUSE_LOAD_PAGE_FAULT: return "LOAD_PAGE_FAULT";
22+
case EXCAUSE_RESERVED_14: return "RESERVED_14";
23+
case EXCAUSE_STORE_PAGE_FAULT: return "STORE_PAGE_FAULT";
24+
// Simulator specific exception cause codes, alliases
25+
case EXCAUSE_HWBREAK: return "HWBREAK";
26+
case EXCAUSE_ECALL_ANY: return "ECALL_ANY";
27+
case EXCAUSE_INT_M: return "INT_M";
28+
case EXCAUSE_INT_S: return "INT_S";
29+
default: UNREACHABLE
30+
}
31+
}
32+
33+
const char *get_privilege_level_name(machine::CSR::PrivilegeLevel level) {
34+
switch (level) {
35+
case CSR::PrivilegeLevel::UNPRIVILEGED: return "UNPRIVILEGED";
36+
case CSR::PrivilegeLevel::SUPERVISOR: return "SUPERVISOR";
37+
case CSR::PrivilegeLevel::HYPERVISOR: return "HYPERVISOR";
38+
case CSR::PrivilegeLevel::MACHINE: return "MACHINE";
39+
default: UNREACHABLE
40+
}
41+
}

src/cli/utilandtext.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef UTILANDTEXT_H
2+
#define UTILANDTEXT_H
3+
4+
#include "machine/csr/address.h"
5+
#include "machine/machinedefs.h"
6+
7+
const char *get_exception_name(machine::ExceptionCause exception_cause);
8+
const char *get_privilege_level_name(machine::CSR::PrivilegeLevel level);
9+
10+
#endif // UTILANDTEXT_H

src/gui/ui/hexlineedit.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#include "hexlineedit.h"
22

3+
#include <QTextStream>
4+
#include <QtGlobal>
5+
36
HexLineEdit::HexLineEdit(QWidget *parent, int digits, int base, const QString &prefix)
47
: Super(parent) {
58
this->base = base;
@@ -40,7 +43,7 @@ HexLineEdit::HexLineEdit(QWidget *parent, int digits, int base, const QString &p
4043
set_value(0);
4144
}
4245

43-
void HexLineEdit::set_value(uint32_t value) {
46+
void HexLineEdit::set_value(uint64_t value) {
4447
QString s, t = "";
4548
last_set = value;
4649
s = QString::number(value, base);
@@ -50,8 +53,9 @@ void HexLineEdit::set_value(uint32_t value) {
5053

5154
void HexLineEdit::on_edit_finished() {
5255
bool ok;
53-
uint32_t val;
54-
val = text().toULong(&ok, 16);
56+
uint64_t val;
57+
58+
val = text().toULongLong(&ok, base);
5559
if (!ok) {
5660
set_value(last_set);
5761
return;

src/gui/ui/hexlineedit.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ class HexLineEdit : public QLineEdit {
1717
const QString &prefix = "0x");
1818

1919
public slots:
20-
void set_value(uint32_t value);
20+
void set_value(uint64_t value);
2121

2222
signals:
23-
void value_edit_finished(uint32_t value);
23+
void value_edit_finished(uint64_t value);
2424

2525
private slots:
2626
void on_edit_finished();
@@ -29,7 +29,7 @@ private slots:
2929
int base;
3030
int digits;
3131
QString prefix;
32-
uint32_t last_set;
32+
uint64_t last_set;
3333
};
3434

3535
#endif // HEXLINEEDIT_H

src/gui/windows/coreview/data.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ static const std::unordered_map<unsigned, QString> EXCEPTION_NAME_TABLE = {
4343
// Simulator specific exception cause codes, alliases
4444
{ machine::EXCAUSE_HWBREAK, QStringLiteral("HWBREAK") },
4545
{ machine::EXCAUSE_ECALL_ANY, QStringLiteral("ECALL") },
46-
{ machine::EXCAUSE_INT, QStringLiteral("INT") },
46+
{ machine::EXCAUSE_INT_M, QStringLiteral("INT_M") },
47+
{ machine::EXCAUSE_INT_S, QStringLiteral("INT_S") },
4748
};
4849

4950
static const std::unordered_map<unsigned, QString> STALL_TEXT_TABLE = {

0 commit comments

Comments
 (0)