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 #if defined (__i386__) 25 static uint32_t g_current_cpu_type = CPU_TYPE_I386; 26 #elif defined (__x86_64__) 27 static uint32_t g_current_cpu_type = CPU_TYPE_X86_64; 28 #elif defined (__arm__) 29 static uint32_t g_current_cpu_type = CPU_TYPE_ARM; 30 #else 31 static uint32_t g_current_cpu_type = 0; 32 #endif 33 34 CPUPluginInfoMap g_arch_plugins; 35 36 37 static const DNBArchPluginInfo * 38 GetArchInfo () 39 { 40 CPUPluginInfoMap::const_iterator pos = g_arch_plugins.find(g_current_cpu_type); 41 if (pos != g_arch_plugins.end()) 42 return &pos->second; 43 return NULL; 44 } 45 46 47 uint32_t 48 DNBArchProtocol::GetArchitecture () 49 { 50 return g_current_cpu_type; 51 } 52 53 bool 54 DNBArchProtocol::SetArchitecture (uint32_t cpu_type) 55 { 56 g_current_cpu_type = cpu_type; 57 bool result = g_arch_plugins.find(g_current_cpu_type) != g_arch_plugins.end(); 58 DNBLogThreadedIf (LOG_PROCESS, "DNBArchProtocol::SetDefaultArchitecture (cpu_type=0x%8.8x) => %i", cpu_type, result); 59 return result; 60 } 61 62 void 63 DNBArchProtocol::RegisterArchPlugin (const DNBArchPluginInfo &arch_info) 64 { 65 if (arch_info.cpu_type) 66 g_arch_plugins[arch_info.cpu_type] = arch_info; 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 * const 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