Blog Code Forum

CoreMod

From Wiki.cyring.fr

(Difference between revisions)
Jump to: navigation, search
(Contact)
(coremod.h)
Line 57: Line 57:
==== Release 2012-0.1.2 ====
==== Release 2012-0.1.2 ====
===== coremod.h =====
===== coremod.h =====
 +
<syntaxhighlight lang="c" line start="1">
 +
/*
 +
* CoreMod by CyrIng
 +
*
 +
* Copyright (C) 2012 CYRIL INGENIERIE
 +
*
 +
* Licenses: GPL2
 +
*
 +
* coremod.h release 2012-0.1.2
 +
*/
 +
 +
 +
// Intel® 64 and IA-32 Architectures Software Developer's Manual - Vol. 3C
 +
// Table 34-5 (Nehalem) and 34-10 (Sandy Bridge)
 +
 +
#define IA32_PERF_STATUS 0x198
 +
#define IA32_THERM_STATUS 0x19c
 +
#define MSR_TEMPERATURE_TARGET 0x1a2
 +
 +
struct COREINFO
 +
{
 +
struct
 +
  {
 +
unsigned long long
 +
Ratio : 16-0,
 +
ReservedBit1 : 32-16,
 +
Voltage : 48-32,
 +
ReservedBit2 : 64-48;
 +
  } Perf;
 +
struct
 +
  {
 +
unsigned long long
 +
Status :  1-0,
 +
StatusLog :  2-1,
 +
PROCHOT :  3-2,
 +
PROCHOTLog :  4-3,
 +
CriticalTemp :  5-4,
 +
CriticalTempLog :  6-5,
 +
Threshold1 :  7-6,
 +
Threshold1Log :  8-7,
 +
Threshold2 :  9-8,
 +
Threshold2Log : 10-9,
 +
PowerLimit : 11-10,
 +
PowerLimitLog : 12-11,
 +
ReservedBit1 : 16-12,
 +
DTS : 23-16,
 +
ReservedBit2 : 27-23,
 +
Resolution : 31-27,
 +
ReadingValid : 32-31,
 +
ReservedBit3 : 64-32;
 +
  } Therm;
 +
struct
 +
{
 +
unsigned long long
 +
ReservedBit1 : 16-0,
 +
Target : 24-16,
 +
ReservedBit2 : 64-24;
 +
} Temp;
 +
};
 +
 +
 +
// System Management BIOS (SMBIOS) Reference Specification
 +
// Version: 2.7.1 § 7.5
 +
 +
struct HEADER
 +
{
 +
unsigned int
 +
Type :  8,
 +
Lenght :  8,
 +
Handle : 16;
 +
};
 +
 +
#define STRING_DELIMITER 0
 +
 +
struct STRING
 +
{
 +
int ID;
 +
char *Buffer;
 +
struct STRING *Link;
 +
};
 +
 +
struct STRUCTINFO
 +
{
 +
struct HEADER Header;
 +
unsigned int Dimension;
 +
unsigned long long *Attrib;
 +
struct STRING *String;
 +
};
 +
 +
struct PACKED
 +
{
 +
int Type;
 +
int Instance;
 +
FILE *File;
 +
size_t Length;
 +
int *Tape;
 +
};
 +
 +
#define _B_ 0
 +
#define _W_ 1
 +
#define _D_ 2
 +
#define _Q_ 3
 +
#define _S_ ,
 +
#define _EOT_ -1
 +
 +
#define SMBIOS_BIOSINFO_TYPE 0
 +
#define SMBIOS_BIOSINFO_INSTANCE 0
 +
 +
#define SMBIOS_BIOSINFO_PACKED {_B_ _S_ _B_ _S_ _W_ _S_ _B_ _S_ _B_ _S_ _Q_ _S_ _W_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _EOT_}
 +
 +
struct SMBIOS0
 +
{
 +
unsigned long long
 +
Vendor,
 +
Version,
 +
Address,
 +
Release_Date,
 +
ROM_Size,
 +
Characteristics,
 +
Extension_Bytes,
 +
Major_Release,
 +
Minor_Release,
 +
Firmware_Major,
 +
Firmware_Minor;
 +
};
 +
 +
struct BIOSINFO
 +
{
 +
struct HEADER Header;
 +
unsigned int Dimension;
 +
struct SMBIOS0 *Attrib;
 +
struct STRING *String;
 +
};
 +
 +
 +
#define SMBIOS_BOARDINFO_TYPE 2
 +
#define SMBIOS_BOARDINFO_INSTANCE 0
 +
/*
 +
* Spec. for a multi motherboard
 +
#define SMBIOS_BOARDINFO_PACKED {_B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _W_ _S_ _B_ _S_ _B_ _S_ _W_ _S_ _EOT_}
 +
 +
* The ASUS Rampage II Gene is a single motherboard
 +
*/
 +
#define SMBIOS_BOARDINFO_PACKED {_B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _W_ _S_ _B_ _S_ _B_ _S_ _EOT_}
 +
#define SMBIOS_BOARDINFO_EXTENS {_W_ _S_ _EOT_}
 +
 +
struct SMBIOS2
 +
{
 +
unsigned long long
 +
Manufacturer,
 +
Product,
 +
Version,
 +
Serial,
 +
AssetTag,
 +
Feature,
 +
Location,
 +
Chassis_Handle,
 +
Board_Type,
 +
Number_Object,
 +
Object_Handles;
 +
// Use Attrib[10] to Attrib[265] to read the list of the 255 object handles
 +
};
 +
 +
