hdt: Changing structure to allow a cli mode
authorErwan Velu <erwan.velu@free.fr>
Fri, 20 Feb 2009 15:09:30 +0000 (16:09 +0100)
committerH. Peter Anvin <hpa@zytor.com>
Thu, 26 Feb 2009 04:58:42 +0000 (20:58 -0800)
com32/hdt/Makefile
com32/hdt/hdt-ata.h
com32/hdt/hdt-cli.c [new file with mode: 0644]
com32/hdt/hdt-cli.h [new file with mode: 0644]
com32/hdt/hdt-common.c [new file with mode: 0644]
com32/hdt/hdt-common.h [new file with mode: 0644]
com32/hdt/hdt-menu-processor.c
com32/hdt/hdt-menu.c
com32/hdt/hdt-menu.h
com32/hdt/hdt.c

index 917c707..9589e54 100644 (file)
@@ -43,6 +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 \
        $(com32)/modules/cpuid.o $(com32)/modules/dmi.o $(topdir)/menu/libmenu/libmenu.a $(LIB) $(C_LIBS)
        $(LD) $(LDFLAGS) -o $@ $^
 
index 61024c7..7236c54 100644 (file)
@@ -30,6 +30,7 @@
 #define DEFINE_HDT_ATA_H
 
 #include "hdt.h"
+#include <com32io.h>
 
 struct ata_identify_device {
   unsigned short words000_009[10];
diff --git a/com32/hdt/hdt-cli.c b/com32/hdt/hdt-cli.c
new file mode 100644 (file)
index 0000000..53c4743
--- /dev/null
@@ -0,0 +1,59 @@
+/* ----------------------------------------------------------------------- *
+ *
+ *   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 <stdlib.h>
+#include <string.h>
+
+/* Code that manage the cli mode */
+void start_cli_mode(int argc, char *argv[]) {
+ char cli_line[256];
+ struct s_hardware hardware;
+
+  /* Cleaning structures */
+ init_hardware(&hardware);
+
+ printf("Entering CLI mode\n");
+ for (;;) {
+  memset(cli_line,0,sizeof cli_line);
+  printf("hdt:");
+  fgets(cli_line, sizeof cli_line, stdin);
+    /* We use sizeof BLAH - 2 to remove the return char */
+    if ( !strncmp(cli_line, CLI_EXIT, sizeof CLI_EXIT - 2 ) )
+                  break;
+    if ( !strncmp(cli_line, CLI_HELP, sizeof CLI_HELP - 2) )
+                  show_cli_help();
+ }
+}
+
+
+void show_cli_help() {
+ printf("Available commands are : %s %s\n",CLI_EXIT,CLI_HELP);
+}
+
diff --git a/com32/hdt/hdt-cli.h b/com32/hdt/hdt-cli.h
new file mode 100644 (file)
index 0000000..e348c9b
--- /dev/null
@@ -0,0 +1,38 @@
+/* ----------------------------------------------------------------------- *
+ *
+ *   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.
+ *
+ * -----------------------------------------------------------------------
+*/
+
+#ifndef DEFINE_HDT_CLI_H
+#define DEFINE_HDT_CLI_H
+#include <stdio.h>
+
+#define CLI_EXIT "exit"
+#define CLI_HELP "help"
+
+void show_cli_help();
+void start_cli_mode(int argc, char *argv[]);
+#endif
diff --git a/com32/hdt/hdt-common.c b/com32/hdt/hdt-common.c
new file mode 100644 (file)
index 0000000..7006412
--- /dev/null
@@ -0,0 +1,82 @@
+/* ----------------------------------------------------------------------- *
+ *
+ *   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-common.h"
+#include <stdlib.h>
+#include <string.h>
+
+void init_hardware(struct s_hardware *hardware) {
+  hardware->nb_pci_devices=0;
+  hardware->is_dmi_valid=false;
+  hardware->pci_domain=NULL;
+
+  /* Cleaning structures */
+  memset(&(hardware->disk_info),0,sizeof (struct diskinfo));
+  memset(&(hardware->dmi),0,sizeof (s_dmi));
+  memset(&(hardware->cpu),0,sizeof (s_cpu));
+}
+
+/* Detecting if a DMI table exist
+ * if yes, let's parse it */
+int detect_dmi(struct s_hardware *hardware) {
+  if (dmi_iterate(&(hardware->dmi)) == -ENODMITABLE ) {
+             printf("No DMI Structure found\n");
+            hardware->is_dmi_valid=false;
+             return -ENODMITABLE;
+  }
+
+  parse_dmitable(&(hardware->dmi));
+  hardware->is_dmi_valid=true;
+ return 0;
+}
+
+/* Try to detects disk from port 0x80 to 0xff*/
+void detect_disks(struct diskinfo *disk_info) {
+ for (int drive = 0x80; drive < 0xff; drive++) {
+    if (get_disk_params(drive,disk_info) != 0)
+          continue;
+    struct diskinfo d=disk_info[drive];
+    printf("  DISK 0x%X: %s : %s %s: sectors=%d, s/t=%d head=%d : EDD=%s\n",drive,d.aid.model,d.host_bus_type,d.interface_type, d.sectors, d.sectors_per_track,d.heads,d.edd_version);
+ }
+}
+
+/* Find the last instance of a particular command line argument
+   (which should include the final =; do not use for boolean arguments) */
+char *find_argument(char **argv, const char *argument)
+{
+  int la = strlen(argument);
+  char **arg;
+  char *ptr = NULL;
+
+  for (arg = argv; *arg; arg++) {
+    if (!memcmp(*arg, argument, la))
+      ptr = *arg + la;
+  }
+
+  return ptr;
+}
diff --git a/com32/hdt/hdt-common.h b/com32/hdt/hdt-common.h
new file mode 100644 (file)
index 0000000..4a78fb9
--- /dev/null
@@ -0,0 +1,50 @@
+/* ----------------------------------------------------------------------- *
+ *
+ *   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.
+ *
+ * -----------------------------------------------------------------------
+*/
+
+#ifndef DEFINE_HDT_COMMON_H
+#define DEFINE_HDT_COMMON_H
+#include <stdio.h>
+#include "sys/pci.h"
+#include "cpuid.h"
+#include "dmi/dmi.h"
+#include "hdt-ata.h"
+
+struct s_hardware {
+  s_dmi dmi; /* DMI table */
+  s_cpu cpu; /* CPU information */
+  struct pci_domain *pci_domain; /* PCI Devices */
+  struct diskinfo disk_info[256];     /* Disk Information*/
+  int nb_pci_devices;
+  bool is_dmi_valid;
+};
+
+char *find_argument(char **argv, const char *argument);
+int detect_dmi(struct s_hardware *hardware);
+void detect_disks(struct diskinfo *disk_info);
+void init_hardware(struct s_hardware *hardware);
+#endif
index 4913771..d0d7dd7 100644 (file)
@@ -29,7 +29,7 @@
 #include "hdt-menu.h"
 
 /* Compute Processor menu */
