Skip to content

Commit

Permalink
CPU capabilities are now detected and displayed
Browse files Browse the repository at this point in the history
  • Loading branch information
lubenard committed Feb 29, 2024
1 parent cec4e44 commit 2ec380a
Show file tree
Hide file tree
Showing 2 changed files with 201 additions and 4 deletions.
138 changes: 135 additions & 3 deletions srcs/drivers/cpu/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ void check_cpu_features() {
get_cpu_features();
}

// This function is called via ASM function check_cpu_vendor
// Letters are stored as int
// Example:
// ebx might look this: 1970169159, which is actually translated to 1110101 01101110 01100101 01000111
Expand Down Expand Up @@ -37,6 +38,137 @@ void display_cpu_vendor(int ebx, int edx, int ecx) {
);
}

void display_cpu_features(int s1, int s2) {
printd(KERN_INFO, "CPU features are: %d %d", s1, s2);
}
void check_ecx_features(int ecx) {
if (ecx & CPUID_FEAT_ECX_SSE3)
printd(KERN_NORMAL, "SSE3, ");
if (ecx & CPUID_FEAT_ECX_PCLMUL)
printd(KERN_NORMAL, "PCLMUL, ");
if (ecx & CPUID_FEAT_ECX_DTES64)
printd(KERN_NORMAL, "DTES64, ");
if (ecx & CPUID_FEAT_ECX_MONITOR)
printd(KERN_NORMAL, "MONITOR, ");
if (ecx & CPUID_FEAT_ECX_DS_CPL)
printd(KERN_NORMAL, "DS_CPl, ");
if (ecx & CPUID_FEAT_ECX_VMX)
printd(KERN_NORMAL, "VMX, ");
if (ecx & CPUID_FEAT_ECX_SMX)
printd(KERN_NORMAL, "SMX, ");
if (ecx & CPUID_FEAT_ECX_EST)
printd(KERN_NORMAL, "EST, ");
if (ecx & CPUID_FEAT_ECX_TM2)
printd(KERN_NORMAL, "TM2, ");
if (ecx & CPUID_FEAT_ECX_SSSE3)
printd(KERN_NORMAL, "SSSE3, ");
if (ecx & CPUID_FEAT_ECX_CID)
printd(KERN_NORMAL, "CID, ");
if (ecx & CPUID_FEAT_ECX_SDBG)
printd(KERN_NORMAL, "SDBG, ");
if (ecx & CPUID_FEAT_ECX_FMA)
printd(KERN_NORMAL, "FMA, ");
if (ecx & CPUID_FEAT_ECX_CX16)
printd(KERN_NORMAL, "CX16, ");
if (ecx & CPUID_FEAT_ECX_XTPR)
printd(KERN_NORMAL, "XPTR, ");
if (ecx & CPUID_FEAT_ECX_PDCM)
printd(KERN_NORMAL, "PDCM, ");
if (ecx & CPUID_FEAT_ECX_PCID)
printd(KERN_NORMAL, "PCID, ");
if (ecx & CPUID_FEAT_ECX_DCA)
printd(KERN_NORMAL, "DCA, ");
if (ecx & CPUID_FEAT_ECX_SSE4_1)
printd(KERN_NORMAL, "SSE4_1, ");
if (ecx & CPUID_FEAT_ECX_SSE4_2)
printd(KERN_NORMAL, "SSE4_2, ");
if (ecx & CPUID_FEAT_ECX_X2APIC)
printd(KERN_NORMAL, "X2APIC, ");
if (ecx & CPUID_FEAT_ECX_MOVBE)
printd(KERN_NORMAL, "MOVBE, ");
if (ecx & CPUID_FEAT_ECX_POPCNT)
printd(KERN_NORMAL, "POPCNT, ");
if (ecx & CPUID_FEAT_ECX_TSC)
printd(KERN_NORMAL, "TSC, ");
if (ecx & CPUID_FEAT_ECX_AES)
printd(KERN_NORMAL, "AES, ");
if (ecx & CPUID_FEAT_ECX_XSAVE)
printd(KERN_NORMAL, "XSAVE, ");
if (ecx & CPUID_FEAT_ECX_OSXSAVE)
printd(KERN_NORMAL, "OSXSAVE, ");
if (ecx & CPUID_FEAT_ECX_AVX)
printd(KERN_NORMAL, "AVX, ");
if (ecx & CPUID_FEAT_ECX_F16C)
printd(KERN_NORMAL, "F16C, ");
if (ecx & CPUID_FEAT_ECX_RDRAND)
printd(KERN_NORMAL, "RDRAND, ");
if (ecx & CPUID_FEAT_ECX_HYPERVISOR)
printd(KERN_NORMAL, "HYPERVISOR, ");
}

