From 2c58232b7d3e5daeef73b08b122b2f5dea21b231 Mon Sep 17 00:00:00 2001 From: Pierre-Alexandre Meyer Date: Sat, 21 Mar 2009 20:52:49 -0700 Subject: [PATCH] hdt: Make CPU module use the new framework Impact: Cleanups in the CPU module. The CPU module now uses the new framework. Misc.: fix indentation in the CPU module. Signed-off-by: Pierre-Alexandre Meyer --- com32/hdt/hdt-cli-cpu.c | 297 +++++++++++++++++++++++------------------------- com32/hdt/hdt-cli.c | 6 +- com32/hdt/hdt-cli.h | 3 +- 3 files changed, 148 insertions(+), 158 deletions(-) diff --git a/com32/hdt/hdt-cli-cpu.c b/com32/hdt/hdt-cli-cpu.c index b57c165..6bc8531 100644 --- a/com32/hdt/hdt-cli-cpu.c +++ b/com32/hdt/hdt-cli-cpu.c @@ -34,163 +34,156 @@ #include "hdt-cli.h" #include "hdt-common.h" -void show_cpu(struct s_hardware *hardware) +void main_show_cpu(int argc __unused, char **argv __unused, + 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); + cpu_detect(hardware); + detect_dmi(hardware); + more_printf("CPU\n"); + more_printf(" Manufacturer : %s \n", hardware->cpu.vendor); + more_printf(" Product : %s \n", hardware->cpu.model); + if ((hardware->cpu.flags.lm == false) + && (hardware->cpu.flags.smp == false)) { + more_printf(" Features : %d MhZ : x86 32bits\n", + hardware->dmi.processor.current_speed); + } else if ((hardware->cpu.flags.lm == false) + && (hardware->cpu.flags.smp == true)) { + more_printf(" Features : %d MhZ : x86 32bits SMP\n", + hardware->dmi.processor.current_speed); + } else if ((hardware->cpu.flags.lm == true) + && (hardware->cpu.flags.smp == false)) { + more_printf(" Features : %d MhZ : x86_64 64bits\n", + hardware->dmi.processor.current_speed); + } else { + more_printf(" Features : %d MhZ : x86_64 64bits SMP\n", + hardware->dmi.processor.current_speed); + } } -static void show_cpu_help() +static void show_cpu(int argc __unused, char **argv __unused, + struct s_hardware *hardware) { - more_printf("Show supports the following commands : %s\n", CLI_CPU); -} + 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"); + } -static void cpu_show(char *item, struct s_hardware *hardware) -{ - if (!strncmp(item, CLI_CPU, sizeof(CLI_CPU) - 1)) { - show_cpu(hardware); - return; - } - show_cpu_help(); -} + 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); -void handle_cpu_commands(char *cli_line, 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; - } -} + 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); -void main_show_cpu(int argc __unused, char **argv __unused, - struct s_hardware *hardware) -{ - cpu_detect(hardware); - detect_dmi(hardware); - more_printf("CPU\n"); - more_printf(" Manufacturer : %s \n", hardware->cpu.vendor); - more_printf(" Product : %s \n", hardware->cpu.model); - if ((hardware->cpu.flags.lm == false) - && (hardware->cpu.flags.smp == false)) { - more_printf(" Features : %d MhZ : x86 32bits\n", - hardware->dmi.processor.current_speed); - } else if ((hardware->cpu.flags.lm == false) - && (hardware->cpu.flags.smp == true)) { - more_printf(" Features : %d MhZ : x86 32bits SMP\n", - hardware->dmi.processor.current_speed); - } else if ((hardware->cpu.flags.lm == true) - && (hardware->cpu.flags.smp == false)) { - more_printf(" Features : %d MhZ : x86_64 64bits\n", - hardware->dmi.processor.current_speed); - } else { - more_printf(" Features : %d MhZ : x86_64 64bits SMP\n", - hardware->dmi.processor.current_speed); - } + 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); } + +struct cli_module_descr cpu_show_modules = { + .modules = NULL, + .nb_modules = 0, + .default_callback = show_cpu, +}; + +struct cli_mode_descr cpu_mode = { + .mode = CPU_MODE, + .name = CLI_CPU, + .default_modules = NULL, + .show_modules = &cpu_show_modules, + .set_modules = NULL, +}; diff --git a/com32/hdt/hdt-cli.c b/com32/hdt/hdt-cli.c index e94aa47..156d7a9 100644 --- a/com32/hdt/hdt-cli.c +++ b/com32/hdt/hdt-cli.c @@ -39,6 +39,7 @@ struct cli_mode_descr *list_modes[] = { &syslinux_mode, &pxe_mode, &kernel_mode, + &cpu_mode, }; /** @@ -357,8 +358,6 @@ static void exec_command(char *line, } dprintf("CLI DEBUG: callback not found!\n", argc); - /* Handle here other keywords such as 'set', ... */ - /* Let's not forget to clean ourselves */ free(command); free(module); @@ -370,9 +369,6 @@ old_cli: case PCI_MODE: handle_pci_commands(line, hardware); break; - case CPU_MODE: - handle_cpu_commands(line, hardware); - break; case VESA_MODE: handle_vesa_commands(line, hardware); break; diff --git a/com32/hdt/hdt-cli.h b/com32/hdt/hdt-cli.h index c4f5981..307184d 100644 --- a/com32/hdt/hdt-cli.h +++ b/com32/hdt/hdt-cli.h @@ -114,13 +114,14 @@ struct cli_callback_descr { }; /* List of implemented modes */ -#define MAX_MODES 5 +#define MAX_MODES 6 struct cli_mode_descr *list_modes[MAX_MODES]; struct cli_mode_descr hdt_mode; struct cli_mode_descr dmi_mode; struct cli_mode_descr syslinux_mode; struct cli_mode_descr pxe_mode; struct cli_mode_descr kernel_mode; +struct cli_mode_descr cpu_mode; /* cli helpers */ void find_cli_mode_descr(cli_mode_t mode, struct cli_mode_descr **mode_found); -- 2.7.4