-void compute_processor(struct s_my_menu *menu,s_cpu *cpu, s_dmi *dmi) {
+void compute_processor(struct s_my_menu *menu,struct s_hardware *hardware) {
   char buffer[SUBMENULEN+1];
   char buffer1[SUBMENULEN+1];
   char statbuffer[STATLEN+1];
@@ -38,59 +38,59 @@ void compute_processor(struct s_my_menu *menu,s_cpu *cpu, s_dmi *dmi) {
   menu->items_count=0;
   set_menu_pos(SUBMENU_Y,SUBMENU_X);
 
-  snprintf(buffer,sizeof buffer,"Vendor    : %s",cpu->vendor);
-  snprintf(statbuffer,sizeof statbuffer,"Vendor: %s",cpu->vendor);
+  snprintf(buffer,sizeof buffer,"Vendor    : %s",hardware->cpu.vendor);
+  snprintf(statbuffer,sizeof statbuffer,"Vendor: %s",hardware->cpu.vendor);
   add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0);
   menu->items_count++;
 
-  snprintf(buffer,sizeof buffer,"Model     : %s",cpu->model);
-  snprintf(statbuffer,sizeof statbuffer,"Model: %s",cpu->model);
+  snprintf(buffer,sizeof buffer,"Model     : %s",hardware->cpu.model);
+  snprintf(statbuffer,sizeof statbuffer,"Model: %s",hardware->cpu.model);
   add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0);
   menu->items_count++;
 
-  snprintf(buffer,sizeof buffer,"Vendor ID : %d",cpu->vendor_id);
-  snprintf(statbuffer,sizeof statbuffer,"Vendor ID: %d",cpu->vendor_id);
+  snprintf(buffer,sizeof buffer,"Vendor ID : %d",hardware->cpu.vendor_id);
+  snprintf(statbuffer,sizeof statbuffer,"Vendor ID: %d",hardware->cpu.vendor_id);
   add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0);
   menu->items_count++;
 
