1ce02552bSGreg Clayton //===-- DNBArch.cpp ---------------------------------------------*- C++ -*-===// 2ce02552bSGreg Clayton // 32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6ce02552bSGreg Clayton // 7ce02552bSGreg Clayton //===----------------------------------------------------------------------===// 8ce02552bSGreg Clayton // 9ce02552bSGreg Clayton // Created by Greg Clayton on 6/24/07. 10ce02552bSGreg Clayton // 11ce02552bSGreg Clayton //===----------------------------------------------------------------------===// 12ce02552bSGreg Clayton 13ce02552bSGreg Clayton #include "DNBArch.h" 14*76e47d48SRaphael Isemann #include <cassert> 15ce02552bSGreg Clayton #include <mach/mach.h> 16ce02552bSGreg Clayton 17ce02552bSGreg Clayton #include <map> 18ce02552bSGreg Clayton 19ce02552bSGreg Clayton #include "DNBLog.h" 20ce02552bSGreg Clayton 21ce02552bSGreg Clayton typedef std::map<uint32_t, DNBArchPluginInfo> CPUPluginInfoMap; 22ce02552bSGreg Clayton 2371337622SGreg Clayton static uint32_t g_current_cpu_type = 0; 240db37576SJonas Devlieghere static uint32_t g_current_cpu_subtype = 0; 25ce02552bSGreg Clayton CPUPluginInfoMap g_arch_plugins; 26ce02552bSGreg Clayton GetArchInfo()27b9c1b51eSKate Stonestatic const DNBArchPluginInfo *GetArchInfo() { 28b9c1b51eSKate Stone CPUPluginInfoMap::const_iterator pos = 29b9c1b51eSKate Stone g_arch_plugins.find(g_current_cpu_type); 30ce02552bSGreg Clayton if (pos != g_arch_plugins.end()) 31ce02552bSGreg Clayton return &pos->second; 32ce02552bSGreg Clayton return NULL; 33ce02552bSGreg Clayton } 34ce02552bSGreg Clayton GetCPUType()350db37576SJonas Devlieghereuint32_t DNBArchProtocol::GetCPUType() { return g_current_cpu_type; } GetCPUSubType()360db37576SJonas Devlieghereuint32_t DNBArchProtocol::GetCPUSubType() { return g_current_cpu_subtype; } 373c14438fSGreg Clayton SetArchitecture(uint32_t cpu_type,uint32_t cpu_subtype)380db37576SJonas Devliegherebool DNBArchProtocol::SetArchitecture(uint32_t cpu_type, uint32_t cpu_subtype) { 39ce02552bSGreg Clayton g_current_cpu_type = cpu_type; 400db37576SJonas Devlieghere g_current_cpu_subtype = cpu_subtype; 413c14438fSGreg Clayton bool result = g_arch_plugins.find(g_current_cpu_type) != g_arch_plugins.end(); 420db37576SJonas Devlieghere DNBLogThreadedIf(LOG_PROCESS, 430db37576SJonas Devlieghere "DNBArchProtocol::SetDefaultArchitecture (cpu_type=0x%8.8x, " 440db37576SJonas Devlieghere "cpu_subtype=0x%8.8x) => %i", 450db37576SJonas Devlieghere cpu_type, cpu_subtype, result); 463c14438fSGreg Clayton return result; 47ce02552bSGreg Clayton } 48ce02552bSGreg Clayton RegisterArchPlugin(const DNBArchPluginInfo & arch_info)49b9c1b51eSKate Stonevoid DNBArchProtocol::RegisterArchPlugin(const DNBArchPluginInfo &arch_info) { 50ce02552bSGreg Clayton if (arch_info.cpu_type) 51ce02552bSGreg Clayton g_arch_plugins[arch_info.cpu_type] = arch_info; 52ce02552bSGreg Clayton } 53ce02552bSGreg Clayton GetRegisterCPUType()54b9c1b51eSKate Stoneuint32_t DNBArchProtocol::GetRegisterCPUType() { 55d04f0edaSGreg Clayton const DNBArchPluginInfo *arch_info = GetArchInfo(); 56d04f0edaSGreg Clayton if (arch_info) 57d04f0edaSGreg Clayton return arch_info->cpu_type; 58d04f0edaSGreg Clayton return 0; 59d04f0edaSGreg Clayton } 60d04f0edaSGreg Clayton 61ce02552bSGreg Clayton const DNBRegisterSetInfo * GetRegisterSetInfo(nub_size_t * num_reg_sets)62b9c1b51eSKate StoneDNBArchProtocol::GetRegisterSetInfo(nub_size_t *num_reg_sets) { 63ce02552bSGreg Clayton const DNBArchPluginInfo *arch_info = GetArchInfo(); 64ce02552bSGreg Clayton if (arch_info) 65ce02552bSGreg Clayton return arch_info->GetRegisterSetInfo(num_reg_sets); 66ce02552bSGreg Clayton *num_reg_sets = 0; 67ce02552bSGreg Clayton return NULL; 68ce02552bSGreg Clayton } 69ce02552bSGreg Clayton Create(MachThread * thread)70b9c1b51eSKate StoneDNBArchProtocol *DNBArchProtocol::Create(MachThread *thread) { 71ce02552bSGreg Clayton const DNBArchPluginInfo *arch_info = GetArchInfo(); 72ce02552bSGreg Clayton if (arch_info) 73ce02552bSGreg Clayton return arch_info->Create(thread); 74ce02552bSGreg Clayton return NULL; 75ce02552bSGreg Clayton } 76ce02552bSGreg Clayton GetBreakpointOpcode(nub_size_t byte_size)77b9c1b51eSKate Stoneconst uint8_t *DNBArchProtocol::GetBreakpointOpcode(nub_size_t byte_size) { 78ce02552bSGreg Clayton const DNBArchPluginInfo *arch_info = GetArchInfo(); 79ce02552bSGreg Clayton if (arch_info) 80ce02552bSGreg Clayton return arch_info->GetBreakpointOpcode(byte_size); 81ce02552bSGreg Clayton return NULL; 82ce02552bSGreg Clayton } 83