blob: 6351ec21017db5e73d4f3e3842994b36971bc0bc [file] [log] [blame]
thughes4ee64962004-06-16 20:51:45 +00001
sewardj0e24d092006-10-17 20:47:13 +00002/*--------------------------------------------------------------------*/
3/*--- CPUID interface. m_cpuid.S ---*/
4/*--------------------------------------------------------------------*/
thughes4ee64962004-06-16 20:51:45 +00005
6/*
njnb9c427c2004-12-01 14:14:42 +00007 This file is part of Valgrind, a dynamic binary instrumentation
8 framework.
thughes4ee64962004-06-16 20:51:45 +00009
sewardj9ebd6e02007-01-08 06:01:59 +000010 Copyright (C) 2000-2007 Julian Seward
thughes4ee64962004-06-16 20:51:45 +000011 jseward@acm.org
12
13 This program is free software; you can redistribute it and/or
14 modify it under the terms of the GNU General Public License as
15 published by the Free Software Foundation; either version 2 of the
16 License, or (at your option) any later version.
17
18 This program is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
26 02111-1307, USA.
27
28 The GNU General Public License is contained in the file COPYING.
29*/
30
sewardj45f4e7c2005-09-27 19:20:21 +000031#include "pub_core_basics_asm.h"
thughes4ee64962004-06-16 20:51:45 +000032
33/*
tomb9c3d462005-03-29 09:53:47 +000034 Bool VG_(has_cpuid)(void)
35 */
36.globl VG_(has_cpuid)
njn68980862005-06-18 18:31:26 +000037#if defined(VGA_x86)
38 VG_(has_cpuid):
tomb9c3d462005-03-29 09:53:47 +000039 pushl %ebp
40 movl %esp, %ebp
41 pushl %ecx
42 pushfl
43 pushfl
44 popl %eax
45 movl %eax, %ecx
46 xorl $0x200000, %eax
47 pushl %eax
48 popfl
49 pushfl
50 popl %eax
51 popfl
52 xorl %ecx, %eax
53 andl $0x200000, %eax
54 shrl $21, %eax
55 popl %ecx
56 movl %ebp, %esp
57 popl %ebp
58 ret
njn68980862005-06-18 18:31:26 +000059#elif defined(VGA_amd64)
60 VG_(has_cpuid):
61 movq $1, %rax
62 ret
63#endif
tomb9c3d462005-03-29 09:53:47 +000064
65/*
66 void VG_(cpuid)(UInt eax,
njn68980862005-06-18 18:31:26 +000067 UInt* eax_ret, UInt* ebx_ret, UInt* ecx_ret, UInt* edx_ret)
thughes4ee64962004-06-16 20:51:45 +000068 */
69.globl VG_(cpuid)
njn68980862005-06-18 18:31:26 +000070#if defined(VGA_x86)
71 VG_(cpuid):
thughes4ee64962004-06-16 20:51:45 +000072 pushl %ebp
73 movl %esp, %ebp
74 pushl %eax
75 pushl %ebx
76 pushl %ecx
77 pushl %edx
78 pushl %esi
79 movl 8(%ebp), %eax
80 cpuid
81 movl 12(%ebp), %esi
82 testl %esi, %esi
83 jz 1f
84 movl %eax, (%esi)
njn68980862005-06-18 18:31:26 +000085 1:
thughes4ee64962004-06-16 20:51:45 +000086 movl 16(%ebp), %esi
87 testl %esi, %esi
88 jz 2f
89 movl %ebx, (%esi)
njn68980862005-06-18 18:31:26 +000090 2:
thughes4ee64962004-06-16 20:51:45 +000091 movl 20(%ebp), %esi
92 testl %esi, %esi
93 jz 3f
94 movl %ecx, (%esi)
njn68980862005-06-18 18:31:26 +000095 3:
thughes4ee64962004-06-16 20:51:45 +000096 movl 24(%ebp), %esi
97 testl %esi, %esi
98 jz 4f
99 movl %edx, (%esi)
njn68980862005-06-18 18:31:26 +0000100 4:
thughes4ee64962004-06-16 20:51:45 +0000101 popl %esi
102 popl %edx
103 popl %ecx
104 popl %ebx
105 popl %eax
106 movl %ebp, %esp
107 popl %ebp
108 ret
njn68980862005-06-18 18:31:26 +0000109#elif defined(VGA_amd64)
110 VG_(cpuid):
111 pushq %rbp
112 movq %rsp, %rbp
113 pushq %rbx
114 movl %edi, %eax
115 movq %rdx, %rdi
116 movq %rcx, %r9
117 /*
118 eax_ret now in %rsi
119 ebx_ret now in %rdi
120 ecx_ret now in %r9
121 edx_ret now in %r8
122 */
123 cpuid
124 testq %rsi, %rsi
125 jz 1f
126 movl %eax, (%rsi)
127 1:
128 testq %rdi, %rdi
129 jz 2f
130 movl %ebx, (%rdi)
131 2:
132 testq %r9, %r9
133 jz 3f
134 movl %ecx, (%r9)
135 3:
136 testq %r8, %r8
137 jz 4f
138 movl %edx, (%r8)
139 4:
140 popq %rbx
141 movq %rbp, %rsp
142 popq %rbp
143 ret
144#endif
sewardj745fc452006-10-17 02:03:11 +0000145
146#if defined(VGA_x86) || defined(VGA_amd64)
thughes4ad52d02004-06-27 17:37:21 +0000147/* Let the linker know we don't need an executable stack */
148.section .note.GNU-stack,"",@progbits
sewardj745fc452006-10-17 02:03:11 +0000149#endif
150
sewardj0e24d092006-10-17 20:47:13 +0000151/*--------------------------------------------------------------------*/
152/*--- end ---*/
153/*--------------------------------------------------------------------*/