1 //===-- DNBArch.cpp ---------------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // Created by Greg Clayton on 6/24/07.
11 //===----------------------------------------------------------------------===//
15 #include <mach/mach.h>
21 typedef std::map
<uint32_t, DNBArchPluginInfo
> CPUPluginInfoMap
;
23 static uint32_t g_current_cpu_type
= 0;
24 static uint32_t g_current_cpu_subtype
= 0;
25 CPUPluginInfoMap g_arch_plugins
;
27 static const DNBArchPluginInfo
*GetArchInfo() {
28 CPUPluginInfoMap::const_iterator pos
=
29 g_arch_plugins
.find(g_current_cpu_type
);
30 if (pos
!= g_arch_plugins
.end())
35 uint32_t DNBArchProtocol::GetCPUType() { return g_current_cpu_type
; }
36 uint32_t DNBArchProtocol::GetCPUSubType() { return g_current_cpu_subtype
; }
38 bool DNBArchProtocol::SetArchitecture(uint32_t cpu_type
, uint32_t cpu_subtype
) {
39 g_current_cpu_type
= cpu_type
;
40 g_current_cpu_subtype
= cpu_subtype
;
41 bool result
= g_arch_plugins
.find(g_current_cpu_type
) != g_arch_plugins
.end();
42 DNBLogThreadedIf(LOG_PROCESS
,
43 "DNBArchProtocol::SetDefaultArchitecture (cpu_type=0x%8.8x, "
44 "cpu_subtype=0x%8.8x) => %i",
45 cpu_type
, cpu_subtype
, result
);
49 void DNBArchProtocol::RegisterArchPlugin(const DNBArchPluginInfo
&arch_info
) {
50 if (arch_info
.cpu_type
)
51 g_arch_plugins
[arch_info
.cpu_type
] = arch_info
;
54 uint32_t DNBArchProtocol::GetRegisterCPUType() {
55 const DNBArchPluginInfo
*arch_info
= GetArchInfo();
57 return arch_info
->cpu_type
;
61 const DNBRegisterSetInfo
*
62 DNBArchProtocol::GetRegisterSetInfo(nub_size_t
*num_reg_sets
) {
63 const DNBArchPluginInfo
*arch_info
= GetArchInfo();
65 return arch_info
->GetRegisterSetInfo(num_reg_sets
);
70 DNBArchProtocol
*DNBArchProtocol::Create(MachThread
*thread
) {
71 const DNBArchPluginInfo
*arch_info
= GetArchInfo();
73 return arch_info
->Create(thread
);
77 const uint8_t *DNBArchProtocol::GetBreakpointOpcode(nub_size_t byte_size
) {
78 const DNBArchPluginInfo
*arch_info
= GetArchInfo();
80 return arch_info
->GetBreakpointOpcode(byte_size
);