struct BOARDINFO
 +
{
 +
struct HEADER Header;
 +
unsigned int Dimension;
 +
struct SMBIOS2 *Attrib;
 +
struct STRING *String;
 +
};
 +
 +
 +
#define SMBIOS_PROCINFO_TYPE 4
 +
#define SMBIOS_PROCINFO_INSTANCE 0
 +
/*
 +
* Spec. Version 2.6+
 +
#define SMBIOS_PROCINFO_PACKED {_B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _Q_ _S_ _B_ _S_ _B_ _S_ _W_ _S_ _W_ _S_ _W_ _S_ _B_ _S_ _B_ _S_ _W_ _S_ _W_ _S_ _W_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _W_ _S_ _W_ _S_ _EOT_}
 +
 +
* The SMBIOS version of the ASUS Rampage II Gene is a 2.5
 +
*/
 +
#define SMBIOS_PROCINFO_PACKED {_B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _Q_ _S_ _B_ _S_ _B_ _S_ _W_ _S_ _W_ _S_ _W_ _S_ _B_ _S_ _B_ _S_ _W_ _S_ _W_ _S_ _W_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _W_ _S_ _EOT_}
 +
#define SMBIOS_PROCINFO_EXTENS {_W_ _S_ _EOT_}
 +
 +
struct SMBIOS4
 +
{
 +
unsigned long long
 +
Socket,
 +
ProcType,
 +
Family,
 +
Manufacturer;
 +
struct
 +
{
 +
unsigned
 +
EAX : 32-0;
 +
struct
 +
{
 +
unsigned
 +
Unused1 :  9-0,
 +
APIC : 10-9,
 +
Unused2 : 12-10,
 +
MTRR : 13-12,
 +
Unused3 : 16-13,
 +
PAT : 17-16,
 +
Unused4 : 23-17,
 +
MMX : 24-23,
 +
Unused5 : 25-24,
 +
SSE : 26-25,
 +
SSE2 : 27-26,
 +
Unused6 : 28-27,
 +
HyperThreading : 29-28,
 +
Unused7 : 32-29;
 +
} EDX;
 +
} CPUID;
 +
unsigned long long
 +
Version;
 +
struct
 +
{
 +
unsigned
 +
Tension : 7-0,
 +
Mode : 8-7;
 +
} Voltage;
 +
unsigned long long
 +
Clock,
 +
MaxSpeed,
 +
CurrentSpeed,
 +
Status,
 +
Upgrade,
 +
L1_Cache_Handle,
 +
L2_Cache_Handle,
 +
L3_Cache_Handle,
 +
Serial,
 +
AssetTag,
 +
PartNumber,
 +
CoreCount,
 +
CoreEnabled,
 +
ThreadCount,
 +
Characteristics,
 +
Family2;
 +
};
 +
 +
struct PROCINFO
 +
{
 +
struct HEADER Header;
 +
unsigned int Dimension;
 +
struct SMBIOS4 *Attrib;
 +
struct STRING *String;
 +
};
 +
 +
 +
#define SMBIOS_CACHEINFO_TYPE 7
 +
 +
#define SMBIOS_CACHEINFO_PACKED {_B_ _S_ _W_ _S_ _W_ _S_ _W_ _S_ _W_ _S_ _W_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _EOT_}
 +
 +
struct SMBIOS7
 +
{
 +
unsigned long long
 +
Socket,
 +
Configuration,
 +
Maximum_Size,
 +
Installed_Size,
 +
Supported_SRAM,
 +
Current_SRAM,
 +
Cache_Speed,
 +
Error_Correction,
 +
System_Cache,
 +
Associativity;
 +
};
 +
 +
struct CACHEINFO
 +
{
 +
struct HEADER Header;
 +
unsigned int Dimension;
 +
struct SMBIOS7 *Attrib;
 +
struct STRING *String;
 +
};
 +
 +
 +
#define SMBIOS_MEMARRAY_TYPE 16
 +
#define SMBIOS_MEMARRAY_INSTANCE 0
 +
 +
#define SMBIOS_MEMARRAY_PACKED {_B_ _S_ _B_ _S_ _B_ _S_ _D_ _S_ _W_ _S_ _W_ _S_ _EOT_}
 +
#define SMBIOS_MEMARRAY_EXTENS {_Q_ _S_ _EOT_}
 +
 +
struct SMBIOS16
 +
{
 +
unsigned long long
 +
Location,
 +
Use,
 +
Error_Correction,
 +
Maximum_Capacity,
 +
Error_Handle,
 +
Number_Devices,
 +
Extended_Capacity;
 +
};
 +
 +
struct MEMARRAY
 +
{
 +
struct HEADER Header;
 +
unsigned int Dimension;
 +
struct SMBIOS16 *Attrib;
 +
struct STRING *String;
 +
};
 +
 +
 +
#define SMBIOS_MEMDEV_TYPE 17
 +
 +
#define SMBIOS_MEMDEV_PACKED {_W_ _S_ _W_ _S_ _W_ _S_ _W_ _S_ _W_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _W_ _S_ _W_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _EOT_}
 +
#define SMBIOS_MEMDEV_EXTENS {_B_ _S_ _D_ _S_ _W_ _S_ _EOT_}
 +
 +
struct SMBIOS17
 +
{
 +
unsigned long long
 +
MemArray_Handle,
 +
Error_Handle,
 +
Total_Width,
 +
Data_Width,
 +
Size,
 +
Form_Factor,
 +
Set,
 +
Socket,
 +
Bank,
 +
Mem_Type,
 +
Mem_Detail,
 +
Speed,
 +
Manufacturer,
 +
Serial,
 +
AssetTag,
 +
PartNumber,
 +
Attributes,
 +
Extended_Size,
 +
Clock_Speed;
 +
};
 +
 +
