--- /dev/null
+/* ----------------------------------------------------------------------- *
+ *
+ * Copyright 2009 Erwan Velu - All Rights Reserved
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall
+ * be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * -----------------------------------------------------------------------
+*/
+
+#include "hdt-cli.h"
+#include "hdt-common.h"
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+
+void show_cpu(struct s_hardware *hardware) {
+ char buffer[81];
+ char buffer1[81];
+ clear_screen();
+ more_printf("CPU\n");
+ more_printf("Vendor : %s\n",hardware->cpu.vendor);
+ more_printf("Model : %s\n",hardware->cpu.model);
+ more_printf("Vendor ID : %d\n",hardware->cpu.vendor_id);
+ more_printf("Family ID : %d\n",hardware->cpu.family);
+ more_printf("Model ID : %d\n",hardware->cpu.model_id);
+ more_printf("Stepping : %d\n",hardware->cpu.stepping);
+ more_printf("FSB : %d MHz\n",hardware->dmi.processor.external_clock);
+ more_printf("Cur. Speed: %d MHz\n",hardware->dmi.processor.current_speed);
+ more_printf("Max Speed : %d MHz\n",hardware->dmi.processor.max_speed);
+ more_printf("Upgrade : %s\n", hardware->dmi.processor.upgrade);
+ if (hardware->cpu.flags.smp) {
+ more_printf("SMP : yes\n");
+ } else {
+ more_printf("SMP : no\n");
+ }
+ if (hardware->cpu.flags.lm) {
+ more_printf("x86_64 : yes\n");
+ } else {
+ more_printf("x86_64 : no\n");
+ }
+
+ memset(buffer,0,sizeof(buffer));
+ memset(buffer1,0,sizeof(buffer1));
+ if (hardware->cpu.flags.fpu) strcat(buffer1,"fpu ");
+ if (hardware->cpu.flags.vme) strcat(buffer1,"vme ");
+ if (hardware->cpu.flags.de) strcat(buffer1,"de ");
+ if (hardware->cpu.flags.pse) strcat(buffer1,"pse ");
+ if (hardware->cpu.flags.tsc) strcat(buffer1,"tsc ");
+ if (hardware->cpu.flags.msr) strcat(buffer1,"msr ");
+ if (hardware->cpu.flags.pae) strcat(buffer1,"pae ");
+if (hardware->cpu.flags.mce) strcat(buffer1,"mce ");
+ if (hardware->cpu.flags.cx8) strcat(buffer1,"cx8 ");
+ if (hardware->cpu.flags.apic) strcat(buffer1,"apic ");
+ if (hardware->cpu.flags.sep) strcat(buffer1,"sep ");
+ if (hardware->cpu.flags.mtrr) strcat(buffer1,"mtrr ");
+ if (hardware->cpu.flags.pge) strcat(buffer1,"pge ");
+ if (hardware->cpu.flags.mca) strcat(buffer1,"mca ");
+ snprintf(buffer,sizeof buffer,"Flags : %s\n",buffer1);
+ more_printf(buffer);
+
+ memset(buffer,0,sizeof(buffer));
+ memset(buffer1,0,sizeof(buffer1));
+ if (hardware->cpu.flags.cmov) strcat(buffer1,"cmov ");
+ if (hardware->cpu.flags.pat) strcat(buffer1,"pat ");
+ if (hardware->cpu.flags.pse_36) strcat(buffer1,"pse_36 ");
+ if (hardware->cpu.flags.psn) strcat(buffer1,"psn ");
+ if (hardware->cpu.flags.clflsh) strcat(buffer1,"clflsh ");
+ if (hardware->cpu.flags.dts) strcat(buffer1,"dts ");
+ if (hardware->cpu.flags.acpi) strcat(buffer1,"acpi ");
+ if (hardware->cpu.flags.mmx) strcat(buffer1,"mmx ");
+ if (hardware->cpu.flags.sse) strcat(buffer1,"sse ");
+ if (hardware->cpu.flags.sse2) strcat(buffer1,"sse2 ");
+ if (hardware->cpu.flags.ss) strcat(buffer1,"ss ");
+ snprintf(buffer,sizeof buffer,"Flags : %s\n",buffer1);
+ more_printf(buffer);
+
+ memset(buffer,0,sizeof(buffer));
+ memset(buffer1,0,sizeof(buffer1));
+ if (hardware->cpu.flags.htt) strcat(buffer1,"ht ");
+ if (hardware->cpu.flags.acc) strcat(buffer1,"acc ");
+ if (hardware->cpu.flags.syscall) strcat(buffer1,"syscall ");
+ if (hardware->cpu.flags.mp) strcat(buffer1,"mp ");
+ if (hardware->cpu.flags.nx) strcat(buffer1,"nx ");
+ if (hardware->cpu.flags.mmxext) strcat(buffer1,"mmxext ");
+ if (hardware->cpu.flags.lm) strcat(buffer1,"lm ");
+ if (hardware->cpu.flags.nowext) strcat(buffer1,"3dnowext ");
+ if (hardware->cpu.flags.now) strcat(buffer1,"3dnow! ");
+ snprintf(buffer,sizeof buffer,"Flags : %s\n",buffer1);
+ more_printf(buffer);
+}
+
+void cpu_show(char *item, struct s_hardware *hardware) {
+ if ( !strncmp(item, CLI_CPU, sizeof(CLI_CPU) - 1) ) {
+ show_cpu(hardware);
+ return;
+ }
+
+}
+
+void handle_cpu_commands(char *cli_line, struct s_cli_mode *cli_mode, struct s_hardware *hardware) {
+ if ( !strncmp(cli_line, CLI_SHOW, sizeof(CLI_SHOW) - 1) ) {
+ cpu_show(strstr(cli_line,"show")+ sizeof(CLI_SHOW), hardware);
+ return;
+ }
+}
+
+void main_show_cpu(struct s_hardware *hardware,struct s_cli_mode *cli_mode) {
+ if (hardware->cpu_detection==false) {
+ cpu_detect(hardware);
+ }
+ if (hardware->dmi_detection==false) {
+ detect_dmi(hardware);
+ }
+
+ if ((hardware->cpu.flags.lm == false) && (hardware->cpu.flags.smp==false)) {
+ more_printf("CPU: %s %s @ %d MhZ : x86 32bits\n", hardware->cpu.vendor, hardware->cpu.model, hardware->dmi.processor.current_speed);
+ } else if ((hardware->cpu.flags.lm == false) && (hardware->cpu.flags.smp==true)) {
+ more_printf("CPU: %s %s @ %d MhZ : X86 32bits SMP\n", hardware->cpu.vendor, hardware->cpu.model, hardware->dmi.processor.current_speed);
+ } else if ((hardware->cpu.flags.lm == true) && (hardware->cpu.flags.smp==false)) {
+ more_printf("CPU: %s %s @ %d MhZ : X86_64 64bits", hardware->cpu.vendor, hardware->cpu.model, hardware->dmi.processor.current_speed);
+ } else {
+ more_printf("CPU: %s %s @ %d MhZ : X86_64 64bits SMP\n", hardware->cpu.vendor, hardware->cpu.model, hardware->dmi.processor.current_speed);
+ }
+
+}
+
+
cli_detect_pci(hardware);
break;
+ case CPU_MODE:
+ cli_mode->mode=mode;
+ snprintf(cli_mode->prompt,sizeof(cli_mode->prompt),"%s> ", CLI_CPU);
+ if (!hardware->dmi_detection)
+ detect_dmi(hardware);
+ if (!hardware->cpu_detection)
+ cpu_detect(hardware);
+ break;
+
case DMI_MODE:
if (!hardware->dmi_detection)
detect_dmi(hardware);
clear_screen();
continue;
}
+ if ( !strncmp(cli_line, CLI_CPU, sizeof(CLI_CPU) - 1) ) {
+ set_mode(&cli_mode,CPU_MODE,hardware);
+ continue;
+ }
if ( !strncmp(cli_line, CLI_DMI, sizeof(CLI_DMI) - 1) ) {
set_mode(&cli_mode,DMI_MODE,hardware);
continue;
case DMI_MODE: handle_dmi_commands(cli_line,&cli_mode, hardware); break;
case PCI_MODE: handle_pci_commands(cli_line,&cli_mode, hardware); break;
case HDT_MODE: handle_hdt_commands(cli_line,&cli_mode, hardware); break;
+ case CPU_MODE: handle_cpu_commands(cli_line,&cli_mode, hardware); break;
case EXIT_MODE: break; /* should not happend */
}
}
int do_exit(struct s_cli_mode *cli_mode) {
switch (cli_mode->mode) {
case HDT_MODE: return EXIT_MODE;
- case PCI_MODE: return HDT_MODE;
- case DMI_MODE: return HDT_MODE;
+ case PCI_MODE:
+ case DMI_MODE:
+ case CPU_MODE: return HDT_MODE;
case EXIT_MODE: return EXIT_MODE; /* should not happend */
}
return HDT_MODE;
case HDT_MODE:
printf("Available commands are : %s %s %s %s %s %s\n",CLI_CLEAR, CLI_EXIT,CLI_HELP,CLI_SHOW, CLI_PCI, CLI_DMI);
break;
+ case CPU_MODE:
case PCI_MODE:
- printf("Available commands are : %s %s %s %s\n",CLI_CLEAR, CLI_EXIT, CLI_HELP, CLI_SHOW);
- break;
case DMI_MODE:
printf("Available commands are : %s %s %s %s\n",CLI_CLEAR, CLI_EXIT, CLI_HELP, CLI_SHOW);
break;
void main_show(char *item, struct s_hardware *hardware, struct s_cli_mode *cli_mode) {
if (!strncmp(item,CLI_PCI, sizeof (CLI_PCI))) main_show_pci(hardware);
if (!strncmp(item,CLI_DMI, sizeof (CLI_DMI))) main_show_dmi(hardware,cli_mode);
+ if (!strncmp(item,CLI_CPU, sizeof (CLI_CPU))) main_show_cpu(hardware,cli_mode);
}
/* Compute Main' Submenus*/
void compute_submenus(struct s_hdt_menu *hdt_menu, struct s_hardware *hardware) {
- /* Compute this menus if a DMI table exist */
- if (hardware->is_dmi_valid) {
+
+ /* Compute this menus if a DMI table exist */
+ if (hardware->is_dmi_valid) {
if (hardware->dmi.base_board.filled==true) compute_motherboard(&(hdt_menu->mobo_menu),&(hardware->dmi));
if (hardware->dmi.chassis.filled==true) compute_chassis(&(hdt_menu->chassis_menu),&(hardware->dmi));
if (hardware->dmi.system.filled==true) compute_system(&(hdt_menu->system_menu),&(hardware->dmi));
}
void compute_main_menu(struct s_hdt_menu *hdt_menu,struct s_hardware *hardware) {
-
+ char menu_item[64];
/* Let's count the number of menu we have */
hdt_menu->total_menu_count=0;
hdt_menu->main_menu.items_count=0;
set_item_options(-1,24);
#ifdef WITH_PCI
- add_item("PC<I> Devices","PCI Devices Menu",OPT_SUBMENU,NULL,hdt_menu->pci_menu.menu);
+ snprintf(menu_item, sizeof (menu_item), "PC<I> Devices(%2d)\n",hardware->nb_pci_devices);
+ add_item(menu_item,"PCI Devices Menu",OPT_SUBMENU,NULL,hdt_menu->pci_menu.menu);
hdt_menu->main_menu.items_count++;
hdt_menu->total_menu_count+=hdt_menu->pci_menu.items_count;
#endif
if (hdt_menu->disk_menu.items_count>0) {
- add_item("<D>isks","Disks Menu",OPT_SUBMENU,NULL,hdt_menu->disk_menu.menu);
+ snprintf(menu_item, sizeof (menu_item), "<D>isks (%2d)\n",hdt_menu->disk_menu.items_count);
+ add_item(menu_item,"Disks Menu",OPT_SUBMENU,NULL,hdt_menu->disk_menu.menu);
hdt_menu->main_menu.items_count++;
hdt_menu->total_menu_count+=hdt_menu->disk_menu.items_count;
}
if (hdt_menu->memory_menu.items_count>0) {
- add_item("<M>emory","Memory Menu",OPT_SUBMENU,NULL,hdt_menu->memory_menu.menu);
+ snprintf(menu_item, sizeof (menu_item), "<M>emory (%2d)\n",hdt_menu->memory_menu.items_count);
+ add_item(menu_item,"Memory Menu",OPT_SUBMENU,NULL,hdt_menu->memory_menu.menu);
hdt_menu->main_menu.items_count++;
hdt_menu->total_menu_count+=hdt_menu->memory_menu.items_count;
}