diff options
author | Reiko Asakura | 2021-02-16 10:24:28 -0500 |
---|---|---|
committer | Reiko Asakura | 2021-02-16 10:24:28 -0500 |
commit | b9aadce8bf66ce4793964663a23d4d793bc28b61 (patch) | |
tree | c7da08831e2009f2bd8b9ecd1899723abcdd05a5 | |
parent | Add lint workflow (diff) | |
download | vds-libraries-b9aadce8bf66ce4793964663a23d4d793bc28b61.tar.gz |
Remove inline asm in cpu.h
-rw-r--r-- | 365compat/CMakeLists.txt | 19 | ||||
-rw-r--r-- | 365compat/sceKernelCpuUnrestrictedMemcpy.c | 22 | ||||
-rw-r--r-- | CMakeLists.txt | 6 | ||||
-rw-r--r-- | include/kernel/kernel/cpu.h | 82 |
4 files changed, 47 insertions, 82 deletions
diff --git a/365compat/CMakeLists.txt b/365compat/CMakeLists.txt new file mode 100644 index 0000000..7c76538 --- /dev/null +++ b/365compat/CMakeLists.txt @@ -0,0 +1,19 @@ +# +# Copyright (C) 2021 Reiko Asakura. All Rights Reserved. +# +# Vita Development Suite Libraries +# + +include_directories(SYSTEM + ../include/kernel + ../include/common +) + +add_library(365compat STATIC + sceKernelCpuUnrestrictedMemcpy.c +) + +install(TARGETS + 365compat + ARCHIVE DESTINATION lib/vdsuite +) diff --git a/365compat/sceKernelCpuUnrestrictedMemcpy.c b/365compat/sceKernelCpuUnrestrictedMemcpy.c new file mode 100644 index 0000000..5a4e4ce --- /dev/null +++ b/365compat/sceKernelCpuUnrestrictedMemcpy.c @@ -0,0 +1,22 @@ +/* + Vita Development Suite Libraries +*/ + +#include <string.h> +#include <kernel/cpu.h> + +#define ALIGN(x) ((((x) + 0x1F) >> 5) << 5) +#define ALIGN_BACK(x) (((x) >> 5) << 5) + +// Copied from sysmem.skprx 3.600 +// Unavailable in 3.650 +int sceKernelCpuUnrestrictedMemcpy(void *dst, const void *src, SceSize len) { + int dacr = __builtin_mrc(15, 0, 3, 0, 0); + __builtin_mcr(15, 0, 3, 0, 0, 0xFFFF0000); + memcpy(dst, src, len); + len = ALIGN((SceSize)dst + len) - ALIGN_BACK((SceSize)dst); + dst = (void*)ALIGN_BACK((SceSize)dst); + sceKernelCpuDcacheWritebackRange(dst, len); + __builtin_mcr(15, 0, 3, 0, 0, dacr); + return 0; +} diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f5cf79..8457489 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ cmake_minimum_required(VERSION 3.19) set(CMAKE_TOOLCHAIN_FILE $ENV{SCE_PSP2_SDK_DIR}/host_tools/build/cmake/psp2-snc-toolchain.cmake) -project(vdsuite-libraries LANGUAGES NONE) +project(vdsuite-libraries LANGUAGES C) include(ExternalProject) include(VitaDevelopmentSuite) @@ -54,3 +54,7 @@ ExternalProject_Add(egl-registry INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory <SOURCE_DIR>/api/EGL <INSTALL_DIR>/include/vdsuite/user/EGL COMMAND ${CMAKE_COMMAND} -E copy_directory <SOURCE_DIR>/api/KHR <INSTALL_DIR>/include/vdsuite/user/KHR ) + +# Static libraries + +add_subdirectory(365compat) diff --git a/include/kernel/kernel/cpu.h b/include/kernel/kernel/cpu.h index 0634ac6..066bf78 100644 --- a/include/kernel/kernel/cpu.h +++ b/include/kernel/kernel/cpu.h @@ -7,36 +7,11 @@ #include_next <kernel/cpu.h> -#include <string.h> -#include <scetypes.h> - #ifdef __cplusplus extern "C" { #endif /** - * @brief Call this when entering a syscall - * - * @param state The state - */ -#define ENTER_SYSCALL(state) \ - do { \ - asm volatile ("mrc p15, 0, %0, c13, c0, 3" : "=r" (state)); \ - asm volatile ("mcr p15, 0, %0, c13, c0, 3" :: "r" (state << 16) : "memory"); \ - } while(0) - -/** - * @brief Call this when exiting a syscall - * - * @param state The state - */ -#define EXIT_SYSCALL(state) \ - do { \ - asm volatile ("mcr p15, 0, %0, c13, c0, 3" :: "r" (state) : "memory"); \ - } while (0) - - -/** * @brief Writeback a range of L1 dcache (without L2) * * @param ptr The pointer @@ -44,43 +19,6 @@ extern "C" { */ void sceKernelCpuDcacheWritebackRange(const void *ptr, SceSize len); - -/** - * @brief Save process context - * - * @param context The context - */ -static inline void sceKernelCpuSaveContext(int context[3]) -{ - asm ("mrc p15, 0, %0, c2, c0, 1" : "=r" (context[0])); - asm ("mrc p15, 0, %0, c3, c0, 0" : "=r" (context[1])); - asm ("mrc p15, 0, %0, c13, c0, 1" : "=r" (context[2])); -} - -/** - * @brief Restore process context - * - * @param context The context, can be from ::sceKernelGetPidContext - */ -static inline void sceKernelCpuRestoreContext(int context[3]) -{ - int cpsr, tmp; - - asm volatile ("mrs %0, cpsr" : "=r" (cpsr)); - if (!(cpsr & 0x80)) - asm volatile ("cpsid i" ::: "memory"); - asm volatile ("mrc p15, 0, %0, c13, c0, 1" : "=r" (tmp)); - tmp = (tmp & 0xFFFFFF00) | context[2]; - asm volatile ("mcr p15, 0, %0, c13, c0, 1" :: "r" (0)); - asm volatile ("isb" ::: "memory"); - asm volatile ("mcr p15, 0, %0, c2, c0, 1" :: "r" (context[0] | 0x4A)); - asm volatile ("isb" ::: "memory"); - asm volatile ("mcr p15, 0, %0, c13, c0, 1" :: "r" (tmp)); - asm volatile ("mcr p15, 0, %0, c3, c0, 0" :: "r" (context[1] & 0x55555555)); - if (!(cpsr & 0x80)) - asm volatile ("cpsie i" ::: "memory"); -} - /** * @brief MMU permission bypassing memcpy * @@ -92,25 +30,7 @@ static inline void sceKernelCpuRestoreContext(int context[3]) * * @return Zero on success. */ -static inline int sceKernelCpuUnrestrictedMemcpy(void *dst, const void *src, SceSize len) -{ - int prev_dacr; - - asm volatile("mrc p15, 0, %0, c3, c0, 0" : "=r" (prev_dacr)); - asm volatile("mcr p15, 0, %0, c3, c0, 0" :: "r" (0xFFFF0000)); - - memcpy(dst, src, len); - - len += (SceSize)(((uintptr_t)dst) & 0x1F); - - dst = (void *)(((uintptr_t)dst) & ~0x1F); - len = (len + 0x1F) & ~0x1F; - - sceKernelCpuDcacheWritebackRange(dst, len); - - asm volatile("mcr p15, 0, %0, c3, c0, 0" :: "r" (prev_dacr)); - return 0; -} +int sceKernelCpuUnrestrictedMemcpy(void *dst, const void *src, SceSize len); /** * @brief Returns the CPU ID of the calling processor |