-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TODO: dispatch functions should afftect the simulator. TODO: Fill in test stubs. TODO: Document. Fixes #17.
- Loading branch information
Sarah Mount
committed
Aug 17, 2016
1 parent
7ce57f2
commit 493c5ae
Showing
12 changed files
with
625 additions
and
7 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from revelation.isa import decode | ||
|
||
BKPT16 = 0b0000000111000010 | ||
NOP16 = 0b0000000110100010 | ||
|
||
|
||
class BreakPointManager(object): | ||
"""Manage breakpoints during GDB execution. | ||
""" | ||
|
||
def __init__(self, simulator): | ||
self.target = simulator | ||
self.breakpoints = {} # Address -> (opcode, size in bytes) | ||
|
||
def _get_global_address(self, address, coreid=0x808): | ||
"""Remap any local addresses to global address. | ||
""" | ||
if (address >> 20) == 0x0: | ||
return (coreid << 20) | address | ||
return address | ||
|
||
def is_breakpoint_set(self, address): | ||
return address in self.breakpoints | ||
|
||
def set_breakpoint(self, address, coreid=0x080): | ||
"""Set a breakpoint at a given address. | ||
1. Read 32 bit current instructions at address, save in dictionary. | ||
2. If current instruction is 16 bit, replace with bkpt16. | ||
3. If current instruction is 32 bit, replace with bkpt16, nop16. | ||
""" | ||
global_address = self._get_global_address(address, coreid) | ||
opcode = self.target.memory.iread(global_address, 4) | ||
mnemonic, _ = decode(opcode) | ||
if mnemonic.endswith('16'): | ||
self.breakpoints[global_address] = (opcode & 0xffff, 2) | ||
self.target.memory.write(global_address, 2, BKPT16) | ||
else: | ||
self.breakpoints[global_address] = (opcode, 4) | ||
self.target.memory.write(global_address, 2, BKPT16) | ||
self.target.memory.write(global_address + 2, 2, NOP16) | ||
|
||
def remove_breakpoint(self, address, coreid=0x808): | ||
"""Remove a breakpoint at a given address.""" | ||
global_address = self._get_global_address(address, coreid) | ||
opcode, size = self.breakpoints[global_address] | ||
self.target.memory.write(global_address, size, opcode) |
Oops, something went wrong.