struct MEMDEV
 +
{
 +
struct HEADER Header;
 +
unsigned int Dimension;
 +
struct SMBIOS17 *Attrib;
 +
struct STRING *String;
 +
};
 +
 +
 +
struct MENUNAV
 +
{
 +
char Command;
 +
int NewLevel;
 +
int Function;
 +
};
 +
 +
#define LEVELS  11
 +
#define CHARS    66
 +
 +
#define MENU_LABEL_ROOT "  Root "
 +
#define MENU_LABEL_HELP "  Help "
 +
#define MENU_LABEL_SHOW "  Show "
 +
#define MENU_LABEL_DUMP "  Dump "
 +
#define MENU_LABEL_ATTR "Attribs"
 +
#define MENU_LABEL_STRG "Strings"
 +
#define MENU_LABEL_CACH " Cache "
 +
#define MENU_LABEL_MEMY " Memory"
 +
#define MENU_LABEL_CMOD " Modify"
 +
 +
#define MENU_PROMPT_ROOT "[E]xit    [H]elp      [S]how        [D]ump      [M]odify      "
 +
#define MENU_PROMPT_HELP "[<]Back                    (C)2012 CyrIng                      "
 +
#define MENU_PROMPT_SHOW "[<]Back  [C]ore      [P]rocessor    [S]ystem                  "
 +
#define MENU_PROMPT_DUMP "[<]Back  [A]ttributes                [S]trings                  "
 +
#define MENU_PROMPT_ATTR "[<]Back  [B]ios      [M]otherboard  [P]rocessor  [C]ache  [R]AM"
 +
#define MENU_PROMPT_STRG "[<]Back  [B]ios      [M]otherboard  [P]rocessor  [C]ache  [R]AM"
 +
#define MENU_PROMPT_CACH "[<]Back  Level L[1]  Level L[2]    Level L[3]                "
 +
#define MENU_PROMPT_MEMY "[<]Back  [A]rray                                                "
 +
#define MENU_PROMPT_CMOD "[<]Back                    MOD is coming, hope so!              "
 +
 +
#define LV_ROOT  0
 +
#define LV_HELP  1
 +
#define LV_SHOW  2
 +
#define LV_DUMP  3
 +
#define LV_ATTR  4
 +
#define LV_STRG  5
 +
#define LV_ATTH  6
 +
#define LV_STRH  7
 +
#define LV_ATTY  8
 +
#define LV_STRY  9
 +
#define LV_CMOD  10
 +
 +
#define FN_EXIT  0
 +
#define FN_NOOP  -1
 +
#define FN_HELP  1
 +
#define FN_SHWC  21
 +
#define FN_SHWP  22
 +
#define FN_SHWS  23
 +
#define FN_ATTB  41
 +
#define FN_ATTM  42
 +
#define FN_ATTP  43
 +
#define FN_STRB  51
 +
#define FN_STRM  52
 +
#define FN_STRP  53
 +
#define FN_ATL1  61
 +
#define FN_ATL2  62
 +
#define FN_ATL3  63
 +
#define FN_STL1  71
 +
#define FN_STL2  72
 +
#define FN_STL3  73
 +
#define FN_ATTY  81
 +
#define FN_STRY  91
 +
#define FN_ATTD 810
 +
#define FN_STRD 910
 +
 +
#define EOL      0
 +
 +
#define MENU_LEVEL_ROOT {{'e', LV_ROOT, FN_EXIT}, {'h', LV_HELP, FN_HELP}, {'s', LV_SHOW, FN_NOOP}, {'d', LV_DUMP, FN_NOOP}, {'m', LV_CMOD, FN_NOOP}, {EOL, LV_ROOT, FN_NOOP}}
 +
#define MENU_LEVEL_HELP {{'e', LV_ROOT, FN_EXIT}, {'<', LV_ROOT, FN_NOOP}, {EOL, LV_HELP, FN_NOOP}}
 +
#define MENU_LEVEL_SHOW {{'e', LV_ROOT, FN_EXIT}, {'<', LV_ROOT, FN_NOOP}, {'c', LV_SHOW, FN_SHWC}, {'p', LV_SHOW, FN_SHWP}, {'s', LV_SHOW, FN_SHWS}, {EOL, LV_SHOW, FN_NOOP}}
 +
#define MENU_LEVEL_DUMP {{'e', LV_ROOT, FN_EXIT}, {'<', LV_ROOT, FN_NOOP}, {'a', LV_ATTR, FN_NOOP}, {'s', LV_STRG, FN_NOOP}, {EOL, LV_DUMP, FN_NOOP}}
 +
#define MENU_LEVEL_ATTR {{'e', LV_ROOT, FN_EXIT}, {'<', LV_DUMP, FN_NOOP}, {'b', LV_ATTR, FN_ATTB}, {'m', LV_ATTR, FN_ATTM}, {'p', LV_ATTR, FN_ATTP}, {'c', LV_ATTH, FN_NOOP}, {'r', LV_ATTY, FN_NOOP}, {EOL, LV_ATTR, FN_NOOP}}
 +
#define MENU_LEVEL_STRG {{'e', LV_ROOT, FN_EXIT}, {'<', LV_DUMP, FN_NOOP}, {'b', LV_STRG, FN_STRB}, {'m', LV_STRG, FN_STRM}, {'p', LV_STRG, FN_STRP}, {'c', LV_STRH, FN_NOOP}, {'r', LV_STRY, FN_NOOP}, {EOL, LV_STRG, FN_NOOP}}
 +
