From a5995cd4aa47110388368fad4ebea6d73db22714 Mon Sep 17 00:00:00 2001 From: Gregor Haas Date: Sun, 23 Feb 2020 20:24:51 -0500 Subject: [PATCH] add some experiments with the cache --- c8_remote/include/payload.h | 1 + c8_remote/lib/CMakeLists.txt | 1 + c8_remote/lib/payload/include/cacheutil.h | 62 +++++++++++++++++++++++ c8_remote/lib/payload/src/cachelib.c | 33 ++++++++++++ c8_remote/src/payload.c | 5 ++ 5 files changed, 102 insertions(+) create mode 100644 c8_remote/lib/payload/include/cacheutil.h create mode 100644 c8_remote/lib/payload/src/cachelib.c diff --git a/c8_remote/include/payload.h b/c8_remote/include/payload.h index 55fa8c8..a18046e 100644 --- a/c8_remote/include/payload.h +++ b/c8_remote/include/payload.h @@ -7,6 +7,7 @@ typedef enum { PAYLOAD_AES_BUSY, PAYLOAD_AES_SW, + PAYLOAD_CACHELIB, PAYLOAD_EXIT_USB_TASK, PAYLOAD_FLOPPYSLEEP, PAYLOAD_SYNC, diff --git a/c8_remote/lib/CMakeLists.txt b/c8_remote/lib/CMakeLists.txt index eb375aa..a7b7200 100644 --- a/c8_remote/lib/CMakeLists.txt +++ b/c8_remote/lib/CMakeLists.txt @@ -1,6 +1,7 @@ set(PL_NAMES aes_busy aes_sw + cachelib exit_usb_task floppysleep sync diff --git a/c8_remote/lib/payload/include/cacheutil.h b/c8_remote/lib/payload/include/cacheutil.h new file mode 100644 index 0000000..f1e126d --- /dev/null +++ b/c8_remote/lib/payload/include/cacheutil.h @@ -0,0 +1,62 @@ +#ifndef CHECKM8_TOOL_CACHEUTIL_H +#define CHECKM8_TOOL_CACHEUTIL_H + +#include "dev_util.h" + +PAYLOAD_SECTION +static inline unsigned long long get_ccsidr_el1() +{ + unsigned long long cacheconfig = 0; + __asm__ volatile ("mrs %0, ccsidr_el1" : "=r" (cacheconfig)); + return cacheconfig; +} + +PAYLOAD_SECTION +static inline void sel_ccsidr_el1(unsigned int level, unsigned int i_or_d) +{ + unsigned long long cachesel = (level & 0b111u) << 1u | (i_or_d & 0b1u); + __asm__ volatile ("msr csselr_el1, %0"::"r" (cachesel)); +} + +PAYLOAD_SECTION +static inline unsigned long long get_ctr_el0() +{ + unsigned long long cacheconfig; + __asm__ volatile ("mrs %0, CTR_EL0" : "=r" (cacheconfig)); + return cacheconfig; +} + +PAYLOAD_SECTION +static inline void inv_l1_setway(unsigned int set, unsigned int way) +{ + unsigned long long val = ((way & 0b11u) << 30u) | ((set & 0xFFu) << 6u); + __asm__ volatile ("dc isw, %0"::"r" (val)); +} + +PAYLOAD_SECTION +static inline void clean_l1_setway(unsigned int set, unsigned int way) +{ + unsigned long long val = ((way & 0b11u) << 30u) | ((set & 0xFFu) << 6u); + __asm__ volatile ("dc csw, %0"::"r" (val)); +} + +PAYLOAD_SECTION +static inline void clean_inv_l1_setway(unsigned int set, unsigned int way) +{ + unsigned long long val = ((way & 0b11u) << 30u) | ((set & 0xFFu) << 6u); + __asm__ volatile ("dc cisw, %0"::"r" (val)); +} + +PAYLOAD_SECTION +static inline void inv_l1_va(unsigned long long *addr) +{ + __asm__ volatile ("dc ivac, %0"::"r" (addr)); +} + +PAYLOAD_SECTION +static inline void clean_inv_l1_va(unsigned long long *addr) +{ + __asm__ volatile ("dc ivac, %0"::"r" (addr)); +} + +#endif //CHECKM8_TOOL_CACHEUTIL_H diff --git a/c8_remote/lib/payload/src/cachelib.c b/c8_remote/lib/payload/src/cachelib.c new file mode 100644 index 0000000..cc832fc --- /dev/null +++ b/c8_remote/lib/payload/src/cachelib.c @@ -0,0 +1,33 @@ +#include "bootrom_func.h" +#include "cacheutil.h" + + +PAYLOAD_SECTION +unsigned long long l1_experiment() +{ + int i; + unsigned long long start, f; + volatile unsigned long long val = 0; + clean_inv_l1_va((unsigned long long *) &val); + + start = get_ticks(); + for(i = 0; i < 10000000; i++) + { + val; + clean_inv_l1_va((unsigned long long *) &val); + } + + return get_ticks() - start; +} + +PAYLOAD_SECTION +unsigned long long entry_sync() +{ + return l1_experiment(); +} + +PAYLOAD_SECTION +void entry_async() +{ + +} \ No newline at end of file diff --git a/c8_remote/src/payload.c b/c8_remote/src/payload.c index 6bbeacf..99663ba 100644 --- a/c8_remote/src/payload.c +++ b/c8_remote/src/payload.c @@ -50,6 +50,11 @@ struct payload *get_payload(PAYLOAD_T p) len = PAYLOAD_AES_SW_SZ; break; + case PAYLOAD_CACHELIB: + pl = payload_cachelib; + len = PAYLOAD_CACHELIB_SZ; + break; + case PAYLOAD_EXIT_USB_TASK: pl = payload_exit_usb_task; len = PAYLOAD_EXIT_USB_TASK_SZ;