From d1ba4d4e2b4307afc1c49b1c8f9979b655fb2bc4 Mon Sep 17 00:00:00 2001 From: yellows8 Date: Tue, 10 Oct 2017 00:44:00 -0400 Subject: [PATCH] Added osDCacheFlush() for use by usbds. --- nx/include/switch.h | 1 + nx/include/switch/os.h | 1 + nx/source/kernel/cache.s | 34 ++++++++++++++++++++++++++++++++++ nx/source/services/usb.c | 2 +- 4 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 nx/include/switch/os.h create mode 100644 nx/source/kernel/cache.s diff --git a/nx/include/switch.h b/nx/include/switch.h index 63d6662b..5773eacd 100644 --- a/nx/include/switch.h +++ b/nx/include/switch.h @@ -12,6 +12,7 @@ extern "C" { #include #include #include +#include #include #include diff --git a/nx/include/switch/os.h b/nx/include/switch/os.h new file mode 100644 index 00000000..2f6a8cc8 --- /dev/null +++ b/nx/include/switch/os.h @@ -0,0 +1 @@ +void osDCacheFlush(void* addr, size_t size); diff --git a/nx/source/kernel/cache.s b/nx/source/kernel/cache.s new file mode 100644 index 00000000..816b921e --- /dev/null +++ b/nx/source/kernel/cache.s @@ -0,0 +1,34 @@ +.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 osDCacheFlush + 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 + +osDCacheFlush_L0: + dc civac, x8 + add x8, x8, x9 + cmp x8, x10 + bcc osDCacheFlush_L0 + + dsb sy + ret +CODE_END + diff --git a/nx/source/services/usb.c b/nx/source/services/usb.c index 5008b45a..6847424c 100644 --- a/nx/source/services/usb.c +++ b/nx/source/services/usb.c @@ -382,7 +382,7 @@ static Result _usbDsCmdNoParams(Handle sessionhandle, u64 cmd_id) { static Result _usbDsPostBuffer(Handle sessionhandle, u64 cmd_id, void* buffer, size_t size, u32 *out) { if(sessionhandle==0)return MAKERESULT(MODULE_LIBNX, LIBNX_NOTINITIALIZED); - //TODO: Add dache-flush code here, breaks otherwise. + osDCacheFlush(buffer, size); IpcCommand c; ipcInitialize(&c);