-  snprintf(buffer,sizeof buffer,"Family ID : %d",cpu->family);
-  snprintf(statbuffer,sizeof statbuffer,"Family ID: %d",cpu->family);
+  snprintf(buffer,sizeof buffer,"Family ID : %d",hardware->cpu.family);
+  snprintf(statbuffer,sizeof statbuffer,"Family ID: %d",hardware->cpu.family);
   add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0);
   menu->items_count++;
 
-  snprintf(buffer,sizeof buffer,"Model  ID : %d",cpu->model_id);
-  snprintf(statbuffer,sizeof statbuffer,"Model  ID: %d",cpu->model_id);
+  snprintf(buffer,sizeof buffer,"Model  ID : %d",hardware->cpu.model_id);
+  snprintf(statbuffer,sizeof statbuffer,"Model  ID: %d",hardware->cpu.model_id);
   add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0);
   menu->items_count++;
 
-  snprintf(buffer,sizeof buffer,"Stepping  : %d",cpu->stepping);
-  snprintf(statbuffer,sizeof statbuffer,"Stepping: %d",cpu->stepping);
+  snprintf(buffer,sizeof buffer,"Stepping  : %d",hardware->cpu.stepping);
+  snprintf(statbuffer,sizeof statbuffer,"Stepping: %d",hardware->cpu.stepping);
   add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0);
   menu->items_count++;
 
-  if (is_dmi_valid) {
-   snprintf(buffer,sizeof buffer,"FSB       : %d",dmi->processor.external_clock);
-   snprintf(statbuffer,sizeof statbuffer,"Front Side Bus (MHz): %d",dmi->processor.external_clock);
+  if (hardware->is_dmi_valid) {
+   snprintf(buffer,sizeof buffer,"FSB       : %d",hardware->dmi.processor.external_clock);
+   snprintf(statbuffer,sizeof statbuffer,"Front Side Bus (MHz): %d",hardware->dmi.processor.external_clock);
    add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0);
    menu->items_count++;
 
-   snprintf(buffer,sizeof buffer,"Cur. Speed: %d",dmi->processor.current_speed);
-   snprintf(statbuffer,sizeof statbuffer,"Current Speed (MHz): %d",dmi->processor.current_speed);
+   snprintf(buffer,sizeof buffer,"Cur. Speed: %d",hardware->dmi.processor.current_speed);
+   snprintf(statbuffer,sizeof statbuffer,"Current Speed (MHz): %d",hardware->dmi.processor.current_speed);
    add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0);
    menu->items_count++;
 
-   snprintf(buffer,sizeof buffer,"Max Speed : %d",dmi->processor.max_speed);
-   snprintf(statbuffer,sizeof statbuffer,"Max Speed (MHz): %d",dmi->processor.max_speed);
+   snprintf(buffer,sizeof buffer,"Max Speed : %d",hardware->dmi.processor.max_speed);
+   snprintf(statbuffer,sizeof statbuffer,"Max Speed (MHz): %d",hardware->dmi.processor.max_speed);
    add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0);
    menu->items_count++;
 
-   snprintf(buffer,sizeof buffer,"Upgrade   : %s",dmi->processor.upgrade);
-   snprintf(statbuffer,sizeof statbuffer,"Upgrade: %s",dmi->processor.upgrade);
+   snprintf(buffer,sizeof buffer,"Upgrade   : %s", hardware->dmi.processor.upgrade);
+   snprintf(statbuffer,sizeof statbuffer,"Upgrade: %s",hardware->dmi.processor.upgrade);
    add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0);
    menu->items_count++;
   }
 
