blob: 9ba75ecc371bf97377c23d96aafd26543ea75d28 [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
sewardjb3a1e4b2015-08-21 11:32:26 +000010 Copyright (C) 2000-2015 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 */
njn68980862005-06-18 18:31:26 +000036#if defined(VGA_x86)
sewardj59570ff2010-01-01 11:59:33 +000037.text
38.globl VG_(has_cpuid)
njn68980862005-06-18 18:31:26 +000039 VG_(has_cpuid):
tomb9c3d462005-03-29 09:53:47 +000040 pushl %ebp
41 movl %esp, %ebp
42 pushl %ecx
43 pushfl
44 pushfl
45 popl %eax
46 movl %eax, %ecx
47 xorl $0x200000, %eax
48 pushl %eax
49 popfl
50 pushfl
51 popl %eax
52 popfl
53 xorl %ecx, %eax
54 andl $0x200000, %eax
55 shrl $21, %eax
56 popl %ecx
57 movl %ebp, %esp
58 popl %ebp
59 ret
njn68980862005-06-18 18:31:26 +000060#elif defined(VGA_amd64)
sewardj59570ff2010-01-01 11:59:33 +000061.text
62.globl VG_(has_cpuid)
njn68980862005-06-18 18:31:26 +000063 VG_(has_cpuid):
64 movq $1, %rax
65 ret
66#endif
tomb9c3d462005-03-29 09:53:47 +000067
68/*
tomad8a5912011-06-10 15:04:22 +000069 void VG_(cpuid)(UInt eax, UInt ecx,
njn68980862005-06-18 18:31:26 +000070 UInt* eax_ret, UInt* ebx_ret, UInt* ecx_ret, UInt* edx_ret)
thughes4ee64962004-06-16 20:51:45 +000071 */
njn68980862005-06-18 18:31:26 +000072#if defined(VGA_x86)
sewardj59570ff2010-01-01 11:59:33 +000073.text
74.globl VG_(cpuid)
njn68980862005-06-18 18:31:26 +000075 VG_(cpuid):
thughes4ee64962004-06-16 20:51:45 +000076 pushl %ebp
77 movl %esp, %ebp
78 pushl %eax
79 pushl %ebx
80 pushl %ecx
81 pushl %edx
82 pushl %esi
83 movl 8(%ebp), %eax
tomad8a5912011-06-10 15:04:22 +000084 movl 12(%ebp), %ecx
thughes4ee64962004-06-16 20:51:45 +000085 cpuid
tomad8a5912011-06-10 15:04:22 +000086 movl 16(%ebp), %esi
thughes4ee64962004-06-16 20:51:45 +000087 testl %esi, %esi
88 jz 1f
89 movl %eax, (%esi)
njn68980862005-06-18 18:31:26 +000090 1:
tomad8a5912011-06-10 15:04:22 +000091 movl 20(%ebp), %esi
thughes4ee64962004-06-16 20:51:45 +000092 testl %esi, %esi
93 jz 2f
94 movl %ebx, (%esi)
njn68980862005-06-18 18:31:26 +000095 2:
tomad8a5912011-06-10 15:04:22 +000096 movl 24(%ebp), %esi
thughes4ee64962004-06-16 20:51:45 +000097 testl %esi, %esi
98 jz 3f
99 movl %ecx, (%esi)
njn68980862005-06-18 18:31:26 +0000100 3:
tomad8a5912011-06-10 15:04:22 +0000101 movl 28(%ebp), %esi
thughes4ee64962004-06-16 20:51:45 +0000102 testl %esi, %esi
103 jz 4f
104 movl %edx, (%esi)
njn68980862005-06-18 18:31:26 +0000105 4:
thughes4ee64962004-06-16 20:51:45 +0000106 popl %esi
107 popl %edx
108 popl %ecx
109 popl %ebx
110 popl %eax
111 movl %ebp, %esp
112 popl %ebp
113 ret
njn68980862005-06-18 18:31:26 +0000114#elif defined(VGA_amd64)
sewardj59570ff2010-01-01 11:59:33 +0000115.text
116.globl VG_(cpuid)
njn68980862005-06-18 18:31:26 +0000117 VG_(cpuid):
118 pushq %rbp
119 movq %rsp, %rbp
120 pushq %rbx
121 movl %edi, %eax
tomad8a5912011-06-10 15:04:22 +0000122 movq %rcx, %rdi
123 movl %esi, %ecx
124 movq %rdx, %rsi
njn68980862005-06-18 18:31:26 +0000125 /*
126 eax_ret now in %rsi
127 ebx_ret now in %rdi
tomad8a5912011-06-10 15:04:22 +0000128 ecx_ret now in %r8
129 edx_ret now in %r9
njn68980862005-06-18 18:31:26 +0000130 */
131 cpuid
132 testq %rsi, %rsi
133 jz 1f
134 movl %eax, (%rsi)
135 1:
136 testq %rdi, %rdi
137 jz 2f
138 movl %ebx, (%rdi)
139 2:
njn68980862005-06-18 18:31:26 +0000140 testq %r8, %r8
tomad8a5912011-06-10 15:04:22 +0000141 jz 3f
142 movl %ecx, (%r8)
143 3:
144 testq %r9, %r9
njn68980862005-06-18 18:31:26 +0000145 jz 4f
tomad8a5912011-06-10 15:04:22 +0000146 movl %edx, (%r9)
njn68980862005-06-18 18:31:26 +0000147 4:
148 popq %rbx
149 movq %rbp, %rsp
150 popq %rbp
151 ret
152#endif
sewardj745fc452006-10-17 02:03:11 +0000153
thughes4ad52d02004-06-27 17:37:21 +0000154/* Let the linker know we don't need an executable stack */
florian3f1d6132015-09-30 20:30:48 +0000155MARK_STACK_NO_EXEC
sewardj745fc452006-10-17 02:03:11 +0000156
sewardj0e24d092006-10-17 20:47:13 +0000157/*--------------------------------------------------------------------*/
158/*--- end ---*/
159/*--------------------------------------------------------------------*/