os-k/include/kernel/ke/cpuid.h

133 lines
5.1 KiB
C
Raw Permalink Normal View History

2019-04-24 11:40:28 +02:00
//----------------------------------------------------------------------------//
2020-09-27 17:33:48 +02:00
// OS on Kaleid //
2019-04-24 11:40:28 +02:00
// //
// Desc: CPUID related functions //
// //
// //
2021-02-18 19:54:35 +01:00
// Copyright © 2018-2021 The OS/K Team //
2019-04-24 11:40:28 +02:00
// //
// This file is part of OS/K. //
// //
// OS/K is free software: you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation, either version 3 of the License, or //
// any later version. //
// //
// OS/K is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY//without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------//
2019-05-13 23:22:27 +02:00
#ifndef _KERNEL_H
#include <kernel.h>
2019-04-24 11:40:28 +02:00
#endif
#ifndef _KALKERN_CPUID_H
#define _KALKERN_CPUID_H
// -------------------------------------------------------------------------- //
// CPU features masks
enum {
FEAT_ECX_SSE3 = 1 << 0,
FEAT_ECX_PCLMUL = 1 << 1,
FEAT_ECX_DTES64 = 1 << 2,
FEAT_ECX_MONITOR = 1 << 3,
FEAT_ECX_DS_CPL = 1 << 4,
FEAT_ECX_VMX = 1 << 5,
FEAT_ECX_SMX = 1 << 6,
FEAT_ECX_EST = 1 << 7,
FEAT_ECX_TM2 = 1 << 8,
FEAT_ECX_SSSE3 = 1 << 9,
FEAT_ECX_CID = 1 << 10,
FEAT_ECX_FMA = 1 << 12,
FEAT_ECX_CX16 = 1 << 13,
FEAT_ECX_ETPRD = 1 << 14,
FEAT_ECX_PDCM = 1 << 15,
FEAT_ECX_PCIDE = 1 << 17,
FEAT_ECX_DCA = 1 << 18,
FEAT_ECX_SSE4_1 = 1 << 19,
FEAT_ECX_SSE4_2 = 1 << 20,
FEAT_ECX_x2APIC = 1 << 21,
FEAT_ECX_MOVBE = 1 << 22,
FEAT_ECX_POPCNT = 1 << 23,
FEAT_ECX_AES = 1 << 25,
FEAT_ECX_XSAVE = 1 << 26,
FEAT_ECX_OSXSAVE = 1 << 27,
FEAT_ECX_AVX = 1 << 28,
FEAT_EDX_FPU = 1 << 0,
FEAT_EDX_VME = 1 << 1,
FEAT_EDX_DE = 1 << 2,
FEAT_EDX_PSE = 1 << 3,
FEAT_EDX_TSC = 1 << 4,
FEAT_EDX_MSR = 1 << 5,
FEAT_EDX_PAE = 1 << 6,
FEAT_EDX_MCE = 1 << 7,
FEAT_EDX_CX8 = 1 << 8,
FEAT_EDX_APIC = 1 << 9,
FEAT_EDX_SEP = 1 << 11,
FEAT_EDX_MTRR = 1 << 12,
FEAT_EDX_PGE = 1 << 13,
FEAT_EDX_MCA = 1 << 14,
FEAT_EDX_CMOV = 1 << 15,
FEAT_EDX_PAT = 1 << 16,
FEAT_EDX_PSE36 = 1 << 17,
FEAT_EDX_PSN = 1 << 18,
FEAT_EDX_CLF = 1 << 19,
FEAT_EDX_DTES = 1 << 21,
FEAT_EDX_ACPI = 1 << 22,
FEAT_EDX_MMX = 1 << 23,
FEAT_EDX_FXSR = 1 << 24,
FEAT_EDX_SSE = 1 << 25,
FEAT_EDX_SSE2 = 1 << 26,
FEAT_EDX_SS = 1 << 27,
FEAT_EDX_HTT = 1 << 28,
FEAT_EDX_TM1 = 1 << 29,
FEAT_EDX_IA64 = 1 << 30,
FEAT_EDX_PBE = 1 << 31
};
2019-05-09 21:57:54 +02:00
2019-04-24 11:40:28 +02:00
// -------------------------------------------------------------------------- //
2019-05-09 12:00:30 +02:00
// Issue a single request to CPUID. Fits 'intel features', for instance
// note that even if only "eax" and "edx" are of interest, other registers
// will be modified by the operation, so we need to tell the compiler about it.
2019-05-22 23:32:44 +02:00
static inline void CpuCpuid(int code, uint *eax, uint *edx)
2019-05-09 12:00:30 +02:00
{
2019-05-22 23:32:44 +02:00
asm volatile("cpuid":"=a"(*eax),"=d"(*edx):"a"(code):"ecx","ebx");
2019-05-09 12:00:30 +02:00
}
// Issue a complete request, storing general registers output as a string
static inline int CpuCpuidString(int code, uint where[4])
2019-04-24 11:40:28 +02:00
{
2019-05-09 12:00:30 +02:00
asm volatile("cpuid":"=a"(*where),"=b"(*(where+1)),
"=c"(*(where+3)),"=d"(*(where+2)):"a"(code));
return (int)where[0];
}
2019-04-24 11:40:28 +02:00
2019-11-15 00:09:20 +01:00
// Read the TSC register
static inline ulong CpuRdtsc(void)
{
uint lo, hi;
asm volatile ("rdtsc" : "=a"(lo), "=d"(hi));
return ( (ulong)lo)|( ((ulong)hi)<<32 );
}
2019-05-22 23:32:44 +02:00
void KeGetCpuInfos(void);
2019-11-15 00:09:20 +01:00
double KeGetCpuFrequency(void);
2019-05-27 20:45:05 +02:00
void KeActivateSSE(void);
2019-05-22 19:41:00 +02:00
2019-04-24 11:40:28 +02:00
// -------------------------------------------------------------------------- //
#endif