Merge branch 'threading'

This commit is contained in:
bunnei 2014-06-01 10:42:51 -04:00
commit f299e29c17
32 changed files with 729 additions and 234 deletions

View File

@ -259,14 +259,17 @@ void ConsoleListener::Log(LogTypes::LOG_LEVELS Level, const char *Text)
switch (Level)
{
case OS_LEVEL: // light yellow
Color = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY;
break;
case NOTICE_LEVEL: // light green
Color = FOREGROUND_GREEN | FOREGROUND_INTENSITY;
break;
case ERROR_LEVEL: // light red
Color = FOREGROUND_RED | FOREGROUND_INTENSITY;
break;
case WARNING_LEVEL: // light yellow
Color = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY;
case WARNING_LEVEL: // light purple
Color = FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY;
break;
case INFO_LEVEL: // cyan
Color = FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY;
@ -278,15 +281,8 @@ void ConsoleListener::Log(LogTypes::LOG_LEVELS Level, const char *Text)
Color = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
break;
}
if (strlen(Text) > 10)
{
// First 10 chars white
SetConsoleTextAttribute(hConsole, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
WriteConsole(hConsole, Text, 10, &cCharsWritten, NULL);
Text += 10;
}
SetConsoleTextAttribute(hConsole, Color);
WriteConsole(hConsole, Text, (DWORD)strlen(Text), &cCharsWritten, NULL);
printf(Text);
#else
char ColorAttr[16] = "";
char ResetAttr[16] = "";

View File

@ -7,11 +7,14 @@
#define LOGGING
#define NOTICE_LEVEL 1 // VERY important information that is NOT errors. Like startup and OSReports.
#define ERROR_LEVEL 2 // Critical errors
#define WARNING_LEVEL 3 // Something is suspicious.
#define INFO_LEVEL 4 // General information.
#define DEBUG_LEVEL 5 // Detailed debugging - might make things slow.
enum {
OS_LEVEL, // Printed by the emulated operating system
NOTICE_LEVEL, // VERY important information that is NOT errors. Like startup and OSReports.
ERROR_LEVEL, // Critical errors
WARNING_LEVEL, // Something is suspicious.
INFO_LEVEL, // General information.
DEBUG_LEVEL, // Detailed debugging - might make things slow.
};
namespace LogTypes
{
@ -70,6 +73,7 @@ enum LOG_TYPE {
// FIXME: should this be removed?
enum LOG_LEVELS {
LOS = OS_LEVEL,
LNOTICE = NOTICE_LEVEL,
LERROR = ERROR_LEVEL,
LWARNING = WARNING_LEVEL,
@ -82,8 +86,8 @@ enum LOG_LEVELS {
} // namespace
void GenericLog(LOGTYPES_LEVELS level, LOGTYPES_TYPE type,
const char *file, int line, const char *fmt, ...)
void GenericLog(LOGTYPES_LEVELS level, LOGTYPES_TYPE type, const char*file, int line,
const char* function, const char* fmt, ...)
#ifdef __GNUC__
__attribute__((format(printf, 5, 6)))
#endif
@ -97,16 +101,19 @@ void GenericLog(LOGTYPES_LEVELS level, LOGTYPES_TYPE type,
#endif // loglevel
#endif // logging
#ifdef GEKKO
#define GENERIC_LOG(t, v, ...)
#else
#ifdef _WIN32
#ifndef __func__
#define __func__ __FUNCTION__
#endif
#endif
// Let the compiler optimize this out
#define GENERIC_LOG(t, v, ...) { \
if (v <= MAX_LOGLEVEL) \
GenericLog(v, t, __FILE__, __LINE__, __VA_ARGS__); \
GenericLog(v, t, __FILE__, __LINE__, __func__, __VA_ARGS__); \
}
#endif
#define OS_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LOS, __VA_ARGS__) } while (0)
#define ERROR_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LERROR, __VA_ARGS__) } while (0)
#define WARN_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LWARNING, __VA_ARGS__) } while (0)
#define NOTICE_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LNOTICE, __VA_ARGS__) } while (0)

View File

@ -10,14 +10,16 @@
#include "common/thread.h"
#include "common/file_util.h"
void GenericLog(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type,
const char *file, int line, const char* fmt, ...)
void GenericLog(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, const char* file, int line,
const char* function, const char* fmt, ...)
{
va_list args;
va_start(args, fmt);
if (LogManager::GetInstance())
if (LogManager::GetInstance()) {
LogManager::GetInstance()->Log(level, type,
file, line, fmt, args);
file, line, function, fmt, args);
}
va_end(args);
}
@ -88,6 +90,8 @@ LogManager::LogManager()
m_Log[i]->AddListener(m_debuggerLog);
#endif
}
m_consoleLog->Open();
}
LogManager::~LogManager()
@ -107,8 +111,8 @@ LogManager::~LogManager()
delete m_debuggerLog;
}
void LogManager::Log(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type,
const char *file, int line, const char *format, va_list args)
void LogManager::Log(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, const char* file,
int line, const char* function, const char *fmt, va_list args)
{
char temp[MAX_MSGLEN];
char msg[MAX_MSGLEN * 2];
@ -117,17 +121,15 @@ void LogManager::Log(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type,
if (!log->IsEnabled() || level > log->GetLevel() || ! log->HasListeners())
return;
CharArrayFromFormatV(temp, MAX_MSGLEN, format, args);
CharArrayFromFormatV(temp, MAX_MSGLEN, fmt, args);
static const char level_to_char[7] = "ONEWID";
sprintf(msg, "%s %s:%u %c[%s] %s: %s\n", Common::Timer::GetTimeFormatted().c_str(), file, line,
level_to_char[(int)level], log->GetShortName(), function, temp);
static const char level_to_char[7] = "-NEWID";
sprintf(msg, "%s %s:%u %c[%s]: %s\n",
Common::Timer::GetTimeFormatted().c_str(),
file, line, level_to_char[(int)level],
log->GetShortName(), temp);
#ifdef ANDROID
Host_SysMessage(msg);
#endif
printf(msg); // TODO(ShizZy): RemoveMe when I no longer need this
log->Trigger(level, msg);
}

View File

@ -99,8 +99,8 @@ public:
static u32 GetMaxLevel() { return MAX_LOGLEVEL; }
void Log(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type,
const char *file, int line, const char *fmt, va_list args);
void Log(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, const char* file, int line,
const char* function, const char *fmt, va_list args);
void SetLogLevel(LogTypes::LOG_TYPE type, LogTypes::LOG_LEVELS level)
{

View File

@ -34,12 +34,14 @@ set(SRCS core.cpp
hle/config_mem.cpp
hle/coprocessor.cpp
hle/svc.cpp
hle/kernel/event.cpp
hle/kernel/kernel.cpp
hle/kernel/mutex.cpp
hle/kernel/thread.cpp
hle/service/apt.cpp
hle/service/gsp.cpp
hle/service/hid.cpp
hle/service/ndm.cpp
hle/service/service.cpp
hle/service/srv.cpp
hw/hw.cpp

View File

@ -4533,23 +4533,7 @@ ARMul_Emulate26 (ARMul_State * state)
case 0xfd:
case 0xfe:
case 0xff:
if (instr == ARMul_ABORTWORD
&& state->AbortAddr == pc) {
/* A prefetch abort. */
XScale_set_fsr_far (state,
ARMul_CP15_R5_MMU_EXCPT,
pc);
ARMul_Abort (state,
ARMul_PrefetchAbortV);
break;
}
//sky_pref_t* pref = get_skyeye_pref();
//if(pref->user_mode_sim){
// ARMul_OSHandleSWI (state, BITS (0, 23));
// break;
//}
HLE::CallSVC(instr);
ARMul_Abort (state, ARMul_SWIV);
break;
}
}

View File

@ -9,6 +9,7 @@
#include "core/core.h"
#include "core/mem_map.h"
#include "core/hw/hw.h"
#include "core/hw/lcd.h"
#include "core/arm/disassembler/arm_disasm.h"
#include "core/arm/interpreter/arm_interpreter.h"
@ -23,7 +24,7 @@ ARM_Interface* g_sys_core = NULL; ///< ARM11 system (OS) core
/// Run the core CPU loop
void RunLoop() {
for (;;){
g_app_core->Run(100);
g_app_core->Run(LCD::kFrameTicks / 2);
HW::Update();
Kernel::Reschedule();
}
@ -31,9 +32,17 @@ void RunLoop() {
/// Step the CPU one instruction
void SingleStep() {
static int ticks = 0;
g_app_core->Step();
if (ticks >= LCD::kFrameTicks / 2) {
HW::Update();
Kernel::Reschedule();
ticks = 0;
} else {
ticks++;
}
}
/// Halt the core

View File

@ -168,12 +168,14 @@
<ClCompile Include="hle\config_mem.cpp" />
<ClCompile Include="hle\coprocessor.cpp" />
<ClCompile Include="hle\hle.cpp" />
<ClCompile Include="hle\kernel\event.cpp" />
<ClCompile Include="hle\kernel\kernel.cpp" />
<ClCompile Include="hle\kernel\mutex.cpp" />
<ClCompile Include="hle\kernel\thread.cpp" />
<ClCompile Include="hle\service\apt.cpp" />
<ClCompile Include="hle\service\gsp.cpp" />
<ClCompile Include="hle\service\hid.cpp" />
<ClCompile Include="hle\service\ndm.cpp" />
<ClCompile Include="hle\service\service.cpp" />
<ClCompile Include="hle\service\srv.cpp" />
<ClCompile Include="hle\svc.cpp" />
@ -217,12 +219,14 @@
<ClInclude Include="hle\coprocessor.h" />
<ClInclude Include="hle\function_wrappers.h" />
<ClInclude Include="hle\hle.h" />
<ClInclude Include="hle\kernel\event.h" />
<ClInclude Include="hle\kernel\kernel.h" />
<ClInclude Include="hle\kernel\mutex.h" />
<ClInclude Include="hle\kernel\thread.h" />
<ClInclude Include="hle\service\apt.h" />
<ClInclude Include="hle\service\gsp.h" />
<ClInclude Include="hle\service\hid.h" />
<ClInclude Include="hle\service\ndm.h" />
<ClInclude Include="hle\service\service.h" />
<ClInclude Include="hle\service\srv.h" />
<ClInclude Include="hle\svc.h" />

View File

@ -165,6 +165,12 @@
<ClCompile Include="arm\interpreter\armcopro.cpp">
<Filter>arm\interpreter</Filter>
</ClCompile>
<ClCompile Include="hle\kernel\event.cpp">
<Filter>hle\kernel</Filter>
</ClCompile>
<ClCompile Include="hle\service\ndm.cpp">
<Filter>hle\service</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="arm\disassembler\arm_disasm.h">
@ -295,6 +301,12 @@
<ClInclude Include="hle\kernel\mutex.h">
<Filter>hle\kernel</Filter>
</ClInclude>
<ClInclude Include="hle\kernel\event.h">
<Filter>hle\kernel</Filter>
</ClInclude>
<ClInclude Include="hle\service\ndm.h">
<Filter>hle\service</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Text Include="CMakeLists.txt" />

View File

@ -55,7 +55,7 @@ inline void Read(T &var, const u32 addr) {
break;
default:
ERROR_LOG(HLE, "unknown ConfigMem::Read%d @ 0x%08X", sizeof(var) * 8, addr);
ERROR_LOG(HLE, "unknown addr=0x%08X", addr);
}
}

View File

@ -627,6 +627,10 @@ template<void func(const char*)> void WrapV_C() {
func(Memory::GetCharPointer(PARAM(0)));
}
template<void func(s64)> void WrapV_S64() {
func(((s64)PARAM(1) << 32) | PARAM(0));
}
template<void func(const char *, int)> void WrapV_CI() {
func(Memory::GetCharPointer(PARAM(0)), PARAM(1));
}
@ -735,11 +739,17 @@ template<int func(void*, u32, u32, u32, u32, u32)> void WrapI_VUUUUU(){
}
template<int func(u32, s64)> void WrapI_US64() {
int retval = func(PARAM(0), PARAM64(1));
int retval = func(PARAM(0), (((u64)PARAM(3) << 32) | PARAM(2)));
RETURN(retval);
}
template<int func(void*, void*, u32, u32, s64)> void WrapI_VVUUS64() {
int retval = func(Memory::GetPointer(PARAM(0)), Memory::GetPointer(PARAM(1)), PARAM(2), PARAM(3), PARAM(4));
int retval = func(Memory::GetPointer(PARAM(5)), Memory::GetPointer(PARAM(1)), PARAM(2), PARAM(3), (((u64)PARAM(4) << 32) | PARAM(0)));
RETURN(retval);
}
// TODO(bunne): Is this correct? Probably not
template<int func(u32, u32, u32, u32, s64)> void WrapI_UUUUS64() {
int retval = func(PARAM(5), PARAM(1), PARAM(2), PARAM(3), (((u64)PARAM(4) << 32) | PARAM(0)));
RETURN(retval);
}

View File

@ -18,7 +18,7 @@ static std::vector<ModuleDef> g_module_db;
const FunctionDef* GetSVCInfo(u32 opcode) {
u32 func_num = opcode & 0xFFFFFF; // 8 bits
if (func_num > 0xFF) {
ERROR_LOG(HLE,"Unknown SVC: 0x%02X", func_num);
ERROR_LOG(HLE,"unknown svc=0x%02X", func_num);
return NULL;
}
return &g_module_db[0].func_table[func_num];
@ -33,7 +33,7 @@ void CallSVC(u32 opcode) {
if (info->func) {
info->func();
} else {
ERROR_LOG(HLE, "Unimplemented SVC function %s(..)", info->name.c_str());
ERROR_LOG(HLE, "unimplemented SVC function %s(..)", info->name.c_str());
}
}
@ -43,7 +43,7 @@ void EatCycles(u32 cycles) {
void ReSchedule(const char *reason) {
#ifdef _DEBUG
_dbg_assert_msg_(HLE, reason != 0 && strlen(reason) < 256, "ReSchedule: Invalid or too long reason.");
_dbg_assert_msg_(HLE, reason != 0 && strlen(reason) < 256, "Reschedule: Invalid or too long reason.");
#endif
// TODO: ImplementMe
}

View File

@ -10,7 +10,6 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
#define PARAM(n) Core::g_app_core->GetReg(n)
#define PARAM64(n) (Core::g_app_core->GetReg(n) | ((u64)Core::g_app_core->GetReg(n + 1) << 32))
#define RETURN(n) Core::g_app_core->SetReg(0, n)
////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -0,0 +1,126 @@
// 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/event.h"
namespace Kernel {
class Event : public Object {
public:
const char* GetTypeName() { return "Event"; }
static Kernel::HandleType GetStaticHandleType() { return Kernel::HandleType::Event; }
Kernel::HandleType GetHandleType() const { return Kernel::HandleType::Event; }
ResetType intitial_reset_type; ///< ResetType specified at Event initialization
ResetType reset_type; ///< Current ResetType
bool locked; ///< Current locked state
bool permanent_locked; ///< Hack - to set event permanent state (for easy passthrough)
/**
* Synchronize kernel object
* @param wait Boolean wait set if current thread should wait as a result of sync operation
* @return Result of operation, 0 on success, otherwise error code
*/
Result SyncRequest(bool* wait) {
// TODO(bunnei): ImplementMe
ERROR_LOG(KERNEL, "(UMIMPLEMENTED) call");
return 0;
}
/**
* Wait for kernel object to synchronize
* @param wait Boolean wait set if current thread should wait as a result of sync operation
* @return Result of operation, 0 on success, otherwise error code
*/
Result WaitSynchronization(bool* wait) {
// TODO(bunnei): ImplementMe
*wait = locked;
if (reset_type != RESETTYPE_STICKY && !permanent_locked) {
locked = true;
}
return 0;
}
};
/**
* Changes whether an event is locked or not
* @param handle Handle to event to change
* @param locked Boolean locked value to set event
* @return Result of operation, 0 on success, otherwise error code
*/
Result SetEventLocked(const Handle handle, const bool locked) {
Event* evt = g_object_pool.GetFast<Event>(handle);
if (!evt) {
ERROR_LOG(KERNEL, "called with unknown handle=0x%08X", handle);
return -1;
}
if (!evt->permanent_locked) {
evt->locked = locked;
}
return 0;
}
/**
* Hackish function to set an events permanent lock state, used to pass through synch blocks
* @param handle Handle to event to change
* @param permanent_locked Boolean permanent locked value to set event
* @return Result of operation, 0 on success, otherwise error code
*/
Result SetPermanentLock(Handle handle, const bool permanent_locked) {
Event* evt = g_object_pool.GetFast<Event>(handle);
if (!evt) {
ERROR_LOG(KERNEL, "called with unknown handle=0x%08X", handle);
return -1;
}
evt->permanent_locked = permanent_locked;
return 0;
}
/**
* Clears an event
* @param handle Handle to event to clear
* @return Result of operation, 0 on success, otherwise error code
*/
Result ClearEvent(Handle handle) {
return SetEventLocked(handle, true);
}
/**
* Creates an event
* @param handle Reference to handle for the newly created mutex
* @param reset_type ResetType describing how to create event
* @return Newly created Event object
*/
Event* CreateEvent(Handle& handle, const ResetType reset_type) {
Event* evt = new Event;
handle = Kernel::g_object_pool.Create(evt);
evt->locked = true;
evt->permanent_locked = false;
evt->reset_type = evt->intitial_reset_type = reset_type;
return evt;
}
/**
* Creates an event
* @param reset_type ResetType describing how to create event
* @return Handle to newly created Event object
*/
Handle CreateEvent(const ResetType reset_type) {
Handle handle;
Event* evt = CreateEvent(handle, reset_type);
return handle;
}
} // namespace

View File

@ -0,0 +1,44 @@
// 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"
#include "core/hle/svc.h"
namespace Kernel {
/**
* Changes whether an event is locked or not
* @param handle Handle to event to change
* @param locked Boolean locked value to set event
* @return Result of operation, 0 on success, otherwise error code
*/
Result SetEventLocked(const Handle handle, const bool locked);
/**
* Hackish function to set an events permanent lock state, used to pass through synch blocks
* @param handle Handle to event to change
* @param permanent_locked Boolean permanent locked value to set event
* @return Result of operation, 0 on success, otherwise error code
*/
Result SetPermanentLock(Handle handle, const bool permanent_locked);
/**
* Clears an event
* @param handle Handle to event to clear
* @return Result of operation, 0 on success, otherwise error code
*/
Result ClearEvent(Handle handle);
/**
* Creates an event
* @param reset_type ResetType describing how to create event
* @return Handle to newly created Event object
*/
Handle CreateEvent(const ResetType reset_type);
} // namespace

View File

@ -11,6 +11,11 @@ typedef s32 Result;
namespace Kernel {
enum KernelHandle {
CurrentThread = 0xFFFF8000,
CurrentProcess = 0xFFFF8001,
};
enum class HandleType : u32 {
Unknown = 0,
Port = 1,
@ -42,6 +47,21 @@ public:
virtual const char *GetTypeName() { return "[BAD KERNEL OBJECT TYPE]"; }
virtual const char *GetName() { return "[UNKNOWN KERNEL OBJECT]"; }
virtual Kernel::HandleType GetHandleType() const = 0;
/**
* Synchronize kernel object
* @param wait Boolean wait set if current thread should wait as a result of sync operation
* @return Result of operation, 0 on success, otherwise error code
*/
virtual Result SyncRequest(bool* wait) = 0;
/**
* Wait for kernel object to synchronize
* @param wait Boolean wait set if current thread should wait as a result of sync operation
* @return Result of operation, 0 on success, otherwise error code
*/
virtual Result WaitSynchronization(bool* wait) = 0;
};
class ObjectPool : NonCopyable {

View File

@ -8,6 +8,7 @@
#include "common/common.h"
#include "core/hle/kernel/kernel.h"
#include "core/hle/kernel/mutex.h"
#include "core/hle/kernel/thread.h"
namespace Kernel {
@ -23,6 +24,28 @@ public:
bool locked; ///< Current locked state
Handle lock_thread; ///< Handle to thread that currently has mutex
std::vector<Handle> waiting_threads; ///< Threads that are waiting for the mutex
/**
* Synchronize kernel object
* @param wait Boolean wait set if current thread should wait as a result of sync operation
* @return Result of operation, 0 on success, otherwise error code
*/
Result SyncRequest(bool* wait) {
// TODO(bunnei): ImplementMe
locked = true;
return 0;
}
/**
* Wait for kernel object to synchronize
* @param wait Boolean wait set if current thread should wait as a result of sync operation
* @return Result of operation, 0 on success, otherwise error code
*/
Result WaitSynchronization(bool* wait) {
// TODO(bunnei): ImplementMe
*wait = locked;
return 0;
}
};
////////////////////////////////////////////////////////////////////////////////////////////////////
@ -70,10 +93,11 @@ bool ReleaseMutexForThread(Mutex* mutex, Handle thread) {
bool ReleaseMutex(Mutex* mutex) {
MutexEraseLock(mutex);
bool woke_threads = false;
auto iter = mutex->waiting_threads.begin();
std::vector<Handle>::iterator iter;
// Find the next waiting thread for the mutex...
while (!woke_threads && !mutex->waiting_threads.empty()) {
iter = mutex->waiting_threads.begin();
woke_threads |= ReleaseMutexForThread(mutex, *iter);
mutex->waiting_threads.erase(iter);
}
@ -91,6 +115,9 @@ bool ReleaseMutex(Mutex* mutex) {
*/
Result ReleaseMutex(Handle handle) {
Mutex* mutex = Kernel::g_object_pool.GetFast<Mutex>(handle);
_assert_msg_(KERNEL, mutex, "ReleaseMutex tried to release a NULL mutex!");
if (!ReleaseMutex(mutex)) {
return -1;
}
@ -101,6 +128,7 @@ Result ReleaseMutex(Handle handle) {
* Creates a mutex
* @param handle Reference to handle for the newly created mutex
* @param initial_locked Specifies if the mutex should be locked initially
* @return Pointer to new Mutex object
*/
Mutex* CreateMutex(Handle& handle, bool initial_locked) {
Mutex* mutex = new Mutex;

View File

@ -13,13 +13,14 @@ namespace Kernel {
/**
* Releases a mutex
* @param handle Handle to mutex to release
* @return Result of operation, 0 on success, otherwise error code
*/
Result ReleaseMutex(Handle handle);
/**
* Creates a mutex
* @param handle Reference to handle for the newly created mutex
* @param initial_locked Specifies if the mutex should be locked initially
* @return Handle to newly created object
*/
Handle CreateMutex(bool initial_locked);

View File

@ -36,6 +36,26 @@ public:
inline bool IsWaiting() const { return (status & THREADSTATUS_WAIT) != 0; }
inline bool IsSuspended() const { return (status & THREADSTATUS_SUSPEND) != 0; }
/**
* Synchronize kernel object
* @param wait Boolean wait set if current thread should wait as a result of sync operation
* @return Result of operation, 0 on success, otherwise error code
*/
Result SyncRequest(bool* wait) {
// TODO(bunnei): ImplementMe
return 0;
}
/**
* Wait for kernel object to synchronize
* @param wait Boolean wait set if current thread should wait as a result of sync operation
* @return Result of operation, 0 on success, otherwise error code
*/
Result WaitSynchronization(bool* wait) {
// TODO(bunnei): ImplementMe
return 0;
}
ThreadContext context;
u32 status;
@ -303,11 +323,29 @@ void Reschedule() {
Thread* prev = GetCurrentThread();
Thread* next = NextThread();
if (next > 0) {
INFO_LOG(KERNEL, "context switch 0x%08X -> 0x%08X", prev->GetHandle(), next->GetHandle());
SwitchContext(next);
// Hack - automatically change previous thread (which would have been in "wait" state) to
// "ready" state, so that we can immediately resume to it when new thread yields. FixMe to
// actually wait for whatever event it is supposed to be waiting on.
ChangeReadyState(prev, true);
} else {
INFO_LOG(KERNEL, "no ready threads, staying on 0x%08X", prev->GetHandle());
// Hack - no other threads are available, so decrement current PC to the last instruction,
// and then resume current thread. This should always be called on a blocking instruction
// (e.g. svcWaitSynchronization), and the result should be that the instruction is repeated
// until it no longer blocks.
// TODO(bunnei): A better solution: Have the CPU switch to an idle thread
ThreadContext ctx;
SaveContext(ctx);
ctx.pc -= 4;
LoadContext(ctx);
ChangeReadyState(prev, true);
}
}

View File

@ -6,6 +6,7 @@
#include "common/common.h"
#include "core/hle/hle.h"
#include "core/hle/kernel/event.h"
#include "core/hle/kernel/mutex.h"
#include "core/hle/service/apt.h"
@ -15,7 +16,16 @@
namespace APT_U {
void Initialize(Service::Interface* self) {
NOTICE_LOG(OSHLE, "APT_U::Sync - Initialize");
u32* cmd_buff = Service::GetCommandBuffer();
DEBUG_LOG(KERNEL, "called");
cmd_buff[3] = Kernel::CreateEvent(RESETTYPE_ONESHOT); // APT menu event handle
cmd_buff[4] = Kernel::CreateEvent(RESETTYPE_ONESHOT); // APT pause event handle
Kernel::SetEventLocked(cmd_buff[3], true);
Kernel::SetEventLocked(cmd_buff[4], false); // Fire start event
cmd_buff[1] = 0; // No error
}
void GetLockHandle(Service::Interface* self) {
@ -23,13 +33,28 @@ void GetLockHandle(Service::Interface* self) {
u32 flags = cmd_buff[1]; // TODO(bunnei): Figure out the purpose of the flag field
cmd_buff[1] = 0; // No error
cmd_buff[5] = Kernel::CreateMutex(false);
DEBUG_LOG(KERNEL, "APT_U::GetLockHandle called : created handle 0x%08X", cmd_buff[5]);
DEBUG_LOG(KERNEL, "called handle=0x%08X", cmd_buff[5]);
}
void Enable(Service::Interface* self) {
u32* cmd_buff = Service::GetCommandBuffer();
u32 unk = cmd_buff[1]; // TODO(bunnei): What is this field used for?
cmd_buff[1] = 0; // No error
ERROR_LOG(KERNEL, "(UNIMPEMENTED) called unk=0x%08X", unk);
}
void InquireNotification(Service::Interface* self) {
u32* cmd_buff = Service::GetCommandBuffer();
u32 app_id = cmd_buff[2];
cmd_buff[1] = 0; // No error
cmd_buff[3] = 0; // Signal type
ERROR_LOG(KERNEL, "(UNIMPEMENTED) called app_id=0x%08X", app_id);
}
const Interface::FunctionInfo FunctionTable[] = {
{0x00010040, GetLockHandle, "GetLockHandle"},
{0x00020080, Initialize, "Initialize"},
{0x00030040, NULL, "Enable"},
{0x00030040, Enable, "Enable"},
{0x00040040, NULL, "Finalize"},
{0x00050040, NULL, "GetAppletManInfo"},
{0x00060040, NULL, "GetAppletInfo"},
@ -37,7 +62,7 @@ const Interface::FunctionInfo FunctionTable[] = {
{0x00080000, NULL, "CountRegisteredApplet"},
{0x00090040, NULL, "IsRegistered"},
{0x000A0040, NULL, "GetAttribute"},
{0x000B0040, NULL, "InquireNotification"},
{0x000B0040, InquireNotification, "InquireNotification"},
{0x000C0104, NULL, "SendParameter"},
{0x000D0080, NULL, "ReceiveParameter"},
{0x000E0080, NULL, "GlanceParameter"},

View File

@ -8,6 +8,7 @@
#include "core/mem_map.h"
#include "core/hle/hle.h"
#include "core/hle/kernel/event.h"
#include "core/hle/service/gsp.h"
#include "core/hw/lcd.h"
@ -52,6 +53,7 @@ void GX_FinishCommand(u32 thread_id) {
namespace GSP_GPU {
Handle g_event_handle = 0;
u32 g_thread_id = 0;
enum {
@ -92,7 +94,7 @@ void ReadHWRegs(Service::Interface* self) {
break;
default:
ERROR_LOG(GSP, "ReadHWRegs unknown register read at address %08X", reg_addr);
ERROR_LOG(GSP, "unknown register read at address %08X", reg_addr);
}
}
@ -100,7 +102,20 @@ void ReadHWRegs(Service::Interface* self) {
void RegisterInterruptRelayQueue(Service::Interface* self) {
u32* cmd_buff = Service::GetCommandBuffer();
u32 flags = cmd_buff[1];
u32 event_handle = cmd_buff[3]; // TODO(bunnei): Implement event handling
u32 event_handle = cmd_buff[3];
_assert_msg_(GSP, event_handle, "called, but event is NULL!");
g_event_handle = event_handle;
Kernel::SetEventLocked(event_handle, false);
// Hack - This function will permanently set the state of the GSP event such that GPU command
// synchronization barriers always passthrough. Correct solution would be to set this after the
// GPU as processed all queued up commands, but due to the emulator being single-threaded they
// will always be ready.
Kernel::SetPermanentLock(event_handle, true);
cmd_buff[2] = g_thread_id; // ThreadID
}
@ -117,7 +132,7 @@ void TriggerCmdReqQueue(Service::Interface* self) {
break;
default:
ERROR_LOG(GSP, "TriggerCmdReqQueue unknown command 0x%08X", cmd_buff[0]);
ERROR_LOG(GSP, "unknown command 0x%08X", cmd_buff[0]);
}
GX_FinishCommand(g_thread_id);

View File

@ -0,0 +1,32 @@
// Copyright 2014 Citra Emulator Project
// Licensed under GPLv2
// Refer to the license.txt file included.
#include "common/log.h"
#include "core/hle/hle.h"
#include "core/hle/service/ndm.h"
////////////////////////////////////////////////////////////////////////////////////////////////////
// Namespace NDM_U
namespace NDM_U {
const Interface::FunctionInfo FunctionTable[] = {
{0x00060040, NULL, "SuspendDaemons"},
{0x00080040, NULL, "DisableWifiUsage"},
{0x00090000, NULL, "EnableWifiUsage"},
{0x00140040, NULL, "OverrideDefaultDaemons"},
};
////////////////////////////////////////////////////////////////////////////////////////////////////
// Interface class
Interface::Interface() {
Register(FunctionTable, ARRAY_SIZE(FunctionTable));
}
Interface::~Interface() {
}
} // namespace

View File

@ -0,0 +1,33 @@
// Copyright 2014 Citra Emulator Project
// Licensed under GPLv2
// Refer to the license.txt file included.
#pragma once
#include "core/hle/service/service.h"
////////////////////////////////////////////////////////////////////////////////////////////////////
// Namespace NDM
// No idea what this is
namespace NDM_U {
class Interface : public Service::Interface {
public:
Interface();
~Interface();
/**
* Gets the string port name used by CTROS for the service
* @return Port name of service
*/
const char *GetPortName() const {
return "ndm:u";
}
};
} // namespace

View File

@ -12,6 +12,7 @@
#include "core/hle/service/apt.h"
#include "core/hle/service/gsp.h"
#include "core/hle/service/hid.h"
#include "core/hle/service/ndm.h"
#include "core/hle/service/srv.h"
#include "core/hle/kernel/kernel.h"
@ -72,14 +73,15 @@ void Init() {
g_manager->AddService(new APT_U::Interface);
g_manager->AddService(new GSP_GPU::Interface);
g_manager->AddService(new HID_User::Interface);
g_manager->AddService(new NDM_U::Interface);
NOTICE_LOG(HLE, "Services initialized OK");
NOTICE_LOG(HLE, "initialized OK");
}
/// Shutdown ServiceManager
void Shutdown() {
delete g_manager;
NOTICE_LOG(HLE, "Services shutdown OK");
NOTICE_LOG(HLE, "shutdown OK");
}

View File

@ -76,22 +76,31 @@ public:
}
/**
* Called when svcSendSyncRequest is called, loads command buffer and executes comand
* @return Return result of svcSendSyncRequest passed back to user app
* Synchronize kernel object
* @param wait Boolean wait set if current thread should wait as a result of sync operation
* @return Result of operation, 0 on success, otherwise error code
*/
Result Sync() {
Result SyncRequest(bool* wait) {
u32* cmd_buff = GetCommandBuffer();
auto itr = m_functions.find(cmd_buff[0]);
if (itr == m_functions.end()) {
ERROR_LOG(OSHLE, "Unknown/unimplemented function: port = %s, command = 0x%08X!",
ERROR_LOG(OSHLE, "unknown/unimplemented function: port=%s, command=0x%08X",
GetPortName(), cmd_buff[0]);
return -1;
// TODO(bunnei): Hack - ignore error
u32* cmd_buff = Service::GetCommandBuffer();
cmd_buff[1] = 0;
return 0;
}
if (itr->second.func == NULL) {
ERROR_LOG(OSHLE, "Unimplemented function: port = %s, name = %s!",
ERROR_LOG(OSHLE, "unimplemented function: port=%s, name=%s",
GetPortName(), itr->second.name.c_str());
return -1;
// TODO(bunnei): Hack - ignore error
u32* cmd_buff = Service::GetCommandBuffer();
cmd_buff[1] = 0;
return 0;
}
itr->second.func(this);
@ -99,6 +108,16 @@ public:
return 0; // TODO: Implement return from actual function
}
/**
* Wait for kernel object to synchronize
* @param wait Boolean wait set if current thread should wait as a result of sync operation
* @return Result of operation, 0 on success, otherwise error code
*/
Result WaitSynchronization(bool* wait) {
// TODO(bunnei): ImplementMe
return 0;
}
protected:
/**

View File

@ -5,21 +5,28 @@
#include "core/hle/hle.h"
#include "core/hle/service/srv.h"
#include "core/hle/service/service.h"
#include "core/hle/kernel/mutex.h"
////////////////////////////////////////////////////////////////////////////////////////////////////
// Namespace SRV
namespace SRV {
Handle g_mutex = 0;
void Initialize(Service::Interface* self) {
NOTICE_LOG(OSHLE, "SRV::Sync - Initialize");
DEBUG_LOG(OSHLE, "called");
if (!g_mutex) {
g_mutex = Kernel::CreateMutex(false);
}
}
void GetProcSemaphore(Service::Interface* self) {
DEBUG_LOG(OSHLE, "called");
// Get process semaphore?
u32* cmd_buff = Service::GetCommandBuffer();
cmd_buff[3] = 0xDEADBEEF; // Return something... 0 == NULL, raises an exception
cmd_buff[1] = 0; // No error
cmd_buff[3] = g_mutex; // Return something... 0 == NULL, raises an exception
}
void GetServiceHandle(Service::Interface* self) {
@ -29,18 +36,14 @@ void GetServiceHandle(Service::Interface* self) {
std::string port_name = std::string((const char*)&cmd_buff[1], 0, Service::kMaxPortSize);
Service::Interface* service = Service::g_manager->FetchFromPortName(port_name);
NOTICE_LOG(OSHLE, "SRV::Sync - GetHandle - port: %s, handle: 0x%08X", port_name.c_str(),
service->GetHandle());
if (NULL != service) {
cmd_buff[3] = service->GetHandle();
DEBUG_LOG(OSHLE, "called port=%s, handle=0x%08X", port_name.c_str(), cmd_buff[3]);
} else {
ERROR_LOG(OSHLE, "Service %s does not exist", port_name.c_str());
ERROR_LOG(OSHLE, "(UNIMPLEMENTED) called port=%s", port_name.c_str());
res = -1;
}
cmd_buff[1] = res;
//return res;
}
const Interface::FunctionInfo FunctionTable[] = {

View File

@ -26,12 +26,6 @@ public:
return "srv:";
}
/**
* Called when svcSendSyncRequest is called, loads command buffer and executes comand
* @return Return result of svcSendSyncRequest passed back to user app
*/
Result Sync();
};
} // namespace

View File

@ -9,6 +9,7 @@
#include "core/mem_map.h"
#include "core/hle/kernel/event.h"
#include "core/hle/kernel/kernel.h"
#include "core/hle/kernel/mutex.h"
#include "core/hle/kernel/thread.h"
@ -16,7 +17,6 @@
#include "core/hle/function_wrappers.h"
#include "core/hle/svc.h"
#include "core/hle/service/service.h"
#include "core/hle/kernel/thread.h"
////////////////////////////////////////////////////////////////////////////////////////////////////
// Namespace SVC
@ -35,10 +35,9 @@ enum MapMemoryPermission {
/// Map application or GSP heap memory
Result ControlMemory(void* _outaddr, u32 operation, u32 addr0, u32 addr1, u32 size, u32 permissions) {
u32* outaddr = (u32*)_outaddr;
u32 virtual_address = 0x00000000;
DEBUG_LOG(SVC, "ControlMemory called operation=0x%08X, addr0=0x%08X, addr1=0x%08X, size=%08X, permissions=0x%08X",
DEBUG_LOG(SVC,"called operation=0x%08X, addr0=0x%08X, addr1=0x%08X, size=%08X, permissions=0x%08X",
operation, addr0, addr1, size, permissions);
switch (operation) {
@ -55,11 +54,9 @@ Result ControlMemory(void* _outaddr, u32 operation, u32 addr0, u32 addr1, u32 si
// Unknown ControlMemory operation
default:
ERROR_LOG(SVC, "ControlMemory unknown operation=0x%08X", operation);
}
if (NULL != outaddr) {
*outaddr = virtual_address;
ERROR_LOG(SVC, "unknown operation=0x%08X", operation);
}
Core::g_app_core->SetReg(1, virtual_address);
return 0;
@ -67,7 +64,7 @@ Result ControlMemory(void* _outaddr, u32 operation, u32 addr0, u32 addr1, u32 si
/// Maps a memory block to specified address
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, "called memblock=0x08X, addr=0x%08X, mypermissions=0x%08X, otherpermission=%d",
memblock, addr, mypermissions, otherpermission);
switch (mypermissions) {
case MEMORY_PERMISSION_NORMAL:
@ -76,72 +73,139 @@ Result MapMemoryBlock(Handle memblock, u32 addr, u32 mypermissions, u32 otherper
Memory::MapBlock_Shared(memblock, addr, mypermissions);
break;
default:
ERROR_LOG(OSHLE, "MapMemoryBlock unknown permissions=0x%08X", mypermissions);
ERROR_LOG(OSHLE, "unknown permissions=0x%08X", mypermissions);
}
return 0;
}
/// Connect to an OS service given the port name, returns the handle to the port to out
Result ConnectToPort(void* out, const char* port_name) {
Result ConnectToPort(void* _out, const char* port_name) {
Service::Interface* service = Service::g_manager->FetchFromPortName(port_name);
if (service) {
DEBUG_LOG(SVC, "called port_name=%s", port_name);
_assert_msg_(KERNEL, service, "called, but service is not implemented!");
Core::g_app_core->SetReg(1, service->GetHandle());
} else {
PanicYesNo("ConnectToPort called port_name=%s, but it is not implemented!", port_name);
}
DEBUG_LOG(SVC, "ConnectToPort called port_name=%s", port_name);
return 0;
}
/// Synchronize to an OS service
Result SendSyncRequest(Handle handle) {
DEBUG_LOG(SVC, "SendSyncRequest called handle=0x%08X");
Service::Interface* service = Service::g_manager->FetchFromHandle(handle);
service->Sync();
return 0;
bool wait = false;
Kernel::Object* object = Kernel::g_object_pool.GetFast<Kernel::Object>(handle);
DEBUG_LOG(SVC, "called handle=0x%08X", handle);
_assert_msg_(KERNEL, object, "called, but kernel object is NULL!");
Result res = object->SyncRequest(&wait);
if (wait) {
Kernel::WaitCurrentThread(WAITTYPE_SYNCH); // TODO(bunnei): Is this correct?
}
return res;
}
/// Close a handle
Result CloseHandle(Handle handle) {
// ImplementMe
DEBUG_LOG(SVC, "(UNIMPLEMENTED) CloseHandle called handle=0x%08X", handle);
ERROR_LOG(SVC, "(UNIMPLEMENTED) called handle=0x%08X", handle);
return 0;
}
/// Wait for a handle to synchronize, timeout after the specified nanoseconds
Result WaitSynchronization1(Handle handle, s64 nano_seconds) {
DEBUG_LOG(SVC, "(UNIMPLEMENTED) WaitSynchronization1 called handle=0x%08X, nanoseconds=%d",
handle, nano_seconds);
// TODO(bunnei): Do something with nano_seconds, currently ignoring this
bool wait = false;
Kernel::Object* object = Kernel::g_object_pool.GetFast<Kernel::Object>(handle);
DEBUG_LOG(SVC, "called handle=0x%08X, nanoseconds=%d", handle,
nano_seconds);
_assert_msg_(KERNEL, object, "called, but kernel object is NULL!");
Result res = object->WaitSynchronization(&wait);
if (wait) {
Kernel::WaitCurrentThread(WAITTYPE_SYNCH); // TODO(bunnei): Is this correct?
return 0;
Kernel::Reschedule();
// Context switch - Function blocked, is not actually returning (will be "called" again)
// TODO(bunnei): This saves handle to R0 so that it's correctly reloaded on context switch
// (otherwise R0 will be set to whatever is returned, and handle will be invalid when this
// thread is resumed). There is probably a better way of keeping track of state so that we
// don't necessarily have to do this.
return (Result)PARAM(0);
}
return res;
}
/// Wait for the given handles to synchronize, timeout after the specified nanoseconds
Result WaitSynchronizationN(void* _out, void* _handles, u32 handle_count, u32 wait_all, s64 nano_seconds) {
s32* out = (s32*)_out;
Handle* handles = (Handle*)_handles;
Result WaitSynchronizationN(void* _out, void* _handles, u32 handle_count, u32 wait_all,
s64 nano_seconds) {
// TODO(bunnei): Do something with nano_seconds, currently ignoring this
DEBUG_LOG(SVC, "(UNIMPLEMENTED) WaitSynchronizationN called handle_count=%d, wait_all=%s, nanoseconds=%d %s",
Handle* handles = (Handle*)_handles;
bool unlock_all = true;
DEBUG_LOG(SVC, "called handle_count=%d, wait_all=%s, nanoseconds=%d",
handle_count, (wait_all ? "true" : "false"), nano_seconds);
// Iterate through each handle, synchronize kernel object
for (u32 i = 0; i < handle_count; i++) {
DEBUG_LOG(SVC, "\thandle[%d]=0x%08X", i, handles[i]);
}
Kernel::WaitCurrentThread(WAITTYPE_SYNCH); // TODO(bunnei): Is this correct?
bool wait = false;
Kernel::Object* object = Kernel::g_object_pool.GetFast<Kernel::Object>(handles[i]); // 0 handle
_assert_msg_(KERNEL, object, "called handle=0x%08X, but kernel object "
"is NULL!", handles[i]);
DEBUG_LOG(SVC, "\thandle[%d] = 0x%08X", i, handles[i]);
Result res = object->WaitSynchronization(&wait);
if (!wait && !wait_all) {
Core::g_app_core->SetReg(1, i);
return 0;
} else {
unlock_all = false;
}
}
if (wait_all && unlock_all) {
Core::g_app_core->SetReg(1, handle_count);
return 0;
}
// Set current thread to wait state if not all handles were unlocked
Kernel::WaitCurrentThread(WAITTYPE_SYNCH); // TODO(bunnei): Is this correct?
Kernel::Reschedule();
// Context switch - Function blocked, is not actually returning (will be "called" again)
// TODO(bunnei): This saves handle to R0 so that it's correctly reloaded on context switch
// (otherwise R0 will be set to whatever is returned, and handle will be invalid when this
// thread is resumed). There is probably a better way of keeping track of state so that we
// don't necessarily have to do this.
return (Result)PARAM(0);
}
/// Create an address arbiter (to allocate access to shared resources)
Result CreateAddressArbiter(void* arbiter) {
// ImplementMe
DEBUG_LOG(SVC, "(UNIMPLEMENTED) CreateAddressArbiter called");
ERROR_LOG(SVC, "(UNIMPLEMENTED) called");
Core::g_app_core->SetReg(1, 0xFABBDADD);
return 0;
}
/// Arbitrate address
Result ArbitrateAddress(Handle arbiter, u32 addr, u32 _type, u32 value, s64 nanoseconds) {
ERROR_LOG(SVC, "(UNIMPLEMENTED) called");
ArbitrationType type = (ArbitrationType)_type;
Memory::Write32(addr, type);
return 0;
}
/// Used to output a message on a debug hardware unit - does nothing on a retail unit
void OutputDebugString(const char* string) {
NOTICE_LOG(SVC, "## OSDEBUG: %08X %s", Core::g_app_core->GetPC(), string);
OS_LOG(SVC, "%s", string);
}
/// Get resource limit
@ -149,15 +213,15 @@ Result GetResourceLimit(void* resource_limit, Handle process) {
// With regards to proceess values:
// 0xFFFF8001 is a handle alias for the current KProcess, and 0xFFFF8000 is a handle alias for
// the current KThread.
DEBUG_LOG(SVC, "(UNIMPLEMENTED) GetResourceLimit called process=0x%08X", process);
ERROR_LOG(SVC, "(UNIMPLEMENTED) called process=0x%08X", process);
Core::g_app_core->SetReg(1, 0xDEADBEEF);
return 0;
}
/// Get resource limit current values
Result GetResourceLimitCurrentValues(void* _values, Handle resource_limit, void* names, s32 name_count) {
//s64* values = (s64*)_values;
DEBUG_LOG(SVC, "(UNIMPLEMENTED) GetResourceLimitCurrentValues called resource_limit=%08X, names=%s, name_count=%d",
Result GetResourceLimitCurrentValues(void* _values, Handle resource_limit, void* names,
s32 name_count) {
ERROR_LOG(SVC, "(UNIMPLEMENTED) called resource_limit=%08X, names=%s, name_count=%d",
resource_limit, names, name_count);
Memory::Write32(Core::g_app_core->GetReg(0), 0); // Normmatt: Set used memory to 0 for now
return 0;
@ -180,8 +244,8 @@ Result CreateThread(u32 priority, u32 entry_point, u32 arg, u32 stack_top, u32 p
Core::g_app_core->SetReg(1, thread);
DEBUG_LOG(SVC, "CreateThread called entrypoint=0x%08X (%s), arg=0x%08X, stacktop=0x%08X, "
"threadpriority=0x%08X, processorid=0x%08X : created handle 0x%08X", entry_point,
DEBUG_LOG(SVC, "called entrypoint=0x%08X (%s), arg=0x%08X, stacktop=0x%08X, "
"threadpriority=0x%08X, processorid=0x%08X : created handle=0x%08X", entry_point,
name.c_str(), arg, stack_top, priority, processor_id, thread);
return 0;
@ -189,43 +253,61 @@ Result CreateThread(u32 priority, u32 entry_point, u32 arg, u32 stack_top, u32 p
/// Create a mutex
Result CreateMutex(void* _mutex, u32 initial_locked) {
Handle* mutex = (Handle*)_mutex;
*mutex = Kernel::CreateMutex((initial_locked != 0));
Core::g_app_core->SetReg(1, *mutex);
DEBUG_LOG(SVC, "CreateMutex called initial_locked=%s : created handle 0x%08X",
initial_locked ? "true" : "false", *mutex);
Handle mutex = Kernel::CreateMutex((initial_locked != 0));
Core::g_app_core->SetReg(1, mutex);
DEBUG_LOG(SVC, "called initial_locked=%s : created handle=0x%08X",
initial_locked ? "true" : "false", mutex);
return 0;
}
/// Release a mutex
Result ReleaseMutex(Handle handle) {
DEBUG_LOG(SVC, "ReleaseMutex called handle=0x%08X", handle);
DEBUG_LOG(SVC, "called handle=0x%08X", handle);
_assert_msg_(KERNEL, handle, "called, but handle is NULL!");
Kernel::ReleaseMutex(handle);
return 0;
}
/// Get current thread ID
Result GetThreadId(void* thread_id, u32 thread) {
DEBUG_LOG(SVC, "(UNIMPLEMENTED) GetThreadId called thread=0x%08X", thread);
ERROR_LOG(SVC, "(UNIMPLEMENTED) called thread=0x%08X", thread);
return 0;
}
/// Query memory
Result QueryMemory(void *_info, void *_out, u32 addr) {
MemoryInfo* info = (MemoryInfo*) _info;
PageInfo* out = (PageInfo*) _out;
DEBUG_LOG(SVC, "(UNIMPLEMENTED) QueryMemory called addr=0x%08X", addr);
ERROR_LOG(SVC, "(UNIMPLEMENTED) called addr=0x%08X", addr);
return 0;
}
/// Create an event
Result CreateEvent(void* _event, u32 reset_type) {
Handle* event = (Handle*)_event;
DEBUG_LOG(SVC, "(UNIMPLEMENTED) CreateEvent called reset_type=0x%08X", reset_type);
Core::g_app_core->SetReg(1, 0xBADC0DE0);
Handle evt = Kernel::CreateEvent((ResetType)reset_type);
Core::g_app_core->SetReg(1, evt);
DEBUG_LOG(SVC, "called reset_type=0x%08X : created handle=0x%08X",
reset_type, evt);
return 0;
}
/// Duplicates a kernel handle
Result DuplicateHandle(void* _out, Handle handle) {
Handle* out = (Handle*)_out;
ERROR_LOG(SVC, "(UNIMPLEMENTED) called handle=0x%08X", handle);
return 0;
}
/// Clears an event
Result ClearEvent(Handle evt) {
Result res = Kernel::ClearEvent(evt);
DEBUG_LOG(SVC, "called event=0x%08X", evt);
return res;
}
/// Sleep the current thread
void SleepThread(s64 nanoseconds) {
DEBUG_LOG(SVC, "called nanoseconds=%d", nanoseconds);
}
const HLE::FunctionDef SVC_Table[] = {
{0x00, NULL, "Unknown"},
{0x01, WrapI_VUUUUU<ControlMemory>, "ControlMemory"},
@ -237,7 +319,7 @@ const HLE::FunctionDef SVC_Table[] = {
{0x07, NULL, "SetProcessIdealProcessor"},
{0x08, WrapI_UUUUU<CreateThread>, "CreateThread"},
{0x09, NULL, "ExitThread"},
{0x0A, NULL, "SleepThread"},
{0x0A, WrapV_S64<SleepThread>, "SleepThread"},
{0x0B, NULL, "GetThreadPriority"},
{0x0C, NULL, "SetThreadPriority"},
{0x0D, NULL, "GetThreadAffinityMask"},
@ -252,7 +334,7 @@ const HLE::FunctionDef SVC_Table[] = {
{0x16, NULL, "ReleaseSemaphore"},
{0x17, WrapI_VU<CreateEvent>, "CreateEvent"},
{0x18, NULL, "SignalEvent"},
{0x19, NULL, "ClearEvent"},
{0x19, WrapI_U<ClearEvent>, "ClearEvent"},
{0x1A, NULL, "CreateTimer"},
{0x1B, NULL, "SetTimer"},
{0x1C, NULL, "CancelTimer"},
@ -261,12 +343,12 @@ const HLE::FunctionDef SVC_Table[] = {
{0x1F, WrapI_UUUU<MapMemoryBlock>, "MapMemoryBlock"},
{0x20, NULL, "UnmapMemoryBlock"},
{0x21, WrapI_V<CreateAddressArbiter>, "CreateAddressArbiter"},
{0x22, NULL, "ArbitrateAddress"},
{0x22, WrapI_UUUUS64<ArbitrateAddress>, "ArbitrateAddress"},
{0x23, WrapI_U<CloseHandle>, "CloseHandle"},
{0x24, WrapI_US64<WaitSynchronization1>, "WaitSynchronization1"},
{0x25, WrapI_VVUUS64<WaitSynchronizationN>, "WaitSynchronizationN"},
{0x26, NULL, "SignalAndWait"},
{0x27, NULL, "DuplicateHandle"},
{0x27, WrapI_VU<DuplicateHandle>, "DuplicateHandle"},
{0x28, NULL, "GetSystemTick"},
{0x29, NULL, "GetHandleInfo"},
{0x2A, NULL, "GetSystemInfo"},

View File

@ -38,6 +38,15 @@ enum ResetType {
RESETTYPE_MAX_BIT = (1u << 31),
};
enum ArbitrationType {
ARBITRATIONTYPE_SIGNAL,
ARBITRATIONTYPE_WAIT_IF_LESS_THAN,
ARBITRATIONTYPE_DECREMENT_AND_WAIT_IF_LESS_THAN,
ARBITRATIONTYPE_WAIT_IF_LESS_THAN_WITH_TIMEOUT,
ARBITRATIONTYPE_DECREMENT_AND_WAIT_IF_LESS_THAN_WITH_TIMEOUT,
ARBITRATIONTYPE_MAX_BIT = (1u << 31)
};
////////////////////////////////////////////////////////////////////////////////////////////////////
// Namespace SVC

View File

@ -17,8 +17,6 @@ namespace LCD {
Registers g_regs;
static const u32 kFrameTicks = 268123480 / 60; ///< 268MHz / 60 frames per second
u64 g_last_ticks = 0; ///< Last CPU ticks
/**

View File

@ -8,6 +8,8 @@
namespace LCD {
static const u32 kFrameTicks = 268123480 / 60; ///< 268MHz / 60 frames per second
struct Registers {
u32 framebuffer_top_left_1;
u32 framebuffer_top_left_2;

View File

@ -86,7 +86,7 @@ inline void _Read(T &var, const u32 addr) {
var = *((const T*)&g_vram[vaddr & VRAM_MASK]);
} else {
//_assert_msg_(MEMMAP, false, "unknown Read%d @ 0x%08X", sizeof(var) * 8, vaddr);
ERROR_LOG(MEMMAP, "unknown Read%d @ 0x%08X", sizeof(var) * 8, vaddr);
}
}
@ -136,8 +136,7 @@ inline void _Write(u32 addr, const T data) {
// Error out...
} else {
_assert_msg_(MEMMAP, false, "unknown Write%d 0x%08X @ 0x%08X", sizeof(data) * 8,
data, vaddr);
ERROR_LOG(MEMMAP, "unknown Write%d 0x%08X @ 0x%08X", sizeof(data) * 8, data, vaddr);
}
}