Added preliminary support for shared memory objects and handles.

This commit is contained in:
inspuration 2014-06-09 14:42:01 -04:00
parent 3285b3c168
commit b7be03fd2c
10 changed files with 90 additions and 3 deletions

View File

@ -37,6 +37,7 @@ set(SRCS core.cpp
hle/kernel/kernel.cpp hle/kernel/kernel.cpp
hle/kernel/mutex.cpp hle/kernel/mutex.cpp
hle/kernel/thread.cpp hle/kernel/thread.cpp
hle/kernel/shared_memory.cpp
hle/service/apt.cpp hle/service/apt.cpp
hle/service/gsp.cpp hle/service/gsp.cpp
hle/service/hid.cpp hle/service/hid.cpp
@ -82,6 +83,7 @@ set(HEADERS core.h
hle/svc.h hle/svc.h
hle/kernel/kernel.h hle/kernel/kernel.h
hle/kernel/mutex.h hle/kernel/mutex.h
hle/kernel/shared_memory.h
hle/kernel/thread.h hle/kernel/thread.h
hle/function_wrappers.h hle/function_wrappers.h
hle/service/apt.h hle/service/apt.h

View File

@ -180,6 +180,7 @@
<ClCompile Include="hle\hle.cpp" /> <ClCompile Include="hle\hle.cpp" />
<ClCompile Include="hle\kernel\kernel.cpp" /> <ClCompile Include="hle\kernel\kernel.cpp" />
<ClCompile Include="hle\kernel\mutex.cpp" /> <ClCompile Include="hle\kernel\mutex.cpp" />
<ClCompile Include="hle\kernel\shared_memory.cpp" />
<ClCompile Include="hle\kernel\thread.cpp" /> <ClCompile Include="hle\kernel\thread.cpp" />
<ClCompile Include="hle\service\apt.cpp" /> <ClCompile Include="hle\service\apt.cpp" />
<ClCompile Include="hle\service\gsp.cpp" /> <ClCompile Include="hle\service\gsp.cpp" />
@ -230,6 +231,7 @@
<ClInclude Include="hle\hle.h" /> <ClInclude Include="hle\hle.h" />
<ClInclude Include="hle\kernel\kernel.h" /> <ClInclude Include="hle\kernel\kernel.h" />
<ClInclude Include="hle\kernel\mutex.h" /> <ClInclude Include="hle\kernel\mutex.h" />
<ClInclude Include="hle\kernel\shared_memory.h" />
<ClInclude Include="hle\kernel\thread.h" /> <ClInclude Include="hle\kernel\thread.h" />
<ClInclude Include="hle\service\apt.h" /> <ClInclude Include="hle\service\apt.h" />
<ClInclude Include="hle\service\gsp.h" /> <ClInclude Include="hle\service\gsp.h" />

View File

@ -168,6 +168,9 @@
<ClCompile Include="hw\hid.cpp"> <ClCompile Include="hw\hid.cpp">
<Filter>hw</Filter> <Filter>hw</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="hle\kernel\shared_memory.cpp">
<Filter>hle\kernel</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="arm\disassembler\arm_disasm.h"> <ClInclude Include="arm\disassembler\arm_disasm.h">
@ -301,6 +304,9 @@
<ClInclude Include="hw\hid.h"> <ClInclude Include="hw\hid.h">
<Filter>hw</Filter> <Filter>hw</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="hle\kernel\shared_memory.h">
<Filter>hle\kernel</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Text Include="CMakeLists.txt" /> <Text Include="CMakeLists.txt" />

View File

@ -94,6 +94,7 @@ public:
template <class T> template <class T>
T *GetFast(Handle handle) { T *GetFast(Handle handle) {
const Handle realHandle = handle - HANDLE_OFFSET; const Handle realHandle = handle - HANDLE_OFFSET;
//bravia note: there is a weird bug caused here which puts the processor into thumb mode
_dbg_assert_(KERNEL, realHandle >= 0 && realHandle < MAX_COUNT && occupied[realHandle]); _dbg_assert_(KERNEL, realHandle >= 0 && realHandle < MAX_COUNT && occupied[realHandle]);
return static_cast<T*>(pool[realHandle]); return static_cast<T*>(pool[realHandle]);
} }

View File

@ -0,0 +1,48 @@
// Copyright 2014 Citra Emulator Project
// Licensed under GPLv2
// Refer to the license.txt file included.
#include <map>
#include <vector>
#include "common/common.h"
#include "core/hle/kernel/kernel.h"
#include "core/hle/kernel/thread.h"
namespace Kernel {
class SharedMemory : public Object {
public:
const char* GetTypeName() { return "SharedMemory"; }
static Kernel::HandleType GetStaticHandleType() { return Kernel::HandleType::SharedMemory; }
Kernel::HandleType GetHandleType() const { return Kernel::HandleType::SharedMemory; }
//TODO: implement
};
////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Creates a mutex
* @param handle Reference to handle for the newly created mutex
* @param initial_locked Specifies if the mutex should be locked initially
*/
SharedMemory* CreateSharedMemory(Handle& handle) {
SharedMemory* mem = new SharedMemory;
handle = Kernel::g_object_pool.Create(mem);
return mem;
}
Handle CreateSharedMemory() {
Handle handle;
SharedMemory* mem = CreateSharedMemory(handle);
return handle;
}
} // namespace

View File

@ -0,0 +1,20 @@
// Copyright 2014 Citra Emulator Project
// Licensed under GPLv2
// Refer to the license.txt file included.
#pragma once
#include "common/common_types.h"
#include "core/hle/kernel/kernel.h"
namespace Kernel {
/**
* Creates a shared memory object
* @param handle Reference to handle for the newly created mutex
* @param
*/
Handle CreateSharedMemory();
} // namespace

View File

@ -102,6 +102,7 @@ void RegisterInterruptRelayQueue(Service::Interface* self) {
u32 flags = cmd_buff[1]; u32 flags = cmd_buff[1];
u32 event_handle = cmd_buff[3]; // TODO(bunnei): Implement event handling u32 event_handle = cmd_buff[3]; // TODO(bunnei): Implement event handling
cmd_buff[2] = g_thread_id; // ThreadID cmd_buff[2] = g_thread_id; // ThreadID
//TODO(bravia): Implement shared memory handling
} }
/// This triggers handling of the GX command written to the command buffer in shared memory. /// This triggers handling of the GX command written to the command buffer in shared memory.

View File

@ -6,14 +6,21 @@
#include "core/hle/hle.h" #include "core/hle/hle.h"
#include "core/hle/service/hid.h" #include "core/hle/service/hid.h"
#include "core/hle/kernel/shared_memory.h"
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
// Namespace HID_User // Namespace HID_User
namespace HID_User { namespace HID_User {
void GetIPCHandles(Service::Interface* self) {
u32* cmd_buff = Service::GetCommandBuffer();
Handle memHandle = Kernel::CreateSharedMemory();
cmd_buff[3] = memHandle; //TODO: return something coherent along with RegisterInterruptRelayQueue for mem handles
}
const Interface::FunctionInfo FunctionTable[] = { const Interface::FunctionInfo FunctionTable[] = {
{0x000A0000, NULL, "GetIPCHandles"}, {0x000A0000, GetIPCHandles, "GetIPCHandles" },
{0x00110000, NULL, "EnableAccelerometer"}, {0x00110000, NULL, "EnableAccelerometer"},
{0x00130000, NULL, "EnableGyroscopeLow"}, {0x00130000, NULL, "EnableGyroscopeLow"},
{0x00150000, NULL, "GetGyroscopeLowRawToDpsCoefficient"}, {0x00150000, NULL, "GetGyroscopeLowRawToDpsCoefficient"},

View File

@ -67,7 +67,7 @@ Result ControlMemory(void* _outaddr, u32 operation, u32 addr0, u32 addr1, u32 si
/// Maps a memory block to specified address /// Maps a memory block to specified address
Result MapMemoryBlock(Handle memblock, u32 addr, u32 mypermissions, u32 otherpermission) { Result MapMemoryBlock(Handle memblock, u32 addr, u32 mypermissions, u32 otherpermission) {
DEBUG_LOG(SVC, "MapMemoryBlock called memblock=0x08X, addr=0x%08X, mypermissions=0x%08X, otherpermission=%d", DEBUG_LOG(SVC, "MapMemoryBlock called memblock=0x%08X, addr=0x%08X, mypermissions=0x%08X, otherpermission=%d",
memblock, addr, mypermissions, otherpermission); memblock, addr, mypermissions, otherpermission);
switch (mypermissions) { switch (mypermissions) {
case MEMORY_PERMISSION_NORMAL: case MEMORY_PERMISSION_NORMAL:

View File

@ -1,6 +1,6 @@
#include "hid.h" #include "hid.h"
//TODO: http://pastebin.com/kkGLQhHV
namespace HID { namespace HID {
template <typename T> template <typename T>