diff --git a/.clang-format b/.clang-format index 6d8c7c71..b6b4f1ad 100644 --- a/.clang-format +++ b/.clang-format @@ -1,9 +1,8 @@ --- -Language: Cpp # BasedOnStyle: WebKit AccessModifierOffset: -4 AlignAfterOpenBracket: AlwaysBreak -AlignConsecutiveMacros: false +AlignConsecutiveMacros: true AlignConsecutiveAssignments: false AlignConsecutiveDeclarations: false AlignEscapedNewlines: Right @@ -120,4 +119,4 @@ StatementMacros: - QT_REQUIRE_VERSION TabWidth: 4 UseCRLF: false -UseTab: Never \ No newline at end of file +UseTab: Never diff --git a/src/assembler/simpleasm.h b/src/assembler/simpleasm.h index be134cd4..aeb05c01 100644 --- a/src/assembler/simpleasm.h +++ b/src/assembler/simpleasm.h @@ -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, @@ -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: diff --git a/src/cli/chariohandler.cpp b/src/cli/chariohandler.cpp index a4d759d4..7db77c5b 100644 --- a/src/cli/chariohandler.cpp +++ b/src/cli/chariohandler.cpp @@ -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) { @@ -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) { @@ -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; } diff --git a/src/cli/main.cpp b/src/cli/main.cpp index e706891c..7fa5e1b6 100644 --- a/src/cli/main.cpp +++ b/src/cli/main.cpp @@ -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" @@ -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." }); @@ -61,24 +67,28 @@ 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" }); @@ -86,9 +96,12 @@ void create_parser(QCommandLineParser &p) { 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" }); } @@ -205,8 +218,7 @@ 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++) { @@ -214,10 +226,10 @@ void configure_machine(QCommandLineParser &parser, MachineConfig &config) { 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; } @@ -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 @@ -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 { @@ -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); } } @@ -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); } } @@ -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])) { @@ -420,8 +430,9 @@ 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( @@ -429,8 +440,8 @@ void configure_osemu(QCommandLineParser &p, MachineConfig &config, Machine *mach config.osemu_fs_root()); if (std_out) { machine::Machine::connect( - osemu_handler, &osemu::OsSyscallExceptionHandler::char_written, - std_out, QOverload::of(&CharIOHandler::writeByte)); + osemu_handler, &osemu::OsSyscallExceptionHandler::char_written, std_out, + QOverload::of(&CharIOHandler::writeByte)); } /*connect( osemu_handler, &osemu::OsSyscallExceptionHandler::rx_byte_pool, terminal, @@ -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); @@ -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(); } diff --git a/src/cli/reporter.cpp b/src/cli/reporter.cpp index 6abde28b..4f8d4491 100644 --- a/src/cli/reporter.cpp +++ b/src/cli/reporter.cpp @@ -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) { diff --git a/src/cli/tracer.cpp b/src/cli/tracer.cpp index 7096c7ff..c52a565d 100644 --- a/src/cli/tracer.cpp +++ b/src/cli/tracer.cpp @@ -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(); diff --git a/src/cli/tracer.h b/src/cli/tracer.h index 2709707e..d6e06d89 100644 --- a/src/cli/tracer.h +++ b/src/cli/tracer.h @@ -28,7 +28,7 @@ private slots: public: std::array 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; }; diff --git a/src/common/endian.h b/src/common/endian.h index b26973dc..83e8d24d 100644 --- a/src/common/endian.h +++ b/src/common/endian.h @@ -33,8 +33,7 @@ inline constexpr Endian get_native_endian() { #elif (defined(__LITTLE_ENDIAN__)) return LITTLE; #else - static_assert( - false, "Could not detect endian or endian is neither big nor little."); + static_assert(false, "Could not detect endian or endian is neither big nor little."); #endif } @@ -46,8 +45,7 @@ constexpr Endian NATIVE_ENDIAN = get_native_endian(); */ template inline T byteswap(T val) { - static_assert( - sizeof(T) <= 8, "Byteswap of large types is implementation dependant."); + static_assert(sizeof(T) <= 8, "Byteswap of large types is implementation dependant."); union U { T val; diff --git a/src/common/logging.h b/src/common/logging.h index 70804ea9..1e40e3ce 100644 --- a/src/common/logging.h +++ b/src/common/logging.h @@ -29,8 +29,8 @@ #else #define DEBUG(...) qCDebug(_loging_category_, __VA_ARGS__) #endif -#define LOG(...) qCInfo(_loging_category_, __VA_ARGS__) -#define WARN(...) qCWarning(_loging_category_, __VA_ARGS__) +#define LOG(...) qCInfo(_loging_category_, __VA_ARGS__) +#define WARN(...) qCWarning(_loging_category_, __VA_ARGS__) #define ERROR(...) qCCritical(_loging_category_, __VA_ARGS__) #endif diff --git a/src/common/logging_format_colors.h b/src/common/logging_format_colors.h index 37314e46..dfdaf27e 100644 --- a/src/common/logging_format_colors.h +++ b/src/common/logging_format_colors.h @@ -4,13 +4,14 @@ #include static void set_default_log_pattern() { - qSetMessagePattern("%{if-info}\033[34m[INFO] %{endif}" - "%{if-debug}\033[37m[DEBUG] %{endif}" - "%{if-warning}\033[33m[WARN] %{endif}" - "%{if-critical}\033[31m[ERROR] %{endif}" - "%{if-fatal}\033[31m[FATAL ERROR] %{endif}" - "%{if-category}%{category}:%{endif}" - "\033[0m\t%{message}"); + qSetMessagePattern( + "%{if-info}\033[34m[INFO] %{endif}" + "%{if-debug}\033[37m[DEBUG] %{endif}" + "%{if-warning}\033[33m[WARN] %{endif}" + "%{if-critical}\033[31m[ERROR] %{endif}" + "%{if-fatal}\033[31m[FATAL ERROR] %{endif}" + "%{if-category}%{category}:%{endif}" + "\033[0m\t%{message}"); } #endif // LOGGING_FORMAT_COLORS_H diff --git a/src/common/polyfills/byteswap.h b/src/common/polyfills/byteswap.h index 07ed706a..bb3aea85 100644 --- a/src/common/polyfills/byteswap.h +++ b/src/common/polyfills/byteswap.h @@ -12,10 +12,10 @@ #define bswap16(x) __builtin_bswap16((x)) #define bswap32(x) __builtin_bswap32((x)) #define bswap64(x) __builtin_bswap64((x)) -#elif defined(__has_builtin) \ - && __has_builtin(__builtin_bswap64) /* for clang; gcc 5 fails on this and \ - && short circuit fails; must be \ - after GCC check */ +#elif defined(__has_builtin) && __has_builtin(__builtin_bswap64) /* for clang; gcc 5 fails on this \ + and \ + && short circuit fails; must \ + be after GCC check */ #define bswap16(x) __builtin_bswap16((x)) #define bswap32(x) __builtin_bswap32((x)) #define bswap64(x) __builtin_bswap64((x)) @@ -29,10 +29,8 @@ static inline uint32_t bswap32(uint32_t x) { return (val << 16) | (val >> 16); } static inline uint64_t bswap64(uint64_t x) { - val = ((val << 8) & 0xFF00FF00FF00FF00ULL) - | ((val >> 8) & 0x00FF00FF00FF00FFULL); - val = ((val << 16) & 0xFFFF0000FFFF0000ULL) - | ((val >> 16) & 0x0000FFFF0000FFFFULL); + val = ((val << 8) & 0xFF00FF00FF00FF00ULL) | ((val >> 8) & 0x00FF00FF00FF00FFULL); + val = ((val << 16) & 0xFFFF0000FFFF0000ULL) | ((val >> 16) & 0x0000FFFF0000FFFFULL); return (val << 32) | (val >> 32); } #endif diff --git a/src/common/polyfills/endian_detection.h b/src/common/polyfills/endian_detection.h index ccfca826..3646b6a6 100644 --- a/src/common/polyfills/endian_detection.h +++ b/src/common/polyfills/endian_detection.h @@ -27,31 +27,27 @@ #endif #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__) - #if (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) \ - || (defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN) \ - || (defined(_BYTE_ORDER) && _BYTE_ORDER == _BIG_ENDIAN) \ - || (defined(BYTE_ORDER) && BYTE_ORDER == BIG_ENDIAN) \ - || (defined(__sun) && defined(__SVR4) && defined(_BIG_ENDIAN)) \ - || defined(__ARMEB__) || defined(__THUMBEB__) \ - || defined(__AARCH64EB__) || defined(_MIBSEB) || defined(__MIBSEB) \ + #if (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) \ + || (defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN) \ + || (defined(_BYTE_ORDER) && _BYTE_ORDER == _BIG_ENDIAN) \ + || (defined(BYTE_ORDER) && BYTE_ORDER == BIG_ENDIAN) \ + || (defined(__sun) && defined(__SVR4) && defined(_BIG_ENDIAN)) || defined(__ARMEB__) \ + || defined(__THUMBEB__) || defined(__AARCH64EB__) || defined(_MIBSEB) || defined(__MIBSEB) \ || defined(__MIBSEB__) || defined(_M_PPC) #define __BIG_ENDIAN__ - #elif ( \ - defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) \ - || /* gcc */ \ - (defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN) /* linux \ - header \ - */ \ - || (defined(_BYTE_ORDER) && _BYTE_ORDER == _LITTLE_ENDIAN) \ - || (defined(BYTE_ORDER) && BYTE_ORDER == LITTLE_ENDIAN) /* mingw \ - header */ \ - || (defined(__sun) && defined(__SVR4) && defined(_LITTLE_ENDIAN)) \ - || /* solaris */ \ - defined(__ARMEL__) || defined(__THUMBEL__) || defined(__AARCH64EL__) \ - || defined(_MIPSEL) || defined(__MIPSEL) || defined(__MIPSEL__) \ - || defined(_M_IX86) || defined(_M_X64) || defined(_M_IA64) \ - || /* msvc for intel processors */ \ - defined(_M_ARM) /* msvc code on arm executes in little endian mode */ + #elif (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) || /* gcc */ \ + (defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN) /* linux \ + header \ + */ \ + || (defined(_BYTE_ORDER) && _BYTE_ORDER == _LITTLE_ENDIAN) \ + || (defined(BYTE_ORDER) && BYTE_ORDER == LITTLE_ENDIAN) /* mingw \ + header */ \ + || (defined(__sun) && defined(__SVR4) && defined(_LITTLE_ENDIAN)) || /* solaris */ \ + defined(__ARMEL__) || defined(__THUMBEL__) || defined(__AARCH64EL__) || defined(_MIPSEL) \ + || defined(__MIPSEL) || defined(__MIPSEL__) || defined(_M_IX86) || defined(_M_X64) \ + || defined(_M_IA64) || /* msvc for intel \ + processors */ \ + defined(_M_ARM) /* msvc code on arm executes in little endian mode */ #define __LITTLE_ENDIAN__ #endif #endif diff --git a/src/common/polyfills/mulh64.h b/src/common/polyfills/mulh64.h index eeaa172e..4b2b21dc 100644 --- a/src/common/polyfills/mulh64.h +++ b/src/common/polyfills/mulh64.h @@ -120,14 +120,14 @@ static inline constexpr uint64_t mulhsu64(int64_t a, uint64_t b) { #include // https://docs.microsoft.com/en-gb/cpp/intrinsics/umulh - #define mulhu64 __umulh + #define mulhu64 __umulh // https://docs.microsoft.com/en-gb/cpp/intrinsics/mulh - #define mulh64 __mulh + #define mulh64 __mulh // Not provided by MVSC #define mulhsu64 mulhsu64_fallback #else - #define mulh64 mulh64_fallback - #define mulhu64 mulhu64_fallback + #define mulh64 mulh64_fallback + #define mulhu64 mulhu64_fallback #define mulhsu64 mulhsu64_fallback #endif diff --git a/src/common/polyfills/qstring_hash.h b/src/common/polyfills/qstring_hash.h index 6afa9f25..4fa533c6 100644 --- a/src/common/polyfills/qstring_hash.h +++ b/src/common/polyfills/qstring_hash.h @@ -9,17 +9,13 @@ namespace std { template<> struct hash { - std::size_t operator()(const QString &s) const noexcept { - return qHash(s); - } + std::size_t operator()(const QString &s) const noexcept { return qHash(s); } }; #if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) template<> struct hash { - std::size_t operator()(const QStringView &s) const noexcept { - return qHash(s); - } + std::size_t operator()(const QStringView &s) const noexcept { return qHash(s); } }; #endif diff --git a/src/common/type_utils/lens.h b/src/common/type_utils/lens.h index 6537a708..12d37f44 100644 --- a/src/common/type_utils/lens.h +++ b/src/common/type_utils/lens.h @@ -31,10 +31,7 @@ template using Lens = const FIELD_TYPE &(*const)(const BASE &); -#define LENS(BASE_TYPE, MEMBER) \ - ([](const BASE_TYPE &base) -> const auto & { \ - return base.MEMBER; \ - }) +#define LENS(BASE_TYPE, MEMBER) ([](const BASE_TYPE &base) -> const auto & { return base.MEMBER; }) template using LensPair = std::pair (*const)(const BASE &); diff --git a/src/gui/dialogs/about/aboutdialog.cpp b/src/gui/dialogs/about/aboutdialog.cpp index 4b7db21d..82d87485 100644 --- a/src/gui/dialogs/about/aboutdialog.cpp +++ b/src/gui/dialogs/about/aboutdialog.cpp @@ -34,9 +34,10 @@ AboutDialog::AboutDialog(QWidget *parent) : QDialog(parent) { QString versionText; versionText = "Version " APP_VERSION "\n"; - vl->addWidget(new QLabel("" APP_NAME " " - "- RISC-V Architecture Simulator")); + vl->addWidget(new QLabel( + "" APP_NAME " " + "- RISC-V Architecture Simulator")); lbl = new QLabel(versionText); lbl->setAlignment(Qt::AlignHCenter); lbl->setOpenExternalLinks(true); @@ -44,19 +45,20 @@ AboutDialog::AboutDialog(QWidget *parent) : QDialog(parent) { vl->addWidget(new QLabel(COPYRIGHT_HTML)); QString supportText; - supportText = "Home Page : " APP_GIT "
" - "Implemented for Computer Architectures and Advanced Computer Architectures courses " - "at Czech Technical " - "University in Prague" - " Faculty of Electrical " - "Engineering
" - "QtRvSim on-line version and links to course materials at
" - "https://comparch.edu.cvut.cz/
"; + supportText + = "Home Page : " APP_GIT "
" + "Implemented for Computer Architectures and Advanced Computer Architectures courses " + "at Czech Technical " + "University in Prague" + " Faculty of Electrical " + "Engineering
" + "QtRvSim on-line version and links to course materials at
" + "https://comparch.edu.cvut.cz/
"; auto *supportBrowser = new QTextBrowser; supportBrowser->setOpenExternalLinks(true); diff --git a/src/gui/dialogs/gotosymbol/gotosymboldialog.cpp b/src/gui/dialogs/gotosymbol/gotosymboldialog.cpp index b96d486f..dcfc0a6b 100644 --- a/src/gui/dialogs/gotosymbol/gotosymboldialog.cpp +++ b/src/gui/dialogs/gotosymbol/gotosymboldialog.cpp @@ -2,19 +2,13 @@ #include "ui_gotosymboldialog.h" -GoToSymbolDialog::GoToSymbolDialog( - QWidget *parent, - const QStringList &symbol_names) +GoToSymbolDialog::GoToSymbolDialog(QWidget *parent, const QStringList &symbol_names) : QDialog(parent) , ui(new Ui::GoToSymbolDialog) { ui->setupUi(this); - connect( - ui->pushShowProg, &QAbstractButton::clicked, this, - &GoToSymbolDialog::show_prog); - connect( - ui->pushShowMem, &QAbstractButton::clicked, this, - &GoToSymbolDialog::show_mem); + connect(ui->pushShowProg, &QAbstractButton::clicked, this, &GoToSymbolDialog::show_prog); + connect(ui->pushShowMem, &QAbstractButton::clicked, this, &GoToSymbolDialog::show_mem); connect(ui->pushClose, &QAbstractButton::clicked, this, &QWidget::close); ui->listSymbols->addItems(symbol_names); diff --git a/src/gui/dialogs/new/newdialog.cpp b/src/gui/dialogs/new/newdialog.cpp index 5fd5bae2..b6bba178 100644 --- a/src/gui/dialogs/new/newdialog.cpp +++ b/src/gui/dialogs/new/newdialog.cpp @@ -33,79 +33,40 @@ NewDialog::NewDialog(QWidget *parent, QSettings *settings) : QDialog(parent) { for (int i = 0; i < ui->config_pages->count(); ++i) { QString page_id = ui->config_pages->widget(i)->objectName(); QString page_name = ui->config_pages->widget(i)->accessibleName(); - config_pages_items.append(new QTreeWidgetItem(static_cast(nullptr), - QStringList{page_name, page_id})); + config_pages_items.append(new QTreeWidgetItem( + static_cast(nullptr), QStringList { page_name, page_id })); } ui->page_select_tree->insertTopLevelItems(0, config_pages_items); - connect( - ui->page_select_tree, &QTreeWidget::currentItemChanged, - this, &NewDialog::switch2page); + connect(ui->page_select_tree, &QTreeWidget::currentItemChanged, this, &NewDialog::switch2page); + connect(ui->pushButton_example, &QAbstractButton::clicked, this, &NewDialog::create_example); + connect(ui->pushButton_start_empty, &QAbstractButton::clicked, this, &NewDialog::create_empty); + connect(ui->pushButton_load, &QAbstractButton::clicked, this, &NewDialog::create); + connect(ui->pushButton_cancel, &QAbstractButton::clicked, this, &NewDialog::cancel); + connect(ui->pushButton_browse, &QAbstractButton::clicked, this, &NewDialog::browse_elf); + connect(ui->elf_file, &QLineEdit::textChanged, this, &NewDialog::elf_change); + connect(ui->preset_no_pipeline, &QAbstractButton::toggled, this, &NewDialog::set_preset); + connect(ui->preset_no_pipeline_cache, &QAbstractButton::toggled, this, &NewDialog::set_preset); + connect(ui->preset_pipelined_bare, &QAbstractButton::toggled, this, &NewDialog::set_preset); + connect(ui->preset_pipelined, &QAbstractButton::toggled, this, &NewDialog::set_preset); connect( - ui->pushButton_example, &QAbstractButton::clicked, this, - &NewDialog::create_example); - connect( - ui->pushButton_start_empty, &QAbstractButton::clicked, this, - &NewDialog::create_empty); - connect( - ui->pushButton_load, &QAbstractButton::clicked, this, - &NewDialog::create); - connect( - ui->pushButton_cancel, &QAbstractButton::clicked, this, - &NewDialog::cancel); - connect( - ui->pushButton_browse, &QAbstractButton::clicked, this, - &NewDialog::browse_elf); - connect( - ui->elf_file, &QLineEdit::textChanged, this, &NewDialog::elf_change); - connect( - ui->preset_no_pipeline, &QAbstractButton::toggled, this, - &NewDialog::set_preset); - connect( - ui->preset_no_pipeline_cache, &QAbstractButton::toggled, this, - &NewDialog::set_preset); - connect( - ui->preset_pipelined_bare, &QAbstractButton::toggled, this, - &NewDialog::set_preset); - connect( - ui->preset_pipelined, &QAbstractButton::toggled, this, - &NewDialog::set_preset); - connect( - ui->reset_at_compile, &QAbstractButton::clicked, this, - &NewDialog::reset_at_compile_change); + ui->reset_at_compile, &QAbstractButton::clicked, this, &NewDialog::reset_at_compile_change); + connect(ui->xlen_64bit, &QAbstractButton::clicked, this, &NewDialog::xlen_64bit_change); + connect(ui->isa_atomic, &QAbstractButton::clicked, this, &NewDialog::isa_atomic_change); + connect(ui->isa_multiply, &QAbstractButton::clicked, this, &NewDialog::isa_multiply_change); + connect(ui->pipelined, &QAbstractButton::clicked, this, &NewDialog::pipelined_change); + connect(ui->delay_slot, &QAbstractButton::clicked, this, &NewDialog::delay_slot_change); + connect(ui->hazard_unit, &QGroupBox::clicked, this, &NewDialog::hazard_unit_change); + connect(ui->hazard_stall, &QAbstractButton::clicked, this, &NewDialog::hazard_unit_change); connect( - ui->xlen_64bit, &QAbstractButton::clicked, this, - &NewDialog::xlen_64bit_change); - connect( - ui->isa_atomic, &QAbstractButton::clicked, this, - &NewDialog::isa_atomic_change); - connect( - ui->isa_multiply, &QAbstractButton::clicked, this, - &NewDialog::isa_multiply_change); - connect( - ui->pipelined, &QAbstractButton::clicked, this, - &NewDialog::pipelined_change); - connect( - ui->delay_slot, &QAbstractButton::clicked, this, - &NewDialog::delay_slot_change); - connect( - ui->hazard_unit, &QGroupBox::clicked, this, - &NewDialog::hazard_unit_change); - connect( - ui->hazard_stall, &QAbstractButton::clicked, this, - &NewDialog::hazard_unit_change); - connect( - ui->hazard_stall_forward, &QAbstractButton::clicked, this, - &NewDialog::hazard_unit_change); + ui->hazard_stall_forward, &QAbstractButton::clicked, this, &NewDialog::hazard_unit_change); connect( - ui->mem_protec_exec, &QAbstractButton::clicked, this, - &NewDialog::mem_protec_exec_change); + ui->mem_protec_exec, &QAbstractButton::clicked, this, &NewDialog::mem_protec_exec_change); connect( - ui->mem_protec_write, &QAbstractButton::clicked, this, - &NewDialog::mem_protec_write_change); + ui->mem_protec_write, &QAbstractButton::clicked, this, &NewDialog::mem_protec_write_change); connect( ui->mem_time_read, QOverload::of(&QSpinBox::valueChanged), this, &NewDialog::mem_time_read_change); @@ -113,8 +74,7 @@ NewDialog::NewDialog(QWidget *parent, QSettings *settings) : QDialog(parent) { ui->mem_time_write, QOverload::of(&QSpinBox::valueChanged), this, &NewDialog::mem_time_write_change); connect( - ui->mem_enable_burst, &QAbstractButton::clicked, this, - &NewDialog::mem_enable_burst_change); + ui->mem_enable_burst, &QAbstractButton::clicked, this, &NewDialog::mem_enable_burst_change); connect( ui->mem_time_burst, QOverload::of(&QSpinBox::valueChanged), this, &NewDialog::mem_time_burst_change); @@ -122,9 +82,7 @@ NewDialog::NewDialog(QWidget *parent, QSettings *settings) : QDialog(parent) { ui->mem_time_level2, QOverload::of(&QSpinBox::valueChanged), this, &NewDialog::mem_time_level2_change); - connect( - ui->osemu_enable, &QAbstractButton::clicked, this, - &NewDialog::osemu_enable_change); + connect(ui->osemu_enable, &QAbstractButton::clicked, this, &NewDialog::osemu_enable_change); connect( ui->osemu_known_syscall_stop, &QAbstractButton::clicked, this, &NewDialog::osemu_known_syscall_stop_change); @@ -158,7 +116,8 @@ NewDialog::NewDialog(QWidget *parent, QSettings *settings) : QDialog(parent) { connect( ui->slider_bp_bht_bhr_bits, &QAbstractSlider::valueChanged, this, &NewDialog::bp_bht_bhr_bits_change); - connect(ui->slider_bp_bht_addr_bits, &QAbstractSlider::valueChanged, this, + connect( + ui->slider_bp_bht_addr_bits, &QAbstractSlider::valueChanged, this, &NewDialog::bp_bht_addr_bits_change); cache_handler_d = new NewDialogCacheHandler(this, ui_cache_d.data()); @@ -177,8 +136,8 @@ NewDialog::NewDialog(QWidget *parent, QSettings *settings) : QDialog(parent) { void NewDialog::switch2page(QTreeWidgetItem *current, QTreeWidgetItem *previous) { (void)previous; - QWidget *page = ui->config_pages->findChild(current->text(1), - Qt::FindDirectChildrenOnly); + QWidget *page + = ui->config_pages->findChild(current->text(1), Qt::FindDirectChildrenOnly); if (page != nullptr) { ui->config_pages->setCurrentWidget(page); ui->config_page_title->setText(current->text(0)); @@ -196,9 +155,7 @@ void NewDialog::closeEvent(QCloseEvent *) { load_settings(); // Reset from settings // Close the main window if not already configured auto *prnt = (MainWindow *)parent(); - if (!prnt->configured()) { - prnt->close(); - } + if (!prnt->configured()) { prnt->close(); } } void NewDialog::cancel() { @@ -285,7 +242,7 @@ void NewDialog::xlen_64bit_change(bool val) { } void NewDialog::isa_atomic_change(bool val) { - auto isa_mask = machine::ConfigIsaWord::byChar('A'); + auto isa_mask = machine::ConfigIsaWord::byChar('A'); if (val) config->modify_isa_word(isa_mask, isa_mask); else @@ -294,7 +251,7 @@ void NewDialog::isa_atomic_change(bool val) { } void NewDialog::isa_multiply_change(bool val) { - auto isa_mask = machine::ConfigIsaWord::byChar('M'); + auto isa_mask = machine::ConfigIsaWord::byChar('M'); if (val) config->modify_isa_word(isa_mask, isa_mask); else @@ -316,9 +273,8 @@ void NewDialog::delay_slot_change(bool val) { void NewDialog::hazard_unit_change() { if (ui->hazard_unit->isChecked()) { config->set_hazard_unit( - ui->hazard_stall->isChecked() - ? machine::MachineConfig::HU_STALL - : machine::MachineConfig::HU_STALL_FORWARD); + ui->hazard_stall->isChecked() ? machine::MachineConfig::HU_STALL + : machine::MachineConfig::HU_STALL_FORWARD); } else { config->set_hazard_unit(machine::MachineConfig::HU_NONE); } @@ -490,13 +446,11 @@ void NewDialog::bp_type_change() { } } break; - default: - break; + default: break; } bp_toggle_widgets(); - if (need_switch2custom) - switch2custom(); + if (need_switch2custom) switch2custom(); } void NewDialog::bp_enabled_change(bool v) { @@ -660,15 +614,9 @@ void NewDialog::load_settings() { auto p = (enum machine::ConfigPresets)(preset - 1); config->preset(p); switch (p) { - case machine::CP_SINGLE: - ui->preset_no_pipeline->setChecked(true); - break; - case machine::CP_SINGLE_CACHE: - ui->preset_no_pipeline_cache->setChecked(true); - break; - case machine::CP_PIPE_NO_HAZARD: - ui->preset_pipelined_bare->setChecked(true); - break; + case machine::CP_SINGLE: ui->preset_no_pipeline->setChecked(true); break; + case machine::CP_SINGLE_CACHE: ui->preset_no_pipeline_cache->setChecked(true); break; + case machine::CP_PIPE_NO_HAZARD: ui->preset_pipelined_bare->setChecked(true); break; case machine::CP_PIPE: ui->preset_pipelined->setChecked(true); break; } } else { @@ -689,14 +637,11 @@ void NewDialog::store_settings() { } } -NewDialogCacheHandler::NewDialogCacheHandler(NewDialog *nd, - Ui::NewDialogCache *cui) : Super(nd) { +NewDialogCacheHandler::NewDialogCacheHandler(NewDialog *nd, Ui::NewDialogCache *cui) : Super(nd) { this->nd = nd; this->ui = cui; this->config = nullptr; - connect( - ui->enabled, &QGroupBox::clicked, this, - &NewDialogCacheHandler::enabled); + connect(ui->enabled, &QGroupBox::clicked, this, &NewDialogCacheHandler::enabled); connect( ui->number_of_sets, &QAbstractSpinBox::editingFinished, this, &NewDialogCacheHandler::numsets); @@ -748,8 +693,7 @@ void NewDialogCacheHandler::degreeassociativity() { } void NewDialogCacheHandler::replacement(int val) { - config->set_replacement_policy( - (enum machine::CacheConfig::ReplacementPolicy)val); + config->set_replacement_policy((enum machine::CacheConfig::ReplacementPolicy)val); nd->switch2custom(); } diff --git a/src/gui/extprocess.cpp b/src/gui/extprocess.cpp index 7a578a26..63b06141 100644 --- a/src/gui/extprocess.cpp +++ b/src/gui/extprocess.cpp @@ -7,9 +7,7 @@ using namespace std; ExtProcess::ExtProcess(QObject *parent) : Super(parent) { setProcessChannelMode(QProcess::MergedChannels); - connect( - this, &QProcess::readyReadStandardOutput, this, - &ExtProcess::process_output); + connect(this, &QProcess::readyReadStandardOutput, this, &ExtProcess::process_output); connect( this, QOverload::of(&QProcess::finished), this, &ExtProcess::report_finished); @@ -20,18 +18,15 @@ void ExtProcess::report_finished(int exitCode, QProcess::ExitStatus exitStatus) if ((exitStatus != QProcess::NormalExit) || (exitCode != 0)) { report_message( messagetype::MSG_FINISH, "", 0, 0, - program() + ": failed - exit code " + QString::number(exitCode), - ""); + program() + ": failed - exit code " + QString::number(exitCode), ""); } else { - report_message( - messagetype::MSG_FINISH, "", 0, 0, program() + ": finished", ""); + report_message(messagetype::MSG_FINISH, "", 0, 0, program() + ": finished", ""); } deleteLater(); } void ExtProcess::report_started() { - report_message( - messagetype::MSG_START, "", 0, 0, program() + ": started", ""); + report_message(messagetype::MSG_START, "", 0, 0, program() + ": started", ""); } void ExtProcess::process_output() { @@ -43,10 +38,7 @@ void ExtProcess::process_output() { while (canReadLine()) { QString line = QString::fromLocal8Bit(readLine()); while (line.count() > 0) { - if (line.at(line.count() - 1) != '\n' - && line.at(line.count() - 1) != '\r') { - break; - } + if (line.at(line.count() - 1) != '\n' && line.at(line.count() - 1) != '\r') { break; } line.truncate(line.count() - 1); } @@ -71,12 +63,8 @@ void ExtProcess::process_output() { line = line.mid(pos + 1); } - if (line.startsWith(' ')) { - line = line.mid(1); - } - if (line.startsWith('\t')) { - line = line.mid(1); - } + if (line.startsWith(' ')) { line = line.mid(1); } + if (line.startsWith('\t')) { line = line.mid(1); } if (line.startsWith("error:", Qt::CaseInsensitive)) { type = messagetype::MSG_ERROR; } else if (line.startsWith("warning:", Qt::CaseInsensitive)) { diff --git a/src/gui/fontsize.cpp b/src/gui/fontsize.cpp index 5d4eda5a..808e92ac 100644 --- a/src/gui/fontsize.cpp +++ b/src/gui/fontsize.cpp @@ -1,9 +1,10 @@ #include "fontsize.h" +#include "common/logging.h" + #include #include #include -#include "common/logging.h" LOG_CATEGORY("gui.font"); diff --git a/src/gui/graphicsview.cpp b/src/gui/graphicsview.cpp index 4df78bd0..ab1ed103 100644 --- a/src/gui/graphicsview.cpp +++ b/src/gui/graphicsview.cpp @@ -13,9 +13,7 @@ void GraphicsView::setScene(QGraphicsScene *scene) { void GraphicsView::resizeEvent(QResizeEvent *event) { Super::resizeEvent(event); - if ((width() != prev_height) || (height() != prev_width)) { - update_scale(); - } + if ((width() != prev_height) || (height() != prev_width)) { update_scale(); } } void GraphicsView::update_scale() { @@ -67,9 +65,7 @@ void GraphicsView::keyPressEvent(QKeyEvent *event) { if (event->matches(QKeySequence::ZoomIn) || (event->key() == Qt::Key_Equal) || (event->key() == Qt::Key_Plus)) { scale(factor, factor); - } else if ( - event->matches(QKeySequence::ZoomOut) - || (event->key() == Qt::Key_Minus)) { + } else if (event->matches(QKeySequence::ZoomOut) || (event->key() == Qt::Key_Minus)) { scale(1 / factor, 1 / factor); } else { Super::keyPressEvent(event); diff --git a/src/gui/hinttabledelegate.cpp b/src/gui/hinttabledelegate.cpp index 97758e5c..8ef2e43c 100644 --- a/src/gui/hinttabledelegate.cpp +++ b/src/gui/hinttabledelegate.cpp @@ -14,6 +14,5 @@ QSize HintTableDelegate::sizeHintForText( opt.features |= QStyleOptionViewItem::HasDisplay; opt.text = str; - return style->sizeFromContents( - QStyle::CT_ItemViewItem, &opt, QSize(), widget); + return style->sizeFromContents(QStyle::CT_ItemViewItem, &opt, QSize(), widget); } diff --git a/src/gui/qhtml5file_html5.cpp b/src/gui/qhtml5file_html5.cpp index 002ecbdf..0bef261c 100644 --- a/src/gui/qhtml5file_html5.cpp +++ b/src/gui/qhtml5file_html5.cpp @@ -55,21 +55,18 @@ std::function g_qtFileDataReadyCallback; extern "C" EMSCRIPTEN_KEEPALIVE void qt_callFileDataReady(char *content, size_t contentSize, const char *fileName) { - if (g_qtFileDataReadyCallback == nullptr) { - return; - } + if (g_qtFileDataReadyCallback == nullptr) { return; } g_qtFileDataReadyCallback(content, contentSize, fileName); g_qtFileDataReadyCallback = nullptr; } namespace { -void loadFile( - const char *accept, - std::function fileDataReady) { +void loadFile(const char *accept, std::function fileDataReady) { if (::g_qtFileDataReadyCallback) { - puts("Warning: Concurrent loadFile() calls are not supported. " - "Cancelling earlier call"); + puts( + "Warning: Concurrent loadFile() calls are not supported. " + "Cancelling earlier call"); } // Call qt_callFileDataReady to make sure the emscripten linker does not @@ -115,8 +112,8 @@ void loadFile( // the C++ side. const heapPointer = _malloc(contentSize); - const heapBytes = new Uint8Array( - Module.HEAPU8.buffer, heapPointer, contentSize); + const heapBytes + = new Uint8Array(Module.HEAPU8.buffer, heapPointer, contentSize); heapBytes.set(contentArray); // Null out the first data copy to enable GC @@ -125,8 +122,7 @@ void loadFile( // Call the C++ file data ready callback ccall( - "qt_callFileDataReady", null, - [ "number", "number", "string" ], + "qt_callFileDataReady", null, [ "number", "number", "string" ], [ heapPointer, contentSize, name ]); }; reader.readAsArrayBuffer(file); @@ -143,10 +139,7 @@ void loadFile( accept); } -void saveFile( - const char *contentPointer, - size_t contentLength, - const char *fileNameHint) { +void saveFile(const char *contentPointer, size_t contentLength, const char *fileNameHint) { EM_ASM_( { // Make the file contents and file name hint accessible to @@ -155,8 +148,8 @@ void saveFile( const contentPointer = $0; const contentLength = $1; const fileNameHint = UTF8ToString($2); - const fileContent = Module.HEAPU8.subarray( - contentPointer, contentPointer + contentLength); + const fileContent + = Module.HEAPU8.subarray(contentPointer, contentPointer + contentLength); // Create a hidden download link and click it programatically const fileblob = new Blob([fileContent], { @@ -193,19 +186,17 @@ void saveFile( void QHtml5File::load( const QString &accept, std::function fileDataReady) { - loadFile( - accept.toUtf8().constData(), - [=](char *content, size_t size, const char *fileName) { - // Copy file data into QByteArray and free buffer that was allocated - // on the JavaScript side. We could have used - // QByteArray::fromRawData() to avoid the copy here, but that would - // make memory management awkward. - QByteArray qtFileContent(content, size); - free(content); - - // Call user-supplied data ready callback - fileDataReady(qtFileContent, QString::fromUtf8(fileName)); - }); + loadFile(accept.toUtf8().constData(), [=](char *content, size_t size, const char *fileName) { + // Copy file data into QByteArray and free buffer that was allocated + // on the JavaScript side. We could have used + // QByteArray::fromRawData() to avoid the copy here, but that would + // make memory management awkward. + QByteArray qtFileContent(content, size); + free(content); + + // Call user-supplied data ready callback + fileDataReady(qtFileContent, QString::fromUtf8(fileName)); + }); } /*! @@ -220,6 +211,5 @@ void QHtml5File::load( */ void QHtml5File::save(const QByteArray &content, const QString &fileNameHint) { // Convert to C types and save - saveFile( - content.constData(), content.size(), fileNameHint.toUtf8().constData()); + saveFile(content.constData(), content.size(), fileNameHint.toUtf8().constData()); } diff --git a/src/gui/statictable.cpp b/src/gui/statictable.cpp index d4d87f95..6dce3af7 100644 --- a/src/gui/statictable.cpp +++ b/src/gui/statictable.cpp @@ -210,7 +210,7 @@ int StaticTableLayout::layout_size(int &row_h, QList> &row_w, int cou w += bhspace - shspace; // subtract latest small spacing and add big // spacing } - w -= bhspace; // subtract latest big spacing + w -= bhspace; // subtract latest big spacing return w; } diff --git a/src/gui/statictable.h b/src/gui/statictable.h index 1bfc823f..f78ec14d 100644 --- a/src/gui/statictable.h +++ b/src/gui/statictable.h @@ -33,7 +33,7 @@ class StaticTableLayout : public QLayout { void addItem(QLayoutItem *item) override; QLayoutItem *itemAt(int index) const override; QLayoutItem *takeAt(int index) override; - int count() const override; // This returns number of item blocks + int count() const override; // This returns number of item blocks void addRow(const QList &); // This adds a row of widgets void insertRow(const QList &, int i); // Insert row to given position while shifting diff --git a/src/gui/textsignalaction.cpp b/src/gui/textsignalaction.cpp index d4632c89..54383f46 100644 --- a/src/gui/textsignalaction.cpp +++ b/src/gui/textsignalaction.cpp @@ -4,39 +4,25 @@ #include TextSignalAction::TextSignalAction(QObject *parent) : Super(parent) { - connect( - this, &TextSignalAction::triggered, this, - &TextSignalAction::process_triggered); + connect(this, &TextSignalAction::triggered, this, &TextSignalAction::process_triggered); } TextSignalAction::TextSignalAction(const QString &text, QObject *parent) : Super(text, parent) , signal_text(text) { - connect( - this, &TextSignalAction::triggered, this, - &TextSignalAction::process_triggered); + connect(this, &TextSignalAction::triggered, this, &TextSignalAction::process_triggered); } -TextSignalAction::TextSignalAction( - const QString &text, - QString signal_text, - QObject *parent) +TextSignalAction::TextSignalAction(const QString &text, QString signal_text, QObject *parent) : Super(text, parent) , signal_text(std::move(signal_text)) { - connect( - this, &TextSignalAction::triggered, this, - &TextSignalAction::process_triggered); + connect(this, &TextSignalAction::triggered, this, &TextSignalAction::process_triggered); } -TextSignalAction::TextSignalAction( - const QIcon &icon, - const QString &text, - QObject *parent) +TextSignalAction::TextSignalAction(const QIcon &icon, const QString &text, QObject *parent) : Super(icon, text, parent) , signal_text(text) { - connect( - this, &TextSignalAction::triggered, this, - &TextSignalAction::process_triggered); + connect(this, &TextSignalAction::triggered, this, &TextSignalAction::process_triggered); } TextSignalAction::TextSignalAction( @@ -46,9 +32,7 @@ TextSignalAction::TextSignalAction( QObject *parent) : Super(icon, text, parent) , signal_text(std::move(signal_text)) { - connect( - this, &TextSignalAction::triggered, this, - &TextSignalAction::process_triggered); + connect(this, &TextSignalAction::triggered, this, &TextSignalAction::process_triggered); } void TextSignalAction::process_triggered(bool checked) { diff --git a/src/gui/textsignalaction.h b/src/gui/textsignalaction.h index a5391e7d..6ef8b53e 100644 --- a/src/gui/textsignalaction.h +++ b/src/gui/textsignalaction.h @@ -12,14 +12,8 @@ class TextSignalAction : public QAction { public: explicit TextSignalAction(QObject *parent = nullptr); explicit TextSignalAction(const QString &text, QObject *parent = nullptr); - TextSignalAction( - const QString &text, - QString signal_text, - QObject *parent = nullptr); - TextSignalAction( - const QIcon &icon, - const QString &text, - QObject *parent = nullptr); + TextSignalAction(const QString &text, QString signal_text, QObject *parent = nullptr); + TextSignalAction(const QIcon &icon, const QString &text, QObject *parent = nullptr); TextSignalAction( const QIcon &icon, const QString &text, diff --git a/src/gui/ui/hexlineedit.cpp b/src/gui/ui/hexlineedit.cpp index 01f7efff..ac0a4a95 100644 --- a/src/gui/ui/hexlineedit.cpp +++ b/src/gui/ui/hexlineedit.cpp @@ -1,10 +1,6 @@ #include "hexlineedit.h" -HexLineEdit::HexLineEdit( - QWidget *parent, - int digits, - int base, - const QString &prefix) +HexLineEdit::HexLineEdit(QWidget *parent, int digits, int base, const QString &prefix) : Super(parent) { this->base = base; this->digits = digits; @@ -33,17 +29,13 @@ HexLineEdit::HexLineEdit( dmask = 'h'; break; } - if (digits > 1) { - t.fill(dmask, digits - 1); - } + if (digits > 1) { t.fill(dmask, digits - 1); } mask += t; setInputMask(mask); - connect( - this, &QLineEdit::editingFinished, this, - &HexLineEdit::on_edit_finished); + connect(this, &QLineEdit::editingFinished, this, &HexLineEdit::on_edit_finished); set_value(0); } @@ -52,9 +44,7 @@ void HexLineEdit::set_value(uint32_t value) { QString s, t = ""; last_set = value; s = QString::number(value, base); - if (s.count() < digits) { - t.fill('0', digits - s.count()); - } + if (s.count() < digits) { t.fill('0', digits - s.count()); } setText(prefix + t + s); } diff --git a/src/gui/windows/cache/cachedock.cpp b/src/gui/windows/cache/cachedock.cpp index 12d9f541..15cf50bb 100644 --- a/src/gui/windows/cache/cachedock.cpp +++ b/src/gui/windows/cache/cachedock.cpp @@ -1,7 +1,6 @@ #include "cachedock.h" -CacheDock::CacheDock(QWidget *parent, const QString &type) - : QDockWidget(parent) { +CacheDock::CacheDock(QWidget *parent, const QString &type) : QDockWidget(parent) { top_widget = new QWidget(this); setWidget(top_widget); layout_box = new QVBoxLayout(top_widget); @@ -106,10 +105,7 @@ void CacheDock::memory_writes_update(unsigned val) { memory_writes = val; } -void CacheDock::statistics_update( - unsigned stalled_cycles, - double speed_improv, - double hit_rate) { +void CacheDock::statistics_update(unsigned stalled_cycles, double speed_improv, double hit_rate) { this->stalled = stalled_cycles; this->hit = hit_rate; this->speed_improv = speed_improv; diff --git a/src/gui/windows/cache/cachedock.h b/src/gui/windows/cache/cachedock.h index b50945d1..d1d8aed7 100644 --- a/src/gui/windows/cache/cachedock.h +++ b/src/gui/windows/cache/cachedock.h @@ -23,10 +23,7 @@ private slots: void miss_update(unsigned); void memory_reads_update(unsigned val); void memory_writes_update(unsigned val); - void statistics_update( - unsigned stalled_cycles, - double speed_improv, - double hit_rate); + void statistics_update(unsigned stalled_cycles, double speed_improv, double hit_rate); private: QVBoxLayout *layout_box; diff --git a/src/gui/windows/cache/cacheview.cpp b/src/gui/windows/cache/cacheview.cpp index 46b5ea76..69315873 100644 --- a/src/gui/windows/cache/cacheview.cpp +++ b/src/gui/windows/cache/cacheview.cpp @@ -7,10 +7,10 @@ ////////////////////// #define ROW_HEIGHT 14 -#define VD_WIDTH 10 +#define VD_WIDTH 10 #define DATA_WIDTH 72 -#define PENW 1 -#define LETTERW 7 +#define PENW 1 +#define LETTERW 7 ////////////////////// #include "common/endian.h" diff --git a/src/gui/windows/cache/cacheview.h b/src/gui/windows/cache/cacheview.h index 782f7c77..ca278f5e 100644 --- a/src/gui/windows/cache/cacheview.h +++ b/src/gui/windows/cache/cacheview.h @@ -16,10 +16,7 @@ class CacheAddressBlock : public QGraphicsObject { [[nodiscard]] QRectF boundingRect() const override; - void paint( - QPainter *painter, - const QStyleOptionGraphicsItem *option, - QWidget *widget) override; + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; private slots: void cache_update( @@ -47,10 +44,7 @@ class CacheViewBlock : public QGraphicsObject { [[nodiscard]] QRectF boundingRect() const override; - void paint( - QPainter *painter, - const QStyleOptionGraphicsItem *option, - QWidget *widget) override; + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; private slots: virtual void cache_update( diff --git a/src/gui/windows/coreview/scene.cpp b/src/gui/windows/coreview/scene.cpp index e8fd432e..37dd1db6 100644 --- a/src/gui/windows/coreview/scene.cpp +++ b/src/gui/windows/coreview/scene.cpp @@ -87,7 +87,8 @@ CoreViewScene::CoreViewScene(machine::Machine *machine, const QString &core_svg_ core_state); } else if (component_name == QStringLiteral("mux2")) { const QString &source_name = component.getAttrValueOr("data-source"); - // Draw.io does not allow tagging the paths, to I use this style identification hack. + // Draw.io does not allow tagging the paths, to I use this style identification + // hack. auto conn_trees = component.findAll("stroke-linecap", "round"); if (conn_trees.size() != 2) { WARN( @@ -110,7 +111,8 @@ CoreViewScene::CoreViewScene(machine::Machine *machine, const QString &core_svg_ } } else if (component_name == QStringLiteral("mux3")) { const QString &source_name = component.getAttrValueOr("data-source"); - // Draw.io does not allow tagging the paths, to I use this style identification hack. + // Draw.io does not allow tagging the paths, to I use this style identification + // hack. auto conn_trees = component.findAll("stroke-linecap", "round"); if (conn_trees.size() != 3) { WARN( @@ -245,7 +247,7 @@ CoreViewSceneSimple::CoreViewSceneSimple(machine::Machine *machine) CoreViewScenePipelined::CoreViewScenePipelined(machine::Machine *machine) : CoreViewScene( - machine, - (machine->config().hazard_unit() == machine::MachineConfig::HU_STALL_FORWARD) - ? "forwarding" - : "pipeline") {} + machine, + (machine->config().hazard_unit() == machine::MachineConfig::HU_STALL_FORWARD) + ? "forwarding" + : "pipeline") {} diff --git a/src/gui/windows/coreview/scene.h b/src/gui/windows/coreview/scene.h index 54a0bc70..64b7312b 100644 --- a/src/gui/windows/coreview/scene.h +++ b/src/gui/windows/coreview/scene.h @@ -102,7 +102,7 @@ public slots: Box data_cache; /** Reference to current PC value to be used to focus PC in program memory on lick */ - const machine::Address& program_counter_value; + const machine::Address &program_counter_value; }; class CoreViewSceneSimple : public CoreViewScene { diff --git a/src/gui/windows/editor/editordock.cpp b/src/gui/windows/editor/editordock.cpp index 4631abfb..a9903921 100644 --- a/src/gui/windows/editor/editordock.cpp +++ b/src/gui/windows/editor/editordock.cpp @@ -68,8 +68,7 @@ EditorTab *EditorDock::open_file(const QString &filename, bool save_as_required) if (tab->get_editor()->loadFile(filename)) { addTab(tab, tab->title()); setCurrentWidget(tab); - if (save_as_required) - tab->get_editor()->setSaveAsRequired(save_as_required); + if (save_as_required) tab->get_editor()->setSaveAsRequired(save_as_required); return tab; } else { delete tab; diff --git a/src/gui/windows/editor/editortab.cpp b/src/gui/windows/editor/editortab.cpp index 9a4f0348..02621e29 100644 --- a/src/gui/windows/editor/editortab.cpp +++ b/src/gui/windows/editor/editortab.cpp @@ -47,7 +47,8 @@ void EditorTab::resizeEvent(QResizeEvent *event) { void EditorTab::elide_file_name() { auto filename = editor->filename().isEmpty() ? "Unknown" : editor->filename(); QFontMetrics metrics(status_bar_path->font()); - int width = status_bar_layout->geometry().width() - status_bar_location->geometry().width() - 10; + int width + = status_bar_layout->geometry().width() - status_bar_location->geometry().width() - 10; QString clippedText = metrics.elidedText(filename, Qt::ElideMiddle, width); status_bar_path->setText(clippedText); } diff --git a/src/gui/windows/editor/highlighterc.cpp b/src/gui/windows/editor/highlighterc.cpp index 63d2cf3a..f216da6d 100644 --- a/src/gui/windows/editor/highlighterc.cpp +++ b/src/gui/windows/editor/highlighterc.cpp @@ -56,23 +56,22 @@ HighlighterC::HighlighterC(QTextDocument *parent) : QSyntaxHighlighter(parent) { keywordFormat.setForeground(Qt::darkBlue); keywordFormat.setFontWeight(QFont::Bold); - const QString keywordPatterns[] = { - QStringLiteral("\\bchar\\b"), QStringLiteral("\\bclass\\b"), - QStringLiteral("\\bconst\\b"), QStringLiteral("\\bdouble\\b"), - QStringLiteral("\\benum\\b"), QStringLiteral("\\bexplicit\\b"), - QStringLiteral("\\bfriend\\b"), QStringLiteral("\\binline\\b"), - QStringLiteral("\\bint\\b"), QStringLiteral("\\blong\\b"), - QStringLiteral("\\bnamespace\\b"), QStringLiteral("\\boperator\\b"), - QStringLiteral("\\bprivate\\b"), QStringLiteral("\\bprotected\\b"), - QStringLiteral("\\bpublic\\b"), QStringLiteral("\\bshort\\b"), - QStringLiteral("\\bsignals\\b"), QStringLiteral("\\bsigned\\b"), - QStringLiteral("\\bslots\\b"), QStringLiteral("\\bstatic\\b"), - QStringLiteral("\\bstruct\\b"), QStringLiteral("\\btemplate\\b"), - QStringLiteral("\\btypedef\\b"), QStringLiteral("\\btypename\\b"), - QStringLiteral("\\bunion\\b"), QStringLiteral("\\bunsigned\\b"), - QStringLiteral("\\bvirtual\\b"), QStringLiteral("\\bvoid\\b"), - QStringLiteral("\\bvolatile\\b"), QStringLiteral("\\bbool\\b") - }; + const QString keywordPatterns[] + = { QStringLiteral("\\bchar\\b"), QStringLiteral("\\bclass\\b"), + QStringLiteral("\\bconst\\b"), QStringLiteral("\\bdouble\\b"), + QStringLiteral("\\benum\\b"), QStringLiteral("\\bexplicit\\b"), + QStringLiteral("\\bfriend\\b"), QStringLiteral("\\binline\\b"), + QStringLiteral("\\bint\\b"), QStringLiteral("\\blong\\b"), + QStringLiteral("\\bnamespace\\b"), QStringLiteral("\\boperator\\b"), + QStringLiteral("\\bprivate\\b"), QStringLiteral("\\bprotected\\b"), + QStringLiteral("\\bpublic\\b"), QStringLiteral("\\bshort\\b"), + QStringLiteral("\\bsignals\\b"), QStringLiteral("\\bsigned\\b"), + QStringLiteral("\\bslots\\b"), QStringLiteral("\\bstatic\\b"), + QStringLiteral("\\bstruct\\b"), QStringLiteral("\\btemplate\\b"), + QStringLiteral("\\btypedef\\b"), QStringLiteral("\\btypename\\b"), + QStringLiteral("\\bunion\\b"), QStringLiteral("\\bunsigned\\b"), + QStringLiteral("\\bvirtual\\b"), QStringLiteral("\\bvoid\\b"), + QStringLiteral("\\bvolatile\\b"), QStringLiteral("\\bbool\\b") }; for (const QString &pattern : keywordPatterns) { rule.pattern = QRegularExpression(pattern); rule.format = keywordFormat; @@ -108,8 +107,7 @@ HighlighterC::HighlighterC(QTextDocument *parent) : QSyntaxHighlighter(parent) { //! [5] functionFormat.setFontItalic(true); functionFormat.setForeground(Qt::blue); - rule.pattern - = QRegularExpression(QStringLiteral("\\b[A-Za-z0-9_]+(?=\\()")); + rule.pattern = QRegularExpression(QStringLiteral("\\b[A-Za-z0-9_]+(?=\\()")); rule.format = functionFormat; highlightingRules.append(rule); //! [5] @@ -128,12 +126,10 @@ void HighlighterC::highlightBlock(const QString &text) { for (const HighlightingRule &rule : qAsConst(highlightingRules)) #endif { - QRegularExpressionMatchIterator matchIterator - = rule.pattern.globalMatch(text); + QRegularExpressionMatchIterator matchIterator = rule.pattern.globalMatch(text); while (matchIterator.hasNext()) { QRegularExpressionMatch match = matchIterator.next(); - setFormat( - match.capturedStart(), match.capturedLength(), rule.format); + setFormat(match.capturedStart(), match.capturedLength(), rule.format); } } //! [7] //! [8] @@ -142,15 +138,12 @@ void HighlighterC::highlightBlock(const QString &text) { //! [9] int startIndex = 0; - if (previousBlockState() != 1) { - startIndex = text.indexOf(commentStartExpression); - } + if (previousBlockState() != 1) { startIndex = text.indexOf(commentStartExpression); } //! [9] //! [10] while (startIndex >= 0) { //! [10] //! [11] - QRegularExpressionMatch match - = commentEndExpression.match(text, startIndex); + QRegularExpressionMatch match = commentEndExpression.match(text, startIndex); int endIndex = match.capturedStart(); int commentLength = 0; if (endIndex == -1) { @@ -160,8 +153,7 @@ void HighlighterC::highlightBlock(const QString &text) { commentLength = endIndex - startIndex + match.capturedLength(); } setFormat(startIndex, commentLength, multiLineCommentFormat); - startIndex - = text.indexOf(commentStartExpression, startIndex + commentLength); + startIndex = text.indexOf(commentStartExpression, startIndex + commentLength); } } //! [11] diff --git a/src/gui/windows/editor/srceditor.h b/src/gui/windows/editor/srceditor.h index 118c80d3..167526c0 100644 --- a/src/gui/windows/editor/srceditor.h +++ b/src/gui/windows/editor/srceditor.h @@ -5,10 +5,10 @@ #include "linenumberarea.h" #include "machine/machine.h" +#include #include #include #include -#include #include #include diff --git a/src/gui/windows/lcd/lcddisplaydock.cpp b/src/gui/windows/lcd/lcddisplaydock.cpp index a9f3504f..1a9c44f0 100644 --- a/src/gui/windows/lcd/lcddisplaydock.cpp +++ b/src/gui/windows/lcd/lcddisplaydock.cpp @@ -5,8 +5,7 @@ #include #include -LcdDisplayDock::LcdDisplayDock(QWidget *parent, QSettings *settings) - : Super(parent) { +LcdDisplayDock::LcdDisplayDock(QWidget *parent, QSettings *settings) : Super(parent) { (void)settings; lcd_display_widget.reset(new LcdDisplayView(this)); auto *fill_widget = new QWidget(this); diff --git a/src/gui/windows/memory/memorydock.cpp b/src/gui/windows/memory/memorydock.cpp index 07fd4d69..2e22d56f 100644 --- a/src/gui/windows/memory/memorydock.cpp +++ b/src/gui/windows/memory/memorydock.cpp @@ -47,14 +47,13 @@ MemoryDock::MemoryDock(QWidget *parent, QSettings *settings) : Super(parent) { setWidget(content); + connect(this, &MemoryDock::machine_setup, memory_model, &MemoryModel::setup); connect( - this, &MemoryDock::machine_setup, memory_model, &MemoryModel::setup); + cell_size, QOverload::of(&QComboBox::currentIndexChanged), memory_content, + &MemoryTableView::set_cell_size); connect( - cell_size, QOverload::of(&QComboBox::currentIndexChanged), - memory_content, &MemoryTableView::set_cell_size); - connect( - cached_access, QOverload::of(&QComboBox::currentIndexChanged), - memory_model, &MemoryModel::cached_access); + cached_access, QOverload::of(&QComboBox::currentIndexChanged), memory_model, + &MemoryModel::cached_access); connect( go_edit, &HexLineEdit::value_edit_finished, memory_content, [memory_content](uint32_t value) { @@ -62,12 +61,8 @@ MemoryDock::MemoryDock(QWidget *parent, QSettings *settings) : Super(parent) { }); connect( memory_content, &MemoryTableView::address_changed, go_edit, - [go_edit](machine::Address addr) { - go_edit->set_value(addr.get_raw()); - }); - connect( - this, &MemoryDock::focus_addr, memory_content, - &MemoryTableView::focus_address); + [go_edit](machine::Address addr) { go_edit->set_value(addr.get_raw()); }); + connect(this, &MemoryDock::focus_addr, memory_content, &MemoryTableView::focus_address); connect( memory_model, &MemoryModel::setup_done, memory_content, &MemoryTableView::recompute_columns); diff --git a/src/gui/windows/memory/memorymodel.h b/src/gui/windows/memory/memorymodel.h index 331aaeb7..7a814498 100644 --- a/src/gui/windows/memory/memorymodel.h +++ b/src/gui/windows/memory/memorymodel.h @@ -21,29 +21,21 @@ class MemoryModel : public QAbstractTableModel { explicit MemoryModel(QObject *parent); [[nodiscard]] int rowCount(const QModelIndex &parent = QModelIndex()) const override; [[nodiscard]] int columnCount(const QModelIndex &parent = QModelIndex()) const override; - [[nodiscard]] QVariant headerData(int section, Qt::Orientation orientation, int role) - const override; [[nodiscard]] QVariant - data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + headerData(int section, Qt::Orientation orientation, int role) const override; + [[nodiscard]] QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; [[nodiscard]] Qt::ItemFlags flags(const QModelIndex &index) const override; - bool - setData(const QModelIndex &index, const QVariant &value, int role) override; + bool setData(const QModelIndex &index, const QVariant &value, int role) override; bool adjustRowAndOffset(int &row, machine::Address address); void update_all(); void setCellsPerRow(unsigned int cells); - [[nodiscard]] inline unsigned int cellsPerRow() const { - return cells_per_row; - } + [[nodiscard]] inline unsigned int cellsPerRow() const { return cells_per_row; } - [[nodiscard]] inline const QFont *getFont() const { - return &data_font; - } + [[nodiscard]] inline const QFont *getFont() const { return &data_font; } - [[nodiscard]] inline machine::Address getIndex0Offset() const { - return index0_offset; - } + [[nodiscard]] inline machine::Address getIndex0Offset() const { return index0_offset; } [[nodiscard]] inline unsigned int cellSizeBytes() const { switch (cell_size) { diff --git a/src/gui/windows/messages/messagesdock.cpp b/src/gui/windows/messages/messagesdock.cpp index 725f1a18..f7c0ef72 100644 --- a/src/gui/windows/messages/messagesdock.cpp +++ b/src/gui/windows/messages/messagesdock.cpp @@ -11,8 +11,7 @@ #include #include -MessagesDock::MessagesDock(QWidget *parent, QSettings *settings) - : Super(parent) { +MessagesDock::MessagesDock(QWidget *parent, QSettings *settings) : Super(parent) { setObjectName("Messages"); setWindowTitle("Messages"); @@ -31,18 +30,13 @@ MessagesDock::MessagesDock(QWidget *parent, QSettings *settings) setWidget(content); + connect(this, &MessagesDock::report_message, messages_model, &MessagesModel::insert_line); connect( - this, &MessagesDock::report_message, messages_model, - &MessagesModel::insert_line); + this, &MessagesDock::pass_clear_messages, messages_model, &MessagesModel::clear_messages); connect( - this, &MessagesDock::pass_clear_messages, messages_model, - &MessagesModel::clear_messages); + messages_content, &QAbstractItemView::activated, messages_model, &MessagesModel::activated); connect( - messages_content, &QAbstractItemView::activated, messages_model, - &MessagesModel::activated); - connect( - messages_model, &MessagesModel::message_selected, this, - &MessagesDock::message_selected); + messages_model, &MessagesModel::message_selected, this, &MessagesDock::message_selected); } void MessagesDock::insert_line( @@ -52,8 +46,7 @@ void MessagesDock::insert_line( int column, QString text, QString hint) { - report_message( - type, std::move(file), line, column, std::move(text), std::move(hint)); + report_message(type, std::move(file), line, column, std::move(text), std::move(hint)); } void MessagesDock::clear_messages() { diff --git a/src/gui/windows/messages/messagesmodel.cpp b/src/gui/windows/messages/messagesmodel.cpp index 67b6b5f8..25952ee3 100644 --- a/src/gui/windows/messages/messagesmodel.cpp +++ b/src/gui/windows/messages/messagesmodel.cpp @@ -27,8 +27,7 @@ class MessagesEntry { QString hint; }; -MessagesModel::MessagesModel(QObject *parent) : Super(parent) { -} +MessagesModel::MessagesModel(QObject *parent) : Super(parent) {} MessagesModel::~MessagesModel() { clear_messages(); @@ -42,10 +41,7 @@ int MessagesModel::columnCount(const QModelIndex & /*parent*/) const { return 1; } -QVariant MessagesModel::headerData( - int section, - Qt::Orientation orientation, - int role) const { +QVariant MessagesModel::headerData(int section, Qt::Orientation orientation, int role) const { if (orientation == Qt::Horizontal) { if (role == Qt::DisplayRole) { switch (section) { @@ -62,22 +58,14 @@ QVariant MessagesModel::headerData( } QVariant MessagesModel::data(const QModelIndex &index, int role) const { - if (index.row() >= rowCount()) { - return {}; - } + if (index.row() >= rowCount()) { return {}; } if (role == Qt::DisplayRole || role == Qt::EditRole) { MessagesEntry *ent = messages.at(index.row()); QString ret = ""; - if (!ent->file.isEmpty()) { - ret += ent->file + ":"; - } - if (ent->line) { - ret += QString::number(ent->line) + ":"; - } - if (ent->column) { - ret += QString::number(ent->column) + ":"; - } + if (!ent->file.isEmpty()) { ret += ent->file + ":"; } + if (ent->line) { ret += QString::number(ent->line) + ":"; } + if (ent->column) { ret += QString::number(ent->column) + ":"; } ret += ent->text; return ret; } @@ -115,11 +103,8 @@ void MessagesModel::clear_messages() { } void MessagesModel::activated(QModelIndex index) { - if (index.row() >= rowCount()) { - return; - } + if (index.row() >= rowCount()) { return; } MessagesEntry *ent = messages.at(index.row()); - emit message_selected( - ent->type, ent->file, ent->line, ent->column, ent->text, ent->hint); + emit message_selected(ent->type, ent->file, ent->line, ent->column, ent->text, ent->hint); } diff --git a/src/gui/windows/messages/messagesmodel.h b/src/gui/windows/messages/messagesmodel.h index 96ab29bc..bbe696fd 100644 --- a/src/gui/windows/messages/messagesmodel.h +++ b/src/gui/windows/messages/messagesmodel.h @@ -19,10 +19,9 @@ class MessagesModel : public QAbstractListModel { ~MessagesModel() override; [[nodiscard]] int rowCount(const QModelIndex &parent = QModelIndex()) const override; [[nodiscard]] int columnCount(const QModelIndex &parent = QModelIndex()) const override; - [[nodiscard]] QVariant headerData(int section, Qt::Orientation orientation, int role) - const override; [[nodiscard]] QVariant - data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + headerData(int section, Qt::Orientation orientation, int role) const override; + [[nodiscard]] QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; public slots: void insert_line( diff --git a/src/gui/windows/messages/messagesview.cpp b/src/gui/windows/messages/messagesview.cpp index 8c505da5..d262d9a2 100644 --- a/src/gui/windows/messages/messagesview.cpp +++ b/src/gui/windows/messages/messagesview.cpp @@ -9,8 +9,7 @@ #include #include -MessagesView::MessagesView(QWidget *parent, QSettings *settings) - : Super(parent) { +MessagesView::MessagesView(QWidget *parent, QSettings *settings) : Super(parent) { this->settings = settings; } diff --git a/src/gui/windows/peripherals/peripheralsdock.cpp b/src/gui/windows/peripherals/peripheralsdock.cpp index 0771bbc0..34641da8 100644 --- a/src/gui/windows/peripherals/peripheralsdock.cpp +++ b/src/gui/windows/peripherals/peripheralsdock.cpp @@ -1,7 +1,6 @@ #include "peripheralsdock.h" -PeripheralsDock::PeripheralsDock(QWidget *parent, QSettings *settings) - : QDockWidget(parent) { +PeripheralsDock::PeripheralsDock(QWidget *parent, QSettings *settings) : QDockWidget(parent) { (void)settings; top_widget = new QWidget(this); setWidget(top_widget); diff --git a/src/gui/windows/peripherals/peripheralsview.cpp b/src/gui/windows/peripherals/peripheralsview.cpp index 38e9f9d4..e56c10d8 100644 --- a/src/gui/windows/peripherals/peripheralsview.cpp +++ b/src/gui/windows/peripherals/peripheralsview.cpp @@ -2,30 +2,22 @@ #include "ui_peripheralsview.h" -PeripheralsView::PeripheralsView(QWidget *parent) - : QWidget(parent) - , ui(new Ui::PeripheralsView) { +PeripheralsView::PeripheralsView(QWidget *parent) : QWidget(parent), ui(new Ui::PeripheralsView) { ui->setupUi(this); ui->dialRed->setStyleSheet("QDial { background-color: red }"); ui->dialGreen->setStyleSheet("QDial { background-color: green }"); ui->dialBlue->setStyleSheet("QDial { background-color: blue }"); - connect( - ui->dialRed, &QAbstractSlider::valueChanged, ui->spinRed, - &QSpinBox::setValue); - connect( - ui->dialGreen, &QAbstractSlider::valueChanged, ui->spinGreen, - &QSpinBox::setValue); - connect( - ui->dialBlue, &QAbstractSlider::valueChanged, ui->spinBlue, - &QSpinBox::setValue); + connect(ui->dialRed, &QAbstractSlider::valueChanged, ui->spinRed, &QSpinBox::setValue); + connect(ui->dialGreen, &QAbstractSlider::valueChanged, ui->spinGreen, &QSpinBox::setValue); + connect(ui->dialBlue, &QAbstractSlider::valueChanged, ui->spinBlue, &QSpinBox::setValue); connect( ui->spinRed, QOverload::of(&QSpinBox::valueChanged), ui->dialRed, &QAbstractSlider::setValue); connect( - ui->spinGreen, QOverload::of(&QSpinBox::valueChanged), - ui->dialGreen, &QAbstractSlider::setValue); + ui->spinGreen, QOverload::of(&QSpinBox::valueChanged), ui->dialGreen, + &QAbstractSlider::setValue); connect( ui->spinBlue, QOverload::of(&QSpinBox::valueChanged), ui->dialBlue, &QAbstractSlider::setValue); @@ -38,11 +30,11 @@ void PeripheralsView::setup(const machine::PeripSpiLed *perip_spi_led) { ui->spinRed, QOverload::of(&QSpinBox::valueChanged), perip_spi_led, &machine::PeripSpiLed::red_knob_update); connect( - ui->spinGreen, QOverload::of(&QSpinBox::valueChanged), - perip_spi_led, &machine::PeripSpiLed::green_knob_update); + ui->spinGreen, QOverload::of(&QSpinBox::valueChanged), perip_spi_led, + &machine::PeripSpiLed::green_knob_update); connect( - ui->spinBlue, QOverload::of(&QSpinBox::valueChanged), - perip_spi_led, &machine::PeripSpiLed::blue_knob_update); + ui->spinBlue, QOverload::of(&QSpinBox::valueChanged), perip_spi_led, + &machine::PeripSpiLed::blue_knob_update); val = ui->spinRed->value(); ui->spinRed->setValue(val - 1); diff --git a/src/gui/windows/predictor/predictor_bht_dock.h b/src/gui/windows/predictor/predictor_bht_dock.h index 0d9c65d3..4b52dcfa 100644 --- a/src/gui/windows/predictor/predictor_bht_dock.h +++ b/src/gui/windows/predictor/predictor_bht_dock.h @@ -24,19 +24,18 @@ #include #include - -#define DOCK_BHT_COL_INDEX 0 -#define DOCK_BHT_COL_STATE 1 -#define DOCK_BHT_COL_CORRECT 2 +#define DOCK_BHT_COL_INDEX 0 +#define DOCK_BHT_COL_STATE 1 +#define DOCK_BHT_COL_CORRECT 2 #define DOCK_BHT_COL_INCORRECT 3 -#define DOCK_BHT_COL_ACCURACY 4 +#define DOCK_BHT_COL_ACCURACY 4 #define STYLESHEET_COLOR_DEFAULT "background: rgb(255,255,255);" #define STYLESHEET_COLOR_PREDICT "background: rgb(255,173,173);" -#define STYLESHEET_COLOR_UPDATE "background: rgb(173,255,229);" -#define Q_COLOR_DEFAULT QColor(255, 255, 255) -#define Q_COLOR_PREDICT QColor(255, 173, 173) -#define Q_COLOR_UPDATE QColor(173, 255, 229) +#define STYLESHEET_COLOR_UPDATE "background: rgb(173,255,229);" +#define Q_COLOR_DEFAULT QColor(255, 255, 255) +#define Q_COLOR_PREDICT QColor(255, 173, 173) +#define Q_COLOR_UPDATE QColor(173, 255, 229) class DockPredictorBHT : public QDockWidget { Q_OBJECT @@ -47,7 +46,7 @@ class DockPredictorBHT : public QDockWidget { DockPredictorBHT(QWidget *parent); private: // Internal functions - QTableWidgetItem* get_bht_cell_item(uint8_t row_index, uint8_t col_index); + QTableWidgetItem *get_bht_cell_item(uint8_t row_index, uint8_t col_index); void set_table_color(QColor color); void set_row_color(uint16_t row_index, QColor color); @@ -61,10 +60,8 @@ public slots: machine::PredictionInput input, machine::BranchResult result, machine::BranchType branch_type); - void show_new_update( - uint16_t btb_index, - uint16_t bht_index, - machine::PredictionFeedback feedback); + void + show_new_update(uint16_t btb_index, uint16_t bht_index, machine::PredictionFeedback feedback); void update_predictor_stats(machine::PredictionStatistics stats); void update_bht_row(uint16_t row_index, machine::BranchHistoryTableEntry bht_entry); void reset_colors(); @@ -74,33 +71,33 @@ public slots: void clear(); private: // Internal variables - uint8_t number_of_bhr_bits{ 0 }; - uint8_t number_of_bht_bits{ 0 }; - machine::PredictorState initial_state{ machine::PredictorState::UNDEFINED }; + uint8_t number_of_bhr_bits { 0 }; + uint8_t number_of_bht_bits { 0 }; + machine::PredictorState initial_state { machine::PredictorState::UNDEFINED }; - QT_OWNED QGroupBox *content{ new QGroupBox() }; + QT_OWNED QGroupBox *content { new QGroupBox() }; - QT_OWNED QVBoxLayout *layout_main{ new QVBoxLayout() }; + QT_OWNED QVBoxLayout *layout_main { new QVBoxLayout() }; // Name - QT_OWNED QHBoxLayout *layout_type{ new QHBoxLayout() }; - QT_OWNED QLabel *label_type{ new QLabel() }; - QT_OWNED QLabel *label_type_value{ new QLabel() }; + QT_OWNED QHBoxLayout *layout_type { new QHBoxLayout() }; + QT_OWNED QLabel *label_type { new QLabel() }; + QT_OWNED QLabel *label_type_value { new QLabel() }; // Stats - QT_OWNED QGridLayout *layout_stats{ new QGridLayout() }; - QT_OWNED QLabel *label_stats_correct_text{ new QLabel() }; - QT_OWNED QLabel *label_stats_wrong_text{ new QLabel() }; - QT_OWNED QLabel *label_stats_accuracy_text{ new QLabel() }; - QT_OWNED QLabel *label_stats_correct_value{ new QLabel() }; - QT_OWNED QLabel *label_stats_wrong_value{ new QLabel() }; - QT_OWNED QLabel *label_stats_accuracy_value{ new QLabel() }; + QT_OWNED QGridLayout *layout_stats { new QGridLayout() }; + QT_OWNED QLabel *label_stats_correct_text { new QLabel() }; + QT_OWNED QLabel *label_stats_wrong_text { new QLabel() }; + QT_OWNED QLabel *label_stats_accuracy_text { new QLabel() }; + QT_OWNED QLabel *label_stats_correct_value { new QLabel() }; + QT_OWNED QLabel *label_stats_wrong_value { new QLabel() }; + QT_OWNED QLabel *label_stats_accuracy_value { new QLabel() }; // Prediction & Update - QT_OWNED QHBoxLayout *layout_event{ new QHBoxLayout() }; + QT_OWNED QHBoxLayout *layout_event { new QHBoxLayout() }; // BHT - QT_OWNED QTableWidget *bht{ new QTableWidget() }; + QT_OWNED QTableWidget *bht { new QTableWidget() }; }; #endif // PREDICTOR_BHT_DOCK_H \ No newline at end of file diff --git a/src/gui/windows/predictor/predictor_btb_dock.cpp b/src/gui/windows/predictor/predictor_btb_dock.cpp index 384ee785..18bd7819 100644 --- a/src/gui/windows/predictor/predictor_btb_dock.cpp +++ b/src/gui/windows/predictor/predictor_btb_dock.cpp @@ -34,7 +34,7 @@ uint8_t DockPredictorBTB::init_number_of_bits(const uint8_t b) const { } // Get BTB cell item, or create new one if needed -QTableWidgetItem* DockPredictorBTB::get_btb_cell_item(uint8_t row_index, uint8_t col_index) { +QTableWidgetItem *DockPredictorBTB::get_btb_cell_item(uint8_t row_index, uint8_t col_index) { QTableWidgetItem *item { btb->item(row_index, col_index) }; if (item == nullptr) { item = new QTableWidgetItem(); @@ -48,23 +48,20 @@ QTableWidgetItem* DockPredictorBTB::get_btb_cell_item(uint8_t row_index, uint8_t void DockPredictorBTB::set_table_color(QColor color) { for (uint16_t row_index = 0; row_index < btb->rowCount(); row_index++) { for (uint16_t column_index = 0; column_index < btb->columnCount(); column_index++) { - get_btb_cell_item(row_index, column_index)->setBackground( - QBrush(color)); + get_btb_cell_item(row_index, column_index)->setBackground(QBrush(color)); } } } void DockPredictorBTB::set_row_color(uint16_t row_index, QColor color) { for (uint16_t column_index = 0; column_index < btb->columnCount(); column_index++) { - get_btb_cell_item(row_index, column_index)->setBackground( - QBrush(color)); + get_btb_cell_item(row_index, column_index)->setBackground(QBrush(color)); } } void DockPredictorBTB::setup( const machine::BranchPredictor *branch_predictor, const machine::Core *core) { - clear(); number_of_bits = init_number_of_bits(branch_predictor->get_number_of_btb_bits()); @@ -76,18 +73,16 @@ void DockPredictorBTB::setup( clear_btb(); connect( - branch_predictor, &machine::BranchPredictor::btb_row_updated, - this, &DockPredictorBTB::update_btb_row); - connect( - branch_predictor, &machine::BranchPredictor::prediction_done, - this, &DockPredictorBTB::highligh_row_after_prediction); + branch_predictor, &machine::BranchPredictor::btb_row_updated, this, + &DockPredictorBTB::update_btb_row); connect( - branch_predictor, &machine::BranchPredictor::update_done, - this, &DockPredictorBTB::highligh_row_after_update); + branch_predictor, &machine::BranchPredictor::prediction_done, this, + &DockPredictorBTB::highligh_row_after_prediction); connect( - core, &machine::Core::step_started, - this, &DockPredictorBTB::reset_colors); - + branch_predictor, &machine::BranchPredictor::update_done, this, + &DockPredictorBTB::highligh_row_after_update); + connect(core, &machine::Core::step_started, this, &DockPredictorBTB::reset_colors); + } else { btb->setRowCount(0); btb->setDisabled(true); @@ -96,31 +91,28 @@ void DockPredictorBTB::setup( void DockPredictorBTB::update_btb_row( uint16_t row_index, - machine::BranchTargetBufferEntry btb_entry -) { + machine::BranchTargetBufferEntry btb_entry) { if (row_index >= btb->rowCount()) { WARN("BTB dock update received invalid row index: %u", row_index); return; } if (btb_entry.entry_valid) { - get_btb_cell_item(row_index, DOCK_BTB_COL_INSTR_ADDR)->setData( - Qt::DisplayRole, machine::addr_to_hex_str(btb_entry.instruction_address)); + get_btb_cell_item(row_index, DOCK_BTB_COL_INSTR_ADDR) + ->setData(Qt::DisplayRole, machine::addr_to_hex_str(btb_entry.instruction_address)); - get_btb_cell_item(row_index, DOCK_BTB_COL_TARGET_ADDR)->setData( - Qt::DisplayRole, machine::addr_to_hex_str(btb_entry.target_address)); + get_btb_cell_item(row_index, DOCK_BTB_COL_TARGET_ADDR) + ->setData(Qt::DisplayRole, machine::addr_to_hex_str(btb_entry.target_address)); - get_btb_cell_item(row_index, DOCK_BTB_COL_TYPE)->setData( - Qt::DisplayRole, machine::branch_type_to_string(btb_entry.branch_type).toString()); + get_btb_cell_item(row_index, DOCK_BTB_COL_TYPE) + ->setData( + Qt::DisplayRole, machine::branch_type_to_string(btb_entry.branch_type).toString()); } else { - get_btb_cell_item(row_index, DOCK_BTB_COL_INSTR_ADDR)->setData( - Qt::DisplayRole, ""); + get_btb_cell_item(row_index, DOCK_BTB_COL_INSTR_ADDR)->setData(Qt::DisplayRole, ""); - get_btb_cell_item(row_index, DOCK_BTB_COL_TARGET_ADDR)->setData( - Qt::DisplayRole, ""); + get_btb_cell_item(row_index, DOCK_BTB_COL_TARGET_ADDR)->setData(Qt::DisplayRole, ""); - get_btb_cell_item(row_index, DOCK_BTB_COL_TYPE)->setData( - Qt::DisplayRole, ""); + get_btb_cell_item(row_index, DOCK_BTB_COL_TYPE)->setData(Qt::DisplayRole, ""); } } @@ -138,17 +130,15 @@ void DockPredictorBTB::reset_colors() { void DockPredictorBTB::clear_btb() { for (uint16_t row_index = 0; row_index < btb->rowCount(); row_index++) { - get_btb_cell_item(row_index, DOCK_BTB_COL_INDEX)->setData( - Qt::DisplayRole, QString::number(row_index)); + get_btb_cell_item(row_index, DOCK_BTB_COL_INDEX) + ->setData(Qt::DisplayRole, QString::number(row_index)); - get_btb_cell_item(row_index, DOCK_BTB_COL_INSTR_ADDR)->setData( - Qt::DisplayRole, QString("")); + get_btb_cell_item(row_index, DOCK_BTB_COL_INSTR_ADDR)->setData(Qt::DisplayRole, QString("")); - get_btb_cell_item(row_index, DOCK_BTB_COL_TARGET_ADDR)->setData( - Qt::DisplayRole, QString("")); + get_btb_cell_item(row_index, DOCK_BTB_COL_TARGET_ADDR) + ->setData(Qt::DisplayRole, QString("")); - get_btb_cell_item(row_index, DOCK_BTB_COL_TYPE)->setData( - Qt::DisplayRole, QString("")); + get_btb_cell_item(row_index, DOCK_BTB_COL_TYPE)->setData(Qt::DisplayRole, QString("")); } btb->resizeRowsToContents(); set_table_color(Q_COLOR_DEFAULT); diff --git a/src/gui/windows/predictor/predictor_btb_dock.h b/src/gui/windows/predictor/predictor_btb_dock.h index 78894ab4..62607958 100644 --- a/src/gui/windows/predictor/predictor_btb_dock.h +++ b/src/gui/windows/predictor/predictor_btb_dock.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -20,16 +21,15 @@ #include #include #include -#include -#define DOCK_BTB_COL_INDEX 0 -#define DOCK_BTB_COL_INSTR_ADDR 1 +#define DOCK_BTB_COL_INDEX 0 +#define DOCK_BTB_COL_INSTR_ADDR 1 #define DOCK_BTB_COL_TARGET_ADDR 2 -#define DOCK_BTB_COL_TYPE 3 +#define DOCK_BTB_COL_TYPE 3 #define Q_COLOR_DEFAULT QColor(255, 255, 255) #define Q_COLOR_PREDICT QColor(255, 173, 173) -#define Q_COLOR_UPDATE QColor(173, 255, 229) +#define Q_COLOR_UPDATE QColor(173, 255, 229) // Branch Target Buffer Dock class DockPredictorBTB : public QDockWidget { @@ -42,10 +42,10 @@ class DockPredictorBTB : public QDockWidget { private: // Internal functions uint8_t init_number_of_bits(const uint8_t b) const; - QTableWidgetItem* get_btb_cell_item(uint8_t row_index, uint8_t col_index); + QTableWidgetItem *get_btb_cell_item(uint8_t row_index, uint8_t col_index); void set_table_color(QColor color); void set_row_color(uint16_t row_index, QColor color); - + public: // General functions void setup(const machine::BranchPredictor *branch_predictor, const machine::Core *core); @@ -58,11 +58,11 @@ public slots: void clear(); private: // Internal variables - uint8_t number_of_bits{ 0 }; + uint8_t number_of_bits { 0 }; - QT_OWNED QGroupBox *content{ new QGroupBox() }; - QT_OWNED QVBoxLayout *layout{ new QVBoxLayout() }; - QT_OWNED QTableWidget *btb{ new QTableWidget() }; + QT_OWNED QGroupBox *content { new QGroupBox() }; + QT_OWNED QVBoxLayout *layout { new QVBoxLayout() }; + QT_OWNED QTableWidget *btb { new QTableWidget() }; }; #endif // PREDICTOR_BTB_DOCK_H \ No newline at end of file diff --git a/src/gui/windows/predictor/predictor_info_dock.cpp b/src/gui/windows/predictor/predictor_info_dock.cpp index 267cfae2..9d9c74b9 100644 --- a/src/gui/windows/predictor/predictor_info_dock.cpp +++ b/src/gui/windows/predictor/predictor_info_dock.cpp @@ -149,9 +149,7 @@ void DockPredictorInfo::set_predict_widget_color(QString color_stylesheet) { value_event_predict_instruction->setStyleSheet(color_stylesheet); value_event_predict_address->setStyleSheet(color_stylesheet); value_event_predict_index_btb->setStyleSheet(color_stylesheet); - if (is_predictor_dynamic) { - value_event_predict_index_bht->setStyleSheet(color_stylesheet); - } + if (is_predictor_dynamic) { value_event_predict_index_bht->setStyleSheet(color_stylesheet); } value_event_predict_result->setStyleSheet(color_stylesheet); } @@ -159,16 +157,13 @@ void DockPredictorInfo::set_update_widget_color(QString color_stylesheet) { value_event_update_instruction->setStyleSheet(color_stylesheet); value_event_update_address->setStyleSheet(color_stylesheet); value_event_update_index_btb->setStyleSheet(color_stylesheet); - if (is_predictor_dynamic) { - value_event_update_index_bht->setStyleSheet(color_stylesheet); - } + if (is_predictor_dynamic) { value_event_update_index_bht->setStyleSheet(color_stylesheet); } value_event_update_result->setStyleSheet(color_stylesheet); } void DockPredictorInfo::setup( const machine::BranchPredictor *branch_predictor, const machine::Core *core) { - clear(); number_of_bhr_bits = branch_predictor->get_number_of_bhr_bits(); @@ -179,22 +174,20 @@ void DockPredictorInfo::setup( if (is_predictor_enabled) { connect( - branch_predictor, &machine::BranchPredictor::total_stats_updated, - this, &DockPredictorInfo::update_stats); - connect( - branch_predictor, &machine::BranchPredictor::prediction_done, - this, &DockPredictorInfo::show_new_prediction); + branch_predictor, &machine::BranchPredictor::total_stats_updated, this, + &DockPredictorInfo::update_stats); connect( - core, &machine::Core::step_started, - this, &DockPredictorInfo::reset_colors); + branch_predictor, &machine::BranchPredictor::prediction_done, this, + &DockPredictorInfo::show_new_prediction); + connect(core, &machine::Core::step_started, this, &DockPredictorInfo::reset_colors); connect( - branch_predictor, &machine::BranchPredictor::update_done, - this, &DockPredictorInfo::show_new_update); + branch_predictor, &machine::BranchPredictor::update_done, this, + &DockPredictorInfo::show_new_update); if (is_predictor_dynamic) { connect( - branch_predictor, &machine::BranchPredictor::bhr_updated, - this, &DockPredictorInfo::update_bhr); + branch_predictor, &machine::BranchPredictor::bhr_updated, this, + &DockPredictorInfo::update_bhr); } } @@ -270,7 +263,7 @@ void DockPredictorInfo::show_new_update( value_event_update_index_btb->setText(QString::number(btb_index)); if (!is_predictor_dynamic) { value_event_update_index_bht->setText(""); - } else if (feedback.branch_type == machine::BranchType::BRANCH ) { + } else if (feedback.branch_type == machine::BranchType::BRANCH) { value_event_update_index_bht->setText(QString::number(bht_index)); } else { value_event_update_index_bht->setText("N/A"); diff --git a/src/gui/windows/predictor/predictor_info_dock.h b/src/gui/windows/predictor/predictor_info_dock.h index a2487375..aa213c7c 100644 --- a/src/gui/windows/predictor/predictor_info_dock.h +++ b/src/gui/windows/predictor/predictor_info_dock.h @@ -18,19 +18,19 @@ #include #include #include +#include #include #include #include #include #include -#include #define STYLESHEET_COLOR_DEFAULT "background: rgb(255,255,255);" #define STYLESHEET_COLOR_PREDICT "background: rgb(255,173,173);" -#define STYLESHEET_COLOR_UPDATE "background: rgb(173,255,229);" -#define Q_COLOR_DEFAULT QColor(255, 255, 255) -#define Q_COLOR_PREDICT QColor(255, 173, 173) -#define Q_COLOR_UPDATE QColor(173, 255, 229) +#define STYLESHEET_COLOR_UPDATE "background: rgb(173,255,229);" +#define Q_COLOR_DEFAULT QColor(255, 255, 255) +#define Q_COLOR_PREDICT QColor(255, 173, 173) +#define Q_COLOR_UPDATE QColor(173, 255, 229) class DockPredictorInfo : public QDockWidget { Q_OBJECT @@ -55,10 +55,8 @@ public slots: machine::PredictionInput input, machine::BranchResult result, machine::BranchType branch_type); - void show_new_update( - uint16_t btb_index, - uint16_t bht_index, - machine::PredictionFeedback feedback); + void + show_new_update(uint16_t btb_index, uint16_t bht_index, machine::PredictionFeedback feedback); void update_stats(machine::PredictionStatistics stats); void reset_colors(); void clear_stats(); @@ -68,67 +66,69 @@ public slots: void clear(); private: // Internal variables - bool is_predictor_enabled{ false }; - bool is_predictor_dynamic{ false }; - uint8_t number_of_bhr_bits{ 0 }; - machine::PredictorState initial_state{ machine::PredictorState::UNDEFINED }; + bool is_predictor_enabled { false }; + bool is_predictor_dynamic { false }; + uint8_t number_of_bhr_bits { 0 }; + machine::PredictorState initial_state { machine::PredictorState::UNDEFINED }; - QT_OWNED QGroupBox *content{ new QGroupBox() }; - QT_OWNED QVBoxLayout *layout_main{ new QVBoxLayout() }; - QT_OWNED QSpacerItem *vertical_spacer{ new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding) }; + QT_OWNED QGroupBox *content { new QGroupBox() }; + QT_OWNED QVBoxLayout *layout_main { new QVBoxLayout() }; + QT_OWNED QSpacerItem *vertical_spacer { + new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding) + }; // Stats - QT_OWNED QGridLayout *layout_stats{ new QGridLayout() }; - QT_OWNED QLabel *label_stats_total_text{ new QLabel() }; - QT_OWNED QLabel *label_stats_miss_text{ new QLabel() }; - QT_OWNED QLabel *label_stats_accuracy_text{ new QLabel() }; - QT_OWNED QLabel *label_stats_total_value{ new QLabel() }; - QT_OWNED QLabel *label_stats_miss_value{ new QLabel() }; - QT_OWNED QLabel *label_stats_accuracy_value{ new QLabel() }; + QT_OWNED QGridLayout *layout_stats { new QGridLayout() }; + QT_OWNED QLabel *label_stats_total_text { new QLabel() }; + QT_OWNED QLabel *label_stats_miss_text { new QLabel() }; + QT_OWNED QLabel *label_stats_accuracy_text { new QLabel() }; + QT_OWNED QLabel *label_stats_total_value { new QLabel() }; + QT_OWNED QLabel *label_stats_miss_value { new QLabel() }; + QT_OWNED QLabel *label_stats_accuracy_value { new QLabel() }; // Prediction & Update - QT_OWNED QHBoxLayout *layout_event{ new QHBoxLayout() }; + QT_OWNED QHBoxLayout *layout_event { new QHBoxLayout() }; // Prediction - QT_OWNED QGroupBox *group_event_predict{ new QGroupBox() }; - QT_OWNED QVBoxLayout *layout_event_predict{ new QVBoxLayout() }; - QT_OWNED QHBoxLayout *layout_event_predict_index{ new QHBoxLayout() }; - QT_OWNED QVBoxLayout *layout_event_predict_index_btb{ new QVBoxLayout() }; - QT_OWNED QVBoxLayout *layout_event_predict_index_bht{ new QVBoxLayout() }; - QT_OWNED QLabel *label_event_predict_header{ new QLabel() }; - QT_OWNED QLabel *label_event_predict_instruction{ new QLabel() }; - QT_OWNED QLabel *label_event_predict_address{ new QLabel() }; - QT_OWNED QLabel *label_event_predict_index_btb{ new QLabel() }; - QT_OWNED QLabel *label_event_predict_index_bht{ new QLabel() }; - QT_OWNED QLabel *label_event_predict_result{ new QLabel() }; - QT_OWNED QLineEdit *value_event_predict_instruction{ new QLineEdit() }; - QT_OWNED QLineEdit *value_event_predict_address{ new QLineEdit() }; - QT_OWNED QLineEdit *value_event_predict_index_btb{ new QLineEdit() }; - QT_OWNED QLineEdit *value_event_predict_index_bht{ new QLineEdit() }; - QT_OWNED QLineEdit *value_event_predict_result{ new QLineEdit() }; + QT_OWNED QGroupBox *group_event_predict { new QGroupBox() }; + QT_OWNED QVBoxLayout *layout_event_predict { new QVBoxLayout() }; + QT_OWNED QHBoxLayout *layout_event_predict_index { new QHBoxLayout() }; + QT_OWNED QVBoxLayout *layout_event_predict_index_btb { new QVBoxLayout() }; + QT_OWNED QVBoxLayout *layout_event_predict_index_bht { new QVBoxLayout() }; + QT_OWNED QLabel *label_event_predict_header { new QLabel() }; + QT_OWNED QLabel *label_event_predict_instruction { new QLabel() }; + QT_OWNED QLabel *label_event_predict_address { new QLabel() }; + QT_OWNED QLabel *label_event_predict_index_btb { new QLabel() }; + QT_OWNED QLabel *label_event_predict_index_bht { new QLabel() }; + QT_OWNED QLabel *label_event_predict_result { new QLabel() }; + QT_OWNED QLineEdit *value_event_predict_instruction { new QLineEdit() }; + QT_OWNED QLineEdit *value_event_predict_address { new QLineEdit() }; + QT_OWNED QLineEdit *value_event_predict_index_btb { new QLineEdit() }; + QT_OWNED QLineEdit *value_event_predict_index_bht { new QLineEdit() }; + QT_OWNED QLineEdit *value_event_predict_result { new QLineEdit() }; // Update - QT_OWNED QGroupBox *group_event_update{ new QGroupBox() }; - QT_OWNED QVBoxLayout *layout_event_update{ new QVBoxLayout() }; - QT_OWNED QHBoxLayout *layout_event_update_index{ new QHBoxLayout() }; - QT_OWNED QVBoxLayout *layout_event_update_index_btb{ new QVBoxLayout() }; - QT_OWNED QVBoxLayout *layout_event_update_index_bht{ new QVBoxLayout() }; - QT_OWNED QLabel *label_event_update_header{ new QLabel() }; - QT_OWNED QLabel *label_event_update_instruction{ new QLabel() }; - QT_OWNED QLabel *label_event_update_address{ new QLabel() }; - QT_OWNED QLabel *label_event_update_index_btb{ new QLabel() }; - QT_OWNED QLabel *label_event_update_index_bht{ new QLabel() }; - QT_OWNED QLabel *label_event_update_result{ new QLabel() }; - QT_OWNED QLineEdit *value_event_update_instruction{ new QLineEdit() }; - QT_OWNED QLineEdit *value_event_update_address{ new QLineEdit() }; - QT_OWNED QLineEdit *value_event_update_index_btb{ new QLineEdit() }; - QT_OWNED QLineEdit *value_event_update_index_bht{ new QLineEdit() }; - QT_OWNED QLineEdit *value_event_update_result{ new QLineEdit() }; + QT_OWNED QGroupBox *group_event_update { new QGroupBox() }; + QT_OWNED QVBoxLayout *layout_event_update { new QVBoxLayout() }; + QT_OWNED QHBoxLayout *layout_event_update_index { new QHBoxLayout() }; + QT_OWNED QVBoxLayout *layout_event_update_index_btb { new QVBoxLayout() }; + QT_OWNED QVBoxLayout *layout_event_update_index_bht { new QVBoxLayout() }; + QT_OWNED QLabel *label_event_update_header { new QLabel() }; + QT_OWNED QLabel *label_event_update_instruction { new QLabel() }; + QT_OWNED QLabel *label_event_update_address { new QLabel() }; + QT_OWNED QLabel *label_event_update_index_btb { new QLabel() }; + QT_OWNED QLabel *label_event_update_index_bht { new QLabel() }; + QT_OWNED QLabel *label_event_update_result { new QLabel() }; + QT_OWNED QLineEdit *value_event_update_instruction { new QLineEdit() }; + QT_OWNED QLineEdit *value_event_update_address { new QLineEdit() }; + QT_OWNED QLineEdit *value_event_update_index_btb { new QLineEdit() }; + QT_OWNED QLineEdit *value_event_update_index_bht { new QLineEdit() }; + QT_OWNED QLineEdit *value_event_update_result { new QLineEdit() }; // BHR - QT_OWNED QHBoxLayout *layout_bhr{ new QHBoxLayout() }; - QT_OWNED QLabel *label_bhr{ new QLabel() }; - QT_OWNED QLineEdit *value_bhr{ new QLineEdit() }; + QT_OWNED QHBoxLayout *layout_bhr { new QHBoxLayout() }; + QT_OWNED QLabel *label_bhr { new QLabel() }; + QT_OWNED QLineEdit *value_bhr { new QLineEdit() }; }; #endif // PREDICTOR_INFO_DOCK_H \ No newline at end of file diff --git a/src/gui/windows/program/programmodel.h b/src/gui/windows/program/programmodel.h index da2d0022..a44217eb 100644 --- a/src/gui/windows/program/programmodel.h +++ b/src/gui/windows/program/programmodel.h @@ -15,26 +15,18 @@ class ProgramModel : public QAbstractTableModel { explicit ProgramModel(QObject *parent); [[nodiscard]] int rowCount(const QModelIndex &parent = QModelIndex()) const override; [[nodiscard]] int columnCount(const QModelIndex &parent = QModelIndex()) const override; - [[nodiscard]] QVariant headerData(int section, Qt::Orientation orientation, int role) - const override; [[nodiscard]] QVariant - data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + headerData(int section, Qt::Orientation orientation, int role) const override; + [[nodiscard]] QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; [[nodiscard]] Qt::ItemFlags flags(const QModelIndex &index) const override; - bool - setData(const QModelIndex &index, const QVariant &value, int role) override; + bool setData(const QModelIndex &index, const QVariant &value, int role) override; bool adjustRowAndOffset(int &row, machine::Address address); - [[nodiscard]] inline const QFont *getFont() const { - return &data_font; - } + [[nodiscard]] inline const QFont *getFont() const { return &data_font; } - [[nodiscard]] inline machine::Address getIndex0Offset() const { - return index0_offset; - } + [[nodiscard]] inline machine::Address getIndex0Offset() const { return index0_offset; } - [[nodiscard]] static inline unsigned int cellSizeBytes() { - return 4; - } + [[nodiscard]] static inline unsigned int cellSizeBytes() { return 4; } inline bool get_row_address(machine::Address &address, int row) const { address = index0_offset + row * cellSizeBytes(); return address >= index0_offset; diff --git a/src/machine/bitfield.h b/src/machine/bitfield.h index ccc99763..73cece8f 100644 --- a/src/machine/bitfield.h +++ b/src/machine/bitfield.h @@ -26,9 +26,7 @@ struct BitField { [[nodiscard]] T encode(T val) const { return ((val & (((uint64_t)1 << count) - 1)) << offset); } - [[nodiscard]] uint64_t mask() const { - return (((uint64_t)1 << count) - 1) << offset; - } + [[nodiscard]] uint64_t mask() const { return (((uint64_t)1 << count) - 1) << offset; } }; template diff --git a/src/machine/config_isa.h b/src/machine/config_isa.h index 6ee262a5..98a38f49 100644 --- a/src/machine/config_isa.h +++ b/src/machine/config_isa.h @@ -1,18 +1,19 @@ #ifndef MACHINE_CONFIG_ISA_H #define MACHINE_CONFIG_ISA_H -#include #include +#include namespace machine { struct ConfigIsaWord { constexpr ConfigIsaWord() : bits(0) {}; constexpr ConfigIsaWord(const quint64 &abits) : bits(abits) {}; - constexpr ConfigIsaWord(const ConfigIsaWord &isaWord) = default; //> Copy constructor - constexpr ConfigIsaWord &operator=(const ConfigIsaWord &isaWord) = default; //> Assign constructor + constexpr ConfigIsaWord(const ConfigIsaWord &isaWord) = default; //> Copy constructor + constexpr ConfigIsaWord &operator=(const ConfigIsaWord &isaWord) = default; //> Assign + // constructor - constexpr static ConfigIsaWord empty() {return ConfigIsaWord(); }; + constexpr static ConfigIsaWord empty() { return ConfigIsaWord(); }; constexpr ConfigIsaWord &operator&=(const ConfigIsaWord &isaWord) { bits &= isaWord.bits; @@ -26,17 +27,15 @@ struct ConfigIsaWord { ConfigIsaWord ans(~bits); return ans; } - friend constexpr ConfigIsaWord operator|(ConfigIsaWord lhs, const ConfigIsaWord& rhs) - { + friend constexpr ConfigIsaWord operator|(ConfigIsaWord lhs, const ConfigIsaWord &rhs) { lhs |= rhs; // reuse compound assignment return lhs; // return the result by value (uses move constructor) } - friend constexpr ConfigIsaWord operator&(ConfigIsaWord lhs, const ConfigIsaWord& rhs) - { + friend constexpr ConfigIsaWord operator&(ConfigIsaWord lhs, const ConfigIsaWord &rhs) { lhs &= rhs; // reuse compound assignment return lhs; // return the result by value (uses move constructor) } - constexpr friend bool operator==(const ConfigIsaWord& lhs, const ConfigIsaWord& rhs) { + constexpr friend bool operator==(const ConfigIsaWord &lhs, const ConfigIsaWord &rhs) { return lhs.bits == rhs.bits; } @@ -51,17 +50,11 @@ struct ConfigIsaWord { return ConfigIsaWord(abits); }; - constexpr bool isEmpty() const { - return bits == 0; - }; + constexpr bool isEmpty() const { return bits == 0; }; - constexpr bool contains(char ch) const { - return !(*this & byChar(ch)).isEmpty(); - }; + constexpr bool contains(char ch) const { return !(*this & byChar(ch)).isEmpty(); }; - constexpr bool contains(ConfigIsaWord &isaWord) const { - return (*this & isaWord) == isaWord; - }; + constexpr bool contains(ConfigIsaWord &isaWord) const { return (*this & isaWord) == isaWord; }; ConfigIsaWord &modify(ConfigIsaWord &mask, ConfigIsaWord &val) { (*this) &= ~mask | val; @@ -69,14 +62,12 @@ struct ConfigIsaWord { return *this; } - constexpr auto toUnsigned() const { - return bits; - }; + constexpr auto toUnsigned() const { return bits; }; quint64 bits; }; -} +} // namespace machine Q_DECLARE_METATYPE(machine::ConfigIsaWord) diff --git a/src/machine/core.cpp b/src/machine/core.cpp index c07cb797..42a43936 100644 --- a/src/machine/core.cpp +++ b/src/machine/core.cpp @@ -10,15 +10,11 @@ LOG_CATEGORY("machine.core"); using namespace machine; -static InstructionFlags unsupported_inst_flags_to_check(Xlen xlen, - ConfigIsaWord isa_word) { +static InstructionFlags unsupported_inst_flags_to_check(Xlen xlen, ConfigIsaWord isa_word) { unsigned flags_to_check = IMF_SUPPORTED; - if (xlen == Xlen::_32) - flags_to_check |= IMF_RV64; - if (!isa_word.contains('A')) - flags_to_check |= IMF_AMO; - if (!isa_word.contains('M')) - flags_to_check |= IMF_MUL; + if (xlen == Xlen::_32) flags_to_check |= IMF_RV64; + if (!isa_word.contains('A')) flags_to_check |= IMF_AMO; + if (!isa_word.contains('M')) flags_to_check |= IMF_MUL; return InstructionFlags(flags_to_check); } @@ -140,7 +136,7 @@ void Core::register_exception_handler(ExceptionCause excause, ExceptionHandler * bool Core::handle_exception( ExceptionCause excause, - const Instruction& inst, + const Instruction &inst, Address inst_addr, Address next_addr, Address jump_branch_pc, @@ -158,7 +154,8 @@ bool Core::handle_exception( control_state->update_exception_cause(excause); if (control_state->read_internal(CSR::Id::MTVEC) != 0 && !get_step_over_exception(excause)) { - control_state->exception_initiate(CSR::PrivilegeLevel::MACHINE, CSR::PrivilegeLevel::MACHINE); + control_state->exception_initiate( + CSR::PrivilegeLevel::MACHINE, CSR::PrivilegeLevel::MACHINE); regs->write_pc(control_state->exception_pc_address()); } } @@ -176,32 +173,32 @@ bool Core::handle_exception( } static int32_t amo32_operations(enum AccessControl memctl, int32_t a, int32_t b) { - switch(memctl) { + switch (memctl) { case AC_AMOSWAP32: return b; - case AC_AMOADD32: return a + b; - case AC_AMOXOR32: return a ^ b; - case AC_AMOAND32: return a & b; - case AC_AMOOR32: return a | b; - case AC_AMOMIN32: return a < b? a: b; - case AC_AMOMAX32: return a < b? b: a; - case AC_AMOMINU32: return (uint32_t)a < (uint32_t)b? a: b; - case AC_AMOMAXU32: return (uint32_t)a < (uint32_t)b? b: a; + case AC_AMOADD32: return a + b; + case AC_AMOXOR32: return a ^ b; + case AC_AMOAND32: return a & b; + case AC_AMOOR32: return a | b; + case AC_AMOMIN32: return a < b ? a : b; + case AC_AMOMAX32: return a < b ? b : a; + case AC_AMOMINU32: return (uint32_t)a < (uint32_t)b ? a : b; + case AC_AMOMAXU32: return (uint32_t)a < (uint32_t)b ? b : a; default: break; } return 0; } static int64_t amo64_operations(enum AccessControl memctl, int64_t a, int64_t b) { - switch(memctl) { + switch (memctl) { case AC_AMOSWAP64: return b; - case AC_AMOADD64: return a + b; - case AC_AMOXOR64: return a ^ b; - case AC_AMOAND64: return a & b; - case AC_AMOOR64: return a | b; - case AC_AMOMIN64: return a < b? a: b; - case AC_AMOMAX64: return a < b? b: a; - case AC_AMOMINU64: return (uint64_t)a < (uint64_t)b? a: b; - case AC_AMOMAXU64: return (uint64_t)a < (uint64_t)b? b: a; + case AC_AMOADD64: return a + b; + case AC_AMOXOR64: return a ^ b; + case AC_AMOAND64: return a & b; + case AC_AMOOR64: return a | b; + case AC_AMOMIN64: return a < b ? a : b; + case AC_AMOMAX64: return a < b ? b : a; + case AC_AMOMINU64: return (uint64_t)a < (uint64_t)b ? a : b; + case AC_AMOMAXU64: return (uint64_t)a < (uint64_t)b ? b : a; default: break; } return 0; @@ -252,8 +249,7 @@ enum ExceptionCause Core::memory_special( towrite_val = 1; } break; - case AC_FISRT_AMO_MODIFY32 ... AC_LAST_AMO_MODIFY32: - { + case AC_FISRT_AMO_MODIFY32 ... AC_LAST_AMO_MODIFY32: { if (!memread || !memwrite) { break; } int32_t fetched_value; fetched_value = (int32_t)(mem_data->read_u32(mem_addr)); @@ -262,8 +258,7 @@ enum ExceptionCause Core::memory_special( towrite_val = fetched_value; break; } - case AC_FISRT_AMO_MODIFY64 ... AC_LAST_AMO_MODIFY64: - { + case AC_FISRT_AMO_MODIFY64 ... AC_LAST_AMO_MODIFY64: { if (!memread || !memwrite) { break; } int64_t fetched_value; fetched_value = (int64_t)(mem_data->read_u64(mem_addr)); @@ -287,9 +282,7 @@ FetchState Core::fetch(PCInterstage pc, bool skip_break) { if (!skip_break && hw_breaks.contains(inst_addr)) { excause = EXCAUSE_HWBREAK; } - if (control_state != nullptr) { - control_state->increment_internal(CSR::Id::MCYCLE, 1); - } + if (control_state != nullptr) { control_state->increment_internal(CSR::Id::MCYCLE, 1); } if (control_state != nullptr && excause == EXCAUSE_NONE) { if (control_state->core_interrupt_request()) { excause = EXCAUSE_INT; } @@ -315,9 +308,7 @@ DecodeState Core::decode(const FetchInterstage &dt) { dt.inst.flags_alu_op_mem_ctl(flags, alu_op, mem_ctl); - if ((flags ^ check_inst_flags_val) & check_inst_flags_mask) { - excause = EXCAUSE_INSN_ILLEGAL; - } + if ((flags ^ check_inst_flags_val) & check_inst_flags_mask) { excause = EXCAUSE_INSN_ILLEGAL; } RegisterId num_rs = (flags & (IMF_ALU_REQ_RS | IMF_ALU_RS_ID)) ? dt.inst.rs() : 0; RegisterId num_rt = (flags & IMF_ALU_REQ_RT) ? dt.inst.rt() : 0; @@ -343,8 +334,7 @@ DecodeState Core::decode(const FetchInterstage &dt) { // TODO: EXCAUSE_ECALL_S, EXCAUSE_ECALL_U } } - if (flags & IMF_FORCE_W_OP) - w_operation = true; + if (flags & IMF_FORCE_W_OP) w_operation = true; return { DecodeInternalState { .alu_op_num = static_cast(alu_op.alu_op), @@ -366,8 +356,9 @@ DecodeState Core::decode(const FetchInterstage &dt) { .excause = excause, .ff_rs = FORWARD_NONE, .ff_rt = FORWARD_NONE, - .alu_component = (flags & IMF_AMO) ? AluComponent::PASS : - (flags & IMF_MUL) ? AluComponent::MUL : AluComponent::ALU, + .alu_component = (flags & IMF_AMO) ? AluComponent::PASS + : (flags & IMF_MUL) ? AluComponent::MUL + : AluComponent::ALU, .aluop = alu_op, .memctl = mem_ctl, .num_rs = num_rs, @@ -409,7 +400,8 @@ ExecuteState Core::execute(const DecodeInterstage &dt) { }(); const RegisterValue alu_val = [=] { if (excause != EXCAUSE_NONE) return RegisterValue(0); - return alu_combined_operate(dt.aluop, dt.alu_component, dt.w_operation, dt.alu_mod, alu_fst, alu_sec); + return alu_combined_operate( + dt.aluop, dt.alu_component, dt.w_operation, dt.alu_mod, alu_fst, alu_sec); }(); const Address branch_jal_target = dt.inst_addr + dt.immediate_val.as_i64(); @@ -502,11 +494,13 @@ MemoryState Core::memory(const ExecuteInterstage &dt) { // Predictor update if (dt.branch_jal) { // JAL Jump instruction (J-type (alternative to U-type with different immediate bit order)) - predictor->update(dt.inst, dt.inst_addr, dt.branch_jal_target, BranchType::JUMP, BranchResult::TAKEN); + predictor->update( + dt.inst, dt.inst_addr, dt.branch_jal_target, BranchType::JUMP, BranchResult::TAKEN); } else if (dt.branch_jalr) { // JALR Jump register instruction (I-type) predictor->update( - dt.inst, dt.inst_addr, Address(get_xlen_from_reg(dt.alu_val)), BranchType::JUMP, BranchResult::TAKEN); + dt.inst, dt.inst_addr, Address(get_xlen_from_reg(dt.alu_val)), BranchType::JUMP, + BranchResult::TAKEN); } else if (dt.branch_bxx) { // BXX Conditional branch instruction (B-type (alternative to S-type with different // immediate bit order)) @@ -525,9 +519,11 @@ MemoryState Core::memory(const ExecuteInterstage &dt) { if (dt.xret) { control_state->exception_return(CSR::PrivilegeLevel::MACHINE); if (this->xlen == Xlen::_32) - computed_next_inst_addr = Address(control_state->read_internal(CSR::Id::MEPC).as_u32()); + computed_next_inst_addr + = Address(control_state->read_internal(CSR::Id::MEPC).as_u32()); else - computed_next_inst_addr = Address(control_state->read_internal(CSR::Id::MEPC).as_u64()); + computed_next_inst_addr + = Address(control_state->read_internal(CSR::Id::MEPC).as_u64()); csr_written = true; } } @@ -577,7 +573,7 @@ WritebackState Core::writeback(const MemoryInterstage &dt) { if (dt.regwrite) { regs->write_gp(dt.num_rd, dt.towrite_val); } return WritebackState { WritebackInternalState { - .inst = (dt.excause == EXCAUSE_NONE)? dt.inst: Instruction::NOP, + .inst = (dt.excause == EXCAUSE_NONE) ? dt.inst : Instruction::NOP, .inst_addr = dt.inst_addr, .value = dt.towrite_val, .num_rd = dt.num_rd, diff --git a/src/machine/core.test.cpp b/src/machine/core.test.cpp index f1aed691..14cc30c9 100644 --- a/src/machine/core.test.cpp +++ b/src/machine/core.test.cpp @@ -49,7 +49,8 @@ void test_program_with_single_result() { TrivialBus memory(&memory_backend); BranchPredictor predictor {}; CSR::ControlState controlst {}; - Core core(®isters, &predictor, &memory, &memory, &controlst, Xlen::_32, config_isa_word_default); + Core core( + ®isters, &predictor, &memory, &memory, &controlst, Xlen::_32, config_isa_word_default); size_t instruction_count = compile_simple_program(memory, 0x200_addr, instructions); if (typeid(Core) == typeid(CorePipelined)) { instruction_count += 3; } // finish pipeline @@ -471,7 +472,8 @@ static void core_alu_forward_data() { { QVector code { // objdump --disassembler-options=no-aliases,numeric -d test-hazards - // sed -n -e 's/^[ \t]*[^ \t]\+:[ \t]\+\([0-9a-f]\+\)[ \t]\+\([^ \t].*\)$/0x\1, \/\/ \2/p' + // sed -n -e 's/^[ \t]*[^ \t]\+:[ \t]\+\([0-9a-f]\+\)[ \t]\+\([^ \t].*\)$/0x\1, \/\/ + // \2/p' 0x00100113, // addi x2,x0,1 0x11100093, // addi x1,x0,273 0x22200093, // addi x1,x0,546 @@ -486,16 +488,16 @@ static void core_alu_forward_data() { 0x00000063, // beq x0,x0,10080 }; Registers regs_init; - regs_init.write_pc(0x200_addr); - Registers regs_res(regs_init); - regs_res.write_gp(1, 0x222); - regs_res.write_gp(2, 3); - regs_res.write_gp(3, 0x223); - regs_res.write_gp(4, 0x223); - regs_res.write_gp(5, 0x225); - regs_res.write_gp(6, 0x225); - regs_res.write_pc(regs_init.read_pc() + 4 * code.length() - 4); - QTest::newRow("alu_forward_1") << code << regs_init << regs_res; + regs_init.write_pc(0x200_addr); + Registers regs_res(regs_init); + regs_res.write_gp(1, 0x222); + regs_res.write_gp(2, 3); + regs_res.write_gp(3, 0x223); + regs_res.write_gp(4, 0x223); + regs_res.write_gp(5, 0x225); + regs_res.write_gp(6, 0x225); + regs_res.write_pc(regs_init.read_pc() + 4 * code.length() - 4); + QTest::newRow("alu_forward_1") << code << regs_init << regs_res; } // Test forwarding in JR and JALR @@ -536,9 +538,9 @@ static void core_alu_forward_data() { Registers regs_init; regs_init.write_pc(0x200_addr); Registers regs_res(regs_init); - regs_res.write_gp( 1, 0x00000234); - regs_res.write_gp( 5, 0x00000250); - regs_res.write_gp( 9, 0x000002cd); + regs_res.write_gp(1, 0x00000234); + regs_res.write_gp(5, 0x00000250); + regs_res.write_gp(9, 0x000002cd); regs_res.write_gp(10, 0x000002cd); regs_res.write_gp(11, 0x02222000); regs_res.write_gp(12, 0x03333000); @@ -669,7 +671,6 @@ static void run_code_fragment( Memory &mem_init, Memory &mem_res, QVector &code) { - uint64_t addr = reg_init.read_pc().get_raw(); foreach (uint32_t i, code) { @@ -707,7 +708,9 @@ void TestCore::singlecore_alu_forward() { BranchPredictor predictor {}; CSR::ControlState controlst {}; - CoreSingle core(®_init, &predictor, &mem_init_frontend, &mem_init_frontend, &controlst, Xlen::_32, config_isa_word_default); + CoreSingle core( + ®_init, &predictor, &mem_init_frontend, &mem_init_frontend, &controlst, Xlen::_32, + config_isa_word_default); run_code_fragment(core, reg_init, reg_res, mem_init, mem_res, code); } @@ -723,8 +726,9 @@ void TestCore::pipecore_alu_forward() { BranchPredictor predictor {}; CSR::ControlState controlst {}; - CorePipelined core(®_init, &predictor, &mem_init_frontend, &mem_init_frontend, &controlst, - Xlen::_32, config_isa_word_default, MachineConfig::HazardUnit::HU_STALL_FORWARD); + CorePipelined core( + ®_init, &predictor, &mem_init_frontend, &mem_init_frontend, &controlst, Xlen::_32, + config_isa_word_default, MachineConfig::HazardUnit::HU_STALL_FORWARD); run_code_fragment(core, reg_init, reg_res, mem_init, mem_res, code); } @@ -740,8 +744,9 @@ void TestCore::pipecorestall_alu_forward() { BranchPredictor predictor {}; CSR::ControlState controlst {}; - CorePipelined core(®_init, &predictor, &mem_init_frontend, &mem_init_frontend, &controlst, - Xlen::_32, config_isa_word_default, MachineConfig::HazardUnit::HU_STALL); + CorePipelined core( + ®_init, &predictor, &mem_init_frontend, &mem_init_frontend, &controlst, Xlen::_32, + config_isa_word_default, MachineConfig::HazardUnit::HU_STALL); run_code_fragment(core, reg_init, reg_res, mem_init, mem_res, code); } @@ -758,7 +763,8 @@ static void core_memory_tests_data() { { QVector code { // objdump --disassembler-options=no-aliases,numeric -d test-hazards - // sed -n -e 's/^[ \t]*[^ \t]\+:[ \t]\+\([0-9a-f]\+\)[ \t]\+\([^ \t].*\)$/0x\1, \/\/ \2/p' + // sed -n -e 's/^[ \t]*[^ \t]\+:[ \t]\+\([0-9a-f]\+\)[ \t]\+\([^ \t].*\)$/0x\1, \/\/ + // \2/p' // _start: 0x40000513, // addi x10,x0,1024 @@ -802,14 +808,14 @@ static void core_memory_tests_data() { Registers regs_init; regs_init.write_pc(0x200_addr); Registers regs_res(regs_init); - regs_res.write_gp( 5, 0x438); - regs_res.write_gp( 8, 0x3c); - regs_res.write_gp( 9, 0x3c); + regs_res.write_gp(5, 0x438); + regs_res.write_gp(8, 0x3c); + regs_res.write_gp(9, 0x3c); regs_res.write_gp(10, 0x400); - regs_res.write_gp(18, 0x3c); - regs_res.write_gp(19, 0x38); - regs_res.write_gp(20, 0xf); - regs_res.write_gp(21, 0xf); + regs_res.write_gp(18, 0x3c); + regs_res.write_gp(19, 0x38); + regs_res.write_gp(20, 0xf); + regs_res.write_gp(21, 0xf); regs_res.write_pc(regs_init.read_pc() + 4 * code.length() - 4); uint32_t addr; Memory mem_init(LITTLE); @@ -948,7 +954,9 @@ void TestCore::singlecore_memory_tests() { BranchPredictor predictor {}; CSR::ControlState controlst {}; - CoreSingle core(®_init, &predictor, &mem_init_frontend, &mem_init_frontend, &controlst, Xlen::_32, config_isa_word_default); + CoreSingle core( + ®_init, &predictor, &mem_init_frontend, &mem_init_frontend, &controlst, Xlen::_32, + config_isa_word_default); run_code_fragment(core, reg_init, reg_res, mem_init, mem_res, code); } @@ -964,7 +972,9 @@ void TestCore::pipecore_nc_memory_tests() { BranchPredictor predictor {}; CSR::ControlState controlst {}; - CorePipelined core(®_init, &predictor, &mem_init_frontend, &mem_init_frontend, &controlst, Xlen::_32, config_isa_word_default); + CorePipelined core( + ®_init, &predictor, &mem_init_frontend, &mem_init_frontend, &controlst, Xlen::_32, + config_isa_word_default); run_code_fragment(core, reg_init, reg_res, mem_init, mem_res, code); } @@ -990,7 +1000,8 @@ void TestCore::pipecore_wt_na_memory_tests() { BranchPredictor predictor {}; CSR::ControlState controlst {}; - CorePipelined core(®_init, &predictor, &i_cache, &d_cache, &controlst, Xlen::_32, config_isa_word_default); + CorePipelined core( + ®_init, &predictor, &i_cache, &d_cache, &controlst, Xlen::_32, config_isa_word_default); run_code_fragment(core, reg_init, reg_res, mem_init, mem_res, code); } @@ -1015,7 +1026,8 @@ void TestCore::pipecore_wt_a_memory_tests() { BranchPredictor predictor {}; CSR::ControlState controlst {}; - CorePipelined core(®_init, &predictor, &i_cache, &d_cache, &controlst, Xlen::_32, config_isa_word_default); + CorePipelined core( + ®_init, &predictor, &i_cache, &d_cache, &controlst, Xlen::_32, config_isa_word_default); run_code_fragment(core, reg_init, reg_res, mem_init, mem_res, code); } @@ -1040,7 +1052,8 @@ void TestCore::pipecore_wb_memory_tests() { BranchPredictor predictor {}; CSR::ControlState controlst {}; - CorePipelined core(®_init, &predictor, &i_cache, &d_cache, &controlst, Xlen::_32, config_isa_word_default); + CorePipelined core( + ®_init, &predictor, &i_cache, &d_cache, &controlst, Xlen::_32, config_isa_word_default); run_code_fragment(core, reg_init, reg_res, mem_init, mem_res, code); } diff --git a/src/machine/core/core_state.h b/src/machine/core/core_state.h index 67c1f7a8..8c65887a 100644 --- a/src/machine/core/core_state.h +++ b/src/machine/core/core_state.h @@ -1,10 +1,10 @@ #ifndef QTRVSIM_CORE_STATE_H #define QTRVSIM_CORE_STATE_H -#include "machinedefs.h" -#include "pipeline.h" #include "common/memory_ownership.h" +#include "machinedefs.h" #include "memory/address_range.h" +#include "pipeline.h" #include #include diff --git a/src/machine/csr/controlstate.cpp b/src/machine/csr/controlstate.cpp index 12aeab5e..e3cc8cf6 100644 --- a/src/machine/csr/controlstate.cpp +++ b/src/machine/csr/controlstate.cpp @@ -1,4 +1,3 @@ -#include #include "controlstate.h" #include "common/logging.h" @@ -6,6 +5,7 @@ #include "simulator_exception.h" #include +#include LOG_CATEGORY("machine.csr.control_state"); @@ -20,7 +20,8 @@ namespace machine { namespace CSR { ControlState::ControlState(const ControlState &other) : QObject(this->parent()) - , xlen(other.xlen), register_data(other.register_data) {} + , xlen(other.xlen) + , register_data(other.register_data) {} void ControlState::reset() { std::transform( @@ -83,14 +84,13 @@ namespace machine { namespace CSR { uint64_t u; u = val.as_u64() & desc.write_mask.as_u64(); u |= reg.as_u64() & ~desc.write_mask.as_u64(); - if (xlen == Xlen::_32) - u &= 0xffffffff; + if (xlen == Xlen::_32) u &= 0xffffffff; reg = u; } void ControlState::mstatus_wlrl_write_handler( const RegisterDesc &desc, RegisterValue ®, - RegisterValue val) { + RegisterValue val) { default_wlrl_write_handler(desc, reg, val); } @@ -128,8 +128,7 @@ namespace machine { namespace CSR { irq_to_signal = 63 - qCountLeadingZeroBits(irqs & (~irqs + 1)); } - value = (uint64_t)(irq_to_signal | - ((uint64_t)1 << ((xlen == Xlen::_32)? 31: 63))); + value = (uint64_t)(irq_to_signal | ((uint64_t)1 << ((xlen == Xlen::_32) ? 31 : 63))); } emit write_signal(Id::MCAUSE, value); } diff --git a/src/machine/csr/controlstate.h b/src/machine/csr/controlstate.h index 90918fd9..9a045579 100644 --- a/src/machine/csr/controlstate.h +++ b/src/machine/csr/controlstate.h @@ -1,13 +1,13 @@ #ifndef CONTROLSTATE_H #define CONTROLSTATE_H +#include "bitfield.h" #include "common/math/bit_ops.h" +#include "config_isa.h" #include "csr/address.h" #include "machinedefs.h" #include "register_value.h" #include "simulator_exception.h" -#include "bitfield.h" -#include "config_isa.h" #include #include @@ -17,7 +17,7 @@ namespace machine { namespace CSR { /** CSR register names mapping the registers to continuous locations in internal buffer */ struct Id { - enum IdxType{ + enum IdxType { // Unprivileged Counter/Timers CYCLE, // Machine Information Registers @@ -53,15 +53,9 @@ namespace machine { namespace CSR { struct RegisterDesc; struct RegisterFieldDesc { - uint64_t decode(uint64_t val) const { - return field.decode(val); - } - uint64_t encode(uint64_t val) const { - return field.encode(val); - } - uint64_t mask() const { - return field.mask(); - } + uint64_t decode(uint64_t val) const { return field.decode(val); } + uint64_t encode(uint64_t val) const { return field.encode(val); } + uint64_t mask() const { return field.mask(); } uint64_t update(uint64_t orig, uint64_t val) const { return field.encode(val) | (orig & ~mask()); } @@ -158,18 +152,12 @@ namespace machine { namespace CSR { std::array register_data; public: - void default_wlrl_write_handler( - const RegisterDesc &desc, - RegisterValue ®, - RegisterValue val); - void mstatus_wlrl_write_handler( - const RegisterDesc &desc, - RegisterValue ®, - RegisterValue val); - void mcycle_wlrl_write_handler( - const RegisterDesc &desc, - RegisterValue ®, - RegisterValue val); + void + default_wlrl_write_handler(const RegisterDesc &desc, RegisterValue ®, RegisterValue val); + void + mstatus_wlrl_write_handler(const RegisterDesc &desc, RegisterValue ®, RegisterValue val); + void + mcycle_wlrl_write_handler(const RegisterDesc &desc, RegisterValue ®, RegisterValue val); }; struct RegisterDesc { @@ -183,54 +171,64 @@ namespace machine { namespace CSR { RegisterValue write_mask = (register_storage_t)0xffffffffffffffff; WriteHandlerFn write_handler = &ControlState::default_wlrl_write_handler; struct { - const RegisterFieldDesc * const *array; + const RegisterFieldDesc *const *array; const unsigned count; - } fields = {nullptr, 0}; + } fields = { nullptr, 0 }; }; - namespace Field { - namespace mstatus { - static constexpr RegisterFieldDesc SIE = { "SIE", Id::MSTATUS, {1, 1}, "System global interrupt-enable"}; - static constexpr RegisterFieldDesc MIE = { "MIE", Id::MSTATUS, {1, 3}, "Machine global interrupt-enable"}; - static constexpr RegisterFieldDesc SPIE = { "SPIE", Id::MSTATUS, {1, 5}, "Previous SIE before the trap"}; - static constexpr RegisterFieldDesc MPIE = { "MPIE", Id::MSTATUS, {1, 7}, "Previous MIE before the trap"}; - static constexpr RegisterFieldDesc SPP = { "SPP", Id::MSTATUS, {1, 8}, "System previous privilege mode"}; - static constexpr RegisterFieldDesc MPP = { "MPP", Id::MSTATUS, {2, 11}, "Machine previous privilege mode"}; - static constexpr RegisterFieldDesc UXL = { "UXL", Id::MSTATUS, {2, 32}, "User mode XLEN (RV64 only)"}; - static constexpr RegisterFieldDesc SXL = { "SXL", Id::MSTATUS, {2, 34}, "Supervisor mode XLEN (RV64 only)"}; - static constexpr const RegisterFieldDesc *fields[] = { &SIE, &MIE, &SPIE, &MPIE, &SPP, &MPP, &UXL, &SXL}; - static constexpr unsigned count = sizeof(fields) / sizeof(fields[0]); - } - } + namespace Field { namespace mstatus { + static constexpr RegisterFieldDesc SIE + = { "SIE", Id::MSTATUS, { 1, 1 }, "System global interrupt-enable" }; + static constexpr RegisterFieldDesc MIE + = { "MIE", Id::MSTATUS, { 1, 3 }, "Machine global interrupt-enable" }; + static constexpr RegisterFieldDesc SPIE + = { "SPIE", Id::MSTATUS, { 1, 5 }, "Previous SIE before the trap" }; + static constexpr RegisterFieldDesc MPIE + = { "MPIE", Id::MSTATUS, { 1, 7 }, "Previous MIE before the trap" }; + static constexpr RegisterFieldDesc SPP + = { "SPP", Id::MSTATUS, { 1, 8 }, "System previous privilege mode" }; + static constexpr RegisterFieldDesc MPP + = { "MPP", Id::MSTATUS, { 2, 11 }, "Machine previous privilege mode" }; + static constexpr RegisterFieldDesc UXL + = { "UXL", Id::MSTATUS, { 2, 32 }, "User mode XLEN (RV64 only)" }; + static constexpr RegisterFieldDesc SXL + = { "SXL", Id::MSTATUS, { 2, 34 }, "Supervisor mode XLEN (RV64 only)" }; + static constexpr const RegisterFieldDesc *fields[] + = { &SIE, &MIE, &SPIE, &MPIE, &SPP, &MPP, &UXL, &SXL }; + static constexpr unsigned count = sizeof(fields) / sizeof(fields[0]); + }} // namespace Field::mstatus /** Definitions of supported CSR registers */ inline constexpr std::array REGISTERS { { // Unprivileged Counter/Timers - [Id::CYCLE] = { "cycle", 0xC00_csr, "Cycle counter for RDCYCLE instruction.", 0, 0}, + [Id::CYCLE] = { "cycle", 0xC00_csr, "Cycle counter for RDCYCLE instruction.", 0, 0 }, // Priviledged Machine Mode Registers - [Id::MVENDORID] = { "mvendorid", 0xF11_csr, "Vendor ID.", 0, 0}, - [Id::MARCHID] = { "marchid", 0xF12_csr, "Architecture ID.", 0, 0}, - [Id::MIMPID] = { "mimpid", 0xF13_csr, "Implementation ID.", 0, 0}, + [Id::MVENDORID] = { "mvendorid", 0xF11_csr, "Vendor ID.", 0, 0 }, + [Id::MARCHID] = { "marchid", 0xF12_csr, "Architecture ID.", 0, 0 }, + [Id::MIMPID] = { "mimpid", 0xF13_csr, "Implementation ID.", 0, 0 }, [Id::MHARTID] = { "mhardid", 0xF14_csr, "Hardware thread ID." }, - [Id::MSTATUS] = { "mstatus", 0x300_csr, "Machine status register.", - 0, 0x007FFFEA, &ControlState::mstatus_wlrl_write_handler, - {Field::mstatus::fields, Field::mstatus::count} }, - [Id::MISA] = { "misa", 0x301_csr, "Machine ISA Register.", 0, 0}, - [Id::MIE] = { "mie", 0x304_csr, "Machine interrupt-enable register.", - 0, 0x00ff0AAA}, - [Id::MTVEC] = { "mtvec", 0x305_csr, "Machine trap-handler base address."}, + [Id::MSTATUS] = { "mstatus", + 0x300_csr, + "Machine status register.", + 0, + 0x007FFFEA, + &ControlState::mstatus_wlrl_write_handler, + { Field::mstatus::fields, Field::mstatus::count } }, + [Id::MISA] = { "misa", 0x301_csr, "Machine ISA Register.", 0, 0 }, + [Id::MIE] = { "mie", 0x304_csr, "Machine interrupt-enable register.", 0, 0x00ff0AAA }, + [Id::MTVEC] = { "mtvec", 0x305_csr, "Machine trap-handler base address." }, [Id::MSCRATCH] = { "mscratch", 0x340_csr, "Scratch register for machine trap handlers." }, [Id::MEPC] = { "mepc", 0x341_csr, "Machine exception program counter." }, [Id::MCAUSE] = { "mcause", 0x342_csr, "Machine trap cause." }, [Id::MTVAL] = { "mtval", 0x343_csr, "Machine bad address or instruction." }, - [Id::MIP] = { "mip", 0x344_csr, "Machine interrupt pending.", - 0, 0x00000222}, + [Id::MIP] = { "mip", 0x344_csr, "Machine interrupt pending.", 0, 0x00000222 }, [Id::MTINST] = { "mtinst", 0x34A_csr, "Machine trap instruction (transformed)." }, [Id::MTVAL2] = { "mtval2", 0x34B_csr, "Machine bad guest physical address." }, // Machine Counter/Timers - [Id::MCYCLE] = { "mcycle", 0xB00_csr, "Machine cycle counter.", - 0, (register_storage_t)0xffffffffffffffff, &ControlState::mcycle_wlrl_write_handler}, - [Id::MINSTRET] = { "minstret", 0xB02_csr, "Machine instructions-retired counter."}, + [Id::MCYCLE] + = { "mcycle", 0xB00_csr, "Machine cycle counter.", 0, + (register_storage_t)0xffffffffffffffff, &ControlState::mcycle_wlrl_write_handler }, + [Id::MINSTRET] = { "minstret", 0xB02_csr, "Machine instructions-retired counter." }, } }; /** Lookup from CSR address (value used in instruction) to internal id (index in continuous @@ -263,6 +261,7 @@ namespace machine { namespace CSR { } initialized = true; } + public: size_t at(std::string name) { if (!initialized) init(); diff --git a/src/machine/execute/alu.cpp b/src/machine/execute/alu.cpp index 27364e25..b862ac86 100644 --- a/src/machine/execute/alu.cpp +++ b/src/machine/execute/alu.cpp @@ -17,8 +17,7 @@ RegisterValue alu_combined_operate( : alu64_operate(op.alu_op, modified, a, b); case AluComponent::MUL: return (w_operation) ? mul32_operate(op.mul_op, a, b) : mul64_operate(op.mul_op, a, b); - case AluComponent::PASS: - return a; + case AluComponent::PASS: return a; default: qDebug("ERROR, unknown alu component: %hhx", uint8_t(component)); return 0; } } diff --git a/src/machine/execute/alu.h b/src/machine/execute/alu.h index e787f173..bccbadf5 100644 --- a/src/machine/execute/alu.h +++ b/src/machine/execute/alu.h @@ -13,8 +13,8 @@ namespace machine { * Components available in combined ALU. */ enum class AluComponent { - ALU, //> RV32/64I - MUL, //> RV32/64M + ALU, //> RV32/64I + MUL, //> RV32/64M PASS, //> Pass operand A without change (used for AMO) }; diff --git a/src/machine/instruction.cpp b/src/machine/instruction.cpp index 340065dd..b60a7e17 100644 --- a/src/machine/instruction.cpp +++ b/src/machine/instruction.cpp @@ -103,17 +103,16 @@ bool argdesbycode_filled = fill_argdesbycode(); (IMF_SUPPORTED | IMF_ALUSRC | IMF_REGWRITE | IMF_MEMREAD | IMF_MEM | IMF_ALU_REQ_RS) #define FLAGS_ALU_I_STORE \ (IMF_SUPPORTED | IMF_ALUSRC | IMF_MEMWRITE | IMF_MEM | IMF_ALU_REQ_RS | IMF_ALU_REQ_RT) -#define FLAGS_ALU_T_R_D (IMF_SUPPORTED | IMF_REGWRITE) +#define FLAGS_ALU_T_R_D (IMF_SUPPORTED | IMF_REGWRITE) #define FLAGS_ALU_T_R_STD (FLAGS_ALU_T_R_D | IMF_ALU_REQ_RS | IMF_ALU_REQ_RT) #define FLAGS_AMO_LOAD (FLAGS_ALU_I_LOAD | IMF_AMO) // FLAGS_AMO_STORE for store conditional requires IMF_MEMREAD to ensure stalling because // forwarding is not possible from memory stage after memory read, TODO to solve better way -#define FLAGS_AMO_STORE (FLAGS_ALU_I_STORE | FLAGS_ALU_T_R_D | IMF_AMO | IMF_MEMREAD) +#define FLAGS_AMO_STORE (FLAGS_ALU_I_STORE | FLAGS_ALU_T_R_D | IMF_AMO | IMF_MEMREAD) #define FLAGS_AMO_MODIFY (FLAGS_ALU_I_LOAD | FLAGS_AMO_STORE | IMF_AMO) -#define NOALU \ - { .alu_op = AluOp::ADD } +#define NOALU { .alu_op = AluOp::ADD } #define NOMEM .mem_ctl = AC_NONE // TODO NOTE: if unknown is defined as all 0, instruction map can be significantly simplified @@ -138,14 +137,14 @@ struct InstructionMap { const InstructionMap *aliases = nullptr; }; -#define IT_R Instruction::R -#define IT_I Instruction::I -#define IT_S Instruction::S -#define IT_B Instruction::B -#define IT_U Instruction::U -#define IT_J Instruction::J -#define IT_AMO Instruction::AMO -#define IT_ZICSR Instruction::ZICSR +#define IT_R Instruction::R +#define IT_I Instruction::I +#define IT_S Instruction::S +#define IT_B Instruction::B +#define IT_U Instruction::U +#define IT_J Instruction::J +#define IT_AMO Instruction::AMO +#define IT_ZICSR Instruction::ZICSR #define IT_UNKNOWN Instruction::UNKNOWN // clang-format off diff --git a/src/machine/instruction.h b/src/machine/instruction.h index 3719d877..c2bf742b 100644 --- a/src/machine/instruction.h +++ b/src/machine/instruction.h @@ -56,7 +56,7 @@ enum InstructionFlags : unsigned { IMF_CSR_TO_ALU = 1L << 21, /**< Instruction modifies the current value */ IMF_ALU_RS_ID = 1L << 22, // RV64/32A - Atomic Memory Operations - IMF_AMO = 1L << 23, /**< Instruction is AMO */ + IMF_AMO = 1L << 23, /**< Instruction is AMO */ // TODO do we want to add those signals to the visualization? IMF_RV64 = 1L << 24, /**< Mark instructions which are available in 64-bit mode only. */ diff --git a/src/machine/machine.cpp b/src/machine/machine.cpp index c50ae78e..7c34c435 100644 --- a/src/machine/machine.cpp +++ b/src/machine/machine.cpp @@ -24,9 +24,7 @@ Machine::Machine(MachineConfig config, bool load_symtab, bool load_executable) else this->machine_config.set_simulated_xlen(Xlen::_32); - if (load_symtab) { - symtab = program.get_symbol_table(); - } + if (load_symtab) { symtab = program.get_symbol_table(); } program_end = program.end(); if (program.get_executable_entry() != 0x0_addr) { @@ -38,8 +36,7 @@ Machine::Machine(MachineConfig config, bool load_symtab, bool load_executable) } data_bus = new MemoryDataBus(machine_config.get_simulated_endian()); - data_bus->insert_device_to_range( - mem, 0x00000000_addr, 0xefffffff_addr, false); + data_bus->insert_device_to_range(mem, 0x00000000_addr, 0xefffffff_addr, false); setup_serial_port(); setup_perip_spi_led(); @@ -54,11 +51,8 @@ Machine::Machine(MachineConfig config, bool load_symtab, bool load_executable) bool access_enable_burst = machine_config.memory_access_enable_burst(); cch_level2 = new Cache( - data_bus, &machine_config.cache_level2(), - access_time_read, - access_time_write, - access_time_burst, - access_enable_burst); + data_bus, &machine_config.cache_level2(), access_time_read, access_time_write, + access_time_burst, access_enable_burst); if (machine_config.cache_level2().enabled()) { access_time_read = machine_config.memory_access_time_level2(); access_time_write = machine_config.memory_access_time_level2(); @@ -66,19 +60,14 @@ Machine::Machine(MachineConfig config, bool load_symtab, bool load_executable) access_enable_burst = true; } cch_program = new Cache( - cch_level2, &machine_config.cache_program(), - access_time_read, - access_time_write, - access_time_burst, - access_enable_burst); + cch_level2, &machine_config.cache_program(), access_time_read, access_time_write, + access_time_burst, access_enable_burst); cch_data = new Cache( - cch_level2, &machine_config.cache_data(), - access_time_read, - access_time_write, - access_time_burst, - access_enable_burst); + cch_level2, &machine_config.cache_data(), access_time_read, access_time_write, + access_time_burst, access_enable_burst); - controlst = new CSR::ControlState(machine_config.get_simulated_xlen(), machine_config.get_isa_word()); + controlst + = new CSR::ControlState(machine_config.get_simulated_xlen(), machine_config.get_isa_word()); predictor = new BranchPredictor( machine_config.get_bp_enabled(), machine_config.get_bp_type(), machine_config.get_bp_init_state(), machine_config.get_bp_btb_bits(), @@ -86,11 +75,12 @@ Machine::Machine(MachineConfig config, bool load_symtab, bool load_executable) if (machine_config.pipelined()) { cr = new CorePipelined( - regs, predictor, cch_program, cch_data, controlst, - machine_config.get_simulated_xlen(), machine_config.get_isa_word(), machine_config.hazard_unit()); + regs, predictor, cch_program, cch_data, controlst, machine_config.get_simulated_xlen(), + machine_config.get_isa_word(), machine_config.hazard_unit()); } else { - cr = new CoreSingle(regs, predictor, cch_program, cch_data, controlst, - machine_config.get_simulated_xlen(), machine_config.get_isa_word()); + cr = new CoreSingle( + regs, predictor, cch_program, cch_data, controlst, machine_config.get_simulated_xlen(), + machine_config.get_isa_word()); } connect( this, &Machine::set_interrupt_signal, controlst, &CSR::ControlState::set_interrupt_signal); @@ -101,10 +91,8 @@ Machine::Machine(MachineConfig config, bool load_symtab, bool load_executable) for (int i = 0; i < EXCAUSE_COUNT; i++) { if (i != EXCAUSE_INT && i != EXCAUSE_BREAK && i != EXCAUSE_HWBREAK) { - set_stop_on_exception( - (enum ExceptionCause)i, machine_config.osemu_exception_stop()); - set_step_over_exception( - (enum ExceptionCause)i, machine_config.osemu_exception_stop()); + set_stop_on_exception((enum ExceptionCause)i, machine_config.osemu_exception_stop()); + set_step_over_exception((enum ExceptionCause)i, machine_config.osemu_exception_stop()); } } @@ -113,16 +101,14 @@ Machine::Machine(MachineConfig config, bool load_symtab, bool load_executable) } void Machine::setup_lcd_display() { perip_lcd_display = new LcdDisplay(machine_config.get_simulated_endian()); - memory_bus_insert_range( - perip_lcd_display, 0xffe00000_addr, 0xffe4afff_addr, true); + memory_bus_insert_range(perip_lcd_display, 0xffe00000_addr, 0xffe4afff_addr, true); if (machine_config.get_simulated_xlen() == Xlen::_64) memory_bus_insert_range( perip_lcd_display, 0xffffffffffe00000_addr, 0xffffffffffe4afff_addr, false); } void Machine::setup_perip_spi_led() { perip_spi_led = new PeripSpiLed(machine_config.get_simulated_endian()); - memory_bus_insert_range( - perip_spi_led, 0xffffc100_addr, 0xffffc1ff_addr, true); + memory_bus_insert_range(perip_spi_led, 0xffffc100_addr, 0xffffc1ff_addr, true); if (machine_config.get_simulated_xlen() == Xlen::_64) memory_bus_insert_range( perip_spi_led, 0xffffffffffffc100_addr, 0xffffffffffffc1ff_addr, false); @@ -133,22 +119,19 @@ void Machine::setup_serial_port() { memory_bus_insert_range(ser_port, 0xffff0000_addr, 0xffff003f_addr, false); if (machine_config.get_simulated_xlen() == Xlen::_64) memory_bus_insert_range(ser_port, 0xffffffffffffc000_addr, 0xffffffffffffc03f_addr, false); - connect( - ser_port, &SerialPort::signal_interrupt, this, - &Machine::set_interrupt_signal); + connect(ser_port, &SerialPort::signal_interrupt, this, &Machine::set_interrupt_signal); } void Machine::setup_aclint_mtime() { aclint_mtimer = new aclint::AclintMtimer(machine_config.get_simulated_endian()); - memory_bus_insert_range(aclint_mtimer, - 0xfffd0000_addr + aclint::CLINT_MTIMER_OFFSET, - 0xfffd0000_addr + aclint::CLINT_MTIMER_OFFSET + aclint::CLINT_MTIMER_SIZE - 1, - true); + memory_bus_insert_range( + aclint_mtimer, 0xfffd0000_addr + aclint::CLINT_MTIMER_OFFSET, + 0xfffd0000_addr + aclint::CLINT_MTIMER_OFFSET + aclint::CLINT_MTIMER_SIZE - 1, true); if (machine_config.get_simulated_xlen() == Xlen::_64) - memory_bus_insert_range(aclint_mtimer, - 0xfffffffffffd0000_addr + aclint::CLINT_MTIMER_OFFSET, - 0xfffffffffffd0000_addr + aclint::CLINT_MTIMER_OFFSET + aclint::CLINT_MTIMER_SIZE - 1, - false); + memory_bus_insert_range( + aclint_mtimer, 0xfffffffffffd0000_addr + aclint::CLINT_MTIMER_OFFSET, + 0xfffffffffffd0000_addr + aclint::CLINT_MTIMER_OFFSET + aclint::CLINT_MTIMER_SIZE - 1, + false); connect( aclint_mtimer, &aclint::AclintMtimer::signal_interrupt, this, &Machine::set_interrupt_signal); @@ -156,34 +139,30 @@ void Machine::setup_aclint_mtime() { void Machine::setup_aclint_mswi() { aclint_mswi = new aclint::AclintMswi(machine_config.get_simulated_endian()); - memory_bus_insert_range(aclint_mswi, - 0xfffd0000_addr + aclint::CLINT_MSWI_OFFSET, - 0xfffd0000_addr + aclint::CLINT_MSWI_OFFSET + aclint::CLINT_MSWI_SIZE - 1, - true); + memory_bus_insert_range( + aclint_mswi, 0xfffd0000_addr + aclint::CLINT_MSWI_OFFSET, + 0xfffd0000_addr + aclint::CLINT_MSWI_OFFSET + aclint::CLINT_MSWI_SIZE - 1, true); if (machine_config.get_simulated_xlen() == Xlen::_64) - memory_bus_insert_range(aclint_mswi, - 0xfffffffffffd0000_addr + aclint::CLINT_MSWI_OFFSET, - 0xfffffffffffd0000_addr + aclint::CLINT_MSWI_OFFSET + aclint::CLINT_MSWI_SIZE - 1, - false); + memory_bus_insert_range( + aclint_mswi, 0xfffffffffffd0000_addr + aclint::CLINT_MSWI_OFFSET, + 0xfffffffffffd0000_addr + aclint::CLINT_MSWI_OFFSET + aclint::CLINT_MSWI_SIZE - 1, + false); connect( - aclint_mswi, &aclint::AclintMswi::signal_interrupt, this, - &Machine::set_interrupt_signal); + aclint_mswi, &aclint::AclintMswi::signal_interrupt, this, &Machine::set_interrupt_signal); } void Machine::setup_aclint_sswi() { aclint_sswi = new aclint::AclintSswi(machine_config.get_simulated_endian()); - memory_bus_insert_range(aclint_sswi, - 0xfffd0000_addr + aclint::CLINT_SSWI_OFFSET, - 0xfffd0000_addr + aclint::CLINT_SSWI_OFFSET + aclint::CLINT_SSWI_SIZE - 1, - true); + memory_bus_insert_range( + aclint_sswi, 0xfffd0000_addr + aclint::CLINT_SSWI_OFFSET, + 0xfffd0000_addr + aclint::CLINT_SSWI_OFFSET + aclint::CLINT_SSWI_SIZE - 1, true); if (machine_config.get_simulated_xlen() == Xlen::_64) - memory_bus_insert_range(aclint_sswi, - 0xfffffffffffd0000_addr + aclint::CLINT_SSWI_OFFSET, - 0xfffffffffffd0000_addr + aclint::CLINT_SSWI_OFFSET + aclint::CLINT_SSWI_SIZE - 1, - false); + memory_bus_insert_range( + aclint_sswi, 0xfffffffffffd0000_addr + aclint::CLINT_SSWI_OFFSET, + 0xfffffffffffd0000_addr + aclint::CLINT_SSWI_OFFSET + aclint::CLINT_SSWI_SIZE - 1, + false); connect( - aclint_sswi, &aclint::AclintSswi::signal_interrupt, this, - &Machine::set_interrupt_signal); + aclint_sswi, &aclint::AclintSswi::signal_interrupt, this, &Machine::set_interrupt_signal); } Machine::~Machine() { @@ -259,15 +238,9 @@ Cache *Machine::cache_data_rw() { } void Machine::cache_sync() { - if (cch_program != nullptr) { - cch_program->sync(); - } - if (cch_data != nullptr) { - cch_data->sync(); - } - if (cch_level2 != nullptr) { - cch_level2->sync(); - } + if (cch_program != nullptr) { cch_program->sync(); } + if (cch_data != nullptr) { cch_data->sync(); } + if (cch_level2 != nullptr) { cch_level2->sync(); } } const MemoryDataBus *Machine::memory_data_bus() { @@ -291,9 +264,7 @@ LcdDisplay *Machine::peripheral_lcd_display() { } SymbolTable *Machine::symbol_table_rw(bool create) { - if (create && (symtab == nullptr)) { - symtab = new SymbolTable; - } + if (create && (symtab == nullptr)) { symtab = new SymbolTable; } return symtab; } @@ -307,9 +278,7 @@ void Machine::set_symbol( uint32_t size, unsigned char info, unsigned char other) { - if (symtab == nullptr) { - symtab = new SymbolTable; - } + if (symtab == nullptr) { symtab = new SymbolTable; } symtab->set_symbol(name, value, size, info, other); } @@ -339,10 +308,9 @@ bool Machine::exited() { // We don't allow to call control methods when machine exited or if it's busy // We rather silently fail. -#define CTL_GUARD \ - do { \ - if (exited() || stat == ST_BUSY) \ - return; \ +#define CTL_GUARD \ + do { \ + if (exited() || stat == ST_BUSY) return; \ } while (false) void Machine::play() { @@ -354,9 +322,7 @@ void Machine::play() { } void Machine::pause() { - if (stat != ST_BUSY) { - CTL_GUARD; - } + if (stat != ST_BUSY) { CTL_GUARD; } set_status(ST_READY); stop_core_clock(); emit play_paused(); @@ -449,17 +415,11 @@ void Machine::restart() { void Machine::set_status(enum Status st) { bool change = st != stat; stat = st; - if (change) { - emit status_change(st); - } + if (change) { emit status_change(st); } } -void Machine::register_exception_handler( - ExceptionCause excause, - ExceptionHandler *exhandler) { - if (cr != nullptr) { - cr->register_exception_handler(excause, exhandler); - } +void Machine::register_exception_handler(ExceptionCause excause, ExceptionHandler *exhandler) { + if (cr != nullptr) { cr->register_exception_handler(excause, exhandler); } } bool Machine::memory_bus_insert_range( @@ -467,63 +427,44 @@ bool Machine::memory_bus_insert_range( Address start_addr, Address last_addr, bool move_ownership) { - if (data_bus == nullptr) { - return false; - } - return data_bus->insert_device_to_range( - mem_acces, start_addr, last_addr, move_ownership); + if (data_bus == nullptr) { return false; } + return data_bus->insert_device_to_range(mem_acces, start_addr, last_addr, move_ownership); } void Machine::insert_hwbreak(Address address) { - if (cr != nullptr) { - cr->insert_hwbreak(address); - } + if (cr != nullptr) { cr->insert_hwbreak(address); } } void Machine::remove_hwbreak(Address address) { - if (cr != nullptr) { - cr->remove_hwbreak(address); - } + if (cr != nullptr) { cr->remove_hwbreak(address); } } bool Machine::is_hwbreak(Address address) { - if (cr != nullptr) { - return cr->is_hwbreak(address); - } + if (cr != nullptr) { return cr->is_hwbreak(address); } return false; } void Machine::set_stop_on_exception(enum ExceptionCause excause, bool value) { - if (cr != nullptr) { - cr->set_stop_on_exception(excause, value); - } + if (cr != nullptr) { cr->set_stop_on_exception(excause, value); } } bool Machine::get_stop_on_exception(enum ExceptionCause excause) const { - if (cr != nullptr) { - return cr->get_stop_on_exception(excause); - } + if (cr != nullptr) { return cr->get_stop_on_exception(excause); } return false; } void Machine::set_step_over_exception(enum ExceptionCause excause, bool value) { - if (cr != nullptr) { - cr->set_step_over_exception(excause, value); - } + if (cr != nullptr) { cr->set_step_over_exception(excause, value); } } bool Machine::get_step_over_exception(enum ExceptionCause excause) const { - if (cr != nullptr) { - return cr->get_step_over_exception(excause); - } + if (cr != nullptr) { return cr->get_step_over_exception(excause); } return false; } enum ExceptionCause Machine::get_exception_cause() const { uint32_t val; - if (controlst == nullptr) { - return EXCAUSE_NONE; - } + if (controlst == nullptr) { return EXCAUSE_NONE; } val = (controlst->read_internal(CSR::Id::MCAUSE).as_u64()); if (val & 0xffffffff80000000) { return EXCAUSE_INT; diff --git a/src/machine/machine.h b/src/machine/machine.h index fc5ba5f9..4a87880a 100644 --- a/src/machine/machine.h +++ b/src/machine/machine.h @@ -3,13 +3,13 @@ #include "core.h" #include "machineconfig.h" +#include "memory/backend/aclintmswi.h" +#include "memory/backend/aclintmtimer.h" +#include "memory/backend/aclintsswi.h" #include "memory/backend/lcddisplay.h" #include "memory/backend/peripheral.h" #include "memory/backend/peripspiled.h" #include "memory/backend/serialport.h" -#include "memory/backend/aclintmtimer.h" -#include "memory/backend/aclintmswi.h" -#include "memory/backend/aclintsswi.h" #include "memory/cache/cache.h" #include "memory/memory_bus.h" #include "predictor.h" diff --git a/src/machine/machineconfig.cpp b/src/machine/machineconfig.cpp index 0a4e74bf..3a1de4ed 100644 --- a/src/machine/machineconfig.cpp +++ b/src/machine/machineconfig.cpp @@ -9,32 +9,32 @@ using namespace machine; ////////////////////////////////////////////////////////////////////////////// /// Default config of MachineConfig -#define DF_PIPELINE false -#define DF_DELAYSLOT true -#define DF_HUNIT HU_STALL_FORWARD -#define DF_EXEC_PROTEC false -#define DF_WRITE_PROTEC false -#define DF_MEM_ACC_READ 10 -#define DF_MEM_ACC_WRITE 10 -#define DF_MEM_ACC_BURST 0 -#define DF_MEM_ACC_LEVEL2 2 +#define DF_PIPELINE false +#define DF_DELAYSLOT true +#define DF_HUNIT HU_STALL_FORWARD +#define DF_EXEC_PROTEC false +#define DF_WRITE_PROTEC false +#define DF_MEM_ACC_READ 10 +#define DF_MEM_ACC_WRITE 10 +#define DF_MEM_ACC_BURST 0 +#define DF_MEM_ACC_LEVEL2 2 #define DF_MEM_ACC_BURST_ENABLE false -#define DF_ELF QString("") +#define DF_ELF QString("") /// Default config of branch predictor -#define DFC_BP_ENABLED false -#define DFC_BP_TYPE PredictorType::SMITH_1_BIT -#define DFC_BP_INIT_STATE PredictorState::NOT_TAKEN -#define DFC_BP_BTB_BITS 2 -#define DFC_BP_BHR_BITS 0 +#define DFC_BP_ENABLED false +#define DFC_BP_TYPE PredictorType::SMITH_1_BIT +#define DFC_BP_INIT_STATE PredictorState::NOT_TAKEN +#define DFC_BP_BTB_BITS 2 +#define DFC_BP_BHR_BITS 0 #define DFC_BP_BHT_ADDR_BITS 2 ////////////////////////////////////////////////////////////////////////////// /// Default config of CacheConfig -#define DFC_EN false -#define DFC_SETS 1 +#define DFC_EN false +#define DFC_SETS 1 #define DFC_BLOCKS 1 -#define DFC_ASSOC 1 +#define DFC_ASSOC 1 #define DFC_REPLAC RP_RAND -#define DFC_WRITE WP_THROUGH_NOALLOC +#define DFC_WRITE WP_THROUGH_NOALLOC ////////////////////////////////////////////////////////////////////////////// CacheConfig::CacheConfig() { @@ -632,9 +632,8 @@ uint8_t MachineConfig::get_bp_bht_bits() const { bool MachineConfig::operator==(const MachineConfig &c) const { #define CMP(GETTER) (GETTER)() == (c.GETTER)() return CMP(pipelined) && CMP(delay_slot) && CMP(hazard_unit) && CMP(get_simulated_xlen) - && CMP(get_isa_word) && CMP(get_bp_enabled) && CMP(get_bp_type) - && CMP(get_bp_init_state) && CMP(get_bp_btb_bits) - && CMP(get_bp_bhr_bits) && CMP(get_bp_bht_addr_bits) + && CMP(get_isa_word) && CMP(get_bp_enabled) && CMP(get_bp_type) && CMP(get_bp_init_state) + && CMP(get_bp_btb_bits) && CMP(get_bp_bhr_bits) && CMP(get_bp_bht_addr_bits) && CMP(memory_execute_protection) && CMP(memory_write_protection) && CMP(memory_access_time_read) && CMP(memory_access_time_write) && CMP(memory_access_time_burst) && CMP(memory_access_time_level2) diff --git a/src/machine/machineconfig.h b/src/machine/machineconfig.h index 5392d9ef..e6215188 100644 --- a/src/machine/machineconfig.h +++ b/src/machine/machineconfig.h @@ -27,10 +27,12 @@ enum ConfigPresets { CP_PIPE // Full pipelined cpu }; -constexpr ConfigIsaWord config_isa_word_default = ConfigIsaWord::byChar('E') | ConfigIsaWord::byChar('I') | - ConfigIsaWord::byChar('A') |ConfigIsaWord::byChar('M'); +constexpr ConfigIsaWord config_isa_word_default + = ConfigIsaWord::byChar('E') | ConfigIsaWord::byChar('I') | ConfigIsaWord::byChar('A') + | ConfigIsaWord::byChar('M'); -constexpr ConfigIsaWord config_isa_word_fixed = ConfigIsaWord::byChar('E') | ConfigIsaWord::byChar('I'); +constexpr ConfigIsaWord config_isa_word_fixed + = ConfigIsaWord::byChar('E') | ConfigIsaWord::byChar('I'); class CacheConfig { public: diff --git a/src/machine/machinedefs.h b/src/machine/machinedefs.h index e24ed74e..de93481b 100644 --- a/src/machine/machinedefs.h +++ b/src/machine/machinedefs.h @@ -82,8 +82,8 @@ enum ExceptionCause { EXCAUSE_STORE_PAGE_FAULT = 15, // Store/AMO page fault // Simulator specific exception cause codes, alliases EXCAUSE_HWBREAK = 16, - EXCAUSE_ECALL_ANY = 17, // sythetic exception to mark ECALL instruction - EXCAUSE_INT = 18, // External/asynchronous interrupt, bit 32 or 63 + EXCAUSE_ECALL_ANY = 17, // sythetic exception to mark ECALL instruction + EXCAUSE_INT = 18, // External/asynchronous interrupt, bit 32 or 63 EXCAUSE_COUNT = 19, }; diff --git a/src/machine/memory/address_range.h b/src/machine/memory/address_range.h index 010e848c..d7898267 100644 --- a/src/machine/memory/address_range.h +++ b/src/machine/memory/address_range.h @@ -1,14 +1,12 @@ #ifndef ADDRESS_RANGE_H #define ADDRESS_RANGE_H +#include "memory/address.h" #include "utils.h" #include #include -#include "memory/address.h" - - namespace machine { /** @@ -21,18 +19,18 @@ namespace machine { class AddressRange { public: Address first; //> The first valid location of the range - Address last; //> The last valid location of the range + Address last; //> The last valid location of the range /** * Default constructor results for empty range. */ constexpr AddressRange() : first(1), last(0) {}; - constexpr AddressRange(const AddressRange &range) = default; //> Copy constructor - constexpr AddressRange(const Address &afirst, const Address &alast) : - first(afirst), last(alast) {}; - constexpr AddressRange(const Address &asingleAddr) : - first(asingleAddr), last(asingleAddr) {}; + constexpr AddressRange(const AddressRange &range) = default; //> Copy constructor + constexpr AddressRange(const Address &afirst, const Address &alast) + : first(afirst) + , last(alast) {}; + constexpr AddressRange(const Address &asingleAddr) : first(asingleAddr), last(asingleAddr) {}; constexpr AddressRange &operator=(const AddressRange &address) = default; //> Assign constructor /** @@ -42,12 +40,10 @@ class AddressRange { /* Eq */ constexpr inline bool operator==(const AddressRange &other) const { - return (first == other.first && last == other.last) || - (is_empty() && other.is_empty()); + return (first == other.first && last == other.last) || (is_empty() && other.is_empty()); }; constexpr inline bool operator!=(const AddressRange &other) const { - return !((first == other.first && last == other.last) || - (is_empty() && other.is_empty())); + return !((first == other.first && last == other.last) || (is_empty() && other.is_empty())); }; constexpr bool within(const AddressRange &other) const { @@ -59,8 +55,7 @@ class AddressRange { }; constexpr bool overlaps(const AddressRange &other) const { - return (first <= other.last) && (last >= other.first) && - !is_empty() && !other.is_empty(); + return (first <= other.last) && (last >= other.first) && !is_empty() && !other.is_empty(); }; void reset() { diff --git a/src/machine/memory/backend/aclintmswi.cpp b/src/machine/memory/backend/aclintmswi.cpp index e8b6ae72..c9fc3d54 100644 --- a/src/machine/memory/backend/aclintmswi.cpp +++ b/src/machine/memory/backend/aclintmswi.cpp @@ -7,14 +7,13 @@ using ae = machine::AccessEffects; // For enum values, type is obvious from // context. - namespace machine::aclint { +namespace machine::aclint { AclintMswi::AclintMswi(Endian simulated_machine_endian) : BackendMemory(simulated_machine_endian) - , mswi_irq_level(3) -{ + , mswi_irq_level(3) { mswi_count = 1; - for (bool & i : mswi_value) + for (bool &i : mswi_value) i = false; } @@ -32,11 +31,8 @@ bool AclintMswi::update_mswi_irq() { return active; } -WriteResult AclintMswi::write( - Offset destination, - const void *source, - size_t size, - WriteOptions options) { +WriteResult +AclintMswi::write(Offset destination, const void *source, size_t size, WriteOptions options) { UNUSED(options) return write_by_u32( destination, source, size, @@ -46,20 +42,15 @@ WriteResult AclintMswi::write( }, [&](Offset src, uint32_t value) { return write_reg32( - src, byteswap_if( - value, internal_endian != simulated_machine_endian)); + src, byteswap_if(value, internal_endian != simulated_machine_endian)); }); } -ReadResult AclintMswi::read( - void *destination, - Offset source, - size_t size, - ReadOptions options) const { +ReadResult +AclintMswi::read(void *destination, Offset source, size_t size, ReadOptions options) const { return read_by_u32(destination, source, size, [&](Offset src) { return byteswap_if( - read_reg32(src, options.type), - internal_endian != simulated_machine_endian); + read_reg32(src, options.type), internal_endian != simulated_machine_endian); }); } @@ -69,9 +60,8 @@ uint32_t AclintMswi::read_reg32(Offset source, AccessEffects type) const { uint32_t value = 0; - if ((source >= ACLINT_MSWI_OFFSET) && - (source < ACLINT_MSWI_OFFSET + 4 * mswi_count)) { - value = mswi_value[source >> 2]? 1: 0; + if ((source >= ACLINT_MSWI_OFFSET) && (source < ACLINT_MSWI_OFFSET + 4 * mswi_count)) { + value = mswi_value[source >> 2] ? 1 : 0; } emit read_notification(source, value); @@ -84,8 +74,8 @@ bool AclintMswi::write_reg32(Offset destination, uint32_t value) { bool changed = false; - if ((destination >= ACLINT_MSWI_OFFSET) && - (destination < ACLINT_MSWI_OFFSET + 4 * mswi_count)) { + if ((destination >= ACLINT_MSWI_OFFSET) + && (destination < ACLINT_MSWI_OFFSET + 4 * mswi_count)) { bool value_bool = value & 1; changed = value_bool != mswi_value[destination >> 2]; mswi_value[destination >> 2] = value_bool; @@ -99,12 +89,10 @@ bool AclintMswi::write_reg32(Offset destination, uint32_t value) { return changed; } LocationStatus AclintMswi::location_status(Offset offset) const { - - if ((offset >= ACLINT_MSWI_OFFSET) && - (offset < ACLINT_MSWI_OFFSET + 4 * mswi_count)) + if ((offset >= ACLINT_MSWI_OFFSET) && (offset < ACLINT_MSWI_OFFSET + 4 * mswi_count)) return LOCSTAT_NONE; return LOCSTAT_ILLEGAL; } -} // namespace machine aclint +} // namespace machine::aclint diff --git a/src/machine/memory/backend/aclintmswi.h b/src/machine/memory/backend/aclintmswi.h index df6b2178..9a390626 100644 --- a/src/machine/memory/backend/aclintmswi.h +++ b/src/machine/memory/backend/aclintmswi.h @@ -4,17 +4,16 @@ #include "common/endian.h" #include "memory/backend/backend_memory.h" -#include - #include +#include namespace machine::aclint { -constexpr Offset CLINT_MSWI_OFFSET = 0x0000u; -constexpr Offset CLINT_MSWI_SIZE = 0x4000u; +constexpr Offset CLINT_MSWI_OFFSET = 0x0000u; +constexpr Offset CLINT_MSWI_SIZE = 0x4000u; -constexpr Offset ACLINT_MSWI_OFFSET = 0; -constexpr Offset ACLINT_MSWI_COUNT_MAX = 1; +constexpr Offset ACLINT_MSWI_OFFSET = 0; +constexpr Offset ACLINT_MSWI_COUNT_MAX = 1; // Timer interrupts // mip.MTIP and mie.MTIE are bit 7 @@ -36,17 +35,11 @@ class AclintMswi : public BackendMemory { void signal_interrupt(uint irq_level, bool active) const; public: - WriteResult write( - Offset destination, - const void *source, - size_t size, - WriteOptions options) override; - - ReadResult read( - void *destination, - Offset source, - size_t size, - ReadOptions options) const override; + WriteResult + write(Offset destination, const void *source, size_t size, WriteOptions options) override; + + ReadResult + read(void *destination, Offset source, size_t size, ReadOptions options) const override; [[nodiscard]] LocationStatus location_status(Offset offset) const override; @@ -60,12 +53,12 @@ class AclintMswi : public BackendMemory { bool update_mswi_irq(); unsigned mswi_count; - bool mswi_value[ACLINT_MSWI_COUNT_MAX]{}; + bool mswi_value[ACLINT_MSWI_COUNT_MAX] {}; const uint8_t mswi_irq_level; bool mswi_irq_active = false; }; -} // namespace machine aclint +} // namespace machine::aclint #endif // ACLINTMSWI_H diff --git a/src/machine/memory/backend/aclintsswi.cpp b/src/machine/memory/backend/aclintsswi.cpp index 0f6936cf..88e7df98 100644 --- a/src/machine/memory/backend/aclintsswi.cpp +++ b/src/machine/memory/backend/aclintsswi.cpp @@ -2,95 +2,80 @@ #include "common/endian.h" -#include #include +#include using ae = machine::AccessEffects; // For enum values, type is obvious from // context. -namespace machine { namespace aclint { - -AclintSswi::AclintSswi(Endian simulated_machine_endian) - : BackendMemory(simulated_machine_endian) - , sswi_irq_level(1) -{ - sswi_count = 1; -} +namespace machine { namespace aclint { -AclintSswi::~AclintSswi() = default; + AclintSswi::AclintSswi(Endian simulated_machine_endian) + : BackendMemory(simulated_machine_endian) + , sswi_irq_level(1) { + sswi_count = 1; + } + AclintSswi::~AclintSswi() = default; + + WriteResult + AclintSswi::write(Offset destination, const void *source, size_t size, WriteOptions options) { + UNUSED(options) + return write_by_u32( + destination, source, size, + [&](Offset src) { + return byteswap_if( + read_reg32(src, options.type), internal_endian != simulated_machine_endian); + }, + [&](Offset src, uint32_t value) { + return write_reg32( + src, byteswap_if(value, internal_endian != simulated_machine_endian)); + }); + } -WriteResult AclintSswi::write( - Offset destination, - const void *source, - size_t size, - WriteOptions options) { - UNUSED(options) - return write_by_u32( - destination, source, size, - [&](Offset src) { + ReadResult + AclintSswi::read(void *destination, Offset source, size_t size, ReadOptions options) const { + return read_by_u32(destination, source, size, [&](Offset src) { return byteswap_if( read_reg32(src, options.type), internal_endian != simulated_machine_endian); - }, - [&](Offset src, uint32_t value) { - return write_reg32( - src, byteswap_if( - value, internal_endian != simulated_machine_endian)); }); -} - -ReadResult AclintSswi::read( - void *destination, - Offset source, - size_t size, - ReadOptions options) const { - return read_by_u32(destination, source, size, [&](Offset src) { - return byteswap_if( - read_reg32(src, options.type), - internal_endian != simulated_machine_endian); - }); -} - -uint32_t AclintSswi::read_reg32(Offset source, AccessEffects type) const { - Q_UNUSED(type) - Q_ASSERT((source & 3U) == 0); // uint32_t aligned - - uint32_t value = 0; - - if ((source >= ACLINT_SSWI_OFFSET) && - (source < ACLINT_SSWI_OFFSET + 4 * sswi_count)) { } - emit read_notification(source, value); + uint32_t AclintSswi::read_reg32(Offset source, AccessEffects type) const { + Q_UNUSED(type) + Q_ASSERT((source & 3U) == 0); // uint32_t aligned - return value; -} + uint32_t value = 0; -bool AclintSswi::write_reg32(Offset destination, uint32_t value) { - Q_ASSERT((destination & 3U) == 0); // uint32_t aligned + if ((source >= ACLINT_SSWI_OFFSET) && (source < ACLINT_SSWI_OFFSET + 4 * sswi_count)) {} - bool changed = false; + emit read_notification(source, value); - if ((destination >= ACLINT_SSWI_OFFSET) && - (destination < ACLINT_SSWI_OFFSET + 4 * sswi_count)) { - bool value_bool = value & 1; - if (value_bool) - emit signal_interrupt(sswi_irq_level, value_bool); - } else { - printf("WARNING: ACLINT SSWI - read out of range (at 0x%zu).\n", destination); + return value; } - emit write_notification(destination, value); + bool AclintSswi::write_reg32(Offset destination, uint32_t value) { + Q_ASSERT((destination & 3U) == 0); // uint32_t aligned - return changed; -} -LocationStatus AclintSswi::location_status(Offset offset) const { + bool changed = false; - if ((offset >= ACLINT_SSWI_OFFSET) && - (offset < ACLINT_SSWI_OFFSET + 4 * sswi_count)) - return LOCSTAT_NONE; + if ((destination >= ACLINT_SSWI_OFFSET) + && (destination < ACLINT_SSWI_OFFSET + 4 * sswi_count)) { + bool value_bool = value & 1; + if (value_bool) emit signal_interrupt(sswi_irq_level, value_bool); + } else { + printf("WARNING: ACLINT SSWI - read out of range (at 0x%zu).\n", destination); + } - return LOCSTAT_ILLEGAL; -} + emit write_notification(destination, value); + + return changed; + } + LocationStatus AclintSswi::location_status(Offset offset) const { + if ((offset >= ACLINT_SSWI_OFFSET) && (offset < ACLINT_SSWI_OFFSET + 4 * sswi_count)) + return LOCSTAT_NONE; + + return LOCSTAT_ILLEGAL; + } -} } // namespace machine aclint +}} // namespace machine::aclint diff --git a/src/machine/memory/backend/aclintsswi.h b/src/machine/memory/backend/aclintsswi.h index c1c31204..03f45024 100644 --- a/src/machine/memory/backend/aclintsswi.h +++ b/src/machine/memory/backend/aclintsswi.h @@ -4,17 +4,16 @@ #include "common/endian.h" #include "memory/backend/backend_memory.h" -#include - #include +#include namespace machine::aclint { -constexpr Offset CLINT_SSWI_OFFSET = 0xc000u; -constexpr Offset CLINT_SSWI_SIZE = 0x4000u; +constexpr Offset CLINT_SSWI_OFFSET = 0xc000u; +constexpr Offset CLINT_SSWI_SIZE = 0x4000u; -constexpr Offset ACLINT_SSWI_OFFSET = 0; -constexpr Offset ACLINT_SSWI_COUNT_MAX = 1; +constexpr Offset ACLINT_SSWI_OFFSET = 0; +constexpr Offset ACLINT_SSWI_COUNT_MAX = 1; // Timer interrupts // mip.MTIP and mie.MTIE are bit 7 @@ -36,17 +35,11 @@ class AclintSswi : public BackendMemory { void signal_interrupt(uint irq_level, bool active) const; public: - WriteResult write( - Offset destination, - const void *source, - size_t size, - WriteOptions options) override; - - ReadResult read( - void *destination, - Offset source, - size_t size, - ReadOptions options) const override; + WriteResult + write(Offset destination, const void *source, size_t size, WriteOptions options) override; + + ReadResult + read(void *destination, Offset source, size_t size, ReadOptions options) const override; [[nodiscard]] LocationStatus location_status(Offset offset) const override; @@ -62,6 +55,6 @@ class AclintSswi : public BackendMemory { const uint8_t sswi_irq_level; }; -} // namespace machine aclint +} // namespace machine::aclint #endif // ACLINTSSWI_H diff --git a/src/machine/memory/backend/backend_memory.h b/src/machine/memory/backend/backend_memory.h index 2e34cc45..23a294d9 100644 --- a/src/machine/memory/backend/backend_memory.h +++ b/src/machine/memory/backend/backend_memory.h @@ -61,11 +61,8 @@ class BackendMemory : public QObject { * @param size number of bytes to be written * @return true when memory before and after write differs */ - virtual WriteResult write( - Offset destination, - const void *source, - size_t size, - WriteOptions options) + virtual WriteResult + write(Offset destination, const void *source, size_t size, WriteOptions options) = 0; /** @@ -77,11 +74,8 @@ class BackendMemory : public QObject { * @param options additional option like debug mode, see type * definition */ - virtual ReadResult read( - void *destination, - Offset source, - size_t size, - ReadOptions options) const = 0; + virtual ReadResult read(void *destination, Offset source, size_t size, ReadOptions options) const + = 0; /** * Determine status of given address. diff --git a/src/machine/memory/backend/lcddisplay.cpp b/src/machine/memory/backend/lcddisplay.cpp index d55f5bfd..944a887e 100644 --- a/src/machine/memory/backend/lcddisplay.cpp +++ b/src/machine/memory/backend/lcddisplay.cpp @@ -20,43 +20,32 @@ LcdDisplay::LcdDisplay(Endian simulated_machine_endian) LcdDisplay::~LcdDisplay() = default; -WriteResult LcdDisplay::write( - Offset destination, - const void *source, - size_t size, - WriteOptions options) { +WriteResult +LcdDisplay::write(Offset destination, const void *source, size_t size, WriteOptions options) { UNUSED(options) return write_by_u16( destination, source, size, [&](Offset src) { - return byteswap_if( - read_raw_pixel(src), internal_endian != simulated_machine_endian); + return byteswap_if(read_raw_pixel(src), internal_endian != simulated_machine_endian); }, [&](Offset src, uint16_t value) { return write_raw_pixel( - src, byteswap_if( - value, internal_endian != simulated_machine_endian)); + src, byteswap_if(value, internal_endian != simulated_machine_endian)); }); } -ReadResult LcdDisplay::read( - void *destination, - Offset source, - size_t size, - ReadOptions options) const { +ReadResult +LcdDisplay::read(void *destination, Offset source, size_t size, ReadOptions options) const { UNUSED(options) return read_by_u16(destination, source, size, [&](Offset src) { - return byteswap_if( - read_raw_pixel(src), internal_endian != simulated_machine_endian); + return byteswap_if(read_raw_pixel(src), internal_endian != simulated_machine_endian); }); } uint16_t LcdDisplay::read_raw_pixel(Offset source) const { Q_ASSERT((source & 1U) == 0); // uint16_t aligned - if (source + 1 >= get_fb_size_bytes()) { - return 0; - } + if (source + 1 >= get_fb_size_bytes()) { return 0; } uint16_t value; memcpy(&value, &fb_data[source], sizeof(value)); @@ -64,8 +53,8 @@ uint16_t LcdDisplay::read_raw_pixel(Offset source) const { // TODO Switch to if constexpr as soon as we have cpp17. if (DEBUG_LCD) { printf( - "LcdDisplay::read_reg address 0x%08lx data 0x%08lx\n", - (unsigned long)source, (unsigned long)value); + "LcdDisplay::read_reg address 0x%08lx data 0x%08lx\n", (unsigned long)source, + (unsigned long)value); } emit read_notification(source, value); @@ -83,13 +72,11 @@ bool LcdDisplay::write_raw_pixel(Offset destination, uint16_t value) { // TODO Switch to if constexpr as soon as we have cpp17. if (DEBUG_LCD) { printf( - "LcdDisplay::write_reg address 0x%08lx data 0x%08lx\n", - (unsigned long)destination, (unsigned long)value); + "LcdDisplay::write_reg address 0x%08lx data 0x%08lx\n", (unsigned long)destination, + (unsigned long)value); } - if (read_raw_pixel(destination) == value) { - return false; - } + if (read_raw_pixel(destination) == value) { return false; } memcpy(&fb_data[destination], &value, sizeof(value)); @@ -132,12 +119,10 @@ size_t LcdDisplay::get_address_from_pixel(size_t x, size_t y) const { return address; } -std::tuple -LcdDisplay::get_pixel_from_address(size_t address) const { +std::tuple LcdDisplay::get_pixel_from_address(size_t address) const { size_t y = address / get_fb_line_size(); size_t x = (fb_bits_per_pixel > 12) - ? (address - y * get_fb_line_size()) - / ((fb_bits_per_pixel + 7) >> 3u) + ? (address - y * get_fb_line_size()) / ((fb_bits_per_pixel + 7) >> 3u) : (address - y * get_fb_line_size()) * 8 / fb_bits_per_pixel; return std::make_tuple(x, y); } @@ -151,9 +136,7 @@ size_t LcdDisplay::get_fb_size_bytes() const { return get_fb_line_size() * fb_height; } LocationStatus LcdDisplay::location_status(Offset offset) const { - if ((offset | ~3u) >= get_fb_size_bytes()) { - return LOCSTAT_ILLEGAL; - } + if ((offset | ~3u) >= get_fb_size_bytes()) { return LOCSTAT_ILLEGAL; } return LOCSTAT_NONE; } diff --git a/src/machine/memory/backend/lcddisplay.h b/src/machine/memory/backend/lcddisplay.h index 31ed370b..85aae25b 100644 --- a/src/machine/memory/backend/lcddisplay.h +++ b/src/machine/memory/backend/lcddisplay.h @@ -24,33 +24,23 @@ class LcdDisplay final : public BackendMemory { void pixel_update(size_t x, size_t y, uint r, uint g, uint b); public: - WriteResult write( - Offset destination, - const void *source, - size_t size, - WriteOptions options) override; - - ReadResult read( - void *destination, - Offset source, - size_t size, - ReadOptions options) const override; + WriteResult + write(Offset destination, const void *source, size_t size, WriteOptions options) override; + + ReadResult + read(void *destination, Offset source, size_t size, ReadOptions options) const override; [[nodiscard]] LocationStatus location_status(Offset offset) const override; /** * @return framebuffer width in pixels */ - [[nodiscard]] inline constexpr size_t get_width() const { - return fb_width; - } + [[nodiscard]] inline constexpr size_t get_width() const { return fb_width; } /** * @return framebuffer height in pixels */ - [[nodiscard]] inline constexpr size_t get_height() const { - return fb_height; - } + [[nodiscard]] inline constexpr size_t get_height() const { return fb_height; } private: /** Endian internal registers of the periphery (framebuffer) use. */ diff --git a/src/machine/memory/backend/memory.cpp b/src/machine/memory/backend/memory.cpp index 9d618ada..f7cf616e 100644 --- a/src/machine/memory/backend/memory.cpp +++ b/src/machine/memory/backend/memory.cpp @@ -7,9 +7,7 @@ namespace machine { -MemorySection::MemorySection( - size_t length_bytes, - Endian simulated_machine_endian) +MemorySection::MemorySection(size_t length_bytes, Endian simulated_machine_endian) : BackendMemory(simulated_machine_endian) , dt(length_bytes, 0) {} @@ -17,7 +15,8 @@ MemorySection::MemorySection(const MemorySection &other) : BackendMemory(other.simulated_machine_endian) , dt(other.dt) {} -WriteResult MemorySection::write(Offset dst_offset, const void *source, size_t size, WriteOptions options) { +WriteResult +MemorySection::write(Offset dst_offset, const void *source, size_t size, WriteOptions options) { UNUSED(options) auto destination = static_cast(dst_offset); @@ -33,14 +32,13 @@ WriteResult MemorySection::write(Offset dst_offset, const void *source, size_t s // TODO, make swap conditional for big endian machines bool changed = memcmp(source, &dt[destination], available_size) != 0; - if (changed) { - memcpy(&dt[destination], source, available_size); - } + if (changed) { memcpy(&dt[destination], source, available_size); } return { .n_bytes = available_size, .changed = changed }; } -ReadResult MemorySection::read(void *destination, Offset src_offset, size_t size, ReadOptions options) const { +ReadResult +MemorySection::read(void *destination, Offset src_offset, size_t size, ReadOptions options) const { UNUSED(options) auto source = static_cast(src_offset); @@ -80,12 +78,8 @@ bool MemorySection::operator!=(const MemorySection &ms) const { } // Settings sanity checks -static_assert( - MEMORY_SECTION_SIZE != 0, - "Nonzero memory section size is required."); -static_assert( - MEMORY_TREE_ROW_SIZE != 0, - "Nonzero memory tree row size is required."); +static_assert(MEMORY_SECTION_SIZE != 0, "Nonzero memory section size is required."); +static_assert(MEMORY_TREE_ROW_SIZE != 0, "Nonzero memory tree row size is required."); static_assert( ((32 - MEMORY_SECTION_BITS) % MEMORY_TREE_BITS) == 0, "Number of bits in tree row has to be exact division of available number " @@ -125,13 +119,11 @@ Memory::Memory() : BackendMemory(BIG) { this->mt_root = nullptr; } -Memory::Memory(Endian simulated_machine_endian) - : BackendMemory(simulated_machine_endian) { +Memory::Memory(Endian simulated_machine_endian) : BackendMemory(simulated_machine_endian) { this->mt_root = allocate_section_tree(); } -Memory::Memory(const Memory &other) - : BackendMemory(other.simulated_machine_endian) { +Memory::Memory(const Memory &other) : BackendMemory(other.simulated_machine_endian) { this->mt_root = copy_section_tree(other.get_memory_tree_root(), 0); } @@ -170,11 +162,8 @@ MemorySection *Memory::get_section(size_t offset, bool create) const { } row_num = get_tree_row(offset, MEMORY_TREE_DEPTH - 1); if (w[row_num].sec == nullptr) { - if (!create) { - return nullptr; - } - w[row_num].sec - = new MemorySection(MEMORY_SECTION_SIZE, simulated_machine_endian); + if (!create) { return nullptr; } + w[row_num].sec = new MemorySection(MEMORY_SECTION_SIZE, simulated_machine_endian); } return w[row_num].sec; } @@ -183,32 +172,21 @@ size_t get_section_offset_mask(size_t addr) { return addr & generate_mask(MEMORY_SECTION_BITS, 0); } -WriteResult Memory::write( - Offset destination, - const void *source, - size_t size, - WriteOptions options) { +WriteResult +Memory::write(Offset destination, const void *source, size_t size, WriteOptions options) { return repeat_access_until_completed( destination, source, size, options, - [this]( - Offset _destination, const void *_source, size_t _size, - WriteOptions) { + [this](Offset _destination, const void *_source, size_t _size, WriteOptions) { MemorySection *section = this->get_section(_destination, true); - return section->write( - get_section_offset_mask(_destination), _source, _size, {}); + return section->write(get_section_offset_mask(_destination), _source, _size, {}); }); } -ReadResult Memory::read( - void *destination, - Offset source, - size_t size, - ReadOptions options) const { +ReadResult Memory::read(void *destination, Offset source, size_t size, ReadOptions options) const { return repeat_access_until_completed( destination, source, size, options, [this]( - void *_destination, Offset _source, size_t _size, - ReadOptions _options) -> ReadResult { + void *_destination, Offset _source, size_t _size, ReadOptions _options) -> ReadResult { MemorySection *section = this->get_section(_source, false); if (section == nullptr) { memset(_destination, 0, _size); @@ -216,8 +194,7 @@ ReadResult Memory::read( return { .n_bytes = _size }; } else { return section->read( - _destination, get_section_offset_mask(_source), _size, - _options); + _destination, get_section_offset_mask(_source), _size, _options); } }); } @@ -268,17 +245,14 @@ bool Memory::compare_section_tree( if (((mt1[i].subtree == nullptr || mt2[i].subtree == nullptr) && mt1[i].subtree != mt2[i].subtree) || (mt1[i].subtree != nullptr && mt2[i].subtree != nullptr - && !compare_section_tree( - mt1[i].subtree, mt2[i].subtree, depth + 1))) { + && !compare_section_tree(mt1[i].subtree, mt2[i].subtree, depth + 1))) { return false; } } } else { // Following level is memory section for (size_t i = 0; i < MEMORY_TREE_ROW_SIZE; i++) { - if (((mt1[i].sec == nullptr || mt2[i].sec == nullptr) - && mt1[i].sec != mt2[i].sec) - || (mt1[i].sec != nullptr && mt2[i].sec != nullptr - && *mt1[i].sec != *mt2[i].sec)) { + if (((mt1[i].sec == nullptr || mt2[i].sec == nullptr) && mt1[i].sec != mt2[i].sec) + || (mt1[i].sec != nullptr && mt2[i].sec != nullptr && *mt1[i].sec != *mt2[i].sec)) { return false; } } @@ -286,8 +260,7 @@ bool Memory::compare_section_tree( return true; } -union machine::MemoryTree * -Memory::copy_section_tree(const union MemoryTree *mt, size_t depth) { +union machine::MemoryTree *Memory::copy_section_tree(const union MemoryTree *mt, size_t depth) { union MemoryTree *nmt = allocate_section_tree(); if (depth < (MEMORY_TREE_DEPTH - 1)) { // Following level is memory tree for (size_t i = 0; i < MEMORY_TREE_ROW_SIZE; i++) { @@ -297,9 +270,7 @@ Memory::copy_section_tree(const union MemoryTree *mt, size_t depth) { } } else { // Following level is memory section for (size_t i = 0; i < MEMORY_TREE_ROW_SIZE; i++) { - if (mt[i].sec != nullptr) { - nmt[i].sec = new MemorySection(*mt[i].sec); - } + if (mt[i].sec != nullptr) { nmt[i].sec = new MemorySection(*mt[i].sec); } } } return nmt; diff --git a/src/machine/memory/backend/memory.h b/src/machine/memory/backend/memory.h index 0199afd9..0555edcb 100644 --- a/src/machine/memory/backend/memory.h +++ b/src/machine/memory/backend/memory.h @@ -24,17 +24,11 @@ class MemorySection final : public BackendMemory { MemorySection(const MemorySection &other); ~MemorySection() override = default; - WriteResult write( - Offset destination, - const void *source, - size_t total_size, - WriteOptions options) override; - - ReadResult read( - void *destination, - Offset source, - size_t size, - ReadOptions options) const override; + WriteResult + write(Offset destination, const void *source, size_t total_size, WriteOptions options) override; + + ReadResult + read(void *destination, Offset source, size_t size, ReadOptions options) const override; [[nodiscard]] LocationStatus location_status(Offset offset) const override; @@ -60,8 +54,7 @@ constexpr size_t MEMORY_SECTION_SIZE = (1u << MEMORY_SECTION_BITS); // Size of one memory row constexpr size_t MEMORY_TREE_ROW_SIZE = (1u << MEMORY_TREE_BITS); // Depth of tree -constexpr size_t MEMORY_TREE_DEPTH - = ((32 - MEMORY_SECTION_BITS) / MEMORY_TREE_BITS); +constexpr size_t MEMORY_TREE_DEPTH = ((32 - MEMORY_SECTION_BITS) / MEMORY_TREE_BITS); union MemoryTree { union MemoryTree *subtree; @@ -87,17 +80,11 @@ class Memory final : public BackendMemory { // returns section containing given address [[nodiscard]] MemorySection *get_section(size_t offset, bool create) const; - WriteResult write( - Offset destination, - const void *source, - size_t size, - WriteOptions options) override; + WriteResult + write(Offset destination, const void *source, size_t size, WriteOptions options) override; - ReadResult read( - void *destination, - Offset source, - size_t size, - ReadOptions options) const override; + ReadResult + read(void *destination, Offset source, size_t size, ReadOptions options) const override; [[nodiscard]] LocationStatus location_status(Offset offset) const override; @@ -111,12 +98,9 @@ class Memory final : public BackendMemory { uint32_t change_counter = 0; static union MemoryTree *allocate_section_tree(); static void free_section_tree(union MemoryTree *, size_t depth); - static bool compare_section_tree( - const union MemoryTree *, - const union MemoryTree *, - size_t depth); - static union MemoryTree * - copy_section_tree(const union MemoryTree *, size_t depth); + static bool + compare_section_tree(const union MemoryTree *, const union MemoryTree *, size_t depth); + static union MemoryTree *copy_section_tree(const union MemoryTree *, size_t depth); [[nodiscard]] uint32_t get_change_counter() const; }; } // namespace machine diff --git a/src/machine/memory/backend/memory.test.cpp b/src/machine/memory/backend/memory.test.cpp index 2ded34a3..a7c3c7fc 100644 --- a/src/machine/memory/backend/memory.test.cpp +++ b/src/machine/memory/backend/memory.test.cpp @@ -351,8 +351,8 @@ void TestMemory::memory_memtest() { uint64_t range_to_test = 128 * 1024; - if (frontend_address.get_raw() < 0x100000000 && - 0x100000000 - range_to_test < frontend_address.get_raw()) + if (frontend_address.get_raw() < 0x100000000 + && 0x100000000 - range_to_test < frontend_address.get_raw()) range_to_test = uint64_t(Address(0x100000000) - frontend_address); for (uint64_t o = 0; o < range_to_test; o += 4) { diff --git a/src/machine/memory/backend/peripheral.cpp b/src/machine/memory/backend/peripheral.cpp index 851b062c..33a2f52e 100644 --- a/src/machine/memory/backend/peripheral.cpp +++ b/src/machine/memory/backend/peripheral.cpp @@ -9,11 +9,8 @@ SimplePeripheral::SimplePeripheral(Endian simulated_machine_endian) SimplePeripheral::~SimplePeripheral() = default; -WriteResult SimplePeripheral::write( - Offset destination, - const void *source, - size_t size, - WriteOptions options) { +WriteResult +SimplePeripheral::write(Offset destination, const void *source, size_t size, WriteOptions options) { UNUSED(source) UNUSED(options) @@ -24,11 +21,8 @@ WriteResult SimplePeripheral::write( return { size, false }; } -ReadResult SimplePeripheral::read( - void *destination, - Offset source, - size_t size, - ReadOptions options) const { +ReadResult +SimplePeripheral::read(void *destination, Offset source, size_t size, ReadOptions options) const { UNUSED(options) memset(destination, 0x12, size); // Random value @@ -41,4 +35,3 @@ LocationStatus SimplePeripheral::location_status(Offset offset) const { UNUSED(offset) return LOCSTAT_NONE; } - diff --git a/src/machine/memory/backend/peripheral.h b/src/machine/memory/backend/peripheral.h index cc1225e9..9b930dbf 100644 --- a/src/machine/memory/backend/peripheral.h +++ b/src/machine/memory/backend/peripheral.h @@ -29,17 +29,11 @@ class SimplePeripheral final : public BackendMemory { void read_notification(Offset address, size_t size) const; public: - WriteResult write( - Offset destination, - const void *source, - size_t size, - WriteOptions options) override; - - ReadResult read( - void *destination, - Offset source, - size_t size, - ReadOptions options) const override; + WriteResult + write(Offset destination, const void *source, size_t size, WriteOptions options) override; + + ReadResult + read(void *destination, Offset source, size_t size, ReadOptions options) const override; [[nodiscard]] LocationStatus location_status(Offset offset) const override; }; diff --git a/src/machine/memory/backend/peripspiled.cpp b/src/machine/memory/backend/peripspiled.cpp index 2cebc1ce..6df12519 100644 --- a/src/machine/memory/backend/peripspiled.cpp +++ b/src/machine/memory/backend/peripspiled.cpp @@ -17,34 +17,24 @@ PeripSpiLed::PeripSpiLed(Endian simulated_machine_endian) PeripSpiLed::~PeripSpiLed() = default; -WriteResult PeripSpiLed::write( - Offset destination, - const void *source, - size_t size, - WriteOptions options) { +WriteResult +PeripSpiLed::write(Offset destination, const void *source, size_t size, WriteOptions options) { UNUSED(options) return write_by_u32( destination, source, size, [&](Offset src) { - return byteswap_if( - read_reg(src), internal_endian != simulated_machine_endian); + return byteswap_if(read_reg(src), internal_endian != simulated_machine_endian); }, [&](Offset src, uint32_t value) { - return write_reg( - src, byteswap_if( - value, internal_endian != simulated_machine_endian)); + return write_reg(src, byteswap_if(value, internal_endian != simulated_machine_endian)); }); } -ReadResult PeripSpiLed::read( - void *destination, - Offset source, - size_t size, - ReadOptions options) const { +ReadResult +PeripSpiLed::read(void *destination, Offset source, size_t size, ReadOptions options) const { UNUSED(options) return read_by_u32(destination, source, size, [&](Offset src) { - return byteswap_if( - read_reg(src), internal_endian != simulated_machine_endian); + return byteswap_if(read_reg(src), internal_endian != simulated_machine_endian); }); } @@ -56,8 +46,7 @@ uint32_t PeripSpiLed::read_reg(Offset source) const { case SPILED_REG_LED_RGB1_o: return spiled_reg_led_rgb1; case SPILED_REG_LED_RGB2_o: return spiled_reg_led_rgb2; case SPILED_REG_LED_KBDWR_DIRECT_o: return spiled_reg_led_kbdwr_direct; - case SPILED_REG_KBDRD_KNOBS_DIRECT_o: - return spiled_reg_kbdrd_knobs_direct; + case SPILED_REG_KBDRD_KNOBS_DIRECT_o: return spiled_reg_kbdrd_knobs_direct; case SPILED_REG_KNOBS_8BIT_o: return spiled_reg_knobs_8bit; default: // Todo show this to user as this is failure of supplied program @@ -114,9 +103,7 @@ void PeripSpiLed::knob_update_notify(uint32_t val, uint32_t mask, size_t shift) mask <<= shift; val <<= shift; - if (!((spiled_reg_knobs_8bit ^ val) & mask)) { - return; - } + if (!((spiled_reg_knobs_8bit ^ val) & mask)) { return; } spiled_reg_knobs_8bit &= ~mask; spiled_reg_knobs_8bit |= val; diff --git a/src/machine/memory/backend/peripspiled.h b/src/machine/memory/backend/peripspiled.h index 7a4c1369..2a073b1a 100644 --- a/src/machine/memory/backend/peripspiled.h +++ b/src/machine/memory/backend/peripspiled.h @@ -34,17 +34,11 @@ public slots: void blue_knob_push(bool state); public: - WriteResult write( - Offset destination, - const void *source, - size_t size, - WriteOptions options) override; + WriteResult + write(Offset destination, const void *source, size_t size, WriteOptions options) override; - ReadResult read( - void *destination, - Offset source, - size_t size, - ReadOptions options) const override; + ReadResult + read(void *destination, Offset source, size_t size, ReadOptions options) const override; [[nodiscard]] LocationStatus location_status(Offset offset) const override; diff --git a/src/machine/memory/backend/serialport.cpp b/src/machine/memory/backend/serialport.cpp index 7cd7758c..6d4ef9a9 100644 --- a/src/machine/memory/backend/serialport.cpp +++ b/src/machine/memory/backend/serialport.cpp @@ -27,8 +27,7 @@ SerialPort::SerialPort(Endian simulated_machine_endian) : BackendMemory(simulated_machine_endian) , tx_irq_level(17) // The second platform HW interrupt , rx_irq_level(16) // The first platform HW interrupt - , tx_st_reg(SERP_TX_ST_REG_READY_m) -{} + , tx_st_reg(SERP_TX_ST_REG_READY_m) {} SerialPort::~SerialPort() = default; @@ -47,11 +46,8 @@ void SerialPort::pool_rx_byte() const { } } -WriteResult SerialPort::write( - Offset destination, - const void *source, - size_t size, - WriteOptions options) { +WriteResult +SerialPort::write(Offset destination, const void *source, size_t size, WriteOptions options) { UNUSED(options) return write_by_u32( destination, source, size, @@ -60,21 +56,15 @@ WriteResult SerialPort::write( return 0; }, [&](Offset src, uint32_t value) { - return write_reg( - src, byteswap_if( - value, internal_endian != simulated_machine_endian)); + return write_reg(src, byteswap_if(value, internal_endian != simulated_machine_endian)); }); } -ReadResult SerialPort::read( - void *destination, - Offset source, - size_t size, - ReadOptions options) const { +ReadResult +SerialPort::read(void *destination, Offset source, size_t size, ReadOptions options) const { return read_by_u32(destination, source, size, [&](Offset src) { return byteswap_if( - read_reg(src, options.type), - internal_endian != simulated_machine_endian); + read_reg(src, options.type), internal_endian != simulated_machine_endian); }); } @@ -88,9 +78,7 @@ void SerialPort::update_rx_irq() const { } void SerialPort::rx_queue_check_internal() const { - if (rx_st_reg & SERP_RX_ST_REG_IE_m) { - pool_rx_byte(); - } + if (rx_st_reg & SERP_RX_ST_REG_IE_m) { pool_rx_byte(); } update_rx_irq(); } diff --git a/src/machine/memory/backend/serialport.h b/src/machine/memory/backend/serialport.h index e663795c..30615059 100644 --- a/src/machine/memory/backend/serialport.h +++ b/src/machine/memory/backend/serialport.h @@ -27,17 +27,11 @@ public slots: void rx_queue_check() const; public: - WriteResult write( - Offset destination, - const void *source, - size_t size, - WriteOptions options) override; + WriteResult + write(Offset destination, const void *source, size_t size, WriteOptions options) override; - ReadResult read( - void *destination, - Offset source, - size_t size, - ReadOptions options) const override; + ReadResult + read(void *destination, Offset source, size_t size, ReadOptions options) const override; LocationStatus location_status(Offset offset) const override; diff --git a/src/machine/memory/cache/cache.cpp b/src/machine/memory/cache/cache.cpp index b48719a0..2348ec35 100644 --- a/src/machine/memory/cache/cache.cpp +++ b/src/machine/memory/cache/cache.cpp @@ -27,27 +27,21 @@ Cache::Cache( , access_ena_b(memory_access_enable_b) , replacement_policy(CachePolicy::get_policy_instance(config)) { // Skip memory allocation if cache is disabled - if (!config->enabled()) { - return; - } + if (!config->enabled()) { return; } dt.resize( config->associativity(), std::vector( - config->set_count(), - { .valid = false, - .dirty = false, - .tag = 0, - .data = std::vector(config->block_size()) })); + config->set_count(), { .valid = false, + .dirty = false, + .tag = 0, + .data = std::vector(config->block_size()) })); } Cache::~Cache() = default; -WriteResult Cache::write( - Address destination, - const void *source, - size_t size, - WriteOptions options) { +WriteResult +Cache::write(Address destination, const void *source, size_t size, WriteOptions options) { if (!cache_config.enabled() || is_in_uncached_area(destination) || is_in_uncached_area(destination + size)) { mem_writes++; @@ -59,8 +53,7 @@ WriteResult Cache::write( // FIXME: Get rid of the cast // access is mostly the same for read and write but one needs to write // to the address - const bool changed - = access(destination, const_cast(source), size, WRITE); + const bool changed = access(destination, const_cast(source), size, WRITE); if (cache_config.write_policy() != CacheConfig::WP_BACK) { mem_writes++; @@ -72,11 +65,7 @@ WriteResult Cache::write( return { .n_bytes = size, .changed = changed }; } -ReadResult Cache::read( - void *destination, - Address source, - size_t size, - ReadOptions options) const { +ReadResult Cache::read(void *destination, Address source, size_t size, ReadOptions options) const { if (!cache_config.enabled() || is_in_uncached_area(source) || is_in_uncached_area(source + size)) { mem_reads++; @@ -103,18 +92,13 @@ bool Cache::is_in_uncached_area(Address source) const { } void Cache::flush() { - if (!cache_config.enabled()) { - return; - } + if (!cache_config.enabled()) { return; } - for (size_t assoc_index = 0; assoc_index < cache_config.associativity(); - assoc_index += 1) { - for (size_t set_index = 0; set_index < cache_config.set_count(); - set_index += 1) { + for (size_t assoc_index = 0; assoc_index < cache_config.associativity(); assoc_index += 1) { + for (size_t set_index = 0; set_index < cache_config.set_count(); set_index += 1) { if (dt[assoc_index][set_index].valid) { kick(assoc_index, set_index); - emit cache_update( - assoc_index, set_index, 0, false, false, 0, nullptr, false); + emit cache_update(assoc_index, set_index, 0, false, false, 0, nullptr, false); } } } @@ -154,12 +138,9 @@ void Cache::reset() { update_all_statistics(); if (cache_config.enabled()) { - for (size_t assoc_index = 0; assoc_index < cache_config.associativity(); - assoc_index++) { - for (size_t set_index = 0; set_index < cache_config.set_count(); - set_index++) { - emit cache_update( - assoc_index, set_index, 0, false, false, 0, nullptr, false); + for (size_t assoc_index = 0; assoc_index < cache_config.associativity(); assoc_index++) { + for (size_t set_index = 0; set_index < cache_config.set_count(); set_index++) { + emit cache_update(assoc_index, set_index, 0, false, false, 0, nullptr, false); } } } @@ -167,32 +148,22 @@ void Cache::reset() { void Cache::internal_read(Address source, void *destination, size_t size) const { CacheLocation loc = compute_location(source); - for (size_t assoc_index = 0; assoc_index < cache_config.associativity(); - assoc_index++) { - if (dt[assoc_index][loc.row].valid - && dt[assoc_index][loc.row].tag == loc.tag) { - memcpy( - destination, - (byte *)&dt[assoc_index][loc.row].data[loc.col] + loc.byte, - size); + for (size_t assoc_index = 0; assoc_index < cache_config.associativity(); assoc_index++) { + if (dt[assoc_index][loc.row].valid && dt[assoc_index][loc.row].tag == loc.tag) { + memcpy(destination, (byte *)&dt[assoc_index][loc.row].data[loc.col] + loc.byte, size); return; } } memset(destination, 0, size); // TODO is this correct } -bool Cache::access( - Address address, - void *buffer, - size_t size, - AccessType access_type) const { +bool Cache::access(Address address, void *buffer, size_t size, AccessType access_type) const { const CacheLocation loc = compute_location(address); size_t way = find_block_index(loc); // check for zero because else last_affected_col can became // ULONG_MAX / BLOCK_ITEM_SIZE and update can take forever - if (size == 0) - return false; + if (size == 0) return false; // search failed - cache miss if (way >= cache_config.associativity()) { @@ -204,13 +175,11 @@ bool Cache::access( emit miss_update(get_miss_count()); update_all_statistics(); - const size_t size_overflow - = calculate_overflow_to_next_blocks(size, loc); + const size_t size_overflow = calculate_overflow_to_next_blocks(size, loc); if (size_overflow > 0) { const size_t size_within_block = size - size_overflow; return access( - address + size_within_block, - (byte *)buffer + size_within_block, size_overflow, + address + size_within_block, (byte *)buffer + size_within_block, size_overflow, access_type); } else { return false; @@ -221,8 +190,7 @@ bool Cache::access( kick(way, loc.row); SANITY_ASSERT( - way < cache_config.associativity(), - "Probably unimplemented replacement policy"); + way < cache_config.associativity(), "Probably unimplemented replacement policy"); } struct CacheLine &cd = dt[way][loc.row]; @@ -246,8 +214,7 @@ bool Cache::access( mem->read( cd.data.data(), calc_base_address(loc.tag, loc.row), - cache_config.block_size() * BLOCK_ITEM_SIZE, - { .type = ae::REGULAR }); + cache_config.block_size() * BLOCK_ITEM_SIZE, { .type = ae::REGULAR }); cd.valid = true; cd.dirty = false; @@ -271,14 +238,9 @@ bool Cache::access( memcpy(buffer, (byte *)&cd.data[loc.col] + loc.byte, size_within_block); } else if (access_type == WRITE) { cd.dirty = true; - changed = memcmp( - (byte *)&cd.data[loc.col] + loc.byte, buffer, - size_within_block) - != 0; + changed = memcmp((byte *)&cd.data[loc.col] + loc.byte, buffer, size_within_block) != 0; if (changed) { - memcpy( - ((byte *)&cd.data[loc.col]) + loc.byte, buffer, - size_within_block); + memcpy(((byte *)&cd.data[loc.col]) + loc.byte, buffer, size_within_block); change_counter++; } } @@ -286,22 +248,19 @@ bool Cache::access( = (loc.col * BLOCK_ITEM_SIZE + loc.byte + size_within_block - 1) / BLOCK_ITEM_SIZE; for (auto col = loc.col; col <= last_affected_col; col++) { emit cache_update( - way, loc.row, col, cd.valid, cd.dirty, cd.tag, cd.data.data(), - access_type); + way, loc.row, col, cd.valid, cd.dirty, cd.tag, cd.data.data(), access_type); } if (size_overflow > 0) { // If access overlaps single cache row, perform access to next row. changed |= access( - address + size_within_block, (byte *)buffer + size_within_block, - size_overflow, access_type); + address + size_within_block, (byte *)buffer + size_within_block, size_overflow, + access_type); } return changed; } -size_t Cache::calculate_overflow_to_next_blocks( - size_t access_size, - const CacheLocation &loc) const { +size_t Cache::calculate_overflow_to_next_blocks(size_t access_size, const CacheLocation &loc) const { return std::max( (ptrdiff_t)(loc.col * BLOCK_ITEM_SIZE + loc.byte + access_size) - (ptrdiff_t)(cache_config.block_size() * BLOCK_ITEM_SIZE), @@ -310,9 +269,8 @@ size_t Cache::calculate_overflow_to_next_blocks( size_t Cache::find_block_index(const CacheLocation &loc) const { uint32_t index = 0; - while ( - index < cache_config.associativity() - and (!dt[index][loc.row].valid or dt[index][loc.row].tag != loc.tag)) { + while (index < cache_config.associativity() + and (!dt[index][loc.row].valid or dt[index][loc.row].tag != loc.tag)) { index++; } return index; @@ -337,14 +295,12 @@ void Cache::kick(size_t way, size_t row) const { } void Cache::update_all_statistics() const { - emit statistics_update( - get_stall_count(), get_speed_improvement(), get_hit_rate()); + emit statistics_update(get_stall_count(), get_speed_improvement(), get_hit_rate()); } Address Cache::calc_base_address(size_t tag, size_t row) const { return Address( - (tag * cache_config.set_count() + row) * cache_config.block_size() - * BLOCK_ITEM_SIZE); + (tag * cache_config.set_count() + row) * cache_config.block_size() * BLOCK_ITEM_SIZE); } CacheLocation Cache::compute_location(Address address) const { @@ -374,10 +330,8 @@ enum LocationStatus Cache::location_status(Address address) const { auto const &block = set[loc.row]; if (block.valid && block.tag == loc.tag) { - if (block.dirty - && cache_config.write_policy() == CacheConfig::WP_BACK) { - return (enum LocationStatus)( - LOCSTAT_CACHED | LOCSTAT_DIRTY); + if (block.dirty && cache_config.write_policy() == CacheConfig::WP_BACK) { + return (enum LocationStatus)(LOCSTAT_CACHED | LOCSTAT_DIRTY); } else { return LOCSTAT_CACHED; } @@ -412,8 +366,7 @@ uint32_t Cache::get_write_count() const { } uint32_t Cache::get_stall_count() const { - uint32_t st_cycles - = mem_reads * (access_pen_r - 1) + mem_writes * (access_pen_w - 1); + uint32_t st_cycles = mem_reads * (access_pen_r - 1) + mem_writes * (access_pen_w - 1); st_cycles += (miss_read + miss_write) * cache_config.block_size(); if (access_ena_b) { st_cycles -= burst_reads * (access_pen_r - access_pen_b) @@ -426,9 +379,7 @@ double Cache::get_speed_improvement() const { uint32_t lookup_time; uint32_t mem_access_time; uint32_t comp = hit_read + hit_write + miss_read + miss_write; - if (comp == 0) { - return 100.0; - } + if (comp == 0) { return 100.0; } lookup_time = hit_read + miss_read; if (cache_config.write_policy() == CacheConfig::WP_BACK) { lookup_time += hit_write + miss_write; @@ -445,9 +396,7 @@ double Cache::get_speed_improvement() const { double Cache::get_hit_rate() const { uint32_t comp = hit_read + hit_write + miss_read + miss_write; - if (comp == 0) { - return 0.0; - } + if (comp == 0) { return 0.0; } return (double)(hit_read + hit_write) / (double)comp * 100.0; } diff --git a/src/machine/memory/cache/cache.h b/src/machine/memory/cache/cache.h index dbfa0842..7b61d070 100644 --- a/src/machine/memory/cache/cache.h +++ b/src/machine/memory/cache/cache.h @@ -58,17 +58,11 @@ class Cache : public FrontendMemory { ~Cache() override; - WriteResult write( - Address destination, - const void *source, - size_t size, - WriteOptions options) override; - - ReadResult read( - void *destination, - Address source, - size_t size, - ReadOptions options) const override; + WriteResult + write(Address destination, const void *source, size_t size, WriteOptions options) override; + + ReadResult + read(void *destination, Address source, size_t size, ReadOptions options) const override; uint32_t get_change_counter() const override; @@ -94,10 +88,7 @@ class Cache : public FrontendMemory { signals: void hit_update(uint32_t) const; void miss_update(uint32_t) const; - void statistics_update( - uint32_t stalled_cycles, - double speed_improv, - double hit_rate) const; + void statistics_update(uint32_t stalled_cycles, double speed_improv, double hit_rate) const; void cache_update( size_t way, size_t row, @@ -121,17 +112,12 @@ class Cache : public FrontendMemory { mutable std::vector> dt; - mutable uint32_t hit_read = 0, miss_read = 0, hit_write = 0, miss_write = 0, - mem_reads = 0, mem_writes = 0, burst_reads = 0, - burst_writes = 0, change_counter = 0; + mutable uint32_t hit_read = 0, miss_read = 0, hit_write = 0, miss_write = 0, mem_reads = 0, + mem_writes = 0, burst_reads = 0, burst_writes = 0, change_counter = 0; void internal_read(Address source, void *destination, size_t size) const; - bool access( - Address address, - void *buffer, - size_t size, - AccessType access_type) const; + bool access(Address address, void *buffer, size_t size, AccessType access_type) const; void kick(size_t way, size_t row) const; @@ -158,9 +144,7 @@ class Cache : public FrontendMemory { * This functions calculated the size, that will have to be performed by * repeated access (recursive call of `access` method). */ - size_t calculate_overflow_to_next_blocks( - size_t access_size, - const CacheLocation &loc) const; + size_t calculate_overflow_to_next_blocks(size_t access_size, const CacheLocation &loc) const; }; } // namespace machine diff --git a/src/machine/memory/cache/cache.test.cpp b/src/machine/memory/cache/cache.test.cpp index 9f9ce042..61787763 100644 --- a/src/machine/memory/cache/cache.test.cpp +++ b/src/machine/memory/cache/cache.test.cpp @@ -7,9 +7,8 @@ #include "machine/memory/memory_bus.h" #include "tests/data/cache_test_performance_data.h" -#include - #include +#include using namespace machine; using std::array; @@ -35,7 +34,8 @@ constexpr array values { 0x4142434445464748 }; * (all combinations are tested) */ constexpr array replacement_policies { - CacheConfig::RP_RAND, CacheConfig::RP_LFU, CacheConfig::RP_LRU, CacheConfig::RP_PLRU, CacheConfig::RP_NMRU + CacheConfig::RP_RAND, CacheConfig::RP_LFU, CacheConfig::RP_LRU, CacheConfig::RP_PLRU, + CacheConfig::RP_NMRU }; constexpr array write_policies { CacheConfig::WP_THROUGH_NOALLOC, // THIS @@ -242,7 +242,8 @@ void TestCache::cache_correctness() { // stderr, "{ %d, %d }, ", cache.get_hit_count(), // cache.get_miss_count()); - if ((cache_config.replacement_policy() != CacheConfig::RP_RAND) && (cache_config.replacement_policy() != CacheConfig::RP_NMRU)) { + if ((cache_config.replacement_policy() != CacheConfig::RP_RAND) + && (cache_config.replacement_policy() != CacheConfig::RP_NMRU)) { // Performance of random policy is implementation dependant and // meaningless. QCOMPARE(performance, cache_test_performance_data.at(case_number)); diff --git a/src/machine/memory/cache/cache_policy.cpp b/src/machine/memory/cache/cache_policy.cpp index 15a4e35a..b549b33d 100644 --- a/src/machine/memory/cache/cache_policy.cpp +++ b/src/machine/memory/cache/cache_policy.cpp @@ -8,18 +8,15 @@ namespace machine { -std::unique_ptr -CachePolicy::get_policy_instance(const CacheConfig *config) { +std::unique_ptr CachePolicy::get_policy_instance(const CacheConfig *config) { if (config->enabled()) { switch (config->replacement_policy()) { case CacheConfig::RP_RAND: return std::make_unique(config->associativity()); case CacheConfig::RP_LRU: - return std::make_unique( - config->associativity(), config->set_count()); + return std::make_unique(config->associativity(), config->set_count()); case CacheConfig::RP_LFU: - return std::make_unique( - config->associativity(), config->set_count()); + return std::make_unique(config->associativity(), config->set_count()); case CacheConfig::RP_PLRU: return std::make_unique(config->associativity(), config->set_count()); case CacheConfig::RP_NMRU: @@ -115,8 +112,7 @@ size_t CachePolicyLFU::select_way_to_evict(size_t row) const { return index; } -CachePolicyRAND::CachePolicyRAND(size_t associativity) - : associativity(associativity) { +CachePolicyRAND::CachePolicyRAND(size_t associativity) : associativity(associativity) { // Reset random generator to make result reproducible. // Random is by default seeded by 1 (by cpp standard), so this makes it // consistent across multiple runs. @@ -191,9 +187,7 @@ void CachePolicyNMRU::update_stats(size_t way, size_t row, bool is_valid) { } size_t CachePolicyNMRU::select_way_to_evict(size_t row) const { - if(associativity == 1) { - return 0; - } + if (associativity == 1) { return 0; } uint32_t idx = std::rand() % (associativity - 1); auto &row_ptr = mru_ptr.at(row); idx = (idx < row_ptr) ? idx : idx + 1; diff --git a/src/machine/memory/cache/cache_policy.h b/src/machine/memory/cache/cache_policy.h index 708fa928..f248cb2d 100644 --- a/src/machine/memory/cache/cache_policy.h +++ b/src/machine/memory/cache/cache_policy.h @@ -32,8 +32,7 @@ class CachePolicy { virtual ~CachePolicy() = default; - static std::unique_ptr - get_policy_instance(const CacheConfig *config); + static std::unique_ptr get_policy_instance(const CacheConfig *config); }; /** diff --git a/src/machine/memory/frontend_memory.cpp b/src/machine/memory/frontend_memory.cpp index a5e2205e..594b838a 100644 --- a/src/machine/memory/frontend_memory.cpp +++ b/src/machine/memory/frontend_memory.cpp @@ -4,31 +4,19 @@ namespace machine { -bool FrontendMemory::write_u8( - Address address, - uint8_t value, - AccessEffects type) { +bool FrontendMemory::write_u8(Address address, uint8_t value, AccessEffects type) { return write_generic(address, value, type); } -bool FrontendMemory::write_u16( - Address address, - uint16_t value, - AccessEffects type) { +bool FrontendMemory::write_u16(Address address, uint16_t value, AccessEffects type) { return write_generic(address, value, type); } -bool FrontendMemory::write_u32( - Address address, - uint32_t value, - AccessEffects type) { +bool FrontendMemory::write_u32(Address address, uint32_t value, AccessEffects type) { return write_generic(address, value, type); } -bool FrontendMemory::write_u64( - Address address, - uint64_t value, - AccessEffects type) { +bool FrontendMemory::write_u64(Address address, uint64_t value, AccessEffects type) { return write_generic(address, value, type); } @@ -48,10 +36,7 @@ uint64_t FrontendMemory::read_u64(Address address, AccessEffects type) const { return read_generic(address, type); } -void FrontendMemory::write_ctl( - enum AccessControl ctl, - Address offset, - RegisterValue value) { +void FrontendMemory::write_ctl(enum AccessControl ctl, Address offset, RegisterValue value) { switch (ctl) { case AC_NONE: { break; @@ -84,8 +69,7 @@ void FrontendMemory::write_ctl( } } -RegisterValue -FrontendMemory::read_ctl(enum AccessControl ctl, Address address) const { +RegisterValue FrontendMemory::read_ctl(enum AccessControl ctl, Address address) const { switch (ctl) { case AC_NONE: return 0; case AC_I8: return (int8_t)read_u8(address); @@ -142,13 +126,9 @@ T FrontendMemory::read_generic(Address address, AccessEffects type) const { } template -bool FrontendMemory::write_generic( - Address address, - const T value, - AccessEffects type) { +bool FrontendMemory::write_generic(Address address, const T value, AccessEffects type) { // See example in read_generic for byteswap explanation. - const T swapped_value - = byteswap_if(value, this->simulated_machine_endian != NATIVE_ENDIAN); + const T swapped_value = byteswap_if(value, this->simulated_machine_endian != NATIVE_ENDIAN); return write(address, &swapped_value, sizeof(T), { .type = type }).changed; } FrontendMemory::FrontendMemory(Endian simulated_endian) diff --git a/src/machine/memory/frontend_memory.h b/src/machine/memory/frontend_memory.h index bab9a9b8..c7306093 100644 --- a/src/machine/memory/frontend_memory.h +++ b/src/machine/memory/frontend_memory.h @@ -51,14 +51,10 @@ class FrontendMemory : public QObject { */ explicit FrontendMemory(Endian simulated_endian); - bool - write_u8(Address address, uint8_t value, AccessEffects type = ae::REGULAR); - bool - write_u16(Address address, uint16_t value, AccessEffects type = ae::REGULAR); - bool - write_u32(Address address, uint32_t value, AccessEffects type = ae::REGULAR); - bool - write_u64(Address address, uint64_t value, AccessEffects type = ae::REGULAR); + bool write_u8(Address address, uint8_t value, AccessEffects type = ae::REGULAR); + bool write_u16(Address address, uint16_t value, AccessEffects type = ae::REGULAR); + bool write_u32(Address address, uint32_t value, AccessEffects type = ae::REGULAR); + bool write_u64(Address address, uint64_t value, AccessEffects type = ae::REGULAR); [[nodiscard]] uint8_t read_u8(Address address, AccessEffects type = ae::REGULAR) const; [[nodiscard]] uint16_t read_u16(Address address, AccessEffects type = ae::REGULAR) const; @@ -72,10 +68,7 @@ class FrontendMemory : public QObject { * REGULAR. * @param control_signal CPU control unit signal */ - void write_ctl( - AccessControl control_signal, - Address destination, - RegisterValue value); + void write_ctl(AccessControl control_signal, Address destination, RegisterValue value); /** * Read with size specified by the CPU control unit. @@ -98,11 +91,8 @@ class FrontendMemory : public QObject { * @param size number of bytes to be written * @return true when memory before and after write differs */ - virtual WriteResult write( - Address destination, - const void *source, - size_t size, - WriteOptions options) + virtual WriteResult + write(Address destination, const void *source, size_t size, WriteOptions options) = 0; /** @@ -114,11 +104,9 @@ class FrontendMemory : public QObject { * @param options additional option like debug mode, see type * definition */ - virtual ReadResult read( - void *destination, - Address source, - size_t size, - ReadOptions options) const = 0; + virtual ReadResult + read(void *destination, Address source, size_t size, ReadOptions options) const + = 0; /** * Endian of the simulated CPU/memory system. diff --git a/src/machine/memory/memory_bus.cpp b/src/machine/memory/memory_bus.cpp index fcc323b0..8932561e 100644 --- a/src/machine/memory/memory_bus.cpp +++ b/src/machine/memory/memory_bus.cpp @@ -5,8 +5,7 @@ using namespace machine; -MemoryDataBus::MemoryDataBus(Endian simulated_endian) - : FrontendMemory(simulated_endian) {}; +MemoryDataBus::MemoryDataBus(Endian simulated_endian) : FrontendMemory(simulated_endian) {}; MemoryDataBus::~MemoryDataBus() { ranges_by_addr.clear(); // No stored values are owned. @@ -14,22 +13,18 @@ MemoryDataBus::~MemoryDataBus() { while (iter != ranges_by_device.end()) { const RangeDesc *range = iter.value(); iter = ranges_by_device.erase(iter); // Advances the iterator. - if (range->owns_device) { - delete range->device; - } + if (range->owns_device) { delete range->device; } delete range; } } -WriteResult MemoryDataBus::write( - Address destination, - const void *source, - size_t size, - WriteOptions options) { +WriteResult +MemoryDataBus::write(Address destination, const void *source, size_t size, WriteOptions options) { return repeat_access_until_completed( destination, source, size, options, - [this](Address dst, const void *src, size_t s, WriteOptions opt) - -> WriteResult { return write_single(dst, src, s, opt); }); + [this](Address dst, const void *src, size_t s, WriteOptions opt) -> WriteResult { + return write_single(dst, src, s, opt); + }); } WriteResult MemoryDataBus::write_single( @@ -44,25 +39,21 @@ WriteResult MemoryDataBus::write_single( // just ignore the write. return (WriteResult) { .n_bytes = 0, .changed = false }; } - WriteResult result = range->device->write( - destination - range->start_addr, source, size, options); + WriteResult result + = range->device->write(destination - range->start_addr, source, size, options); - if (result.changed) { - change_counter++; - } + if (result.changed) { change_counter++; } return result; } -ReadResult MemoryDataBus::read( - void *destination, - Address source, - size_t size, - ReadOptions options) const { +ReadResult +MemoryDataBus::read(void *destination, Address source, size_t size, ReadOptions options) const { return repeat_access_until_completed( destination, source, size, options, - [this](void *dst, Address src, size_t s, ReadOptions opt) - -> ReadResult { return read_single(dst, src, s, opt); }); + [this](void *dst, Address src, size_t s, ReadOptions opt) -> ReadResult { + return read_single(dst, src, s, opt); + }); } ReadResult MemoryDataBus::read_single( @@ -79,8 +70,7 @@ ReadResult MemoryDataBus::read_single( return (ReadResult) { .n_bytes = size }; } - return p_range->device->read( - destination, source - p_range->start_addr, size, options); + return p_range->device->read(destination, source - p_range->start_addr, size, options); } uint32_t MemoryDataBus::get_change_counter() const { @@ -89,26 +79,19 @@ uint32_t MemoryDataBus::get_change_counter() const { enum LocationStatus MemoryDataBus::location_status(Address address) const { const RangeDesc *range = find_range(address); - if (range == nullptr) { - return LOCSTAT_ILLEGAL; - } + if (range == nullptr) { return LOCSTAT_ILLEGAL; } return range->device->location_status(address - range->start_addr); } -const MemoryDataBus::RangeDesc * -MemoryDataBus::find_range(Address address) const { +const MemoryDataBus::RangeDesc *MemoryDataBus::find_range(Address address) const { // lowerBound finds range what has highest key (which is range->last_addr) // less then or equal to address. // See comment in insert_device_to_range for description, why this works. auto iter = ranges_by_addr.lowerBound(address); - if (iter == ranges_by_addr.end()) { - return nullptr; - } + if (iter == ranges_by_addr.end()) { return nullptr; } const RangeDesc *range = iter.value(); - if (address >= range->start_addr && address <= range->last_addr) { - return range; - } + if (address >= range->start_addr && address <= range->last_addr) { return range; } return nullptr; } @@ -119,8 +102,7 @@ bool MemoryDataBus::insert_device_to_range( Address last_addr, bool move_ownership) { auto iter = ranges_by_addr.lowerBound(start_addr); - if (iter != ranges_by_addr.end() - && iter.value()->overlaps(start_addr, last_addr)) { + if (iter != ranges_by_addr.end() && iter.value()->overlaps(start_addr, last_addr)) { // Some part of requested range in already taken. return false; } @@ -150,17 +132,14 @@ bool MemoryDataBus::remove_device(BackendMemory *device) { } ranges_by_addr.remove(range->last_addr); - if (range->owns_device) { - delete range->device; - } + if (range->owns_device) { delete range->device; } delete range; return true; } void MemoryDataBus::clean_range(Address start_addr, Address last_addr) { - for (auto iter = ranges_by_addr.lowerBound(start_addr); - iter != ranges_by_addr.end(); iter++) { + for (auto iter = ranges_by_addr.lowerBound(start_addr); iter != ranges_by_addr.end(); iter++) { const RangeDesc *range = iter.value(); if (range->start_addr <= last_addr) { remove_device(range->device); @@ -210,20 +189,14 @@ TrivialBus::TrivialBus(BackendMemory *backend_memory) : FrontendMemory(backend_memory->simulated_machine_endian) , device(backend_memory) {} -WriteResult TrivialBus::write( - Address destination, - const void *source, - size_t size, - WriteOptions options) { +WriteResult +TrivialBus::write(Address destination, const void *source, size_t size, WriteOptions options) { change_counter += 1; // Counter is mandatory by the frontend interface. return device->write(destination.get_raw(), source, size, options); } -ReadResult TrivialBus::read( - void *destination, - Address source, - size_t size, - ReadOptions options) const { +ReadResult +TrivialBus::read(void *destination, Address source, size_t size, ReadOptions options) const { return device->read(destination, source.get_raw(), size, options); } diff --git a/src/machine/memory/memory_bus.h b/src/machine/memory/memory_bus.h index 88eeebd7..e9f37178 100644 --- a/src/machine/memory/memory_bus.h +++ b/src/machine/memory/memory_bus.h @@ -47,11 +47,8 @@ class MemoryDataBus : public FrontendMemory { * * @see MemoryDataBus::write_single */ - WriteResult write( - Address destination, - const void *source, - size_t size, - WriteOptions options) override; + WriteResult + write(Address destination, const void *source, size_t size, WriteOptions options) override; /** * Read method that repeats write single (for each affected range) until @@ -59,11 +56,8 @@ class MemoryDataBus : public FrontendMemory { * * @see MemoryDataBus:read_single */ - ReadResult read( - void *destination, - Address source, - size_t size, - ReadOptions options) const override; + ReadResult + read(void *destination, Address source, size_t size, ReadOptions options) const override; /** * Number of writes and external changes recorded. @@ -138,11 +132,8 @@ private slots: * that was written. * API corresponds to `BackendMemory` interface method `write`. */ - WriteResult write_single( - Address destination, - const void *source, - size_t size, - WriteOptions options); + WriteResult + write_single(Address destination, const void *source, size_t size, WriteOptions options); /** * Helper to read from single range. Used by `read` from Backend memory @@ -152,11 +143,8 @@ private slots: * size, that was written. * API corresponds to `BackendMemory` interface method `read`. */ - ReadResult read_single( - void *destination, - Address source, - size_t size, - ReadOptions options) const; + ReadResult + read_single(void *destination, Address source, size_t size, ReadOptions options) const; /** * Get range (or nullptr) for arbitrary address (not just start or last). @@ -169,11 +157,7 @@ private slots: */ class MemoryDataBus::RangeDesc { public: - RangeDesc( - BackendMemory *device, - Address start_addr, - Address last_addr, - bool owns_device); + RangeDesc(BackendMemory *device, Address start_addr, Address last_addr, bool owns_device); /** * Tells, whether given address belongs to this range. @@ -204,17 +188,11 @@ class TrivialBus final : public FrontendMemory { public: explicit TrivialBus(BackendMemory *backend_memory); - WriteResult write( - Address destination, - const void *source, - size_t size, - WriteOptions options) override; - - ReadResult read( - void *destination, - Address source, - size_t size, - ReadOptions options) const override; + WriteResult + write(Address destination, const void *source, size_t size, WriteOptions options) override; + + ReadResult + read(void *destination, Address source, size_t size, ReadOptions options) const override; uint32_t get_change_counter() const override; diff --git a/src/machine/memory/memory_utils.h b/src/machine/memory/memory_utils.h index fa692453..e0ba3111 100644 --- a/src/machine/memory/memory_utils.h +++ b/src/machine/memory/memory_utils.h @@ -15,9 +15,9 @@ namespace machine { * Determines what effects should memory access cause. */ enum class AccessEffects { - REGULAR, //> All (memory, simulation counters, simulation flags, allocation - // on read miss (write allocation is necessary)). For accessed - // requested by simulated program. + REGULAR, //> All (memory, simulation counters, simulation flags, allocation + // on read miss (write allocation is necessary)). For accessed + // requested by simulated program. INTERNAL, //> Only memory. Internal access performed for visualization, // control and debugging. EXTERNAL_ASYNC, //> Used for DMA. @@ -105,16 +105,12 @@ struct WriteResult { * @return size to be used from aligned access */ template -inline void partial_access_parameters( - size_t &data_offset, - size_t &partial_size, - uintptr_t ptr, - size_t size) { +inline void +partial_access_parameters(size_t &data_offset, size_t &partial_size, uintptr_t ptr, size_t size) { data_offset = ptr % sizeof(STORAGE_TYPE); partial_size = sizeof(STORAGE_TYPE); partial_size -= data_offset; - if (partial_size > size) - partial_size = size; + if (partial_size > size) partial_size = size; } /** @@ -225,8 +221,7 @@ write_by_u32(size_t dst, const void *src, size_t size, FUNC1 data_getter, FUNC2 size_t partial_size = std::min(sizeof(uint32_t) - data_offset, remaining_size); uint32_t data = 0; - if (partial_size < sizeof(data)) - data = data_getter(current_dst & ~3u); + if (partial_size < sizeof(data)) data = data_getter(current_dst & ~3u); memcpy((byte *)&data + data_offset, current_src, partial_size); @@ -254,8 +249,7 @@ write_by_u16(size_t dst, const void *src, size_t size, FUNC1 data_getter, FUNC2 size_t partial_size = std::min(sizeof(uint16_t) - data_offset, remaining_size); uint16_t data = 0; - if (partial_size < sizeof(data)) - data = data_getter(current_dst & ~1u); + if (partial_size < sizeof(data)) data = data_getter(current_dst & ~1u); memcpy((byte *)&data + data_offset, current_src, partial_size); @@ -283,8 +277,7 @@ write_by_u64(size_t dst, const void *src, size_t size, FUNC1 data_getter, FUNC2 size_t partial_size = std::min(sizeof(uint64_t) - data_offset, remaining_size); uint64_t data = 0; - if (partial_size < sizeof(data)) - data = data_getter(current_dst & ~7u); + if (partial_size < sizeof(data)) data = data_getter(current_dst & ~7u); memcpy((byte *)&data + data_offset, current_src, partial_size); diff --git a/src/machine/pipeline.h b/src/machine/pipeline.h index 92b1a74b..de7c6881 100644 --- a/src/machine/pipeline.h +++ b/src/machine/pipeline.h @@ -116,7 +116,7 @@ struct DecodeInterstage { bool csr = false; // Zicsr, implies csr read and csr write bool csr_to_alu = false; bool csr_write = false; - bool xret = false; // Return from exception, MRET and SRET + bool xret = false; // Return from exception, MRET and SRET bool insert_stall_before = false; public: diff --git a/src/machine/predictor.cpp b/src/machine/predictor.cpp index 2feb494c..0df165aa 100644 --- a/src/machine/predictor.cpp +++ b/src/machine/predictor.cpp @@ -52,20 +52,16 @@ QString machine::addr_to_hex_str(const machine::Address address) { } bool machine::is_predictor_type_dynamic(const PredictorType type) { - switch (type) - { + switch (type) { case PredictorType::ALWAYS_NOT_TAKEN: case PredictorType::ALWAYS_TAKEN: - case PredictorType::BTFNT: - return false; + case PredictorType::BTFNT: return false; case PredictorType::SMITH_1_BIT: case PredictorType::SMITH_2_BIT: - case PredictorType::SMITH_2_BIT_HYSTERESIS: - return true; + case PredictorType::SMITH_2_BIT_HYSTERESIS: return true; - default: - return false; + default: return false; } } @@ -167,7 +163,10 @@ BranchTargetBufferEntry BranchTargetBuffer::get_entry(const Address instruction_ } // Update BTB entry with given values, at index computed from the instruction address -void BranchTargetBuffer::update(const Address instruction_address, const Address target_address, const BranchType branch_type) { +void BranchTargetBuffer::update( + const Address instruction_address, + const Address target_address, + const BranchType branch_type) { // Get index from instruction address const uint16_t btb_index { calculate_index(instruction_address) }; @@ -178,12 +177,10 @@ void BranchTargetBuffer::update(const Address instruction_address, const Address } // Write new entry to the table - const BranchTargetBufferEntry btb_entry = { - .entry_valid = true, - .instruction_address = instruction_address, - .target_address = target_address, - .branch_type = branch_type - }; + const BranchTargetBufferEntry btb_entry = { .entry_valid = true, + .instruction_address = instruction_address, + .target_address = target_address, + .branch_type = branch_type }; btb.at(btb_index) = btb_entry; // Send signal with the data @@ -276,14 +273,14 @@ void Predictor::update_bht_stats(uint16_t bht_index, bool prediction_was_correct } else { bht.at(bht_index).stats.wrong += 1; } - bht.at(bht_index).stats.accuracy = ((bht.at(bht_index).stats.correct * 100) / bht.at(bht_index).stats.total); + bht.at(bht_index).stats.accuracy + = ((bht.at(bht_index).stats.correct * 100) / bht.at(bht_index).stats.total); emit bht_row_updated(bht_index, bht.at(bht_index)); } // Calculate index for addressing Branch History Table from BHR and instruction address -uint16_t Predictor::calculate_bht_index( - const uint16_t bhr_value, - const Address instruction_address) const { +uint16_t +Predictor::calculate_bht_index(const uint16_t bhr_value, const Address instruction_address) const { const uint16_t bhr_part = bhr_value << number_of_bht_addr_bits; const uint16_t address_mask = (1 << number_of_bht_addr_bits) - 1; const uint16_t address_part = ((uint16_t)(instruction_address.get_raw() >> 2)) & address_mask; @@ -558,31 +555,27 @@ BranchPredictor::BranchPredictor( , number_of_bhr_bits(init_number_of_bhr_bits(number_of_bhr_bits)) , number_of_bht_addr_bits(init_number_of_bht_addr_bits(number_of_bht_addr_bits)) , number_of_bht_bits(init_number_of_bht_bits(number_of_bhr_bits, number_of_bht_addr_bits)) { - // Create predicotr switch (predictor_type) { - case PredictorType::ALWAYS_NOT_TAKEN: - predictor = new PredictorAlwaysNotTaken(); - break; + case PredictorType::ALWAYS_NOT_TAKEN: predictor = new PredictorAlwaysNotTaken(); break; - case PredictorType::ALWAYS_TAKEN: - predictor = new PredictorAlwaysTaken(); - break; + case PredictorType::ALWAYS_TAKEN: predictor = new PredictorAlwaysTaken(); break; - case PredictorType::BTFNT: - predictor = new PredictorBTFNT(); - break; + case PredictorType::BTFNT: predictor = new PredictorBTFNT(); break; case PredictorType::SMITH_1_BIT: - predictor = new PredictorSmith1Bit(number_of_bht_addr_bits, number_of_bht_bits, initial_state); + predictor + = new PredictorSmith1Bit(number_of_bht_addr_bits, number_of_bht_bits, initial_state); break; case PredictorType::SMITH_2_BIT: - predictor = new PredictorSmith2Bit(number_of_bht_addr_bits, number_of_bht_bits, initial_state); + predictor + = new PredictorSmith2Bit(number_of_bht_addr_bits, number_of_bht_bits, initial_state); break; case PredictorType::SMITH_2_BIT_HYSTERESIS: - predictor = new PredictorSmith2BitHysteresis(number_of_bht_addr_bits, number_of_bht_bits, initial_state); + predictor = new PredictorSmith2BitHysteresis( + number_of_bht_addr_bits, number_of_bht_bits, initial_state); break; default: throw std::invalid_argument("Invalid predictor type selected"); @@ -595,26 +588,17 @@ BranchPredictor::BranchPredictor( if (enabled) { // Pass through BTB signals - connect( - btb, &BranchTargetBuffer::btb_row_updated, - this, &BranchPredictor::btb_row_updated - ); + connect(btb, &BranchTargetBuffer::btb_row_updated, this, &BranchPredictor::btb_row_updated); // Pass through BHR signals - connect( - bhr, &BranchHistoryRegister::bhr_updated, - this, &BranchPredictor::bhr_updated - ); + connect(bhr, &BranchHistoryRegister::bhr_updated, this, &BranchPredictor::bhr_updated); // Pass through predictor signals connect( - predictor, &Predictor::stats_updated, - this, &BranchPredictor::predictor_stats_updated - ); + predictor, &Predictor::stats_updated, this, &BranchPredictor::predictor_stats_updated); connect( - predictor, &Predictor::bht_row_updated, - this, &BranchPredictor::predictor_bht_row_updated - ); + predictor, &Predictor::bht_row_updated, this, + &BranchPredictor::predictor_bht_row_updated); } } @@ -748,19 +732,17 @@ Address BranchPredictor::predict_next_pc_address( .instruction_address = instruction_address, .target_address = btb_entry.target_address, }; - BranchResult predicted_result{ BranchResult::UNDEFINED }; + BranchResult predicted_result { BranchResult::UNDEFINED }; if (btb_entry.branch_type == BranchType::BRANCH) { predicted_result = predictor->predict(prediction_input); } else { predicted_result = BranchResult::TAKEN; } - + emit prediction_done( btb->calculate_index(instruction_address), - predictor->calculate_bht_index(bhr->get_value(), instruction_address), - prediction_input, - predicted_result, - btb_entry.branch_type); + predictor->calculate_bht_index(bhr->get_value(), instruction_address), prediction_input, + predicted_result, btb_entry.branch_type); // If the branch was predicted Taken if (predicted_result == BranchResult::TAKEN) { return btb_entry.target_address; } @@ -783,24 +765,19 @@ void BranchPredictor::update( btb->update(instruction_address, target_address, branch_type); // Update predictor only for conditional branches - const PredictionFeedback prediction_feedback { - .instruction = instruction, - .bhr_value = bhr->get_value(), - .instruction_address = instruction_address, - .target_address = target_address, - .result = result, - .branch_type = branch_type - }; - if (branch_type == BranchType::BRANCH) { - predictor->update(prediction_feedback); - } + const PredictionFeedback prediction_feedback { .instruction = instruction, + .bhr_value = bhr->get_value(), + .instruction_address = instruction_address, + .target_address = target_address, + .result = result, + .branch_type = branch_type }; + if (branch_type == BranchType::BRANCH) { predictor->update(prediction_feedback); } increment_jumps(); emit update_done( btb->calculate_index(instruction_address), - predictor->calculate_bht_index(bhr->get_value(), instruction_address), - prediction_feedback); + predictor->calculate_bht_index(bhr->get_value(), instruction_address), prediction_feedback); // Update global branch history bhr->update(result); diff --git a/src/machine/predictor.h b/src/machine/predictor.h index 4aa3689c..8496b463 100644 --- a/src/machine/predictor.h +++ b/src/machine/predictor.h @@ -58,10 +58,10 @@ class BranchHistoryRegister final : public QObject { ///////////////////////////// struct BranchTargetBufferEntry { - bool entry_valid{ false }; - Address instruction_address{ Address::null() }; - Address target_address{ Address::null() }; - BranchType branch_type{ BranchType::UNDEFINED }; + bool entry_valid { false }; + Address instruction_address { Address::null() }; + Address target_address { Address::null() }; + BranchType branch_type { BranchType::UNDEFINED }; }; class BranchTargetBuffer final : public QObject { @@ -77,7 +77,10 @@ class BranchTargetBuffer final : public QObject { uint8_t get_number_of_bits() const; uint16_t calculate_index(const Address instruction_address) const; BranchTargetBufferEntry get_entry(const Address instruction_address) const; - void update(const Address instruction_address, const Address target_address, const BranchType branch_type); + void update( + const Address instruction_address, + const Address target_address, + const BranchType branch_type); void clear(); signals: @@ -136,14 +139,14 @@ class Predictor : public QObject { BranchResult convert_state_to_prediction(PredictorState state) const; void update_stats(bool prediction_was_correct); void update_bht_stats(uint16_t bht_index, bool prediction_was_correct); - + public: // General functions uint16_t calculate_bht_index(const uint16_t bhr_value, const Address instruction_address) const; virtual PredictorType get_type() const = 0; - virtual BranchResult predict(PredictionInput input) = 0; // Function which handles all actions ties - // to making a branch prediction - virtual void update(PredictionFeedback feedback) = 0; // Update predictor based on jump / branch - // result + virtual BranchResult predict(PredictionInput input) = 0; // Function which handles all actions + // ties to making a branch prediction + virtual void update(PredictionFeedback feedback) = 0; // Update predictor based on jump / branch + // result void clear_stats(); void clear_bht_stats(); void clear_bht_state(); @@ -154,12 +157,12 @@ class Predictor : public QObject { void stats_updated(PredictionStatistics stats) const; void bht_row_updated(uint16_t index, BranchHistoryTableEntry entry) const; -protected: // Internal variables +protected: // Internal variables const uint8_t number_of_bht_addr_bits; // Number of Branch History Table (BHT) bits taken from // instruction address const uint8_t number_of_bht_bits; // Number of Branch History Table (BHT) bits const PredictorState initial_state; - PredictionStatistics stats; // Total predictor statistics + PredictionStatistics stats; // Total predictor statistics std::vector bht; // Branch History Table (BHT) }; @@ -260,7 +263,6 @@ class BranchPredictor : public QObject { uint8_t init_number_of_bhr_bits(const uint8_t b) const; uint8_t init_number_of_bht_addr_bits(const uint8_t b) const; uint8_t init_number_of_bht_bits(const uint8_t b_bhr, const uint8_t b_addr) const; - public: // General functions bool get_enabled() const; @@ -273,7 +275,8 @@ class BranchPredictor : public QObject { uint8_t get_number_of_bht_bits() const; void increment_jumps(); void increment_mispredictions(); - Address predict_next_pc_address(const Instruction instruction, const Address instruction_address) const; + Address + predict_next_pc_address(const Instruction instruction, const Address instruction_address) const; void update( const Instruction instruction, const Address instruction_address, @@ -285,7 +288,12 @@ class BranchPredictor : public QObject { signals: void total_stats_updated(PredictionStatistics total_stats); - void prediction_done(uint16_t btb_index, uint16_t bht_index, PredictionInput input, BranchResult result, BranchType branch_type) const; + void prediction_done( + uint16_t btb_index, + uint16_t bht_index, + PredictionInput input, + BranchResult result, + BranchType branch_type) const; void update_done(uint16_t btb_index, uint16_t bht_index, PredictionFeedback feedback) const; void predictor_stats_updated(PredictionStatistics stats) const; void predictor_bht_row_updated(uint16_t index, BranchHistoryTableEntry entry) const; @@ -295,7 +303,7 @@ class BranchPredictor : public QObject { void flushed() const; // Only BHT state and BTB rows were reset private: // Internal variables - bool enabled{ false }; + bool enabled { false }; PredictionStatistics total_stats; Predictor *predictor; BranchHistoryRegister *bhr; diff --git a/src/machine/predictor_types.h b/src/machine/predictor_types.h index 2c6bf31a..d9c7a80d 100644 --- a/src/machine/predictor_types.h +++ b/src/machine/predictor_types.h @@ -5,23 +5,19 @@ namespace machine { Q_NAMESPACE // Should not exceed 16, because uint16_t is used for addressing -#define BP_MAX_BTB_BITS 8 -#define BP_MAX_BHR_BITS 8 +#define BP_MAX_BTB_BITS 8 +#define BP_MAX_BHR_BITS 8 #define BP_MAX_BHT_ADDR_BITS 8 -#define BP_MAX_BHT_BITS (BP_MAX_BHT_ADDR_BITS + BP_MAX_BHT_ADDR_BITS) +#define BP_MAX_BHT_BITS (BP_MAX_BHT_ADDR_BITS + BP_MAX_BHT_ADDR_BITS) enum class BranchType { - JUMP, // JAL, JALR - Unconditional - BRANCH, // BXX - Conditional + JUMP, // JAL, JALR - Unconditional + BRANCH, // BXX - Conditional UNDEFINED }; Q_ENUM_NS(machine::BranchType) -enum class BranchResult { - NOT_TAKEN, - TAKEN, - UNDEFINED -}; +enum class BranchResult { NOT_TAKEN, TAKEN, UNDEFINED }; Q_ENUM_NS(machine::BranchResult) enum class PredictorType { diff --git a/src/machine/programloader.cpp b/src/machine/programloader.cpp index adddf42c..878527ad 100644 --- a/src/machine/programloader.cpp +++ b/src/machine/programloader.cpp @@ -21,34 +21,29 @@ ProgramLoader::ProgramLoader(const QString &file) : elf_file(file) { const GElf_Ehdr *elf_ehdr; // Initialize elf library if (elf_version(EV_CURRENT) == EV_NONE) { - throw SIMULATOR_EXCEPTION( - Input, "Elf library initialization failed", elf_errmsg(-1)); + throw SIMULATOR_EXCEPTION(Input, "Elf library initialization failed", elf_errmsg(-1)); } // Open source file - option QIODevice::ExistingOnly cannot be used on Qt // <5.11 if (!elf_file.open(QIODevice::ReadOnly | QIODevice::Unbuffered)) { throw SIMULATOR_EXCEPTION( Input, - QString("Can't open input elf file for reading (") + QString(file) - + QString(")"), + QString("Can't open input elf file for reading (") + QString(file) + QString(")"), std::strerror(errno)); } // Initialize elf if (!(this->elf = elf_begin(elf_file.handle(), ELF_C_READ, nullptr))) { - throw SIMULATOR_EXCEPTION( - Input, "Elf read begin failed", elf_errmsg(-1)); + throw SIMULATOR_EXCEPTION(Input, "Elf read begin failed", elf_errmsg(-1)); } // Check elf kind if (elf_kind(this->elf) != ELF_K_ELF) { throw SIMULATOR_EXCEPTION( - Input, "Invalid input file elf format, plain elf file expected", - ""); + Input, "Invalid input file elf format, plain elf file expected", ""); } elf_ehdr = gelf_getehdr(this->elf, &this->hdr); if (!elf_ehdr) { - throw SIMULATOR_EXCEPTION( - Input, "Getting elf file header failed", elf_errmsg(-1)); + throw SIMULATOR_EXCEPTION(Input, "Getting elf file header failed", elf_errmsg(-1)); } executable_entry = Address(elf_ehdr->e_entry); @@ -65,13 +60,11 @@ ProgramLoader::ProgramLoader(const QString &file) : elf_file(file) { // Check elf file class, only 32bit architecture is supported. int elf_class; if ((elf_class = gelf_getclass(this->elf)) == ELFCLASSNONE) { - throw SIMULATOR_EXCEPTION( - Input, "Getting elf class failed", elf_errmsg(-1)); + throw SIMULATOR_EXCEPTION(Input, "Getting elf class failed", elf_errmsg(-1)); } // Get number of program sections in elf file if (elf_getphdrnum(this->elf, &this->n_secs)) { - throw SIMULATOR_EXCEPTION( - Input, "Elf program sections count query failed", elf_errmsg(-1)); + throw SIMULATOR_EXCEPTION(Input, "Elf program sections count query failed", elf_errmsg(-1)); } if (elf_class == ELFCLASS32) { @@ -110,8 +103,7 @@ ProgramLoader::ProgramLoader(const QString &file) : elf_file(file) { } } -ProgramLoader::ProgramLoader(const char *file) - : ProgramLoader(QString::fromLocal8Bit(file)) {} +ProgramLoader::ProgramLoader(const char *file) : ProgramLoader(QString::fromLocal8Bit(file)) {} ProgramLoader::~ProgramLoader() { // Close elf @@ -176,9 +168,7 @@ SymbolTable *ProgramLoader::get_symbol_table() { elf_version(EV_CURRENT); while (true) { - if ((scn = elf_nextscn(this->elf, scn)) == nullptr) { - return p_st; - } + if ((scn = elf_nextscn(this->elf, scn)) == nullptr) { return p_st; } gelf_getshdr(scn, &shdr); if (shdr.sh_type == SHT_SYMTAB) { /* found a symbol table, go print it. */ @@ -194,8 +184,8 @@ SymbolTable *ProgramLoader::get_symbol_table() { GElf_Sym sym; gelf_getsym(data, ii, &sym); p_st->add_symbol( - elf_strptr(elf, shdr.sh_link, sym.st_name), sym.st_value, - sym.st_size, sym.st_info, sym.st_other); + elf_strptr(elf, shdr.sh_link, sym.st_name), sym.st_value, sym.st_size, sym.st_info, + sym.st_other); } return p_st; diff --git a/src/machine/programloader.h b/src/machine/programloader.h index f6e9ccc1..c371061a 100644 --- a/src/machine/programloader.h +++ b/src/machine/programloader.h @@ -26,8 +26,8 @@ class ProgramLoader { void to_memory(Memory *mem); // Writes all loaded sections to memory TODO: // really to memory ??? - Address end(); // Return address after which there is no more code for - // sure + Address end(); // Return address after which there is no more code for + // sure Address get_executable_entry() const; SymbolTable *get_symbol_table(); @@ -47,7 +47,7 @@ class ProgramLoader { union { Elf32_Phdr *arch32; Elf64_Phdr *arch64; - } sections_headers{}; + } sections_headers {}; QVector indexes_of_load_sections; // external index to sections_headers index Address executable_entry; }; diff --git a/src/machine/registers.cpp b/src/machine/registers.cpp index 372d7e04..6fee2626 100644 --- a/src/machine/registers.cpp +++ b/src/machine/registers.cpp @@ -77,5 +77,5 @@ void Registers::reset() { write_gp(i, 0); } write_gp(2_reg, SP_INIT.get_raw()); // initialize to safe RAM area - - // corresponds to Linux + // corresponds to Linux } diff --git a/src/machine/registers.h b/src/machine/registers.h index c6d40896..2b7b5a02 100644 --- a/src/machine/registers.h +++ b/src/machine/registers.h @@ -58,11 +58,11 @@ class Registers : public QObject { Address read_pc() const; // Return current value of program counter void write_pc(Address address); // Absolute jump in program counter - RegisterValue read_gp(RegisterId reg) const; // Read general-purpose - // register + RegisterValue read_gp(RegisterId reg) const; // Read general-purpose + // register RegisterValue read_gp_internal(RegisterId reg) const; // For use from GUI. - void write_gp(RegisterId reg, RegisterValue value); // Write general-purpose - // register + void write_gp(RegisterId reg, RegisterValue value); // Write general-purpose + // register bool operator==(const Registers &c) const; bool operator!=(const Registers &c) const; diff --git a/src/machine/simulator_exception.cpp b/src/machine/simulator_exception.cpp index 35acfcec..719641f4 100644 --- a/src/machine/simulator_exception.cpp +++ b/src/machine/simulator_exception.cpp @@ -6,11 +6,7 @@ using namespace machine; -SimulatorException::SimulatorException( - QString reason, - QString ext, - QString file, - int line) { +SimulatorException::SimulatorException(QString reason, QString ext, QString file, int line) { this->name = "Exception"; this->reason = std::move(reason); this->ext = std::move(ext); @@ -20,15 +16,11 @@ SimulatorException::SimulatorException( } SimulatorException::~SimulatorException() { - if (this->cached_what) { - delete[] this->cached_what; - } + if (this->cached_what) { delete[] this->cached_what; } } const char *SimulatorException::what() const noexcept { - if (this->cached_what) { - return this->cached_what; - } + if (this->cached_what) { return this->cached_what; } std::string message = this->msg(true).toStdString(); this->cached_what = new char[message.length() + 1]; @@ -41,8 +33,8 @@ QString SimulatorException::msg(bool pos) const { QString message; message += name; if (pos) { - message += QString(" (") + QString(this->file) + QString(":") - + QString::number(this->line) + QString(")"); + message += QString(" (") + QString(this->file) + QString(":") + QString::number(this->line) + + QString(")"); } message += ": " + this->reason; if (!this->ext.isEmpty()) { @@ -52,11 +44,11 @@ QString SimulatorException::msg(bool pos) const { return message; } -#define EXCEPTION(NAME, PARENT) \ - SimulatorException##NAME::SimulatorException##NAME( \ - QString reason, QString ext, QString file, int line) \ - : SimulatorException##PARENT(reason, ext, file, line) { \ - name = #NAME; \ +#define EXCEPTION(NAME, PARENT) \ + SimulatorException##NAME::SimulatorException##NAME( \ + QString reason, QString ext, QString file, int line) \ + : SimulatorException##PARENT(reason, ext, file, line) { \ + name = #NAME; \ } SIMULATOR_EXCEPTIONS #undef EXCEPTION diff --git a/src/machine/simulator_exception.h b/src/machine/simulator_exception.h index cc69982e..de48085d 100644 --- a/src/machine/simulator_exception.h +++ b/src/machine/simulator_exception.h @@ -17,8 +17,9 @@ class SimulatorException : public std::exception { protected: QString name, reason, ext, file; int line; + private: - mutable char * cached_what; + mutable char *cached_what; }; /* This is list of all QtRvSim specific exceptions diff --git a/src/machine/symboltable.cpp b/src/machine/symboltable.cpp index 1eebca14..711e6e25 100644 --- a/src/machine/symboltable.cpp +++ b/src/machine/symboltable.cpp @@ -26,7 +26,7 @@ SymbolTable::~SymbolTable() { auto iter = map_value_to_symbol.begin(); while (iter != map_value_to_symbol.end()) { const SymbolTableEntry *p_entry = iter.value(); - iter = map_value_to_symbol .erase(iter); // Advances iterator. + iter = map_value_to_symbol.erase(iter); // Advances iterator. delete p_entry; } } @@ -44,9 +44,7 @@ void SymbolTable::add_symbol( void SymbolTable::remove_symbol(const QString &name) { auto *p_entry = map_name_to_symbol.take(name); - if (p_entry == nullptr) { - return; - } + if (p_entry == nullptr) { return; } map_value_to_symbol.remove(p_entry->value, p_entry); delete p_entry; } diff --git a/src/machine/tests/utils/integer_decomposition.h b/src/machine/tests/utils/integer_decomposition.h index ec6af8ec..7929783d 100644 --- a/src/machine/tests/utils/integer_decomposition.h +++ b/src/machine/tests/utils/integer_decomposition.h @@ -6,7 +6,6 @@ #include #include - using namespace machine; using std::array; using std::uint16_t; @@ -15,11 +14,9 @@ using std::uint64_t; using std::uint8_t; template -constexpr void decompose_int_to_array(array &dst, - uint64_t value, - Endian endian) { +constexpr void decompose_int_to_array(array &dst, uint64_t value, Endian endian) { for (size_t i = 0; i < N; ++i) { - T val = (T) (value >> (8 * sizeof(T) * i)); + T val = (T)(value >> (8 * sizeof(T) * i)); if (endian == LITTLE) { dst.at(i) = val; } else { @@ -28,12 +25,11 @@ constexpr void decompose_int_to_array(array &dst, } } - struct IntegerDecomposition { - uint64_t u64{}; - array u32{}; - array u16{}; - array u8{}; + uint64_t u64 {}; + array u32 {}; + array u16 {}; + array u8 {}; constexpr IntegerDecomposition() = default; @@ -45,17 +41,12 @@ struct IntegerDecomposition { } constexpr bool operator==(const IntegerDecomposition &rhs) const { - return u64 == rhs.u64 && u32 == rhs.u32 && u16 == rhs.u16 - && u8 == rhs.u8; + return u64 == rhs.u64 && u32 == rhs.u32 && u16 == rhs.u16 && u8 == rhs.u8; } - constexpr bool operator!=(const IntegerDecomposition &rhs) const { - return !(rhs == *this); - } + constexpr bool operator!=(const IntegerDecomposition &rhs) const { return !(rhs == *this); } }; - Q_DECLARE_METATYPE(IntegerDecomposition) - #endif // INTEGER_DECOMPOSITION_H diff --git a/src/machine/utils.h b/src/machine/utils.h index de4c09f4..da2f609b 100644 --- a/src/machine/utils.h +++ b/src/machine/utils.h @@ -31,9 +31,9 @@ template void ignore(const T &) {} #define UNIMPLEMENTED throw std::logic_error("Unimplemented"); -#define PANIC throw std::logic_error("The program panicked."); -#define UNREACHABLE Q_UNREACHABLE(); -#define UNUSED(arg) ignore(arg); +#define PANIC throw std::logic_error("The program panicked."); +#define UNREACHABLE Q_UNREACHABLE(); +#define UNUSED(arg) ignore(arg); /** * Annotate pointer ownership. * Smartpointer may be used in the future. diff --git a/src/os_emulation/ossyscall.cpp b/src/os_emulation/ossyscall.cpp index 0bf52fda..0ab96d76 100644 --- a/src/os_emulation/ossyscall.cpp +++ b/src/os_emulation/ossyscall.cpp @@ -2,9 +2,9 @@ #include "machine/core.h" #include "machine/utils.h" +#include "posix_polyfill.h" #include "syscall_nr.h" #include "target_errno.h" -#include "posix_polyfill.h" #include #include @@ -17,27 +17,27 @@ using namespace osemu; // The copied from musl-libc -#define TARGET_O_CREAT 0100 -#define TARGET_O_EXCL 0200 -#define TARGET_O_NOCTTY 0400 -#define TARGET_O_TRUNC 01000 -#define TARGET_O_APPEND 02000 -#define TARGET_O_NONBLOCK 04000 -#define TARGET_O_DSYNC 010000 -#define TARGET_O_SYNC 04010000 -#define TARGET_O_RSYNC 04010000 +#define TARGET_O_CREAT 0100 +#define TARGET_O_EXCL 0200 +#define TARGET_O_NOCTTY 0400 +#define TARGET_O_TRUNC 01000 +#define TARGET_O_APPEND 02000 +#define TARGET_O_NONBLOCK 04000 +#define TARGET_O_DSYNC 010000 +#define TARGET_O_SYNC 04010000 +#define TARGET_O_RSYNC 04010000 #define TARGET_O_DIRECTORY 0200000 #define TARGET_O_NOFOLLOW 0400000 -#define TARGET_O_CLOEXEC 02000000 +#define TARGET_O_CLOEXEC 02000000 #define TARGET_O_PATH 010000000 #define TARGET_O_SYNC1 040000 #define TARGET_O_ACCMODE (03 | TARGET_O_PATH) -#define TARGET_O_RDONLY 00 -#define TARGET_O_WRONLY 01 -#define TARGET_O_RDWR 02 +#define TARGET_O_RDONLY 00 +#define TARGET_O_WRONLY 01 +#define TARGET_O_RDWR 02 #define TARGET_AT_FDCWD -100 @@ -570,11 +570,9 @@ bool OsSyscallExceptionHandler::handle_exception( #if 1 printf( "Exception cause %d instruction PC 0x%08" PRIx64 " next PC 0x%08" PRIx64 " jump branch " - "PC 0x%08" PRIx64 - "registers PC 0x%08" PRIx64 " mem ref 0x%08" PRIx64 "\n", - excause, inst_addr.get_raw(), next_addr.get_raw(), - jump_branch_pc.get_raw(), regs->read_pc().get_raw(), - mem_ref_addr.get_raw()); + "PC 0x%08" PRIx64 "registers PC 0x%08" PRIx64 " mem ref 0x%08" PRIx64 "\n", + excause, inst_addr.get_raw(), next_addr.get_raw(), jump_branch_pc.get_raw(), + regs->read_pc().get_raw(), mem_ref_addr.get_raw()); #else (void)excause; (void)inst_addr; @@ -606,7 +604,8 @@ bool OsSyscallExceptionHandler::handle_exception( #if 1 printf( - "Syscall %s number %" PRId64 "/0x%" PRIx64 " a1=%" PRIu64 " a2=%" PRIu64 " a3=%" PRIu64 " a4=%" PRIu64 "\n", + "Syscall %s number %" PRId64 "/0x%" PRIx64 " a1=%" PRIu64 " a2=%" PRIu64 " a3=%" PRIu64 + " a4=%" PRIu64 "\n", sdesc->name, syscall_num, syscall_num, a1.as_u64(), a2.as_u64(), a3.as_u64(), a4.as_u64()); #endif @@ -786,9 +785,9 @@ int OsSyscallExceptionHandler::syscall_default_handler( const rv_syscall_desc_t *sdesc = &rv_syscall_args[syscall_num]; #if 1 printf( - "Unimplemented syscall %s number %" PRId64 "/0x%" PRIx64 " a1 %" PRId64 - " a2 %" PRId64 " a3 %" PRId64 " a4 %" PRId64 "\n", sdesc->name, - syscall_num, syscall_num, a1, a2, a3, a4); + "Unimplemented syscall %s number %" PRId64 "/0x%" PRIx64 " a1 %" PRId64 " a2 %" PRId64 + " a3 %" PRId64 " a4 %" PRId64 "\n", + sdesc->name, syscall_num, syscall_num, a1, a2, a3, a4); #endif (void)core; @@ -1138,9 +1137,7 @@ int OsSyscallExceptionHandler::do_sys_ftruncate( result = 0; int fd = a1; uint64_t length = core->get_xlen_from_reg(a2); - if (core->get_xlen() == Xlen::_32) { - length |= core->get_xlen_from_reg(a3) << 32; - } + if (core->get_xlen() == Xlen::_32) { length |= core->get_xlen_from_reg(a3) << 32; } printf("sys_ftruncate fd %d\n", fd); diff --git a/src/os_emulation/posix_polyfill.h b/src/os_emulation/posix_polyfill.h index a823967c..f2baa488 100644 --- a/src/os_emulation/posix_polyfill.h +++ b/src/os_emulation/posix_polyfill.h @@ -2,18 +2,18 @@ #define POSIX_POLYFILL_H #ifndef _WIN32 -// POSIX already provides these functions, just include unistd -#include + // POSIX already provides these functions, just include unistd + #include #else -// wrap the "Low-Level I/O API" provided by Microsoft CRT, which exposes -// a POSIX-like wrapper over Win32 -#include + // wrap the "Low-Level I/O API" provided by Microsoft CRT, which exposes + // a POSIX-like wrapper over Win32 + #include -#define open _open -#define close _close -#define read _read -#define write _write -#define ftruncate _chsize_s + #define open _open + #define close _close + #define read _read + #define write _write + #define ftruncate _chsize_s #endif // _WIN32 diff --git a/src/os_emulation/syscall_nr.h b/src/os_emulation/syscall_nr.h index 8c5cf73c..e38f20cf 100644 --- a/src/os_emulation/syscall_nr.h +++ b/src/os_emulation/syscall_nr.h @@ -4,377 +4,376 @@ /* * Linux o32 style syscalls are in the range from 4000 to 4999. */ -#define TARGET_NR_Linux 4000 -#define TARGET_NR_syscall (TARGET_NR_Linux + 0) -#define TARGET_NR_exit (TARGET_NR_Linux + 1) -#define TARGET_NR_fork (TARGET_NR_Linux + 2) -#define TARGET_NR_read (TARGET_NR_Linux + 3) -#define TARGET_NR_write (TARGET_NR_Linux + 4) -#define TARGET_NR_open (TARGET_NR_Linux + 5) -#define TARGET_NR_close (TARGET_NR_Linux + 6) -#define TARGET_NR_waitpid (TARGET_NR_Linux + 7) -#define TARGET_NR_creat (TARGET_NR_Linux + 8) -#define TARGET_NR_link (TARGET_NR_Linux + 9) -#define TARGET_NR_unlink (TARGET_NR_Linux + 10) -#define TARGET_NR_execve (TARGET_NR_Linux + 11) -#define TARGET_NR_chdir (TARGET_NR_Linux + 12) -#define TARGET_NR_time (TARGET_NR_Linux + 13) -#define TARGET_NR_mknod (TARGET_NR_Linux + 14) -#define TARGET_NR_chmod (TARGET_NR_Linux + 15) -#define TARGET_NR_lchown (TARGET_NR_Linux + 16) -#define TARGET_NR_break (TARGET_NR_Linux + 17) -#define TARGET_NR_unused18 (TARGET_NR_Linux + 18) -#define TARGET_NR_lseek (TARGET_NR_Linux + 19) -#define TARGET_NR_getpid (TARGET_NR_Linux + 20) -#define TARGET_NR_mount (TARGET_NR_Linux + 21) -#define TARGET_NR_umount (TARGET_NR_Linux + 22) -#define TARGET_NR_setuid (TARGET_NR_Linux + 23) -#define TARGET_NR_getuid (TARGET_NR_Linux + 24) -#define TARGET_NR_stime (TARGET_NR_Linux + 25) -#define TARGET_NR_ptrace (TARGET_NR_Linux + 26) -#define TARGET_NR_alarm (TARGET_NR_Linux + 27) -#define TARGET_NR_unused28 (TARGET_NR_Linux + 28) -#define TARGET_NR_pause (TARGET_NR_Linux + 29) -#define TARGET_NR_utime (TARGET_NR_Linux + 30) -#define TARGET_NR_stty (TARGET_NR_Linux + 31) -#define TARGET_NR_gtty (TARGET_NR_Linux + 32) -#define TARGET_NR_access (TARGET_NR_Linux + 33) -#define TARGET_NR_nice (TARGET_NR_Linux + 34) -#define TARGET_NR_ftime (TARGET_NR_Linux + 35) -#define TARGET_NR_sync (TARGET_NR_Linux + 36) -#define TARGET_NR_kill (TARGET_NR_Linux + 37) -#define TARGET_NR_rename (TARGET_NR_Linux + 38) -#define TARGET_NR_mkdir (TARGET_NR_Linux + 39) -#define TARGET_NR_rmdir (TARGET_NR_Linux + 40) -#define TARGET_NR_dup (TARGET_NR_Linux + 41) -#define TARGET_NR_pipe (TARGET_NR_Linux + 42) -#define TARGET_NR_times (TARGET_NR_Linux + 43) -#define TARGET_NR_prof (TARGET_NR_Linux + 44) -#define TARGET_NR_brk (TARGET_NR_Linux + 45) -#define TARGET_NR_setgid (TARGET_NR_Linux + 46) -#define TARGET_NR_getgid (TARGET_NR_Linux + 47) -#define TARGET_NR_signal (TARGET_NR_Linux + 48) -#define TARGET_NR_geteuid (TARGET_NR_Linux + 49) -#define TARGET_NR_getegid (TARGET_NR_Linux + 50) -#define TARGET_NR_acct (TARGET_NR_Linux + 51) -#define TARGET_NR_umount2 (TARGET_NR_Linux + 52) -#define TARGET_NR_lock (TARGET_NR_Linux + 53) -#define TARGET_NR_ioctl (TARGET_NR_Linux + 54) -#define TARGET_NR_fcntl (TARGET_NR_Linux + 55) -#define TARGET_NR_mpx (TARGET_NR_Linux + 56) -#define TARGET_NR_setpgid (TARGET_NR_Linux + 57) -#define TARGET_NR_ulimit (TARGET_NR_Linux + 58) -#define TARGET_NR_unused59 (TARGET_NR_Linux + 59) -#define TARGET_NR_umask (TARGET_NR_Linux + 60) -#define TARGET_NR_chroot (TARGET_NR_Linux + 61) -#define TARGET_NR_ustat (TARGET_NR_Linux + 62) -#define TARGET_NR_dup2 (TARGET_NR_Linux + 63) -#define TARGET_NR_getppid (TARGET_NR_Linux + 64) -#define TARGET_NR_getpgrp (TARGET_NR_Linux + 65) -#define TARGET_NR_setsid (TARGET_NR_Linux + 66) -#define TARGET_NR_sigaction (TARGET_NR_Linux + 67) -#define TARGET_NR_sgetmask (TARGET_NR_Linux + 68) -#define TARGET_NR_ssetmask (TARGET_NR_Linux + 69) -#define TARGET_NR_setreuid (TARGET_NR_Linux + 70) -#define TARGET_NR_setregid (TARGET_NR_Linux + 71) -#define TARGET_NR_sigsuspend (TARGET_NR_Linux + 72) -#define TARGET_NR_sigpending (TARGET_NR_Linux + 73) -#define TARGET_NR_sethostname (TARGET_NR_Linux + 74) -#define TARGET_NR_setrlimit (TARGET_NR_Linux + 75) -#define TARGET_NR_getrlimit (TARGET_NR_Linux + 76) -#define TARGET_NR_getrusage (TARGET_NR_Linux + 77) -#define TARGET_NR_gettimeofday (TARGET_NR_Linux + 78) -#define TARGET_NR_settimeofday (TARGET_NR_Linux + 79) -#define TARGET_NR_getgroups (TARGET_NR_Linux + 80) -#define TARGET_NR_setgroups (TARGET_NR_Linux + 81) -#define TARGET_NR_reserved82 (TARGET_NR_Linux + 82) -#define TARGET_NR_symlink (TARGET_NR_Linux + 83) -#define TARGET_NR_unused84 (TARGET_NR_Linux + 84) -#define TARGET_NR_readlink (TARGET_NR_Linux + 85) -#define TARGET_NR_uselib (TARGET_NR_Linux + 86) -#define TARGET_NR_swapon (TARGET_NR_Linux + 87) -#define TARGET_NR_reboot (TARGET_NR_Linux + 88) -#define TARGET_NR_readdir (TARGET_NR_Linux + 89) -#define TARGET_NR_mmap (TARGET_NR_Linux + 90) -#define TARGET_NR_munmap (TARGET_NR_Linux + 91) -#define TARGET_NR_truncate (TARGET_NR_Linux + 92) -#define TARGET_NR_ftruncate (TARGET_NR_Linux + 93) -#define TARGET_NR_fchmod (TARGET_NR_Linux + 94) -#define TARGET_NR_fchown (TARGET_NR_Linux + 95) -#define TARGET_NR_getpriority (TARGET_NR_Linux + 96) -#define TARGET_NR_setpriority (TARGET_NR_Linux + 97) -#define TARGET_NR_profil (TARGET_NR_Linux + 98) -#define TARGET_NR_statfs (TARGET_NR_Linux + 99) -#define TARGET_NR_fstatfs (TARGET_NR_Linux + 100) -#define TARGET_NR_ioperm (TARGET_NR_Linux + 101) -#define TARGET_NR_socketcall (TARGET_NR_Linux + 102) -#define TARGET_NR_syslog (TARGET_NR_Linux + 103) -#define TARGET_NR_setitimer (TARGET_NR_Linux + 104) -#define TARGET_NR_getitimer (TARGET_NR_Linux + 105) -#define TARGET_NR_stat (TARGET_NR_Linux + 106) -#define TARGET_NR_lstat (TARGET_NR_Linux + 107) -#define TARGET_NR_fstat (TARGET_NR_Linux + 108) -#define TARGET_NR_unused109 (TARGET_NR_Linux + 109) -#define TARGET_NR_iopl (TARGET_NR_Linux + 110) -#define TARGET_NR_vhangup (TARGET_NR_Linux + 111) -#define TARGET_NR_idle (TARGET_NR_Linux + 112) -#define TARGET_NR_vm86 (TARGET_NR_Linux + 113) -#define TARGET_NR_wait4 (TARGET_NR_Linux + 114) -#define TARGET_NR_swapoff (TARGET_NR_Linux + 115) -#define TARGET_NR_sysinfo (TARGET_NR_Linux + 116) -#define TARGET_NR_ipc (TARGET_NR_Linux + 117) -#define TARGET_NR_fsync (TARGET_NR_Linux + 118) -#define TARGET_NR_sigreturn (TARGET_NR_Linux + 119) -#define TARGET_NR_clone (TARGET_NR_Linux + 120) -#define TARGET_NR_setdomainname (TARGET_NR_Linux + 121) -#define TARGET_NR_uname (TARGET_NR_Linux + 122) -#define TARGET_NR_modify_ldt (TARGET_NR_Linux + 123) -#define TARGET_NR_adjtimex (TARGET_NR_Linux + 124) -#define TARGET_NR_mprotect (TARGET_NR_Linux + 125) -#define TARGET_NR_sigprocmask (TARGET_NR_Linux + 126) -#define TARGET_NR_create_module (TARGET_NR_Linux + 127) -#define TARGET_NR_init_module (TARGET_NR_Linux + 128) -#define TARGET_NR_delete_module (TARGET_NR_Linux + 129) -#define TARGET_NR_get_kernel_syms (TARGET_NR_Linux + 130) -#define TARGET_NR_quotactl (TARGET_NR_Linux + 131) -#define TARGET_NR_getpgid (TARGET_NR_Linux + 132) -#define TARGET_NR_fchdir (TARGET_NR_Linux + 133) -#define TARGET_NR_bdflush (TARGET_NR_Linux + 134) -#define TARGET_NR_sysfs (TARGET_NR_Linux + 135) -#define TARGET_NR_personality (TARGET_NR_Linux + 136) -#define TARGET_NR_afs_syscall \ - (TARGET_NR_Linux + 137) /* Syscall for Andrew File System */ -#define TARGET_NR_setfsuid (TARGET_NR_Linux + 138) -#define TARGET_NR_setfsgid (TARGET_NR_Linux + 139) -#define TARGET_NR__llseek (TARGET_NR_Linux + 140) -#define TARGET_NR_getdents (TARGET_NR_Linux + 141) -#define TARGET_NR__newselect (TARGET_NR_Linux + 142) -#define TARGET_NR_flock (TARGET_NR_Linux + 143) -#define TARGET_NR_msync (TARGET_NR_Linux + 144) -#define TARGET_NR_readv (TARGET_NR_Linux + 145) -#define TARGET_NR_writev (TARGET_NR_Linux + 146) -#define TARGET_NR_cacheflush (TARGET_NR_Linux + 147) -#define TARGET_NR_cachectl (TARGET_NR_Linux + 148) -#define TARGET_NR_sysmips (TARGET_NR_Linux + 149) -#define TARGET_NR_unused150 (TARGET_NR_Linux + 150) -#define TARGET_NR_getsid (TARGET_NR_Linux + 151) -#define TARGET_NR_fdatasync (TARGET_NR_Linux + 152) -#define TARGET_NR__sysctl (TARGET_NR_Linux + 153) -#define TARGET_NR_mlock (TARGET_NR_Linux + 154) -#define TARGET_NR_munlock (TARGET_NR_Linux + 155) -#define TARGET_NR_mlockall (TARGET_NR_Linux + 156) -#define TARGET_NR_munlockall (TARGET_NR_Linux + 157) -#define TARGET_NR_sched_setparam (TARGET_NR_Linux + 158) -#define TARGET_NR_sched_getparam (TARGET_NR_Linux + 159) -#define TARGET_NR_sched_setscheduler (TARGET_NR_Linux + 160) -#define TARGET_NR_sched_getscheduler (TARGET_NR_Linux + 161) -#define TARGET_NR_sched_yield (TARGET_NR_Linux + 162) +#define TARGET_NR_Linux 4000 +#define TARGET_NR_syscall (TARGET_NR_Linux + 0) +#define TARGET_NR_exit (TARGET_NR_Linux + 1) +#define TARGET_NR_fork (TARGET_NR_Linux + 2) +#define TARGET_NR_read (TARGET_NR_Linux + 3) +#define TARGET_NR_write (TARGET_NR_Linux + 4) +#define TARGET_NR_open (TARGET_NR_Linux + 5) +#define TARGET_NR_close (TARGET_NR_Linux + 6) +#define TARGET_NR_waitpid (TARGET_NR_Linux + 7) +#define TARGET_NR_creat (TARGET_NR_Linux + 8) +#define TARGET_NR_link (TARGET_NR_Linux + 9) +#define TARGET_NR_unlink (TARGET_NR_Linux + 10) +#define TARGET_NR_execve (TARGET_NR_Linux + 11) +#define TARGET_NR_chdir (TARGET_NR_Linux + 12) +#define TARGET_NR_time (TARGET_NR_Linux + 13) +#define TARGET_NR_mknod (TARGET_NR_Linux + 14) +#define TARGET_NR_chmod (TARGET_NR_Linux + 15) +#define TARGET_NR_lchown (TARGET_NR_Linux + 16) +#define TARGET_NR_break (TARGET_NR_Linux + 17) +#define TARGET_NR_unused18 (TARGET_NR_Linux + 18) +#define TARGET_NR_lseek (TARGET_NR_Linux + 19) +#define TARGET_NR_getpid (TARGET_NR_Linux + 20) +#define TARGET_NR_mount (TARGET_NR_Linux + 21) +#define TARGET_NR_umount (TARGET_NR_Linux + 22) +#define TARGET_NR_setuid (TARGET_NR_Linux + 23) +#define TARGET_NR_getuid (TARGET_NR_Linux + 24) +#define TARGET_NR_stime (TARGET_NR_Linux + 25) +#define TARGET_NR_ptrace (TARGET_NR_Linux + 26) +#define TARGET_NR_alarm (TARGET_NR_Linux + 27) +#define TARGET_NR_unused28 (TARGET_NR_Linux + 28) +#define TARGET_NR_pause (TARGET_NR_Linux + 29) +#define TARGET_NR_utime (TARGET_NR_Linux + 30) +#define TARGET_NR_stty (TARGET_NR_Linux + 31) +#define TARGET_NR_gtty (TARGET_NR_Linux + 32) +#define TARGET_NR_access (TARGET_NR_Linux + 33) +#define TARGET_NR_nice (TARGET_NR_Linux + 34) +#define TARGET_NR_ftime (TARGET_NR_Linux + 35) +#define TARGET_NR_sync (TARGET_NR_Linux + 36) +#define TARGET_NR_kill (TARGET_NR_Linux + 37) +#define TARGET_NR_rename (TARGET_NR_Linux + 38) +#define TARGET_NR_mkdir (TARGET_NR_Linux + 39) +#define TARGET_NR_rmdir (TARGET_NR_Linux + 40) +#define TARGET_NR_dup (TARGET_NR_Linux + 41) +#define TARGET_NR_pipe (TARGET_NR_Linux + 42) +#define TARGET_NR_times (TARGET_NR_Linux + 43) +#define TARGET_NR_prof (TARGET_NR_Linux + 44) +#define TARGET_NR_brk (TARGET_NR_Linux + 45) +#define TARGET_NR_setgid (TARGET_NR_Linux + 46) +#define TARGET_NR_getgid (TARGET_NR_Linux + 47) +#define TARGET_NR_signal (TARGET_NR_Linux + 48) +#define TARGET_NR_geteuid (TARGET_NR_Linux + 49) +#define TARGET_NR_getegid (TARGET_NR_Linux + 50) +#define TARGET_NR_acct (TARGET_NR_Linux + 51) +#define TARGET_NR_umount2 (TARGET_NR_Linux + 52) +#define TARGET_NR_lock (TARGET_NR_Linux + 53) +#define TARGET_NR_ioctl (TARGET_NR_Linux + 54) +#define TARGET_NR_fcntl (TARGET_NR_Linux + 55) +#define TARGET_NR_mpx (TARGET_NR_Linux + 56) +#define TARGET_NR_setpgid (TARGET_NR_Linux + 57) +#define TARGET_NR_ulimit (TARGET_NR_Linux + 58) +#define TARGET_NR_unused59 (TARGET_NR_Linux + 59) +#define TARGET_NR_umask (TARGET_NR_Linux + 60) +#define TARGET_NR_chroot (TARGET_NR_Linux + 61) +#define TARGET_NR_ustat (TARGET_NR_Linux + 62) +#define TARGET_NR_dup2 (TARGET_NR_Linux + 63) +#define TARGET_NR_getppid (TARGET_NR_Linux + 64) +#define TARGET_NR_getpgrp (TARGET_NR_Linux + 65) +#define TARGET_NR_setsid (TARGET_NR_Linux + 66) +#define TARGET_NR_sigaction (TARGET_NR_Linux + 67) +#define TARGET_NR_sgetmask (TARGET_NR_Linux + 68) +#define TARGET_NR_ssetmask (TARGET_NR_Linux + 69) +#define TARGET_NR_setreuid (TARGET_NR_Linux + 70) +#define TARGET_NR_setregid (TARGET_NR_Linux + 71) +#define TARGET_NR_sigsuspend (TARGET_NR_Linux + 72) +#define TARGET_NR_sigpending (TARGET_NR_Linux + 73) +#define TARGET_NR_sethostname (TARGET_NR_Linux + 74) +#define TARGET_NR_setrlimit (TARGET_NR_Linux + 75) +#define TARGET_NR_getrlimit (TARGET_NR_Linux + 76) +#define TARGET_NR_getrusage (TARGET_NR_Linux + 77) +#define TARGET_NR_gettimeofday (TARGET_NR_Linux + 78) +#define TARGET_NR_settimeofday (TARGET_NR_Linux + 79) +#define TARGET_NR_getgroups (TARGET_NR_Linux + 80) +#define TARGET_NR_setgroups (TARGET_NR_Linux + 81) +#define TARGET_NR_reserved82 (TARGET_NR_Linux + 82) +#define TARGET_NR_symlink (TARGET_NR_Linux + 83) +#define TARGET_NR_unused84 (TARGET_NR_Linux + 84) +#define TARGET_NR_readlink (TARGET_NR_Linux + 85) +#define TARGET_NR_uselib (TARGET_NR_Linux + 86) +#define TARGET_NR_swapon (TARGET_NR_Linux + 87) +#define TARGET_NR_reboot (TARGET_NR_Linux + 88) +#define TARGET_NR_readdir (TARGET_NR_Linux + 89) +#define TARGET_NR_mmap (TARGET_NR_Linux + 90) +#define TARGET_NR_munmap (TARGET_NR_Linux + 91) +#define TARGET_NR_truncate (TARGET_NR_Linux + 92) +#define TARGET_NR_ftruncate (TARGET_NR_Linux + 93) +#define TARGET_NR_fchmod (TARGET_NR_Linux + 94) +#define TARGET_NR_fchown (TARGET_NR_Linux + 95) +#define TARGET_NR_getpriority (TARGET_NR_Linux + 96) +#define TARGET_NR_setpriority (TARGET_NR_Linux + 97) +#define TARGET_NR_profil (TARGET_NR_Linux + 98) +#define TARGET_NR_statfs (TARGET_NR_Linux + 99) +#define TARGET_NR_fstatfs (TARGET_NR_Linux + 100) +#define TARGET_NR_ioperm (TARGET_NR_Linux + 101) +#define TARGET_NR_socketcall (TARGET_NR_Linux + 102) +#define TARGET_NR_syslog (TARGET_NR_Linux + 103) +#define TARGET_NR_setitimer (TARGET_NR_Linux + 104) +#define TARGET_NR_getitimer (TARGET_NR_Linux + 105) +#define TARGET_NR_stat (TARGET_NR_Linux + 106) +#define TARGET_NR_lstat (TARGET_NR_Linux + 107) +#define TARGET_NR_fstat (TARGET_NR_Linux + 108) +#define TARGET_NR_unused109 (TARGET_NR_Linux + 109) +#define TARGET_NR_iopl (TARGET_NR_Linux + 110) +#define TARGET_NR_vhangup (TARGET_NR_Linux + 111) +#define TARGET_NR_idle (TARGET_NR_Linux + 112) +#define TARGET_NR_vm86 (TARGET_NR_Linux + 113) +#define TARGET_NR_wait4 (TARGET_NR_Linux + 114) +#define TARGET_NR_swapoff (TARGET_NR_Linux + 115) +#define TARGET_NR_sysinfo (TARGET_NR_Linux + 116) +#define TARGET_NR_ipc (TARGET_NR_Linux + 117) +#define TARGET_NR_fsync (TARGET_NR_Linux + 118) +#define TARGET_NR_sigreturn (TARGET_NR_Linux + 119) +#define TARGET_NR_clone (TARGET_NR_Linux + 120) +#define TARGET_NR_setdomainname (TARGET_NR_Linux + 121) +#define TARGET_NR_uname (TARGET_NR_Linux + 122) +#define TARGET_NR_modify_ldt (TARGET_NR_Linux + 123) +#define TARGET_NR_adjtimex (TARGET_NR_Linux + 124) +#define TARGET_NR_mprotect (TARGET_NR_Linux + 125) +#define TARGET_NR_sigprocmask (TARGET_NR_Linux + 126) +#define TARGET_NR_create_module (TARGET_NR_Linux + 127) +#define TARGET_NR_init_module (TARGET_NR_Linux + 128) +#define TARGET_NR_delete_module (TARGET_NR_Linux + 129) +#define TARGET_NR_get_kernel_syms (TARGET_NR_Linux + 130) +#define TARGET_NR_quotactl (TARGET_NR_Linux + 131) +#define TARGET_NR_getpgid (TARGET_NR_Linux + 132) +#define TARGET_NR_fchdir (TARGET_NR_Linux + 133) +#define TARGET_NR_bdflush (TARGET_NR_Linux + 134) +#define TARGET_NR_sysfs (TARGET_NR_Linux + 135) +#define TARGET_NR_personality (TARGET_NR_Linux + 136) +#define TARGET_NR_afs_syscall (TARGET_NR_Linux + 137) /* Syscall for Andrew File System */ +#define TARGET_NR_setfsuid (TARGET_NR_Linux + 138) +#define TARGET_NR_setfsgid (TARGET_NR_Linux + 139) +#define TARGET_NR__llseek (TARGET_NR_Linux + 140) +#define TARGET_NR_getdents (TARGET_NR_Linux + 141) +#define TARGET_NR__newselect (TARGET_NR_Linux + 142) +#define TARGET_NR_flock (TARGET_NR_Linux + 143) +#define TARGET_NR_msync (TARGET_NR_Linux + 144) +#define TARGET_NR_readv (TARGET_NR_Linux + 145) +#define TARGET_NR_writev (TARGET_NR_Linux + 146) +#define TARGET_NR_cacheflush (TARGET_NR_Linux + 147) +#define TARGET_NR_cachectl (TARGET_NR_Linux + 148) +#define TARGET_NR_sysmips (TARGET_NR_Linux + 149) +#define TARGET_NR_unused150 (TARGET_NR_Linux + 150) +#define TARGET_NR_getsid (TARGET_NR_Linux + 151) +#define TARGET_NR_fdatasync (TARGET_NR_Linux + 152) +#define TARGET_NR__sysctl (TARGET_NR_Linux + 153) +#define TARGET_NR_mlock (TARGET_NR_Linux + 154) +#define TARGET_NR_munlock (TARGET_NR_Linux + 155) +#define TARGET_NR_mlockall (TARGET_NR_Linux + 156) +#define TARGET_NR_munlockall (TARGET_NR_Linux + 157) +#define TARGET_NR_sched_setparam (TARGET_NR_Linux + 158) +#define TARGET_NR_sched_getparam (TARGET_NR_Linux + 159) +#define TARGET_NR_sched_setscheduler (TARGET_NR_Linux + 160) +#define TARGET_NR_sched_getscheduler (TARGET_NR_Linux + 161) +#define TARGET_NR_sched_yield (TARGET_NR_Linux + 162) #define TARGET_NR_sched_get_priority_max (TARGET_NR_Linux + 163) #define TARGET_NR_sched_get_priority_min (TARGET_NR_Linux + 164) -#define TARGET_NR_sched_rr_get_interval (TARGET_NR_Linux + 165) -#define TARGET_NR_nanosleep (TARGET_NR_Linux + 166) -#define TARGET_NR_mremap (TARGET_NR_Linux + 167) -#define TARGET_NR_accept (TARGET_NR_Linux + 168) -#define TARGET_NR_bind (TARGET_NR_Linux + 169) -#define TARGET_NR_connect (TARGET_NR_Linux + 170) -#define TARGET_NR_getpeername (TARGET_NR_Linux + 171) -#define TARGET_NR_getsockname (TARGET_NR_Linux + 172) -#define TARGET_NR_getsockopt (TARGET_NR_Linux + 173) -#define TARGET_NR_listen (TARGET_NR_Linux + 174) -#define TARGET_NR_recv (TARGET_NR_Linux + 175) -#define TARGET_NR_recvfrom (TARGET_NR_Linux + 176) -#define TARGET_NR_recvmsg (TARGET_NR_Linux + 177) -#define TARGET_NR_send (TARGET_NR_Linux + 178) -#define TARGET_NR_sendmsg (TARGET_NR_Linux + 179) -#define TARGET_NR_sendto (TARGET_NR_Linux + 180) -#define TARGET_NR_setsockopt (TARGET_NR_Linux + 181) -#define TARGET_NR_shutdown (TARGET_NR_Linux + 182) -#define TARGET_NR_socket (TARGET_NR_Linux + 183) -#define TARGET_NR_socketpair (TARGET_NR_Linux + 184) -#define TARGET_NR_setresuid (TARGET_NR_Linux + 185) -#define TARGET_NR_getresuid (TARGET_NR_Linux + 186) -#define TARGET_NR_query_module (TARGET_NR_Linux + 187) -#define TARGET_NR_poll (TARGET_NR_Linux + 188) -#define TARGET_NR_nfsservctl (TARGET_NR_Linux + 189) -#define TARGET_NR_setresgid (TARGET_NR_Linux + 190) -#define TARGET_NR_getresgid (TARGET_NR_Linux + 191) -#define TARGET_NR_prctl (TARGET_NR_Linux + 192) -#define TARGET_NR_rt_sigreturn (TARGET_NR_Linux + 193) -#define TARGET_NR_rt_sigaction (TARGET_NR_Linux + 194) -#define TARGET_NR_rt_sigprocmask (TARGET_NR_Linux + 195) -#define TARGET_NR_rt_sigpending (TARGET_NR_Linux + 196) -#define TARGET_NR_rt_sigtimedwait (TARGET_NR_Linux + 197) -#define TARGET_NR_rt_sigqueueinfo (TARGET_NR_Linux + 198) -#define TARGET_NR_rt_sigsuspend (TARGET_NR_Linux + 199) -#define TARGET_NR_pread64 (TARGET_NR_Linux + 200) -#define TARGET_NR_pwrite64 (TARGET_NR_Linux + 201) -#define TARGET_NR_chown (TARGET_NR_Linux + 202) -#define TARGET_NR_getcwd (TARGET_NR_Linux + 203) -#define TARGET_NR_capget (TARGET_NR_Linux + 204) -#define TARGET_NR_capset (TARGET_NR_Linux + 205) -#define TARGET_NR_sigaltstack (TARGET_NR_Linux + 206) -#define TARGET_NR_sendfile (TARGET_NR_Linux + 207) -#define TARGET_NR_getpmsg (TARGET_NR_Linux + 208) -#define TARGET_NR_putpmsg (TARGET_NR_Linux + 209) -#define TARGET_NR_mmap2 (TARGET_NR_Linux + 210) -#define TARGET_NR_truncate64 (TARGET_NR_Linux + 211) -#define TARGET_NR_ftruncate64 (TARGET_NR_Linux + 212) -#define TARGET_NR_stat64 (TARGET_NR_Linux + 213) -#define TARGET_NR_lstat64 (TARGET_NR_Linux + 214) -#define TARGET_NR_fstat64 (TARGET_NR_Linux + 215) -#define TARGET_NR_pivot_root (TARGET_NR_Linux + 216) -#define TARGET_NR_mincore (TARGET_NR_Linux + 217) -#define TARGET_NR_madvise (TARGET_NR_Linux + 218) -#define TARGET_NR_getdents64 (TARGET_NR_Linux + 219) -#define TARGET_NR_fcntl64 (TARGET_NR_Linux + 220) -#define TARGET_NR_reserved221 (TARGET_NR_Linux + 221) -#define TARGET_NR_gettid (TARGET_NR_Linux + 222) -#define TARGET_NR_readahead (TARGET_NR_Linux + 223) -#define TARGET_NR_setxattr (TARGET_NR_Linux + 224) -#define TARGET_NR_lsetxattr (TARGET_NR_Linux + 225) -#define TARGET_NR_fsetxattr (TARGET_NR_Linux + 226) -#define TARGET_NR_getxattr (TARGET_NR_Linux + 227) -#define TARGET_NR_lgetxattr (TARGET_NR_Linux + 228) -#define TARGET_NR_fgetxattr (TARGET_NR_Linux + 229) -#define TARGET_NR_listxattr (TARGET_NR_Linux + 230) -#define TARGET_NR_llistxattr (TARGET_NR_Linux + 231) -#define TARGET_NR_flistxattr (TARGET_NR_Linux + 232) -#define TARGET_NR_removexattr (TARGET_NR_Linux + 233) -#define TARGET_NR_lremovexattr (TARGET_NR_Linux + 234) -#define TARGET_NR_fremovexattr (TARGET_NR_Linux + 235) -#define TARGET_NR_tkill (TARGET_NR_Linux + 236) -#define TARGET_NR_sendfile64 (TARGET_NR_Linux + 237) -#define TARGET_NR_futex (TARGET_NR_Linux + 238) -#define TARGET_NR_sched_setaffinity (TARGET_NR_Linux + 239) -#define TARGET_NR_sched_getaffinity (TARGET_NR_Linux + 240) -#define TARGET_NR_io_setup (TARGET_NR_Linux + 241) -#define TARGET_NR_io_destroy (TARGET_NR_Linux + 242) -#define TARGET_NR_io_getevents (TARGET_NR_Linux + 243) -#define TARGET_NR_io_submit (TARGET_NR_Linux + 244) -#define TARGET_NR_io_cancel (TARGET_NR_Linux + 245) -#define TARGET_NR_exit_group (TARGET_NR_Linux + 246) -#define TARGET_NR_lookup_dcookie (TARGET_NR_Linux + 247) -#define TARGET_NR_epoll_create (TARGET_NR_Linux + 248) -#define TARGET_NR_epoll_ctl (TARGET_NR_Linux + 249) -#define TARGET_NR_epoll_wait (TARGET_NR_Linux + 250) -#define TARGET_NR_remap_file_pages (TARGET_NR_Linux + 251) -#define TARGET_NR_set_tid_address (TARGET_NR_Linux + 252) -#define TARGET_NR_restart_syscall (TARGET_NR_Linux + 253) -#define TARGET_NR_fadvise64_64 (TARGET_NR_Linux + 254) -#define TARGET_NR_statfs64 (TARGET_NR_Linux + 255) -#define TARGET_NR_fstatfs64 (TARGET_NR_Linux + 256) -#define TARGET_NR_timer_create (TARGET_NR_Linux + 257) -#define TARGET_NR_timer_settime (TARGET_NR_Linux + 258) -#define TARGET_NR_timer_gettime (TARGET_NR_Linux + 259) -#define TARGET_NR_timer_getoverrun (TARGET_NR_Linux + 260) -#define TARGET_NR_timer_delete (TARGET_NR_Linux + 261) -#define TARGET_NR_clock_settime (TARGET_NR_Linux + 262) -#define TARGET_NR_clock_gettime (TARGET_NR_Linux + 263) -#define TARGET_NR_clock_getres (TARGET_NR_Linux + 264) -#define TARGET_NR_clock_nanosleep (TARGET_NR_Linux + 265) -#define TARGET_NR_tgkill (TARGET_NR_Linux + 266) -#define TARGET_NR_utimes (TARGET_NR_Linux + 267) -#define TARGET_NR_mbind (TARGET_NR_Linux + 268) -#define TARGET_NR_get_mempolicy (TARGET_NR_Linux + 269) -#define TARGET_NR_set_mempolicy (TARGET_NR_Linux + 270) -#define TARGET_NR_mq_open (TARGET_NR_Linux + 271) -#define TARGET_NR_mq_unlink (TARGET_NR_Linux + 272) -#define TARGET_NR_mq_timedsend (TARGET_NR_Linux + 273) -#define TARGET_NR_mq_timedreceive (TARGET_NR_Linux + 274) -#define TARGET_NR_mq_notify (TARGET_NR_Linux + 275) -#define TARGET_NR_mq_getsetattr (TARGET_NR_Linux + 276) -#define TARGET_NR_vserver (TARGET_NR_Linux + 277) -#define TARGET_NR_waitid (TARGET_NR_Linux + 278) +#define TARGET_NR_sched_rr_get_interval (TARGET_NR_Linux + 165) +#define TARGET_NR_nanosleep (TARGET_NR_Linux + 166) +#define TARGET_NR_mremap (TARGET_NR_Linux + 167) +#define TARGET_NR_accept (TARGET_NR_Linux + 168) +#define TARGET_NR_bind (TARGET_NR_Linux + 169) +#define TARGET_NR_connect (TARGET_NR_Linux + 170) +#define TARGET_NR_getpeername (TARGET_NR_Linux + 171) +#define TARGET_NR_getsockname (TARGET_NR_Linux + 172) +#define TARGET_NR_getsockopt (TARGET_NR_Linux + 173) +#define TARGET_NR_listen (TARGET_NR_Linux + 174) +#define TARGET_NR_recv (TARGET_NR_Linux + 175) +#define TARGET_NR_recvfrom (TARGET_NR_Linux + 176) +#define TARGET_NR_recvmsg (TARGET_NR_Linux + 177) +#define TARGET_NR_send (TARGET_NR_Linux + 178) +#define TARGET_NR_sendmsg (TARGET_NR_Linux + 179) +#define TARGET_NR_sendto (TARGET_NR_Linux + 180) +#define TARGET_NR_setsockopt (TARGET_NR_Linux + 181) +#define TARGET_NR_shutdown (TARGET_NR_Linux + 182) +#define TARGET_NR_socket (TARGET_NR_Linux + 183) +#define TARGET_NR_socketpair (TARGET_NR_Linux + 184) +#define TARGET_NR_setresuid (TARGET_NR_Linux + 185) +#define TARGET_NR_getresuid (TARGET_NR_Linux + 186) +#define TARGET_NR_query_module (TARGET_NR_Linux + 187) +#define TARGET_NR_poll (TARGET_NR_Linux + 188) +#define TARGET_NR_nfsservctl (TARGET_NR_Linux + 189) +#define TARGET_NR_setresgid (TARGET_NR_Linux + 190) +#define TARGET_NR_getresgid (TARGET_NR_Linux + 191) +#define TARGET_NR_prctl (TARGET_NR_Linux + 192) +#define TARGET_NR_rt_sigreturn (TARGET_NR_Linux + 193) +#define TARGET_NR_rt_sigaction (TARGET_NR_Linux + 194) +#define TARGET_NR_rt_sigprocmask (TARGET_NR_Linux + 195) +#define TARGET_NR_rt_sigpending (TARGET_NR_Linux + 196) +#define TARGET_NR_rt_sigtimedwait (TARGET_NR_Linux + 197) +#define TARGET_NR_rt_sigqueueinfo (TARGET_NR_Linux + 198) +#define TARGET_NR_rt_sigsuspend (TARGET_NR_Linux + 199) +#define TARGET_NR_pread64 (TARGET_NR_Linux + 200) +#define TARGET_NR_pwrite64 (TARGET_NR_Linux + 201) +#define TARGET_NR_chown (TARGET_NR_Linux + 202) +#define TARGET_NR_getcwd (TARGET_NR_Linux + 203) +#define TARGET_NR_capget (TARGET_NR_Linux + 204) +#define TARGET_NR_capset (TARGET_NR_Linux + 205) +#define TARGET_NR_sigaltstack (TARGET_NR_Linux + 206) +#define TARGET_NR_sendfile (TARGET_NR_Linux + 207) +#define TARGET_NR_getpmsg (TARGET_NR_Linux + 208) +#define TARGET_NR_putpmsg (TARGET_NR_Linux + 209) +#define TARGET_NR_mmap2 (TARGET_NR_Linux + 210) +#define TARGET_NR_truncate64 (TARGET_NR_Linux + 211) +#define TARGET_NR_ftruncate64 (TARGET_NR_Linux + 212) +#define TARGET_NR_stat64 (TARGET_NR_Linux + 213) +#define TARGET_NR_lstat64 (TARGET_NR_Linux + 214) +#define TARGET_NR_fstat64 (TARGET_NR_Linux + 215) +#define TARGET_NR_pivot_root (TARGET_NR_Linux + 216) +#define TARGET_NR_mincore (TARGET_NR_Linux + 217) +#define TARGET_NR_madvise (TARGET_NR_Linux + 218) +#define TARGET_NR_getdents64 (TARGET_NR_Linux + 219) +#define TARGET_NR_fcntl64 (TARGET_NR_Linux + 220) +#define TARGET_NR_reserved221 (TARGET_NR_Linux + 221) +#define TARGET_NR_gettid (TARGET_NR_Linux + 222) +#define TARGET_NR_readahead (TARGET_NR_Linux + 223) +#define TARGET_NR_setxattr (TARGET_NR_Linux + 224) +#define TARGET_NR_lsetxattr (TARGET_NR_Linux + 225) +#define TARGET_NR_fsetxattr (TARGET_NR_Linux + 226) +#define TARGET_NR_getxattr (TARGET_NR_Linux + 227) +#define TARGET_NR_lgetxattr (TARGET_NR_Linux + 228) +#define TARGET_NR_fgetxattr (TARGET_NR_Linux + 229) +#define TARGET_NR_listxattr (TARGET_NR_Linux + 230) +#define TARGET_NR_llistxattr (TARGET_NR_Linux + 231) +#define TARGET_NR_flistxattr (TARGET_NR_Linux + 232) +#define TARGET_NR_removexattr (TARGET_NR_Linux + 233) +#define TARGET_NR_lremovexattr (TARGET_NR_Linux + 234) +#define TARGET_NR_fremovexattr (TARGET_NR_Linux + 235) +#define TARGET_NR_tkill (TARGET_NR_Linux + 236) +#define TARGET_NR_sendfile64 (TARGET_NR_Linux + 237) +#define TARGET_NR_futex (TARGET_NR_Linux + 238) +#define TARGET_NR_sched_setaffinity (TARGET_NR_Linux + 239) +#define TARGET_NR_sched_getaffinity (TARGET_NR_Linux + 240) +#define TARGET_NR_io_setup (TARGET_NR_Linux + 241) +#define TARGET_NR_io_destroy (TARGET_NR_Linux + 242) +#define TARGET_NR_io_getevents (TARGET_NR_Linux + 243) +#define TARGET_NR_io_submit (TARGET_NR_Linux + 244) +#define TARGET_NR_io_cancel (TARGET_NR_Linux + 245) +#define TARGET_NR_exit_group (TARGET_NR_Linux + 246) +#define TARGET_NR_lookup_dcookie (TARGET_NR_Linux + 247) +#define TARGET_NR_epoll_create (TARGET_NR_Linux + 248) +#define TARGET_NR_epoll_ctl (TARGET_NR_Linux + 249) +#define TARGET_NR_epoll_wait (TARGET_NR_Linux + 250) +#define TARGET_NR_remap_file_pages (TARGET_NR_Linux + 251) +#define TARGET_NR_set_tid_address (TARGET_NR_Linux + 252) +#define TARGET_NR_restart_syscall (TARGET_NR_Linux + 253) +#define TARGET_NR_fadvise64_64 (TARGET_NR_Linux + 254) +#define TARGET_NR_statfs64 (TARGET_NR_Linux + 255) +#define TARGET_NR_fstatfs64 (TARGET_NR_Linux + 256) +#define TARGET_NR_timer_create (TARGET_NR_Linux + 257) +#define TARGET_NR_timer_settime (TARGET_NR_Linux + 258) +#define TARGET_NR_timer_gettime (TARGET_NR_Linux + 259) +#define TARGET_NR_timer_getoverrun (TARGET_NR_Linux + 260) +#define TARGET_NR_timer_delete (TARGET_NR_Linux + 261) +#define TARGET_NR_clock_settime (TARGET_NR_Linux + 262) +#define TARGET_NR_clock_gettime (TARGET_NR_Linux + 263) +#define TARGET_NR_clock_getres (TARGET_NR_Linux + 264) +#define TARGET_NR_clock_nanosleep (TARGET_NR_Linux + 265) +#define TARGET_NR_tgkill (TARGET_NR_Linux + 266) +#define TARGET_NR_utimes (TARGET_NR_Linux + 267) +#define TARGET_NR_mbind (TARGET_NR_Linux + 268) +#define TARGET_NR_get_mempolicy (TARGET_NR_Linux + 269) +#define TARGET_NR_set_mempolicy (TARGET_NR_Linux + 270) +#define TARGET_NR_mq_open (TARGET_NR_Linux + 271) +#define TARGET_NR_mq_unlink (TARGET_NR_Linux + 272) +#define TARGET_NR_mq_timedsend (TARGET_NR_Linux + 273) +#define TARGET_NR_mq_timedreceive (TARGET_NR_Linux + 274) +#define TARGET_NR_mq_notify (TARGET_NR_Linux + 275) +#define TARGET_NR_mq_getsetattr (TARGET_NR_Linux + 276) +#define TARGET_NR_vserver (TARGET_NR_Linux + 277) +#define TARGET_NR_waitid (TARGET_NR_Linux + 278) /* #define TARGET_NR_sys_setaltroot (TARGET_NR_Linux + 279) */ -#define TARGET_NR_add_key (TARGET_NR_Linux + 280) -#define TARGET_NR_request_key (TARGET_NR_Linux + 281) -#define TARGET_NR_keyctl (TARGET_NR_Linux + 282) -#define TARGET_NR_set_thread_area (TARGET_NR_Linux + 283) -#define TARGET_NR_inotify_init (TARGET_NR_Linux + 284) +#define TARGET_NR_add_key (TARGET_NR_Linux + 280) +#define TARGET_NR_request_key (TARGET_NR_Linux + 281) +#define TARGET_NR_keyctl (TARGET_NR_Linux + 282) +#define TARGET_NR_set_thread_area (TARGET_NR_Linux + 283) +#define TARGET_NR_inotify_init (TARGET_NR_Linux + 284) #define TARGET_NR_inotify_add_watch (TARGET_NR_Linux + 285) -#define TARGET_NR_inotify_rm_watch (TARGET_NR_Linux + 286) -#define TARGET_NR_migrate_pages (TARGET_NR_Linux + 287) -#define TARGET_NR_openat (TARGET_NR_Linux + 288) -#define TARGET_NR_mkdirat (TARGET_NR_Linux + 289) -#define TARGET_NR_mknodat (TARGET_NR_Linux + 290) -#define TARGET_NR_fchownat (TARGET_NR_Linux + 291) -#define TARGET_NR_futimesat (TARGET_NR_Linux + 292) -#define TARGET_NR_fstatat64 (TARGET_NR_Linux + 293) -#define TARGET_NR_unlinkat (TARGET_NR_Linux + 294) -#define TARGET_NR_renameat (TARGET_NR_Linux + 295) -#define TARGET_NR_linkat (TARGET_NR_Linux + 296) -#define TARGET_NR_symlinkat (TARGET_NR_Linux + 297) -#define TARGET_NR_readlinkat (TARGET_NR_Linux + 298) -#define TARGET_NR_fchmodat (TARGET_NR_Linux + 299) -#define TARGET_NR_faccessat (TARGET_NR_Linux + 300) -#define TARGET_NR_pselect6 (TARGET_NR_Linux + 301) -#define TARGET_NR_ppoll (TARGET_NR_Linux + 302) -#define TARGET_NR_unshare (TARGET_NR_Linux + 303) -#define TARGET_NR_splice (TARGET_NR_Linux + 304) -#define TARGET_NR_sync_file_range (TARGET_NR_Linux + 305) -#define TARGET_NR_tee (TARGET_NR_Linux + 306) -#define TARGET_NR_vmsplice (TARGET_NR_Linux + 307) -#define TARGET_NR_move_pages (TARGET_NR_Linux + 308) -#define TARGET_NR_set_robust_list (TARGET_NR_Linux + 309) -#define TARGET_NR_get_robust_list (TARGET_NR_Linux + 310) -#define TARGET_NR_kexec_load (TARGET_NR_Linux + 311) -#define TARGET_NR_getcpu (TARGET_NR_Linux + 312) -#define TARGET_NR_epoll_pwait (TARGET_NR_Linux + 313) -#define TARGET_NR_ioprio_set (TARGET_NR_Linux + 314) -#define TARGET_NR_ioprio_get (TARGET_NR_Linux + 315) -#define TARGET_NR_utimensat (TARGET_NR_Linux + 316) -#define TARGET_NR_signalfd (TARGET_NR_Linux + 317) -#define TARGET_NR_timerfd (TARGET_NR_Linux + 318) -#define TARGET_NR_eventfd (TARGET_NR_Linux + 319) -#define TARGET_NR_fallocate (TARGET_NR_Linux + 320) -#define TARGET_NR_timerfd_create (TARGET_NR_Linux + 321) -#define TARGET_NR_timerfd_gettime (TARGET_NR_Linux + 322) -#define TARGET_NR_timerfd_settime (TARGET_NR_Linux + 323) -#define TARGET_NR_signalfd4 (TARGET_NR_Linux + 324) -#define TARGET_NR_eventfd2 (TARGET_NR_Linux + 325) -#define TARGET_NR_epoll_create1 (TARGET_NR_Linux + 326) -#define TARGET_NR_dup3 (TARGET_NR_Linux + 327) -#define TARGET_NR_pipe2 (TARGET_NR_Linux + 328) -#define TARGET_NR_inotify_init1 (TARGET_NR_Linux + 329) -#define TARGET_NR_preadv (TARGET_NR_Linux + 330) -#define TARGET_NR_pwritev (TARGET_NR_Linux + 331) +#define TARGET_NR_inotify_rm_watch (TARGET_NR_Linux + 286) +#define TARGET_NR_migrate_pages (TARGET_NR_Linux + 287) +#define TARGET_NR_openat (TARGET_NR_Linux + 288) +#define TARGET_NR_mkdirat (TARGET_NR_Linux + 289) +#define TARGET_NR_mknodat (TARGET_NR_Linux + 290) +#define TARGET_NR_fchownat (TARGET_NR_Linux + 291) +#define TARGET_NR_futimesat (TARGET_NR_Linux + 292) +#define TARGET_NR_fstatat64 (TARGET_NR_Linux + 293) +#define TARGET_NR_unlinkat (TARGET_NR_Linux + 294) +#define TARGET_NR_renameat (TARGET_NR_Linux + 295) +#define TARGET_NR_linkat (TARGET_NR_Linux + 296) +#define TARGET_NR_symlinkat (TARGET_NR_Linux + 297) +#define TARGET_NR_readlinkat (TARGET_NR_Linux + 298) +#define TARGET_NR_fchmodat (TARGET_NR_Linux + 299) +#define TARGET_NR_faccessat (TARGET_NR_Linux + 300) +#define TARGET_NR_pselect6 (TARGET_NR_Linux + 301) +#define TARGET_NR_ppoll (TARGET_NR_Linux + 302) +#define TARGET_NR_unshare (TARGET_NR_Linux + 303) +#define TARGET_NR_splice (TARGET_NR_Linux + 304) +#define TARGET_NR_sync_file_range (TARGET_NR_Linux + 305) +#define TARGET_NR_tee (TARGET_NR_Linux + 306) +#define TARGET_NR_vmsplice (TARGET_NR_Linux + 307) +#define TARGET_NR_move_pages (TARGET_NR_Linux + 308) +#define TARGET_NR_set_robust_list (TARGET_NR_Linux + 309) +#define TARGET_NR_get_robust_list (TARGET_NR_Linux + 310) +#define TARGET_NR_kexec_load (TARGET_NR_Linux + 311) +#define TARGET_NR_getcpu (TARGET_NR_Linux + 312) +#define TARGET_NR_epoll_pwait (TARGET_NR_Linux + 313) +#define TARGET_NR_ioprio_set (TARGET_NR_Linux + 314) +#define TARGET_NR_ioprio_get (TARGET_NR_Linux + 315) +#define TARGET_NR_utimensat (TARGET_NR_Linux + 316) +#define TARGET_NR_signalfd (TARGET_NR_Linux + 317) +#define TARGET_NR_timerfd (TARGET_NR_Linux + 318) +#define TARGET_NR_eventfd (TARGET_NR_Linux + 319) +#define TARGET_NR_fallocate (TARGET_NR_Linux + 320) +#define TARGET_NR_timerfd_create (TARGET_NR_Linux + 321) +#define TARGET_NR_timerfd_gettime (TARGET_NR_Linux + 322) +#define TARGET_NR_timerfd_settime (TARGET_NR_Linux + 323) +#define TARGET_NR_signalfd4 (TARGET_NR_Linux + 324) +#define TARGET_NR_eventfd2 (TARGET_NR_Linux + 325) +#define TARGET_NR_epoll_create1 (TARGET_NR_Linux + 326) +#define TARGET_NR_dup3 (TARGET_NR_Linux + 327) +#define TARGET_NR_pipe2 (TARGET_NR_Linux + 328) +#define TARGET_NR_inotify_init1 (TARGET_NR_Linux + 329) +#define TARGET_NR_preadv (TARGET_NR_Linux + 330) +#define TARGET_NR_pwritev (TARGET_NR_Linux + 331) #define TARGET_NR_rt_tgsigqueueinfo (TARGET_NR_Linux + 332) -#define TARGET_NR_perf_event_open (TARGET_NR_Linux + 333) -#define TARGET_NR_accept4 (TARGET_NR_Linux + 334) -#define TARGET_NR_recvmmsg (TARGET_NR_Linux + 335) -#define TARGET_NR_fanotify_init (TARGET_NR_Linux + 336) -#define TARGET_NR_fanotify_mark (TARGET_NR_Linux + 337) -#define TARGET_NR_prlimit64 (TARGET_NR_Linux + 338) +#define TARGET_NR_perf_event_open (TARGET_NR_Linux + 333) +#define TARGET_NR_accept4 (TARGET_NR_Linux + 334) +#define TARGET_NR_recvmmsg (TARGET_NR_Linux + 335) +#define TARGET_NR_fanotify_init (TARGET_NR_Linux + 336) +#define TARGET_NR_fanotify_mark (TARGET_NR_Linux + 337) +#define TARGET_NR_prlimit64 (TARGET_NR_Linux + 338) #define TARGET_NR_name_to_handle_at (TARGET_NR_Linux + 339) #define TARGET_NR_open_by_handle_at (TARGET_NR_Linux + 340) -#define TARGET_NR_clock_adjtime (TARGET_NR_Linux + 341) -#define TARGET_NR_syncfs (TARGET_NR_Linux + 342) -#define TARGET_NR_sendmmsg (TARGET_NR_Linux + 343) -#define TARGET_NR_setns (TARGET_NR_Linux + 344) -#define TARGET_NR_process_vm_readv (TARGET_NR_Linux + 345) +#define TARGET_NR_clock_adjtime (TARGET_NR_Linux + 341) +#define TARGET_NR_syncfs (TARGET_NR_Linux + 342) +#define TARGET_NR_sendmmsg (TARGET_NR_Linux + 343) +#define TARGET_NR_setns (TARGET_NR_Linux + 344) +#define TARGET_NR_process_vm_readv (TARGET_NR_Linux + 345) #define TARGET_NR_process_vm_writev (TARGET_NR_Linux + 346) -#define TARGET_NR_kcmp (TARGET_NR_Linux + 347) -#define TARGET_NR_finit_module (TARGET_NR_Linux + 348) +#define TARGET_NR_kcmp (TARGET_NR_Linux + 347) +#define TARGET_NR_finit_module (TARGET_NR_Linux + 348) -#define TARGET_NR_sched_setattr (TARGET_NR_Linux + 349) -#define TARGET_NR_sched_getattr (TARGET_NR_Linux + 350) -#define TARGET_NR_renameat2 (TARGET_NR_Linux + 351) -#define TARGET_NR_seccomp (TARGET_NR_Linux + 352) -#define TARGET_NR_getrandom (TARGET_NR_Linux + 353) -#define TARGET_NR_memfd_create (TARGET_NR_Linux + 354) -#define TARGET_NR_bpf (TARGET_NR_Linux + 355) -#define TARGET_NR_execveat (TARGET_NR_Linux + 356) -#define TARGET_NR_userfaultfd (TARGET_NR_Linux + 357) -#define TARGET_NR_membarrier (TARGET_NR_Linux + 358) -#define TARGET_NR_mlock2 (TARGET_NR_Linux + 359) +#define TARGET_NR_sched_setattr (TARGET_NR_Linux + 349) +#define TARGET_NR_sched_getattr (TARGET_NR_Linux + 350) +#define TARGET_NR_renameat2 (TARGET_NR_Linux + 351) +#define TARGET_NR_seccomp (TARGET_NR_Linux + 352) +#define TARGET_NR_getrandom (TARGET_NR_Linux + 353) +#define TARGET_NR_memfd_create (TARGET_NR_Linux + 354) +#define TARGET_NR_bpf (TARGET_NR_Linux + 355) +#define TARGET_NR_execveat (TARGET_NR_Linux + 356) +#define TARGET_NR_userfaultfd (TARGET_NR_Linux + 357) +#define TARGET_NR_membarrier (TARGET_NR_Linux + 358) +#define TARGET_NR_mlock2 (TARGET_NR_Linux + 359) #define TARGET_NR_copy_file_range (TARGET_NR_Linux + 360) -#define TARGET_NR_preadv2 (TARGET_NR_Linux + 361) -#define TARGET_NR_pwritev2 (TARGET_NR_Linux + 362) -#define TARGET_NR_pkey_mprotect (TARGET_NR_Linux + 363) -#define TARGET_NR_pkey_alloc (TARGET_NR_Linux + 364) -#define TARGET_NR_pkey_free (TARGET_NR_Linux + 365) -#define TARGET_NR_statx (TARGET_NR_Linux + 366) -#define TARGET_NR_rseq (TARGET_NR_Linux + 367) -#define TARGET_NR_io_pgetevents (TARGET_NR_Linux + 368) +#define TARGET_NR_preadv2 (TARGET_NR_Linux + 361) +#define TARGET_NR_pwritev2 (TARGET_NR_Linux + 362) +#define TARGET_NR_pkey_mprotect (TARGET_NR_Linux + 363) +#define TARGET_NR_pkey_alloc (TARGET_NR_Linux + 364) +#define TARGET_NR_pkey_free (TARGET_NR_Linux + 365) +#define TARGET_NR_statx (TARGET_NR_Linux + 366) +#define TARGET_NR_rseq (TARGET_NR_Linux + 367) +#define TARGET_NR_io_pgetevents (TARGET_NR_Linux + 368) #endif /*SYSCALL_NR_H*/ diff --git a/src/os_emulation/target_errno.h b/src/os_emulation/target_errno.h index c8463da2..c5d58177 100644 --- a/src/os_emulation/target_errno.h +++ b/src/os_emulation/target_errno.h @@ -1,139 +1,139 @@ #ifndef TARGET_ERRNO_H #define TARGET_ERRNO_H -#define TARGET_EPERM 1 -#define TARGET_ENOENT 2 -#define TARGET_ESRCH 3 -#define TARGET_EINTR 4 -#define TARGET_EIO 5 -#define TARGET_ENXIO 6 -#define TARGET_E2BIG 7 -#define TARGET_ENOEXEC 8 -#define TARGET_EBADF 9 -#define TARGET_ECHILD 10 -#define TARGET_EAGAIN 11 -#define TARGET_ENOMEM 12 -#define TARGET_EACCES 13 -#define TARGET_EFAULT 14 -#define TARGET_ENOTBLK 15 -#define TARGET_EBUSY 16 -#define TARGET_EEXIST 17 -#define TARGET_EXDEV 18 -#define TARGET_ENODEV 19 -#define TARGET_ENOTDIR 20 -#define TARGET_EISDIR 21 -#define TARGET_EINVAL 22 -#define TARGET_ENFILE 23 -#define TARGET_EMFILE 24 -#define TARGET_ENOTTY 25 -#define TARGET_ETXTBSY 26 -#define TARGET_EFBIG 27 -#define TARGET_ENOSPC 28 -#define TARGET_ESPIPE 29 -#define TARGET_EROFS 30 -#define TARGET_EMLINK 31 -#define TARGET_EPIPE 32 -#define TARGET_EDOM 33 -#define TARGET_ERANGE 34 -#define TARGET_ENOMSG 35 -#define TARGET_EIDRM 36 -#define TARGET_ECHRNG 37 -#define TARGET_EL2NSYNC 38 -#define TARGET_EL3HLT 39 -#define TARGET_EL3RST 40 -#define TARGET_ELNRNG 41 -#define TARGET_EUNATCH 42 -#define TARGET_ENOCSI 43 -#define TARGET_EL2HLT 44 -#define TARGET_EDEADLK 45 -#define TARGET_ENOLCK 46 -#define TARGET_EBADE 50 -#define TARGET_EBADR 51 -#define TARGET_EXFULL 52 -#define TARGET_ENOANO 53 -#define TARGET_EBADRQC 54 -#define TARGET_EBADSLT 55 -#define TARGET_EDEADLOCK 56 -#define TARGET_EBFONT 59 -#define TARGET_ENOSTR 60 -#define TARGET_ENODATA 61 -#define TARGET_ETIME 62 -#define TARGET_ENOSR 63 -#define TARGET_ENONET 64 -#define TARGET_ENOPKG 65 -#define TARGET_EREMOTE 66 -#define TARGET_ENOLINK 67 -#define TARGET_EADV 68 -#define TARGET_ESRMNT 69 -#define TARGET_ECOMM 70 -#define TARGET_EPROTO 71 -#define TARGET_EDOTDOT 73 -#define TARGET_EMULTIHOP 74 -#define TARGET_EBADMSG 77 -#define TARGET_ENAMETOOLONG 78 -#define TARGET_EOVERFLOW 79 -#define TARGET_ENOTUNIQ 80 -#define TARGET_EBADFD 81 -#define TARGET_EREMCHG 82 -#define TARGET_ELIBACC 83 -#define TARGET_ELIBBAD 84 -#define TARGET_ELIBSCN 85 -#define TARGET_ELIBMAX 86 -#define TARGET_ELIBEXEC 87 -#define TARGET_EILSEQ 88 -#define TARGET_ENOSYS 89 -#define TARGET_ELOOP 90 -#define TARGET_ERESTART 91 -#define TARGET_ESTRPIPE 92 -#define TARGET_ENOTEMPTY 93 -#define TARGET_EUSERS 94 -#define TARGET_ENOTSOCK 95 -#define TARGET_EDESTADDRREQ 96 -#define TARGET_EMSGSIZE 97 -#define TARGET_EPROTOTYPE 98 -#define TARGET_ENOPROTOOPT 99 +#define TARGET_EPERM 1 +#define TARGET_ENOENT 2 +#define TARGET_ESRCH 3 +#define TARGET_EINTR 4 +#define TARGET_EIO 5 +#define TARGET_ENXIO 6 +#define TARGET_E2BIG 7 +#define TARGET_ENOEXEC 8 +#define TARGET_EBADF 9 +#define TARGET_ECHILD 10 +#define TARGET_EAGAIN 11 +#define TARGET_ENOMEM 12 +#define TARGET_EACCES 13 +#define TARGET_EFAULT 14 +#define TARGET_ENOTBLK 15 +#define TARGET_EBUSY 16 +#define TARGET_EEXIST 17 +#define TARGET_EXDEV 18 +#define TARGET_ENODEV 19 +#define TARGET_ENOTDIR 20 +#define TARGET_EISDIR 21 +#define TARGET_EINVAL 22 +#define TARGET_ENFILE 23 +#define TARGET_EMFILE 24 +#define TARGET_ENOTTY 25 +#define TARGET_ETXTBSY 26 +#define TARGET_EFBIG 27 +#define TARGET_ENOSPC 28 +#define TARGET_ESPIPE 29 +#define TARGET_EROFS 30 +#define TARGET_EMLINK 31 +#define TARGET_EPIPE 32 +#define TARGET_EDOM 33 +#define TARGET_ERANGE 34 +#define TARGET_ENOMSG 35 +#define TARGET_EIDRM 36 +#define TARGET_ECHRNG 37 +#define TARGET_EL2NSYNC 38 +#define TARGET_EL3HLT 39 +#define TARGET_EL3RST 40 +#define TARGET_ELNRNG 41 +#define TARGET_EUNATCH 42 +#define TARGET_ENOCSI 43 +#define TARGET_EL2HLT 44 +#define TARGET_EDEADLK 45 +#define TARGET_ENOLCK 46 +#define TARGET_EBADE 50 +#define TARGET_EBADR 51 +#define TARGET_EXFULL 52 +#define TARGET_ENOANO 53 +#define TARGET_EBADRQC 54 +#define TARGET_EBADSLT 55 +#define TARGET_EDEADLOCK 56 +#define TARGET_EBFONT 59 +#define TARGET_ENOSTR 60 +#define TARGET_ENODATA 61 +#define TARGET_ETIME 62 +#define TARGET_ENOSR 63 +#define TARGET_ENONET 64 +#define TARGET_ENOPKG 65 +#define TARGET_EREMOTE 66 +#define TARGET_ENOLINK 67 +#define TARGET_EADV 68 +#define TARGET_ESRMNT 69 +#define TARGET_ECOMM 70 +#define TARGET_EPROTO 71 +#define TARGET_EDOTDOT 73 +#define TARGET_EMULTIHOP 74 +#define TARGET_EBADMSG 77 +#define TARGET_ENAMETOOLONG 78 +#define TARGET_EOVERFLOW 79 +#define TARGET_ENOTUNIQ 80 +#define TARGET_EBADFD 81 +#define TARGET_EREMCHG 82 +#define TARGET_ELIBACC 83 +#define TARGET_ELIBBAD 84 +#define TARGET_ELIBSCN 85 +#define TARGET_ELIBMAX 86 +#define TARGET_ELIBEXEC 87 +#define TARGET_EILSEQ 88 +#define TARGET_ENOSYS 89 +#define TARGET_ELOOP 90 +#define TARGET_ERESTART 91 +#define TARGET_ESTRPIPE 92 +#define TARGET_ENOTEMPTY 93 +#define TARGET_EUSERS 94 +#define TARGET_ENOTSOCK 95 +#define TARGET_EDESTADDRREQ 96 +#define TARGET_EMSGSIZE 97 +#define TARGET_EPROTOTYPE 98 +#define TARGET_ENOPROTOOPT 99 #define TARGET_EPROTONOSUPPORT 120 #define TARGET_ESOCKTNOSUPPORT 121 -#define TARGET_EOPNOTSUPP 122 -#define TARGET_ENOTSUP EOPNOTSUPP -#define TARGET_EPFNOSUPPORT 123 -#define TARGET_EAFNOSUPPORT 124 -#define TARGET_EADDRINUSE 125 -#define TARGET_EADDRNOTAVAIL 126 -#define TARGET_ENETDOWN 127 -#define TARGET_ENETUNREACH 128 -#define TARGET_ENETRESET 129 -#define TARGET_ECONNABORTED 130 -#define TARGET_ECONNRESET 131 -#define TARGET_ENOBUFS 132 -#define TARGET_EISCONN 133 -#define TARGET_ENOTCONN 134 -#define TARGET_EUCLEAN 135 -#define TARGET_ENOTNAM 137 -#define TARGET_ENAVAIL 138 -#define TARGET_EISNAM 139 -#define TARGET_EREMOTEIO 140 -#define TARGET_ESHUTDOWN 143 -#define TARGET_ETOOMANYREFS 144 -#define TARGET_ETIMEDOUT 145 -#define TARGET_ECONNREFUSED 146 -#define TARGET_EHOSTDOWN 147 -#define TARGET_EHOSTUNREACH 148 -#define TARGET_EWOULDBLOCK EAGAIN -#define TARGET_EALREADY 149 -#define TARGET_EINPROGRESS 150 -#define TARGET_ESTALE 151 -#define TARGET_ECANCELED 158 -#define TARGET_ENOMEDIUM 159 -#define TARGET_EMEDIUMTYPE 160 -#define TARGET_ENOKEY 161 -#define TARGET_EKEYEXPIRED 162 -#define TARGET_EKEYREVOKED 163 -#define TARGET_EKEYREJECTED 164 -#define TARGET_EOWNERDEAD 165 +#define TARGET_EOPNOTSUPP 122 +#define TARGET_ENOTSUP EOPNOTSUPP +#define TARGET_EPFNOSUPPORT 123 +#define TARGET_EAFNOSUPPORT 124 +#define TARGET_EADDRINUSE 125 +#define TARGET_EADDRNOTAVAIL 126 +#define TARGET_ENETDOWN 127 +#define TARGET_ENETUNREACH 128 +#define TARGET_ENETRESET 129 +#define TARGET_ECONNABORTED 130 +#define TARGET_ECONNRESET 131 +#define TARGET_ENOBUFS 132 +#define TARGET_EISCONN 133 +#define TARGET_ENOTCONN 134 +#define TARGET_EUCLEAN 135 +#define TARGET_ENOTNAM 137 +#define TARGET_ENAVAIL 138 +#define TARGET_EISNAM 139 +#define TARGET_EREMOTEIO 140 +#define TARGET_ESHUTDOWN 143 +#define TARGET_ETOOMANYREFS 144 +#define TARGET_ETIMEDOUT 145 +#define TARGET_ECONNREFUSED 146 +#define TARGET_EHOSTDOWN 147 +#define TARGET_EHOSTUNREACH 148 +#define TARGET_EWOULDBLOCK EAGAIN +#define TARGET_EALREADY 149 +#define TARGET_EINPROGRESS 150 +#define TARGET_ESTALE 151 +#define TARGET_ECANCELED 158 +#define TARGET_ENOMEDIUM 159 +#define TARGET_EMEDIUMTYPE 160 +#define TARGET_ENOKEY 161 +#define TARGET_EKEYEXPIRED 162 +#define TARGET_EKEYREVOKED 163 +#define TARGET_EKEYREJECTED 164 +#define TARGET_EOWNERDEAD 165 #define TARGET_ENOTRECOVERABLE 166 -#define TARGET_ERFKILL 167 -#define TARGET_EHWPOISON 168 -#define TARGET_EDQUOT 1133 +#define TARGET_ERFKILL 167 +#define TARGET_EHWPOISON 168 +#define TARGET_EDQUOT 1133 #endif /*TARGET_ERRNO_H*/