Adding initial support for performance counters.
[akaros.git] / user / include / i686 / arch.h
1 #ifndef PARLIB_ARCH_H
2 #define PARLIB_ARCH_H
3
4 #include <ros/arch/trapframe.h>
5 #include <ros/arch/mmu.h>
6 #include <ros/common.h>
7 #include <string.h>
8
9 #define internal_function   __attribute ((regparm (3), stdcall))
10
11 #define ARCH_CL_SIZE 64
12
13 /* Make sure you subtract off/save enough space at the top of the stack for
14  * whatever you compiler might want to use when calling a noreturn function or
15  * to handle a HW spill or whatever. */
16 static __inline void __attribute__((always_inline))
17 set_stack_pointer(void* sp)
18 {
19         asm volatile ("mov %0,%%esp" : : "r"(sp) : "memory","esp");
20 }
21
22 static __inline void
23 breakpoint(void)
24 {
25         __asm __volatile("int3");
26 }
27
28 static __inline uint64_t
29 read_tsc(void)
30 {
31         uint64_t tsc;
32         __asm __volatile("rdtsc" : "=A" (tsc));
33         return tsc;
34 }
35
36 static __inline void
37 cpu_relax(void)
38 {
39         asm volatile("pause" : : : "memory");
40 }
41
42 static __inline uint64_t                                                                             
43 read_pmc(uint32_t index)
44 {                                                                                                    
45     uint64_t pmc;
46
47     __asm __volatile("rdpmc" : "=A" (pmc) : "c" (index)); 
48     return pmc;                                                                                      
49 }
50
51
52 #endif /* PARLIB_ARCH_H */