From 552d95f9e0f414fd04d7d1e40cf0f32079c5228a Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Thu, 4 Jul 2013 12:12:44 -0400 Subject: [PATCH] breakpoint code --- bin/debugger.cpp | 121 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) diff --git a/bin/debugger.cpp b/bin/debugger.cpp index 05d46e4..8acf9f7 100644 --- a/bin/debugger.cpp +++ b/bin/debugger.cpp @@ -6,7 +6,10 @@ #include #include +#include #include +#include + #include #include @@ -22,6 +25,124 @@ #include #include +bool ParseLine(const char *iter, Command *command); + +extern "C" { + + // any reason to have enable/disable flag + // vs deleting it? + std::unordered_map tbrkMap; + + std::unordered_map brkMap; + std::array brkPageMap; // bloom filter on a page-level. + + void tbrkAdd(uint16_t tool) + { + auto iter = tbrkMap.find(tool); + if (iter == tbrkMap.end()) + { + tbrkMap.emplace(tool, true); + } + } + + void tbrkRemove(uint16_t tool) + { + auto iter = tbrkMap.find(tool); + if (iter == tbrkMap.end()) return; + + tbrkMap.erase(iter); + } + + void tbrkRemoveAll() + { + tbrkMap.clear(); + } + + bool tbrkLookup(uint16_t tool) + { + if ((tool & 0xf000) != 0xa000) return false; + + return tbrkMap.find(tool) != tbrkMap.end(); + } + + + void brkRemoveAll() + { + brkPageMap.fill(0); + brkMap.clear(); + } + + void brkRemove(uint32_t address) + { + uint32_t page = address >> 12; + if (page >= brkPageMap.size()) return; + + auto iter = brkMap.find(address); + if (iter == brkMap.end()) + return; + + brkPageMap[page]--; + brkMap.erase(iter); + } + + void brkAdd(uint32_t address) + { + uint32_t page = address >> 12; + if (page >= brkPageMap.size()) return; + + auto iter = brkMap.find(address); + if (iter == brkMap.end()) + { + brkPageMap[page]++; + brkMap.emplace(address, 0); + } + + } + + bool brkLookup(uint32_t address) + { + uint32_t page = address >> 12; + if (page >= brkPageMap.size()) return false; + + if (!brkPageMap[page]) return false; + + return brkMap.find(address) != brkMap.end(); + } + + uint32_t debuggerReadLong(uint32_t address) + { + uint32_t tmp = 0; + for (unsigned i = 0; i < 4; ++i) + { + if (address < Flags.memorySize) + tmp = (tmp << 8) + Flags.memory[address++]; + } + + return tmp; + } + + uint16_t debuggerReadWord(uint32_t address) + { + uint16_t tmp = 0; + for (unsigned i = 0; i < 2; ++i) + { + if (address < Flags.memorySize) + tmp = (tmp << 8) + Flags.memory[address++]; + } + + return tmp; + } + + uint8_t debuggerReadByte(uint32_t address) + { + if (address < Flags.memorySize) + return Flags.memory[address]; + + return 0; + } + +} + namespace { void hexdump(const uint8_t *data, ssize_t size, uint32_t address = 0)