xref: /reactos/hal/halx86/apic/tsccal.S (revision 7e22dc05)
1
2#include <asm.inc>
3#include "tsc.h"
4
5.code
6
7#ifdef _M_IX86
8
9EXTERN _TscCalibrationPhase:BYTE
10EXTERN _TscCalibrationArray:QWORD
11EXTERN _HalpSendEOI@0:PROC
12
13PUBLIC _TscCalibrationISR
14_TscCalibrationISR:
15    push eax
16    push ecx
17    push edx
18
19    /* The first thing we do is read the current TSC value */
20    rdtsc
21
22    /* Read the current phase */
23    movzx ecx, byte ptr ds:[_TscCalibrationPhase]
24
25    /* Check if we're already done */
26    cmp cl, NUM_SAMPLES
27    jnb _CalibrationISR_Exit
28
29    /* Store the current value */
30    shl ecx, 3
31    mov dword ptr _TscCalibrationArray[ecx], eax
32    mov dword ptr _TscCalibrationArray[ecx + 4], edx
33
34    /* Advance phase */
35    inc byte ptr ds:[_TscCalibrationPhase]
36
37_CalibrationISR_Exit:
38
39    /* Read CMOS register C */
40    mov al, HEX(0C)
41    out HEX(70), al
42    jmp $+2
43    in al, HEX(71)
44    jmp $+2
45
46    /* Send EOI */
47    call _HalpSendEOI@0
48
49    pop edx
50    pop ecx
51    pop eax
52    iretd
53
54#else
55
56EXTERN TscCalibrationPhase:BYTE
57EXTERN TscCalibrationArray:DWORD
58EXTERN HalpSendEOI:PROC
59
60PUBLIC TscCalibrationISR
61FUNC TscCalibrationISR
62    push rax
63    push rbx
64    push rcx
65    push rdx
66    .ENDPROLOG
67
68    /* The first thing we do is read the current TSC value */
69    rdtsc
70
71    /* Read the current phase */
72    movzx rcx, byte ptr [rip+TscCalibrationPhase]
73
74    /* Check if we're already done */
75    cmp cl, NUM_SAMPLES
76    jnb CalibrationISR_Exit
77
78    /* Store the current value */
79    shl rcx, 3
80    lea rbx, [rip+TscCalibrationArray]
81    mov dword ptr [rbx + rcx], eax
82    mov dword ptr [rbx + rcx + 4], edx
83
84    /* Advance phase */
85    inc byte ptr [rip+TscCalibrationPhase]
86
87CalibrationISR_Exit:
88    /* Read CMOS register C */
89    mov al, HEX(0C)
90    out HEX(70), al
91    jmp $+2
92    in al, HEX(71)
93    jmp $+2
94
95    /* Send EOI */
96    call HalpSendEOI
97
98    pop rdx
99    pop rcx
100    pop rbx
101    pop rax
102    iretq
103ENDFUNC
104#endif
105
106END
107