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