1*9c7fbc3fSMichał Górny //===-- RegisterContextFreeBSDKernel_i386.cpp -----------------------------===//
2*9c7fbc3fSMichał Górny //
3*9c7fbc3fSMichał Górny // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*9c7fbc3fSMichał Górny // See https://llvm.org/LICENSE.txt for license information.
5*9c7fbc3fSMichał Górny // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*9c7fbc3fSMichał Górny //
7*9c7fbc3fSMichał Górny //===----------------------------------------------------------------------===//
8*9c7fbc3fSMichał Górny 
9*9c7fbc3fSMichał Górny #include "RegisterContextFreeBSDKernel_i386.h"
10*9c7fbc3fSMichał Górny 
11*9c7fbc3fSMichał Górny #include "lldb/Target/Process.h"
12*9c7fbc3fSMichał Górny #include "lldb/Target/Thread.h"
13*9c7fbc3fSMichał Górny #include "lldb/Utility/RegisterValue.h"
14*9c7fbc3fSMichał Górny #include "llvm/Support/Endian.h"
15*9c7fbc3fSMichał Górny 
16*9c7fbc3fSMichał Górny using namespace lldb;
17*9c7fbc3fSMichał Górny using namespace lldb_private;
18*9c7fbc3fSMichał Górny 
RegisterContextFreeBSDKernel_i386(Thread & thread,RegisterInfoInterface * register_info,lldb::addr_t pcb_addr)19*9c7fbc3fSMichał Górny RegisterContextFreeBSDKernel_i386::RegisterContextFreeBSDKernel_i386(
20*9c7fbc3fSMichał Górny     Thread &thread, RegisterInfoInterface *register_info, lldb::addr_t pcb_addr)
21*9c7fbc3fSMichał Górny     : RegisterContextPOSIX_x86(thread, 0, register_info), m_pcb_addr(pcb_addr) {
22*9c7fbc3fSMichał Górny }
23*9c7fbc3fSMichał Górny 
ReadGPR()24*9c7fbc3fSMichał Górny bool RegisterContextFreeBSDKernel_i386::ReadGPR() { return true; }
25*9c7fbc3fSMichał Górny 
ReadFPR()26*9c7fbc3fSMichał Górny bool RegisterContextFreeBSDKernel_i386::ReadFPR() { return true; }
27*9c7fbc3fSMichał Górny 
WriteGPR()28*9c7fbc3fSMichał Górny bool RegisterContextFreeBSDKernel_i386::WriteGPR() {
29*9c7fbc3fSMichał Górny   assert(0);
30*9c7fbc3fSMichał Górny   return false;
31*9c7fbc3fSMichał Górny }
32*9c7fbc3fSMichał Górny 
WriteFPR()33*9c7fbc3fSMichał Górny bool RegisterContextFreeBSDKernel_i386::WriteFPR() {
34*9c7fbc3fSMichał Górny   assert(0);
35*9c7fbc3fSMichał Górny   return false;
36*9c7fbc3fSMichał Górny }
37*9c7fbc3fSMichał Górny 
ReadRegister(const RegisterInfo * reg_info,RegisterValue & value)38*9c7fbc3fSMichał Górny bool RegisterContextFreeBSDKernel_i386::ReadRegister(
39*9c7fbc3fSMichał Górny     const RegisterInfo *reg_info, RegisterValue &value) {
40*9c7fbc3fSMichał Górny   if (m_pcb_addr == LLDB_INVALID_ADDRESS)
41*9c7fbc3fSMichał Górny     return false;
42*9c7fbc3fSMichał Górny 
43*9c7fbc3fSMichał Górny   struct {
44*9c7fbc3fSMichał Górny     llvm::support::ulittle32_t edi;
45*9c7fbc3fSMichał Górny     llvm::support::ulittle32_t esi;
46*9c7fbc3fSMichał Górny     llvm::support::ulittle32_t ebp;
47*9c7fbc3fSMichał Górny     llvm::support::ulittle32_t esp;
48*9c7fbc3fSMichał Górny     llvm::support::ulittle32_t ebx;
49*9c7fbc3fSMichał Górny     llvm::support::ulittle32_t eip;
50*9c7fbc3fSMichał Górny   } pcb;
51*9c7fbc3fSMichał Górny 
52*9c7fbc3fSMichał Górny   Status error;
53*9c7fbc3fSMichał Górny   size_t rd =
54*9c7fbc3fSMichał Górny       m_thread.GetProcess()->ReadMemory(m_pcb_addr, &pcb, sizeof(pcb), error);
55*9c7fbc3fSMichał Górny   if (rd != sizeof(pcb))
56*9c7fbc3fSMichał Górny     return false;
57*9c7fbc3fSMichał Górny 
58*9c7fbc3fSMichał Górny   uint32_t reg = reg_info->kinds[lldb::eRegisterKindLLDB];
59*9c7fbc3fSMichał Górny   switch (reg) {
60*9c7fbc3fSMichał Górny #define REG(x)                                                                 \
61*9c7fbc3fSMichał Górny   case lldb_##x##_i386:                                                      \
62*9c7fbc3fSMichał Górny     value = pcb.x;                                                             \
63*9c7fbc3fSMichał Górny     break;
64*9c7fbc3fSMichał Górny 
65*9c7fbc3fSMichał Górny     REG(edi);
66*9c7fbc3fSMichał Górny     REG(esi);
67*9c7fbc3fSMichał Górny     REG(ebp);
68*9c7fbc3fSMichał Górny     REG(esp);
69*9c7fbc3fSMichał Górny     REG(eip);
70*9c7fbc3fSMichał Górny 
71*9c7fbc3fSMichał Górny #undef REG
72*9c7fbc3fSMichał Górny 
73*9c7fbc3fSMichał Górny   default:
74*9c7fbc3fSMichał Górny     return false;
75*9c7fbc3fSMichał Górny   }
76*9c7fbc3fSMichał Górny 
77*9c7fbc3fSMichał Górny   return true;
78*9c7fbc3fSMichał Górny }
79*9c7fbc3fSMichał Górny 
WriteRegister(const RegisterInfo * reg_info,const RegisterValue & value)80*9c7fbc3fSMichał Górny bool RegisterContextFreeBSDKernel_i386::WriteRegister(
81*9c7fbc3fSMichał Górny     const RegisterInfo *reg_info, const RegisterValue &value) {
82*9c7fbc3fSMichał Górny   return false;
83*9c7fbc3fSMichał Górny }
84