1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
; $Id: rdtsc-asm.asm $
;; @file
; RDTSC test, assembly code
;
;
; Copyright (C) 2009-2019 Oracle Corporation
;
; This file is part of VirtualBox Open Source Edition (OSE), as
; available from http://www.virtualbox.org. This file is free software;
; you can redistribute it and/or modify it under the terms of the GNU
; General Public License (GPL) as published by the Free Software
; Foundation, in version 2 as it comes in the "COPYING" file of the
; VirtualBox OSE distribution. VirtualBox OSE is distributed in the
; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
;
; The contents of this file may alternatively be used under the terms
; of the Common Development and Distribution License Version 1.0
; (CDDL) only, as it comes in the "COPYING.CDDL" file of the
; VirtualBox OSE distribution, in which case the provisions of the
; CDDL are applicable instead of those of the GPL.
;
; You may elect to license modified versions of this file under the
; terms and conditions of either the GPL or the CDDL or both.
;
;*********************************************************************************************************************************
;* Header Files *
;*********************************************************************************************************************************
%include "iprt/asmdefs.mac"
%include "iprt/x86.mac"
;*********************************************************************************************************************************
;* Global Variables *
;*********************************************************************************************************************************
BEGINDATA
;;
; Where DoTscReads() returns the rdtsc values.
;
; @note The results are 32-bit value pairs in x86 mode and 64-bit pairs in
; AMD64 mode.
GLOBALNAME g_aRdTscResults
%ifdef RT_ARCH_AMD64
dq 0, 0
dq 0, 0 ; first value stored
dq 0, 0
dq 0, 0
dq 0, 0
dq 0, 0
dq 0, 0
%else
dq 0, 0
dd 0, 0 ; first value stored
dd 0, 0
dd 0, 0
%endif
BEGINCODE
;; Takes no arguments, returns number of values read into g_aRdTscResults.
BEGINPROC DoTscReads
push xBP
mov xBP, xSP
%ifdef RT_ARCH_AMD64
mov rax, 0feedfacecafebabeh
mov rdx, 0cafebabefeedfaceh
mov r8, 0deadbeef0deadbeefh
mov r9, 0deadbeef0deadbeefh
mov r10, 0deadbeef0deadbeefh
mov r11, 0deadbeef0deadbeefh
push rbx
push r12
push r13
push r14
push r15
; Read 6x TSC into registers.
rdtsc
mov r8, rax
mov r9, rdx
rdtsc
mov r10, rax
mov r11, rdx
rdtsc
mov r12, rax
mov r13, rdx
rdtsc
mov r14, rax
mov r15, rdx
rdtsc
mov rbx, rax
mov rcx, rdx
rdtsc
; Store the values (64-bit).
mov [NAME(g_aRdTscResults) + 10h xWrtRIP], r8
mov [NAME(g_aRdTscResults) + 18h xWrtRIP], r9
mov [NAME(g_aRdTscResults) + 20h xWrtRIP], r10
mov [NAME(g_aRdTscResults) + 28h xWrtRIP], r11
mov [NAME(g_aRdTscResults) + 30h xWrtRIP], r12
mov [NAME(g_aRdTscResults) + 38h xWrtRIP], r13
mov [NAME(g_aRdTscResults) + 40h xWrtRIP], r14
mov [NAME(g_aRdTscResults) + 48h xWrtRIP], r15
mov [NAME(g_aRdTscResults) + 50h xWrtRIP], rbx
mov [NAME(g_aRdTscResults) + 58h xWrtRIP], rcx
mov [NAME(g_aRdTscResults) + 60h xWrtRIP], rax
mov [NAME(g_aRdTscResults) + 68h xWrtRIP], rdx
pop r15
pop r14
pop r13
pop r12
pop rbx
mov eax, 6
%else
mov eax, 0feedfaceh
mov edx, 0cafebabeh
push esi
push edi
push ebx
; Read 3x TSC into registers.
rdtsc
mov ebx, eax
mov ecx, edx
rdtsc
mov esi, eax
mov edi, edx
rdtsc
; Store values.
mov [NAME(g_aRdTscResults) + 08h], ebx
mov [NAME(g_aRdTscResults) + 0ch], ecx
mov [NAME(g_aRdTscResults) + 10h], esi
mov [NAME(g_aRdTscResults) + 14h], edi
mov [NAME(g_aRdTscResults) + 18h], eax
mov [NAME(g_aRdTscResults) + 1ch], edx
pop ebx
pop edi
pop esi
mov eax, 3
%endif
leave
ret
ENDPROC DoTscReads
|