void check_edx_features(int edx) {
if (edx & CPUID_FEAT_EDX_FPU)
printd(KERN_NORMAL, "FPU, ");
if (edx & CPUID_FEAT_EDX_VME)
printd(KERN_NORMAL, "VME, ");
if (edx & CPUID_FEAT_EDX_DE)
printd(KERN_NORMAL, "DE, ");
if (edx & CPUID_FEAT_EDX_PSE)
printd(KERN_NORMAL, "PSE, ");
if (edx & CPUID_FEAT_EDX_TSC)
printd(KERN_NORMAL, "TSC, ");
if (edx & CPUID_FEAT_EDX_MSR)
printd(KERN_NORMAL, "MSR, ");
if (edx & CPUID_FEAT_EDX_PAE)
printd(KERN_NORMAL, "PAE, ");
if (edx & CPUID_FEAT_EDX_MCE)
printd(KERN_NORMAL, "MCE, ");
if (edx & CPUID_FEAT_EDX_CX8)
printd(KERN_NORMAL, "CX8, ");
if (edx & CPUID_FEAT_EDX_APIC)
printd(KERN_NORMAL, "APIC, ");
if (edx & CPUID_FEAT_EDX_SEP)
printd(KERN_NORMAL, "SEP, ");
if (edx & CPUID_FEAT_EDX_MTRR)
printd(KERN_NORMAL, "MTRR, ");
if (edx & CPUID_FEAT_EDX_PGE)
printd(KERN_NORMAL, "PGE, ");
if (edx & CPUID_FEAT_EDX_MCA)
printd(KERN_NORMAL, "MCA, ");
if (edx & CPUID_FEAT_EDX_CMOV)
printd(KERN_NORMAL, "CMOV, ");
if (edx & CPUID_FEAT_EDX_PAT)
printd(KERN_NORMAL, "PAT, ");
if (edx & CPUID_FEAT_EDX_PSE36)
printd(KERN_NORMAL, "PSE36, ");
if (edx & CPUID_FEAT_EDX_PSN)
printd(KERN_NORMAL, "PSN, ");
if (edx & CPUID_FEAT_EDX_CLFLUSH)
printd(KERN_NORMAL, "CLFLUSH, ");
if (edx & CPUID_FEAT_EDX_DS)
printd(KERN_NORMAL, "DS, ");
if (edx & CPUID_FEAT_EDX_ACPI)
printd(KERN_NORMAL, "ACPI, ");
if (edx & CPUID_FEAT_EDX_MMX)
printd(KERN_NORMAL, "MMX, ");
if (edx & CPUID_FEAT_EDX_FXSR)
printd(KERN_NORMAL, "FXSR, ");
if (edx & CPUID_FEAT_EDX_SSE)
printd(KERN_NORMAL, "SSE, ");
if (edx & CPUID_FEAT_EDX_SSE2)
printd(KERN_NORMAL, "SSE2, ");
if (edx & CPUID_FEAT_EDX_SS)
printd(KERN_NORMAL, "SS, ");
if (edx & CPUID_FEAT_EDX_HTT)
printd(KERN_NORMAL, "HTT, ");
if (edx & CPUID_FEAT_EDX_TM)
printd(KERN_NORMAL, "TM, ");
if (edx & CPUID_FEAT_EDX_IA64)
printd(KERN_NORMAL, "IA64, ");
if (edx & CPUID_FEAT_EDX_PBE)
printd(KERN_NORMAL, "PBE, ");
}

