restructured hle:services completely to use function lookup tables
This commit is contained in:
parent
386dd722e7
commit
ffabed8c25
|
@ -10,9 +10,18 @@
|
|||
|
||||
namespace APT_U {
|
||||
|
||||
const HLE::FunctionDef APT_U_Table[] = {
|
||||
{0x00010040, NULL, "GetLockHandle"},
|
||||
{0x00020080, NULL, "Initialize"},
|
||||
void Initialize() {
|
||||
NOTICE_LOG(OSHLE, "APT_U::Sync - Initialize");
|
||||
}
|
||||
|
||||
void GetLockHandle() {
|
||||
u32* cmd_buff = (u32*)HLE::GetPointer(HLE::CMD_BUFFER_ADDR + Service::kCommandHeaderOffset);
|
||||
cmd_buff[5] = 0x00000000; // TODO: This should be an actual mutex handle
|
||||
}
|
||||
|
||||
const HLE::FunctionDef FunctionTable[] = {
|
||||
{0x00010040, GetLockHandle, "GetLockHandle"},
|
||||
{0x00020080, Initialize, "Initialize"},
|
||||
{0x00030040, NULL, "Enable"},
|
||||
{0x00040040, NULL, "Finalize"},
|
||||
{0x00050040, NULL, "GetAppletManInfo"},
|
||||
|
@ -91,37 +100,14 @@ const HLE::FunctionDef APT_U_Table[] = {
|
|||
{0x004E0000, NULL, "HardwareResetAsync"},
|
||||
};
|
||||
|
||||
// Returns handle to APT Mutex. Not imlemented.
|
||||
Syscall::Result Interface::GetLockHandle() {
|
||||
return 0x00000000;
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Interface class
|
||||
|
||||
Interface::Interface() {
|
||||
Register(FunctionTable, ARRAY_SIZE(FunctionTable));
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when svcSendSyncRequest is called, loads command buffer and executes comand
|
||||
* @return Return result of svcSendSyncRequest passed back to user app
|
||||
*/
|
||||
Syscall::Result Interface::Sync() {
|
||||
Syscall::Result res = 0;
|
||||
u32* cmd_buff = (u32*)HLE::GetPointer(HLE::CMD_BUFFER_ADDR + CMD_OFFSET);
|
||||
|
||||
switch(cmd_buff[0]) {
|
||||
case CMD_HEADER_INIT:
|
||||
NOTICE_LOG(OSHLE, "APT_U::Sync - Initialize");
|
||||
break;
|
||||
|
||||
case CMD_HEADER_GET_LOCK_HANDLE:
|
||||
NOTICE_LOG(OSHLE, "APT_U::Sync - GetLockHandle");
|
||||
cmd_buff[5] = GetLockHandle();
|
||||
break;
|
||||
|
||||
default:
|
||||
ERROR_LOG(OSHLE, "APT_U::Sync - Unknown command 0x%08X", cmd_buff[0]);
|
||||
res = -1;
|
||||
break;
|
||||
Interface::~Interface() {
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
} // namespace
|
||||
|
|
|
@ -20,29 +20,9 @@ namespace APT_U {
|
|||
class Interface : public Service::Interface {
|
||||
public:
|
||||
|
||||
Interface() {
|
||||
}
|
||||
Interface();
|
||||
|
||||
~Interface() {
|
||||
}
|
||||
|
||||
enum {
|
||||
CMD_OFFSET = 0x00000080,
|
||||
|
||||
CMD_HEADER_INIT = 0x00020080, ///< Initialize service
|
||||
CMD_HEADER_GET_LOCK_HANDLE = 0x00010040, ///< Get service Mutex
|
||||
CMD_HEADER_ENABLE = 0x00030040, ///< Enable service
|
||||
CMD_HEADER_INQUIRE_NOTIFICATION = 0x000B0040, ///< Inquire notification
|
||||
CMD_HEADER_PREPARE_TO_JUMP_TO_HOME_MENU = 0x002B0000, ///< Prepare to jump to home menu
|
||||
CMD_HEADER_JUMP_TO_HOME_MENU = 0x002C0044, ///< Jump to home menu
|
||||
CMD_HEADER_NOTIFY_TO_WAIT = 0x00430040, ///< Notify to wait
|
||||
CMD_HEADER_APPLET_UTILITY = 0x004B00C2, ///< Applet utility
|
||||
CMD_HEADER_GLANCE_PARAMETER = 0x000E0080, ///< Glance parameter
|
||||
CMD_HEADER_RECEIVE_PARAMETER = 0x000D0080, ///< Receive parameter
|
||||
CMD_HEADER_REPLY_SLEEP_QUERY = 0x003E0080, ///< Reply sleep query
|
||||
CMD_HEADER_PREPARE_TO_CLOSE_APP = 0x00220040, ///< Prepare to close application
|
||||
CMD_HEADER_CLOSE_APP = 0x00270044, ///< Close application
|
||||
};
|
||||
~Interface();
|
||||
|
||||
/**
|
||||
* Gets the string port name used by CTROS for the APT service
|
||||
|
@ -52,12 +32,6 @@ public:
|
|||
return "APT:U";
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when svcSendSyncRequest is called, loads command buffer and executes comand
|
||||
* @return Return result of svcSendSyncRequest passed back to user app
|
||||
*/
|
||||
Syscall::Result Sync();
|
||||
|
||||
private:
|
||||
|
||||
Syscall::Result GetLockHandle();
|
||||
|
|
|
@ -19,6 +19,8 @@ namespace Service {
|
|||
|
||||
typedef s32 NativeUID; ///< Native handle for a service
|
||||
|
||||
static const int kCommandHeaderOffset = 0x80; ///< Offset into command buffer of header
|
||||
|
||||
class Manager;
|
||||
|
||||
/// Interface to a CTROS service
|
||||
|
@ -26,6 +28,9 @@ class Interface {
|
|||
friend class Manager;
|
||||
public:
|
||||
|
||||
Interface() {
|
||||
}
|
||||
|
||||
virtual ~Interface() {
|
||||
}
|
||||
|
||||
|
@ -49,7 +54,24 @@ public:
|
|||
* Called when svcSendSyncRequest is called, loads command buffer and executes comand
|
||||
* @return Return result of svcSendSyncRequest passed back to user app
|
||||
*/
|
||||
virtual Syscall::Result Sync() = 0;
|
||||
Syscall::Result Sync() {
|
||||
u32* cmd_buff = (u32*)HLE::GetPointer(HLE::CMD_BUFFER_ADDR + kCommandHeaderOffset);
|
||||
auto itr = m_functions.find(cmd_buff[0]);
|
||||
|
||||
if (itr == m_functions.end()) {
|
||||
ERROR_LOG(OSHLE, "Unknown/unimplemented function: port=%s, command=0x%08X!",
|
||||
GetPortName().c_str(), cmd_buff[0]);
|
||||
return -1;
|
||||
}
|
||||
if (itr->second.func == NULL) {
|
||||
ERROR_LOG(OSHLE, "Unimplemented function: port=%s, name=%s!",
|
||||
GetPortName().c_str(), itr->second.name.c_str());
|
||||
}
|
||||
|
||||
itr->second.func();
|
||||
|
||||
return 0; // TODO: Implement return from actual function
|
||||
}
|
||||
|
||||
protected:
|
||||
/**
|
||||
|
@ -64,6 +86,8 @@ protected:
|
|||
private:
|
||||
u32 m_uid;
|
||||
std::map<u32, HLE::FunctionDef> m_functions;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(Interface);
|
||||
};
|
||||
|
||||
/// Simple class to manage accessing services from ports and UID handles
|
||||
|
|
55
src/core/hle/service/srv.cpp
Normal file
55
src/core/hle/service/srv.cpp
Normal file
|
@ -0,0 +1,55 @@
|
|||
// Copyright 2014 Citra Emulator Project
|
||||
// Licensed under GPLv2
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "core/hle/hle.h"
|
||||
#include "core/hle/service/srv.h"
|
||||
#include "core/hle/service/service.h"
|
||||
|
||||
|
||||
namespace SRV {
|
||||
|
||||
void Initialize() {
|
||||
NOTICE_LOG(OSHLE, "SRV::Sync - Initialize");
|
||||
}
|
||||
|
||||
void GetServiceHandle() {
|
||||
Syscall::Result res = 0;
|
||||
u32* cmd_buff = (u32*)HLE::GetPointer(HLE::CMD_BUFFER_ADDR + Service::kCommandHeaderOffset);
|
||||
|
||||
const char* port_name = (const char*)&cmd_buff[1];
|
||||
Service::Interface* service = Service::g_manager->FetchFromPortName(port_name);
|
||||
|
||||
NOTICE_LOG(OSHLE, "SRV::Sync - GetHandle - port: %s, handle: 0x%08X", port_name,
|
||||
service->GetUID());
|
||||
|
||||
if (NULL != service) {
|
||||
cmd_buff[3] = service->GetUID();
|
||||
} else {
|
||||
ERROR_LOG(OSHLE, "Service %s does not exist", port_name);
|
||||
res = -1;
|
||||
}
|
||||
cmd_buff[1] = res;
|
||||
|
||||
//return res;
|
||||
}
|
||||
|
||||
const HLE::FunctionDef FunctionTable[] = {
|
||||
{0x00010002, Initialize, "Initialize"},
|
||||
{0x00020000, NULL, "GetProcSemaphore"},
|
||||
{0x00030100, NULL, "RegisterService"},
|
||||
{0x000400C0, NULL, "UnregisterService"},
|
||||
{0x00050100, GetServiceHandle, "GetServiceHandle"},
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Interface class
|
||||
|
||||
Interface::Interface() {
|
||||
Register(FunctionTable, ARRAY_SIZE(FunctionTable));
|
||||
}
|
||||
|
||||
Interface::~Interface() {
|
||||
}
|
||||
|
||||
} // namespace
|
39
src/core/hle/service/srv.h
Normal file
39
src/core/hle/service/srv.h
Normal file
|
@ -0,0 +1,39 @@
|
|||
// Copyright 2014 Citra Emulator Project
|
||||
// Licensed under GPLv2
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "core/hle/service/service.h"
|
||||
|
||||
namespace SRV {
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Interface to "SRV" service
|
||||
|
||||
class Interface : public Service::Interface {
|
||||
|
||||
public:
|
||||
|
||||
Interface();
|
||||
|
||||
~Interface();
|
||||
|
||||
/**
|
||||
* Gets the string name used by CTROS for a service
|
||||
* @return Port name of service
|
||||
*/
|
||||
std::string GetPortName() const {
|
||||
return "srv:";
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when svcSendSyncRequest is called, loads command buffer and executes comand
|
||||
* @return Return result of svcSendSyncRequest passed back to user app
|
||||
*/
|
||||
Syscall::Result Sync();
|
||||
|
||||
private:
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(Interface);
|
||||
};
|
||||
|
||||
} // namespace
|
Loading…
Reference in a new issue