From d0eea3df638a40eb32f0679020f7699595624052 Mon Sep 17 00:00:00 2001 From: Erwan Velu Date: Sun, 22 Feb 2009 23:20:53 +0100 Subject: [PATCH] hdt: Adding CPU mode. cpu> show cpu DMI: Renaming processor to cpu Menu: Displaying number of elements for PCI,DISKS,MEMORY Bump to 0.1.9 --- com32/hdt/Makefile | 2 +- com32/hdt/hdt-cli-cpu.c | 147 ++++++++++++++++++++++++++++++++++++++++++++++++ com32/hdt/hdt-cli.c | 23 ++++++-- com32/hdt/hdt-cli.h | 11 +++- com32/hdt/hdt-common.c | 2 +- com32/hdt/hdt-menu.c | 16 ++++-- com32/hdt/hdt.h | 2 +- 7 files changed, 188 insertions(+), 15 deletions(-) create mode 100644 com32/hdt/hdt-cli-cpu.c diff --git a/com32/hdt/Makefile b/com32/hdt/Makefile index c148737..37f85c6 100644 --- a/com32/hdt/Makefile +++ b/com32/hdt/Makefile @@ -43,7 +43,7 @@ all: hdt.c32 $(LIB) hdt.elf: hdt.o hdt-ata.o hdt-menu.o hdt-menu-pci.o hdt-menu-kernel.o \ hdt-menu-disk.o hdt-menu-dmi.o hdt-menu-processor.o hdt-menu-syslinux.o hdt-menu-about.o \ - hdt-cli.o hdt-common.o hdt-cli-pci.o hdt-cli-dmi.o \ + hdt-cli.o hdt-common.o hdt-cli-pci.o hdt-cli-dmi.o hdt-cli-cpu.o\ $(com32)/modules/cpuid.o $(com32)/modules/dmi.o $(topdir)/menu/libmenu/libmenu.a $(LIB) $(C_LIBS) $(LD) $(LDFLAGS) -o $@ $^ diff --git a/com32/hdt/hdt-cli-cpu.c b/com32/hdt/hdt-cli-cpu.c new file mode 100644 index 0000000..eb86bb5 --- /dev/null +++ b/com32/hdt/hdt-cli-cpu.c @@ -0,0 +1,147 @@ +/* ----------------------------------------------------------------------- * + * + * 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 +#include +#include +#include + +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); + } + +} + + diff --git a/com32/hdt/hdt-cli.c b/com32/hdt/hdt-cli.c index d86c6cb..6560d53 100644 --- a/com32/hdt/hdt-cli.c +++ b/com32/hdt/hdt-cli.c @@ -50,6 +50,15 @@ void set_mode(struct s_cli_mode *cli_mode, cli_mode_t mode, struct s_hardware *h 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); @@ -109,6 +118,10 @@ void start_cli_mode(struct s_hardware *hardware, int argc, char *argv[]) { 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; @@ -119,6 +132,7 @@ void start_cli_mode(struct s_hardware *hardware, int argc, char *argv[]) { 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 */ } } @@ -127,8 +141,9 @@ void start_cli_mode(struct s_hardware *hardware, int argc, char *argv[]) { 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; @@ -139,9 +154,8 @@ switch (cli_mode->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; @@ -153,4 +167,5 @@ switch (cli_mode->mode) { 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); } diff --git a/com32/hdt/hdt-cli.h b/com32/hdt/hdt-cli.h index 5208456..9b1bed1 100644 --- a/com32/hdt/hdt-cli.h +++ b/com32/hdt/hdt-cli.h @@ -39,13 +39,15 @@ #define CLI_PCI "pci" #define CLI_COMMANDS "commands" #define CLI_DMI "dmi" +#define CLI_CPU "cpu" #define CLI_SHOW_LIST "list" typedef enum { EXIT_MODE, HDT_MODE, PCI_MODE, - DMI_MODE + DMI_MODE, + CPU_MODE, } cli_mode_t; struct s_cli_mode { @@ -66,7 +68,7 @@ int do_exit(struct s_cli_mode *cli_mode); #define CLI_DMI_CHASSIS "chassis" #define CLI_DMI_MEMORY "memory" #define CLI_DMI_MEMORY_BANK "bank" -#define CLI_DMI_PROCESSOR "processor" +#define CLI_DMI_PROCESSOR "cpu" #define CLI_DMI_SYSTEM "system" void main_show_dmi(struct s_hardware *hardware,struct s_cli_mode *cli_mode); @@ -87,4 +89,9 @@ void main_show_pci(struct s_hardware *hardware); void handle_pci_commands(char *cli_line, struct s_cli_mode *cli_mode, struct s_hardware *hardware); void pci_show(char *item, struct s_hardware *hardware); void cli_detect_pci(struct s_hardware *hardware); + +//CPU STUFF +void main_show_cpu(struct s_hardware *hardware,struct s_cli_mode *cli_mode); +void handle_cpu_commands(char *cli_line, struct s_cli_mode *cli_mode, struct s_hardware *hardware); +void cpu_show(char *item, struct s_hardware *hardware); #endif diff --git a/com32/hdt/hdt-common.c b/com32/hdt/hdt-common.c index cf5b1ae..19ddbad 100644 --- a/com32/hdt/hdt-common.c +++ b/com32/hdt/hdt-common.c @@ -101,8 +101,8 @@ void detect_pci(struct s_hardware *hardware) { } void cpu_detect(struct s_hardware *hardware) { - hardware->cpu_detection=true; detect_cpu(&hardware->cpu); + hardware->cpu_detection=true; } /* Find the last instance of a particular command line argument diff --git a/com32/hdt/hdt-menu.c b/com32/hdt/hdt-menu.c index 6a8d660..6512900 100644 --- a/com32/hdt/hdt-menu.c +++ b/com32/hdt/hdt-menu.c @@ -120,8 +120,9 @@ void setup_menu(char *version) { /* 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)); @@ -146,7 +147,7 @@ void compute_submenus(struct s_hdt_menu *hdt_menu, struct s_hardware *hardware) } 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; @@ -155,18 +156,21 @@ void compute_main_menu(struct s_hdt_menu *hdt_menu,struct s_hardware *hardware) set_item_options(-1,24); #ifdef WITH_PCI - add_item("PC Devices","PCI Devices Menu",OPT_SUBMENU,NULL,hdt_menu->pci_menu.menu); + snprintf(menu_item, sizeof (menu_item), "PC 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("isks","Disks Menu",OPT_SUBMENU,NULL,hdt_menu->disk_menu.menu); + snprintf(menu_item, sizeof (menu_item), "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("emory","Memory Menu",OPT_SUBMENU,NULL,hdt_menu->memory_menu.menu); + snprintf(menu_item, sizeof (menu_item), "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; } diff --git a/com32/hdt/hdt.h b/com32/hdt/hdt.h index 93b2cbb..5660e21 100644 --- a/com32/hdt/hdt.h +++ b/com32/hdt/hdt.h @@ -32,7 +32,7 @@ #define PRODUCT_NAME "Hardware Detection Tool" #define AUTHOR "Erwan Velu" #define CONTACT "erwan(dot)velu(point)free(dot)fr" -#define VERSION "0.1.8" +#define VERSION "0.1.9" #define ATTR_PACKED __attribute__((packed)) -- 2.7.4