summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/kernel.h
diff options
context:
space:
mode:
authorGravatar bunnei2014-05-20 18:13:25 -0400
committerGravatar bunnei2014-05-20 18:13:25 -0400
commit44336329eddd7dbe1f76144e9a1e95e5f76ed372 (patch)
tree49c103d52af50fe6ef451324f1c8aae6363d0468 /src/core/hle/kernel/kernel.h
parentapt: changed stubbed handle to be something other than 0xDEADBEEF (used as a ... (diff)
downloadyuzu-44336329eddd7dbe1f76144e9a1e95e5f76ed372.tar.gz
yuzu-44336329eddd7dbe1f76144e9a1e95e5f76ed372.tar.xz
yuzu-44336329eddd7dbe1f76144e9a1e95e5f76ed372.zip
- created a Kernel namespace
- cleaned up Kernel code a bit (moved stuff into namespace, fixed whitespace issues) - added handle types for all different CTROS handles
Diffstat (limited to 'src/core/hle/kernel/kernel.h')
-rw-r--r--src/core/hle/kernel/kernel.h75
1 files changed, 44 insertions, 31 deletions
diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h
index 8f2b7b36d..19edb7b57 100644
--- a/src/core/hle/kernel/kernel.h
+++ b/src/core/hle/kernel/kernel.h
@@ -9,41 +9,50 @@
9typedef u32 Handle; 9typedef u32 Handle;
10typedef s32 Result; 10typedef s32 Result;
11 11
12enum KernelIDType { 12namespace Kernel {
13 KERNEL_ID_TYPE_THREAD, 13
14 KERNEL_ID_TYPE_SEMAPHORE, 14enum class HandleType : u32 {
15 KERNEL_ID_TYPE_MUTEX, 15 Unknown = 0,
16 KERNEL_ID_TYPE_EVENT, 16 Port = 1,
17 KERNEL_ID_TYPE_SERVICE, 17 Service = 2,
18 Event = 3,
19 Mutex = 4,
20 SharedMemory = 5,
21 Redirection = 6,
22 Thread = 7,
23 Process = 8,
24 Arbiter = 9,
25 File = 10,
26 Semaphore = 11,
18}; 27};
19 28
20enum { 29enum {
21 KERNEL_MAX_NAME_LENGTH = 0x100, 30 MAX_NAME_LENGTH = 0x100,
22 KERNEL_DEFAULT_STACK_SIZE = 0x4000, 31 DEFAULT_STACK_SIZE = 0x4000,
23}; 32};
24 33
25class KernelObjectPool; 34class ObjectPool;
26 35
27class KernelObject { 36class Object : NonCopyable {
28 friend class KernelObjectPool; 37 friend class ObjectPool;
29 u32 handle; 38 u32 handle;
30public: 39public:
31 virtual ~KernelObject() {} 40 virtual ~Object() {}
32 Handle GetHandle() const { return handle; } 41 Handle GetHandle() const { return handle; }
33 virtual const char *GetTypeName() { return "[BAD KERNEL OBJECT TYPE]"; } 42 virtual const char *GetTypeName() { return "[BAD KERNEL OBJECT TYPE]"; }
34 virtual const char *GetName() { return "[UNKNOWN KERNEL OBJECT]"; } 43 virtual const char *GetName() { return "[UNKNOWN KERNEL OBJECT]"; }
35 virtual KernelIDType GetIDType() const = 0; 44 virtual Kernel::HandleType GetHandleType() const = 0;
36}; 45};
37 46
38class KernelObjectPool { 47class ObjectPool : NonCopyable {
39public: 48public:
40 KernelObjectPool(); 49 ObjectPool();
41 ~KernelObjectPool() {} 50 ~ObjectPool() {}
42 51
43 // Allocates a handle within the range and inserts the object into the map. 52 // Allocates a handle within the range and inserts the object into the map.
44 Handle Create(KernelObject *obj, int range_bottom=INITIAL_NEXT_ID, int range_top=0x7FFFFFFF); 53 Handle Create(Object* obj, int range_bottom=INITIAL_NEXT_ID, int range_top=0x7FFFFFFF);
45 54
46 static KernelObject *CreateByIDType(int type); 55 static Object* CreateByIDType(int type);
47 56
48 template <class T> 57 template <class T>
49 u32 Destroy(Handle handle) { 58 u32 Destroy(Handle handle) {
@@ -71,7 +80,7 @@ public:
71 // it just acted as a static case and everything worked. This means that we will never 80 // it just acted as a static case and everything worked. This means that we will never
72 // see the Wrong type object error below, but we'll just have to live with that danger. 81 // see the Wrong type object error below, but we'll just have to live with that danger.
73 T* t = static_cast<T*>(pool[handle - HANDLE_OFFSET]); 82 T* t = static_cast<T*>(pool[handle - HANDLE_OFFSET]);
74 if (t == 0 || t->GetIDType() != T::GetStaticIDType()) { 83 if (t == 0 || t->GetHandleType() != T::GetStaticHandleType()) {
75 WARN_LOG(KERNEL, "Kernel: Wrong object type for %i (%08x)", handle, handle); 84 WARN_LOG(KERNEL, "Kernel: Wrong object type for %i (%08x)", handle, handle);
76 outError = 0;//T::GetMissingErrorCode(); 85 outError = 0;//T::GetMissingErrorCode();
77 return 0; 86 return 0;
@@ -86,17 +95,17 @@ public:
86 T *GetFast(Handle handle) { 95 T *GetFast(Handle handle) {
87 const Handle realHandle = handle - HANDLE_OFFSET; 96 const Handle realHandle = handle - HANDLE_OFFSET;
88 _dbg_assert_(KERNEL, realHandle >= 0 && realHandle < MAX_COUNT && occupied[realHandle]); 97 _dbg_assert_(KERNEL, realHandle >= 0 && realHandle < MAX_COUNT && occupied[realHandle]);
89 return static_cast<T *>(pool[realHandle]); 98 return static_cast<T*>(pool[realHandle]);
90 } 99 }
91 100
92 template <class T, typename ArgT> 101 template <class T, typename ArgT>
93 void Iterate(bool func(T *, ArgT), ArgT arg) { 102 void Iterate(bool func(T*, ArgT), ArgT arg) {
94 int type = T::GetStaticIDType(); 103 int type = T::GetStaticIDType();
95 for (int i = 0; i < MAX_COUNT; i++) 104 for (int i = 0; i < MAX_COUNT; i++)
96 { 105 {
97 if (!occupied[i]) 106 if (!occupied[i])
98 continue; 107 continue;
99 T *t = static_cast<T *>(pool[i]); 108 T* t = static_cast<T*>(pool[i]);
100 if (t->GetIDType() == type) { 109 if (t->GetIDType() == type) {
101 if (!func(t, arg)) 110 if (!func(t, arg))
102 break; 111 break;
@@ -104,33 +113,37 @@ public:
104 } 113 }
105 } 114 }
106 115
107 bool GetIDType(Handle handle, int *type) const { 116 bool GetIDType(Handle handle, HandleType* type) const {
108 if ((handle < HANDLE_OFFSET) || (handle >= HANDLE_OFFSET + MAX_COUNT) || 117 if ((handle < HANDLE_OFFSET) || (handle >= HANDLE_OFFSET + MAX_COUNT) ||
109 !occupied[handle - HANDLE_OFFSET]) { 118 !occupied[handle - HANDLE_OFFSET]) {
110 ERROR_LOG(KERNEL, "Kernel: Bad object handle %i (%08x)", handle, handle); 119 ERROR_LOG(KERNEL, "Kernel: Bad object handle %i (%08x)", handle, handle);
111 return false; 120 return false;
112 } 121 }
113 KernelObject *t = pool[handle - HANDLE_OFFSET]; 122 Object* t = pool[handle - HANDLE_OFFSET];
114 *type = t->GetIDType(); 123 *type = t->GetHandleType();
115 return true; 124 return true;
116 } 125 }
117 126
118 KernelObject *&operator [](Handle handle); 127 Object* &operator [](Handle handle);
119 void List(); 128 void List();
120 void Clear(); 129 void Clear();
121 int GetCount(); 130 int GetCount();
122 131
123private: 132private:
133
124 enum { 134 enum {
125 MAX_COUNT = 0x1000, 135 MAX_COUNT = 0x1000,
126 HANDLE_OFFSET = 0x100, 136 HANDLE_OFFSET = 0x100,
127 INITIAL_NEXT_ID = 0x10, 137 INITIAL_NEXT_ID = 0x10,
128 }; 138 };
129 KernelObject *pool[MAX_COUNT]; 139
130 bool occupied[MAX_COUNT]; 140 Object* pool[MAX_COUNT];
131 int next_id; 141 bool occupied[MAX_COUNT];
142 int next_id;
132}; 143};
133 144
134extern KernelObjectPool g_kernel_objects; 145extern ObjectPool g_object_pool;
146
147} // namespace
135 148
136bool __KernelLoadExec(u32 entry_point); 149bool __KernelLoadExec(u32 entry_point);