1 //===-- NativeRegisterContextLinux_mips64.h ---------------------*- C++ -*-===//
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 #if defined(__mips__)
10 
11 #ifndef lldb_NativeRegisterContextLinux_mips64_h
12 #define lldb_NativeRegisterContextLinux_mips64_h
13 
14 #include "Plugins/Process/Linux/NativeRegisterContextLinux.h"
15 #include "Plugins/Process/Utility/RegisterContext_mips.h"
16 #include "Plugins/Process/Utility/lldb-mips-linux-register-enums.h"
17 #include <sys/uio.h>
18 
19 #define MAX_NUM_WP 8
20 
21 namespace lldb_private {
22 namespace process_linux {
23 
24 class NativeProcessLinux;
25 
26 class NativeRegisterContextLinux_mips64 : public NativeRegisterContextLinux {
27 public:
28   NativeRegisterContextLinux_mips64(const ArchSpec &target_arch,
29                                     NativeThreadProtocol &native_thread);
30 
31   uint32_t GetRegisterSetCount() const override;
32 
33   lldb::addr_t GetPCfromBreakpointLocation(
34       lldb::addr_t fail_value = LLDB_INVALID_ADDRESS) override;
35 
36   lldb::addr_t GetWatchpointHitAddress(uint32_t wp_index) override;
37 
38   const RegisterSet *GetRegisterSet(uint32_t set_index) const override;
39 
40   Status ReadRegister(const RegisterInfo *reg_info,
41                       RegisterValue &reg_value) override;
42 
43   Status WriteRegister(const RegisterInfo *reg_info,
44                        const RegisterValue &reg_value) override;
45 
46   Status ReadAllRegisterValues(lldb::DataBufferSP &data_sp) override;
47 
48   Status WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) override;
49 
50   Status ReadCP1();
51 
52   Status WriteCP1();
53 
54   uint8_t *ReturnFPOffset(uint8_t reg_index, uint32_t byte_offset);
55 
56   Status IsWatchpointHit(uint32_t wp_index, bool &is_hit) override;
57 
58   Status GetWatchpointHitIndex(uint32_t &wp_index,
59                                lldb::addr_t trap_addr) override;
60 
61   Status IsWatchpointVacant(uint32_t wp_index, bool &is_vacant) override;
62 
63   bool ClearHardwareWatchpoint(uint32_t wp_index) override;
64 
65   Status ClearAllHardwareWatchpoints() override;
66 
67   Status SetHardwareWatchpointWithIndex(lldb::addr_t addr, size_t size,
68                                         uint32_t watch_flags,
69                                         uint32_t wp_index);
70 
71   uint32_t SetHardwareWatchpoint(lldb::addr_t addr, size_t size,
72                                  uint32_t watch_flags) override;
73 
74   lldb::addr_t GetWatchpointAddress(uint32_t wp_index) override;
75 
76   uint32_t NumSupportedHardwareWatchpoints() override;
77 
78   static bool IsMSAAvailable();
79 
80 protected:
81   Status Read_SR_Config(uint32_t offset, const char *reg_name, uint32_t size,
82                         RegisterValue &value);
83 
84   Status ReadRegisterRaw(uint32_t reg_index, RegisterValue &value) override;
85 
86   Status WriteRegisterRaw(uint32_t reg_index,
87                           const RegisterValue &value) override;
88 
89   Status DoReadWatchPointRegisterValue(lldb::tid_t tid, void *watch_readback);
90 
91   Status DoWriteWatchPointRegisterValue(lldb::tid_t tid, void *watch_readback);
92 
93   bool IsFR0();
94 
95   bool IsFRE();
96 
97   bool IsFPR(uint32_t reg_index) const;
98 
99   bool IsMSA(uint32_t reg_index) const;
100 
GetGPRBuffer()101   void *GetGPRBuffer() override { return &m_gpr; }
102 
GetFPRBuffer()103   void *GetFPRBuffer() override { return &m_fpr; }
104 
GetFPRSize()105   size_t GetFPRSize() override { return sizeof(FPR_linux_mips); }
106 
107 private:
108   // Info about register ranges.
109   struct RegInfo {
110     uint32_t num_registers;
111     uint32_t num_gpr_registers;
112     uint32_t num_fpr_registers;
113 
114     uint32_t last_gpr;
115     uint32_t first_fpr;
116     uint32_t last_fpr;
117     uint32_t first_msa;
118     uint32_t last_msa;
119   };
120 
121   RegInfo m_reg_info;
122 
123   GPR_linux_mips m_gpr;
124 
125   FPR_linux_mips m_fpr;
126 
127   MSA_linux_mips m_msa;
128 
129   lldb::addr_t hw_addr_map[MAX_NUM_WP];
130 
131   struct iovec m_iovec;
132 };
133 
134 } // namespace process_linux
135 } // namespace lldb_private
136 
137 #endif // #ifndef lldb_NativeRegisterContextLinux_mips64_h
138 
139 #endif // defined (__mips__)
140