Blog Code Forum

CoreMod

From Wiki.cyring.fr

(Difference between revisions)
Jump to: navigation, search
(Compiling)
(Compiling)
Line 17: Line 17:
$ make
$ make
</syntaxhighlight>
</syntaxhighlight>
 +
<pre>
Compiling : Done.
Compiling : Done.
Linking  : Done.
Linking  : Done.
Ready    : ./bin/coremod
Ready    : ./bin/coremod
Remark    : You must be root to run CoreMod
Remark    : You must be root to run CoreMod
 +
</pre>
<br />
<br />

Revision as of 07:09, 5 September 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 then launch the debugger

$ kdesu ddd ./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.

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
  1. /*
  2.  * CoreMod by CyrIng
  3.  * 
  4.  * Copyright (C) 2012 CYRIL INGENIERIE
  5.  * 
  6.  * Licenses: GPL2
  7.  * 
  8.  * coremod.c release 2012-0.1.2
  9.  */
  10.  
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <unistd.h>
  14. #include <sys/stat.h>
  15. #include <fcntl.h>
  16. #include <ctype.h>
  17. #include <errno.h>
  18. #include "coremod.h"
  19.  
  20.  
  21. struct STRING *SMB_Dig_Strings(struct PACKED *packed, int ID)
  22. {
  23. 	struct	STRING *pstr=NULL;
  24. 	char	*buffer=NULL;
  25. 	size_t	rbyte=0;
  26.  
  27. 	if( getdelim(&buffer, &rbyte, STRING_DELIMITER, packed->File) > 1 )
  28. 	{
  29. 		pstr=malloc(sizeof(struct STRING));
  30. 		pstr->Buffer=buffer;
  31. 		pstr->ID=++ID;
  32. 		pstr->Link=SMB_Dig_Strings(packed, ID);
  33. 		return(pstr);
  34. 	}
  35. 	else
  36. 		return(NULL);
  37. }
  38.  
  39. struct STRING *SMB_Read_Strings(struct PACKED *packed)
  40. {
  41. 	return(packed->Length==0 ? SMB_Dig_Strings(packed, 0) : NULL);
  42. }
  43.  
  44. void SMB_Dump_Strings(struct STRUCTINFO *smb)
  45. {
  46. 	struct STRING *pstr=NULL;
  47.  
  48. 	if(smb!=NULL)
  49. 	{
  50. 		printf("\nString#\t- Buffer -\n");
  51. 		pstr=smb->String;
  52. 		while(pstr!=NULL)
  53. 		{
  54. 			printf("%3d\t[%s]\n", pstr->ID, pstr->Buffer);
  55. 			pstr=pstr->Link;
  56. 		};
  57. 	}
  58. }
  59.  
  60. char *SMB_Find_String(struct STRUCTINFO *smb, int ID)
  61. {
  62. 	struct STRING *pstr=NULL;
  63.  
  64. 	if(smb!=NULL)
  65. 	{
  66. 		pstr=smb->String;
  67. 		while(pstr!=NULL && pstr->ID!=ID)
  68. 			pstr=pstr->Link;
  69. 	}
  70. 	return(pstr!=NULL ? pstr->Buffer : "");
  71. }
  72.  
  73. int SMB_Read_Length(struct PACKED *packed)
  74. {
  75. 	char	pathName[]="/sys/firmware/dmi/entries/999-99/file1234567890";
  76.  
  77. 	sprintf(pathName, "/sys/firmware/dmi/entries/%d-%d/length", packed->Type, packed->Instance);
  78. 	if( (packed->File=fopen(pathName, "r")) != NULL )
  79. 	{
  80. 		fscanf(packed->File, "%zd\n", &packed->Length);
  81. 		fclose(packed->File);
  82. 		packed->Length-=sizeof(struct HEADER);
  83. 		return(0);
  84. 	}
  85. 	else
  86. 		return(errno);
  87. }
  88.  
  89. int SMB_Open_Structure(struct PACKED *packed)
  90. {
  91. 	char	pathName[]="/sys/firmware/dmi/entries/999-99/file1234567890";
  92.  
  93. 	sprintf(pathName, "/sys/firmware/dmi/entries/%d-%d/raw", packed->Type, packed->Instance);
  94. 	if( (packed->File=fopen(pathName, "rb")) == NULL )
  95. 		return(errno);
  96. 	else
  97. 		return(0);
  98. }
  99.  
  100. int SMB_Close_Structure(struct PACKED *packed)
  101. {
  102. 	if(packed->File)
  103. 	{
  104. 		fclose(packed->File);
  105. 		packed->File=NULL;
  106. 	}
  107. 	return(errno);
  108. }
  109.  
  110. struct STRUCTINFO *SMB_Read_Structure(struct PACKED *packed)
  111. {
  112. 	struct STRUCTINFO *smb=NULL;
  113. 	unsigned long long	poly=0;
  114. 	unsigned int		head=0;
  115.  
  116. 	if( (smb=calloc(1, sizeof(struct STRUCTINFO))) !=NULL )
  117. 	{
  118. 		fread(&smb->Header, sizeof(struct HEADER), 1, packed->File);
  119.  
  120. 		while(packed->Tape[head] != _EOT_)
  121. 		{
  122. 			smb->Attrib=realloc(smb->Attrib, (head + 1) * sizeof(unsigned long long));
  123. 			fread(&poly, 0b0001 << packed->Tape[head], 1, packed->File);
  124. 			smb->Attrib[head]=poly;
  125. 			packed->Length-=0b0001 << packed->Tape[head];
  126. 			poly=0;
  127. 			head++ ;
  128. 		}
  129. 		smb->Dimension=head;
  130. 	}
  131. 	return(smb);
  132. }
  133.  
  134. void SMB_Read_Extension(struct PACKED *packed, struct STRUCTINFO *smb)
  135. {
  136. 	unsigned long long	poly=0;
  137. 	unsigned int		head=0;
  138.  
  139. 	while(smb!=NULL && packed->Tape[head]!=_EOT_)
  140. 	{
  141. 		smb->Attrib=realloc(smb->Attrib, (smb->Dimension + head + 1) * sizeof(unsigned long long));
  142. 		fread(&poly, 0b0001 << packed->Tape[head], 1, packed->File);
  143. 		smb->Attrib[smb->Dimension + head]=poly;
  144. 		packed->Length-=0b0001 << packed->Tape[head];
  145. 		poly=0;
  146. 		head++ ;
  147. 	}
  148. 	smb->Dimension+=head ;
  149. }
  150.  
  151. void BIOS_Free_Structure(struct STRUCTINFO *smb)
  152. {
  153. 	struct STRING *Link=NULL, *pstr=NULL;
  154.  
  155. 	if(smb!=NULL)
  156. 	{
  157. 		pstr=smb->String;
  158. 		while(pstr!=NULL)
  159. 		{
  160. 			Link=pstr->Link;
  161. 			free(pstr);
  162. 			pstr=Link;
  163. 		};
  164. 		smb->String=NULL;
  165. 		if(smb->Attrib)
  166. 		{
  167. 			free(smb->Attrib);
  168. 			smb->Attrib=NULL;
  169. 		}
  170. 		free(smb);
  171. 		smb=NULL;
  172. 	}
  173. }
  174.  
  175. void SMB_Dump_Attribs(struct STRUCTINFO *smb)
  176. {
  177. 	int	ix=0;
  178. 	if(smb!=NULL)
  179. 	{
  180. 		printf("\nAttribute#\tHex\t\t\tDec\n");
  181. 		for(ix=0; ix < smb->Dimension; ix++)
  182. 			printf("%3d\t\t0x%-16llX\t( %20llu )\n", \
  183. 					ix, smb->Attrib[ix], smb->Attrib[ix]);
  184. 	}
  185. }
  186.  
  187. struct BIOSINFO *BIOS_Read_Info(void)
  188. {
  189. 	int               tape[]=SMBIOS_BIOSINFO_PACKED;
  190. 	struct PACKED     packed={SMBIOS_BIOSINFO_TYPE, SMBIOS_BIOSINFO_INSTANCE, NULL, 0, &tape[0]};
  191. 	struct STRUCTINFO *smb=NULL;
  192.  
  193. 	if(!SMB_Read_Length(&packed) && !SMB_Open_Structure(&packed))
  194. 	{
  195. 		smb=SMB_Read_Structure(&packed);
  196. 		smb->String=SMB_Read_Strings(&packed);
  197. 		SMB_Close_Structure(&packed);
  198. 	}
  199. 	return((struct BIOSINFO*) smb);
  200. }
  201.  
  202. struct BOARDINFO *BOARD_Read_Info(void)
  203. {
  204. 	int               tape[]=SMBIOS_BOARDINFO_PACKED,
  205. 	                  extens[]=SMBIOS_BOARDINFO_EXTENS;
  206. 	struct PACKED     packed={SMBIOS_BOARDINFO_TYPE, SMBIOS_BOARDINFO_INSTANCE, NULL, 0, &tape[0]};
  207. 	struct STRUCTINFO *smb=NULL;
  208.  
  209. 	if(!SMB_Read_Length(&packed) && !SMB_Open_Structure(&packed))
  210. 	{
  211. 		smb=SMB_Read_Structure(&packed);
  212. 		if(smb->Attrib[9] > 0)
  213. 		{
  214. 			packed.Tape=&extens[0];
  215. 			while(packed.Length > 0)
  216. 				SMB_Read_Extension(&packed, smb);
  217. 		}
  218. 		smb->String=SMB_Read_Strings(&packed);
  219. 		SMB_Close_Structure(&packed);
  220. 	}
  221. 	return((struct BOARDINFO*) smb);
  222. }
  223.  
  224. struct PROCINFO *PROC_Read_Info(void)
  225. {
  226. 	int               tape[]=SMBIOS_PROCINFO_PACKED,
  227. 	                  extens[]=SMBIOS_PROCINFO_EXTENS;
  228. 	struct PACKED     packed={SMBIOS_PROCINFO_TYPE, SMBIOS_PROCINFO_INSTANCE, NULL, 0, &tape[0]};
  229. 	struct STRUCTINFO *smb=NULL;
  230.  
  231. 	if(!SMB_Read_Length(&packed) && !SMB_Open_Structure(&packed))
  232. 	{
  233. 		smb=SMB_Read_Structure(&packed);
  234. 		if(packed.Length > 0)
  235. 		{
  236. 			packed.Tape=&extens[0];
  237. 			SMB_Read_Extension(&packed, smb);
  238. 		}
  239. 		smb->String=SMB_Read_Strings(&packed);
  240. 		SMB_Close_Structure(&packed);
  241. 	}
  242. 	return((struct PROCINFO*) smb);
  243. }
  244.  
  245. struct CACHEINFO *CACHE_Read_Info(int instance)
  246. {
  247. 	int               tape[]=SMBIOS_CACHEINFO_PACKED;
  248. 	struct PACKED     packed={SMBIOS_CACHEINFO_TYPE, instance, NULL, 0, &tape[0]};
  249. 	struct STRUCTINFO *smb=NULL;
  250.  
  251. 	if(!SMB_Read_Length(&packed) && !SMB_Open_Structure(&packed))
  252. 	{
  253. 		smb=SMB_Read_Structure(&packed);
  254. 		smb->String=SMB_Read_Strings(&packed);
  255. 		SMB_Close_Structure(&packed);
  256. 	}
  257. 	return((struct CACHEINFO*) smb);
  258. }
  259.  
  260. struct MEMARRAY *MEM_Read_Array(void)
  261. {
  262. 	int               tape[]=SMBIOS_MEMARRAY_PACKED,
  263. 	                  extens[]=SMBIOS_MEMARRAY_EXTENS;
  264. 	struct PACKED     packed={SMBIOS_MEMARRAY_TYPE, SMBIOS_MEMARRAY_INSTANCE, NULL, 0, &tape[0]};
  265. 	struct STRUCTINFO *smb=NULL;
  266.  
  267. 	if(!SMB_Read_Length(&packed) && !SMB_Open_Structure(&packed))
  268. 	{
  269. 		smb=SMB_Read_Structure(&packed);
  270. 		if(packed.Length > 0)
  271. 		{
  272. 			packed.Tape=&extens[0];
  273. 			SMB_Read_Extension(&packed, smb);
  274. 		}
  275. 		smb->String=SMB_Read_Strings(&packed);
  276. 		SMB_Close_Structure(&packed);
  277. 	}
  278. 	return((struct MEMARRAY*) smb);
  279. }
  280.  
  281. struct MEMDEV *MEM_Read_Device(int instance)
  282. {
  283. 	int               tape[]=SMBIOS_MEMDEV_PACKED,
  284. 	                  extens[]=SMBIOS_MEMDEV_EXTENS;
  285. 	struct PACKED     packed={SMBIOS_MEMDEV_TYPE, instance, NULL, 0, &tape[0]};
  286. 	struct STRUCTINFO *smb=NULL;
  287.  
  288. 	if(!SMB_Read_Length(&packed) && !SMB_Open_Structure(&packed))
  289. 	{
  290. 		smb=SMB_Read_Structure(&packed);
  291. 		if(packed.Length > 0)
  292. 		{
  293. 			packed.Tape=&extens[0];
  294. 			SMB_Read_Extension(&packed, smb);
  295. 		}
  296. 		smb->String=SMB_Read_Strings(&packed);
  297. 		SMB_Close_Structure(&packed);
  298. 	}
  299. 	return((struct MEMDEV*) smb);
  300. }
  301.  
  302. struct MEMDEV **MEM_ReadAll_Devices(struct MEMARRAY *memArray)
  303. {
  304. 	struct MEMDEV **memory=NULL;
  305. 	int           stick=0;
  306.  
  307. 	if(memArray!=NULL)
  308. 	{
  309. 		memory=malloc(sizeof(struct MEMDEV*) * memArray->Attrib->Number_Devices);
  310. 		for(stick=0; stick < memArray->Attrib->Number_Devices; stick++)
  311. 			memory[stick]=MEM_Read_Device(stick);
  312. 	}
  313. 	return(memory);
  314. }
  315.  
  316. void MEM_FreeAll_Devices(struct MEMDEV **memory, struct MEMARRAY *memArray)
  317. {
  318. 	int           stick=0;
  319.  
  320. 	if(memArray!=NULL)
  321. 	{
  322. 		for(stick=0; stick < memArray->Attrib->Number_Devices; stick++)
  323. 			BIOS_Free_Structure((struct STRUCTINFO*) memory[stick]);
  324.  
  325. 		free(memory);
  326. 		memory=NULL;
  327. 	}
  328. }
  329.  
  330. struct COREINFO *CORE_Read_Info(struct PROCINFO *proc)
  331. {
  332. 	struct	COREINFO *core=NULL;
  333. 	char	pathName[]="/dev/cpu/99/msr";
  334. 	ssize_t	rbyte=0;
  335. 	int		cpu=0, File=-1;
  336.  
  337. 	if(proc!=NULL)
  338. 	{
  339. 		core=malloc(sizeof(struct COREINFO) * proc->Attrib->ThreadCount);
  340. 		for(cpu=0; core && cpu < proc->Attrib->ThreadCount; cpu++)
  341. 		{
  342. 			sprintf(pathName, "/dev/cpu/%d/msr", cpu);
  343. 			if((File=open(pathName, O_RDONLY)) != -1)
  344. 			{
  345. 				rbyte=pread(File, &core[cpu].Temp, 8, MSR_TEMPERATURE_TARGET);
  346. 				close(File);
  347. 			}
  348. 		}
  349. 	}
  350. 	return(core);
  351. }
  352.  
  353. void CORE_Update_Info(struct COREINFO *core, struct PROCINFO *proc)
  354. {
  355. 	char	pathName[]="/dev/cpu/99/msr";
  356. 	ssize_t	rbyte=0;
  357. 	int		cpu=0, File=-1;
  358.  
  359. 	if(core!=NULL && proc!=NULL)
  360. 		for(cpu=0; cpu < proc->Attrib->ThreadCount; cpu++)
  361. 		{
  362. 			sprintf(pathName, "/dev/cpu/%d/msr", cpu);
  363. 			if((File=open(pathName, O_RDONLY)) != -1)
  364. 			{
  365. 				rbyte=pread(File, &core[cpu].Perf, 8, IA32_PERF_STATUS);
  366. 				rbyte=pread(File, &core[cpu].Therm, 8, IA32_THERM_STATUS);
  367. 				close(File);
  368. 			}
  369. 		}
  370. }
  371.  
  372. void CORE_Free_Info(struct COREINFO *core)
  373. {
  374. 	if(core)
  375. 	{
  376. 		free(core);
  377. 		core=NULL;
  378. 	}
  379. }
  380.  
  381. void CORE_Show_Info(struct COREINFO *core, struct PROCINFO *proc)
  382. {
  383. 	int	cpu=0;
  384.  
  385. 	if(core!=NULL && proc!=NULL)
  386. 	{
  387. 		printf("\n\tCore#\tRatio\tx Clock\t= Frequency\tTJMAX\t- DTS\t= Temperature\n");
  388. 		for(cpu=0; cpu < proc->Attrib->ThreadCount; cpu++)
  389. 			printf("\t%2d\t %2d\tx  %3lld\t= %4lld MHz\t %3d\t- %3d\t=  %3d°C\n", \
  390. 				cpu, \
  391. 				core[cpu].Perf.Ratio, \
  392. 				proc->Attrib->Clock, \
  393. 				core[cpu].Perf.Ratio * proc->Attrib->Clock, \
  394. 				core[cpu].Temp.Target, \
  395. 				core[cpu].Therm.DTS, \
  396. 				core[cpu].Temp.Target - core[cpu].Therm.DTS);
  397. 	}
  398. }
  399.  
  400. void PROC_Show_Info(struct PROCINFO *proc, struct CACHEINFO *cache[])
  401. {
  402. 	const float tension[0B1000]={0.0f, 5.0f, 3.3f, 0.0f, 2.9f, 0.0f, 0.0f, 0.0f};
  403. 	const char *power[2]={"OFF", "ON"};
  404. 	int         ix=0;
  405.  
  406. 	if(proc!=NULL && cache[0]!=NULL && cache[1]!=NULL && cache[2]!=NULL)
  407. 	{
  408. 		printf("\n\t%s\n\tBase clock  @ %lld MHz\n\t%sclocked @ %lld MHz\n", \
  409. 			SMB_Find_String((struct STRUCTINFO*) proc, proc->Attrib->Version), \
  410. 			proc->Attrib->Clock, \
  411. 			llabs(proc->Attrib->CurrentSpeed - proc->Attrib->MaxSpeed) > 20 ? \
  412. 				"Over" : "Factory ", \
  413. 			proc->Attrib->CurrentSpeed);
  414. 		printf("\t%lld/%lld cores enabled, %lld threads detected.\n", \
  415. 			proc->Attrib->CoreEnabled, \
  416. 			proc->Attrib->CoreCount, \
  417. 			proc->Attrib->ThreadCount);
  418. 		printf("\tSocket : %s\n", \
  419. 			SMB_Find_String((struct STRUCTINFO*) proc, proc->Attrib->Socket));
  420. 		printf("\tTension: %.1f V\n\t",
  421. 			proc->Attrib->Voltage.Mode ? proc->Attrib->Voltage.Tension / 10.0f \
  422. 						   : tension[proc->Attrib->Voltage.Tension & 0B0111]);
  423. 		for(ix=0; ix < 3; ix++)
  424. 			printf("%s [%4lld]%s", \
  425. 			SMB_Find_String((struct STRUCTINFO*) cache[ix], cache[ix]->Attrib->Socket), \
  426. 			cache[ix]->Attrib->Installed_Size, ix < 2 ? "     " : "");
  427. 		printf("\n\n\tCPUID.1:EAX=0x%08X          CPUID.1:EDX=0x%08X\n\n", \
  428. 			proc->Attrib->CPUID.EAX, proc->Attrib->CPUID.EDX);
  429. 		printf("\tAdvanced Programmable Interrupt Controller  APIC [%3s]\n", \
  430. 			power[proc->Attrib->CPUID.EDX.APIC]);
  431. 		printf("\tHyper-Threading                                  [%3s]\n", \
  432. 			power[proc->Attrib->CPUID.EDX.HyperThreading]);
  433. 		printf("\tMemory Type Range Registers                 MTRR [%3s]\n", \
  434. 			power[proc->Attrib->CPUID.EDX.MTRR]);
  435. 		printf("\tPage Attribute Table                         PAT [%3s]\n", \
  436. 			power[proc->Attrib->CPUID.EDX.PAT]);
  437. 		printf("\tInstruction set:      MMX [%3s]  SSE [%3s]  SSE2 [%3s]\n", \
  438. 			power[proc->Attrib->CPUID.EDX.MMX], \
  439. 			power[proc->Attrib->CPUID.EDX.SSE], \
  440. 			power[proc->Attrib->CPUID.EDX.SSE2]);
  441. 	}
  442. }
  443.  
  444. void SYS_Show_Info(struct BIOSINFO *bios, \
  445. 		   struct BOARDINFO *board, \
  446. 		   struct MEMARRAY  *memArray, \
  447. 		   struct MEMDEV **memory )
  448. {
  449. 	unsigned long long totalMemSize=0;
  450. 	int                ix=0;
  451.  
  452. 	if(bios!=NULL && board!=NULL && memArray!=NULL && memory!=NULL)
  453. 	{
  454. 	printf("\n\tBoard: %s\n\t |- version %s\n\t |- manufactured by %s\n", \
  455. 		SMB_Find_String((struct STRUCTINFO*) board, board->Attrib->Product), \
  456. 		SMB_Find_String((struct STRUCTINFO*) board, board->Attrib->Version), \
  457. 		SMB_Find_String((struct STRUCTINFO*) board, board->Attrib->Manufacturer));
  458. 	printf("\n\tBIOS: %s\n\t |- version %s\n\t |- released date %s\n\t |- revision %lld.%lld\n", \
  459. 		SMB_Find_String((struct STRUCTINFO*) bios, bios->Attrib->Vendor), \
  460. 		SMB_Find_String((struct STRUCTINFO*) bios, bios->Attrib->Version), \
  461. 		SMB_Find_String((struct STRUCTINFO*) bios, bios->Attrib->Release_Date), \
  462. 		bios->Attrib->Major_Release, bios->Attrib->Minor_Release);
  463. 	printf("\t |- ROM Size: %lld KB at 0x%04X\n",
  464. 		64 * (1 + bios->Attrib->ROM_Size), bios->Attrib->Address);
  465. 	for(ix=0; ix < memArray->Attrib->Number_Devices; ix++)
  466. 		totalMemSize+=memory[ix]->Attrib->Size;
  467. 	printf("\n\tRAM: %lld/%lld MB\n", totalMemSize, memArray->Attrib->Maximum_Capacity/1024);
  468. 	for(ix=0; ix < memArray->Attrib->Number_Devices; ix++)
  469. 		printf("\t |- %s:%s  %lld MB @ %lld MHz\n", \
  470. 			SMB_Find_String((struct STRUCTINFO*) memory[ix], memory[ix]->Attrib->Socket), \
  471. 			SMB_Find_String((struct STRUCTINFO*) memory[ix], memory[ix]->Attrib->Bank), \
  472. 			memory[ix]->Attrib->Size, memory[ix]->Attrib->Speed);
  473. 	}
  474. }
  475.  
  476. int Menu_Getkey(void)
  477. {
  478. 	int key=0, flush=0;
  479.  
  480. 	key=flush=tolower(getchar());
  481.   	while(flush != '\n')
  482. 		flush=getchar();
  483. 	return(key);
  484. }
  485.  
  486.  
  487. int main(int argc, char *argv[])
  488. {
  489. 	int    ix=0, runLevel=0, function=FN_NOOP, command=0;
  490.  
  491. 	struct BIOSINFO  *Bios = BIOS_Read_Info();
  492. 	struct BOARDINFO *Board= BOARD_Read_Info();
  493. 	struct PROCINFO  *Proc = PROC_Read_Info();
  494. 	struct CACHEINFO *Cache[3]={CACHE_Read_Info(0), CACHE_Read_Info(1), CACHE_Read_Info(2)};
  495. 	struct MEMARRAY  *MemArray = MEM_Read_Array();
  496. 	struct MEMDEV    **Memory = MEM_ReadAll_Devices(MemArray);
  497. 	struct COREINFO  *Core=CORE_Read_Info(Proc);
  498.  
  499. 	char menuLabel[LEVELS][CHARS]=
  500. 	{
  501. 		MENU_LABEL_ROOT,
  502. 		MENU_LABEL_HELP,
  503. 		MENU_LABEL_SHOW,
  504. 		MENU_LABEL_DUMP,
  505. 		MENU_LABEL_ATTR,
  506. 		MENU_LABEL_STRG,
  507. 		MENU_LABEL_CACH,
  508. 		MENU_LABEL_CACH,
  509. 		MENU_LABEL_MEMY,
  510. 		MENU_LABEL_MEMY,
  511. 		MENU_LABEL_CMOD
  512. 	};
  513. 	char menuPrompt[LEVELS][CHARS]=
  514. 	{
  515. 		MENU_PROMPT_ROOT,
  516. 		MENU_PROMPT_HELP,
  517. 		MENU_PROMPT_SHOW,
  518. 		MENU_PROMPT_DUMP,
  519. 		MENU_PROMPT_ATTR,
  520. 		MENU_PROMPT_STRG,
  521. 		MENU_PROMPT_CACH,
  522. 		MENU_PROMPT_CACH,
  523. 		MENU_PROMPT_MEMY,
  524. 		MENU_PROMPT_MEMY,
  525. 		MENU_PROMPT_CMOD
  526. 	};
  527. 	struct MENUNAV	levelRoot[]=MENU_LEVEL_ROOT,
  528. 		levelHelp[]=MENU_LEVEL_HELP,
  529. 		levelShow[]=MENU_LEVEL_SHOW,
  530. 		levelDump[]=MENU_LEVEL_DUMP,
  531. 		levelAttr[]=MENU_LEVEL_ATTR,
  532. 		levelStrg[]=MENU_LEVEL_STRG,
  533. 		levelAttH[]=MENU_LEVEL_ATTH,
  534. 		levelStrH[]=MENU_LEVEL_STRH,
  535. 		levelAttY[]=MENU_LEVEL_ATTY,
  536. 		levelStrY[]=MENU_LEVEL_STRY,
  537. 		levelCMod[]=MENU_LEVEL_CMOD;
  538.  
  539. 	struct MENUNAV	*menuNav[LEVELS]=
  540. 	{
  541. 		levelRoot,
  542. 		levelHelp,
  543. 		levelShow,
  544. 		levelDump,
  545. 		levelAttr,
  546. 		levelStrg,
  547. 		levelAttH,
  548. 		levelStrH,
  549. 		levelAttY,
  550. 		levelStrY,
  551. 		levelCMod
  552. 	};
  553.  
  554. 	if(MemArray!=NULL)
  555. 		for(ix=0; ix < MemArray->Attrib->Number_Devices; ix++)
  556. 		{
  557. 			menuPrompt[LV_ATTY][23+ix*6]='[';
  558. 			menuPrompt[LV_ATTY][24+ix*6]='1'+ix;
  559. 			menuPrompt[LV_ATTY][25+ix*6]=']';
  560. 			menuNav[LV_ATTY][3+ix].Command='1'+ix;
  561. 			menuNav[LV_ATTY][3+ix].Function=FN_ATTD+ix;
  562. 			menuPrompt[LV_STRY][23+ix*6]='[';
  563. 			menuPrompt[LV_STRY][24+ix*6]='1'+ix;
  564. 			menuPrompt[LV_STRY][25+ix*6]=']';
  565. 			menuNav[LV_STRY][3+ix].Command='1'+ix;
  566. 			menuNav[LV_STRY][3+ix].Function=FN_STRD+ix;
  567. 		}
  568.  
  569. 	while(function != FN_EXIT)
  570. 	{
  571. 		Menu_Display(runLevel);
  572. 		{
  573. 			command=Menu_Getkey();
  574.  
  575. 			ix=0;
  576. 			while( command != menuNav[runLevel][ix].Command \
  577. 				&& menuNav[runLevel][ix].Command != EOL )
  578. 					ix++ ;
  579.  
  580. 			function =menuNav[runLevel][ix].Function;
  581. 			runLevel=menuNav[runLevel][ix].NewLevel;
  582. 		}
  583. 		switch(function)
  584. 		{
  585. 			case FN_SHWC:	CORE_Update_Info(Core, Proc);
  586. 					CORE_Show_Info(Core, Proc);
  587. 			break;
  588. 			case FN_SHWP:	PROC_Show_Info(Proc, Cache);
  589. 			break;
  590. 			case FN_SHWS:	SYS_Show_Info(Bios, Board, MemArray, Memory);
  591. 			break;
  592. 			case FN_ATTB:	SMB_Dump_Attribs((struct STRUCTINFO*) Bios);
  593. 			break;
  594. 			case FN_ATTM:	SMB_Dump_Attribs((struct STRUCTINFO*) Board);
  595. 			break;
  596. 			case FN_ATTP:	SMB_Dump_Attribs((struct STRUCTINFO*) Proc);
  597. 			break;
  598. 			case FN_ATL1:	SMB_Dump_Attribs((struct STRUCTINFO*) Cache[0]);
  599. 			break;
  600. 			case FN_ATL2:	SMB_Dump_Attribs((struct STRUCTINFO*) Cache[1]);
  601. 			break;
  602. 			case FN_ATL3:	SMB_Dump_Attribs((struct STRUCTINFO*) Cache[2]);
  603. 			break;
  604. 			case FN_ATTY:	SMB_Dump_Attribs((struct STRUCTINFO*) MemArray);
  605. 			break;
  606. 			case FN_ATTD+0:
  607. 			case FN_ATTD+1:
  608. 			case FN_ATTD+2:
  609. 			case FN_ATTD+3:
  610. 			case FN_ATTD+4:
  611. 			case FN_ATTD+5:
  612. 			case FN_ATTD+6:
  613. 			case FN_ATTD+7:	SMB_Dump_Attribs((struct STRUCTINFO*) Memory[function-FN_ATTD]);
  614. 			break;
  615. 			case FN_STRB:	SMB_Dump_Strings((struct STRUCTINFO*) Bios);
  616. 			break;
  617. 			case FN_STRM:	SMB_Dump_Strings((struct STRUCTINFO*) Board);
  618. 			break;
  619. 			case FN_STRP:	SMB_Dump_Strings((struct STRUCTINFO*) Proc);
  620. 			break;
  621. 			case FN_STL1:	SMB_Dump_Strings((struct STRUCTINFO*) Cache[0]);
  622. 			break;
  623. 			case FN_STL2:	SMB_Dump_Strings((struct STRUCTINFO*) Cache[1]);
  624. 			break;
  625. 			case FN_STL3:	SMB_Dump_Strings((struct STRUCTINFO*) Cache[2]);
  626. 			break;
  627. 			case FN_STRY:	SMB_Dump_Strings((struct STRUCTINFO*) MemArray);
  628. 			break;
  629. 			case FN_STRD+0:
  630. 			case FN_STRD+1:
  631. 			case FN_STRD+2:
  632. 			case FN_STRD+3:
  633. 			case FN_STRD+4:
  634. 			case FN_STRD+5:
  635. 			case FN_STRD+6:
  636. 			case FN_STRD+7:	SMB_Dump_Strings((struct STRUCTINFO*) Memory[function-FN_STRD]);
  637. 		}
  638. 	};
  639.  
  640. 	CORE_Free_Info(Core);
  641. 	MEM_FreeAll_Devices(Memory, MemArray);
  642. 	BIOS_Free_Structure((struct STRUCTINFO*) MemArray);
  643. 	BIOS_Free_Structure((struct STRUCTINFO*) Cache[2]);
  644. 	BIOS_Free_Structure((struct STRUCTINFO*) Cache[1]);
  645. 	BIOS_Free_Structure((struct STRUCTINFO*) Cache[0]);
  646. 	BIOS_Free_Structure((struct STRUCTINFO*) Proc);
  647. 	BIOS_Free_Structure((struct STRUCTINFO*) Board);
  648. 	BIOS_Free_Structure((struct STRUCTINFO*) Bios);
  649.  
  650. 	return(function);
  651. }


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