From de279f472189c0f629883bb94920a04dc4d582c9 Mon Sep 17 00:00:00 2001 From: OmniaX-Dev Date: Mon, 15 Jun 2026 08:18:44 +0200 Subject: [PATCH] Stripped old debugger code --- CMakeLists.txt | 3 - src/assembler/Assembler.cpp | 2 +- src/debugger/Debugger.cpp | 1743 -------------------------------- src/debugger/Debugger.hpp | 105 -- src/debugger/debugger_main.cpp | 47 +- src/hardware/VirtualCPU.cpp | 122 +-- src/hardware/VirtualCPU.hpp | 8 - src/hardware/VirtualMMU.cpp | 14 - src/hardware/VirtualMMU.hpp | 23 - src/runtime/DragonRuntime.cpp | 182 +--- src/runtime/DragonRuntime.hpp | 60 +- 11 files changed, 40 insertions(+), 2269 deletions(-) delete mode 100644 src/debugger/Debugger.cpp delete mode 100644 src/debugger/Debugger.hpp delete mode 100644 src/hardware/VirtualMMU.cpp delete mode 100644 src/hardware/VirtualMMU.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 79c6063..1393fff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,7 +40,6 @@ list(APPEND RUNTIME_SOURCE_FILES ${CMAKE_CURRENT_LIST_DIR}/src/hardware/VirtualHardDrive.cpp ${CMAKE_CURRENT_LIST_DIR}/src/hardware/VirtualDisplay.cpp ${CMAKE_CURRENT_LIST_DIR}/src/hardware/CPUExtensions.cpp - ${CMAKE_CURRENT_LIST_DIR}/src/hardware/VirtualMMU.cpp ${CMAKE_CURRENT_LIST_DIR}/src/tools/Utils.cpp ${CMAKE_CURRENT_LIST_DIR}/src/tools/GlobalData.cpp @@ -49,7 +48,6 @@ list(APPEND RUNTIME_SOURCE_FILES list(APPEND DEBUGGER_SOURCE_FILES ${CMAKE_CURRENT_LIST_DIR}/src/debugger/debugger_main.cpp ${CMAKE_CURRENT_LIST_DIR}/src/debugger/DisassemblyLoader.cpp - ${CMAKE_CURRENT_LIST_DIR}/src/debugger/Debugger.cpp ${CMAKE_CURRENT_LIST_DIR}/src/hardware/VirtualCPU.cpp ${CMAKE_CURRENT_LIST_DIR}/src/hardware/VirtualRAM.cpp @@ -58,7 +56,6 @@ list(APPEND DEBUGGER_SOURCE_FILES ${CMAKE_CURRENT_LIST_DIR}/src/hardware/VirtualHardDrive.cpp ${CMAKE_CURRENT_LIST_DIR}/src/hardware/VirtualDisplay.cpp ${CMAKE_CURRENT_LIST_DIR}/src/hardware/CPUExtensions.cpp - ${CMAKE_CURRENT_LIST_DIR}/src/hardware/VirtualMMU.cpp ${CMAKE_CURRENT_LIST_DIR}/src/runtime/DragonRuntime.cpp ${CMAKE_CURRENT_LIST_DIR}/src/runtime/ConfigLoader.cpp diff --git a/src/assembler/Assembler.cpp b/src/assembler/Assembler.cpp index 3ae5dbb..81df3d3 100644 --- a/src/assembler/Assembler.cpp +++ b/src/assembler/Assembler.cpp @@ -775,7 +775,7 @@ namespace dragon void Assembler::saveCurrentStageToFile(void) { - std::cout << "LINES: " << (int)m_lines.size() << "\n"; + // std::cout << "LINES: " << (int)m_lines.size() << "\n"; ostd::FileSystem::writeTextFile(Application::args.final_stage_path, m_lines); } diff --git a/src/debugger/Debugger.cpp b/src/debugger/Debugger.cpp deleted file mode 100644 index e2d0531..0000000 --- a/src/debugger/Debugger.cpp +++ /dev/null @@ -1,1743 +0,0 @@ -#include "Debugger.hpp" -#include "../runtime/DragonRuntime.hpp" -#include "DisassemblyLoader.hpp" -#include -#include -#include -#include -#include - -namespace dragon -{ - //Close Event Listener - Debugger::tCloseEventListener Debugger::closeEventListener; - - void Debugger::tCloseEventListener::init(void) - { - validate(); - enableSignals(); - connectSignal(ostd::BuiltinSignals::WindowClosed); - } - - void Debugger::tCloseEventListener::handleSignal(ostd::Signal& signal) - { - m_mainWindowClosed = signal.ID == ostd::BuiltinSignals::WindowClosed; - } - - - - - //Debugger::Utils - DisassemblyList Debugger::Utils::findCodeRegion(const DisassemblyList& code, u16 address, u16 codeRegionMargin) - { - if (code.size() <= (codeRegionMargin * 2) + 1) return code; - std::vector codeRegion; - u16 start = 0; - u16 end = (codeRegionMargin * 2); - for (i32 i = 0; i < code.size(); i++) - { - if (code[i].addr != address) continue; - if (i + 1 <= codeRegionMargin) break; - if (code.size() - (i + 1) < codeRegionMargin) - { - end = code.size() - 1; - start = end - ((codeRegionMargin * 2) + 1); - break; - } - start = i - codeRegionMargin; - end = i + codeRegionMargin; - break; - } - for (i16 i = start; i <= end; i++) - codeRegion.push_back(code[i]); - return codeRegion; - } - - String Debugger::Utils::findSymbol(const DisassemblyList& list, u16 address, u16* outSize) - { - for (auto& line : list) - { - if (line.addr == address) - { - if (outSize != nullptr) - *outSize = line.size; - return line.code; - } - } - return ""; - } - - u16 Debugger::Utils::findSymbol(const DisassemblyList& list, const String& symbol, u16* outSize) - { - for (auto& line : list) - { - if (line.code == symbol) - { - if (outSize != nullptr) - *outSize = line.size; - return line.addr; - } - } - return 0x0000; - } - - bool Debugger::Utils::isValidLabelNameChar(char c) - { - return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c == '_'); - } - - void Debugger::Utils::clearConsoleLine(void) - { - for (i32 i = 0; i < ostd::BasicConsole::getConsoleWidth(); i++) - out.p("\b"); - for (i32 i = 0; i < ostd::BasicConsole::getConsoleWidth(); i++) - out.p(" "); - for (i32 i = 0; i < ostd::BasicConsole::getConsoleWidth(); i++) - out.p("\b"); - } - - bool Debugger::Utils::isEscapeKeyPressed(bool blocking) - { - ostd::KeyboardController kbc; - kbc.disableCommandBuffer(); - kbc.disableOutput(); - if (blocking) - { - ostd::eKeys key = ostd::eKeys::NoKeyPressed; - while ((key = kbc.waitForKeyPress()) != ostd::eKeys::Escape) - { - ostd::Time::sleep(120); - } - return true; - } - return kbc.getPressedKey() == ostd::eKeys::Escape; - } - - ostd::ConsoleOutputHandler& Debugger::Utils::printFullLine(char c, const ostd::ConsoleColors::tConsoleColor& foreground) - { - i32 cw = ostd::BasicConsole::getConsoleWidth(); - String str = String::duplicateChar(c, cw); - out.fg(foreground).p(str).reset().nl(); - return out; - } - - ostd::ConsoleOutputHandler& Debugger::Utils::printFullLine(char c, const ostd::ConsoleColors::tConsoleColor& foreground, const ostd::ConsoleColors::tConsoleColor& background) - { - i32 cw = ostd::BasicConsole::getConsoleWidth(); - String str = String::duplicateChar(c, cw); - out.bg(background).fg(foreground).p(str).reset().nl(); - return out; - } - - void Debugger::Utils::removeBreakPoint(u16 addr) - { - if (debugger.manualBreakPoints.size() == 0) - return; - i32 i = 0; - for ( ; i < debugger.manualBreakPoints.size(); i++) - { - if (debugger.manualBreakPoints[i] == addr) - break; - } - if (i >= debugger.manualBreakPoints.size()) - return; - debugger.manualBreakPoints.erase(debugger.manualBreakPoints.begin() + i); - } - - bool Debugger::Utils::isBreakPoint(u16 addr) - { - for (const auto& b : debugger.manualBreakPoints) - if (b == addr) return true; - return false; - } - - void Debugger::Utils::addBreakPoint(u16 addr) - { - debugger.manualBreakPoints.push_back(addr); - } - - - - - - //Debugger::Display - void Debugger::Display::colorizeInstructionBody(const String& instBody, bool currentLine, const DisassemblyList& labelList) - { - ostd::RegexRichString rgxrstr(instBody); - rgxrstr.fg("\\{|\\}|\\+|\\*|\\-|\\/|\\(|\\)|\\[|\\]", "Red"); //Operators - rgxrstr.fg("0x[0-9A-Fa-f]+|0b[0-1]+|(? ").fg(ostd::ConsoleColors::White).flush(); - } - - void Debugger::Display::printStep(void) - { - out.clear(); - i32 codeRegionSpan = 15; - auto codeRegion = Utils::findCodeRegion(debugger.code, debugger.currentAddress, codeRegionSpan); - for (i32 i = 0; i < codeRegion.size(); i++) - { - auto& _da = codeRegion[i]; - bool currentLine = _da.addr == debugger.currentAddress; - String label = Utils::findSymbol(debugger.labels, _da.addr); - bool specialSection = _da.code.startsWith("[") &&_da.code.endsWith("]"); - label.fixedLength(debugger.labelLineLength); - out.fg(ostd::ConsoleColors::Gray).p(label.cpp_str()).p(" "); - if (currentLine) - { - out.fg(ostd::ConsoleColors::Black).bg(ostd::ConsoleColors::Yellow).p(String::getHexStr(_da.addr, true, 2).cpp_str()).p(" ").reset();; - } - else - { - if (specialSection) - out.fg(ostd::ConsoleColors::Cyan); - else if (_da.code == "debug_break") - out.fg(ostd::ConsoleColors::Red); - else - out.fg(ostd::ConsoleColors::BrightGray); - out.p(String::getHexStr(_da.addr, true, 2).cpp_str()).p(" "); - } - if (specialSection) - out.fg(ostd::ConsoleColors::Cyan).p(_da.code.cpp_str()).nl(); - colorCodeInstructions(_da.code, currentLine, debugger.labels); - out.reset(); - } - Utils::printFullLine('#', ostd::ConsoleColors::Black, ostd::ConsoleColors::Yellow); - } - - void Debugger::Display::printDiff(void) - { - out.clear(); - String str; - str.add("|===============|================PREV================|================CURR================|=====|===PREV====|===CURR====|"); - str.add("\n"); - str.add("| InstAddr: |*%PREV_INST_ADDR%*******************|*%CURR_INST_ADDR%*******************| R1 |*%PREV_R1%*|*%CURR_R1%*|"); - str.add("\n"); - str.add("|---------------|------------------------------------|------------------------------------|-----|-----------|-----------|"); - str.add("\n"); - str.add("| Code: | ----- |*%CURR_CODE%************************| R2 |*%PREV_R2%*|*%CURR_R2%*|"); - str.add("\n"); - str.add("|---------------|------------------------------------|------------------------------------|-----|-----------|-----------|"); - str.add("\n"); - str.add("| StackFrame: |*%PREV_STACK_FRAME%*****************|*%CURR_STACK_FRAME%*****************| R3 |*%PREV_R3%*|*%CURR_R3%*|"); - str.add("\n"); - str.add("|---------------|------------------------------------|------------------------------------|-----|-----------|-----------|"); - str.add("\n"); - str.add("| DBG BRK: |*%PREV_DBG_BRK%*********************|*%CURR_DBG_BRK%*********************| R4 |*%PREV_R4%*|*%CURR_R4%*|"); - str.add("\n"); - str.add("|---------------|------------------------------------|------------------------------------|-----|-----------|-----------|"); - str.add("\n"); - str.add("| INT Handler: |*%PREV_INT_HANDLER%*****************|*%CURR_INT_HANDLER%*****************| R5 |*%PREV_R5%*|*%CURR_R5%*|"); - str.add("\n"); - str.add("|---------------|------------------------------------|------------------------------------|-----|-----------|-----------|"); - str.add("\n"); - str.add("| BIOS Mode: |*%PREV_BIOS_MODE%*******************|**%CURR_BIOS_MODE%******************| R6 |*%PREV_R6%*|*%CURR_R6%*|"); - str.add("\n"); - str.add("|---------------|------------------------------------|------------------------------------|-----|-----------|-----------|"); - str.add("\n"); - str.add("| SubRoutine: |*%PREV_SUB_ROUTINE%*****************|**%CURR_SUB_ROUTINE%****************| R7 |*%PREV_R7%*|*%CURR_R7%*|"); - str.add("\n"); - str.add("|---------------|------------------------------------|------------------------------------|-----|-----------|-----------|"); - str.add("\n"); - str.add("| IP: |*%PREV_IP%**************************|**%CURR_IP%*************************| R8 |*%PREV_R8%*|*%CURR_R8%*|"); - str.add("\n"); - str.add("|---------------|------------------------------------|------------------------------------|-----|-----------|-----------|"); - str.add("\n"); - str.add("| SP: |*%PREV_SP%**************************|**%CURR_SP%*************************| R9 |*%PREV_R9%*|*%CURR_R9%*|"); - str.add("\n"); - str.add("|---------------|------------------------------------|------------------------------------|-----|-----------|-----------|"); - str.add("\n"); - str.add("| FP: |*%PREV_FP%**************************|**%CURR_FP%*************************| R10 |*%PREV_R10%|*%CURR_R10%|"); - str.add("\n"); - str.add("|---------------|------------------------------------|------------------------------------|=====|===========|===========|"); - str.add("\n"); - str.add("| RV: |*%PREV_RV%**************************|**%CURR_RV%*************************| S1 |*%PREV_S1%*|*%CURR_S1*%|"); - str.add("\n"); - str.add("|---------------|------------------------------------|------------------------------------|-----|-----------|-----------|"); - str.add("\n"); - str.add("| PP: |*%PREV_PP%**************************|**%CURR_PP%*************************| S2 |*%PREV_S2%*|*%CURR_S2%*|"); - str.add("\n"); - str.add("|---------------|------------------------------------|------------------------------------|-----|-----------|-----------|"); - str.add("\n"); - str.add("| FL: |*%PREV_FL%**************************|**%CURR_FL%*************************| OF |*%PREV_OF%*|*%CURR_OF%*|"); - str.add("\n"); - str.add("|---------------|------------------------------------|------------------------------------|=====|===========|===========|"); - str.add("\n"); - str.add("| ACC: |*%PREV_ACC%*************************|**%CURR_ACC%************************|"); - str.add("\n"); - str.add("|===============|====================================|====================================|"); - - - str.replaceAll("*", ""); - i32 item_len = 36; - const dragon::DragonRuntime::tMachineDebugInfo& minfo = dragon::DragonRuntime::getMachineInfoDiff(); - String tmp = " ", tmpStyle = ""; - - //Instruction Address - { - tmp.add(String::getHexStr(minfo.previousInstructionAddress, true, 2)); - tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - tmpStyle = "[@@style foreground:Blue]"; - tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%PREV_INST_ADDR%", tmpStyle); - - tmp = " "; - tmp.add(String::getHexStr(minfo.currentInstructionAddress, true, 2)); - tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - if (minfo.currentInstructionAddress != minfo.previousInstructionAddress) - tmpStyle = "[@@style foreground:Black,background:BrightRed]"; - else - tmpStyle = "[@@style foreground:Blue]"; - tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%CURR_INST_ADDR%", tmpStyle); - } - - //Code - { - tmp = " ", tmpStyle = ""; - String prevCode = " ("; - prevCode.add(minfo.previousInstructionOpCode).add(") "); - for (i32 i = 0; i < minfo.previousInstructionFootprintSize; i++) - prevCode.add(String::getHexStr(minfo.previousInstructionFootprint[i], false, 1)).add(" "); - tmp.add(prevCode); - tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - tmpStyle = "[@@style foreground:Blue]"; - tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%CURR_CODE%", tmpStyle); - - // tmp = " "; - // String currCode = " ("; - // currCode.add(minfo.currentInstructionOpCode).add(") "); - // for (i32 i = 0; i < minfo.currentInstructionFootprintSize; i++) - // currCode.add(String::getHexStr(minfo.currentInstructionFootprint[i], false, 1)).add(" "); - // tmp.add(currCode); - // tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - // // if (currCode != prevCode) - // // tmpStyle = "[@@style foreground:Black,background:BrightRed]"; - // // else - // tmpStyle = "[@@style foreground:Blue]"; - // tmpStyle.add(tmp).add("[@@/]"); - // str.replaceAll("%CURR_CODE%", tmpStyle); - } - - //Stack Frame - { - tmp = " ", tmpStyle = ""; - tmp.add(String::getHexStr(minfo.previousInstructionStackFrameSize, true, 2)); - tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - tmpStyle = "[@@style foreground:Blue]"; - tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%PREV_STACK_FRAME%", tmpStyle); - - tmp = " "; - tmp.add(String::getHexStr(minfo.currentInstructionStackFrameSize, true, 2)); - tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - if (minfo.currentInstructionStackFrameSize != minfo.previousInstructionStackFrameSize) - tmpStyle = "[@@style foreground:Black,background:BrightRed]"; - else - tmpStyle = "[@@style foreground:Blue]"; - tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%CURR_STACK_FRAME%", tmpStyle); - } - - //Debug Break - { - tmp = " ", tmpStyle = ""; - tmp.add(STR_BOOL(minfo.previousInstructionDebugBreak)); - tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - tmpStyle = "[@@style foreground:Blue]"; - tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%PREV_DBG_BRK%", tmpStyle); - - tmp = " "; - tmp.add(STR_BOOL(minfo.currentInstructionDebugBreak)); - tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - if (minfo.currentInstructionDebugBreak != minfo.previousInstructionDebugBreak) - tmpStyle = "[@@style foreground:Black,background:BrightRed]"; - else - tmpStyle = "[@@style foreground:Blue]"; - tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%CURR_DBG_BRK%", tmpStyle); - } - - //INT Handler - { - tmp = " ", tmpStyle = ""; - tmp.add(minfo.previousInstructionInterruptHandlerCount); - tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - tmpStyle = "[@@style foreground:Blue]"; - tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%PREV_INT_HANDLER%", tmpStyle); - - tmp = " "; - tmp.add(minfo.currentInstructionInterruptHandlerCount); - tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - if (minfo.currentInstructionInterruptHandlerCount != minfo.previousInstructionInterruptHandlerCount) - tmpStyle = "[@@style foreground:Black,background:BrightRed]"; - else - tmpStyle = "[@@style foreground:Blue]"; - tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%CURR_INT_HANDLER%", tmpStyle); - } - - //Bios Mode - { - tmp = " ", tmpStyle = ""; - tmp.add(STR_BOOL(minfo.previousInstructionBiosMode)); - tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - tmpStyle = "[@@style foreground:Blue]"; - tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%PREV_BIOS_MODE%", tmpStyle); - - tmp = " "; - tmp.add(STR_BOOL(minfo.currentInstructionBiosMode)); - tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - if (minfo.currentInstructionBiosMode != minfo.previousInstructionBiosMode) - tmpStyle = "[@@style foreground:Black,background:BrightRed]"; - else - tmpStyle = "[@@style foreground:Blue]"; - tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%CURR_BIOS_MODE%", tmpStyle); - } - - //SubRoutine Info - { - tmp = " ", tmpStyle = ""; - tmp.add(minfo.previousSubRoutineCounter).add(" ("); - tmp.add(STR_BOOL(minfo.previousIsInSubRoutine)).add(")"); - tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - String old_tmp = tmp; - tmpStyle = "[@@style foreground:Blue]"; - tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%PREV_SUB_ROUTINE%", tmpStyle); - - tmp = " "; - tmp.add(minfo.currentSubRoutineCounter).add(" ("); - tmp.add(STR_BOOL(minfo.currentIsInSubRoutine)).add(")"); - tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - if (old_tmp != tmp) - tmpStyle = "[@@style foreground:Black,background:BrightRed]"; - else - tmpStyle = "[@@style foreground:Blue]"; - tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%CURR_SUB_ROUTINE%", tmpStyle); - } - - //System Registers - { - tmp = " ", tmpStyle = ""; - tmp.add(String::getHexStr(minfo.previousInstructionRegisters[dragon::data::Registers::IP], true, 2)); - tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - tmpStyle = "[@@style foreground:Blue]"; - tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%PREV_IP%", tmpStyle); - - tmp = " "; - tmp.add(String::getHexStr(minfo.currentInstructionRegisters[dragon::data::Registers::IP], true, 2)); - tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - if (minfo.currentInstructionRegisters[dragon::data::Registers::IP] != minfo.previousInstructionRegisters[dragon::data::Registers::IP]) - tmpStyle = "[@@style foreground:Black,background:BrightRed]"; - else - tmpStyle = "[@@style foreground:Blue]"; - tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%CURR_IP%", tmpStyle); - - - - - tmp = " ", tmpStyle = ""; - tmp.add(String::getHexStr(minfo.previousInstructionRegisters[dragon::data::Registers::SP], true, 2)); - tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - tmpStyle = "[@@style foreground:Blue]"; - tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%PREV_SP%", tmpStyle); - - tmp = " "; - tmp.add(String::getHexStr(minfo.currentInstructionRegisters[dragon::data::Registers::SP], true, 2)); - tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - if (minfo.currentInstructionRegisters[dragon::data::Registers::SP] != minfo.previousInstructionRegisters[dragon::data::Registers::SP]) - tmpStyle = "[@@style foreground:Black,background:BrightRed]"; - else - tmpStyle = "[@@style foreground:Blue]"; - tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%CURR_SP%", tmpStyle); - - - - - tmp = " ", tmpStyle = ""; - tmp.add(String::getHexStr(minfo.previousInstructionRegisters[dragon::data::Registers::FP], true, 2)); - tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - tmpStyle = "[@@style foreground:Blue]"; - tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%PREV_FP%", tmpStyle); - - tmp = " "; - tmp.add(String::getHexStr(minfo.currentInstructionRegisters[dragon::data::Registers::FP], true, 2)); - tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - if (minfo.currentInstructionRegisters[dragon::data::Registers::FP] != minfo.previousInstructionRegisters[dragon::data::Registers::FP]) - tmpStyle = "[@@style foreground:Black,background:BrightRed]"; - else - tmpStyle = "[@@style foreground:Blue]"; - tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%CURR_FP%", tmpStyle); - - - - - tmp = " ", tmpStyle = ""; - tmp.add(String::getHexStr(minfo.previousInstructionRegisters[dragon::data::Registers::RV], true, 2)); - tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - tmpStyle = "[@@style foreground:Blue]"; - tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%PREV_RV%", tmpStyle); - - tmp = " "; - tmp.add(String::getHexStr(minfo.currentInstructionRegisters[dragon::data::Registers::RV], true, 2)); - tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - if (minfo.currentInstructionRegisters[dragon::data::Registers::RV] != minfo.previousInstructionRegisters[dragon::data::Registers::RV]) - tmpStyle = "[@@style foreground:Black,background:BrightRed]"; - else - tmpStyle = "[@@style foreground:Blue]"; - tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%CURR_RV%", tmpStyle); - - - - - tmp = " ", tmpStyle = ""; - tmp.add(String::getHexStr(minfo.previousInstructionRegisters[dragon::data::Registers::PP], true, 2)); - tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - tmpStyle = "[@@style foreground:Blue]"; - tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%PREV_PP%", tmpStyle); - - tmp = " "; - tmp.add(String::getHexStr(minfo.currentInstructionRegisters[dragon::data::Registers::PP], true, 2)); - tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - if (minfo.currentInstructionRegisters[dragon::data::Registers::PP] != minfo.previousInstructionRegisters[dragon::data::Registers::PP]) - tmpStyle = "[@@style foreground:Black,background:BrightRed]"; - else - tmpStyle = "[@@style foreground:Blue]"; - tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%CURR_PP%", tmpStyle); - - - - - tmp = " ", tmpStyle = ""; - tmp.add(String::getHexStr(minfo.previousInstructionRegisters[dragon::data::Registers::FL], true, 2)); - tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - tmpStyle = "[@@style foreground:Blue]"; - tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%PREV_FL%", tmpStyle); - - tmp = " "; - tmp.add(String::getHexStr(minfo.currentInstructionRegisters[dragon::data::Registers::FL], true, 2)); - tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - if (minfo.currentInstructionRegisters[dragon::data::Registers::FL] != minfo.previousInstructionRegisters[dragon::data::Registers::FL]) - tmpStyle = "[@@style foreground:Black,background:BrightRed]"; - else - tmpStyle = "[@@style foreground:Blue]"; - tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%CURR_FL%", tmpStyle); - - - - - tmp = " ", tmpStyle = ""; - tmp.add(String::getHexStr(minfo.previousInstructionRegisters[dragon::data::Registers::ACC], true, 2)); - tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - tmpStyle = "[@@style foreground:Blue]"; - tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%PREV_ACC%", tmpStyle); - - tmp = " "; - tmp.add(String::getHexStr(minfo.currentInstructionRegisters[dragon::data::Registers::ACC], true, 2)); - tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - if (minfo.currentInstructionRegisters[dragon::data::Registers::ACC] != minfo.previousInstructionRegisters[dragon::data::Registers::ACC]) - tmpStyle = "[@@style foreground:Black,background:BrightRed]"; - else - tmpStyle = "[@@style foreground:Blue]"; - tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%CURR_ACC%", tmpStyle); - } - - item_len = 11; - //General Registers - { - tmp = " ", tmpStyle = ""; - tmp.add(String::getHexStr(minfo.previousInstructionRegisters[dragon::data::Registers::R1], true, 2)); - tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - tmpStyle = "[@@style foreground:Blue]"; - tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%PREV_R1%", tmpStyle); - - tmp = " "; - tmp.add(String::getHexStr(minfo.currentInstructionRegisters[dragon::data::Registers::R1], true, 2)); - tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - if (minfo.currentInstructionRegisters[dragon::data::Registers::R1] != minfo.previousInstructionRegisters[dragon::data::Registers::R1]) - tmpStyle = "[@@style foreground:Black,background:BrightRed]"; - else - tmpStyle = "[@@style foreground:Blue]"; - tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%CURR_R1%", tmpStyle); - - - - - tmp = " ", tmpStyle = ""; - tmp.add(String::getHexStr(minfo.previousInstructionRegisters[dragon::data::Registers::R2], true, 2)); - tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - tmpStyle = "[@@style foreground:Blue]"; - tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%PREV_R2%", tmpStyle); - - tmp = " "; - tmp.add(String::getHexStr(minfo.currentInstructionRegisters[dragon::data::Registers::R2], true, 2)); - tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - if (minfo.currentInstructionRegisters[dragon::data::Registers::R2] != minfo.previousInstructionRegisters[dragon::data::Registers::R2]) - tmpStyle = "[@@style foreground:Black,background:BrightRed]"; - else - tmpStyle = "[@@style foreground:Blue]"; - tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%CURR_R2%", tmpStyle); - - - - - tmp = " ", tmpStyle = ""; - tmp.add(String::getHexStr(minfo.previousInstructionRegisters[dragon::data::Registers::R3], true, 2)); - tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - tmpStyle = "[@@style foreground:Blue]"; - tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%PREV_R3%", tmpStyle); - - tmp = " "; - tmp.add(String::getHexStr(minfo.currentInstructionRegisters[dragon::data::Registers::R3], true, 2)); - tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - if (minfo.currentInstructionRegisters[dragon::data::Registers::R3] != minfo.previousInstructionRegisters[dragon::data::Registers::R3]) - tmpStyle = "[@@style foreground:Black,background:BrightRed]"; - else - tmpStyle = "[@@style foreground:Blue]"; - tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%CURR_R3%", tmpStyle); - - - - - tmp = " ", tmpStyle = ""; - tmp.add(String::getHexStr(minfo.previousInstructionRegisters[dragon::data::Registers::R4], true, 2)); - tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - tmpStyle = "[@@style foreground:Blue]"; - tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%PREV_R4%", tmpStyle); - - tmp = " "; - tmp.add(String::getHexStr(minfo.currentInstructionRegisters[dragon::data::Registers::R4], true, 2)); - tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - if (minfo.currentInstructionRegisters[dragon::data::Registers::R4] != minfo.previousInstructionRegisters[dragon::data::Registers::R4]) - tmpStyle = "[@@style foreground:Black,background:BrightRed]"; - else - tmpStyle = "[@@style foreground:Blue]"; - tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%CURR_R4%", tmpStyle); - - - - - tmp = " ", tmpStyle = ""; - tmp.add(String::getHexStr(minfo.previousInstructionRegisters[dragon::data::Registers::R5], true, 2)); - tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - tmpStyle = "[@@style foreground:Blue]"; - tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%PREV_R5%", tmpStyle); - - tmp = " "; - tmp.add(String::getHexStr(minfo.currentInstructionRegisters[dragon::data::Registers::R5], true, 2)); - tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - if (minfo.currentInstructionRegisters[dragon::data::Registers::R5] != minfo.previousInstructionRegisters[dragon::data::Registers::R5]) - tmpStyle = "[@@style foreground:Black,background:BrightRed]"; - else - tmpStyle = "[@@style foreground:Blue]"; - tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%CURR_R5%", tmpStyle); - - - - - tmp = " ", tmpStyle = ""; - tmp.add(String::getHexStr(minfo.previousInstructionRegisters[dragon::data::Registers::R6], true, 2)); - tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - tmpStyle = "[@@style foreground:Blue]"; - tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%PREV_R6%", tmpStyle); - - tmp = " "; - tmp.add(String::getHexStr(minfo.currentInstructionRegisters[dragon::data::Registers::R6], true, 2)); - tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - if (minfo.currentInstructionRegisters[dragon::data::Registers::R6] != minfo.previousInstructionRegisters[dragon::data::Registers::R6]) - tmpStyle = "[@@style foreground:Black,background:BrightRed]"; - else - tmpStyle = "[@@style foreground:Blue]"; - tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%CURR_R6%", tmpStyle); - - - - - tmp = " ", tmpStyle = ""; - tmp.add(String::getHexStr(minfo.previousInstructionRegisters[dragon::data::Registers::R7], true, 2)); - tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - tmpStyle = "[@@style foreground:Blue]"; - tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%PREV_R7%", tmpStyle); - - tmp = " "; - tmp.add(String::getHexStr(minfo.currentInstructionRegisters[dragon::data::Registers::R7], true, 2)); - tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - if (minfo.currentInstructionRegisters[dragon::data::Registers::R7] != minfo.previousInstructionRegisters[dragon::data::Registers::R7]) - tmpStyle = "[@@style foreground:Black,background:BrightRed]"; - else - tmpStyle = "[@@style foreground:Blue]"; - tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%CURR_R7%", tmpStyle); - - - - - tmp = " ", tmpStyle = ""; - tmp.add(String::getHexStr(minfo.previousInstructionRegisters[dragon::data::Registers::R8], true, 2)); - tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - tmpStyle = "[@@style foreground:Blue]"; - tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%PREV_R8%", tmpStyle); - - tmp = " "; - tmp.add(String::getHexStr(minfo.currentInstructionRegisters[dragon::data::Registers::R8], true, 2)); - tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - if (minfo.currentInstructionRegisters[dragon::data::Registers::R8] != minfo.previousInstructionRegisters[dragon::data::Registers::R8]) - tmpStyle = "[@@style foreground:Black,background:BrightRed]"; - else - tmpStyle = "[@@style foreground:Blue]"; - tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%CURR_R8%", tmpStyle); - - - - - tmp = " ", tmpStyle = ""; - tmp.add(String::getHexStr(minfo.previousInstructionRegisters[dragon::data::Registers::R9], true, 2)); - tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - tmpStyle = "[@@style foreground:Blue]"; - tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%PREV_R9%", tmpStyle); - - tmp = " "; - tmp.add(String::getHexStr(minfo.currentInstructionRegisters[dragon::data::Registers::R9], true, 2)); - tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - if (minfo.currentInstructionRegisters[dragon::data::Registers::R9] != minfo.previousInstructionRegisters[dragon::data::Registers::R9]) - tmpStyle = "[@@style foreground:Black,background:BrightRed]"; - else - tmpStyle = "[@@style foreground:Blue]"; - tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%CURR_R9%", tmpStyle); - - - - - tmp = " ", tmpStyle = ""; - tmp.add(String::getHexStr(minfo.previousInstructionRegisters[dragon::data::Registers::R10], true, 2)); - tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - tmpStyle = "[@@style foreground:Blue]"; - tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%PREV_R10%", tmpStyle); - - tmp = " "; - tmp.add(String::getHexStr(minfo.currentInstructionRegisters[dragon::data::Registers::R10], true, 2)); - tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - if (minfo.currentInstructionRegisters[dragon::data::Registers::R10] != minfo.previousInstructionRegisters[dragon::data::Registers::R10]) - tmpStyle = "[@@style foreground:Black,background:BrightRed]"; - else - tmpStyle = "[@@style foreground:Blue]"; - tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%CURR_R10%", tmpStyle); - } - - //Special Registers - { - tmp = " ", tmpStyle = ""; - tmp.add(String::getHexStr(minfo.previousInstructionRegisters[dragon::data::Registers::S1], true, 2)); - tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - tmpStyle = "[@@style foreground:Blue]"; - tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%PREV_S1%", tmpStyle); - - tmp = " "; - tmp.add(String::getHexStr(minfo.currentInstructionRegisters[dragon::data::Registers::S1], true, 2)); - tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - if (minfo.currentInstructionRegisters[dragon::data::Registers::S1] != minfo.previousInstructionRegisters[dragon::data::Registers::S1]) - tmpStyle = "[@@style foreground:Black,background:BrightRed]"; - else - tmpStyle = "[@@style foreground:Blue]"; - tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%CURR_S1%", tmpStyle); - - - - - tmp = " ", tmpStyle = ""; - tmp.add(String::getHexStr(minfo.previousInstructionRegisters[dragon::data::Registers::S2], true, 2)); - tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - tmpStyle = "[@@style foreground:Blue]"; - tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%PREV_S2%", tmpStyle); - - tmp = " "; - tmp.add(String::getHexStr(minfo.currentInstructionRegisters[dragon::data::Registers::S2], true, 2)); - tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - if (minfo.currentInstructionRegisters[dragon::data::Registers::S2] != minfo.previousInstructionRegisters[dragon::data::Registers::S2]) - tmpStyle = "[@@style foreground:Black,background:BrightRed]"; - else - tmpStyle = "[@@style foreground:Blue]"; - tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%CURR_S2%", tmpStyle); - - - - - tmp = " ", tmpStyle = ""; - tmp.add(String::getHexStr(minfo.previousInstructionRegisters[dragon::data::Registers::OFFSET], true, 2)); - tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - tmpStyle = "[@@style foreground:Blue]"; - tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%PREV_OF%", tmpStyle); - - tmp = " "; - tmp.add(String::getHexStr(minfo.currentInstructionRegisters[dragon::data::Registers::OFFSET], true, 2)); - tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); - if (minfo.currentInstructionRegisters[dragon::data::Registers::OFFSET] != minfo.previousInstructionRegisters[dragon::data::Registers::OFFSET]) - tmpStyle = "[@@style foreground:Black,background:BrightRed]"; - else - tmpStyle = "[@@style foreground:Blue]"; - tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%CURR_OF%", tmpStyle); - } - - ostd::RegexRichString rgxstr(str); - rgxstr.fg("InstAddr|Code|StackFrame|DBG BRK|INT Handler|BIOS Mode|SubRoutine", "Magenta"); - rgxstr.fg("IP|SP|FP|RV|PP|FL|ACC", "Cyan"); - rgxstr.fg("R10|R2|R3|R4|R5|R6|R7|R8|R9|R1", "BrightGreen"); - rgxstr.fg("S1|S2|OF", "BrightRed"); - rgxstr.fg("PREV", "Red"); - rgxstr.fg("CURR", "Green"); - out.pStyled(rgxstr); - - out.nl().nl().fg(ostd::ConsoleColors::Yellow).p("Pres to go back...").nl().reset(); - Utils::isEscapeKeyPressed(true); - } - - void Debugger::Display::printTrackedAddresses(void) - { - out.clear(); - out.fg(ostd::ConsoleColors::Yellow).p("Tracked Data: ").reset().nl(); - const i32 symbol_len = 24; - const i32 size_len = 8; - const i32 addr_len = 10; - const i32 map_len = 8; - const i32 prev_len = 35; - const dragon::DragonRuntime::tMachineDebugInfo& minfo = dragon::DragonRuntime::getMachineInfoDiff(); - if (minfo.trackedAddresses.size() == 0) return; - i32 cw = ostd::BasicConsole::getConsoleWidth(); - String header = "|Symbol"; - header.addRightPadding(symbol_len); - header.add("|Bytes"); - header.addRightPadding(header.len() + size_len - 6); - header.add("|Addr"); - header.addRightPadding(header.len() + addr_len - 5); - header.add("|Map"); - header.addRightPadding(header.len() + map_len - 4); - header.add("|Previous"); - header.addRightPadding(header.len() + prev_len - 9); - header.add("|Current"); - header.fixedLength(cw - 1); - header.addChar('|'); - String border = String::duplicateChar('=', cw); - out.fg(ostd::ConsoleColors::Blue).p(border).nl(); - ostd::RegexRichString rgx(header); - rgx.fg("\\|", "blue"); - rgx.fg("Symbol|Bytes|Addr|Map|Previous|Current", "yellow"); - out.pStyled(rgx).reset().nl(); - String h_sep = String::duplicateChar('=', cw); - h_sep.put(0, '|'); - h_sep.put(symbol_len, '|'); - h_sep.put(symbol_len + size_len, '|'); - h_sep.put(symbol_len + size_len + addr_len, '|'); - h_sep.put(symbol_len + size_len + addr_len + map_len, '|'); - h_sep.put(symbol_len + size_len + addr_len + map_len + prev_len, '|'); - h_sep.put(cw - 1, '|'); - out.fg(ostd::ConsoleColors::Blue).p(h_sep).reset().nl(); - for (i32 i = 0; i < minfo.trackedAddresses.size(); i++) - { - u16 data_size = 1; - auto addr = minfo.trackedAddresses[i]; - String symbol = Utils::findSymbol(debugger.data, addr, &data_size); - if (symbol == "") - symbol = Utils::findSymbol(debugger.labels, addr, &data_size); - bool no_symbol = false; - if (symbol == "") - { - symbol = ""; - no_symbol = true; - } - symbol.fixedLength(symbol_len - 1); - if (no_symbol) - out.fg(ostd::ConsoleColors::Blue).p("|").fg(ostd::ConsoleColors::Gray).p(symbol).reset(); - else - out.fg(ostd::ConsoleColors::Blue).p("|").fg(ostd::ConsoleColors::Magenta).p(symbol).reset(); - - String tmp = ""; - tmp.add(data_size); - tmp.fixedLength(size_len - 1); - if (no_symbol) - out.fg(ostd::ConsoleColors::Blue).p("|").fg(ostd::ConsoleColors::Cyan).p(tmp).reset(); - else - out.fg(ostd::ConsoleColors::Blue).p("|").fg(ostd::ConsoleColors::BrightCyan).p(tmp).reset(); - - tmp = ""; - tmp.add(String::getHexStr(addr, true, 2)); - tmp.fixedLength(addr_len - 1); - if (no_symbol) - out.fg(ostd::ConsoleColors::Blue).p("|").fg(ostd::ConsoleColors::Gray).p(tmp).reset(); - else - out.fg(ostd::ConsoleColors::Blue).p("|").fg(ostd::ConsoleColors::BrightGray).p(tmp).reset(); - - tmp = ""; - if (addr >= (u16)DragonRuntime::cpu.readRegister(data::Registers::SP)) - tmp.add("STACK"); - else - tmp.add(DragonRuntime::memMap.getMemoryRegionName(addr)); - tmp.fixedLength(map_len - 1); - out.fg(ostd::ConsoleColors::Blue).p("|").fg(ostd::ConsoleColors::BrightYellow).p(tmp).reset(); - - tmp = ""; - tmp.add(String::getHexStr(minfo.previousInstructionTrackedValues[i], false, 1)); - for (i32 j = 1; j < data_size; j++) - tmp.add(".").add(String::getHexStr(minfo.previousInstructionTrackedValues[i + j], false, 1)); - tmp.fixedLength(prev_len - 1); - if (no_symbol) - out.fg(ostd::ConsoleColors::Blue).p("|").fg(ostd::ConsoleColors::Red).p(tmp).reset(); - else - out.fg(ostd::ConsoleColors::Blue).p("|").fg(ostd::ConsoleColors::BrightRed).p(tmp).reset(); - - tmp = ""; - tmp.add(String::getHexStr(minfo.currentInstructionTrackedValues[i], false, 1)); - u32 tmp_i = i; - for (i32 j = 1; j < data_size; j++, i++) - tmp.add(".").add(String::getHexStr(minfo.currentInstructionTrackedValues[i + 1], false, 1)); - tmp.fixedLength(prev_len - 1); - bool data_different = false; - for (i32 j = 0; j < data_size; j++) - { - if (minfo.currentInstructionTrackedValues[tmp_i + j] != minfo.previousInstructionTrackedValues[tmp_i + j]) - { - data_different = true; - break; - } - } - if (no_symbol) - { - if (data_different) - out.fg(ostd::ConsoleColors::Blue).p("|").fg(ostd::ConsoleColors::BrightGray).p(tmp).reset(); - else - out.fg(ostd::ConsoleColors::Blue).p("|").fg(ostd::ConsoleColors::Green).p(tmp).reset(); - } - else - { - if (data_different) - out.fg(ostd::ConsoleColors::Blue).p("|").fg(ostd::ConsoleColors::White).p(tmp).reset(); - else - out.fg(ostd::ConsoleColors::Blue).p("|").fg(ostd::ConsoleColors::BrightGreen).p(tmp).reset(); - } - tmp = "|"; - tmp.addLeftPadding(cw - symbol_len - size_len - addr_len - map_len - prev_len - prev_len); - out.fg(ostd::ConsoleColors::Blue).p(tmp).reset(); - } - out.nl(); - out.fg(ostd::ConsoleColors::Blue).p(border).reset().nl(); - - out.nl().nl().fg(ostd::ConsoleColors::Yellow).p("Pres to go back...").nl().reset(); - Utils::isEscapeKeyPressed(true); - } - - void Debugger::Display::printStack(u16 nrows) - { - if (nrows == 0) nrows = 8; - u16 ncols = 16; - u16 startAddr = (0xFFFF - (ncols * nrows) + 1); - out.clear(); - - out.nl(); - out.fg(ostd::ConsoleColors::Yellow).p("Stack frames: ").reset().nl(); - Utils::printFullLine('=', ostd::ConsoleColors::BrightBlue); - for (auto& frame : dragon::DragonRuntime::cpu.m_debug_stackFrameStrings) - { - ostd::RegexRichString rgxrstr(frame); - rgxrstr.fg("0x[0-9A-Fa-f]+|0b[0-1]+|(? to go back...").nl().reset(); - Utils::isEscapeKeyPressed(true); - } - - void Debugger::Display::printCallStack(void) - { - out.clear(); - out.fg(ostd::ConsoleColors::Yellow).p("Subroutine/Interrupt call stack: ").reset().nl(); - Utils::printFullLine('=', ostd::ConsoleColors::Yellow); - - const dragon::DragonRuntime::tMachineDebugInfo& minfo = dragon::DragonRuntime::getMachineInfoDiff(); - - auto& callStack = minfo.callStack; - i32 level = -1; - String ch_ang_u = ""; - //TODO: Find a fix for the UTF characters - ch_ang_u.add("┌"); - // ch_ang_u.addChar((uchar)218); - String ch_ang_l = "|"; - String ch_ang_d = ""; - ch_ang_d.add("└"); - // ch_ang_d.addChar((uchar)192); - for (auto& call : callStack) - { - String call_info = call.info.new_trim().toLower(); - String subroutine_addr = String::getHexStr(call.addr, true, 2); - String subroutine_name = Utils::findSymbol(debugger.labels, call.addr); - String call_str = ""; - bool dec_lvl = false; - if (call_info == "int") - { - call_str = ch_ang_u + "int " + String::getHexStr(call.addr, true, 1); - level++; - } - else if (call_info == "hw int") - { - call_str = ch_ang_u + "hwi " + String::getHexStr(call.addr, true, 1) + " (" + data::InterruptCodes::getInterruptName(call.addr) + ")"; - level++; - } - else if (call_info == "ret") - { - call_str = ch_ang_d + "ret"; - dec_lvl = true; - } - else if (call_info == "ret int") - { - call_str = ch_ang_d + "rti"; - dec_lvl = true; - } - else - { - if (call_info == "call reg") - subroutine_addr = "*" + subroutine_addr; - if (subroutine_name != "") - call_str = ch_ang_u + "call " + subroutine_name + " (" + subroutine_addr + ")"; - else - call_str = ch_ang_u + "call " + subroutine_addr; - level++; - } - - String line_str = ""; - for (i32 i = 0; i < level; i++) - line_str.add("| "); - line_str.add(call_str); - - ostd::RegexRichString rgx(line_str); - rgx.fg("\\(|\\)|\\*", "Cyan"); //Operators - rgx.fg("(? ").reset(); - out.pStyled(rgx).nl().reset(); - - if (dec_lvl) - level--; - } - - Utils::printFullLine('=', ostd::ConsoleColors::Yellow); - out.nl().nl().fg(ostd::ConsoleColors::Yellow).p("Pres to go back...").nl().reset(); - Utils::isEscapeKeyPressed(true); - } - - void Debugger::Display::printHelp(void) - { - out.clear(); - i32 commandLength = 34; - Utils::printFullLine('#', ostd::ConsoleColors::Black, ostd::ConsoleColors::Red); - - out.nl().fg(ostd::ConsoleColors::Yellow).p("List of available commands:").reset().nl(); - String tmpCommand = "(d)iff-view"; - tmpCommand.addRightPadding(commandLength); - out.fg(ostd::ConsoleColors::Blue).p(tmpCommand).fg(ostd::ConsoleColors::Green).p("Used to show the state of the machine, comparing the current cycle with the last.").reset().nl(); - tmpCommand = "(q)uit"; - tmpCommand.addRightPadding(commandLength); - out.fg(ostd::ConsoleColors::Blue).p(tmpCommand).fg(ostd::ConsoleColors::Green).p("Used to close the program and exit the debugger. ( key can also be used.)").reset().nl(); - tmpCommand = "(h)elp"; - tmpCommand.addRightPadding(commandLength); - out.fg(ostd::ConsoleColors::Blue).p(tmpCommand).fg(ostd::ConsoleColors::Green).p("Used to show this dialog.").reset().nl(); - tmpCommand = "(t)racker"; - tmpCommand.addRightPadding(commandLength); - out.fg(ostd::ConsoleColors::Blue).p(tmpCommand).fg(ostd::ConsoleColors::Green).p("Used to show manually tracked values.").reset().nl(); - tmpCommand = "(s)tack [rows=8]"; - tmpCommand.addRightPadding(commandLength); - out.fg(ostd::ConsoleColors::Blue).p(tmpCommand).fg(ostd::ConsoleColors::Green).p("Used to show the stack and a description of every stack-frame saved.").reset().nl(); - tmpCommand = "(ca)ll-stack"; - tmpCommand.addRightPadding(commandLength); - out.fg(ostd::ConsoleColors::Blue).p(tmpCommand).fg(ostd::ConsoleColors::Green).p("Used to show information about all subroutine/interrupt calls.").reset().nl(); - tmpCommand = "(c)ontinue"; - tmpCommand.addRightPadding(commandLength); - out.fg(ostd::ConsoleColors::Blue).p(tmpCommand).fg(ostd::ConsoleColors::Green).p("Used exit step-execution mode and resume the normal execution of the program.").reset().nl(); - tmpCommand = "(p)rint [word] "; - tmpCommand.addRightPadding(commandLength); - out.fg(ostd::ConsoleColors::Blue).p(tmpCommand).fg(ostd::ConsoleColors::Green).p("Used to print values from memory. Valid [size] values are: byte/word/dword/qword.").reset().nl(); - - out.nl().fg(ostd::ConsoleColors::Cyan).p("The letters in parenthesis can be used as the short version of the command.").nl(); - out.p("Square brackets represent optional parameters. If they have an '=' and a value, that is the default if not specified.").reset().nl(); - - out.nl(); - Utils::printFullLine('#', ostd::ConsoleColors::Black, ostd::ConsoleColors::Red); - - out.nl().nl().fg(ostd::ConsoleColors::Yellow).p("Pres to go back...").nl().reset(); - Utils::isEscapeKeyPressed(true); - } - - String Debugger::Display::changeScreen(void) - { - if (debugger.command == "diff-view" || debugger.command == "d") - { - printDiff(); - printStep(); - printPrompt(); - return getCommandInput(); - } - else if (debugger.command == "tracker" || debugger.command == "t") - { - printTrackedAddresses(); - printStep(); - printPrompt(); - return getCommandInput(); - } - else if (debugger.command.startsWith("stack") || debugger.command.startsWith("s")) - { - u16 default_stack_rows = 8; - String params = debugger.command.new_trim(); - if (params == "stack" || params == "s") - printStack(default_stack_rows); - else if (params.contains(" ")) - { - params.substr(params.indexOf(" ") + 1).trim(); - if (!params.isNumeric()) return ""; - default_stack_rows = (u16)params.toInt(); - if (default_stack_rows > 0xFFFF / 16) default_stack_rows = 8; - printStack(default_stack_rows); - } - else return ""; - printStep(); - printPrompt(); - return getCommandInput(); - } - else if (debugger.command == "call-stack" || debugger.command == "ca") - { - printCallStack(); - printStep(); - printPrompt(); - return getCommandInput(); - } - else if (debugger.command == "help" || debugger.command == "h") - { - printHelp(); - printStep(); - printPrompt(); - return getCommandInput(); - } - return ""; - } - - - - - //Debugger - void Debugger::processErrors(void) - { - if (!dragon::DragonRuntime::hasError()) return; - while (dragon::data::ErrorHandler::hasError()) - { - auto err = dragon::data::ErrorHandler::popError(); - out.nl().fg(ostd::ConsoleColors::Red).p("Error ").p(String::getHexStr(err.code, true, 8).cpp_str()).p(": ").p(err.text.cpp_str()).nl(); - } - debugger.args.step_exec = true; - } - - i32 Debugger::loadArguments(int argc, char** argv) - { - if (argc < 2) - { - out.fg(ostd::ConsoleColors::Red).p("Error: too few arguments.").nl(); - out.fg(ostd::ConsoleColors::Red).p("Use the --help option for more info.").reset().nl(); - return DragonRuntime::RETURN_VAL_TOO_FEW_ARGUMENTS; - } - else - { - debugger.args.machine_config_path = argv[1]; - if (debugger.args.machine_config_path == "--help") - { - print_application_help(); - return DragonRuntime::RETURN_VAL_CLOSE_DEBUGGER; - } - for (i32 i = 2; i < argc; i++) - { - String edit(argv[i]); - if (edit == "--verbose-load") - debugger.args.verbose_load = true; - else if (edit == "--step-exec") - debugger.args.step_exec = true; - else if (edit == "--track-step-diff-off") - debugger.args.track_step_diff = false; - else if (edit == "--auto-track-data-off") - debugger.args.auto_track_all_data_symbols = false; - else if (edit == "--hide-vdisplay") - debugger.args.hide_virtual_display = true; - else if (edit == "--auto-start") - debugger.args.auto_start_debug = true; - else if (edit == "--force-load") - { - if ((argc - 1) - i < 2) - return DragonRuntime::RETURN_VAL_MISSING_PARAM; - i++; - debugger.args.force_load_file = argv[i]; - i++; - edit = argv[i]; - if (!edit.isNumeric()) - return DragonRuntime::RETURN_VAL_PARAMETER_NOT_NUMERIC; - debugger.args.force_load_mem_offset = (u16)edit.toInt(); - debugger.args.force_load = true; - } - else if (edit == "--help") - { - print_application_help(); - return DragonRuntime::RETURN_VAL_CLOSE_DEBUGGER; - } - } - } - return DragonRuntime::RETURN_VAL_EXIT_SUCCESS; - } - - i32 Debugger::initRuntime(void) - { - - dragon::DragonRuntime::tRuntimeInitInfo initInfo; - initInfo.configFilePath = debugger.args.machine_config_path; - initInfo.verboseLoad = debugger.args.verbose_load; - initInfo.trackMachineInfoDiff = debugger.args.track_step_diff; - initInfo.hideVirtualDisplay = debugger.args.hide_virtual_display; - initInfo.trackCallStack = debugger.args.track_call_stack; - initInfo.debugModeEnabled = true; - i32 init_state = dragon::DragonRuntime::initMachine(initInfo); - closeEventListener.init(); - if (init_state != 0) return init_state; //TODO: Error - - if (debugger.args.force_load) - dragon::DragonRuntime::forceLoad(debugger.args.force_load_file, debugger.args.force_load_mem_offset); - - dragon::DisassemblyLoader::loadDirectory(debugger.disassemblyDirectory); - debugger.code = dragon::DisassemblyLoader::getCodeTable(); - debugger.labels = dragon::DisassemblyLoader::getLabelTable(); - debugger.data = dragon::DisassemblyLoader::getDataTable(); - - return DragonRuntime::RETURN_VAL_EXIT_SUCCESS; - } - - String Debugger::getCommandInput(void) - { - String cmd; - ostd::KeyboardController kbc; - ostd::eKeys key = ostd::eKeys::NoKeyPressed; - - while ((key = kbc.getPressedKey()) != ostd::eKeys::Enter) - { - if (key == ostd::eKeys::Escape) - return InputCommandQuit; - } - return kbc.getInputString(); - - // String cmd; - // std::getline(std::cin, cmd.cpp_str_ref()); - // return cmd; - } - - i32 Debugger::topLevelPrompt(void) - { - if (!data().args.auto_start_debug) - { - bool exit_loop = false; - bool done_with_auto_data_track = false; - DragonRuntime::vDisplay.hide(); - while (!exit_loop) - { - if (!done_with_auto_data_track) - { - data().command = "track "; - for (auto& sym : debugger.data) - data().command.add(sym.code).add(" "); - done_with_auto_data_track = true; - } - else - { - Display::printPrompt(); - data().command = getCommandInput(); - } - data().command.trim().toLower(); - if (data().command == "r" || data().command == "run") - { - output().p("Starting program...").nl(); - exit_loop = true; - } - else if (data().command == "q" || data().command == "quit" || data().command == InputCommandQuit) - { - output().nl().p("Exiting debugger...").nl(); - return DragonRuntime::RETURN_VAL_CLOSE_DEBUGGER; - } - else if (data().command.startsWith("t ") || data().command.startsWith("track ")) - { - data().command.substr(data().command.indexOf(" ") + 1).trim(); - exec_watch_command(); - } - else if (data().command == "h" || data().command == "help") - { - print_top_level_prompt_help(); - } - else if (data().command == "s" || data().command == "step") - { - data().args.step_exec = !data().args.step_exec; - output().p("Step execution = ").p(STR_BOOL(data().args.step_exec)).nl(); - } - else if (data().command == "display") - { - data().args.hide_virtual_display = !data().args.hide_virtual_display; - output().p("Virtual Display Hidden = ").p(STR_BOOL(data().args.hide_virtual_display)).nl(); - } - } - } - - if (!data().args.hide_virtual_display) - DragonRuntime::vDisplay.show(); - - data().currentAddress = DragonRuntime::cpu.readRegister(data::Registers::IP); - return DragonRuntime::RETURN_VAL_EXIT_SUCCESS; - } - - i32 Debugger::executeRuntime(void) - { - i32 rValue = 0; - bool userQuit = false; - output().clear().fg(ostd::ConsoleColors::Green).p("Program running...").nl(); - if (!data().args.step_exec) - output().fg(ostd::ConsoleColors::Yellow).p("Press to enter in step-execution mode...").reset().nl(); - while (!userQuit) - { - ostd::SignalHandler::handleDelegateSignals(); - if (closeEventListener.hasHappened()) - userQuit = true; - data().command.clr(); - if (!userQuit && data().args.step_exec) - rValue = step_execution(userQuit, true); - else if (!userQuit) - rValue = normal_runtime(userQuit); - data().currentAddress = DragonRuntime::cpu.readRegister(data::Registers::IP); - } - output().nl().fg(ostd::ConsoleColors::Yellow).p("Execution terminated.").nl().nl().reset(); - return rValue; - } - - i32 Debugger::step_execution(bool& outUserQuit, bool exec_first_step) - { - if (exec_first_step && !DragonRuntime::cpu.isHalted()) - DragonRuntime::runStep(data().trackedAddresses); - Display::printStep(); - processErrors(); - if (DragonRuntime::cpu.isInDebugBreakPoint()) - output().fg(ostd::ConsoleColors::Red).p("Reached Debug Break Point.").reset().nl(); - if (DragonRuntime::cpu.isRamDumped()) - output().fg(ostd::ConsoleColors::Red).p("RAM Dumped to .").reset().nl(); - Display::printPrompt(); - data().command = getCommandInput(); - data().command.trim().toLower(); - while (data().command != "") - { - if (data().command == "q" || data().command == "quit" || data().command == InputCommandQuit) - { - output().nl(); - outUserQuit = true; - data().command = ""; - } - else if (data().command == "c" || data().command == "continue") - { - data().args.step_exec = false; - data().command = ""; - output().clear().fg(ostd::ConsoleColors::Green).p("Program running...").nl(); - output().fg(ostd::ConsoleColors::Yellow).p("Press to enter in step-execution mode...").reset().nl(); - } - else if (data().command.startsWith("p ") || data().command.startsWith("print ")) - { - data().command.substr(data().command.indexOf(" ") + 1).trim(); - const u8 TYPE_STRING = 0; - const u8 TYPE_BYTE = 1; - const u8 TYPE_WORD = 2; - const u8 TYPE_DWORD = 4; - const u8 TYPE_QWORD = 8; - u8 type = TYPE_WORD; - if (data().command.contains(" ")) - { - String size_str = data().command.new_substr(0, data().command.indexOf(" ")).trim(); - data().command.substr(data().command.indexOf(" ") + 1).trim(); - if (size_str == "byte") type = TYPE_BYTE; - else if (size_str == "word") type = TYPE_WORD; - else if (size_str == "dword") type = TYPE_DWORD; - else if (size_str == "qword") type = TYPE_QWORD; - else if (size_str == "string") type = TYPE_STRING; - } - if (data().command.isNumeric()) - { - if (type == TYPE_STRING) - type = TYPE_WORD; - u16 addr = data().command.toInt(); - u16 end_addr = addr; - String tmp = ""; - tmp.add("*(").add(String::getHexStr(addr, true, 2)); - if (type != TYPE_BYTE) - { - end_addr = addr + type - 1; - if (end_addr < addr) - end_addr = addr; - else - tmp.add("-").add(String::getHexStr(end_addr, true, 2)); - } - tmp.add(")"); - ostd::RegexRichString rgx(tmp); - rgx.fg("\\(|\\)|-", "darkgray"); - rgx.fg("\\*", "red"); - rgx.fg("0x[0-9A-Fa-f]+|0b[0-1]+|(? command.").reset().nl(); - else - { - String tmp = ""; - tmp.add("*(").add(String::getHexStr(addr, true, 2)); - if (size > 1) - tmp.add("-").add(String::getHexStr((u16)(addr + size - 1), true, 2)); - tmp.add(")"); - ostd::RegexRichString rgx(tmp); - rgx.fg("\\(|\\)|-", "darkgray"); - rgx.fg("\\*", "red"); - rgx.fg("0x[0-9A-Fa-f]+|0b[0-1]+|(? command.").reset().nl(); - } - Display::printPrompt(); - data().command = getCommandInput(); - } - else if (data().command.startsWith("b ") || data().command.startsWith("break ")) - {//0x2C1D - data().command.substr(data().command.indexOf(" ") + 1).trim(); - u16 addr = 0; - bool valid = false; - if (data().command.isNumeric()) - { - addr = (u16)data().command.toInt(); - valid = true; - } - else if (data().command.startsWith("$")) - { - addr = Utils::findSymbol(debugger.labels, data().command); - if (addr == 0x0000 || addr == 0xFFFF) - output().fg(ostd::ConsoleColors::Red).p("Invalid symbol: ").p(data().command).reset().nl(); - else - valid = true; - } - else - { - output().fg(ostd::ConsoleColors::Red).p("Invalid value for command.").reset().nl(); - } - if (valid) - { - if (Utils::isBreakPoint(addr)) - { - Utils::removeBreakPoint(addr); - output().fg(ostd::ConsoleColors::Yellow).p("Breakpoint removed at address: ").p(String::getHexStr(addr, true, 2)).reset().nl(); - } - else - { - Utils::addBreakPoint(addr); - output().fg(ostd::ConsoleColors::Yellow).p("Breakpoint set at address: ").p(String::getHexStr(addr, true, 2)).reset().nl(); - } - } - Display::printPrompt(); - data().command = getCommandInput(); - } - else - data().command = Display::changeScreen(); - } - return DragonRuntime::RETURN_VAL_EXIT_SUCCESS; - } - - i32 Debugger::normal_runtime(bool& outUserQuit) - { - bool result = DragonRuntime::runStep(data().trackedAddresses); - if (Utils::isBreakPoint((u16)DragonRuntime::cpu.readRegister(data::Registers::IP))) - { - data().args.step_exec = true; - return step_execution(outUserQuit, false); - } - bool hasError = DragonRuntime::hasError(); - bool enableStepExec = !result || hasError || Utils::isEscapeKeyPressed() || DragonRuntime::cpu.isInDebugBreakPoint(); - data().args.step_exec = enableStepExec; - if (enableStepExec) - return step_execution(outUserQuit, false); - return DragonRuntime::RETURN_VAL_EXIT_SUCCESS; - } - - void Debugger::exec_watch_command(void) - { - auto tokens = data().command.tokenize(); - for (auto& addr : tokens) - { - data().command = addr; - if (data().command.isNumeric()) - { - data().trackedAddresses.push_back((u16)data().command.toInt()); - } - else if (data().command.startsWith("$")) - { - u16 nbytes = 1; - u16 addr = Utils::findSymbol(data().data, data().command, &nbytes); - if (addr > 0) - { - for (i32 i = 0; i < nbytes; i++) - data().trackedAddresses.push_back(addr + i); - } - else - { - addr = Utils::findSymbol(data().labels, data().command, &nbytes); - if (addr > 0) - { - for (i32 i = 0; i < nbytes; i++) - data().trackedAddresses.push_back(addr + i); - } - } - } - else if (data().command.contains("[") && data().command.endsWith("]")) - { - u16 nbytes = 1; - String str_nbytes = data().command.new_substr(data().command.indexOf("[") + 1).trim(); - str_nbytes.substr(0, str_nbytes.len() - 1); - data().command.substr(0, data().command.indexOf("[")).trim(); - if (str_nbytes.isNumeric()) - nbytes = str_nbytes.toInt(); - if (nbytes < 1) nbytes = 1; - if (data().command.isNumeric()) - { - u16 addr = data().command.toInt(); - for (i32 i = 0; i < nbytes; i++) - data().trackedAddresses.push_back(addr + i); - } - } - } - output().p("Tracking ").p((int)data().trackedAddresses.size()).p(" addresses.").nl(); - } - - void Debugger::print_top_level_prompt_help(void) - { - i32 commandLength = 40; - Utils::printFullLine('#', ostd::ConsoleColors::Black, ostd::ConsoleColors::Red); - - out.nl().fg(ostd::ConsoleColors::Yellow).p("List of available commands:").reset().nl(); - String tmpCommand = "(r)un"; - tmpCommand.addRightPadding(commandLength); - out.fg(ostd::ConsoleColors::Blue).p(tmpCommand).fg(ostd::ConsoleColors::Green).p("Used to start the runtime.").reset().nl(); - tmpCommand = "(q)uit"; - tmpCommand.addRightPadding(commandLength); - out.fg(ostd::ConsoleColors::Blue).p(tmpCommand).fg(ostd::ConsoleColors::Green).p("Used to exit the debugger. ( key can also be used here.)").reset().nl(); - tmpCommand = "(h)elp"; - tmpCommand.addRightPadding(commandLength); - out.fg(ostd::ConsoleColors::Blue).p(tmpCommand).fg(ostd::ConsoleColors::Green).p("Used to show this dialog.").reset().nl(); - tmpCommand = "(s)tep"; - tmpCommand.addRightPadding(commandLength); - out.fg(ostd::ConsoleColors::Blue).p(tmpCommand).fg(ostd::ConsoleColors::Green).p("Used to enable/disable step-execution for the runtime.").reset().nl(); - tmpCommand = "(t)rack "; - tmpCommand.addRightPadding(commandLength); - out.fg(ostd::ConsoleColors::Blue).p(tmpCommand).fg(ostd::ConsoleColors::Green).p("Used to track specific addresses during execution.").reset().nl(); - tmpCommand = "display"; - tmpCommand.addRightPadding(commandLength); - out.fg(ostd::ConsoleColors::Blue).p(tmpCommand).fg(ostd::ConsoleColors::Green).p("Used to enable/disable the Virtual Display for the runtime.").reset().nl(); - - out.nl().fg(ostd::ConsoleColors::Cyan).p("The letters in parenthesis can be used as the short version of the command.").nl(); - out.p("Square brackets represent optional parameters. If they have an '=' and a value, that is the default if not specified.").reset().nl(); - - out.nl(); - Utils::printFullLine('#', ostd::ConsoleColors::Black, ostd::ConsoleColors::Red); - } - - void Debugger::print_application_help(void) - { - i32 commandLength = 46; - - out.nl().fg(ostd::ConsoleColors::Yellow).p("List of available parameters:").reset().nl(); - String tmpCommand = "--verbose-load"; - tmpCommand.addRightPadding(commandLength); - out.fg(ostd::ConsoleColors::Blue).p(tmpCommand).fg(ostd::ConsoleColors::Green).p("Used to show more information while loading the virtual machine.").reset().nl(); - tmpCommand = "--step-exec"; - tmpCommand.addRightPadding(commandLength); - out.fg(ostd::ConsoleColors::Blue).p(tmpCommand).fg(ostd::ConsoleColors::Green).p("Launches the debugger directly in step-execution mode.").reset().nl(); - tmpCommand = "--track-step-diff-off"; - tmpCommand.addRightPadding(commandLength); - out.fg(ostd::ConsoleColors::Blue).p(tmpCommand).fg(ostd::ConsoleColors::Green).p("Disables the tracking of most machine data used for differential-view.").reset().nl(); - tmpCommand = "--auto-track-data-off"; - tmpCommand.addRightPadding(commandLength); - out.fg(ostd::ConsoleColors::Blue).p(tmpCommand).fg(ostd::ConsoleColors::Green).p("Disables the automatic tracking of all data-symbols.").reset().nl(); - tmpCommand = "--hide-vdisplay"; - tmpCommand.addRightPadding(commandLength); - out.fg(ostd::ConsoleColors::Blue).p(tmpCommand).fg(ostd::ConsoleColors::Green).p("Hides the Virtual Display during the execution of the program.").reset().nl(); - tmpCommand = "--auto-start"; - tmpCommand.addRightPadding(commandLength); - out.fg(ostd::ConsoleColors::Blue).p(tmpCommand).fg(ostd::ConsoleColors::Green).p("Launches the runtime directly, skipping the top-level prompt of the debugger.").reset().nl(); - tmpCommand = "--force-load "; - tmpCommand.addRightPadding(commandLength); - out.fg(ostd::ConsoleColors::Blue).p(tmpCommand).fg(ostd::ConsoleColors::Green).p("Injects the specified binary into RAM at the specified offset.").reset().nl(); - tmpCommand = "--help"; - tmpCommand.addRightPadding(commandLength); - out.fg(ostd::ConsoleColors::Blue).p(tmpCommand).fg(ostd::ConsoleColors::Green).p("Displays this help message.").reset().nl(); - - out.nl().fg(ostd::ConsoleColors::Magenta).p("Usage: ./ddb [...options...]").reset().nl(); - out.nl(); - } -} diff --git a/src/debugger/Debugger.hpp b/src/debugger/Debugger.hpp deleted file mode 100644 index cf9767b..0000000 --- a/src/debugger/Debugger.hpp +++ /dev/null @@ -1,105 +0,0 @@ -#pragma once - -#include -#include "../assembler/Assembler.hpp" - -namespace dragon -{ - typedef std::vector DisassemblyList; - - class Debugger - { - public: struct tCommandLineArgs - { - inline tCommandLineArgs(void) { } - String machine_config_path = ""; - bool verbose_load = false; - bool force_load = false; - bool step_exec = false; - bool track_step_diff = true; - bool auto_start_debug = false; - bool hide_virtual_display = true; - bool track_call_stack = true; - bool auto_track_all_data_symbols = true; - String force_load_file = ""; - u16 force_load_mem_offset = 0x00; - }; - public: struct tDebuggerData - { - inline tDebuggerData(void) { } - tCommandLineArgs args; - DisassemblyList code; - DisassemblyList labels; - DisassemblyList data; - std::vector trackedAddresses; - String command; - i32 labelLineLength { 40 }; - u16 currentAddress { 0 }; - bool userQuit { false }; - String disassemblyDirectory { "disassembly" }; - std::vector manualBreakPoints; - }; - struct tCloseEventListener : public ostd::BaseObject - { - void init(void); - void handleSignal(ostd::Signal& signal); - inline bool hasHappened(void) const { return m_mainWindowClosed; } - - private: - bool m_mainWindowClosed { false }; - }; - public: class Utils - { - public: - static DisassemblyList findCodeRegion(const DisassemblyList& code, u16 address, u16 codeRegionMargin); - static String findSymbol(const DisassemblyList& labels, u16 address, u16* outSize = nullptr); - static u16 findSymbol(const DisassemblyList& labels, const String& symbol, u16* outSize = nullptr); - static bool isValidLabelNameChar(char c); - static void clearConsoleLine(void); - static bool isEscapeKeyPressed(bool blocking = false); - static ostd::ConsoleOutputHandler& printFullLine(char c, const ostd::ConsoleColors::tConsoleColor& foreground); - static ostd::ConsoleOutputHandler& printFullLine(char c, const ostd::ConsoleColors::tConsoleColor& foreground, const ostd::ConsoleColors::tConsoleColor& background); - static void removeBreakPoint(u16 addr); - static bool isBreakPoint(u16 addr); - static void addBreakPoint(u16 addr); - }; - public: class Display - { - public: - static void colorizeInstructionBody(const String& instBody, bool currentLine, const DisassemblyList& labelList); - static void colorCodeInstructions(const String& inst, bool currentLine, const DisassemblyList& labelList); - static void printPrompt(void); - static void printStep(void); - static void printDiff(void); - static void printTrackedAddresses(void); - static void printStack(u16 nrows); - static void printCallStack(void); - static void printHelp(void); - static String changeScreen(void); - }; - public: - static void processErrors(void); - static i32 loadArguments(int argc, char** argv); - static i32 initRuntime(void); - static String getCommandInput(void); - static inline tDebuggerData& data(void) { return debugger; } - static inline ostd::ConsoleOutputHandler& output(void) { return out; } - static i32 topLevelPrompt(void); - static i32 executeRuntime(void); - - private: - static i32 step_execution(bool& outUserQuit, bool exec_first_step = true); - static i32 normal_runtime(bool& outUserQuit); - static void exec_watch_command(void); - static void print_top_level_prompt_help(void); - static void print_application_help(void); - - private: - inline static tDebuggerData debugger; - inline static ostd::ConsoleOutputHandler out; - static tCloseEventListener closeEventListener; - - public: - inline static const String InputCommandQuit = "//quit//"; - }; -} diff --git a/src/debugger/debugger_main.cpp b/src/debugger/debugger_main.cpp index b583a2b..9d54ff9 100644 --- a/src/debugger/debugger_main.cpp +++ b/src/debugger/debugger_main.cpp @@ -1,54 +1,29 @@ #include -#include "Debugger.hpp" -#include "../runtime/DragonRuntime.hpp" -// #include "DebuggerNew.hpp" +// #include "../runtime/DragonRuntime.hpp" #include int main(int argc, char** argv) { //Loading commandline arguments - i32 rValue = dragon::Debugger::loadArguments(argc, argv); - if (rValue == dragon::DragonRuntime::RETURN_VAL_CLOSE_DEBUGGER) - return 0; - if (rValue != 0) return rValue; - - //Initializing the runtime - rValue = dragon::Debugger::initRuntime(); - if (rValue == dragon::DragonRuntime::RETURN_VAL_CLOSE_DEBUGGER) - return 0; - if (rValue != 0) return rValue; - - //Running top-level prompt - rValue = dragon::Debugger::topLevelPrompt(); - if (rValue == dragon::DragonRuntime::RETURN_VAL_CLOSE_DEBUGGER) - return 0; - if (rValue != 0) return rValue; - - //Executing the runtime - return dragon::Debugger::executeRuntime(); - - - - // dragon::DebuggerNew debuggerInstance; - // debuggerInstance.initialize(2000, 1090, "DragonVM Live Debugger"); - // debuggerInstance.setClearColor({ 5, 0, 0 }); - - // //Loading commandline arguments - // i32 rValue = debuggerInstance.loadArguments(argc, argv); + // i32 rValue = dragon::Debugger::loadArguments(argc, argv); // if (rValue == dragon::DragonRuntime::RETURN_VAL_CLOSE_DEBUGGER) // return 0; // if (rValue != 0) return rValue; // //Initializing the runtime - // rValue = debuggerInstance.initRuntime(); + // rValue = dragon::Debugger::initRuntime(); // if (rValue == dragon::DragonRuntime::RETURN_VAL_CLOSE_DEBUGGER) // return 0; // if (rValue != 0) return rValue; - // while (debuggerInstance.isRunning()) - // { - // debuggerInstance.update(); - // } + // //Running top-level prompt + // rValue = dragon::Debugger::topLevelPrompt(); + // if (rValue == dragon::DragonRuntime::RETURN_VAL_CLOSE_DEBUGGER) + // return 0; + // if (rValue != 0) return rValue; + + // //Executing the runtime + // return dragon::Debugger::executeRuntime(); return 0; } diff --git a/src/hardware/VirtualCPU.cpp b/src/hardware/VirtualCPU.cpp index 245abdd..5e63eda 100644 --- a/src/hardware/VirtualCPU.cpp +++ b/src/hardware/VirtualCPU.cpp @@ -82,11 +82,6 @@ namespace dragon void VirtualCPU::pushStackFrame(void) { - if (m_debugModeEnabled) - { - __debug_store_stack_frame_string_on_push(); - return; - } u16 argStartAddr = readRegister(data::Registers::SP) + 2; u16 argCount = m_memory.read16(argStartAddr); if (argCount == 0) @@ -120,7 +115,6 @@ namespace dragon u16 framePointerAddr = readRegister(data::Registers::FP); writeRegister16(data::Registers::SP, framePointerAddr); m_stackFrameSize = popFromStack(); - // u16 tmpStackFrameSize = m_stackFrameSize; writeRegister16(data::Registers::FP, popFromStack()); writeRegister16(data::Registers::IP, popFromStack()); @@ -139,12 +133,7 @@ namespace dragon u16 nArgs = popFromStack(); for (i32 i = 0; i < nArgs; i++) - { popFromStack(); - // writeRegister(data::Registers::FP, readRegister(data::Registers::FP) - 2); - } - - // writeRegister(data::Registers::FP, framePointerAddr + tmpStackFrameSize); } bool VirtualCPU::readFlag(u8 flg) @@ -173,15 +162,15 @@ namespace dragon m_subroutineCounter++; m_interruptHandlerCount++; writeRegister16(data::Registers::IP, handlerAddress); - if (m_debugModeEnabled && hardware) - { - DragonRuntime::tCallInfo interruptData; - interruptData.info = "HW INT"; - interruptData.addr = intValue; - interruptData.inst_addr = 0x0000; - interruptData.interrupts_disabled = !readFlag(data::Flags::InterruptsEnabled); - ostd::SignalHandler::emitSignal(DragonRuntime::SignalListener::Signal_HardwareInterruptOccurred, ostd::Signal::Priority::RealTime, interruptData); - } + // if (m_debugModeEnabled && hardware) + // { + // DragonRuntime::tCallInfo interruptData; + // interruptData.info = "HW INT"; + // interruptData.addr = intValue; + // interruptData.inst_addr = 0x0000; + // interruptData.interrupts_disabled = !readFlag(data::Flags::InterruptsEnabled); + // ostd::SignalHandler::emitSignal(DragonRuntime::SignalListener::Signal_HardwareInterruptOccurred, ostd::Signal::Priority::RealTime, interruptData); + // } } bool VirtualCPU::loadExtension(void) @@ -222,33 +211,26 @@ namespace dragon { case data::OpCodes::NoOp: { - + // } break; case data::OpCodes::DEBUG_Break: { + if (!m_debugModeEnabled) break; m_isDebugBreakPoint = true; } break; case data::OpCodes::DEBUG_DumpRAM: { + if (!m_debugModeEnabled) break; ostd::Memory::saveByteStreamToFile(*DragonRuntime::ram.getByteStream(), "ram_dump.bin"); m_isDebugBreakPoint = true; m_ramDumped = true; } break; - case data::OpCodes::BIOSModeImm: - { - u16 tmpAddr = m_currentAddr; - i8 value = fetch8(); - if (tmpAddr >= data::MemoryMapAddresses::BIOS_End) - m_biosMode = false; - else - m_biosMode = value != 0; - } - break; case data::OpCodes::DEBUG_StartProfile: { + if (!m_debugModeEnabled) break; i8 id = fetch8(); i8 timeUnit = fetch8(); ostd::eTimeUnits tu = ostd::eTimeUnits::Milliseconds; @@ -264,11 +246,22 @@ namespace dragon break; case data::OpCodes::DEBUG_StopProfile: { + if (!m_debugModeEnabled) break; if (m_debugProfilerStarted) m_profilerTimer.end(true); m_debugProfilerStarted = false; } break; + case data::OpCodes::BIOSModeImm: + { + u16 tmpAddr = m_currentAddr; + i8 value = fetch8(); + if (tmpAddr >= data::MemoryMapAddresses::BIOS_End) + m_biosMode = false; + else + m_biosMode = value != 0; + } + break; case data::OpCodes::MovImmReg: { u8 regAddr = fetch8(); @@ -325,16 +318,6 @@ namespace dragon m_memory.write16(destAddr, value); } break; - // case data::OpCodes::MovImmRegOffReg: - // { - // u8 destRegAddr = fetch8(); - // u16 addr = fetch16(); - // u8 offRegAddr = fetch8(); - // i16 offset = readRegister(offRegAddr); - // i16 value = m_memory.read16(addr + offset); - // writeRegister(destRegAddr, value); - // } - // break; case data::OpCodes::MovRegDerefReg: { u8 destRegAddr = fetch8(); @@ -821,7 +804,6 @@ namespace dragon case data::OpCodes::Ret: { popStackFrame(); - // m_subroutineCounter = ZERO(m_subroutineCounter - 1); m_subroutineCounter--; } break; @@ -839,7 +821,6 @@ namespace dragon { m_interruptHandlerCount--; popStackFrame(); - // m_subroutineCounter = ZERO(m_subroutineCounter - 1); m_subroutineCounter--; } break; @@ -903,60 +884,5 @@ namespace dragon return true; } - - void VirtualCPU::__debug_store_stack_frame_string_on_push(void) - { - if (!m_debugModeEnabled) return; - String stackFrameString = ""; - - u16 argStartAddr = readRegister(data::Registers::SP) + 2; - u16 argCount = m_memory.read16(argStartAddr); - if (argCount == 0) - argStartAddr = 0; - else - argStartAddr += (argCount * 2); - - stackFrameString.add("args: ").add(String::getHexStr(argStartAddr, true, 2)).add(", argc: ").add(argCount).add("\n"); - - pushToStack(readRegister(data::Registers::R1)); - stackFrameString.add("R1: ").add(String::getHexStr(readRegister(data::Registers::R1), true, 2)); - pushToStack(readRegister(data::Registers::R2)); - stackFrameString.add(" R2: ").add(String::getHexStr(readRegister(data::Registers::R2), true, 2)); - pushToStack(readRegister(data::Registers::R3)); - stackFrameString.add(" R3: ").add(String::getHexStr(readRegister(data::Registers::R3), true, 2)); - pushToStack(readRegister(data::Registers::R4)); - stackFrameString.add(" R4: ").add(String::getHexStr(readRegister(data::Registers::R4), true, 2)); - pushToStack(readRegister(data::Registers::R5)); - stackFrameString.add(" R5: ").add(String::getHexStr(readRegister(data::Registers::R5), true, 2)); - pushToStack(readRegister(data::Registers::R6)); - stackFrameString.add(" R6: ").add(String::getHexStr(readRegister(data::Registers::R6), true, 2)); - pushToStack(readRegister(data::Registers::R7)); - stackFrameString.add(" R7: ").add(String::getHexStr(readRegister(data::Registers::R7), true, 2)); - pushToStack(readRegister(data::Registers::R8)); - stackFrameString.add(" R8: ").add(String::getHexStr(readRegister(data::Registers::R8), true, 2)); - pushToStack(readRegister(data::Registers::R9)); - stackFrameString.add(" R9: ").add(String::getHexStr(readRegister(data::Registers::R9), true, 2)); - pushToStack(readRegister(data::Registers::R10)); - stackFrameString.add(" R10: ").add(String::getHexStr(readRegister(data::Registers::R10), true, 2)); - stackFrameString.add("\n"); - pushToStack(readRegister(data::Registers::PP)); - stackFrameString.add("PP: ").add(String::getHexStr(readRegister(data::Registers::PP), true, 2)); - pushToStack(readRegister(data::Registers::ACC)); - stackFrameString.add(" ACC: ").add(String::getHexStr(readRegister(data::Registers::ACC), true, 2)); - pushToStack(readRegister(data::Registers::IP)); - stackFrameString.add(" IP: ").add(String::getHexStr(readRegister(data::Registers::IP), true, 2)); - pushToStack(readRegister(data::Registers::FP)); - stackFrameString.add(" FP: ").add(String::getHexStr(readRegister(data::Registers::FP), true, 2)); - stackFrameString.add("\n"); - pushToStack(m_stackFrameSize); - stackFrameString.add("StackFrame: ").add(m_stackFrameSize).add(", "); - - writeRegister16(data::Registers::PP, argStartAddr); - writeRegister16(data::Registers::FP, readRegister(data::Registers::SP)); - stackFrameString.add("New FP: ").add(String::getHexStr(readRegister(data::Registers::FP), true, 2)); - m_stackFrameSize = 0; - - m_debug_stackFrameStrings.push_back(stackFrameString); - } } } diff --git a/src/hardware/VirtualCPU.hpp b/src/hardware/VirtualCPU.hpp index 7c5a45d..09c873f 100644 --- a/src/hardware/VirtualCPU.hpp +++ b/src/hardware/VirtualCPU.hpp @@ -5,7 +5,6 @@ #include #include "IMemoryDevice.hpp" -#include "../debugger/Debugger.hpp" #include "../tools/GlobalData.hpp" namespace dragon @@ -52,9 +51,6 @@ namespace dragon inline bool isOffsetAddressingModeEnabled(void) const { return m_isOffsetAddressingEnabled; } inline u16 getCurrentOffset(void) const { return m_currentOffset; } - private: - void __debug_store_stack_frame_string_on_push(void); - private: i16 m_registers[20]; ostd::BitField_16 m_tempFlags; @@ -78,13 +74,9 @@ namespace dragon data::CPUExtension* m_currentExtension { nullptr }; u8 m_currentExtInst { 0x00 }; - std::vector m_debug_stackFrameStrings; - ostd::Counter m_profilerTimer; friend class dragon::DragonRuntime; - friend class dragon::Debugger::Display; - friend class dragon::Debugger; }; } } diff --git a/src/hardware/VirtualMMU.cpp b/src/hardware/VirtualMMU.cpp deleted file mode 100644 index a36d5ee..0000000 --- a/src/hardware/VirtualMMU.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "VirtualMMU.hpp" - -namespace dragon -{ - namespace hw - { - VirtualMMU& VirtualMMU::init(void) - { - m_data.init(VirtualMMU::MMUSize); - m_data.enableAutoResize(false); - return *this; - } - } -} \ No newline at end of file diff --git a/src/hardware/VirtualMMU.hpp b/src/hardware/VirtualMMU.hpp deleted file mode 100644 index acd1b0f..0000000 --- a/src/hardware/VirtualMMU.hpp +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include "../tools/LegacyOstdSerial.hpp" - -namespace dragon -{ - namespace hw - { - class VirtualMMU //TODO: Implement for later use - { - public: - inline VirtualMMU(void) { init(); } - VirtualMMU& init(void); - - private: - ostd::serial::SerialIO m_data; - - public: - inline static constexpr u16 MMUSize = 6144; - inline static constexpr u16 PageSize = 512; - }; - } -} diff --git a/src/runtime/DragonRuntime.cpp b/src/runtime/DragonRuntime.cpp index 7a843da..b3afc61 100644 --- a/src/runtime/DragonRuntime.cpp +++ b/src/runtime/DragonRuntime.cpp @@ -17,51 +17,12 @@ namespace dragon { if (signal.ID == Signal_HardwareInterruptOccurred) { - tCallInfo& interruptData = (tCallInfo&)signal.userData; - DragonRuntime::s_machineInfo.callStack.push_back(interruptData); } } - void DragonRuntime::printRegisters(dragon::hw::VirtualCPU& cpu) - { - out.fg("green").p("IP: ").fg("white").p(String::getHexStr(cpu.readRegister(dragon::data::Registers::IP), true, 2).cpp_str()); - out.p(" "); - out.fg("yellow").p("R1: ").fg("white").p(String::getHexStr(cpu.readRegister(dragon::data::Registers::R1), true, 2).cpp_str()); - out.p(" "); - out.fg("yellow").p("R2: ").fg("white").p(String::getHexStr(cpu.readRegister(dragon::data::Registers::R2), true, 2).cpp_str()).nl(); - - out.fg("green").p("SP: ").fg("white").p(String::getHexStr(cpu.readRegister(dragon::data::Registers::SP), true, 2).cpp_str()); - out.p(" "); - out.fg("yellow").p("R3: ").fg("white").p(String::getHexStr(cpu.readRegister(dragon::data::Registers::R3), true, 2).cpp_str()); - out.p(" "); - out.fg("yellow").p("R4: ").fg("white").p(String::getHexStr(cpu.readRegister(dragon::data::Registers::R4), true, 2).cpp_str()).nl(); - - out.fg("green").p("FP: ").fg("white").p(String::getHexStr(cpu.readRegister(dragon::data::Registers::FP), true, 2).cpp_str()); - out.p(" "); - out.fg("yellow").p("R5: ").fg("white").p(String::getHexStr(cpu.readRegister(dragon::data::Registers::R5), true, 2).cpp_str()); - out.p(" "); - out.fg("yellow").p("R6: ").fg("white").p(String::getHexStr(cpu.readRegister(dragon::data::Registers::R6), true, 2).cpp_str()).nl(); - - out.fg("green").p("RV: ").fg("white").p(String::getHexStr(cpu.readRegister(dragon::data::Registers::RV), true, 2).cpp_str()); - out.p(" "); - out.fg("yellow").p("R7: ").fg("white").p(String::getHexStr(cpu.readRegister(dragon::data::Registers::R7), true, 2).cpp_str()); - out.p(" "); - out.fg("yellow").p("R8: ").fg("white").p(String::getHexStr(cpu.readRegister(dragon::data::Registers::R8), true, 2).cpp_str()).nl(); - - out.fg("green").p("PP: ").fg("white").p(String::getHexStr(cpu.readRegister(dragon::data::Registers::PP), true, 2).cpp_str()); - out.p(" "); - out.fg("yellow").p("R9: ").fg("white").p(String::getHexStr(cpu.readRegister(dragon::data::Registers::R9), true, 2).cpp_str()); - out.p(" "); - out.fg("yellow").p("R10: ").fg("white").p(String::getHexStr(cpu.readRegister(dragon::data::Registers::R10), true, 2).cpp_str()).nl(); - - out.fg("green").p("ACC: ").fg("white").p(String::getHexStr(cpu.readRegister(dragon::data::Registers::ACC), true, 2).cpp_str()); - out.p(" "); - out.fg("yellow").p("FL: ").fg("white").p(String::getBinStr(cpu.readRegister(dragon::data::Registers::FL), true, 2).cpp_str()); - } - void DragonRuntime::processErrors(void) { while (dragon::data::ErrorHandler::hasError()) @@ -330,12 +291,7 @@ namespace dragon if (info.verboseLoad) out.fg(ostd::ConsoleColors::BrightYellow).p(" Loading CMOS Machine info").nl(); - - - out.nl().nl(); - s_trackMachineInfo = info.trackMachineInfoDiff; - s_trackCallStack = info.trackCallStack; return RETURN_VAL_EXIT_SUCCESS; } @@ -363,9 +319,7 @@ namespace dragon u16 addr = cpu.readRegister(dragon::data::Registers::IP); u16 spAddr = cpu.readRegister(dragon::data::Registers::SP); u8 screenRedrawRate = vCMOS.read8(data::CMOSRegisters::ScreenRedrawRate); - // _timer.start(true, "Profiling", ostd::eTimeUnits::Microseconds, &out); running = cpu.execute() && vDisplay.isRunning(); - // _timer.end(true); vDisplay.mainLoop(); vDiskInterface.cycleStep(); if (dragon::data::ErrorHandler::hasError()) @@ -378,7 +332,6 @@ namespace dragon avg_count++; avg_tot += _time; s_avgInstTime = (u64)std::round(avg_tot / avg_count); - // out.fg(ostd::ConsoleColors::Red).p(getAvgClockSpeed()).nl().reset(); acc = 0; } if (acc2 == (1000.0 / screenRedrawRate)) @@ -394,11 +347,8 @@ namespace dragon } } - bool DragonRuntime::runStep(std::vector trackedAddresses) + bool DragonRuntime::runStep(void) { - std::sort(trackedAddresses.begin(), trackedAddresses.end()); - __get_machine_footprint(&s_machineInfo, trackedAddresses, true); - __track_call_stack(&s_machineInfo); bool running = cpu.execute() && vDisplay.isRunning(); u8 screenRedrawRate = vCMOS.read8(data::CMOSRegisters::ScreenRedrawRate); vDisplay.mainLoop(); @@ -414,7 +364,6 @@ namespace dragon s_stepAcc2++; // vDisplay.redrawScreen(); // This is slow...maybe it should be on a 100ms rate, like in normal runtime mode vDiskInterface.cycleStep(); - __get_machine_footprint(&s_machineInfo, trackedAddresses, false); return running || vDiskInterface.isBusy(); } @@ -431,133 +380,8 @@ namespace dragon } } - - void DragonRuntime::__get_machine_footprint(DragonRuntime::tMachineDebugInfo* machineInfo, std::vector trackedAddresses, bool previous) + void DragonRuntime::__print_application_help(void) { - if (!s_trackMachineInfo || machineInfo == nullptr) return; - auto& minfo = *machineInfo; - - if (previous) - { - minfo.vCPUHalt = cpu.m_halt; - minfo.trackedAddresses.clear(); - minfo.previousInstructionTrackedValues.clear(); - minfo.currentInstructionTrackedValues.clear(); - - for (i32 i = 0; i < 20; i++) - { - if (i < 5) - { - minfo.previousInstructionFootprint[i] = 0; - minfo.currentInstructionFootprint[i] = 0; - } - minfo.previousInstructionRegisters[i] = 0; - minfo.currentInstructionRegisters[i] = 0; - } - - for (auto& addr : trackedAddresses) - minfo.trackedAddresses.push_back(addr); - } - - u16 instAddr = cpu.readRegister(data::Registers::IP); - u8 int_op_code = memMap.read8(instAddr); - u8 instSize = data::OpCodes::getInstructionSIze(int_op_code); - String opCode = data::OpCodes::getOpCodeString(int_op_code); - u16 stackFrameSize = cpu.m_stackFrameSize; - i32 subRoutineCounter = cpu.m_subroutineCounter; - - bool debugBreak = cpu.m_isDebugBreakPoint; - i32 intHandlerCount = cpu.m_interruptHandlerCount; - bool biosMode = cpu.m_biosMode; - bool isInSubRoutine = cpu.isInSubRoutine(); - - if (previous) - { - minfo.previousInstructionAddress = instAddr; - minfo.previousInstructionFootprintSize = instSize; - minfo.previousInstructionStackFrameSize = stackFrameSize; - minfo.previousInstructionOpCode = opCode; - minfo.previousSubRoutineCounter = subRoutineCounter; - - for (i8 i = 0; i < instSize; i++) - minfo.previousInstructionFootprint[i] = memMap.read8(instAddr + i); - - for (i8 i = 0; i < 20; i++) - minfo.previousInstructionRegisters[i] = cpu.readRegister(i); - - for (auto& addr : minfo.trackedAddresses) - minfo.previousInstructionTrackedValues.push_back(memMap.read8(addr)); - - minfo.previousInstructionDebugBreak = debugBreak; - minfo.previousInstructionInterruptHandlerCount = intHandlerCount; - minfo.previousInstructionBiosMode = biosMode; - minfo.previousIsInSubRoutine = isInSubRoutine; - } - else - { - //if (int_op_code >= data::OpCodes::Ext01 && int_op_code <= data::OpCodes::Ext16) - // minfo.currentInstructionAddress = minfo.previousInstructionAddress; - //else - minfo.currentInstructionAddress = instAddr; - minfo.currentInstructionFootprintSize = instSize; - minfo.currentInstructionStackFrameSize = stackFrameSize; - minfo.currentInstructionOpCode = opCode; - minfo.currentSubRoutineCounter = subRoutineCounter; - - for (i8 i = 0; i < instSize; i++) - minfo.currentInstructionFootprint[i] = memMap.read8(minfo.currentInstructionAddress + i); - - for (i8 i = 0; i < 20; i++) - minfo.currentInstructionRegisters[i] = cpu.readRegister(i); - - for (auto& addr : minfo.trackedAddresses) - minfo.currentInstructionTrackedValues.push_back(memMap.read8(addr)); - - minfo.currentInstructionDebugBreak = debugBreak; - minfo.currentInstructionInterruptHandlerCount = intHandlerCount; - minfo.currentInstructionBiosMode = biosMode; - minfo.currentIsInSubRoutine = isInSubRoutine; - } - } - - void DragonRuntime::__track_call_stack(tMachineDebugInfo* machineInfo) - { - if (!s_trackCallStack || machineInfo == nullptr) return; - auto& minfo = *machineInfo; - - bool interrupts_enabled = cpu.readFlag(data::Flags::InterruptsEnabled); - - u16 instAddr = cpu.readRegister(data::Registers::IP); - u8 inst = memMap.read8(instAddr); - - if (inst == data::OpCodes::CallImm) - { - u16 call_addr = memMap.read16(instAddr + 1); - minfo.callStack.push_back({ "CALL IMM", call_addr, instAddr, !interrupts_enabled }); - } - else if (inst == data::OpCodes::CallReg) - { - u8 reg_addr = memMap.read8(instAddr + 1); - u16 call_addr = cpu.readRegister(reg_addr); - minfo.callStack.push_back({ "CALL REG", call_addr, instAddr, !interrupts_enabled }); - } - else if (interrupts_enabled && inst == data::OpCodes::Int) - { - u8 int_num = memMap.read8(instAddr + 1); - minfo.callStack.push_back({ "INT", int_num, instAddr, !interrupts_enabled }); - } - else if (inst == data::OpCodes::Ret) - { - minfo.callStack.push_back({ "RET", 0x0000, instAddr, !interrupts_enabled }); - } - else if (interrupts_enabled && inst == data::OpCodes::RetInt) - { - minfo.callStack.push_back({ "RET INT", 0x0000, instAddr, !interrupts_enabled }); - } - } - - void DragonRuntime::__print_application_help(void) - { i32 commandLength = 46; out.nl().fg(ostd::ConsoleColors::Yellow).p("List of available parameters:").reset().nl(); @@ -573,5 +397,5 @@ namespace dragon out.nl().fg(ostd::ConsoleColors::Magenta).p("Usage: ./dvm [...options...]").reset().nl(); out.nl(); - } + } } diff --git a/src/runtime/DragonRuntime.hpp b/src/runtime/DragonRuntime.hpp index 142274b..22ef130 100644 --- a/src/runtime/DragonRuntime.hpp +++ b/src/runtime/DragonRuntime.hpp @@ -25,15 +25,6 @@ namespace dragon public: inline static const i32 Signal_HardwareInterruptOccurred = ostd::SignalHandler::newCustomSignal(8129); }; - public: struct tCallInfo : public ostd::BaseObject - { - inline tCallInfo(void) { } - inline tCallInfo(const String& _info, u16 _addr, u16 _inst_addr, bool ints_disabled) : info(_info), addr(_addr), inst_addr(_inst_addr), interrupts_disabled(ints_disabled) { } - String info; - u16 addr; - u16 inst_addr; - bool interrupts_disabled; - }; public: struct tCommandLineArgs { String machine_config_path = ""; @@ -46,69 +37,24 @@ namespace dragon { String configFilePath; bool verboseLoad { false }; - bool trackMachineInfoDiff { false }; bool hideVirtualDisplay { false }; - bool trackCallStack { false }; bool debugModeEnabled { false }; }; - public: struct tMachineDebugInfo - { - inline tMachineDebugInfo(void) { } - - u16 previousInstructionAddress { 0x0000 }; - u16 currentInstructionAddress { 0x0000 }; - i8 previousInstructionFootprintSize { 0x00 }; - i8 currentInstructionFootprintSize { 0x00 }; - u16 previousInstructionStackFrameSize { 0x00 }; - u16 currentInstructionStackFrameSize { 0x00 }; - i32 previousSubRoutineCounter { 0x00000000 }; - i32 currentSubRoutineCounter { 0x00000000 }; - - String previousInstructionOpCode { "" }; - String currentInstructionOpCode { "" }; - - i8 previousInstructionFootprint[5] { 0x00, 0x00, 0x00, 0x00, 0x00 }; - i8 currentInstructionFootprint[5] { 0x00, 0x00, 0x00, 0x00, 0x00 }; - i16 previousInstructionRegisters[20] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - i16 currentInstructionRegisters[20] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - i32 previousInstructionInterruptHandlerCount { 0 }; - i32 currentInstructionInterruptHandlerCount { 0 }; - - std::vector trackedAddresses; - std::vector previousInstructionTrackedValues; - std::vector currentInstructionTrackedValues; - - bool previousInstructionDebugBreak { false }; - bool currentInstructionDebugBreak { false }; - bool previousInstructionBiosMode { false }; - bool currentInstructionBiosMode { false }; - bool previousIsInSubRoutine { false }; - bool currentIsInSubRoutine { false }; - - bool vCPUHalt { false }; - - - std::vector callStack; - }; public: - static void printRegisters(hw::VirtualCPU& cpu); static void processErrors(void); static std::vector getErrorList(void); static i32 loadArguments(int argc, char** argv, tCommandLineArgs& args); static i32 initMachine(const tRuntimeInitInfo& info); static void shutdownMachine(void); static void runMachine(void); - static bool runStep(std::vector trackedAddresses = { }); + static bool runStep(void); static void forceLoad(const String& filePath, u16 loadAddress); - inline static const tMachineDebugInfo& getMachineInfoDiff(void) { return s_machineInfo; } inline static bool hasError(void) { return data::ErrorHandler::hasError(); } inline static ostd::ConsoleOutputHandler& output(void) { return out; } inline static u64 getAvgClockSpeed(void) { return (u64)std::round(1000000.0 / s_avgInstTime); } private: - static void __get_machine_footprint(tMachineDebugInfo* machineInfo, std::vector trackedAddresses, bool previous); - static void __track_call_stack(tMachineDebugInfo* machineInfo); static void __print_application_help(void); public: @@ -138,12 +84,8 @@ namespace dragon inline static bool s_enableScreenRedrawDelay { true }; private: - inline static tMachineDebugInfo s_machineInfo; - inline static bool s_trackMachineInfo { false }; - inline static bool s_trackCallStack { false }; inline static SignalListener s_signalListener; - public: inline static const i32 RETURN_VAL_CLOSE_DEBUGGER = 128; inline static const i32 RETURN_VAL_CLOSE_RUNTIME = 256;