| 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 <cassert> |
| 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 | static uint32_t g_current_cpu_subtype = 0; |
| 25 | CPUPluginInfoMap g_arch_plugins; |
| 26 | |
| 27 | static const DNBArchPluginInfo *GetArchInfo() { |
| 28 | CPUPluginInfoMap::const_iterator pos = |
| 29 | g_arch_plugins.find(x: g_current_cpu_type); |
| 30 | if (pos != g_arch_plugins.end()) |
| 31 | return &pos->second; |
| 32 | return NULL; |
| 33 | } |
| 34 | |
| 35 | uint32_t DNBArchProtocol::GetCPUType() { return g_current_cpu_type; } |
| 36 | uint32_t DNBArchProtocol::GetCPUSubType() { return g_current_cpu_subtype; } |
| 37 | |
| 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(x: 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); |
| 46 | return result; |
| 47 | } |
| 48 | |
| 49 | void DNBArchProtocol::RegisterArchPlugin(const DNBArchPluginInfo &arch_info) { |
| 50 | if (arch_info.cpu_type) |
| 51 | g_arch_plugins[arch_info.cpu_type] = arch_info; |
| 52 | } |
| 53 | |
| 54 | uint32_t DNBArchProtocol::GetRegisterCPUType() { |
| 55 | const DNBArchPluginInfo *arch_info = GetArchInfo(); |
| 56 | if (arch_info) |
| 57 | return arch_info->cpu_type; |
| 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | const DNBRegisterSetInfo * |
| 62 | DNBArchProtocol::GetRegisterSetInfo(nub_size_t *num_reg_sets) { |
| 63 | const DNBArchPluginInfo *arch_info = GetArchInfo(); |
| 64 | if (arch_info) |
| 65 | return arch_info->GetRegisterSetInfo(num_reg_sets); |
| 66 | *num_reg_sets = 0; |
| 67 | return NULL; |
| 68 | } |
| 69 | |
| 70 | DNBArchProtocol *DNBArchProtocol::Create(MachThread *thread) { |
| 71 | const DNBArchPluginInfo *arch_info = GetArchInfo(); |
| 72 | if (arch_info) |
| 73 | return arch_info->Create(thread); |
| 74 | return NULL; |
| 75 | } |
| 76 | |
| 77 | const uint8_t *DNBArchProtocol::GetBreakpointOpcode(nub_size_t byte_size) { |
| 78 | const DNBArchPluginInfo *arch_info = GetArchInfo(); |
| 79 | if (arch_info) |
| 80 | return arch_info->GetBreakpointOpcode(byte_size); |
| 81 | return NULL; |
| 82 | } |
| 83 |
