From c4de3e6d0462d5df1624f7299c8cf6e7149093fa Mon Sep 17 00:00:00 2001 From: OmniaX Date: Sat, 22 Jun 2024 00:20:17 +0200 Subject: [PATCH] Added memory offset mode --- extra/dragon/bios.bin | Bin 4096 -> 4096 bytes extra/dss/bios/data.dss | 2 +- extra/dss/bios/entry.dss | 4 ++++ extra/dss/drake/bootsector.dss | 2 +- src/debugger/Debugger.cpp | 14 +++++++------- src/hardware/VirtualCPU.cpp | 5 +++++ src/hardware/VirtualCPU.hpp | 7 ++++++- src/hardware/VirtualRAM.cpp | 13 +++++++++---- src/tools/GlobalData.hpp | 3 ++- 9 files changed, 35 insertions(+), 15 deletions(-) diff --git a/extra/dragon/bios.bin b/extra/dragon/bios.bin index b08040f87c4663c3d03325971cf9b9e88d1fabec..dfcdd690161fdc6067eb92778b68593423ebf699 100644 GIT binary patch delta 541 zcmYk2v5ONy6vn^ZnKyIyVllIU)xu)ALUJe}f);iw3fEqYN#%8NjZJtUh^!i ziu@T0b~aWXSSliRX8jAS?7a9UInZKw-|xMdZ@!s%HLu>@vG<>aE)WX)Geiu|szYEz ztB30|isTZwFUQCdgk9hmd6GGr?tC3xSL_l&>?xwyPk`8O$Qs)&UfKSvRWXdi;t=`B z#{?>|r9bH`^^pnPLN0U{M(6>o&?Au0Q#hd)@Ioip5qgbXp(R-84LU-nxFGZyE1~ab z8~U+d+M+5=uCgjEt28QSJuY;TFt3ZAE2er2bPzo96eSz^8(TF0;kj9I(34J=-AdB( z&(fS*E;p7}TuD><08}Mqo9%?lT8q-9WPacN+gBn$Gy$bN_hfFI;$T%>V!Z delta 523 zcmYk2KS*Oi5XQgvc4t;M7H?nRorT3i;Yi?+vr1~~-Xg%kfK$os} zrqASv1MuHnL;+%y_0iOEUGx}<=rcIc=YZ&ch)R7^9qQHLjTdd#PB#&E4F~WNGkOZW zw1P-z6|vA)D4{mA&=yE&A1w48M(6-@LO(DsG=>#AK~3lk3qpTzFLZ%PNmtEGr+KDg zFY`=WFO`?WhE07YU|ggPP6vJpd?GQ3!zxkNG-s$j;G0=+@SW_ho=NiI-BP_-j$bW5 zb4CL?1@erd*K)#=k7>qXGc$7tyL!6!p}M1o=x24wU!woj6E6+<(OK1JF*&eor=?k0 zwkYhPo~w?HdjZ>xc;)~A diff --git a/extra/dss/bios/data.dss b/extra/dss/bios/data.dss index d9a1f94..e7873f6 100644 --- a/extra/dss/bios/data.dss +++ b/extra/dss/bios/data.dss @@ -77,7 +77,7 @@ @define S_REG_1 0x07 @define S_REG_2 0x08 -@define S_REG_3 0x09 +@define S_REG_OFFSET 0x09 @define INST_BIOS_NODE_TOGGLE 0x02 ## =============================================================================================== diff --git a/extra/dss/bios/entry.dss b/extra/dss/bios/entry.dss index 101083f..49173bf 100644 --- a/extra/dss/bios/entry.dss +++ b/extra/dss/bios/entry.dss @@ -26,6 +26,10 @@ mov FL, ACC ## ---- + mov reg(S_REG_OFFSET), 0x0000 ## Zero the offset register + or FL, 0b0000000000000010 ## Enable offset mode for memory addressing + mov FL, ACC + %low INST_BIOS_NODE_TOGGLE 0x00 ## Disable BIOS Mode before leaving the BIOS jmp MemoryAddresses.MBR ## Jump to start of MBR in memory hlt ## Just in case somehow execution reaches this point diff --git a/extra/dss/drake/bootsector.dss b/extra/dss/drake/bootsector.dss index 15ba6b5..8a32f4b 100644 --- a/extra/dss/drake/bootsector.dss +++ b/extra/dss/drake/bootsector.dss @@ -1,4 +1,4 @@ -.load [dynamic] +.load [dynamic, base=0x1740] .data $string "Hello BOOTSECTOR!!" diff --git a/src/debugger/Debugger.cpp b/src/debugger/Debugger.cpp index aaa9200..e3849d4 100644 --- a/src/debugger/Debugger.cpp +++ b/src/debugger/Debugger.cpp @@ -285,7 +285,7 @@ namespace dragon str.add("\n"); str.add("|---------------|------------------------------------|------------------------------------|-----|-----------|-----------|"); str.add("\n"); - str.add("| FL: |*%PREV_FL%**************************|**%CURR_FL%*************************| S3 |*%PREV_S3%*|*%CURR_S3%*|"); + str.add("| FL: |*%PREV_FL%**************************|**%CURR_FL%*************************| OF |*%PREV_OF%*|*%CURR_OF%*|"); str.add("\n"); str.add("|---------------|------------------------------------|------------------------------------|=====|===========|===========|"); str.add("\n"); @@ -833,28 +833,28 @@ namespace dragon tmp = " ", tmpStyle = ""; - tmp.add(ostd::Utils::getHexStr(minfo.previousInstructionRegisters[dragon::data::Registers::S3], true, 2)); + tmp.add(ostd::Utils::getHexStr(minfo.previousInstructionRegisters[dragon::data::Registers::OFFSET], true, 2)); tmp.addPadding(item_len, ' ', ostd::String::ePaddingBehavior::AllowOddExtraLeft); tmpStyle = "[@@style foreground:Blue]"; tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%PREV_S3%", tmpStyle); + str.replaceAll("%PREV_OF%", tmpStyle); tmp = " "; - tmp.add(ostd::Utils::getHexStr(minfo.currentInstructionRegisters[dragon::data::Registers::S3], true, 2)); + tmp.add(ostd::Utils::getHexStr(minfo.currentInstructionRegisters[dragon::data::Registers::OFFSET], true, 2)); tmp.addPadding(item_len, ' ', ostd::String::ePaddingBehavior::AllowOddExtraLeft); - if (minfo.currentInstructionRegisters[dragon::data::Registers::S3] != minfo.previousInstructionRegisters[dragon::data::Registers::S3]) + 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_S3%", tmpStyle); + 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|S3", "BrightRed"); + rgxstr.fg("S1|S2|OF", "BrightRed"); rgxstr.fg("PREV", "Red"); rgxstr.fg("CURR", "Green"); out.pStyled(rgxstr); diff --git a/src/hardware/VirtualCPU.cpp b/src/hardware/VirtualCPU.cpp index 2424a66..5847639 100644 --- a/src/hardware/VirtualCPU.cpp +++ b/src/hardware/VirtualCPU.cpp @@ -203,6 +203,11 @@ namespace dragon m_currentExtension = nullptr; m_currentExtInst = 0x00; m_isDebugBreakPoint = false; + m_isOffsetAddressingEnabled = readFlag(data::Flags::OffsetModeEnabled); + if (m_isOffsetAddressingEnabled) + m_currentOffset = readRegister(data::Registers::OFFSET); + else + m_currentOffset = 0x0000; uint8_t inst = fetch8(); m_currentInst = inst; if (loadExtension()) diff --git a/src/hardware/VirtualCPU.hpp b/src/hardware/VirtualCPU.hpp index c9d378c..2348a72 100644 --- a/src/hardware/VirtualCPU.hpp +++ b/src/hardware/VirtualCPU.hpp @@ -47,7 +47,9 @@ namespace dragon inline int32_t getSubRoutineCounter(void) const { return m_subroutineCounter; } inline data::CPUExtension* getCurrentCPUExtension(void) const { return m_currentExtension; } inline uint8_t getCurrentCPUExtensionInstruction(void) const { return m_currentExtInst; } - + inline bool isOffsetAddressingModeEnabled(void) const { return m_isOffsetAddressingEnabled; } + inline uint16_t getCurrentOffset(void) const { return m_currentOffset; } + private: void __debug_store_stack_frame_string_on_push(void); @@ -65,6 +67,9 @@ namespace dragon bool m_debugModeEnabled { false }; int32_t m_subroutineCounter { 0 }; + bool m_isOffsetAddressingEnabled { false }; + uint16_t m_currentOffset { 0x0000 }; + data::CPUExtension* m_extensions[16]; data::CPUExtension* m_currentExtension { nullptr }; uint8_t m_currentExtInst { 0x00 }; diff --git a/src/hardware/VirtualRAM.cpp b/src/hardware/VirtualRAM.cpp index 4bb212f..3c87002 100644 --- a/src/hardware/VirtualRAM.cpp +++ b/src/hardware/VirtualRAM.cpp @@ -1,6 +1,7 @@ #include "VirtualRAM.hpp" #include "../tools/GlobalData.hpp" +#include "../runtime/DragonRuntime.hpp" namespace dragon { @@ -14,26 +15,30 @@ namespace dragon int8_t VirtualRAM::read8(uint16_t addr) { int8_t outVal = 0; - if (!m_memory.r_Byte(addr, outVal)) return 0x00; //TODO: Error + uint16_t offset = DragonRuntime::cpu.getCurrentOffset(); + if (!m_memory.r_Byte(addr + offset, outVal)) return 0x00; //TODO: Error return outVal; } int16_t VirtualRAM::read16(uint16_t addr) { int16_t outVal = 0; - if (!m_memory.r_Word(addr, outVal)) return 0x00; //TODO: Error + uint16_t offset = DragonRuntime::cpu.getCurrentOffset(); + if (!m_memory.r_Word(addr + offset, outVal)) return 0x00; //TODO: Error return outVal; } int8_t VirtualRAM::write8(uint16_t addr, int8_t value) { - if (!m_memory.w_Byte(addr, value)) return 0; //TODO: Error + uint16_t offset = DragonRuntime::cpu.getCurrentOffset(); + if (!m_memory.w_Byte(addr + offset, value)) return 0; //TODO: Error return value; } int16_t VirtualRAM::write16(uint16_t addr, int16_t value) { - if (!m_memory.w_Word(addr, value)) return 0; //TODO: Error + uint16_t offset = DragonRuntime::cpu.getCurrentOffset(); + if (!m_memory.w_Word(addr + offset, value)) return 0; //TODO: Error return value; } diff --git a/src/tools/GlobalData.hpp b/src/tools/GlobalData.hpp index 7fa8b63..58e2f16 100644 --- a/src/tools/GlobalData.hpp +++ b/src/tools/GlobalData.hpp @@ -166,7 +166,7 @@ namespace dragon inline static constexpr uint8_t ACC = 0x06; inline static constexpr uint8_t S1 = 0x07; inline static constexpr uint8_t S2 = 0x08; - inline static constexpr uint8_t S3 = 0x09; + inline static constexpr uint8_t OFFSET = 0x09; inline static constexpr uint8_t R1 = 0x0A; inline static constexpr uint8_t R2 = 0x0B; inline static constexpr uint8_t R3 = 0x0C; @@ -185,6 +185,7 @@ namespace dragon { public: inline static constexpr uint8_t InterruptsEnabled = 0; + inline static constexpr uint8_t OffsetModeEnabled = 1; }; class InterruptCodes