summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/break_points.cpp97
-rw-r--r--src/common/break_points.h48
-rw-r--r--src/common/common.vcxproj1
-rw-r--r--src/common/common.vcxproj.filters1
-rw-r--r--src/common/register_set.h163
-rw-r--r--src/common/thread.cpp4
6 files changed, 70 insertions, 244 deletions
diff --git a/src/common/break_points.cpp b/src/common/break_points.cpp
index 25d34a21a..25528b864 100644
--- a/src/common/break_points.cpp
+++ b/src/common/break_points.cpp
@@ -9,32 +9,29 @@
9#include <sstream> 9#include <sstream>
10#include <algorithm> 10#include <algorithm>
11 11
12bool BreakPoints::IsAddressBreakPoint(u32 _iAddress) 12bool BreakPoints::IsAddressBreakPoint(u32 iAddress)
13{ 13{
14 for (TBreakPoints::iterator i = m_BreakPoints.begin(); i != m_BreakPoints.end(); ++i) 14 auto cond = [&iAddress](const TBreakPoint& bp) { return bp.iAddress == iAddress; };
15 if (i->iAddress == _iAddress) 15 auto it = std::find_if(m_BreakPoints.begin(), m_BreakPoints.end(), cond);
16 return true; 16 return it != m_BreakPoints.end();
17 return false;
18} 17}
19 18
20bool BreakPoints::IsTempBreakPoint(u32 _iAddress) 19bool BreakPoints::IsTempBreakPoint(u32 iAddress)
21{ 20{
22 for (TBreakPoints::iterator i = m_BreakPoints.begin(); i != m_BreakPoints.end(); ++i) 21 auto cond = [&iAddress](const TBreakPoint& bp) { return bp.iAddress == iAddress && bp.bTemporary; };
23 if (i->iAddress == _iAddress && i->bTemporary) 22 auto it = std::find_if(m_BreakPoints.begin(), m_BreakPoints.end(), cond);
24 return true; 23 return it != m_BreakPoints.end();
25 return false;
26} 24}
27 25
28BreakPoints::TBreakPointsStr BreakPoints::GetStrings() const 26BreakPoints::TBreakPointsStr BreakPoints::GetStrings() const
29{ 27{
30 TBreakPointsStr bps; 28 TBreakPointsStr bps;
31 for (TBreakPoints::const_iterator i = m_BreakPoints.begin(); 29 for (auto breakpoint : m_BreakPoints)
32 i != m_BreakPoints.end(); ++i)
33 { 30 {
34 if (!i->bTemporary) 31 if (!breakpoint.bTemporary)
35 { 32 {
36 std::stringstream bp; 33 std::stringstream bp;
37 bp << std::hex << i->iAddress << " " << (i->bOn ? "n" : ""); 34 bp << std::hex << breakpoint.iAddress << " " << (breakpoint.bOn ? "n" : "");
38 bps.push_back(bp.str()); 35 bps.push_back(bp.str());
39 } 36 }
40 } 37 }
@@ -44,13 +41,13 @@ BreakPoints::TBreakPointsStr BreakPoints::GetStrings() const
44 41
45void BreakPoints::AddFromStrings(const TBreakPointsStr& bps) 42void BreakPoints::AddFromStrings(const TBreakPointsStr& bps)
46{ 43{
47 for (TBreakPointsStr::const_iterator i = bps.begin(); i != bps.end(); ++i) 44 for (auto bps_item : bps)
48 { 45 {
49 TBreakPoint bp; 46 TBreakPoint bp;
50 std::stringstream bpstr; 47 std::stringstream bpstr;
51 bpstr << std::hex << *i; 48 bpstr << std::hex << bps_item;
52 bpstr >> bp.iAddress; 49 bpstr >> bp.iAddress;
53 bp.bOn = i->find("n") != i->npos; 50 bp.bOn = bps_item.find("n") != bps_item.npos;
54 bp.bTemporary = false; 51 bp.bTemporary = false;
55 Add(bp); 52 Add(bp);
56 } 53 }
@@ -84,16 +81,10 @@ void BreakPoints::Add(u32 em_address, bool temp)
84 81
85void BreakPoints::Remove(u32 em_address) 82void BreakPoints::Remove(u32 em_address)
86{ 83{
87 for (TBreakPoints::iterator i = m_BreakPoints.begin(); i != m_BreakPoints.end(); ++i) 84 auto cond = [&em_address](const TBreakPoint& bp) { return bp.iAddress == em_address; };
88 { 85 auto it = std::find_if(m_BreakPoints.begin(), m_BreakPoints.end(), cond);
89 if (i->iAddress == em_address) 86 if (it != m_BreakPoints.end())
90 { 87 m_BreakPoints.erase(it);
91 m_BreakPoints.erase(i);
92 //if (jit)
93 // jit->GetBlockCache()->InvalidateICache(em_address, 4);
94 return;
95 }
96 }
97} 88}
98 89
99void BreakPoints::Clear() 90void BreakPoints::Clear()
@@ -107,21 +98,23 @@ void BreakPoints::Clear()
107 // } 98 // }
108 // ); 99 // );
109 //} 100 //}
110 101
111 m_BreakPoints.clear(); 102 m_BreakPoints.clear();
112} 103}
113 104
114MemChecks::TMemChecksStr MemChecks::GetStrings() const 105MemChecks::TMemChecksStr MemChecks::GetStrings() const
115{ 106{
116 TMemChecksStr mcs; 107 TMemChecksStr mcs;
117 for (TMemChecks::const_iterator i = m_MemChecks.begin(); 108 for (auto memcheck : m_MemChecks)
118 i != m_MemChecks.end(); ++i)
119 { 109 {
120 std::stringstream mc; 110 std::stringstream mc;
121 mc << std::hex << i->StartAddress; 111 mc << std::hex << memcheck.StartAddress;
122 mc << " " << (i->bRange ? i->EndAddress : i->StartAddress) << " " << 112 mc << " " << (memcheck.bRange ? memcheck.EndAddress : memcheck.StartAddress) << " "
123 (i->bRange ? "n" : "") << (i->OnRead ? "r" : "") << 113 << (memcheck.bRange ? "n" : "")
124 (i->OnWrite ? "w" : "") << (i->Log ? "l" : "") << (i->Break ? "p" : ""); 114 << (memcheck.OnRead ? "r" : "")
115 << (memcheck.OnWrite ? "w" : "")
116 << (memcheck.Log ? "l" : "")
117 << (memcheck.Break ? "p" : "");
125 mcs.push_back(mc.str()); 118 mcs.push_back(mc.str());
126 } 119 }
127 120
@@ -130,17 +123,17 @@ MemChecks::TMemChecksStr MemChecks::GetStrings() const
130 123
131void MemChecks::AddFromStrings(const TMemChecksStr& mcs) 124void MemChecks::AddFromStrings(const TMemChecksStr& mcs)
132{ 125{
133 for (TMemChecksStr::const_iterator i = mcs.begin(); i != mcs.end(); ++i) 126 for (auto mcs_item : mcs)
134 { 127 {
135 TMemCheck mc; 128 TMemCheck mc;
136 std::stringstream mcstr; 129 std::stringstream mcstr;
137 mcstr << std::hex << *i; 130 mcstr << std::hex << mcs_item;
138 mcstr >> mc.StartAddress; 131 mcstr >> mc.StartAddress;
139 mc.bRange = i->find("n") != i->npos; 132 mc.bRange = mcs_item.find("n") != mcs_item.npos;
140 mc.OnRead = i->find("r") != i->npos; 133 mc.OnRead = mcs_item.find("r") != mcs_item.npos;
141 mc.OnWrite = i->find("w") != i->npos; 134 mc.OnWrite = mcs_item.find("w") != mcs_item.npos;
142 mc.Log = i->find("l") != i->npos; 135 mc.Log = mcs_item.find("l") != mcs_item.npos;
143 mc.Break = i->find("p") != i->npos; 136 mc.Break = mcs_item.find("p") != mcs_item.npos;
144 if (mc.bRange) 137 if (mc.bRange)
145 mcstr >> mc.EndAddress; 138 mcstr >> mc.EndAddress;
146 else 139 else
@@ -149,27 +142,23 @@ void MemChecks::AddFromStrings(const TMemChecksStr& mcs)
149 } 142 }
150} 143}
151 144
152void MemChecks::Add(const TMemCheck& _rMemoryCheck) 145void MemChecks::Add(const TMemCheck& rMemoryCheck)
153{ 146{
154 if (GetMemCheck(_rMemoryCheck.StartAddress) == 0) 147 if (GetMemCheck(rMemoryCheck.StartAddress) == 0)
155 m_MemChecks.push_back(_rMemoryCheck); 148 m_MemChecks.push_back(rMemoryCheck);
156} 149}
157 150
158void MemChecks::Remove(u32 _Address) 151void MemChecks::Remove(u32 Address)
159{ 152{
160 for (TMemChecks::iterator i = m_MemChecks.begin(); i != m_MemChecks.end(); ++i) 153 auto cond = [&Address](const TMemCheck& mc) { return mc.StartAddress == Address; };
161 { 154 auto it = std::find_if(m_MemChecks.begin(), m_MemChecks.end(), cond);
162 if (i->StartAddress == _Address) 155 if (it != m_MemChecks.end())
163 { 156 m_MemChecks.erase(it);
164 m_MemChecks.erase(i);
165 return;
166 }
167 }
168} 157}
169 158
170TMemCheck *MemChecks::GetMemCheck(u32 address) 159TMemCheck *MemChecks::GetMemCheck(u32 address)
171{ 160{
172 for (TMemChecks::iterator i = m_MemChecks.begin(); i != m_MemChecks.end(); ++i) 161 for (auto i = m_MemChecks.begin(); i != m_MemChecks.end(); ++i)
173 { 162 {
174 if (i->bRange) 163 if (i->bRange)
175 { 164 {
diff --git a/src/common/break_points.h b/src/common/break_points.h
index 46df34665..da14ca7f3 100644
--- a/src/common/break_points.h
+++ b/src/common/break_points.h
@@ -14,32 +14,33 @@ class DebugInterface;
14 14
15struct TBreakPoint 15struct TBreakPoint
16{ 16{
17 u32 iAddress; 17 u32 iAddress;
18 bool bOn; 18 bool bOn;
19 bool bTemporary; 19 bool bTemporary;
20}; 20};
21 21
22struct TMemCheck 22struct TMemCheck
23{ 23{
24 TMemCheck() { 24 TMemCheck():
25 numHits = 0; 25 StartAddress(0), EndAddress(0),
26 StartAddress = EndAddress = 0; 26 bRange(false), OnRead(false), OnWrite(false),
27 bRange = OnRead = OnWrite = Log = Break = false; 27 Log(false), Break(false), numHits(0)
28 } 28 { }
29 u32 StartAddress;
30 u32 EndAddress;
31 29
32 bool bRange; 30 u32 StartAddress;
31 u32 EndAddress;
33 32
34 bool OnRead; 33 bool bRange;
35 bool OnWrite;
36 34
37 bool Log; 35 bool OnRead;
38 bool Break; 36 bool OnWrite;
39 37
40 u32 numHits; 38 bool Log;
39 bool Break;
41 40
42 void Action(DebugInterface *dbg_interface, u32 _iValue, u32 addr, 41 u32 numHits;
42
43 void Action(DebugInterface *dbg_interface, u32 iValue, u32 addr,
43 bool write, int size, u32 pc); 44 bool write, int size, u32 pc);
44}; 45};
45 46
@@ -56,22 +57,22 @@ public:
56 void AddFromStrings(const TBreakPointsStr& bps); 57 void AddFromStrings(const TBreakPointsStr& bps);
57 58
58 // is address breakpoint 59 // is address breakpoint
59 bool IsAddressBreakPoint(u32 _iAddress); 60 bool IsAddressBreakPoint(u32 iAddress);
60 bool IsTempBreakPoint(u32 _iAddress); 61 bool IsTempBreakPoint(u32 iAddress);
61 62
62 // Add BreakPoint 63 // Add BreakPoint
63 void Add(u32 em_address, bool temp=false); 64 void Add(u32 em_address, bool temp=false);
64 void Add(const TBreakPoint& bp); 65 void Add(const TBreakPoint& bp);
65 66
66 // Remove Breakpoint 67 // Remove Breakpoint
67 void Remove(u32 _iAddress); 68 void Remove(u32 iAddress);
68 void Clear(); 69 void Clear();
69 70
70 void DeleteByAddress(u32 _Address); 71 void DeleteByAddress(u32 Address);
71 72
72private: 73private:
73 TBreakPoints m_BreakPoints; 74 TBreakPoints m_BreakPoints;
74 u32 m_iBreakOnCount; 75 u32 m_iBreakOnCount;
75}; 76};
76 77
77 78
@@ -89,7 +90,7 @@ public:
89 TMemChecksStr GetStrings() const; 90 TMemChecksStr GetStrings() const;
90 void AddFromStrings(const TMemChecksStr& mcs); 91 void AddFromStrings(const TMemChecksStr& mcs);
91 92
92 void Add(const TMemCheck& _rMemoryCheck); 93 void Add(const TMemCheck& rMemoryCheck);
93 94
94 // memory breakpoint 95 // memory breakpoint
95 TMemCheck *GetMemCheck(u32 address); 96 TMemCheck *GetMemCheck(u32 address);
@@ -99,4 +100,3 @@ public:
99}; 100};
100 101
101#endif 102#endif
102
diff --git a/src/common/common.vcxproj b/src/common/common.vcxproj
index 1f5c714c3..341d3a813 100644
--- a/src/common/common.vcxproj
+++ b/src/common/common.vcxproj
@@ -182,7 +182,6 @@
182 <ClInclude Include="mem_arena.h" /> 182 <ClInclude Include="mem_arena.h" />
183 <ClInclude Include="msg_handler.h" /> 183 <ClInclude Include="msg_handler.h" />
184 <ClInclude Include="platform.h" /> 184 <ClInclude Include="platform.h" />
185 <ClInclude Include="register_set.h" />
186 <ClInclude Include="scm_rev.h" /> 185 <ClInclude Include="scm_rev.h" />
187 <ClInclude Include="std_condition_variable.h" /> 186 <ClInclude Include="std_condition_variable.h" />
188 <ClInclude Include="std_mutex.h" /> 187 <ClInclude Include="std_mutex.h" />
diff --git a/src/common/common.vcxproj.filters b/src/common/common.vcxproj.filters
index e8c4ce360..59268ce5a 100644
--- a/src/common/common.vcxproj.filters
+++ b/src/common/common.vcxproj.filters
@@ -29,7 +29,6 @@
29 <ClInclude Include="memory_util.h" /> 29 <ClInclude Include="memory_util.h" />
30 <ClInclude Include="msg_handler.h" /> 30 <ClInclude Include="msg_handler.h" />
31 <ClInclude Include="platform.h" /> 31 <ClInclude Include="platform.h" />
32 <ClInclude Include="register_set.h" />
33 <ClInclude Include="std_condition_variable.h" /> 32 <ClInclude Include="std_condition_variable.h" />
34 <ClInclude Include="std_mutex.h" /> 33 <ClInclude Include="std_mutex.h" />
35 <ClInclude Include="std_thread.h" /> 34 <ClInclude Include="std_thread.h" />
diff --git a/src/common/register_set.h b/src/common/register_set.h
deleted file mode 100644
index ba19a2614..000000000
--- a/src/common/register_set.h
+++ /dev/null
@@ -1,163 +0,0 @@
1// Copyright 2014 Citra Emulator Project
2// Licensed under GPLv2
3// Refer to the license.txt file included.
4
5#pragma once
6
7// Copyright 2014 Tony Wasserka
8// All rights reserved.
9//
10// Redistribution and use in source and binary forms, with or without
11// modification, are permitted provided that the following conditions are met:
12//
13// * Redistributions of source code must retain the above copyright
14// notice, this list of conditions and the following disclaimer.
15// * Redistributions in binary form must reproduce the above copyright
16// notice, this list of conditions and the following disclaimer in the
17// documentation and/or other materials provided with the distribution.
18// * Neither the name of the owner nor the names of its contributors may
19// be used to endorse or promote products derived from this software
20// without specific prior written permission.
21//
22// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
34/*
35 * Standardized way to define a group of registers and corresponding data structures. To define
36 * a new register set, first define struct containing an enumeration called "Id" containing
37 * all register IDs and a template struct called "Struct". Specialize the Struct struct for any
38 * register ID which needs to be accessed in a specialized way. You can then declare the object
39 * containing all register values using the RegisterSet<BaseType, DefiningStruct> type, where
40 * BaseType is the underlying type of each register (e.g. u32).
41 * Of course, you'll usually want to implement the Struct template such that they are of the same
42 * size as BaseType. However, it's also possible to make it larger, e.g. when you want to describe
43 * multiple registers with the same structure.
44 *
45 * Example:
46 *
47 * struct Regs {
48 * enum Id : u32 {
49 * Value1 = 0,
50 * Value2 = 1,
51 * Value3 = 2,
52 * NumIds = 3
53 * };
54 *
55 * // declare register definition structures
56 * template<Id id>
57 * struct Struct;
58 * };
59 *
60 * // Define register set object
61 * RegisterSet<u32, CommandIds> registers;
62 *
63 * // define register definition structures
64 * template<>
65 * struct Regs::Struct<Regs::Value1> {
66 * union {
67 * BitField<0, 4, u32> some_field;
68 * BitField<4, 3, u32> some_other_field;
69 * };
70 * };
71 *
72 * Usage in external code (within SomeNamespace scope):
73 *
74 * For a register which maps to a single index:
75 * registers.Get<Regs::Value1>().some_field = some_value;
76 *
77 * For a register which maps to different indices, e.g. a group of similar registers
78 * registers.Get<Regs::Value1>(index).some_field = some_value;
79 *
80 *
81 * @tparam BaseType Base type used for storing individual registers, e.g. u32
82 * @tparam RegDefinition Class defining an enumeration called "Id" and a template<Id id> struct, as described above.
83 * @note RegDefinition::Id needs to have an enum value called NumIds defining the number of registers to be allocated.
84 */
85template<typename BaseType, typename RegDefinition>
86struct RegisterSet {
87 // Register IDs
88 using Id = typename RegDefinition::Id;
89
90 // type used for *this
91 using ThisType = RegisterSet<BaseType, RegDefinition>;
92
93 // Register definition structs, defined in RegDefinition
94 template<Id id>
95 using Struct = typename RegDefinition::template Struct<id>;
96
97
98 /*
99 * Lookup register with the given id and return it as the corresponding structure type.
100 * @note This just forwards the arguments to Get(Id).
101 */
102 template<Id id>
103 const Struct<id>& Get() const {
104 return Get<id>(id);
105 }
106
107 /*
108 * Lookup register with the given id and return it as the corresponding structure type.
109 * @note This just forwards the arguments to Get(Id).
110 */
111 template<Id id>
112 Struct<id>& Get() {
113 return Get<id>(id);
114 }
115
116 /*
117 * Lookup register with the given index and return it as the corresponding structure type.
118 * @todo Is this portable with regards to structures larger than BaseType?
119 * @note if index==id, you don't need to specify the function parameter.
120 */
121 template<Id id>
122 const Struct<id>& Get(const Id& index) const {
123 const int idx = static_cast<size_t>(index);
124 return *reinterpret_cast<const Struct<id>*>(&raw[idx]);
125 }
126
127 /*
128 * Lookup register with the given index and return it as the corresponding structure type.
129 * @note This just forwards the arguments to the const version of Get(Id).
130 * @note if index==id, you don't need to specify the function parameter.
131 */
132 template<Id id>
133 Struct<id>& Get(const Id& index) {
134 return const_cast<Struct<id>&>(GetThis().Get<id>(index));
135 }
136
137 /*
138 * Plain array access.
139 * @note If you want to have this casted to a register defininition struct, use Get() instead.
140 */
141 const BaseType& operator[] (const Id& id) const {
142 return raw[static_cast<size_t>(id)];
143 }
144
145 /*
146 * Plain array access.
147 * @note If you want to have this casted to a register defininition struct, use Get() instead.
148 * @note This operator just forwards its argument to the const version.
149 */
150 BaseType& operator[] (const Id& id) {
151 return const_cast<BaseType&>(GetThis()[id]);
152 }
153
154private:
155 /*
156 * Returns a const reference to "this".
157 */
158 const ThisType& GetThis() const {
159 return static_cast<const ThisType&>(*this);
160 }
161
162 BaseType raw[Id::NumIds];
163};
diff --git a/src/common/thread.cpp b/src/common/thread.cpp
index c70ee37cf..7341035c2 100644
--- a/src/common/thread.cpp
+++ b/src/common/thread.cpp
@@ -7,7 +7,7 @@
7 7
8#ifdef __APPLE__ 8#ifdef __APPLE__
9#include <mach/mach.h> 9#include <mach/mach.h>
10#elif defined BSD4_4 10#elif defined(BSD4_4) || defined(__OpenBSD__)
11#include <pthread_np.h> 11#include <pthread_np.h>
12#endif 12#endif
13 13
@@ -123,6 +123,8 @@ void SetCurrentThreadName(const char* szThreadName)
123{ 123{
124#ifdef __APPLE__ 124#ifdef __APPLE__
125 pthread_setname_np(szThreadName); 125 pthread_setname_np(szThreadName);
126#elif defined(__OpenBSD__)
127 pthread_set_name_np(pthread_self(), szThreadName);
126#else 128#else
127 pthread_setname_np(pthread_self(), szThreadName); 129 pthread_setname_np(pthread_self(), szThreadName);
128#endif 130#endif