thughes | 4ee6496 | 2004-06-16 20:51:45 +0000 | [diff] [blame] | 1 | |
| 2 | ##--------------------------------------------------------------------## |
njn | 6898086 | 2005-06-18 18:31:26 +0000 | [diff] [blame] | 3 | ##--- CPUID interface. m_cpuid.S ---## |
thughes | 4ee6496 | 2004-06-16 20:51:45 +0000 | [diff] [blame] | 4 | ##--------------------------------------------------------------------## |
| 5 | |
| 6 | /* |
njn | b9c427c | 2004-12-01 14:14:42 +0000 | [diff] [blame] | 7 | This file is part of Valgrind, a dynamic binary instrumentation |
| 8 | framework. |
thughes | 4ee6496 | 2004-06-16 20:51:45 +0000 | [diff] [blame] | 9 | |
njn | 5361242 | 2005-03-12 16:22:54 +0000 | [diff] [blame] | 10 | Copyright (C) 2000-2005 Julian Seward |
thughes | 4ee6496 | 2004-06-16 20:51:45 +0000 | [diff] [blame] | 11 | 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 | |
njn | c7561b9 | 2005-06-19 01:24:32 +0000 | [diff] [blame] | 31 | #include "pub_tool_basics_asm.h" |
thughes | 4ee6496 | 2004-06-16 20:51:45 +0000 | [diff] [blame] | 32 | |
| 33 | /* |
tom | b9c3d46 | 2005-03-29 09:53:47 +0000 | [diff] [blame] | 34 | Bool VG_(has_cpuid)(void) |
| 35 | */ |
| 36 | .globl VG_(has_cpuid) |
njn | 6898086 | 2005-06-18 18:31:26 +0000 | [diff] [blame] | 37 | #if defined(VGA_x86) |
| 38 | VG_(has_cpuid): |
tom | b9c3d46 | 2005-03-29 09:53:47 +0000 | [diff] [blame] | 39 | 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 |
njn | 6898086 | 2005-06-18 18:31:26 +0000 | [diff] [blame] | 59 | #elif defined(VGA_amd64) |
| 60 | VG_(has_cpuid): |
| 61 | movq $1, %rax |
| 62 | ret |
cerion | 85665ca | 2005-06-20 15:51:07 +0000 | [diff] [blame^] | 63 | #elif defined(VGA_appc32) |
| 64 | //CAB: TODO |
njn | 6898086 | 2005-06-18 18:31:26 +0000 | [diff] [blame] | 65 | #endif |
tom | b9c3d46 | 2005-03-29 09:53:47 +0000 | [diff] [blame] | 66 | |
| 67 | /* |
| 68 | void VG_(cpuid)(UInt eax, |
njn | 6898086 | 2005-06-18 18:31:26 +0000 | [diff] [blame] | 69 | UInt* eax_ret, UInt* ebx_ret, UInt* ecx_ret, UInt* edx_ret) |
thughes | 4ee6496 | 2004-06-16 20:51:45 +0000 | [diff] [blame] | 70 | */ |
| 71 | .globl VG_(cpuid) |
njn | 6898086 | 2005-06-18 18:31:26 +0000 | [diff] [blame] | 72 | #if defined(VGA_x86) |
| 73 | VG_(cpuid): |
thughes | 4ee6496 | 2004-06-16 20:51:45 +0000 | [diff] [blame] | 74 | pushl %ebp |
| 75 | movl %esp, %ebp |
| 76 | pushl %eax |
| 77 | pushl %ebx |
| 78 | pushl %ecx |
| 79 | pushl %edx |
| 80 | pushl %esi |
| 81 | movl 8(%ebp), %eax |
| 82 | cpuid |
| 83 | movl 12(%ebp), %esi |
| 84 | testl %esi, %esi |
| 85 | jz 1f |
| 86 | movl %eax, (%esi) |
njn | 6898086 | 2005-06-18 18:31:26 +0000 | [diff] [blame] | 87 | 1: |
thughes | 4ee6496 | 2004-06-16 20:51:45 +0000 | [diff] [blame] | 88 | movl 16(%ebp), %esi |
| 89 | testl %esi, %esi |
| 90 | jz 2f |
| 91 | movl %ebx, (%esi) |
njn | 6898086 | 2005-06-18 18:31:26 +0000 | [diff] [blame] | 92 | 2: |
thughes | 4ee6496 | 2004-06-16 20:51:45 +0000 | [diff] [blame] | 93 | movl 20(%ebp), %esi |
| 94 | testl %esi, %esi |
| 95 | jz 3f |
| 96 | movl %ecx, (%esi) |
njn | 6898086 | 2005-06-18 18:31:26 +0000 | [diff] [blame] | 97 | 3: |
thughes | 4ee6496 | 2004-06-16 20:51:45 +0000 | [diff] [blame] | 98 | movl 24(%ebp), %esi |
| 99 | testl %esi, %esi |
| 100 | jz 4f |
| 101 | movl %edx, (%esi) |
njn | 6898086 | 2005-06-18 18:31:26 +0000 | [diff] [blame] | 102 | 4: |
thughes | 4ee6496 | 2004-06-16 20:51:45 +0000 | [diff] [blame] | 103 | popl %esi |
| 104 | popl %edx |
| 105 | popl %ecx |
| 106 | popl %ebx |
| 107 | popl %eax |
| 108 | movl %ebp, %esp |
| 109 | popl %ebp |
| 110 | ret |
njn | 6898086 | 2005-06-18 18:31:26 +0000 | [diff] [blame] | 111 | #elif defined(VGA_amd64) |
| 112 | VG_(cpuid): |
| 113 | pushq %rbp |
| 114 | movq %rsp, %rbp |
| 115 | pushq %rbx |
| 116 | movl %edi, %eax |
| 117 | movq %rdx, %rdi |
| 118 | movq %rcx, %r9 |
| 119 | /* |
| 120 | eax_ret now in %rsi |
| 121 | ebx_ret now in %rdi |
| 122 | ecx_ret now in %r9 |
| 123 | edx_ret now in %r8 |
| 124 | */ |
| 125 | cpuid |
| 126 | testq %rsi, %rsi |
| 127 | jz 1f |
| 128 | movl %eax, (%rsi) |
| 129 | 1: |
| 130 | testq %rdi, %rdi |
| 131 | jz 2f |
| 132 | movl %ebx, (%rdi) |
| 133 | 2: |
| 134 | testq %r9, %r9 |
| 135 | jz 3f |
| 136 | movl %ecx, (%r9) |
| 137 | 3: |
| 138 | testq %r8, %r8 |
| 139 | jz 4f |
| 140 | movl %edx, (%r8) |
| 141 | 4: |
| 142 | popq %rbx |
| 143 | movq %rbp, %rsp |
| 144 | popq %rbp |
| 145 | ret |
cerion | 85665ca | 2005-06-20 15:51:07 +0000 | [diff] [blame^] | 146 | #elif defined(VGA_appc32) |
| 147 | //CAB: TODO |
njn | 6898086 | 2005-06-18 18:31:26 +0000 | [diff] [blame] | 148 | #endif |
thughes | 4ad52d0 | 2004-06-27 17:37:21 +0000 | [diff] [blame] | 149 | |
| 150 | /* Let the linker know we don't need an executable stack */ |
| 151 | .section .note.GNU-stack,"",@progbits |
njn | 6898086 | 2005-06-18 18:31:26 +0000 | [diff] [blame] | 152 | |
thughes | 4ad52d0 | 2004-06-27 17:37:21 +0000 | [diff] [blame] | 153 | ##--------------------------------------------------------------------## |
njn | 6898086 | 2005-06-18 18:31:26 +0000 | [diff] [blame] | 154 | ##--- end ---## |
thughes | 4ad52d0 | 2004-06-27 17:37:21 +0000 | [diff] [blame] | 155 | ##--------------------------------------------------------------------## |