Skip to content

Commit

Permalink
Cleanup and improve CPU feature detection (#104)
Browse files Browse the repository at this point in the history
* Clean up CPU feature detection and per-CPU data initialization code.
* Enforce minimum system requirements (Pentium or later).
  • Loading branch information
phaubertin authored Jan 11, 2025
1 parent 04864ac commit b92e88d
Show file tree
Hide file tree
Showing 6 changed files with 490 additions and 192 deletions.
16 changes: 6 additions & 10 deletions include/kernel/infrastructure/i686/asm/cpuinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,17 @@

/* features */

#define CPUINFO_FEATURE_CPUID (1<<0)
#define CPUINFO_FEATURE_SYSENTER (1<<0)

#define CPUINFO_FEATURE_SYSENTER (1<<1)
#define CPUINFO_FEATURE_SYSCALL (1<<1)

#define CPUINFO_FEATURE_SYSCALL (1<<2)
#define CPUINFO_FEATURE_LOCAL_APIC (1<<2)

#define CPUINFO_FEATURE_LOCAL_APIC (1<<3)
#define CPUINFO_FEATURE_PAE (1<<3)

#define CPUINFO_FEATURE_PAE (1<<4)
#define CPUINFO_FEATURE_PGE (1<<4)

#define CPUINFO_FEATURE_PGE (1<<5)

#define CPUINFO_FEATURE_PSE (1<<6)

#define CPUINFO_FEATURE_NOEXEC (1<<7)
#define CPUINFO_FEATURE_PSE (1<<5)

/* vendors */

Expand Down
18 changes: 9 additions & 9 deletions include/kernel/infrastructure/i686/cpuinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,21 @@
#include <stdint.h>

typedef struct {
unsigned int maxphyaddr;
unsigned int dcache_alignment;
uint32_t features;
int vendor;
int family;
int model;
int stepping;
unsigned int maxphyaddr;
unsigned int dcache_alignment;
uint32_t features;
int vendor;
unsigned int family;
unsigned int model;
unsigned int stepping;
} cpuinfo_t;

extern cpuinfo_t cpuinfo;
extern cpuinfo_t bsp_cpuinfo;

void detect_cpu_features(void);

static inline bool cpu_has_feature(uint32_t mask) {
return (cpuinfo.features & mask) == mask;
return (bsp_cpuinfo.features & mask) == mask;
}

#endif
9 changes: 9 additions & 0 deletions include/kernel/infrastructure/i686/isa/instrs.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ typedef struct {
uint32_t edx;
} x86_cpuid_regs_t;

typedef struct {
x86_cpuid_regs_t basic0;
x86_cpuid_regs_t basic1;
x86_cpuid_regs_t ext0;
x86_cpuid_regs_t ext1;
x86_cpuid_regs_t ext8;
bool ext8_valid;
} x86_cpuid_leafs;

void cli(void);

void sti(void);
Expand Down
Loading

0 comments on commit b92e88d

Please sign in to comment.