diff options
-rw-r--r-- | com32/LICENCE | 4 | ||||
-rw-r--r-- | com32/MCONFIG | 13 | ||||
-rw-r--r-- | com32/Makefile | 3 | ||||
-rw-r--r-- | com32/cmenu/CHANGES (renamed from menu/CHANGES) | 0 | ||||
-rw-r--r-- | com32/cmenu/HISTORY (renamed from menu/HISTORY) | 0 | ||||
-rw-r--r-- | com32/cmenu/MANUAL (renamed from menu/MANUAL) | 0 | ||||
-rw-r--r-- | com32/cmenu/MENU_FORMAT (renamed from menu/MENU_FORMAT) | 0 | ||||
-rw-r--r-- | com32/cmenu/Makefile (renamed from menu/Makefile) | 12 | ||||
-rw-r--r-- | com32/cmenu/README (renamed from menu/README) | 0 | ||||
-rw-r--r-- | com32/cmenu/TODO (renamed from menu/TODO) | 0 | ||||
-rw-r--r-- | com32/cmenu/adv_menu.tpl (renamed from menu/adv_menu.tpl) | 0 | ||||
-rw-r--r-- | com32/cmenu/complex.c (renamed from menu/complex.c) | 0 | ||||
-rw-r--r-- | com32/cmenu/display.c (renamed from menu/display.c) | 0 | ||||
-rw-r--r-- | com32/cmenu/libmenu/com32io.c (renamed from menu/libmenu/com32io.c) | 0 | ||||
-rw-r--r-- | com32/cmenu/libmenu/com32io.h (renamed from menu/libmenu/com32io.h) | 0 | ||||
-rw-r--r-- | com32/cmenu/libmenu/des.c (renamed from menu/libmenu/des.c) | 0 | ||||
-rw-r--r-- | com32/cmenu/libmenu/des.h (renamed from menu/libmenu/des.h) | 0 | ||||
-rw-r--r-- | com32/cmenu/libmenu/help.c (renamed from menu/libmenu/help.c) | 0 | ||||
-rw-r--r-- | com32/cmenu/libmenu/help.h (renamed from menu/libmenu/help.h) | 0 | ||||
-rw-r--r-- | com32/cmenu/libmenu/menu.c (renamed from menu/libmenu/menu.c) | 0 | ||||
-rw-r--r-- | com32/cmenu/libmenu/menu.h (renamed from menu/libmenu/menu.h) | 12 | ||||
-rw-r--r-- | com32/cmenu/libmenu/passwords.c (renamed from menu/libmenu/passwords.c) | 0 | ||||
-rw-r--r-- | com32/cmenu/libmenu/passwords.h (renamed from menu/libmenu/passwords.h) | 0 | ||||
-rw-r--r-- | com32/cmenu/libmenu/scancodes.h (renamed from menu/libmenu/scancodes.h) | 0 | ||||
-rw-r--r-- | com32/cmenu/libmenu/syslnx.c (renamed from menu/libmenu/syslnx.c) | 0 | ||||
-rw-r--r-- | com32/cmenu/libmenu/syslnx.h (renamed from menu/libmenu/syslnx.h) | 0 | ||||
-rw-r--r-- | com32/cmenu/libmenu/tui.c (renamed from menu/libmenu/tui.c) | 0 | ||||
-rw-r--r-- | com32/cmenu/libmenu/tui.h (renamed from menu/libmenu/tui.h) | 0 | ||||
-rw-r--r-- | com32/cmenu/menugen.py (renamed from menu/menugen.py) | 0 | ||||
-rw-r--r-- | com32/cmenu/password (renamed from menu/password) | 0 | ||||
-rw-r--r-- | com32/cmenu/simple.c (renamed from menu/simple.c) | 0 | ||||
-rw-r--r-- | com32/cmenu/test.menu (renamed from menu/test.menu) | 0 | ||||
-rw-r--r-- | com32/cmenu/test2.menu (renamed from menu/test2.menu) | 0 | ||||
-rw-r--r-- | com32/gplinclude/README | 1 | ||||
-rw-r--r-- | com32/gplinclude/cpuid.h (renamed from com32/include/cpuid.h) | 32 | ||||
-rw-r--r-- | com32/gplinclude/dmi/dmi.h (renamed from com32/include/dmi/dmi.h) | 62 | ||||
-rw-r--r-- | com32/gplinclude/dmi/dmi_base_board.h (renamed from com32/include/dmi/dmi_base_board.h) | 10 | ||||
-rw-r--r-- | com32/gplinclude/dmi/dmi_battery.h | 57 | ||||
-rw-r--r-- | com32/gplinclude/dmi/dmi_bios.h (renamed from com32/include/dmi/dmi_bios.h) | 57 | ||||
-rw-r--r-- | com32/gplinclude/dmi/dmi_chassis.h | 50 | ||||
-rw-r--r-- | com32/gplinclude/dmi/dmi_memory.h | 61 | ||||
-rw-r--r-- | com32/gplinclude/dmi/dmi_processor.h | 111 | ||||
-rw-r--r-- | com32/gplinclude/dmi/dmi_system.h (renamed from com32/include/dmi/dmi_system.h) | 2 | ||||
-rw-r--r-- | com32/gpllib/Makefile | 45 | ||||
-rw-r--r-- | com32/gpllib/cpuid.c (renamed from com32/modules/cpuid.c) | 65 | ||||
-rw-r--r-- | com32/gpllib/dmi/dmi.c (renamed from com32/modules/dmi.c) | 328 | ||||
-rw-r--r-- | com32/gpllib/dmi/dmi_base_board.c | 38 | ||||
-rw-r--r-- | com32/gpllib/dmi/dmi_battery.c | 73 | ||||
-rw-r--r-- | com32/gpllib/dmi/dmi_bios.c | 80 | ||||
-rw-r--r-- | com32/gpllib/dmi/dmi_chassis.c (renamed from com32/include/dmi/dmi_chassis.h) | 68 | ||||
-rw-r--r-- | com32/gpllib/dmi/dmi_memory.c | 172 | ||||
-rw-r--r-- | com32/gpllib/dmi/dmi_processor.c | 433 | ||||
-rw-r--r-- | com32/hdt/Makefile | 75 | ||||
-rw-r--r-- | com32/hdt/hdt-ata.c | 254 | ||||
-rw-r--r-- | com32/hdt/hdt-ata.h | 121 | ||||
-rw-r--r-- | com32/hdt/hdt-cli-cpu.c | 151 | ||||
-rw-r--r-- | com32/hdt/hdt-cli-dmi.c | 360 | ||||
-rw-r--r-- | com32/hdt/hdt-cli-kernel.c | 147 | ||||
-rw-r--r-- | com32/hdt/hdt-cli-pci.c | 241 | ||||
-rw-r--r-- | com32/hdt/hdt-cli-pxe.c | 90 | ||||
-rw-r--r-- | com32/hdt/hdt-cli-syslinux.c | 65 | ||||
-rw-r--r-- | com32/hdt/hdt-cli.c | 254 | ||||
-rw-r--r-- | com32/hdt/hdt-cli.h | 116 | ||||
-rw-r--r-- | com32/hdt/hdt-common.c | 253 | ||||
-rw-r--r-- | com32/hdt/hdt-common.h | 113 | ||||
-rw-r--r-- | com32/hdt/hdt-menu-about.c | 64 | ||||
-rw-r--r-- | com32/hdt/hdt-menu-disk.c | 148 | ||||
-rw-r--r-- | com32/hdt/hdt-menu-dmi.c | 383 | ||||
-rw-r--r-- | com32/hdt/hdt-menu-kernel.c | 73 | ||||
-rw-r--r-- | com32/hdt/hdt-menu-pci.c | 125 | ||||
-rw-r--r-- | com32/hdt/hdt-menu-processor.c | 186 | ||||
-rw-r--r-- | com32/hdt/hdt-menu-pxe.c | 99 | ||||
-rw-r--r-- | com32/hdt/hdt-menu-summary.c | 158 | ||||
-rw-r--r-- | com32/hdt/hdt-menu-syslinux.c | 74 | ||||
-rw-r--r-- | com32/hdt/hdt-menu.c | 253 | ||||
-rw-r--r-- | com32/hdt/hdt-menu.h | 121 | ||||
-rw-r--r-- | com32/hdt/hdt.c | 79 | ||||
-rw-r--r-- | com32/hdt/hdt.h | 42 | ||||
-rw-r--r-- | com32/include/dmi/dmi_processor.h | 482 | ||||
-rw-r--r-- | com32/include/string.h | 1 | ||||
-rw-r--r-- | com32/include/sys/pci.h | 31 | ||||
-rw-r--r-- | com32/include/syslinux/pxe.h | 33 | ||||
-rw-r--r-- | com32/lib/MCONFIG | 1 | ||||
-rw-r--r-- | com32/lib/Makefile | 14 | ||||
-rw-r--r-- | com32/lib/pci/scan.c | 219 | ||||
-rw-r--r-- | com32/lib/strpcpy.c | 20 | ||||
-rw-r--r-- | com32/lib/syslinux/pxe_get_nic.c | 61 | ||||
-rw-r--r-- | com32/modules/Makefile | 10 | ||||
-rw-r--r-- | com32/modules/cmd.c | 11 | ||||
-rw-r--r-- | com32/modules/dmi_utils.c | 4 | ||||
-rw-r--r-- | com32/modules/dmitest.c | 57 | ||||
-rw-r--r-- | com32/modules/pcitest.c | 76 | ||||
-rw-r--r-- | sample/Makefile | 5 |
93 files changed, 5975 insertions, 884 deletions
diff --git a/com32/LICENCE b/com32/LICENCE index 4fd64b3c..8934e8fb 100644 --- a/com32/LICENCE +++ b/com32/LICENCE @@ -2,7 +2,7 @@ libcom32 and libutil are licensed under the MIT license: ## ----------------------------------------------------------------------- ## -## Copyright 2004-2008 H. Peter Anvin - All Rights Reserved +## Copyright 2004-2009 H. Peter Anvin - All Rights Reserved ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation @@ -27,5 +27,5 @@ libcom32 and libutil are licensed under the MIT license: ## ## ----------------------------------------------------------------------- -The files in the samples and modules directories are mostly under the +The files in the sample, modules and libgpl directories are mostly under the GNU GPL (see the file COPYING in the directory above.) diff --git a/com32/MCONFIG b/com32/MCONFIG index 2b7e018b..d1af9455 100644 --- a/com32/MCONFIG +++ b/com32/MCONFIG @@ -23,10 +23,18 @@ GCCOPT := $(call gcc_ok,-std=gnu99,) \ com32 = $(topdir)/com32 +ifneq ($(NOGPL),1) +GPLLIB = $(com32)/gpllib/libcom32gpl.a +GPLINCLUDE = -I$(com32)/gplinclude +else +GPLLIB = +GPLINCLUDE = +endif + CFLAGS = $(GCCOPT) -W -Wall -march=i386 \ -fomit-frame-pointer -D__COM32__ \ -nostdinc -iwithprefix include \ - -I$(com32)/libutil/include -I$(com32)/include + -I$(com32)/libutil/include -I$(com32)/include $(GPLINCLUDE) SFLAGS = $(GCCOPT) -D__COM32__ -march=i386 LDFLAGS = -m elf_i386 -T $(com32)/lib/com32.ld LIBGCC := $(shell $(CC) $(GCCOPT) --print-libgcc) @@ -35,7 +43,8 @@ LNXCFLAGS = -I$(com32)/libutil/include -W -Wall -O -g -D_GNU_SOURCE LNXSFLAGS = -g LNXLDFLAGS = -g -C_LIBS = $(com32)/libutil/libutil_com.a $(com32)/lib/libcom32.a $(LIBGCC) +C_LIBS = $(com32)/libutil/libutil_com.a $(GPLLIB) \ + $(com32)/lib/libcom32.a $(LIBGCC) C_LNXLIBS = $(com32)/libutil/libutil_lnx.a .SUFFIXES: .lss .c .lo .o .elf .c32 .lnx diff --git a/com32/Makefile b/com32/Makefile index 9dee9684..64049d07 100644 --- a/com32/Makefile +++ b/com32/Makefile @@ -1,4 +1,3 @@ -SUBDIRS = lib libutil modules menu samples rosh - +SUBDIRS = lib gpllib libutil modules menu samples rosh cmenu hdt all tidy dist clean spotless install: set -e; for d in $(SUBDIRS); do $(MAKE) -C $$d $@; done diff --git a/menu/CHANGES b/com32/cmenu/CHANGES index cce21838..cce21838 100644 --- a/menu/CHANGES +++ b/com32/cmenu/CHANGES diff --git a/menu/HISTORY b/com32/cmenu/HISTORY index 8e9beb3f..8e9beb3f 100644 --- a/menu/HISTORY +++ b/com32/cmenu/HISTORY diff --git a/menu/MANUAL b/com32/cmenu/MANUAL index 4e70149c..4e70149c 100644 --- a/menu/MANUAL +++ b/com32/cmenu/MANUAL diff --git a/menu/MENU_FORMAT b/com32/cmenu/MENU_FORMAT index 24cb02f8..24cb02f8 100644 --- a/menu/MENU_FORMAT +++ b/com32/cmenu/MENU_FORMAT diff --git a/menu/Makefile b/com32/cmenu/Makefile index 151e2822..010fa122 100644 --- a/menu/Makefile +++ b/com32/cmenu/Makefile @@ -1,6 +1,6 @@ ## ----------------------------------------------------------------------- ## -## Copyright 2001-2008 H. Peter Anvin - All Rights Reserved +## Copyright 2001-2009 H. Peter Anvin - All Rights Reserved ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by @@ -11,14 +11,16 @@ ## ----------------------------------------------------------------------- ## -## samples for syslinux users +## Makefile for the complex menu system ## +NOGPL := 1 + # This must be defined before MCONFIG is included LIBS = libmenu/libmenu.a -topdir = .. -include $(topdir)/com32/MCONFIG +topdir = ../.. +include ../MCONFIG CFLAGS += -I./libmenu @@ -64,7 +66,7 @@ tidy dist: libclean: rm -f libmenu/*.o libmenu/*.a -clean: tidy menuclean +clean: tidy menuclean libclean rm -f *.lss *.c32 *.com menuclean: diff --git a/menu/README b/com32/cmenu/README index d585d2fa..d585d2fa 100644 --- a/menu/README +++ b/com32/cmenu/README diff --git a/menu/TODO b/com32/cmenu/TODO index d2ee82c4..d2ee82c4 100644 --- a/menu/TODO +++ b/com32/cmenu/TODO diff --git a/menu/adv_menu.tpl b/com32/cmenu/adv_menu.tpl index 6ce4acf8..6ce4acf8 100644 --- a/menu/adv_menu.tpl +++ b/com32/cmenu/adv_menu.tpl diff --git a/menu/complex.c b/com32/cmenu/complex.c index 94627c4f..94627c4f 100644 --- a/menu/complex.c +++ b/com32/cmenu/complex.c diff --git a/menu/display.c b/com32/cmenu/display.c index 5391d7fd..5391d7fd 100644 --- a/menu/display.c +++ b/com32/cmenu/display.c diff --git a/menu/libmenu/com32io.c b/com32/cmenu/libmenu/com32io.c index 31aec5df..31aec5df 100644 --- a/menu/libmenu/com32io.c +++ b/com32/cmenu/libmenu/com32io.c diff --git a/menu/libmenu/com32io.h b/com32/cmenu/libmenu/com32io.h index 78ce72fa..78ce72fa 100644 --- a/menu/libmenu/com32io.h +++ b/com32/cmenu/libmenu/com32io.h diff --git a/menu/libmenu/des.c b/com32/cmenu/libmenu/des.c index 47ff78c4..47ff78c4 100644 --- a/menu/libmenu/des.c +++ b/com32/cmenu/libmenu/des.c diff --git a/menu/libmenu/des.h b/com32/cmenu/libmenu/des.h index 67fc6b70..67fc6b70 100644 --- a/menu/libmenu/des.h +++ b/com32/cmenu/libmenu/des.h diff --git a/menu/libmenu/help.c b/com32/cmenu/libmenu/help.c index 31944c79..31944c79 100644 --- a/menu/libmenu/help.c +++ b/com32/cmenu/libmenu/help.c diff --git a/menu/libmenu/help.h b/com32/cmenu/libmenu/help.h index 06832d84..06832d84 100644 --- a/menu/libmenu/help.h +++ b/com32/cmenu/libmenu/help.h diff --git a/menu/libmenu/menu.c b/com32/cmenu/libmenu/menu.c index 56a7426c..56a7426c 100644 --- a/menu/libmenu/menu.c +++ b/com32/cmenu/libmenu/menu.c diff --git a/menu/libmenu/menu.h b/com32/cmenu/libmenu/menu.h index 446b3adb..d8db6c25 100644 --- a/menu/libmenu/menu.h +++ b/com32/cmenu/libmenu/menu.h @@ -77,16 +77,16 @@ #define SCROLLBOX 176 // Filled char to display // Attributes of the menu system -#define MAXMENUS 10 // Maximum number of menu's allowed -#define MAXMENUSIZE 30 // Default value for max num of entries in each menu -#define MAXMENUHEIGHT 14 // Maximum number of entries displayed +#define MAXMENUS 100 // Maximum number of menu's allowed +#define MAXMENUSIZE 60 // Default value for max num of entries in each menu +#define MAXMENUHEIGHT 20 // Maximum number of entries displayed #define MENUBOXTYPE BOX_SINSIN // Default box type Look at tui.h for other values // Upper bounds on lengths // We copy the given string, so user can reuse the space used to store incoming arguments. -#define MENULEN 40 // Each menu entry is atmost MENULEN chars -#define STATLEN 80 // Maximum length of status string -#define TITLELEN 80 // Maximum length of title string +#define MENULEN 78 // Each menu entry is atmost MENULEN chars +#define STATLEN 78 // Maximum length of status string +#define TITLELEN 78 // Maximum length of title string #define ACTIONLEN 255 // Maximum length of an action string // Layout of menu diff --git a/menu/libmenu/passwords.c b/com32/cmenu/libmenu/passwords.c index 40b5c49f..40b5c49f 100644 --- a/menu/libmenu/passwords.c +++ b/com32/cmenu/libmenu/passwords.c diff --git a/menu/libmenu/passwords.h b/com32/cmenu/libmenu/passwords.h index 00e5702d..00e5702d 100644 --- a/menu/libmenu/passwords.h +++ b/com32/cmenu/libmenu/passwords.h diff --git a/menu/libmenu/scancodes.h b/com32/cmenu/libmenu/scancodes.h index d3f625a6..d3f625a6 100644 --- a/menu/libmenu/scancodes.h +++ b/com32/cmenu/libmenu/scancodes.h diff --git a/menu/libmenu/syslnx.c b/com32/cmenu/libmenu/syslnx.c index d2b0aef4..d2b0aef4 100644 --- a/menu/libmenu/syslnx.c +++ b/com32/cmenu/libmenu/syslnx.c diff --git a/menu/libmenu/syslnx.h b/com32/cmenu/libmenu/syslnx.h index 755b9690..755b9690 100644 --- a/menu/libmenu/syslnx.h +++ b/com32/cmenu/libmenu/syslnx.h diff --git a/menu/libmenu/tui.c b/com32/cmenu/libmenu/tui.c index cb8c1936..cb8c1936 100644 --- a/menu/libmenu/tui.c +++ b/com32/cmenu/libmenu/tui.c diff --git a/menu/libmenu/tui.h b/com32/cmenu/libmenu/tui.h index 92f93863..92f93863 100644 --- a/menu/libmenu/tui.h +++ b/com32/cmenu/libmenu/tui.h diff --git a/menu/menugen.py b/com32/cmenu/menugen.py index 70ec1f87..70ec1f87 100644 --- a/menu/menugen.py +++ b/com32/cmenu/menugen.py diff --git a/menu/password b/com32/cmenu/password index 3caffe22..3caffe22 100644 --- a/menu/password +++ b/com32/cmenu/password diff --git a/menu/simple.c b/com32/cmenu/simple.c index 92e8ab12..92e8ab12 100644 --- a/menu/simple.c +++ b/com32/cmenu/simple.c diff --git a/menu/test.menu b/com32/cmenu/test.menu index 061c548e..061c548e 100644 --- a/menu/test.menu +++ b/com32/cmenu/test.menu diff --git a/menu/test2.menu b/com32/cmenu/test2.menu index 4570dc2c..4570dc2c 100644 --- a/menu/test2.menu +++ b/com32/cmenu/test2.menu diff --git a/com32/gplinclude/README b/com32/gplinclude/README new file mode 100644 index 00000000..ac1bf6a8 --- /dev/null +++ b/com32/gplinclude/README @@ -0,0 +1 @@ +Put header files for LGPL or GPL library functions in this directory. diff --git a/com32/include/cpuid.h b/com32/gplinclude/cpuid.h index 050cfedb..2473b41e 100644 --- a/com32/include/cpuid.h +++ b/com32/gplinclude/cpuid.h @@ -1,27 +1,15 @@ /* ----------------------------------------------------------------------- * + * + * Copyright 2006-2009 Erwan Velu - All Rights Reserved * - * Copyright 2006 Erwan Velu - All Rights Reserved + * Portions of this file taken from the Linux kernel, + * Copyright 1991-2009 Linus Torvalds and contributors * - * 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. + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston MA 02110-1301; + * incorporated herein by reference. * * ----------------------------------------------------------------------- */ @@ -168,6 +156,8 @@ struct cpuinfo_x86 { unsigned char x86_max_cores; /* cpuid returned max cores value */ unsigned char booted_cores; /* number of cores as seen by OS */ unsigned char apicid; + unsigned char x86_clflush_size; + } __attribute__((__packed__)); #endif diff --git a/com32/include/dmi/dmi.h b/com32/gplinclude/dmi/dmi.h index ceed3b4d..924ed420 100644 --- a/com32/include/dmi/dmi.h +++ b/com32/gplinclude/dmi/dmi.h @@ -12,49 +12,53 @@ #ifndef DMI_H #define DMI_H +#include <inttypes.h> +#define MAX_DMI_MEMORY_ITEMS 32 -#define u32 unsigned int -#define u16 unsigned short -#define u8 unsigned char #define PAGE_SIZE 4096 -typedef struct { - u32 l; - u32 h; -} u64; +/*typedef struct { + uint32_t l; + uint32_t h; +} uint64_t;*/ + +extern const char *out_of_spec; +extern const char *bad_index; -static const char *out_of_spec = "<OUT OF SPEC>"; -static const char *bad_index = "<BAD INDEX>"; +#define WORD(x) (uint16_t)(*(const uint16_t *)(x)) +#define DWORD(x) (uint32_t)(*(const uint32_t *)(x)) +#define QWORD(x) (*(const uint64_t *)(x)) -#define WORD(x) (u16)(*(const u16 *)(x)) -#define DWORD(x) (u32)(*(const u32 *)(x)) -#define QWORD(x) (*(const u64 *)(x)) +enum {DMI_TABLE_PRESENT = 100, ENODMITABLE}; #include "dmi_bios.h" #include "dmi_system.h" #include "dmi_base_board.h" #include "dmi_chassis.h" #include "dmi_processor.h" +#include "dmi_memory.h" +#include "dmi_battery.h" extern char display_line; #define moreprintf(...) do { display_line++; if (display_line == 24) { char tempbuf[10]; display_line=0; printf("Press enter to continue"); fgets(tempbuf, sizeof tempbuf, stdin);} printf ( __VA_ARGS__); } while (0); typedef struct { -u16 num; -u16 len; -u16 ver; -u32 base; +uint16_t num; +uint16_t len; +uint16_t ver; +uint32_t base; +uint16_t major_version; +uint16_t minor_version; } dmi_table; -static dmi_table dmitable; struct dmi_header { - u8 type; - u8 length; - u16 handle; - u8 *data; + uint8_t type; + uint8_t length; + uint16_t handle; + uint8_t *data; }; typedef struct { @@ -63,15 +67,19 @@ typedef struct { s_base_board base_board; s_chassis chassis; s_processor processor; + s_battery battery; + s_memory memory[MAX_DMI_MEMORY_ITEMS]; + int memory_count; + dmi_table dmitable; } s_dmi; -void to_dmi_header(struct dmi_header *h, u8 *data); -void dmi_bios_runtime_size(u32 code, s_dmi *dmi); -const char *dmi_string(struct dmi_header *dm, u8 s); -inline int dmi_checksum(u8 *buf); +void to_dmi_header(struct dmi_header *h, uint8_t *data); +void dmi_bios_runtime_size(uint32_t code, s_dmi *dmi); +const char *dmi_string(struct dmi_header *dm, uint8_t s); +int dmi_checksum(uint8_t *buf); void parse_dmitable(s_dmi *dmi); -void dmi_decode(struct dmi_header *h, u16 ver, s_dmi *dmi); -int dmi_interate(); +void dmi_decode(struct dmi_header *h, uint16_t ver, s_dmi *dmi); +int dmi_iterate(s_dmi *dmi); /* dmi_utils.c */ void display_bios_characteristics(s_dmi *dmi); diff --git a/com32/include/dmi/dmi_base_board.h b/com32/gplinclude/dmi/dmi_base_board.h index d6634c01..5b92b848 100644 --- a/com32/include/dmi/dmi_base_board.h +++ b/com32/gplinclude/dmi/dmi_base_board.h @@ -25,13 +25,7 @@ #define BASE_BOARD_NB_ELEMENTS 5 -static const char *base_board_features_strings[]={ - "Board is a hosting board", /* 0 */ - "Board requires at least one daughter board", - "Board is removable", - "Board is replaceable", - "Board is hot swappable" /* 4 */ -}; +extern const char *base_board_features_strings[]; /* this struct have BASE_BOARD_NB_ELEMENTS */ /* each bool is associated to the relevant message above */ @@ -52,6 +46,8 @@ char asset_tag[BASE_BOARD_ASSET_TAG_SIZE]; char location[BASE_BOARD_LOCATION_SIZE]; char type[BASE_BOARD_TYPE_SIZE]; s_base_board_features features; +/* The filled field have to be set to true when the dmitable implement that item */ +bool filled; } s_base_board; #endif diff --git a/com32/gplinclude/dmi/dmi_battery.h b/com32/gplinclude/dmi/dmi_battery.h new file mode 100644 index 00000000..72c19693 --- /dev/null +++ b/com32/gplinclude/dmi/dmi_battery.h @@ -0,0 +1,57 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 2009 Erwan Velu - All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, Inc., 53 Temple Place Ste 330, + * Boston MA 02111-1307, USA; either version 2 of the License, or + * (at your option) any later version; incorporated herein by reference. + * + * ----------------------------------------------------------------------- */ + +#ifndef DMI_BATTERY_H +#define DMI_BATTERY_H + +#include <stdbool.h> +#include <inttypes.h> + +#define BATTERY_LOCATION_SIZE 255 +#define BATTERY_MANUFACTURER_SIZE 255 +#define BATTERY_MANUFACTURE_DATE_SIZE 255 +#define BATTERY_SERIAL_SIZE 255 +#define BATTERY_DEVICE_NAME_SIZE 255 +#define BATTERY_CHEMISTRY_SIZE 32 +#define BATTERY_CAPACITY_SIZE 16 +#define BATTERY_DESIGN_VOLTAGE_SIZE 16 +#define BATTERY_SBDS_SIZE 255 +#define BATTERY_MAXIMUM_ERROR_SIZE 32 +#define BATTERY_SBDS_SERIAL_SIZE 32 +#define BATTERY_SBDS_MANUFACTURE_DATE_SIZE 255 +#define BATTERY_SBDS_CHEMISTRY_SIZE 16 +#define BATTERY_OEM_INFO_SIZE 255 + +typedef struct { +char location[BATTERY_LOCATION_SIZE]; +char manufacturer[BATTERY_MANUFACTURER_SIZE]; +char manufacture_date[BATTERY_MANUFACTURE_DATE_SIZE]; +char serial[BATTERY_SERIAL_SIZE]; +char name[BATTERY_DEVICE_NAME_SIZE]; +char chemistry[BATTERY_CHEMISTRY_SIZE]; +char design_capacity[BATTERY_CAPACITY_SIZE]; +char design_voltage[BATTERY_DESIGN_VOLTAGE_SIZE]; +char sbds[BATTERY_SBDS_SIZE]; +char sbds_serial[BATTERY_SBDS_SERIAL_SIZE]; +char maximum_error[BATTERY_MAXIMUM_ERROR_SIZE]; +char sbds_manufacture_date[BATTERY_SBDS_MANUFACTURE_DATE_SIZE]; +char sbds_chemistry[BATTERY_SBDS_CHEMISTRY_SIZE]; +char oem_info[BATTERY_OEM_INFO_SIZE]; +/* The filled field have to be set to true when the dmitable implement that item */ +bool filled; +} s_battery; + +const char *dmi_battery_chemistry(uint8_t code); +void dmi_battery_capacity(uint16_t code, uint8_t multiplier,char *capacity); +void dmi_battery_voltage(uint16_t code, char *voltage); +void dmi_battery_maximum_error(uint8_t code, char *error); +#endif diff --git a/com32/include/dmi/dmi_bios.h b/com32/gplinclude/dmi/dmi_bios.h index 0241f0b2..546bbefc 100644 --- a/com32/include/dmi/dmi_bios.h +++ b/com32/gplinclude/dmi/dmi_bios.h @@ -26,37 +26,7 @@ #define BIOS_CHAR_X1_NB_ELEMENTS 8 #define BIOS_CHAR_X2_NB_ELEMENTS 3 -static const char *bios_charac_strings[]={ - "BIOS characteristics not supported", /* 3 */ - "ISA is supported", - "MCA is supported", - "EISA is supported", - "PCI is supported", - "PC Card (PCMCIA) is supported", - "PNP is supported", - "APM is supported", - "BIOS is upgradeable", - "BIOS shadowing is allowed", - "VLB is supported", - "ESCD support is available", - "Boot from CD is supported", - "Selectable boot is supported", - "BIOS ROM is socketed", - "Boot from PC Card (PCMCIA) is supported", - "EDD is supported", - "Japanese floppy for NEC 9800 1.2 MB is supported (int 13h)", - "Japanese floppy for Toshiba 1.2 MB is supported (int 13h)", - "5.25\"/360 KB floppy services are supported (int 13h)", - "5.25\"/1.2 MB floppy services are supported (int 13h)", - "3.5\"/720 KB floppy services are supported (int 13h)", - "3.5\"/2.88 MB floppy services are supported (int 13h)", - "Print screen service is supported (int 5h)", - "8042 keyboard services are supported (int 9h)", - "Serial services are supported (int 14h)", - "Printer services are supported (int 17h)", - "CGA/mono video services are supported (int 10h)", - "NEC PC-98" /* 31 */ -}; +extern const char *bios_charac_strings[]; /* this struct has BIOS_CHAR_NB_ELEMENTS */ /* each bool is associated with the relevant message above */ @@ -91,16 +61,7 @@ bool cga_mono_support; bool nec_pc_98; } __attribute__((__packed__)) s_characteristics; -static const char *bios_charac_x1_strings[]={ - "ACPI is supported", /* 0 */ - "USB legacy is supported", - "AGP is supported", - "I2O boot is supported", - "LS-120 boot is supported", - "ATAPI Zip drive boot is supported", - "IEEE 1394 boot is supported", - "Smart battery is supported" /* 7 */ -}; +extern const char *bios_charac_x1_strings[]; /* this struct has BIOS_CHAR_X1_NB_ELEMENTS */ /* each bool is associated with the relevant message above */ @@ -115,11 +76,7 @@ bool ieee_1394_boot; bool smart_battery; } __attribute__((__packed__)) s_characteristics_x1; -static const char *bios_charac_x2_strings[]={ - "BIOS boot specification is supported", /* 0 */ - "Function key-initiated network boot is supported", - "Targeted content distribution is supported" /* 2 */ -}; +extern const char *bios_charac_x2_strings[]; /* this struct has BIOS_CHAR_X2_NB_ELEMENTS */ /* each bool is associated with the relevant message above */ @@ -133,16 +90,18 @@ typedef struct { char vendor[BIOS_VENDOR_SIZE]; char version[BIOS_VERSION_SIZE]; char release_date[BIOS_RELEASE_SIZE]; -u16 address; -u16 runtime_size; +uint16_t address; +uint16_t runtime_size; char runtime_size_unit[BIOS_RUNTIME_SIZE_UNIT_SIZE]; -u16 rom_size; +uint16_t rom_size; char rom_size_unit[BIOS_ROM_UNIT_SIZE]; s_characteristics characteristics; s_characteristics_x1 characteristics_x1; s_characteristics_x2 characteristics_x2; char bios_revision [BIOS_BIOS_REVISION_SIZE]; char firmware_revision [BIOS_FIRMWARE_REVISION_SIZE]; +/* The filled field have to be set to true when the dmitable implement that item */ +bool filled; } s_bios; #endif diff --git a/com32/gplinclude/dmi/dmi_chassis.h b/com32/gplinclude/dmi/dmi_chassis.h new file mode 100644 index 00000000..96711ed4 --- /dev/null +++ b/com32/gplinclude/dmi/dmi_chassis.h @@ -0,0 +1,50 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 2006 Erwan Velu - All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, Inc., 53 Temple Place Ste 330, + * Boston MA 02111-1307, USA; either version 2 of the License, or + * (at your option) any later version; incorporated herein by reference. + * + * ----------------------------------------------------------------------- */ + +#ifndef DMI_CHASSIS_H +#define DMI_CHASSIS_H + +#define CHASSIS_MANUFACTURER_SIZE 32 +#define CHASSIS_TYPE_SIZE 16 +#define CHASSIS_LOCK_SIZE 16 +#define CHASSIS_VERSION_SIZE 16 +#define CHASSIS_SERIAL_SIZE 32 +#define CHASSIS_ASSET_TAG_SIZE 32 +#define CHASSIS_BOOT_UP_STATE_SIZE 32 +#define CHASSIS_POWER_SUPPLY_STATE_SIZE 32 +#define CHASSIS_THERMAL_STATE_SIZE 32 +#define CHASSIS_SECURITY_STATUS_SIZE 32 +#define CHASSIS_OEM_INFORMATION_SIZE 32 + +typedef struct { +char manufacturer[CHASSIS_MANUFACTURER_SIZE]; +char type[CHASSIS_TYPE_SIZE]; +char lock[CHASSIS_LOCK_SIZE]; +char version[CHASSIS_VERSION_SIZE]; +char serial[CHASSIS_SERIAL_SIZE]; +char asset_tag[CHASSIS_ASSET_TAG_SIZE]; +char boot_up_state[CHASSIS_BOOT_UP_STATE_SIZE]; +char power_supply_state[CHASSIS_POWER_SUPPLY_STATE_SIZE]; +char thermal_state[CHASSIS_THERMAL_STATE_SIZE]; +char security_status[CHASSIS_SECURITY_STATUS_SIZE]; +char oem_information[CHASSIS_OEM_INFORMATION_SIZE]; +uint16_t height; +uint16_t nb_power_cords; +/* The filled field have to be set to true when the dmitable implement that item */ +bool filled; +} s_chassis; + +const char *dmi_chassis_type(uint8_t code); +const char *dmi_chassis_lock(uint8_t code); +const char *dmi_chassis_state(uint8_t code); +const char *dmi_chassis_security_status(uint8_t code); +#endif diff --git a/com32/gplinclude/dmi/dmi_memory.h b/com32/gplinclude/dmi/dmi_memory.h new file mode 100644 index 00000000..2b744b5c --- /dev/null +++ b/com32/gplinclude/dmi/dmi_memory.h @@ -0,0 +1,61 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 2009 Erwan Velu - All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, Inc., 53 Temple Place Ste 330, + * Boston MA 02111-1307, USA; either version 2 of the License, or + * (at your option) any later version; incorporated herein by reference. + * + * ----------------------------------------------------------------------- */ + +#ifndef DMI_MEMORY_H +#define DMI_MEMORY_H + +#define MEMORY_MANUFACTURER_SIZE 32 +#define MEMORY_ERROR_SIZE 16 +#define MEMORY_TOTAL_WIDTH_SIZE 16 +#define MEMORY_DATA_WIDTH_SIZE 16 +#define MEMORY_SIZE_SIZE 32 +#define MEMORY_FORM_FACTOR_SIZE 32 +#define MEMORY_DEVICE_SET_SIZE 32 +#define MEMORY_DEVICE_LOCATOR_SIZE 32 +#define MEMORY_BANK_LOCATOR_SIZE 32 +#define MEMORY_TYPE_SIZE 32 +#define MEMORY_TYPE_DETAIL_SIZE 16 +#define MEMORY_SPEED_SIZE 16 +#define MEMORY_SERIAL_SIZE 16 +#define MEMORY_ASSET_TAG_SIZE 16 +#define MEMORY_PART_NUMBER_SIZE 16 + +typedef struct { +char manufacturer[MEMORY_MANUFACTURER_SIZE]; +char error[MEMORY_ERROR_SIZE]; +char total_width[MEMORY_TOTAL_WIDTH_SIZE]; +char data_width[MEMORY_DATA_WIDTH_SIZE]; +char size[MEMORY_SIZE_SIZE]; +char form_factor[MEMORY_FORM_FACTOR_SIZE]; +char device_set[MEMORY_DEVICE_SET_SIZE]; +char device_locator[MEMORY_DEVICE_LOCATOR_SIZE]; +char bank_locator[MEMORY_BANK_LOCATOR_SIZE]; +char type[MEMORY_TYPE_SIZE]; +char type_detail[MEMORY_TYPE_DETAIL_SIZE]; +char speed[MEMORY_SPEED_SIZE]; +char serial[MEMORY_SERIAL_SIZE]; +char asset_tag[MEMORY_ASSET_TAG_SIZE]; +char part_number[MEMORY_PART_NUMBER_SIZE]; +/* The filled field have to be set to true when the dmitable implement that item */ +bool filled; +} s_memory; + +void dmi_memory_array_error_handle(uint16_t code,char *array); +void dmi_memory_device_width(uint16_t code, char *width); +void dmi_memory_device_size(uint16_t code, char *size); +const char *dmi_memory_device_form_factor(uint8_t code); +void dmi_memory_device_set(uint8_t code, char *set); +const char *dmi_memory_device_type(uint8_t code); +void dmi_memory_device_type_detail(uint16_t code,char *type_detail); +void dmi_memory_device_speed(uint16_t code, char *speed); + +#endif diff --git a/com32/gplinclude/dmi/dmi_processor.h b/com32/gplinclude/dmi/dmi_processor.h new file mode 100644 index 00000000..79ee43d4 --- /dev/null +++ b/com32/gplinclude/dmi/dmi_processor.h @@ -0,0 +1,111 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 2006 Erwan Velu - All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, Inc., 53 Temple Place Ste 330, + * Boston MA 02111-1307, USA; either version 2 of the License, or + * (at your option) any later version; incorporated herein by reference. + * + * ----------------------------------------------------------------------- */ + +#ifndef DMI_PROCESSOR_H +#define DMI_PROCESSOR_H + +#include "stdbool.h" +#include "string.h" +#define PROCESSOR_SOCKET_DESIGNATION_SIZE 32 +#define PROCESSOR_TYPE_SIZE 32 +#define PROCESSOR_FAMILY_SIZE 32 +#define PROCESSOR_MANUFACTURER_SIZE 64 +#define PROCESSOR_VERSION_SIZE 32 +#define PROCESSOR_VOLTAGE_SIZE 16 +#define PROCESSOR_STATUS_SIZE 16 +#define PROCESSOR_UPGRADE_SIZE 16 +#define PROCESSOR_CACHE_SIZE 16 +#define PROCESSOR_SERIAL_SIZE 32 +#define PROCESSOR_ASSET_TAG_SIZE 32 +#define PROCESSOR_PART_NUMBER_SIZE 32 +#define PROCESSOR_ID_SIZE 32 + +#define PROCESSOR_FLAGS_ELEMENTS 32 +/* Intel AP-485 revision 28, table 5 */ +extern const char *cpu_flags_strings[PROCESSOR_FLAGS_ELEMENTS]; + +/* this struct have PROCESSOR_FLAGS_ELEMENTS */ +/* each bool is associated to the relevant message above */ +typedef struct { +bool fpu; +bool vme; +bool de; +bool pse; +bool tsc; +bool msr; +bool pae; +bool mce; +bool cx8; +bool apic; +bool null_10; +bool sep; +bool mtrr; +bool pge; +bool mca; +bool cmov; +bool pat; +bool pse_36; +bool psn; +bool clfsh; +bool null_20; +bool ds; +bool acpi; +bool mmx; +bool fxsr; +bool sse; +bool sse2; +bool ss; +bool htt; +bool tm; +bool null_30; +bool pbe; +} __attribute__((__packed__)) s_dmi_cpu_flags; + +typedef struct { +uint8_t type; +uint8_t family; +uint8_t model; +uint8_t stepping; +uint8_t minor_stepping; +} __attribute__((__packed__)) s_signature; + +typedef struct { +char socket_designation[PROCESSOR_SOCKET_DESIGNATION_SIZE]; +char type[PROCESSOR_TYPE_SIZE]; +char family[PROCESSOR_FAMILY_SIZE]; +char manufacturer[PROCESSOR_MANUFACTURER_SIZE]; +char version[PROCESSOR_VERSION_SIZE]; +float voltage; +uint16_t external_clock; +uint16_t max_speed; +uint16_t current_speed; +char status[PROCESSOR_STATUS_SIZE]; +char upgrade[PROCESSOR_UPGRADE_SIZE]; +char cache1[PROCESSOR_CACHE_SIZE]; +char cache2[PROCESSOR_CACHE_SIZE]; +char cache3[PROCESSOR_CACHE_SIZE]; +char serial[PROCESSOR_SERIAL_SIZE]; +char asset_tag[PROCESSOR_ASSET_TAG_SIZE]; +char part_number[PROCESSOR_PART_NUMBER_SIZE]; +char id[PROCESSOR_ID_SIZE]; +s_dmi_cpu_flags cpu_flags; +s_signature signature; +/* The filled field have to be set to true when the dmitable implement that item */ +bool filled; +} s_processor; + +const char *dmi_processor_type(uint8_t code); +const char *dmi_processor_family(uint8_t code, char *manufacturer); +const char *dmi_processor_status(uint8_t code); +const char *dmi_processor_upgrade(uint8_t code); +void dmi_processor_cache(uint16_t code, const char *level, uint16_t ver, char *cache); +#endif diff --git a/com32/include/dmi/dmi_system.h b/com32/gplinclude/dmi/dmi_system.h index 27293649..5a461d5f 100644 --- a/com32/include/dmi/dmi_system.h +++ b/com32/gplinclude/dmi/dmi_system.h @@ -31,6 +31,8 @@ char uuid[SYSTEM_UUID_SIZE]; char wakeup_type[SYSTEM_WAKEUP_TYPE_SIZE]; char sku_number[SYSTEM_SKU_NUMBER_SIZE]; char family[SYSTEM_FAMILY_SIZE]; +/* The filled field have to be set to true when the dmitable implement that item */ +bool filled; } s_system; #endif diff --git a/com32/gpllib/Makefile b/com32/gpllib/Makefile new file mode 100644 index 00000000..08164c2a --- /dev/null +++ b/com32/gpllib/Makefile @@ -0,0 +1,45 @@ +# +# LGPL/GPL code library +# + +# Include configuration rules +topdir = ../.. +include ../lib/MCONFIG + +REQFLAGS += -I../gplinclude + +LIBOBJS = dmi/dmi_battery.o dmi/dmi_chassis.o dmi/dmi_memory.o \ + dmi/dmi_processor.o dmi/dmi.o dmi/dmi_bios.o dmi/dmi_base_board.o \ + cpuid.o + +BINDIR = /usr/bin +LIBDIR = /usr/lib +DATADIR = /usr/share +AUXDIR = $(DATADIR)/syslinux +INCDIR = /usr/include +COM32DIR = $(AUXDIR)/com32 + +all: libcom32gpl.a + +libcom32gpl.a : $(LIBOBJS) + rm -f $@ + $(AR) cq $@ $^ + $(RANLIB) $@ + +tidy dist clean: + find . \( -name \*.o -o -name \*.a -o -name .\*.d -o -name \*.tmp \) -print0 | \ + xargs -0r rm -f + +spotless: clean + rm -f *.a + rm -f *~ \#* */*~ */\#* + +# Mixing in the GPL include files is suboptimal, but I'm not sure +# there is a better way to do it. +install: all + mkdir -m 755 -p $(INSTALLROOT)$(COM32DIR) + install -m 644 libcom32gpl.a $(INSTALLROOT)$(COM32DIR) + mkdir -p $(INSTALLROOT)$(COM32DIR)/include/ + cp -r ../gplinclude $(INSTALLROOT)$(COM32DIR)/include/ + +-include .*.d */.*.d */*/.*.d diff --git a/com32/modules/cpuid.c b/com32/gpllib/cpuid.c index 9418a21e..ed3224d4 100644 --- a/com32/modules/cpuid.c +++ b/com32/gpllib/cpuid.c @@ -1,29 +1,20 @@ -/* ----------------------------------------------------------------------- * - * - * Copyright 2006 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. +/* + * Portions of this file taken from the Linux kernel, + * Copyright 1991-2009 Linus Torvalds and contributors * - * 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. + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * ----------------------------------------------------------------------- */ + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ #include <stdio.h> #include <string.h> @@ -144,7 +135,8 @@ int get_model_name(struct cpuinfo_x86 *c) void generic_identify(struct cpuinfo_x86 *c) { - uint32_t tfms, xlvl, junk; + uint32_t tfms, xlvl; + unsigned int ebx; /* Get vendor name */ cpuid(0x00000000, @@ -157,18 +149,18 @@ void generic_identify(struct cpuinfo_x86 *c) /* Intel-defined flags: level 0x00000001 */ if ( c->cpuid_level >= 0x00000001 ) { uint32_t capability, excap; - cpuid(0x00000001, &tfms, &junk, &excap, &capability); + cpuid(0x00000001, &tfms, &ebx, &excap, &capability); c->x86_capability[0] = capability; c->x86_capability[4] = excap; c->x86 = (tfms >> 8) & 15; c->x86_model = (tfms >> 4) & 15; - if (c->x86 == 0xf) { + if (c->x86 == 0xf) c->x86 += (tfms >> 20) & 0xff; + if (c->x86 >= 0x6) c->x86_model += ((tfms >> 16) & 0xF) << 4; - } c->x86_mask = tfms & 15; - if (capability & (1<<19)) - c->x86_cache_alignment = ((junk >> 8) & 0xff) * 8; + if (cpu_has(c, X86_FEATURE_CLFLSH)) + c->x86_clflush_size = ((ebx >> 8) & 0xff) * 8; } else { /* Have CPUID level 0 only - unheard of */ c->x86 = 4; @@ -310,21 +302,22 @@ void set_generic_info(struct cpuinfo_x86 *c,s_cpu *cpu) { cpu->vendor_id=c->x86_vendor; cpu->model_id=c->x86_model; cpu->stepping=c->x86_mask; - strncpy(cpu->vendor,cpu_devs[c->x86_vendor]->c_vendor,CPU_VENDOR_SIZE); - strncpy(cpu->model,c->x86_model_id,CPU_MODEL_SIZE); + strncpy(cpu->vendor,cpu_devs[c->x86_vendor]->c_vendor,sizeof(cpu->vendor)); + strncpy(cpu->model,c->x86_model_id,sizeof(cpu->model)); } void detect_cpu(s_cpu *cpu) { struct cpuinfo_x86 c; - c.x86_cache_alignment = 32; + c.x86_clflush_size = 32; c.x86_cache_size = -1; c.x86_vendor = X86_VENDOR_UNKNOWN; c.cpuid_level = -1; /* CPUID not detected */ c.x86_model = c.x86_mask = 0; /* So far unknown... */ - c.x86_vendor_id[0] = '\0'; /* Unset */ - c.x86_model_id[0] = '\0'; /* Unset */ - memset(&c.x86_vendor_id,'\0',CPU_VENDOR_SIZE); + c.x86_max_cores = 1; + memset(&c.x86_capability, 0, sizeof(c.x86_capability)); + memset(&c.x86_vendor_id,0,sizeof(c.x86_vendor_id)); + memset(&c.x86_model_id,0,sizeof(c.x86_model_id)); if (!have_cpuid_p()) return; diff --git a/com32/modules/dmi.c b/com32/gpllib/dmi/dmi.c index 1e47c1a6..a2a08b56 100644 --- a/com32/modules/dmi.c +++ b/com32/gpllib/dmi/dmi.c @@ -30,17 +30,60 @@ #include <string.h> #include "dmi/dmi.h" +const char *out_of_spec = "<OUT OF SPEC>"; +const char *bad_index = "<BAD INDEX>"; +void dmi_bios_runtime_size(uint32_t code, s_dmi *dmi) +{ + if(code&0x000003FF) { + dmi->bios.runtime_size=code; + strcpy(dmi->bios.runtime_size_unit,"bytes"); + } else { + dmi->bios.runtime_size=code >>10; + strcpy(dmi->bios.runtime_size_unit,"KB"); + + } +} -void to_dmi_header(struct dmi_header *h, u8 *data) +void dmi_bios_characteristics(uint64_t code, s_dmi *dmi) { - h->type=data[0]; - h->length=data[1]; - h->handle=WORD(data+2); - h->data=data; + int i; + /* + * This isn't very clear what this bit is supposed to mean + */ + //if(code.l&(1<<3)) + if(code&&(1<<3)) + { + ((bool *)(& dmi->bios.characteristics))[0]=true; + return; + } + + for(i=4; i<=31; i++) + //if(code.l&(1<<i)) + if(code&(1<<i)) + ((bool *)(& dmi->bios.characteristics))[i-3]=true; +} + +void dmi_bios_characteristics_x1(uint8_t code, s_dmi *dmi) +{ + int i; + + for(i=0; i<=7; i++) + if(code&(1<<i)) + ((bool *)(& dmi->bios.characteristics_x1))[i]=true; +} + +void dmi_bios_characteristics_x2(uint8_t code, s_dmi *dmi) +{ + int i; + + for(i=0; i<=2; i++) + if(code&(1<<i)) + ((bool *)(& dmi->bios.characteristics_x2))[i]=true; } -void dmi_system_uuid(u8 *p, s_dmi *dmi) + +void dmi_system_uuid(uint8_t *p, s_dmi *dmi) { int only0xFF=1, only0x00=1; int i; @@ -67,20 +110,42 @@ void dmi_system_uuid(u8 *p, s_dmi *dmi) p[8], p[9], p[10], p[11], p[12], p[13], p[14], p[15]); } -static void dmi_base_board_features(u8 code, s_dmi *dmi) +void dmi_system_wake_up_type(uint8_t code, s_dmi *dmi) +{ + /* 3.3.2.1 */ + static const char *type[]={ + "Reserved", /* 0x00 */ + "Other", + "Unknown", + "APM Timer", + "Modem Ring", + "LAN Remote", + "Power Switch", + "PCI PME#", + "AC Power Restored" /* 0x08 */ + }; + + if(code<=0x08) { + strcpy(dmi->system.wakeup_type,type[code]); + } else { + strcpy(dmi->system.wakeup_type,out_of_spec); + } +return; +} + +static void dmi_base_board_features(uint8_t code, s_dmi *dmi) { if((code&0x1F)!=0) { int i; - printf("\n"); for(i=0; i<=4; i++) if(code&(1<<i)) - ((bool *)(& dmi->base_board.features))[i]=true; + ((bool *)(& dmi->base_board.features))[i]=true; } } -static void dmi_processor_voltage(u8 code, s_dmi *dmi) +static void dmi_processor_voltage(uint8_t code, s_dmi *dmi) { /* 3.3.5.4 */ static const float voltage[]={ @@ -100,14 +165,14 @@ static void dmi_processor_voltage(u8 code, s_dmi *dmi) } } -static void dmi_processor_id(u8 type, u8 *p, const char *version, s_dmi *dmi) +static void dmi_processor_id(uint8_t type, uint8_t *p, const char *version, s_dmi *dmi) { /* * Extra flags are now returned in the ECX register when one calls * the CPUID instruction. Their meaning is explained in table 6, but * DMI doesn't support this yet. */ - u32 eax, edx; + uint32_t eax, edx; int sig=0; /* @@ -119,7 +184,7 @@ static void dmi_processor_id(u8 type, u8 *p, const char *version, s_dmi *dmi) if(type==0x05) /* 80386 */ { - u16 dx=WORD(p); + uint16_t dx=WORD(p); /* * 80386 have a different signature. */ @@ -131,7 +196,7 @@ static void dmi_processor_id(u8 type, u8 *p, const char *version, s_dmi *dmi) } if(type==0x06) /* 80486 */ { - u16 dx=WORD(p); + uint16_t dx=WORD(p); /* * Not all 80486 CPU support the CPUID instruction, we have to find * wether the one we have here does or not. Note that this trick @@ -207,77 +272,15 @@ static void dmi_processor_id(u8 type, u8 *p, const char *version, s_dmi *dmi) } -void dmi_system_wake_up_type(u8 code, s_dmi *dmi) -{ - /* 3.3.2.1 */ - static const char *type[]={ - "Reserved", /* 0x00 */ - "Other", - "Unknown", - "APM Timer", - "Modem Ring", - "LAN Remote", - "Power Switch", - "PCI PME#", - "AC Power Restored" /* 0x08 */ - }; - - if(code<=0x08) { - strcpy(dmi->system.wakeup_type,type[code]); - } else { - strcpy(dmi->system.wakeup_type,out_of_spec); - } -return; -} - -void dmi_bios_runtime_size(u32 code, s_dmi *dmi) -{ - if(code&0x000003FF) { - dmi->bios.runtime_size=code; - strcpy(dmi->bios.runtime_size_unit,"bytes"); - } else { - dmi->bios.runtime_size=code >>10; - strcpy(dmi->bios.runtime_size_unit,"KB"); - - } -} - -void dmi_bios_characteristics(u64 code, s_dmi *dmi) -{ - int i; - /* - * This isn't very clear what this bit is supposed to mean - */ - if(code.l&(1<<3)) - { - ((bool *)(& dmi->bios.characteristics))[0]=true; - return; - } - - for(i=4; i<=31; i++) - if(code.l&(1<<i)) - ((bool *)(& dmi->bios.characteristics))[i-3]=true; -} - -void dmi_bios_characteristics_x1(u8 code, s_dmi *dmi) -{ - int i; - - for(i=0; i<=7; i++) - if(code&(1<<i)) - ((bool *)(& dmi->bios.characteristics_x1))[i]=true; -} - -void dmi_bios_characteristics_x2(u8 code, s_dmi *dmi) +void to_dmi_header(struct dmi_header *h, uint8_t *data) { - int i; - - for(i=0; i<=2; i++) - if(code&(1<<i)) - ((bool *)(& dmi->bios.characteristics_x2))[i]=true; + h->type=data[0]; + h->length=data[1]; + h->handle=WORD(data+2); + h->data=data; } -const char *dmi_string(struct dmi_header *dm, u8 s) +const char *dmi_string(struct dmi_header *dm, uint8_t s) { char *bp=(char *)dm->data; size_t i, len; @@ -305,9 +308,9 @@ const char *dmi_string(struct dmi_header *dm, u8 s) return bp; } -inline int dmi_checksum(u8 *buf) +int dmi_checksum(uint8_t *buf) { - u8 sum=0; + uint8_t sum=0; int a; for(a=0; a<15; a++) @@ -315,41 +318,68 @@ inline int dmi_checksum(u8 *buf) return (sum==0); } -int dmi_interate() { - u8 buf[16]; +int dmi_iterate(s_dmi *dmi) { + uint8_t buf[16]; char *p,*q; + + /* Cleaning structures */ + memset(&dmi->base_board,0,sizeof (s_base_board)); + memset(&dmi->battery,0,sizeof (s_battery)); + memset(&dmi->bios,0,sizeof (s_bios)); + memset(&dmi->chassis,0,sizeof (s_chassis)); + for (int i=0;i<MAX_DMI_MEMORY_ITEMS;i++) + memset(&dmi->memory[i],0,sizeof (s_memory)); + memset(&dmi->processor,0,sizeof (s_processor)); + memset(&dmi->system,0,sizeof (s_system)); + + /* Until we found this elements in the dmitable, we consider them as not filled */ + dmi->base_board.filled=false; + dmi->battery.filled=false; + dmi->bios.filled=false; + dmi->chassis.filled=false; + for (int i=0;i<MAX_DMI_MEMORY_ITEMS;i++) + dmi->memory[i].filled=false; + dmi->processor.filled=false; + dmi->system.filled=false; + p=(char *)0xF0000; /* The start address to look at the dmi table */ for (q = p; q < p + 0x10000; q += 16) { memcpy(buf, q, 15); if(memcmp(buf, "_DMI_", 5)==0 && dmi_checksum(buf)) { - dmitable.num = buf[13]<<8|buf[12]; - dmitable.len = buf[7]<<8|buf[6]; - dmitable.base = buf[11]<<24|buf[10]<<16|buf[9]<<8|buf[8]; - dmitable.ver = (buf[0x06]<<8)+buf[0x07]; + dmi->dmitable.num = buf[13]<<8|buf[12]; + dmi->dmitable.len = buf[7]<<8|buf[6]; + dmi->dmitable.base = buf[11]<<24|buf[10]<<16|buf[9]<<8|buf[8]; + dmi->dmitable.ver = (buf[0x06]<<8)+buf[0x07]; /* * DMI version 0.0 means that the real version is taken from * the SMBIOS version, which we don't know at this point. */ - if(buf[14]!=0) - printf("DMI %d.%d present.\n",buf[14]>>4, buf[14]&0x0F); - else - printf("DMI present.\n"); + if(buf[14]!=0) { + dmi->dmitable.major_version=buf[14]>>4; + dmi->dmitable.minor_version=buf[14]&0x0F; + } + else { + dmi->dmitable.major_version=0; + dmi->dmitable.minor_version=0; + + } +/* printf("DMI present (version %d.%d)\n", dmitable.major_version,dmitable.minor_version); printf("%d structures occupying %d bytes.\n",dmitable.num, dmitable.len); - printf("DMI table at 0x%08X.\n",dmitable.base); - return 1; + printf("DMI table at 0x%08X.\n",dmitable.base);*/ + return DMI_TABLE_PRESENT; } } - dmitable.base=0; - dmitable.num=0; - dmitable.ver=0; - dmitable.len=0; - return 0; + dmi->dmitable.base=0; + dmi->dmitable.num=0; + dmi->dmitable.ver=0; + dmi->dmitable.len=0; + return -ENODMITABLE; } -void dmi_decode(struct dmi_header *h, u16 ver, s_dmi *dmi) +void dmi_decode(struct dmi_header *h, uint16_t ver, s_dmi *dmi) { - u8 *data=h->data; + uint8_t *data=h->data; /* * Note: DMI types 37, 38 and 39 are untested @@ -359,6 +389,7 @@ void dmi_decode(struct dmi_header *h, u16 ver, s_dmi *dmi) case 0: /* 3.3.1 BIOS Information */ // printf("BIOS Information\n"); if(h->length<0x12) break; + dmi->bios.filled=true; strcpy(dmi->bios.vendor,dmi_string(h,data[0x04])); strcpy(dmi->bios.version,dmi_string(h,data[0x05])); strcpy(dmi->bios.release_date,dmi_string(h,data[0x08])); @@ -383,6 +414,7 @@ void dmi_decode(struct dmi_header *h, u16 ver, s_dmi *dmi) case 1: /* 3.3.2 System Information */ // printf("System Information\n"); if(h->length<0x08) break; + dmi->system.filled=true; strcpy(dmi->system.manufacturer,dmi_string(h,data[0x04])); strcpy(dmi->system.product_name,dmi_string(h,data[0x05])); strcpy(dmi->system.version,dmi_string(h,data[0x06])); @@ -398,6 +430,7 @@ void dmi_decode(struct dmi_header *h, u16 ver, s_dmi *dmi) case 2: /* 3.3.3 Base Board Information */ // printf("Base Board Information\n"); if(h->length<0x08) break; + dmi->base_board.filled=true; strcpy(dmi->base_board.manufacturer,dmi_string(h,data[0x04])); strcpy(dmi->base_board.product_name,dmi_string(h,data[0x05])); strcpy(dmi->base_board.version,dmi_string(h,data[0x06])); @@ -407,11 +440,12 @@ void dmi_decode(struct dmi_header *h, u16 ver, s_dmi *dmi) dmi_base_board_features(data[0x09], dmi); strcpy(dmi->base_board.location,dmi_string(h,data[0x0A])); strcpy(dmi->base_board.type,dmi_string(h,data[0x0D])); - if(h->length<0x0F+data[0x0E]*sizeof(u16)) break; + if(h->length<0x0F+data[0x0E]*sizeof(uint16_t)) break; break; case 3: /* 3.3.4 Chassis Information */ // printf("Chassis Information\n"); if(h->length<0x09) break; + dmi->chassis.filled=true; strcpy(dmi->chassis.manufacturer,dmi_string(h,data[0x04])); strcpy(dmi->chassis.type,dmi_chassis_type(data[0x05]&0x7F)); strcpy(dmi->chassis.lock,dmi_chassis_lock(data[0x05]>>7)); @@ -433,10 +467,11 @@ void dmi_decode(struct dmi_header *h, u16 ver, s_dmi *dmi) case 4: /* 3.3.5 Processor Information */ // printf("Processor Information\n"); if(h->length<0x1A) break; + dmi->processor.filled=true; strcpy(dmi->processor.socket_designation,dmi_string(h, data[0x04])); strcpy(dmi->processor.type,dmi_processor_type(data[0x05])); - strcpy(dmi->processor.family,dmi_processor_family(data[0x06])); strcpy(dmi->processor.manufacturer,dmi_string(h, data[0x07])); + strcpy(dmi->processor.family,dmi_processor_family(data[0x06],dmi->processor.manufacturer)); dmi_processor_id(data[0x06], data+8, dmi_string(h, data[0x10]), dmi); strcpy(dmi->processor.version,dmi_string(h, data[0x10])); dmi_processor_voltage(data[0x11],dmi); @@ -457,18 +492,82 @@ void dmi_decode(struct dmi_header *h, u16 ver, s_dmi *dmi) strcpy(dmi->processor.asset_tag,dmi_string(h, data[0x21])); strcpy(dmi->processor.part_number,dmi_string(h, data[0x22])); break; + case 17: /* 3.3.18 Memory Device */ + if (h->length < 0x15) break; + dmi->memory_count++; + s_memory *mem = &dmi->memory[dmi->memory_count-1]; + dmi->memory[dmi->memory_count-1].filled=true; + dmi_memory_array_error_handle(WORD(data + 0x06),mem->error); + dmi_memory_device_width(WORD(data + 0x08),mem->total_width); + dmi_memory_device_width(WORD(data + 0x0A),mem->data_width); + dmi_memory_device_size(WORD(data + 0x0C),mem->size); + strcpy(mem->form_factor,dmi_memory_device_form_factor(data[0x0E])); + dmi_memory_device_set(data[0x0F],mem->device_set); + strcpy(mem->device_locator,dmi_string(h, data[0x10])); + strcpy(mem->bank_locator,dmi_string(h, data[0x11])); + strcpy(mem->type,dmi_memory_device_type(data[0x12])); + dmi_memory_device_type_detail(WORD(data + 0x13),mem->type_detail); + if (h->length < 0x17) break; + dmi_memory_device_speed(WORD(data + 0x15),mem->speed); + if (h->length < 0x1B) break; + strcpy(mem->manufacturer, dmi_string(h, data[0x17])); + strcpy(mem->serial,dmi_string(h, data[0x18])); + strcpy(mem->asset_tag,dmi_string(h, data[0x19])); + strcpy(mem->part_number,dmi_string(h, data[0x1A])); + break; + case 22: /* 3.3.23 Portable Battery */ + if (h->length < 0x10) break; + dmi->battery.filled=true; + strcpy(dmi->battery.location,dmi_string(h, data[0x04])); + strcpy(dmi->battery.manufacturer,dmi_string(h, data[0x05])); + + if (data[0x06] || h->length < 0x1A) + strcpy(dmi->battery.manufacture_date, dmi_string(h, data[0x06])); + + if (data[0x07] || h->length < 0x1A) + strcpy(dmi->battery.serial, dmi_string(h, data[0x07])); + + strcpy(dmi->battery.name,dmi_string(h, data[0x08])); + + if (data[0x09] != 0x02 || h->length < 0x1A) + strcpy(dmi->battery.chemistry,dmi_battery_chemistry(data[0x09])); + + if (h->length < 0x1A) + dmi_battery_capacity(WORD(data + 0x0A), 1,dmi->battery.design_capacity); + else + dmi_battery_capacity(WORD(data + 0x0A), data[0x15],dmi->battery.design_capacity); + dmi_battery_voltage(WORD(data + 0x0C),dmi->battery.design_voltage); + strcpy(dmi->battery.sbds,dmi_string(h, data[0x0E])); + dmi_battery_maximum_error(data[0x0F],dmi->battery.maximum_error); + if (h->length < 0x1A) break; + if (data[0x07] == 0) + sprintf(dmi->battery.sbds_serial,"%04X", WORD(data + 0x10)); + + if (data[0x06] == 0) + sprintf(dmi->battery.sbds_manufacture_date,"%u-%02u-%02u", + 1980 + (WORD(data + 0x12) >> 9), + (WORD(data + 0x12) >> 5) & 0x0F, + WORD(data + 0x12) & 0x1F); + if (data[0x09] == 0x02) + strcpy(dmi->battery.sbds_chemistry, dmi_string(h, data[0x14])); + + // sprintf(dmi->battery.oem_info,"0x%08X",DWORD(h, data+0x16)); + break; + + } } void parse_dmitable(s_dmi *dmi) { int i=0; - u8 *data = NULL; - u8 buf[dmitable.len]; + uint8_t *data = NULL; + uint8_t buf[dmi->dmitable.len]; - memcpy(buf,(int *)dmitable.base,sizeof(u8) * dmitable.len); + memcpy(buf,(int *)dmi->dmitable.base,sizeof(uint8_t) * dmi->dmitable.len); data=buf; - while(i<dmitable.num && data+4<=buf+dmitable.len) /* 4 is the length of an SMBIOS structure header */ { - u8 *next; + dmi->memory_count=0; + while(i<dmi->dmitable.num && data+4<=buf+dmi->dmitable.len) /* 4 is the length of an SMBIOS structure header */ { + uint8_t *next; struct dmi_header h; to_dmi_header(&h, data); @@ -488,16 +587,13 @@ void parse_dmitable(s_dmi *dmi) { /* loo for the next handle */ next=data+h.length; - while(next-buf+1<dmitable.len && (next[0]!=0 || next[1]!=0)) + while(next-buf+1<dmi->dmitable.len && (next[0]!=0 || next[1]!=0)) next++; next+=2; - if(next-buf<=dmitable.len) + if(next-buf<=dmi->dmitable.len) { - dmi_decode(&h, dmitable.ver,dmi); + dmi_decode(&h, dmi->dmitable.ver,dmi); } - else - printf("\t<TRUNCATED>\n"); - printf("\n"); data=next; i++; } diff --git a/com32/gpllib/dmi/dmi_base_board.c b/com32/gpllib/dmi/dmi_base_board.c new file mode 100644 index 00000000..f37feec9 --- /dev/null +++ b/com32/gpllib/dmi/dmi_base_board.c @@ -0,0 +1,38 @@ +/* ----------------------------------------------------------------------- * + * + * Pportions of this file taken from the dmidecode project + * + * Copyright (C) 2000-2002 Alan Cox <alan@redhat.com> + * Copyright (C) 2002-2008 Jean Delvare <khali@linux-fr.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * For the avoidance of doubt the "preferred form" of this code is one which + * is in an open unpatent encumbered format. Where cryptographic key signing + * forms part of the process of creating an executable the information + * including keys needed to generate an equivalently functional executable + * are deemed to be part of the source code. +*/ + +#include <dmi/dmi.h> +#include <stdio.h> +const char *base_board_features_strings[]={ + "Board is a hosting board", /* 0 */ + "Board requires at least one daughter board", + "Board is removable", + "Board is replaceable", + "Board is hot swappable" /* 4 */ +}; + diff --git a/com32/gpllib/dmi/dmi_battery.c b/com32/gpllib/dmi/dmi_battery.c new file mode 100644 index 00000000..567254a8 --- /dev/null +++ b/com32/gpllib/dmi/dmi_battery.c @@ -0,0 +1,73 @@ +/* ----------------------------------------------------------------------- * + * + * Pportions of this file taken from the dmidecode project + * + * Copyright (C) 2000-2002 Alan Cox <alan@redhat.com> + * Copyright (C) 2002-2008 Jean Delvare <khali@linux-fr.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * For the avoidance of doubt the "preferred form" of this code is one which + * is in an open unpatent encumbered format. Where cryptographic key signing + * forms part of the process of creating an executable the information + * including keys needed to generate an equivalently functional executable + * are deemed to be part of the source code. +*/ + +#include <dmi/dmi.h> +#include <stdio.h> +const char *dmi_battery_chemistry(uint8_t code) +{ + /* 3.3.23.1 */ + static const char *chemistry[] = { + "Other", /* 0x01 */ + "Unknown", + "Lead Acid", + "Nickel Cadmium", + "Nickel Metal Hydride", + "Lithium Ion", + "Zinc Air", + "Lithium Polymer" /* 0x08 */ + }; + + if (code >= 0x01 && code <= 0x08) + return chemistry[code - 0x01]; + return out_of_spec; +} + +void dmi_battery_capacity(uint16_t code, uint8_t multiplier,char *capacity) +{ + if (code == 0) + sprintf(capacity,"%s","Unknown"); + else + sprintf(capacity,"%u mWh", code * multiplier); +} + +void dmi_battery_voltage(uint16_t code, char *voltage) +{ + if (code == 0) + sprintf(voltage,"%s","Unknown"); + else + sprintf(voltage,"%u mV", code); +} + +void dmi_battery_maximum_error(uint8_t code, char *error) +{ + if (code == 0xFF) + sprintf(error,"%s","Unknown"); + else + sprintf(error,"%u%%", code); +} + diff --git a/com32/gpllib/dmi/dmi_bios.c b/com32/gpllib/dmi/dmi_bios.c new file mode 100644 index 00000000..9458d492 --- /dev/null +++ b/com32/gpllib/dmi/dmi_bios.c @@ -0,0 +1,80 @@ +/* ----------------------------------------------------------------------- * + * + * Pportions of this file taken from the dmidecode project + * + * Copyright (C) 2000-2002 Alan Cox <alan@redhat.com> + * Copyright (C) 2002-2008 Jean Delvare <khali@linux-fr.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * For the avoidance of doubt the "preferred form" of this code is one which + * is in an open unpatent encumbered format. Where cryptographic key signing + * forms part of the process of creating an executable the information + * including keys needed to generate an equivalently functional executable + * are deemed to be part of the source code. +*/ + +#include <dmi/dmi.h> +#include <stdio.h> + +const char *bios_charac_strings[]={ + "BIOS characteristics not supported", /* 3 */ + "ISA is supported", + "MCA is supported", + "EISA is supported", + "PCI is supported", + "PC Card (PCMCIA) is supported", + "PNP is supported", + "APM is supported", + "BIOS is upgradeable", + "BIOS shadowing is allowed", + "VLB is supported", + "ESCD support is available", + "Boot from CD is supported", + "Selectable boot is supported", + "BIOS ROM is socketed", + "Boot from PC Card (PCMCIA) is supported", + "EDD is supported", + "Japanese floppy for NEC 9800 1.2 MB is supported (int 13h)", + "Japanese floppy for Toshiba 1.2 MB is supported (int 13h)", + "5.25\"/360 KB floppy services are supported (int 13h)", + "5.25\"/1.2 MB floppy services are supported (int 13h)", + "3.5\"/720 KB floppy services are supported (int 13h)", + "3.5\"/2.88 MB floppy services are supported (int 13h)", + "Print screen service is supported (int 5h)", + "8042 keyboard services are supported (int 9h)", + "Serial services are supported (int 14h)", + "Printer services are supported (int 17h)", + "CGA/mono video services are supported (int 10h)", + "NEC PC-98" /* 31 */ +}; + +const char *bios_charac_x1_strings[]={ + "ACPI is supported", /* 0 */ + "USB legacy is supported", + "AGP is supported", + "I2O boot is supported", + "LS-120 boot is supported", + "ATAPI Zip drive boot is supported", + "IEEE 1394 boot is supported", + "Smart battery is supported" /* 7 */ +}; + +const char *bios_charac_x2_strings[]={ + "BIOS boot specification is supported", /* 0 */ + "Function key-initiated network boot is supported", + "Targeted content distribution is supported" /* 2 */ +}; + diff --git a/com32/include/dmi/dmi_chassis.h b/com32/gpllib/dmi/dmi_chassis.c index 1456ede9..6150016f 100644 --- a/com32/include/dmi/dmi_chassis.h +++ b/com32/gpllib/dmi/dmi_chassis.c @@ -1,47 +1,35 @@ /* ----------------------------------------------------------------------- * * - * Copyright 2006 Erwan Velu - All Rights Reserved + * Pportions of this file taken from the dmidecode project + * + * Copyright (C) 2000-2002 Alan Cox <alan@redhat.com> + * Copyright (C) 2002-2008 Jean Delvare <khali@linux-fr.org> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, Inc., 53 Temple Place Ste 330, - * Boston MA 02111-1307, USA; either version 2 of the License, or - * (at your option) any later version; incorporated herein by reference. + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * - * ----------------------------------------------------------------------- */ - -#ifndef DMI_CHASSIS_H -#define DMI_CHASSIS_H - -#define CHASSIS_MANUFACTURER_SIZE 32 -#define CHASSIS_TYPE_SIZE 16 -#define CHASSIS_LOCK_SIZE 16 -#define CHASSIS_VERSION_SIZE 16 -#define CHASSIS_SERIAL_SIZE 32 -#define CHASSIS_ASSET_TAG_SIZE 32 -#define CHASSIS_BOOT_UP_STATE_SIZE 32 -#define CHASSIS_POWER_SUPPLY_STATE_SIZE 32 -#define CHASSIS_THERMAL_STATE_SIZE 32 -#define CHASSIS_SECURITY_STATUS_SIZE 32 -#define CHASSIS_OEM_INFORMATION_SIZE 32 + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * For the avoidance of doubt the "preferred form" of this code is one which + * is in an open unpatent encumbered format. Where cryptographic key signing + * forms part of the process of creating an executable the information + * including keys needed to generate an equivalently functional executable + * are deemed to be part of the source code. +*/ -typedef struct { -char manufacturer[CHASSIS_MANUFACTURER_SIZE]; -char type[CHASSIS_TYPE_SIZE]; -char lock[CHASSIS_LOCK_SIZE]; -char version[CHASSIS_VERSION_SIZE]; -char serial[CHASSIS_SERIAL_SIZE]; -char asset_tag[CHASSIS_ASSET_TAG_SIZE]; -char boot_up_state[CHASSIS_BOOT_UP_STATE_SIZE]; -char power_supply_state[CHASSIS_POWER_SUPPLY_STATE_SIZE]; -char thermal_state[CHASSIS_THERMAL_STATE_SIZE]; -char security_status[CHASSIS_SECURITY_STATUS_SIZE]; -char oem_information[CHASSIS_OEM_INFORMATION_SIZE]; -u16 height; -u16 nb_power_cords; -} s_chassis; +#include <dmi/dmi.h> +#include <stdio.h> -static const char *dmi_chassis_type(u8 code) +const char *dmi_chassis_type(uint8_t code) { /* 3.3.4.1 */ static const char *type[]={ @@ -77,7 +65,7 @@ static const char *dmi_chassis_type(u8 code) return out_of_spec; } -static const char *dmi_chassis_lock(u8 code) +const char *dmi_chassis_lock(uint8_t code) { static const char *lock[]={ "Not Present", /* 0x00 */ @@ -87,7 +75,7 @@ static const char *dmi_chassis_lock(u8 code) return lock[code]; } -static const char *dmi_chassis_state(u8 code) +const char *dmi_chassis_state(uint8_t code) { /* 3.3.4.2 */ static const char *state[]={ @@ -104,7 +92,7 @@ static const char *dmi_chassis_state(u8 code) return out_of_spec; } -static const char *dmi_chassis_security_status(u8 code) +const char *dmi_chassis_security_status(uint8_t code) { /* 3.3.4.3 */ static const char *status[]={ @@ -119,5 +107,3 @@ static const char *dmi_chassis_security_status(u8 code) return(status[code-0x01]); return out_of_spec; } - -#endif diff --git a/com32/gpllib/dmi/dmi_memory.c b/com32/gpllib/dmi/dmi_memory.c new file mode 100644 index 00000000..dc354df1 --- /dev/null +++ b/com32/gpllib/dmi/dmi_memory.c @@ -0,0 +1,172 @@ +/* ----------------------------------------------------------------------- * + * + * Pportions of this file taken from the dmidecode project + * + * Copyright (C) 2000-2002 Alan Cox <alan@redhat.com> + * Copyright (C) 2002-2008 Jean Delvare <khali@linux-fr.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * For the avoidance of doubt the "preferred form" of this code is one which + * is in an open unpatent encumbered format. Where cryptographic key signing + * forms part of the process of creating an executable the information + * including keys needed to generate an equivalently functional executable + * are deemed to be part of the source code. +*/ + +#include <dmi/dmi.h> +#include <stdio.h> + +void dmi_memory_array_error_handle(uint16_t code,char *array) +{ + if (code == 0xFFFE) + sprintf(array,"%s","Not Provided"); + else if (code == 0xFFFF) + sprintf(array,"%s","No Error"); + else + sprintf(array,"0x%04X", code); +} + +void dmi_memory_device_width(uint16_t code, char *width) +{ + /* + * 3.3.18 Memory Device (Type 17) + * If no memory module is present, width may be 0 + */ + if (code == 0xFFFF || code == 0) + sprintf(width,"%s","Unknown"); + else + sprintf(width,"%u bits", code); +} + +void dmi_memory_device_size(uint16_t code, char *size) +{ + if (code == 0) + sprintf(size,"%s","Free"); + else if (code == 0xFFFF) + sprintf(size,"%s","Unknown"); + else { + if (code & 0x8000) + sprintf(size, "%u kB", code & 0x7FFF); + else + sprintf(size,"%u MB", code); + } +} + +const char *dmi_memory_device_form_factor(uint8_t code) +{ + /* 3.3.18.1 */ + static const char *form_factor[] = { + "Other", /* 0x01 */ + "Unknown", + "SIMM", + "SIP", + "Chip", + "DIP", + "ZIP", + "Proprietary Card", + "DIMM", + "TSOP", + "Row Of Chips", + "RIMM", + "SODIMM", + "SRIMM", + "FB-DIMM" /* 0x0F */ + }; + + if (code >= 0x01 && code <= 0x0F) + return form_factor[code - 0x01]; + return out_of_spec; +} + +void dmi_memory_device_set(uint8_t code, char *set) +{ + if (code == 0) + sprintf(set,"%s","None"); + else if (code == 0xFF) + sprintf(set,"%s","Unknown"); + else + sprintf(set,"%u", code); +} + +const char *dmi_memory_device_type(uint8_t code) +{ + /* 3.3.18.2 */ + static const char *type[] = { + "Other", /* 0x01 */ + "Unknown", + "DRAM", + "EDRAM", + "VRAM", + "SRAM", + "RAM", + "ROM", + "Flash", + "EEPROM", + "FEPROM", + "EPROM", + "CDRAM", + "3DRAM", + "SDRAM", + "SGRAM", + "RDRAM", + "DDR", + "DDR2", + "DDR2 FB-DIMM" /* 0x14 */ + }; + + if (code >= 0x01 && code <= 0x14) + return type[code - 0x01]; + return out_of_spec; +} + +void dmi_memory_device_type_detail(uint16_t code,char *type_detail) +{ + /* 3.3.18.3 */ + static const char *detail[] = { + "Other", /* 1 */ + "Unknown", + "Fast-paged", + "Static Column", + "Pseudo-static", + "RAMBus", + "Synchronous", + "CMOS", + "EDO", + "Window DRAM", + "Cache DRAM", + "Non-Volatile" /* 12 */ + }; + + if ((code & 0x1FFE) == 0) + sprintf(type_detail,"%s","None"); + else + { + int i; + + for (i = 1; i <= 12; i++) + if (code & (1 << i)) + sprintf(type_detail,"%s", detail[i - 1]); + } +} + +void dmi_memory_device_speed(uint16_t code, char *speed) +{ + if (code == 0) + sprintf(speed,"%s","Unknown"); + else + sprintf(speed,"%u MHz", code); +} + diff --git a/com32/gpllib/dmi/dmi_processor.c b/com32/gpllib/dmi/dmi_processor.c new file mode 100644 index 00000000..f86f0095 --- /dev/null +++ b/com32/gpllib/dmi/dmi_processor.c @@ -0,0 +1,433 @@ +/* ----------------------------------------------------------------------- * + * + * Pportions of this file taken from the dmidecode project + * + * Copyright (C) 2000-2002 Alan Cox <alan@redhat.com> + * Copyright (C) 2002-2008 Jean Delvare <khali@linux-fr.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * For the avoidance of doubt the "preferred form" of this code is one which + * is in an open unpatent encumbered format. Where cryptographic key signing + * forms part of the process of creating an executable the information + * including keys needed to generate an equivalently functional executable + * are deemed to be part of the source code. +*/ + +#include <dmi/dmi.h> +#include <stdio.h> + +const char *dmi_processor_type(uint8_t code) +{ + /* 3.3.5.1 */ + static const char *type[]={ + "Other", /* 0x01 */ + "Unknown", + "Central Processor", + "Math Processor", + "DSP Processor", + "Video Processor" /* 0x06 */ + }; + + if(code>=0x01 && code<=0x06) + return type[code-0x01]; + return out_of_spec; +} + +const char *dmi_processor_family(uint8_t code, char *manufacturer) +{ + /* 3.3.5.2 */ + static const char *family[]={ + NULL, /* 0x00 */ + "Other", + "Unknown", + "8086", + "80286", + "80386", + "80486", + "8087", + "80287", + "80387", + "80487", + "Pentium", + "Pentium Pro", + "Pentium II", + "Pentium MMX", + "Celeron", + "Pentium II Xeon", + "Pentium III", + "M1", + "M2", + "Celeron M", /* 0x14 */ + "Pentium 4 HT", + NULL, + NULL, /* 0x17 */ + "Duron", + "K5", + "K6", + "K6-2", + "K6-3", + "Athlon", + "AMD2900", + "K6-2+", + "Power PC", + "Power PC 601", + "Power PC 603", + "Power PC 603+", + "Power PC 604", + "Power PC 620", + "Power PC x704", + "Power PC 750", + "Core 2 Duo", /* 0x28 */ + "Core 2 Duo Mobile", + "Core Solo Mobile", + "Atom", + NULL, + NULL, + NULL, + NULL,/* 0x2F */ + "Alpha", + "Alpha 21064", + "Alpha 21066", + "Alpha 21164", + "Alpha 21164PC", + "Alpha 21164a", + "Alpha 21264", + "Alpha 21364", + NULL, /* 0x38 */ + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, /* 0x3F */ + "MIPS", + "MIPS R4000", + "MIPS R4200", + "MIPS R4400", + "MIPS R4600", + "MIPS R10000", + NULL, /* 0x46 */ + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, /* 0x4F */ + "SPARC", + "SuperSPARC", + "MicroSPARC II", + "MicroSPARC IIep", + "UltraSPARC", + "UltraSPARC II", + "UltraSPARC IIi", + "UltraSPARC III", + "UltraSPARC IIIi", + NULL, /* 0x59 */ + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, /* 0x5F */ + "68040", + "68xxx", + "68000", + "68010", + "68020", + "68030", + NULL, /* 0x66 */ + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, /* 0x6F */ + "Hobbit", + NULL, /* 0x71 */ + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, /* 0x77 */ + "Crusoe TM5000", + "Crusoe TM3000", + "Efficeon TM8000", + NULL, /* 0x7B */ + NULL, + NULL, + NULL, + NULL, /* 0x7F */ + "Weitek", + NULL, /* 0x81 */ + "Itanium", + "Athlon 64", + "Opteron", + "Sempron", + "Turion 64", /* 0x86 */ + "Dual-Core Opteron", + "Atlhon 64 X2", + "Turion 64 X2", + "Quad-Core Opteron", + "Third-Generation Opteron", + "Phenom FX", + "Phenom X4", + "Phenom X2", + "Athlon X2",/* 0x8F */ + "PA-RISC", + "PA-RISC 8500", + "PA-RISC 8000", + "PA-RISC 7300LC", + "PA-RISC 7200", + "PA-RISC 7100LC", + "PA-RISC 7100", + NULL, /* 0x97 */ + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, /* 0x9F */ + "V30", + "Quad-Core Xeon 3200", /* 0xA1 */ + "Dual-Core Xeon 3000", + "Quad-Core Xeon 5300", + "Dual-Core Xeon 5100", + "Dual-Core Xeon 5000", + "Dual-Core Xeon LV", + "Dual-Core Xeon ULV", + "Dual-Core Xeon 7100", + "Quad-Core Xeon 5400", + "Quad-Core Xeon", /* 0xAA */ + NULL, + NULL, + NULL, + NULL, + NULL, /* 0xAF */ + "Pentium III Xeon", + "Pentium III Speedstep", + "Pentium 4", + "Xeon", + "AS400", + "Xeon MP", + "Athlon XP", + "Athlon MP", + "Itanium 2", + "Pentium M", + "Celeron D", /* 0xBA */ + "Pentium D", + "Pentium EE", + "Core Solo", /* 0xBD */ + NULL, + "Core 2 Duo", + "Core 2 Solo", + "Core 2 Extreme", + "Core 2 Quad", + "Core 2 Extreme Mobile", + "Core 2 Duo Mobile", + "Core 2 Solo Mobile", + NULL, + NULL, /* 0xC7 */ + "IBM390", + "G4", + "G5", + "ESA/390 G6", /* 0xCB */ + "z/Architectur", + NULL, + NULL, + NULL, + NULL, /*0xD0*/ + NULL, + "C7-M", + "C7-D", + "C7", + "Eden", + NULL,/*0xD6*/ + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, /*0xE0*/ + NULL, + NULL, + NULL, + NULL, + NULL, + "Embedded Opteron Quad-Core",/* 0xE6*/ + "Phenom Triple-Core" , + "Turion Ultra Dual-Core Mobile", + "Turion Dual-Core Mobile", + "Athlon Dual-Core", + "Sempron SI",/*0xEB*/ + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, /* 0xF9 */ + "i860", + "i960", + NULL, /* 0xFC */ + NULL, + NULL, + NULL /* 0xFF */ + /* master.mif has values beyond that, but they can't be used for DMI */ + }; + /* Special case for ambiguous value 0xBE */ + if (code == 0xBE) + { + /* Best bet based on manufacturer string */ + if (strstr(manufacturer, "Intel") != NULL + || strncasecmp(manufacturer, "Intel", 5) == 0) + return "Core 2"; + if (strstr(manufacturer, "AMD") != NULL + || strncasecmp(manufacturer, "AMD", 3) == 0) + return "K7"; + return "Core 2 or K7"; + } + + if(family[code]!=NULL) { + return family[code]; + } + return out_of_spec; +} + +const char *dmi_processor_status(uint8_t code) +{ + static const char *status[]={ + "Unknown", /* 0x00 */ + "Enabled", + "Disabled By User", + "Disabled By BIOS", + "Idle", /* 0x04 */ + "<OUT OF SPEC>", + "<OUT OF SPEC>", + "Other" /* 0x07 */ + }; + + if(code<=0x04) + return status[code]; + if(code==0x07) + return status[0x05]; + return out_of_spec; +} + +const char *dmi_processor_upgrade(uint8_t code) +{ + /* 3.3.5.5 */ + static const char *upgrade[]={ + "Other", /* 0x01 */ + "Unknown", + "Daughter Board", + "ZIF Socket", + "Replaceable Piggy Back", + "None", + "LIF Socket", + "Slot 1", + "Slot 2", + "370-pin Socket", + "Slot A", + "Slot M", + "Socket 423", + "Socket A (Socket 462)", + "Socket 478", + "Socket 754", + "Socket 940", + "Socket 939" /* 0x12 */ + "Socket mPGA604", + "Socket LGA771", + "Socket LGA775", + "Socket S1", + "Socket AM2", + "Socket F (1207)" + }; + + if(code>=0x01 && code<=0x11) + return upgrade[code-0x01]; + return out_of_spec; +} + +void dmi_processor_cache(uint16_t code, const char *level, uint16_t ver, char *cache) +{ + if(code==0xFFFF) + { + if(ver>=0x0203) + sprintf(cache,"Not Provided"); + else + sprintf(cache,"No %s Cache", level); + } + else + sprintf(cache,"0x%04X", code); +} + +/* Intel AP-485 revision 28, table 5 */ +const char *cpu_flags_strings[PROCESSOR_FLAGS_ELEMENTS]={ + "FPU (Floating-point unit on-chip)", /* 0 */ + "VME (Virtual mode extension)", + "DE (Debugging extension)", + "PSE (Page size extension)", + "TSC (Time stamp counter)", + "MSR (Model specific registers)", + "PAE (Physical address extension)", + "MCE (Machine check exception)", + "CX8 (CMPXCHG8 instruction supported)", + "APIC (On-chip APIC hardware supported)", + NULL, /* 10 */ + "SEP (Fast system call)", + "MTRR (Memory type range registers)", + "PGE (Page global enable)", + "MCA (Machine check architecture)", + "CMOV (Conditional move instruction supported)", + "PAT (Page attribute table)", + "PSE-36 (36-bit page size extension)", + "PSN (Processor serial number present and enabled)", + "CLFSH (CLFLUSH instruction supported)", + NULL, /* 20 */ + "DS (Debug store)", + "ACPI (ACPI supported)", + "MMX (MMX technology supported)", + "FXSR (Fast floating-point save and restore)", + "SSE (Streaming SIMD extensions)", + "SSE2 (Streaming SIMD extensions 2)", + "SS (Self-snoop)", + "HTT (Hyper-threading technology)", + "TM (Thermal monitor supported)", + "IA64 (IA64 capabilities)", /* 30 */ + "PBE (Pending break enabled)" /* 31 */ +}; + diff --git a/com32/hdt/Makefile b/com32/hdt/Makefile new file mode 100644 index 00000000..58715071 --- /dev/null +++ b/com32/hdt/Makefile @@ -0,0 +1,75 @@ +## ----------------------------------------------------------------------- +## +## Copyright 2001-2008 H. Peter Anvin - All Rights Reserved +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation, Inc., 53 Temple Place Ste 330, +## Boston MA 02111-1307, USA; either version 2 of the License, or +## (at your option) any later version; incorporated herein by reference. +## +## ----------------------------------------------------------------------- + +## +## samples for syslinux users +## + +topdir = ../.. +include $(topdir)/MCONFIG.embedded + +INCLUDES = -I$(com32)/include -I$(com32)/cmenu/libmenu -I$(com32)/gplinclude + +LIBGCC := $(shell $(CC) $(GCCOPT) --print-libgcc) +LIB = liboldcom32.a + +com32 = $(topdir)/com32 +LIBS = $(LIB) $(com32)/cmenu/libmenu/libmenu.a \ + $(com32)/gpllib/libcom32gpl.a \ + $(com32)/libutil/libutil_com.a $(com32)/lib/libcom32.a \ + $(LIBGCC) + +LDFLAGS = -m elf_i386 -T $(com32)/lib/com32.ld + +all: hdt.c32 $(LIB) + +.PRECIOUS: %.o +%.o: %.S + $(CC) $(SFLAGS) -c -o $@ $< + +.PRECIOUS: %.o +%.o: %.c + $(CC) $(CFLAGS) -std=gnu99 -D__COM32__ -c -o $@ $< + +.PRECIOUS: %.elf +%.elf: c32entry.o %.o $(LIB) + $(LD) -Ttext 0x101000 -e _start -o $@ $^ + +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-cpu.o hdt-cli-pxe.o hdt-cli-kernel.o \ + hdt-cli-syslinux.o \ + hdt-menu-pxe.o hdt-menu-summary.o\ + $(LIBS) + $(LD) $(LDFLAGS) -o $@ $^ + +%.c32: %.elf + $(OBJCOPY) -O binary $< $@ + +%.com: %.asm + $(NASM) $(NASMOPT) -f bin -o $@ -l $*.lst $< + +$(LIB): + rm -f $@ + $(AR) cq $@ $^ + $(RANLIB) $@ + +tidy dist: + rm -f *.o *.a *.lst *.elf + +# Don't specify *.com since mdiskchk.com can't be built using Linux tools +clean: tidy + rm -f *.o *.c32 *.c~ *.h~ Makefile~ + +spotless: clean diff --git a/com32/hdt/hdt-ata.c b/com32/hdt/hdt-ata.c new file mode 100644 index 00000000..a5000609 --- /dev/null +++ b/com32/hdt/hdt-ata.c @@ -0,0 +1,254 @@ +/* ----------------------------------------------------------------------- * + * + * 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 <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <console.h> +#include "com32io.h" +#include "hdt-ata.h" + +#ifdef ATA +/** + * ata_id_string - Convert IDENTIFY DEVICE page into string + * @id: IDENTIFY DEVICE results we will examine + * @s: string into which data is output + * @ofs: offset into identify device page + * @len: length of string to return. must be an even number. + * + * The strings in the IDENTIFY DEVICE page are broken up into + * 16-bit chunks. Run through the string, and output each + * 8-bit chunk linearly, regardless of platform. + * + * LOCKING: + * caller. + */ + +void ata_id_string(const uint16_t *id, unsigned char *s, + unsigned int ofs, unsigned int len) +{ + unsigned int c; + + while (len > 0) { + c = id[ofs] >> 8; + *s = c; + s++; + + c = id[ofs] & 0xff; + *s = c; + s++; + + ofs++; + len -= 2; + } +} + +/** + * ata_id_c_string - Convert IDENTIFY DEVICE page into C string + * @id: IDENTIFY DEVICE results we will examine + * @s: string into which data is output + * @ofs: offset into identify device page + * @len: length of string to return. must be an odd number. + * + * This function is identical to ata_id_string except that it + * trims trailing spaces and terminates the resulting string with + * null. @len must be actual maximum length (even number) + 1. + * + * LOCKING: + * caller. + */ +void ata_id_c_string(const uint16_t *id, unsigned char *s, + unsigned int ofs, unsigned int len) +{ + unsigned char *p; + + //WARN_ON(!(len & 1)); + + ata_id_string(id, s, ofs, len - 1); + + p = s + strnlen(s, len - 1); + while (p > s && p[-1] == ' ') + p--; + *p = '\0'; +} +#endif + +/* + * Call int 13h, but with retry on failure. Especially floppies need this. + */ +int int13_retry(const com32sys_t *inreg, com32sys_t *outreg) +{ + int retry = 6; /* Number of retries */ + com32sys_t tmpregs; + + if ( !outreg ) outreg = &tmpregs; + + while ( retry-- ) { + __intcall(0x13, inreg, outreg); + if ( !(outreg->eflags.l & EFLAGS_CF) ) + return 0; /* CF=0, OK */ + } + + return -1; /* Error */ +} + +/* Display CPU registers for debugging purposes */ +void printregs(const com32sys_t *r) +{ + printf("eflags = %08x ds = %04x es = %04x fs = %04x gs = %04x\n" + "eax = %08x ebx = %08x ecx = %08x edx = %08x\n" + "ebp = %08x esi = %08x edi = %08x esp = %08x\n", + r->eflags.l, r->ds, r->es, r->fs, r->gs, + r->eax.l, r->ebx.l, r->ecx.l, r->edx.l, + r->ebp.l, r->esi.l, r->edi.l, r->_unused_esp.l); +} + +/* Try to get information for a given disk*/ +int get_disk_params(int disk, struct diskinfo *disk_info) +{ + static com32sys_t getparm, parm, getebios, ebios, inreg,outreg; + struct device_parameter dp; +#ifdef ATA + struct ata_identify_device aid; +#endif + + memset(&(disk_info[disk]), 0, sizeof(struct diskinfo)); + + disk_info[disk].disk = disk; + disk_info[disk].ebios = disk_info[disk].cbios = 0; + + /* Sending int 13h func 41h to query EBIOS information*/ + memset(&getebios, 0, sizeof (com32sys_t)); + memset(&ebios, 0, sizeof (com32sys_t)); + + /* Get EBIOS support */ + getebios.eax.w[0] = 0x4100; + getebios.ebx.w[0] = 0x55aa; + getebios.edx.b[0] = disk; + getebios.eflags.b[0] = 0x3; /* CF set */ + + __intcall(0x13, &getebios, &ebios); + + /* Detecting EDD support */ + if ( !(ebios.eflags.l & EFLAGS_CF) && + ebios.ebx.w[0] == 0xaa55 && + (ebios.ecx.b[0] & 1) ) { + disk_info[disk].ebios = 1; + switch(ebios.eax.b[1]) { + case 32: strlcpy(disk_info[disk].edd_version,"1.0",3); break; + case 33: strlcpy(disk_info[disk].edd_version,"1.1",3); break; + case 48: strlcpy(disk_info[disk].edd_version,"3.0",3); break; + default: strlcpy(disk_info[disk].edd_version,"0",1); break; + } + } + /* Get disk parameters -- really only useful for + hard disks, but if we have a partitioned floppy + it's actually our best chance... */ + memset(&getparm, 0, sizeof (com32sys_t)); + memset(&parm, 0, sizeof (com32sys_t)); + getparm.eax.b[1] = 0x08; + getparm.edx.b[0] = disk; + + __intcall(0x13, &getparm, &parm); + + if ( parm.eflags.l & EFLAGS_CF ) + return disk_info[disk].ebios ? 0 : -1; + + disk_info[disk].heads = parm.edx.b[1]+1; + disk_info[disk].sectors_per_track = parm.ecx.b[0] & 0x3f; + if ( disk_info[disk].sectors_per_track == 0 ) { + disk_info[disk].sectors_per_track = 1; + } else { + disk_info[disk].cbios = 1; /* Valid geometry */ + } + +/* FIXME: memset to 0 make it fails + * memset(__com32.cs_bounce, 0, sizeof(struct device_pairameter)); */ + memset(&dp, 0, sizeof(struct device_parameter)); + memset(&inreg, 0, sizeof(com32sys_t)); + + /* Requesting Extended Read Drive Parameters via int13h func 48h*/ + inreg.esi.w[0] = OFFS(__com32.cs_bounce); + inreg.ds = SEG(__com32.cs_bounce); + inreg.eax.w[0] = 0x4800; + inreg.edx.b[0] = disk; + + __intcall(0x13, &inreg, &outreg); + + /* Saving bounce buffer before anything corrupt it */ + memcpy(&dp, __com32.cs_bounce, sizeof (struct device_parameter)); + + if ( outreg.eflags.l & EFLAGS_CF) { + printf("Disk 0x%X doesn't supports EDD 3.0\n",disk); + return -1; + } + + /* Copying result to the disk_info structure + * host_bus_type, interface_type, sectors & cylinders */ + snprintf(disk_info[disk].host_bus_type,sizeof disk_info[disk].host_bus_type,"%c%c%c%c",dp.host_bus_type[0],dp.host_bus_type[1],dp.host_bus_type[2],dp.host_bus_type[3]); + snprintf(disk_info[disk].interface_type,sizeof disk_info[disk].interface_type,"%c%c%c%c%c%c%c%c",dp.interface_type[0],dp.interface_type[1],dp.interface_type[2],dp.interface_type[3],dp.interface_type[4],dp.interface_type[5],dp.interface_type[6],dp.interface_type[7]); + disk_info[disk].sectors=dp.sectors; + disk_info[disk].cylinders=dp.cylinders; + + /*FIXME: we have to find a way to grab the model & fw + * We do put dummy data until we found a solution */ + snprintf(disk_info[disk].aid.model,sizeof disk_info[disk].aid.model,"0x%X",disk); + snprintf(disk_info[disk].aid.fw_rev,sizeof disk_info[disk].aid.fw_rev,"%s","N/A"); + snprintf(disk_info[disk].aid.serial_no,sizeof disk_info[disk].aid.serial_no,"%s","N/A"); + + /* Useless stuff before I figure how to send ata packets */ +#ifdef ATA + memset(__com32.cs_bounce, 0, sizeof(struct device_parameter)); + memset(&aid, 0, sizeof(struct ata_identify_device)); + memset(&inreg, 0, sizeof inreg); + inreg.ebx.w[0] = OFFS(__com32.cs_bounce+1024); + inreg.es = SEG(__com32.cs_bounce+1024); + inreg.eax.w[0] = 0x2500; + inreg.edx.b[0] = disk; + + __intcall(0x13,&inreg, &outreg); + + memcpy(&aid, __com32.cs_bounce, sizeof (struct ata_identify_device)); + + if ( outreg.eflags.l & EFLAGS_CF) { + printf("Disk 0x%X: Failed to Identify Device\n",disk); + //FIXME + return 0; + } +// ata_id_c_string(aid, disk_info[disk].fwrev, ATA_ID_FW_REV, sizeof(disk_info[disk].fwrev)); +// ata_id_c_string(aid, disk_info[disk].model, ATA_ID_PROD, sizeof(disk_info[disk].model)); + + char buff[sizeof(struct ata_identify_device)]; + memcpy(buff,&aid, sizeof (struct ata_identify_device)); + for (int j=0;j<sizeof(struct ata_identify_device);j++) + printf ("model=|%c|\n",buff[j]); + printf ("Disk 0x%X : %s %s %s\n",disk, aid.model, aid.fw_rev,aid.serial_no); +#endif + +return 0; +} + diff --git a/com32/hdt/hdt-ata.h b/com32/hdt/hdt-ata.h new file mode 100644 index 00000000..7236c549 --- /dev/null +++ b/com32/hdt/hdt-ata.h @@ -0,0 +1,121 @@ +/* ----------------------------------------------------------------------- * + * + * 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_ATA_H +#define DEFINE_HDT_ATA_H + +#include "hdt.h" +#include <com32io.h> + +struct ata_identify_device { + unsigned short words000_009[10]; + unsigned char serial_no[20]; + unsigned short words020_022[3]; + unsigned char fw_rev[8]; + unsigned char model[40]; + unsigned short words047_079[33]; + unsigned short major_rev_num; + unsigned short minor_rev_num; + unsigned short command_set_1; + unsigned short command_set_2; + unsigned short command_set_extension; + unsigned short cfs_enable_1; + unsigned short word086; + unsigned short csf_default; + unsigned short words088_255[168]; +} ATTR_PACKED; + +struct diskinfo { + int disk; + int ebios; /* EBIOS supported on this disk */ + int cbios; /* CHS geometry is valid */ + int heads; + int sectors_per_track; + int sectors; + int cylinders; + char edd_version[4]; + struct ata_identify_device aid; /* IDENTIFY xxx DEVICE data */ + char host_bus_type[5]; + char interface_type[9]; + char interface_port; +} ATTR_PACKED; + +/* + * Get a disk block and return a malloc'd buffer. + * Uses the disk number and information from disk_info. + */ +struct ebios_dapa { + uint16_t len; + uint16_t count; + uint16_t off; + uint16_t seg; + uint64_t lba; +}; + +// BYTE=8 +// WORD=16 +// DWORD=32 +// QWORD=64 +struct device_parameter { + uint16_t len; + uint16_t info; + uint32_t cylinders; + uint32_t heads; + uint32_t sectors_per_track; + uint64_t sectors; + uint16_t bytes_per_sector; + uint32_t dpte_pointer; + uint16_t device_path_information; + uint8_t device_path_lenght; + uint8_t device_path_reserved; + uint16_t device_path_reserved_2; + uint8_t host_bus_type[4]; + uint8_t interface_type[8]; + uint64_t interace_path; + uint64_t device_path[2]; + uint8_t reserved; + uint8_t cheksum; +} ATTR_PACKED; + + +/* Useless stuff until I manage how to send ata packets */ +#ifdef ATA +enum { + ATA_ID_FW_REV = 23, + ATA_ID_PROD = 27, + ATA_ID_FW_REV_LEN = 8, + ATA_ID_PROD_LEN = 40, +}; +void ata_id_c_string(const uint16_t *id, unsigned char *s, unsigned int ofs, unsigned int len); +void ata_id_string(const uint16_t *id, unsigned char *s, unsigned int ofs, unsigned int len); +int int13_retry(const com32sys_t *inreg, com32sys_t *outreg); +void printregs(const com32sys_t *r); +#endif + +int get_disk_params(int disk, struct diskinfo *disk_info); +#endif diff --git a/com32/hdt/hdt-cli-cpu.c b/com32/hdt/hdt-cli-cpu.c new file mode 100644 index 00000000..edeef24a --- /dev/null +++ b/com32/hdt/hdt-cli-cpu.c @@ -0,0 +1,151 @@ +/* ----------------------------------------------------------------------- * + * + * 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 show_cpu_help() { + more_printf("Show supports the following commands : %s\n",CLI_CPU); +} + +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(); +} + +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) { + 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); + } + +} + + diff --git a/com32/hdt/hdt-cli-dmi.c b/com32/hdt/hdt-cli-dmi.c new file mode 100644 index 00000000..c9820657 --- /dev/null +++ b/com32/hdt/hdt-cli-dmi.c @@ -0,0 +1,360 @@ +/* ----------------------------------------------------------------------- * + * + * 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_dmi_help(struct s_hardware *hardware) { + more_printf("Show supports the following commands : \n"); + more_printf(" %s\n",CLI_SHOW_LIST); + more_printf(" <module_name>\n"); + more_printf(" -\n"); + show_dmi_modules(hardware); +} + + +void dmi_show(char *item, struct s_hardware *hardware) { + if ( !strncmp(item, CLI_DMI_BASE_BOARD, sizeof(CLI_DMI_BASE_BOARD) - 1) ) { + show_dmi_base_board(hardware); + return; + } + if ( !strncmp(item, CLI_DMI_SYSTEM, sizeof(CLI_DMI_SYSTEM) - 1) ) { + show_dmi_system(hardware); + return; + } + if ( !strncmp(item, CLI_DMI_BIOS, sizeof(CLI_DMI_BIOS) - 1) ) { + show_dmi_bios(hardware); + return; + } + if ( !strncmp(item, CLI_DMI_CHASSIS, sizeof(CLI_DMI_CHASSIS) - 1) ) { + show_dmi_chassis(hardware); + return; + } + if ( !strncmp(item, CLI_DMI_PROCESSOR, sizeof(CLI_DMI_PROCESSOR) - 1) ) { + show_dmi_cpu(hardware); + return; + } + if ( !strncmp(item, CLI_DMI_MEMORY, sizeof(CLI_DMI_MEMORY) - 1) ) { + show_dmi_memory_modules(hardware,true,true); + return; + } + if ( !strncmp(item, CLI_DMI_MEMORY_BANK, sizeof(CLI_DMI_MEMORY_BANK) - 1) ) { + show_dmi_memory_bank(hardware,item+ sizeof(CLI_DMI_MEMORY_BANK)-1); + return; + } + if ( !strncmp(item, CLI_SHOW_LIST, sizeof(CLI_SHOW_LIST) - 1) ) { + show_dmi_modules(hardware); + return; + } + if ( !strncmp(item, CLI_DMI_BATTERY, sizeof(CLI_DMI_BATTERY) - 1) ) { + show_dmi_battery(hardware); + return; + } + + show_dmi_help(hardware); +} + +void handle_dmi_commands(char *cli_line, struct s_cli_mode *cli_mode, struct s_hardware *hardware) { + if ( !strncmp(cli_line, CLI_SHOW, sizeof(CLI_SHOW) - 1) ) { + dmi_show(strstr(cli_line,"show")+ sizeof(CLI_SHOW), hardware); + return; + } +} + +void show_dmi_modules(struct s_hardware *hardware) { + char available_dmi_commands[1024]; + memset(available_dmi_commands,0,sizeof(available_dmi_commands)); + + if (hardware->dmi.base_board.filled==true) { + strncat(available_dmi_commands,CLI_DMI_BASE_BOARD,sizeof(CLI_DMI_BASE_BOARD)-1); + strncat(available_dmi_commands," ",1); + } + if (hardware->dmi.battery.filled==true) { + strncat(available_dmi_commands,CLI_DMI_BATTERY,sizeof(CLI_DMI_BATTERY)-1); + strncat(available_dmi_commands," ",1); + } + if (hardware->dmi.bios.filled==true) { + strncat(available_dmi_commands,CLI_DMI_BIOS,sizeof(CLI_DMI_BIOS)-1); + strncat(available_dmi_commands," ",1); + } + if (hardware->dmi.chassis.filled==true) { + strncat(available_dmi_commands,CLI_DMI_CHASSIS,sizeof(CLI_DMI_CHASSIS)-1); + strncat(available_dmi_commands," ",1); + } + for (int i=0;i<hardware->dmi.memory_count;i++) { + if (hardware->dmi.memory[i].filled==true) { + strncat(available_dmi_commands,CLI_DMI_MEMORY,sizeof(CLI_DMI_MEMORY)-1); + strncat(available_dmi_commands," bank<bank_number> ",19); + break; + } + } + if (hardware->dmi.processor.filled==true) { + strncat(available_dmi_commands,CLI_DMI_PROCESSOR,sizeof(CLI_DMI_PROCESSOR)-1); + strncat(available_dmi_commands," ",1); + } + if (hardware->dmi.system.filled==true) { + strncat(available_dmi_commands,CLI_DMI_SYSTEM,sizeof(CLI_DMI_SYSTEM)-1); + strncat(available_dmi_commands," ",1); + } + printf("Available DMI modules: %s\n",available_dmi_commands); +} + +void main_show_dmi(struct s_hardware *hardware,struct s_cli_mode *cli_mode) { + + detect_dmi(hardware); + + if (hardware->is_dmi_valid==false) { + printf("No valid DMI table found, exiting.\n"); + do_exit(cli_mode); + return; + } + printf("DMI Table version %d.%d found\n",hardware->dmi.dmitable.major_version,hardware->dmi.dmitable.minor_version); + + show_dmi_modules(hardware); +} + + +void show_dmi_base_board(struct s_hardware *hardware) { + if (hardware->dmi.base_board.filled==false) { + printf("Base_board module not available\n"); + return; + } + clear_screen(); + more_printf("Base board\n"); + more_printf(" Manufacturer : %s\n",hardware->dmi.base_board.manufacturer); + more_printf(" Product Name : %s\n",hardware->dmi.base_board.product_name); + more_printf(" Version : %s\n",hardware->dmi.base_board.version); + more_printf(" Serial : %s\n",hardware->dmi.base_board.serial); + more_printf(" Asset Tag : %s\n",hardware->dmi.base_board.asset_tag); + more_printf(" Location : %s\n",hardware->dmi.base_board.location); + more_printf(" Type : %s\n",hardware->dmi.base_board.type); + for (int i=0;i<BASE_BOARD_NB_ELEMENTS; i++) { + if (((bool *)(& hardware->dmi.base_board.features))[i] == true) { + more_printf(" %s\n", base_board_features_strings[i]); + } + } +} + +void show_dmi_system(struct s_hardware *hardware) { + if (hardware->dmi.system.filled==false) { + printf("System module not available\n"); + return; + } + clear_screen(); + more_printf("System\n"); + more_printf(" Manufacturer : %s\n",hardware->dmi.system.manufacturer); + more_printf(" Product Name : %s\n",hardware->dmi.system.product_name); + more_printf(" Version : %s\n",hardware->dmi.system.version); + more_printf(" Serial : %s\n",hardware->dmi.system.serial); + more_printf(" UUID : %s\n",hardware->dmi.system.uuid); + more_printf(" Wakeup Type : %s\n",hardware->dmi.system.wakeup_type); + more_printf(" SKU Number : %s\n",hardware->dmi.system.sku_number); + more_printf(" Family : %s\n",hardware->dmi.system.family); +} + +void show_dmi_bios(struct s_hardware *hardware) { + if (hardware->dmi.bios.filled==false) { + printf("Bios module not available\n"); + return; + } + clear_screen(); + more_printf("BIOS\n"); + more_printf(" Vendor : %s\n",hardware->dmi.bios.vendor); + more_printf(" Version : %s\n",hardware->dmi.bios.version); + more_printf(" Release : %s\n",hardware->dmi.bios.release_date); + more_printf(" Bios Revision : %s\n",hardware->dmi.bios.bios_revision); + more_printf(" Firmware Revision : %s\n",hardware->dmi.bios.firmware_revision); + more_printf(" Address : 0x%04X0\n",hardware->dmi.bios.address); + more_printf(" Runtime address : %u %s\n",hardware->dmi.bios.runtime_size,hardware->dmi.bios.runtime_size_unit); + more_printf(" Rom size : %u %s\n",hardware->dmi.bios.rom_size,hardware->dmi.bios.rom_size_unit); + + for (int i=0;i<BIOS_CHAR_NB_ELEMENTS; i++) { + if (((bool *)(& hardware->dmi.bios.characteristics))[i] == true) { + more_printf(" %s\n", bios_charac_strings[i]); + } + } + for (int i=0;i<BIOS_CHAR_X1_NB_ELEMENTS; i++) { + if (((bool *)(& hardware->dmi.bios.characteristics_x1))[i] == true) { + more_printf(" %s\n", bios_charac_x1_strings[i]); + } + } + + for (int i=0;i<BIOS_CHAR_X2_NB_ELEMENTS; i++) { + if (((bool *)(& hardware->dmi.bios.characteristics_x2))[i] == true) { + more_printf(" %s\n", bios_charac_x2_strings[i]); + } + } + +} + +void show_dmi_chassis(struct s_hardware *hardware) { + if (hardware->dmi.chassis.filled==false) { + printf("Chassis module not available\n"); + return; + } + clear_screen(); + more_printf("Chassis\n"); + more_printf(" Manufacturer : %s\n",hardware->dmi.chassis.manufacturer); + more_printf(" Type : %s\n",hardware->dmi.chassis.type); + more_printf(" Lock : %s\n",hardware->dmi.chassis.lock); + more_printf(" Version : %s\n",hardware->dmi.chassis.version); + more_printf(" Serial : %s\n",hardware->dmi.chassis.serial); + more_printf(" Asset Tag : %s\n",hardware->dmi.chassis.asset_tag); + more_printf(" Boot up state : %s\n",hardware->dmi.chassis.boot_up_state); + more_printf(" Power supply state : %s\n",hardware->dmi.chassis.power_supply_state); + more_printf(" Thermal state : %s\n",hardware->dmi.chassis.thermal_state); + more_printf(" Security Status : %s\n",hardware->dmi.chassis.security_status); + more_printf(" OEM Information : %s\n",hardware->dmi.chassis.oem_information); + more_printf(" Height : %u\n",hardware->dmi.chassis.height); + more_printf(" NB Power Cords : %u\n",hardware->dmi.chassis.nb_power_cords); +} + +void show_dmi_battery(struct s_hardware *hardware) { + if (hardware->dmi.battery.filled==false) { + printf("Battery module not available\n"); + return; + } + clear_screen(); + more_printf("Battery \n"); + more_printf(" Vendor : %s\n",hardware->dmi.battery.manufacturer); + more_printf(" Manufacture Date : %s\n",hardware->dmi.battery.manufacture_date); + more_printf(" Serial : %s\n",hardware->dmi.battery.serial); + more_printf(" Name : %s\n",hardware->dmi.battery.name); + more_printf(" Chemistry : %s\n",hardware->dmi.battery.chemistry); + more_printf(" Design Capacity : %s\n",hardware->dmi.battery.design_capacity); + more_printf(" Design Voltage : %s\n",hardware->dmi.battery.design_voltage); + more_printf(" SBDS : %s\n",hardware->dmi.battery.sbds); + more_printf(" SBDS Manuf. Date : %s\n",hardware->dmi.battery.sbds_manufacture_date); + more_printf(" SBDS Chemistry : %s\n",hardware->dmi.battery.sbds_chemistry); + more_printf(" Maximum Error : %s\n",hardware->dmi.battery.maximum_error); + more_printf(" OEM Info : %s\n",hardware->dmi.battery.oem_info); +} + +void show_dmi_cpu(struct s_hardware *hardware) { + if (hardware->dmi.processor.filled==false) { + printf("Processor module not available\n"); + return; + } + clear_screen(); + more_printf("CPU\n"); + more_printf(" Socket Designation : %s\n",hardware->dmi.processor.socket_designation); + more_printf(" Type : %s\n",hardware->dmi.processor.type); + more_printf(" Family : %s\n",hardware->dmi.processor.family); + more_printf(" Manufacturer : %s\n",hardware->dmi.processor.manufacturer); + more_printf(" Version : %s\n",hardware->dmi.processor.version); + more_printf(" External Clock : %u\n",hardware->dmi.processor.external_clock); + more_printf(" Max Speed : %u\n",hardware->dmi.processor.max_speed); + more_printf(" Current Speed : %u\n",hardware->dmi.processor.current_speed); + more_printf(" Cpu Type : %u\n",hardware->dmi.processor.signature.type); + more_printf(" Cpu Family : %u\n",hardware->dmi.processor.signature.family); + more_printf(" Cpu Model : %u\n",hardware->dmi.processor.signature.model); + more_printf(" Cpu Stepping : %u\n",hardware->dmi.processor.signature.stepping); + more_printf(" Cpu Minor Stepping : %u\n",hardware->dmi.processor.signature.minor_stepping); +// more_printf(" Voltage : %f\n",hardware->dmi.processor.voltage); + more_printf(" Status : %s\n",hardware->dmi.processor.status); + more_printf(" Upgrade : %s\n",hardware->dmi.processor.upgrade); + more_printf(" Cache L1 Handle : %s\n",hardware->dmi.processor.cache1); + more_printf(" Cache L2 Handle : %s\n",hardware->dmi.processor.cache2); + more_printf(" Cache L3 Handle : %s\n",hardware->dmi.processor.cache3); + more_printf(" Serial : %s\n",hardware->dmi.processor.serial); + more_printf(" Part Number : %s\n",hardware->dmi.processor.part_number); + more_printf(" ID : %s\n",hardware->dmi.processor.id); + for (int i=0;i<PROCESSOR_FLAGS_ELEMENTS; i++) { + if (((bool *)(& hardware->dmi.processor.cpu_flags))[i] == true) { + more_printf(" %s\n", cpu_flags_strings[i]); + } + } + +} + +void show_dmi_memory_modules(struct s_hardware *hardware, bool clear, bool show_free_banks) { + char bank_number[10]; + char available_dmi_commands[1024]; + memset(available_dmi_commands,0,sizeof(available_dmi_commands)); + + if (hardware->dmi.memory_count <=0) { + printf("No memory module found\n"); + return; + } + + if (clear) clear_screen(); + more_printf("Memory Banks\n"); + for (int i=0;i<hardware->dmi.memory_count;i++) { + if (hardware->dmi.memory[i].filled==true) { + /* When discovering the first item, let's clear the screen */ + strncat(available_dmi_commands,CLI_DMI_MEMORY_BANK,sizeof(CLI_DMI_MEMORY_BANK)-1); + memset(bank_number,0,sizeof(bank_number)); + snprintf(bank_number,sizeof(bank_number),"%d ",i); + strncat(available_dmi_commands,bank_number,sizeof(bank_number)); + if (show_free_banks==false) { + if (strncmp(hardware->dmi.memory[i].size,"Free",4)) + printf(" bank %02d : %s %s@%s\n",i,hardware->dmi.memory[i].size, hardware->dmi.memory[i].type, hardware->dmi.memory[i].speed); + } else { + printf(" bank %02d : %s %s@%s\n",i,hardware->dmi.memory[i].size, hardware->dmi.memory[i].type, hardware->dmi.memory[i].speed); + } + } + } + //printf("Type 'show bank<bank_number>' for more details.\n"); +} + +void show_dmi_memory_bank(struct s_hardware *hardware, const char *item) { + long bank = strtol(item,(char **) NULL,10); + if (errno == ERANGE) { + printf("This bank number is incorrect\n"); + return; + } + if ((bank>=hardware->dmi.memory_count) || (bank<0)) { + printf("Bank %d number doesn't exists\n",bank); + return; + } + + if (hardware->dmi.memory[bank].filled==false) { + printf("Bank %d doesn't contain any information\n",bank); + return; + } + printf("Memory Bank %d\n",bank); + more_printf(" Form Factor : %s\n",hardware->dmi.memory[bank].form_factor); + more_printf(" Type : %s\n",hardware->dmi.memory[bank].type); + more_printf(" Type Detail : %s\n",hardware->dmi.memory[bank].type_detail); + more_printf(" Speed : %s\n",hardware->dmi.memory[bank].speed); + more_printf(" Size : %s\n",hardware->dmi.memory[bank].size); + more_printf(" Device Set : %s\n",hardware->dmi.memory[bank].device_set); + more_printf(" Device Loc. : %s\n",hardware->dmi.memory[bank].device_locator); + more_printf(" Bank Locator : %s\n",hardware->dmi.memory[bank].bank_locator); + more_printf(" Total Width : %s\n",hardware->dmi.memory[bank].total_width); + more_printf(" Data Width : %s\n",hardware->dmi.memory[bank].data_width); + more_printf(" Error : %s\n",hardware->dmi.memory[bank].error); + more_printf(" Vendor : %s\n",hardware->dmi.memory[bank].manufacturer); + more_printf(" Serial : %s\n",hardware->dmi.memory[bank].serial); + more_printf(" Asset Tag : %s\n",hardware->dmi.memory[bank].asset_tag); + more_printf(" Part Number : %s\n",hardware->dmi.memory[bank].part_number); +} diff --git a/com32/hdt/hdt-cli-kernel.c b/com32/hdt/hdt-cli-kernel.c new file mode 100644 index 00000000..b5c453f1 --- /dev/null +++ b/com32/hdt/hdt-cli-kernel.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 <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <errno.h> + +void main_show_kernel(struct s_hardware *hardware,struct s_cli_mode *cli_mode) { + char buffer[1024]; + struct pci_device *pci_device; + bool found=false; + char kernel_modules [LINUX_KERNEL_MODULE_SIZE*MAX_KERNEL_MODULES_PER_PCI_DEVICE]; + + memset(buffer,0,sizeof(buffer)); + + detect_pci(hardware); + more_printf("Kernel modules\n"); + +// more_printf(" PCI device no: %d \n", p->pci_device_pos); + + if (hardware->modules_pcimap_return_code == -ENOMODULESPCIMAP) { + more_printf(" modules.pcimap is missing\n"); + return; + } + + /* For every detected pci device, compute its submenu */ + for_each_pci_func(pci_device, hardware->pci_domain) { + memset(kernel_modules,0,sizeof kernel_modules); + + for (int kmod=0; kmod<pci_device->dev_info->linux_kernel_module_count;kmod++) { + if (kmod>0) { + strncat(kernel_modules," | ",3); + } + strncat(kernel_modules, pci_device->dev_info->linux_kernel_module[kmod],LINUX_KERNEL_MODULE_SIZE-1); + } + + if ((pci_device->dev_info->linux_kernel_module_count>0) && (!strstr(buffer,kernel_modules))) { + found=true; + if (pci_device->dev_info->linux_kernel_module_count>1) strncat(buffer,"(",1); + strncat(buffer, kernel_modules, sizeof(kernel_modules)); + if (pci_device->dev_info->linux_kernel_module_count>1) strncat(buffer,")",1); + strncat(buffer," # ", 3); + } + + } + if (found ==true) { + strncat(buffer,"\n",1); + more_printf(buffer); + } +} + +void show_kernel_modules(struct s_hardware *hardware) { + int i=1; + struct pci_device *pci_device; + char kernel_modules [LINUX_KERNEL_MODULE_SIZE*MAX_KERNEL_MODULES_PER_PCI_DEVICE]; + bool nopciids=false; + bool nomodulespcimap=false; + char first_line[81]; + char second_line[81]; + char modules[MAX_PCI_CLASSES][256]; + char category_name[MAX_PCI_CLASSES][256]; + + detect_pci(hardware); + memset(&modules,0,sizeof(modules)); + + if (hardware->pci_ids_return_code == -ENOPCIIDS) { + nopciids=true; + more_printf(" Missing pci.ids, we can't compute the list\n"); + return; + } + + if (hardware->modules_pcimap_return_code == -ENOMODULESPCIMAP) { + nomodulespcimap=true; + more_printf(" Missing modules.pcimap, we can't compute the list\n"); + return; + } + + clear_screen(); + + for_each_pci_func(pci_device, hardware->pci_domain) { + memset(kernel_modules,0,sizeof kernel_modules); + + for (int kmod=0; kmod<pci_device->dev_info->linux_kernel_module_count;kmod++) { + strncat(kernel_modules, pci_device->dev_info->linux_kernel_module[kmod],LINUX_KERNEL_MODULE_SIZE-1); + strncat(kernel_modules," ",1); + } + + if ((pci_device->dev_info->linux_kernel_module_count>0) && (!strstr(modules[pci_device->class[2]],kernel_modules))) { + strncat(modules[pci_device->class[2]], kernel_modules, sizeof(kernel_modules)); + snprintf(category_name[pci_device->class[2]], sizeof(category_name[pci_device->class[2]]),"%s",pci_device->dev_info->category_name); + } + } + /* print the found items */ + for (int i=0; i<MAX_PCI_CLASSES;i++) { + if (strlen(category_name[i])>1) { + more_printf("%s : %s\n",category_name[i], modules[i]); + } + } +} + +void show_kernel_help() { + more_printf("Show supports the following commands : %s\n",CLI_SHOW_LIST); +} + +void kernel_show(char *item, struct s_hardware *hardware) { + if ( !strncmp(item, CLI_SHOW_LIST, sizeof(CLI_SHOW_LIST) - 1) ) { + show_kernel_modules(hardware); + return; + } + show_kernel_help(); +} + +void handle_kernel_commands(char *cli_line, struct s_cli_mode *cli_mode, struct s_hardware *hardware) { + if ( !strncmp(cli_line, CLI_SHOW, sizeof(CLI_SHOW) - 1) ) { + kernel_show(strstr(cli_line,"show")+ sizeof(CLI_SHOW), hardware); + return; + } +} + diff --git a/com32/hdt/hdt-cli-pci.c b/com32/hdt/hdt-cli-pci.c new file mode 100644 index 00000000..554c2ce5 --- /dev/null +++ b/com32/hdt/hdt-cli-pci.c @@ -0,0 +1,241 @@ +/* ----------------------------------------------------------------------- * + * + * 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> +#include <errno.h> + +void show_pci_device(struct s_hardware *hardware, const char *item) { + int i=0; + struct pci_device *pci_device=NULL, *temp_pci_device; + long pcidev = strtol(item,(char **) NULL,10); + bool nopciids=false; + bool nomodulespcimap=false; + char kernel_modules [LINUX_KERNEL_MODULE_SIZE*MAX_KERNEL_MODULES_PER_PCI_DEVICE]; + int bus=0,slot=0,func=0; + + if (errno == ERANGE) { + printf("This PCI device number is incorrect\n"); + return; + } + if ((pcidev > hardware->nb_pci_devices) || (pcidev<=0)) { + printf("PCI device %d doesn't exists\n",pcidev); + return; + } + + if (hardware->pci_ids_return_code == -ENOPCIIDS) { + nopciids=true; + } + + if (hardware->modules_pcimap_return_code == -ENOMODULESPCIMAP) { + nomodulespcimap=true; + } + + for_each_pci_func(temp_pci_device, hardware->pci_domain) { + i++; + if (i==pcidev) { + bus=__pci_bus; + slot=__pci_slot; + func=__pci_func; + pci_device=temp_pci_device; + } + } + + if (pci_device == NULL) { + printf("We were enabled to find PCI device %d\n",pcidev); + return; + } + + memset(kernel_modules,0,sizeof kernel_modules); + for (int kmod=0; kmod<pci_device->dev_info->linux_kernel_module_count;kmod++) { + if (kmod>0) { + strncat(kernel_modules," | ",3); + } + strncat(kernel_modules, pci_device->dev_info->linux_kernel_module[kmod],LINUX_KERNEL_MODULE_SIZE-1); + } + if (pci_device->dev_info->linux_kernel_module_count==0) strlcpy(kernel_modules,"unknown",7); + + clear_screen(); + printf("PCI Device %d\n",pcidev); + + if (nopciids == false) { + more_printf("Vendor Name : %s\n", pci_device->dev_info->vendor_name); + more_printf("Product Name : %s\n", pci_device->dev_info->product_name); + more_printf("Class Name : %s\n", pci_device->dev_info->class_name); + } + + if (nomodulespcimap == false) { + more_printf("Kernel module : %s\n", kernel_modules); + } + + more_printf("Vendor ID : %04x\n",pci_device->vendor); + more_printf("Product ID : %04x\n",pci_device->product); + more_printf("SubVendor ID : %04x\n",pci_device->sub_vendor); + more_printf("SubProduct ID : %04x\n",pci_device->sub_product); + more_printf("Class ID : %02x.%02x.%02x\n",pci_device->class[2], pci_device->class[1],pci_device->class[0]); + more_printf("Revision : %02x\n",pci_device->revision); + more_printf("PCI Bus : %02d\n",bus); + more_printf("PCI Slot : %02d\n",slot); + more_printf("PCI Func : %02d\n",func); + + if (hardware->is_pxe_valid == true) { + more_printf("Mac Address : %s\n",hardware->pxe.mac_addr); + if ((hardware->pxe.pci_device != NULL) && (hardware->pxe.pci_device == pci_device)) + more_printf("PXE : Current boot device\n",func); + } +} + +void show_pci_devices(struct s_hardware *hardware) { + int i=1; + struct pci_device *pci_device; + char kernel_modules [LINUX_KERNEL_MODULE_SIZE*MAX_KERNEL_MODULES_PER_PCI_DEVICE]; + bool nopciids=false; + bool nomodulespcimap=false; + char first_line[81]; + char second_line[81]; + + clear_screen(); + more_printf("%d PCI devices detected\n",hardware->nb_pci_devices); + + if (hardware->pci_ids_return_code == -ENOPCIIDS) { + nopciids=true; + } + + if (hardware->modules_pcimap_return_code == -ENOMODULESPCIMAP) { + nomodulespcimap=true; + } + + /* For every detected pci device, compute its submenu */ + for_each_pci_func(pci_device, hardware->pci_domain) { + memset(kernel_modules,0,sizeof kernel_modules); + for (int kmod=0; kmod<pci_device->dev_info->linux_kernel_module_count;kmod++) { + if (kmod>0) { + strncat(kernel_modules," | ",3); + } + strncat(kernel_modules, pci_device->dev_info->linux_kernel_module[kmod],LINUX_KERNEL_MODULE_SIZE-1); + } + if (pci_device->dev_info->linux_kernel_module_count==0) strlcpy(kernel_modules,"unknown",7); + + if (nopciids == false) { + snprintf(first_line,sizeof(first_line),"%02d: %s %s \n", + i,pci_device->dev_info->vendor_name, + pci_device->dev_info->product_name); + if (nomodulespcimap == false) + snprintf(second_line,sizeof(second_line)," # %-25s # Kmod: %s\n", pci_device->dev_info->class_name, kernel_modules); + else + snprintf(second_line,sizeof(second_line)," # %-25s # ID:%04x:%04x[%04x:%04x]\n", + pci_device->dev_info->class_name, + pci_device->vendor, pci_device->product, + pci_device->sub_vendor, pci_device->sub_product); + + more_printf(first_line); + more_printf(second_line); + more_printf("\n"); + } else if (nopciids == true) { + if (nomodulespcimap == true) { + more_printf("%02d: %04x:%04x [%04x:%04x] \n", + i, pci_device->vendor, pci_device->product, + pci_device->sub_vendor, pci_device->sub_product,kernel_modules); + } + else { + more_printf("%02d: %04x:%04x [%04x:%04x] Kmod:%s\n", + i, + pci_device->vendor, pci_device->product, + pci_device->sub_vendor, pci_device->sub_product,kernel_modules, + pci_device->sub_product,kernel_modules); + } + } + i++; + } + +} +void show_pci_help() { + more_printf("Show supports the following commands : \n"); + more_printf(" %s\n",CLI_SHOW_LIST); + more_printf(" %s <device_number>\n",CLI_PCI_DEVICE); +} + +void pci_show(char *item, struct s_hardware *hardware) { + if ( !strncmp(item, CLI_SHOW_LIST, sizeof(CLI_SHOW_LIST) - 1) ) { + show_pci_devices(hardware); + return; + } + if ( !strncmp(item, CLI_PCI_DEVICE, sizeof(CLI_PCI_DEVICE) - 1) ) { + show_pci_device(hardware,item+ sizeof(CLI_PCI_DEVICE)-1); + return; + } + show_pci_help(); +} + +void handle_pci_commands(char *cli_line, struct s_cli_mode *cli_mode, struct s_hardware *hardware) { + if ( !strncmp(cli_line, CLI_SHOW, sizeof(CLI_SHOW) - 1) ) { + pci_show(strstr(cli_line,"show")+ sizeof(CLI_SHOW), hardware); + return; + } +} + + +void cli_detect_pci(struct s_hardware *hardware) { + bool error=false; + if (hardware->pci_detection==false) { + detect_pci(hardware); + if (hardware->pci_ids_return_code == -ENOPCIIDS) { + more_printf("The pci.ids file is missing, device names can't be computed.\n"); + more_printf("Please put one in same dir as hdt\n"); + error=true; + } + if (hardware->modules_pcimap_return_code == -ENOMODULESPCIMAP) { + more_printf("The modules.pcimap file is missing, device names can't be computed.\n"); + more_printf("Please put one in same dir as hdt\n"); + error=true; + } + if (error == true) { + char tempbuf[10];\ + printf("Press enter to continue\n");\ + fgets(tempbuf, sizeof(tempbuf), stdin);\ + } + } +} + +void main_show_pci(struct s_hardware *hardware) { + int i=1; + char kernel_modules [LINUX_KERNEL_MODULE_SIZE*MAX_KERNEL_MODULES_PER_PCI_DEVICE]; + struct pci_device *pci_device; + bool nopciids=false; + bool nomodulespcimap=false; + char first_line[81]; + char second_line[81]; + char third_line[81]; + cli_detect_pci(hardware); + + more_printf("PCI\n"); + more_printf(" NB Devices : %d\n",hardware->nb_pci_devices); + +} diff --git a/com32/hdt/hdt-cli-pxe.c b/com32/hdt/hdt-cli-pxe.c new file mode 100644 index 00000000..2ad6981a --- /dev/null +++ b/com32/hdt/hdt-cli-pxe.c @@ -0,0 +1,90 @@ +/* ----------------------------------------------------------------------- * + * + * 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> +#include <syslinux/pxe.h> +#include <syslinux/config.h> + +void main_show_pxe(struct s_hardware *hardware,struct s_cli_mode *cli_mode) { + char buffer[81]; + memset(buffer,0,sizeof(81)); + if (hardware->sv->filesystem != SYSLINUX_FS_PXELINUX) { + more_printf("You are not currently using PXELINUX\n"); + return; + } + + detect_pxe(hardware); + more_printf("PXE\n"); + if (hardware->is_pxe_valid==false) { + more_printf(" No valid PXE ROM found\n"); + return; + } + + struct s_pxe *p = &hardware->pxe; + more_printf(" PCI device no: %d \n", p->pci_device_pos); + + if (hardware->pci_ids_return_code == -ENOPCIIDS) { + snprintf(buffer,sizeof(buffer)," PCI ID : %04x:%04x[%04x:%04X] rev(%02x)\n", + p->vendor_id, p->product_id, p->subvendor_id, p->subproduct_id, + p->rev); + snprintf(buffer,sizeof(buffer)," PCI Bus pos. : %02x:%02x.%02x\n", + p->pci_bus,p->pci_dev, p->pci_func); + more_printf(buffer); + } else { + snprintf(buffer,sizeof(buffer)," Manufacturer : %s \n", p->pci_device->dev_info->vendor_name); + more_printf(buffer); + snprintf(buffer,sizeof(buffer)," Product : %s \n", p->pci_device->dev_info->product_name); + more_printf(buffer); + } + more_printf( " Addresses : %d.%d.%d.%d @ %s\n",p->ip_addr[0], p->ip_addr[1], p->ip_addr[2], p->ip_addr[3],p->mac_addr); +} + +void show_pxe_help() { + more_printf("Show supports the following commands : %s\n",CLI_SHOW_LIST); +} + +void pxe_show(char *item, struct s_hardware *hardware) { + if ( !strncmp(item, CLI_SHOW_LIST, sizeof(CLI_SHOW_LIST) - 1) ) { + main_show_pxe(hardware,NULL); + return; + } + show_pxe_help(); +} + +void handle_pxe_commands(char *cli_line, struct s_cli_mode *cli_mode, struct s_hardware *hardware) { + if ( !strncmp(cli_line, CLI_SHOW, sizeof(CLI_SHOW) - 1) ) { + pxe_show(strstr(cli_line,"show")+ sizeof(CLI_SHOW), hardware); + return; + } +} + diff --git a/com32/hdt/hdt-cli-syslinux.c b/com32/hdt/hdt-cli-syslinux.c new file mode 100644 index 00000000..1a0c1e0e --- /dev/null +++ b/com32/hdt/hdt-cli-syslinux.c @@ -0,0 +1,65 @@ +/* ----------------------------------------------------------------------- * + * + * 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> +#include <syslinux/pxe.h> +#include <syslinux/config.h> + +void main_show_syslinux(struct s_hardware *hardware,struct s_cli_mode *cli_mode) { + more_printf("SYSLINUX\n"); + more_printf(" Bootloader : %s\n", hardware->syslinux_fs); + more_printf(" Version : %s\n", hardware->sv->version_string+2); + more_printf(" Version : %u\n",hardware->sv->version); + more_printf(" Max API : %u\n",hardware->sv->max_api); + more_printf(" Copyright : %s\n", hardware->sv->copyright_string+1); +} + +void show_syslinux_help() { + more_printf("Show supports the following commands : %s\n",CLI_SHOW_LIST); +} + +void syslinux_show(char *item, struct s_hardware *hardware) { + if ( !strncmp(item, CLI_SHOW_LIST, sizeof(CLI_SHOW_LIST) - 1) ) { + main_show_syslinux(hardware,NULL); + return; + } + show_syslinux_help(); +} + +void handle_syslinux_commands(char *cli_line, struct s_cli_mode *cli_mode, struct s_hardware *hardware) { + if ( !strncmp(cli_line, CLI_SHOW, sizeof(CLI_SHOW) - 1) ) { + syslinux_show(strstr(cli_line,"show")+ sizeof(CLI_SHOW), hardware); + return; + } +} + diff --git a/com32/hdt/hdt-cli.c b/com32/hdt/hdt-cli.c new file mode 100644 index 00000000..3f714858 --- /dev/null +++ b/com32/hdt/hdt-cli.c @@ -0,0 +1,254 @@ +/* ----------------------------------------------------------------------- * + * + * 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> +#include <syslinux/config.h> + +void set_mode(struct s_cli_mode *cli_mode, cli_mode_t mode, struct s_hardware *hardware) { + switch (mode) { + case EXIT_MODE: + cli_mode->mode=mode; + snprintf(cli_mode->prompt, sizeof(cli_mode->prompt), "%s> ", CLI_EXIT); + break; + + case HDT_MODE: + cli_mode->mode=mode; + snprintf(cli_mode->prompt, sizeof(cli_mode->prompt), "%s> ", CLI_HDT); + break; + + case PXE_MODE: + if (hardware->sv->filesystem != SYSLINUX_FS_PXELINUX) { + more_printf("You are not currently using PXELINUX\n"); + break; + } + cli_mode->mode=mode; + snprintf(cli_mode->prompt, sizeof(cli_mode->prompt), "%s> ", CLI_PXE); + break; + + case KERNEL_MODE: + detect_pci(hardware); + cli_mode->mode=mode; + snprintf(cli_mode->prompt, sizeof(cli_mode->prompt), "%s> ", CLI_KERNEL); + break; + + case SYSLINUX_MODE: + cli_mode->mode=mode; + snprintf(cli_mode->prompt, sizeof(cli_mode->prompt), "%s> ", CLI_SYSLINUX); + break; + + case PCI_MODE: + cli_mode->mode=mode; + snprintf(cli_mode->prompt,sizeof(cli_mode->prompt),"%s> ", CLI_PCI); + if (!hardware->pci_detection) + 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: + detect_dmi(hardware); + if (!hardware->is_dmi_valid) { + printf("No valid DMI table found, exiting.\n"); + break; + } + cli_mode->mode=mode; + snprintf(cli_mode->prompt,sizeof(cli_mode->prompt),"%s> ",CLI_DMI); + break; + } +} + +void handle_hdt_commands(char *cli_line, struct s_cli_mode *cli_mode, struct s_hardware *hardware) { + /* hdt cli mode specific commands */ + if ( !strncmp(cli_line, CLI_SHOW, sizeof(CLI_SHOW) - 1) ) { + main_show(strstr(cli_line,"show")+ sizeof (CLI_SHOW), hardware,cli_mode); + return; + } +} + +/* Code that manage the cli mode */ +void start_cli_mode(struct s_hardware *hardware, int argc, char *argv[]) { + char cli_line[256]; + struct s_cli_mode cli_mode; + + set_mode(&cli_mode,HDT_MODE,hardware); + + printf("Entering CLI mode\n"); + + for (;;) { + memset(cli_line,0,sizeof cli_line); + printf("%s",cli_mode.prompt); + + fgets(cli_line, sizeof cli_line, stdin); + cli_line[strlen(cli_line)-1]='\0'; + /* We use sizeof BLAH - 1 to remove the last \0 */ + + if ( !strncmp(cli_line, CLI_EXIT, sizeof(CLI_EXIT) - 1) ) { + int mode=do_exit(&cli_mode); + if (mode == EXIT_MODE) + return; + set_mode(&cli_mode,mode,hardware); + continue; + } + + if ( !strncmp(cli_line, CLI_HELP, sizeof(CLI_HELP) - 1) ) { + show_cli_help(&cli_mode); + continue; + } + + if ( !strncmp(cli_line, CLI_PCI, sizeof(CLI_PCI) - 1) ) { + set_mode(&cli_mode,PCI_MODE,hardware); + continue; + } + if ( !strncmp(cli_line, CLI_CLEAR, sizeof(CLI_CLEAR) - 1) ) { + 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; + } + if ( !strncmp(cli_line, CLI_PXE, sizeof(CLI_PXE) - 1) ) { + set_mode(&cli_mode,PXE_MODE,hardware); + continue; + } + if ( !strncmp(cli_line, CLI_KERNEL, sizeof(CLI_KERNEL) - 1) ) { + set_mode(&cli_mode,KERNEL_MODE,hardware); + continue; + } + if ( !strncmp(cli_line, CLI_SYSLINUX, sizeof(CLI_SYSLINUX) - 1) ) { + set_mode(&cli_mode,SYSLINUX_MODE,hardware); + continue; + } + /* All commands before that line are common for all cli modes + * the following will be specific for every mode */ + switch(cli_mode.mode) { + 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 PXE_MODE: handle_pxe_commands(cli_line,&cli_mode, hardware); break; + case SYSLINUX_MODE: handle_syslinux_commands(cli_line,&cli_mode, hardware); break; + case KERNEL_MODE: handle_kernel_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 KERNEL_MODE: + case PXE_MODE: + case SYSLINUX_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; +} + +void show_cli_help(struct s_cli_mode *cli_mode) { +switch (cli_mode->mode) { + case HDT_MODE: + printf("Available commands are : %s %s %s %s %s %s %s %s %s %s\n", + CLI_CLEAR, CLI_EXIT,CLI_HELP,CLI_SHOW, CLI_PCI, + CLI_DMI, CLI_PXE, CLI_KERNEL, CLI_CPU, CLI_SYSLINUX); + break; + case SYSLINUX_MODE: + case KERNEL_MODE: + case PXE_MODE: + case CPU_MODE: + case PCI_MODE: + case DMI_MODE: + printf("Available commands are : %s %s %s %s\n", + CLI_CLEAR, CLI_EXIT, CLI_HELP, CLI_SHOW); + break; + case EXIT_MODE: /* Should not happend*/ + break; +} +} + +void main_show_summary(struct s_hardware *hardware, struct s_cli_mode *cli_mode) { + detect_pci(hardware); /* pxe is detected in the pci */ + detect_dmi(hardware); + cpu_detect(hardware); + clear_screen(); + main_show_cpu(hardware,cli_mode); + if (hardware->is_dmi_valid) { + more_printf("System\n"); + more_printf(" Manufacturer : %s\n",hardware->dmi.system.manufacturer); + more_printf(" Product Name : %s\n",hardware->dmi.system.product_name); + more_printf(" Serial : %s\n",hardware->dmi.system.serial); + more_printf("Bios\n"); + more_printf(" Version : %s\n",hardware->dmi.bios.version); + more_printf(" Release : %s\n",hardware->dmi.bios.release_date); + show_dmi_memory_modules(hardware,false,false); + } + main_show_pci(hardware); + if (hardware->is_pxe_valid) + main_show_pxe(hardware,cli_mode); + main_show_kernel(hardware,cli_mode); +} + +void show_main_help(struct s_hardware *hardware) { + more_printf("Show supports the following commands : \n"); + more_printf(" %s\n",CLI_SUMMARY); + more_printf(" %s\n",CLI_PCI); + more_printf(" %s\n",CLI_DMI); + more_printf(" %s\n",CLI_CPU); + more_printf(" %s\n",CLI_KERNEL); + more_printf(" %s\n",CLI_SYSLINUX); + if (hardware->sv->filesystem == SYSLINUX_FS_PXELINUX) + more_printf(" %s\n",CLI_PXE); +} + +void main_show(char *item, struct s_hardware *hardware, struct s_cli_mode *cli_mode) { + if (!strncmp(item,CLI_SUMMARY, sizeof (CLI_SUMMARY))) { main_show_summary(hardware,cli_mode); return; } + if (!strncmp(item,CLI_PCI, sizeof (CLI_PCI))) { main_show_pci(hardware); return; } + if (!strncmp(item,CLI_DMI, sizeof (CLI_DMI))) { main_show_dmi(hardware,cli_mode); return; } + if (!strncmp(item,CLI_CPU, sizeof (CLI_CPU))) { main_show_cpu(hardware,cli_mode); return; } + if (!strncmp(item,CLI_PXE, sizeof (CLI_PXE))) { main_show_pxe(hardware,cli_mode); return; } + if (!strncmp(item,CLI_SYSLINUX, sizeof (CLI_SYSLINUX))) { main_show_syslinux(hardware,cli_mode); return; } + if (!strncmp(item,CLI_KERNEL, sizeof (CLI_KERNEL))) { main_show_kernel(hardware,cli_mode); return; } + show_main_help(hardware); +} diff --git a/com32/hdt/hdt-cli.h b/com32/hdt/hdt-cli.h new file mode 100644 index 00000000..92791c49 --- /dev/null +++ b/com32/hdt/hdt-cli.h @@ -0,0 +1,116 @@ +/* ----------------------------------------------------------------------- * + * + * 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> +#include "hdt-common.h" + +#define CLI_CLEAR "clear" +#define CLI_EXIT "exit" +#define CLI_HELP "help" +#define CLI_SHOW "show" +#define CLI_HDT "hdt" +#define CLI_PCI "pci" +#define CLI_PXE "pxe" +#define CLI_KERNEL "kernel" +#define CLI_SYSLINUX "syslinux" +#define CLI_SUMMARY "summary" +#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, + CPU_MODE, + PXE_MODE, + KERNEL_MODE, + SYSLINUX_MODE, +} cli_mode_t; + +struct s_cli_mode { + cli_mode_t mode; + char prompt[32]; +}; + + +void show_cli_help(struct s_cli_mode *cli_mode); +void start_cli_mode(struct s_hardware *hardware, int argc, char *argv[]); +void main_show(char *item, struct s_hardware *hardware, struct s_cli_mode *cli_mode); +int do_exit(struct s_cli_mode *cli_mode); + +//DMI STUFF +#define CLI_DMI_BASE_BOARD "base_board" +#define CLI_DMI_BATTERY "battery" +#define CLI_DMI_BIOS "bios" +#define CLI_DMI_CHASSIS "chassis" +#define CLI_DMI_MEMORY "memory" +#define CLI_DMI_MEMORY_BANK "bank" +#define CLI_DMI_PROCESSOR "cpu" +#define CLI_DMI_SYSTEM "system" + +void main_show_dmi(struct s_hardware *hardware,struct s_cli_mode *cli_mode); +void handle_dmi_commands(char *cli_line, struct s_cli_mode *cli_mode, struct s_hardware *hardware); +void show_dmi_base_board(struct s_hardware *hardware); +void show_dmi_system(struct s_hardware *hardware); +void show_dmi_bios(struct s_hardware *hardware); +void show_dmi_chassis(struct s_hardware *hardware); +void show_dmi_cpu(struct s_hardware *hardware); +void show_dmi_modules(struct s_hardware *hardware); +void show_dmi_memory_modules(struct s_hardware *hardware,bool clearscreen, bool show_free_banks); +void show_dmi_memory_bank(struct s_hardware *hardware, const char *item); +void show_dmi_battery(struct s_hardware *hardware); + +//PCI STUFF +#define CLI_PCI_DEVICE "device" +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); + +//PXE STUFF +void main_show_pxe(struct s_hardware *hardware,struct s_cli_mode *cli_mode); +void handle_pxe_commands(char *cli_line, struct s_cli_mode *cli_mode, struct s_hardware *hardware); + +//KERNEL STUFF +void main_show_kernel(struct s_hardware *hardware,struct s_cli_mode *cli_mode); +void handle_kernel_commands(char *cli_line, struct s_cli_mode *cli_mode, struct s_hardware *hardware); + +//SYSLINUX STUFF +void main_show_syslinux(struct s_hardware *hardware,struct s_cli_mode *cli_mode); +void handle_syslinux_commands(char *cli_line, struct s_cli_mode *cli_mode, struct s_hardware *hardware); +#endif diff --git a/com32/hdt/hdt-common.c b/com32/hdt/hdt-common.c new file mode 100644 index 00000000..0ff7e86d --- /dev/null +++ b/com32/hdt/hdt-common.c @@ -0,0 +1,253 @@ +/* ----------------------------------------------------------------------- * + * + * 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> +#include <stdio.h> +#include "syslinux/config.h" + +void detect_parameters(int argc, char *argv[], struct s_hardware *hardware) { + for (int i = 1; i < argc; i++) { + if (!strncmp(argv[i], "modules=", 8)) { + strncpy(hardware->modules_pcimap_path,argv[i]+8, sizeof(hardware->modules_pcimap_path)); + } else if (!strncmp(argv[i], "pciids=",7 )) { + strncpy(hardware->pciids_path,argv[i]+7, sizeof(hardware->pciids_path)); + } + } +} + +void detect_syslinux(struct s_hardware *hardware) { + hardware->sv = syslinux_version(); + switch(hardware->sv->filesystem) { + case SYSLINUX_FS_SYSLINUX: strlcpy(hardware->syslinux_fs,"SYSlinux",9); break; + case SYSLINUX_FS_PXELINUX: strlcpy(hardware->syslinux_fs,"PXElinux",9); break; + case SYSLINUX_FS_ISOLINUX: strlcpy(hardware->syslinux_fs,"ISOlinux",9); break; + case SYSLINUX_FS_EXTLINUX: strlcpy(hardware->syslinux_fs,"EXTlinux",9); break; + case SYSLINUX_FS_UNKNOWN: + default: strlcpy(hardware->syslinux_fs,"Unknown Bootloader",sizeof hardware->syslinux_fs); break; + } +} + +void init_hardware(struct s_hardware *hardware) { + hardware->pci_ids_return_code=0; + hardware->modules_pcimap_return_code=0; + hardware->cpu_detection=false; + hardware->pci_detection=false; + hardware->disk_detection=false; + hardware->dmi_detection=false; + hardware->pxe_detection=false; + hardware->nb_pci_devices=0; + hardware->is_dmi_valid=false; + hardware->is_pxe_valid=false; + hardware->pci_domain=NULL; + + /* Cleaning structures */ + memset(hardware->disk_info,0,sizeof(hardware->disk_info)); + memset(&hardware->dmi,0,sizeof(s_dmi)); + memset(&hardware->cpu,0,sizeof(s_cpu)); + memset(&hardware->pxe,0,sizeof(struct s_pxe)); + memset(hardware->syslinux_fs,0,sizeof hardware->syslinux_fs); + memset(hardware->pciids_path,0,sizeof hardware->pciids_path); + memset(hardware->modules_pcimap_path,0,sizeof hardware->modules_pcimap_path); + strcat(hardware->pciids_path,"pci.ids"); + strcat(hardware->modules_pcimap_path,"modules.pcimap"); +} + +/* Detecting if a DMI table exist + * if yes, let's parse it */ +int detect_dmi(struct s_hardware *hardware) { + if (hardware->dmi_detection == true) return -1; + hardware->dmi_detection=true; + if (dmi_iterate(&hardware->dmi) == -ENODMITABLE ) { + 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 s_hardware *hardware) { + hardware->disk_detection=true; + for (int drive = 0x80; drive < 0xff; drive++) { + if (get_disk_params(drive,hardware->disk_info) != 0) + continue; + struct diskinfo *d=&hardware->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 detect_pxe(struct s_hardware *hardware) { + void *dhcpdata; + + size_t dhcplen; + t_PXENV_UNDI_GET_NIC_TYPE gnt; + + if (hardware->pxe_detection == true) return -1; + hardware->pxe_detection=true; + hardware->is_pxe_valid=false; + memset(&gnt,0, sizeof(t_PXENV_UNDI_GET_NIC_TYPE)); + memset(&hardware->pxe,0, sizeof(struct s_pxe)); + + /* This code can only work if pxelinux is loaded*/ + if (hardware->sv->filesystem != SYSLINUX_FS_PXELINUX) { + return -1; + } + +// printf("PXE: PXElinux detected\n"); + if (!pxe_get_cached_info(PXENV_PACKET_TYPE_DHCP_ACK, &dhcpdata, &dhcplen)) { + pxe_bootp_t *dhcp=&hardware->pxe.dhcpdata; + memcpy(&hardware->pxe.dhcpdata,dhcpdata,sizeof(hardware->pxe.dhcpdata)); + snprintf(hardware->pxe.mac_addr, sizeof(hardware->pxe.mac_addr), "%02x:%02x:%02x:%02x:%02x:%02x", + dhcp->CAddr[0],dhcp->CAddr[1],dhcp->CAddr[2],dhcp->CAddr[3],dhcp->CAddr[4],dhcp->CAddr[5]); + + /* Saving Our IP address in a easy format*/ + hardware->pxe.ip_addr[0]= hardware->pxe.dhcpdata.yip & 0xff; + hardware->pxe.ip_addr[1]= hardware->pxe.dhcpdata.yip >>8 & 0xff; + hardware->pxe.ip_addr[2]= hardware->pxe.dhcpdata.yip >>16 & 0xff; + hardware->pxe.ip_addr[3]= hardware->pxe.dhcpdata.yip >>24 & 0xff; + + if (!pxe_get_nic_type(&gnt)) { + switch(gnt.NicType) { + case PCI_NIC: + hardware->is_pxe_valid=true; + hardware->pxe.vendor_id=gnt.info.pci.Vendor_ID; + hardware->pxe.product_id=gnt.info.pci.Dev_ID; + hardware->pxe.subvendor_id=gnt.info.pci.SubVendor_ID; + hardware->pxe.subproduct_id=gnt.info.pci.SubDevice_ID, + hardware->pxe.rev=gnt.info.pci.Rev; + hardware->pxe.pci_bus= (gnt.info.pci.BusDevFunc >> 8) & 0xff; + hardware->pxe.pci_dev= (gnt.info.pci.BusDevFunc >> 3) & 0x7; + hardware->pxe.pci_func=gnt.info.pci.BusDevFunc & 0x03; + hardware->pxe.base_class=gnt.info.pci.Base_Class; + hardware->pxe.sub_class=gnt.info.pci.Sub_Class; + hardware->pxe.prog_intf=gnt.info.pci.Prog_Intf; + hardware->pxe.nictype=gnt.NicType; + break; + case CardBus_NIC: + hardware->is_pxe_valid=true; + hardware->pxe.vendor_id=gnt.info.cardbus.Vendor_ID; + hardware->pxe.product_id=gnt.info.cardbus.Dev_ID; + hardware->pxe.subvendor_id=gnt.info.cardbus.SubVendor_ID; + hardware->pxe.subproduct_id=gnt.info.cardbus.SubDevice_ID, + hardware->pxe.rev=gnt.info.cardbus.Rev; + hardware->pxe.pci_bus= (gnt.info.cardbus.BusDevFunc >> 8) & 0xff; + hardware->pxe.pci_dev= (gnt.info.cardbus.BusDevFunc >> 3) & 0x7; + hardware->pxe.pci_func=gnt.info.cardbus.BusDevFunc & 0x03; + hardware->pxe.base_class=gnt.info.cardbus.Base_Class; + hardware->pxe.sub_class=gnt.info.cardbus.Sub_Class; + hardware->pxe.prog_intf=gnt.info.cardbus.Prog_Intf; + hardware->pxe.nictype=gnt.NicType; + break; + case PnP_NIC: + default: return -1; break; + } + /* Let's try to find the associated pci device */ + detect_pci(hardware); + hardware->pxe.pci_device=NULL; + hardware->pxe.pci_device_pos=0; + struct pci_device *pci_device; + int pci_number=0; + for_each_pci_func(pci_device, hardware->pci_domain) { + pci_number++; + if ((__pci_bus == hardware->pxe.pci_bus) && + (__pci_slot == hardware->pxe.pci_dev) && + (__pci_func == hardware->pxe.pci_func) && + (pci_device->vendor == hardware->pxe.vendor_id) && + (pci_device->product == hardware->pxe.product_id)) { + hardware->pxe.pci_device=pci_device; + hardware->pxe.pci_device_pos=pci_number; + } + } + } + } + return 0; +} + +void detect_pci(struct s_hardware *hardware) { + if (hardware->pci_detection == true) return; + hardware->pci_detection=true; + + /* Scanning to detect pci buses and devices */ + hardware->pci_domain = pci_scan(); + + hardware->nb_pci_devices=0; + struct pci_device *pci_device; + for_each_pci_func(pci_device, hardware->pci_domain) { + hardware->nb_pci_devices++; + } + + printf("PCI: %d devices detected\n",hardware->nb_pci_devices); + printf("PCI: Resolving names\n"); + /* Assigning product & vendor name for each device*/ + hardware->pci_ids_return_code=get_name_from_pci_ids(hardware->pci_domain, hardware->pciids_path); + + printf("PCI: Resolving class names\n"); + /* Assigning class name for each device*/ + hardware->pci_ids_return_code=get_class_name_from_pci_ids(hardware->pci_domain, hardware->pciids_path); + + + printf("PCI: Resolving module names\n"); + /* Detecting which kernel module should match each device */ + hardware->modules_pcimap_return_code=get_module_name_from_pci_ids(hardware->pci_domain,hardware->modules_pcimap_path); + + /* we try to detect the pxe stuff to populate the PXE: field of pci devices */ + detect_pxe(hardware); +} + +void cpu_detect(struct s_hardware *hardware) { + if (hardware->cpu_detection == true) return; + detect_cpu(&hardware->cpu); + hardware->cpu_detection=true; +} + +/* Find the last instance of a particular command line argument + (which should include the final =; do not use for boolean arguments) */ +char *find_argument(const char **argv, const char *argument) +{ + int la = strlen(argument); + const char **arg; + char *ptr = NULL; + + for (arg = argv; *arg; arg++) { + if (!memcmp(*arg, argument, la)) + ptr = *arg + la; + } + + return ptr; +} + +void clear_screen(void) +{ + fputs("\033e\033%@\033)0\033(B\1#0\033[?25l\033[2J", stdout); + display_line_nb=0; +} + diff --git a/com32/hdt/hdt-common.h b/com32/hdt/hdt-common.h new file mode 100644 index 00000000..1b27b588 --- /dev/null +++ b/com32/hdt/hdt-common.h @@ -0,0 +1,113 @@ +/* ----------------------------------------------------------------------- * + * + * 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 <syslinux/pxe.h> +#include "hdt-ata.h" + +/* This two values are used for switching for the menu to the CLI mode*/ +#define HDT_SWITCH_TO_CLI "hdt_switch_to_cli" +#define HDT_RETURN_TO_CLI 100 + +extern int display_line_nb; + +#define more_printf(...) do {\ + if (display_line_nb == 23) {\ + char tempbuf[10];\ + printf("Press enter to continue\n");\ + display_line_nb=0;\ + fgets(tempbuf, sizeof(tempbuf), stdin);\ + }\ + printf ( __VA_ARGS__);\ + display_line_nb++; \ +} while (0); + + +struct s_pxe { + uint16_t vendor_id; + uint16_t product_id; + uint16_t subvendor_id; + uint16_t subproduct_id; + uint8_t rev; + uint8_t pci_bus; + uint8_t pci_dev; + uint8_t pci_func; + uint8_t base_class; + uint8_t sub_class; + uint8_t prog_intf; + uint8_t nictype; + char mac_addr[18]; /* The current mac address */ + uint8_t ip_addr[4]; + + pxe_bootp_t dhcpdata; /* The dhcp answer */ + struct pci_device *pci_device; /* The matching pci device */ + uint8_t pci_device_pos; /* It position in our pci sorted list*/ + +}; + +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*/ + struct s_pxe pxe; + + int pci_ids_return_code; + int modules_pcimap_return_code; + int nb_pci_devices; + bool is_dmi_valid; + bool is_pxe_valid; + + bool dmi_detection; /* Does the dmi stuff have been already detected */ + bool pci_detection; /* Does the pci stuff have been already detected */ + bool cpu_detection; /* Does the cpu stuff have been already detected */ + bool disk_detection; /* Does the disk stuff have been already detected */ + bool pxe_detection; /* Does the pxe stuff have been already detected*/ + + char syslinux_fs[22]; + struct syslinux_version *sv; + char modules_pcimap_path[255]; + char pciids_path[255]; +}; + +char *find_argument(const char **argv, const char *argument); +int detect_dmi(struct s_hardware *hardware); +void detect_disks(struct s_hardware *hardware); +void detect_pci(struct s_hardware *hardware); +void cpu_detect(struct s_hardware *hardware); +int detect_pxe(struct s_hardware *hardware); +void init_hardware(struct s_hardware *hardware); +void clear_screen(void); +void detect_syslinux(struct s_hardware *hardware); +void detect_parameters(int argc, char *argv[], struct s_hardware *hardware); +#endif diff --git a/com32/hdt/hdt-menu-about.c b/com32/hdt/hdt-menu-about.c new file mode 100644 index 00000000..51032402 --- /dev/null +++ b/com32/hdt/hdt-menu-about.c @@ -0,0 +1,64 @@ +/* ----------------------------------------------------------------------- * + * + * 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-menu.h" + +/* Computing About menu*/ +void compute_aboutmenu(struct s_my_menu *menu) { + char buffer[SUBMENULEN+1]; + char statbuffer[STATLEN+1]; + + menu->menu = add_menu(" About ",-1); + menu->items_count=0; + + set_menu_pos(SUBMENU_Y,SUBMENU_X); + + snprintf(buffer, sizeof buffer, "Product : %s", PRODUCT_NAME); + snprintf(statbuffer, sizeof statbuffer, "Product : %s", PRODUCT_NAME); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer, sizeof buffer, "Version : %s", VERSION); + snprintf(statbuffer, sizeof statbuffer, "Version : %s", VERSION); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer, sizeof buffer, "Author : %s", AUTHOR); + snprintf(statbuffer, sizeof statbuffer, "Author : %s", AUTHOR); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer, sizeof buffer, "Contact : %s", CONTACT); + snprintf(statbuffer, sizeof statbuffer, "Contact : %s", CONTACT); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + printf("MENU: About menu done (%d items)\n",menu->items_count); + +} + diff --git a/com32/hdt/hdt-menu-disk.c b/com32/hdt/hdt-menu-disk.c new file mode 100644 index 00000000..9c96e787 --- /dev/null +++ b/com32/hdt/hdt-menu-disk.c @@ -0,0 +1,148 @@ +/* ----------------------------------------------------------------------- * + * + * 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-menu.h" + +/* Compute the disk submenu */ +int compute_disk_module(struct s_my_menu *menu, int nb_sub_disk_menu,struct diskinfo *d,int disk_number) { + char buffer[MENULEN+1]; + char statbuffer[STATLEN+1]; + + /* No need to add no existing devices*/ + if (strlen(d[disk_number].aid.model)<=0) return -1; + + snprintf(buffer,sizeof buffer," Disk <%d> ",nb_sub_disk_menu); + menu[nb_sub_disk_menu].menu = add_menu(buffer,-1); + menu[nb_sub_disk_menu].items_count=0; + + snprintf(buffer,sizeof buffer,"Model : %s",d[disk_number].aid.model); + snprintf(statbuffer,sizeof statbuffer,"Model: %s",d[disk_number].aid.model); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu[nb_sub_disk_menu].items_count++; + + /* Compute device size */ + char previous_unit[3],unit[3]; //GB + int previous_size,size = d[disk_number].sectors/2; // Converting to bytes + strlcpy(unit,"KB",2); + strlcpy(previous_unit,unit,2); + previous_size=size; + if (size>1000) { + size=size/1000; + strlcpy(unit,"MB",2); + if (size>1000) { + previous_size=size; + size=size/1000; + strlcpy(previous_unit,unit,2); + strlcpy(unit,"GB",2); + if (size>1000) { + previous_size=size; + size=size/1000; + strlcpy(previous_unit,unit,2); + strlcpy(unit,"TB",2); + } + } + } + + snprintf(buffer,sizeof buffer,"Size : %d %s (%d %s)",size,unit,previous_size,previous_unit); + snprintf(statbuffer, sizeof statbuffer, "Size: %d %s (%d %s)",size,unit,previous_size,previous_unit); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu[nb_sub_disk_menu].items_count++; + + snprintf(buffer,sizeof buffer,"Firmware Rev.: %s",d[disk_number].aid.fw_rev); + snprintf(statbuffer,sizeof statbuffer,"Firmware Revision: %s",d[disk_number].aid.fw_rev); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu[nb_sub_disk_menu].items_count++; + + snprintf(buffer,sizeof buffer,"Serial Number: %s",d[disk_number].aid.serial_no); + snprintf(statbuffer,sizeof statbuffer,"Serial Number: %s",d[disk_number].aid.serial_no); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu[nb_sub_disk_menu].items_count++; + + snprintf(buffer,sizeof buffer,"Interface : %s",d[disk_number].interface_type); + snprintf(statbuffer,sizeof statbuffer,"Interface: %s",d[disk_number].interface_type); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu[nb_sub_disk_menu].items_count++; + + snprintf(buffer,sizeof buffer,"Host Bus : %s",d[disk_number].host_bus_type); + snprintf(statbuffer,sizeof statbuffer,"Host Bus Type: %s",d[disk_number].host_bus_type); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu[nb_sub_disk_menu].items_count++; + + snprintf(buffer,sizeof buffer, "Sectors : %d",d[disk_number].sectors); + snprintf(statbuffer,sizeof statbuffer, "Sectors: %d",d[disk_number].sectors); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu[nb_sub_disk_menu].items_count++; + + snprintf(buffer,sizeof buffer,"Heads : %d",d[disk_number].heads); + snprintf(statbuffer,sizeof statbuffer,"Heads: %d",d[disk_number].heads); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu[nb_sub_disk_menu].items_count++; + + snprintf(buffer, sizeof buffer,"Cylinders : %d",d[disk_number].cylinders); + snprintf(statbuffer, sizeof statbuffer,"Cylinders: %d",d[disk_number].cylinders); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu[nb_sub_disk_menu].items_count++; + + snprintf(buffer,sizeof buffer, "Sectors/Track: %d",d[disk_number].sectors_per_track); + snprintf(statbuffer,sizeof statbuffer, "Sectors per Track: %d",d[disk_number].sectors_per_track); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu[nb_sub_disk_menu].items_count++; + + snprintf(buffer,sizeof buffer,"Port : 0x%X",disk_number); + snprintf(statbuffer,sizeof statbuffer,"Port: 0x%X",disk_number); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu[nb_sub_disk_menu].items_count++; + + snprintf(buffer,sizeof buffer,"EDD Version : %s",d[disk_number].edd_version); + snprintf(statbuffer,sizeof statbuffer,"EDD Version: %s",d[disk_number].edd_version); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu[nb_sub_disk_menu].items_count++; + + return 0; +} + +/* Compute the Disk Menu*/ +void compute_disks(struct s_hdt_menu *menu, struct diskinfo *disk_info) { + char buffer[MENULEN+1]; + int nb_sub_disk_menu=0; + for (int i=0;i<0xff;i++) { + if (compute_disk_module(&(menu->disk_sub_menu),nb_sub_disk_menu,disk_info,i) == 0) + nb_sub_disk_menu++; + } + + menu->disk_menu.menu = add_menu(" Disks ",-1); + menu->disk_menu.items_count=0; + + for (int i=0;i<nb_sub_disk_menu;i++) { + snprintf(buffer,sizeof buffer," Disk <%d> ",i); + add_item(buffer,"Disk",OPT_SUBMENU,NULL,menu->disk_sub_menu[i].menu); + menu->disk_menu.items_count++; + } + printf("MENU: Disks menu done (%d items)\n",menu->disk_menu.items_count); +} + diff --git a/com32/hdt/hdt-menu-dmi.c b/com32/hdt/hdt-menu-dmi.c new file mode 100644 index 00000000..485f25ec --- /dev/null +++ b/com32/hdt/hdt-menu-dmi.c @@ -0,0 +1,383 @@ +/* ----------------------------------------------------------------------- * + * + * 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-menu.h" + +/* Compute System main menu */ +void compute_system(struct s_my_menu *menu,s_dmi *dmi) { + char buffer[SUBMENULEN+1]; + char statbuffer[STATLEN+1]; + + menu->menu = add_menu(" System ",-1); + menu->items_count=0; + set_menu_pos(SUBMENU_Y,SUBMENU_X); + + snprintf(buffer,sizeof buffer,"Vendor : %s",dmi->system.manufacturer); + snprintf(statbuffer,sizeof statbuffer,"Vendor: %s",dmi->system.manufacturer); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer,sizeof buffer,"Product : %s",dmi->system.product_name); + snprintf(statbuffer,sizeof statbuffer,"Product Name: %s",dmi->system.product_name); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer,sizeof buffer,"Version : %s",dmi->system.version); + snprintf(statbuffer,sizeof statbuffer,"Version: %s",dmi->system.version); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer,sizeof buffer,"Serial : %s",dmi->system.serial); + snprintf(statbuffer,sizeof statbuffer,"Serial Number: %s",dmi->system.serial); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer,sizeof buffer,"UUID : %s",dmi->system.uuid); + snprintf(statbuffer,sizeof statbuffer,"UUID: %s",dmi->system.uuid); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer,sizeof buffer,"Wakeup : %s",dmi->system.wakeup_type); + snprintf(statbuffer,sizeof statbuffer,"Wakeup Type: %s",dmi->system.wakeup_type); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer,sizeof buffer,"SKU Number: %s",dmi->system.sku_number); + snprintf(statbuffer,sizeof statbuffer,"SKU Number: %s",dmi->system.sku_number); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer,sizeof buffer,"Family : %s",dmi->system.family); + snprintf(statbuffer,sizeof statbuffer,"Family: %s",dmi->system.family); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + printf("MENU: System menu done (%d items)\n",menu->items_count); +} + +/* Compute Chassis menu */ +void compute_chassis(struct s_my_menu *menu,s_dmi *dmi) { + char buffer[SUBMENULEN+1]; + char statbuffer[STATLEN+1]; + menu->menu = add_menu(" Chassis ",-1); + menu->items_count=0; + set_menu_pos(SUBMENU_Y,SUBMENU_X); + + snprintf(buffer,sizeof buffer,"Vendor : %s",dmi->chassis.manufacturer); + snprintf(statbuffer,sizeof statbuffer,"Vendor: %s",dmi->chassis.manufacturer); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer,sizeof buffer,"Type : %s",dmi->chassis.type); + snprintf(statbuffer,sizeof statbuffer,"Type: %s",dmi->chassis.type); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer,sizeof buffer,"Version : %s",dmi->chassis.version); + snprintf(statbuffer,sizeof statbuffer,"Version: %s",dmi->chassis.version); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer,sizeof buffer,"Serial : %s",dmi->chassis.serial); + snprintf(statbuffer,sizeof statbuffer,"Serial Number: %s",dmi->chassis.serial); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer,sizeof buffer,"Asset Tag : %s",dmi->chassis.asset_tag); + snprintf(statbuffer,sizeof statbuffer,"Asset Tag: %s",dmi->chassis.asset_tag); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer,sizeof buffer,"Lock : %s",dmi->chassis.lock); + snprintf(statbuffer,sizeof statbuffer,"Lock: %s",dmi->chassis.lock); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + printf("MENU: Chassis menu done (%d items)\n", menu->items_count); +} + +/* Compute BIOS menu */ +void compute_bios(struct s_my_menu *menu,s_dmi *dmi) { + char buffer[SUBMENULEN+1]; + char statbuffer[STATLEN+1]; + + menu->menu = add_menu(" BIOS ",-1); + menu->items_count=0; + set_menu_pos(SUBMENU_Y,SUBMENU_X); + + snprintf(buffer,sizeof buffer,"Vendor : %s",dmi->bios.vendor); + snprintf(statbuffer,sizeof statbuffer,"Vendor: %s",dmi->bios.vendor); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer,sizeof buffer,"Version : %s",dmi->bios.version); + snprintf(statbuffer,sizeof statbuffer,"Version: %s",dmi->bios.version); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer,sizeof buffer,"Release : %s",dmi->bios.release_date); + snprintf(statbuffer,sizeof statbuffer,"Release Date: %s",dmi->bios.release_date); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer,sizeof buffer,"Bios Rev. : %s",dmi->bios.bios_revision); + snprintf(statbuffer,sizeof statbuffer,"Bios Revision: %s",dmi->bios.bios_revision); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer,sizeof buffer,"Fw. Rev. : %s",dmi->bios.firmware_revision); + snprintf(statbuffer,sizeof statbuffer,"Firmware Revision : %s",dmi->bios.firmware_revision); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + + printf("MENU: BIOS menu done (%d items)\n",menu->items_count); +} + +/* Compute Motherboard main menu */ +void compute_motherboard(struct s_my_menu *menu,s_dmi *dmi) { + char buffer[SUBMENULEN+1]; + char statbuffer[STATLEN+1]; + + menu->menu = add_menu(" Motherboard ",-1); + menu->items_count=0; + set_menu_pos(SUBMENU_Y,SUBMENU_X); + + snprintf(buffer,sizeof buffer,"Vendor : %s",dmi->base_board.manufacturer); + snprintf(statbuffer,sizeof statbuffer,"Vendor: %s",dmi->base_board.manufacturer); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer,sizeof buffer,"Product : %s",dmi->base_board.product_name); + snprintf(statbuffer,sizeof statbuffer,"Product Name: %s",dmi->base_board.product_name); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer,sizeof buffer,"Version : %s",dmi->base_board.version); + snprintf(statbuffer,sizeof statbuffer,"Version: %s",dmi->base_board.version); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer,sizeof buffer,"Serial : %s",dmi->base_board.serial); + snprintf(statbuffer,sizeof statbuffer,"Serial Number: %s",dmi->base_board.serial); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer,sizeof buffer,"Asset Tag : %s",dmi->base_board.asset_tag); + snprintf(statbuffer,sizeof statbuffer,"Asset Tag: %s",dmi->base_board.asset_tag); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer,sizeof buffer,"Location : %s",dmi->base_board.location); + snprintf(statbuffer,sizeof statbuffer,"Location: %s",dmi->base_board.location); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer,sizeof buffer,"Type : %s",dmi->base_board.type); + snprintf(statbuffer,sizeof statbuffer,"Type: %s",dmi->base_board.type); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + printf("MENU: Motherboard menu done (%d items)\n",menu->items_count); +} + +/* Compute the memory submenu */ +void compute_memory_module(struct s_my_menu *menu, s_dmi *dmi, int slot_number) { + int i=slot_number; + char buffer[MENULEN+1]; + char statbuffer[STATLEN+1]; + + sprintf(buffer," Bank <%d> ",i); + menu->items_count=0; + menu->menu = add_menu(buffer,-1); + + snprintf(buffer,sizeof buffer,"Form Factor : %s",dmi->memory[i].form_factor); + snprintf(statbuffer,sizeof statbuffer,"Form Factor: %s",dmi->memory[i].form_factor); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer,sizeof buffer,"Type : %s",dmi->memory[i].type); + snprintf(statbuffer,sizeof statbuffer,"Type: %s",dmi->memory[i].type); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer,sizeof buffer,"Type Details : %s",dmi->memory[i].type_detail); + snprintf(statbuffer,sizeof statbuffer,"Type Details: %s",dmi->memory[i].type_detail); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer,sizeof buffer,"Speed : %s",dmi->memory[i].speed); + snprintf(statbuffer,sizeof statbuffer,"Speed (Mhz): %s",dmi->memory[i].speed); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer,sizeof buffer,"Size : %s",dmi->memory[i].size); + snprintf(statbuffer,sizeof statbuffer,"Size: %s",dmi->memory[i].size); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer,sizeof buffer,"Device Set : %s",dmi->memory[i].device_set); + snprintf(statbuffer,sizeof statbuffer,"Device Set: %s",dmi->memory[i].device_set); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer,sizeof buffer,"Device Loc. : %s",dmi->memory[i].device_locator); + snprintf(statbuffer,sizeof statbuffer,"Device Location: %s",dmi->memory[i].device_locator); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer,sizeof buffer,"Bank Locator : %s",dmi->memory[i].bank_locator); + snprintf(statbuffer,sizeof statbuffer,"Bank Locator: %s",dmi->memory[i].bank_locator); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer,sizeof buffer,"Total Width : %s",dmi->memory[i].total_width); + snprintf(statbuffer,sizeof statbuffer,"Total bit Width: %s",dmi->memory[i].total_width); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer,sizeof buffer,"Data Width : %s",dmi->memory[i].data_width); + snprintf(statbuffer,sizeof statbuffer,"Data bit Width: %s",dmi->memory[i].data_width); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer,sizeof buffer,"Error : %s",dmi->memory[i].error); + snprintf(statbuffer,sizeof statbuffer,"Error: %s",dmi->memory[i].error); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer,sizeof buffer,"Vendor : %s",dmi->memory[i].manufacturer); + snprintf(statbuffer,sizeof statbuffer,"Vendor: %s",dmi->memory[i].manufacturer); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer,sizeof buffer,"Serial : %s",dmi->memory[i].serial); + snprintf(statbuffer,sizeof statbuffer,"Serial: %s",dmi->memory[i].serial); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer,sizeof buffer,"Asset Tag : %s",dmi->memory[i].asset_tag); + snprintf(statbuffer,sizeof statbuffer,"Asset Tag: %s",dmi->memory[i].asset_tag); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer,sizeof buffer,"Part Number : %s",dmi->memory[i].part_number); + snprintf(buffer,sizeof statbuffer,"Part Number: %s",dmi->memory[i].part_number); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + +} + +/* Compute the Memory Menu*/ +void compute_memory(struct s_hdt_menu *menu, s_dmi *dmi) { + char buffer[MENULEN+1]; + for (int i=0;i<dmi->memory_count;i++) { + compute_memory_module(&(menu->memory_sub_menu[i]),dmi,i); + } + + menu->memory_menu.menu = add_menu(" Memory Banks ",-1); + menu->memory_menu.items_count=0; + + for (int i=0;i<dmi->memory_count;i++) { + snprintf(buffer,sizeof buffer," Bank <%d> ",i); + add_item(buffer,"Memory Bank",OPT_SUBMENU,NULL,menu->memory_sub_menu[i].menu); + menu->memory_menu.items_count++; + } + printf("MENU: Memory menu done (%d items)\n",menu->memory_menu.items_count); + add_item("Run Test","Run Test",OPT_RUN,"memtest",0); +} + + +/* Main Battery Menu*/ +void compute_battery(struct s_my_menu *menu, s_dmi *dmi) { + char buffer[SUBMENULEN+1]; + char statbuffer[STATLEN+1]; + menu->menu = add_menu(" Battery ",-1); + menu->items_count=0; + set_menu_pos(SUBMENU_Y,SUBMENU_X); + + snprintf(buffer, sizeof buffer,"Vendor : %s",dmi->battery.manufacturer); + snprintf(statbuffer, sizeof statbuffer,"Vendor: %s",dmi->battery.manufacturer); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer, sizeof buffer,"Manufacture Date: %s",dmi->battery.manufacture_date); + snprintf(statbuffer, sizeof statbuffer,"Manufacture Date: %s",dmi->battery.manufacture_date); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer, sizeof buffer,"Serial : %s",dmi->battery.serial); + snprintf(statbuffer, sizeof statbuffer,"Serial: %s",dmi->battery.serial); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer, sizeof buffer,"Name : %s",dmi->battery.name); + snprintf(statbuffer, sizeof statbuffer,"Name: %s",dmi->battery.name); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer, sizeof buffer,"Chemistry : %s",dmi->battery.chemistry); + snprintf(statbuffer, sizeof statbuffer,"Chemistry: %s",dmi->battery.chemistry); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer, sizeof buffer,"Design Capacity : %s",dmi->battery.design_capacity); + snprintf(statbuffer, sizeof statbuffer,"Design Capacity: %s",dmi->battery.design_capacity); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer, sizeof buffer,"Design Voltage : %s",dmi->battery.design_voltage); + snprintf(statbuffer, sizeof statbuffer,"Design Voltage : %s",dmi->battery.design_voltage); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer, sizeof buffer,"SBDS : %s",dmi->battery.sbds); + snprintf(statbuffer, sizeof statbuffer,"SBDS: %s",dmi->battery.sbds); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer, sizeof buffer,"SBDS Manuf. Date: %s",dmi->battery.sbds_manufacture_date); + snprintf(statbuffer, sizeof statbuffer,"SBDS Manufacture Date: %s",dmi->battery.sbds_manufacture_date); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer, sizeof buffer,"SBDS Chemistry : %s",dmi->battery.sbds_chemistry); + snprintf(statbuffer, sizeof statbuffer,"SBDS Chemistry : %s",dmi->battery.sbds_chemistry); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer, sizeof buffer,"Maximum Error : %s",dmi->battery.maximum_error); + snprintf(statbuffer, sizeof statbuffer,"Maximum Error (%) : %s",dmi->battery.maximum_error); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer, sizeof buffer,"OEM Info : %s",dmi->battery.oem_info); + snprintf(statbuffer, sizeof statbuffer,"OEM Info: %s",dmi->battery.oem_info); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + printf("MENU: Battery menu done (%d items)\n",menu->items_count); +} diff --git a/com32/hdt/hdt-menu-kernel.c b/com32/hdt/hdt-menu-kernel.c new file mode 100644 index 00000000..39979279 --- /dev/null +++ b/com32/hdt/hdt-menu-kernel.c @@ -0,0 +1,73 @@ +/* ----------------------------------------------------------------------- * + * + * 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-menu.h" + +/* Main Kernel Menu*/ +void compute_kernel(struct s_my_menu *menu,struct s_hardware *hardware) { + char buffer[SUBMENULEN+1]; + char infobar[STATLEN+1]; + char kernel_modules [LINUX_KERNEL_MODULE_SIZE*MAX_KERNEL_MODULES_PER_PCI_DEVICE]; + struct pci_device *pci_device; + + menu->menu = add_menu(" Kernel Modules ",-1); + menu->items_count=0; + set_menu_pos(SUBMENU_Y,SUBMENU_X); + + if (hardware->modules_pcimap_return_code == -ENOMODULESPCIMAP) { + add_item("The modules.pcimap file is missing","Missing modules.pcimap file",OPT_INACTIVE,NULL,0); + add_item("Kernel modules can't be computed.","Missing modules.pcimap file",OPT_INACTIVE,NULL,0); + add_item("Please put one in same dir as hdt","Missing modules.pcimap file",OPT_INACTIVE,NULL,0); + add_item("","",OPT_SEP,"",0); + } else { + /* For every detected pci device, grab its kernel module to compute this submenu */ + for_each_pci_func(pci_device, hardware->pci_domain) { + memset(kernel_modules,0,sizeof kernel_modules); + for (int i=0; i<pci_device->dev_info->linux_kernel_module_count;i++) { + if (i>0) { + strncat(kernel_modules," | ",3); + } + strncat(kernel_modules, pci_device->dev_info->linux_kernel_module[i],LINUX_KERNEL_MODULE_SIZE-1); + } + /* No need to add unknown kernel modules*/ + if (strlen(kernel_modules)>0) { + snprintf(buffer,sizeof buffer,"%s (%s)",kernel_modules, pci_device->dev_info->class_name); + snprintf(infobar, sizeof infobar,"%04x:%04x %s : %s\n", + pci_device->vendor, pci_device->product, + pci_device->dev_info->vendor_name, + pci_device->dev_info->product_name); + + add_item(buffer,infobar,OPT_INACTIVE,NULL,0); + menu->items_count++; + } + } + } + + printf("MENU: Kernel menu done (%d items)\n",menu->items_count); +} + diff --git a/com32/hdt/hdt-menu-pci.c b/com32/hdt/hdt-menu-pci.c new file mode 100644 index 00000000..477ba4aa --- /dev/null +++ b/com32/hdt/hdt-menu-pci.c @@ -0,0 +1,125 @@ +/* ----------------------------------------------------------------------- * + * + * 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-menu.h" + + +/* Dynamic submenu for the pci devices */ +void compute_pci_device(struct s_my_menu *menu,struct pci_device *pci_device,int pci_bus, int pci_slot, int pci_func) { + char buffer[56]; + char statbuffer[STATLEN]; + char kernel_modules [LINUX_KERNEL_MODULE_SIZE*MAX_KERNEL_MODULES_PER_PCI_DEVICE]; + + menu->menu = add_menu(" Details ",-1); + menu->items_count=0; + set_menu_pos(5,17); + + snprintf(buffer,sizeof buffer,"Vendor : %s",pci_device->dev_info->vendor_name); + snprintf(statbuffer,sizeof statbuffer,"Vendor Name: %s",pci_device->dev_info->vendor_name); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer,sizeof buffer,"Product : %s",pci_device->dev_info->product_name); + snprintf(statbuffer,sizeof statbuffer,"Product Name %s",pci_device->dev_info->product_name); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer,sizeof buffer,"Class : %s",pci_device->dev_info->class_name); + snprintf(statbuffer,sizeof statbuffer,"Class Name: %s",pci_device->dev_info->class_name); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer,sizeof buffer,"Location: %02x:%02x.%01x",pci_bus, pci_slot, pci_func); + snprintf(statbuffer,sizeof statbuffer,"Location on the PCI Bus: %02x:%02x.%01x",pci_bus, pci_slot, pci_func); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer,sizeof buffer,"PCI ID : %04x:%04x[%04x:%04x]",pci_device->vendor, pci_device->product,pci_device->sub_vendor, pci_device->sub_product); + snprintf(statbuffer,sizeof statbuffer,"vendor:product[sub_vendor:sub_product] : %04x:%04x[%04x:%04x]",pci_device->vendor, pci_device->product,pci_device->sub_vendor, pci_device->sub_product); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + if (pci_device->dev_info->linux_kernel_module_count>1) { + for (int i=0; i<pci_device->dev_info->linux_kernel_module_count;i++) { + if (i>0) { + strncat(kernel_modules," | ",3); + } + strncat(kernel_modules, pci_device->dev_info->linux_kernel_module[i],LINUX_KERNEL_MODULE_SIZE-1); + } + snprintf(buffer,sizeof buffer,"Modules : %s",kernel_modules); + snprintf(statbuffer,sizeof statbuffer,"Kernel Modules: %s",kernel_modules); + } else { + snprintf(buffer,sizeof buffer,"Module : %s",pci_device->dev_info->linux_kernel_module[0]); + snprintf(statbuffer,sizeof statbuffer,"Kernel Module: %s",pci_device->dev_info->linux_kernel_module[0]); + } + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; +} + +/* Main PCI Menu*/ +int compute_PCI(struct s_hdt_menu *hdt_menu, struct s_hardware *hardware) { + int i=0; + char menuname[255][MENULEN+1]; + char infobar[255][STATLEN+1]; + struct pci_device *pci_device; + char kernel_modules [LINUX_KERNEL_MODULE_SIZE*MAX_KERNEL_MODULES_PER_PCI_DEVICE]; + + /* For every detected pci device, compute its submenu */ + for_each_pci_func(pci_device, hardware->pci_domain) { + memset(kernel_modules,0,sizeof kernel_modules); + for (int kmod=0; kmod<pci_device->dev_info->linux_kernel_module_count;kmod++) { + if (kmod>0) { + strncat(kernel_modules," | ",3); + } + strncat(kernel_modules, pci_device->dev_info->linux_kernel_module[kmod],LINUX_KERNEL_MODULE_SIZE-1); + } + if (pci_device->dev_info->linux_kernel_module_count==0) strlcpy(kernel_modules,"unknown",7); + + compute_pci_device(&(hdt_menu->pci_sub_menu[i]),pci_device,__pci_bus,__pci_slot,__pci_func); + snprintf(menuname[i],59,"%s|%s",pci_device->dev_info->vendor_name,pci_device->dev_info->product_name); + snprintf(infobar[i], STATLEN,"%02x:%02x.%01x # %s # ID:%04x:%04x[%04x:%04x] # Kmod:%s\n", + __pci_bus, __pci_slot, __pci_func,pci_device->dev_info->class_name, + pci_device->vendor, pci_device->product, + pci_device->sub_vendor, pci_device->sub_product,kernel_modules); + i++; + } + + hdt_menu->pci_menu.menu = add_menu(" PCI Devices ",-1); + hdt_menu->pci_menu.items_count=0; + if (hardware->pci_ids_return_code == -ENOPCIIDS) { + add_item("The pci.ids file is missing","Missing pci.ids file",OPT_INACTIVE,NULL,0); + add_item("PCI Device names can't be computed.","Missing pci.ids file",OPT_INACTIVE,NULL,0); + add_item("Please put one in same dir as hdt","Missing pci.ids file",OPT_INACTIVE,NULL,0); + add_item("","",OPT_SEP,"",0); + } + for (int j=0;j<i;j++) { + add_item(menuname[j],infobar[j],OPT_SUBMENU,NULL,hdt_menu->pci_sub_menu[j].menu); + hdt_menu->pci_menu.items_count++; + } + printf("MENU: PCI menu done (%d items)\n",hdt_menu->pci_menu.items_count); + return 0; +} diff --git a/com32/hdt/hdt-menu-processor.c b/com32/hdt/hdt-menu-processor.c new file mode 100644 index 00000000..d0d7dd7b --- /dev/null +++ b/com32/hdt/hdt-menu-processor.c @@ -0,0 +1,186 @@ +/* ----------------------------------------------------------------------- * + * + * 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-menu.h" + +/* Compute Processor menu */ +void compute_processor(struct s_my_menu *menu,struct s_hardware *hardware) { + char buffer[SUBMENULEN+1]; + char buffer1[SUBMENULEN+1]; + char statbuffer[STATLEN+1]; + + menu->menu = add_menu(" Main Processor ",-1); + menu->items_count=0; + set_menu_pos(SUBMENU_Y,SUBMENU_X); + + 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",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",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",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",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",hardware->cpu.stepping); + snprintf(statbuffer,sizeof statbuffer,"Stepping: %d",hardware->cpu.stepping); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + 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",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",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", 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 (hardware->cpu.flags.smp) { + snprintf(buffer,sizeof buffer,"SMP : Yes"); + snprintf(statbuffer,sizeof statbuffer,"SMP: Yes"); + } + else { + snprintf(buffer,sizeof buffer,"SMP : No"); + snprintf(statbuffer,sizeof statbuffer,"SMP: No"); + } + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + if (hardware->cpu.flags.lm) { + snprintf(buffer,sizeof buffer,"x86_64 : Yes"); + snprintf(statbuffer,sizeof statbuffer,"x86_64 compatible processor: Yes"); + } + else { + snprintf(buffer,sizeof buffer,"X86_64 : No"); + snprintf(statbuffer,sizeof statbuffer,"X86_64 compatible processor: No"); + } + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + buffer1[0]='\0'; + 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 (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 (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 (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 (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 (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); + menu->items_count++; + + printf("MENU: Processor menu done (%d items)\n",menu->items_count); +} diff --git a/com32/hdt/hdt-menu-pxe.c b/com32/hdt/hdt-menu-pxe.c new file mode 100644 index 00000000..5ab3d8b3 --- /dev/null +++ b/com32/hdt/hdt-menu-pxe.c @@ -0,0 +1,99 @@ +/* ----------------------------------------------------------------------- * + * + * 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-menu.h" + +/* Main Kernel Menu*/ +void compute_PXE(struct s_my_menu *menu,struct s_hardware *hardware) { + char buffer[SUBMENULEN+1]; + char infobar[STATLEN+1]; + + if (hardware->is_pxe_valid==false) return; + + menu->menu = add_menu(" PXE ",-1); + menu->items_count=0; + set_menu_pos(SUBMENU_Y,SUBMENU_X); + + struct s_pxe *p = &hardware->pxe; + + if (hardware->pci_ids_return_code == -ENOPCIIDS) { + snprintf(buffer,sizeof buffer, "PCI Vendor : %d",p->vendor_id); + snprintf(infobar,sizeof infobar,"PCI Vendor : %d",p->vendor_id); + add_item(buffer,infobar,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer,sizeof buffer, "PCI Product : %d",p->vendor_id); + snprintf(infobar,sizeof infobar,"PCI Product : %d",p->vendor_id); + add_item(buffer,infobar,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer,sizeof buffer, "PCI SubVendor : %d",p->subvendor_id); + snprintf(infobar,sizeof infobar,"PCI SubVendor : %d",p->subvendor_id); + add_item(buffer,infobar,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer,sizeof buffer, "PCI SubProduct : %d",p->subproduct_id); + snprintf(infobar,sizeof infobar,"PCI SubProduct : %d",p->subproduct_id); + add_item(buffer,infobar,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer,sizeof buffer, "PCI Revision : %d",p->rev); + snprintf(infobar,sizeof infobar,"PCI Revision : %d",p->rev); + add_item(buffer,infobar,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer,sizeof buffer, "PCI Bus Pos. : %02x:%02x.%02x",p->pci_bus,p->pci_dev, p->pci_func); + snprintf(infobar,sizeof infobar,"PCI Bus Pos. : %02x:%02x.%02x",p->pci_bus,p->pci_dev, p->pci_func); + add_item(buffer,infobar,OPT_INACTIVE,NULL,0); + menu->items_count++; + + } else { + + snprintf(buffer,sizeof buffer, "Manufacturer : %s", p->pci_device->dev_info->vendor_name); + snprintf(infobar,sizeof infobar,"Manufacturer : %s", p->pci_device->dev_info->vendor_name); + add_item(buffer,infobar,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer,sizeof buffer, "Product : %s", p->pci_device->dev_info->product_name); + snprintf(infobar,sizeof infobar,"Product : %s", p->pci_device->dev_info->product_name); + add_item(buffer,infobar,OPT_INACTIVE,NULL,0); + menu->items_count++; + } + + snprintf(buffer,sizeof buffer, "MAC Address : %s", p->mac_addr); + snprintf(infobar,sizeof infobar, "MAC Address : %s", p->mac_addr); + add_item(buffer,infobar,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer,sizeof buffer, "IP Address : %d.%d.%d.%d", p->ip_addr[0], p->ip_addr[1], p->ip_addr[2], p->ip_addr[3]); + snprintf(infobar,sizeof infobar, "IP Address : %d.%d.%d.%d", p->ip_addr[0], p->ip_addr[1], p->ip_addr[2], p->ip_addr[3]); + add_item(buffer,infobar,OPT_INACTIVE,NULL,0); + menu->items_count++; + + printf("MENU: PXE menu done (%d items)\n",menu->items_count); +} diff --git a/com32/hdt/hdt-menu-summary.c b/com32/hdt/hdt-menu-summary.c new file mode 100644 index 00000000..9bbefbfe --- /dev/null +++ b/com32/hdt/hdt-menu-summary.c @@ -0,0 +1,158 @@ +/* ----------------------------------------------------------------------- * + * + * 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-menu.h" + +/* Computing Summary menu*/ +void compute_summarymenu(struct s_my_menu *menu, struct s_hardware *hardware) { + char buffer[SUBMENULEN+1]; + char statbuffer[STATLEN+1]; + char bank_number[10]; + + menu->menu = add_menu(" Summary ",-1); + menu->items_count=0; + + set_menu_pos(SUBMENU_Y,SUBMENU_X); + + snprintf(buffer,sizeof buffer,"CPU Vendor : %s",hardware->cpu.vendor); + snprintf(statbuffer,sizeof statbuffer,"CPU Vendor: %s",hardware->cpu.vendor); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer,sizeof buffer,"CPU Model : %s",hardware->cpu.model); + snprintf(statbuffer,sizeof statbuffer,"CPU Model: %s",hardware->cpu.model); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + add_item("","",OPT_SEP,"",0); + if (hardware->is_dmi_valid == true) { + + snprintf(buffer,sizeof buffer,"System Vendor : %s",hardware->dmi.system.manufacturer); + snprintf(statbuffer,sizeof statbuffer,"System Vendor: %s",hardware->dmi.system.manufacturer); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer,sizeof buffer,"System Product: %s",hardware->dmi.system.product_name); + snprintf(statbuffer,sizeof statbuffer,"System Product Name: %s",hardware->dmi.system.product_name); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer,sizeof buffer,"System Serial : %s",hardware->dmi.system.serial); + snprintf(statbuffer,sizeof statbuffer,"System Serial Number: %s",hardware->dmi.system.serial); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + add_item("","",OPT_SEP,"",0); + + snprintf(buffer,sizeof buffer,"Bios Version : %s",hardware->dmi.bios.version); + snprintf(statbuffer,sizeof statbuffer,"Bios Version: %s",hardware->dmi.bios.version); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer,sizeof buffer,"Bios Release : %s",hardware->dmi.bios.release_date); + snprintf(statbuffer,sizeof statbuffer,"Bios Release Date: %s",hardware->dmi.bios.release_date); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + add_item("","",OPT_SEP,"",0); + + for (int i=0;i<hardware->dmi.memory_count;i++) { + if (hardware->dmi.memory[i].filled==true) { + /* When discovering the first item, let's clear the screen */ + memset(bank_number,0,sizeof(bank_number)); + snprintf(bank_number,sizeof(bank_number),"%d ",i); + if (strncmp(hardware->dmi.memory[i].size,"Free",4)) { + snprintf(buffer,sizeof buffer,"Mem bank %02d : %s %s@%s", + i,hardware->dmi.memory[i].size, hardware->dmi.memory[i].type, hardware->dmi.memory[i].speed); + snprintf(statbuffer,sizeof statbuffer,"Memory bank %02d : %s %s@%s", + i,hardware->dmi.memory[i].size, hardware->dmi.memory[i].type, hardware->dmi.memory[i].speed); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + } + } + } + + add_item("","",OPT_SEP,"",0); + } + + snprintf(buffer,sizeof buffer,"Nb PCI Devices: %d",hardware->nb_pci_devices); + snprintf(statbuffer,sizeof statbuffer,"Number of PCI Devices: %d",hardware->nb_pci_devices); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + add_item("","",OPT_SEP,"",0); + + if (hardware->is_pxe_valid==true) { + struct s_pxe *p = &hardware->pxe; + + snprintf(buffer,sizeof buffer, "PXE MAC Address: %s", p->mac_addr); + snprintf(statbuffer,sizeof statbuffer, "PXE MAC Address: %s", p->mac_addr); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer,sizeof buffer, "PXE IP Address : %d.%d.%d.%d", p->ip_addr[0], p->ip_addr[1], p->ip_addr[2], p->ip_addr[3]); + snprintf(statbuffer,sizeof statbuffer, "PXE IP Address: %d.%d.%d.%d", p->ip_addr[0], p->ip_addr[1], p->ip_addr[2], p->ip_addr[3]); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + add_item("","",OPT_SEP,"",0); + } + + if (hardware->modules_pcimap_return_code != -ENOMODULESPCIMAP) { + bool kmod=false; + struct pci_device *pci_device; + char kernel_modules [LINUX_KERNEL_MODULE_SIZE*MAX_KERNEL_MODULES_PER_PCI_DEVICE]; + + /* For every detected pci device, grab its kernel module to compute this submenu */ + for_each_pci_func(pci_device, hardware->pci_domain) { + memset(kernel_modules,0,sizeof kernel_modules); + for (int i=0; i<pci_device->dev_info->linux_kernel_module_count;i++) { + if (i>0) { + strncat(kernel_modules," | ",3); + } + strncat(kernel_modules, pci_device->dev_info->linux_kernel_module[i],LINUX_KERNEL_MODULE_SIZE-1); + } + /* No need to add unknown kernel modules*/ + if (strlen(kernel_modules)>0) { + snprintf(buffer,sizeof buffer,"%s (%s)",kernel_modules, pci_device->dev_info->class_name); + snprintf(statbuffer, sizeof statbuffer,"%04x:%04x %s : %s\n", + pci_device->vendor, pci_device->product, + pci_device->dev_info->vendor_name, + pci_device->dev_info->product_name); + + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + kmod=true; + } + } + if (kmod==true) add_item("","",OPT_SEP,"",0); + } + + printf("MENU: Summary menu done (%d items)\n",menu->items_count); +} + diff --git a/com32/hdt/hdt-menu-syslinux.c b/com32/hdt/hdt-menu-syslinux.c new file mode 100644 index 00000000..d17070f8 --- /dev/null +++ b/com32/hdt/hdt-menu-syslinux.c @@ -0,0 +1,74 @@ +/* ----------------------------------------------------------------------- * + * + * 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 "syslinux/config.h" +#include "hdt-menu.h" + +/* Computing Syslinux menu*/ +void compute_syslinuxmenu(struct s_my_menu *menu, struct s_hardware *hardware) { + char syslinux_fs_menu[24]; + char buffer[SUBMENULEN+1]; + char statbuffer[STATLEN+1]; + + memset(syslinux_fs_menu,0,sizeof syslinux_fs_menu); + + snprintf(syslinux_fs_menu,sizeof syslinux_fs_menu," %s ",hardware->syslinux_fs); + menu->menu = add_menu(syslinux_fs_menu,-1); + menu->items_count=0; + set_menu_pos(SUBMENU_Y,SUBMENU_X); + + snprintf(buffer, sizeof buffer, "Bootloader : %s", hardware->syslinux_fs); + snprintf(statbuffer, sizeof statbuffer, "Bootloader: %s", hardware->syslinux_fs); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer, sizeof buffer, "Version : %s", hardware->sv->version_string+2); + snprintf(statbuffer, sizeof statbuffer, "Version: %s", hardware->sv->version_string+2); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer, sizeof buffer, "Version : %u",hardware->sv->version); + snprintf(statbuffer, sizeof statbuffer, "Version: %u",hardware->sv->version); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + snprintf(buffer, sizeof buffer, "Max API : %u",hardware->sv->max_api); + snprintf(statbuffer, sizeof statbuffer, "Max API: %u",hardware->sv->max_api); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + add_item("","",OPT_SEP,"",0); + + snprintf(buffer, sizeof buffer, "%s", hardware->sv->copyright_string+1); + snprintf(statbuffer, sizeof statbuffer, "%s", hardware->sv->copyright_string+1); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + menu->items_count++; + + printf("MENU: Syslinux menu done (%d items)\n",menu->items_count); +} + diff --git a/com32/hdt/hdt-menu.c b/com32/hdt/hdt-menu.c new file mode 100644 index 00000000..0853f09e --- /dev/null +++ b/com32/hdt/hdt-menu.c @@ -0,0 +1,253 @@ +/* ----------------------------------------------------------------------- * + * + * 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-menu.h" + + + +int start_menu_mode(struct s_hardware *hardware, char *version_string) { + struct s_hdt_menu hdt_menu; + + 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) + { + /* Tweak, we want to switch to the cli*/ + if (! strncmp(curr->data,HDT_SWITCH_TO_CLI,sizeof(HDT_SWITCH_TO_CLI))) { + return HDT_RETURN_TO_CLI; + } + 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() +{ + // beep(); + return CODE_WAIT; +} + +/* Keyboard handler for the menu system */ +void keys_handler(t_menusystem *ms, t_menuitem *mi,unsigned int scancode) +{ + char nc; + + if ((scancode >> 8) == F1) { // If scancode of F1 + runhelpsystem(mi->helpid); + } + // If user hit TAB, and item is an "executable" item + // and user has privileges to edit it, edit it in place. + if (((scancode & 0xFF) == 0x09) && (mi->action == OPT_RUN)) { +//(isallowed(username,"editcmd") || isallowed(username,"root"))) { + nc = getnumcols(); + // User typed TAB and has permissions to edit command line + gotoxy(EDITPROMPT,1,ms->menupage); + csprint("Command line:",0x07); + editstring(mi->data,ACTIONLEN); + gotoxy(EDITPROMPT,1,ms->menupage); + cprint(' ',0x07,nc-1,ms->menupage); + } +} + +/* 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) { + 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)); + for (int i=0;i<hardware->dmi.memory_count;i++) { + if (hardware->dmi.memory[i].filled==true) { + compute_memory(hdt_menu,&(hardware->dmi)); + break; + } + } + if (hardware->dmi.bios.filled==true) compute_bios(&(hdt_menu->bios_menu),&(hardware->dmi)); + if (hardware->dmi.battery.filled==true) 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); + compute_PXE(&(hdt_menu->pxe_menu),hardware); + compute_kernel(&(hdt_menu->kernel_menu),hardware); +#endif + compute_summarymenu(&(hdt_menu->summary_menu),hardware); + compute_syslinuxmenu(&(hdt_menu->syslinux_menu),hardware); + compute_aboutmenu(&(hdt_menu->about_menu)); +} + +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; + + hdt_menu->main_menu.menu = add_menu(" Main Menu ",-1); + set_item_options(-1,24); + +#ifdef WITH_PCI + 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) { + 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) { + 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; + } + 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) { + if (hardware->dmi.base_board.filled==true) { + add_item("M<o>therboard","Motherboard Menu",OPT_SUBMENU,NULL,hdt_menu->mobo_menu.menu); + hdt_menu->main_menu.items_count++; + } + + if (hardware->dmi.bios.filled==true) { + add_item("<B>ios","Bios Menu",OPT_SUBMENU,NULL,hdt_menu->bios_menu.menu); + hdt_menu->main_menu.items_count++; + } + + if (hardware->dmi.chassis.filled==true) { + add_item("<C>hassis","Chassis Menu",OPT_SUBMENU,NULL,hdt_menu->chassis_menu.menu); + hdt_menu->main_menu.items_count++; + } + + if (hardware->dmi.system.filled==true) { + add_item("<S>ystem","System Menu",OPT_SUBMENU,NULL,hdt_menu->system_menu.menu); + hdt_menu->main_menu.items_count++; + } + + if (hardware->dmi.battery.filled==true) { + add_item("Ba<t>tery","Battery Menu",OPT_SUBMENU,NULL,hdt_menu->battery_menu.menu); + hdt_menu->main_menu.items_count++; + } +} + + if (hardware->is_pxe_valid == true) { + add_item("P<X>E","PXE Information Menu",OPT_SUBMENU,NULL,hdt_menu->pxe_menu.menu); + hdt_menu->main_menu.items_count++; + } + + add_item("","",OPT_SEP,"",0); +#ifdef WITH_PCI + if (hardware->modules_pcimap_return_code != -ENOMODULESPCIMAP) { + 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("S<u>mmary","Summary Information Menu",OPT_SUBMENU,NULL,hdt_menu->summary_menu.menu); + hdt_menu->main_menu.items_count++; + + add_item("","",OPT_SEP,"",0); + + add_item("S<w>itch to CLI","Switch to Command Line",OPT_RUN,HDT_SWITCH_TO_CLI,0); + 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"); + cpu_detect(hardware); + + printf("DISKS: Detecting\n"); + detect_disks(hardware); + + printf("DMI: Detecting Table\n"); + if (detect_dmi(hardware) == -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 + detect_pci(hardware); + printf("PCI: %d Devices Found\n",hardware->nb_pci_devices); +#endif +} diff --git a/com32/hdt/hdt-menu.h b/com32/hdt/hdt-menu.h new file mode 100644 index 00000000..db94057a --- /dev/null +++ b/com32/hdt/hdt-menu.h @@ -0,0 +1,121 @@ +/* ----------------------------------------------------------------------- * + * + * 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_MENU_H +#define DEFINE_HDT_MENU_H +#include <stdio.h> +#include "menu.h" +#include "help.h" +//#include "cpuid.h" +#include "sys/pci.h" +#include "hdt-common.h" +#include "dmi/dmi.h" +#include "hdt-ata.h" + +#define EDITPROMPT 21 + +#define SUBMENULEN 46 + +#define SUBMENU_Y 3 +#define SUBMENU_X 29 + +#define MAX_PCI_SUB_MENU 128 +#define MAX_MEMORY_SUB_MENU 32 +#define MAX_DISK_SUB_MENU 32 + +struct s_my_menu { + unsigned char menu; + int items_count; +}; + +struct s_hdt_menu { + struct s_my_menu main_menu; + struct s_my_menu cpu_menu; + struct s_my_menu mobo_menu; + struct s_my_menu chassis_menu; + struct s_my_menu bios_menu; + struct s_my_menu system_menu; + struct s_my_menu pci_menu; + struct s_my_menu pci_sub_menu[MAX_PCI_SUB_MENU]; + struct s_my_menu kernel_menu; + struct s_my_menu memory_menu; + struct s_my_menu memory_sub_menu[MAX_MEMORY_SUB_MENU]; + struct s_my_menu disk_menu; + struct s_my_menu disk_sub_menu[MAX_DISK_SUB_MENU]; + struct s_my_menu battery_menu; + struct s_my_menu syslinux_menu; + struct s_my_menu about_menu; + struct s_my_menu summary_menu; + struct s_my_menu pxe_menu; + int total_menu_count; // sum of all menus we have +}; + +TIMEOUTCODE ontimeout(); +void keys_handler(t_menusystem *ms, t_menuitem *mi,unsigned int scancode); + +// PCI Stuff +void compute_pci_device(struct s_my_menu *menu,struct pci_device *pci_device,int pci_bus, int pci_slot, int pci_func); +int compute_PCI(struct s_hdt_menu *hdt_menu, struct s_hardware *hardware); + +// KERNEL Stuff +void compute_kernel(struct s_my_menu *menu,struct s_hardware *hardware); + +// Disk Stuff +int compute_disk_module(struct s_my_menu *menu, int nb_sub_disk_menu, struct diskinfo *d,int disk_number); +void compute_disks(struct s_hdt_menu *menu, struct diskinfo *disk_info); + +// DMI Stuff +void compute_motherboard(struct s_my_menu *menu,s_dmi *dmi); +void compute_battery(struct s_my_menu *menu, s_dmi *dmi); +void compute_system(struct s_my_menu *menu,s_dmi *dmi); +void compute_chassis(struct s_my_menu *menu,s_dmi *dmi); +void compute_bios(struct s_my_menu *menu,s_dmi *dmi); +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 +void compute_processor(struct s_my_menu *menu,struct s_hardware *hardware); + +// Syslinux stuff +void compute_syslinuxmenu(struct s_my_menu *menu,struct s_hardware *hardware); + +// About menu +void compute_aboutmenu(struct s_my_menu *menu); + +// Summary menu +void compute_summarymenu(struct s_my_menu *menu, struct s_hardware *hardware); + +//PXE menu +void compute_PXE(struct s_my_menu *menu,struct s_hardware *hardware); + +int start_menu_mode(struct s_hardware *hardware, 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 diff --git a/com32/hdt/hdt.c b/com32/hdt/hdt.c new file mode 100644 index 00000000..b417d9da --- /dev/null +++ b/com32/hdt/hdt.c @@ -0,0 +1,79 @@ +/* ----------------------------------------------------------------------- * + * + * 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. + * + * ----------------------------------------------------------------------- +*/ + +/* + * hdt.c + * + * An Hardware Detection Tool + */ + +#include <stdio.h> +#include <console.h> +#include "hdt.h" +#include "hdt-menu.h" +#include "hdt-cli.h" +#include "hdt-common.h" + +int display_line_nb=0; + +int main(int argc, char *argv[]) +{ + char version_string[256]; + char *arg; + struct s_hardware hardware; + + snprintf(version_string,sizeof version_string,"%s %s by %s",PRODUCT_NAME,VERSION,AUTHOR); + + /* Cleaning structures */ + init_hardware(&hardware); + + /* Detecting parameters */ + detect_parameters(argc,argv,&hardware); + + /* Detecting Syslinux Version*/ + detect_syslinux(&hardware); + + /* Opening the syslinux console */ + openconsole(&dev_stdcon_r, &dev_ansicon_w); + + clear_screen(); + printf("%s\n",version_string); + + if ((arg = find_argument(argv+1, "nomenu"))) { + start_cli_mode(&hardware, argc, argv); + } else{ + int return_code = start_menu_mode(&hardware, version_string); + if (return_code == HDT_RETURN_TO_CLI) { + start_cli_mode(&hardware,argc,argv); + } else { + return return_code; + } + } + + return 0; +} diff --git a/com32/hdt/hdt.h b/com32/hdt/hdt.h new file mode 100644 index 00000000..b8563ab5 --- /dev/null +++ b/com32/hdt/hdt.h @@ -0,0 +1,42 @@ +/* ----------------------------------------------------------------------- * + * + * 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_H +#define DEFINE_HDT_H + +#define PRODUCT_NAME "Hardware Detection Tool" +#define AUTHOR "Erwan Velu" +#define CONTACT "erwan(dot)velu(point)free(dot)fr" +#define VERSION "0.2.3" + +#define ATTR_PACKED __attribute__((packed)) + +#define WITH_PCI 1 +#define WITH_MENU_DISPLAY 1 + +#endif diff --git a/com32/include/dmi/dmi_processor.h b/com32/include/dmi/dmi_processor.h deleted file mode 100644 index 26ac97ac..00000000 --- a/com32/include/dmi/dmi_processor.h +++ /dev/null @@ -1,482 +0,0 @@ -/* ----------------------------------------------------------------------- * - * - * Copyright 2006 Erwan Velu - All Rights Reserved - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, Inc., 53 Temple Place Ste 330, - * Boston MA 02111-1307, USA; either version 2 of the License, or - * (at your option) any later version; incorporated herein by reference. - * - * ----------------------------------------------------------------------- */ - -#ifndef DMI_PROCESSOR_H -#define DMI_PROCESSOR_H - -#include "stdbool.h" -#define PROCESSOR_SOCKET_DESIGNATION_SIZE 32 -#define PROCESSOR_TYPE_SIZE 32 -#define PROCESSOR_FAMILY_SIZE 32 -#define PROCESSOR_MANUFACTURER_SIZE 64 -#define PROCESSOR_VERSION_SIZE 32 -#define PROCESSOR_VOLTAGE_SIZE 16 -#define PROCESSOR_STATUS_SIZE 16 -#define PROCESSOR_UPGRADE_SIZE 16 -#define PROCESSOR_CACHE_SIZE 16 -#define PROCESSOR_SERIAL_SIZE 32 -#define PROCESSOR_ASSET_TAG_SIZE 32 -#define PROCESSOR_PART_NUMBER_SIZE 32 -#define PROCESSOR_ID_SIZE 32 - -#define PROCESSOR_FLAGS_ELEMENTS 32 -/* Intel AP-485 revision 28, table 5 */ -static const char *cpu_flags_strings[32]={ - "FPU (Floating-point unit on-chip)", /* 0 */ - "VME (Virtual mode extension)", - "DE (Debugging extension)", - "PSE (Page size extension)", - "TSC (Time stamp counter)", - "MSR (Model specific registers)", - "PAE (Physical address extension)", - "MCE (Machine check exception)", - "CX8 (CMPXCHG8 instruction supported)", - "APIC (On-chip APIC hardware supported)", - NULL, /* 10 */ - "SEP (Fast system call)", - "MTRR (Memory type range registers)", - "PGE (Page global enable)", - "MCA (Machine check architecture)", - "CMOV (Conditional move instruction supported)", - "PAT (Page attribute table)", - "PSE-36 (36-bit page size extension)", - "PSN (Processor serial number present and enabled)", - "CLFSH (CLFLUSH instruction supported)", - NULL, /* 20 */ - "DS (Debug store)", - "ACPI (ACPI supported)", - "MMX (MMX technology supported)", - "FXSR (Fast floating-point save and restore)", - "SSE (Streaming SIMD extensions)", - "SSE2 (Streaming SIMD extensions 2)", - "SS (Self-snoop)", - "HTT (Hyper-threading technology)", - "TM (Thermal monitor supported)", - NULL, /* 30 */ - "PBE (Pending break enabled)" /* 31 */ -}; - -/* this struct have PROCESSOR_FLAGS_ELEMENTS */ -/* each bool is associated to the relevant message above */ -typedef struct { -bool fpu; -bool vme; -bool de; -bool pse; -bool tsc; -bool msr; -bool pae; -bool mce; -bool cx8; -bool apic; -bool null_10; -bool sep; -bool mtrr; -bool pge; -bool mca; -bool cmov; -bool pat; -bool pse_36; -bool psn; -bool clfsh; -bool null_20; -bool ds; -bool acpi; -bool mmx; -bool fxsr; -bool sse; -bool sse2; -bool ss; -bool htt; -bool tm; -bool null_30; -bool pbe; -} __attribute__((__packed__)) s_cpu_flags; - -typedef struct { -u8 type; -u8 family; -u8 model; -u8 stepping; -u8 minor_stepping; -} __attribute__((__packed__)) s_signature; - -typedef struct { -char socket_designation[PROCESSOR_SOCKET_DESIGNATION_SIZE]; -char type[PROCESSOR_TYPE_SIZE]; -char family[PROCESSOR_FAMILY_SIZE]; -char manufacturer[PROCESSOR_MANUFACTURER_SIZE]; -char version[PROCESSOR_VERSION_SIZE]; -float voltage; -u16 external_clock; -u16 max_speed; -u16 current_speed; -char status[PROCESSOR_STATUS_SIZE]; -char upgrade[PROCESSOR_UPGRADE_SIZE]; -char cache1[PROCESSOR_CACHE_SIZE]; -char cache2[PROCESSOR_CACHE_SIZE]; -char cache3[PROCESSOR_CACHE_SIZE]; -char serial[PROCESSOR_SERIAL_SIZE]; -char asset_tag[PROCESSOR_ASSET_TAG_SIZE]; -char part_number[PROCESSOR_PART_NUMBER_SIZE]; -char id[PROCESSOR_ID_SIZE]; -s_cpu_flags cpu_flags; -s_signature signature; -} s_processor; - -static const char *dmi_processor_type(u8 code) -{ - /* 3.3.5.1 */ - static const char *type[]={ - "Other", /* 0x01 */ - "Unknown", - "Central Processor", - "Math Processor", - "DSP Processor", - "Video Processor" /* 0x06 */ - }; - - if(code>=0x01 && code<=0x06) - return type[code-0x01]; - return out_of_spec; -} - -static const char *dmi_processor_family(u8 code) -{ - /* 3.3.5.2 */ - static const char *family[]={ - NULL, /* 0x00 */ - "Other", - "Unknown", - "8086", - "80286", - "80386", - "80486", - "8087", - "80287", - "80387", - "80487", - "Pentium", - "Pentium Pro", - "Pentium II", - "Pentium MMX", - "Celeron", - "Pentium II Xeon", - "Pentium III", - "M1", - "M2", - NULL, /* 0x14 */ - NULL, - NULL, - NULL, /* 0x17 */ - "Duron", - "K5", - "K6", - "K6-2", - "K6-3", - "Athlon", - "AMD2900", - "K6-2+", - "Power PC", - "Power PC 601", - "Power PC 603", - "Power PC 603+", - "Power PC 604", - "Power PC 620", - "Power PC x704", - "Power PC 750", - NULL, /* 0x28 */ - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL,/* 0x2F */ - "Alpha", - "Alpha 21064", - "Alpha 21066", - "Alpha 21164", - "Alpha 21164PC", - "Alpha 21164a", - "Alpha 21264", - "Alpha 21364", - NULL, /* 0x38 */ - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, /* 0x3F */ - "MIPS", - "MIPS R4000", - "MIPS R4200", - "MIPS R4400", - "MIPS R4600", - "MIPS R10000", - NULL, /* 0x46 */ - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, /* 0x4F */ - "SPARC", - "SuperSPARC", - "MicroSPARC II", - "MicroSPARC IIep", - "UltraSPARC", - "UltraSPARC II", - "UltraSPARC IIi", - "UltraSPARC III", - "UltraSPARC IIIi", - NULL, /* 0x59 */ - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, /* 0x5F */ - "68040", - "68xxx", - "68000", - "68010", - "68020", - "68030", - NULL, /* 0x66 */ - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, /* 0x6F */ - "Hobbit", - NULL, /* 0x71 */ - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, /* 0x77 */ - "Crusoe TM5000", - "Crusoe TM3000", - "Efficeon TM8000", - NULL, /* 0x7B */ - NULL, - NULL, - NULL, - NULL, /* 0x7F */ - "Weitek", - NULL, /* 0x81 */ - "Itanium", - "Athlon 64", - "Opteron", - "Sempron", - NULL, /* 0x86 */ - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, /* 0x8F */ - "PA-RISC", - "PA-RISC 8500", - "PA-RISC 8000", - "PA-RISC 7300LC", - "PA-RISC 7200", - "PA-RISC 7100LC", - "PA-RISC 7100", - NULL, /* 0x97 */ - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, /* 0x9F */ - "V30", - NULL, /* 0xA1 */ - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, /* 0xAF */ - "Pentium III Xeon", - "Pentium III Speedstep", - "Pentium 4", - "Xeon", - "AS400", - "Xeon MP", - "Athlon XP", - "Athlon MP", - "Itanium 2", - "Pentium M", - NULL, /* 0xBA */ - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, /* 0xC7 */ - "IBM390", - "G4", - "G5", - NULL, /* 0xCB */ - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, /* 0xF9 */ - "i860", - "i960", - NULL, /* 0xFC */ - NULL, - NULL, - NULL /* 0xFF */ - /* master.mif has values beyond that, but they can't be used for DMI */ - }; - - if(family[code]!=NULL) { - return family[code]; - } - return out_of_spec; -} - -static const char *dmi_processor_status(u8 code) -{ - static const char *status[]={ - "Unknown", /* 0x00 */ - "Enabled", - "Disabled By User", - "Disabled By BIOS", - "Idle", /* 0x04 */ - "Other" /* 0x07 */ - }; - - if(code<=0x04) - return status[code]; - if(code==0x07) - return status[0x05]; - return out_of_spec; -} -static const char *dmi_processor_upgrade(u8 code) -{ - /* 3.3.5.5 */ - static const char *upgrade[]={ - "Other", /* 0x01 */ - "Unknown", - "Daughter Board", - "ZIF Socket", - "Replaceable Piggy Back", - "None", - "LIF Socket", - "Slot 1", - "Slot 2", - "370-pin Socket", - "Slot A", - "Slot M", - "Socket 423", - "Socket A (Socket 462)", - "Socket 478", - "Socket 754", - "Socket 940", - "Socket 939" /* 0x12 */ - }; - - if(code>=0x01 && code<=0x11) - return upgrade[code-0x01]; - return out_of_spec; -} - -static void dmi_processor_cache(u16 code, const char *level, u16 ver, char *cache) -{ - if(code==0xFFFF) - { - if(ver>=0x0203) - sprintf(cache,"Not Provided"); - else - sprintf(cache,"No %s Cache", level); - } - else - sprintf(cache,"0x%04X", code); -} - - -#endif diff --git a/com32/include/string.h b/com32/include/string.h index af9792b6..c964ee3b 100644 --- a/com32/include/string.h +++ b/com32/include/string.h @@ -23,6 +23,7 @@ __extern char *strcat(char *, const char *); __extern char *strchr(const char *, int); __extern int strcmp(const char *, const char *); __extern char *strcpy(char *, const char *); +__extern char *strpcpy(char *, const char *); __extern size_t strcspn(const char *, const char *); __extern char *strdup(const char *); __extern char *strndup(const char *, size_t); diff --git a/com32/include/sys/pci.h b/com32/include/sys/pci.h index 1de095af..fad7250c 100644 --- a/com32/include/sys/pci.h +++ b/com32/include/sys/pci.h @@ -4,18 +4,32 @@ #include <inttypes.h> #include <sys/io.h> -#define MAX_PCI_FUNC 8 -#define MAX_PCI_DEVICES 32 -#define MAX_PCI_BUSES 256 +#define MAX_PCI_FUNC 8 +#define MAX_PCI_DEVICES 32 +#define MAX_PCI_BUSES 256 +#define LINUX_KERNEL_MODULE_SIZE 64 +#define PCI_VENDOR_NAME_SIZE 256 +#define PCI_PRODUCT_NAME_SIZE 256 +#define PCI_CLASS_NAME_SIZE 256 +#define MAX_KERNEL_MODULES_PER_PCI_DEVICE 10 +#define MAX_PCI_CLASSES 256 typedef uint32_t pciaddr_t; +enum { + ENOPCIIDS = 100, + ENOMODULESPCIMAP +}; + /* a structure for extended pci information */ /* XXX: use pointers for these? */ struct pci_dev_info { - char vendor_name[256]; - char product_name[256]; - char linux_kernel_module[64]; + char vendor_name[PCI_VENDOR_NAME_SIZE]; + char product_name[PCI_PRODUCT_NAME_SIZE]; + char linux_kernel_module[LINUX_KERNEL_MODULE_SIZE][MAX_KERNEL_MODULES_PER_PCI_DEVICE]; + int linux_kernel_module_count; + char class_name[PCI_CLASS_NAME_SIZE]; /* The most precise class name */ + char category_name[PCI_CLASS_NAME_SIZE]; /*The general category*/ }; /* PCI device (really, function) */ @@ -117,7 +131,8 @@ struct pci_domain *pci_scan(void); void free_pci_domain(struct pci_domain *domain); struct match * find_pci_device(const struct pci_domain *pci_domain, struct match *list); -int get_name_from_pci_ids(struct pci_domain *pci_domain); -int get_module_name_from_pci_ids(struct pci_domain *pci_domain); +int get_name_from_pci_ids(struct pci_domain *pci_domain, char *pciids_path); +int get_module_name_from_pci_ids(struct pci_domain *pci_domain, char *modules_pcimap_path); +int get_class_name_from_pci_ids(struct pci_domain *pci_domain, char *pciids_path); #endif /* _SYS_PCI_H */ diff --git a/com32/include/syslinux/pxe.h b/com32/include/syslinux/pxe.h index 7550817f..31a4041e 100644 --- a/com32/include/syslinux/pxe.h +++ b/com32/include/syslinux/pxe.h @@ -62,6 +62,38 @@ typedef struct { uint16_t seg; } segoff16_t; +typedef struct { +uint8_t opcode; +#define BOOTP_REQ 1 +#define BOOTP_REP 2 +uint8_t Hardware; +uint8_t Hardlen; +uint8_t Gatehops; +uint32_t ident; +uint16_t seconds; +uint16_t Flags; +#define BOOTP_BCAST 0x8000 +in_addr_t cip; /* Client IP address*/ +in_addr_t yip; /* You IP address*/ +in_addr_t sip; /* next server IP address*/ +in_addr_t gip; /*relay agent IP address */ +mac_addr_t CAddr; +uint8_t Sname[64]; +uint8_t bootfile[128]; +union + { + #define BOOTP_DHCPVEND 1024 + uint8_t d[BOOTP_DHCPVEND]; + struct { + uint8_t magic[4]; + #define VM_RFC1048 0x63825363L + uint32_t flags; + uint8_t pad[56]; + } v; + } vendor; +} __packed pxe_bootp_t; + + /* Function calling structures and constants */ typedef struct s_PXENV_GET_CACHED_INFO @@ -528,5 +560,6 @@ typedef struct s_PXENV_UNDI_ISR /* SYSLINUX-defined PXE utility functions */ int pxe_get_cached_info(int level, void **buf, size_t *len); +int pxe_get_nic_type(t_PXENV_UNDI_GET_NIC_TYPE *gnt); #endif /* _SYSLINUX_PXE_H */ diff --git a/com32/lib/MCONFIG b/com32/lib/MCONFIG index e40cf83c..aea0ed74 100644 --- a/com32/lib/MCONFIG +++ b/com32/lib/MCONFIG @@ -1,6 +1,5 @@ # -*- makefile -*- -topdir = ../.. include $(topdir)/MCONFIG GCCOPT := $(call gcc_ok,-std=gnu99,) \ diff --git a/com32/lib/Makefile b/com32/lib/Makefile index 0cc40617..6c137f9d 100644 --- a/com32/lib/Makefile +++ b/com32/lib/Makefile @@ -1,4 +1,10 @@ +# +# ONLY INCLUDE MIT OR 2/3-BSD-LICENSED CODE IN THIS LIBRARY +# + # Include configuration rules +NOGPL := 1 +topdir = ../.. include MCONFIG LIBOBJS = \ @@ -11,8 +17,8 @@ LIBOBJS = \ exit.o onexit.o \ perror.o printf.o puts.o qsort.o realloc.o seed48.o snprintf.o \ sprintf.o srand48.o sscanf.o stack.o strcasecmp.o strcat.o \ - strchr.o strcmp.o strcpy.o strdup.o strerror.o strlen.o \ - strnlen.o \ + strchr.o strcmp.o strcpy.o strpcpy.o strdup.o strlen.o \ + strerror.o strnlen.o \ strncasecmp.o strncat.o strncmp.o strncpy.o strndup.o \ stpcpy.o stpncpy.o \ strntoimax.o strntoumax.o strrchr.o strsep.o strspn.o strstr.o \ @@ -92,7 +98,7 @@ LIBOBJS = \ syslinux/initramfs_file.o syslinux/initramfs_loadfile.o \ syslinux/initramfs_archive.o \ \ - syslinux/pxe_get_cached.o \ + syslinux/pxe_get_cached.o syslinux/pxe_get_nic.o \ \ syslinux/adv.o syslinux/advwrite.o syslinux/getadv.o \ syslinux/setadv.o @@ -113,7 +119,7 @@ libcom32.a : $(LIBOBJS) tidy dist clean: rm -f sys/vesa/alphatbl.c - find . \( -name \*.o -o -name .\*.d -o -name \*.tmp \) -print0 | \ + find . \( -name \*.o -o -name \*.a -o -name .\*.d -o -name \*.tmp \) -print0 | \ xargs -0r rm -f spotless: clean diff --git a/com32/lib/pci/scan.c b/com32/lib/pci/scan.c index 98df0dd3..cfd9e654 100644 --- a/com32/lib/pci/scan.c +++ b/com32/lib/pci/scan.c @@ -73,7 +73,7 @@ static int hex_to_int(char *hexa) /* Try to match any pci device to the appropriate kernel module */ /* it uses the modules.pcimap from the boot device */ -int get_module_name_from_pci_ids(struct pci_domain *domain) +int get_module_name_from_pci_ids(struct pci_domain *domain, char *modules_pcimap_path) { char line[MAX_LINE]; char module_name[21]; // the module name field is 21 char long @@ -94,18 +94,21 @@ int get_module_name_from_pci_ids(struct pci_domain *domain) if (!dev->dev_info) return -1; } - strcpy(dev->dev_info->linux_kernel_module, "unknown"); + for (int i=0;i<MAX_KERNEL_MODULES_PER_PCI_DEVICE;i++) { + strlcpy(dev->dev_info->linux_kernel_module[i], "unknown",7); + } } /* Opening the modules.pcimap (of a linux kernel) from the boot device */ - f=fopen("modules.pcimap", "r"); + f=fopen(modules_pcimap_path, "r"); if (!f) - return -1; + return -ENOMODULESPCIMAP; strcpy(vendor_id,"0000"); strcpy(product_id,"0000"); strcpy(sub_product_id,"0000"); strcpy(sub_vendor_id,"0000"); + dev->dev_info->linux_kernel_module_count=0; /* for each line we found in the modules.pcimap */ while ( fgets(line, sizeof line, f) ) { @@ -134,35 +137,136 @@ int get_module_name_from_pci_ids(struct pci_domain *domain) /* Searching the next field */ result = strtok( NULL, delims ); } + int int_vendor_id=hex_to_int(vendor_id); + int int_sub_vendor_id=hex_to_int(sub_vendor_id); + int int_product_id=hex_to_int(product_id); + int int_sub_product_id=hex_to_int(sub_product_id); /* if a pci_device matches an entry, fill the linux_kernel_module with the appropriate kernel module */ for_each_pci_func(dev, domain) { - if (hex_to_int(vendor_id) == dev->vendor && - hex_to_int(product_id) == dev->product && - (hex_to_int(sub_product_id) & dev->sub_product) + if (int_vendor_id == dev->vendor && + int_product_id == dev->product && + (int_sub_product_id & dev->sub_product) == dev->sub_product && - (hex_to_int(sub_vendor_id) & dev->sub_vendor) - == dev->sub_vendor) - strcpy(dev->dev_info->linux_kernel_module, module_name); + (int_sub_vendor_id & dev->sub_vendor) + == dev->sub_vendor) { + strcpy(dev->dev_info->linux_kernel_module[dev->dev_info->linux_kernel_module_count], module_name); + dev->dev_info->linux_kernel_module_count++; + } + } + } + fclose(f); + return 0; +} + +/* Try to match any pci device to the appropriate class name */ +/* it uses the pci.ids from the boot device */ +int get_class_name_from_pci_ids(struct pci_domain *domain, char *pciids_path) +{ + char line[MAX_LINE]; + char class_name[PCI_CLASS_NAME_SIZE]; + char sub_class_name[PCI_CLASS_NAME_SIZE]; + char class_id_str[5]; + char sub_class_id_str[5]; + FILE *f; + struct pci_device *dev; + bool class_mode=false; + + /* Intializing the vendor/product name for each pci device to "unknown" */ + /* adding a dev_info member if needed */ + for_each_pci_func(dev, domain) { + /* initialize the dev_info structure if it doesn't exist yet. */ + if (! dev->dev_info) { + dev->dev_info = zalloc(sizeof *dev->dev_info); + if (!dev->dev_info) + return -1; + } + strlcpy(dev->dev_info->class_name,"unknown",7); + } + + /* Opening the pci.ids from the boot device */ + f = fopen(pciids_path,"r"); + if (!f) + return -ENOPCIIDS; + + /* for each line we found in the pci.ids */ + while ( fgets(line, sizeof line, f) ) { + /* Skipping uncessary lines */ + if ((line[0] == '#') || (line[0] == ' ') || + (line[0] == 10)) + continue; + + /* Until we found a line starting with a 'C', we are not parsing classes */ + if (line[0] == 'C') + class_mode=true; + if (class_mode == false) + continue; + strlcpy(class_name,"unknown",7); + /* If the line doesn't start with a tab, it means that's a class name */ + if (line[0] != '\t') { + + /* ignore the two first char and then copy 2 chars (class id)*/ + strlcpy(class_id_str,&line[2],2); + class_id_str[2]=0; + + /* the class name is the next field */ + strlcpy(class_name,skipspace(strstr(line," ")),PCI_CLASS_NAME_SIZE-1); + remove_eol(class_name); + + int int_class_id_str=hex_to_int(class_id_str); + /* assign the class_name to any matching pci device */ + for_each_pci_func(dev, domain) { + if (int_class_id_str == dev->class[2]) { + strlcpy(dev->dev_info->class_name,class_name,PCI_CLASS_NAME_SIZE-1); + /* This value is usually the main category*/ + strlcpy(dev->dev_info->category_name,class_name+4,PCI_CLASS_NAME_SIZE-1); + } + } + /* if we have a tab + a char, it means this is a sub class name */ + } else if ((line[0] == '\t') && (line[1] != '\t')) { + + /* the sub class name the second field */ + strlcpy(sub_class_name,skipspace(strstr(line," ")),PCI_CLASS_NAME_SIZE-1); + remove_eol(sub_class_name); + + /* the sub class id is first field */ + strlcpy(sub_class_id_str,&line[1],2); + sub_class_id_str[2]=0; + + int int_class_id_str=hex_to_int(class_id_str); + int int_sub_class_id_str=hex_to_int(sub_class_id_str); + /* assign the product_name to any matching pci device */ + for_each_pci_func(dev, domain) { + if (int_class_id_str == dev->class[2] && + int_sub_class_id_str == dev->class[1]) + strlcpy(dev->dev_info->class_name,sub_class_name,PCI_CLASS_NAME_SIZE-1); + } + } } fclose(f); return 0; } + /* Try to match any pci device to the appropriate vendor and product name */ /* it uses the pci.ids from the boot device */ -int get_name_from_pci_ids(struct pci_domain *domain) +int get_name_from_pci_ids(struct pci_domain *domain, char *pciids_path) { char line[MAX_LINE]; - char vendor[255]; + char vendor[PCI_VENDOR_NAME_SIZE]; char vendor_id[5]; - char product[255]; + char product[PCI_PRODUCT_NAME_SIZE]; char product_id[5]; char sub_product_id[5]; char sub_vendor_id[5]; FILE *f; struct pci_device *dev; + bool skip_to_next_vendor=false; + uint16_t int_vendor_id; + uint16_t int_product_id; + uint16_t int_sub_product_id; + uint16_t int_sub_vendor_id; /* Intializing the vendor/product name for each pci device to "unknown" */ /* adding a dev_info member if needed */ @@ -173,19 +277,19 @@ int get_name_from_pci_ids(struct pci_domain *domain) if (!dev->dev_info) return -1; } - strcpy(dev->dev_info->vendor_name,"unknown"); - strcpy(dev->dev_info->product_name,"unknown"); + strlcpy(dev->dev_info->vendor_name,"unknown",7); + strlcpy(dev->dev_info->product_name,"unknown",7); } /* Opening the pci.ids from the boot device */ - f = fopen("pci.ids","r"); + f = fopen(pciids_path,"r"); if (!f) - return -1; + return -ENOPCIIDS; - strcpy(vendor_id,"0000"); - strcpy(product_id,"0000"); - strcpy(sub_product_id,"0000"); - strcpy(sub_vendor_id,"0000"); + strlcpy(vendor_id,"0000",4); + strlcpy(product_id,"0000",4); + strlcpy(sub_product_id,"0000",4); + strlcpy(sub_vendor_id,"0000",4); /* for each line we found in the pci.ids */ while ( fgets(line, sizeof line, f) ) { @@ -193,6 +297,7 @@ int get_name_from_pci_ids(struct pci_domain *domain) if ((line[0] == '#') || (line[0] == ' ') || (line[0] == 'C') || (line[0] == 10)) continue; + /* If the line doesn't start with a tab, it means that's a vendor id */ if (line[0] != '\t') { @@ -201,26 +306,35 @@ int get_name_from_pci_ids(struct pci_domain *domain) /* the vendor name is the next field */ vendor_id[4]=0; - strlcpy(vendor,skipspace(strstr(line," ")),255); + strlcpy(vendor,skipspace(strstr(line," ")),PCI_VENDOR_NAME_SIZE-1); remove_eol(vendor); /* init product_id, sub_product and sub_vendor */ - strcpy(product_id,"0000"); - strcpy(sub_product_id,"0000"); - strcpy(sub_vendor_id,"0000"); + strlcpy(product_id,"0000",4); + strlcpy(sub_product_id,"0000",4); + strlcpy(sub_vendor_id,"0000",4); - /* ffff is an invalid vendor id */ - if (strstr(vendor_id,"ffff")) break; - /* assign the vendor_name to any matching pci device */ + /* Unless we found a matching device, we have to skip to the next vendor */ + skip_to_next_vendor=true; + + int_vendor_id=hex_to_int(vendor_id); + /* Iterate in all pci devices to find a matching vendor */ for_each_pci_func(dev, domain) { - if (hex_to_int(vendor_id) == dev->vendor) - strlcpy(dev->dev_info->vendor_name,vendor,255); + /* if one device that match this vendor */ + if (int_vendor_id == dev->vendor) { + /* copy the vendor name for this device */ + strlcpy(dev->dev_info->vendor_name,vendor,PCI_VENDOR_NAME_SIZE-1); + /* Some pci devices match this vendor, so we have to found them */ + skip_to_next_vendor=false; + /* Let's loop on the other devices as some may have the same vendor */ + } } - /* if we have a tab + a char, it means this is a product id */ - } else if ((line[0] == '\t') && (line[1] != '\t')) { + /* if we have a tab + a char, it means this is a product id + * but we only look at it if we own some pci devices of the current vendor*/ + } else if ((line[0] == '\t') && (line[1] != '\t') && (skip_to_next_vendor == false)) { /* the product name the second field */ - strlcpy(product,skipspace(strstr(line," ")),255); + strlcpy(product,skipspace(strstr(line," ")),PCI_PRODUCT_NAME_SIZE-1); remove_eol(product); /* the product id is first field */ @@ -228,22 +342,27 @@ int get_name_from_pci_ids(struct pci_domain *domain) product_id[4]=0; /* init sub_product and sub_vendor */ - strcpy(sub_product_id,"0000"); - strcpy(sub_vendor_id,"0000"); + strlcpy(sub_product_id,"0000",4); + strlcpy(sub_vendor_id,"0000",4); + int_vendor_id=hex_to_int(vendor_id); + int_product_id=hex_to_int(product_id); /* assign the product_name to any matching pci device */ for_each_pci_func(dev, domain) { - if (hex_to_int(vendor_id) == dev->vendor && - hex_to_int(product_id) == dev->product) - strlcpy(dev->dev_info->product_name,product,255); + if (int_vendor_id == dev->vendor && + int_product_id == dev->product) { + strlcpy(dev->dev_info->vendor_name,vendor,PCI_VENDOR_NAME_SIZE-1); + strlcpy(dev->dev_info->product_name,product,PCI_PRODUCT_NAME_SIZE-1); + } } - /* if we have two tabs, it means this is a sub product */ - } else if ((line[0] == '\t') && (line[1] == '\t')) { + /* if we have two tabs, it means this is a sub product + * but we only look at it if we own some pci devices of the current vendor*/ + } else if ((line[0] == '\t') && (line[1] == '\t') && (skip_to_next_vendor == false)) { /* the product name is last field */ - strlcpy(product,skipspace(strstr(line," ")),255); - strlcpy(product,skipspace(strstr(product," ")),255); + strlcpy(product,skipspace(strstr(line," ")),PCI_PRODUCT_NAME_SIZE-1); + strlcpy(product,skipspace(strstr(product," ")),PCI_PRODUCT_NAME_SIZE-1); remove_eol(product); /* the sub_vendor id is first field */ @@ -254,13 +373,19 @@ int get_name_from_pci_ids(struct pci_domain *domain) strlcpy(sub_product_id,&line[7],4); sub_product_id[4]=0; + int_vendor_id=hex_to_int(vendor_id); + int_sub_vendor_id=hex_to_int(sub_vendor_id); + int_product_id=hex_to_int(product_id); + int_sub_product_id=hex_to_int(sub_product_id); /* assign the product_name to any matching pci device */ for_each_pci_func(dev, domain) { - if (hex_to_int(vendor_id) == dev->vendor && - hex_to_int(product_id) == dev->product && - hex_to_int(sub_product_id) == dev->sub_product && - hex_to_int(sub_vendor_id) == dev->sub_vendor) - strlcpy(dev->dev_info->product_name,product,255); + if (int_vendor_id == dev->vendor && + int_product_id == dev->product && + int_sub_product_id == dev->sub_product && + int_sub_vendor_id == dev->sub_vendor) { + strlcpy(dev->dev_info->vendor_name,vendor,PCI_VENDOR_NAME_SIZE-1); + strlcpy(dev->dev_info->product_name,product,PCI_PRODUCT_NAME_SIZE-1); + } } } } diff --git a/com32/lib/strpcpy.c b/com32/lib/strpcpy.c new file mode 100644 index 00000000..e181e78f --- /dev/null +++ b/com32/lib/strpcpy.c @@ -0,0 +1,20 @@ +/* + * strpcpy.c + * + * strpcpy() - strcpy() which returns a pointer to the final null + */ + +#include <string.h> + +char *strpcpy(char *dst, const char *src) +{ + char *q = dst; + const char *p = src; + char ch; + + do { + *q++ = ch = *p++; + } while ( ch ); + + return q-1; +} diff --git a/com32/lib/syslinux/pxe_get_nic.c b/com32/lib/syslinux/pxe_get_nic.c new file mode 100644 index 00000000..b779542c --- /dev/null +++ b/com32/lib/syslinux/pxe_get_nic.c @@ -0,0 +1,61 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 2007-2008 H. Peter Anvin - 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. + * + * ----------------------------------------------------------------------- */ + +/* + * pxe_get_cached.c + * + * PXE call "get cached info" + */ + +#include <stdlib.h> +#include <stdint.h> +#include <string.h> +#include <com32.h> + +#include <syslinux/pxe.h> + +/* Returns the status code from PXE (0 on success), + or -1 on invocation failure */ +int pxe_get_nic_type(t_PXENV_UNDI_GET_NIC_TYPE *gnt) +{ + com32sys_t regs; + + memset(®s, 0, sizeof regs); + regs.eax.w[0] = 0x0009; + regs.ebx.w[0] = PXENV_UNDI_GET_NIC_TYPE; + regs.es = SEG( __com32.cs_bounce); + regs.edi.w[0] = OFFS( __com32.cs_bounce); + + __intcall(0x22, ®s, ®s); + + memcpy(gnt, __com32.cs_bounce, sizeof(t_PXENV_UNDI_GET_NIC_TYPE)); + + if (regs.eflags.l & EFLAGS_CF) + return -1; + + return gnt->Status; +} diff --git a/com32/modules/Makefile b/com32/modules/Makefile index 930e89b6..5a8a88c4 100644 --- a/com32/modules/Makefile +++ b/com32/modules/Makefile @@ -1,6 +1,6 @@ ## ----------------------------------------------------------------------- ## -## Copyright 2001-2008 H. Peter Anvin - All Rights Reserved +## Copyright 2001-2009 H. Peter Anvin - All Rights Reserved ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by @@ -29,10 +29,14 @@ all: $(MODULES) $(TESTFILES) pcitest.elf : pcitest.o $(LIBS) $(C_LIBS) $(LD) $(LDFLAGS) -o $@ $^ -cpuidtest.elf : cpuidtest.o cpuid.o $(LIBS) $(C_LIBS) +cpuidtest.elf : cpuidtest.o $(GPLLIB) $(LIBS) $(C_LIBS) $(LD) $(LDFLAGS) -o $@ $^ -dmitest.elf : dmitest.o dmi_utils.o dmi.o $(LIBS) $(C_LIBS) +.PRECIOUS: %.o +dmitest.o: dmitest.c + $(CC) $(CFLAGS) $(GPLINCLUDE) -c -o $@ $< + +dmitest.elf : dmi_utils.o dmitest.o $(GPLLIB) $(LIBS) $(C_LIBS) $(LD) $(LDFLAGS) -o $@ $^ ethersel.elf : ethersel.o $(LIBS) $(C_LIBS) diff --git a/com32/modules/cmd.c b/com32/modules/cmd.c index f0b0a968..e1d646b5 100644 --- a/com32/modules/cmd.c +++ b/com32/modules/cmd.c @@ -18,7 +18,6 @@ #include <string.h> #include <alloca.h> -#include <console.h> #include <com32.h> int main(int argc, const char *argv[]) @@ -28,15 +27,17 @@ int main(int argc, const char *argv[]) char *tmp; int i; - openconsole(&dev_stdcon_r, &dev_stdcon_w); - for (i = 1; i < argc; i++) len += strlen(argv[i]) + 1; tmp = cmd = alloca(len); - for (i = 1; i < argc; i++) - tmp += sprintf(tmp, "%s%s", argv[i], (i == argc-1) ? "" : " "); + for (i = 1; i < argc; i++) { + tmp = strpcpy(tmp, argv[i]); + if (i != argc-1) + *tmp++ = ' '; + } + *tmp = '\0'; syslinux_run_command(cmd); } diff --git a/com32/modules/dmi_utils.c b/com32/modules/dmi_utils.c index df03ba7c..e0baa873 100644 --- a/com32/modules/dmi_utils.c +++ b/com32/modules/dmi_utils.c @@ -51,7 +51,7 @@ int i; void display_base_board_features(s_dmi *dmi) { int i; - for (i=0;i<=BASE_BOARD_NB_ELEMENTS; i++) { + for (i=0;i<BASE_BOARD_NB_ELEMENTS; i++) { if (((bool *)(& dmi->base_board.features))[i] == true) { moreprintf("\t\t%s\n", base_board_features_strings[i]); } @@ -60,7 +60,7 @@ int i; void display_processor_flags(s_dmi *dmi) { int i; - for (i=0;i<=PROCESSOR_FLAGS_ELEMENTS; i++) { + for (i=0;i<PROCESSOR_FLAGS_ELEMENTS; i++) { if (((bool *)(& dmi->processor.cpu_flags))[i] == true) { moreprintf("\t\t%s\n", cpu_flags_strings[i]); } diff --git a/com32/modules/dmitest.c b/com32/modules/dmitest.c index 64f0635d..07febc51 100644 --- a/com32/modules/dmitest.c +++ b/com32/modules/dmitest.c @@ -39,6 +39,44 @@ char display_line; +void display_memory(s_dmi *dmi) { + int i; + for (i=0;i<dmi->memory_count;i++) { + moreprintf("Memory Bank %d\n",i); + moreprintf("\tForm Factor : %s\n",dmi->memory[i].form_factor); + moreprintf("\tType : %s\n",dmi->memory[i].type); + moreprintf("\tType Detail : %s\n",dmi->memory[i].type_detail); + moreprintf("\tSpeed : %s\n",dmi->memory[i].speed); + moreprintf("\tSize : %s\n",dmi->memory[i].size); + moreprintf("\tDevice Set : %s\n",dmi->memory[i].device_set); + moreprintf("\tDevice Loc. : %s\n",dmi->memory[i].device_locator); + moreprintf("\tBank Locator : %s\n",dmi->memory[i].bank_locator); + moreprintf("\tTotal Width : %s\n",dmi->memory[i].total_width); + moreprintf("\tData Width : %s\n",dmi->memory[i].data_width); + moreprintf("\tError : %s\n",dmi->memory[i].error); + moreprintf("\tVendor : %s\n",dmi->memory[i].manufacturer); + moreprintf("\tSerial : %s\n",dmi->memory[i].serial); + moreprintf("\tAsset Tag : %s\n",dmi->memory[i].asset_tag); + moreprintf("\tPart Number : %s\n",dmi->memory[i].part_number); + } +} + +void display_battery(s_dmi *dmi) { + moreprintf("Battery\n"); + moreprintf("\tVendor : %s\n",dmi->battery.manufacturer); + moreprintf("\tManufacture Date : %s\n",dmi->battery.manufacture_date); + moreprintf("\tSerial : %s\n",dmi->battery.serial); + moreprintf("\tName : %s\n",dmi->battery.name); + moreprintf("\tChemistry : %s\n",dmi->battery.chemistry); + moreprintf("\tDesign Capacity : %s\n",dmi->battery.design_capacity); + moreprintf("\tDesign Voltage : %s\n",dmi->battery.design_voltage); + moreprintf("\tSBDS : %s\n",dmi->battery.sbds); + moreprintf("\tSBDS Manufact. Date : %s\n",dmi->battery.sbds_manufacture_date); + moreprintf("\tSBDS Chemistry : %s\n",dmi->battery.sbds_chemistry); + moreprintf("\tMaximum Error : %s\n",dmi->battery.maximum_error); + moreprintf("\tOEM Info : %s\n",dmi->battery.oem_info); +} + void display_bios(s_dmi *dmi) { moreprintf("BIOS\n"); moreprintf("\tVendor: %s\n",dmi->bios.vendor); @@ -126,15 +164,20 @@ int main(void) s_dmi dmi; openconsole(&dev_stdcon_r, &dev_stdcon_w); - if ( ! dmi_interate() ) { - printf("No DMI Structure found\n"); - return -1; + if (dmi_iterate(&dmi) == -ENODMITABLE) { + printf("No DMI Structure found\n"); + return -1; + } else { + printf("DMI %d.%d present.\n",dmi.dmitable.major_version,dmi.dmitable.minor_version); + printf("%d structures occupying %d bytes.\n",dmi.dmitable.num, dmi.dmitable.len); + printf("DMI table at 0x%08X.\n",dmi.dmitable.base); } + parse_dmitable(&dmi); for (;;) { - printf("Available commands are system, chassis, base_board, cpu, bios, all, exit\n"); + printf("Available commands are system, chassis, base_board, cpu, bios, memory, battery, all, exit\n"); printf("dmi: "); fgets(buffer, sizeof buffer, stdin); if ( !strncmp(buffer, "exit", 4) ) @@ -149,12 +192,18 @@ int main(void) display_cpu(&dmi); if ( !strncmp(buffer, "bios", 4) ) display_bios(&dmi); + if ( !strncmp(buffer, "memory", 6) ) + display_memory(&dmi); + if ( !strncmp(buffer, "battery", 7) ) + display_battery(&dmi); if ( !strncmp(buffer, "all", 3) ) { display_bios(&dmi); display_system(&dmi); display_chassis(&dmi); display_base_board(&dmi); display_cpu(&dmi); + display_memory(&dmi); + display_battery(&dmi); } } diff --git a/com32/modules/pcitest.c b/com32/modules/pcitest.c index 240f19f2..00647535 100644 --- a/com32/modules/pcitest.c +++ b/com32/modules/pcitest.c @@ -46,7 +46,7 @@ # define dprintf(...) ((void)0) #endif -char display_line; +char display_line=0; #define moreprintf(...) \ do { \ display_line++; \ @@ -61,34 +61,82 @@ char display_line; void display_pci_devices(struct pci_domain *pci_domain) { struct pci_device *pci_device; - int ndev = 0; + char kernel_modules [LINUX_KERNEL_MODULE_SIZE*MAX_KERNEL_MODULES_PER_PCI_DEVICE]; + for_each_pci_func(pci_device, pci_domain) { - printf("[%02x:%02x.%01x]: %s: %04x:%04x[%04x:%04x]) %s:%s\n", - __pci_bus, __pci_slot, __pci_func, - pci_device->dev_info->linux_kernel_module, - pci_device->vendor, pci_device->product, - pci_device->sub_vendor, pci_device->sub_product, - pci_device->dev_info->vendor_name, - pci_device->dev_info->product_name); - ndev++; + + memset(kernel_modules,0,sizeof kernel_modules); + +/* printf("PCI: found %d kernel modules for %04x:%04x[%04x:%04x]\n", + pci_device->dev_info->linux_kernel_module_count, + pci_device->vendor, pci_device->product, + pci_device->sub_vendor, pci_device->sub_product); +*/ + for (int i=0; i<pci_device->dev_info->linux_kernel_module_count;i++) { + if (i>0) { + strncat(kernel_modules," | ",3); + } + strncat(kernel_modules, pci_device->dev_info->linux_kernel_module[i],LINUX_KERNEL_MODULE_SIZE-1); + } + + moreprintf("%04x:%04x[%04x:%04x]: %s\n", + pci_device->vendor, pci_device->product, + pci_device->sub_vendor, pci_device->sub_product, + pci_device->dev_info->class_name); + + moreprintf(" Vendor Name : %s\n", pci_device->dev_info->vendor_name); + moreprintf(" Product Name : %s\n", pci_device->dev_info->product_name); + moreprintf(" PCI bus position : %02x:%02x.%01x\n", __pci_bus, __pci_slot, __pci_func); + moreprintf(" Kernel modules : %s\n\n",kernel_modules); } - printf("PCI: %d devices found\n", ndev); } int main(int argc, char *argv[]) { struct pci_domain *pci_domain; + int return_code=0; + int nb_pci_devices=0; - openconsole(&dev_null_r, &dev_stdcon_w); + openconsole(&dev_stdcon_r, &dev_stdcon_w); /* Scanning to detect pci buses and devices */ + printf("PCI: Scanning PCI BUS\n"); pci_domain = pci_scan(); + struct pci_device *pci_device; + for_each_pci_func(pci_device, pci_domain) { + nb_pci_devices++; + } + + printf("PCI: %d PCI devices found\n",nb_pci_devices); + + + printf("PCI: Looking for device name\n"); /* Assigning product & vendor name for each device*/ - get_name_from_pci_ids(pci_domain); + return_code=get_name_from_pci_ids(pci_domain,"pci.ids"); + if (return_code == -ENOPCIIDS) { + printf("PCI: ERROR !\n"); + printf("PCI: Unable to open pci.ids in the same directory as pcitest.c32.\n"); + printf("PCI: PCI Device names can't be computed.\n"); + } + + printf("PCI: Resolving class names\n"); + /* Assigning class name for each device*/ + return_code=get_class_name_from_pci_ids(pci_domain,"pci.ids"); + if (return_code == -ENOPCIIDS) { + printf("PCI: ERROR !\n"); + printf("PCI: Unable to open pci.ids in the same directory as pcitest.c32.\n"); + printf("PCI: PCI class names can't be computed.\n"); + } + printf("PCI: Looking for Kernel modules\n"); /* Detecting which kernel module should match each device */ - get_module_name_from_pci_ids(pci_domain); + return_code=get_module_name_from_pci_ids(pci_domain,"modules.pcimap"); + if (return_code == -ENOMODULESPCIMAP) { + printf("PCI: ERROR !\n"); + printf("PCI: Unable to open modules.pcimap in the same directory as pcitest.c32.\n"); + printf("PCI: Kernel Module names can't be computed.\n"); + } /* display the pci devices we found */ display_pci_devices(pci_domain); diff --git a/sample/Makefile b/sample/Makefile index 8560b3e1..e4c4a6d6 100644 --- a/sample/Makefile +++ b/sample/Makefile @@ -20,10 +20,15 @@ include $(topdir)/MCONFIG.embedded INCLUDES = -I$(com32)/include PPMTOLSS16 = $(topdir)/utils/ppmtolss16 +LIBGCC := $(shell $(CC) $(GCCOPT) --print-libgcc) LIB = liboldcom32.a LIBOBJS = conio.o atou.o skipatou.o printf.o c32exit.o +com32 = $(topdir)/com32 +C_LIBS = $(com32)/libutil/libutil_com.a $(com32)/lib/libcom32.a $(LIBGCC) +LDFLAGS = -m elf_i386 -T $(com32)/lib/com32.ld + all: syslogo.lss comecho.com hello.c32 hello2.c32 filetest.c32 c32echo.c32 \ fd.c32 $(LIB) |