Back to home page

Quest Cross Reference

 
 

    


Warning, cross-references for /kernel/util/cpuid.c need to be fixed.

0001 /*                    The Quest Operating System
0002  *  Copyright (C) 2005-2010  Richard West, Boston University
0003  *
0004  *  This program is free software: you can redistribute it and/or modify
0005  *  it under the terms of the GNU General Public License as published by
0006  *  the Free Software Foundation, either version 3 of the License, or
0007  *  (at your option) any later version.
0008  *
0009  *  This program is distributed in the hope that it will be useful,
0010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0012  *  GNU General Public License for more details.
0013  *
0014  *  You should have received a copy of the GNU General Public License
0015  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
0016  */
0017 
0018 #include"arch/i386.h"
0019 #include"util/cpuid.h"
0020 #include"kernel.h"
0021 
0022 void
0023 cpuid_get_brand_string (char *str, uint32 n)
0024 {
0025   uint32 eax, ebx, ecx, edx;
0026   char buf[I386_CPUID_BRAND_STRING_LENGTH], *ptr = buf;
0027 
0028   if (n < 1)
0029     return;
0030   cpuid (I386_CPUID_BRAND_STRING_INPUT1, 0, &eax, NULL, NULL, NULL);
0031   if (eax & I386_CPUID_BRAND_STRING_INPUT1) {
0032 #define WRBUF(r) *((int *)ptr) = r; ptr+=4
0033     cpuid (I386_CPUID_BRAND_STRING_INPUT2, 0, &eax, &ebx, &ecx, &edx);
0034     WRBUF (eax);
0035     WRBUF (ebx);
0036     WRBUF (ecx);
0037     WRBUF (edx);
0038     cpuid (I386_CPUID_BRAND_STRING_INPUT3, 0, &eax, &ebx, &ecx, &edx);
0039     WRBUF (eax);
0040     WRBUF (ebx);
0041     WRBUF (ecx);
0042     WRBUF (edx);
0043     cpuid (I386_CPUID_BRAND_STRING_INPUT4, 0, &eax, &ebx, &ecx, &edx);
0044     WRBUF (eax);
0045     WRBUF (ebx);
0046     WRBUF (ecx);
0047     WRBUF (edx);
0048     buf[48] = 0;                /* nul-terminate */
0049     memcpy (str, buf,
0050             n <
0051             I386_CPUID_BRAND_STRING_LENGTH ? n :
0052             I386_CPUID_BRAND_STRING_LENGTH);
0053   } else {
0054     memcpy (str, "Brand String not supported.", n);
0055   }
0056   str[n - 1] = 0;
0057 }
0058 
0059 uint32
0060 cpuid_display_family_model (void)
0061 {
0062   u32 family, model;
0063   u32 eax, display = 0;
0064 
0065   cpuid (1, 0, &eax, NULL, NULL, NULL);
0066   model = (eax >> 4) & 0xF;
0067   family = (eax >> 8) & 0xF;
0068 
0069   if (family != 0xF)
0070     display |= family << 8;
0071   else
0072     display |= (family + ((eax >> 20) & 0xFF)) << 8;
0073 
0074   if (family == 0xF || family == 0x6)
0075     display |= model + (((eax >> 16) & 0xF) << 4);
0076   else
0077     display |= model;
0078 
0079   return display;
0080 }
0081 
0082 bool
0083 cpuid_tsc_support (void)
0084 {
0085   int edx;
0086   cpuid (1, 0, NULL, NULL, NULL, &edx);
0087   return (edx & (1 << 4));
0088 }
0089 
0090 bool
0091 cpuid_rdtscp_support (void)
0092 {
0093   uint edx;
0094   cpuid (0x80000001, 0, NULL, NULL, NULL, &edx);
0095   return (edx & (1 << 27));
0096 }
0097 
0098 bool
0099 cpuid_invariant_tsc_support (void)
0100 {
0101   uint edx;
0102   cpuid (0x80000007, 0, NULL, NULL, NULL, &edx);
0103   return (edx & (1 << 8));
0104 }
0105 
0106 bool
0107 cpuid_msr_support (void)
0108 {
0109   int edx;
0110   cpuid (1, 0, NULL, NULL, NULL, &edx);
0111   return (edx & (1 << 5));
0112 }
0113 
0114 bool
0115 cpuid_vmx_support (void)
0116 {
0117   int ecx;
0118   cpuid (1, 0, NULL, NULL, &ecx, NULL);
0119   return (ecx & (1 << 5));
0120 }
0121 
0122 /*
0123  * Local Variables:
0124  * indent-tabs-mode: nil
0125  * mode: C
0126  * c-file-style: "gnu"
0127  * c-basic-offset: 2
0128  * End:
0129  */
0130 
0131 /* vi: set et sw=2 sts=2: */