hdt: Make CPU module use the new framework
authorPierre-Alexandre Meyer <pierre@mouraf.org>
Sun, 22 Mar 2009 03:52:49 +0000 (20:52 -0700)
committerPierre-Alexandre Meyer <pierre@mouraf.org>
Sun, 22 Mar 2009 03:52:49 +0000 (20:52 -0700)
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 <pierre@mouraf.org>
com32/hdt/hdt-cli-cpu.c
com32/hdt/hdt-cli.c
com32/hdt/hdt-cli.h

index b57c165..6bc8531 100644 (file)
 #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,
+};
index e94aa47..156d7a9 100644 (file)
@@ -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;
index c4f5981..307184d 100644 (file)
@@ -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);