]> 4ch.mooo.com Git - 16.git/blob - src/lib/doslib/hw/cpu/cpurdtsc.h
added a bunch of things~ and midi stuff~
[16.git] / src / lib / doslib / hw / cpu / cpurdtsc.h
1 /* rdtsc.h
2  *
3  * Library of functions to read the Pentium TSC register.
4  * (C) 2009-2012 Jonathan Campbell.
5  * Hackipedia DOS library.
6  *
7  * This code is licensed under the LGPL.
8  * <insert LGPL legal text here>
9  *
10  */
11
12 #ifndef __HW_CPU_RDTSC_H
13 #define __HW_CPU_RDTSC_H
14
15 #include <stdint.h>
16
17 typedef uint64_t rdtsc_t;
18
19 #if TARGET_MSDOS == 32
20 static inline uint64_t cpu_rdtsc();
21 #pragma aux cpu_rdtsc = \
22         ".586p" \
23         "rdtsc" \
24         value [edx eax]
25
26 static inline void cpu_rdtsc_write(const uint64_t val);
27 #pragma aux cpu_rdtsc_write = \
28         ".586p" \
29         "mov ecx,0x10" \
30         "wrmsr" \
31         parm [edx eax] \
32         modify [ecx]
33 #else
34 /* This is too much code to inline insert everywhere---unless you want extra-large EXEs.
35  * It's better to conform to Watcom's register calling convention and make it a function.
36  * Note that if you look at the assembly language most of the code is shuffling the values
37  * around to convert EDX:EAX to AX:BX:CX:DX and disabling interrupts during the call. */
38 uint64_t cpu_rdtsc();
39 void cpu_rdtsc_write(const uint64_t val);
40 #endif
41
42 #endif /* __HW_CPU_RDTSC_H */
43