#define MENU_LEVEL_ATTH {{'e', LV_ROOT, FN_EXIT}, {'<', LV_ATTR, FN_NOOP}, {'1', LV_ATTH, FN_ATL1}, {'2', LV_ATTH, FN_ATL2}, {'3', LV_ATTH, FN_ATL3}, {EOL, LV_ATTH, FN_NOOP}}
 +
#define MENU_LEVEL_STRH {{'e', LV_ROOT, FN_EXIT}, {'<', LV_STRG, FN_NOOP}, {'1', LV_STRH, FN_STL1}, {'2', LV_STRH, FN_STL2}, {'3', LV_STRH, FN_STL3}, {EOL, LV_STRH, FN_NOOP}}
 +
#define MENU_LEVEL_ATTY {{'e', LV_ROOT, FN_EXIT}, {'<', LV_ATTR, FN_NOOP}, {'a', LV_ATTY, FN_ATTY}, {EOL, LV_ATTY, FN_NOOP}, {EOL, LV_ATTY, FN_NOOP}, {EOL, LV_ATTY, FN_NOOP}, {EOL, LV_ATTY, FN_NOOP}, {EOL, LV_ATTY, FN_NOOP}, {EOL, LV_ATTY, FN_NOOP}, {EOL, LV_ATTY, FN_NOOP}, {EOL, LV_ATTY, FN_NOOP}, {EOL, LV_ATTY, FN_NOOP}}
 +
#define MENU_LEVEL_STRY {{'e', LV_ROOT, FN_EXIT}, {'<', LV_STRG, FN_NOOP}, {'a', LV_STRY, FN_STRY}, {EOL, LV_STRY, FN_NOOP}, {EOL, LV_STRY, FN_NOOP}, {EOL, LV_STRY, FN_NOOP}, {EOL, LV_STRY, FN_NOOP}, {EOL, LV_STRY, FN_NOOP}, {EOL, LV_STRY, FN_NOOP}, {EOL, LV_STRY, FN_NOOP}, {EOL, LV_STRY, FN_NOOP}, {EOL, LV_STRY, FN_NOOP}}
 +
#define MENU_LEVEL_CMOD {{'e', LV_ROOT, FN_EXIT}, {'<', LV_ROOT, FN_NOOP}, {EOL, LV_CMOD, FN_NOOP}}
 +
 +
#define Menu_Display(runLevel) printf("\n%7s | %66s :", menuLabel[runLevel], menuPrompt[runLevel])
 +
 +
</syntaxhighlight>
 +
===== coremod.c =====
===== coremod.c =====
==== Release 2012-0.1.1 ====
==== Release 2012-0.1.1 ====

Revision as of 21:20, 9 July 2012

Contents

How To

Requirements

Mandatory,

  • The GNU/Linux x86_64 3.x : linux
  • The GNU Compiler Collection: gcc - or - The C language family frontend for LLVM: clang
  • Being root !
  • The Intel(R) Core(TM) i7, i5 Processors


Optionally,


Compiling

$ gcc coremod.c -o coremod

- or -

$ clang coremod.c -o coremod


Debugging

First of all, compile sources with the -g switch then launch the debugger

$ kdesu ddd ./coremod


Usage

Two kernel modules must be loaded

  1. msr
  2. dmi-sysfs


Execute CoreMod as root

# ./coremod


Usage is straightforward. Just enter the corresponding initial character to the function you want to execute. Thus to show the core temperature, press the following keys:

  • [s]
  • [Enter]
  • [c]
  • [Enter]

And for instance to go back to previous menu level:

  • [<]
  • [Enter]


Discover the other functions to dump your components !

Contact

Feel free to contact us for any suggestion or question.

Releases

Release 2012-0.1.2

