From: Joshua Wise Date: Sat, 3 Oct 2009 06:40:29 +0000 (-0400) Subject: Fix smm_type detection to actually detect, and add a state_num_regs routine. X-Git-Url: http://git.joshuawise.com/netwatch.git/commitdiff_plain/3cfffb8916ccc8aaeab1589804f8eab919d932c3?ds=sidebyside;hp=-c Fix smm_type detection to actually detect, and add a state_num_regs routine. --- 3cfffb8916ccc8aaeab1589804f8eab919d932c3 diff --git a/include/state.h b/include/state.h index 9bc4b90..8bfb96d 100644 --- a/include/state.h +++ b/include/state.h @@ -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); diff --git a/lib/state.c b/lib/state.c index 46a56e8..9a14efc 100644 --- a/lib/state.c +++ b/lib/state.c @@ -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; +}