mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-06-05 17:14:22 -04:00
emummc: temp delete
This commit is contained in:
parent
b1a4a0db67
commit
e3cb5e74b9
112 changed files with 0 additions and 21966 deletions
41
emummc/source/nx/cache.h
vendored
41
emummc/source/nx/cache.h
vendored
|
@ -1,41 +0,0 @@
|
|||
/**
|
||||
* @file cache.h
|
||||
* @brief AArch64 cache operations.
|
||||
* @author plutoo
|
||||
* @copyright libnx Authors
|
||||
*/
|
||||
#pragma once
|
||||
#include "../utils/types.h"
|
||||
|
||||
/**
|
||||
* @brief Performs a data cache flush on the specified buffer.
|
||||
* @param addr Address of the buffer.
|
||||
* @param size Size of the buffer, in bytes.
|
||||
* @remarks Cache flush is defined as Clean + Invalidate.
|
||||
* @note The start and end addresses of the buffer are forcibly rounded to cache line boundaries (read from CTR_EL0 system register).
|
||||
*/
|
||||
void armDCacheFlush(void* addr, size_t size);
|
||||
|
||||
/**
|
||||
* @brief Performs a data cache clean on the specified buffer.
|
||||
* @param addr Address of the buffer.
|
||||
* @param size Size of the buffer, in bytes.
|
||||
* @note The start and end addresses of the buffer are forcibly rounded to cache line boundaries (read from CTR_EL0 system register).
|
||||
*/
|
||||
void armDCacheClean(void* addr, size_t size);
|
||||
|
||||
/**
|
||||
* @brief Performs an instruction cache invalidation clean on the specified buffer.
|
||||
* @param addr Address of the buffer.
|
||||
* @param size Size of the buffer, in bytes.
|
||||
* @note The start and end addresses of the buffer are forcibly rounded to cache line boundaries (read from CTR_EL0 system register).
|
||||
*/
|
||||
void armICacheInvalidate(void* addr, size_t size);
|
||||
|
||||
/**
|
||||
* @brief Performs a data cache zeroing operation on the specified buffer.
|
||||
* @param addr Address of the buffer.
|
||||
* @param size Size of the buffer, in bytes.
|
||||
* @note The start and end addresses of the buffer are forcibly rounded to cache line boundaries (read from CTR_EL0 system register).
|
||||
*/
|
||||
void armDCacheZero(void* addr, size_t size);
|
100
emummc/source/nx/cache.s
vendored
100
emummc/source/nx/cache.s
vendored
|
@ -1,100 +0,0 @@
|
|||
/**
|
||||
* @file cache.s
|
||||
* @copyright libnx Authors
|
||||
*/
|
||||
|
||||
.macro CODE_BEGIN name
|
||||
.section .text.\name, "ax", %progbits
|
||||
.global \name
|
||||
.type \name, %function
|
||||
.align 2
|
||||
.cfi_startproc
|
||||
\name:
|
||||
.endm
|
||||
|
||||
.macro CODE_END
|
||||
.cfi_endproc
|
||||
.endm
|
||||
|
||||
CODE_BEGIN armDCacheFlush
|
||||
add x1, x1, x0
|
||||
mrs x8, CTR_EL0
|
||||
lsr x8, x8, #16
|
||||
and x8, x8, #0xf
|
||||
mov x9, #4
|
||||
lsl x9, x9, x8
|
||||
sub x10, x9, #1
|
||||
bic x8, x0, x10
|
||||
mov x10, x1
|
||||
|
||||
armDCacheFlush_L0:
|
||||
dc civac, x8
|
||||
add x8, x8, x9
|
||||
cmp x8, x10
|
||||
bcc armDCacheFlush_L0
|
||||
|
||||
dsb sy
|
||||
ret
|
||||
CODE_END
|
||||
|
||||
CODE_BEGIN armDCacheClean
|
||||
add x1, x1, x0
|
||||
mrs x8, CTR_EL0
|
||||
lsr x8, x8, #16
|
||||
and x8, x8, #0xf
|
||||
mov x9, #4
|
||||
lsl x9, x9, x8
|
||||
sub x10, x9, #1
|
||||
bic x8, x0, x10
|
||||
mov x10, x1
|
||||
|
||||
armDCacheClean_L0:
|
||||
dc cvac, x8
|
||||
add x8, x8, x9
|
||||
cmp x8, x10
|
||||
bcc armDCacheClean_L0
|
||||
|
||||
dsb sy
|
||||
ret
|
||||
CODE_END
|
||||
|
||||
CODE_BEGIN armICacheInvalidate
|
||||
add x1, x1, x0
|
||||
mrs x8, CTR_EL0
|
||||
and x8, x8, #0xf
|
||||
mov x9, #4
|
||||
lsl x9, x9, x8
|
||||
sub x10, x9, #1
|
||||
bic x8, x0, x10
|
||||
mov x10, x1
|
||||
|
||||
armICacheInvalidate_L0:
|
||||
ic ivau, x8
|
||||
add x8, x8, x9
|
||||
cmp x8, x10
|
||||
bcc armICacheInvalidate_L0
|
||||
|
||||
dsb sy
|
||||
ret
|
||||
CODE_END
|
||||
|
||||
CODE_BEGIN armDCacheZero
|
||||
add x1, x1, x0
|
||||
mrs x8, CTR_EL0
|
||||
lsr x8, x8, #16
|
||||
and x8, x8, #0xf
|
||||
mov x9, #4
|
||||
lsl x9, x9, x8
|
||||
sub x10, x9, #1
|
||||
bic x8, x0, x10
|
||||
mov x10, x1
|
||||
|
||||
armDCacheZero_L0:
|
||||
dc zva, x8
|
||||
add x8, x8, x9
|
||||
cmp x8, x10
|
||||
bcc armDCacheZero_L0
|
||||
|
||||
dsb sy
|
||||
ret
|
||||
CODE_END
|
46
emummc/source/nx/counter.h
vendored
46
emummc/source/nx/counter.h
vendored
|
@ -1,46 +0,0 @@
|
|||
/**
|
||||
* @file counter.h
|
||||
* @brief AArch64 system counter-timer.
|
||||
* @author fincs
|
||||
* @copyright libnx Authors
|
||||
*/
|
||||
#pragma once
|
||||
#include "../utils/types.h"
|
||||
|
||||
/**
|
||||
* @brief Gets the current system tick.
|
||||
* @return The current system tick.
|
||||
*/
|
||||
static inline u64 armGetSystemTick(void) {
|
||||
u64 ret;
|
||||
__asm__ __volatile__ ("mrs %x[data], cntpct_el0" : [data] "=r" (ret));
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets the system counter-timer frequency
|
||||
* @return The system counter-timer frequency, in Hz.
|
||||
*/
|
||||
static inline u64 armGetSystemTickFreq(void) {
|
||||
u64 ret;
|
||||
__asm__ ("mrs %x[data], cntfrq_el0" : [data] "=r" (ret));
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Converts from nanoseconds to CPU ticks unit.
|
||||
* @param ns Time in nanoseconds.
|
||||
* @return Time in CPU ticks.
|
||||
*/
|
||||
static inline u64 armNsToTicks(u64 ns) {
|
||||
return (ns * 12) / 625;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Converts from CPU ticks unit to nanoseconds.
|
||||
* @param tick Time in ticks.
|
||||
* @return Time in nanoseconds.
|
||||
*/
|
||||
static inline u64 armTicksToNs(u64 tick) {
|
||||
return (tick * 625) / 12;
|
||||
}
|
45
emummc/source/nx/dynamic.c
vendored
45
emummc/source/nx/dynamic.c
vendored
|
@ -1,45 +0,0 @@
|
|||
/**
|
||||
* @file dynamic.c
|
||||
* @copyright libnx Authors
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include "../utils/types.h"
|
||||
#include <elf.h>
|
||||
|
||||
void __nx_dynamic(uintptr_t base, const Elf64_Dyn* dyn)
|
||||
{
|
||||
const Elf64_Rela* rela = NULL;
|
||||
u64 relasz = 0;
|
||||
|
||||
for (; dyn->d_tag != DT_NULL; dyn++)
|
||||
{
|
||||
switch (dyn->d_tag)
|
||||
{
|
||||
case DT_RELA:
|
||||
rela = (const Elf64_Rela*)(base + dyn->d_un.d_ptr);
|
||||
break;
|
||||
case DT_RELASZ:
|
||||
relasz = dyn->d_un.d_val / sizeof(Elf64_Rela);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (rela == NULL) {
|
||||
while(true)
|
||||
;
|
||||
}
|
||||
|
||||
for (; relasz--; rela++)
|
||||
{
|
||||
switch (ELF64_R_TYPE(rela->r_info))
|
||||
{
|
||||
case R_AARCH64_RELATIVE:
|
||||
{
|
||||
u64* ptr = (u64*)(base + rela->r_offset);
|
||||
*ptr = base + rela->r_addend;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
217
emummc/source/nx/smc.c
vendored
217
emummc/source/nx/smc.c
vendored
|
@ -1,217 +0,0 @@
|
|||
/**
|
||||
* @file smc.c
|
||||
* @copyright libnx Authors
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include "smc.h"
|
||||
#include "../utils/fatal.h"
|
||||
|
||||
void smcRebootToRcm(void)
|
||||
{
|
||||
SecmonArgs args;
|
||||
args.X[0] = 0xC3000401; /* smcSetConfig */
|
||||
args.X[1] = SplConfigItem_NeedsReboot; /* Exosphere reboot */
|
||||
args.X[3] = 1; /* Perform reboot to RCM. */
|
||||
svcCallSecureMonitor(&args);
|
||||
}
|
||||
|
||||
void smcRebootToIramPayload(void)
|
||||
{
|
||||
SecmonArgs args;
|
||||
args.X[0] = 0xC3000401; /* smcSetConfig */
|
||||
args.X[1] = SplConfigItem_NeedsReboot; /* Exosphere reboot */
|
||||
args.X[3] = 2; /* Perform reboot to payload at 0x40010000 in IRAM. */
|
||||
svcCallSecureMonitor(&args);
|
||||
}
|
||||
|
||||
void smcPerformShutdown(void)
|
||||
{
|
||||
SecmonArgs args;
|
||||
args.X[0] = 0xC3000401; /* smcSetConfig */
|
||||
args.X[1] = SplConfigItem_NeedsShutdown; /* Exosphere shutdown */
|
||||
args.X[3] = 1; /* Perform shutdown. */
|
||||
svcCallSecureMonitor(&args);
|
||||
}
|
||||
|
||||
Result smcGetConfig(SplConfigItem config_item, u64 *out_config)
|
||||
{
|
||||
SecmonArgs args;
|
||||
args.X[0] = 0xC3000002; /* smcGetConfig */
|
||||
args.X[1] = (u64)config_item; /* config item */
|
||||
Result rc = svcCallSecureMonitor(&args);
|
||||
if (rc == 0)
|
||||
{
|
||||
if (args.X[0] == 0)
|
||||
{
|
||||
if (out_config)
|
||||
{
|
||||
*out_config = args.X[1];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* SPL result n = SMC result n */
|
||||
rc = (26u | ((u32)args.X[0] << 9u));
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
SplHardwareType splGetHardwareType(void)
|
||||
{
|
||||
u64 value;
|
||||
Result rc = smcGetConfig(SplConfigItem_HardwareType, &value);
|
||||
if (rc != 0)
|
||||
{
|
||||
fatal_abort(Fatal_BadResult);
|
||||
}
|
||||
return (SplHardwareType)value;
|
||||
}
|
||||
|
||||
SplSocType splGetSocType(void)
|
||||
{
|
||||
static SplSocType soc_type;
|
||||
static bool soc_type_set = false;
|
||||
|
||||
if (soc_type_set)
|
||||
return soc_type;
|
||||
|
||||
switch (splGetHardwareType())
|
||||
{
|
||||
case SplHardwareType_Icosa:
|
||||
case SplHardwareType_Copper:
|
||||
soc_type = SplSocType_Erista;
|
||||
break;
|
||||
case SplHardwareType_Hoag:
|
||||
case SplHardwareType_Iowa:
|
||||
case SplHardwareType_Calcio:
|
||||
case SplHardwareType_Five:
|
||||
soc_type = SplSocType_Mariko;
|
||||
break;
|
||||
default:
|
||||
fatal_abort(Fatal_InvalidEnum);
|
||||
}
|
||||
|
||||
soc_type_set = true;
|
||||
|
||||
return soc_type;
|
||||
}
|
||||
|
||||
|
||||
Result smcCopyToIram(uintptr_t iram_addr, const void *src_addr, u32 size)
|
||||
{
|
||||
SecmonArgs args;
|
||||
args.X[0] = 0xF0000201; /* smcAmsIramCopy */
|
||||
args.X[1] = (u64)src_addr; /* DRAM address */
|
||||
args.X[2] = (u64)iram_addr; /* IRAM address */
|
||||
args.X[3] = size; /* Amount to copy */
|
||||
args.X[4] = 1; /* 1 = 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 smcCopyFromIram(void *dst_addr, uintptr_t iram_addr, u32 size)
|
||||
{
|
||||
SecmonArgs args;
|
||||
args.X[0] = 0xF0000201; /* smcAmsIramCopy */
|
||||
args.X[1] = (u64)dst_addr; /* DRAM address */
|
||||
args.X[2] = (u64)iram_addr; /* IRAM address */
|
||||
args.X[3] = size; /* Amount to copy */
|
||||
args.X[4] = 0; /* 0 = Read */
|
||||
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 smcReadWriteRegister(u32 phys_addr, u32 value, u32 mask)
|
||||
{
|
||||
SecmonArgs args;
|
||||
args.X[0] = 0xF0000002; /* smcAmsReadWriteRegister */
|
||||
args.X[1] = phys_addr; /* MMIO address */
|
||||
args.X[2] = mask; /* mask */
|
||||
args.X[3] = value; /* value */
|
||||
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 smcGetEmummcConfig(exo_emummc_mmc_t mmc_id, exo_emummc_config_t *out_cfg, void *out_paths)
|
||||
{
|
||||
SecmonArgs args;
|
||||
args.X[0] = 0xF0000404; /* smcAmsGetEmunandConfig */
|
||||
args.X[1] = mmc_id;
|
||||
args.X[2] = (u64)out_paths; /* out path */
|
||||
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(out_cfg, &args.X[1], sizeof(*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;
|
||||
}
|
105
emummc/source/nx/smc.h
vendored
105
emummc/source/nx/smc.h
vendored
|
@ -1,105 +0,0 @@
|
|||
/**
|
||||
* @file smc.h
|
||||
* @brief Wrappers for secure monitor calls.
|
||||
* @copyright libnx Authors
|
||||
*/
|
||||
#pragma once
|
||||
#include "../utils/types.h"
|
||||
#include "svc.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
SplConfigItem_DisableProgramVerification = 1,
|
||||
SplConfigItem_DramId = 2,
|
||||
SplConfigItem_SecurityEngineIrqNumber = 3,
|
||||
SplConfigItem_Version = 4,
|
||||
SplConfigItem_HardwareType = 5,
|
||||
SplConfigItem_IsRetail = 6,
|
||||
SplConfigItem_IsRecoveryBoot = 7,
|
||||
SplConfigItem_DeviceId = 8,
|
||||
SplConfigItem_BootReason = 9,
|
||||
SplConfigItem_MemoryArrange = 10,
|
||||
SplConfigItem_IsDebugMode = 11,
|
||||
SplConfigItem_KernelMemoryConfiguration = 12,
|
||||
SplConfigItem_IsChargerHiZModeEnabled = 13,
|
||||
SplConfigItem_IsKiosk = 14,
|
||||
SplConfigItem_NewHardwareType = 15,
|
||||
SplConfigItem_NewKeyGeneration = 16,
|
||||
SplConfigItem_Package2Hash = 17,
|
||||
|
||||
SplConfigItem_ExosphereVersion = 65000,
|
||||
SplConfigItem_NeedsReboot = 65001,
|
||||
SplConfigItem_NeedsShutdown = 65002,
|
||||
SplConfigItem_ExosphereVerHash = 65003,
|
||||
SplConfigItem_HasRcmBugPatch = 65004,
|
||||
} SplConfigItem;
|
||||
|
||||
typedef enum {
|
||||
SplSocType_Erista = 0,
|
||||
SplSocType_Mariko = 1,
|
||||
} SplSocType;
|
||||
|
||||
typedef enum {
|
||||
SplHardwareType_Icosa = 0,
|
||||
SplHardwareType_Copper = 1,
|
||||
SplHardwareType_Hoag = 2,
|
||||
SplHardwareType_Iowa = 3,
|
||||
SplHardwareType_Calcio = 4,
|
||||
SplHardwareType_Five = 5,
|
||||
} SplHardwareType;
|
||||
|
||||
typedef enum {
|
||||
EXO_EMUMMC_TYPE_NONE = 0,
|
||||
EXO_EMUMMC_TYPE_PARTITION = 1,
|
||||
EXO_EMUMMC_TYPE_FILES = 2,
|
||||
} exo_emummc_type_t;
|
||||
|
||||
typedef enum {
|
||||
EXO_EMUMMC_MMC_NAND = 0,
|
||||
EXO_EMUMMC_MMC_SD = 1,
|
||||
EXO_EMUMMC_MMC_GC = 2,
|
||||
} exo_emummc_mmc_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t magic;
|
||||
uint32_t type;
|
||||
uint32_t id;
|
||||
uint32_t fs_version;
|
||||
} exo_emummc_base_config_t;
|
||||
|
||||
typedef struct {
|
||||
uint64_t start_sector;
|
||||
} exo_emummc_partition_config_t;
|
||||
|
||||
typedef struct {
|
||||
exo_emummc_base_config_t base_cfg;
|
||||
union {
|
||||
exo_emummc_partition_config_t partition_cfg;
|
||||
};
|
||||
} exo_emummc_config_t;
|
||||
|
||||
Result smcGetConfig(SplConfigItem config_item, u64 *out_config);
|
||||
|
||||
SplHardwareType splGetHardwareType(void);
|
||||
SplSocType splGetSocType(void);
|
||||
|
||||
void smcRebootToRcm(void);
|
||||
void smcRebootToIramPayload(void);
|
||||
void smcPerformShutdown(void);
|
||||
|
||||
Result smcCopyToIram(uintptr_t iram_addr, const void *src_addr, u32 size);
|
||||
Result smcCopyFromIram(void *dst_addr, uintptr_t iram_addr, u32 size);
|
||||
|
||||
Result smcReadWriteRegister(u32 phys_addr, u32 value, u32 mask);
|
||||
|
||||
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
|
131
emummc/source/nx/start.s
vendored
131
emummc/source/nx/start.s
vendored
|
@ -1,131 +0,0 @@
|
|||
/**
|
||||
* @file start.s
|
||||
* @copyright libnx Authors
|
||||
*/
|
||||
|
||||
.macro push_all
|
||||
SUB SP, SP, #0x100
|
||||
STP X29, X30, [SP, #0x0]
|
||||
STP X27, X28, [SP, #0x10]
|
||||
STP X25, X26, [SP, #0x20]
|
||||
STP X23, X24, [SP, #0x30]
|
||||
STP X21, X22, [SP, #0x40]
|
||||
STP X19, X20, [SP, #0x50]
|
||||
STP X17, X18, [SP, #0x60]
|
||||
STP X15, X16, [SP, #0x70]
|
||||
STP X13, X14, [SP, #0x80]
|
||||
STP X11, X12, [SP, #0x90]
|
||||
STP X9, X10, [SP, #0xA0]
|
||||
STP X7, X8, [SP, #0xB0]
|
||||
STP X5, X6, [SP, #0xC0]
|
||||
STP X3, X4, [SP, #0xD0]
|
||||
STP X1, X2, [SP, #0xE0]
|
||||
STR X0, [SP, #0xF0]
|
||||
.endm
|
||||
|
||||
.macro pop_all
|
||||
LDR X0, [SP, #0xF0]
|
||||
LDP X1, X2, [SP, #0xE0]
|
||||
LDP X3, X4, [SP, #0xD0]
|
||||
LDP X5, X6, [SP, #0xC0]
|
||||
LDP X7, X8, [SP, #0xB0]
|
||||
LDP X9, X10, [SP, #0xA0]
|
||||
LDP X11, X12, [SP, #0x90]
|
||||
LDP X13, X14, [SP, #0x80]
|
||||
LDP X15, X16, [SP, #0x70]
|
||||
LDP X17, X18, [SP, #0x60]
|
||||
LDP X19, X20, [SP, #0x50]
|
||||
LDP X21, X22, [SP, #0x40]
|
||||
LDP X23, X24, [SP, #0x30]
|
||||
LDP X25, X26, [SP, #0x20]
|
||||
LDP X27, X28, [SP, #0x10]
|
||||
LDP X29, X30, [SP, #0x0]
|
||||
ADD SP, SP, #0x100
|
||||
.endm
|
||||
|
||||
.section ".crt0","ax"
|
||||
.global _start
|
||||
_start:
|
||||
B startup
|
||||
.org _start+0xc
|
||||
B sdmmc_wrapper_read
|
||||
.org _start+0x18
|
||||
B sdmmc_wrapper_write
|
||||
.org _start+0x80
|
||||
|
||||
.section ".crt0","ax"
|
||||
startup:
|
||||
# Save LR
|
||||
MOV X7, X30
|
||||
|
||||
# Retrieve ASLR Base
|
||||
BL +4
|
||||
SUB X6, X30, #0x88
|
||||
|
||||
# Context Ptr and MainThread Handle
|
||||
MOV X5, X0
|
||||
MOV X4, X1
|
||||
|
||||
# Inject start
|
||||
push_all
|
||||
|
||||
MOV W0, #0xFFFF8001
|
||||
ADR X1, __rodata_start
|
||||
ADR X2, __data_start
|
||||
SUB X2, X2, X1
|
||||
MOV X3, #1
|
||||
SVC 0x73
|
||||
|
||||
MOV W0, #0xFFFF8001
|
||||
ADR X1, __data_start
|
||||
ADR X2, __argdata__
|
||||
SUB X2, X2, X1
|
||||
MOV X3, #3
|
||||
SVC 0x73
|
||||
|
||||
pop_all
|
||||
|
||||
MOV X27, X7
|
||||
MOV X25, X5
|
||||
MOV X26, X4
|
||||
|
||||
# Clear .bss
|
||||
ADRP X0, __bss_start__
|
||||
ADRP X1, __bss_end__
|
||||
ADD X0, X0, #:lo12:__bss_start__
|
||||
ADD X1, X1, #:lo12:__bss_end__
|
||||
SUB X1, X1, X0
|
||||
ADD X1, X1, #7
|
||||
BIC X1, X1, #7
|
||||
|
||||
bss_loop:
|
||||
STR XZR, [X0], #8
|
||||
SUBS X1, X1, #8
|
||||
BNE bss_loop
|
||||
|
||||
# Store SP
|
||||
MOV X1, SP
|
||||
ADRP X0, __stack_top
|
||||
STR X1, [X0, #:lo12:__stack_top]
|
||||
|
||||
# Process _DYNAMIC Section
|
||||
MOV X0, X6
|
||||
ADRP X1, _DYNAMIC
|
||||
ADD X1, X1, #:lo12:_DYNAMIC
|
||||
BL __nx_dynamic
|
||||
|
||||
# TODO: handle in code
|
||||
MOV X0, X25
|
||||
MOV X1, X26
|
||||
MOV X2, X27
|
||||
|
||||
BL __initheap
|
||||
BL __init
|
||||
|
||||
MOV X0, X25
|
||||
MOV X1, X26
|
||||
MOV X30, X27
|
||||
|
||||
# FS main
|
||||
ADRP X16, __argdata__
|
||||
BR X16
|
220
emummc/source/nx/svc.h
vendored
220
emummc/source/nx/svc.h
vendored
|
@ -1,220 +0,0 @@
|
|||
/**
|
||||
* @file svc.h
|
||||
* @brief Wrappers for kernel syscalls.
|
||||
* @copyright libnx Authors
|
||||
*/
|
||||
#pragma once
|
||||
#include "../utils/types.h"
|
||||
|
||||
/// Memory information structure.
|
||||
typedef struct {
|
||||
u64 addr; ///< Base address.
|
||||
u64 size; ///< Size.
|
||||
u32 type; ///< Memory type (see lower 8 bits of \ref MemoryState).
|
||||
u32 attr; ///< Memory attributes (see \ref MemoryAttribute).
|
||||
u32 perm; ///< Memory permissions (see \ref Permission).
|
||||
u32 device_refcount; ///< Device reference count.
|
||||
u32 ipc_refcount; ///< IPC reference count.
|
||||
u32 padding; ///< Padding.
|
||||
} MemoryInfo;
|
||||
|
||||
/// Memory permission bitmasks.
|
||||
typedef enum {
|
||||
Perm_None = 0, ///< No permissions.
|
||||
Perm_R = BIT(0), ///< Read permission.
|
||||
Perm_W = BIT(1), ///< Write permission.
|
||||
Perm_X = BIT(2), ///< Execute permission.
|
||||
Perm_Rw = Perm_R | Perm_W, ///< Read/write permissions.
|
||||
Perm_Rx = Perm_R | Perm_X, ///< Read/execute permissions.
|
||||
Perm_DontCare = BIT(28), ///< Don't care
|
||||
} Permission;
|
||||
|
||||
/// Secure monitor arguments.
|
||||
typedef struct {
|
||||
u64 X[8]; ///< Values of X0 through X7.
|
||||
} SecmonArgs;
|
||||
|
||||
_Static_assert(sizeof(SecmonArgs) == 0x40, "SecmonArgs definition");
|
||||
|
||||
#define DeviceName_SDMMC1A 19
|
||||
#define DeviceName_SDMMC2A 20
|
||||
#define DeviceName_SDMMC3A 21
|
||||
#define DeviceName_SDMMC4A 22
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Returns a virtual address mapped to a given IO range.
|
||||
* @return Result code.
|
||||
* @note Syscall number 0x55.
|
||||
* @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
|
||||
* @warning Only exists on [10.0.0+]. For older versions use \ref svcLegacyQueryIoMapping.
|
||||
*/
|
||||
Result svcQueryIoMapping(u64* virtaddr, u64* out_size, u64 physaddr, u64 size);
|
||||
|
||||
/**
|
||||
* @brief Returns a virtual address mapped to a given IO range.
|
||||
* @return Result code.
|
||||
* @note Syscall number 0x55.
|
||||
* @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
|
||||
* @warning Only exists on [1.0.0-9.2.0]. For newer versions use \ref svcQueryIoMapping.
|
||||
*/
|
||||
Result svcLegacyQueryIoMapping(u64* virtaddr, u64 physaddr, u64 size);
|
||||
|
||||
/**
|
||||
* @brief Attaches a device address space to a device.
|
||||
* @return Result code.
|
||||
* @note Syscall number 0x57.
|
||||
* @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
|
||||
*/
|
||||
Result svcAttachDeviceAddressSpace(u64 device, Handle handle);
|
||||
|
||||
/**
|
||||
* @brief Query information about an address. Will always fetch the lowest page-aligned mapping that contains the provided address.
|
||||
* @param[out] meminfo_ptr \ref MemoryInfo structure which will be filled in.
|
||||
* @param[out] pageinfo Page information which will be filled in.
|
||||
* @param[in] addr Address to query.
|
||||
* @return Result code.
|
||||
* @note Syscall number 0x06.
|
||||
*/
|
||||
Result svcQueryMemory(MemoryInfo* meminfo_ptr, u32 *pageinfo, u64 addr);
|
||||
|
||||
/**
|
||||
* @brief Sets the memory permissions for the specified memory with the supplied process handle.
|
||||
* @param[in] proc Process handle.
|
||||
* @param[in] addr Address of the memory.
|
||||
* @param[in] size Size of the memory.
|
||||
* @param[in] perm Permissions (see \ref Permission).
|
||||
* @return Result code.
|
||||
* @remark This returns an error (0xD801) when \p perm is >0x5, hence -WX and RWX are not allowed.
|
||||
* @note Syscall number 0x73.
|
||||
* @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
|
||||
*/
|
||||
Result svcSetProcessMemoryPermission(Handle proc, u64 addr, u64 size, u32 perm);
|
||||
|
||||
/**
|
||||
* @brief Set the memory permissions of a (page-aligned) range of memory.
|
||||
* @param[in] addr Start address of the range.
|
||||
* @param[in] size Size of the range, in bytes.
|
||||
* @param[in] perm Permissions (see \ref Permission).
|
||||
* @return Result code.
|
||||
* @remark Perm_X is not allowed. Setting write-only is not allowed either (Perm_W).
|
||||
* This can be used to move back and forth between Perm_None, Perm_R and Perm_Rw.
|
||||
* @note Syscall number 0x01.
|
||||
*/
|
||||
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.
|
||||
* @return Return value from the secure monitor.
|
||||
* @note Syscall number 0x7F.
|
||||
* @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available.
|
||||
*/
|
||||
u64 svcCallSecureMonitor(SecmonArgs* regs);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
///@}
|
136
emummc/source/nx/svc.s
vendored
136
emummc/source/nx/svc.s
vendored
|
@ -1,136 +0,0 @@
|
|||
/**
|
||||
* @file svc.s
|
||||
* @copyright libnx Authors
|
||||
*/
|
||||
|
||||
.macro SVC_BEGIN name
|
||||
.section .text.\name, "ax", %progbits
|
||||
.global \name
|
||||
.type \name, %function
|
||||
.align 2
|
||||
.cfi_startproc
|
||||
\name:
|
||||
.endm
|
||||
|
||||
.macro SVC_END
|
||||
.cfi_endproc
|
||||
.endm
|
||||
|
||||
SVC_BEGIN svcQueryIoMapping
|
||||
STP X0, X1, [SP, #-16]!
|
||||
SVC 0x55
|
||||
LDP X3, X4, [SP], #16
|
||||
STR X1, [X3]
|
||||
STR X2, [X4]
|
||||
RET
|
||||
SVC_END
|
||||
|
||||
SVC_BEGIN svcLegacyQueryIoMapping
|
||||
STR X0, [SP, #-16]!
|
||||
SVC 0x55
|
||||
LDR X2, [SP], #16
|
||||
STR X1, [X2]
|
||||
RET
|
||||
SVC_END
|
||||
|
||||
SVC_BEGIN svcAttachDeviceAddressSpace
|
||||
SVC 0x57
|
||||
RET
|
||||
SVC_END
|
||||
|
||||
SVC_BEGIN svcQueryMemory
|
||||
STR X1, [SP, #-16]!
|
||||
SVC 0x6
|
||||
LDR X2, [SP], #16
|
||||
STR W1, [X2]
|
||||
RET
|
||||
SVC_END
|
||||
|
||||
SVC_BEGIN svcSetMemoryPermission
|
||||
SVC 0x2
|
||||
RET
|
||||
SVC_END
|
||||
|
||||
SVC_BEGIN svcSetProcessMemoryPermission
|
||||
SVC 0x73
|
||||
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
|
||||
LDP X0, X1, [X8]
|
||||
LDP X2, X3, [X8, #0x10]
|
||||
LDP X4, X5, [X8, #0x20]
|
||||
LDP X6, X7, [X8, #0x30]
|
||||
SVC 0x7F
|
||||
LDR X8, [SP], #16
|
||||
STP X0, X1, [X8]
|
||||
STP X2, X3, [X8, #0x10]
|
||||
STP X4, X5, [X8, #0x20]
|
||||
STP X6, X7, [X8, #0x30]
|
||||
RET
|
||||
SVC_END
|
Loading…
Add table
Add a link
Reference in a new issue