correctly mark code segments as code in SELF
[coreboot.git] / util / msrtool / sys.c
1 /*
2  * This file is part of msrtool.
3  *
4  * Copyright (c) 2008 Peter Stuge <peter@stuge.se>
5  * Copyright (c) 2009 coresystems GmbH
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
19  */
20
21 #include <pci/pci.h>
22
23 #include "msrtool.h"
24
25 static struct cpuid_t id;
26
27 struct cpuid_t *cpuid(void) {
28         uint32_t outeax;
29
30 #if defined(__DARWIN__) && !defined(__LP64__)
31         asm volatile (
32                 "pushl %%ebx    \n"
33                 "cpuid          \n"
34                 "popl %%ebx     \n"
35                 : "=a" (outeax) : "a" (1) : "%ecx", "%edx"
36         );
37 #else
38         asm ("cpuid" : "=a" (outeax) : "a" (1) : "%ebx", "%ecx", "%edx");
39 #endif
40
41         id.stepping = outeax & 0xf;
42         outeax >>= 4;
43         id.model = outeax & 0xf;
44         outeax >>= 4;
45         id.family = outeax & 0xf;
46         outeax >>= 8;
47         id.ext_model = outeax & 0xf;
48         outeax >>= 4;
49         id.ext_family = outeax & 0xff;
50         if (0xf == id.family) {
51                 /* Intel says always do this, AMD says only for family f */
52                 id.model |= (id.ext_model << 4);
53                 id.family += id.ext_family;
54         }
55         printf_verbose("CPU: family %x, model %x, stepping %x\n",
56                         id.family, id.model, id.stepping);
57
58         return &id;
59 }
60
61 struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device) {
62         struct pci_dev *temp;
63         struct pci_filter filter;
64
65         pci_filter_init(NULL, &filter);
66         filter.vendor = vendor;
67         filter.device = device;
68
69         for (temp = pacc->devices; temp; temp = temp->next)
70                 if (pci_filter_match(&filter, temp))
71                         return temp;
72
73         return NULL;
74 }