-  if (cpu->flags.smp) {
+  if (hardware->cpu.flags.smp) {
           snprintf(buffer,sizeof buffer,"SMP       : Yes");
           snprintf(statbuffer,sizeof statbuffer,"SMP: Yes");
   }
@@ -101,7 +101,7 @@ void compute_processor(struct s_my_menu *menu,s_cpu *cpu, s_dmi *dmi) {
   add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0);
   menu->items_count++;
 
-  if (cpu->flags.lm) {
+  if (hardware->cpu.flags.lm) {
           snprintf(buffer,sizeof buffer,"x86_64    : Yes");
           snprintf(statbuffer,sizeof statbuffer,"x86_64 compatible processor: Yes");
   }
@@ -113,70 +113,70 @@ void compute_processor(struct s_my_menu *menu,s_cpu *cpu, s_dmi *dmi) {
   menu->items_count++;
 
   buffer1[0]='\0';
-  if (cpu->flags.fpu) strcat(buffer1,"fpu ");
-  if (cpu->flags.vme) strcat(buffer1,"vme ");
-  if (cpu->flags.de)  strcat(buffer1,"de ");
-  if (cpu->flags.pse) strcat(buffer1,"pse ");
-  if (cpu->flags.tsc) strcat(buffer1,"tsc ");
-  if (cpu->flags.msr) strcat(buffer1,"msr ");
-  if (cpu->flags.pae) strcat(buffer1,"pae ");
+  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 ");
   snprintf(buffer,sizeof buffer,"Flags     : %s",buffer1);
   snprintf(statbuffer,sizeof statbuffer,"Flags: %s",buffer1);
   add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0);
   menu->items_count++;
 
   buffer1[0]='\0';
-  if (cpu->flags.mce) strcat(buffer1,"mce ");
-  if (cpu->flags.cx8) strcat(buffer1,"cx8 ");
-  if (cpu->flags.apic) strcat(buffer1,"apic ");
-  if (cpu->flags.sep) strcat(buffer1,"sep ");
-  if (cpu->flags.mtrr) strcat(buffer1,"mtrr ");
-  if (cpu->flags.pge) strcat(buffer1,"pge ");
-  if (cpu->flags.mca) strcat(buffer1,"mca ");
+  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",buffer1);
   snprintf(statbuffer,sizeof statbuffer,"Flags: %s",buffer1);
   add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0);
   menu->items_count++;
 
   buffer1[0]='\0';
-  if (cpu->flags.cmov) strcat(buffer1,"cmov ");
-  if (cpu->flags.pat)  strcat(buffer1,"pat ");
-  if (cpu->flags.pse_36) strcat(buffer1,"pse_36 ");
-  if (cpu->flags.psn)  strcat(buffer1,"psn ");
-  if (cpu->flags.clflsh) strcat(buffer1,"clflsh ");
+  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 ");
   snprintf(buffer,sizeof buffer,"Flags     : %s",buffer1);
   snprintf(statbuffer,sizeof statbuffer,"Flags: %s",buffer1);
   add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0);
   menu->items_count++;
 
   buffer1[0]='\0';
-  if (cpu->flags.dts)  strcat(buffer1,"dts ");
-  if (cpu->flags.acpi) strcat(buffer1,"acpi ");
-  if (cpu->flags.mmx)  strcat(buffer1,"mmx ");
-  if (cpu->flags.sse)  strcat(buffer1,"sse ");
+  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 ");
   snprintf(buffer,sizeof buffer,"Flags     : %s",buffer1);
   snprintf(statbuffer,sizeof statbuffer,"Flags: %s",buffer1);
   add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0);
   menu->items_count++;
 
   buffer1[0]='\0';
-  if (cpu->flags.sse2) strcat(buffer1,"sse2 ");
-  if (cpu->flags.ss)   strcat(buffer1,"ss ");
-  if (cpu->flags.htt)  strcat(buffer1,"ht ");
-  if (cpu->flags.acc)  strcat(buffer1,"acc ");
-  if (cpu->flags.syscall) strcat(buffer1,"syscall ");
-  if (cpu->flags.mp)   strcat(buffer1,"mp ");
+  if (hardware->cpu.flags.sse2) strcat(buffer1,"sse2 ");
+  if (hardware->cpu.flags.ss)   strcat(buffer1,"ss ");
+  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 ");
   snprintf(buffer,sizeof buffer,"Flags     : %s",buffer1);
   snprintf(statbuffer,sizeof statbuffer,"Flags: %s",buffer1);
   add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0);
   menu->items_count++;
 
   buffer1[0]='\0';
-  if (cpu->flags.nx)    strcat(buffer1,"nx ");
-  if (cpu->flags.mmxext) strcat(buffer1,"mmxext ");
-  if (cpu->flags.lm)     strcat(buffer1,"lm ");
-  if (cpu->flags.nowext) strcat(buffer1,"3dnowext ");
-  if (cpu->flags.now)    strcat(buffer1,"3dnow! ");
+  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",buffer1);
   snprintf(statbuffer,sizeof statbuffer,"Flags: %s",buffer1);
   add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0);
index 1e01e2d..662fe2c 100644 (file)
 
 #include "hdt-menu.h"
 