void display_cpu_features(int edx, int ecx) {
printd(KERN_NORMAL, "CPU features are: ");
check_edx_features(edx);
check_ecx_features(ecx);
printd(KERN_NORMAL, "\n");
}
67 changes: 66 additions & 1 deletion srcs/drivers/cpu/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: luca </var/spool/mail/luca> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/02 14:11:48 by luca #+# #+# */
/* Updated: 2024/02/02 14:11:48 by luca ### ########.fr */
/* Updated: 2024/02/29 11:24:26 by lubenard ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -46,6 +46,71 @@
#define CPUID_VENDOR_BHYVE "bhyve bhyve "
#define CPUID_VENDOR_QNX " QNXQVMBSQG "

enum {
CPUID_FEAT_ECX_SSE3 = 1 << 0, // 1
CPUID_FEAT_ECX_PCLMUL = 1 << 1, // 2
CPUID_FEAT_ECX_DTES64 = 1 << 2, // 4
CPUID_FEAT_ECX_MONITOR = 1 << 3, // 8 ....
CPUID_FEAT_ECX_DS_CPL = 1 << 4,
CPUID_FEAT_ECX_VMX = 1 << 5,
CPUID_FEAT_ECX_SMX = 1 << 6,
CPUID_FEAT_ECX_EST = 1 << 7,
CPUID_FEAT_ECX_TM2 = 1 << 8,
CPUID_FEAT_ECX_SSSE3 = 1 << 9,
CPUID_FEAT_ECX_CID = 1 << 10,
CPUID_FEAT_ECX_SDBG = 1 << 11,
CPUID_FEAT_ECX_FMA = 1 << 12,
CPUID_FEAT_ECX_CX16 = 1 << 13,
CPUID_FEAT_ECX_XTPR = 1 << 14,
CPUID_FEAT_ECX_PDCM = 1 << 15,
CPUID_FEAT_ECX_PCID = 1 << 17,
CPUID_FEAT_ECX_DCA = 1 << 18,
CPUID_FEAT_ECX_SSE4_1 = 1 << 19,
CPUID_FEAT_ECX_SSE4_2 = 1 << 20,
CPUID_FEAT_ECX_X2APIC = 1 << 21,
CPUID_FEAT_ECX_MOVBE = 1 << 22,
CPUID_FEAT_ECX_POPCNT = 1 << 23,
CPUID_FEAT_ECX_TSC = 1 << 24,
CPUID_FEAT_ECX_AES = 1 << 25,
CPUID_FEAT_ECX_XSAVE = 1 << 26,
CPUID_FEAT_ECX_OSXSAVE = 1 << 27,
CPUID_FEAT_ECX_AVX = 1 << 28,
CPUID_FEAT_ECX_F16C = 1 << 29,
CPUID_FEAT_ECX_RDRAND = 1 << 30,
CPUID_FEAT_ECX_HYPERVISOR = 1 << 31,

CPUID_FEAT_EDX_FPU = 1 << 0,
CPUID_FEAT_EDX_VME = 1 << 1,
CPUID_FEAT_EDX_DE = 1 << 2,
CPUID_FEAT_EDX_PSE = 1 << 3,
CPUID_FEAT_EDX_TSC = 1 << 4,
CPUID_FEAT_EDX_MSR = 1 << 5,
CPUID_FEAT_EDX_PAE = 1 << 6,
CPUID_FEAT_EDX_MCE = 1 << 7,
CPUID_FEAT_EDX_CX8 = 1 << 8,
CPUID_FEAT_EDX_APIC = 1 << 9,
CPUID_FEAT_EDX_SEP = 1 << 11,
CPUID_FEAT_EDX_MTRR = 1 << 12,
CPUID_FEAT_EDX_PGE = 1 << 13,
CPUID_FEAT_EDX_MCA = 1 << 14,
CPUID_FEAT_EDX_CMOV = 1 << 15,
CPUID_FEAT_EDX_PAT = 1 << 16,
CPUID_FEAT_EDX_PSE36 = 1 << 17,
CPUID_FEAT_EDX_PSN = 1 << 18,
CPUID_FEAT_EDX_CLFLUSH = 1 << 19,
CPUID_FEAT_EDX_DS = 1 << 21,
CPUID_FEAT_EDX_ACPI = 1 << 22,
CPUID_FEAT_EDX_MMX = 1 << 23,
CPUID_FEAT_EDX_FXSR = 1 << 24,
CPUID_FEAT_EDX_SSE = 1 << 25,
CPUID_FEAT_EDX_SSE2 = 1 << 26,
CPUID_FEAT_EDX_SS = 1 << 27,
CPUID_FEAT_EDX_HTT = 1 << 28,
CPUID_FEAT_EDX_TM = 1 << 29,
CPUID_FEAT_EDX_IA64 = 1 << 30,
CPUID_FEAT_EDX_PBE = 1 << 31
};

void check_cpu_features();
void display_cpu_vendor(int s1, int s2, int s3);
void display_cpu_features(int s1, int s2);
Expand Down

0 comments on commit 2ec380a

Please sign in to comment.