]> Joshua Wise's Git repositories - netwatch.git/commitdiff
Fix smm_type detection to actually detect, and add a state_num_regs routine.
authorJoshua Wise <joshua@ainfvec.fac.cs.cmu.edu>
Sat, 3 Oct 2009 06:40:29 +0000 (02:40 -0400)
committerJoshua Wise <joshua@ainfvec.fac.cs.cmu.edu>
Sat, 3 Oct 2009 06:40:29 +0000 (02:40 -0400)
include/state.h
lib/state.c

index 9bc4b9060c3719f7bc8d99c7b89ccd18f5db20fa..8bfb96db4d36da696af76b1963cb393b608298f8 100644 (file)
@@ -122,6 +122,7 @@ enum smm_type state_get_type(void);
 uint64_t state_get_reg (enum state_reg_t reg);
 int state_reg_size (enum state_reg_t reg);
 int state_set_reg (enum state_reg_t reg, uint64_t value);
+int state_num_regs();
 
 int state_dump_reg(char * dest, int max, enum state_reg_t reg);
 
index 46a56e8ee7c35221a7d2a4464c90cf4ecab0285c..9a14efc853379184b71c8e1abfc33ebfaf2b6010 100644 (file)
@@ -72,7 +72,7 @@ static const uint32_t offset_table_legacy[] = {
        [STATE_REG_IDT_BASE]    = 0xff94 | SZ_DWORD
 };
 
-#define MAX_REG_LEGACY (sizeof(offset_table_legacy)/sizeof(uint32_t))
+#define MAX_REG_LEGACY (sizeof(offset_table_legacy)/sizeof(offset_table_legacy[0]) - 1)
 
 static const uint32_t offset_table_amd64[] = {
        [STATE_REV]             = 0xfefc | SZ_DWORD,
@@ -207,9 +207,9 @@ static const char register_names[][4] = {
        [STATE_REG_EFER]        = "EFER"
 };
 
-#define MAX_REG_AMD64 (sizeof(offset_table_amd64)/sizeof(uint32_t))
+#define MAX_REG_AMD64 (sizeof(offset_table_amd64)/sizeof(offset_table_amd64[0]) - 1)
 
-static enum smm_type smm_type = SMM_TYPE_64;
+static enum smm_type smm_type = SMM_TYPE_UNKNOWN;
 
 /* Probe CPUID to figure out what kind of processor this actually is.
  * We memoize this in 'smm_type', so cpuid only needs to happen once.
@@ -245,9 +245,9 @@ static unsigned long get_offset(enum state_reg_t reg) {
 
        check_smm_type();
 
-       if (smm_type == SMM_TYPE_32 && reg < MAX_REG_LEGACY)
+       if (smm_type == SMM_TYPE_32 && reg <= MAX_REG_LEGACY)
                return offset_table_legacy[reg];
-       else if (smm_type == SMM_TYPE_64 && reg < MAX_REG_AMD64)
+       else if (smm_type == SMM_TYPE_64 && reg <= MAX_REG_AMD64)
                return offset_table_amd64[reg];
        else
                return 0;
@@ -355,3 +355,13 @@ int state_dump_reg(char * dest, int max, enum state_reg_t reg) {
                return 0;
        }
 }
+
+int state_num_regs() {
+       check_smm_type();
+
+       if (smm_type == SMM_TYPE_32)
+               return MAX_REG_LEGACY;
+       else if (smm_type == SMM_TYPE_64)
+               return MAX_REG_AMD64;
+       return 0;
+}
This page took 0.034497 seconds and 4 git commands to generate.