+
+
+int start_menu_mode(char *version_string) {
+  struct s_hdt_menu hdt_menu;
+  struct s_hardware hardware;
+
+  /* Cleaning structures */
+  init_hardware(&hardware);
+  memset(&hdt_menu,0,sizeof (hdt_menu));
+
+  /* Detect every kind of hardware */
+  detect_hardware(&hardware);
+
+  /* Setup the menu system*/
+  setup_menu(version_string);
+
+  /* Compute all sub menus */
+  compute_submenus(&hdt_menu, &hardware);
+
+  /* Compute main menu */
+  compute_main_menu(&hdt_menu,&hardware);
+
+#ifdef WITH_MENU_DISPLAY
+  t_menuitem * curr;
+  char cmd[160];
+
+  printf("Starting Menu (%d menus)\n",hdt_menu.total_menu_count);
+  curr=showmenus(hdt_menu.main_menu.menu);
+  /* When we exit the menu, do we have something to do */
+  if (curr) {
+        /* When want to execute something */
+        if (curr->action == OPT_RUN)
+        {
+            strcpy(cmd,curr->data);
+
+            /* Use specific syslinux call if needed */
+            if (issyslinux())
+               runsyslinuxcmd(cmd);
+            else csprint(cmd,0x07);
+            return 1; // Should not happen when run from SYSLINUX
+        }
+  }
+#endif
+  return 0;
+}
+
 /* In the menu system, what to do on keyboard timeout */
 TIMEOUTCODE ontimeout()
 {
@@ -57,3 +103,132 @@ void keys_handler(t_menusystem *ms, t_menuitem *mi,unsigned int scancode)
    }
 }
 
+/* Setup the Menu system*/
+void setup_menu(char *version) {
+   /* Creating the menu */
+  init_menusystem(version);
+  set_window_size(0,0,24,80);
+
+ // Register the menusystem handler
+ // reg_handler(HDLR_SCREEN,&msys_handler);
+  reg_handler(HDLR_KEYS,&keys_handler);
+
+  // Register the ontimeout handler, with a time out of 10 seconds
+  reg_ontimeout(ontimeout,1000,0);
+}
+
+/* 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_motherboard(&(hdt_menu->mobo_menu),&(hardware->dmi));
+    compute_chassis(&(hdt_menu->chassis_menu),&(hardware->dmi));
+    compute_system(&(hdt_menu->system_menu),&(hardware->dmi));
+    compute_memory(hdt_menu,&(hardware->dmi));
+    compute_bios(&(hdt_menu->bios_menu),&(hardware->dmi));
+    compute_battery(&(hdt_menu->battery_menu),&(hardware->dmi));
+  }
+
+  compute_processor(&(hdt_menu->cpu_menu),hardware);
+  compute_disks(hdt_menu,hardware->disk_info);
+#ifdef WITH_PCI
+  compute_PCI(hdt_menu,&(hardware->pci_domain));
+  compute_kernel(&(hdt_menu->kernel_menu),&(hardware->pci_domain));
+#endif
+  compute_syslinuxmenu(&(hdt_menu->syslinux_menu));
+  compute_aboutmenu(&(hdt_menu->about_menu));
+}
+
+void compute_main_menu(struct s_hdt_menu *hdt_menu,struct s_hardware *hardware) {
+
+  /* Let's count the number of menu we have */
+  hdt_menu->total_menu_count=0;
+  hdt_menu->main_menu.items_count=0;
+
+  hdt_menu->main_menu.menu = add_menu(" Main Menu ",-1);
+  set_item_options(-1,24);
+
+#ifdef WITH_PCI
+  add_item("PCI <D>evices","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);
+     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 Modules","Memory Modules 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;
+  }
+  add_item("<P>rocessor","Main Processor Menu",OPT_SUBMENU,NULL,hdt_menu->cpu_menu.menu);
+  hdt_menu->main_menu.items_count++;
+
+if (hardware->is_dmi_valid) {
+  add_item("M<o>therboard","Motherboard Menu",OPT_SUBMENU,NULL,hdt_menu->mobo_menu.menu);
+  hdt_menu->main_menu.items_count++;
+  add_item("<B>ios","Bios Menu",OPT_SUBMENU,NULL,hdt_menu->bios_menu.menu);
+  hdt_menu->main_menu.items_count++;
+  add_item("<C>hassis","Chassis Menu",OPT_SUBMENU,NULL,hdt_menu->chassis_menu.menu);
+  hdt_menu->main_menu.items_count++;
+  add_item("<S>ystem","System Menu",OPT_SUBMENU,NULL,hdt_menu->system_menu.menu);
+  hdt_menu->main_menu.items_count++;
+  add_item("Ba<t>tery","Battery Menu",OPT_SUBMENU,NULL,hdt_menu->battery_menu.menu);
+  hdt_menu->main_menu.items_count++;
+}
+  add_item("","",OPT_SEP,"",0);
+#ifdef WITH_PCI
+  add_item("<K>ernel Modules","Kernel Modules Menu",OPT_SUBMENU,NULL,hdt_menu->kernel_menu.menu);
+  hdt_menu->main_menu.items_count++;
+#endif
+  add_item("<S>yslinux","Syslinux Information Menu",OPT_SUBMENU,NULL,hdt_menu->syslinux_menu.menu);
+  hdt_menu->main_menu.items_count++;
+  add_item("<A>bout","About Menu",OPT_SUBMENU,NULL,hdt_menu->about_menu.menu);
+  hdt_menu->main_menu.items_count++;
+
+  hdt_menu->total_menu_count+=hdt_menu->main_menu.items_count;
+}
+
+void detect_hardware(struct s_hardware *hardware) {
+  printf("CPU: Detecting\n");
+  detect_cpu(&(hardware->cpu));
+
+  printf("DISKS: Detecting\n");
+  detect_disks(hardware->disk_info);
+
+  printf("DMI: Detecting Table\n");
+  if (detect_dmi(&(hardware->dmi)) == -ENODMITABLE ) {
+   printf("DMI: ERROR ! Table not found ! \n");
+   printf("DMI: Many hardware components will not be detected ! \n");
+  } else {
+   printf("DMI: Table found ! (version %d.%d)\n",hardware->dmi.dmitable.major_version,hardware->dmi.dmitable.minor_version);
+  }
+#ifdef WITH_PCI
+  printf("PCI: Detecting Devices\n");
+  /* Scanning to detect pci buses and devices */
+  hardware->pci_domain = pci_scan();
+
+  struct pci_device *pci_device;
+  for_each_pci_func(pci_device, hardware->pci_domain) {
+          hardware->nb_pci_devices++;
+  }
+
+  printf("PCI: %d Devices Found\n",hardware->nb_pci_devices);
+
+  printf("PCI: Resolving names\n");
+  /* Assigning product & vendor name for each device*/
+  get_name_from_pci_ids(hardware->pci_domain);
+
+  printf("PCI: Resolving class names\n");
+  /* Assigning class name for each device*/
+  pci_ids=get_class_name_from_pci_ids(hardware->pci_domain);
+
+
+  printf("PCI: Resolving module names\n");
+  /* Detecting which kernel module should match each device */
+  modules_pcimap=get_module_name_from_pci_ids(hardware->pci_domain);
+#endif
+}
index 7a38ae8..f965282 100644 (file)
 #define DEFINE_HDT_MENU_H
 #include <stdio.h>
 #include "menu.h"
