rrcSmall/src/AnalysisState.cpp
DataHoarder 0caa10273e
All checks were successful
continuous-integration/drone/push Build is passing
Added interrupt handler known jump and parsing when found
2021-01-11 13:18:17 +01:00

89 lines
3.9 KiB
C++

/*****************************************************************************
* Copyright (c) 2020, rrcSmall FM10K-Documentation Contributors
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#include "AnalysisState.h"
#include "Registers.h"
uint32_t AnalysisState::getAddressOffset(uint8_t offsetEntry) const {
if (offsetEntry == 0) {
return 0;
}
return getRegister((uint32_t) KnownRegisters::BSM_ADDR_OFFSET_0 + offsetEntry);
}
uint32_t AnalysisState::getRegister(const Instruction::AddressWithOffset &address) const {
return getRegister(getAddressWithOffset(address));
}
void AnalysisState::setRegister(const Instruction::AddressWithOffset &address, uint32_t value) {
setRegister(getAddressWithOffset(address), value);
}
uint32_t AnalysisState::getAddressWithOffset(const Instruction::AddressWithOffset &address) const {
return address.address + getAddressOffset(address.offset);
}
uint32_t AnalysisState::getDefaultRegisterValue(uint32_t addr) {
if(addr == (uint32_t)KnownRegisters::SOFT_RESET){
return 0b0000000001111111110111;
}else if(addr == (uint32_t)KnownRegisters::DEVICE_CFG){
return 0b01111111110000000;
}else if(addr == (uint32_t)KnownRegisters::RESET_CFG){
return (0x40 << 8) | 0x10;
}else if(addr == (uint32_t)KnownRegisters::VITAL_PRODUCT_DATA){
return 0xAE21;
}else if(addr == (uint32_t)KnownRegisters::SRAM_ERR_IM_0){
return 0xFFFFFFFF;
}else if(addr == (uint32_t)KnownRegisters::SRAM_ERR_IM_1){
return 0x0000FFFF;
}else if(addr == (uint32_t)KnownRegisters::SW_IM){
return 0xFFFFFFFF;
}else if(addr == (uint32_t)KnownRegisters::CHIP_VERSION){
return 0x1;
}else if(addr == (uint32_t)KnownRegisters::REI_CTRL){
return 0b1;
}else if(addr == (uint32_t)KnownRegisters::GPIO_IM){
return 0xFFFFFFFF;
}else if(addr == (uint32_t)KnownRegisters::PLL_PCIE_CTRL){
return (0xA << 18) | (0x19 << 10) | (0x1 << 3) | 0b1;
}else if(addr == (uint32_t)KnownRegisters::SBUS_PCIE_CFG){
return 0b1;
}else if(addr == (uint32_t)KnownRegisters::SBUS_PCIE_IM){
return 0xFFFFFFFF;
}
return 0;
}
void AnalysisState::setRegister(uint32_t addr, uint32_t value) {
if(addr == (uint32_t)KnownRegisters::BSM_ARGS){
addKnownJump(value & 0xFFFFFF, current, JumpKind::Interrupt);
}
memory[addr] = value;
}