1 //===-- ArchitecturePPC64.cpp -----------------------------------*- 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 #include "Plugins/Architecture/PPC64/ArchitecturePPC64.h"
10 #include "lldb/Core/PluginManager.h"
11 #include "lldb/Symbol/Function.h"
12 #include "lldb/Symbol/Symbol.h"
13 #include "lldb/Target/RegisterContext.h"
14 #include "lldb/Target/Target.h"
15 #include "lldb/Target/Thread.h"
16 #include "lldb/Utility/ArchSpec.h"
17 
18 #include "llvm/BinaryFormat/ELF.h"
19 
20 using namespace lldb_private;
21 using namespace lldb;
22 
23 ConstString ArchitecturePPC64::GetPluginNameStatic() {
24   return ConstString("ppc64");
25 }
26 
27 void ArchitecturePPC64::Initialize() {
28   PluginManager::RegisterPlugin(GetPluginNameStatic(),
29                                 "PPC64-specific algorithms",
30                                 &ArchitecturePPC64::Create);
31 }
32 
33 void ArchitecturePPC64::Terminate() {
34   PluginManager::UnregisterPlugin(&ArchitecturePPC64::Create);
35 }
36 
37 std::unique_ptr<Architecture> ArchitecturePPC64::Create(const ArchSpec &arch) {
38   if (arch.GetTriple().isPPC64() &&
39       arch.GetTriple().getObjectFormat() == llvm::Triple::ObjectFormatType::ELF)
40     return std::unique_ptr<Architecture>(new ArchitecturePPC64());
41   return nullptr;
42 }
43 
44 ConstString ArchitecturePPC64::GetPluginName() { return GetPluginNameStatic(); }
45 uint32_t ArchitecturePPC64::GetPluginVersion() { return 1; }
46 
47 static int32_t GetLocalEntryOffset(const Symbol &sym) {
48   unsigned char other = sym.GetFlags() >> 8 & 0xFF;
49   return llvm::ELF::decodePPC64LocalEntryOffset(other);
50 }
51 
52 size_t ArchitecturePPC64::GetBytesToSkip(Symbol &func,
53                                          const Address &curr_addr) const {
54   if (curr_addr.GetFileAddress() ==
55       func.GetFileAddress() + GetLocalEntryOffset(func))
56     return func.GetPrologueByteSize();
57   return 0;
58 }
59 
60 void ArchitecturePPC64::AdjustBreakpointAddress(const Symbol &func,
61                                                 Address &addr) const {
62   int32_t loffs = GetLocalEntryOffset(func);
63   if (!loffs)
64     return;
65 
66   addr.SetOffset(addr.GetOffset() + loffs);
67 }
68