-#include "cpuid.h"
+#include "help.h"
+//#include "cpuid.h"
 #include "sys/pci.h"
+#include "hdt-common.h"
 #include "dmi/dmi.h"
 #include "hdt-ata.h"
 
@@ -97,12 +99,17 @@ void compute_memory(struct s_hdt_menu *menu, s_dmi *dmi);
 void compute_memory_module(struct s_my_menu *menu, s_dmi *dmi, int slot_number);
 
 // Processor Stuff
-static bool is_dmi_valid=false;
-void compute_processor(struct s_my_menu *menu,s_cpu *cpu, s_dmi *dmi);
+void compute_processor(struct s_my_menu *menu,struct s_hardware *hardware);
 
 // Syslinux stuff
 void compute_syslinuxmenu(struct s_my_menu *menu);
 
 // About menu
 void compute_aboutmenu(struct s_my_menu *menu);
+
+int start_menu_mode(char *version_string);
+void setup_menu(char *version);
+void compute_main_menu(struct s_hdt_menu *hdt_menu, struct s_hardware *hardware);
+void compute_submenus(struct s_hdt_menu *hdt_menu,struct s_hardware *hardware);
+void detect_hardware(struct s_hardware *hardware);
 #endif
index 15b71c6..611cddc 100644 (file)
  * An Hardware Detection Tool
  */
 
-#include <string.h>
 #include <stdio.h>
-#include <stdlib.h>
 #include <console.h>
-#include "com32io.h"
-#include "menu.h"
-#include "help.h"
-#include "passwords.h"
-#include "dmi/dmi.h"
-#include "sys/pci.h"
 #include "hdt.h"
 #include "hdt-menu.h"
-#include "hdt-ata.h"
+#include "hdt-cli.h"
+#include "hdt-common.h"
 
-int nb_pci_devices=0;
 
