aboutsummaryrefslogtreecommitdiffstats
path: root/com32/elflink/ldlinux
diff options
context:
space:
mode:
authorMatt Fleming <matt.fleming@linux.intel.com>2011-04-08 13:21:51 +0100
committerMatt Fleming <matt.fleming@linux.intel.com>2011-04-26 09:53:31 +0100
commit43d7cbaa55806ecb33b0cc5aa56e97b0f8027c45 (patch)
treebfe0b4d22649c6e4859fe85cbe46063c4436b3b0 /com32/elflink/ldlinux
parent990e7e1df3dc6fa456ff7cdaec7d239977557c8d (diff)
downloadsyslinux-43d7cbaa55806ecb33b0cc5aa56e97b0f8027c45.tar.gz
syslinux-43d7cbaa55806ecb33b0cc5aa56e97b0f8027c45.tar.xz
syslinux-43d7cbaa55806ecb33b0cc5aa56e97b0f8027c45.zip
elflink: Move more code from core/ into ldlinux
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@linux.intel.com>
Diffstat (limited to 'com32/elflink/ldlinux')
-rw-r--r--com32/elflink/ldlinux/Makefile2
-rw-r--r--com32/elflink/ldlinux/execute.c171
-rw-r--r--com32/elflink/ldlinux/kernel.c128
3 files changed, 300 insertions, 1 deletions
diff --git a/com32/elflink/ldlinux/Makefile b/com32/elflink/ldlinux/Makefile
index 6fbe1b16..09aa4af4 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/com32/elflink/ldlinux/execute.c b/com32/elflink/ldlinux/execute.c
new file mode 100644
index 00000000..f67d707b
--- /dev/null
+++ b/com32/elflink/ldlinux/execute.c
@@ -0,0 +1,171 @@
+/* ----------------------------------------------------------------------- *
+ *
+ * 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 <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <dprintf.h>
+
+#include <com32.h>
+#include <sys/exec.h>
+#include "core.h"
+#include "core-elf.h"
+
+/* Must match enum kernel_type */
+const char *const kernel_types[] = {
+ "none",
+ "localboot",
+ "kernel",
+ "linux",
+ "boot",
+ "bss",
+ "pxe",
+ "fdimage",
+ "comboot",
+ "com32",
+ "config",
+ 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;
+ const char *kernel, *args;
+ com32sys_t ireg;
+ char *q;
+
+ memset(&ireg, 0, sizeof ireg);
+
+ /* for parameter will be passed to __intcall, we need use
+ * lmalloc a block of low memory */
+ q = lmalloc(128);
+ if (!q) {
+ printf("%s(): Fail to lmalloc a buffer to exec %s\n",
+ __func__, cmdline);
+ return;
+ }
+
+ kernel = q;
+ p = cmdline;
+ while (*p && !my_isspace(*p))
+ *q++ = *p++;
+ *q++ = '\0';
+
+ args = q;
+ while (*p && my_isspace(*p))
+ p++;
+
+ strcpy(q, p);
+
+ dprintf("kernel is %s, args = %s type = %d \n", kernel, args, type);
+
+ if (kernel[0] == '.' && type == KT_NONE) {
+ /* It might be a type specifier */
+ enum kernel_type type = KT_NONE;
+ for (pp = kernel_types; *pp; pp++, type++) {
+ if (!strcmp(kernel + 1, *pp))
+ execute(p, type); /* Strip the type specifier and retry */
+ }
+ }
+
+ if (type == KT_COM32) {
+ /* new entry for elf format c32 */
+ 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, 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 */
+ char *spawn_load_param[2] = { args, NULL };
+ module_load_dependencies("ui.c32", "modules.dep");
+ spawn_load(kernel, 1, spawn_load_param);
+ } else {
+ /* process the image need int 22 support */
+ if (type == KT_LOCALBOOT) {
+ ireg.eax.w[0] = 0x0014; /* Local boot */
+ ireg.edx.w[0] = strtoul(kernel, NULL, 0);
+ }
+ ireg.eax.w[0] = 0x0016; /* Run kernel image */
+ ireg.esi.w[0] = OFFS(kernel);
+ ireg.ds = SEG(kernel);
+ ireg.ebx.w[0] = OFFS(args);
+ ireg.es = SEG(args);
+ ireg.edx.l = type - KT_KERNEL;
+ /* ireg.ecx.l = 0; *//* We do ipappend "manually" */
+
+ __intcall(0x22, &ireg, NULL);
+ }
+
+ lfree(kernel);
+
+ /* If this returns, something went bad; return to menu */
+}
diff --git a/com32/elflink/ldlinux/kernel.c b/com32/elflink/ldlinux/kernel.c
new file mode 100644
index 00000000..3ce2358d
--- /dev/null
+++ b/com32/elflink/ldlinux/kernel.c
@@ -0,0 +1,128 @@
+#include <stdbool.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <console.h>
+#include <dprintf.h>
+#include <syslinux/loadfile.h>
+#include <syslinux/linux.h>
+#include <syslinux/pxe.h>
+#include "core.h"
+#include "core-elf.h"
+
+const char *globaldefault = NULL;
+const char *append = NULL;
+
+/* Will be called from readconfig.c */
+int new_linux_kernel(char *okernel, char *ocmdline)
+{
+ const char *kernel_name;
+ struct initramfs *initramfs;
+ char *temp;
+ void *kernel_data;
+ size_t kernel_len;
+ bool opt_quiet = false;
+ char initrd_name[256];
+ char cmdline_buf[256], *cmdline;
+ int i;
+
+ dprintf("okernel = %s, ocmdline = %s", okernel, ocmdline);
+
+ cmdline = cmdline_buf;
+
+ temp = cmdline;
+ /*
+ strcpy(temp, "BOOT_IMAGE=");
+ temp += 11;
+ */
+
+ if (okernel)
+ kernel_name = okernel;
+ else if (globaldefault)
+ kernel_name = globaldefault;
+
+ strcpy(temp, kernel_name);
+ temp += strlen(kernel_name);
+
+ /* in elflink branch, KernelCName no more exist */
+ /*
+ else {
+ strcpy(temp, KernelCName);
+ temp += strlen(KernelCName);
+ kernel_name = KernelCName;
+ }
+ */
+
+ *temp = ' ';
+ temp++;
+ if (ocmdline)
+ strcpy(temp, ocmdline);
+ else if (append)
+ strcpy(temp, append);
+ /*
+ else if (*(char *)CmdOptPtr)
+ strcpy(temp, (char *)CmdOptPtr);
+ else if (AppendLen) {
+ for (i = 0; i < AppendLen; i++)
+ *temp++ = AppendBuf[i];
+ *temp = '\0';
+ }
+ */
+
+ printf("cmdline = %s\n", cmdline);
+ /*
+ printf("VkernelEnd = %x\n", VKernelEnd);
+ printf("HighMemSize = %x\n", __com32.cs_memsize);
+ */
+
+ /* "keeppxe" handling */
+#if IS_PXELINUX
+ extern char KeepPXE;
+
+ if (strstr(cmdline, "keeppxe"))
+ KeepPXE |= 1;
+#endif
+
+ if (strstr(cmdline, "quiet"))
+ opt_quiet = true;
+
+ if (!opt_quiet)
+ printf("Loading %s... ", kernel_name);
+
+ if (loadfile(kernel_name, &kernel_data, &kernel_len)) {
+ if (opt_quiet)
+ printf("Loading %s ", kernel_name);
+ printf("failed!\n");
+ goto bail;
+ }
+
+ if (!opt_quiet)
+ printf("ok\n");
+
+ /* Initialize the initramfs chain */
+ initramfs = initramfs_init();
+ if (!initramfs)
+ goto bail;
+
+ /* Find and load initramfs */
+ temp = strstr(cmdline, "initrd=");
+ if (temp) {
+ i = 0;
+
+ temp += strlen("initrd=");
+ while (*temp != ' ' && *temp)
+ initrd_name[i++] = *temp++;
+ initrd_name[i] = '\0';
+
+ initramfs_load_archive(initramfs, initrd_name);
+ }
+
+ //dprintf("loading initrd done");
+
+ /* This should not return... */
+ syslinux_boot_linux(kernel_data, kernel_len, initramfs, cmdline);
+
+bail:
+ printf("Kernel load failure (insufficient memory?)\n");
+ return 1;
+}