Blog Code Forum

CoreMod

From Wiki.cyring.fr

(Difference between revisions)
Jump to: navigation, search
(coremod.c)
 
(16 intermediate revisions not shown)
Line 14: Line 14:
<br />
<br />
==== Compiling ====
==== Compiling ====
-
<syntaxhighlight lang="c">
+
<syntaxhighlight lang="bash">
-
$ gcc coremod.c -o coremod
+
$ make
-
</syntaxhighlight>
+
-
- or -
+
-
<syntaxhighlight lang="c">
+
-
$ clang coremod.c -o coremod
+
</syntaxhighlight>
</syntaxhighlight>
 +
<pre>
 +
Compiling : Done.
 +
Linking  : Done.
 +
Ready    : ./bin/coremod
 +
Remark    : You must be root to run CoreMod
 +
</pre>
<br />
<br />
 +
==== Debugging ====
==== Debugging ====
-
First of all, compile sources with the -g switch then launch the debugger<br />
+
First of all, compile sources with the -g switch enabled, if not already, in the Makefile's CFLAGS, then launch the debugger<br />
<syntaxhighlight lang="c">
<syntaxhighlight lang="c">
-
$ kdesu ddd ./coremod
+
$ kdesu ddd ./bin/coremod
</syntaxhighlight>
</syntaxhighlight>
<br />
<br />
 +
==== Usage ====
==== Usage ====
Two kernel modules must be loaded
Two kernel modules must be loaded
Line 38: Line 42:
</syntaxhighlight>
</syntaxhighlight>
<br />
<br />
 +
http://blog.cyring.fr/wp-content/uploads/2012/07/CyrIng_coremod_screen12.jpg
 +
<br /><br />
Usage is straightforward. Just enter the corresponding initial character to the function you want to execute.
Usage is straightforward. Just enter the corresponding initial character to the function you want to execute.
 +
<br />
Thus to show the core temperature, press the following keys:<br />
Thus to show the core temperature, press the following keys:<br />
* [s]
* [s]
Line 44: Line 51:
* [c]
* [c]
* [Enter]
* [Enter]
-
And for instance to go back to previous menu level:<br />
+
and for instance, to go back to previous menu level:<br />
* [<]
* [<]
* [Enter]
* [Enter]
<br />
<br />
Discover the other functions to dump your components !
Discover the other functions to dump your components !
 +
<br /><br />
 +
http://blog.cyring.fr/wp-content/uploads/2012/07/CyrIng_coremod_screen17.jpg
<br />
<br />
-
==== Contact ====
+
<br />
 +
 
 +