-/* Detecting if a DMI table exist
- * if yes, let's parse it */
-int detect_dmi(s_dmi *dmi) {
-  if (dmi_iterate(dmi) == -ENODMITABLE ) {
-             printf("No DMI Structure found\n");
-             return -ENODMITABLE;
-  }
-
-  parse_dmitable(dmi);
- return 0;
-}
-
-/* Try to detects disk from port 0x80 to 0xff*/
-void detect_disks(struct diskinfo *disk_info) {
- for (int drive = 0x80; drive < 0xff; drive++) {
-    if (get_disk_params(drive,disk_info) != 0)
-          continue;
-    struct diskinfo d=disk_info[drive];
-    printf("  DISK 0x%X: %s : %s %s: sectors=%d, s/t=%d head=%d : EDD=%s\n",drive,d.aid.model,d.host_bus_type,d.interface_type, d.sectors, d.sectors_per_track,d.heads,d.edd_version);
- }
-}
+int main(int argc, char *argv[])
+{
+  char version_string[256];
+  char *arg, **argp;
+  argp = argv+1;
 
-/* Setup our environement */
-void setup_env() {
-  char version[255];
+  snprintf(version_string,sizeof version_string,"%s %s by %s",PRODUCT_NAME,VERSION,AUTHOR);
 
   /* Opening the syslinux console */
   openconsole(&dev_stdcon_r, &dev_stdcon_w);
 
-  sprintf(version,"%s %s by %s",PRODUCT_NAME,VERSION,AUTHOR);
-  printf("%s\n",version);
-
-  /* Creating the menu */
-  init_menusystem(version);
-  set_window_size(0,0,24,80); // Leave some space around
-
- // Register the menusystem handler
- // reg_handler(HDLR_SCREEN,&msys_handler);
-  reg_handler(HDLR_KEYS,&keys_handler);
-
-  // Register the ontimeout handler, with a time out of 10 seconds
-  reg_ontimeout(ontimeout,1000,0);
-}
-
-/* Detect the hardware stuff */
-void detect_hardware(s_dmi *dmi, s_cpu *cpu, struct pci_domain **pci_domain, struct diskinfo *disk_info) {
-  printf("CPU: Detecting\n");
-  detect_cpu(cpu);
-
-  printf("DISKS: Detecting\n");
-  detect_disks(disk_info);
-
-  printf("DMI: Detecting Table\n");
-  if (detect_dmi(dmi) == -ENODMITABLE ) {
-   is_dmi_valid=false;
-   printf("DMI: ERROR ! Table not found ! \n");
-   printf("DMI: Many hardware components will not be detected ! \n");
-  } else {
-   is_dmi_valid=true;
-   printf("DMI: Table found ! (version %d.%d)\n",dmi->dmitable.major_version,dmi->dmitable.minor_version);
-  }
-
-#ifdef WITH_PCI
-  printf("PCI: Detecting Devices\n");
-  /* Scanning to detect pci buses and devices */
-  *pci_domain = pci_scan();
-
-  struct pci_device *pci_device;
-  for_each_pci_func(pci_device, *pci_domain) {
-         nb_pci_devices++;
-  }
-
-  printf("PCI: %d Devices Found\n",nb_pci_devices);
-
-  printf("PCI: Resolving names\n");
-  /* Assigning product & vendor name for each device*/
-  get_name_from_pci_ids(*pci_domain);
-
-  printf("PCI: Resolving class names\n");
-  /* Assigning class name for each device*/
-  pci_ids=get_class_name_from_pci_ids(*pci_domain);
-
-
-  printf("PCI: Resolving module names\n");
-  /* Detecting which kernel module should match each device */
-  modules_pcimap=get_module_name_from_pci_ids(*pci_domain);
-#endif
-}
-
-/* Compute Main' Submenus*/
-void compute_submenus(struct s_hdt_menu *hdt_menu, s_dmi *dmi, s_cpu *cpu, struct pci_domain **pci_domain, struct diskinfo *disk_info) {
- /* Compute this menus if a DMI table exist */
-  if (is_dmi_valid) {
-    compute_motherboard(&(hdt_menu->mobo_menu),dmi);
-    compute_chassis(&(hdt_menu->chassis_menu),dmi);
-    compute_system(&(hdt_menu->system_menu),dmi);
-    compute_memory(hdt_menu,dmi);
-    compute_bios(&(hdt_menu->bios_menu),dmi);
-    compute_battery(&(hdt_menu->battery_menu),dmi);
-  }
-
-  compute_processor(&(hdt_menu->cpu_menu),cpu,dmi);
-  compute_disks(hdt_menu,disk_info);
-#ifdef WITH_PCI
-  compute_PCI(hdt_menu,pci_domain);
-  compute_kernel(&(hdt_menu->kernel_menu),pci_domain);
-#endif
-  compute_syslinuxmenu(&(hdt_menu->syslinux_menu));
-  compute_aboutmenu(&(hdt_menu->about_menu));
-}
-
-/* Compute Main Menu*/
-void compute_main_menu(struct s_hdt_menu *hdt_menu) {
-
-  /* Let's count the number of menu we have */
-  hdt_menu->total_menu_count=0;
-  hdt_menu->main_menu.items_count=0;
-
-  hdt_menu->main_menu.menu = add_menu(" Main Menu ",-1);
-  set_item_options(-1,24);
-
-#ifdef WITH_PCI
-  add_item("PCI <D>evices","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);
-     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 Modules","Memory Modules 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;
-  }
-  add_item("<P>rocessor","Main Processor Menu",OPT_SUBMENU,NULL,hdt_menu->cpu_menu.menu);
-  hdt_menu->main_menu.items_count++;
-
-if (is_dmi_valid) {
-  add_item("M<o>therboard","Motherboard Menu",OPT_SUBMENU,NULL,hdt_menu->mobo_menu.menu);
-  hdt_menu->main_menu.items_count++;
-  add_item("<B>ios","Bios Menu",OPT_SUBMENU,NULL,hdt_menu->bios_menu.menu);
-  hdt_menu->main_menu.items_count++;
-  add_item("<C>hassis","Chassis Menu",OPT_SUBMENU,NULL,hdt_menu->chassis_menu.menu);
-  hdt_menu->main_menu.items_count++;
-  add_item("<S>ystem","System Menu",OPT_SUBMENU,NULL,hdt_menu->system_menu.menu);
-  hdt_menu->main_menu.items_count++;
-  add_item("Ba<t>tery","Battery Menu",OPT_SUBMENU,NULL,hdt_menu->battery_menu.menu);
-  hdt_menu->main_menu.items_count++;
-}
-  add_item("","",OPT_SEP,"",0);
-#ifdef WITH_PCI
-  add_item("<K>ernel Modules","Kernel Modules Menu",OPT_SUBMENU,NULL,hdt_menu->kernel_menu.menu);
-  hdt_menu->main_menu.items_count++;
-#endif
-  add_item("<S>yslinux","Syslinux Information Menu",OPT_SUBMENU,NULL,hdt_menu->syslinux_menu.menu);
-  hdt_menu->main_menu.items_count++;
-  add_item("<A>bout","About Menu",OPT_SUBMENU,NULL,hdt_menu->about_menu.menu);
-  hdt_menu->main_menu.items_count++;
-
-  hdt_menu->total_menu_count+=hdt_menu->main_menu.items_count;
-}
-
-int main(void)
-{
-  struct s_hdt_menu hdt_menu;
-  s_dmi dmi; /* DMI table */
-  s_cpu cpu; /* CPU information */
-  struct pci_domain *pci_domain=NULL; /* PCI Devices */
-  struct diskinfo disk_info[256];     /* Disk Information*/
-
-  /* Cleaning structures */
-  memset(&disk_info,0,sizeof (disk_info));
-  memset(&dmi,0,sizeof (dmi));
-  memset(&cpu,0,sizeof (cpu));
-  memset(&hdt_menu,0,sizeof (hdt_menu));
-
-  /* Setup the environement */
-  setup_env();
-
-  /* Detect every kind of hardware */
-  detect_hardware(&dmi,&cpu,&pci_domain,disk_info);
-
-  /* Compute all sub menus */
-  compute_submenus(&hdt_menu, &dmi,&cpu,&pci_domain,disk_info);
-
-  /* Compute main menu */
-  compute_main_menu(&hdt_menu);
-
-#ifdef WITH_MENU_DISPLAY
-  t_menuitem * curr;
-  char cmd[160];
+  printf("%s\n",version_string);
 
-  printf("Starting Menu (%d menus)\n",hdt_menu.total_menu_count);
-  curr=showmenus(hdt_menu.main_menu.menu);
-  /* When we exit the menu, do we have something to do */
-  if (curr) {
-        /* When want to execute something */
-        if (curr->action == OPT_RUN)
-        {
-            strcpy(cmd,curr->data);
 
-           /* Use specific syslinux call if needed */
-           if (issyslinux())
-               runsyslinuxcmd(cmd);
-            else csprint(cmd,0x07);
-            return 1; // Should not happen when run from SYSLINUX
-        }
+  if ((arg = find_argument(argp, "nomenu"))) {
+         start_cli_mode(argc, argv);
+  } else{
+        return start_menu_mode(version_string);
   }
-#endif
 
   return 0;
 }