From 98793badc1c1d3e4bfd735fdecd3d2d731701ab3 Mon Sep 17 00:00:00 2001 From: Christian Cunningham Date: Tue, 1 Feb 2022 19:39:36 -0700 Subject: Syscall to get timer value --- include/cpu.h | 14 ++++++++++++++ src/cpu/irq.c | 13 +++++++++++++ src/exceptions/svc.S | 6 ++++++ 3 files changed, 33 insertions(+) diff --git a/include/cpu.h b/include/cpu.h index cccc12b..c15c086 100644 --- a/include/cpu.h +++ b/include/cpu.h @@ -82,6 +82,20 @@ static inline void* getirqstack(void) #define sys0(sys_n) asm volatile("svc #" syscall_h_expand_and_quote(sys_n) ::: "r0", "r1", "r2", "r3"); #define sys1(sys_n,arg0) asm volatile("svc #" syscall_h_expand_and_quote(sys_n) ::[r0]"r"(arg0): "r0", "r1", "r2", "r3"); +__attribute__((always_inline)) static inline unsigned long long get_sys_time(void) +{ + union { + struct { + unsigned long lo; + unsigned long hi; + }s; + unsigned long long llv; + }t; + asm volatile("svc #1\nmov %0, r0\nmov %0, r1" : "=r"(t.s.lo), "=r"(t.s.hi)); + return t.llv; +} + #define SYS_SCHED 2 +#define SYS_TIME 1 #endif diff --git a/src/cpu/irq.c b/src/cpu/irq.c index 24a809c..612b6d8 100644 --- a/src/cpu/irq.c +++ b/src/cpu/irq.c @@ -11,6 +11,7 @@ #include #include +void utime(void); void testfxn(void); void handle_data(unsigned char); @@ -109,6 +110,8 @@ void handle_data(unsigned char data) add_thread(uart_scheduler, 0, 2); } else if (data == 0x63) { add_thread(heap_info, 0, 2); + } else if (data == 0x64) { + add_thread(utime, 0, 2); } else { } g_Drawer.x = 0; @@ -120,6 +123,16 @@ void handle_data(unsigned char data) write_string(&g_Drawer, "> "); } +void utime(void) +{ + unsigned long thi, tlo; + unsigned long long t = get_sys_time(); + thi = t >> 32; + tlo = t; + uart_hex(thi); + uart_hexn(tlo); +} + void testfxn2(void) { uart_string("Ran testfxn2\n"); diff --git a/src/exceptions/svc.S b/src/exceptions/svc.S index d1fcbc0..51c6479 100644 --- a/src/exceptions/svc.S +++ b/src/exceptions/svc.S @@ -18,6 +18,12 @@ svc_000000: cps #0x13 b svc_exit svc_000001: + mov r2, #0x3004 + movt r2, #0x3F00 + ldr r0, [r2, #4] // <- SYS_TIMER_CLO + ldr r1, [r2, #0] // <- SYS_TIMER_CHI + str r0, [sp] // Return value + str r1, [sp, #4] // Return value hi b svc_exit svc_000002: ldmfd sp!, {r0-r12,lr} -- cgit v1.2.1