12c44bdfc9280fe156566c401e21f170d1d45352
[akaros.git] / kern / arch / sparc / timer.c
1 #include <arch/timer.h>
2 #include <arch/types.h>
3 #include <arch/trap.h>
4 #include <arch/arch.h>
5 #include <stdio.h>
6
7 system_timing_t system_timing = {0};
8 volatile uint32_t timer_ticks = 0;
9
10 asm (
11 ".global handle_timer_interrupt         \n\t"
12 "handle_timer_interrupt:                \n\t"
13 "       mov     " XSTR(CORE_ID_REG) ",%l3       \n\t"
14 "       mov     %psr,%l4                        \n\t"
15 "       cmp     %l3,0                           \n\t"
16 "       bne     1f                              \n\t"
17 "        mov    %l4,%psr                        \n\t"
18 "       sethi   %hi(timer_ticks),%l4            \n\t"
19 "       ld      [%l4+%lo(timer_ticks)],%l5      \n\t"
20 "       inc     %l5                             \n\t"
21 "       st      %l5,[%l4+%lo(timer_ticks)]      \n\t"
22 "1:     jmp     %l1                             \n\t"
23 "        rett   %l2                             \n\t" );
24
25 void
26 timer_init(void)
27 {
28         uint32_t ticks = timer_ticks;
29         uint64_t tsc_ticks;
30
31         while(ticks == timer_ticks) ;
32
33         ticks = timer_ticks;
34         tsc_ticks = read_tsc();
35
36         while(ticks == timer_ticks) ;
37
38         system_timing.tsc_freq = read_tsc() - tsc_ticks;
39
40         cprintf("TSC Frequency: %llu\n", system_timing.tsc_freq);
41 }