xref: /openbsd-src/gnu/llvm/lldb/tools/debugserver/source/DNBArch.cpp (revision 46035553bfdd96e63c94e32da0210227ec2e3cf1)
1 //===-- DNBArch.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 //  Created by Greg Clayton on 6/24/07.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "DNBArch.h"
14 #include <assert.h>
15 #include <mach/mach.h>
16 
17 #include <map>
18 
19 #include "DNBLog.h"
20 
21 typedef std::map<uint32_t, DNBArchPluginInfo> CPUPluginInfoMap;
22 
23 static uint32_t g_current_cpu_type = 0;
24 CPUPluginInfoMap g_arch_plugins;
25 
26 static const DNBArchPluginInfo *GetArchInfo() {
27   CPUPluginInfoMap::const_iterator pos =
28       g_arch_plugins.find(g_current_cpu_type);
29   if (pos != g_arch_plugins.end())
30     return &pos->second;
31   return NULL;
32 }
33 
34 uint32_t DNBArchProtocol::GetArchitecture() { return g_current_cpu_type; }
35 
36 bool DNBArchProtocol::SetArchitecture(uint32_t cpu_type) {
37   g_current_cpu_type = cpu_type;
38   bool result = g_arch_plugins.find(g_current_cpu_type) != g_arch_plugins.end();
39   DNBLogThreadedIf(
40       LOG_PROCESS,
41       "DNBArchProtocol::SetDefaultArchitecture (cpu_type=0x%8.8x) => %i",
42       cpu_type, result);
43   return result;
44 }
45 
46 void DNBArchProtocol::RegisterArchPlugin(const DNBArchPluginInfo &arch_info) {
47   if (arch_info.cpu_type)
48     g_arch_plugins[arch_info.cpu_type] = arch_info;
49 }
50 
51 uint32_t DNBArchProtocol::GetRegisterCPUType() {
52   const DNBArchPluginInfo *arch_info = GetArchInfo();
53   if (arch_info)
54     return arch_info->cpu_type;
55   return 0;
56 }
57 
58 const DNBRegisterSetInfo *
59 DNBArchProtocol::GetRegisterSetInfo(nub_size_t *num_reg_sets) {
60   const DNBArchPluginInfo *arch_info = GetArchInfo();
61   if (arch_info)
62     return arch_info->GetRegisterSetInfo(num_reg_sets);
63   *num_reg_sets = 0;
64   return NULL;
65 }
66 
67 DNBArchProtocol *DNBArchProtocol::Create(MachThread *thread) {
68   const DNBArchPluginInfo *arch_info = GetArchInfo();
69   if (arch_info)
70     return arch_info->Create(thread);
71   return NULL;
72 }
73 
74 const uint8_t *DNBArchProtocol::GetBreakpointOpcode(nub_size_t byte_size) {
75   const DNBArchPluginInfo *arch_info = GetArchInfo();
76   if (arch_info)
77     return arch_info->GetBreakpointOpcode(byte_size);
78   return NULL;
79 }
80