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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
# Copyright (C) 2002-2014 Intel Corporation. All Rights Reserved.
#
# This file is part of SEP Development Kit
#
# SEP Development Kit is free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public License
# version 2 as published by the Free Software Foundation.
#
# SEP Development Kit is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with SEP Development Kit; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# As a special exception, you may use this file as part of a free software
# library without restriction. Specifically, if other files instantiate
# templates or use macros or inline functions from this file, or you compile
# this file and link it with other files to produce an executable, this
# file does not by itself cause the resulting executable to be covered by
# the GNU General Public License. This exception does not however
# invalidate any other reasons why the executable file might be covered by
# the GNU General Public License.
#include <linux/version.h>
#include <asm/segment.h>
#if LINUX_VERSION_CODE == KERNEL_VERSION(2,6,20)
#define USE_KERNEL_PERCPU_SEGMENT_GS
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21) && LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,29)
#define USE_KERNEL_PERCPU_SEGMENT_FS
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
#define USE_KERNEL_PERCPU_SEGMENT_FS
#define USE_KERNEL_PERCPU_SEGMENT_GS
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
#if !defined(__KERNEL_PERCPU)
#define __KERNEL_PERCPU __KERNEL_PDA
#endif
#endif
#***********************************************************************
#
# SYS_Get_IDT_Base_HWR
# Get the IDT Desc address
#
# Entry: none
#
# Exit: base address in eax
#
# void SYS_Get_IDT_Base_HWR(U64 *pIdtDesc);
#
#***********************************************************************
.text
.align 4
.global SYS_IO_Delay
SYS_IO_Delay:
ret
.global SYS_Get_IDT_Base_HWR
SYS_Get_IDT_Base_HWR:
subl $8,%esp
sidt 2(%esp)
movl 4(%esp),%eax
addl $8,%esp
ret
.global SYS_Get_cs
SYS_Get_cs:
mov %cs, %ax
andl $0x0000ffff, %eax
ret
.global SYS_Get_TSC
SYS_Get_TSC:
rdtsc
ret
.text
.align 4
.global SYS_Perfvec_Handler
SYS_Perfvec_Handler:
# This is the same as KERNEL's
pushl %eax # Filler for Error Code
cld
pushl %es # SAVE_ALL macro to access pt_regs
pushl %ds # inside our ISR.
#if defined(USE_KERNEL_PERCPU_SEGMENT_GS)
pushl %gs
#endif
#if defined(USE_KERNEL_PERCPU_SEGMENT_FS)
pushl %fs
#endif
pushl %eax
pushl %ebp
pushl %edi
pushl %esi
pushl %edx
pushl %ecx
pushl %ebx
movl $(__KERNEL_DS), %edx # Use KERNEL DS selector
movl %edx,%ds # Make sure we set Kernel
movl %edx,%es # DS into local DS and ES
#if defined(USE_KERNEL_PERCPU_SEGMENT_GS)
movl $(__KERNEL_PERCPU), %edx # Use kernel percpu segment
movl %edx,%gs # ... and load it into %gs
#endif
#if defined(USE_KERNEL_PERCPU_SEGMENT_FS)
movl $(__KERNEL_PERCPU), %edx # Use kernel percpu segment
movl %edx,%fs # ... and load it into %fs
#endif
movl %esp, %ebx # get ready to put *pt_regs on stack
pushl %ebx # put *pt_regs on the stack
call PMI_Interrupt_Handler
addl $0x4, %esp # pop to nowhere...
pop %ebx # restore register set
pop %ecx
pop %edx
pop %esi
pop %edi
pop %ebp
pop %eax
#if defined(USE_KERNEL_PERCPU_SEGMENT_FS)
pop %fs
#endif
#if defined(USE_KERNEL_PERCPU_SEGMENT_GS)
pop %gs
#endif
pop %ds
pop %es
pop %eax
iret
# ----------------------------------------------------------------------------
# name: get_CSD
#
# description: get the CS descriptor
#
# input: code segment selector
#
# output: code segment descriptor
# ----------------------------------------------------------------------------
.text
.align 4
.globl SYS_Get_CSD
SYS_Get_CSD:
pushl %ebp
movl %esp, %ebp
pushal # save regs
subl $8,%esp
xorl %eax, %eax
movw 8(%ebp), %ax # eax.lo = cs
sgdt (%esp) # store gdt reg
leal (%esp), %ebx # ebx = gdt reg ptr
movl 2(%ebx), %ecx # ecx = gdt base
xorl %edx, %edx
movw %ax, %dx
andl $4, %edx
cmpl $0, %edx # test ti. GDT?
jz .bsr_10 # ..yes
xorl %edx, %edx
sldt %dx # ..no dx=ldtsel
andb $0xf8, %dl # clear ti,rpl
addl 2(%ebx), %edx # add gdt base
movb 7(%edx), %cl # ecx = ldt base
shll $8, %ecx # ..
movb 4(%edx), %cl # ..
shll $16, %ecx # ..
movw 2(%edx), %cx # ..
.bsr_10:
andb $0xf8, %al # clear ti & rpl
addl %eax, %ecx # add to gdt/ldt
movl (%ecx), %eax # copy code seg
movl 12(%ebp), %edx # ..descriptor (csdlo)
movl %eax, (%edx) # ..descriptor (csdlo)
movl 4(%ecx), %eax # ..from gdt or
movl 16(%ebp), %edx # ..ldt to sample (csdhi)
movl %eax, (%edx) # ..ldt to sample (csdhi)
addl $8,%esp
popal # restore regs
leave
ret
|