1 //===-- DNBArch.cpp ---------------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // Created by Greg Clayton on 6/24/07. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "DNBArch.h" 15 #include <assert.h> 16 #include <mach/mach.h> 17 18 #include <map> 19 20 #include "DNBLog.h" 21 22 typedef std::map<uint32_t, DNBArchPluginInfo> CPUPluginInfoMap; 23 24 static uint32_t g_current_cpu_type = 0; 25 CPUPluginInfoMap g_arch_plugins; 26 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()) 31 return &pos->second; 32 return NULL; 33 } 34 35 uint32_t DNBArchProtocol::GetArchitecture() { return g_current_cpu_type; } 36 37 bool DNBArchProtocol::SetArchitecture(uint32_t cpu_type) { 38 g_current_cpu_type = cpu_type; 39 bool result = g_arch_plugins.find(g_current_cpu_type) != g_arch_plugins.end(); 40 DNBLogThreadedIf( 41 LOG_PROCESS, 42 "DNBArchProtocol::SetDefaultArchitecture (cpu_type=0x%8.8x) => %i", 43 cpu_type, result); 44 return result; 45 } 46 47 void DNBArchProtocol::RegisterArchPlugin(const DNBArchPluginInfo &arch_info) { 48 if (arch_info.cpu_type) 49 g_arch_plugins[arch_info.cpu_type] = arch_info; 50 } 51 52 uint32_t DNBArchProtocol::GetRegisterCPUType() { 53 const DNBArchPluginInfo *arch_info = GetArchInfo(); 54 if (arch_info) 55 return arch_info->cpu_type; 56 return 0; 57 } 58 59 const DNBRegisterSetInfo * 60 DNBArchProtocol::GetRegisterSetInfo(nub_size_t *num_reg_sets) { 61 const DNBArchPluginInfo *arch_info = GetArchInfo(); 62 if (arch_info) 63 return arch_info->GetRegisterSetInfo(num_reg_sets); 64 *num_reg_sets = 0; 65 return NULL; 66 } 67 68 DNBArchProtocol *DNBArchProtocol::Create(MachThread *thread) { 69 const DNBArchPluginInfo *arch_info = GetArchInfo(); 70 if (arch_info) 71 return arch_info->Create(thread); 72 return NULL; 73 } 74 75 const uint8_t *DNBArchProtocol::GetBreakpointOpcode(nub_size_t byte_size) { 76 const DNBArchPluginInfo *arch_info = GetArchInfo(); 77 if (arch_info) 78 return arch_info->GetBreakpointOpcode(byte_size); 79 return NULL; 80 } 81