Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
---
Language: Cpp
# BasedOnStyle: WebKit
AccessModifierOffset: -4
AlignAfterOpenBracket: AlwaysBreak
AlignConsecutiveMacros: false
AlignConsecutiveMacros: true
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
Expand Down Expand Up @@ -120,4 +119,4 @@ StatementMacros:
- QT_REQUIRE_VERSION
TabWidth: 4
UseCRLF: false
UseTab: Never
UseTab: Never
6 changes: 2 additions & 4 deletions src/assembler/simpleasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ class SimpleAsm : public QObject {
~SimpleAsm() override;

public:
static uint64_t
string_to_uint64(const QString &str, int base, int *chars_taken = nullptr);
static uint64_t string_to_uint64(const QString &str, int base, int *chars_taken = nullptr);
void clear();
void setup(
machine::FrontendMemory *mem,
Expand All @@ -61,8 +60,7 @@ class SimpleAsm : public QObject {
const QString &filename = "",
int line_number = 0,
QString *error_ptr = nullptr);
virtual bool
process_file(const QString &filename, QString *error_ptr = nullptr);
virtual bool process_file(const QString &filename, QString *error_ptr = nullptr);
bool finish(QString *error_ptr = nullptr);

protected:
Expand Down
34 changes: 9 additions & 25 deletions src/cli/chariohandler.cpp
Original file line number Diff line number Diff line change
@@ -1,33 +1,20 @@
#include "chariohandler.h"

CharIOHandler::CharIOHandler(QIODevice *iodev, QObject *parent)
: QIODevice(parent)
, fd_list() {
CharIOHandler::CharIOHandler(QIODevice *iodev, QObject *parent) : QIODevice(parent), fd_list() {
this->iodev = iodev;
if (!iodev->parent()) {
iodev->setParent(this);
}
if (!iodev->parent()) { iodev->setParent(this); }
fd_specific = false;
if (iodev->isOpen()) {
Super::open(iodev->openMode());
}
if (iodev->isOpen()) { Super::open(iodev->openMode()); }
connect(iodev, &Super::aboutToClose, this, &CharIOHandler::aboutToClose);
connect(iodev, &Super::bytesWritten, this, &CharIOHandler::bytesWritten);
connect(
iodev, &Super::channelBytesWritten, this,
&CharIOHandler::channelBytesWritten);
connect(
iodev, &Super::channelReadyRead, this,
&CharIOHandler::channelReadyRead);
connect(
iodev, &Super::readChannelFinished, this,
&CharIOHandler::readChannelFinished);
connect(iodev, &Super::channelBytesWritten, this, &CharIOHandler::channelBytesWritten);
connect(iodev, &Super::channelReadyRead, this, &CharIOHandler::channelReadyRead);
connect(iodev, &Super::readChannelFinished, this, &CharIOHandler::readChannelFinished);
connect(iodev, &Super::readyRead, this, &CharIOHandler::readyRead);
}

CharIOHandler::~CharIOHandler() {
if (iodev->parent() == this)
delete iodev;
if (iodev->parent() == this) { delete iodev; }
}

void CharIOHandler::writeByte(unsigned int data) {
Expand All @@ -36,8 +23,7 @@ void CharIOHandler::writeByte(unsigned int data) {
}

void CharIOHandler::writeByte(int fd, unsigned int data) {
if (!fd_specific || fd_list.contains(fd))
writeByte(data);
if (!fd_specific || fd_list.contains(fd)) { writeByte(data); }
}

void CharIOHandler::readBytePoll(int fd, unsigned int &data, bool &available) {
Expand Down Expand Up @@ -67,9 +53,7 @@ bool CharIOHandler::isSequential() const {
}

bool CharIOHandler::open(OpenMode mode) {
if (!iodev->open(mode)) {
return false;
}
if (!iodev->open(mode)) { return false; }
Super::open(mode);
return true;
}
Expand Down
125 changes: 66 additions & 59 deletions src/cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#include "common/logging.h"
#include "common/logging_format_colors.h"
#include "machine/machineconfig.h"
#include "os_emulation/ossyscall.h"
#include "msgreport.h"
#include "os_emulation/ossyscall.h"
#include "reporter.h"
#include "tracer.h"

Expand Down Expand Up @@ -34,23 +34,29 @@ void create_parser(QCommandLineParser &p) {
p.addOption({ "no-delay-slot", "Disable jump delay slot." });
p.addOption(
{ "hazard-unit", "Specify hazard unit implementation [none|stall|forward].", "HUKIND" });
p.addOption({ { "trace-fetch", "tr-fetch" },
"Trace fetched instruction (for both pipelined and not core)." });
p.addOption({ { "trace-decode", "tr-decode" },
"Trace instruction in decode stage. (only for pipelined core)" });
p.addOption({ { "trace-execute", "tr-execute" },
"Trace instruction in execute stage. (only for pipelined core)" });
p.addOption({ { "trace-memory", "tr-memory" },
"Trace instruction in memory stage. (only for pipelined core)" });
p.addOption({ { "trace-writeback", "tr-writeback" },
"Trace instruction in write back stage. (only for pipelined core)" });
p.addOption(
{ { "trace-fetch", "tr-fetch" },
"Trace fetched instruction (for both pipelined and not core)." });
p.addOption(
{ { "trace-decode", "tr-decode" },
"Trace instruction in decode stage. (only for pipelined core)" });
p.addOption(
{ { "trace-execute", "tr-execute" },
"Trace instruction in execute stage. (only for pipelined core)" });
p.addOption(
{ { "trace-memory", "tr-memory" },
"Trace instruction in memory stage. (only for pipelined core)" });
p.addOption(
{ { "trace-writeback", "tr-writeback" },
"Trace instruction in write back stage. (only for pipelined core)" });
p.addOption({ { "trace-pc", "tr-pc" }, "Print program counter register changes." });
p.addOption({ { "trace-wrmem", "tr-wr" }, "Trace writes into memory." });
p.addOption({ { "trace-rdmem", "tr-rd" }, "Trace reads from memory." });
p.addOption({ { "trace-gp", "tr-gp" },
"Print general purpose register changes. You can use * for "
"all registers.",
"REG" });
p.addOption(
{ { "trace-gp", "tr-gp" },
"Print general purpose register changes. You can use * for "
"all registers.",
"REG" });
p.addOption({ "dump-to-json", "Configure reportor dump to json file.", "FNAME" });
p.addOption({ "only-dump", "Do not start the processor." });
p.addOption({ "disable-console-dump", "Configure reporter not to dump to console." });
Expand All @@ -61,34 +67,41 @@ void create_parser(QCommandLineParser &p) {
p.addOption({ "dump-symbol-table", "Dump the symbol table." });
p.addOption({ "load-range", "Load memory range.", "START,FNAME" });
p.addOption({ "expect-fail", "Expect that program causes CPU trap and fail if it doesn't." });
p.addOption({ "fail-match",
"Program should exit with exactly this CPU TRAP. Possible values are "
"I(unsupported Instruction), A(Unsupported ALU operation), "
"O(Overflow/underflow) and J(Unaligned Jump). You can freely combine "
"them. Using this implies expect-fail option.",
"TRAP" });
p.addOption({ "d-cache",
"Data cache. Format policy,sets,words_in_blocks,associativity where "
"policy is random/lru/lfu",
"DCACHE" });
p.addOption({ "i-cache",
"Instruction cache. Format policy,sets,words_in_blocks,associativity "
"where policy is random/lru/lfu",
"ICACHE" });
p.addOption({ "l2-cache",
"L2 cache. Format policy,sets,words_in_blocks,associativity where "
"policy is random/lru/lfu",
"L2CACHE" });
p.addOption(
{ "fail-match",
"Program should exit with exactly this CPU TRAP. Possible values are "
"I(unsupported Instruction), A(Unsupported ALU operation), "
"O(Overflow/underflow) and J(Unaligned Jump). You can freely combine "
"them. Using this implies expect-fail option.",
"TRAP" });
p.addOption(
{ "d-cache",
"Data cache. Format policy,sets,words_in_blocks,associativity where "
"policy is random/lru/lfu",
"DCACHE" });
p.addOption(
{ "i-cache",
"Instruction cache. Format policy,sets,words_in_blocks,associativity "
"where policy is random/lru/lfu",
"ICACHE" });
p.addOption(
{ "l2-cache",
"L2 cache. Format policy,sets,words_in_blocks,associativity where "
"policy is random/lru/lfu",
"L2CACHE" });
p.addOption({ "read-time", "Memory read access time (cycles).", "RTIME" });
p.addOption({ "write-time", "Memory read access time (cycles).", "WTIME" });
p.addOption({ "burst-time", "Memory read access time (cycles).", "BTIME" });
p.addOption({ { "serial-in", "serin" }, "File connected to the serial port input.", "FNAME" });
p.addOption(
{ { "serial-out", "serout" }, "File connected to the serial port output.", "FNAME" });
p.addOption({ { "os-emulation", "osemu" }, "Operating system emulation." });
p.addOption({ { "std-out", "stdout" }, "File connected to the syscall standard output.", "FNAME" });
p.addOption({ { "os-fs-root", "osfsroot" }, "Emulated system root/prefix for opened files", "DIR" });
p.addOption({ { "isa-variant", "isavariant" }, "Instruction set to emulate (default RV32IMA)", "STR" });
p.addOption(
{ { "std-out", "stdout" }, "File connected to the syscall standard output.", "FNAME" });
p.addOption(
{ { "os-fs-root", "osfsroot" }, "Emulated system root/prefix for opened files", "DIR" });
p.addOption(
{ { "isa-variant", "isavariant" }, "Instruction set to emulate (default RV32IMA)", "STR" });
p.addOption({ "cycle-limit", "Limit execution to specified maximum clock cycles", "NUMBER" });
}

Expand Down Expand Up @@ -205,19 +218,18 @@ void configure_machine(QCommandLineParser &parser, MachineConfig &config) {
int siz = parser.values("os-fs-root").size();
if (siz >= 1) {
QString osemu_fs_root = parser.values("os-fs-root").at(siz - 1);
if (osemu_fs_root.length() > 0)
config.set_osemu_fs_root(osemu_fs_root);
if (osemu_fs_root.length() > 0) { config.set_osemu_fs_root(osemu_fs_root); }
}
siz = parser.values("isa-variant").size();
for (int i = 0; i < siz; i++) {
int pos = 0;
bool first = true;
bool subtract = false;
QString isa_str = parser.values("isa-variant").at(i).toUpper();
if (isa_str.startsWith ("RV32")) {
if (isa_str.startsWith("RV32")) {
config.set_simulated_xlen(machine::Xlen::_32);
pos = 4;
} else if (isa_str.startsWith ("RV64")) {
} else if (isa_str.startsWith("RV64")) {
config.set_simulated_xlen(machine::Xlen::_64);
pos = 4;
}
Expand All @@ -231,10 +243,10 @@ void configure_machine(QCommandLineParser &parser, MachineConfig &config) {
continue;
}
auto flag = machine::ConfigIsaWord::byChar(ch);
if (flag.isEmpty())
continue;
if (flag.isEmpty()) continue;
if (first)
config.modify_isa_word(~machine::ConfigIsaWord::empty(), machine::ConfigIsaWord::empty());
config.modify_isa_word(
~machine::ConfigIsaWord::empty(), machine::ConfigIsaWord::empty());
if (subtract)
config.modify_isa_word(flag, machine::ConfigIsaWord::empty());
else
Expand All @@ -256,7 +268,7 @@ void configure_tracer(QCommandLineParser &p, Tracer &tr) {
if (p.isSet("trace-gp")) { tr.trace_regs_gp = true; }

QStringList gps = p.values("trace-gp");
for (const auto & gp : gps) {
for (const auto &gp : gps) {
if (gp == "*") {
tr.regs_to_trace.fill(true);
} else {
Expand All @@ -265,8 +277,7 @@ void configure_tracer(QCommandLineParser &p, Tracer &tr) {
if (res && num <= machine::REGISTER_COUNT) {
tr.regs_to_trace.at(num) = true;
} else {
fprintf(
stderr, "Unknown register number given for trace-gp: %s\n", qPrintable(gp));
fprintf(stderr, "Unknown register number given for trace-gp: %s\n", qPrintable(gp));
exit(EXIT_FAILURE);
}
}
Expand All @@ -280,8 +291,7 @@ void configure_tracer(QCommandLineParser &p, Tracer &tr) {
bool ok;
tr.cycle_limit = clim.at(clim.size() - 1).toLong(&ok);
if (!ok) {
fprintf(
stderr, "Cycle limit parse error\n");
fprintf(stderr, "Cycle limit parse error\n");
exit(EXIT_FAILURE);
}
}
Expand All @@ -303,7 +313,7 @@ void configure_reporter(QCommandLineParser &p, Reporter &r, const SymbolTable *s
if (p.isSet("dump-symbol-table")) { r.enable_symbol_table_reporting(); }

QStringList fail = p.values("fail-match");
for (const auto & i : fail) {
for (const auto &i : fail) {
for (int y = 0; y < i.length(); y++) {
enum Reporter::FailReason reason;
switch (tolower(i.toStdString()[y])) {
Expand Down Expand Up @@ -420,17 +430,18 @@ void configure_osemu(QCommandLineParser &p, MachineConfig &config, Machine *mach
exit(EXIT_FAILURE);
}
}
const static machine::ExceptionCause ecall_variats[] = {machine::EXCAUSE_ECALL_ANY,
machine::EXCAUSE_ECALL_M, machine::EXCAUSE_ECALL_S, machine::EXCAUSE_ECALL_U};
const static machine::ExceptionCause ecall_variats[]
= { machine::EXCAUSE_ECALL_ANY, machine::EXCAUSE_ECALL_M, machine::EXCAUSE_ECALL_S,
machine::EXCAUSE_ECALL_U };

if (config.osemu_enable()) {
auto *osemu_handler = new osemu::OsSyscallExceptionHandler(
config.osemu_known_syscall_stop(), config.osemu_unknown_syscall_stop(),
config.osemu_fs_root());
if (std_out) {
machine::Machine::connect(
osemu_handler, &osemu::OsSyscallExceptionHandler::char_written,
std_out, QOverload<int, unsigned>::of(&CharIOHandler::writeByte));
osemu_handler, &osemu::OsSyscallExceptionHandler::char_written, std_out,
QOverload<int, unsigned>::of(&CharIOHandler::writeByte));
}
/*connect(
osemu_handler, &osemu::OsSyscallExceptionHandler::rx_byte_pool, terminal,
Expand Down Expand Up @@ -475,9 +486,7 @@ void load_ranges(Machine &machine, const QStringList &ranges) {
Address addr = start;
for (std::string line; getline(in, line);) {
size_t end_pos = line.find_last_not_of(" \t\n");
if (std::string::npos == end_pos) {
continue;
}
if (std::string::npos == end_pos) { continue; }

size_t start_pos = line.find_first_not_of(" \t\n");
line = line.substr(0, end_pos + 1);
Expand Down Expand Up @@ -507,9 +516,7 @@ bool assemble(Machine &machine, MsgReport &msgrep, const QString &filename) {

assembler.setup(mem, &symbol_table_db, 0x00000200_addr, machine.core()->get_xlen());

if (!assembler.process_file(filename)) {
return false;
}
if (!assembler.process_file(filename)) { return false; }

return assembler.finish();
}
Expand Down
12 changes: 5 additions & 7 deletions src/cli/reporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,16 @@ void Reporter::report() {
for (const auto &name : machine->symbol_table()->names()) {
SymbolValue sym_val;
machine->symbol_table()->name_to_value(sym_val, name);
QString value = QString::asprintf(machine->core()->get_xlen() == Xlen::_32 ? "0x%08" PRIx64 : "0x%016" PRIx64, sym_val);
if (dump_format & DumpFormat::JSON) {
symtab_json[name] = value;
}
QString value = QString::asprintf(
machine->core()->get_xlen() == Xlen::_32 ? "0x%08" PRIx64 : "0x%016" PRIx64,
sym_val);
if (dump_format & DumpFormat::JSON) { symtab_json[name] = value; }
if (dump_format & DumpFormat::CONSOLE) {
printf("SYM[%s]: %s\n", qPrintable(name), qPrintable(value));
}
}

if (dump_format & DumpFormat::JSON) {
dump_data_json["symbols"] = symtab_json;
}
if (dump_format & DumpFormat::JSON) { dump_data_json["symbols"] = symtab_json; }
}

if (dump_format & DumpFormat::JSON) {
Expand Down
10 changes: 6 additions & 4 deletions src/cli/tracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ void Tracer::step_output() {
printf("GP %zu: %" PRIx64 "\n", size_t(wb.num_rd), wb.value.as_u64());
}
if (trace_rdmem && mem_wb.memtoreg) {
printf("MEM[%" PRIx64 "]: RD %" PRIx64 "\n", mem_wb.mem_addr.get_raw(),
mem_wb.towrite_val.as_u64());
printf(
"MEM[%" PRIx64 "]: RD %" PRIx64 "\n", mem_wb.mem_addr.get_raw(),
mem_wb.towrite_val.as_u64());
}
if (trace_wrmem && mem.memwrite) {
printf("MEM[%" PRIx64 "]: WR %" PRIx64 "\n", mem_wb.mem_addr.get_raw(),
mem.mem_write_val.as_u64());
printf(
"MEM[%" PRIx64 "]: WR %" PRIx64 "\n", mem_wb.mem_addr.get_raw(),
mem.mem_write_val.as_u64());
}
if ((cycle_limit != 0) && (core_state.cycle_count >= cycle_limit)) {
emit cycle_limit_reached();
Expand Down
2 changes: 1 addition & 1 deletion src/cli/tracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private slots:
public:
std::array<bool, machine::REGISTER_COUNT> regs_to_trace = {};
bool trace_fetch = false, trace_decode = false, trace_execute = false, trace_memory = false,
trace_writeback = false, trace_pc = false, trace_wrmem = false, trace_rdmem = false,
trace_writeback = false, trace_pc = false, trace_wrmem = false, trace_rdmem = false,
trace_regs_gp = false;
quint64 cycle_limit;
};
Expand Down
Loading
Loading