=== Contact ===
Feel free to [http://blog.cyring.fr/about/?lang=en contact] us for any suggestion or question.
Feel free to [http://blog.cyring.fr/about/?lang=en contact] us for any suggestion or question.
 +
<br />
<br />
<br />
-
=== Releases ===
+
=== Versions ===
-
==== Release 2012-0.1.2 ====
+
===== Nightly Build =====
-
===== coremod.h =====
+
:[http://code.cyring.fr/FTS/?PATH=Source/C/CoreMod/Nightly_Build/Latest Latest]
-
<syntaxhighlight lang="c" line start="1">
+
-
/*
+
-
* CoreMod by CyrIng
+
-
*
+
-
* Copyright (C) 2012 CYRIL INGENIERIE
+
-
*
+
-
* Licenses: GPL2
+
-
*
+
-
* coremod.h release 2012-0.1.2
+
-
*/
+
-
 
+
===== Release 2012-0.1.4 =====
-
// Intel® 64 and IA-32 Architectures Software Developer's Manual - Vol. 3C
+
:[http://code.cyring.fr/FTS/?PATH=Source/C/CoreMod/Previous_Build/2012-0.1.4 2012-0.1.4]
-
// Table 34-5 (Nehalem) and 34-10 (Sandy Bridge)
+
===== Release 2012-0.1.3 =====
-
 
+
:[http://code.cyring.fr/FTS/?PATH=Source/C/CoreMod/Previous_Build/2012-0.1.3 2012-0.1.3]
-
#define IA32_PERF_STATUS 0x198
+
===== Release 2012-0.1.2 =====
-
#define IA32_THERM_STATUS 0x19c
+
:[http://code.cyring.fr/FTS/?PATH=Source/C/CoreMod/Previous_Build/2012-0.1.2 2012-0.1.2]
-
#define MSR_TEMPERATURE_TARGET 0x1a2
+
===== Release 2012-0.1.1 =====
-
 
+
:[http://code.cyring.fr/FTS/?PATH=Source/C/CoreMod/Previous_Build/2012-0.1.1 2012-0.1.1]
-
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 =====
+
-
<syntaxhighlight lang="c" line start="1">
+
-
/*
+
-
* CoreMod by CyrIng
+
-
*
+
-
* Copyright (C) 2012 CYRIL INGENIERIE
+
-
*
+
-
* Licenses: GPL2
+
-
*
+
-
* coremod.c release 2012-0.1.2
+
-
*/
+
-
 
+
-
#include <stdio.h>
+
-
#include <stdlib.h>
+
-
#include <unistd.h>
+
-
#include <sys/stat.h>
+
-
#include <fcntl.h>
+
-
#include <ctype.h>
+
-
#include <errno.h>
+
-
#include "coremod.h"
+
-
 
+
-
 
+
-
struct STRING *SMB_Dig_Strings(struct PACKED *packed, int ID)
+
-
{
+
-
struct STRING *pstr=NULL;
+
-
char *buffer=NULL;
+
-
size_t rbyte=0;
+
-
 
+
-
if( getdelim(&buffer, &rbyte, STRING_DELIMITER, packed->File) > 1 )
+
-
{
+
-
pstr=malloc(sizeof(struct STRING));
+
-
pstr->Buffer=buffer;
+
-
pstr->ID=++ID;
+
-
pstr->Link=SMB_Dig_Strings(packed, ID);
+
-
return(pstr);
+
-
}
+
-
else
+
-
return(NULL);
+
-
}
+
-
 
+
-
struct STRING *SMB_Read_Strings(struct PACKED *packed)
+
-
{
+
-
return(packed->Length==0 ? SMB_Dig_Strings(packed, 0) : NULL);
+
-
}
+
-
 
+
-
void SMB_Dump_Strings(struct STRUCTINFO *smb)
+
-
{
+
-
struct STRING *pstr=NULL;
+
-
+
-
if(smb!=NULL)
+
-
{
+
-
printf("\nString#\t- Buffer -\n");
+
-
pstr=smb->String;
+
-
while(pstr!=NULL)
+
-
{
+
-
printf("%3d\t[%s]\n", pstr->ID, pstr->Buffer);
+
-
pstr=pstr->Link;
+
-
};
+
-
}
+
-
}
+
-
 
+
-
char *SMB_Find_String(struct STRUCTINFO *smb, int ID)
+
-
{
+
-
struct STRING *pstr=NULL;
+
-
 
+
-
if(smb!=NULL)
+
-
{
+
-
pstr=smb->String;
+
-
while(pstr!=NULL && pstr->ID!=ID)
+
-
pstr=pstr->Link;
+
-
}
+
-
return(pstr!=NULL ? pstr->Buffer : "");
+
-
}
+
-
 
+
-
int SMB_Read_Length(struct PACKED *packed)
+
-
{
+
-
char pathName[]="/sys/firmware/dmi/entries/999-99/file1234567890";
+
-
 
+
-
sprintf(pathName, "/sys/firmware/dmi/entries/%d-%d/length", packed->Type, packed->Instance);
+
-
if( (packed->File=fopen(pathName, "r")) != NULL )
+
-
{
+
-
fscanf(packed->File, "%zd\n", &packed->Length);
+
-
fclose(packed->File);
+
-
packed->Length-=sizeof(struct HEADER);
+
-
return(0);
+
-
}
+
-
else
+
-
return(errno);
+
-
}
+
-
 
+
-
int SMB_Open_Structure(struct PACKED *packed)
+
-
{
+
-
char pathName[]="/sys/firmware/dmi/entries/999-99/file1234567890";
+
-
 
+
-
sprintf(pathName, "/sys/firmware/dmi/entries/%d-%d/raw", packed->Type, packed->Instance);
+
-
if( (packed->File=fopen(pathName, "rb")) == NULL )
+
-
return(errno);
+
-
else
+
-
return(0);
+
-
}
+
-
 
+
-
int SMB_Close_Structure(struct PACKED *packed)
+
-
{
+
-
if(packed->File)
+
-
{
+
-
fclose(packed->File);
+
-
packed->File=NULL;
+
-
}
+
-
return(errno);
+
-
}
+
-
 
+
-
struct STRUCTINFO *SMB_Read_Structure(struct PACKED *packed)
+
-
{
+
-
struct STRUCTINFO *smb=NULL;
+
-
unsigned long long poly=0;
+
-
unsigned int head=0;
+
-
 
+
-
if( (smb=calloc(1, sizeof(struct STRUCTINFO))) !=NULL )
+
-
{
+
-
fread(&smb->Header, sizeof(struct HEADER), 1, packed->File);
+
-
 
+
-
while(packed->Tape[head] != _EOT_)
+
-
{
+
-
smb->Attrib=realloc(smb->Attrib, (head + 1) * sizeof(unsigned long long));
+
-
fread(&poly, 0b0001 << packed->Tape[head], 1, packed->File);
+
-
smb->Attrib[head]=poly;
+
-
packed->Length-=0b0001 << packed->Tape[head];
+
-
poly=0;
+
-
head++ ;
+
-
}
+
-
smb->Dimension=head;
+
-
}
+
-
return(smb);
+
-
}
+
-
 
+
-
void SMB_Read_Extension(struct PACKED *packed, struct STRUCTINFO *smb)
+
-
{
+
-
unsigned long long poly=0;
+
-
unsigned int head=0;
+
-
 
+
-
while(smb!=NULL && packed->Tape[head]!=_EOT_)
+
-
{
+
-
smb->Attrib=realloc(smb->Attrib, (smb->Dimension + head + 1) * sizeof(unsigned long long));
+
-
fread(&poly, 0b0001 << packed->Tape[head], 1, packed->File);
+
-
smb->Attrib[smb->Dimension + head]=poly;
+
-
packed->Length-=0b0001 << packed->Tape[head];
+
-
poly=0;
+
-
head++ ;
+
-
}
+
-
smb->Dimension+=head ;
+
-
}
+
-
 
+
-
void BIOS_Free_Structure(struct STRUCTINFO *smb)
+
-
{
+
-
struct STRING *Link=NULL, *pstr=NULL;
+
-
 
+
-
if(smb!=NULL)
+
-
{
+
-
pstr=smb->String;
+
-
while(pstr!=NULL)
+
-
{
+
-
Link=pstr->Link;
+
-
free(pstr);
+
-
pstr=Link;
+
-
};
+
-
smb->String=NULL;
+
-
if(smb->Attrib)
+
-
{
+
-
free(smb->Attrib);
+
-
smb->Attrib=NULL;
+
-
}
+
-
free(smb);
+
-
smb=NULL;
+
-
}
+
-
}
+
-
 
+
-
void SMB_Dump_Attribs(struct STRUCTINFO *smb)
+
-
{
+
-
int ix=0;
+
-
if(smb!=NULL)
+
-
{
+
-
printf("\nAttribute#\tHex\t\t\tDec\n");
+
-
for(ix=0; ix < smb->Dimension; ix++)
+
-
printf("%3d\t\t0x%-16llX\t( %20llu )\n", \
+
-
ix, smb->Attrib[ix], smb->Attrib[ix]);
+
-
}
+
-
}
+
-
 
+
-
struct BIOSINFO *BIOS_Read_Info(void)
+
-
{
+
-
int              tape[]=SMBIOS_BIOSINFO_PACKED;
+
-
struct PACKED    packed={SMBIOS_BIOSINFO_TYPE, SMBIOS_BIOSINFO_INSTANCE, NULL, 0, &tape[0]};
+
-
struct STRUCTINFO *smb=NULL;
+
-
 
+
-
if(!SMB_Read_Length(&packed) && !SMB_Open_Structure(&packed))
+
-
{
+
-
smb=SMB_Read_Structure(&packed);
+
-
smb->String=SMB_Read_Strings(&packed);
+
-
SMB_Close_Structure(&packed);
+
-
}
+
-
return((struct BIOSINFO*) smb);
+
-
}
+
-
 
+
-
struct BOARDINFO *BOARD_Read_Info(void)
+
-
{
+
-
int              tape[]=SMBIOS_BOARDINFO_PACKED,
+
-
                  extens[]=SMBIOS_BOARDINFO_EXTENS;
+
-
struct PACKED    packed={SMBIOS_BOARDINFO_TYPE, SMBIOS_BOARDINFO_INSTANCE, NULL, 0, &tape[0]};
+
-
struct STRUCTINFO *smb=NULL;
+
-
 
+
-
if(!SMB_Read_Length(&packed) && !SMB_Open_Structure(&packed))
+
-
{
+
-
smb=SMB_Read_Structure(&packed);
+
-
if(smb->Attrib[9] > 0)
+
-
{
+
-
packed.Tape=&extens[0];
+
-
while(packed.Length > 0)
+
-
SMB_Read_Extension(&packed, smb);
+
-
}
+
-
smb->String=SMB_Read_Strings(&packed);
+
-
SMB_Close_Structure(&packed);
+
-
}
+
-
return((struct BOARDINFO*) smb);
+
-
}
+
-
 
+
-
struct PROCINFO *PROC_Read_Info(void)
+
-
{
+
-
int              tape[]=SMBIOS_PROCINFO_PACKED,
+
-
                  extens[]=SMBIOS_PROCINFO_EXTENS;
+
-
struct PACKED    packed={SMBIOS_PROCINFO_TYPE, SMBIOS_PROCINFO_INSTANCE, NULL, 0, &tape[0]};
+
-
struct STRUCTINFO *smb=NULL;
+
-
 
+
-
if(!SMB_Read_Length(&packed) && !SMB_Open_Structure(&packed))
+
-
{
+
-
smb=SMB_Read_Structure(&packed);
+
-
if(packed.Length > 0)
+
-
{
+
-
packed.Tape=&extens[0];
+
-
SMB_Read_Extension(&packed, smb);
+
-
}
+
-
smb->String=SMB_Read_Strings(&packed);
+
-
SMB_Close_Structure(&packed);
+
-
}
+
-
return((struct PROCINFO*) smb);
+
-
}
+
-
 
+
-
struct CACHEINFO *CACHE_Read_Info(int instance)
+
-
{
+
-
int              tape[]=SMBIOS_CACHEINFO_PACKED;
+
-
struct PACKED    packed={SMBIOS_CACHEINFO_TYPE, instance, NULL, 0, &tape[0]};
+
-
struct STRUCTINFO *smb=NULL;
+
-
 
+
-
if(!SMB_Read_Length(&packed) && !SMB_Open_Structure(&packed))
+
-
{
+
-
smb=SMB_Read_Structure(&packed);
+
-
smb->String=SMB_Read_Strings(&packed);
+
-
SMB_Close_Structure(&packed);
+
-
}
+
-
return((struct CACHEINFO*) smb);
+
-
}
+
-
 
+
-
struct MEMARRAY *MEM_Read_Array(void)
+
-
{
+
-
int              tape[]=SMBIOS_MEMARRAY_PACKED,
+
-
                  extens[]=SMBIOS_MEMARRAY_EXTENS;
+
-
struct PACKED    packed={SMBIOS_MEMARRAY_TYPE, SMBIOS_MEMARRAY_INSTANCE, NULL, 0, &tape[0]};
+
-
struct STRUCTINFO *smb=NULL;
+
-
 
+
-
if(!SMB_Read_Length(&packed) && !SMB_Open_Structure(&packed))
+
-
{
+
-
smb=SMB_Read_Structure(&packed);
+
-
if(packed.Length > 0)
+
-
{
+
-
packed.Tape=&extens[0];
+
-
SMB_Read_Extension(&packed, smb);
+
-
}
+
-
smb->String=SMB_Read_Strings(&packed);
+
-
SMB_Close_Structure(&packed);
+
-
}
+
-
return((struct MEMARRAY*) smb);
+
-
}
+
-
 
+
-
struct MEMDEV *MEM_Read_Device(int instance)
+
-
{
+
-
int              tape[]=SMBIOS_MEMDEV_PACKED,
+
-
                  extens[]=SMBIOS_MEMDEV_EXTENS;
+
-
struct PACKED    packed={SMBIOS_MEMDEV_TYPE, instance, NULL, 0, &tape[0]};
+
-
struct STRUCTINFO *smb=NULL;
+
-
 
+
-
if(!SMB_Read_Length(&packed) && !SMB_Open_Structure(&packed))
+
-
{
+
-
smb=SMB_Read_Structure(&packed);
+
-
if(packed.Length > 0)
+
-
{
+
-
packed.Tape=&extens[0];
+
-
SMB_Read_Extension(&packed, smb);
+
-
}
+
-
smb->String=SMB_Read_Strings(&packed);
+
-
SMB_Close_Structure(&packed);
+
-
}
+
-
return((struct MEMDEV*) smb);
+
-
}
+
-
 
+
-
struct MEMDEV **MEM_ReadAll_Devices(struct MEMARRAY *memArray)
+
-
{
+
-
struct MEMDEV **memory=NULL;
+
-
int          stick=0;
+
-
 
+
-
if(memArray!=NULL)
+
-
{
+
-
memory=malloc(sizeof(struct MEMDEV*) * memArray->Attrib->Number_Devices);
+
-
for(stick=0; stick < memArray->Attrib->Number_Devices; stick++)
+
-
memory[stick]=MEM_Read_Device(stick);
+
-
}
+
-
return(memory);
+
-
}
+
-
 
+
-
void MEM_FreeAll_Devices(struct MEMDEV **memory, struct MEMARRAY *memArray)
+
-
{
+
-
int          stick=0;
+
-
 
+
-
if(memArray!=NULL)
+
-
{
+
-
for(stick=0; stick < memArray->Attrib->Number_Devices; stick++)
+
-
BIOS_Free_Structure((struct STRUCTINFO*) memory[stick]);
+
-
 
+
-
free(memory);
+
-
memory=NULL;
+
-
}
+
-
}
+
-
 
+
-
struct COREINFO *CORE_Read_Info(struct PROCINFO *proc)
+
-
{
+
-
struct COREINFO *core=NULL;
+
-
char pathName[]="/dev/cpu/99/msr";
+
-
ssize_t rbyte=0;
+
-
int cpu=0, File=-1;
+
-
 
+
-
if(proc!=NULL)
+
-
{
+
-
core=malloc(sizeof(struct COREINFO) * proc->Attrib->ThreadCount);
+
-
for(cpu=0; core && cpu < proc->Attrib->ThreadCount; cpu++)
+
-
{
+
-
sprintf(pathName, "/dev/cpu/%d/msr", cpu);
+
-
if((File=open(pathName, O_RDONLY)) != -1)
+
-
{
+
-
rbyte=pread(File, &core[cpu].Temp, 8, MSR_TEMPERATURE_TARGET);
+
-
close(File);
+
-
}
+
-
}
+
-
}
+
-
return(core);
+
-
}
+
-
 
+
-
void CORE_Update_Info(struct COREINFO *core, struct PROCINFO *proc)
+
-
{
+
-
char pathName[]="/dev/cpu/99/msr";
+
-
ssize_t rbyte=0;
+
-
int cpu=0, File=-1;
+
-
 
+
-
if(core!=NULL && proc!=NULL)
+
-
for(cpu=0; cpu < proc->Attrib->ThreadCount; cpu++)
+
-
{
+
-
sprintf(pathName, "/dev/cpu/%d/msr", cpu);
+
-
if((File=open(pathName, O_RDONLY)) != -1)
+
-
{
+
-
rbyte=pread(File, &core[cpu].Perf, 8, IA32_PERF_STATUS);
+
-
rbyte=pread(File, &core[cpu].Therm, 8, IA32_THERM_STATUS);
+
-
close(File);
+
-
}
+
-
}
+
-
}
+
-
 
+
-
void CORE_Free_Info(struct COREINFO *core)
+
-
{
+
-
if(core)
+
-
{
+
-
free(core);
+
-
core=NULL;
+
-
}
+
-
}
+
-
 
+
-
void CORE_Show_Info(struct COREINFO *core, struct PROCINFO *proc)
+
-
{
+
-
int cpu=0;
+
-
 
+
-
if(core!=NULL && proc!=NULL)
+
-
{
+
-
printf("\n\tCore#\tRatio\tx Clock\t= Frequency\tTJMAX\t- DTS\t= Temperature\n");
+
-
for(cpu=0; cpu < proc->Attrib->ThreadCount; cpu++)
+
-
printf("\t%2d\t %2d\tx  %3lld\t= %4lld MHz\t %3d\t- %3d\t=  %3d°C\n", \
+
-
cpu, \
+
-
core[cpu].Perf.Ratio, \
+
-
proc->Attrib->Clock, \
+
-
core[cpu].Perf.Ratio * proc->Attrib->Clock, \
+
-
core[cpu].Temp.Target, \
+
-
core[cpu].Therm.DTS, \
+
-
core[cpu].Temp.Target - core[cpu].Therm.DTS);
+
-
}
+
-
}
+
-
 
+
-
void PROC_Show_Info(struct PROCINFO *proc, struct CACHEINFO *cache[])
+
-
{
+
-
const float tension[0B1000]={0.0f, 5.0f, 3.3f, 0.0f, 2.9f, 0.0f, 0.0f, 0.0f};
+
-
const char *power[2]={"OFF", "ON"};
+
-
int        ix=0;
+
-
 
+
-
if(proc!=NULL && cache[0]!=NULL && cache[1]!=NULL && cache[2]!=NULL)
+
-
{
+
-
printf("\n\t%s\n\tBase clock  @ %lld MHz\n\t%sclocked @ %lld MHz\n", \
+
-
SMB_Find_String((struct STRUCTINFO*) proc, proc->Attrib->Version), \
+
-
proc->Attrib->Clock, \
+
-
llabs(proc->Attrib->CurrentSpeed - proc->Attrib->MaxSpeed) > 20 ? \
+
-
"Over" : "Factory ", \
+
-
proc->Attrib->CurrentSpeed);
+
-
printf("\t%lld/%lld cores enabled, %lld threads detected.\n", \
+
-
proc->Attrib->CoreEnabled, \
+
-
proc->Attrib->CoreCount, \
+
-
proc->Attrib->ThreadCount);
+
-
printf("\tSocket : %s\n", \
+
-
SMB_Find_String((struct STRUCTINFO*) proc, proc->Attrib->Socket));
+
-
printf("\tTension: %.1f V\n\t",
+
-
proc->Attrib->Voltage.Mode ? proc->Attrib->Voltage.Tension / 10.0f \
+
-
  : tension[proc->Attrib->Voltage.Tension & 0B0111]);
+
-
for(ix=0; ix < 3; ix++)
+
-
printf("%s [%4lld]%s", \
+
-
SMB_Find_String((struct STRUCTINFO*) cache[ix], cache[ix]->Attrib->Socket), \
+
-
cache[ix]->Attrib->Installed_Size, ix < 2 ? "    " : "");
+
-
printf("\n\n\tCPUID.1:EAX=0x%08X          CPUID.1:EDX=0x%08X\n\n", \
+
-
proc->Attrib->CPUID.EAX, proc->Attrib->CPUID.EDX);
+
-
printf("\tAdvanced Programmable Interrupt Controller  APIC [%3s]\n", \
+
-
power[proc->Attrib->CPUID.EDX.APIC]);
+
-
printf("\tHyper-Threading                                  [%3s]\n", \
+
-
power[proc->Attrib->CPUID.EDX.HyperThreading]);
+
-
printf("\tMemory Type Range Registers                MTRR [%3s]\n", \
+
-
power[proc->Attrib->CPUID.EDX.MTRR]);
+
-
printf("\tPage Attribute Table                        PAT [%3s]\n", \
+
-
power[proc->Attrib->CPUID.EDX.PAT]);
+
-
printf("\tInstruction set:      MMX [%3s]  SSE [%3s]  SSE2 [%3s]\n", \
+
-
power[proc->Attrib->CPUID.EDX.MMX], \
+
-
power[proc->Attrib->CPUID.EDX.SSE], \
+
-
power[proc->Attrib->CPUID.EDX.SSE2]);
+
-
}
+
-
}
+
-
 
+
-
void SYS_Show_Info(struct BIOSINFO *bios, \
+
-
  struct BOARDINFO *board, \
+
-
  struct MEMARRAY  *memArray, \
+
-
  struct MEMDEV **memory )
+
-
{
+
-
unsigned long long totalMemSize=0;
+
-
int                ix=0;
+
-
 
+
-
if(bios!=NULL && board!=NULL && memArray!=NULL && memory!=NULL)
+
-
{
+
-
printf("\n\tBoard: %s\n\t |- version %s\n\t |- manufactured by %s\n", \
+
-
SMB_Find_String((struct STRUCTINFO*) board, board->Attrib->Product), \
+
-
SMB_Find_String((struct STRUCTINFO*) board, board->Attrib->Version), \
+
-
SMB_Find_String((struct STRUCTINFO*) board, board->Attrib->Manufacturer));
+
-
printf("\n\tBIOS: %s\n\t |- version %s\n\t |- released date %s\n\t |- revision %lld.%lld\n", \
+
-
SMB_Find_String((struct STRUCTINFO*) bios, bios->Attrib->Vendor), \
+
-
SMB_Find_String((struct STRUCTINFO*) bios, bios->Attrib->Version), \
+
-
SMB_Find_String((struct STRUCTINFO*) bios, bios->Attrib->Release_Date), \
+
-
bios->Attrib->Major_Release, bios->Attrib->Minor_Release);
+
-
printf("\t |- ROM Size: %lld KB at 0x%04X\n",
+
-
64 * (1 + bios->Attrib->ROM_Size), bios->Attrib->Address);
+
-
for(ix=0; ix < memArray->Attrib->Number_Devices; ix++)
+
-
totalMemSize+=memory[ix]->Attrib->Size;
+
-
printf("\n\tRAM: %lld/%lld MB\n", totalMemSize, memArray->Attrib->Maximum_Capacity/1024);
+
-
for(ix=0; ix < memArray->Attrib->Number_Devices; ix++)
+
-
printf("\t |- %s:%s  %lld MB @ %lld MHz\n", \
+
-
SMB_Find_String((struct STRUCTINFO*) memory[ix], memory[ix]->Attrib->Socket), \
+
-
SMB_Find_String((struct STRUCTINFO*) memory[ix], memory[ix]->Attrib->Bank), \
+
-
memory[ix]->Attrib->Size, memory[ix]->Attrib->Speed);
+
-
}
+
-
}
+
-
 
+
-
int Menu_Getkey(void)
+
-
{
+
-
int key=0, flush=0;
+
-
 
+
-
key=flush=tolower(getchar());
+
-
  while(flush != '\n')
+
-
flush=getchar();
+
-
return(key);
+
-
}
+
-
 
+
-
 
+
-
int main(int argc, char *argv[])
+
-
{
+
-
int    ix=0, runLevel=0, function=FN_NOOP, command=0;
+
-
 
+
-
struct BIOSINFO  *Bios = BIOS_Read_Info();
+
-
struct BOARDINFO *Board= BOARD_Read_Info();
+
-
struct PROCINFO  *Proc = PROC_Read_Info();
+
-
struct CACHEINFO *Cache[3]={CACHE_Read_Info(0), CACHE_Read_Info(1), CACHE_Read_Info(2)};
+
-
struct MEMARRAY  *MemArray = MEM_Read_Array();
+
-
struct MEMDEV    **Memory = MEM_ReadAll_Devices(MemArray);
+
-
struct COREINFO  *Core=CORE_Read_Info(Proc);
+
-
 
+
-
char menuLabel[LEVELS][CHARS]=
+
-
{
+
-
MENU_LABEL_ROOT,
+
-
MENU_LABEL_HELP,
+
-
MENU_LABEL_SHOW,
+
-
MENU_LABEL_DUMP,
+
-
MENU_LABEL_ATTR,
+
-
MENU_LABEL_STRG,
+
-
MENU_LABEL_CACH,
+
-
MENU_LABEL_CACH,
+
-
MENU_LABEL_MEMY,
+
-
MENU_LABEL_MEMY,
+
-
MENU_LABEL_CMOD
+
-
};
+
-
char menuPrompt[LEVELS][CHARS]=
+
-
{
+
-
MENU_PROMPT_ROOT,
+
-
MENU_PROMPT_HELP,
+
-
MENU_PROMPT_SHOW,
+
-
MENU_PROMPT_DUMP,
+
-
MENU_PROMPT_ATTR,
+
-
MENU_PROMPT_STRG,
+
-
MENU_PROMPT_CACH,
+
-
MENU_PROMPT_CACH,
+
-
MENU_PROMPT_MEMY,
+
-
MENU_PROMPT_MEMY,
+
-
MENU_PROMPT_CMOD
+
-
};
+
-
struct MENUNAV levelRoot[]=MENU_LEVEL_ROOT,
+
-
levelHelp[]=MENU_LEVEL_HELP,
+
-
levelShow[]=MENU_LEVEL_SHOW,
+
-
levelDump[]=MENU_LEVEL_DUMP,
+
-
levelAttr[]=MENU_LEVEL_ATTR,
+
-
levelStrg[]=MENU_LEVEL_STRG,
+
-
levelAttH[]=MENU_LEVEL_ATTH,
+
-
levelStrH[]=MENU_LEVEL_STRH,
+
-
levelAttY[]=MENU_LEVEL_ATTY,
+
-
levelStrY[]=MENU_LEVEL_STRY,
+
-
levelCMod[]=MENU_LEVEL_CMOD;
+
-
 
+
-
struct MENUNAV *menuNav[LEVELS]=
+
-
{
+
-
levelRoot,
+
-
levelHelp,
+
-
levelShow,
+
-
levelDump,
+
-
levelAttr,
+
-
levelStrg,
+
-
levelAttH,
+
-
levelStrH,
+
-
levelAttY,
+
-
levelStrY,
+
-
levelCMod
+
-
};
+
-
 
+
-
if(MemArray!=NULL)
+
-
for(ix=0; ix < MemArray->Attrib->Number_Devices; ix++)
+
-
{
+
-
menuPrompt[LV_ATTY][23+ix*6]='[';
+
-
menuPrompt[LV_ATTY][24+ix*6]='1'+ix;
+
-
menuPrompt[LV_ATTY][25+ix*6]=']';
+
-
menuNav[LV_ATTY][3+ix].Command='1'+ix;
+
-
menuNav[LV_ATTY][3+ix].Function=FN_ATTD+ix;
+
-
menuPrompt[LV_STRY][23+ix*6]='[';
+
-
menuPrompt[LV_STRY][24+ix*6]='1'+ix;
+
-
menuPrompt[LV_STRY][25+ix*6]=']';
+
-
menuNav[LV_STRY][3+ix].Command='1'+ix;
+
-
menuNav[LV_STRY][3+ix].Function=FN_STRD+ix;
+
-
}
+
-
 
+
-
while(function != FN_EXIT)
+
-
{
+
-
Menu_Display(runLevel);
+
-
{
+
-
command=Menu_Getkey();
+
-
 
+
-
ix=0;
+
-
while( command != menuNav[runLevel][ix].Command \
+
-
&& menuNav[runLevel][ix].Command != EOL )
+
-
ix++ ;
+
-
 
+
-
function =menuNav[runLevel][ix].Function;
+
-
runLevel=menuNav[runLevel][ix].NewLevel;
+
-
}
+
-
switch(function)
+
-
{
+
-
case FN_SHWC: CORE_Update_Info(Core, Proc);
+
-
CORE_Show_Info(Core, Proc);
+
-
break;
+
-
case FN_SHWP: PROC_Show_Info(Proc, Cache);
+
-
break;
+
-
case FN_SHWS: SYS_Show_Info(Bios, Board, MemArray, Memory);
+
-
break;
+
-
case FN_ATTB: SMB_Dump_Attribs((struct STRUCTINFO*) Bios);
+
-
break;
+
-
case FN_ATTM: SMB_Dump_Attribs((struct STRUCTINFO*) Board);
+
-
break;
+
-
case FN_ATTP: SMB_Dump_Attribs((struct STRUCTINFO*) Proc);
+
-
break;
+
-
case FN_ATL1: SMB_Dump_Attribs((struct STRUCTINFO*) Cache[0]);
+
-
break;
+
-
case FN_ATL2: SMB_Dump_Attribs((struct STRUCTINFO*) Cache[1]);
+
-
break;
+
-
case FN_ATL3: SMB_Dump_Attribs((struct STRUCTINFO*) Cache[2]);
+
-
break;
+
-
case FN_ATTY: SMB_Dump_Attribs((struct STRUCTINFO*) MemArray);
+
-
break;
+
-
case FN_ATTD+0:
+
-
case FN_ATTD+1:
+
-
case FN_ATTD+2:
+
-
case FN_ATTD+3:
+
-
case FN_ATTD+4:
+
-
case FN_ATTD+5:
+
-
case FN_ATTD+6:
+
-
case FN_ATTD+7: SMB_Dump_Attribs((struct STRUCTINFO*) Memory[function-FN_ATTD]);
+
-
break;
+
-
case FN_STRB: SMB_Dump_Strings((struct STRUCTINFO*) Bios);
+
-
break;
+
-
case FN_STRM: SMB_Dump_Strings((struct STRUCTINFO*) Board);
+
-
break;
+
-
case FN_STRP: SMB_Dump_Strings((struct STRUCTINFO*) Proc);
+
-
break;
+
-
case FN_STL1: SMB_Dump_Strings((struct STRUCTINFO*) Cache[0]);
+
-
break;
+
-
case FN_STL2: SMB_Dump_Strings((struct STRUCTINFO*) Cache[1]);
+
-
break;
+
-
case FN_STL3: SMB_Dump_Strings((struct STRUCTINFO*) Cache[2]);
+
-
break;
+
-
case FN_STRY: SMB_Dump_Strings((struct STRUCTINFO*) MemArray);
+
-
break;
+
-
case FN_STRD+0:
+
-
case FN_STRD+1:
+
-
case FN_STRD+2:
+
-
case FN_STRD+3:
+
-
case FN_STRD+4:
+
-
case FN_STRD+5:
+
-
case FN_STRD+6:
+
-
case FN_STRD+7: SMB_Dump_Strings((struct STRUCTINFO*) Memory[function-FN_STRD]);
+
-
}
+
-
};
+
-
 
+
-
CORE_Free_Info(Core);
+
-
MEM_FreeAll_Devices(Memory, MemArray);
+
-
BIOS_Free_Structure((struct STRUCTINFO*) MemArray);
+
-
BIOS_Free_Structure((struct STRUCTINFO*) Cache[2]);
+
-
BIOS_Free_Structure((struct STRUCTINFO*) Cache[1]);
+
-
BIOS_Free_Structure((struct STRUCTINFO*) Cache[0]);
+
-
BIOS_Free_Structure((struct STRUCTINFO*) Proc);
+
-
BIOS_Free_Structure((struct STRUCTINFO*) Board);
+
-
BIOS_Free_Structure((struct STRUCTINFO*) Bios);
+
-
 
+
-
return(function);
+
-
}
+
-
 
+
-
</syntaxhighlight>
+
-
 
+
-
==== Release 2012-0.1.1 ====
+
-
===== coremod.c =====
+
-
<syntaxhighlight lang="c" line start="1">
+
-
// coremod.c - CyrIng 2012
+
-
 
+
-
#include <stdio.h>
+
-
#include <stdlib.h>
+
-
#include <unistd.h>
+
-
#include <sys/stat.h>
+
-
#include <fcntl.h>
+
-
 
+
-
// Intel® 64 and IA-32 Architectures Software Developer’s Manual
+
-
// Vol. 3C § 34-1
+
-
// Table 34-2. IA-32 Architectural MSRs
+
-
 
+
-
#define IA32_PERF_STATUS 0x198
+
-
 
+
-
// System Management BIOS (SMBIOS) Reference Specification
+
-
// Version: 2.7.1 § 7.5
+
-
// Table 20 – Processor Information (Type 4) Structure
+
-
 
+
-
#define SMBIOS_PROCINFO_STRUCTURE 4
+
-
#define SMBIOS_PROCINFO_INSTANCE 0
+
-
#define SMBIOS_PROCINFO_EXTCLK 0x12
+
-
 
+
-
 
+
-
int Read_MSR(int cpu, off_t offset, unsigned long long *msr) {
+
-
ssize_t retval=0;
+
-
char pathname[32]="";
+
-
int fd=0, rc=-1;
+
-
 
+
-
sprintf(pathname, "/dev/cpu/%d/msr", cpu);
+
-
if( (fd=open(pathname, O_RDONLY)) != -1 ) {
+
-
retval=pread(fd, msr, sizeof *msr, offset);
+
-
close(fd);
+
-
rc=(retval != sizeof *msr) ? -1 : 0;
+
-
}
+
-
return(rc);
+
-
}
+
-
 
+
-
int Read_SMBIOS(int structure, int instance, off_t offset, void *buf, size_t nbyte) {
+
-
ssize_t retval=0;
+
-
char pathname[]="/sys/firmware/dmi/entries/999-99/raw";
+
-
int fd=0, rc=-1;
+
-
 
+
-
sprintf(pathname, "/sys/firmware/dmi/entries/%d-%d/raw", structure, instance);
+
-
if( (fd=open(pathname, O_RDONLY)) != -1 ) {
+
-
retval=pread(fd, buf, nbyte, offset);
+
-
close(fd);
+
-
rc=(retval != nbyte) ? -1 : 0;
+
-
}
+
-
return(rc);
+
-
}
+
-
 
+
-
int Get_Ratio(int target) {
+
-
unsigned long long msr=0;
+
-
 
+
-
if( Read_MSR(target, IA32_PERF_STATUS, &msr) != -1)
+
-
return((int) msr);
+
-
else
+
-
return(0);
+
-
}
+
-
 
+
-
int External_Clock() {
+
-
int clock=0;
+
-
+
-
if( Read_SMBIOS(SMBIOS_PROCINFO_STRUCTURE, SMBIOS_PROCINFO_INSTANCE, SMBIOS_PROCINFO_EXTCLK, &clock, 1) != -1)
+
-
return(clock);
+
-
else
+
-
return(0);
+
-
}
+
-
 
+
-
int main(int argc, char *argv[]) {
+
-
int target=0, first=0, last=0, clock=0, ratio=0, rc=0;
+
-
+
-
switch(argc) {
+
-
  case 2: first = atoi(argv[1]);
+
-
last  = first;
+
-
  break;
+
-
  case 3: first = atoi(argv[1]);
+
-
last  = atoi(argv[2]);
+
-
  break;
+
-
}
+
-
if((clock=External_Clock())!=0)
+
-
  for(target=first; target<=last && (ratio=Get_Ratio(target)) != 0; target++)
+
-
printf("Processor#%d : Ratio[%d] x Clock[%d] = %d Mhz\n", target, ratio, clock, ratio*clock);
+
-
else
+
-
rc=-1;
+
-
return(rc);
+
-
}
+
-
</syntaxhighlight>
+

Latest revision as of 10:04, 19 November 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

$ make
Compiling : Done.
Linking   : Done.
Ready     : ./bin/coremod
Remark    : You must be root to run CoreMod


Debugging

First of all, compile sources with the -g switch enabled, if not already, in the Makefile's CFLAGS, then launch the debugger

$ kdesu ddd ./bin/coremod


Usage

Two kernel modules must be loaded

  1. msr
  2. dmi-sysfs


Execute CoreMod as root

# ./coremod


CyrIng_coremod_screen12.jpg

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 !

CyrIng_coremod_screen17.jpg

Contact

Feel free to contact us for any suggestion or question.

Versions

Nightly Build
Latest
Release 2012-0.1.4
2012-0.1.4
Release 2012-0.1.3
2012-0.1.3
Release 2012-0.1.2
2012-0.1.2
Release 2012-0.1.1
2012-0.1.1
Personal tools