diff --git a/kinclude/csr.c b/kinclude/csr.c index b154a37..6ac05b8 100644 --- a/kinclude/csr.c +++ b/kinclude/csr.c @@ -6,27 +6,31 @@ #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) { +void write_mtimecmp(unsigned long long int mtimecmp) +{ unsigned int lo = mtimecmp; unsigned int hi = mtimecmp >> 32; - __asm__( - "li t0, %0\n" - "sw %1, 0(t0)\n" - "sw %2, 4(t0)" :: - "i"(TIMECMP_MEM_ADDR), "r"(lo), "r"(hi) + + __asm__ ( + "li t0, %0\n" + "sw %1, 0(t0)\n" + "sw %2, 4(t0)" :: + "i"(TIMECMP_MEM_ADDR), "r"(lo), "r"(hi) ); } #else -void write_mtimecmp(unsigned long long int mtimecmp) { +void write_mtimecmp(unsigned long long int mtimecmp) +{ unsigned int lower = mtimecmp; unsigned int higher = mtimecmp >> 32; - __asm__( - "csrw %0, %2\n" - "csrw %1, %3" :: - "I"(CSR_MTIMECMP),"I"(CSR_MTIMECMPH), - "r"(lower), "r"(higher) + + __asm__ ( + "csrw %0, %2\n" + "csrw %1, %3" :: + "I"(CSR_MTIMECMP),"I"(CSR_MTIMECMPH), + "r"(lower), "r"(higher) ); } diff --git a/kinclude/csr.h b/kinclude/csr.h index f85a79b..7d9dd5e 100644 --- a/kinclude/csr.h +++ b/kinclude/csr.h @@ -23,31 +23,33 @@ // do not define C macros and other C stuff when this is included inside assembly #ifndef __assembly -#define CSR_READ(csr_id, result) {\ - __asm__ ("csrr %0, %1" : "=r"((result)) : "I"((csr_id))); \ +#define CSR_READ(csr_id, result) { \ + __asm__ ("csrr %0, %1" : "=r"((result)) : "I"((csr_id))); \ } -#define CSR_WRITE(csr_id, val) {\ - __asm__ ("csrw %0, %1" :: "I"((csr_id)), "r"((val))); \ +#define CSR_WRITE(csr_id, val) { \ + __asm__ ("csrw %0, %1" :: "I"((csr_id)), "r"((val))); \ } -#define HALT(code) {\ - __asm__("csrw %0, %1" :: "I"(CSR_HALT), "I"(code)); \ +#define HALT(code) { \ + __asm__ ("csrw %0, %1" :: "I"(CSR_HALT), "I"(code)); \ } void write_mtimecmp(unsigned long long int mtimecmp); -inline __attribute__((always_inline)) unsigned long long int read_time() { +inline __attribute__((always_inline)) unsigned long long int read_time() +{ unsigned int lower, higher; - __asm__( - "csrr %0, %2\n" - "csrr %1, %3\n" - : "=r"(lower), "=r"(higher) - : "i"(CSR_TIME), "i"(CSR_TIMEH) + + __asm__ ( + "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; } #endif -#endif \ No newline at end of file +#endif