180814287SRaphael Isemann //===-- RegisterContextKDP_arm64.cpp --------------------------------------===//
2a332978bSJason Molenda //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6a332978bSJason Molenda //
7a332978bSJason Molenda //===----------------------------------------------------------------------===//
8a332978bSJason Molenda 
9a332978bSJason Molenda #include "RegisterContextKDP_arm64.h"
10a332978bSJason Molenda 
11a332978bSJason Molenda #include "ProcessKDP.h"
12a332978bSJason Molenda #include "ThreadKDP.h"
13a332978bSJason Molenda 
14a332978bSJason Molenda using namespace lldb;
15a332978bSJason Molenda using namespace lldb_private;
16a332978bSJason Molenda 
RegisterContextKDP_arm64(ThreadKDP & thread,uint32_t concrete_frame_idx)17b9c1b51eSKate Stone RegisterContextKDP_arm64::RegisterContextKDP_arm64(ThreadKDP &thread,
18b9c1b51eSKate Stone                                                    uint32_t concrete_frame_idx)
19b9c1b51eSKate Stone     : RegisterContextDarwin_arm64(thread, concrete_frame_idx),
20b9c1b51eSKate Stone       m_kdp_thread(thread) {}
21a332978bSJason Molenda 
22*fd2433e1SJonas Devlieghere RegisterContextKDP_arm64::~RegisterContextKDP_arm64() = default;
23a332978bSJason Molenda 
DoReadGPR(lldb::tid_t tid,int flavor,GPR & gpr)24b9c1b51eSKate Stone int RegisterContextKDP_arm64::DoReadGPR(lldb::tid_t tid, int flavor, GPR &gpr) {
25a332978bSJason Molenda   ProcessSP process_sp(CalculateProcess());
26b9c1b51eSKate Stone   if (process_sp) {
2797206d57SZachary Turner     Status error;
28b9c1b51eSKate Stone     if (static_cast<ProcessKDP *>(process_sp.get())
29b9c1b51eSKate Stone             ->GetCommunication()
30b9c1b51eSKate Stone             .SendRequestReadRegisters(tid, GPRRegSet, &gpr, sizeof(gpr),
31b9c1b51eSKate Stone                                       error)) {
32a332978bSJason Molenda       if (error.Success())
33a332978bSJason Molenda         return 0;
34a332978bSJason Molenda     }
35a332978bSJason Molenda   }
36a332978bSJason Molenda   return -1;
37a332978bSJason Molenda }
38a332978bSJason Molenda 
DoReadFPU(lldb::tid_t tid,int flavor,FPU & fpu)39b9c1b51eSKate Stone int RegisterContextKDP_arm64::DoReadFPU(lldb::tid_t tid, int flavor, FPU &fpu) {
40a332978bSJason Molenda   ProcessSP process_sp(CalculateProcess());
41b9c1b51eSKate Stone   if (process_sp) {
4297206d57SZachary Turner     Status error;
43b9c1b51eSKate Stone     if (static_cast<ProcessKDP *>(process_sp.get())
44b9c1b51eSKate Stone             ->GetCommunication()
45b9c1b51eSKate Stone             .SendRequestReadRegisters(tid, FPURegSet, &fpu, sizeof(fpu),
46b9c1b51eSKate Stone                                       error)) {
47a332978bSJason Molenda       if (error.Success())
48a332978bSJason Molenda         return 0;
49a332978bSJason Molenda     }
50a332978bSJason Molenda   }
51a332978bSJason Molenda   return -1;
52a332978bSJason Molenda }
53a332978bSJason Molenda 
DoReadEXC(lldb::tid_t tid,int flavor,EXC & exc)54b9c1b51eSKate Stone int RegisterContextKDP_arm64::DoReadEXC(lldb::tid_t tid, int flavor, EXC &exc) {
55a332978bSJason Molenda   ProcessSP process_sp(CalculateProcess());
56b9c1b51eSKate Stone   if (process_sp) {
5797206d57SZachary Turner     Status error;
58b9c1b51eSKate Stone     if (static_cast<ProcessKDP *>(process_sp.get())
59b9c1b51eSKate Stone             ->GetCommunication()
60b9c1b51eSKate Stone             .SendRequestReadRegisters(tid, EXCRegSet, &exc, sizeof(exc),
61b9c1b51eSKate Stone                                       error)) {
62a332978bSJason Molenda       if (error.Success())
63a332978bSJason Molenda         return 0;
64a332978bSJason Molenda     }
65a332978bSJason Molenda   }
66a332978bSJason Molenda   return -1;
67a332978bSJason Molenda }
68a332978bSJason Molenda 
DoReadDBG(lldb::tid_t tid,int flavor,DBG & dbg)69b9c1b51eSKate Stone int RegisterContextKDP_arm64::DoReadDBG(lldb::tid_t tid, int flavor, DBG &dbg) {
70a332978bSJason Molenda   ProcessSP process_sp(CalculateProcess());
71b9c1b51eSKate Stone   if (process_sp) {
7297206d57SZachary Turner     Status error;
73b9c1b51eSKate Stone     if (static_cast<ProcessKDP *>(process_sp.get())
74b9c1b51eSKate Stone             ->GetCommunication()
75b9c1b51eSKate Stone             .SendRequestReadRegisters(tid, DBGRegSet, &dbg, sizeof(dbg),
76b9c1b51eSKate Stone                                       error)) {
77a332978bSJason Molenda       if (error.Success())
78a332978bSJason Molenda         return 0;
79a332978bSJason Molenda     }
80a332978bSJason Molenda   }
81a332978bSJason Molenda   return -1;
82a332978bSJason Molenda }
83a332978bSJason Molenda 
DoWriteGPR(lldb::tid_t tid,int flavor,const GPR & gpr)84b9c1b51eSKate Stone int RegisterContextKDP_arm64::DoWriteGPR(lldb::tid_t tid, int flavor,
85b9c1b51eSKate Stone                                          const GPR &gpr) {
86a332978bSJason Molenda   ProcessSP process_sp(CalculateProcess());
87b9c1b51eSKate Stone   if (process_sp) {
8897206d57SZachary Turner     Status error;
89b9c1b51eSKate Stone     if (static_cast<ProcessKDP *>(process_sp.get())
90b9c1b51eSKate Stone             ->GetCommunication()
91b9c1b51eSKate Stone             .SendRequestWriteRegisters(tid, GPRRegSet, &gpr, sizeof(gpr),
92b9c1b51eSKate Stone                                        error)) {
93a332978bSJason Molenda       if (error.Success())
94a332978bSJason Molenda         return 0;
95a332978bSJason Molenda     }
96a332978bSJason Molenda   }
97a332978bSJason Molenda   return -1;
98a332978bSJason Molenda }
99a332978bSJason Molenda 
DoWriteFPU(lldb::tid_t tid,int flavor,const FPU & fpu)100b9c1b51eSKate Stone int RegisterContextKDP_arm64::DoWriteFPU(lldb::tid_t tid, int flavor,
101b9c1b51eSKate Stone                                          const FPU &fpu) {
102a332978bSJason Molenda   ProcessSP process_sp(CalculateProcess());
103b9c1b51eSKate Stone   if (process_sp) {
10497206d57SZachary Turner     Status error;
105b9c1b51eSKate Stone     if (static_cast<ProcessKDP *>(process_sp.get())
106b9c1b51eSKate Stone             ->GetCommunication()
107b9c1b51eSKate Stone             .SendRequestWriteRegisters(tid, FPURegSet, &fpu, sizeof(fpu),
108b9c1b51eSKate Stone                                        error)) {
109a332978bSJason Molenda       if (error.Success())
110a332978bSJason Molenda         return 0;
111a332978bSJason Molenda     }
112a332978bSJason Molenda   }
113a332978bSJason Molenda   return -1;
114a332978bSJason Molenda }
115a332978bSJason Molenda 
DoWriteEXC(lldb::tid_t tid,int flavor,const EXC & exc)116b9c1b51eSKate Stone int RegisterContextKDP_arm64::DoWriteEXC(lldb::tid_t tid, int flavor,
117b9c1b51eSKate Stone                                          const EXC &exc) {
118a332978bSJason Molenda   ProcessSP process_sp(CalculateProcess());
119b9c1b51eSKate Stone   if (process_sp) {
12097206d57SZachary Turner     Status error;
121b9c1b51eSKate Stone     if (static_cast<ProcessKDP *>(process_sp.get())
122b9c1b51eSKate Stone             ->GetCommunication()
123b9c1b51eSKate Stone             .SendRequestWriteRegisters(tid, EXCRegSet, &exc, sizeof(exc),
124b9c1b51eSKate Stone                                        error)) {
125a332978bSJason Molenda       if (error.Success())
126a332978bSJason Molenda         return 0;
127a332978bSJason Molenda     }
128a332978bSJason Molenda   }
129a332978bSJason Molenda   return -1;
130a332978bSJason Molenda }
131a332978bSJason Molenda 
DoWriteDBG(lldb::tid_t tid,int flavor,const DBG & dbg)132b9c1b51eSKate Stone int RegisterContextKDP_arm64::DoWriteDBG(lldb::tid_t tid, int flavor,
133b9c1b51eSKate Stone                                          const DBG &dbg) {
134a332978bSJason Molenda   ProcessSP process_sp(CalculateProcess());
135b9c1b51eSKate Stone   if (process_sp) {
13697206d57SZachary Turner     Status error;
137b9c1b51eSKate Stone     if (static_cast<ProcessKDP *>(process_sp.get())
138b9c1b51eSKate Stone             ->GetCommunication()
139b9c1b51eSKate Stone             .SendRequestWriteRegisters(tid, DBGRegSet, &dbg, sizeof(dbg),
140b9c1b51eSKate Stone                                        error)) {
141a332978bSJason Molenda       if (error.Success())
142a332978bSJason Molenda         return 0;
143a332978bSJason Molenda     }
144a332978bSJason Molenda   }
145a332978bSJason Molenda   return -1;
146a332978bSJason Molenda }
147