Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * This file is part of msrtool. |
| 3 | * |
| 4 | * Copyright (c) 2008 Peter Stuge <peter@stuge.se> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | #include "msrtool.h" |
| 21 | |
| 22 | static struct cpuid_t id; |
| 23 | |
| 24 | struct cpuid_t *cpuid(void) { |
| 25 | uint32_t outeax; |
| 26 | asm ("cpuid" : "=a" (outeax) : "a" (1) : "%ebx", "%ecx", "%edx"); |
| 27 | id.stepping = outeax & 0xf; |
| 28 | outeax >>= 4; |
| 29 | id.model = outeax & 0xf; |
| 30 | outeax >>= 4; |
| 31 | id.family = outeax & 0xf; |
| 32 | outeax >>= 8; |
| 33 | id.ext_model = outeax & 0xf; |
| 34 | outeax >>= 4; |
| 35 | id.ext_family = outeax & 0xff; |
| 36 | if (0xf == id.family) { |
| 37 | /* Intel says always do this, AMD says only for family f */ |
| 38 | id.model |= (id.ext_model << 4); |
| 39 | id.family += id.ext_family; |
| 40 | } |
| 41 | return &id; |
| 42 | } |