diff options
author | Gene Cumm <gene.cumm@gmail.com> | 2015-02-14 14:04:45 -0500 |
---|---|---|
committer | Gene Cumm <gene.cumm@gmail.com> | 2015-02-14 14:04:45 -0500 |
commit | 9cb1b0bdf58454c1206ed6f9db8e0d1cdc514979 (patch) | |
tree | a729e475419295cf7f9e3e952c6c6990908e09f1 | |
parent | aee0dc5565711ef5be7c30fb5fc1c5f3f98db09f (diff) | |
parent | 68cb978ab7e692d772e4d62d3585b8f7bac43b4b (diff) | |
download | syslinux-9cb1b0bdf58454c1206ed6f9db8e0d1cdc514979.tar.gz |
Merge remote-tracking branch 'u-gh-wferi/pub'
Signed-off-by: Gene Cumm <gene.cumm@gmail.com>
-rw-r--r-- | com32/include/libansi.h | 3 | ||||
-rw-r--r-- | com32/lua/doc/syslinux.asc | 336 | ||||
-rw-r--r-- | com32/lua/src/syslinux.c | 291 | ||||
-rw-r--r-- | com32/lua/src/vesa.c | 2 | ||||
-rw-r--r-- | com32/lua/test/automenu.lua | 38 |
5 files changed, 329 insertions, 341 deletions
diff --git a/com32/include/libansi.h b/com32/include/libansi.h index d813f9fc..030fd0df 100644 --- a/com32/include/libansi.h +++ b/com32/include/libansi.h @@ -29,6 +29,9 @@ #ifndef DEFINE_LIB_ANSI_H #define DEFINE_LIB_ANSI_H +#include <stdbool.h> +#include <stdio.h> + #define CSI "\e[" void display_cursor(bool status); diff --git a/com32/lua/doc/syslinux.asc b/com32/lua/doc/syslinux.asc index 424c51f1..6475d42f 100644 --- a/com32/lua/doc/syslinux.asc +++ b/com32/lua/doc/syslinux.asc @@ -23,270 +23,232 @@ Modules Modules must be explicitly loaded into the namespace before use, for example: ...................................................... -syslinux = require ("syslinux") +local sl = require "syslinux" ...................................................... +Using +local+, as above, is good practice in scripts, but it must be +omitted when working interactively. SYSLINUX ~~~~~~~~ -.syslinux.version() +version():: +Return the Syslinux version string. -Returns version string +derivative():: +Return the running Syslinux derivative +(the string +ISOLINUX+, +PXELINUX+ or +SYSLINUX+). -.syslinux.derivative() +sleep(s):: +Sleep for +s+ seconds. -Returns running Syslinux's derivative (ISOLINUX, PXELINUX or SYSLINUX). -See com32/lua/test/syslinux-derivative.lua for an example. - -.syslinux.sleep(s) - -Sleep for +s+ seconds - -.syslinux.msleep(ms) - -Sleep for +ms+ milliseconds - -.run_command(command) +msleep(ms):: +Sleep for +ms+ milliseconds. +run_command(command):: Execute syslinux command line +command+. - ++ _Example_: ...................................................... - syslinux.run_command("memdisk initrd=/dos/BIOS/FSC-P7935-108.img raw") +local sl = require "syslinux" +sl.run_command "memdisk initrd=/dos/BIOS/FSC-P7935-108.img raw" ...................................................... -.run_default() +run_default():: +Execute the default command in the configuration. -FIXME +local_boot(type):: +Do a local boot. The +type+ values are described in the documentation +of the LOCALBOOT configuration item. -.local_boot() +final_cleanup(flags):: +Restore sane hardware and software status before booting. If +flags+ +is 3, keep the PXE and UNDI stacks in memory (see the _keeppxe_ option). +Only needed in special circumstances. -FIXME +boot_linux(kernel[,cmdline]):: +Load and boot the Linux kernel at path +kernel+. Initramfs images are +loaded according to the +initrd+ option in +cmdline+. The ++BOOT_IMAGE+ parameter is added to the command line with the value of ++kernel+. -.final_cleanup() +IMAGE_TYPE:: +A table mapping the various kernel type strings to the integer +type+ +parameter of +run_kernel_image()+. -FIXME +run_kernel_image(kernel, cmdline, ipappend_flags, type):: +Load the specified +kernel+ and run it with +cmdline+. See also the +documentation of the IPAPPEND configuration item; +type+ is one of +the values of the +IMAGE_TYPE+ table. -.boot_linux(kernel, cmdline, [mem_limit], [videomode]) +loadfile(filename):: +Return a _file_ object with the contents of file +filename+ loaded. +Its methods are: -FIXME +size()::: +Return the size of a loaded _file_. -.run_kernel_image(kernel, cmdline, ipappend_flags, type) +name()::: +Return the name of a loaded _file_. -FIXME +initramfs():: +Return an empty _initramfs_ object. Its methods are: -.loadfile(filname) +load(filename)::: +Load contents of +filename+ into an _initramfs_ and return the +extended object. -Load file +filename+ (via TFTP) +add_file(filename[,data[,do_mkdir[,mode]]])::: +Add +filename+ of +mode+ containing +data+ to an _initramfs_ and +return the extended object. +If +do_mkdir+, create parent directories, too. +mode+ defaults +to 7*64+5*8+5 (which is 0755 in octal). -.filesize(file) +size()::: +Returns the current size of an _initramfs_. -Return size of +file+ (loaded by loadfile()) +boot_it(kernel[,initramfs,[cmdline]]):: +Boot the loaded +kernel+ (a _file_ object) with an optional ++initramfs+ (an _initramfs_ object or +nil+) and +cmdline+. -.filename(file) +_Example_: +...................................................... +local sl = require "syslinux" -Return name of +file+ (loaded by loadfile()) +kernel = sl.loadfile "/SuSE-11.1/x86_64/linux" +print("File name: " .. kernel:name() .. " size: " .. kernel:size()) -.in itramfs_init() +initrd1 = "/SuSE-11.1/x86_64/initrd" -Return empty initramfs object +initrd = sl.initramfs() +initrd:load(initrd1) +print ("File name: " .. initrd1 .. " size: " .. initrd:size()) -.initramfs_load_archive(initramfs, filename) +sl.boot_it(kernel, initrd, "init=/bin/bash") +...................................................... -Load contents of +filename+ into +initramfs+. Initialize -+initramfs+ with initramfs_init() before use. +KEY:: +Table containing the return values of +get_key()+ for special (eg. function) +keys. -.initramfs_add_file(initramfs, file) +KEY_CTRL(key):: +Return the code for the Ctrl-modified version of the given ASCII code. -Adds +file+ to +initramfs+. +initramfs+ needs to be -initialized, +file+ has been loaded by loadfile(). +get_key(timeout):: +Wait at most +timeout+ ms for a key press. +Return the ASCII code of the pressed key, some other value of the +KEY+ +table, or +KEY.NONE+ on timeout. -_Example_: -...................................................... - -- get nice output - printf = function(s,...) - return io.write(s:format(...)) - end -- function - - kernel = syslinux.loadfile("/SuSE-11.1/x86_64/linux") - - printf("Filename/size: %s %d\n", syslinux.filename(kernel), syslinux.filesize(kernel)) - - initrd = syslinux.loadfile("/SuSE-11.1/x86_64/initrd") - - printf("Filename/size: %s %d\n", syslinux.filename(initrd), syslinux.filesize(initrd)) - - initrd = syslinux.initramfs_init() - syslinux.initramfs_load_archive(initrd, "/SuSE-11.1/x86_64/initrd"); - - syslinux.boot_it(kernel, initrd, "init=/bin/bash") - - syslinux.sleep(20) - -...................................................... +config_file():: +Return the path of the current config file. +ipappend_strs():: +Return the table of SYSAPPEND (formerly IPAPPEND) strings. See also +the documentation of those configuration items. + +reboot([warm_boot]):: +Reboot. If +warm_boot+ is nonzero, perform a warm reboot. DMI ~~~ -.dmi_supported() - -Returns +true+ if DMI is supported on machine, +false+ otherwise. - -.dmi_gettable() +supported():: +Return true if DMI is supported on machine, false otherwise. -Returns a list if key-value pairs. The key is one of the DMI property strings: -FIXME list +gettable():: +Return DMI info as a nested table. _Example_: ...................................................... - if (dmi.supported()) then - - dmitable = dmi.gettable() - - for k,v in pairs(dmitable) do - print(k, v) - end - - print(dmitable["system.manufacturer"]) - print(dmitable["system.product_name"]) - print(dmitable["bios.bios_revision"]) - - if ( string.match(dmitable["system.product_name"], "ESPRIMO P7935") ) then - print("Matches") - syslinux.run_command("memdisk initrd=/dos/BIOS/FSC-P7935-108.img raw") - else - print("Does not match") - syslinux.run_command("memdisk initrd=/dos/BIOS/FSC-P7935-108.img raw") - end - - end +local sl = require "syslinux" +local dmi = require "dmi" + +if (dmi.supported()) then + + dmitable = dmi.gettable() + + for k,v in pairs(dmitable) do + print(k, v) + end + + print(dmitable.system.manufacturer) + print(dmitable.system.product_name) + print(dmitable.bios.bios_revision) + + if ( string.match(dmitable.system.product_name, "ESPRIMO P7935") ) then + print("Matches") + sl.run_command("memdisk initrd=/dos/BIOS/FSC-P7935-108.img raw") + else + print("Does not match") + sl.run_command("memdisk initrd=/dos/BIOS/FSC-P7935-108.img raw") + end +end ...................................................... PCI ~~~ -.pci_getinfo() - -Return list of value pairs (device_index, device) of all PCI devices. - -.pci_getidlist(filename) +getinfo():: +Return the table of all PCI devices, keyed by the device index. +Each device is described by a table of its properties. +getidlist(filename):: Load a tab separated list of PCI IDs and their description. Sample files can be found here: http://pciids.sourceforge.net/ - _Example_: ...................................................... --- get nice output -printf = function(s,...) - return io.write(s:format(...)) - end - --- get device info -pciinfo = pci.getinfo() +local pci = require "pci" --- get plain text device description pciids = pci.getidlist("/pci.ids") --- list all pci busses -for dind,device in pairs(pciinfo) do - - -- search for device description - search = string.format("%04x%04x", device['vendor'], device['product']) - - printf(" %04x:%04x:%04x:%04x = ", device['vendor'], device['product'], - device['sub_vendor'], device['sub_product']) - - if ( pciids[search] ) then - printf("%s\n", pciids[search]) - else - printf("Unknown\n") - end +for dind, device in pairs (pci.getinfo()) do + local vendor = string.format ("%04x", device.vendor) + local main_id = vendor .. string.format ("%04x", device.product) + local sub_id = string.format ("%04x%04x", device.sub_vendor, device.sub_product) + io.write (string.format ("%s:%s = %s %s (%s)\n", main_id, sub_id, pciids[vendor], + pciids[main_id], pciids[main_id .. sub_id] or "unknown subdevice")) end - --- print(pciids["8086"]) --- print(pciids["10543009"]) --- print(pciids["00700003"]) --- print(pciids["0070e817"]) --- print(pciids["1002437a1002437a"]) ...................................................... VESA ~~~~ -.getmodes() - +getmodes():: Return list of available VESA modes. - ++ _Example_: ...................................................... - -- get nice output - printf = function(s,...) - return io.write(s:format(...)) - end - - -- list available vesa modes - -- only one supported right now, not of much use - modes = vesa.getmodes() - - for mind,mode in pairs(modes) do - printf("%04x: %dx%dx%d\n", mode['mode'], mode['hres'], mode['vres'], mode['bpp']) - end -...................................................... +local vesa = require "vesa" +for mind,mode in pairs(vesa.getmodes()) do + print (string.format ("%04x: %dx%dx%d", mode.mode, mode.hres, mode.vres, mode.bpp)) +end +...................................................... -.setmode() - -Set (only currently supported) VESA mode. - -.load_background(filename) +setmode():: +Set the 640x480 VESA mode. -Load +filename+ from TFTP, and use it as background image. +load_background(filename):: +Load +filename+ (a PNG, JPEG or LSS-16 format image), and tile it as +background image. The text already present is not erased. _Example_: ...................................................... - -- get nice output - printf = function(s,...) - return io.write(s:format(...)) - end - - -- lets go to graphics land - vesa.setmode() - - printf("Hello World! - VESA mode") - - -- some text to display "typing style" - textline=[[ - From syslinux GSOC 2009 home page: - - Finish the Lua engine - - We already have a Lua interpreter integrated with the Syslinux build. However, right now it is not very useful. We need to create a set of bindings to the Syslinux functionality, and have an array of documentation and examples so users can use them. - - This is not a documentation project, but the documentation deliverable will be particularly important for this one, since the intended target is system administrators, not developers. - ]] - - - -- do display loop - -- keep in mind: background change will not erase text! - while ( true ) do - - vesa.load_background("/background1.jpg") - - syslinux.sleep(1) - - for i = 1, #textline do - local c = textline:sub(i,i) - printf("%s", c) - syslinux.msleep(200) - end - - syslinux.sleep(10) +local sl = require "syslinux" +local vesa = require "vesa" -...................................................... +vesa.setmode() +vesa.load_background "sample2.jpg" +for c in string.gmatch ("Hello World! - VESA mode", ".") do + io.write (c) + sl.msleep(200) +end + +vesa.load_background "PXE-RRZE_small.jpg" +sl.sleep(3) +...................................................... diff --git a/com32/lua/src/syslinux.c b/com32/lua/src/syslinux.c index ea702fa7..9a2998b9 100644 --- a/com32/lua/src/syslinux.c +++ b/com32/lua/src/syslinux.c @@ -44,10 +44,11 @@ int __parse_argv(char ***argv, const char *str); -#define SYSLINUX_FILE "syslinux_file" +static const char SYSLINUX_FILE[] = "syslinux_file"; +static const char SYSLINUX_INITRAMFS[] = "syslinux_initramfs"; typedef struct syslinux_file { - char *data; + void *data; char *name; size_t size; } syslinux_file; @@ -73,48 +74,6 @@ static char *find_argument(char **argv, const char *argument) return ptr; } -/* Get a value with a potential suffix (k/m/g/t/p/e) */ -static unsigned long long suffix_number(const char *str) -{ - char *ep; - unsigned long long v; - int shift; - - v = strtoull(str, &ep, 0); - switch (*ep | 0x20) { - case 'k': - shift = 10; - break; - case 'm': - shift = 20; - break; - case 'g': - shift = 30; - break; - case 't': - shift = 40; - break; - case 'p': - shift = 50; - break; - case 'e': - shift = 60; - break; - default: - shift = 0; - break; - } - v <<= shift; - - return v; -} - -/* Truncate to 32 bits, with saturate */ -static inline uint32_t saturate32(unsigned long long v) -{ - return (v > 0xffffffff) ? 0xffffffff : (uint32_t) v; -} - /* Stitch together the command line from a set of argv's */ static char *make_cmdline(char **argv) { @@ -171,8 +130,7 @@ static int sl_local_boot(lua_State * L) static int sl_final_cleanup(lua_State * L) { - uint16_t flags = luaL_checkint(L, 1); - syslinux_local_boot(flags); + syslinux_final_cleanup (luaL_checkint (L, 1)); return 0; } @@ -182,18 +140,13 @@ static int sl_boot_linux(lua_State * L) const char *kernel = luaL_checkstring(L, 1); const char *cmdline = luaL_optstring(L, 2, ""); char *initrd; - void *kernel_data, *file_data; - size_t kernel_len, file_len; + void *kernel_data; + size_t kernel_len; struct initramfs *initramfs; char *newcmdline; - uint32_t mem_limit = luaL_optint(L, 3, 0); - uint16_t video_mode = luaL_optint(L, 4, 0); int ret; char **argv, **argp, *arg, *p; - (void)mem_limit; - (void)video_mode; - ret = __parse_argv(&argv, cmdline); newcmdline = malloc(strlen(kernel) + 12); @@ -219,7 +172,7 @@ static int sl_boot_linux(lua_State * L) msleep(1000); */ - printf("Loading kernel %s...\n", kernel); + printf("Loading kernel %s... ", kernel); if (loadfile(kernel, &kernel_data, &kernel_len)) printf("failed!\n"); else @@ -237,10 +190,10 @@ static int sl_boot_linux(lua_State * L) initrd = arg; printf("Loading initrd %s... ", initrd); - if (initramfs_load_archive(initramfs, initrd)) { + if (initramfs_load_archive(initramfs, initrd)) printf("failed!\n"); - } - printf("ok\n"); + else + printf("ok\n"); if (p) *p++ = ','; @@ -283,27 +236,30 @@ static int sl_run_kernel_image(lua_State * L) static int sl_loadfile(lua_State * L) { - const char *filename = luaL_checkstring(L, 1); - syslinux_file *file; - - void *file_data; - size_t file_len; - - if (loadfile(filename, &file_data, &file_len)) { - lua_pushstring(L, "Could not load file"); - lua_error(L); + size_t name_len; + const char *filename = luaL_checklstring (L, 1, &name_len); + syslinux_file *file = lua_newuserdata (L, sizeof (syslinux_file)); + + file->name = malloc (name_len+1); + if (!file->name) return luaL_error (L, "Out of memory"); + memcpy (file->name, filename, name_len+1); + if (loadfile (file->name, &file->data, &file->size)) { + free (file->name); + return luaL_error (L, "Could not load file"); } + luaL_setmetatable (L, SYSLINUX_FILE); + return 1; +} - file = malloc(sizeof(syslinux_file)); - strlcpy(file->name,filename,sizeof(syslinux_file)); - file->size = file_len; - file->data = file_data; - - lua_pushlightuserdata(L, file); - luaL_getmetatable(L, SYSLINUX_FILE); - lua_setmetatable(L, -2); +static int sl_unloadfile (lua_State *L) +{ + syslinux_file *file = luaL_checkudata (L, 1, SYSLINUX_FILE); - return 1; + free (file->name); + free (file->data); + /* the __gc method may also be (repeatedly) called before garbage collection, so: */ + file->name = file->data = NULL; + return 0; } static int sl_filesize(lua_State * L) @@ -326,55 +282,80 @@ static int sl_filename(lua_State * L) static int sl_initramfs_init(lua_State * L) { - struct initramfs *initramfs; + struct initramfs *ir = lua_newuserdata (L, sizeof (*ir)); - initramfs = initramfs_init(); - if (!initramfs) - printf("Initializing initrd failed!\n"); + memset (ir, 0, sizeof (*ir)); /* adapted from initramfs_init() */ + ir->prev = ir->next = ir; + luaL_setmetatable (L, SYSLINUX_INITRAMFS); + return 1; +} - lua_pushlightuserdata(L, initramfs); - luaL_getmetatable(L, SYSLINUX_FILE); - lua_setmetatable(L, -2); +static int sl_initramfs_load_archive(lua_State * L) +{ + const char *filename = luaL_checkstring(L, 2); + if (initramfs_load_archive (luaL_checkudata(L, 1, SYSLINUX_INITRAMFS), filename)) + return luaL_error (L, "Loading initramfs %s failed", filename); + lua_settop (L, 1); return 1; } -static int sl_initramfs_load_archive(lua_State * L) +static int sl_initramfs_add_file(lua_State * L) { - struct initramfs *initramfs = luaL_checkudata(L, 1, SYSLINUX_FILE); const char *filename = luaL_checkstring(L, 2); + size_t file_len; + const char *file_data = luaL_optlstring (L, 3, NULL, &file_len); + void *data = NULL; - if (initramfs_load_archive(initramfs, filename)) { - printf("failed!\n"); + if (file_len) { + data = malloc (file_len); + if (!data) return luaL_error (L, "Out of memory"); + memcpy (data, file_data, file_len); } + if (initramfs_add_file(luaL_checkudata(L, 1, SYSLINUX_INITRAMFS), + data, file_len, file_len, filename, + luaL_optint (L, 4, 0), luaL_optint (L, 5, 0755))) + return luaL_error (L, "Adding file %s to initramfs failed", filename); + lua_settop (L, 1); + return 1; +} - return 0; +static int sl_initramfs_size (lua_State *L) +{ + lua_pushinteger (L, initramfs_size (luaL_checkudata(L, 1, SYSLINUX_INITRAMFS))); + return 1; } -static int sl_initramfs_add_file(lua_State * L) +static int sl_initramfs_purge (lua_State *L) { - struct initramfs *initramfs = luaL_checkudata(L, 1, SYSLINUX_FILE); - const char *filename = luaL_checkstring(L, 2); - void *file_data = NULL; - size_t file_len = 0; + struct initramfs *ir = luaL_checkudata(L, 1, SYSLINUX_INITRAMFS); - return initramfs_add_file(initramfs, file_data, file_len, file_len, - filename, 0, 0755); + ir = ir->next; + while (ir->len) { + free ((void *)ir->data); + ir = ir->next; + free (ir->prev); + } + /* the __gc method may also be (repeatedly) called before garbage collection, so: */ + ir->next = ir->prev = ir; + return 0; } static int sl_boot_it(lua_State * L) { const syslinux_file *kernel = luaL_checkudata(L, 1, SYSLINUX_FILE); - struct initramfs *initramfs = luaL_checkudata(L, 2, SYSLINUX_FILE); - const char *cmdline = luaL_optstring(L, 3, ""); - uint32_t mem_limit = luaL_optint(L, 4, 0); - uint16_t video_mode = luaL_optint(L, 5, 0); - /* Preventing gcc to complain about unused variables */ - (void)video_mode; - (void)mem_limit; - - return syslinux_boot_linux(kernel->data, kernel->size, - initramfs, NULL, (char *)cmdline); + struct initramfs *ir = luaL_testudata(L, 2, SYSLINUX_INITRAMFS); + size_t len; + const char *cmdline_param = luaL_optlstring(L, 3, "", &len); + char *cmdline = malloc (len+1); /* syslinux_boot_linux needs non-const cmdline */ + int err; + + if (!cmdline) return luaL_error (L, "Out of memory"); + memcpy (cmdline, cmdline_param, len+1); + err = syslinux_boot_linux (kernel->data, kernel->size, ir, NULL, cmdline); + free (cmdline); + if (err) return luaL_error (L, "Booting failed"); + return 0; /* unexpected */ } static int sl_config_file(lua_State * L) @@ -464,11 +445,7 @@ static const luaL_Reg syslinuxlib[] = { {"sleep", sl_sleep}, {"msleep", sl_msleep}, {"loadfile", sl_loadfile}, - {"filesize", sl_filesize}, - {"filename", sl_filename}, - {"initramfs_init", sl_initramfs_init}, - {"initramfs_load_archive", sl_initramfs_load_archive}, - {"initramfs_add_file", sl_initramfs_add_file}, + {"initramfs", sl_initramfs_init}, {"boot_it", sl_boot_it}, {"config_file", sl_config_file}, {"ipappend_strs", sl_ipappend_strs}, @@ -480,46 +457,84 @@ static const luaL_Reg syslinuxlib[] = { {NULL, NULL} }; +static const luaL_Reg file_methods[] = { + {"__gc", sl_unloadfile}, + {"name", sl_filename}, + {"size", sl_filesize}, + {NULL, NULL} +}; + +static const luaL_Reg initramfs_methods[] = { + {"__gc", sl_initramfs_purge}, + {"load", sl_initramfs_load_archive}, + {"add_file", sl_initramfs_add_file}, + {"size", sl_initramfs_size}, + {NULL, NULL} +}; + /* This defines a function that opens up your library. */ LUALIB_API int luaopen_syslinux(lua_State * L) { luaL_newmetatable(L, SYSLINUX_FILE); + lua_pushstring (L, "__index"); + lua_pushvalue (L, -2); + lua_settable (L, -3); + luaL_setfuncs (L, file_methods, 0); + + luaL_newmetatable (L, SYSLINUX_INITRAMFS); + lua_pushstring (L, "__index"); + lua_pushvalue (L, -2); + lua_settable (L, -3); + luaL_setfuncs (L, initramfs_methods, 0); luaL_newlib(L, syslinuxlib); +#define export(c,x) lua_pushinteger (L,c##_##x); lua_setfield (L, -2, #x); + lua_newtable (L); -#define export_key(x) lua_pushinteger (L, KEY_##x); lua_setfield (L, -2, #x); - export_key (NONE); - export_key (BACKSPACE); - export_key (TAB); - export_key (ENTER); - export_key (ESC); - export_key (DEL); - export_key (F1); - export_key (F2); - export_key (F3); - export_key (F4); - export_key (F5); - export_key (F6); - export_key (F7); - export_key (F8); - export_key (F9); - export_key (F10); - export_key (F11); - export_key (F12); - export_key (UP); - export_key (DOWN); - export_key (LEFT); - export_key (RIGHT); - export_key (PGUP); - export_key (PGDN); - export_key (HOME); - export_key (END); - export_key (INSERT); - export_key (DELETE); + export (KEY, NONE); + export (KEY, BACKSPACE); + export (KEY, TAB); + export (KEY, ENTER); + export (KEY, ESC); + export (KEY, DEL); + export (KEY, F1); + export (KEY, F2); + export (KEY, F3); + export (KEY, F4); + export (KEY, F5); + export (KEY, F6); + export (KEY, F7); + export (KEY, F8); + export (KEY, F9); + export (KEY, F10); + export (KEY, F11); + export (KEY, F12); + export (KEY, UP); + export (KEY, DOWN); + export (KEY, LEFT); + export (KEY, RIGHT); + export (KEY, PGUP); + export (KEY, PGDN); + export (KEY, HOME); + export (KEY, END); + export (KEY, INSERT); + export (KEY, DELETE); lua_setfield (L, -2, "KEY"); + lua_newtable (L); + export (IMAGE_TYPE, KERNEL); + export (IMAGE_TYPE, LINUX); + export (IMAGE_TYPE, BOOT); + export (IMAGE_TYPE, BSS); + export (IMAGE_TYPE, PXE); + export (IMAGE_TYPE, FDIMAGE); + export (IMAGE_TYPE, COM32); + export (IMAGE_TYPE, CONFIG); + export (IMAGE_TYPE, LOCALBOOT); + lua_setfield (L, -2, "IMAGE_TYPE"); + return 1; } diff --git a/com32/lua/src/vesa.c b/com32/lua/src/vesa.c index 28e01246..119f6fc3 100644 --- a/com32/lua/src/vesa.c +++ b/com32/lua/src/vesa.c @@ -59,8 +59,6 @@ static int vesa_getmodes(lua_State *L) while ((mode = *mode_ptr++) != 0xFFFF) { mode &= 0x1FF; /* The rest are attributes of sorts */ - printf("Found mode: 0x%04x (%dx%dx%d)\n", mode, mi->h_res, mi->v_res, mi->bpp); - memset(&rm, 0, sizeof(rm)); memset(mi, 0, sizeof *mi); rm.eax.w[0] = 0x4F01; /* Get SVGA mode information */ diff --git a/com32/lua/test/automenu.lua b/com32/lua/test/automenu.lua index 1e66cca1..002fb095 100644 --- a/com32/lua/test/automenu.lua +++ b/com32/lua/test/automenu.lua @@ -26,6 +26,17 @@ local function modifiers () return (single and " single" or "") .. ({" quiet",""," debug"})[verbosity] end +local function boot (kernel_path, initrd_path, cmdline) + print ("Loading " .. kernel_path .. " ...") + local kernel = sl.loadfile (kernel_path) + local initrd + if (initrd_path) then + print ("Loading " .. initrd_path .. " ...") + initrd = sl.initramfs():load (initrd_path) + end + sl.boot_it (kernel, initrd, cmdline) +end + local function scan (params) local sep = string.sub (params.dir, -1) == "/" and "" or "/" if not params.items then params.items = {} end @@ -35,14 +46,16 @@ local function scan (params) local from,to,version = string.find (name, "^vmlinuz%-(.*)") if from then local initrd = params.dir .. sep .. "initrd.img-" .. version - local initrd_param = "" - if lfs.attributes (initrd, "size") then - initrd_param = "initrd=" .. initrd .. " " + if not lfs.attributes (initrd, "size") then + initrd = nil end table.insert (params.items, { - show = function () return name end, + show = name .. (initrd and " +initrd" or ""), version = version, - execute = function () sl.boot_linux (path, initrd_param .. params.append .. modifiers ()) end + execute = function () + boot (path, initrd, + params.append .. modifiers ()) + end }) end end @@ -81,21 +94,18 @@ local function kernel_gt (k1, k2) return version_gt (k1.version, k2.version) end -local function print_or_call (x, def) - local t = type (x) - if t == "nil" then - if def then print (def) end - elseif t == "function" then - x () +local function get (x) + if type (x) == "function" then + return x () else - print (x) + return x end end local function draw (params) - print_or_call (params.title, "\n=== Boot menu ===") + print (get (params.title) or "\n=== Boot menu ===") for i, item in ipairs (params.items) do - print ((i == params.default and " > " or " ") .. i .. " " .. item.show ()) + print ((i == params.default and " > " or " ") .. i .. " " .. get (item.show)) end print ("\nKernel arguments:\n " .. params.append .. modifiers ()) print ("\nHit a number to select from the menu,\n ENTER to accept default,\n ESC to exit\n or any other key to print menu again") |