From: Matt Fleming <matt.fleming at linux.intel.com> This series fixes some bugs and switches the elflink branch to be entirely ELF modules. It applies on top of, http://syslinux.zytor.com/archives/2011-April/016369.html The deletions in the diff stat below are mainly from deleting com32/elflink/modules (finally!). Now there should be no duplicate code because we don't need COM32 and ELF modules to coexist. I've sent this as a patch series instead of a pull request because it includes some pretty fundamental changes to the elflink branch and I'd feel better if it got a little bit of a review first. Matt Fleming (20): elflink: Move elf MCONFIG to mk/elf.mk mk: Add rule for emitting .c32 ELF files mk: LDFLAGS use elf_i386 emulation for ld exit: Delete exit.S and references to __exit_handler com32: console is already initialised when we enter main() elflink: Remove MODULE_MAIN() from executable ELF modules elflink: Move more code from core/ into ldlinux com32: Put deleted object files back into the Makefile com32: Remove klibc.c32 cmenu: Rename menu.h to cmenu.h com32: We only need one refstr.h com32: Move menu.h elflink: Delete core-elf.h elflink: Make ELF the default object format exit.c: Truncate exit status to uint8_t elflink: ldlinux should not have any dependencies elflink: Don't compile in debug output by default elflink: Don't require every module to have init/exit functions elf_gen_dep.sh: Don't calculate dependencies for whitespace symbols elf_gen_dep.sh: Prioritise symbols exported by core com32/Makefile | 4 +- com32/cmenu/Makefile | 16 +- com32/cmenu/adv_menu.tpl | 2 +- com32/cmenu/complex.c | 2 +- com32/cmenu/display.c | 2 +- com32/cmenu/libmenu/{menu.h => cmenu.h} | 0 com32/cmenu/libmenu/help.h | 2 +- com32/cmenu/libmenu/menu.c | 2 +- com32/cmenu/simple.c | 2 +- com32/elflink/Makefile | 3 - com32/elflink/ldlinux/Makefile | 15 +- com32/elflink/ldlinux/cli.c | 1 - com32/elflink/ldlinux/colors.c | 1 - {core/elflink => com32/elflink/ldlinux}/execute.c | 74 ++- com32/{libutil => elflink/ldlinux}/get_key.c | 0 {core/elflink => com32/elflink/ldlinux}/kernel.c | 1 - com32/elflink/ldlinux/ldlinux.c | 4 +- com32/elflink/ldlinux/readconfig.c | 1 - com32/elflink/modules/Makefile | 111 --- com32/elflink/modules/README | 1 - com32/elflink/modules/ansiraw.c | 115 --- com32/elflink/modules/background.c | 57 -- com32/elflink/modules/base64.h | 51 - com32/elflink/modules/cpuid.c | 61 -- com32/elflink/modules/cpuidtest.c | 140 --- com32/elflink/modules/crypt-md5.c | 173 ---- com32/elflink/modules/dir.c | 178 ---- com32/elflink/modules/disk.c | 60 -- com32/elflink/modules/drain.c | 40 - com32/elflink/modules/get_key.c | 187 ---- com32/elflink/modules/md5.c | 288 ------ com32/elflink/modules/md5.h | 46 - com32/elflink/modules/meminfo.c | 133 --- com32/elflink/modules/menu.c | 20 - com32/elflink/modules/menu.h | 218 ----- com32/elflink/modules/menumain.c | 977 -------------------- com32/elflink/modules/modules.dep | 19 - com32/elflink/modules/mytest.c | 30 - com32/elflink/modules/passwd.c | 112 --- com32/elflink/modules/pcitest.c | 156 ---- com32/elflink/modules/printmsg.c | 116 --- com32/elflink/modules/refstr.h | 40 - com32/elflink/modules/sha1.h | 18 - com32/elflink/modules/sha1hash.c | 347 ------- com32/elflink/modules/sha256crypt.c | 559 ----------- com32/elflink/modules/sha512crypt.c | 606 ------------ com32/elflink/modules/test.c | 112 --- com32/elflink/modules/unbase64.c | 91 -- com32/elflink/modules/vesainfo.c | 93 -- com32/gfxboot/Makefile | 6 +- com32/gpllib/Makefile | 14 +- com32/hdt/Makefile | 4 +- com32/{elflink/modules => include}/cli.h | 0 com32/{menu => include}/menu.h | 0 com32/{elflink/ldlinux => include}/refstr.h | 0 com32/{elflink/modules => include}/sort.h | 0 com32/include/sys/exec.h | 3 +- com32/include/sys/module.h | 5 +- com32/lib/Makefile | 30 +- com32/lib/exit.c | 2 +- com32/lib/onexit.c | 3 - com32/lib/sys/exit.S | 41 - com32/lib/sys/module/elf_module.c | 47 +- com32/lib/sys/module/exec.c | 53 +- com32/libutil/Makefile | 15 +- .../modules/sort.c => libutil/quicksort.c} | 21 - com32/lua/src/Makefile | 12 +- com32/mboot/Makefile | 4 +- com32/menu/Makefile | 2 +- com32/menu/refstr.h | 40 - com32/modules/Makefile | 15 +- com32/modules/cat.c | 2 - com32/modules/chain.c | 2 - com32/modules/config.c | 2 - com32/modules/cpuid.c | 2 - com32/modules/cpuidtest.c | 1 - com32/modules/dir.c | 2 - com32/modules/disk.c | 2 - com32/modules/dmitest.c | 1 - com32/modules/elf.c | 2 - com32/modules/ethersel.c | 1 - com32/modules/gpxecmd.c | 2 - com32/{elflink => }/modules/hello.c | 7 +- com32/modules/host.c | 2 - com32/modules/ifplop.c | 2 - com32/modules/kbdmap.c | 2 - com32/modules/linux.c | 2 - com32/modules/ls.c | 2 - com32/modules/meminfo.c | 20 +- com32/modules/pcitest.c | 2 - com32/modules/pmload.c | 2 - com32/modules/pwd.c | 1 - com32/modules/sanboot.c | 2 - com32/modules/sdi.c | 2 - com32/modules/vesainfo.c | 46 +- com32/modules/vpdtest.c | 1 - com32/modules/whichsys.c | 2 - com32/samples/Makefile | 2 +- com32/sysdump/Makefile | 6 +- com32/sysdump/main.c | 1 - core/elflink/core-elf.h | 29 - core/elflink/load_env32.c | 8 +- core/strncasecmp.c | 24 - elf_gen_dep.sh | 7 +- mk/com32.mk | 2 +- com32/elflink/modules/MCONFIG => mk/elf.mk | 25 +- mk/lib.mk | 2 +- mk/rosh.mk | 2 +- 108 files changed, 258 insertions(+), 5568 deletions(-) rename com32/cmenu/libmenu/{menu.h => cmenu.h} (100%) rename {core/elflink => com32/elflink/ldlinux}/execute.c (72%) rename com32/{libutil => elflink/ldlinux}/get_key.c (100%) rename {core/elflink => com32/elflink/ldlinux}/kernel.c (99%) delete mode 100644 com32/elflink/modules/Makefile delete mode 100644 com32/elflink/modules/README delete mode 100644 com32/elflink/modules/ansiraw.c delete mode 100644 com32/elflink/modules/background.c delete mode 100644 com32/elflink/modules/base64.h delete mode 100644 com32/elflink/modules/cpuid.c delete mode 100644 com32/elflink/modules/cpuidtest.c delete mode 100644 com32/elflink/modules/crypt-md5.c delete mode 100644 com32/elflink/modules/dir.c delete mode 100644 com32/elflink/modules/disk.c delete mode 100644 com32/elflink/modules/drain.c delete mode 100644 com32/elflink/modules/get_key.c delete mode 100644 com32/elflink/modules/md5.c delete mode 100644 com32/elflink/modules/md5.h delete mode 100644 com32/elflink/modules/meminfo.c delete mode 100644 com32/elflink/modules/menu.c delete mode 100644 com32/elflink/modules/menu.h delete mode 100644 com32/elflink/modules/menumain.c delete mode 100644 com32/elflink/modules/modules.dep delete mode 100644 com32/elflink/modules/mytest.c delete mode 100644 com32/elflink/modules/passwd.c delete mode 100644 com32/elflink/modules/pcitest.c delete mode 100644 com32/elflink/modules/printmsg.c delete mode 100644 com32/elflink/modules/refstr.h delete mode 100644 com32/elflink/modules/sha1.h delete mode 100644 com32/elflink/modules/sha1hash.c delete mode 100644 com32/elflink/modules/sha256crypt.c delete mode 100644 com32/elflink/modules/sha512crypt.c delete mode 100644 com32/elflink/modules/test.c delete mode 100644 com32/elflink/modules/unbase64.c delete mode 100644 com32/elflink/modules/vesainfo.c rename com32/{elflink/modules => include}/cli.h (100%) rename com32/{menu => include}/menu.h (100%) rename com32/{elflink/ldlinux => include}/refstr.h (100%) rename com32/{elflink/modules => include}/sort.h (100%) delete mode 100644 com32/lib/sys/exit.S rename com32/{elflink/modules/sort.c => libutil/quicksort.c} (80%) delete mode 100644 com32/menu/refstr.h rename com32/{elflink => }/modules/hello.c (77%) delete mode 100644 core/elflink/core-elf.h delete mode 100644 core/strncasecmp.c rename com32/elflink/modules/MCONFIG => mk/elf.mk (78%) -- 1.7.4.2
Matt Fleming
2011-Apr-16 14:17 UTC
[syslinux] [PATCH 01/20] elflink: Move elf MCONFIG to mk/elf.mk
From: Matt Fleming <matt.fleming at linux.intel.com> Catch up with recent changes to the Makefile fragments in the MCONFIG files. Signed-off-by: Matt Fleming <matt.fleming at linux.intel.com> --- com32/elflink/Makefile | 3 --- com32/elflink/ldlinux/Makefile | 3 ++- com32/elflink/modules/Makefile | 3 ++- com32/elflink/modules/MCONFIG => mk/elf.mk | 2 +- 4 files changed, 5 insertions(+), 6 deletions(-) rename com32/elflink/modules/MCONFIG => mk/elf.mk (98%) diff --git a/com32/elflink/Makefile b/com32/elflink/Makefile index 39266de..aca3743 100644 --- a/com32/elflink/Makefile +++ b/com32/elflink/Makefile @@ -10,9 +10,6 @@ ## ## ----------------------------------------------------------------------- -topdir = ../.. -include ../MCONFIG - MODULES = TESTFILES diff --git a/com32/elflink/ldlinux/Makefile b/com32/elflink/ldlinux/Makefile index f960693..6fbe1b1 100644 --- a/com32/elflink/ldlinux/Makefile +++ b/com32/elflink/ldlinux/Makefile @@ -11,7 +11,8 @@ ## ----------------------------------------------------------------------- topdir = ../../.. -include ../modules/MCONFIG +MAKEDIR = $(topdir)/mk +include $(MAKEDIR)/elf.mk CFLAGS += -I../modules -I$(topdir)/core/elflink -I$(topdir)/core/include diff --git a/com32/elflink/modules/Makefile b/com32/elflink/modules/Makefile index 6cd0767..eb2d052 100644 --- a/com32/elflink/modules/Makefile +++ b/com32/elflink/modules/Makefile @@ -11,7 +11,8 @@ ## ----------------------------------------------------------------------- topdir = ../../.. -include MCONFIG +MAKEDIR = $(topdir)/mk +include $(MAKEDIR)/elf.mk CFLAGS += -I$(topdir)/core/elflink diff --git a/com32/elflink/modules/MCONFIG b/mk/elf.mk similarity index 98% rename from com32/elflink/modules/MCONFIG rename to mk/elf.mk index 0049128..530cd94 100644 --- a/com32/elflink/modules/MCONFIG +++ b/mk/elf.mk @@ -14,7 +14,7 @@ ## COM32 common configurables ## -include $(topdir)/MCONFIG +include $(MAKEDIR)/syslinux.mk GCCOPT := $(call gcc_ok,-std=gnu99,) GCCOPT += $(call gcc_ok,-m32,) -- 1.7.4.2
Matt Fleming
2011-Apr-16 14:17 UTC
[syslinux] [PATCH 02/20] mk: Add rule for emitting .c32 ELF files
From: Matt Fleming <matt.fleming at linux.intel.com> We currently open code the Makefile rules for outputting .c32 files, so provide a pattern rule to make things easier. There are no users of this rule yet, but we'll make use of it when we switch all modules over to ELF. Signed-off-by: Matt Fleming <matt.fleming at linux.intel.com> --- mk/elf.mk | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diff --git a/mk/elf.mk b/mk/elf.mk index 530cd94..6efcf47 100644 --- a/mk/elf.mk +++ b/mk/elf.mk @@ -11,7 +11,7 @@ ## ----------------------------------------------------------------------- ## -## COM32 common configurables +## ELF common configurables ## include $(MAKEDIR)/syslinux.mk @@ -67,3 +67,5 @@ LNXLDFLAGS = -g %.lnx: %.lo $(LNXLIBS) $(CC) $(LNXLDFLAGS) -o $@ $^ +%.c32: %.o + $(LD) $(LDFLAGS) -o $@ $^ -- 1.7.4.2
Matt Fleming
2011-Apr-16 14:17 UTC
[syslinux] [PATCH 03/20] mk: LDFLAGS use elf_i386 emulation for ld
From: Matt Fleming <matt.fleming at linux.intel.com> elf32_i386 isn't a valid ld emulation mode. Presumably no one is using $(LDFLAGS) set in this file. Signed-off-by: Matt Fleming <matt.fleming at linux.intel.com> --- mk/lib.mk | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/mk/lib.mk b/mk/lib.mk index 3344027..1792ea1 100644 --- a/mk/lib.mk +++ b/mk/lib.mk @@ -38,7 +38,7 @@ OPTFLAGS = -Os -march=i386 -falign-functions=0 -falign-jumps=0 \ WARNFLAGS = $(GCCWARN) -Wpointer-arith -Wwrite-strings -Wstrict-prototypes -Winline CFLAGS = $(OPTFLAGS) $(REQFLAGS) $(WARNFLAGS) $(LIBFLAGS) -LDFLAGS = -m elf32_i386 --hash-style=gnu +LDFLAGS = -m elf_i386 --hash-style=gnu .SUFFIXES: .c .o .a .so .lo .i .S .s .ls .ss .lss -- 1.7.4.2
Matt Fleming
2011-Apr-16 14:17 UTC
[syslinux] [PATCH 04/20] exit: Delete exit.S and references to __exit_handler
From: Matt Fleming <matt.fleming at linux.intel.com> We stopped using exit.S (and thus __exit_handler) in 71d5d1ba646e ("elflink: change the exit.c, remove the exit.S to make process exit working") when we moved to using the C version of _exit(). If we don't remove the symbol __exit_handler we'll encounter undefined symbol errors when moving libcom32.a over to an ELF shared library. Signed-off-by: Matt Fleming <matt.fleming at linux.intel.com> --- com32/lib/onexit.c | 3 --- com32/lib/sys/exit.S | 41 ----------------------------------------- 2 files changed, 0 insertions(+), 44 deletions(-) delete mode 100644 com32/lib/sys/exit.S diff --git a/com32/lib/onexit.c b/com32/lib/onexit.c index d409e82..272f8f1 100644 --- a/com32/lib/onexit.c +++ b/com32/lib/onexit.c @@ -6,7 +6,6 @@ #include <unistd.h> #include "atexit.h" -extern __noreturn(*__exit_handler) (int); static struct atexit *__atexit_list; static __noreturn on_exit_exit(int rv) @@ -33,7 +32,5 @@ int on_exit(void (*fctn) (int, void *), void *arg) as->next = __atexit_list; __atexit_list = as; - __exit_handler = on_exit_exit; - return 0; } diff --git a/com32/lib/sys/exit.S b/com32/lib/sys/exit.S deleted file mode 100644 index 2ab8012..0000000 --- a/com32/lib/sys/exit.S +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Implementation of _exit() for com32 based on c32entry.S - */ - .text - - .globl _Exit - .type _Exit, @function -_Exit: - /* Just fall through to _exit */ - .size _Exit, .-_Exit - - .globl _exit - .type _exit, @function -_exit: -#ifdef REGPARM - pushl %eax -#endif - - /* Run any destructors */ - movl $__dtors_start, %esi -2: - cmpl $__dtors_end, %esi - jae 1f - call *(%esi) - addl $4,%esi - jmp 2b - -1: -#ifdef REGPARM - popl %eax -#else - movl 4(%esp),%eax # Exit code in %eax = return value -#endif - movl (__entry_esp),%esp # Return stack pointer to entry value - ret # Return to termination address - .size _exit, .-_exit - - .data -__exit_handler: - .globl __exit_handler - .long _exit -- 1.7.4.2
Matt Fleming
2011-Apr-16 14:17 UTC
[syslinux] [PATCH 05/20] com32: console is already initialised when we enter main()
From: Matt Fleming <matt.fleming at linux.intel.com> There's no need to initialise the console when we enter main() as ldlinux.c32 will already have initialised it for us. Leaving the calls to openconsole() causes the console settings to be reset whenever we run a module. Signed-off-by: Matt Fleming <matt.fleming at linux.intel.com> --- com32/modules/cat.c | 2 -- com32/modules/chain.c | 2 -- com32/modules/config.c | 2 -- com32/modules/cpuid.c | 2 -- com32/modules/cpuidtest.c | 1 - com32/modules/dir.c | 2 -- com32/modules/disk.c | 2 -- com32/modules/dmitest.c | 1 - com32/modules/elf.c | 2 -- com32/modules/ethersel.c | 1 - com32/modules/gpxecmd.c | 2 -- com32/modules/host.c | 2 -- com32/modules/ifplop.c | 2 -- com32/modules/kbdmap.c | 2 -- com32/modules/linux.c | 2 -- com32/modules/ls.c | 2 -- com32/modules/meminfo.c | 2 -- com32/modules/pcitest.c | 2 -- com32/modules/pmload.c | 2 -- com32/modules/pwd.c | 1 - com32/modules/sanboot.c | 2 -- com32/modules/sdi.c | 2 -- com32/modules/vesainfo.c | 2 -- com32/modules/vpdtest.c | 1 - com32/modules/whichsys.c | 2 -- com32/sysdump/main.c | 1 - 26 files changed, 0 insertions(+), 46 deletions(-) diff --git a/com32/modules/cat.c b/com32/modules/cat.c index 0a9514c..2a7683f 100644 --- a/com32/modules/cat.c +++ b/com32/modules/cat.c @@ -9,8 +9,6 @@ int main(int argc, char *argv[]) int len; char buf[4096]; - openconsole(&dev_stdcon_r, &dev_stdcon_w); - if (argc < 2) { fprintf(stderr, "Usage: %s filename...\n", argv[0]); return 1; diff --git a/com32/modules/chain.c b/com32/modules/chain.c index 48f53ff..09cbeff 100644 --- a/com32/modules/chain.c +++ b/com32/modules/chain.c @@ -1314,8 +1314,6 @@ int main(int argc, char *argv[]) addr_t load_base; static const char cmldr_signature[8] = "cmdcons"; - openconsole(&dev_null_r, &dev_stdcon_w); - drivename = "boot"; partition = NULL; diff --git a/com32/modules/config.c b/com32/modules/config.c index 334a635..04cb0ab 100644 --- a/com32/modules/config.c +++ b/com32/modules/config.c @@ -24,8 +24,6 @@ int main(int argc, char *argv[]) { - openconsole(&dev_null_r, &dev_stdcon_w); - if (argc < 2 || argc > 3) { fprintf(stderr, "Usage: config <filename> [<directory>]\n"); return 1; diff --git a/com32/modules/cpuid.c b/com32/modules/cpuid.c index 78cb3f5..a243896 100644 --- a/com32/modules/cpuid.c +++ b/com32/modules/cpuid.c @@ -34,8 +34,6 @@ int main(int argc, char *argv[]) uint32_t leaf, counter; uint32_t eax, ebx, ecx, edx; - openconsole(&dev_null_r, &dev_stdcon_w); - if (argc < 2 || argc > 4) { printf("Usage: %s leaf [counter]\n", argv[0]); exit(1); diff --git a/com32/modules/cpuidtest.c b/com32/modules/cpuidtest.c index b768885..d00256f 100644 --- a/com32/modules/cpuidtest.c +++ b/com32/modules/cpuidtest.c @@ -42,7 +42,6 @@ char display_line; int main(void) { s_cpu cpu; - openconsole(&dev_stdcon_r, &dev_stdcon_w); for (;;) { detect_cpu(&cpu); diff --git a/com32/modules/dir.c b/com32/modules/dir.c index c9d9370..01a99ed 100644 --- a/com32/modules/dir.c +++ b/com32/modules/dir.c @@ -155,8 +155,6 @@ int main(int argc, char *argv[]) { int rv; - openconsole(&dev_rawcon_r, &dev_stdcon_w); - if (getscreensize(1, &rows, &cols)) { /* Unknown screen size? */ rows = 24; diff --git a/com32/modules/disk.c b/com32/modules/disk.c index ca4b598..5d68381 100644 --- a/com32/modules/disk.c +++ b/com32/modules/disk.c @@ -27,8 +27,6 @@ int main(int argc, char *argv[]) (void)argc; (void)argv; - openconsole(&dev_null_r, &dev_stdcon_w); - for (int disk = 0x80; disk < 0xff; disk++) { memset(d, 0, sizeof(struct driveinfo)); d->disk = disk; diff --git a/com32/modules/dmitest.c b/com32/modules/dmitest.c index 294585b..4ce2eaa 100644 --- a/com32/modules/dmitest.c +++ b/com32/modules/dmitest.c @@ -179,7 +179,6 @@ int main(void) { char buffer[1024]; s_dmi dmi; - openconsole(&dev_stdcon_r, &dev_stdcon_w); if (dmi_iterate(&dmi) == -ENODMITABLE) { printf("No DMI Structure found\n"); diff --git a/com32/modules/elf.c b/com32/modules/elf.c index 182afa6..84c80ac 100644 --- a/com32/modules/elf.c +++ b/com32/modules/elf.c @@ -269,8 +269,6 @@ int main(int argc, char *argv[]) void *data; size_t data_len; - openconsole(&dev_null_r, &dev_stdcon_w); - if (argc < 2) { error("Usage: elf.c32 elf_file arguments...\n"); return 1; diff --git a/com32/modules/ethersel.c b/com32/modules/ethersel.c index 5c3cf02..d6b4774 100644 --- a/com32/modules/ethersel.c +++ b/com32/modules/ethersel.c @@ -185,7 +185,6 @@ int main(int argc, char *argv[]) struct match *list, *match; struct pci_domain *pci_domain; - openconsole(&dev_null_r, &dev_stdcon_w); pci_domain = pci_scan(); if (pci_domain) { diff --git a/com32/modules/gpxecmd.c b/com32/modules/gpxecmd.c index 057659b..9ae1b60 100644 --- a/com32/modules/gpxecmd.c +++ b/com32/modules/gpxecmd.c @@ -68,8 +68,6 @@ static void gpxecmd(const char **args) int main(int argc, const char *argv[]) { - openconsole(&dev_null_r, &dev_stdcon_w); - if (argc < 2) { printf("Usage: gpxecmd command...\n"); return 1; diff --git a/com32/modules/host.c b/com32/modules/host.c index 94ca876..c9cea97 100644 --- a/com32/modules/host.c +++ b/com32/modules/host.c @@ -25,8 +25,6 @@ int main(int argc, char *argv[]) int i; struct in_addr addr; - openconsole(&dev_null_r, &dev_stdcon_w); - for (i = 1; i < argc; i++) { addr = dnsresolve(argv[i]); diff --git a/com32/modules/ifplop.c b/com32/modules/ifplop.c index a846df8..f502e2b 100644 --- a/com32/modules/ifplop.c +++ b/com32/modules/ifplop.c @@ -144,8 +144,6 @@ int main(int argc, char *argv[]) char **args[2]; int arg = 0; - openconsole(&dev_null_r, &dev_stdcon_w); - if (argc) arg++; args[0] = &argv[arg]; diff --git a/com32/modules/kbdmap.c b/com32/modules/kbdmap.c index f1c736d..7ec4001 100644 --- a/com32/modules/kbdmap.c +++ b/com32/modules/kbdmap.c @@ -27,8 +27,6 @@ int main(int argc, char *argv[]) size_t map_size; void *kbdmap; - openconsole(&dev_null_r, &dev_stdcon_w); - if (argc != 2) { error("Usage: kbdmap mapfile\n"); return 1; diff --git a/com32/modules/linux.c b/com32/modules/linux.c index b902ebc..a5ce01f 100644 --- a/com32/modules/linux.c +++ b/com32/modules/linux.c @@ -122,8 +122,6 @@ int main(int argc, char *argv[]) size_t dhcplen; char **argp, *arg, *p; - openconsole(&dev_null_r, &dev_stdcon_w); - (void)argc; argp = argv + 1; diff --git a/com32/modules/ls.c b/com32/modules/ls.c index c311621..11c18ae 100644 --- a/com32/modules/ls.c +++ b/com32/modules/ls.c @@ -155,8 +155,6 @@ int main(int argc, char *argv[]) { int rv; - openconsole(&dev_rawcon_r, &dev_stdcon_w); - if (getscreensize(1, &rows, &cols)) { /* Unknown screen size? */ rows = 24; diff --git a/com32/modules/meminfo.c b/com32/modules/meminfo.c index 6e24f35..96006d4 100644 --- a/com32/modules/meminfo.c +++ b/com32/modules/meminfo.c @@ -117,8 +117,6 @@ static void dump_legacy(void) int main(void) { - openconsole(&dev_null_r, &dev_stdcon_w); - dump_legacy(); dump_e820(); diff --git a/com32/modules/pcitest.c b/com32/modules/pcitest.c index 672023a..c4317ef 100644 --- a/com32/modules/pcitest.c +++ b/com32/modules/pcitest.c @@ -108,8 +108,6 @@ int main(int argc, char *argv[]) (void)argc; (void)argv; - openconsole(&dev_stdcon_r, &dev_stdcon_w); - /* Scanning to detect pci buses and devices */ printf("PCI: Scanning PCI BUS\n"); pci_domain = pci_scan(); diff --git a/com32/modules/pmload.c b/com32/modules/pmload.c index 3064a94..88065fb 100644 --- a/com32/modules/pmload.c +++ b/com32/modules/pmload.c @@ -204,8 +204,6 @@ int main(int argc, char *argv[]) size_t data_len; addr_t where; - openconsole(&dev_null_r, &dev_stdcon_w); - if (argc < 3) { error("Usage: pmload.c32 bin_file address arguments...\n"); return 1; diff --git a/com32/modules/pwd.c b/com32/modules/pwd.c index 880327d..2794e3d 100644 --- a/com32/modules/pwd.c +++ b/com32/modules/pwd.c @@ -36,7 +36,6 @@ int main(void) int rv = 0; char pwd[PATH_MAX], *pwdptr; - openconsole(&dev_rawcon_r, &dev_stdcon_w); pwdptr = getcwd(pwd, PATH_MAX); if (pwdptr) { if (pwd[0] != 0) diff --git a/com32/modules/sanboot.c b/com32/modules/sanboot.c index 46df6bc..01265de 100644 --- a/com32/modules/sanboot.c +++ b/com32/modules/sanboot.c @@ -69,8 +69,6 @@ static void sanboot(const char **args) int main(int argc, const char *argv[]) { - openconsole(&dev_null_r, &dev_stdcon_w); - if (argc < 2) { printf("Usage: sanboot rootpath\n"); return 1; diff --git a/com32/modules/sdi.c b/com32/modules/sdi.c index 69841d2..e57ad4a 100644 --- a/com32/modules/sdi.c +++ b/com32/modules/sdi.c @@ -160,8 +160,6 @@ int main(int argc, char *argv[]) void *data; size_t data_len; - openconsole(&dev_null_r, &dev_stdcon_w); - if (argc != 2) { error("Usage: sdi.c32 sdi_file\n"); return 1; diff --git a/com32/modules/vesainfo.c b/com32/modules/vesainfo.c index 00181e4..f9b2502 100644 --- a/com32/modules/vesainfo.c +++ b/com32/modules/vesainfo.c @@ -75,8 +75,6 @@ static void print_modes(void) int main(void) { - openconsole(&dev_rawcon_r, &dev_stdcon_w); - print_modes(); return 0; } diff --git a/com32/modules/vpdtest.c b/com32/modules/vpdtest.c index 1d50c68..c0f32ba 100644 --- a/com32/modules/vpdtest.c +++ b/com32/modules/vpdtest.c @@ -40,7 +40,6 @@ int main(void) { s_vpd vpd; - openconsole(&dev_stdcon_r, &dev_stdcon_w); if (vpd_decode(&vpd) == -ENOVPDTABLE) { printf("No VPD Structure found\n"); diff --git a/com32/modules/whichsys.c b/com32/modules/whichsys.c index af133f2..777cb9e 100644 --- a/com32/modules/whichsys.c +++ b/com32/modules/whichsys.c @@ -78,8 +78,6 @@ int main(int argc, char *argv[]) int arg = 0; - openconsole(&dev_null_r, &dev_stdcon_w); - /* If no argument got passed, let's show the usage */ if (argc == 1) { usage(); diff --git a/com32/sysdump/main.c b/com32/sysdump/main.c index d0d40a7..155b980 100644 --- a/com32/sysdump/main.c +++ b/com32/sysdump/main.c @@ -73,7 +73,6 @@ int main(int argc, char *argv[]) { struct backend **bep, *be; - openconsole(&dev_null_r, &dev_stdcon_w); fputs(version, stdout); if (argc < 2) -- 1.7.4.2
Matt Fleming
2011-Apr-16 14:17 UTC
[syslinux] [PATCH 06/20] elflink: Remove MODULE_MAIN() from executable ELF modules
From: Matt Fleming <matt.fleming at linux.intel.com> To make it easier to move existing COM32 modules over to ELF modules without having to modify them we need to search for and run their main() functions when they're loaded instead of requiring their initial function to be labeled with MODULE_MAIN(). Currently, we require all executable ELF modules to specify their initial function with the use of the MODULE_MAIN() macro and not via the traditional method of naming it main(). However, there are weird restrictions on what functions can be passed to MODULE_MAIN(), for instance, they must be declared static. This patch makes life much simpler and allows executable ELF modules to be loaded without the MODULE_MAIN() wrapper, but rather by naming their initial function main(). All the modules in com32/modules can now be run as ELF modules without any modifications. Signed-off-by: Matt Fleming <matt.fleming at linux.intel.com> --- com32/elflink/ldlinux/ldlinux.c | 3 +- com32/elflink/modules/Makefile | 11 +-- com32/elflink/modules/cpuid.c | 61 ------------- com32/elflink/modules/cpuidtest.c | 140 ----------------------------- com32/elflink/modules/dir.c | 178 ------------------------------------- com32/elflink/modules/disk.c | 60 ------------- com32/elflink/modules/hello.c | 7 +- com32/elflink/modules/meminfo.c | 5 +- com32/elflink/modules/menu.c | 4 +- com32/elflink/modules/mytest.c | 5 +- com32/elflink/modules/pcitest.c | 156 -------------------------------- com32/elflink/modules/test.c | 5 +- com32/elflink/modules/vesainfo.c | 5 +- com32/include/sys/module.h | 5 +- com32/lib/sys/module/elf_module.c | 16 +--- com32/lib/sys/module/exec.c | 8 +- 16 files changed, 18 insertions(+), 651 deletions(-) delete mode 100644 com32/elflink/modules/cpuid.c delete mode 100644 com32/elflink/modules/cpuidtest.c delete mode 100644 com32/elflink/modules/dir.c delete mode 100644 com32/elflink/modules/disk.c delete mode 100644 com32/elflink/modules/pcitest.c diff --git a/com32/elflink/ldlinux/ldlinux.c b/com32/elflink/ldlinux/ldlinux.c index 839a28a..5f4b058 100644 --- a/com32/elflink/ldlinux/ldlinux.c +++ b/com32/elflink/ldlinux/ldlinux.c @@ -97,7 +97,7 @@ static void enter_cmdline(void) } } -static int ldlinux_main(int argc, char **argv) +int main(int argc, char **argv) { openconsole(&dev_rawcon_r, &dev_ansiserial_w); @@ -129,4 +129,3 @@ cmdline: return 0; } -MODULE_MAIN(ldlinux_main); diff --git a/com32/elflink/modules/Makefile b/com32/elflink/modules/Makefile index eb2d052..8a274ae 100644 --- a/com32/elflink/modules/Makefile +++ b/com32/elflink/modules/Makefile @@ -18,7 +18,7 @@ CFLAGS += -I$(topdir)/core/elflink MODULES = hello.c32 sort.c32 mytest.c32 menumain.c32 printmsg.c32 background.c32 passwd.c32 sha1hash.c32 \ unbase64.c32 sha512crypt.c32 md5.c32 crypt-md5.c32 sha256crypt.c32 get_key.c32 ansiraw.c32 test.c32 \ - meminfo.c32 menu.c32 drain.c32 dir.c32 pcitest.c32 vesainfo.c32 cpuid.c32 cpuidtest.c32 + meminfo.c32 menu.c32 drain.c32 vesainfo.c32 TESTFILES @@ -84,18 +84,9 @@ meminfo.c32 : meminfo.o pcitest.c32 : pcitest.o $(LD) $(LDFLAGS) -o $@ $^ -dir.c32 : dir.o - $(LD) $(LDFLAGS) -o $@ $^ - vesainfo.c32 : vesainfo.o $(LD) $(LDFLAGS) -o $@ $^ -cpuid.c32 : cpuid.o - $(LD) $(LDFLAGS) -o $@ $^ - -cpuidtest.c32 : cpuidtest.o - $(LD) $(LDFLAGS) -o $@ $^ - tidy dist: rm -f *.o *.lo *.a *.lst .*.d diff --git a/com32/elflink/modules/cpuid.c b/com32/elflink/modules/cpuid.c deleted file mode 100644 index 1b5d188..0000000 --- a/com32/elflink/modules/cpuid.c +++ /dev/null @@ -1,61 +0,0 @@ -/* ----------------------------------------------------------------------- * - * - * Copyright 2010 Intel Corporation; author: H. Peter Anvin - * - * 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., 51 Franklin St, Fifth Floor, - * Boston MA 02110-1301, USA; either version 2 of the License, or - * (at your option) any later version; incorporated herein by reference. - * - * ----------------------------------------------------------------------- */ - -#include <stdio.h> -#include <stdlib.h> -#include <sys/cpu.h> -#include <console.h> -#include <com32.h> - -#include <sys/module.h> - -static void dump_reg(const char *name, uint32_t val) -{ - int i; - - printf("%-3s : %10u 0x%08x ", name, val, val); - - for (i = 3; i >= 0; i--) { - uint8_t c = val >> (i*8); - putchar((c >= ' ' && c <= '~') ? c : '.'); - } - putchar('\n'); -} - -static int cpuid_main(int argc, char *argv[]) -{ - uint32_t leaf, counter; - uint32_t eax, ebx, ecx, edx; - - if (argc < 2 || argc > 4) { - printf("Usage: %s leaf [counter]\n", argv[0]); - exit(1); - } - - leaf = strtoul(argv[1], NULL, 0); - counter = (argc > 2) ? strtoul(argv[2], NULL, 0) : 0; - - if (!cpu_has_eflag(EFLAGS_ID)) { - printf("The CPUID instruction is not supported\n"); - exit(1); - } - - cpuid_count(leaf, counter, &eax, &ebx, &ecx, &edx); - - dump_reg("eax", eax); - dump_reg("ebx", ebx); - dump_reg("ecx", ecx); - dump_reg("edx", edx); - - return 0; -} -MODULE_MAIN(cpuid_main); diff --git a/com32/elflink/modules/cpuidtest.c b/com32/elflink/modules/cpuidtest.c deleted file mode 100644 index 942955f..0000000 --- a/com32/elflink/modules/cpuidtest.c +++ /dev/null @@ -1,140 +0,0 @@ -/* ----------------------------------------------------------------------- * - * - * 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. - * - * 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. - * - * ----------------------------------------------------------------------- -*/ - -/* - * cpuidtest.c - * - * A CPUID demo program using libcom32 - */ - -#include <string.h> -#include <stdio.h> -#include <console.h> -#include "cpuid.h" - -#include <sys/module.h> - -char display_line; - -static int cpuidtest_main(void) -{ - s_cpu cpu; - - for (;;) { - detect_cpu(&cpu); - printf("Vendor = %s\n", cpu.vendor); - printf("Model = %s\n", cpu.model); - printf("Vendor ID = %d\n", cpu.vendor_id); - printf("Family = %d\n", cpu.family); - printf("Model ID = %d\n", cpu.model_id); - printf("Stepping = %d\n", cpu.stepping); - printf("Flags = "); - if (cpu.flags.fpu) - printf("fpu "); - if (cpu.flags.vme) - printf("vme "); - if (cpu.flags.de) - printf("de "); - if (cpu.flags.pse) - printf("pse "); - if (cpu.flags.tsc) - printf("tsc "); - if (cpu.flags.msr) - printf("msr "); - if (cpu.flags.pae) - printf("pae "); - if (cpu.flags.mce) - printf("mce "); - if (cpu.flags.cx8) - printf("cx8 "); - if (cpu.flags.apic) - printf("apic "); - if (cpu.flags.sep) - printf("sep "); - if (cpu.flags.mtrr) - printf("mtrr "); - if (cpu.flags.pge) - printf("pge "); - if (cpu.flags.mca) - printf("mca "); - if (cpu.flags.cmov) - printf("cmov "); - if (cpu.flags.pat) - printf("pat "); - if (cpu.flags.pse_36) - printf("pse_36 "); - if (cpu.flags.psn) - printf("psn "); - if (cpu.flags.clflsh) - printf("clflsh "); - if (cpu.flags.dts) - printf("dts "); - if (cpu.flags.acpi) - printf("acpi "); - if (cpu.flags.mmx) - printf("mmx "); - if (cpu.flags.sse) - printf("sse "); - if (cpu.flags.sse2) - printf("sse2 "); - if (cpu.flags.ss) - printf("ss "); - if (cpu.flags.htt) - printf("ht "); - if (cpu.flags.acc) - printf("acc "); - if (cpu.flags.syscall) - printf("syscall "); - if (cpu.flags.mp) - printf("mp "); - if (cpu.flags.nx) - printf("nx "); - if (cpu.flags.mmxext) - printf("mmxext "); - if (cpu.flags.lm) - printf("lm "); - if (cpu.flags.nowext) - printf("3dnowext "); - if (cpu.flags.now) - printf("3dnow! "); - if (cpu.flags.vmx) - printf("vmx "); - if (cpu.flags.svm) - printf("svm "); - printf("\n"); - printf("SMP = "); - if (cpu.flags.smp) - printf("yes\n"); - else - printf("no\n"); - break; - } - - return 0; -} -MODULE_MAIN(cpuidtest_main); diff --git a/com32/elflink/modules/dir.c b/com32/elflink/modules/dir.c deleted file mode 100644 index 17e7880..0000000 --- a/com32/elflink/modules/dir.c +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Display directory contents - */ -#include <stdlib.h> -#include <stdio.h> -#include <console.h> -#include <string.h> -#include <com32.h> -#include <dirent.h> -#include <minmax.h> -#include <unistd.h> -#include <getkey.h> - -#include <sys/module.h> - -static int rows, cols; /* Screen parameters */ - -#define DIR_CHUNK 1024 - -static const char *type_str(int type) -{ - switch (type) { - case DT_FIFO: - return "[fif]"; - case DT_CHR: - return "[chr]"; - case DT_DIR: - return "[dir]"; - case DT_BLK: - return "[blk]"; - case DT_UNKNOWN: - case DT_REG: - return ""; - case DT_LNK: - return "[lnk]"; - case DT_SOCK: - return "[sck]"; - case DT_WHT: - return "[wht]"; - default: - return "[???]"; - } -} - -static void free_dirents(struct dirent **dex, size_t n_de) -{ - size_t i; - - for (i = 0; i < n_de; i++) - free(dex[i]); - - free(dex); -} - -static int compare_dirent(const void *p_de1, const void *p_de2) -{ - const struct dirent *de1 = *(const struct dirent **)p_de1; - const struct dirent *de2 = *(const struct dirent **)p_de2; - int ndir1, ndir2; - - ndir1 = de1->d_type != DT_DIR; - ndir2 = de2->d_type != DT_DIR; - - if (ndir1 != ndir2) - return ndir1 - ndir2; - - return strcmp(de1->d_name, de2->d_name); -} - -static int display_directory(const char *dirname) -{ - DIR *dir; - struct dirent *de; - struct dirent **dex = NULL; - size_t n_dex = 0, n_de = 0; - size_t i, j, k; - size_t nrows, ncols, perpage; - size_t endpage; - int maxlen = 0; - int pos, tpos, colwidth; - - dir = opendir(dirname); - if (!dir) { - printf("Unable to read directory: %s\n", dirname); - return -1; - } - - while ((de = readdir(dir)) != NULL) { - struct dirent *nde; - - if (n_de >= n_dex) { - struct dirent **ndex; - - ndex = realloc(dex, (n_dex + DIR_CHUNK) * sizeof *dex); - if (!ndex) - goto nomem; - - dex = ndex; - n_dex += DIR_CHUNK; - } - - nde = malloc(de->d_reclen); - if (!nde) - goto nomem; - - memcpy(nde, de, de->d_reclen); - dex[n_de++] = nde; - - maxlen = max(maxlen, de->d_reclen); - } - - closedir(dir); - - qsort(dex, n_de, sizeof *dex, compare_dirent); - - maxlen -= offsetof(struct dirent, d_name) + 1; - ncols = (cols + 2)/(maxlen + 8); - ncols = min(ncols, n_de); - ncols = max(ncols, 1U); - colwidth = (cols + 2)/ncols; - perpage = ncols * (rows - 1); - - for (i = 0; i < n_de; i += perpage) { - /* Rows on this page */ - endpage = min(i+perpage, n_de); - nrows = ((endpage-i) + ncols - 1)/ncols; - - for (j = 0; j < nrows; j++) { - pos = tpos = 0; - for (k = i+j; k < endpage; k += nrows) { - pos += printf("%*s%-5s %s", - (tpos - pos), "", - type_str(dex[k]->d_type), - dex[k]->d_name); - tpos += colwidth; - } - printf("\n"); - } - - if (endpage >= n_de) - break; - - get_key(stdin, 0); - } - - free_dirents(dex, n_de); - return 0; - -nomem: - closedir(dir); - printf("Out of memory error!\n"); - free_dirents(dex, n_de); - return -1; -} - -static int dir_main(int argc, char *argv[]) -{ - int rv; - - if (getscreensize(1, &rows, &cols)) { - /* Unknown screen size? */ - rows = 24; - cols = 80; - } - - if (argc < 2) - rv = display_directory("."); - else if (argc == 2) - rv = display_directory(argv[1]); - else { - printf("Usage: dir directory\n"); - rv = 1; - } - - return rv ? 1 : 0; -} -MODULE_MAIN(dir_main); - diff --git a/com32/elflink/modules/disk.c b/com32/elflink/modules/disk.c deleted file mode 100644 index 3c864bd..0000000 --- a/com32/elflink/modules/disk.c +++ /dev/null @@ -1,60 +0,0 @@ -/* ----------------------------------------------------------------------- * - * - * Copyright 2009 Pierre-Alexandre Meyer - 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., 51 Franklin St, Fifth Floor, - * Boston MA 02110-1301, USA; either version 2 of the License, or - * (at your option) any later version; incorporated herein by reference. - * - * ----------------------------------------------------------------------- */ - -#include <stdio.h> -#include <console.h> -#include <stdlib.h> -#include <string.h> -#include <disk/geom.h> -#include <disk/util.h> -#include <disk/errno_disk.h> -#include <disk/error.h> - -#include <sys/module.h> - -int disk_main(int argc, char *argv[]) -{ - struct driveinfo drive; - struct driveinfo *d = &drive; - - for (int disk = 0x80; disk < 0xff; disk++) { - memset(d, 0, sizeof(struct driveinfo)); - d->disk = disk; - get_drive_parameters(d); - - /* Do not print output when drive does not exists */ - if (errno_disk == -1 || !d->cbios) - continue; - - if (errno_disk) { - printf("reading disk"); - continue; - } - - printf("DISK 0x%X:\n", d->disk); - printf(" C/H/S: %d heads, %d cylinders\n", - d->legacy_max_head + 1, d->legacy_max_cylinder + 1); - printf(" %d sectors/track, %d drives\n", - d->legacy_sectors_per_track, d->legacy_max_drive); - printf(" EDD: ebios=%d, EDD version: %X\n", - d->ebios, d->edd_version); - printf(" %d heads, %d cylinders\n", - (int) d->edd_params.heads, (int) d->edd_params.cylinders); - printf(" %d sectors, %d bytes/sector, %d sectors/track\n", - (int) d->edd_params.sectors, (int) d->edd_params.bytes_per_sector, - (int) d->edd_params.sectors_per_track); - printf(" Host bus: %s, Interface type: %s\n\n", - d->edd_params.host_bus_type, d->edd_params.interface_type); - } - return 0; -} -MODULE_MAIN(disk_main); diff --git a/com32/elflink/modules/hello.c b/com32/elflink/modules/hello.c index b38f05c..f28d38d 100644 --- a/com32/elflink/modules/hello.c +++ b/com32/elflink/modules/hello.c @@ -7,23 +7,20 @@ #include <stdio.h> #include <stdlib.h> -#include <sys/module.h> #include "sort.h" #define NUM_COUNT 10 #define MAX_NUM 100 -static int hello_main(int argc, char **argv) +int main(int argc, char **argv) { int *nums = NULL; nums = malloc(NUM_COUNT * sizeof(int)); - printf("Hello, world, from 0x%08X! malloc return %p\n", (unsigned int)&hello_main, nums); + printf("Hello, world, from 0x%08X! malloc return %p\n", (unsigned int)&main, nums); free(nums); return 0; } - -MODULE_MAIN(hello_main); diff --git a/com32/elflink/modules/meminfo.c b/com32/elflink/modules/meminfo.c index db9718a..00d0e14 100644 --- a/com32/elflink/modules/meminfo.c +++ b/com32/elflink/modules/meminfo.c @@ -22,8 +22,6 @@ #include <console.h> #include <com32.h> -#include <sys/module.h> - struct e820_data { uint64_t base; uint64_t len; @@ -124,10 +122,9 @@ static void dump_legacy(void) oreg.ecx.w[0], oreg.ecx.w[0], oreg.edx.w[0], oreg.edx.w[0] << 6); } -static int meminfo_main(void) +int main(int argc, char **argv) { dump_legacy(); dump_e820(); return 0; } -MODULE_MAIN(meminfo_main); diff --git a/com32/elflink/modules/menu.c b/com32/elflink/modules/menu.c index c0813a8..d0134b3 100644 --- a/com32/elflink/modules/menu.c +++ b/com32/elflink/modules/menu.c @@ -5,16 +5,14 @@ #include <stdio.h> #include <stdlib.h> #include <core-elf.h> -#include <sys/module.h> #include "menu.h" /* * useage: menu.c32 [config file] */ -static int menu(int argc, char **argv) +int menu(int argc, char **argv) { menu_main(argc, argv); return 0; } -MODULE_MAIN(menu); diff --git a/com32/elflink/modules/mytest.c b/com32/elflink/modules/mytest.c index 04c59ac..e8b5c1c 100644 --- a/com32/elflink/modules/mytest.c +++ b/com32/elflink/modules/mytest.c @@ -15,16 +15,13 @@ #include <core-elf.h> #include <syslinux/adv.h> #include <syslinux/config.h> -#include <sys/module.h> #include "menu.h" -static int mytest_main(int argc, char **argv) +int main(int argc, char **argv) { console_ansi_raw(); //edit_cmdline("",1); menu_main(argc, argv); return 0; } - -MODULE_MAIN(mytest_main); diff --git a/com32/elflink/modules/pcitest.c b/com32/elflink/modules/pcitest.c deleted file mode 100644 index dcb8098..0000000 --- a/com32/elflink/modules/pcitest.c +++ /dev/null @@ -1,156 +0,0 @@ -/* ----------------------------------------------------------------------- * - * - * 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. - * - * 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. - * - * ----------------------------------------------------------------------- -*/ - -/* - * pcitest.c - * - */ - -#include <inttypes.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <console.h> -#include <com32.h> -#include <sys/pci.h> -#include <stdbool.h> - -#include <sys/module.h> - -#ifdef DEBUG -# define dprintf printf -#else -# define dprintf(...) ((void)0) -#endif - -char display_line = 0; -#define moreprintf(...) \ - do { \ - display_line++; \ - if (display_line == 24) { \ - char tempbuf[10]; \ - display_line=0; \ - printf("Press Enter to continue\n"); \ - fgets(tempbuf, sizeof tempbuf, stdin); \ - } \ - printf ( __VA_ARGS__); \ - } while (0); - -void display_pci_devices(struct pci_domain *pci_domain) -{ - struct pci_device *pci_device; - char kernel_modules[LINUX_KERNEL_MODULE_SIZE * - MAX_KERNEL_MODULES_PER_PCI_DEVICE]; - - for_each_pci_func(pci_device, pci_domain) { - - 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); - } -} - -static int pcitest_main(int argc, char *argv[]) -{ - struct pci_domain *pci_domain; - int return_code = 0; - int nb_pci_devices = 0; - - /* Scanning to detect pci buses and devices */ - printf("PCI: Scanning PCI BUS\n"); - pci_domain = pci_scan(); - if (!pci_domain) { - printf("PCI: no devices found!\n"); - return 1; - } - - 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 */ - 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 file in current directory.\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 file in current directory.\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 */ - return_code = get_module_name_from_pcimap(pci_domain, "modules.pcimap"); - if (return_code == -ENOMODULESPCIMAP) { - printf("PCI: ERROR !\n"); - printf("PCI: Unable to open modules.pcimap file in current directory.\n"); - printf("PCI: Kernel Module names can't be computed.\n"); - } - - /* display the pci devices we found */ - display_pci_devices(pci_domain); - return 0; -} -MODULE_MAIN(pcitest_main); diff --git a/com32/elflink/modules/test.c b/com32/elflink/modules/test.c index dd9e520..13892fb 100644 --- a/com32/elflink/modules/test.c +++ b/com32/elflink/modules/test.c @@ -45,12 +45,11 @@ #include <console.h> #include <syslinux/loadfile.h> #include <syslinux/linux.h> -#include <sys/module.h> #include <dprintf.h> //const char *progname = "test.c32"; -static int test_main(int argc, char *argv[]) +int main(int argc, char *argv[]) { const char *kernel_name; struct initramfs *initramfs; @@ -108,5 +107,3 @@ bail: fprintf(stderr, "Kernel load failure (insufficient memory?)\n"); return 1; } - -MODULE_MAIN(test_main); diff --git a/com32/elflink/modules/vesainfo.c b/com32/elflink/modules/vesainfo.c index 05e4f2c..86a4365 100644 --- a/com32/elflink/modules/vesainfo.c +++ b/com32/elflink/modules/vesainfo.c @@ -11,8 +11,6 @@ #include <inttypes.h> #include "../lib/sys/vesa/vesa.h" -#include <sys/module.h> - /* Wait for a keypress */ static void wait_key(void) { @@ -85,9 +83,8 @@ exit: return; } -static int vesainfo_main(void) +int main(int argc, char **argv) { print_modes(); return 0; } -MODULE_MAIN(vesainfo_main); diff --git a/com32/include/sys/module.h b/com32/include/sys/module.h index dbeab4a..fb72c4b 100644 --- a/com32/include/sys/module.h +++ b/com32/include/sys/module.h @@ -97,7 +97,7 @@ struct elf_module { module_init_t *init_func; // The initialization entry point module_exit_t *exit_func; // The module finalization code - module_main_t *main_func; // The main function (for executable modules) + module_main_t main_func; // The main function (for executable modules) void *module_addr; // The module location in the memory @@ -175,9 +175,6 @@ struct module_dep { #define MODULE_EXIT(fn) static module_exit_t __module_exit \ __used __attribute__((section(".dtors_modexit"))) = fn -#define MODULE_MAIN(fn) static module_main_t __module_main \ - __used __attribute__((section(".ctors_modmain"))) = fn - #else /* diff --git a/com32/lib/sys/module/elf_module.c b/com32/lib/sys/module/elf_module.c index 4bc5d94..afb5b64 100644 --- a/com32/lib/sys/module/elf_module.c +++ b/com32/lib/sys/module/elf_module.c @@ -388,7 +388,7 @@ static int resolve_symbols(struct elf_module *module) { static int extract_operations(struct elf_module *module) { Elf32_Sym *init_sym = module_find_symbol(MODULE_ELF_INIT_PTR, module); Elf32_Sym *exit_sym = module_find_symbol(MODULE_ELF_EXIT_PTR, module); - Elf32_Sym *main_sym = module_find_symbol(MODULE_ELF_MAIN_PTR, module); + Elf32_Sym *main_sym = module_find_symbol("main", module); if (init_sym == NULL) { DBG_PRINT("Cannot find initialization routine pointer.\n"); @@ -400,11 +400,6 @@ static int extract_operations(struct elf_module *module) { printf("Cannot find exit routine pointer.\n"); return -1; } - if (main_sym == NULL) { - DBG_PRINT("Cannot find main routine pointer.\n"); - printf("Cannot find main routine pointer.\n"); - return -1; - } module->init_func = (module_init_t*)module_get_absolute( init_sym->st_value, module); @@ -418,12 +413,9 @@ static int extract_operations(struct elf_module *module) { module->exit_func = NULL; } - module->main_func = (module_main_t*)module_get_absolute( - main_sym->st_value, module); - if (*(module->main_func) == NULL) { - module->main_func = NULL; - } - + if (main_sym) + module->main_func + module_get_absolute(main_sym->st_value, module); return 0; } diff --git a/com32/lib/sys/module/exec.c b/com32/lib/sys/module/exec.c index fbe165d..78df72e 100644 --- a/com32/lib/sys/module/exec.c +++ b/com32/lib/sys/module/exec.c @@ -188,7 +188,7 @@ int spawnv(const char *name, const char **argv) else if (!module->main_func) ret_val = -1; else - exit((*module->main_func)(argc, args)); /* Actually run! */ + exit((module->main_func)(argc, args)); /* Actually run! */ // Clean up the allocation context __free_tagged(module); @@ -246,8 +246,8 @@ int spawn_load(const char *name,const char **argv) * type EXEC_MODULE, then just return. We don't reload * the module because that might cause us to re-run * the init functions, which will cause us to run the - * MODULE_MAIN function, which will take control of - * this process. + * main function, which will take control of this + * process. * * This can happen if some other EXEC_MODULE is * resolving a symbol that is exported by the current @@ -318,7 +318,7 @@ int spawn_load(const char *name,const char **argv) else if (!module->main_func) ret_val = -1; else - exit((*module->main_func)(argc, args)); /* Actually run! */ + exit((module->main_func)(argc, args)); /* Actually run! */ // Clean up the allocation context -- 1.7.4.2
Matt Fleming
2011-Apr-16 14:17 UTC
[syslinux] [PATCH 07/20] elflink: Move more code from core/ into ldlinux
From: Matt Fleming <matt.fleming at linux.intel.com> ldlinux now contains all the code necessary to load and execute modules, none is contained in the core. This change also allows us to change the spawn_load() prototype and to push the job of processing arguments to executable functions (e.g. the contents of char *argv[] as passed to a module's main function) into ldlinux/execute.c instead of doing it in spawn_load(). Moving it into ldlinux/ makes sense because the only core user of spawn_load() is load_env32() and we don't require any sort of argument processing in that path. Signed-off-by: Matt Fleming <matt.fleming at linux.intel.com> --- com32/elflink/ldlinux/Makefile | 2 +- {core/elflink => com32/elflink/ldlinux}/execute.c | 67 ++++++++++++++++++--- {core/elflink => com32/elflink/ldlinux}/kernel.c | 0 com32/include/sys/exec.h | 3 +- com32/lib/sys/module/exec.c | 47 ++++++++------- core/elflink/load_env32.c | 7 ++- 6 files changed, 92 insertions(+), 34 deletions(-) rename {core/elflink => com32/elflink/ldlinux}/execute.c (73%) rename {core/elflink => com32/elflink/ldlinux}/kernel.c (100%) diff --git a/com32/elflink/ldlinux/Makefile b/com32/elflink/ldlinux/Makefile index 6fbe1b1..09aa4af 100644 --- a/com32/elflink/ldlinux/Makefile +++ b/com32/elflink/ldlinux/Makefile @@ -19,7 +19,7 @@ CFLAGS += -I../modules -I$(topdir)/core/elflink -I$(topdir)/core/include all: ldlinux.c32 ldlinux.c32 : ldlinux.o cli.o readconfig.o refstr.o colors.o getadv.o \ - adv.o ipappend.o + adv.o ipappend.o execute.o kernel.o $(LD) $(LDFLAGS) -o $@ $^ tidy dist: diff --git a/core/elflink/execute.c b/com32/elflink/ldlinux/execute.c similarity index 73% rename from core/elflink/execute.c rename to com32/elflink/ldlinux/execute.c index 7e70323..f67d707 100644 --- a/core/elflink/execute.c +++ b/com32/elflink/ldlinux/execute.c @@ -43,13 +43,10 @@ static inline int my_isspace(char c) void execute(const char *cmdline, enum kernel_type type) { - com32sys_t ireg; const char *p, *const *pp; - char *q; const char *kernel, *args; - - /* work around for spawn_load parameter */ - char *spawn_load_param[2] = { NULL, NULL}; + com32sys_t ireg; + char *q; memset(&ireg, 0, sizeof ireg); @@ -87,18 +84,70 @@ void execute(const char *cmdline, enum kernel_type type) if (type == KT_COM32) { /* new entry for elf format c32 */ - spawn_load_param[0] = args; + char **argv; + int i, argc; + + q = args; + for (argc = 0; *q; q++) { + argc++; + + /* Find the end of this arg */ + while(*q && !my_isspace(*q)) + q++; + + /* + * Now skip all whitespace between arguments. + */ + while (*q && my_isspace(*q)) + q++; + } + + /* + * Generate a copy of argv on the stack as this is + * traditionally where process arguments go. + * + * argv[0] must be the command name, so bump argc to + * include argv[0]. + */ + argc += 1; + argv = alloca(argc * sizeof(char *)); + argv[0] = kernel; + + for (q = args, i = 1; i < argc - 1; i++) { + char *start; + int len = 0; + + start = q; + + /* Find the end of this arg */ + while(*q && !my_isspace(*q)) { + q++; + len++; + } + + argv[i] = malloc(len + 1); + strncpy(argv[i], start, len); + argv[i][len] = '\0'; + + /* + * Now skip all whitespace between arguments. + */ + while (*q && my_isspace(*q)) + q++; + } + + argv[argc] = NULL; module_load_dependencies(kernel, "modules.dep"); - spawn_load(kernel, spawn_load_param); + spawn_load(kernel, argc, argv); } else if (type <= KT_KERNEL) { /* Need add one item for kernel load, as we don't use * the assembly runkernel.inc any more */ new_linux_kernel(kernel, cmdline); } else if (type == KT_CONFIG) { /* kernel contains the config file name */ - spawn_load_param[0] = args; + char *spawn_load_param[2] = { args, NULL }; module_load_dependencies("ui.c32", "modules.dep"); - spawn_load(kernel, spawn_load_param); + spawn_load(kernel, 1, spawn_load_param); } else { /* process the image need int 22 support */ if (type == KT_LOCALBOOT) { diff --git a/core/elflink/kernel.c b/com32/elflink/ldlinux/kernel.c similarity index 100% rename from core/elflink/kernel.c rename to com32/elflink/ldlinux/kernel.c diff --git a/com32/include/sys/exec.h b/com32/include/sys/exec.h index 31b62be..656f8e2 100644 --- a/com32/include/sys/exec.h +++ b/com32/include/sys/exec.h @@ -33,6 +33,7 @@ * spawn_load - Load a library module or executes an executable one * @name the name of the library/executable to use, including the extension * (e.g. 'sort.c32') + * @argc: the number of string arguments in @argv * @argv: a NULL-terminated vector of string arguments, starting with * the program name. * @@ -40,7 +41,7 @@ * kind of module it is ( executable or library ), after which is performs the * appropriate action, either spawning or simply loading the module into memory. */ -extern int spawn_load(const char *name,const char **argv); +extern int spawn_load(const char *name, int argc, char **argv); extern int module_load_dependencies(const char*name,const char*dep_file); diff --git a/com32/lib/sys/module/exec.c b/com32/lib/sys/module/exec.c index 78df72e..1ed3263 100644 --- a/com32/lib/sys/module/exec.c +++ b/com32/lib/sys/module/exec.c @@ -220,12 +220,25 @@ int spawnl(const char *name, const char *arg, ...) struct elf_module *cur_module; -int spawn_load(const char *name,const char **argv) +/* + * Load a module and runs its start function. + * + * For library modules the start function is module->init_func and for + * executable modules its module->main_func. + * + * "name" is the name of the module to load. + * + * "argv" and "argc" are only passed to module->main_func, for library + * modules these arguments can be NULL and 0, respectively. + * + * "argv" is an array of arguments to pass to module->main_func. + * argv[0] must be a pointer to "name" and argv[argc] must be NULL. + * + * "argc" is the number of arguments in "argv". + */ +int spawn_load(const char *name, int argc, char **argv) { int res, ret_val = 0; - const char **arg; - int argc; - char **argp, **args; struct elf_module *previous; //malloc_tag_t prev_mem_tag; struct elf_module *module = module_alloc(name); @@ -238,6 +251,11 @@ int spawn_load(const char *name,const char **argv) if (module == NULL) return -1; + if (get_module_type(module) == EXEC_MODULE) { + if (!argc || !argv || strcmp(argv[0], name)) + return -1; + } + if (!strcmp(cur_module->name, module->name)) { dprintf("We is running this module %s already!", module->name); @@ -295,21 +313,6 @@ int spawn_load(const char *name,const char **argv) __syslinux_current = module; //__mem_set_tag_global((malloc_tag_t)module); - // Generate a new process copy of argv (on the stack) - argc = 0; - for (arg = argv; *arg; arg++) - argc++; - - args = alloca((argc+1) * sizeof(char *)); - - for (arg = argv, argp = args; *arg; arg++, argp++) { - size_t l = strlen(*arg)+1; - *argp = alloca(l); - memcpy(*argp, *arg, l); - } - - *args = NULL; - // Execute the program ret_val = setjmp(module->u.x.process_exit); @@ -318,7 +321,7 @@ int spawn_load(const char *name,const char **argv) else if (!module->main_func) ret_val = -1; else - exit((module->main_func)(argc, args)); /* Actually run! */ + exit((module->main_func)(argc, argv)); /* Actually run! */ // Clean up the allocation context @@ -468,13 +471,13 @@ int module_load_dependencies(const char *name,const char *dep_file) i++; /* skip a space */ if (strlen(temp_name)) { - char *argv[2] = { NULL, NULL }; + char *argv[2] = { temp_name, NULL }; int ret; ret = module_load_dependencies(temp_name, MODULES_DEP); if (!ret) { - if (spawn_load(temp_name, argv) < 0) + if (spawn_load(temp_name, 1, argv) < 0) continue; } } diff --git a/core/elflink/load_env32.c b/core/elflink/load_env32.c index 501f267..8a71634 100644 --- a/core/elflink/load_env32.c +++ b/core/elflink/load_env32.c @@ -18,6 +18,8 @@ #include "menu.h" #include "core-elf.h" +#define LDLINUX "ldlinux.c32" + typedef void (*constructor_t) (void); constructor_t __ctors_start[], __ctors_end[]; @@ -68,10 +70,13 @@ static void call_constr(void) /* note to self: do _*NOT*_ use static key word on this function */ void load_env32(com32sys_t * regs) { + char *argv[] = { LDLINUX, NULL }; + dprintf("Starting 32 bit elf module subsystem...\n"); call_constr(); init_module_subsystem(&core_module); - execute("ldlinux.c32", KT_COM32); + module_load_dependencies(LDLINUX, "modules.dep"); + spawn_load(LDLINUX, 1, argv); } -- 1.7.4.2
Matt Fleming
2011-Apr-16 14:17 UTC
[syslinux] [PATCH 08/20] com32: Put deleted object files back into the Makefile
From: Matt Fleming <matt.fleming at linux.intel.com> For some reason that I can't understand, some object files were removed from this Makefile in the following commit, |commit 0cb6490fa96f752c01bbb9add2c9ca6dbf99ece2 |Author: Feng Tang <feng.tang at intel.com> |Date: Thu Jun 3 10:48:22 2010 +0800 | | elflink: start merge with pathbased branch | | modify these files to make compile pass | | modified: com32/MCONFIG | modified: com32/Makefile | modified: com32/include/klibc/compiler.h | modified: com32/include/sys/elfcommon.h | modified: com32/lib/Makefile | modified: com32/lib/free.c | modified: com32/lib/malloc.c However, with this patch things continue to compile correctly so I'm unsure why they were ever removed. Furthermore, pieces of code in com32/ refer to symbols defined in these these object files and so they are required in order to load modules. These missing object files were discovered when loading libcom32.c32, which wouldn't load because it was complaining about unresolved symbols. The removal of core/strncasecmp.c needs some explanation. There are currently two identical copies of strncasecmp.c, one in com32/lib and one in core/, and while the core copy is part of core/libcom32.a, the copy in com32/lib isn't compiled. Now, because there are no references to strncasecmp within core/ the symbol isn't pulled in from libcom32.a and exported as a global symbol by the core. So, if ELF modules have references to strncasecmp they cannot be resolved at runtime. To fix this I've included strncasecmp.o in libcom32min.a which isolinux.elf, ldlinux.elf and pxelinux.elf link against with --whole-archive, which means that even if there are no references to strncasecmp within the core, that symbol is still exported. Signed-off-by: Matt Fleming <matt.fleming at linux.intel.com> --- com32/lib/Makefile | 15 ++++++++++++--- core/strncasecmp.c | 24 ------------------------ 2 files changed, 12 insertions(+), 27 deletions(-) delete mode 100644 core/strncasecmp.c diff --git a/com32/lib/Makefile b/com32/lib/Makefile index 7a0474b..f5c7f5b 100644 --- a/com32/lib/Makefile +++ b/com32/lib/Makefile @@ -33,7 +33,11 @@ LIBJPG_OBJS = \ LIBVESA_OBJS = \ sys/vesacon_write.o sys/vesaserial_write.o \ sys/vesa/initvesa.o sys/vesa/drawtxt.o sys/vesa/background.o \ - sys/vesa/alphatbl.o sys/vesa/screencpy.o sys/vesa/fmtpixel.o + sys/vesa/alphatbl.o sys/vesa/screencpy.o sys/vesa/fmtpixel.o \ + sys/vesa/i915resolution.o + +LIBMISC_OBJS = \ + sys/libansi.o sys/gpxe.o LIBPCI_OBJS = \ pci/cfgtype.o pci/scan.o pci/bios.o \ @@ -45,8 +49,11 @@ LIBSYSLINUX_OBJS = \ syslinux/features.o syslinux/config.o \ syslinux/ipappend.o syslinux/dsinfo.o syslinux/version.o \ syslinux/pxe_get_cached.o syslinux/pxe_get_nic.o \ + syslinux/pxe_dns.o \ syslinux/adv.o syslinux/advwrite.o syslinux/getadv.o \ - syslinux/setadv.o + syslinux/setadv.o \ + syslinux/video/fontquery.o syslinux/video/forcetext.o \ + syslinux/video/reportmode.o LIBLOAD_OBJS = \ syslinux/addlist.o syslinux/freelist.o syslinux/memmap.o \ @@ -69,7 +76,7 @@ DYNENTRY_OBJS = \ ## CORE OBJECTS, INCLUDED IN THE ROOT COM32 MODULE LIBENTRY_OBJS = \ sys/intcall.o sys/farcall.o sys/cfarcall.o sys/zeroregs.o \ - sys/argv.o \ + sys/argv.o sys/sleep.o \ sys/fileinfo.o sys/opendev.o sys/read.o sys/write.o sys/ftell.o \ sys/close.o sys/open.o sys/fileread.o sys/fileclose.o \ sys/openmem.o \ @@ -120,6 +127,7 @@ LIBOTHER_OBJS = \ strchr.o strcmp.o strcpy.o strdup.o strerror.o strlen.o \ strnlen.o \ strncat.o strncmp.o strncpy.o strndup.o \ + strncasecmp.o \ stpcpy.o stpncpy.o \ strntoimax.o strntoumax.o strrchr.o strsep.o strspn.o strstr.o \ strtoimax.o strtok.o strtol.o strtoll.o strtoul.o strtoull.o \ @@ -181,6 +189,7 @@ DYNLIBOBJS = \ $(LIBVESA_OBJS) \ $(LIBSYSLINUX_OBJS) \ $(LIBLOAD_OBJS) \ + $(LIBMISC_OBJS) \ $(DYNENTRY_OBJS) diff --git a/core/strncasecmp.c b/core/strncasecmp.c deleted file mode 100644 index 2caac0a..0000000 --- a/core/strncasecmp.c +++ /dev/null @@ -1,24 +0,0 @@ -/* - * strncasecmp.c - */ - -#include <string.h> -#include <ctype.h> - -int strncasecmp(const char *s1, const char *s2, size_t n) -{ - const unsigned char *c1 = (const unsigned char *)s1; - const unsigned char *c2 = (const unsigned char *)s2; - unsigned char ch; - int d = 0; - - while (n--) { - /* toupper() expects an unsigned char (implicitly cast to int) - as input, and returns an int, which is exactly what we want. */ - d = toupper(ch = *c1++) - toupper(*c2++); - if (d || !ch) - break; - } - - return d; -} -- 1.7.4.2
From: Matt Fleming <matt.fleming at linux.intel.com> We don't need this anymore as it includes DYNOBJS but libcom32.c32 also includes those objects and we can now dynamically load libcom32.c32 at runtime. Signed-off-by: Matt Fleming <matt.fleming at linux.intel.com> --- com32/lib/Makefile | 6 +----- 1 files changed, 1 insertions(+), 5 deletions(-) diff --git a/com32/lib/Makefile b/com32/lib/Makefile index f5c7f5b..ad861c9 100644 --- a/com32/lib/Makefile +++ b/com32/lib/Makefile @@ -204,7 +204,7 @@ AUXDIR = $(DATADIR)/syslinux INCDIR = /usr/include COM32DIR = $(AUXDIR)/com32 -all: libcom32.a libcom32min.a klibc.c32 +all: libcom32.a libcom32min.a libcom32.a : $(LIBOBJS) rm -f $@ @@ -217,10 +217,6 @@ libcom32min.a : $(MINLIBOBJS) $(AR) cq $@ $^ $(RANLIB) $@ -klibc.c32 : $(DYNLIBOBJS) - rm -f $@ - $(LD) -shared -T elf32.ld -o $@ $(DYNLIBOBJS) - tidy dist clean: rm -f sys/vesa/alphatbl.c find . \( -name \*.o -o -name \*.a -o -name .\*.d -o -name \*.tmp \) -print0 | \ -- 1.7.4.2
Matt Fleming
2011-Apr-16 14:17 UTC
[syslinux] [PATCH 10/20] cmenu: Rename menu.h to cmenu.h
From: Matt Fleming <matt.fleming at linux.intel.com> In preparation for moving com32/menu/menu.h to com32/include/ let's rename com32/cmenu/menu.h. This stops us having two header files named menu.h which would mean that we'd have to be super careful with our include paths to ensure we included the correct header. Signed-off-by: Matt Fleming <matt.fleming at linux.intel.com> --- com32/cmenu/adv_menu.tpl | 2 +- com32/cmenu/complex.c | 2 +- com32/cmenu/display.c | 2 +- com32/cmenu/libmenu/{menu.h => cmenu.h} | 0 com32/cmenu/libmenu/help.h | 2 +- com32/cmenu/libmenu/menu.c | 2 +- com32/cmenu/simple.c | 2 +- 7 files changed, 6 insertions(+), 6 deletions(-) rename com32/cmenu/libmenu/{menu.h => cmenu.h} (100%) diff --git a/com32/cmenu/adv_menu.tpl b/com32/cmenu/adv_menu.tpl index e60383f..8931709 100644 --- a/com32/cmenu/adv_menu.tpl +++ b/com32/cmenu/adv_menu.tpl @@ -34,7 +34,7 @@ modify this template to suit your needs #define NULL ((void *) 0) #endif -#include "menu.h" +#include "cmenu.h" #include "help.h" #include "passwords.h" #include "com32io.h" diff --git a/com32/cmenu/complex.c b/com32/cmenu/complex.c index b80005d..d6658fb 100644 --- a/com32/cmenu/complex.c +++ b/com32/cmenu/complex.c @@ -14,7 +14,7 @@ #define NULL ((void *) 0) #endif -#include "menu.h" +#include "cmenu.h" #include "com32io.h" #include "help.h" #include "passwords.h" diff --git a/com32/cmenu/display.c b/com32/cmenu/display.c index 3acdf6a..59612f9 100644 --- a/com32/cmenu/display.c +++ b/com32/cmenu/display.c @@ -16,7 +16,7 @@ #include "help.h" #include "com32io.h" -#include "menu.h" +#include "cmenu.h" #include "tui.h" #include <stdlib.h> #include <com32.h> diff --git a/com32/cmenu/libmenu/menu.h b/com32/cmenu/libmenu/cmenu.h similarity index 100% rename from com32/cmenu/libmenu/menu.h rename to com32/cmenu/libmenu/cmenu.h diff --git a/com32/cmenu/libmenu/help.h b/com32/cmenu/libmenu/help.h index de01b46..383cc3c 100644 --- a/com32/cmenu/libmenu/help.h +++ b/com32/cmenu/libmenu/help.h @@ -13,7 +13,7 @@ #ifndef __HELP_H_ #define __HELP_H_ -#include "menu.h" +#include "cmenu.h" #include "com32io.h" #include "tui.h" #include <string.h> diff --git a/com32/cmenu/libmenu/menu.c b/com32/cmenu/libmenu/menu.c index 19a7e59..9b1e7ad 100644 --- a/com32/cmenu/libmenu/menu.c +++ b/com32/cmenu/libmenu/menu.c @@ -10,7 +10,7 @@ * * ----------------------------------------------------------------------- */ -#include "menu.h" +#include "cmenu.h" #include "com32io.h" #include <stdlib.h> #include <console.h> diff --git a/com32/cmenu/simple.c b/com32/cmenu/simple.c index 4f602a9..ba9669f 100644 --- a/com32/cmenu/simple.c +++ b/com32/cmenu/simple.c @@ -14,7 +14,7 @@ #define NULL ((void *) 0) #endif -#include "menu.h" +#include "cmenu.h" #include "com32io.h" #include <string.h> -- 1.7.4.2
Matt Fleming
2011-Apr-16 14:17 UTC
[syslinux] [PATCH 11/20] com32: We only need one refstr.h
From: Matt Fleming <matt.fleming at linux.intel.com> Delete the duplicate refstr.h and move the remaining copy into com32/include so that it can be included by both ldlinux and the menu code. Signed-off-by: Matt Fleming <matt.fleming at linux.intel.com> --- com32/{elflink/ldlinux => include}/refstr.h | 0 com32/menu/refstr.h | 40 --------------------------- 2 files changed, 0 insertions(+), 40 deletions(-) rename com32/{elflink/ldlinux => include}/refstr.h (100%) delete mode 100644 com32/menu/refstr.h diff --git a/com32/elflink/ldlinux/refstr.h b/com32/include/refstr.h similarity index 100% rename from com32/elflink/ldlinux/refstr.h rename to com32/include/refstr.h diff --git a/com32/menu/refstr.h b/com32/menu/refstr.h deleted file mode 100644 index 7001d40..0000000 --- a/com32/menu/refstr.h +++ /dev/null @@ -1,40 +0,0 @@ -/* ----------------------------------------------------------------------- * - * - * Copyright 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., 51 Franklin St, Fifth Floor, - * Boston MA 02110-1301, USA; either version 2 of the License, or - * (at your option) any later version; incorporated herein by reference. - * - * ----------------------------------------------------------------------- */ - -/* - * refstr.h - * - * Simple reference-counted strings - */ - -#ifndef REFSTR_H -#define REFSTR_H - -#include <stddef.h> -#include <stdarg.h> - -static inline __attribute__ ((always_inline)) -const char *refstr_get(const char *r) -{ - if (r) - ((unsigned int *)r)[-1]++; - return r; -} - -void refstr_put(const char *); -char *refstr_alloc(size_t); -const char *refstrdup(const char *); -const char *refstrndup(const char *, size_t); -int rsprintf(const char **, const char *, ...); -int vrsprintf(const char **, const char *, va_list); - -#endif -- 1.7.4.2
From: Matt Fleming <matt.fleming at linux.intel.com> menu.h is required by the menu code in com32/menu and also by ldlinux. So move it to a more neutral place. Signed-off-by: Matt Fleming <matt.fleming at linux.intel.com> --- com32/{menu => include}/menu.h | 0 1 files changed, 0 insertions(+), 0 deletions(-) rename com32/{menu => include}/menu.h (100%) diff --git a/com32/menu/menu.h b/com32/include/menu.h similarity index 100% rename from com32/menu/menu.h rename to com32/include/menu.h -- 1.7.4.2
From: Matt Fleming <matt.fleming at linux.intel.com> This header file really just duplicates code that is available in other header files. It has no reason to exist. Signed-off-by: Matt Fleming <matt.fleming at linux.intel.com> --- com32/elflink/ldlinux/cli.c | 1 - com32/elflink/ldlinux/colors.c | 1 - com32/elflink/ldlinux/execute.c | 7 +------ com32/elflink/ldlinux/kernel.c | 1 - com32/elflink/ldlinux/ldlinux.c | 1 - com32/elflink/ldlinux/readconfig.c | 1 - core/elflink/core-elf.h | 29 ----------------------------- core/elflink/load_env32.c | 1 - 8 files changed, 1 insertions(+), 41 deletions(-) delete mode 100644 core/elflink/core-elf.h diff --git a/com32/elflink/ldlinux/cli.c b/com32/elflink/ldlinux/cli.c index 3026cac..4749dda 100644 --- a/com32/elflink/ldlinux/cli.c +++ b/com32/elflink/ldlinux/cli.c @@ -12,7 +12,6 @@ #include <linux/list.h> #include <sys/exec.h> #include <sys/module.h> -#include <core-elf.h> #include <dprintf.h> #include "getkey.h" diff --git a/com32/elflink/ldlinux/colors.c b/com32/elflink/ldlinux/colors.c index c1ef390..68732bd 100644 --- a/com32/elflink/ldlinux/colors.c +++ b/com32/elflink/ldlinux/colors.c @@ -14,7 +14,6 @@ #include <string.h> #include <stdio.h> #include <colortbl.h> -#include <core-elf.h> #include "menu.h" /* diff --git a/com32/elflink/ldlinux/execute.c b/com32/elflink/ldlinux/execute.c index f67d707..a00a5b1 100644 --- a/com32/elflink/ldlinux/execute.c +++ b/com32/elflink/ldlinux/execute.c @@ -18,7 +18,7 @@ #include <com32.h> #include <sys/exec.h> #include "core.h" -#include "core-elf.h" +#include "menu.h" /* Must match enum kernel_type */ const char *const kernel_types[] = { @@ -36,11 +36,6 @@ const char *const kernel_types[] = { NULL }; -static inline int my_isspace(char c) -{ - return (unsigned char)c <= ' '; -} - void execute(const char *cmdline, enum kernel_type type) { const char *p, *const *pp; diff --git a/com32/elflink/ldlinux/kernel.c b/com32/elflink/ldlinux/kernel.c index 3ce2358..2438d11 100644 --- a/com32/elflink/ldlinux/kernel.c +++ b/com32/elflink/ldlinux/kernel.c @@ -8,7 +8,6 @@ #include <syslinux/linux.h> #include <syslinux/pxe.h> #include "core.h" -#include "core-elf.h" const char *globaldefault = NULL; const char *append = NULL; diff --git a/com32/elflink/ldlinux/ldlinux.c b/com32/elflink/ldlinux/ldlinux.c index 5f4b058..9ba1aeb 100644 --- a/com32/elflink/ldlinux/ldlinux.c +++ b/com32/elflink/ldlinux/ldlinux.c @@ -2,7 +2,6 @@ #include <sys/times.h> #include <stdbool.h> #include <core.h> -#include <core-elf.h> #include "cli.h" #include "console.h" #include "com32.h" diff --git a/com32/elflink/ldlinux/readconfig.c b/com32/elflink/ldlinux/readconfig.c index d78c015..441651e 100644 --- a/com32/elflink/ldlinux/readconfig.c +++ b/com32/elflink/ldlinux/readconfig.c @@ -22,7 +22,6 @@ #include <com32.h> #include <syslinux/adv.h> #include <syslinux/config.h> -#include <core-elf.h> #include <dprintf.h> #include "menu.h" diff --git a/core/elflink/core-elf.h b/core/elflink/core-elf.h deleted file mode 100644 index dcca900..0000000 --- a/core/elflink/core-elf.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef _CORE_ELF_H -#define _coRE_ELF_H - -enum kernel_type { - /* Meta-types for internal use */ - KT_NONE, - KT_LOCALBOOT, - - /* The ones we can pass off to SYSLINUX, in order */ - KT_KERNEL, /* Undefined type */ - KT_LINUX, /* Linux kernel */ - KT_BOOT, /* Bootstrap program */ - KT_BSS, /* Boot sector with patch */ - KT_PXE, /* PXE NBP */ - KT_FDIMAGE, /* Floppy disk image */ - KT_COMBOOT, /* COMBOOT image */ - KT_COM32, /* COM32 image */ - KT_CONFIG, /* Configuration file */ -}; - -extern const char *append; -extern char *ippappend; -extern const char *globaldefault; -extern short onerrorlen; - -extern int new_linux_kernel(char *okernel, char *ocmdline); - -extern void start_ui(char *config_file); -#endif diff --git a/core/elflink/load_env32.c b/core/elflink/load_env32.c index 8a71634..16b21a6 100644 --- a/core/elflink/load_env32.c +++ b/core/elflink/load_env32.c @@ -16,7 +16,6 @@ #include <sys/module.h> #include "common.h" #include "menu.h" -#include "core-elf.h" #define LDLINUX "ldlinux.c32" -- 1.7.4.2
Matt Fleming
2011-Apr-16 14:17 UTC
[syslinux] [PATCH 14/20] elflink: Make ELF the default object format
From: Matt Fleming <matt.fleming at linux.intel.com> com32/elflink/modules was originally created to house ELF modules and keep them separate from the COM32 modules as the elflink branch was being developed. However, this has inadvertently created a maintenance nightmare because code was copied from elsewhere in the tree into com32/elflink/modules, resulting in duplication. Bug fixes have been going into the original code but have not been merged onto the elflink branch, leaving the duplicate code in com32/elflink/modules buggy. So let's delete this directory. There really is no reason to keep ELF and COM32 modules separate because there's no reason to need both COM32 and ELF modules to coexist. ELF is a far superior object file format and all modules are not emitted as ELF objects. Now that we're outputting ELF modules we can use dynamic memory instead of the cs_bounce bounce buffer. This commit requires a certain amount of shuffling for some files. quicksort.c isn't a module and belongs as part of the util library. cli.h belongs in com32/include so that other modules can make use of the cli code in ldlinux.c32. All libraries are now ELF shared libraries which are only loaded to fixup unresolved symbols for executable modules and renamed from *.a to *.c32. This reduces the runtime memory footprint because libraries are only loaded when needed and because every executable no longer gets its own copy of code/data (as it would if linking with a static library). Also, remove MINLIBOBJS from libcom32.c32 because it is already part of libcom32min.a and we don't want to have any duplicate symbols between the core (which links with libcom32min.a) and libcom32.c32. Welcome to the New World Order of ELF modules! Signed-off-by: Matt Fleming <matt.fleming at linux.intel.com> --- com32/Makefile | 2 +- com32/cmenu/Makefile | 16 +- com32/elflink/ldlinux/Makefile | 2 +- com32/elflink/modules/Makefile | 103 -- com32/elflink/modules/README | 1 - com32/elflink/modules/ansiraw.c | 115 --- com32/elflink/modules/background.c | 57 -- com32/elflink/modules/base64.h | 51 - com32/elflink/modules/crypt-md5.c | 173 ---- com32/elflink/modules/drain.c | 40 - com32/elflink/modules/get_key.c | 187 ---- com32/elflink/modules/md5.c | 288 ------ com32/elflink/modules/md5.h | 46 - com32/elflink/modules/meminfo.c | 130 --- com32/elflink/modules/menu.c | 18 - com32/elflink/modules/menu.h | 218 ----- com32/elflink/modules/menumain.c | 977 -------------------- com32/elflink/modules/modules.dep | 19 - com32/elflink/modules/mytest.c | 27 - com32/elflink/modules/passwd.c | 112 --- com32/elflink/modules/printmsg.c | 116 --- com32/elflink/modules/refstr.h | 40 - com32/elflink/modules/sha1.h | 18 - com32/elflink/modules/sha1hash.c | 347 ------- com32/elflink/modules/sha256crypt.c | 559 ----------- com32/elflink/modules/sha512crypt.c | 606 ------------ com32/elflink/modules/test.c | 109 --- com32/elflink/modules/unbase64.c | 91 -- com32/elflink/modules/vesainfo.c | 90 -- com32/gfxboot/Makefile | 6 +- com32/gpllib/Makefile | 14 +- com32/hdt/Makefile | 4 +- com32/{elflink/modules => include}/cli.h | 0 com32/{elflink/modules => include}/sort.h | 0 com32/lib/Makefile | 10 +- com32/libutil/Makefile | 13 +- .../modules/sort.c => libutil/quicksort.c} | 21 - com32/lua/src/Makefile | 12 +- com32/mboot/Makefile | 4 +- com32/menu/Makefile | 2 +- com32/modules/Makefile | 15 +- com32/{elflink => }/modules/hello.c | 0 com32/modules/meminfo.c | 18 +- com32/modules/vesainfo.c | 44 +- com32/samples/Makefile | 2 +- com32/sysdump/Makefile | 6 +- elf_gen_dep.sh | 2 +- mk/com32.mk | 2 +- mk/elf.mk | 18 +- mk/rosh.mk | 2 +- 50 files changed, 102 insertions(+), 4651 deletions(-) delete mode 100644 com32/elflink/modules/Makefile delete mode 100644 com32/elflink/modules/README delete mode 100644 com32/elflink/modules/ansiraw.c delete mode 100644 com32/elflink/modules/background.c delete mode 100644 com32/elflink/modules/base64.h delete mode 100644 com32/elflink/modules/crypt-md5.c delete mode 100644 com32/elflink/modules/drain.c delete mode 100644 com32/elflink/modules/get_key.c delete mode 100644 com32/elflink/modules/md5.c delete mode 100644 com32/elflink/modules/md5.h delete mode 100644 com32/elflink/modules/meminfo.c delete mode 100644 com32/elflink/modules/menu.c delete mode 100644 com32/elflink/modules/menu.h delete mode 100644 com32/elflink/modules/menumain.c delete mode 100644 com32/elflink/modules/modules.dep delete mode 100644 com32/elflink/modules/mytest.c delete mode 100644 com32/elflink/modules/passwd.c delete mode 100644 com32/elflink/modules/printmsg.c delete mode 100644 com32/elflink/modules/refstr.h delete mode 100644 com32/elflink/modules/sha1.h delete mode 100644 com32/elflink/modules/sha1hash.c delete mode 100644 com32/elflink/modules/sha256crypt.c delete mode 100644 com32/elflink/modules/sha512crypt.c delete mode 100644 com32/elflink/modules/test.c delete mode 100644 com32/elflink/modules/unbase64.c delete mode 100644 com32/elflink/modules/vesainfo.c rename com32/{elflink/modules => include}/cli.h (100%) rename com32/{elflink/modules => include}/sort.h (100%) rename com32/{elflink/modules/sort.c => libutil/quicksort.c} (80%) rename com32/{elflink => }/modules/hello.c (100%) diff --git a/com32/Makefile b/com32/Makefile index bc13cf6..7506521 100644 --- a/com32/Makefile +++ b/com32/Makefile @@ -1,4 +1,4 @@ -SUBDIRS = tools lib gpllib libutil modules mboot menu samples elflink elflink/modules rosh cmenu \ +SUBDIRS = tools lib gpllib libutil modules mboot menu samples elflink rosh cmenu \ hdt gfxboot sysdump lua/src elflink/ldlinux all tidy dist clean spotless install: set -e; for d in $(SUBDIRS); do $(MAKE) -C $$d $@; done diff --git a/com32/cmenu/Makefile b/com32/cmenu/Makefile index 446bbcd..00825b4 100644 --- a/com32/cmenu/Makefile +++ b/com32/cmenu/Makefile @@ -18,11 +18,11 @@ NOGPL := 1 # This must be defined before com32.mk is included -LIBS = libmenu/libmenu.a +LIBS = libmenu/libmenu.c32 topdir = ../.. MAKEDIR = $(topdir)/mk -include $(MAKEDIR)/com32.mk +include $(MAKEDIR)/elf.mk CFLAGS += -I./libmenu @@ -32,7 +32,7 @@ LIBMENU = libmenu/syslnx.o libmenu/com32io.o libmenu/tui.o \ CMENUS = $(patsubst %.c,%.c32,$(wildcard *.c)) IMENUS = $(patsubst %.menu,%.c32,$(wildcard *.menu)) -MENUS = $(CMENUS) $(IMENUS) +MENUS = $(CMENUS) $(IMENUS) $(LIBS) .SUFFIXES: .S .c .o .elf .c32 .menu @@ -42,16 +42,14 @@ MENUS = $(CMENUS) $(IMENUS) all: menus -libmenu/libmenu.a: $(LIBMENU) - -rm -f $@ - $(AR) cq $@ $^ - $(RANLIB) $@ +libmenu/libmenu.c32: $(LIBMENU) + $(LD) -shared $(LDFLAGS) -o $@ $^ tidy dist: - rm -f *.o *.lo *.a *.lst *.elf .*.d */.*.d + rm -f *.o *.lo *.c32 *.lst *.elf .*.d */.*.d libclean: - rm -f libmenu/*.o libmenu/*.a + rm -f libmenu/*.o libmenu/*.c32 clean: tidy menuclean libclean rm -f *.lss *.c32 *.com diff --git a/com32/elflink/ldlinux/Makefile b/com32/elflink/ldlinux/Makefile index 09aa4af..8fe4d71 100644 --- a/com32/elflink/ldlinux/Makefile +++ b/com32/elflink/ldlinux/Makefile @@ -14,7 +14,7 @@ topdir = ../../.. MAKEDIR = $(topdir)/mk include $(MAKEDIR)/elf.mk -CFLAGS += -I../modules -I$(topdir)/core/elflink -I$(topdir)/core/include +CFLAGS += -I$(topdir)/core/elflink -I$(topdir)/core/include all: ldlinux.c32 diff --git a/com32/elflink/modules/Makefile b/com32/elflink/modules/Makefile deleted file mode 100644 index 8a274ae..0000000 --- a/com32/elflink/modules/Makefile +++ /dev/null @@ -1,103 +0,0 @@ -## ----------------------------------------------------------------------- -## -## 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. -## -## ----------------------------------------------------------------------- - -topdir = ../../.. -MAKEDIR = $(topdir)/mk -include $(MAKEDIR)/elf.mk - -CFLAGS += -I$(topdir)/core/elflink - -MODULES = hello.c32 sort.c32 mytest.c32 menumain.c32 printmsg.c32 background.c32 passwd.c32 sha1hash.c32 \ - unbase64.c32 sha512crypt.c32 md5.c32 crypt-md5.c32 sha256crypt.c32 get_key.c32 ansiraw.c32 test.c32 \ - meminfo.c32 menu.c32 drain.c32 vesainfo.c32 - -TESTFILES - -all: $(MODULES) $(TESTFILES) - -test.c32 : test.o - $(LD) $(LDFLAGS) -o $@ $^ - -menu.c32 : menu.o - $(LD) $(LDFLAGS) -o $@ $^ - -hello.c32 : hello.o - $(LD) $(LDFLAGS) -o $@ $^ - -sort.c32 : sort.o - $(LD) $(LDFLAGS) -o $@ $^ - -mytest.c32 : mytest.o - $(LD) $(LDFLAGS) -o $@ $^ - -menumain.c32 : menumain.o - $(LD) $(LDFLAGS) -o $@ $^ - -printmsg.c32 : printmsg.o - $(LD) $(LDFLAGS) -o $@ $^ - -background.c32 : background.o - $(LD) $(LDFLAGS) -o $@ $^ - -drain.c32 : drain.o - $(LD) $(LDFLAGS) -o $@ $^ - -passwd.c32 : passwd.o - $(LD) $(LDFLAGS) -o $@ $^ - -sha1hash.c32 : sha1hash.o - $(LD) $(LDFLAGS) -o $@ $^ - -unbase64.c32 : unbase64.o - $(LD) $(LDFLAGS) -o $@ $^ - -sha512crypt.c32 : sha512crypt.o - $(LD) $(LDFLAGS) -o $@ $^ - -sha256crypt.c32 : sha256crypt.o - $(LD) $(LDFLAGS) -o $@ $^ - -md5.c32 : md5.o - $(LD) $(LDFLAGS) -o $@ $^ - -crypt-md5.c32 : crypt-md5.o - $(LD) $(LDFLAGS) -o $@ $^ - -get_key.c32 : get_key.o - $(LD) $(LDFLAGS) -o $@ $^ - -ansiraw.c32 : ansiraw.o - $(LD) $(LDFLAGS) -o $@ $^ - -meminfo.c32 : meminfo.o - $(LD) $(LDFLAGS) -o $@ $^ - -pcitest.c32 : pcitest.o - $(LD) $(LDFLAGS) -o $@ $^ - -vesainfo.c32 : vesainfo.o - $(LD) $(LDFLAGS) -o $@ $^ - -tidy dist: - rm -f *.o *.lo *.a *.lst .*.d - -clean: tidy - rm -f *.lss *.lnx *.com *.c32 - -spotless: clean - rm -f *~ \#* - -install: all - mkdir -m 755 -p $(INSTALLROOT)$(AUXDIR) - install -m 644 $(MODULES) $(INSTALLROOT)$(AUXDIR) - --include .*.d diff --git a/com32/elflink/modules/README b/com32/elflink/modules/README deleted file mode 100644 index 090313a..0000000 --- a/com32/elflink/modules/README +++ /dev/null @@ -1 +0,0 @@ -This folder contains dynamically loadable ELF modules for SYSLINUX. \ No newline at end of file diff --git a/com32/elflink/modules/ansiraw.c b/com32/elflink/modules/ansiraw.c deleted file mode 100644 index aca90ce..0000000 --- a/com32/elflink/modules/ansiraw.c +++ /dev/null @@ -1,115 +0,0 @@ -/* ----------------------------------------------------------------------- * - * - * Copyright 2004-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. - * - * ----------------------------------------------------------------------- */ - -/* - * ansiraw.c - * - * Configures the console for ANSI output in raw mode; versions - * for COM32 and Linux support. - */ - -#ifdef __COM32__ - -#include <stdio.h> -#include <unistd.h> -#include <console.h> -#include <sys/module.h> - -static int ansiraw_init(void) -{ - return 0; // Nothing to do; return success -} - -void console_ansi_raw(void) -{ - openconsole(&dev_rawcon_r, &dev_ansiserial_w); -} - -static void ansiraw_exit(void) -{ - // Nothing to do -} - -// Define entry and exit points. -MODULE_INIT(ansiraw_init); -MODULE_EXIT(ansiraw_exit); - -#else - -#include <stdio.h> -#include <termios.h> -#include <sys/module.h> - -static int ansiraw_init(void) -{ - return 0; // Nothing to do; return success -} - -static struct termios original_termios_settings; - -static void __attribute__ ((constructor)) console_init(void) -{ - tcgetattr(0, &original_termios_settings); -} - -static void __attribute__ ((destructor)) console_cleanup(void) -{ - tcsetattr(0, TCSANOW, &original_termios_settings); -} - -void console_ansi_raw(void) -{ - struct termios tio; - - /* Disable stdio buffering */ - setbuf(stdin, NULL); - setbuf(stdout, NULL); - setbuf(stderr, NULL); - - /* Set the termios flag so we behave the same as libcom32 */ - tcgetattr(0, &tio); - tio.c_iflag &= ~ICRNL; - tio.c_iflag |= IGNCR; - tio.c_lflag &= ~(ISIG | ICANON | ECHO); - if (!tio.c_oflag & OPOST) - tio.c_oflag = 0; - tio.c_oflag |= OPOST | ONLCR; - tio.c_cc[VMIN] = 0; - tio.c_cc[VTIME] = 1; /* Don't 100% busy-wait in Linux */ - tcsetattr(0, TCSAFLUSH, &tio); -} - -static void ansiraw_exit(void) -{ - // Nothing to do -} - -// Define entry and exit points. -MODULE_INIT(ansiraw_init); -MODULE_EXIT(ansiraw_exit); - -#endif diff --git a/com32/elflink/modules/background.c b/com32/elflink/modules/background.c deleted file mode 100644 index 467f6fd..0000000 --- a/com32/elflink/modules/background.c +++ /dev/null @@ -1,57 +0,0 @@ -/* ----------------------------------------------------------------------- * - * - * Copyright 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., 51 Franklin St, Fifth Floor, - * Boston MA 02110-1301, USA; either version 2 of the License, or - * (at your option) any later version; incorporated herein by reference. - * - * ----------------------------------------------------------------------- */ - -#include <consoles.h> -#include <string.h> -#include <core-elf.h> -#include <syslinux/vesacon.h> -#include <sys/module.h> -#include "menu.h" - -static int background_init(void) -{ - return 0; // Nothing to do; return success -} - -const char *current_background = NULL; - -int draw_background(const char *what) -{ -#if 0 - if (!what) - return vesacon_default_background(); - else if (what[0] == '#') - return vesacon_set_background(parse_argb((char **)&what)); - else - return vesacon_load_background(what); -#endif - - return 0; -} - -void set_background(const char *new_background) -{ - if (!current_background || !new_background || - strcmp(current_background, new_background)) { - draw_background(new_background); - current_background = new_background; - } -} - -static void background_exit(void) -{ - // Nothing to do -} - -// Define entry and exit points. -MODULE_INIT(background_init); -MODULE_EXIT(background_exit); diff --git a/com32/elflink/modules/base64.h b/com32/elflink/modules/base64.h deleted file mode 100644 index b71855b..0000000 --- a/com32/elflink/modules/base64.h +++ /dev/null @@ -1,51 +0,0 @@ -/* ----------------------------------------------------------------------- * - * - * Copyright 2005-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. - * - * ----------------------------------------------------------------------- */ - -/* - * base64.h - * - * Simple routines for handing base64 text - */ - -#ifndef LIBUTIL_BASE64_H -#define LIBUTIL_BASE64_H - -#include <stddef.h> - -#define BASE64_PAD 0x10000 - -/* There is plenty of disagreement w.r.t. the last few characters... */ -#define BASE64_MIME ('+' + ('/' << 8)) -#define BASE64_SAFE ('-' + ('_' << 8)) -#define BASE64_CRYPT ('.' + ('/' << 8)) -#define BASE64_URL ('*' + ('-' << 8)) /* Haven't seen myself */ -#define BASE64_REGEX ('|' + ('-' << 8)) /* Ditto... */ - -size_t genbase64(char *output, const void *digest, size_t size, int flags); -size_t unbase64(unsigned char *, size_t, const char *); - -#endif diff --git a/com32/elflink/modules/crypt-md5.c b/com32/elflink/modules/crypt-md5.c deleted file mode 100644 index 08e3639..0000000 --- a/com32/elflink/modules/crypt-md5.c +++ /dev/null @@ -1,173 +0,0 @@ -/*- - * Copyright (c) 2003 Poul-Henning Kamp - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include <inttypes.h> -#include <md5.h> -#include <string.h> -#include <sys/module.h> - -static int crypt_md5_init(void) -{ - return 0; // Nothing to do; return success -} - -/* - * UNIX password - */ - -static char *_crypt_to64(char *s, uint32_t v, int n) -{ - static const char itoa64[64] = "./0123456789" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; - - while (--n >= 0) { - *s++ = itoa64[v & 0x3f]; - v >>= 6; - } - return s; -} - -char *crypt_md5(const char *pw, const char *salt) -{ - MD5_CTX ctx, ctx1; - unsigned long l; - int sl, pl; - uint32_t i; - uint8_t final[MD5_SIZE]; - const char *sp; - static char passwd[120]; /* Output buffer */ - static const char magic[] = "$1$"; - char *p; - const int magic_len = sizeof magic - 1; - int pwlen = strlen(pw); - - /* Refine the Salt first */ - sp = salt; - - /* If it starts with the magic string, then skip that */ - if (!strncmp(sp, magic, magic_len)) - sp += magic_len; - - /* Compute the salt length: - it stops at the first '$', max 8 chars */ - for (sl = 0; sl < 8 && sp[sl] && sp[sl] != '$'; sl++) ; - - MD5Init(&ctx); - - /* The password first, since that is what is most unknown */ - MD5Update(&ctx, pw, pwlen); - - /* Then our magic string */ - MD5Update(&ctx, magic, magic_len); - - /* Then the raw salt */ - MD5Update(&ctx, sp, sl); - - /* Then just as many characters of the MD5(pw,salt,pw) */ - MD5Init(&ctx1); - MD5Update(&ctx1, pw, pwlen); - MD5Update(&ctx1, sp, sl); - MD5Update(&ctx1, pw, pwlen); - MD5Final(final, &ctx1); - for (pl = pwlen; pl > 0; pl -= MD5_SIZE) - MD5Update(&ctx, final, pl > MD5_SIZE ? MD5_SIZE : pl); - - /* Don't leave anything around in vm they could use. */ - memset(final, 0, sizeof final); - - /* Then something really weird... */ - for (i = pwlen; i; i >>= 1) - if (i & 1) - MD5Update(&ctx, final, 1); - else - MD5Update(&ctx, pw, 1); - - /* Now make the output string */ - p = passwd; - - memcpy(p, magic, magic_len); - p += magic_len; - - memcpy(p, sp, sl); - p += sl; - - *p++ = '$'; - - MD5Final(final, &ctx); - - /* - * and now, just to make sure things don't run too fast - * On a 60 Mhz Pentium this takes 34 msec, so you would - * need 30 seconds to build a 1000 entry dictionary... - */ - for (i = 0; i < 1000; i++) { - MD5Init(&ctx1); - if (i & 1) - MD5Update(&ctx1, pw, pwlen); - else - MD5Update(&ctx1, final, MD5_SIZE); - - if (i % 3) - MD5Update(&ctx1, sp, sl); - - if (i % 7) - MD5Update(&ctx1, pw, pwlen); - - if (i & 1) - MD5Update(&ctx1, final, MD5_SIZE); - else - MD5Update(&ctx1, pw, pwlen); - MD5Final(final, &ctx1); - } - - l = (final[0] << 16) | (final[6] << 8) | final[12]; - p = _crypt_to64(p, l, 4); - l = (final[1] << 16) | (final[7] << 8) | final[13]; - p = _crypt_to64(p, l, 4); - l = (final[2] << 16) | (final[8] << 8) | final[14]; - p = _crypt_to64(p, l, 4); - l = (final[3] << 16) | (final[9] << 8) | final[15]; - p = _crypt_to64(p, l, 4); - l = (final[4] << 16) | (final[10] << 8) | final[5]; - p = _crypt_to64(p, l, 4); - l = final[11]; - p = _crypt_to64(p, l, 2); - *p = '\0'; - - /* Don't leave anything around in vm they could use. */ - memset(final, 0, sizeof final); - - return passwd; -} - -static void crypt_md5_exit(void) -{ - // Nothing to do -} - -// Define entry and exit points. -MODULE_INIT(crypt_md5_init); -MODULE_EXIT(crypt_md5_exit); diff --git a/com32/elflink/modules/drain.c b/com32/elflink/modules/drain.c deleted file mode 100644 index 032003c..0000000 --- a/com32/elflink/modules/drain.c +++ /dev/null @@ -1,40 +0,0 @@ -#include <stdio.h> -#include <unistd.h> -#include <errno.h> -#include <string.h> -#include <sys/cpu.h> -#include <sys/module.h> - -static int drain_init(void) -{ - return 0; // Nothing to do; return success -} - -void drain_keyboard(void) -{ - /* Prevent "ghost typing" and keyboard buffer snooping */ - volatile char junk; - int rv; - - do { - rv = read(0, (char *)&junk, 1); - } while (rv > 0); - - junk = 0; - - cli(); - *(volatile uint8_t *)0x419 = 0; /* Alt-XXX keyboard area */ - *(volatile uint16_t *)0x41a = 0x1e; /* Keyboard buffer empty */ - *(volatile uint16_t *)0x41c = 0x1e; - memset((void *)0x41e, 0, 32); /* Clear the actual keyboard buffer */ - sti(); -} - -static void drain_exit(void) -{ - // Nothing to do -} - -// Define entry and exit points. -MODULE_INIT(drain_init); -MODULE_EXIT(drain_exit); diff --git a/com32/elflink/modules/get_key.c b/com32/elflink/modules/get_key.c deleted file mode 100644 index 5749b05..0000000 --- a/com32/elflink/modules/get_key.c +++ /dev/null @@ -1,187 +0,0 @@ -/* ----------------------------------------------------------------------- * - * - * Copyright 2004-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. - * - * ----------------------------------------------------------------------- */ - -/* - * get_key.c - * - * Get a single key, and try to pick apart function key codes. - * This doesn't decode anywhere close to all possiblities, but - * hopefully is enough to be useful. - */ - -#include <stdio.h> -#include <string.h> -#include <errno.h> -#include <unistd.h> -#include <time.h> -#include <sys/times.h> -#include <getkey.h> -#include <libutil.h> -#include <sys/module.h> - -static int getkey_init(void) -{ - return 0; // Nothing to do; return success -} - -struct keycode { - int code; - int seqlen; - const unsigned char *seq; -}; - -#define MAXLEN 8 -#define CODE(x,y) { x, (sizeof y)-1, y } - -static const struct keycode keycodes[] = { - /* First, the BIOS combined codes */ - CODE(KEY_F1, "\0\x3B"), - CODE(KEY_F2, "\0\x3C"), - CODE(KEY_F3, "\0\x3D"), - CODE(KEY_F4, "\0\x3E"), - CODE(KEY_F5, "\0\x3F"), - CODE(KEY_F6, "\0\x40"), - CODE(KEY_F7, "\0\x41"), - CODE(KEY_F8, "\0\x42"), - CODE(KEY_F9, "\0\x43"), - CODE(KEY_F10, "\0\x44"), - CODE(KEY_F11, "\0\x85"), - CODE(KEY_F12, "\0\x86"), - - CODE(KEY_UP, "\0\x48"), - CODE(KEY_DOWN, "\0\x50"), - CODE(KEY_LEFT, "\0\x4B"), - CODE(KEY_RIGHT, "\0\x4D"), - CODE(KEY_PGUP, "\0\x49"), - CODE(KEY_PGDN, "\0\x51"), - CODE(KEY_HOME, "\0\x47"), - CODE(KEY_END, "\0\x4F"), - CODE(KEY_INSERT, "\0\x52"), - CODE(KEY_DELETE, "\0\x53"), - - /* Now, VT/xterm/Linux codes */ - CODE(KEY_F1, "\033[[A"), - CODE(KEY_F1, "\033OP"), - CODE(KEY_F2, "\033[[B"), - CODE(KEY_F2, "\033OQ"), - CODE(KEY_F3, "\033[[C"), - CODE(KEY_F3, "\033OR"), - CODE(KEY_F4, "\033[[D"), - CODE(KEY_F4, "\033OS"), - CODE(KEY_F5, "\033[[E"), - CODE(KEY_F5, "\033[15~"), - CODE(KEY_F6, "\033[17~"), - CODE(KEY_F7, "\033[18~"), - CODE(KEY_F8, "\033[19~"), - CODE(KEY_F9, "\033[20~"), - CODE(KEY_F10, "\033[21~"), - CODE(KEY_F11, "\033[23~"), - CODE(KEY_F12, "\033[24~"), - - CODE(KEY_UP, "\033[A"), - CODE(KEY_DOWN, "\033[B"), - CODE(KEY_LEFT, "\033[D"), - CODE(KEY_RIGHT, "\033[C"), - CODE(KEY_PGUP, "\033[5~"), - CODE(KEY_PGUP, "\033[V"), - CODE(KEY_PGDN, "\033[6~"), - CODE(KEY_PGDN, "\033[U"), - CODE(KEY_HOME, "\033[1~"), - CODE(KEY_HOME, "\033[H"), - CODE(KEY_END, "\033[4~"), - CODE(KEY_END, "\033[F"), - CODE(KEY_END, "\033OF"), - CODE(KEY_INSERT, "\033[2~"), - CODE(KEY_INSERT, "\033[@"), - CODE(KEY_DELETE, "\033[3~"), -}; - -#define NCODES ((int)(sizeof keycodes/sizeof(struct keycode))) - -#define KEY_TIMEOUT ((CLK_TCK+9)/10) - -int get_key(FILE * f, clock_t timeout) -{ - unsigned char buffer[MAXLEN]; - int nc, i, rv; - const struct keycode *kc; - int another; - unsigned char ch; - clock_t start; - - /* We typically start in the middle of a clock tick */ - if (timeout) - timeout++; - - nc = 0; - start = times(NULL); - do { - rv = read(fileno(f), &ch, 1); - if (rv == 0 || (rv == -1 && errno == EAGAIN)) { - clock_t lateness = times(NULL) - start; - if (nc && lateness > 1 + KEY_TIMEOUT) { - if (nc == 1) - return buffer[0]; /* timeout in sequence */ - else if (timeout && lateness > timeout) - return KEY_NONE; - } else if (!nc && timeout && lateness > timeout) - return KEY_NONE; /* timeout before sequence */ - - do_idle(); - - another = 1; - continue; - } - - start = times(NULL); - - buffer[nc++] = ch; - - another = 0; - for (i = 0, kc = keycodes; i < NCODES; i++, kc++) { - if (nc == kc->seqlen && !memcmp(buffer, kc->seq, nc)) - return kc->code; - else if (nc < kc->seqlen && !memcmp(buffer, kc->seq, nc)) { - another = 1; - break; - } - } - } while (another); - - /* We got an unrecognized sequence; return the first character */ - /* We really should remember this and return subsequent characters later */ - return buffer[0]; -} - -static void getkey_exit(void) -{ - // Nothing to do -} - -// Define entry and exit points. -MODULE_INIT(getkey_init); -MODULE_EXIT(getkey_exit); diff --git a/com32/elflink/modules/md5.c b/com32/elflink/modules/md5.c deleted file mode 100644 index c39bd9b..0000000 --- a/com32/elflink/modules/md5.c +++ /dev/null @@ -1,288 +0,0 @@ -/* - * MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm - * - * Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All - * rights reserved. - * - * License to copy and use this software is granted provided that it - * is identified as the "RSA Data Security, Inc. MD5 Message-Digest - * Algorithm" in all material mentioning or referencing this software - * or this function. - * - * License is also granted to make and use derivative works provided - * that such works are identified as "derived from the RSA Data - * Security, Inc. MD5 Message-Digest Algorithm" in all material - * mentioning or referencing the derived work. - * - * RSA Data Security, Inc. makes no representations concerning either - * the merchantability of this software or the suitability of this - * software for any particular purpose. It is provided "as is" - * without express or implied warranty of any kind. - * - * These notices must be retained in any copies of any part of this - * documentation and/or software. - * - * This code is the same as the code published by RSA Inc. It has been - * edited for clarity and style only. - */ - -#include <string.h> -#include <endian.h> -#include <md5.h> -#include <sys/module.h> - -static int md5_init(void) -{ - return 0; // Nothing to do; return success -} - -static void MD5Transform(uint32_t[4], const unsigned char[64]); - -#define Encode memcpy -#define Decode memcpy - -static unsigned char PADDING[64] = { - 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -}; - -/* F, G, H and I are basic MD5 functions. */ -#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) -#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) -#define H(x, y, z) ((x) ^ (y) ^ (z)) -#define I(x, y, z) ((y) ^ ((x) | (~z))) - -/* ROTATE_LEFT rotates x left n bits. */ -#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) - -/* - * FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. - * Rotation is separate from addition to prevent recomputation. - */ -#define FF(a, b, c, d, x, s, ac) { \ - (a) += F ((b), (c), (d)) + (x) + (uint32_t)(ac); \ - (a) = ROTATE_LEFT ((a), (s)); \ - (a) += (b); \ - } -#define GG(a, b, c, d, x, s, ac) { \ - (a) += G ((b), (c), (d)) + (x) + (uint32_t)(ac); \ - (a) = ROTATE_LEFT ((a), (s)); \ - (a) += (b); \ - } -#define HH(a, b, c, d, x, s, ac) { \ - (a) += H ((b), (c), (d)) + (x) + (uint32_t)(ac); \ - (a) = ROTATE_LEFT ((a), (s)); \ - (a) += (b); \ - } -#define II(a, b, c, d, x, s, ac) { \ - (a) += I ((b), (c), (d)) + (x) + (uint32_t)(ac); \ - (a) = ROTATE_LEFT ((a), (s)); \ - (a) += (b); \ - } - -/* MD5 initialization. Begins an MD5 operation, writing a new context. */ - -void MD5Init(MD5_CTX * context) -{ - context->count[0] = context->count[1] = 0; - - /* Load magic initialization constants. */ - context->state[0] = 0x67452301; - context->state[1] = 0xefcdab89; - context->state[2] = 0x98badcfe; - context->state[3] = 0x10325476; -} - -/* - * MD5 block update operation. Continues an MD5 message-digest - * operation, processing another message block, and updating the - * context. - */ - -void MD5Update(MD5_CTX * context, const void *in, size_t inputLen) -{ - unsigned int i, idx, partLen; - const unsigned char *input = in; - - /* Compute number of bytes mod 64 */ - idx = (unsigned int)((context->count[0] >> 3) & 0x3F); - - /* Update number of bits */ - if ((context->count[0] += ((uint32_t) inputLen << 3)) - < ((uint32_t) inputLen << 3)) - context->count[1]++; - context->count[1] += ((uint32_t) inputLen >> 29); - - partLen = 64 - idx; - - /* Transform as many times as possible. */ - if (inputLen >= partLen) { - memcpy((void *)&context->buffer[idx], (const void *)input, partLen); - MD5Transform(context->state, context->buffer); - - for (i = partLen; i + 63 < inputLen; i += 64) - MD5Transform(context->state, &input[i]); - - idx = 0; - } else - i = 0; - - /* Buffer remaining input */ - memcpy((void *)&context->buffer[idx], (const void *)&input[i], - inputLen - i); -} - -/* - * MD5 padding. Adds padding followed by original length. - */ - -static void MD5Pad(MD5_CTX * context) -{ - unsigned char bits[8]; - unsigned int idx, padLen; - - /* Save number of bits */ - Encode(bits, context->count, 8); - - /* Pad out to 56 mod 64. */ - idx = (unsigned int)((context->count[0] >> 3) & 0x3f); - padLen = (idx < 56) ? (56 - idx) : (120 - idx); - MD5Update(context, PADDING, padLen); - - /* Append length (before padding) */ - MD5Update(context, bits, 8); -} - -/* - * MD5 finalization. Ends an MD5 message-digest operation, writing the - * the message digest and zeroizing the context. - */ - -void MD5Final(unsigned char digest[16], MD5_CTX * context) -{ - /* Do padding. */ - MD5Pad(context); - - /* Store state in digest */ - Encode(digest, context->state, 16); - - /* Zeroize sensitive information. */ - memset((void *)context, 0, sizeof(*context)); -} - -/* MD5 basic transformation. Transforms state based on block. */ - -static void MD5Transform(state, block) -uint32_t state[4]; -const unsigned char block[64]; -{ - uint32_t a = state[0], b = state[1], c = state[2], d = state[3], x[16]; - - Decode(x, block, 64); - - /* Round 1 */ -#define S11 7 -#define S12 12 -#define S13 17 -#define S14 22 - FF(a, b, c, d, x[0], S11, 0xd76aa478); /* 1 */ - FF(d, a, b, c, x[1], S12, 0xe8c7b756); /* 2 */ - FF(c, d, a, b, x[2], S13, 0x242070db); /* 3 */ - FF(b, c, d, a, x[3], S14, 0xc1bdceee); /* 4 */ - FF(a, b, c, d, x[4], S11, 0xf57c0faf); /* 5 */ - FF(d, a, b, c, x[5], S12, 0x4787c62a); /* 6 */ - FF(c, d, a, b, x[6], S13, 0xa8304613); /* 7 */ - FF(b, c, d, a, x[7], S14, 0xfd469501); /* 8 */ - FF(a, b, c, d, x[8], S11, 0x698098d8); /* 9 */ - FF(d, a, b, c, x[9], S12, 0x8b44f7af); /* 10 */ - FF(c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */ - FF(b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */ - FF(a, b, c, d, x[12], S11, 0x6b901122); /* 13 */ - FF(d, a, b, c, x[13], S12, 0xfd987193); /* 14 */ - FF(c, d, a, b, x[14], S13, 0xa679438e); /* 15 */ - FF(b, c, d, a, x[15], S14, 0x49b40821); /* 16 */ - - /* Round 2 */ -#define S21 5 -#define S22 9 -#define S23 14 -#define S24 20 - GG(a, b, c, d, x[1], S21, 0xf61e2562); /* 17 */ - GG(d, a, b, c, x[6], S22, 0xc040b340); /* 18 */ - GG(c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */ - GG(b, c, d, a, x[0], S24, 0xe9b6c7aa); /* 20 */ - GG(a, b, c, d, x[5], S21, 0xd62f105d); /* 21 */ - GG(d, a, b, c, x[10], S22, 0x2441453); /* 22 */ - GG(c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */ - GG(b, c, d, a, x[4], S24, 0xe7d3fbc8); /* 24 */ - GG(a, b, c, d, x[9], S21, 0x21e1cde6); /* 25 */ - GG(d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */ - GG(c, d, a, b, x[3], S23, 0xf4d50d87); /* 27 */ - GG(b, c, d, a, x[8], S24, 0x455a14ed); /* 28 */ - GG(a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */ - GG(d, a, b, c, x[2], S22, 0xfcefa3f8); /* 30 */ - GG(c, d, a, b, x[7], S23, 0x676f02d9); /* 31 */ - GG(b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */ - - /* Round 3 */ -#define S31 4 -#define S32 11 -#define S33 16 -#define S34 23 - HH(a, b, c, d, x[5], S31, 0xfffa3942); /* 33 */ - HH(d, a, b, c, x[8], S32, 0x8771f681); /* 34 */ - HH(c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */ - HH(b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */ - HH(a, b, c, d, x[1], S31, 0xa4beea44); /* 37 */ - HH(d, a, b, c, x[4], S32, 0x4bdecfa9); /* 38 */ - HH(c, d, a, b, x[7], S33, 0xf6bb4b60); /* 39 */ - HH(b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */ - HH(a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */ - HH(d, a, b, c, x[0], S32, 0xeaa127fa); /* 42 */ - HH(c, d, a, b, x[3], S33, 0xd4ef3085); /* 43 */ - HH(b, c, d, a, x[6], S34, 0x4881d05); /* 44 */ - HH(a, b, c, d, x[9], S31, 0xd9d4d039); /* 45 */ - HH(d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */ - HH(c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */ - HH(b, c, d, a, x[2], S34, 0xc4ac5665); /* 48 */ - - /* Round 4 */ -#define S41 6 -#define S42 10 -#define S43 15 -#define S44 21 - II(a, b, c, d, x[0], S41, 0xf4292244); /* 49 */ - II(d, a, b, c, x[7], S42, 0x432aff97); /* 50 */ - II(c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */ - II(b, c, d, a, x[5], S44, 0xfc93a039); /* 52 */ - II(a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */ - II(d, a, b, c, x[3], S42, 0x8f0ccc92); /* 54 */ - II(c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */ - II(b, c, d, a, x[1], S44, 0x85845dd1); /* 56 */ - II(a, b, c, d, x[8], S41, 0x6fa87e4f); /* 57 */ - II(d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */ - II(c, d, a, b, x[6], S43, 0xa3014314); /* 59 */ - II(b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */ - II(a, b, c, d, x[4], S41, 0xf7537e82); /* 61 */ - II(d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */ - II(c, d, a, b, x[2], S43, 0x2ad7d2bb); /* 63 */ - II(b, c, d, a, x[9], S44, 0xeb86d391); /* 64 */ - - state[0] += a; - state[1] += b; - state[2] += c; - state[3] += d; - - /* Zeroize sensitive information. */ - memset((void *)x, 0, sizeof(x)); -} - -static void md5_exit(void) -{ - // Nothing to do -} - -// Define entry and exit points. -MODULE_INIT(md5_init); -MODULE_EXIT(md5_exit); diff --git a/com32/elflink/modules/md5.h b/com32/elflink/modules/md5.h deleted file mode 100644 index db38c66..0000000 --- a/com32/elflink/modules/md5.h +++ /dev/null @@ -1,46 +0,0 @@ -/* MD5.H - header file for MD5C.C - */ - -/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All -rights reserved. - -License to copy and use this software is granted provided that it -is identified as the "RSA Data Security, Inc. MD5 Message-Digest -Algorithm" in all material mentioning or referencing this software -or this function. - -License is also granted to make and use derivative works provided -that such works are identified as "derived from the RSA Data -Security, Inc. MD5 Message-Digest Algorithm" in all material -mentioning or referencing the derived work. - -RSA Data Security, Inc. makes no representations concerning either -the merchantability of this software or the suitability of this -software for any particular purpose. It is provided "as is" -without express or implied warranty of any kind. -These notices must be retained in any copies of any part of this -documentation and/or software. - */ - -#ifndef _LIBUTIL_MD5_H -#define _LIBUTIL_MD5_H - -#include <stddef.h> -#include <stdint.h> - -#define MD5_SIZE 16 /* 128 bits */ - -/* MD5 context. */ -typedef struct { - uint32_t state[4]; /* state (ABCD) */ - uint32_t count[2]; /* number of bits, modulo 2^64 (lsb first) */ - unsigned char buffer[64]; /* input buffer */ -} MD5_CTX; - -void MD5Init(MD5_CTX *); -void MD5Update(MD5_CTX *, const void *, size_t); -void MD5Final(unsigned char[MD5_SIZE], MD5_CTX *); - -char *crypt_md5(const char *, const char *); - -#endif diff --git a/com32/elflink/modules/meminfo.c b/com32/elflink/modules/meminfo.c deleted file mode 100644 index 00d0e14..0000000 --- a/com32/elflink/modules/meminfo.c +++ /dev/null @@ -1,130 +0,0 @@ -/* ----------------------------------------------------------------------- * - * - * Copyright 2008 H. Peter Anvin - All Rights Reserved - * Copyright 2009 Intel Corporation; author: H. Peter Anvin - * - * 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., 51 Franklin St, Fifth Floor, - * Boston MA 02110-1301, USA; either version 2 of the License, or - * (at your option) any later version; incorporated herein by reference. - * - * ----------------------------------------------------------------------- */ - -/* - * meminfo.c - * - * Dump the memory map of the system - */ -#include <inttypes.h> -#include <stdio.h> -#include <string.h> -#include <console.h> -#include <com32.h> - -struct e820_data { - uint64_t base; - uint64_t len; - uint32_t type; - uint32_t extattr; -} __attribute__ ((packed)); - -static const char *const e820_types[] = { - "usable", - "reserved", - "ACPI reclaim", - "ACPI NVS", - "unusable", -}; - -static void dump_e820(void) -{ - com32sys_t ireg, oreg; - struct e820_data ed; - uint32_t type; - void *low_ed; - - low_ed = lmalloc(sizeof ed); - if (!low_ed) - return; - - memset(&ireg, 0, sizeof ireg); - - ireg.eax.w[0] = 0xe820; - ireg.edx.l = 0x534d4150; - ireg.ecx.l = sizeof(struct e820_data); - ireg.edi.w[0] = OFFS(low_ed); - ireg.es = SEG(low_ed); - - memset(&ed, 0, sizeof ed); - ed.extattr = 1; - - do { - memcpy(low_ed, &ed, sizeof ed); - - __intcall(0x15, &ireg, &oreg); - if (oreg.eflags.l & EFLAGS_CF || - oreg.eax.l != 0x534d4150 || oreg.ecx.l < 20) - break; - - memcpy(&ed, low_ed, sizeof ed); - - if (oreg.ecx.l >= 24) { - /* ebx base length end type */ - printf("%8x %016llx %016llx %016llx %d [%x]", - ireg.ebx.l, ed.base, ed.len, ed.base + ed.len, ed.type, - ed.extattr); - } else { - /* ebx base length end */ - printf("%8x %016llx %016llx %016llx %d [-]", - ireg.ebx.l, ed.base, ed.len, ed.base + ed.len, ed.type); - ed.extattr = 1; - } - - type = ed.type - 1; - if (type < sizeof(e820_types) / sizeof(e820_types[0])) - printf(" %s", e820_types[type]); - - putchar('\n'); - - ireg.ebx.l = oreg.ebx.l; - } while (ireg.ebx.l); - - free(low_ed); -} - -static void dump_legacy(void) -{ - com32sys_t ireg, oreg; - uint16_t dosram = *(uint16_t *) 0x413; - struct { - uint16_t offs, seg; - } *const ivt = (void *)0; - - memset(&ireg, 0, sizeof ireg); - - __intcall(0x12, &ireg, &oreg); - - printf - ("INT 15h = %04x:%04x DOS RAM: %dK (0x%05x) INT 12h: %dK (0x%05x)\n", - ivt[0x15].seg, ivt[0x15].offs, dosram, dosram << 10, oreg.eax.w[0], - oreg.eax.w[0] << 10); - - ireg.eax.b[1] = 0x88; - __intcall(0x15, &ireg, &oreg); - - printf("INT 15 88: 0x%04x (%uK) ", oreg.eax.w[0], oreg.eax.w[0]); - - ireg.eax.w[0] = 0xe801; - __intcall(0x15, &ireg, &oreg); - - printf("INT 15 E801: 0x%04x (%uK) 0x%04x (%uK)\n", - oreg.ecx.w[0], oreg.ecx.w[0], oreg.edx.w[0], oreg.edx.w[0] << 6); -} - -int main(int argc, char **argv) -{ - dump_legacy(); - dump_e820(); - return 0; -} diff --git a/com32/elflink/modules/menu.c b/com32/elflink/modules/menu.c deleted file mode 100644 index d0134b3..0000000 --- a/com32/elflink/modules/menu.c +++ /dev/null @@ -1,18 +0,0 @@ -/* - * menu.c -- simple program to test menu_main() - */ - -#include <stdio.h> -#include <stdlib.h> -#include <core-elf.h> - -#include "menu.h" - -/* - * useage: menu.c32 [config file] - */ -int menu(int argc, char **argv) -{ - menu_main(argc, argv); - return 0; -} diff --git a/com32/elflink/modules/menu.h b/com32/elflink/modules/menu.h deleted file mode 100644 index e79fb3e..0000000 --- a/com32/elflink/modules/menu.h +++ /dev/null @@ -1,218 +0,0 @@ -/* ----------------------------------------------------------------------- * - * - * Copyright 2004-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., 51 Franklin St, Fifth Floor, - * Boston MA 02110-1301, USA; either version 2 of the License, or - * (at your option) any later version; incorporated herein by reference. - * - * ----------------------------------------------------------------------- */ - -/* - * menu.h - * - * Header file for the simple menu system - */ - -#ifndef MENU_H -#define MENU_H - -#include <time.h> -#include <sys/time.h> -#include <sys/times.h> -#include <inttypes.h> -#include <unistd.h> -#include <colortbl.h> -#include <stdbool.h> -#include <setjmp.h> -#include "refstr.h" - -#ifndef CLK_TCK -# define CLK_TCK sysconf(_SC_CLK_TCK) -#endif - -struct menu; - -/* Note: the _UNRES variants must always be immediately after their - "normal" versions. */ -enum menu_action { - MA_NONE, /* Undefined value */ - MA_CMD, /* Execute a command */ - MA_DISABLED, /* Disabled menu entry */ - MA_SUBMENU, /* This is a submenu entry */ - MA_GOTO, /* Go to another menu */ - MA_GOTO_UNRES, /* Unresolved go to */ - MA_QUIT, /* Quit to CLI */ - MA_EXIT, /* Exit to higher-level menu */ - MA_EXIT_UNRES, /* Unresolved exit */ -}; - -struct menu_entry { - struct menu *menu; /* Parent menu */ - const char *displayname; - const char *label; - const char *passwd; - char *helptext; - const char *cmdline; - struct menu *submenu; - struct menu_entry *next; /* Linked list of all labels across menus */ - int entry; /* Entry number inside menu */ - enum menu_action action; - unsigned char hotkey; - bool save; /* Save this entry if selected */ -}; - -static inline bool is_disabled(struct menu_entry *me) -{ - return me->action == MA_DISABLED; -} - -extern const char *const kernel_types[]; - -/* Configurable integer parameters */ -enum parameter_number { - P_WIDTH, - P_MARGIN, - P_PASSWD_MARGIN, - P_MENU_ROWS, - P_TABMSG_ROW, - P_CMDLINE_ROW, - P_END_ROW, - P_PASSWD_ROW, - P_TIMEOUT_ROW, - P_HELPMSG_ROW, - P_HELPMSGEND_ROW, - P_HSHIFT, - P_VSHIFT, - P_HIDDEN_ROW, - - NPARAMS -}; - -/* Configurable messages */ -enum message_number { - MSG_TITLE, - MSG_AUTOBOOT, - MSG_TAB, - MSG_NOTAB, - MSG_PASSPROMPT, - - MSG_COUNT -}; - -struct messages { - const char *name; /* Message configuration name */ - const char *defmsg; /* Default message text */ -}; - -struct menu_parameter { - const char *name; - int value; -}; - -extern const struct menu_parameter mparm[NPARAMS]; - -struct fkey_help { - const char *textname; - const char *background; -}; - -struct menu { - struct menu *next; /* Linked list of all menus */ - const char *label; /* Goto label for this menu */ - struct menu *parent; - struct menu_entry *parent_entry; /* Entry for self in parent */ - - struct menu_entry **menu_entries; - struct menu_entry *menu_hotkeys[256]; - - const char *messages[MSG_COUNT]; - int mparm[NPARAMS]; - - int nentries; - int nentries_space; - int defentry; - int timeout; - - bool allowedit; - bool save; /* MENU SAVE default for this menu */ - - int curentry; - int curtop; - - const char *title; - const char *ontimeout; - const char *onerror; - const char *menu_master_passwd; - const char *menu_background; - - struct color_table *color_table; - - struct fkey_help fkeyhelp[12]; -}; - -extern struct menu *root_menu, *start_menu, *hide_menu, *menu_list; - -/* 2048 is the current definition inside syslinux */ -#define MAX_CMDLINE_LEN 2048 - -/* These are global parameters regardless of which menu we're displaying */ -extern int shiftkey; -extern int hiddenmenu; -extern long long totaltimeout; - -void parse_configs(char **argv); -extern int draw_background(const char *filename); - -static inline int my_isspace(char c) -{ - return (unsigned char)c <= ' '; -} - -int my_isxdigit(char c); -unsigned int hexval(char c); -unsigned int hexval2(const char *p); -uint32_t parse_argb(char **p); - -int menu_main(int argc, char *argv[]); -void console_prepare(void); -void console_cleanup(void); - -extern const int message_base_color, menu_color_table_size; -int mygetkey(clock_t timeout); -int show_message_file(const char *filename, const char *background); - -extern void print_labels(const char *prefix, size_t len); - -/* passwd.c */ -int passwd_compare(const char *passwd, const char *entry); - -/* colors.c */ -#define MSG_COLORS_DEF_FG 0x90ffffff -#define MSG_COLORS_DEF_BG 0x80ffffff -#define MSG_COLORS_DEF_SHADOW SHADOW_NORMAL -void set_msg_colors_global(struct color_table *tbl, - unsigned int fg, unsigned int bg, - enum color_table_shadow shadow); -struct color_table *default_color_table(void); -struct color_table *copy_color_table(const struct color_table *master); -extern const int message_base_color; - -/* background.c */ -extern const char *current_background; -void set_background(const char *new_background); - -extern struct menu_entry *find_label(const char *str); - -/* execute.c */ -void execute(const char *cmdline, enum kernel_type type); - -/* drain.c */ -void drain_keyboard(void); - -/* printmsg.c */ -int draw_message_file(const char *filename); - -#endif /* MENU_H */ diff --git a/com32/elflink/modules/menumain.c b/com32/elflink/modules/menumain.c deleted file mode 100644 index 4d00dc3..0000000 --- a/com32/elflink/modules/menumain.c +++ /dev/null @@ -1,977 +0,0 @@ -/* ----------------------------------------------------------------------- * - * - * Copyright 2004-2008 H. Peter Anvin - All Rights Reserved - * Copyright 2009 Intel Corporation; author: H. Peter Anvin - * - * 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., 51 Franklin St, Fifth Floor, - * Boston MA 02110-1301, USA; either version 2 of the License, or - * (at your option) any later version; incorporated herein by reference. - * - * ----------------------------------------------------------------------- */ - -/* - * menumain.c - * - * Simple menu system which displays a list and allows the user to select - * a command line and/or edit it. - */ - -#include <ctype.h> -#include <string.h> -#include <stdlib.h> -#include <stdio.h> -#include <consoles.h> -#include <getkey.h> -#include <minmax.h> -#include <setjmp.h> -#include <limits.h> -#include <com32.h> -#include <syslinux/adv.h> -#include <sys/module.h> -#include <core-elf.h> -#include <dprintf.h> - -#include "menu.h" -#include "cli.h" - -static jmp_buf timeout_jump; - -static int menumain_init(void) -{ - return 0; // Nothing to do; return success -} - -/* The symbol "cm" always refers to the current menu across this file... */ -static struct menu *cm; - -const struct menu_parameter mparm[NPARAMS] = { - [P_WIDTH] = {"width", 0}, - [P_MARGIN] = {"margin", 10}, - [P_PASSWD_MARGIN] = {"passwordmargin", 3}, - [P_MENU_ROWS] = {"rows", 12}, - [P_TABMSG_ROW] = {"tabmsgrow", 18}, - [P_CMDLINE_ROW] = {"cmdlinerow", 18}, - [P_END_ROW] = {"endrow", -1}, - [P_PASSWD_ROW] = {"passwordrow", 11}, - [P_TIMEOUT_ROW] = {"timeoutrow", 20}, - [P_HELPMSG_ROW] = {"helpmsgrow", 22}, - [P_HELPMSGEND_ROW] = {"helpmsgendrow", -1}, - [P_HSHIFT] = {"hshift", 0}, - [P_VSHIFT] = {"vshift", 0}, - [P_HIDDEN_ROW] = {"hiddenrow", -2}, -}; - -/* These macros assume "cm" is a pointer to the current menu */ -#define WIDTH (cm->mparm[P_WIDTH]) -#define MARGIN (cm->mparm[P_MARGIN]) -#define PASSWD_MARGIN (cm->mparm[P_PASSWD_MARGIN]) -#define MENU_ROWS (cm->mparm[P_MENU_ROWS]) -#define TABMSG_ROW (cm->mparm[P_TABMSG_ROW]+VSHIFT) -#define CMDLINE_ROW (cm->mparm[P_CMDLINE_ROW]+VSHIFT) -#define END_ROW (cm->mparm[P_END_ROW]) -#define PASSWD_ROW (cm->mparm[P_PASSWD_ROW]+VSHIFT) -#define TIMEOUT_ROW (cm->mparm[P_TIMEOUT_ROW]+VSHIFT) -#define HELPMSG_ROW (cm->mparm[P_HELPMSG_ROW]+VSHIFT) -#define HELPMSGEND_ROW (cm->mparm[P_HELPMSGEND_ROW]) -#define HSHIFT (cm->mparm[P_HSHIFT]) -#define VSHIFT (cm->mparm[P_VSHIFT]) -#define HIDDEN_ROW (cm->mparm[P_HIDDEN_ROW]) - -static char *pad_line(const char *text, int align, int width) -{ - static char buffer[MAX_CMDLINE_LEN]; - int n, p; - - if (width >= (int)sizeof buffer) - return NULL; /* Can't do it */ - - n = strlen(text); - if (n >= width) - n = width; - - memset(buffer, ' ', width); - buffer[width] = 0; - p = ((width - n) * align) >> 1; - memcpy(buffer + p, text, n); - - return buffer; -} - -/* Display an entry, with possible hotkey highlight. Assumes - that the current attribute is the non-hotkey one, and will - guarantee that as an exit condition as well. */ -static void -display_entry(const struct menu_entry *entry, const char *attrib, - const char *hotattrib, int width) -{ - const char *p = entry->displayname; - char marker; - - if (!p) - p = ""; - - switch (entry->action) { - case MA_SUBMENU: - marker = '>'; - break; - case MA_EXIT: - marker = '<'; - break; - default: - marker = 0; - break; - } - - if (marker) - width -= 2; - - while (width) { - if (*p) { - if (*p == '^') { - p++; - if (*p && ((unsigned char)*p & ~0x20) == entry->hotkey) { - fputs(hotattrib, stdout); - putchar(*p++); - fputs(attrib, stdout); - width--; - } - } else { - putchar(*p++); - width--; - } - } else { - putchar(' '); - width--; - } - } - - if (marker) { - putchar(' '); - putchar(marker); - } -} - -static void draw_row(int y, int sel, int top, int sbtop, int sbbot) -{ - int i = (y - 4 - VSHIFT) + top; - int dis = (i < cm->nentries) && is_disabled(cm->menu_entries[i]); - - printf("\033[%d;%dH\1#1\016x\017%s ", - y, MARGIN + 1 + HSHIFT, - (i == sel) ? "\1#5" : dis ? "\2#17" : "\1#3"); - - if (i >= cm->nentries) { - fputs(pad_line("", 0, WIDTH - 2 * MARGIN - 4), stdout); - } else { - display_entry(cm->menu_entries[i], - (i == sel) ? "\1#5" : dis ? "\2#17" : "\1#3", - (i == sel) ? "\1#6" : dis ? "\2#17" : "\1#4", - WIDTH - 2 * MARGIN - 4); - } - - if (cm->nentries <= MENU_ROWS) { - printf(" \1#1\016x\017"); - } else if (sbtop > 0) { - if (y >= sbtop && y <= sbbot) - printf(" \1#7\016a\017"); - else - printf(" \1#1\016x\017"); - } else { - putchar(' '); /* Don't modify the scrollbar */ - } -} - -int show_message_file(const char *filename, const char *background) -{ - int rv = KEY_NONE; - const char *old_background = NULL; - - if (background) { - old_background = current_background; - set_background(background); - } - - if (!(rv = draw_message_file(filename))) - rv = mygetkey(0); /* Wait for keypress */ - - if (old_background) - set_background(old_background); - - return rv; -} - -static int ask_passwd(const char *menu_entry) -{ - char user_passwd[WIDTH], *p; - int done; - int key; - int x; - int rv; - - printf("\033[%d;%dH\2#11\016l", PASSWD_ROW, PASSWD_MARGIN + 1); - for (x = 2; x <= WIDTH - 2 * PASSWD_MARGIN - 1; x++) - putchar('q'); - - printf("k\033[%d;%dHx", PASSWD_ROW + 1, PASSWD_MARGIN + 1); - for (x = 2; x <= WIDTH - 2 * PASSWD_MARGIN - 1; x++) - putchar(' '); - - printf("x\033[%d;%dHm", PASSWD_ROW + 2, PASSWD_MARGIN + 1); - for (x = 2; x <= WIDTH - 2 * PASSWD_MARGIN - 1; x++) - putchar('q'); - - printf("j\017\033[%d;%dH\2#12 %s \033[%d;%dH\2#13", - PASSWD_ROW, (WIDTH - (strlen(cm->messages[MSG_PASSPROMPT]) + 2)) / 2, - cm->messages[MSG_PASSPROMPT], PASSWD_ROW + 1, PASSWD_MARGIN + 3); - - drain_keyboard(); - - /* Actually allow user to type a password, then compare to the SHA1 */ - done = 0; - p = user_passwd; - - while (!done) { - key = mygetkey(0); - - switch (key) { - case KEY_ENTER: - case KEY_CTRL('J'): - done = 1; - break; - - case KEY_ESC: - case KEY_CTRL('C'): - p = user_passwd; /* No password entered */ - done = 1; - break; - - case KEY_BACKSPACE: - case KEY_DEL: - case KEY_DELETE: - if (p > user_passwd) { - printf("\b \b"); - p--; - } - break; - - case KEY_CTRL('U'): - while (p > user_passwd) { - printf("\b \b"); - p--; - } - break; - - default: - if (key >= ' ' && key <= 0xFF && - (p - user_passwd) < WIDTH - 2 * PASSWD_MARGIN - 5) { - *p++ = key; - putchar('*'); - } - break; - } - } - - if (p == user_passwd) - return 0; /* No password entered */ - - *p = '\0'; - - rv = (cm->menu_master_passwd && - passwd_compare(cm->menu_master_passwd, user_passwd)) - || (menu_entry && passwd_compare(menu_entry, user_passwd)); - - /* Clean up */ - memset(user_passwd, 0, WIDTH); - drain_keyboard(); - - return rv; -} - -static int draw_menu(int sel, int top, int edit_line) -{ - int x, y; - int sbtop = 0, sbbot = 0; - const char *tabmsg; - int tabmsg_len; - - if (cm->nentries > MENU_ROWS) { - int sblen = max(MENU_ROWS * MENU_ROWS / cm->nentries, 1); - sbtop = (MENU_ROWS - sblen + 1) * top / (cm->nentries - MENU_ROWS + 1); - sbbot = sbtop + sblen - 1; - sbtop += 4; - sbbot += 4; /* Starting row of scrollbar */ - } - - printf("\033[%d;%dH\1#1\016l", VSHIFT + 1, HSHIFT + MARGIN + 1); - for (x = 2 + HSHIFT; x <= (WIDTH - 2 * MARGIN - 1) + HSHIFT; x++) - putchar('q'); - - printf("k\033[%d;%dH\1#1x\017\1#2 %s \1#1\016x", - VSHIFT + 2, - HSHIFT + MARGIN + 1, pad_line(cm->title, 1, WIDTH - 2 * MARGIN - 4)); - - printf("\033[%d;%dH\1#1t", VSHIFT + 3, HSHIFT + MARGIN + 1); - for (x = 2 + HSHIFT; x <= (WIDTH - 2 * MARGIN - 1) + HSHIFT; x++) - putchar('q'); - fputs("u\017", stdout); - - for (y = 4 + VSHIFT; y < 4 + VSHIFT + MENU_ROWS; y++) - draw_row(y, sel, top, sbtop, sbbot); - - printf("\033[%d;%dH\1#1\016m", y, HSHIFT + MARGIN + 1); - for (x = 2 + HSHIFT; x <= (WIDTH - 2 * MARGIN - 1) + HSHIFT; x++) - putchar('q'); - fputs("j\017", stdout); - - if (edit_line && cm->allowedit && !cm->menu_master_passwd) - tabmsg = cm->messages[MSG_TAB]; - else - tabmsg = cm->messages[MSG_NOTAB]; - - tabmsg_len = strlen(tabmsg); - - printf("\1#8\033[%d;%dH%s", - TABMSG_ROW, 1 + HSHIFT + ((WIDTH - tabmsg_len) >> 1), tabmsg); - printf("\1#0\033[%d;1H", END_ROW); - return 0; -} - -static void display_help(const char *text) -{ - int row; - const char *p; - - if (!text) { - text = ""; - printf("\1#0\033[%d;1H", HELPMSG_ROW); - } else { - printf("\2#16\033[%d;1H", HELPMSG_ROW); - } - - for (p = text, row = HELPMSG_ROW; *p && row <= HELPMSGEND_ROW; p++) { - switch (*p) { - case '\r': - case '\f': - case '\v': - case '\033': - break; - case '\n': - printf("\033[K\033[%d;1H", ++row); - break; - default: - putchar(*p); - } - } - - fputs("\033[K", stdout); - - while (row <= HELPMSGEND_ROW) { - printf("\033[K\033[%d;1H", ++row); - } -} - -static void show_fkey(int key) -{ - int fkey; - - while (1) { - switch (key) { - case KEY_F1: - fkey = 0; - break; - case KEY_F2: - fkey = 1; - break; - case KEY_F3: - fkey = 2; - break; - case KEY_F4: - fkey = 3; - break; - case KEY_F5: - fkey = 4; - break; - case KEY_F6: - fkey = 5; - break; - case KEY_F7: - fkey = 6; - break; - case KEY_F8: - fkey = 7; - break; - case KEY_F9: - fkey = 8; - break; - case KEY_F10: - fkey = 9; - break; - case KEY_F11: - fkey = 10; - break; - case KEY_F12: - fkey = 11; - break; - default: - fkey = -1; - break; - } - - if (fkey == -1) - break; - - if (cm->fkeyhelp[fkey].textname) - key = show_message_file(cm->fkeyhelp[fkey].textname, - cm->fkeyhelp[fkey].background); - else - break; - } -} - -static inline int shift_is_held(void) -{ - uint8_t shift_bits = *(uint8_t *) 0x417; - - return !!(shift_bits & 0x5d); /* Caps/Scroll/Alt/Shift */ -} - -static void print_timeout_message(int tol, int row, const char *msg) -{ - char buf[256]; - int nc = 0, nnc; - const char *tp = msg; - char tc; - char *tq = buf; - - while ((size_t) (tq - buf) < (sizeof buf - 16) && (tc = *tp)) { - tp++; - if (tc == '#') { - nnc = sprintf(tq, "\2#15%d\2#14", tol); - tq += nnc; - nc += nnc - 8; /* 8 formatting characters */ - } else if (tc == '{') { - /* Deal with {singular[,dual],plural} constructs */ - struct { - const char *s, *e; - } tx[3]; - const char *tpp; - int n = 0; - - memset(tx, 0, sizeof tx); - - tx[0].s = tp; - - while (*tp && *tp != '}') { - if (*tp == ',' && n < 2) { - tx[n].e = tp; - n++; - tx[n].s = tp + 1; - } - tp++; - } - tx[n].e = tp; - - if (*tp) - tp++; /* Skip final bracket */ - - if (!tx[1].s) - tx[1] = tx[0]; - if (!tx[2].s) - tx[2] = tx[1]; - - /* Now [0] is singular, [1] is dual, and [2] is plural, - even if the user only specified some of them. */ - - switch (tol) { - case 1: - n = 0; - break; - case 2: - n = 1; - break; - default: - n = 2; - break; - } - - for (tpp = tx[n].s; tpp < tx[n].e; tpp++) { - if ((size_t) (tq - buf) < (sizeof buf)) { - *tq++ = *tpp; - nc++; - } - } - } else { - *tq++ = tc; - nc++; - } - } - *tq = '\0'; - - /* Let's hope 4 spaces on each side is enough... */ - printf("\033[%d;%dH\2#14 %s ", row, - HSHIFT + 1 + ((WIDTH - nc - 8) >> 1), buf); -} - -/* Set the background screen, etc. */ -static void prepare_screen_for_menu(void) -{ - console_color_table = cm->color_table; - console_color_table_size = menu_color_table_size; - set_background(cm->menu_background); -} - -static const char *do_hidden_menu(void) -{ - int key; - int timeout_left, this_timeout; - - clear_screen(); - - if (!setjmp(timeout_jump)) { - timeout_left = cm->timeout; - - while (!cm->timeout || timeout_left) { - int tol = timeout_left / CLK_TCK; - - print_timeout_message(tol, HIDDEN_ROW, cm->messages[MSG_AUTOBOOT]); - - this_timeout = min(timeout_left, CLK_TCK); - key = mygetkey(this_timeout); - - if (key != KEY_NONE) - return NULL; /* Key pressed */ - - timeout_left -= this_timeout; - } - } - - if (cm->ontimeout) - return cm->ontimeout; - else - return cm->menu_entries[cm->defentry]->cmdline; /* Default entry */ -} - -static const char *run_menu(void) -{ - int key; - int done = 0; - volatile int entry = cm->curentry; - int prev_entry = -1; - volatile int top = cm->curtop; - int prev_top = -1; - int clear = 1, to_clear; - const char *cmdline = NULL; - volatile clock_t key_timeout, timeout_left, this_timeout; - const struct menu_entry *me; - - /* Note: for both key_timeout and timeout == 0 means no limit */ - timeout_left = key_timeout = cm->timeout; - - /* If we're in shiftkey mode, exit immediately unless a shift key - is pressed */ - if (shiftkey && !shift_is_held()) { - return cm->menu_entries[cm->defentry]->cmdline; - } else { - shiftkey = 0; - } - - /* Do this before hiddenmenu handling, so we show the background */ - prepare_screen_for_menu(); - - /* Handle hiddenmenu */ - if (hiddenmenu) { - cmdline = do_hidden_menu(); - if (cmdline) - return cmdline; - - /* Otherwise display the menu now; the timeout has already been - cancelled, since the user pressed a key. */ - hiddenmenu = 0; - key_timeout = 0; - } - - /* Handle both local and global timeout */ - if (setjmp(timeout_jump)) { - entry = cm->defentry; - - if (top < 0 || top < entry - MENU_ROWS + 1) - top = max(0, entry - MENU_ROWS + 1); - else if (top > entry || top > max(0, cm->nentries - MENU_ROWS)) - top = min(entry, max(0, cm->nentries - MENU_ROWS)); - - draw_menu(cm->ontimeout ? -1 : entry, top, 1); - cmdline - cm->ontimeout ? cm->ontimeout : cm->menu_entries[entry]->cmdline; - done = 1; - } - - while (!done) { - if (entry <= 0) { - entry = 0; - while (entry < cm->nentries && is_disabled(cm->menu_entries[entry])) - entry++; - } - if (entry >= cm->nentries) { - entry = cm->nentries - 1; - while (entry > 0 && is_disabled(cm->menu_entries[entry])) - entry--; - } - - me = cm->menu_entries[entry]; - - if (top < 0 || top < entry - MENU_ROWS + 1) - top = max(0, entry - MENU_ROWS + 1); - else if (top > entry || top > max(0, cm->nentries - MENU_ROWS)) - top = min(entry, max(0, cm->nentries - MENU_ROWS)); - - /* Start with a clear screen */ - if (clear) { - /* Clear and redraw whole screen */ - /* Enable ASCII on G0 and DEC VT on G1; do it in this order - to avoid confusing the Linux console */ - if (clear >= 2) - prepare_screen_for_menu(); - clear_screen(); - clear = 0; - prev_entry = prev_top = -1; - } - - if (top != prev_top) { - draw_menu(entry, top, 1); - display_help(me->helptext); - } else if (entry != prev_entry) { - draw_row(prev_entry - top + 4 + VSHIFT, entry, top, 0, 0); - draw_row(entry - top + 4 + VSHIFT, entry, top, 0, 0); - display_help(me->helptext); - } - - prev_entry = entry; - prev_top = top; - cm->curentry = entry; - cm->curtop = top; - - /* Cursor movement cancels timeout */ - if (entry != cm->defentry) - key_timeout = 0; - - if (key_timeout) { - int tol = timeout_left / CLK_TCK; - print_timeout_message(tol, TIMEOUT_ROW, cm->messages[MSG_AUTOBOOT]); - to_clear = 1; - } else { - to_clear = 0; - } - - this_timeout = min(min(key_timeout, timeout_left), (clock_t) CLK_TCK); - key = mygetkey(this_timeout); - - if (key != KEY_NONE) { - timeout_left = key_timeout; - if (to_clear) - printf("\033[%d;1H\1#0\033[K", TIMEOUT_ROW); - } - - switch (key) { - case KEY_NONE: /* Timeout */ - /* This is somewhat hacky, but this at least lets the user - know what's going on, and still deals with "phantom inputs" - e.g. on serial ports. - - Warning: a timeout will boot the default entry without any - password! */ - if (key_timeout) { - if (timeout_left <= this_timeout) - longjmp(timeout_jump, 1); - - timeout_left -= this_timeout; - } - break; - - case KEY_CTRL('L'): - clear = 1; - break; - - case KEY_ENTER: - case KEY_CTRL('J'): - key_timeout = 0; /* Cancels timeout */ - if (me->passwd) { - clear = 1; - done = ask_passwd(me->passwd); - } else { - done = 1; - } - cmdline = NULL; - if (done) { - switch (me->action) { - case MA_CMD: - cmdline = me->cmdline; - break; - case MA_SUBMENU: - case MA_GOTO: - case MA_EXIT: - done = 0; - clear = 2; - cm = me->submenu; - entry = cm->curentry; - top = cm->curtop; - break; - case MA_QUIT: - /* Quit menu system */ - done = 1; - clear = 1; - draw_row(entry - top + 4 + VSHIFT, -1, top, 0, 0); - break; - default: - done = 0; - break; - } - } - if (done && !me->passwd) { - /* Only save a new default if we don't have a password... */ - /* - if (me->save && me->label) { - syslinux_setadv(ADV_MENUSAVE, strlen(me->label), me->label); - syslinux_adv_write(); - } - */ - } - break; - - case KEY_UP: - case KEY_CTRL('P'): - while (entry > 0) { - entry--; - if (entry < top) - top -= MENU_ROWS; - if (!is_disabled(cm->menu_entries[entry])) - break; - } - break; - - case KEY_DOWN: - case KEY_CTRL('N'): - while (entry < cm->nentries - 1) { - entry++; - if (entry >= top + MENU_ROWS) - top += MENU_ROWS; - if (!is_disabled(cm->menu_entries[entry])) - break; - } - break; - - case KEY_PGUP: - case KEY_LEFT: - case KEY_CTRL('B'): - case '<': - entry -= MENU_ROWS; - top -= MENU_ROWS; - while (entry > 0 && is_disabled(cm->menu_entries[entry])) { - entry--; - if (entry < top) - top -= MENU_ROWS; - } - break; - - case KEY_PGDN: - case KEY_RIGHT: - case KEY_CTRL('F'): - case '>': - case ' ': - entry += MENU_ROWS; - top += MENU_ROWS; - while (entry < cm->nentries - 1 - && is_disabled(cm->menu_entries[entry])) { - entry++; - if (entry >= top + MENU_ROWS) - top += MENU_ROWS; - } - break; - - case '-': - while (entry > 0) { - entry--; - top--; - if (!is_disabled(cm->menu_entries[entry])) - break; - } - break; - - case '+': - while (entry < cm->nentries - 1) { - entry++; - top++; - if (!is_disabled(cm->menu_entries[entry])) - break; - } - break; - - case KEY_CTRL('A'): - case KEY_HOME: - top = entry = 0; - break; - - case KEY_CTRL('E'): - case KEY_END: - entry = cm->nentries - 1; - top = max(0, cm->nentries - MENU_ROWS); - break; - - case KEY_F1: - case KEY_F2: - case KEY_F3: - case KEY_F4: - case KEY_F5: - case KEY_F6: - case KEY_F7: - case KEY_F8: - case KEY_F9: - case KEY_F10: - case KEY_F11: - case KEY_F12: - show_fkey(key); - clear = 1; - break; - - case KEY_TAB: - if (cm->allowedit && me->action == MA_CMD) { - int ok = 1; - - key_timeout = 0; /* Cancels timeout */ - draw_row(entry - top + 4 + VSHIFT, -1, top, 0, 0); - - if (cm->menu_master_passwd) { - ok = ask_passwd(NULL); - clear_screen(); - draw_menu(-1, top, 0); - } else { - /* Erase [Tab] message and help text */ - printf("\033[%d;1H\1#0\033[K", TABMSG_ROW); - display_help(NULL); - } - - if (ok) { - cmdline - edit_cmdline(me->cmdline, top, &draw_menu, &show_fkey); - done = !!cmdline; - clear = 1; /* In case we hit [Esc] and done is null */ - } else { - draw_row(entry - top + 4 + VSHIFT, entry, top, 0, 0); - } - } - break; - case KEY_CTRL('C'): /* Ctrl-C */ - case KEY_ESC: /* Esc */ - if (cm->parent) { - cm = cm->parent; - clear = 2; - entry = cm->curentry; - top = cm->curtop; - } else if (cm->allowedit) { - done = 1; - clear = 1; - key_timeout = 0; - - draw_row(entry - top + 4 + VSHIFT, -1, top, 0, 0); - - if (cm->menu_master_passwd) - done = ask_passwd(NULL); - } - break; - default: - if (key > 0 && key < 0xFF) { - key &= ~0x20; /* Upper case */ - if (cm->menu_hotkeys[key]) { - key_timeout = 0; - entry = cm->menu_hotkeys[key]->entry; - /* Should we commit at this point? */ - } - } - break; - } - } - - printf("\033[?25h"); /* Show cursor */ - - /* Return the label name so localboot and ipappend work */ - return cmdline; -} - -static void dump_menu(struct menu *menu) -{ - dprintf("will dump menu for %s:", menu->label); - printf("entries num: %d\n", menu->nentries); - printf("defentry: %d, nam = %s\n", - menu->defentry, menu->menu_entries[menu->defentry]->label); - //printf("save: %d\n", menu->save); - //printf("", menu->); - //printf("", menu->); - //printf("", menu->); -} - -int menu_main(int argc, char *argv[]) -{ - const char *cmdline; - struct menu *m; - int rows, cols; - int i; - - (void)argc; - - if (getscreensize(1, &rows, &cols)) { - /* Unknown screen size? */ - rows = 24; - cols = 80; - } - - /* - * If there is a config file given, parse it - * otherwise use the config already parsed - */ - if (argc == 2) - parse_configs(argv + 1); - - /* Some postprocessing for all menus */ - for (m = menu_list; m; m = m->next) { - if (!m->mparm[P_WIDTH]) - m->mparm[P_WIDTH] = cols; - - /* If anyone has specified negative parameters, consider them - relative to the bottom row of the screen. */ - for (i = 0; i < NPARAMS; i++) - if (m->mparm[i] < 0) - m->mparm[i] = max(m->mparm[i] + rows, 0); - } - - cm = start_menu; - if (!cm->nentries) { - fputs("Initial menu has no LABEL entries!\n", stdout); - return 1; /* Error! */ - } - - dump_menu(cm); - for (;;) { - cmdline = run_menu(); - - printf("\033[?25h\033[%d;1H\033[0m", END_ROW); - - if (cmdline) { - dprintf("cmdline = %s", cmdline); - execute(cmdline, KT_NONE); - if (cm->onerror) - execute(cm->onerror, KT_NONE); - } else { - return 0; /* Exit */ - } - } -} - -static void menumain_exit(void) -{ - // Nothing to do -} - -// Define entry and exit points. -MODULE_INIT(menumain_init); -MODULE_EXIT(menumain_exit); diff --git a/com32/elflink/modules/modules.dep b/com32/elflink/modules/modules.dep deleted file mode 100644 index 90feb0b..0000000 --- a/com32/elflink/modules/modules.dep +++ /dev/null @@ -1,19 +0,0 @@ -ansiraw: -background: -crypt-md5: md5 -drain: -execute: -get_key: -hello: -md5: -menu: menumain -menumain: drain passwd background printmsg execute -mytest: ansiraw menumain -passwd: crypt-md5 sha1hash unbase64 sha256crypt sha512crypt -printmsg: -sha1hash: -sha256crypt: -sha512crypt: -sort: -test: -unbase64: diff --git a/com32/elflink/modules/mytest.c b/com32/elflink/modules/mytest.c deleted file mode 100644 index e8b5c1c..0000000 --- a/com32/elflink/modules/mytest.c +++ /dev/null @@ -1,27 +0,0 @@ -#include <stdio.h> -#include <stdbool.h> -#include <stdlib.h> -#include <string.h> -#include <minmax.h> -#include <console.h> -#include <consoles.h> -#include <alloca.h> -#include <inttypes.h> -#include <colortbl.h> -#include <getkey.h> -#include <setjmp.h> -#include <limits.h> -#include <com32.h> -#include <core-elf.h> -#include <syslinux/adv.h> -#include <syslinux/config.h> - -#include "menu.h" - -int main(int argc, char **argv) -{ - console_ansi_raw(); - //edit_cmdline("",1); - menu_main(argc, argv); - return 0; -} diff --git a/com32/elflink/modules/passwd.c b/com32/elflink/modules/passwd.c deleted file mode 100644 index d190b1c..0000000 --- a/com32/elflink/modules/passwd.c +++ /dev/null @@ -1,112 +0,0 @@ -/* ----------------------------------------------------------------------- * - * - * Copyright 2004-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., 51 Franklin St, Fifth Floor, - * Boston MA 02110-1301, USA; either version 2 of the License, or - * (at your option) any later version; incorporated herein by reference. - * - * ----------------------------------------------------------------------- */ - -#include <string.h> -#include <xcrypt.h> -#include <sha1.h> -#include <base64.h> -#include <core-elf.h> -#include <sys/module.h> - -#include "menu.h" - -static int passwd_init(void) -{ - return 0; // Nothing to do; return success -} - -static int passwd_compare_sha1(const char *passwd, const char *entry) -{ - struct { - SHA1_CTX ctx; - unsigned char sha1[20], pwdsha1[20]; - } d; - const char *p; - int rv; - - SHA1Init(&d.ctx); - - if ((p = strchr(passwd + 3, '$'))) { - SHA1Update(&d.ctx, (void *)passwd + 3, p - (passwd + 3)); - p++; - } else { - p = passwd + 3; /* Assume no salt */ - } - - SHA1Update(&d.ctx, (void *)entry, strlen(entry)); - SHA1Final(d.sha1, &d.ctx); - - memset(d.pwdsha1, 0, 20); - unbase64(d.pwdsha1, 20, p); - - rv = !memcmp(d.sha1, d.pwdsha1, 20); - - memset(&d, 0, sizeof d); - return rv; -} - -static int passwd_compare_md5(const char *passwd, const char *entry) -{ - const char *crypted = crypt_md5(entry, passwd + 3); - int len = strlen(crypted); - - return !strncmp(crypted, passwd, len) && - (passwd[len] == '\0' || passwd[len] == '$'); -} - -static int passwd_compare_sha256(const char *passwd, const char *entry) -{ - const char *crypted = sha256_crypt(entry, passwd + 3); - int len = strlen(crypted); - - return !strncmp(crypted, passwd, len) && - (passwd[len] == '\0' || passwd[len] == '$'); -} - -static int passwd_compare_sha512(const char *passwd, const char *entry) -{ - const char *crypted = sha512_crypt(entry, passwd + 3); - int len = strlen(crypted); - - return !strncmp(crypted, passwd, len) && - (passwd[len] == '\0' || passwd[len] == '$'); -} - -int passwd_compare(const char *passwd, const char *entry) -{ - if (passwd[0] != '$' || !passwd[1] || passwd[2] != '$') { - /* Plaintext passwd, yuck! */ - return !strcmp(entry, passwd); - } else { - switch (passwd[1]) { - case '1': - return passwd_compare_md5(passwd, entry); - case '4': - return passwd_compare_sha1(passwd, entry); - case '5': - return passwd_compare_sha256(passwd, entry); - case '6': - return passwd_compare_sha512(passwd, entry); - default: - return 0; /* Unknown encryption algorithm -> false */ - } - } -} - -static void passwd_exit(void) -{ - // Nothing to do -} - -// Define entry and exit points. -MODULE_INIT(passwd_init); -MODULE_EXIT(passwd_exit); diff --git a/com32/elflink/modules/printmsg.c b/com32/elflink/modules/printmsg.c deleted file mode 100644 index e5fc62c..0000000 --- a/com32/elflink/modules/printmsg.c +++ /dev/null @@ -1,116 +0,0 @@ -/* ----------------------------------------------------------------------- * - * - * Copyright 2004-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., 51 Franklin St, Fifth Floor, - * Boston MA 02110-1301, USA; either version 2 of the License, or - * (at your option) any later version; incorporated herein by reference. - * - * ----------------------------------------------------------------------- */ - -#include <ctype.h> -#include <string.h> -#include <stdlib.h> -#include <stdio.h> -#include <consoles.h> -#include <getkey.h> -#include <minmax.h> -#include <setjmp.h> -#include <limits.h> -#include <sha1.h> -#include <base64.h> -#include <colortbl.h> -#include <sys/module.h> -#ifdef __COM32__ -#include <com32.h> -#endif -#include <core-elf.h> - -#include "menu.h" - -static int printmsg_init(void) -{ - return 0; // Nothing to do; return success -} - -int draw_message_file(const char *filename) -{ - FILE *f; - int ch; - enum msgname_state { - st_init, /* Base state */ - st_si_1, /* <SI> digit 1 */ - st_si_2, /* <SI> digit 2 */ - st_skipline, /* Skip until NL */ - } state = st_init; - int eof = 0; - int attr = 0; - - f = fopen(filename, "r"); - if (!f) - return -1; - - /* Clear screen, hide cursor, default attribute */ - printf("\033e\033%%@\033)0\033(B\3#%03d\033[?25l\033[2J\033[H", - message_base_color + 0x07); - - while (!eof && (ch = getc(f)) != EOF) { - switch (state) { - case st_init: - switch (ch) { - case '\f': - fputs("\033[2J\033[H", stdout); - break; - case 15: /* SI */ - state = st_si_1; - break; - case 24: - state = st_skipline; - break; - case 26: - eof = 1; - break; - case '\a': - case '\n': - case '\r': - putchar(ch); - break; - default: - if (ch >= 32) - putchar(ch); - break; - } - break; - - case st_si_1: - attr = hexval(ch) << 4; - state = st_si_2; - break; - - case st_si_2: - attr |= hexval(ch); - printf("\3#%03d", attr + message_base_color); - state = st_init; - break; - - case st_skipline: - if (ch == '\n') - state = st_init; - break; - } - } - - fclose(f); - return 0; -} - -static void printmsg_exit(void) -{ - // Nothing to do -} - -// Define entry and exit points. -MODULE_INIT(printmsg_init); -MODULE_EXIT(printmsg_exit); diff --git a/com32/elflink/modules/refstr.h b/com32/elflink/modules/refstr.h deleted file mode 100644 index 7001d40..0000000 --- a/com32/elflink/modules/refstr.h +++ /dev/null @@ -1,40 +0,0 @@ -/* ----------------------------------------------------------------------- * - * - * Copyright 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., 51 Franklin St, Fifth Floor, - * Boston MA 02110-1301, USA; either version 2 of the License, or - * (at your option) any later version; incorporated herein by reference. - * - * ----------------------------------------------------------------------- */ - -/* - * refstr.h - * - * Simple reference-counted strings - */ - -#ifndef REFSTR_H -#define REFSTR_H - -#include <stddef.h> -#include <stdarg.h> - -static inline __attribute__ ((always_inline)) -const char *refstr_get(const char *r) -{ - if (r) - ((unsigned int *)r)[-1]++; - return r; -} - -void refstr_put(const char *); -char *refstr_alloc(size_t); -const char *refstrdup(const char *); -const char *refstrndup(const char *, size_t); -int rsprintf(const char **, const char *, ...); -int vrsprintf(const char **, const char *, va_list); - -#endif diff --git a/com32/elflink/modules/sha1.h b/com32/elflink/modules/sha1.h deleted file mode 100644 index 3b35e77..0000000 --- a/com32/elflink/modules/sha1.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef LIBUTIL_SHA1_H -#define LIBUTIL_SHA1_H - -#include <stdint.h> - -typedef struct { - uint32_t state[5]; - uint32_t count[2]; - unsigned char buffer[64]; -} SHA1_CTX; - -void SHA1Transform(uint32_t state[5], const unsigned char buffer[64]); -void SHA1Init(SHA1_CTX * context); -void SHA1Update(SHA1_CTX * context, const unsigned char *data, uint32_t len); /* - JHB */ -void SHA1Final(unsigned char digest[20], SHA1_CTX * context); - -#endif /* LIBUTIL_SHA1_H */ diff --git a/com32/elflink/modules/sha1hash.c b/com32/elflink/modules/sha1hash.c deleted file mode 100644 index cafdc46..0000000 --- a/com32/elflink/modules/sha1hash.c +++ /dev/null @@ -1,347 +0,0 @@ -/* -SHA-1 in C -By Steve Reid <sreid at sea-to-sky.net> -100% Public Domain - ------------------ -Modified 7/98 -By James H. Brown <jbrown at burgoyne.com> -Still 100% Public Domain - -Corrected a problem which generated improper hash values on 16 bit machines -Routine SHA1Update changed from - void SHA1Update(SHA1_CTX* context, unsigned char* data, unsigned int -len) -to - void SHA1Update(SHA1_CTX* context, unsigned char* data, unsigned -long len) - -The 'len' parameter was declared an int which works fine on 32 bit machines. -However, on 16 bit machines an int is too small for the shifts being done -against -it. This caused the hash function to generate incorrect values if len was -greater than 8191 (8K - 1) due to the 'len << 3' on line 3 of SHA1Update(). - -Since the file IO in main() reads 16K at a time, any file 8K or larger would -be guaranteed to generate the wrong hash (e.g. Test Vector #3, a million -"a"s). - -I also changed the declaration of variables i & j in SHA1Update to -unsigned long from unsigned int for the same reason. - -These changes should make no difference to any 32 bit implementations since -an -int and a long are the same size in those environments. - --- -I also corrected a few compiler warnings generated by Borland C. -1. Added #include <process.h> for exit() prototype -2. Removed unused variable 'j' in SHA1Final -3. Changed exit(0) to return(0) at end of main. - -ALL changes I made can be located by searching for comments containing 'JHB' ------------------ -Modified 8/98 -By Steve Reid <sreid at sea-to-sky.net> -Still 100% public domain - -1- Removed #include <process.h> and used return() instead of exit() -2- Fixed overwriting of finalcount in SHA1Final() (discovered by Chris Hall) -3- Changed email address from steve at edmweb.com to sreid at sea-to-sky.net - ------------------ -Modified 4/01 -By Saul Kravitz <Saul.Kravitz at celera.com> -Still 100% PD -Modified to run on Compaq Alpha hardware. - ------------------ -Modified 2/03 -By H. Peter Anvin <hpa at zytor.com> -Still 100% PD -Modified to run on any hardware with <inttypes.h> and <netinet/in.h> -Changed the driver program - -*/ - -/* -Test Vectors (from FIPS PUB 180-1) -"abc" - A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D -"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" - 84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1 -A million repetitions of "a" - 34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F -*/ - -/* #define SHA1HANDSOFF */ - -#include <stdio.h> -#include <string.h> -#include <inttypes.h> -#include <netinet/in.h> /* For htonl/ntohl/htons/ntohs */ -#include <sys/module.h> - -#include "sha1.h" - -static int sha1hash_init(void) -{ - return 0; // Nothing to do; return success -} - -#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits)))) - -/* blk0() and blk() perform the initial expand. */ -/* I got the idea of expanding during the round function from SSLeay */ -#define blk0(i) (block->l[i] = ntohl(block->l[i])) -#define blk(i) (block->l[i&15] = rol(block->l[(i+13)&15]^block->l[(i+8)&15] \ - ^block->l[(i+2)&15]^block->l[i&15],1)) - -/* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */ -#define R0(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk0(i)+0x5A827999+rol(v,5);w=rol(w,30); -#define R1(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk(i)+0x5A827999+rol(v,5);w=rol(w,30); -#define R2(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0x6ED9EBA1+rol(v,5);w=rol(w,30); -#define R3(v,w,x,y,z,i) z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=rol(w,30); -#define R4(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=rol(w,30); - -#ifdef VERBOSE /* SAK */ -void SHAPrintContext(SHA1_CTX * context, char *msg) -{ - printf("%s (%d,%d) %x %x %x %x %x\n", - msg, - context->count[0], context->count[1], - context->state[0], - context->state[1], - context->state[2], context->state[3], context->state[4]); -} -#endif - -/* Hash a single 512-bit block. This is the core of the algorithm. */ - -void SHA1Transform(uint32_t state[5], const unsigned char buffer[64]) -{ - uint32_t a, b, c, d, e; - typedef union { - unsigned char c[64]; - uint32_t l[16]; - } CHAR64LONG16; - CHAR64LONG16 *block; -#ifdef SHA1HANDSOFF - static unsigned char workspace[64]; - block = (CHAR64LONG16 *) workspace; - memcpy(block, buffer, 64); -#else - block = (CHAR64LONG16 *) buffer; -#endif - /* Copy context->state[] to working vars */ - a = state[0]; - b = state[1]; - c = state[2]; - d = state[3]; - e = state[4]; - /* 4 rounds of 20 operations each. Loop unrolled. */ - R0(a, b, c, d, e, 0); - R0(e, a, b, c, d, 1); - R0(d, e, a, b, c, 2); - R0(c, d, e, a, b, 3); - R0(b, c, d, e, a, 4); - R0(a, b, c, d, e, 5); - R0(e, a, b, c, d, 6); - R0(d, e, a, b, c, 7); - R0(c, d, e, a, b, 8); - R0(b, c, d, e, a, 9); - R0(a, b, c, d, e, 10); - R0(e, a, b, c, d, 11); - R0(d, e, a, b, c, 12); - R0(c, d, e, a, b, 13); - R0(b, c, d, e, a, 14); - R0(a, b, c, d, e, 15); - R1(e, a, b, c, d, 16); - R1(d, e, a, b, c, 17); - R1(c, d, e, a, b, 18); - R1(b, c, d, e, a, 19); - R2(a, b, c, d, e, 20); - R2(e, a, b, c, d, 21); - R2(d, e, a, b, c, 22); - R2(c, d, e, a, b, 23); - R2(b, c, d, e, a, 24); - R2(a, b, c, d, e, 25); - R2(e, a, b, c, d, 26); - R2(d, e, a, b, c, 27); - R2(c, d, e, a, b, 28); - R2(b, c, d, e, a, 29); - R2(a, b, c, d, e, 30); - R2(e, a, b, c, d, 31); - R2(d, e, a, b, c, 32); - R2(c, d, e, a, b, 33); - R2(b, c, d, e, a, 34); - R2(a, b, c, d, e, 35); - R2(e, a, b, c, d, 36); - R2(d, e, a, b, c, 37); - R2(c, d, e, a, b, 38); - R2(b, c, d, e, a, 39); - R3(a, b, c, d, e, 40); - R3(e, a, b, c, d, 41); - R3(d, e, a, b, c, 42); - R3(c, d, e, a, b, 43); - R3(b, c, d, e, a, 44); - R3(a, b, c, d, e, 45); - R3(e, a, b, c, d, 46); - R3(d, e, a, b, c, 47); - R3(c, d, e, a, b, 48); - R3(b, c, d, e, a, 49); - R3(a, b, c, d, e, 50); - R3(e, a, b, c, d, 51); - R3(d, e, a, b, c, 52); - R3(c, d, e, a, b, 53); - R3(b, c, d, e, a, 54); - R3(a, b, c, d, e, 55); - R3(e, a, b, c, d, 56); - R3(d, e, a, b, c, 57); - R3(c, d, e, a, b, 58); - R3(b, c, d, e, a, 59); - R4(a, b, c, d, e, 60); - R4(e, a, b, c, d, 61); - R4(d, e, a, b, c, 62); - R4(c, d, e, a, b, 63); - R4(b, c, d, e, a, 64); - R4(a, b, c, d, e, 65); - R4(e, a, b, c, d, 66); - R4(d, e, a, b, c, 67); - R4(c, d, e, a, b, 68); - R4(b, c, d, e, a, 69); - R4(a, b, c, d, e, 70); - R4(e, a, b, c, d, 71); - R4(d, e, a, b, c, 72); - R4(c, d, e, a, b, 73); - R4(b, c, d, e, a, 74); - R4(a, b, c, d, e, 75); - R4(e, a, b, c, d, 76); - R4(d, e, a, b, c, 77); - R4(c, d, e, a, b, 78); - R4(b, c, d, e, a, 79); - /* Add the working vars back into context.state[] */ - state[0] += a; - state[1] += b; - state[2] += c; - state[3] += d; - state[4] += e; - /* Wipe variables */ - a = b = c = d = e = 0; -} - -/* SHA1Init - Initialize new context */ - -void SHA1Init(SHA1_CTX * context) -{ - /* SHA1 initialization constants */ - context->state[0] = 0x67452301; - context->state[1] = 0xEFCDAB89; - context->state[2] = 0x98BADCFE; - context->state[3] = 0x10325476; - context->state[4] = 0xC3D2E1F0; - context->count[0] = context->count[1] = 0; -} - -/* Run your data through this. */ - -void SHA1Update(SHA1_CTX * context, const unsigned char *data, uint32_t len) -{ /* - JHB */ - uint32_t i, j; /* JHB */ - -#ifdef VERBOSE - SHAPrintContext(context, "before"); -#endif - j = (context->count[0] >> 3) & 63; - if ((context->count[0] += len << 3) < (len << 3)) - context->count[1]++; - context->count[1] += (len >> 29); - if ((j + len) > 63) { - memcpy(&context->buffer[j], data, (i = 64 - j)); - SHA1Transform(context->state, context->buffer); - for (; i + 63 < len; i += 64) { - SHA1Transform(context->state, &data[i]); - } - j = 0; - } else - i = 0; - memcpy(&context->buffer[j], &data[i], len - i); -#ifdef VERBOSE - SHAPrintContext(context, "after "); -#endif -} - -/* Add padding and return the message digest. */ - -void SHA1Final(unsigned char digest[20], SHA1_CTX * context) -{ - uint32_t i; /* JHB */ - unsigned char finalcount[8]; - - for (i = 0; i < 8; i++) { - finalcount[i] = (unsigned char)((context->count[(i >= 4 ? 0 : 1)] - >> ((3 - (i & 3)) * 8)) & 255); /* Endian independent */ - } - SHA1Update(context, (unsigned char *)"\200", 1); - while ((context->count[0] & 504) != 448) { - SHA1Update(context, (unsigned char *)"\0", 1); - } - SHA1Update(context, finalcount, 8); /* Should cause a SHA1Transform() - */ - for (i = 0; i < 20; i++) { - digest[i] = (unsigned char) - ((context->state[i >> 2] >> ((3 - (i & 3)) * 8)) & 255); - } - /* Wipe variables */ - i = 0; /* JHB */ - memset(context->buffer, 0, 64); - memset(context->state, 0, 20); - memset(context->count, 0, 8); - memset(finalcount, 0, 8); /* SWR */ -#ifdef SHA1HANDSOFF /* make SHA1Transform overwrite it's own static vars */ - SHA1Transform(context->state, context->buffer); -#endif -} - -/*************************************************************/ - -/* This is not quite the MIME base64 algorithm: it uses _ instead of /, - and instead of padding the output with = characters we just make the - output shorter. */ -char *mybase64(uint8_t digest[20]) -{ - static const char charz[] - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+_"; - uint8_t input[21]; - static char output[28]; - int i, j; - uint8_t *p; - char *q; - uint32_t bv; - - memcpy(input, digest, 20); - input[20] = 0; /* Pad to multiple of 3 bytes */ - - p = input; - q = output; - for (i = 0; i < 7; i++) { - bv = (p[0] << 16) | (p[1] << 8) | p[2]; - p += 3; - for (j = 0; j < 4; j++) { - *q++ = charz[(bv >> 18) & 0x3f]; - bv <<= 6; - } - } - *--q = '\0'; /* The last character is not significant */ - return output; -} - -static void sha1hash_exit(void) -{ - // Nothing to do -} - -// Define entry and exit points. -MODULE_INIT(sha1hash_init); -MODULE_EXIT(sha1hash_exit); diff --git a/com32/elflink/modules/sha256crypt.c b/com32/elflink/modules/sha256crypt.c deleted file mode 100644 index 61b23f2..0000000 --- a/com32/elflink/modules/sha256crypt.c +++ /dev/null @@ -1,559 +0,0 @@ -/* SHA256-based Unix crypt implementation. - Released into the Public Domain by Ulrich Drepper <drepper at redhat.com>. */ - -#include <alloca.h> -#include <endian.h> -#include <errno.h> -#include <limits.h> -#include <stdint.h> -#include <stdbool.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <minmax.h> -#include <sys/types.h> -#include <sys/module.h> - -#include "xcrypt.h" - -static int sha256crypt_init(void) -{ - return 0; // Nothing to do; return success -} - -#define MIN(x,y) min(x,y) -#define MAX(x,y) max(x,y) - -/* Structure to save state of computation between the single steps. */ -struct sha256_ctx { - uint32_t H[8]; - - uint32_t total[2]; - uint32_t buflen; - char buffer[128]; /* NB: always correctly aligned for uint32_t. */ -}; - -#if __BYTE_ORDER == __LITTLE_ENDIAN -# define SWAP(n) \ - (((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24)) -#else -# define SWAP(n) (n) -#endif - -/* This array contains the bytes used to pad the buffer to the next - 64-byte boundary. (FIPS 180-2:5.1.1) */ -static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ... */ }; - -/* Constants for SHA256 from FIPS 180-2:4.2.2. */ -static const uint32_t K[64] = { - 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, - 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, - 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, - 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, - 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, - 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, - 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, - 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, - 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, - 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, - 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, - 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, - 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, - 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, - 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, - 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 -}; - -/* Process LEN bytes of BUFFER, accumulating context into CTX. - It is assumed that LEN % 64 == 0. */ -static void -sha256_process_block(const void *buffer, size_t len, struct sha256_ctx *ctx) -{ - unsigned int t; - const uint32_t *words = buffer; - size_t nwords = len / sizeof(uint32_t); - uint32_t a = ctx->H[0]; - uint32_t b = ctx->H[1]; - uint32_t c = ctx->H[2]; - uint32_t d = ctx->H[3]; - uint32_t e = ctx->H[4]; - uint32_t f = ctx->H[5]; - uint32_t g = ctx->H[6]; - uint32_t h = ctx->H[7]; - - /* First increment the byte count. FIPS 180-2 specifies the possible - length of the file up to 2^64 bits. Here we only compute the - number of bytes. Do a double word increment. */ - ctx->total[0] += len; - if (ctx->total[0] < len) - ++ctx->total[1]; - - /* Process all bytes in the buffer with 64 bytes in each round of - the loop. */ - while (nwords > 0) { - uint32_t W[64]; - uint32_t a_save = a; - uint32_t b_save = b; - uint32_t c_save = c; - uint32_t d_save = d; - uint32_t e_save = e; - uint32_t f_save = f; - uint32_t g_save = g; - uint32_t h_save = h; - - /* Operators defined in FIPS 180-2:4.1.2. */ -#define Ch(x, y, z) ((x & y) ^ (~x & z)) -#define Maj(x, y, z) ((x & y) ^ (x & z) ^ (y & z)) -#define S0(x) (CYCLIC (x, 2) ^ CYCLIC (x, 13) ^ CYCLIC (x, 22)) -#define S1(x) (CYCLIC (x, 6) ^ CYCLIC (x, 11) ^ CYCLIC (x, 25)) -#define R0(x) (CYCLIC (x, 7) ^ CYCLIC (x, 18) ^ (x >> 3)) -#define R1(x) (CYCLIC (x, 17) ^ CYCLIC (x, 19) ^ (x >> 10)) - - /* It is unfortunate that C does not provide an operator for - cyclic rotation. Hope the C compiler is smart enough. */ -#define CYCLIC(w, s) ((w >> s) | (w << (32 - s))) - - /* Compute the message schedule according to FIPS 180-2:6.2.2 step 2. */ - for (t = 0; t < 16; ++t) { - W[t] = SWAP(*words); - ++words; - } - for (t = 16; t < 64; ++t) - W[t] = R1(W[t - 2]) + W[t - 7] + R0(W[t - 15]) + W[t - 16]; - - /* The actual computation according to FIPS 180-2:6.2.2 step 3. */ - for (t = 0; t < 64; ++t) { - uint32_t T1 = h + S1(e) + Ch(e, f, g) + K[t] + W[t]; - uint32_t T2 = S0(a) + Maj(a, b, c); - h = g; - g = f; - f = e; - e = d + T1; - d = c; - c = b; - b = a; - a = T1 + T2; - } - - /* Add the starting values of the context according to FIPS 180-2:6.2.2 - step 4. */ - a += a_save; - b += b_save; - c += c_save; - d += d_save; - e += e_save; - f += f_save; - g += g_save; - h += h_save; - - /* Prepare for the next round. */ - nwords -= 16; - } - - /* Put checksum in context given as argument. */ - ctx->H[0] = a; - ctx->H[1] = b; - ctx->H[2] = c; - ctx->H[3] = d; - ctx->H[4] = e; - ctx->H[5] = f; - ctx->H[6] = g; - ctx->H[7] = h; -} - -/* Initialize structure containing state of computation. - (FIPS 180-2:5.3.2) */ -static void sha256_init_ctx(struct sha256_ctx *ctx) -{ - ctx->H[0] = 0x6a09e667; - ctx->H[1] = 0xbb67ae85; - ctx->H[2] = 0x3c6ef372; - ctx->H[3] = 0xa54ff53a; - ctx->H[4] = 0x510e527f; - ctx->H[5] = 0x9b05688c; - ctx->H[6] = 0x1f83d9ab; - ctx->H[7] = 0x5be0cd19; - - ctx->total[0] = ctx->total[1] = 0; - ctx->buflen = 0; -} - -/* Process the remaining bytes in the internal buffer and the usual - prolog according to the standard and write the result to RESBUF. - - IMPORTANT: On some systems it is required that RESBUF is correctly - aligned for a 32 bits value. */ -static void *sha256_finish_ctx(struct sha256_ctx *ctx, void *resbuf) -{ - unsigned int i; - /* Take yet unprocessed bytes into account. */ - uint32_t bytes = ctx->buflen; - size_t pad; - - /* Now count remaining bytes. */ - ctx->total[0] += bytes; - if (ctx->total[0] < bytes) - ++ctx->total[1]; - - pad = bytes >= 56 ? 64 + 56 - bytes : 56 - bytes; - memcpy(&ctx->buffer[bytes], fillbuf, pad); - - /* Put the 64-bit file length in *bits* at the end of the buffer. */ - *(uint32_t *) & ctx->buffer[bytes + pad + 4] = SWAP(ctx->total[0] << 3); - *(uint32_t *) & ctx->buffer[bytes + pad] = SWAP((ctx->total[1] << 3) | - (ctx->total[0] >> 29)); - - /* Process last bytes. */ - sha256_process_block(ctx->buffer, bytes + pad + 8, ctx); - - /* Put result from CTX in first 32 bytes following RESBUF. */ - for (i = 0; i < 8; ++i) - ((uint32_t *) resbuf)[i] = SWAP(ctx->H[i]); - - return resbuf; -} - -static void -sha256_process_bytes(const void *buffer, size_t len, struct sha256_ctx *ctx) -{ - /* When we already have some bits in our internal buffer concatenate - both inputs first. */ - if (ctx->buflen != 0) { - size_t left_over = ctx->buflen; - size_t add = 128 - left_over > len ? len : 128 - left_over; - - memcpy(&ctx->buffer[left_over], buffer, add); - ctx->buflen += add; - - if (ctx->buflen > 64) { - sha256_process_block(ctx->buffer, ctx->buflen & ~63, ctx); - - ctx->buflen &= 63; - /* The regions in the following copy operation cannot overlap. */ - memcpy(ctx->buffer, &ctx->buffer[(left_over + add) & ~63], - ctx->buflen); - } - - buffer = (const char *)buffer + add; - len -= add; - } - - /* Process available complete blocks. */ - if (len >= 64) { -/* To check alignment gcc has an appropriate operator. Other - compilers don't. */ -#if __GNUC__ >= 2 -# define UNALIGNED_P(p) (((uintptr_t) p) % __alignof__ (uint32_t) != 0) -#else -# define UNALIGNED_P(p) (((uintptr_t) p) % sizeof (uint32_t) != 0) -#endif - if (UNALIGNED_P(buffer)) - while (len > 64) { - sha256_process_block(memcpy(ctx->buffer, buffer, 64), 64, ctx); - buffer = (const char *)buffer + 64; - len -= 64; - } else { - sha256_process_block(buffer, len & ~63, ctx); - buffer = (const char *)buffer + (len & ~63); - len &= 63; - } - } - - /* Move remaining bytes into internal buffer. */ - if (len > 0) { - size_t left_over = ctx->buflen; - - memcpy(&ctx->buffer[left_over], buffer, len); - left_over += len; - if (left_over >= 64) { - sha256_process_block(ctx->buffer, 64, ctx); - left_over -= 64; - memcpy(ctx->buffer, &ctx->buffer[64], left_over); - } - ctx->buflen = left_over; - } -} - -/* Define our magic string to mark salt for SHA256 "encryption" - replacement. */ -static const char sha256_salt_prefix[] = "$5$"; - -/* Prefix for optional rounds specification. */ -static const char sha256_rounds_prefix[] = "rounds="; - -/* Maximum salt string length. */ -#define SALT_LEN_MAX 16 -/* Default number of rounds if not explicitly specified. */ -#define ROUNDS_DEFAULT 5000 -/* Minimum number of rounds. */ -#define ROUNDS_MIN 1000 -/* Maximum number of rounds. */ -#define ROUNDS_MAX 999999999 - -/* Table with characters for base64 transformation. */ -static const char b64t[64] - "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; - -static char *sha256_crypt_r(const char *key, const char *salt, char *buffer, - int buflen) -{ - unsigned char alt_result[32] - __attribute__ ((__aligned__(__alignof__(uint32_t)))); - unsigned char temp_result[32] - __attribute__ ((__aligned__(__alignof__(uint32_t)))); - struct sha256_ctx ctx; - struct sha256_ctx alt_ctx; - size_t salt_len; - size_t key_len; - size_t cnt; - char *cp; - char *copied_key = NULL; - char *copied_salt = NULL; - char *p_bytes; - char *s_bytes; - /* Default number of rounds. */ - size_t rounds = ROUNDS_DEFAULT; - bool rounds_custom = false; - - /* Find beginning of salt string. The prefix should normally always - be present. Just in case it is not. */ - if (strncmp(sha256_salt_prefix, salt, sizeof(sha256_salt_prefix) - 1) == 0) - /* Skip salt prefix. */ - salt += sizeof(sha256_salt_prefix) - 1; - - if (strncmp(salt, sha256_rounds_prefix, sizeof(sha256_rounds_prefix) - 1) - == 0) { - const char *num = salt + sizeof(sha256_rounds_prefix) - 1; - char *endp; - unsigned long int srounds = strtoul(num, &endp, 10); - if (*endp == '$') { - salt = endp + 1; - rounds = MAX(ROUNDS_MIN, MIN(srounds, ROUNDS_MAX)); - rounds_custom = true; - } - } - - salt_len = MIN(strcspn(salt, "$"), SALT_LEN_MAX); - key_len = strlen(key); - - if ((key - (char *)0) % __alignof__(uint32_t) != 0) { - char *tmp = (char *)alloca(key_len + __alignof__(uint32_t)); - key = copied_key = memcpy(tmp + __alignof__(uint32_t) - - (tmp - (char *)0) % __alignof__(uint32_t), - key, key_len); - } - - if ((salt - (char *)0) % __alignof__(uint32_t) != 0) { - char *tmp = (char *)alloca(salt_len + __alignof__(uint32_t)); - salt = copied_salt = memcpy(tmp + __alignof__(uint32_t) - - (tmp - (char *)0) % __alignof__(uint32_t), - salt, salt_len); - } - - /* Prepare for the real work. */ - sha256_init_ctx(&ctx); - - /* Add the key string. */ - sha256_process_bytes(key, key_len, &ctx); - - /* The last part is the salt string. This must be at most 8 - characters and it ends at the first `$' character (for - compatibility with existing implementations). */ - sha256_process_bytes(salt, salt_len, &ctx); - - /* Compute alternate SHA256 sum with input KEY, SALT, and KEY. The - final result will be added to the first context. */ - sha256_init_ctx(&alt_ctx); - - /* Add key. */ - sha256_process_bytes(key, key_len, &alt_ctx); - - /* Add salt. */ - sha256_process_bytes(salt, salt_len, &alt_ctx); - - /* Add key again. */ - sha256_process_bytes(key, key_len, &alt_ctx); - - /* Now get result of this (32 bytes) and add it to the other - context. */ - sha256_finish_ctx(&alt_ctx, alt_result); - - /* Add for any character in the key one byte of the alternate sum. */ - for (cnt = key_len; cnt > 32; cnt -= 32) - sha256_process_bytes(alt_result, 32, &ctx); - sha256_process_bytes(alt_result, cnt, &ctx); - - /* Take the binary representation of the length of the key and for every - 1 add the alternate sum, for every 0 the key. */ - for (cnt = key_len; cnt > 0; cnt >>= 1) - if ((cnt & 1) != 0) - sha256_process_bytes(alt_result, 32, &ctx); - else - sha256_process_bytes(key, key_len, &ctx); - - /* Create intermediate result. */ - sha256_finish_ctx(&ctx, alt_result); - - /* Start computation of P byte sequence. */ - sha256_init_ctx(&alt_ctx); - - /* For every character in the password add the entire password. */ - for (cnt = 0; cnt < key_len; ++cnt) - sha256_process_bytes(key, key_len, &alt_ctx); - - /* Finish the digest. */ - sha256_finish_ctx(&alt_ctx, temp_result); - - /* Create byte sequence P. */ - cp = p_bytes = alloca(key_len); - for (cnt = key_len; cnt >= 32; cnt -= 32) - cp = mempcpy(cp, temp_result, 32); - memcpy(cp, temp_result, cnt); - - /* Start computation of S byte sequence. */ - sha256_init_ctx(&alt_ctx); - - /* For every character in the password add the entire password. */ - for (cnt = 0; cnt < 16 + alt_result[0]; ++cnt) - sha256_process_bytes(salt, salt_len, &alt_ctx); - - /* Finish the digest. */ - sha256_finish_ctx(&alt_ctx, temp_result); - - /* Create byte sequence S. */ - cp = s_bytes = alloca(salt_len); - for (cnt = salt_len; cnt >= 32; cnt -= 32) - cp = mempcpy(cp, temp_result, 32); - memcpy(cp, temp_result, cnt); - - /* Repeatedly run the collected hash value through SHA256 to burn - CPU cycles. */ - for (cnt = 0; cnt < rounds; ++cnt) { - /* New context. */ - sha256_init_ctx(&ctx); - - /* Add key or last result. */ - if ((cnt & 1) != 0) - sha256_process_bytes(p_bytes, key_len, &ctx); - else - sha256_process_bytes(alt_result, 32, &ctx); - - /* Add salt for numbers not divisible by 3. */ - if (cnt % 3 != 0) - sha256_process_bytes(s_bytes, salt_len, &ctx); - - /* Add key for numbers not divisible by 7. */ - if (cnt % 7 != 0) - sha256_process_bytes(p_bytes, key_len, &ctx); - - /* Add key or last result. */ - if ((cnt & 1) != 0) - sha256_process_bytes(alt_result, 32, &ctx); - else - sha256_process_bytes(p_bytes, key_len, &ctx); - - /* Create intermediate result. */ - sha256_finish_ctx(&ctx, alt_result); - } - - /* Now we can construct the result string. It consists of three - parts. */ - cp = stpncpy(buffer, sha256_salt_prefix, MAX(0, buflen)); - buflen -= sizeof(sha256_salt_prefix) - 1; - - if (rounds_custom) { - int n = snprintf(cp, MAX(0, buflen), "%s%zu$", - sha256_rounds_prefix, rounds); - cp += n; - buflen -= n; - } - - cp = stpncpy(cp, salt, MIN((size_t) MAX(0, buflen), salt_len)); - buflen -= MIN((size_t) MAX(0, buflen), salt_len); - - if (buflen > 0) { - *cp++ = '$'; - --buflen; - } -#define b64_from_24bit(B2, B1, B0, N) \ - do { \ - unsigned int w = ((B2) << 16) | ((B1) << 8) | (B0); \ - int n = (N); \ - while (n-- > 0 && buflen > 0) \ - { \ - *cp++ = b64t[w & 0x3f]; \ - --buflen; \ - w >>= 6; \ - } \ - } while (0) - - b64_from_24bit(alt_result[0], alt_result[10], alt_result[20], 4); - b64_from_24bit(alt_result[21], alt_result[1], alt_result[11], 4); - b64_from_24bit(alt_result[12], alt_result[22], alt_result[2], 4); - b64_from_24bit(alt_result[3], alt_result[13], alt_result[23], 4); - b64_from_24bit(alt_result[24], alt_result[4], alt_result[14], 4); - b64_from_24bit(alt_result[15], alt_result[25], alt_result[5], 4); - b64_from_24bit(alt_result[6], alt_result[16], alt_result[26], 4); - b64_from_24bit(alt_result[27], alt_result[7], alt_result[17], 4); - b64_from_24bit(alt_result[18], alt_result[28], alt_result[8], 4); - b64_from_24bit(alt_result[9], alt_result[19], alt_result[29], 4); - b64_from_24bit(0, alt_result[31], alt_result[30], 3); - if (buflen <= 0) { - errno = ERANGE; - buffer = NULL; - } else - *cp = '\0'; /* Terminate the string. */ - - /* Clear the buffer for the intermediate result so that people - attaching to processes or reading core dumps cannot get any - information. We do it in this way to clear correct_words[] - inside the SHA256 implementation as well. */ - sha256_init_ctx(&ctx); - sha256_finish_ctx(&ctx, alt_result); - memset(temp_result, '\0', sizeof(temp_result)); - memset(p_bytes, '\0', key_len); - memset(s_bytes, '\0', salt_len); - memset(&ctx, '\0', sizeof(ctx)); - memset(&alt_ctx, '\0', sizeof(alt_ctx)); - if (copied_key != NULL) - memset(copied_key, '\0', key_len); - if (copied_salt != NULL) - memset(copied_salt, '\0', salt_len); - - return buffer; -} - -/* This entry point is equivalent to the `crypt' function in Unix - libcs. */ -char *sha256_crypt(const char *key, const char *salt) -{ - /* We don't want to have an arbitrary limit in the size of the - password. We can compute an upper bound for the size of the - result in advance and so we can prepare the buffer we pass to - `sha256_crypt_r'. */ - static char *buffer; - static int buflen; - int needed = (sizeof(sha256_salt_prefix) - 1 - + sizeof(sha256_rounds_prefix) + 9 + 1 - + strlen(salt) + 1 + 43 + 1); - - if (buflen < needed) { - char *new_buffer = (char *)realloc(buffer, needed); - if (new_buffer == NULL) - return NULL; - - buffer = new_buffer; - buflen = needed; - } - - return sha256_crypt_r(key, salt, buffer, buflen); -} - -static void sha256crypt_exit(void) -{ - // Nothing to do -} - -// Define entry and exit points. -MODULE_INIT(sha256crypt_init); -MODULE_EXIT(sha256crypt_exit); diff --git a/com32/elflink/modules/sha512crypt.c b/com32/elflink/modules/sha512crypt.c deleted file mode 100644 index 617423c..0000000 --- a/com32/elflink/modules/sha512crypt.c +++ /dev/null @@ -1,606 +0,0 @@ -/* SHA512-based Unix crypt implementation. - Released into the Public Domain by Ulrich Drepper <drepper at redhat.com>. */ - -#include <alloca.h> -#include <endian.h> -#include <errno.h> -#include <limits.h> -#include <stdbool.h> -#include <stdint.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <minmax.h> -#include <sys/types.h> -#include <sys/module.h> - -#include "xcrypt.h" - -static int sha512crypt_init() -{ - return 0; // Nothing to do; return success -} - -#define MIN(x,y) min(x,y) -#define MAX(x,y) max(x,y) - -/* Structure to save state of computation between the single steps. */ -struct sha512_ctx { - uint64_t H[8]; - - uint64_t total[2]; - uint64_t buflen; - char buffer[256]; /* NB: always correctly aligned for uint64_t. */ -}; - -#if __BYTE_ORDER == __LITTLE_ENDIAN -# define SWAP(n) \ - (((n) << 56) \ - | (((n) & 0xff00) << 40) \ - | (((n) & 0xff0000) << 24) \ - | (((n) & 0xff000000) << 8) \ - | (((n) >> 8) & 0xff000000) \ - | (((n) >> 24) & 0xff0000) \ - | (((n) >> 40) & 0xff00) \ - | ((n) >> 56)) -#else -# define SWAP(n) (n) -#endif - -/* This array contains the bytes used to pad the buffer to the next - 64-byte boundary. (FIPS 180-2:5.1.2) */ -static const unsigned char fillbuf[128] = { 0x80, 0 /* , 0, 0, ... */ }; - -/* Constants for SHA512 from FIPS 180-2:4.2.3. */ -static const uint64_t K[80] = { - UINT64_C(0x428a2f98d728ae22), UINT64_C(0x7137449123ef65cd), - UINT64_C(0xb5c0fbcfec4d3b2f), UINT64_C(0xe9b5dba58189dbbc), - UINT64_C(0x3956c25bf348b538), UINT64_C(0x59f111f1b605d019), - UINT64_C(0x923f82a4af194f9b), UINT64_C(0xab1c5ed5da6d8118), - UINT64_C(0xd807aa98a3030242), UINT64_C(0x12835b0145706fbe), - UINT64_C(0x243185be4ee4b28c), UINT64_C(0x550c7dc3d5ffb4e2), - UINT64_C(0x72be5d74f27b896f), UINT64_C(0x80deb1fe3b1696b1), - UINT64_C(0x9bdc06a725c71235), UINT64_C(0xc19bf174cf692694), - UINT64_C(0xe49b69c19ef14ad2), UINT64_C(0xefbe4786384f25e3), - UINT64_C(0x0fc19dc68b8cd5b5), UINT64_C(0x240ca1cc77ac9c65), - UINT64_C(0x2de92c6f592b0275), UINT64_C(0x4a7484aa6ea6e483), - UINT64_C(0x5cb0a9dcbd41fbd4), UINT64_C(0x76f988da831153b5), - UINT64_C(0x983e5152ee66dfab), UINT64_C(0xa831c66d2db43210), - UINT64_C(0xb00327c898fb213f), UINT64_C(0xbf597fc7beef0ee4), - UINT64_C(0xc6e00bf33da88fc2), UINT64_C(0xd5a79147930aa725), - UINT64_C(0x06ca6351e003826f), UINT64_C(0x142929670a0e6e70), - UINT64_C(0x27b70a8546d22ffc), UINT64_C(0x2e1b21385c26c926), - UINT64_C(0x4d2c6dfc5ac42aed), UINT64_C(0x53380d139d95b3df), - UINT64_C(0x650a73548baf63de), UINT64_C(0x766a0abb3c77b2a8), - UINT64_C(0x81c2c92e47edaee6), UINT64_C(0x92722c851482353b), - UINT64_C(0xa2bfe8a14cf10364), UINT64_C(0xa81a664bbc423001), - UINT64_C(0xc24b8b70d0f89791), UINT64_C(0xc76c51a30654be30), - UINT64_C(0xd192e819d6ef5218), UINT64_C(0xd69906245565a910), - UINT64_C(0xf40e35855771202a), UINT64_C(0x106aa07032bbd1b8), - UINT64_C(0x19a4c116b8d2d0c8), UINT64_C(0x1e376c085141ab53), - UINT64_C(0x2748774cdf8eeb99), UINT64_C(0x34b0bcb5e19b48a8), - UINT64_C(0x391c0cb3c5c95a63), UINT64_C(0x4ed8aa4ae3418acb), - UINT64_C(0x5b9cca4f7763e373), UINT64_C(0x682e6ff3d6b2b8a3), - UINT64_C(0x748f82ee5defb2fc), UINT64_C(0x78a5636f43172f60), - UINT64_C(0x84c87814a1f0ab72), UINT64_C(0x8cc702081a6439ec), - UINT64_C(0x90befffa23631e28), UINT64_C(0xa4506cebde82bde9), - UINT64_C(0xbef9a3f7b2c67915), UINT64_C(0xc67178f2e372532b), - UINT64_C(0xca273eceea26619c), UINT64_C(0xd186b8c721c0c207), - UINT64_C(0xeada7dd6cde0eb1e), UINT64_C(0xf57d4f7fee6ed178), - UINT64_C(0x06f067aa72176fba), UINT64_C(0x0a637dc5a2c898a6), - UINT64_C(0x113f9804bef90dae), UINT64_C(0x1b710b35131c471b), - UINT64_C(0x28db77f523047d84), UINT64_C(0x32caab7b40c72493), - UINT64_C(0x3c9ebe0a15c9bebc), UINT64_C(0x431d67c49c100d4c), - UINT64_C(0x4cc5d4becb3e42b6), UINT64_C(0x597f299cfc657e2a), - UINT64_C(0x5fcb6fab3ad6faec), UINT64_C(0x6c44198c4a475817) -}; - -/* Process LEN bytes of BUFFER, accumulating context into CTX. - It is assumed that LEN % 128 == 0. */ -static void -sha512_process_block(const void *buffer, size_t len, struct sha512_ctx *ctx) -{ - unsigned int t; - const uint64_t *words = buffer; - size_t nwords = len / sizeof(uint64_t); - uint64_t a = ctx->H[0]; - uint64_t b = ctx->H[1]; - uint64_t c = ctx->H[2]; - uint64_t d = ctx->H[3]; - uint64_t e = ctx->H[4]; - uint64_t f = ctx->H[5]; - uint64_t g = ctx->H[6]; - uint64_t h = ctx->H[7]; - - /* First increment the byte count. FIPS 180-2 specifies the possible - length of the file up to 2^128 bits. Here we only compute the - number of bytes. Do a double word increment. */ - ctx->total[0] += len; - if (ctx->total[0] < len) - ++ctx->total[1]; - - /* Process all bytes in the buffer with 128 bytes in each round of - the loop. */ - while (nwords > 0) { - uint64_t W[80]; - uint64_t a_save = a; - uint64_t b_save = b; - uint64_t c_save = c; - uint64_t d_save = d; - uint64_t e_save = e; - uint64_t f_save = f; - uint64_t g_save = g; - uint64_t h_save = h; - - /* Operators defined in FIPS 180-2:4.1.2. */ -#define Ch(x, y, z) ((x & y) ^ (~x & z)) -#define Maj(x, y, z) ((x & y) ^ (x & z) ^ (y & z)) -#define S0(x) (CYCLIC (x, 28) ^ CYCLIC (x, 34) ^ CYCLIC (x, 39)) -#define S1(x) (CYCLIC (x, 14) ^ CYCLIC (x, 18) ^ CYCLIC (x, 41)) -#define R0(x) (CYCLIC (x, 1) ^ CYCLIC (x, 8) ^ (x >> 7)) -#define R1(x) (CYCLIC (x, 19) ^ CYCLIC (x, 61) ^ (x >> 6)) - - /* It is unfortunate that C does not provide an operator for - cyclic rotation. Hope the C compiler is smart enough. */ -#define CYCLIC(w, s) ((w >> s) | (w << (64 - s))) - - /* Compute the message schedule according to FIPS 180-2:6.3.2 step 2. */ - for (t = 0; t < 16; ++t) { - W[t] = SWAP(*words); - ++words; - } - for (t = 16; t < 80; ++t) - W[t] = R1(W[t - 2]) + W[t - 7] + R0(W[t - 15]) + W[t - 16]; - - /* The actual computation according to FIPS 180-2:6.3.2 step 3. */ - for (t = 0; t < 80; ++t) { - uint64_t T1 = h + S1(e) + Ch(e, f, g) + K[t] + W[t]; - uint64_t T2 = S0(a) + Maj(a, b, c); - h = g; - g = f; - f = e; - e = d + T1; - d = c; - c = b; - b = a; - a = T1 + T2; - } - - /* Add the starting values of the context according to FIPS 180-2:6.3.2 - step 4. */ - a += a_save; - b += b_save; - c += c_save; - d += d_save; - e += e_save; - f += f_save; - g += g_save; - h += h_save; - - /* Prepare for the next round. */ - nwords -= 16; - } - - /* Put checksum in context given as argument. */ - ctx->H[0] = a; - ctx->H[1] = b; - ctx->H[2] = c; - ctx->H[3] = d; - ctx->H[4] = e; - ctx->H[5] = f; - ctx->H[6] = g; - ctx->H[7] = h; -} - -/* Initialize structure containing state of computation. - (FIPS 180-2:5.3.3) */ -static void sha512_init_ctx(struct sha512_ctx *ctx) -{ - ctx->H[0] = UINT64_C(0x6a09e667f3bcc908); - ctx->H[1] = UINT64_C(0xbb67ae8584caa73b); - ctx->H[2] = UINT64_C(0x3c6ef372fe94f82b); - ctx->H[3] = UINT64_C(0xa54ff53a5f1d36f1); - ctx->H[4] = UINT64_C(0x510e527fade682d1); - ctx->H[5] = UINT64_C(0x9b05688c2b3e6c1f); - ctx->H[6] = UINT64_C(0x1f83d9abfb41bd6b); - ctx->H[7] = UINT64_C(0x5be0cd19137e2179); - - ctx->total[0] = ctx->total[1] = 0; - ctx->buflen = 0; -} - -/* Process the remaining bytes in the internal buffer and the usual - prolog according to the standard and write the result to RESBUF. - - IMPORTANT: On some systems it is required that RESBUF is correctly - aligned for a 32 bits value. */ -static void *sha512_finish_ctx(struct sha512_ctx *ctx, void *resbuf) -{ - unsigned int i; - /* Take yet unprocessed bytes into account. */ - uint64_t bytes = ctx->buflen; - size_t pad; - - /* Now count remaining bytes. */ - ctx->total[0] += bytes; - if (ctx->total[0] < bytes) - ++ctx->total[1]; - - pad = bytes >= 112 ? 128 + 112 - bytes : 112 - bytes; - memcpy(&ctx->buffer[bytes], fillbuf, pad); - - /* Put the 128-bit file length in *bits* at the end of the buffer. */ - *(uint64_t *) & ctx->buffer[bytes + pad + 8] = SWAP(ctx->total[0] << 3); - *(uint64_t *) & ctx->buffer[bytes + pad] = SWAP((ctx->total[1] << 3) | - (ctx->total[0] >> 61)); - - /* Process last bytes. */ - sha512_process_block(ctx->buffer, bytes + pad + 16, ctx); - - /* Put result from CTX in first 64 bytes following RESBUF. */ - for (i = 0; i < 8; ++i) - ((uint64_t *) resbuf)[i] = SWAP(ctx->H[i]); - - return resbuf; -} - -static void -sha512_process_bytes(const void *buffer, size_t len, struct sha512_ctx *ctx) -{ - /* When we already have some bits in our internal buffer concatenate - both inputs first. */ - if (ctx->buflen != 0) { - size_t left_over = ctx->buflen; - size_t add = 256 - left_over > len ? len : 256 - left_over; - - memcpy(&ctx->buffer[left_over], buffer, add); - ctx->buflen += add; - - if (ctx->buflen > 128) { - sha512_process_block(ctx->buffer, ctx->buflen & ~127, ctx); - - ctx->buflen &= 127; - /* The regions in the following copy operation cannot overlap. */ - memcpy(ctx->buffer, &ctx->buffer[(left_over + add) & ~127], - ctx->buflen); - } - - buffer = (const char *)buffer + add; - len -= add; - } - - /* Process available complete blocks. */ - if (len >= 128) { -#if !_STRING_ARCH_unaligned -/* To check alignment gcc has an appropriate operator. Other - compilers don't. */ -# if __GNUC__ >= 2 -# define UNALIGNED_P(p) (((uintptr_t) p) % __alignof__ (uint64_t) != 0) -# else -# define UNALIGNED_P(p) (((uintptr_t) p) % sizeof (uint64_t) != 0) -# endif - if (UNALIGNED_P(buffer)) - while (len > 128) { - sha512_process_block(memcpy(ctx->buffer, buffer, 128), 128, - ctx); - buffer = (const char *)buffer + 128; - len -= 128; - } else -#endif - { - sha512_process_block(buffer, len & ~127, ctx); - buffer = (const char *)buffer + (len & ~127); - len &= 127; - } - } - - /* Move remaining bytes into internal buffer. */ - if (len > 0) { - size_t left_over = ctx->buflen; - - memcpy(&ctx->buffer[left_over], buffer, len); - left_over += len; - if (left_over >= 128) { - sha512_process_block(ctx->buffer, 128, ctx); - left_over -= 128; - memcpy(ctx->buffer, &ctx->buffer[128], left_over); - } - ctx->buflen = left_over; - } -} - -/* Define our magic string to mark salt for SHA512 "encryption" - replacement. */ -static const char sha512_salt_prefix[] = "$6$"; - -/* Prefix for optional rounds specification. */ -static const char sha512_rounds_prefix[] = "rounds="; - -/* Maximum salt string length. */ -#define SALT_LEN_MAX 16 -/* Default number of rounds if not explicitly specified. */ -#define ROUNDS_DEFAULT 5000 -/* Minimum number of rounds. */ -#define ROUNDS_MIN 1000 -/* Maximum number of rounds. */ -#define ROUNDS_MAX 999999999 - -/* Table with characters for base64 transformation. */ -static const char b64t[64] - "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; - -static char *sha512_crypt_r(const char *key, const char *salt, char *buffer, - int buflen) -{ - unsigned char alt_result[64] - __attribute__ ((__aligned__(__alignof__(uint64_t)))); - unsigned char temp_result[64] - __attribute__ ((__aligned__(__alignof__(uint64_t)))); - struct sha512_ctx ctx; - struct sha512_ctx alt_ctx; - size_t salt_len; - size_t key_len; - size_t cnt; - char *cp; - char *copied_key = NULL; - char *copied_salt = NULL; - char *p_bytes; - char *s_bytes; - /* Default number of rounds. */ - size_t rounds = ROUNDS_DEFAULT; - bool rounds_custom = false; - - /* Find beginning of salt string. The prefix should normally always - be present. Just in case it is not. */ - if (strncmp(sha512_salt_prefix, salt, sizeof(sha512_salt_prefix) - 1) == 0) - /* Skip salt prefix. */ - salt += sizeof(sha512_salt_prefix) - 1; - - if (strncmp(salt, sha512_rounds_prefix, sizeof(sha512_rounds_prefix) - 1) - == 0) { - const char *num = salt + sizeof(sha512_rounds_prefix) - 1; - char *endp; - unsigned long int srounds = strtoul(num, &endp, 10); - if (*endp == '$') { - salt = endp + 1; - rounds = MAX(ROUNDS_MIN, MIN(srounds, ROUNDS_MAX)); - rounds_custom = true; - } - } - - salt_len = MIN(strcspn(salt, "$"), SALT_LEN_MAX); - key_len = strlen(key); - - if ((key - (char *)0) % __alignof__(uint64_t) != 0) { - char *tmp = (char *)alloca(key_len + __alignof__(uint64_t)); - key = copied_key = memcpy(tmp + __alignof__(uint64_t) - - (tmp - (char *)0) % __alignof__(uint64_t), - key, key_len); - } - - if ((salt - (char *)0) % __alignof__(uint64_t) != 0) { - char *tmp = (char *)alloca(salt_len + __alignof__(uint64_t)); - salt = copied_salt = memcpy(tmp + __alignof__(uint64_t) - - (tmp - (char *)0) % __alignof__(uint64_t), - salt, salt_len); - } - - /* Prepare for the real work. */ - sha512_init_ctx(&ctx); - - /* Add the key string. */ - sha512_process_bytes(key, key_len, &ctx); - - /* The last part is the salt string. This must be at most 8 - characters and it ends at the first `$' character (for - compatibility with existing implementations). */ - sha512_process_bytes(salt, salt_len, &ctx); - - /* Compute alternate SHA512 sum with input KEY, SALT, and KEY. The - final result will be added to the first context. */ - sha512_init_ctx(&alt_ctx); - - /* Add key. */ - sha512_process_bytes(key, key_len, &alt_ctx); - - /* Add salt. */ - sha512_process_bytes(salt, salt_len, &alt_ctx); - - /* Add key again. */ - sha512_process_bytes(key, key_len, &alt_ctx); - - /* Now get result of this (64 bytes) and add it to the other - context. */ - sha512_finish_ctx(&alt_ctx, alt_result); - - /* Add for any character in the key one byte of the alternate sum. */ - for (cnt = key_len; cnt > 64; cnt -= 64) - sha512_process_bytes(alt_result, 64, &ctx); - sha512_process_bytes(alt_result, cnt, &ctx); - - /* Take the binary representation of the length of the key and for every - 1 add the alternate sum, for every 0 the key. */ - for (cnt = key_len; cnt > 0; cnt >>= 1) - if ((cnt & 1) != 0) - sha512_process_bytes(alt_result, 64, &ctx); - else - sha512_process_bytes(key, key_len, &ctx); - - /* Create intermediate result. */ - sha512_finish_ctx(&ctx, alt_result); - - /* Start computation of P byte sequence. */ - sha512_init_ctx(&alt_ctx); - - /* For every character in the password add the entire password. */ - for (cnt = 0; cnt < key_len; ++cnt) - sha512_process_bytes(key, key_len, &alt_ctx); - - /* Finish the digest. */ - sha512_finish_ctx(&alt_ctx, temp_result); - - /* Create byte sequence P. */ - cp = p_bytes = alloca(key_len); - for (cnt = key_len; cnt >= 64; cnt -= 64) - cp = mempcpy(cp, temp_result, 64); - memcpy(cp, temp_result, cnt); - - /* Start computation of S byte sequence. */ - sha512_init_ctx(&alt_ctx); - - /* For every character in the password add the entire password. */ - for (cnt = 0; cnt < 16 + alt_result[0]; ++cnt) - sha512_process_bytes(salt, salt_len, &alt_ctx); - - /* Finish the digest. */ - sha512_finish_ctx(&alt_ctx, temp_result); - - /* Create byte sequence S. */ - cp = s_bytes = alloca(salt_len); - for (cnt = salt_len; cnt >= 64; cnt -= 64) - cp = mempcpy(cp, temp_result, 64); - memcpy(cp, temp_result, cnt); - - /* Repeatedly run the collected hash value through SHA512 to burn - CPU cycles. */ - for (cnt = 0; cnt < rounds; ++cnt) { - /* New context. */ - sha512_init_ctx(&ctx); - - /* Add key or last result. */ - if ((cnt & 1) != 0) - sha512_process_bytes(p_bytes, key_len, &ctx); - else - sha512_process_bytes(alt_result, 64, &ctx); - - /* Add salt for numbers not divisible by 3. */ - if (cnt % 3 != 0) - sha512_process_bytes(s_bytes, salt_len, &ctx); - - /* Add key for numbers not divisible by 7. */ - if (cnt % 7 != 0) - sha512_process_bytes(p_bytes, key_len, &ctx); - - /* Add key or last result. */ - if ((cnt & 1) != 0) - sha512_process_bytes(alt_result, 64, &ctx); - else - sha512_process_bytes(p_bytes, key_len, &ctx); - - /* Create intermediate result. */ - sha512_finish_ctx(&ctx, alt_result); - } - - /* Now we can construct the result string. It consists of three - parts. */ - cp = stpncpy(buffer, sha512_salt_prefix, MAX(0, buflen)); - buflen -= sizeof(sha512_salt_prefix) - 1; - - if (rounds_custom) { - int n = snprintf(cp, MAX(0, buflen), "%s%zu$", - sha512_rounds_prefix, rounds); - cp += n; - buflen -= n; - } - - cp = stpncpy(cp, salt, MIN((size_t) MAX(0, buflen), salt_len)); - buflen -= MIN((size_t) MAX(0, buflen), salt_len); - - if (buflen > 0) { - *cp++ = '$'; - --buflen; - } -#define b64_from_24bit(B2, B1, B0, N) \ - do { \ - unsigned int w = ((B2) << 16) | ((B1) << 8) | (B0); \ - int n = (N); \ - while (n-- > 0 && buflen > 0) \ - { \ - *cp++ = b64t[w & 0x3f]; \ - --buflen; \ - w >>= 6; \ - } \ - } while (0) - - b64_from_24bit(alt_result[0], alt_result[21], alt_result[42], 4); - b64_from_24bit(alt_result[22], alt_result[43], alt_result[1], 4); - b64_from_24bit(alt_result[44], alt_result[2], alt_result[23], 4); - b64_from_24bit(alt_result[3], alt_result[24], alt_result[45], 4); - b64_from_24bit(alt_result[25], alt_result[46], alt_result[4], 4); - b64_from_24bit(alt_result[47], alt_result[5], alt_result[26], 4); - b64_from_24bit(alt_result[6], alt_result[27], alt_result[48], 4); - b64_from_24bit(alt_result[28], alt_result[49], alt_result[7], 4); - b64_from_24bit(alt_result[50], alt_result[8], alt_result[29], 4); - b64_from_24bit(alt_result[9], alt_result[30], alt_result[51], 4); - b64_from_24bit(alt_result[31], alt_result[52], alt_result[10], 4); - b64_from_24bit(alt_result[53], alt_result[11], alt_result[32], 4); - b64_from_24bit(alt_result[12], alt_result[33], alt_result[54], 4); - b64_from_24bit(alt_result[34], alt_result[55], alt_result[13], 4); - b64_from_24bit(alt_result[56], alt_result[14], alt_result[35], 4); - b64_from_24bit(alt_result[15], alt_result[36], alt_result[57], 4); - b64_from_24bit(alt_result[37], alt_result[58], alt_result[16], 4); - b64_from_24bit(alt_result[59], alt_result[17], alt_result[38], 4); - b64_from_24bit(alt_result[18], alt_result[39], alt_result[60], 4); - b64_from_24bit(alt_result[40], alt_result[61], alt_result[19], 4); - b64_from_24bit(alt_result[62], alt_result[20], alt_result[41], 4); - b64_from_24bit(0, 0, alt_result[63], 2); - - if (buflen <= 0) { - errno = ERANGE; - buffer = NULL; - } else - *cp = '\0'; /* Terminate the string. */ - - /* Clear the buffer for the intermediate result so that people - attaching to processes or reading core dumps cannot get any - information. We do it in this way to clear correct_words[] - inside the SHA512 implementation as well. */ - sha512_init_ctx(&ctx); - sha512_finish_ctx(&ctx, alt_result); - memset(temp_result, '\0', sizeof(temp_result)); - memset(p_bytes, '\0', key_len); - memset(s_bytes, '\0', salt_len); - memset(&ctx, '\0', sizeof(ctx)); - memset(&alt_ctx, '\0', sizeof(alt_ctx)); - if (copied_key != NULL) - memset(copied_key, '\0', key_len); - if (copied_salt != NULL) - memset(copied_salt, '\0', salt_len); - - return buffer; -} - -/* This entry point is equivalent to the `crypt' function in Unix - libcs. */ -char *sha512_crypt(const char *key, const char *salt) -{ - /* We don't want to have an arbitrary limit in the size of the - password. We can compute an upper bound for the size of the - result in advance and so we can prepare the buffer we pass to - `sha512_crypt_r'. */ - static char *buffer; - static int buflen; - int needed = (sizeof(sha512_salt_prefix) - 1 - + sizeof(sha512_rounds_prefix) + 9 + 1 - + strlen(salt) + 1 + 86 + 1); - - if (buflen < needed) { - char *new_buffer = (char *)realloc(buffer, needed); - if (new_buffer == NULL) - return NULL; - - buffer = new_buffer; - buflen = needed; - } - - return sha512_crypt_r(key, salt, buffer, buflen); -} - -static void sha512crypt_exit() -{ - // Nothing to do -} - -// Define entry and exit points. -MODULE_INIT(sha512crypt_init); -MODULE_EXIT(sha512crypt_exit); diff --git a/com32/elflink/modules/test.c b/com32/elflink/modules/test.c deleted file mode 100644 index 13892fb..0000000 --- a/com32/elflink/modules/test.c +++ /dev/null @@ -1,109 +0,0 @@ -/* ----------------------------------------------------------------------- * - * - * Copyright 2007-2008 H. Peter Anvin - All Rights Reserved - * Copyright 2009 Intel Corporation; author: H. Peter Anvin - * - * 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. - * - * ----------------------------------------------------------------------- */ - -/* - * linux.c - * - * Sample module to load Linux kernels. This module can also create - * a file out of the DHCP return data if running under PXELINUX. - * - * If -dhcpinfo is specified, the DHCP info is written into the file - * /dhcpinfo.dat in the initramfs. - * - * Usage: linux.c32 [-dhcpinfo] kernel arguments... - */ - -#include <stdbool.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <console.h> -#include <syslinux/loadfile.h> -#include <syslinux/linux.h> -#include <dprintf.h> - -//const char *progname = "test.c32"; - -int main(int argc, char *argv[]) -{ - const char *kernel_name; - struct initramfs *initramfs; - char *cmdline; - char *boot_image; - void *kernel_data; - size_t kernel_len; - bool opt_quiet = false; - char **argp, *arg, *p; - - /* - while ((arg = *argp) && arg[0] == '-') { - if (!strcmp("-dhcpinfo", arg)) { - printf("haha\n"); - } else { - fprintf(stderr, "%s: unknown option: %s\n", progname, arg); - return 1; - } - argp++; - } - - if (!arg) { - fprintf(stderr, "%s: missing kernel name\n", progname); - return 1; - } - */ - - //kernel_name = arg; - kernel_name = "vmlinuz"; - - printf("Loading %s... ", kernel_name); - if (loadfile(kernel_name, &kernel_data, &kernel_len)) { - printf("failed!\n"); - goto bail; - } - printf("ok\n"); - - /* Initialize the initramfs chain */ - initramfs = initramfs_init(); - if (!initramfs) - goto bail; - - - if (initramfs_load_archive(initramfs, "initrd.gz")) - dprintf("initrd load failure\n"); - else - dprintf("initrd load success\n"); - - dprintf("1111"); - - /* This should not return... */ - syslinux_boot_linux(kernel_data, kernel_len, initramfs, cmdline); - -bail: - fprintf(stderr, "Kernel load failure (insufficient memory?)\n"); - return 1; -} diff --git a/com32/elflink/modules/unbase64.c b/com32/elflink/modules/unbase64.c deleted file mode 100644 index 86ddfc8..0000000 --- a/com32/elflink/modules/unbase64.c +++ /dev/null @@ -1,91 +0,0 @@ -/* ----------------------------------------------------------------------- * - * - * Copyright 2005-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. - * - * ----------------------------------------------------------------------- */ - -/* - * unbase64.c - * - * Convert a string in base64 format to a byte array. - */ - -#include <string.h> -#include <base64.h> -#include <sys/module.h> - -static int unbase64_init(void) -{ - return 0; // Nothing to do; return success -} - -static const unsigned char _base64chars[] - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - -size_t unbase64(unsigned char *buffer, size_t bufsiz, const char *txt) -{ - unsigned int bits = 0; - int nbits = 0; - char base64tbl[256]; - int i; - char v; - size_t nbytes = 0; - - memset(base64tbl, -1, sizeof base64tbl); - - for (i = 0; _base64chars[i]; i++) { - base64tbl[_base64chars[i]] = i; - } - - /* Also support filesystem safe alternate base64 encoding */ - base64tbl['.'] = 62; - base64tbl['-'] = 62; - base64tbl['_'] = 63; - - while (*txt) { - if ((v = base64tbl[(unsigned char)*txt]) >= 0) { - bits <<= 6; - bits += v; - nbits += 6; - if (nbits >= 8) { - if (nbytes < bufsiz) - *buffer++ = (bits >> (nbits - 8)); - nbytes++; - nbits -= 8; - } - } - txt++; - } - - return nbytes; -} - -static void unbase64_exit(void) -{ - // Nothing to do -} - -// Define entry and exit points. -MODULE_INIT(unbase64_init); -MODULE_EXIT(unbase64_exit); diff --git a/com32/elflink/modules/vesainfo.c b/com32/elflink/modules/vesainfo.c deleted file mode 100644 index 86a4365..0000000 --- a/com32/elflink/modules/vesainfo.c +++ /dev/null @@ -1,90 +0,0 @@ -/* - * vesainfo.c - * - * Dump information about what VESA graphics modes are supported. - */ - -#include <string.h> -#include <stdio.h> -#include <console.h> -#include <com32.h> -#include <inttypes.h> -#include "../lib/sys/vesa/vesa.h" - -/* Wait for a keypress */ -static void wait_key(void) -{ - char ch; - while (fread(&ch, 1, 1, stdin) == 0) ; -} - -static void print_modes(void) -{ - static com32sys_t rm; - struct vesa_general_info *gi; - struct vesa_mode_info *mi; - uint16_t mode, *mode_ptr; - int lines; - - struct vesa_info *vesa; - - vesa = lmalloc(sizeof(*vesa)); - if (!vesa) { - printf("vesainfo.c32: fail in lmalloc\n"); - return; - } - gi = &vesa->gi; - mi = &vesa->mi; - - gi->signature = VBE2_MAGIC; /* Get VBE2 extended data */ - rm.eax.w[0] = 0x4F00; /* Get SVGA general information */ - rm.edi.w[0] = OFFS(gi); - rm.es = SEG(gi); - __intcall(0x10, &rm, &rm); - - if (rm.eax.w[0] != 0x004F) { - printf("No VESA BIOS detected\n"); - goto exit; - } else if (gi->signature != VESA_MAGIC) { - printf("VESA information structure has bad magic, trying anyway...\n"); - } - - printf("VBE version %d.%d\n" - "Mode attrib h_res v_res bpp layout rpos gpos bpos\n", - (gi->version >> 8) & 0xff, gi->version & 0xff); - - lines = 1; - - mode_ptr = GET_PTR(gi->video_mode_ptr); - - while ((mode = *mode_ptr++) != 0xFFFF) { - if (++lines >= 23) { - wait_key(); - lines = 0; - } - - rm.eax.w[0] = 0x4F01; /* Get SVGA mode information */ - rm.ecx.w[0] = mode; - rm.edi.w[0] = OFFS(mi); - rm.es = SEG(mi); - __intcall(0x10, &rm, &rm); - - /* Must be a supported mode */ - if (rm.eax.w[0] != 0x004f) - continue; - - printf("0x%04x 0x%04x %5u %5u %3u %6u %4u %4u %4u\n", - mode, mi->mode_attr, mi->h_res, mi->v_res, mi->bpp, - mi->memory_layout, mi->rpos, mi->gpos, mi->bpos); - } - -exit: - free(vesa); - return; -} - -int main(int argc, char **argv) -{ - print_modes(); - return 0; -} diff --git a/com32/gfxboot/Makefile b/com32/gfxboot/Makefile index 183115f..f2a7376 100644 --- a/com32/gfxboot/Makefile +++ b/com32/gfxboot/Makefile @@ -13,13 +13,13 @@ topdir = ../.. MAKEDIR = $(topdir)/mk -include $(MAKEDIR)/com32.mk +include $(MAKEDIR)/elf.mk MODULES = gfxboot.c32 all: $(MODULES) -gfxboot.elf : gfxboot.o realmode_callback.o $(LIBS) $(C_LIBS) +gfxboot.c32 : gfxboot.o realmode_callback.o $(LIBS) $(C_LIBS) $(LD) $(LDFLAGS) -o $@ $^ realmode_callback.o: realmode_callback.asm @@ -31,7 +31,7 @@ realmode_callback.o: realmode_callback.asm $*.tmp $@ tidy dist: - rm -f *.o *.lo *.a *.lst *.elf .*.d *.tmp + rm -f *.o *.lo *.a *.lst .*.d *.tmp clean: tidy rm -f *.lnx diff --git a/com32/gpllib/Makefile b/com32/gpllib/Makefile index 1c07068..1476a15 100644 --- a/com32/gpllib/Makefile +++ b/com32/gpllib/Makefile @@ -19,26 +19,24 @@ AUXDIR = $(DATADIR)/syslinux INCDIR = /usr/include COM32DIR = $(AUXDIR)/com32 -all: libcom32gpl.a +all: libcom32gpl.c32 -libcom32gpl.a : $(LIBOBJS) - rm -f $@ - $(AR) cq $@ $^ - $(RANLIB) $@ +libcom32gpl.c32 : $(LIBOBJS) + $(LD) -shared $(LDFLAGS) -o $@ $^ tidy dist clean: - find . \( -name \*.o -o -name \*.a -o -name .\*.d -o -name \*.tmp \) -print0 | \ + find . \( -name \*.o -o -name \*.c32 -o -name .\*.d -o -name \*.tmp \) -print0 | \ xargs -0r rm -f spotless: clean - rm -f *.a + rm -f *.c32 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) + install -m 644 libcom32gpl.c32 $(INSTALLROOT)$(COM32DIR) mkdir -p $(INSTALLROOT)$(COM32DIR)/include/ cp -r ../gplinclude $(INSTALLROOT)$(COM32DIR)/include/ diff --git a/com32/hdt/Makefile b/com32/hdt/Makefile index 8900a2e..db45eef 100644 --- a/com32/hdt/Makefile +++ b/com32/hdt/Makefile @@ -17,7 +17,7 @@ topdir = ../.. MAKEDIR = $(topdir)/mk -include $(MAKEDIR)/com32.mk +include $(MAKEDIR)/elf.mk LIBS = ../cmenu/libmenu/libmenu.a CFLAGS += -I$(com32)/cmenu/libmenu @@ -49,7 +49,7 @@ QEMU ?= qemu-kvm all: $(MODULES) $(TESTFILES) -hdt.elf : $(OBJS) $(LIBS) $(C_LIBS) +hdt.c32 : $(OBJS) $(LIBS) $(C_LIBS) $(LD) $(LDFLAGS) -o $@ $^ memtest: diff --git a/com32/elflink/modules/cli.h b/com32/include/cli.h similarity index 100% rename from com32/elflink/modules/cli.h rename to com32/include/cli.h diff --git a/com32/elflink/modules/sort.h b/com32/include/sort.h similarity index 100% rename from com32/elflink/modules/sort.h rename to com32/include/sort.h diff --git a/com32/lib/Makefile b/com32/lib/Makefile index ad861c9..771f1c7 100644 --- a/com32/lib/Makefile +++ b/com32/lib/Makefile @@ -194,7 +194,6 @@ DYNLIBOBJS = \ LIBOBJS = \ - $(MINLIBOBJS) \ $(DYNLIBOBJS) BINDIR = /usr/bin @@ -204,12 +203,11 @@ AUXDIR = $(DATADIR)/syslinux INCDIR = /usr/include COM32DIR = $(AUXDIR)/com32 -all: libcom32.a libcom32min.a +all: libcom32.c32 libcom32min.a -libcom32.a : $(LIBOBJS) +libcom32.c32 : $(LIBOBJS) rm -f $@ - $(AR) cq $@ $^ - $(RANLIB) $@ + $(LD) -shared $(LDFLAGS) -o $@ $^ $(LIBMODULE_OBJS) : CFLAGS += -DELF_DEBUG libcom32min.a : $(MINLIBOBJS) @@ -228,7 +226,7 @@ spotless: clean install: all mkdir -m 755 -p $(INSTALLROOT)$(COM32DIR) - install -m 644 libcom32.a com32.ld $(INSTALLROOT)$(COM32DIR) + install -m 644 com32.ld $(INSTALLROOT)$(COM32DIR) -rm -rf $(INSTALLROOT)$(COM32DIR)/include cp -r ../include $(INSTALLROOT)$(COM32DIR) diff --git a/com32/libutil/Makefile b/com32/libutil/Makefile index 5942a08..c76433a 100644 --- a/com32/libutil/Makefile +++ b/com32/libutil/Makefile @@ -31,18 +31,17 @@ topdir = ../.. MAKEDIR = $(topdir)/mk -include $(MAKEDIR)/com32.mk +include $(MAKEDIR)/elf.mk LIBOBJS = ansiline.o ansiraw.o get_key.o sha1hash.o unbase64.o \ - md5.o crypt-md5.o sha256crypt.o sha512crypt.o base64.o + md5.o crypt-md5.o sha256crypt.o sha512crypt.o base64.o \ + quicksort.o LNXLIBOBJS = $(patsubst %.o,%.lo,$(LIBOBJS)) -all: libutil_com.a libutil_lnx.a +all: libutil_com.c32 libutil_lnx.a -libutil_com.a: $(LIBOBJS) - rm -f $@ - $(AR) cq $@ $(LIBOBJS) - $(RANLIB) $@ +libutil_com.c32: $(LIBOBJS) + $(LD) $(LDFLAGS) -o $@ $^ libutil_lnx.a: $(LNXLIBOBJS) rm -f $@ diff --git a/com32/elflink/modules/sort.c b/com32/libutil/quicksort.c similarity index 80% rename from com32/elflink/modules/sort.c rename to com32/libutil/quicksort.c index f91cb60..32ac0f0 100644 --- a/com32/elflink/modules/sort.c +++ b/com32/libutil/quicksort.c @@ -6,15 +6,6 @@ */ #include <stdlib.h> -#include <sys/module.h> - -/** - * sort_init - Module entry point. - */ -static int sort_init(void) -{ - return 0; // Nothing to do; return success -} static inline void swap(int *x, int *y) { @@ -66,15 +57,3 @@ void quick_sort(int *nums, int count) { quick_sort_range(nums, 0, count - 1); } - -/** - * sort_exit - Module exit point. - */ -static void sort_exit(void) -{ - // Nothing to do -} - -// Define entry and exit points. -MODULE_INIT(sort_init); -MODULE_EXIT(sort_exit); diff --git a/com32/lua/src/Makefile b/com32/lua/src/Makefile index 14b0e33..f1ffb7e 100644 --- a/com32/lua/src/Makefile +++ b/com32/lua/src/Makefile @@ -17,7 +17,7 @@ topdir = ../../.. MAKEDIR = $(topdir)/mk -include $(MAKEDIR)/com32.mk +include $(MAKEDIR)/elf.mk LNXLIBS = @@ -30,7 +30,7 @@ TESTFILES OBJS = lua.o -LIBLUA = liblua.a +LIBLUA = liblua.c32 LIBLUA_OBJS := lapi.o lcode.o ldebug.o ldo.o ldump.o lfunc.o LIBLUA_OBJS += lgc.o llex.o lmem.o lobject.o lopcodes.o lparser.o @@ -50,15 +50,13 @@ CFLAGS += -DLUA_ANSI all: $(MODULES) $(TESTFILES) $(LIBLUA) : $(LIBLUA_OBJS) - rm -f $@ - $(AR) cq $@ $^ - $(RANLIB) $@ + $(LD) -shared $(LDFLAGS) -o $@ $^ -lua.elf : $(OBJS) $(LIBLUA) $(C_LIBS) +lua.c32 : $(OBJS) $(LIBLUA) $(C_LIBS) $(LD) $(LDFLAGS) -o $@ $^ tidy dist: - rm -f *.o *.lo *.a *.lst *.elf .*.d *.tmp + rm -f *.o *.lo *.lst *.elf .*.d *.tmp clean: tidy rm -f *.lnx diff --git a/com32/mboot/Makefile b/com32/mboot/Makefile index b7ee115..02e9f49 100644 --- a/com32/mboot/Makefile +++ b/com32/mboot/Makefile @@ -17,7 +17,7 @@ topdir = ../.. MAKEDIR = $(topdir)/mk -include $(MAKEDIR)/com32.mk +include $(MAKEDIR)/elf.mk LNXLIBS = ../libutil/libutil_lnx.a @@ -28,7 +28,7 @@ OBJS = mboot.o map.o mem.o initvesa.o apm.o solaris.o syslinux.o all: $(MODULES) $(TESTFILES) -mboot.elf : $(OBJS) $(C_LIBS) +mboot.c32 : $(OBJS) $(C_LIBS) $(LD) $(LDFLAGS) -o $@ $^ tidy dist: diff --git a/com32/menu/Makefile b/com32/menu/Makefile index b67b997..5a9b3c6 100644 --- a/com32/menu/Makefile +++ b/com32/menu/Makefile @@ -16,7 +16,7 @@ topdir = ../.. MAKEDIR = $(topdir)/mk -include $(MAKEDIR)/com32.mk +include $(MAKEDIR)/elf.mk LNXLIBS = ../libutil/libutil_lnx.a diff --git a/com32/modules/Makefile b/com32/modules/Makefile index 6f21d28..6cfdd47 100644 --- a/com32/modules/Makefile +++ b/com32/modules/Makefile @@ -17,32 +17,23 @@ topdir = ../.. MAKEDIR = $(topdir)/mk -include $(MAKEDIR)/com32.mk +include $(MAKEDIR)/elf.mk MODULES = chain.c32 config.c32 ethersel.c32 dmitest.c32 cpuidtest.c32 \ disk.c32 pcitest.c32 elf.c32 linux.c32 reboot.c32 pmload.c32 \ meminfo.c32 sdi.c32 sanboot.c32 ifcpu64.c32 vesainfo.c32 \ kbdmap.c32 cmd.c32 vpdtest.c32 host.c32 dir.c32 gpxecmd.c32 \ - ifcpu.c32 cpuid.c32 cat.c32 + ifcpu.c32 cpuid.c32 cat.c32 hello.c32 TESTFILES all: $(MODULES) $(TESTFILES) -pcitest.elf : pcitest.o $(LIBS) $(C_LIBS) - $(LD) $(LDFLAGS) -o $@ $^ - -cpuidtest.elf : cpuidtest.o $(GPLLIB) $(LIBS) $(C_LIBS) - $(LD) $(LDFLAGS) -o $@ $^ - .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) +dmitest.c32 : dmi_utils.o dmitest.o $(GPLLIB) $(LIBS) $(C_LIBS) $(LD) $(LDFLAGS) -o $@ $^ tidy dist: diff --git a/com32/elflink/modules/hello.c b/com32/modules/hello.c similarity index 100% rename from com32/elflink/modules/hello.c rename to com32/modules/hello.c diff --git a/com32/modules/meminfo.c b/com32/modules/meminfo.c index 96006d4..00d0e14 100644 --- a/com32/modules/meminfo.c +++ b/com32/modules/meminfo.c @@ -42,27 +42,32 @@ static void dump_e820(void) com32sys_t ireg, oreg; struct e820_data ed; uint32_t type; + void *low_ed; + + low_ed = lmalloc(sizeof ed); + if (!low_ed) + return; memset(&ireg, 0, sizeof ireg); ireg.eax.w[0] = 0xe820; ireg.edx.l = 0x534d4150; ireg.ecx.l = sizeof(struct e820_data); - ireg.edi.w[0] = OFFS(__com32.cs_bounce); - ireg.es = SEG(__com32.cs_bounce); + ireg.edi.w[0] = OFFS(low_ed); + ireg.es = SEG(low_ed); memset(&ed, 0, sizeof ed); ed.extattr = 1; do { - memcpy(__com32.cs_bounce, &ed, sizeof ed); + memcpy(low_ed, &ed, sizeof ed); __intcall(0x15, &ireg, &oreg); if (oreg.eflags.l & EFLAGS_CF || oreg.eax.l != 0x534d4150 || oreg.ecx.l < 20) break; - memcpy(&ed, __com32.cs_bounce, sizeof ed); + memcpy(&ed, low_ed, sizeof ed); if (oreg.ecx.l >= 24) { /* ebx base length end type */ @@ -84,6 +89,8 @@ static void dump_e820(void) ireg.ebx.l = oreg.ebx.l; } while (ireg.ebx.l); + + free(low_ed); } static void dump_legacy(void) @@ -115,10 +122,9 @@ static void dump_legacy(void) oreg.ecx.w[0], oreg.ecx.w[0], oreg.edx.w[0], oreg.edx.w[0] << 6); } -int main(void) +int main(int argc, char **argv) { dump_legacy(); dump_e820(); - return 0; } diff --git a/com32/modules/vesainfo.c b/com32/modules/vesainfo.c index f9b2502..86a4365 100644 --- a/com32/modules/vesainfo.c +++ b/com32/modules/vesainfo.c @@ -20,25 +20,31 @@ static void wait_key(void) static void print_modes(void) { - static com32sys_t rm; - struct vesa_general_info *gi; - struct vesa_mode_info *mi; - uint16_t mode, *mode_ptr; - int lines; - - /* Allocate space in the bounce buffer for these structures */ - gi = &((struct vesa_info *)__com32.cs_bounce)->gi; - mi = &((struct vesa_info *)__com32.cs_bounce)->mi; - - gi->signature = VBE2_MAGIC; /* Get VBE2 extended data */ - rm.eax.w[0] = 0x4F00; /* Get SVGA general information */ - rm.edi.w[0] = OFFS(gi); - rm.es = SEG(gi); - __intcall(0x10, &rm, &rm); + static com32sys_t rm; + struct vesa_general_info *gi; + struct vesa_mode_info *mi; + uint16_t mode, *mode_ptr; + int lines; + + struct vesa_info *vesa; + + vesa = lmalloc(sizeof(*vesa)); + if (!vesa) { + printf("vesainfo.c32: fail in lmalloc\n"); + return; + } + gi = &vesa->gi; + mi = &vesa->mi; + + gi->signature = VBE2_MAGIC; /* Get VBE2 extended data */ + rm.eax.w[0] = 0x4F00; /* Get SVGA general information */ + rm.edi.w[0] = OFFS(gi); + rm.es = SEG(gi); + __intcall(0x10, &rm, &rm); if (rm.eax.w[0] != 0x004F) { printf("No VESA BIOS detected\n"); - return; + goto exit; } else if (gi->signature != VESA_MAGIC) { printf("VESA information structure has bad magic, trying anyway...\n"); } @@ -71,9 +77,13 @@ static void print_modes(void) mode, mi->mode_attr, mi->h_res, mi->v_res, mi->bpp, mi->memory_layout, mi->rpos, mi->gpos, mi->bpos); } + +exit: + free(vesa); + return; } -int main(void) +int main(int argc, char **argv) { print_modes(); return 0; diff --git a/com32/samples/Makefile b/com32/samples/Makefile index 76986d5..167c638 100644 --- a/com32/samples/Makefile +++ b/com32/samples/Makefile @@ -16,7 +16,7 @@ topdir = ../.. MAKEDIR = $(topdir)/mk -include $(MAKEDIR)/com32.mk +include $(MAKEDIR)/elf.mk all: hello.c32 resolv.c32 serialinfo.c32 \ localboot.c32 \ diff --git a/com32/sysdump/Makefile b/com32/sysdump/Makefile index 5d7f4ef..02b20d8 100644 --- a/com32/sysdump/Makefile +++ b/com32/sysdump/Makefile @@ -17,7 +17,7 @@ topdir = ../.. MAKEDIR = $(topdir)/mk -include $(MAKEDIR)/com32.mk +include $(MAKEDIR)/elf.mk -include $(topdir)/version.mk LNXLIBS = ../libutil/libutil_lnx.a @@ -42,11 +42,11 @@ CFLAGS += -DDATE='"$(DATE)"' all: $(MODULES) $(TESTFILES) -sysdump.elf : $(OBJS) $(C_LIBS) +sysdump.c32 : $(OBJS) $(C_LIBS) $(LD) $(LDFLAGS) -o $@ $^ tidy dist: - rm -f *.o *.lo *.a *.lst *.elf .*.d *.tmp + rm -f *.o *.lo *.a *.lst .*.d *.tmp clean: tidy rm -f *.lnx diff --git a/elf_gen_dep.sh b/elf_gen_dep.sh index dba990d..1c357db 100755 --- a/elf_gen_dep.sh +++ b/elf_gen_dep.sh @@ -4,7 +4,7 @@ # Round 1: get all the loacl and external symbols ####################################################### -for i in com32/elflink/modules/*.c32 core/isolinux.elf core/pxelinux.elf com32/elflink/ldlinux/*.c32 +for i in core/isolinux.elf core/pxelinux.elf com32/*/*.c32 com32/*/*/*.c32 do # module=$(echo $i | sed "s/^\(.*\).o$/\1/") diff --git a/mk/com32.mk b/mk/com32.mk index 531459e..262d2a6 100644 --- a/mk/com32.mk +++ b/mk/com32.mk @@ -64,7 +64,7 @@ LNXSFLAGS = -g LNXLDFLAGS = -g C_LIBS = $(com32)/libutil/libutil_com.a $(GPLLIB) \ - $(com32)/lib/libcom32.a $(LIBGCC) + $(com32)/lib/libcom32.c32 $(LIBGCC) C_LNXLIBS = $(com32)/libutil/libutil_lnx.a .SUFFIXES: .lss .c .lo .o .elf .c32 .lnx diff --git a/mk/elf.mk b/mk/elf.mk index 6efcf47..4a0b5a6 100644 --- a/mk/elf.mk +++ b/mk/elf.mk @@ -33,10 +33,18 @@ GCCOPT += $(call gcc_ok,-mpreferred-stack-boundary=2,) com32 = $(topdir)/com32 +ifneq ($(NOGPL),1) +GPLLIB = $(com32)/gpllib/libcom32gpl.c32 +GPLINCLUDE = -I$(com32)/gplinclude +else +GPLLIB +GPLINCLUDE +endif + CFLAGS = $(GCCOPT) -W -Wall -march=i386 \ -fomit-frame-pointer -D__COM32__ -DDYNAMIC_MODULE \ -nostdinc -iwithprefix include \ - -I$(com32)/libutil/include -I$(com32)/include -I$(com32)/gplinclude + -I$(com32)/libutil/include -I$(com32)/include $(GPLINCLUDE) SFLAGS = $(GCCOPT) -D__COM32__ -march=i386 LDFLAGS = -m elf_i386 -shared --hash-style=gnu -T $(com32)/lib/elf32.ld LIBGCC := $(shell $(CC) $(GCCOPT) --print-libgcc) @@ -45,6 +53,10 @@ LNXCFLAGS = -I$(com32)/libutil/include -W -Wall -O -g -D_GNU_SOURCE LNXSFLAGS = -g LNXLDFLAGS = -g +C_LIBS = $(com32)/libutil/libutil_com.c32 $(GPLLIB) \ + $(com32)/lib/libcom32.c32 $(LIBGCC) +C_LNXLIBS = $(com32)/libutil/libutil_lnx.a + .SUFFIXES: .lss .c .o .PRECIOUS: %.o @@ -64,8 +76,8 @@ LNXLDFLAGS = -g $(CC) $(LNXCFLAGS) -c -o $@ $< .PRECIOUS: %.lnx -%.lnx: %.lo $(LNXLIBS) - $(CC) $(LNXLDFLAGS) -o $@ $^ +%.lnx: %.lo $(LNXLIBS) $(C_LNXLIBS) + $(CC) $(LNXCFLAGS) -o $@ $^ %.c32: %.o $(LD) $(LDFLAGS) -o $@ $^ diff --git a/mk/rosh.mk b/mk/rosh.mk index 7fdba0f..45b9821 100644 --- a/mk/rosh.mk +++ b/mk/rosh.mk @@ -15,7 +15,7 @@ ## ## Include the COM32 common configurables -include $(MAKEDIR)/com32.mk +include $(MAKEDIR)/elf.mk # CFLAGS = $(GCCOPT) $(GCCWARN) -march=i386 \ # -fomit-frame-pointer -D__COM32__ \ -- 1.7.4.2
Matt Fleming
2011-Apr-16 14:17 UTC
[syslinux] [PATCH 15/20] exit.c: Truncate exit status to uint8_t
From: Matt Fleming <matt.fleming at linux.intel.com> The valid range for an exit status is 0 - 255, so we need to truncate the value passed to _exit(). I noticed this when a module was doing _exit(-1), and ended up calling longjmp(.., 0xffffffff + 1) which meant that setjmp() in spawn_load() returned 0. Obviously, we wanted the setjmp() to return 256 (0xff + 1), because the code in spawn_load() handles the return value like so, ret_val = setjmp(module->u.x.process_exit); if (ret_val) ret_val--; /* Valid range is 0-255 */ else if (!module->main_func) ret_val = -1; else exit((module->main_func)(argc, argv)); /* Actually run! */ There actually is code in spawn_load() to properly truncate 'ret_val', but it is applied too late. The truncation needs to happen when we pass the exit status to longjmp(). Suggested-by: H. Peter Anvin <hpa at zytor.com> Signed-off-by: Matt Fleming <matt.fleming at linux.intel.com> --- com32/lib/exit.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/com32/lib/exit.c b/com32/lib/exit.c index cba6cee..ebec0a1 100644 --- a/com32/lib/exit.c +++ b/com32/lib/exit.c @@ -54,6 +54,6 @@ __noreturn _Exit(int rv) __noreturn _exit(int rv) { - longjmp(__syslinux_current->u.x.process_exit, rv+1); + longjmp(__syslinux_current->u.x.process_exit, (uint8_t)rv+1); } -- 1.7.4.2
Matt Fleming
2011-Apr-16 14:17 UTC
[syslinux] [PATCH 16/20] elflink: ldlinux should not have any dependencies
From: Matt Fleming <matt.fleming at linux.intel.com> ldlinux currently requires the get_key() symbol, which means it has a dependency on libutil_com.c32. ldlinux.c32 really should be a standalone module so let's move get_key.c into ldlinux/. However, moving get_key.c creates a new problem - native linux applications such as com32/samples/keytest.c require the get_key() symbol which is currently exported by libutil_lnx.a. To fix this, we create a new native linux library that exports any required symbols from ldlinux. With this change we need to update com32/Makefile so that we build com32/elfink/ldlinux before com32/samples, and seeing as ldlinux now has no dependencies, we may as well move it to the front of $SUBDIRS. Also, update elf_gen_dep.sh to skip ldlinux.c32 and not search for dependencies for any of its unresolved symbols. This way, if anyone inadvertently introduces a dependency that cannot be resolved by the core, ldlinux.c32 will fail to load at runtime (which guarantees that the newly introduced dependency won't go unnoticed). Signed-off-by: Matt Fleming <matt.fleming at linux.intel.com> --- com32/Makefile | 4 ++-- com32/elflink/ldlinux/Makefile | 10 ++++++++-- com32/{libutil => elflink/ldlinux}/get_key.c | 0 com32/libutil/Makefile | 2 +- elf_gen_dep.sh | 1 + mk/elf.mk | 3 ++- 6 files changed, 14 insertions(+), 6 deletions(-) rename com32/{libutil => elflink/ldlinux}/get_key.c (100%) diff --git a/com32/Makefile b/com32/Makefile index 7506521..8fa40b6 100644 --- a/com32/Makefile +++ b/com32/Makefile @@ -1,4 +1,4 @@ -SUBDIRS = tools lib gpllib libutil modules mboot menu samples elflink rosh cmenu \ - hdt gfxboot sysdump lua/src elflink/ldlinux +SUBDIRS = elflink/ldlinux tools lib gpllib libutil modules mboot menu samples elflink rosh cmenu \ + hdt gfxboot sysdump lua/src all tidy dist clean spotless install: set -e; for d in $(SUBDIRS); do $(MAKE) -C $$d $@; done diff --git a/com32/elflink/ldlinux/Makefile b/com32/elflink/ldlinux/Makefile index 8fe4d71..318b3ac 100644 --- a/com32/elflink/ldlinux/Makefile +++ b/com32/elflink/ldlinux/Makefile @@ -16,12 +16,18 @@ include $(MAKEDIR)/elf.mk CFLAGS += -I$(topdir)/core/elflink -I$(topdir)/core/include -all: ldlinux.c32 +all: ldlinux.c32 ldlinux_lnx.a ldlinux.c32 : ldlinux.o cli.o readconfig.o refstr.o colors.o getadv.o \ - adv.o ipappend.o execute.o kernel.o + adv.o ipappend.o execute.o kernel.o get_key.o $(LD) $(LDFLAGS) -o $@ $^ +LNXLIBOBJS = get_key.lo +ldlinux_lnx.a: $(LNXLIBOBJS) + rm -f $@ + $(AR) cq $@ $(LNXLIBOBJS) + $(RANLIB) $@ + tidy dist: rm -f *.o *.lo *.a *.lst .*.d diff --git a/com32/libutil/get_key.c b/com32/elflink/ldlinux/get_key.c similarity index 100% rename from com32/libutil/get_key.c rename to com32/elflink/ldlinux/get_key.c diff --git a/com32/libutil/Makefile b/com32/libutil/Makefile index c76433a..8dcede9 100644 --- a/com32/libutil/Makefile +++ b/com32/libutil/Makefile @@ -33,7 +33,7 @@ topdir = ../.. MAKEDIR = $(topdir)/mk include $(MAKEDIR)/elf.mk -LIBOBJS = ansiline.o ansiraw.o get_key.o sha1hash.o unbase64.o \ +LIBOBJS = ansiline.o ansiraw.o sha1hash.o unbase64.o \ md5.o crypt-md5.o sha256crypt.o sha512crypt.o base64.o \ quicksort.o LNXLIBOBJS = $(patsubst %.o,%.lo,$(LIBOBJS)) diff --git a/elf_gen_dep.sh b/elf_gen_dep.sh index 1c357db..9a26c92 100755 --- a/elf_gen_dep.sh +++ b/elf_gen_dep.sh @@ -51,6 +51,7 @@ rm_cr () echo $line | grep extlinux > /dev/null && continue echo $line | grep isolinux > /dev/null && continue echo $line | grep pxelinux > /dev/null && continue + echo $line | grep ldlinux > /dev/null && continue all_dep=$all_dep$space$line echo $all_dep > rmcr.tmp diff --git a/mk/elf.mk b/mk/elf.mk index 4a0b5a6..5a2ce2d 100644 --- a/mk/elf.mk +++ b/mk/elf.mk @@ -55,7 +55,8 @@ LNXLDFLAGS = -g C_LIBS = $(com32)/libutil/libutil_com.c32 $(GPLLIB) \ $(com32)/lib/libcom32.c32 $(LIBGCC) -C_LNXLIBS = $(com32)/libutil/libutil_lnx.a +C_LNXLIBS = $(com32)/libutil/libutil_lnx.a \ + $(com32)/elflink/ldlinux/ldlinux_lnx.a .SUFFIXES: .lss .c .o -- 1.7.4.2
Matt Fleming
2011-Apr-16 14:17 UTC
[syslinux] [PATCH 17/20] elflink: Don't compile in debug output by default
From: Matt Fleming <matt.fleming at linux.intel.com> Turn off ELF_DEBUG, we really don't need to see the "[ELF] MODULE UNLOADED" message everytime we finish executing an ELF module. Signed-off-by: Matt Fleming <matt.fleming at linux.intel.com> --- com32/lib/Makefile | 1 - 1 files changed, 0 insertions(+), 1 deletions(-) diff --git a/com32/lib/Makefile b/com32/lib/Makefile index 771f1c7..0be2e80 100644 --- a/com32/lib/Makefile +++ b/com32/lib/Makefile @@ -209,7 +209,6 @@ libcom32.c32 : $(LIBOBJS) rm -f $@ $(LD) -shared $(LDFLAGS) -o $@ $^ -$(LIBMODULE_OBJS) : CFLAGS += -DELF_DEBUG libcom32min.a : $(MINLIBOBJS) rm -f $@ $(AR) cq $@ $^ -- 1.7.4.2
Matt Fleming
2011-Apr-16 14:17 UTC
[syslinux] [PATCH 18/20] elflink: Don't require every module to have init/exit functions
From: Matt Fleming <matt.fleming at linux.intel.com> Don't complain or refuse to load a module if it doesn't contain an init or exit function, as many of the init/exit functions are in fact empty. Signed-off-by: Matt Fleming <matt.fleming at linux.intel.com> --- com32/lib/sys/module/elf_module.c | 31 ++++++++++++------------------- 1 files changed, 12 insertions(+), 19 deletions(-) diff --git a/com32/lib/sys/module/elf_module.c b/com32/lib/sys/module/elf_module.c index afb5b64..8db4220 100644 --- a/com32/lib/sys/module/elf_module.c +++ b/com32/lib/sys/module/elf_module.c @@ -390,27 +390,20 @@ static int extract_operations(struct elf_module *module) { Elf32_Sym *exit_sym = module_find_symbol(MODULE_ELF_EXIT_PTR, module); Elf32_Sym *main_sym = module_find_symbol("main", module); - if (init_sym == NULL) { - DBG_PRINT("Cannot find initialization routine pointer.\n"); - printf("Cannot find initialization routine pointer.\n"); - return -1; - } - if (exit_sym == NULL) { - DBG_PRINT("Cannot find exit routine pointer.\n"); - printf("Cannot find exit routine pointer.\n"); - return -1; - } - - module->init_func = (module_init_t*)module_get_absolute( - init_sym->st_value, module); - if (*(module->init_func) == NULL) { - module->init_func = NULL; + if (init_sym) { + module->init_func = (module_init_t*)module_get_absolute( + init_sym->st_value, module); + if (*(module->init_func) == NULL) { + module->init_func = NULL; + } } - module->exit_func = (module_exit_t*)module_get_absolute( - exit_sym->st_value, module); - if (*(module->exit_func) == NULL) { - module->exit_func = NULL; + if (exit_sym) { + module->exit_func = (module_exit_t*)module_get_absolute( + exit_sym->st_value, module); + if (*(module->exit_func) == NULL) { + module->exit_func = NULL; + } } if (main_sym) -- 1.7.4.2
Matt Fleming
2011-Apr-16 14:17 UTC
[syslinux] [PATCH 19/20] elf_gen_dep.sh: Don't calculate dependencies for whitespace symbols
From: Matt Fleming <matt.fleming at linux.intel.com> Don't try to resolve dependencies for a symbol whose name is purely made up of whitespace. Signed-off-by: Matt Fleming <matt.fleming at linux.intel.com> --- elf_gen_dep.sh | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/elf_gen_dep.sh b/elf_gen_dep.sh index 9a26c92..2cde308 100755 --- a/elf_gen_dep.sh +++ b/elf_gen_dep.sh @@ -23,6 +23,8 @@ do sed -n -e "/UND/d" -e "/ABS/d" -e "/...[0-9] $/d" -e "/...[0-9] \./d" -e "/...[0-9]/p" $module.txt > $module.int sed -i -e "s/^.....//g" $module.int sed -i -e "s/^\(.*\)$/\1 <$module>/g" $module.int + # Delete all whitespace + sed -i -e "s/^[ \t]*$//g" $module.int cat $module.int >> all.txt done -- 1.7.4.2
Matt Fleming
2011-Apr-16 14:17 UTC
[syslinux] [PATCH 20/20] elf_gen_dep.sh: Prioritise symbols exported by core
From: Matt Fleming <matt.fleming at linux.intel.com> It's possible for multiple modules to export the same symbol. We always favour the symbols exported from core/ because this means that modules will have less runtime dependencies. For example, some symbols required by ldlinux.c32 are exported by both core/ and libmenu.c32. Because we don't want ldlinux.c32 to have any dependencies, we need to make sure we resolve to the symbol exported by core/. Note that now the order in which we extract global symbols from ELF files in elf_gen_dep.sh is important, because this dictates our order of preference and hence core/isolinux.elf and core/pxelinux.elf need to come first. Signed-off-by: Matt Fleming <matt.fleming at linux.intel.com> --- elf_gen_dep.sh | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/elf_gen_dep.sh b/elf_gen_dep.sh index 2cde308..1badb64 100755 --- a/elf_gen_dep.sh +++ b/elf_gen_dep.sh @@ -85,7 +85,7 @@ resolve_sym () fi else #echo $symbol - sed -n -e "s/^$symbol <\(.*\)>/\1/p" all.txt >> resolve.tmp + sed -n -e "s/^$symbol <\(.*\)>/\1/p" all.txt | head -n1 >> resolve.tmp #grep $symbol all.txt fi done -- 1.7.4.2