| 1 | //===-- NativeRegisterContextDBReg_loongarch.cpp --------------------------===// |
|---|---|
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "NativeRegisterContextDBReg_loongarch.h" |
| 10 | |
| 11 | #include "lldb/Utility/LLDBLog.h" |
| 12 | #include "lldb/Utility/Log.h" |
| 13 | #include "lldb/Utility/RegisterValue.h" |
| 14 | |
| 15 | using namespace lldb_private; |
| 16 | |
| 17 | uint32_t |
| 18 | NativeRegisterContextDBReg_loongarch::GetWatchpointSize(uint32_t wp_index) { |
| 19 | Log *log = GetLog(mask: LLDBLog::Watchpoints); |
| 20 | LLDB_LOG(log, "wp_index: {0}", wp_index); |
| 21 | |
| 22 | switch ((m_hwp_regs[wp_index].control >> 10) & 0x3) { |
| 23 | case 0x0: |
| 24 | return 8; |
| 25 | case 0x1: |
| 26 | return 4; |
| 27 | case 0x2: |
| 28 | return 2; |
| 29 | case 0x3: |
| 30 | return 1; |
| 31 | default: |
| 32 | return 0; |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | std::optional<NativeRegisterContextDBReg::WatchpointDetails> |
| 37 | NativeRegisterContextDBReg_loongarch::AdjustWatchpoint( |
| 38 | const WatchpointDetails &details) { |
| 39 | // LoongArch only needs to check the size; it does not need to check the |
| 40 | // address. |
| 41 | size_t size = details.size; |
| 42 | if (size != 1 && size != 2 && size != 4 && size != 8) |
| 43 | return std::nullopt; |
| 44 | |
| 45 | return details; |
| 46 | } |
| 47 | |
| 48 | uint32_t |
| 49 | NativeRegisterContextDBReg_loongarch::MakeBreakControlValue(size_t size) { |
| 50 | // Return encoded hardware breakpoint control value. |
| 51 | return m_hw_dbg_enable_bit; |
| 52 | } |
| 53 | |
| 54 | uint32_t NativeRegisterContextDBReg_loongarch::MakeWatchControlValue( |
| 55 | size_t size, uint32_t watch_flags) { |
| 56 | // Encoding hardware watchpoint control value. |
| 57 | // Size encoded: |
| 58 | // case 1 : 0b11 |
| 59 | // case 2 : 0b10 |
| 60 | // case 4 : 0b01 |
| 61 | // case 8 : 0b00 |
| 62 | size_t encoded_size = (3 - llvm::Log2_32(Value: size)) << 10; |
| 63 | |
| 64 | return m_hw_dbg_enable_bit | encoded_size | (watch_flags << 8); |
| 65 | } |
| 66 |