coremod.h
  1. /*
  2.  * CoreMod by CyrIng
  3.  * 
  4.  * Copyright (C) 2012 CYRIL INGENIERIE
  5.  * 
  6.  * Licenses: GPL2
  7.  * 
  8.  * coremod.h release 2012-0.1.2
  9.  */
  10.  
  11.  
  12. // Intel® 64 and IA-32 Architectures Software Developer's Manual - Vol. 3C
  13. // Table 34-5 (Nehalem) and 34-10 (Sandy Bridge)
  14.  
  15. #define IA32_PERF_STATUS	0x198
  16. #define IA32_THERM_STATUS	0x19c
  17. #define MSR_TEMPERATURE_TARGET	0x1a2
  18.  
  19. struct COREINFO
  20. {
  21. 	struct
  22. 	  {
  23. 		unsigned long long
  24. 				Ratio		: 16-0,
  25. 				ReservedBit1	: 32-16,
  26. 				Voltage		: 48-32,
  27. 				ReservedBit2	: 64-48;
  28. 	  } Perf;
  29. 	struct
  30. 	  {
  31. 		unsigned long long
  32. 				Status		:  1-0,
  33. 				StatusLog	:  2-1,
  34. 				PROCHOT		:  3-2,
  35. 				PROCHOTLog	:  4-3,
  36. 				CriticalTemp	:  5-4,
  37. 				CriticalTempLog	:  6-5,
  38. 				Threshold1	:  7-6,
  39. 				Threshold1Log	:  8-7,
  40. 				Threshold2	:  9-8,
  41. 				Threshold2Log	: 10-9,
  42. 				PowerLimit	: 11-10,
  43. 				PowerLimitLog	: 12-11,
  44. 				ReservedBit1	: 16-12,
  45. 				DTS		: 23-16,
  46. 				ReservedBit2	: 27-23,
  47. 				Resolution	: 31-27,
  48. 				ReadingValid	: 32-31,
  49. 				ReservedBit3	: 64-32;
  50. 	  } Therm;
  51. 	struct
  52. 	{
  53. 		unsigned long long
  54. 				ReservedBit1	: 16-0,
  55. 				Target		: 24-16,
  56. 				ReservedBit2	: 64-24;
  57. 	} Temp;
  58. };
  59.  
  60.  
  61. // System Management BIOS (SMBIOS) Reference Specification
  62. // Version: 2.7.1 § 7.5
  63.  
  64. struct HEADER
  65. {
  66. 		unsigned int
  67. 				Type	:  8,
  68. 				Lenght	:  8,
  69. 				Handle	: 16;
  70. };
  71.  
  72. #define STRING_DELIMITER 0
  73.  
  74. struct STRING
  75. {
  76. 		int		ID;
  77. 		char		*Buffer;
  78. 		struct STRING	*Link;
  79. };
  80.  
  81. struct STRUCTINFO
  82. {
  83. 	struct HEADER		Header;
  84. 	unsigned int		Dimension;
  85. 	unsigned long long	*Attrib;
  86. 	struct STRING		*String;
  87. };
  88.  
  89. struct PACKED
  90. {
  91. 		int		Type;
  92. 		int		Instance;
  93. 		FILE		*File;
  94. 		size_t		Length;
  95. 		int		*Tape;
  96. };
  97.  
  98. #define _B_		0
  99. #define _W_		1
  100. #define _D_		2
  101. #define _Q_		3
  102. #define _S_		,
  103. #define _EOT_		-1
  104.  
  105. #define SMBIOS_BIOSINFO_TYPE		0
  106. #define SMBIOS_BIOSINFO_INSTANCE	0
  107.  
  108. #define SMBIOS_BIOSINFO_PACKED {_B_ _S_ _B_ _S_ _W_ _S_ _B_ _S_ _B_ _S_ _Q_ _S_ _W_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _EOT_}
  109.  
  110. struct SMBIOS0
  111. {
  112. 		unsigned long long
  113. 				Vendor,
  114. 				Version,
  115. 				Address,
  116. 				Release_Date,
  117. 				ROM_Size,
  118. 				Characteristics,
  119. 				Extension_Bytes,
  120. 				Major_Release,
  121. 				Minor_Release,
  122. 				Firmware_Major,
  123. 				Firmware_Minor;
  124. };
  125.  
  126. struct BIOSINFO
  127. {
  128. 	struct HEADER		Header;
  129. 	unsigned int		Dimension;
  130. 	struct SMBIOS0		*Attrib;
  131. 	struct STRING		*String;
  132. };
  133.  
  134.  
  135. #define SMBIOS_BOARDINFO_TYPE		2
  136. #define SMBIOS_BOARDINFO_INSTANCE	0
  137. /*
  138. * Spec. for a multi motherboard
  139. #define SMBIOS_BOARDINFO_PACKED {_B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _W_ _S_ _B_ _S_ _B_ _S_ _W_ _S_ _EOT_}
  140.  
  141. * The ASUS Rampage II Gene is a single motherboard
  142. */
  143. #define SMBIOS_BOARDINFO_PACKED {_B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _W_ _S_ _B_ _S_ _B_ _S_ _EOT_}
  144. #define SMBIOS_BOARDINFO_EXTENS {_W_ _S_ _EOT_}
  145.  
  146. struct SMBIOS2
  147. {
  148. 		unsigned long long
  149. 				Manufacturer,
  150. 				Product,
  151. 				Version,
  152. 				Serial,
  153. 				AssetTag,
  154. 				Feature,
  155. 				Location,
  156. 				Chassis_Handle,
  157. 				Board_Type,
  158. 				Number_Object,
  159. 				Object_Handles;
  160. 			//	Use Attrib[10] to Attrib[265] to read the list of the 255 object handles
  161. };
  162.  
  163. struct BOARDINFO
  164. {
  165. 	struct HEADER		Header;
  166. 	unsigned int		Dimension;
  167. 	struct SMBIOS2		*Attrib;
  168. 	struct STRING		*String;
  169. };
  170.  
  171.  
  172. #define SMBIOS_PROCINFO_TYPE		4
  173. #define SMBIOS_PROCINFO_INSTANCE	0
  174. /*
  175. * Spec. Version 2.6+
  176. #define SMBIOS_PROCINFO_PACKED {_B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _Q_ _S_ _B_ _S_ _B_ _S_ _W_ _S_ _W_ _S_ _W_ _S_ _B_ _S_ _B_ _S_ _W_ _S_ _W_ _S_ _W_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _W_ _S_ _W_ _S_ _EOT_}
  177.  
  178. * The SMBIOS version of the ASUS Rampage II Gene is a 2.5
  179. */
  180. #define SMBIOS_PROCINFO_PACKED {_B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _Q_ _S_ _B_ _S_ _B_ _S_ _W_ _S_ _W_ _S_ _W_ _S_ _B_ _S_ _B_ _S_ _W_ _S_ _W_ _S_ _W_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _W_ _S_ _EOT_}
  181. #define SMBIOS_PROCINFO_EXTENS {_W_ _S_ _EOT_}
  182.  
  183. struct SMBIOS4
  184. {
  185. 		unsigned long long
  186. 				Socket,
  187. 				ProcType,
  188. 				Family,
  189. 				Manufacturer;
  190. 				struct
  191. 				{
  192. 		unsigned
  193. 					EAX		: 32-0;
  194. 					struct
  195. 					{
  196. 		unsigned
  197. 						Unused1		:  9-0,
  198. 						APIC		: 10-9,
  199. 						Unused2		: 12-10,
  200. 						MTRR		: 13-12,
  201. 						Unused3		: 16-13,
  202. 						PAT		: 17-16,
  203. 						Unused4		: 23-17,
  204. 						MMX		: 24-23,
  205. 						Unused5		: 25-24,
  206. 						SSE		: 26-25,
  207. 						SSE2		: 27-26,
  208. 						Unused6		: 28-27,
  209. 						HyperThreading	: 29-28,
  210. 						Unused7		: 32-29;
  211. 					} EDX;
  212. 				} CPUID;
  213. 		unsigned long long
  214. 				Version;
  215. 				struct
  216. 				{
  217. 		unsigned
  218. 					Tension	: 7-0,
  219. 					Mode	: 8-7;
  220. 				} Voltage;
  221. 		unsigned long long
  222. 				Clock,
  223. 				MaxSpeed,
  224. 				CurrentSpeed,
  225. 				Status,
  226. 				Upgrade,
  227. 				L1_Cache_Handle,
  228. 				L2_Cache_Handle,
  229. 				L3_Cache_Handle,
  230. 				Serial,
  231. 				AssetTag,
  232. 				PartNumber,
  233. 				CoreCount,
  234. 				CoreEnabled,
  235. 				ThreadCount,
  236. 				Characteristics,
  237. 				Family2;
  238. };
  239.  
  240. struct PROCINFO
  241. {
  242. 	struct HEADER		Header;
  243. 	unsigned int		Dimension;
  244. 	struct SMBIOS4		*Attrib;
  245. 	struct STRING		*String;
  246. };
  247.  
  248.  
  249. #define SMBIOS_CACHEINFO_TYPE		7
  250.  
  251. #define SMBIOS_CACHEINFO_PACKED {_B_ _S_ _W_ _S_ _W_ _S_ _W_ _S_ _W_ _S_ _W_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _EOT_}
  252.  
  253. struct SMBIOS7
  254. {
  255. 		unsigned long long
  256. 				Socket,
  257. 				Configuration,
  258. 				Maximum_Size,
  259. 				Installed_Size,
  260. 				Supported_SRAM,
  261. 				Current_SRAM,
  262. 				Cache_Speed,
  263. 				Error_Correction,
  264. 				System_Cache,
  265. 				Associativity;
  266. };
  267.  
  268. struct CACHEINFO
  269. {
  270. 	struct HEADER		Header;
  271. 	unsigned int		Dimension;
  272. 	struct SMBIOS7		*Attrib;
  273. 	struct STRING		*String;
  274. };
  275.  
  276.  
  277. #define SMBIOS_MEMARRAY_TYPE		16
  278. #define SMBIOS_MEMARRAY_INSTANCE	0
  279.  
  280. #define SMBIOS_MEMARRAY_PACKED {_B_ _S_ _B_ _S_ _B_ _S_ _D_ _S_ _W_ _S_ _W_ _S_ _EOT_}
  281. #define SMBIOS_MEMARRAY_EXTENS {_Q_ _S_ _EOT_}
  282.  
  283. struct SMBIOS16
  284. {
  285. 		unsigned long long
  286. 				Location,
  287. 				Use,
  288. 				Error_Correction,
  289. 				Maximum_Capacity,
  290. 				Error_Handle,
  291. 				Number_Devices,
  292. 				Extended_Capacity;
  293. };
  294.  
  295. struct MEMARRAY
  296. {
  297. 	struct HEADER		Header;
  298. 	unsigned int		Dimension;
  299. 	struct SMBIOS16		*Attrib;
  300. 	struct STRING		*String;
  301. };
  302.  
  303.  
  304. #define SMBIOS_MEMDEV_TYPE		17
  305.  
  306. #define SMBIOS_MEMDEV_PACKED {_W_ _S_ _W_ _S_ _W_ _S_ _W_ _S_ _W_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _W_ _S_ _W_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _EOT_}
  307. #define SMBIOS_MEMDEV_EXTENS {_B_ _S_ _D_ _S_ _W_ _S_ _EOT_}
  308.  
  309. struct SMBIOS17
  310. {
  311. 		unsigned long long
  312. 				MemArray_Handle,
  313. 				Error_Handle,
  314. 				Total_Width,
  315. 				Data_Width,
  316. 				Size,
  317. 				Form_Factor,
  318. 				Set,
  319. 				Socket,
  320. 				Bank,
  321. 				Mem_Type,
  322. 				Mem_Detail,
  323. 				Speed,
  324. 				Manufacturer,
  325. 				Serial,
  326. 				AssetTag,
  327. 				PartNumber,
  328. 				Attributes,
  329. 				Extended_Size,
  330. 				Clock_Speed;
  331. };
  332.  
  333. struct MEMDEV
  334. {
  335. 	struct HEADER		Header;
  336. 	unsigned int		Dimension;
  337. 	struct SMBIOS17		*Attrib;
  338. 	struct STRING		*String;
  339. };
  340.  
  341.  
  342. struct MENUNAV
  343. {
  344. 	char	Command;
  345. 	int		NewLevel;
  346. 	int		Function;
  347. };
  348.  
  349. #define LEVELS   11
  350. #define CHARS    66
  351.  
  352. #define MENU_LABEL_ROOT "  Root "
  353. #define MENU_LABEL_HELP "  Help "
  354. #define MENU_LABEL_SHOW "  Show "
  355. #define MENU_LABEL_DUMP "  Dump "
  356. #define MENU_LABEL_ATTR "Attribs"
  357. #define MENU_LABEL_STRG "Strings"
  358. #define MENU_LABEL_CACH " Cache "
  359. #define MENU_LABEL_MEMY " Memory"
  360. #define MENU_LABEL_CMOD " Modify"
  361.  
  362. #define MENU_PROMPT_ROOT "[E]xit    [H]elp       [S]how         [D]ump       [M]odify      "
  363. #define	MENU_PROMPT_HELP "[<]Back                     (C)2012 CyrIng                       "
  364. #define MENU_PROMPT_SHOW "[<]Back   [C]ore       [P]rocessor    [S]ystem                   "
  365. #define MENU_PROMPT_DUMP "[<]Back   [A]ttributes                [S]trings                  "
  366. #define MENU_PROMPT_ATTR "[<]Back   [B]ios       [M]otherboard  [P]rocessor  [C]ache  [R]AM"
  367. #define MENU_PROMPT_STRG "[<]Back   [B]ios       [M]otherboard  [P]rocessor  [C]ache  [R]AM"
  368. #define MENU_PROMPT_CACH "[<]Back   Level L[1]   Level L[2]     Level L[3]                 "
  369. #define MENU_PROMPT_MEMY "[<]Back   [A]rray                                                "
  370. #define MENU_PROMPT_CMOD "[<]Back                     MOD is coming, hope so!              "
  371.  
  372. #define LV_ROOT   0
  373. #define LV_HELP   1
  374. #define LV_SHOW   2
  375. #define LV_DUMP   3
  376. #define LV_ATTR   4
  377. #define LV_STRG   5
  378. #define LV_ATTH   6
  379. #define LV_STRH   7
  380. #define LV_ATTY   8
  381. #define LV_STRY   9
  382. #define LV_CMOD  10
  383.  
  384. #define FN_EXIT   0
  385. #define FN_NOOP  -1
  386. #define FN_HELP   1
  387. #define FN_SHWC  21
  388. #define FN_SHWP  22
  389. #define FN_SHWS  23
  390. #define FN_ATTB  41
  391. #define FN_ATTM  42
  392. #define FN_ATTP  43
  393. #define FN_STRB  51
  394. #define FN_STRM  52
  395. #define FN_STRP  53
  396. #define FN_ATL1  61
  397. #define FN_ATL2  62
  398. #define FN_ATL3  63
  399. #define FN_STL1  71
  400. #define FN_STL2  72
  401. #define FN_STL3  73
  402. #define FN_ATTY  81
  403. #define FN_STRY  91
  404. #define FN_ATTD 810
  405. #define FN_STRD 910
  406.  
  407. #define EOL       0
  408.  
  409. #define MENU_LEVEL_ROOT {{'e', LV_ROOT, FN_EXIT}, {'h', LV_HELP, FN_HELP}, {'s', LV_SHOW, FN_NOOP}, {'d', LV_DUMP, FN_NOOP}, {'m', LV_CMOD, FN_NOOP}, {EOL, LV_ROOT, FN_NOOP}}
  410. #define MENU_LEVEL_HELP {{'e', LV_ROOT, FN_EXIT}, {'<', LV_ROOT, FN_NOOP}, {EOL, LV_HELP, FN_NOOP}}
  411. #define MENU_LEVEL_SHOW {{'e', LV_ROOT, FN_EXIT}, {'<', LV_ROOT, FN_NOOP}, {'c', LV_SHOW, FN_SHWC}, {'p', LV_SHOW, FN_SHWP}, {'s', LV_SHOW, FN_SHWS}, {EOL, LV_SHOW, FN_NOOP}}
  412. #define MENU_LEVEL_DUMP {{'e', LV_ROOT, FN_EXIT}, {'<', LV_ROOT, FN_NOOP}, {'a', LV_ATTR, FN_NOOP}, {'s', LV_STRG, FN_NOOP}, {EOL, LV_DUMP, FN_NOOP}}
  413. #define MENU_LEVEL_ATTR {{'e', LV_ROOT, FN_EXIT}, {'<', LV_DUMP, FN_NOOP}, {'b', LV_ATTR, FN_ATTB}, {'m', LV_ATTR, FN_ATTM}, {'p', LV_ATTR, FN_ATTP}, {'c', LV_ATTH, FN_NOOP}, {'r', LV_ATTY, FN_NOOP}, {EOL, LV_ATTR, FN_NOOP}}
  414. #define MENU_LEVEL_STRG {{'e', LV_ROOT, FN_EXIT}, {'<', LV_DUMP, FN_NOOP}, {'b', LV_STRG, FN_STRB}, {'m', LV_STRG, FN_STRM}, {'p', LV_STRG, FN_STRP}, {'c', LV_STRH, FN_NOOP}, {'r', LV_STRY, FN_NOOP}, {EOL, LV_STRG, FN_NOOP}}
  415. #define MENU_LEVEL_ATTH {{'e', LV_ROOT, FN_EXIT}, {'<', LV_ATTR, FN_NOOP}, {'1', LV_ATTH, FN_ATL1}, {'2', LV_ATTH, FN_ATL2}, {'3', LV_ATTH, FN_ATL3}, {EOL, LV_ATTH, FN_NOOP}}
  416. #define MENU_LEVEL_STRH {{'e', LV_ROOT, FN_EXIT}, {'<', LV_STRG, FN_NOOP}, {'1', LV_STRH, FN_STL1}, {'2', LV_STRH, FN_STL2}, {'3', LV_STRH, FN_STL3}, {EOL, LV_STRH, FN_NOOP}}
  417. #define MENU_LEVEL_ATTY {{'e', LV_ROOT, FN_EXIT}, {'<', LV_ATTR, FN_NOOP}, {'a', LV_ATTY, FN_ATTY}, {EOL, LV_ATTY, FN_NOOP}, {EOL, LV_ATTY, FN_NOOP}, {EOL, LV_ATTY, FN_NOOP}, {EOL, LV_ATTY, FN_NOOP}, {EOL, LV_ATTY, FN_NOOP}, {EOL, LV_ATTY, FN_NOOP}, {EOL, LV_ATTY, FN_NOOP}, {EOL, LV_ATTY, FN_NOOP}, {EOL, LV_ATTY, FN_NOOP}}
  418. #define MENU_LEVEL_STRY {{'e', LV_ROOT, FN_EXIT}, {'<', LV_STRG, FN_NOOP}, {'a', LV_STRY, FN_STRY}, {EOL, LV_STRY, FN_NOOP}, {EOL, LV_STRY, FN_NOOP}, {EOL, LV_STRY, FN_NOOP}, {EOL, LV_STRY, FN_NOOP}, {EOL, LV_STRY, FN_NOOP}, {EOL, LV_STRY, FN_NOOP}, {EOL, LV_STRY, FN_NOOP}, {EOL, LV_STRY, FN_NOOP}, {EOL, LV_STRY, FN_NOOP}}
  419. #define MENU_LEVEL_CMOD {{'e', LV_ROOT, FN_EXIT}, {'<', LV_ROOT, FN_NOOP}, {EOL, LV_CMOD, FN_NOOP}}
  420.  
  421. #define Menu_Display(runLevel) printf("\n%7s | %66s :", menuLabel[runLevel], menuPrompt[runLevel])
