1 /* ----------------------------------------------------------------------- *
3 * Copyright 2004-2008 H. Peter Anvin - All Rights Reserved
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
8 * Boston MA 02110-1301, USA; either version 2 of the License, or
9 * (at your option) any later version; incorporated herein by reference.
11 * ----------------------------------------------------------------------- */
21 #include <sys/module.h>
26 #include "localboot.h"
29 #include <syslinux/bootrm.h>
30 #include <syslinux/movebits.h>
31 #include <syslinux/config.h>
32 #include <syslinux/boot.h>
34 const struct image_types image_boot_types
[] = {
35 { "localboot", IMAGE_TYPE_LOCALBOOT
},
36 { "kernel", IMAGE_TYPE_KERNEL
},
37 { "linux", IMAGE_TYPE_LINUX
},
38 { "boot", IMAGE_TYPE_BOOT
},
39 { "bss", IMAGE_TYPE_BSS
},
40 { "pxe", IMAGE_TYPE_PXE
},
41 { "fdimage", IMAGE_TYPE_FDIMAGE
},
42 { "com32", IMAGE_TYPE_COM32
},
43 { "config", IMAGE_TYPE_CONFIG
},
47 extern int create_args_and_load(char *);
49 __export
void execute(const char *cmdline
, uint32_t type
)
51 const char *kernel
, *args
;
56 memset(&ireg
, 0, sizeof ireg
);
58 q
= malloc(strlen(cmdline
) + 2);
60 printf("%s(): Fail to malloc a buffer to exec %s\n",
67 while (*p
&& !my_isspace(*p
))
72 while (*p
&& my_isspace(*p
))
77 dprintf("kernel is %s, args = %s type = %d \n", kernel
, args
, type
);
79 if (kernel
[0] == '.') {
80 /* It might be a type specifier */
81 const struct image_types
*t
;
82 for (t
= image_boot_types
; t
->name
; t
++) {
83 if (!strcmp(kernel
+ 1, t
->name
)) {
85 * Strip the type specifier, apply the
86 * filename extension if COM32 and
89 if (t
->type
== IMAGE_TYPE_COM32
) {
90 p
= apply_extension(p
, ".c32");
101 if (type
== IMAGE_TYPE_COM32
) {
103 * We may be called with the console in an unknown
104 * state, so initialise it.
106 ldlinux_console_init();
108 /* new entry for elf format c32 */
109 if (create_args_and_load((char *)cmdline
))
110 printf("Failed to load COM32 file %s\n", kernel
);
113 * The old COM32 module code would run the module then
114 * drop the user back at the command prompt,
115 * irrespective of how the COM32 module was loaded,
116 * e.g. from vesamenu.c32.
118 unload_modules_since("ldlinux.c32");
120 /* Restore the console */
121 ldlinux_console_init();
123 ldlinux_enter_command();
124 } else if (type
== IMAGE_TYPE_CONFIG
) {
125 char *argv
[] = { "ldlinux.c32", NULL
};
128 /* kernel contains the config file name */
129 realpath(ConfigName
, kernel
, FILENAME_MAX
);
131 /* If we got anything on the command line, do a chdir */
133 mangle_name(config_cwd
, args
);
135 rv
= start_ldlinux(argv
);
136 printf("Failed to exec ldlinux.c32: %s\n", strerror(rv
));
137 } else if (type
== IMAGE_TYPE_LOCALBOOT
) {
138 local_boot(strtoul(kernel
, NULL
, 0));
139 } else if (type
== IMAGE_TYPE_PXE
|| type
== IMAGE_TYPE_BSS
||
140 type
== IMAGE_TYPE_BOOT
) {
141 chainboot_file(kernel
, type
);
143 /* Need add one item for kernel load, as we don't use
144 * the assembly runkernel.inc any more */
145 new_linux_kernel((char *)kernel
, (char *)cmdline
);
148 free((void *)kernel
);
150 /* If this returns, something went bad; return to menu */