From cfd74e66b4e1034e0fa3e7c11b8d88a6ef3079ab Mon Sep 17 00:00:00 2001 From: Anton Lydike Date: Mon, 16 Aug 2021 17:21:29 +0200 Subject: [PATCH] fixed assembly format of read_time and write_mtimecmp --- kinclude/csr.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/kinclude/csr.c b/kinclude/csr.c index bd8cf2a..bf54fdb 100644 --- a/kinclude/csr.c +++ b/kinclude/csr.c @@ -2,14 +2,18 @@ #ifdef TIMECMP_IN_MEMORY +#ifndef TIMECMP_MEM_ADDR +#error "You set TIMECMP_IN_MEMORY but did not provide a memory addres in TIMECMP_MEM_ADDR!" +#endif + void write_mtimecmp(unsigned long long int mtimecmp) { - unsigned int lower = mtimecmp; - unsigned int higher = mtimecmp >> 32; + unsigned int lo = mtimecmp; + unsigned int hi = mtimecmp >> 32; __asm__( - "sw %1, 0(%0)\n" - "sw %2, 4(%0)" :: - "r"(TIMECMP_MEM_ADDR), - "r"(lower), "r"(higher) + "li t0, %0\n" + "sw %1, 0(t0)\n" + "sw %2, 4(t0)" :: + "i"(TIMECMP_MEM_ADDR), "r"(lo), "r"(hi) ); } @@ -32,9 +36,10 @@ void write_mtimecmp(unsigned long long int mtimecmp) { unsigned long long int read_time() { unsigned int lower, higher; __asm__( - "csrr %0, 0xC01\n" - "csrr %1, 0xC81\n" + "csrr %0, %2\n" + "csrr %1, %3\n" : "=r"(lower), "=r"(higher) + : "i"(CSR_TIME), "i"(CSR_TIMEH) ); return (unsigned long long) higher << 32 | lower; }