coremod.c

Release 2012-0.1.1

coremod.c
  1. // coremod.c - CyrIng 2012
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <unistd.h>
  6. #include <sys/stat.h>
  7. #include <fcntl.h>
  8.  
  9. // Intel® 64 and IA-32 Architectures Software Developer’s Manual
  10. // Vol. 3C § 34-1
  11. // Table 34-2. IA-32 Architectural MSRs
  12.  
  13. #define	IA32_PERF_STATUS	0x198
  14.  
  15. // System Management BIOS (SMBIOS) Reference Specification
  16. // Version: 2.7.1 § 7.5
  17. // Table 20 – Processor Information (Type 4) Structure
  18.  
  19. #define	SMBIOS_PROCINFO_STRUCTURE	4
  20. #define	SMBIOS_PROCINFO_INSTANCE	0
  21. #define	SMBIOS_PROCINFO_EXTCLK		0x12
  22.  
  23.  
  24. int Read_MSR(int cpu, off_t offset, unsigned long long *msr) {
  25. 	ssize_t	retval=0;
  26. 	char	pathname[32]="";
  27. 	int		fd=0, rc=-1;
  28.  
  29. 	sprintf(pathname, "/dev/cpu/%d/msr", cpu);
  30. 	if( (fd=open(pathname, O_RDONLY)) != -1 ) {
  31. 		retval=pread(fd, msr, sizeof *msr, offset);
  32. 		close(fd);
  33. 		rc=(retval != sizeof *msr) ? -1 : 0;
  34. 	}
  35. 	return(rc);
  36. }
  37.  
  38. int Read_SMBIOS(int structure, int instance, off_t offset, void *buf, size_t nbyte) {
  39. 	ssize_t	retval=0;
  40. 	char	pathname[]="/sys/firmware/dmi/entries/999-99/raw";
  41. 	int		fd=0, rc=-1;
  42.  
  43. 	sprintf(pathname, "/sys/firmware/dmi/entries/%d-%d/raw", structure, instance);
  44. 	if( (fd=open(pathname, O_RDONLY)) != -1 ) {
  45. 		retval=pread(fd, buf, nbyte, offset);
  46. 		close(fd);
  47. 		rc=(retval != nbyte) ? -1 : 0;
  48. 	}
  49. 	return(rc);
  50. }
  51.  
  52. int	Get_Ratio(int target) {
  53. 	unsigned long long msr=0;
  54.  
  55. 	if( Read_MSR(target, IA32_PERF_STATUS, &msr) != -1)
  56. 		return((int) msr);
  57. 	else
  58. 		return(0);
  59. }
  60.  
  61. int External_Clock() {
  62. 	int	clock=0;
  63.  
  64. 	if( Read_SMBIOS(SMBIOS_PROCINFO_STRUCTURE, SMBIOS_PROCINFO_INSTANCE, SMBIOS_PROCINFO_EXTCLK, &clock, 1) != -1)
  65. 		return(clock);
  66. 	else
  67. 		return(0);
  68. }
  69.  
  70. int main(int argc, char *argv[]) {
  71. 	int	target=0, first=0, last=0, clock=0, ratio=0, rc=0;
  72.  
  73. 	switch(argc) {
  74. 	  case 2:	first = atoi(argv[1]);
  75. 				last  = first;
  76. 	  break;
  77. 	  case 3:	first = atoi(argv[1]);
  78. 				last  = atoi(argv[2]);
  79. 	  break;
  80. 	}
  81. 	if((clock=External_Clock())!=0)
  82. 	  for(target=first; target<=last && (ratio=Get_Ratio(target)) != 0; target++)
  83. 		printf("Processor#%d : Ratio[%d] x Clock[%d] = %d Mhz\n", target, ratio, clock, ratio*clock);
  84. 	else
  85. 		rc=-1;
  86. 	return(rc);
  87. }
Personal tools