diff options
Diffstat (limited to 'com32/elflink/ldlinux')
-rw-r--r-- | com32/elflink/ldlinux/Makefile | 3 | ||||
-rw-r--r-- | com32/elflink/ldlinux/adv.c | 8 | ||||
-rw-r--r-- | com32/elflink/ldlinux/advwrite.c | 45 | ||||
-rw-r--r-- | com32/elflink/ldlinux/ldlinux.c | 35 | ||||
-rw-r--r-- | com32/elflink/ldlinux/setadv.c | 116 |
5 files changed, 204 insertions, 3 deletions
diff --git a/com32/elflink/ldlinux/Makefile b/com32/elflink/ldlinux/Makefile index 318b3ac4..32780c49 100644 --- a/com32/elflink/ldlinux/Makefile +++ b/com32/elflink/ldlinux/Makefile @@ -19,7 +19,8 @@ CFLAGS += -I$(topdir)/core/elflink -I$(topdir)/core/include 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 get_key.o + adv.o ipappend.o execute.o kernel.o get_key.o \ + advwrite.o setadv.o $(LD) $(LDFLAGS) -o $@ $^ LNXLIBOBJS = get_key.lo diff --git a/com32/elflink/ldlinux/adv.c b/com32/elflink/ldlinux/adv.c index be38e89d..b81361f2 100644 --- a/com32/elflink/ldlinux/adv.c +++ b/com32/elflink/ldlinux/adv.c @@ -33,15 +33,21 @@ #include <syslinux/adv.h> #include <klibc/compiler.h> +#include <inttypes.h> #include <com32.h> void *__syslinux_adv_ptr; size_t __syslinux_adv_size; -void __constructor __syslinux_get_adv(void) +extern void adv_init(void); +void __constructor __syslinux_init(void) { static com32sys_t reg; + /* Initialize the ADV structure */ + reg.eax.w[0] = 0x0025; + __intcall(0x22, ®, NULL); + reg.eax.w[0] = 0x001c; __intcall(0x22, ®, ®); __syslinux_adv_ptr = MK_PTR(reg.es, reg.ebx.w[0]); diff --git a/com32/elflink/ldlinux/advwrite.c b/com32/elflink/ldlinux/advwrite.c new file mode 100644 index 00000000..4152eea5 --- /dev/null +++ b/com32/elflink/ldlinux/advwrite.c @@ -0,0 +1,45 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 2007-2008 H. Peter Anvin - All Rights Reserved + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall + * be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * ----------------------------------------------------------------------- */ + +/* + * syslinux/advwrite.c + * + * Write back the ADV + */ + +#include <syslinux/adv.h> +#include <klibc/compiler.h> +#include <com32.h> + +int syslinux_adv_write(void) +{ + static com32sys_t reg; + + reg.eax.w[0] = 0x001d; + __intcall(0x22, ®, ®); + return (reg.eflags.l & EFLAGS_CF) ? -1 : 0; +} diff --git a/com32/elflink/ldlinux/ldlinux.c b/com32/elflink/ldlinux/ldlinux.c index 67f38c0d..8b5fd301 100644 --- a/com32/elflink/ldlinux/ldlinux.c +++ b/com32/elflink/ldlinux/ldlinux.c @@ -7,6 +7,7 @@ #include "com32.h" #include "menu.h" #include "config.h" +#include "syslinux/adv.h" #include <sys/module.h> @@ -103,11 +104,43 @@ static void enter_cmdline(void) int main(int argc, char **argv) { + com32sys_t ireg, oreg; + uint8_t *adv; + int count = 0; + openconsole(&dev_rawcon_r, &dev_ansiserial_w); parse_configs(NULL); - /* TODO: ADV */ + __syslinux_init(); + adv = syslinux_getadv(ADV_BOOTONCE, &count); + if (adv && count) { + /* + * We apparently have a boot-once set; clear it and + * then execute the boot-once. + */ + uint8_t *src, *dst, *cmdline; + int i; + + src = adv; + cmdline = dst = malloc(count + 1); + if (!dst) { + printf("Failed to allocate memory for ADV\n"); + goto cmdline; + } + + for (i = 0; i < count; i++) + *dst++ = *src++; + *dst = '\0'; /* Null-terminate */ + + /* Clear the boot-once data from the ADV */ + if (!syslinux_setadv(ADV_BOOTONCE, 0, NULL)) + syslinux_adv_write(); + + load_kernel(cmdline); /* Shouldn't return */ + goto cmdline; + } + /* TODO: Check KbdFlags? */ if (forceprompt) diff --git a/com32/elflink/ldlinux/setadv.c b/com32/elflink/ldlinux/setadv.c new file mode 100644 index 00000000..40f00a4e --- /dev/null +++ b/com32/elflink/ldlinux/setadv.c @@ -0,0 +1,116 @@ +/* ----------------------------------------------------------------------- * + * + * 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. + * + * ----------------------------------------------------------------------- */ + +/* + * syslinux/setadv.c + * + * (Over)write a data item in the auxilliary data vector. To + * delete an item, set its length to zero. + * + * Return 0 on success, -1 on error, and set errno. + * + * NOTE: Data is not written to disk unless + * syslinux_adv_write() is called. + */ + +#include <syslinux/adv.h> +#include <klibc/compiler.h> +#include <inttypes.h> +#include <string.h> +#include <errno.h> +#include <alloca.h> + +int syslinux_setadv(int tag, size_t size, const void *data) +{ + uint8_t *p, *advtmp; + size_t rleft, left; + + if ((unsigned)tag - 1 > 254) { + errno = EINVAL; + return -1; /* Impossible tag value */ + } + + if (size > 255) { + errno = ENOSPC; /* Max 255 bytes for a data item */ + return -1; + } + + rleft = left = syslinux_adv_size(); + p = advtmp = alloca(left); + memcpy(p, syslinux_adv_ptr(), left); /* Make working copy */ + + while (rleft >= 2) { + uint8_t ptag = p[0]; + size_t plen = p[1] + 2; + + if (ptag == ADV_END) + break; + + if (ptag == tag) { + /* Found our tag. Delete it. */ + + if (plen >= rleft) { + /* Entire remainder is our tag */ + break; + } + memmove(p, p + plen, rleft - plen); + rleft -= plen; /* Fewer bytes to read, but not to write */ + } else { + /* Not our tag */ + if (plen > rleft) + break; /* Corrupt tag (overrun) - overwrite it */ + + left -= plen; + rleft -= plen; + p += plen; + } + } + + /* Now (p, left) reflects the position to write in and how much space + we have for our data. */ + + if (size) { + if (left < size + 2) { + errno = ENOSPC; /* Not enough space for data */ + return -1; + } + + *p++ = tag; + *p++ = size; + memcpy(p, data, size); + p += size; + left -= size + 2; + } + + memset(p, 0, left); + + /* If we got here, everything went OK, commit the write to low memory */ + memcpy(syslinux_adv_ptr(), advtmp, syslinux_adv_size()); + + return 0; +} |