emummc: update for exo2
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include "smc.h"
|
||||
#include "../utils/fatal.h"
|
||||
|
||||
void smcRebootToRcm(void)
|
||||
{
|
||||
@@ -117,45 +118,6 @@ Result smcReadWriteRegister(u32 phys_addr, u32 value, u32 mask)
|
||||
return rc;
|
||||
}
|
||||
|
||||
static Result _smcWriteAddress(void *dst_addr, u64 val, u32 size)
|
||||
{
|
||||
SecmonArgs args;
|
||||
args.X[0] = 0xF0000003; /* smcAmsWriteAddress */
|
||||
args.X[1] = (u64)dst_addr; /* DRAM address */
|
||||
args.X[2] = val; /* value */
|
||||
args.X[3] = size; /* Amount to write */
|
||||
Result rc = svcCallSecureMonitor(&args);
|
||||
if (rc == 0)
|
||||
{
|
||||
if (args.X[0] != 0)
|
||||
{
|
||||
/* SPL result n = SMC result n */
|
||||
rc = (26u | ((u32)args.X[0] << 9u));
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
Result smcWriteAddress8(void *dst_addr, u8 val)
|
||||
{
|
||||
return _smcWriteAddress(dst_addr, val, 1);
|
||||
}
|
||||
|
||||
Result smcWriteAddress16(void *dst_addr, u16 val)
|
||||
{
|
||||
return _smcWriteAddress(dst_addr, val, 2);
|
||||
}
|
||||
|
||||
Result smcWriteAddress32(void *dst_addr, u32 val)
|
||||
{
|
||||
return _smcWriteAddress(dst_addr, val, 4);
|
||||
}
|
||||
|
||||
Result smcWriteAddress64(void *dst_addr, u64 val)
|
||||
{
|
||||
return _smcWriteAddress(dst_addr, val, 8);
|
||||
}
|
||||
|
||||
Result smcGetEmummcConfig(exo_emummc_mmc_t mmc_id, exo_emummc_config_t *out_cfg, void *out_paths)
|
||||
{
|
||||
SecmonArgs args;
|
||||
@@ -177,4 +139,38 @@ Result smcGetEmummcConfig(exo_emummc_mmc_t mmc_id, exo_emummc_config_t *out_cfg,
|
||||
}
|
||||
return rc;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Result smcGenerateRandomBytes(void *dst, u32 size)
|
||||
{
|
||||
SecmonArgs args;
|
||||
args.X[0] = 0xC3000006; /* smcGenerateRandomBytes */
|
||||
args.X[1] = size;
|
||||
Result rc = svcCallSecureMonitor(&args);
|
||||
if (rc == 0)
|
||||
{
|
||||
if (args.X[0] != 0)
|
||||
{
|
||||
/* SPL result n = SMC result n */
|
||||
rc = (26u | ((u32)args.X[0] << 9u));
|
||||
}
|
||||
if (rc == 0)
|
||||
{
|
||||
memcpy(dst, &args.X[1], size);
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
u64 smcGenerateRandomU64(void)
|
||||
{
|
||||
u64 random;
|
||||
|
||||
Result rc = smcGenerateRandomBytes(&random, sizeof(random));
|
||||
if (rc != 0)
|
||||
{
|
||||
fatal_abort(Fatal_BadResult);
|
||||
}
|
||||
|
||||
return random;
|
||||
}
|
||||
|
||||
@@ -78,13 +78,11 @@ Result smcCopyFromIram(void *dst_addr, uintptr_t iram_addr, u32 size);
|
||||
|
||||
Result smcReadWriteRegister(u32 phys_addr, u32 value, u32 mask);
|
||||
|
||||
Result smcWriteAddress8(void *dst_addr, u8 val);
|
||||
Result smcWriteAddress16(void *dst_addr, u16 val);
|
||||
Result smcWriteAddress32(void *dst_addr, u32 val);
|
||||
Result smcWriteAddress64(void *dst_addr, u64 val);
|
||||
|
||||
Result smcGetEmummcConfig(exo_emummc_mmc_t mmc_id, exo_emummc_config_t *out_cfg, void *out_paths);
|
||||
|
||||
Result smcGenerateRandomBytes(void *dst, u32 size);
|
||||
u64 smcGenerateRandomU64(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -106,6 +106,104 @@ Result svcSetProcessMemoryPermission(Handle proc, u64 addr, u64 size, u32 perm);
|
||||
*/
|
||||
Result svcSetMemoryPermission(void* addr, u64 size, u32 perm);
|
||||
|
||||
/**
|
||||
* @brief Creates a thread.
|
||||
* @return Result code.
|
||||
* @note Syscall number 0x08.
|
||||
*/
|
||||
Result svcCreateThread(Handle* out, void* entry, void* arg, void* stack_top, int prio, int cpuid);
|
||||
|
||||
/**
|
||||
* @brief Starts a freshly created thread.
|
||||
* @return Result code.
|
||||
* @note Syscall number 0x09.
|
||||
*/
|
||||
Result svcStartThread(Handle handle);
|
||||
|
||||
/**
|
||||
* @brief Exits the current thread.
|
||||
* @note Syscall number 0x0A.
|
||||
*/
|
||||
void __attribute__((noreturn)) svcExitThread(void);
|
||||
|
||||
/**
|
||||
* @brief Closes a handle, decrementing the reference count of the corresponding kernel object.
|
||||
* This might result in the kernel freeing the object.
|
||||
* @param handle Handle to close.
|
||||
* @return Result code.
|
||||
* @note Syscall number 0x16.
|
||||
*/
|
||||
Result svcCloseHandle(Handle handle);
|
||||
|
||||
/**
|
||||
* @brief Waits on one or more synchronization objects, optionally with a timeout.
|
||||
* @return Result code.
|
||||
* @note Syscall number 0x18.
|
||||
* @note \p handleCount must not be greater than \ref MAX_WAIT_OBJECTS. This is a Horizon kernel limitation.
|
||||
* @note This is the raw syscall, which can be cancelled by \ref svcCancelSynchronization or other means. \ref waitHandles or \ref waitMultiHandle should normally be used instead.
|
||||
*/
|
||||
Result svcWaitSynchronization(s32* index, const Handle* handles, s32 handleCount, u64 timeout);
|
||||
|
||||
/**
|
||||
* @brief Waits on a single synchronization object, optionally with a timeout.
|
||||
* @return Result code.
|
||||
* @note Wrapper for \ref svcWaitSynchronization.
|
||||
* @note This is the raw syscall, which can be cancelled by \ref svcCancelSynchronization or other means. \ref waitSingleHandle should normally be used instead.
|
||||
*/
|
||||
static inline Result svcWaitSynchronizationSingle(Handle handle, u64 timeout) {
|
||||
s32 tmp;
|
||||
return svcWaitSynchronization(&tmp, &handle, 1, timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Creates an IPC session.
|
||||
* @return Result code.
|
||||
* @note Syscall number 0x40.
|
||||
* @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
|
||||
*/
|
||||
Result svcCreateSession(Handle *server_handle, Handle *client_handle, u32 unk0, u64 unk1);//unk* are normally 0?
|
||||
|
||||
/**
|
||||
* @brief Sends an IPC synchronization request to a session.
|
||||
* @return Result code.
|
||||
* @note Syscall number 0x21.
|
||||
*/
|
||||
Result svcSendSyncRequest(Handle session);
|
||||
|
||||
/**
|
||||
* @brief Performs IPC input/output.
|
||||
* @return Result code.
|
||||
* @note Syscall number 0x43.
|
||||
* @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
|
||||
*/
|
||||
Result svcReplyAndReceive(s32* index, const Handle* handles, s32 handleCount, Handle replyTarget, u64 timeout);
|
||||
|
||||
/**
|
||||
* @brief Maps the src address from the supplied process handle into the current process.
|
||||
* @param[in] dst Address to which map the memory in the current process.
|
||||
* @param[in] proc Process handle.
|
||||
* @param[in] src Source mapping address.
|
||||
* @param[in] size Size of the memory.
|
||||
* @return Result code.
|
||||
* @remark This allows mapping code and rodata with RW- permission.
|
||||
* @note Syscall number 0x74.
|
||||
* @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
|
||||
*/
|
||||
Result svcMapProcessMemory(void* dst, Handle proc, u64 src, u64 size);
|
||||
|
||||
/**
|
||||
* @brief Undoes the effects of \ref svcMapProcessMemory.
|
||||
* @param[in] dst Destination mapping address
|
||||
* @param[in] proc Process handle.
|
||||
* @param[in] src Address of the memory in the process.
|
||||
* @param[in] size Size of the memory.
|
||||
* @return Result code.
|
||||
* @remark This allows mapping code and rodata with RW- permission.
|
||||
* @note Syscall number 0x75.
|
||||
* @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
|
||||
*/
|
||||
Result svcUnmapProcessMemory(void* dst, Handle proc, u64 src, u64 size);
|
||||
|
||||
/**
|
||||
* @brief Calls a secure monitor function (TrustZone, EL3).
|
||||
* @param regs Arguments to pass to the secure monitor.
|
||||
|
||||
@@ -56,6 +56,69 @@ SVC_BEGIN svcSetProcessMemoryPermission
|
||||
RET
|
||||
SVC_END
|
||||
|
||||
SVC_BEGIN svcCreateThread
|
||||
STR X0, [SP, #-16]!
|
||||
SVC 0x8
|
||||
LDR X2, [SP], #16
|
||||
STR W1, [X2]
|
||||
RET
|
||||
SVC_END
|
||||
|
||||
SVC_BEGIN svcStartThread
|
||||
SVC 0x9
|
||||
RET
|
||||
SVC_END
|
||||
|
||||
SVC_BEGIN svcExitThread
|
||||
SVC 0xA
|
||||
RET
|
||||
SVC_END
|
||||
|
||||
SVC_BEGIN svcCloseHandle
|
||||
SVC 0x16
|
||||
RET
|
||||
SVC_END
|
||||
|
||||
SVC_BEGIN svcWaitSynchronization
|
||||
STR X0, [SP, #-16]!
|
||||
SVC 0x18
|
||||
LDR X2, [SP], #16
|
||||
STR W1, [X2]
|
||||
RET
|
||||
SVC_END
|
||||
|
||||
SVC_BEGIN svcCreateSession
|
||||
STP X0, X1, [SP, #-16]!
|
||||
SVC 0x40
|
||||
LDP X3, X4, [SP], #16
|
||||
STR W1, [X3]
|
||||
STR W2, [X4]
|
||||
RET
|
||||
SVC_END
|
||||
|
||||
SVC_BEGIN svcSendSyncRequest
|
||||
SVC 0x21
|
||||
RET
|
||||
SVC_END
|
||||
|
||||
SVC_BEGIN svcReplyAndReceive
|
||||
STR X0, [SP, #-16]!
|
||||
SVC 0x43
|
||||
LDR X2, [SP], #16
|
||||
STR W1, [X2]
|
||||
RET
|
||||
SVC_END
|
||||
|
||||
SVC_BEGIN svcMapProcessMemory
|
||||
SVC 0x74
|
||||
RET
|
||||
SVC_END
|
||||
|
||||
SVC_BEGIN svcUnmapProcessMemory
|
||||
SVC 0x75
|
||||
RET
|
||||
SVC_END
|
||||
|
||||
SVC_BEGIN svcCallSecureMonitor
|
||||
STR X0, [SP, #-16]!
|
||||
MOV X8, X0
|
||||
|
||||
Reference in New Issue
Block a user