Skip to content

Commit

Permalink
emummc: fix for svcQueryIoMapping abi change
Browse files Browse the repository at this point in the history
  • Loading branch information
SciresM committed Apr 14, 2020
1 parent f35ce00 commit b168ddf
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 6 deletions.
3 changes: 1 addition & 2 deletions source/emuMMC/emummc.c
Expand Up @@ -36,7 +36,6 @@ sdmmc_storage_t sd_storage;

// init vars
bool custom_driver = true;
extern const volatile emuMMC_ctx_t emuMMC_ctx;

// FS funcs
_sdmmc_accessor_gc sdmmc_accessor_gc;
Expand Down Expand Up @@ -344,7 +343,7 @@ uint64_t sdmmc_wrapper_controller_close(int mmc_id)
{
return 0;
}

if (mmc_id == FS_SDMMC_EMMC)
{
// Close file handles and unmount
Expand Down
12 changes: 11 additions & 1 deletion source/nx/svc.h
Expand Up @@ -50,8 +50,18 @@ extern "C" {
* @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 physaddr, u64 size);
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.
Expand Down
9 changes: 9 additions & 0 deletions source/nx/svc.s
Expand Up @@ -17,6 +17,15 @@
.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
Expand Down
3 changes: 2 additions & 1 deletion source/utils/fatal.h
Expand Up @@ -25,11 +25,12 @@ enum FatalReason
Fatal_InvalidAccessor,
Fatal_ReadNoAccessor,
Fatal_WriteNoAccessor,
Fatal_IoMapping,
Fatal_IoMappingLegacy,
Fatal_UnknownVersion,
Fatal_BadResult,
Fatal_GetConfig,
Fatal_CloseAccessor,
Fatal_IoMapping,
Fatal_Max
};

Expand Down
11 changes: 9 additions & 2 deletions source/utils/util.c
Expand Up @@ -38,8 +38,15 @@ static inline uintptr_t _GetIoMapping(u64 io_addr, u64 io_size)
u64 vaddr;
u64 aligned_addr = (io_addr & ~0xFFFul);
u64 aligned_size = io_size + (io_addr - aligned_addr);
if (svcQueryIoMapping(&vaddr, aligned_addr, aligned_size) != 0) {
fatal_abort(Fatal_IoMapping);
if (emuMMC_ctx.fs_ver >= FS_VER_10_0_0) {
u64 out_size;
if (svcQueryIoMapping(&vaddr, &out_size, aligned_addr, aligned_size) != 0) {
fatal_abort(Fatal_IoMapping);
}
} else {
if (svcLegacyQueryIoMapping(&vaddr, aligned_addr, aligned_size) != 0) {
fatal_abort(Fatal_IoMappingLegacy);
}
}
return (uintptr_t)(vaddr + (io_addr - aligned_addr));
}
Expand Down
3 changes: 3 additions & 0 deletions source/utils/util.h
Expand Up @@ -19,6 +19,7 @@
#define _UTIL_H_

#include "types.h"
#include "../emuMMC/emummc_ctx.h"

intptr_t QueryIoMapping(u64 addr, u64 size);
#define byte_swap_32(num) ((num >> 24) & 0xff) | ((num << 8) & 0xff0000) | \
Expand All @@ -37,4 +38,6 @@ void usleep(u64 ticks);
void msleep(u64 milliseconds);
void exec_cfg(u32 *base, const cfg_op_t *ops, u32 num_ops);

extern volatile emuMMC_ctx_t emuMMC_ctx;

#endif

0 comments on commit b168ddf

Please sign in to comment.