1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-12-28 13:16:02 +00:00
Atmosphere/thermosphere/src/hvisor_hw_breakpoint_manager.cpp
2021-02-19 21:52:24 +00:00

63 lines
1.8 KiB
C++

/*
* Copyright (c) 2019-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "hvisor_hw_breakpoint_manager.hpp"
#include "cpu/hvisor_cpu_instructions.hpp"
#define _REENT_ONLY
#include <cerrno>
namespace ams::hvisor {
HwBreakpointManager HwBreakpointManager::instance{};
void HwBreakpointManager::Reload() const
{
// TODO
}
bool HwBreakpointManager::FindPredicate(const cpu::DebugRegisterPair &pair, uintptr_t addr, size_t, cpu::DebugRegisterPair::LoadStoreControl) const
{
return pair.vr == addr;
}
// Note: A32/T32/T16 support intentionnally left out
// Note: addresses are supposed to be well-formed regarding the sign extension bits
int HwBreakpointManager::Add(uintptr_t addr)
{
// Reject misaligned addresses
if (addr & 3) {
return -EINVAL;
}
cpu::DebugRegisterPair bp{};
bp.cr.bt = cpu::DebugRegisterPair::AddressMatch;
bp.cr.bas = 0xF; // mandated
bp.vr = addr;
return AddImpl(addr, 0, bp);
}
int HwBreakpointManager::Remove(uintptr_t addr)
{
// Reject misaligned addresses
if (addr & 3) {
return -EINVAL;
}
return RemoveImpl(addr, 0, cpu::DebugRegisterPair::NotAWatchpoint);
}
}