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 28 static const DNBArchPluginInfo * 29 GetArchInfo () 30 { 31 CPUPluginInfoMap::const_iterator pos = g_arch_plugins.find(g_current_cpu_type); 32 if (pos != g_arch_plugins.end()) 33 return &pos->second; 34 return NULL; 35 } 36 37 38 uint32_t 39 DNBArchProtocol::GetArchitecture () 40 { 41 return g_current_cpu_type; 42 } 43 44 bool 45 DNBArchProtocol::SetArchitecture (uint32_t cpu_type) 46 { 47 g_current_cpu_type = cpu_type; 48 bool result = g_arch_plugins.find(g_current_cpu_type) != g_arch_plugins.end(); 49 DNBLogThreadedIf (LOG_PROCESS, "DNBArchProtocol::SetDefaultArchitecture (cpu_type=0x%8.8x) => %i", cpu_type, result); 50 return result; 51 } 52 53 void 54 DNBArchProtocol::RegisterArchPlugin (const DNBArchPluginInfo &arch_info) 55 { 56 if (arch_info.cpu_type) 57 g_arch_plugins[arch_info.cpu_type] = arch_info; 58 } 59 60 uint32_t 61 DNBArchProtocol::GetRegisterCPUType () 62 { 63 const DNBArchPluginInfo *arch_info = GetArchInfo (); 64 if (arch_info) 65 return arch_info->cpu_type; 66 return 0; 67 } 68 69 const DNBRegisterSetInfo * 70 DNBArchProtocol::GetRegisterSetInfo (nub_size_t *num_reg_sets) 71 { 72 const DNBArchPluginInfo *arch_info = GetArchInfo (); 73 if (arch_info) 74 return arch_info->GetRegisterSetInfo (num_reg_sets); 75 *num_reg_sets = 0; 76 return NULL; 77 } 78 79 DNBArchProtocol * 80 DNBArchProtocol::Create (MachThread *thread) 81 { 82 const DNBArchPluginInfo *arch_info = GetArchInfo (); 83 if (arch_info) 84 return arch_info->Create (thread); 85 return NULL; 86 87 } 88 89 const uint8_t * 90 DNBArchProtocol::GetBreakpointOpcode (nub_size_t byte_size) 91 { 92 const DNBArchPluginInfo *arch_info = GetArchInfo (); 93 if (arch_info) 94 return arch_info->GetBreakpointOpcode (byte_size); 95 return NULL; 96 } 97 98