diff -ur --exclude='*.a' --exclude='*.o' --exclude='*.map' --unidirectional-new-file /usr/local/src/lua-4.0.1/config lua-4.0.1/config
--- /usr/local/src/lua-4.0.1/config	2000-11-07 07:28:20.000000000 +1100
+++ lua-4.0.1/config	2003-01-13 10:49:43.000000000 +1100
@@ -28,8 +28,10 @@
 # ------------------------------------------------------------------ C compiler
 
 # You need an ANSI C compiler. gcc is a popular one.
-CC= gcc
-WARN= -ansi -pedantic -Wall
+CC= /usr/i386-linux-uclibc/bin/i386-uclibc-gcc -nostdlib -Os -ffreestanding -fstrength-reduce -mcpu=i386
+WARN=-Wall -W -Wno-format -Wno-unused
+LUA_RELOC=0x60000
+EXTRA_DEFS=-DLUA_RELOC=$(LUA_RELOC) -DDATA_START=0x80000
 
 # On IRIX, cc is a good ANSI compiler.
 #CC= cc
@@ -56,7 +58,8 @@
 # in libm.a (-lm).  If your C library already includes the math functions,
 # or if you are using a modified interpreter that does not need them,
 # then comment the following line.
-EXTRA_LIBS= -lm
+#EXTRA_LIBS= -lm
+EXTRA_LIBS= /usr/i386-linux-uclibc/lib/libc.a
 
 # ------------------------------------------------------------------ librarian
 
diff -ur --exclude='*.a' --exclude='*.o' --exclude='*.map' --unidirectional-new-file /usr/local/src/lua-4.0.1/include/byteswap.h lua-4.0.1/include/byteswap.h
--- /usr/local/src/lua-4.0.1/include/byteswap.h	1970-01-01 10:00:00.000000000 +1000
+++ lua-4.0.1/include/byteswap.h	2003-01-07 22:27:31.000000000 +1100
@@ -0,0 +1,65 @@
+#define	__LITTLE_ENDIAN		/* x86 */
+
+/* Taken from /usr/include/linux/hfs_sysdep.h */
+#if defined(__BIG_ENDIAN)
+#	if !defined(__constant_htonl)
+#		define __constant_htonl(x) (x)
+#	endif
+#	if !defined(__constant_htons)
+#		define __constant_htons(x) (x)
+#	endif
+#elif defined(__LITTLE_ENDIAN)
+#	if !defined(__constant_htonl)
+#		define __constant_htonl(x) \
+        ((unsigned long int)((((unsigned long int)(x) & 0x000000ffU) << 24) | \
+                             (((unsigned long int)(x) & 0x0000ff00U) <<  8) | \
+                             (((unsigned long int)(x) & 0x00ff0000U) >>  8) | \
+                             (((unsigned long int)(x) & 0xff000000U) >> 24)))
+#	endif
+#	if !defined(__constant_htons)
+#		define __constant_htons(x) \
+        ((unsigned short int)((((unsigned short int)(x) & 0x00ff) << 8) | \
+                              (((unsigned short int)(x) & 0xff00) >> 8)))
+#	endif
+#else
+#	error "Don't know if bytes are big- or little-endian!"
+#endif
+
+#define ntohl(x) \
+(__builtin_constant_p(x) ? \
+ __constant_htonl((x)) : \
+ __swap32(x))
+#define htonl(x) \
+(__builtin_constant_p(x) ? \
+ __constant_htonl((x)) : \
+ __swap32(x))
+#define ntohs(x) \
+(__builtin_constant_p(x) ? \
+ __constant_htons((x)) : \
+ __swap16(x))
+#define htons(x) \
+(__builtin_constant_p(x) ? \
+ __constant_htons((x)) : \
+ __swap16(x))
+
+static inline unsigned long int __swap32(unsigned long int x)
+{
+	__asm__("xchgb %b0,%h0\n\t"
+		"rorl $16,%0\n\t"
+		"xchgb %b0,%h0"
+		: "=q" (x)
+		: "0" (x));
+	return x;
+}
+
+static inline unsigned short int __swap16(unsigned short int x)
+{
+	__asm__("xchgb %b0,%h0"
+		: "=q" (x)
+		: "0" (x));
+	return x;
+}
+
+/* Make routines available to all */
+#define	swap32(x)	__swap32(x)
+#define	swap16(x)	__swap16(x)
diff -ur --exclude='*.a' --exclude='*.o' --exclude='*.map' --unidirectional-new-file /usr/local/src/lua-4.0.1/include/elf_boot.h lua-4.0.1/include/elf_boot.h
--- /usr/local/src/lua-4.0.1/include/elf_boot.h	1970-01-01 10:00:00.000000000 +1000
+++ lua-4.0.1/include/elf_boot.h	2003-01-07 22:27:31.000000000 +1100
@@ -0,0 +1 @@
+#include "../../elf_boot.h"
diff -ur --exclude='*.a' --exclude='*.o' --exclude='*.map' --unidirectional-new-file /usr/local/src/lua-4.0.1/include/etherboot.h lua-4.0.1/include/etherboot.h
--- /usr/local/src/lua-4.0.1/include/etherboot.h	1970-01-01 10:00:00.000000000 +1000
+++ lua-4.0.1/include/etherboot.h	2003-01-07 22:27:31.000000000 +1100
@@ -0,0 +1 @@
+#include "../../etherboot.h"
diff -ur --exclude='*.a' --exclude='*.o' --exclude='*.map' --unidirectional-new-file /usr/local/src/lua-4.0.1/include/lualib.h lua-4.0.1/include/lualib.h
--- /usr/local/src/lua-4.0.1/include/lualib.h	2000-10-28 03:15:53.000000000 +1100
+++ lua-4.0.1/include/lualib.h	2003-01-13 11:02:01.000000000 +1100
@@ -23,6 +23,7 @@
 LUALIB_API void lua_strlibopen (lua_State *L);
 LUALIB_API void lua_mathlibopen (lua_State *L);
 LUALIB_API void lua_dblibopen (lua_State *L);
+LUALIB_API void lua_userlibopen (lua_State *L);
 
 
 
diff -ur --exclude='*.a' --exclude='*.o' --exclude='*.map' --unidirectional-new-file /usr/local/src/lua-4.0.1/include/misc.h lua-4.0.1/include/misc.h
--- /usr/local/src/lua-4.0.1/include/misc.h	1970-01-01 10:00:00.000000000 +1000
+++ lua-4.0.1/include/misc.h	2003-01-13 01:07:18.000000000 +1100
@@ -0,0 +1 @@
+#include "../../misc.h"
diff -ur --exclude='*.a' --exclude='*.o' --exclude='*.map' --unidirectional-new-file /usr/local/src/lua-4.0.1/include/printf.h lua-4.0.1/include/printf.h
--- /usr/local/src/lua-4.0.1/include/printf.h	1970-01-01 10:00:00.000000000 +1000
+++ lua-4.0.1/include/printf.h	2003-01-07 22:27:31.000000000 +1100
@@ -0,0 +1 @@
+#include "../../printf.h"
diff -ur --exclude='*.a' --exclude='*.o' --exclude='*.map' --unidirectional-new-file /usr/local/src/lua-4.0.1/include/setjmp.h lua-4.0.1/include/setjmp.h
--- /usr/local/src/lua-4.0.1/include/setjmp.h	1970-01-01 10:00:00.000000000 +1000
+++ lua-4.0.1/include/setjmp.h	2003-01-07 22:27:31.000000000 +1100
@@ -0,0 +1 @@
+#include "../../setjmp.h"
diff -ur --exclude='*.a' --exclude='*.o' --exclude='*.map' --unidirectional-new-file /usr/local/src/lua-4.0.1/include/signal.h lua-4.0.1/include/signal.h
--- /usr/local/src/lua-4.0.1/include/signal.h	1970-01-01 10:00:00.000000000 +1000
+++ lua-4.0.1/include/signal.h	2003-01-13 11:02:54.000000000 +1100
@@ -0,0 +1,4 @@
+#ifndef	_SIGNAL_H
+#define	_SIGNAL_H
+#define	signal(a,b)
+#endif
diff -ur --exclude='*.a' --exclude='*.o' --exclude='*.map' --unidirectional-new-file /usr/local/src/lua-4.0.1/include/startmenu.h lua-4.0.1/include/startmenu.h
--- /usr/local/src/lua-4.0.1/include/startmenu.h	1970-01-01 10:00:00.000000000 +1000
+++ lua-4.0.1/include/startmenu.h	2003-01-12 20:18:10.000000000 +1100
@@ -0,0 +1 @@
+#include "../../startmenu.h"
diff -ur --exclude='*.a' --exclude='*.o' --exclude='*.map' --unidirectional-new-file /usr/local/src/lua-4.0.1/include/stddef.h lua-4.0.1/include/stddef.h
--- /usr/local/src/lua-4.0.1/include/stddef.h	1970-01-01 10:00:00.000000000 +1000
+++ lua-4.0.1/include/stddef.h	2003-01-07 22:27:31.000000000 +1100
@@ -0,0 +1 @@
+#include "../../stddef.h"
diff -ur --exclude='*.a' --exclude='*.o' --exclude='*.map' --unidirectional-new-file /usr/local/src/lua-4.0.1/include/stdio.h lua-4.0.1/include/stdio.h
--- /usr/local/src/lua-4.0.1/include/stdio.h	1970-01-01 10:00:00.000000000 +1000
+++ lua-4.0.1/include/stdio.h	2003-01-07 22:27:31.000000000 +1100
@@ -0,0 +1,16 @@
+#ifndef	_STDIO_H
+#define	_STDIO_H
+#include "stddef.h"
+#include "printf.h"
+#define	BUFSIZ	8192
+typedef void FILE;
+extern FILE *stdin, *stdout, *stderr;
+extern int sprintf(char *str, const char *fmt, ...);
+extern int vsprintf(char *buf, const char *fmt, const int *dp);
+extern inline int fprintf(FILE *f, const char *fmt, ...) {
+        return (vsprintf(0, fmt, ((const int *)&fmt)+1));
+}
+#define fputs(s,f)	printf("%s",s)
+#define	fread(a,b,c,d)	1
+#define	feof(f)		0
+#endif
diff -ur --exclude='*.a' --exclude='*.o' --exclude='*.map' --unidirectional-new-file /usr/local/src/lua-4.0.1/Makefile lua-4.0.1/Makefile
--- /usr/local/src/lua-4.0.1/Makefile	2000-11-01 04:32:01.000000000 +1100
+++ lua-4.0.1/Makefile	2003-01-07 22:27:31.000000000 +1100
@@ -10,8 +10,9 @@
 all clean co klean:
 	cd include; $(MAKE) $@
 	cd src; $(MAKE) $@
-	cd src/luac; $(MAKE) $@
+	# cd src/luac; $(MAKE) $@
 	cd src/lib; $(MAKE) $@
+	cd sa; $(MAKE) $@
 	cd src/lua; $(MAKE) $@
 
 # remove debug information from binaries
diff -ur --exclude='*.a' --exclude='*.o' --exclude='*.map' --unidirectional-new-file /usr/local/src/lua-4.0.1/sa/brk.c lua-4.0.1/sa/brk.c
--- /usr/local/src/lua-4.0.1/sa/brk.c	1970-01-01 10:00:00.000000000 +1000
+++ lua-4.0.1/sa/brk.c	2003-01-07 22:27:31.000000000 +1100
@@ -0,0 +1,31 @@
+#include	<errno.h>
+
+extern void _end;
+static void *curr_heap_top = &_end;
+
+int brk(void *end_data_segment) {
+	int	sp;
+
+	/* Give 256 bytes of room between heap and stack */
+	if (end_data_segment > (void *)&sp - 0x100) {
+		errno = ENOMEM;
+		return (-1);
+	}
+	curr_heap_top = end_data_segment;
+	return (0);
+}
+
+void *sbrk(unsigned long increment) {
+	int	sp;
+
+	if (increment <= 0)
+		return (curr_heap_top);
+	void *p = curr_heap_top;
+	/* Give 256 bytes of room between heap and stack */
+	if (p + increment > (void *)&sp - 0x100) {
+		errno = ENOMEM;
+		return (0);
+	}
+	curr_heap_top += increment;
+	return (p);
+}
diff -ur --exclude='*.a' --exclude='*.o' --exclude='*.map' --unidirectional-new-file /usr/local/src/lua-4.0.1/sa/luserlib.c lua-4.0.1/sa/luserlib.c
--- /usr/local/src/lua-4.0.1/sa/luserlib.c	1970-01-01 10:00:00.000000000 +1000
+++ lua-4.0.1/sa/luserlib.c	2003-01-13 10:43:39.000000000 +1100
@@ -0,0 +1,80 @@
+/*
+ *	Interface to available routines in BIOS library.
+ *	GPL, Ken Yap 2003
+ *	(I know the filename suggests ineptitude, but it's not a
+ *	very rich set of routines anyway. :-)
+ */
+
+#include "lauxlib.h"
+#include "lualib.h"
+
+#include "startmenu.h"
+#include "misc.h"
+
+#define	zero_result(x)		x; return 0
+#define	single_result(x)	lua_pushnumber(L, x); return 1
+
+static int l_checkkey(lua_State *L) { single_result(console_checkkey()); }
+
+static int l_cls(lua_State *L) { zero_result(console_cls()); }
+
+static int l_getkey(lua_State *L) { single_result(console_getkey()); }
+
+static int l_getshift(lua_State *L) { single_result(console_getshift()); }
+
+static int l_getxy(lua_State *L) { single_result(console_getxy()); }
+
+static int l_gotoxy(lua_State *L) {
+	int n = lua_gettop(L);
+	if (n < 2) {
+		single_result(0);
+	}
+	zero_result(console_gotoxy(luaL_check_number(L, 1), luaL_check_number(L, 2)));
+}
+
+static int l_ischar(lua_State *L) { single_result(console_ischar()); }
+
+static int l_nocursor(lua_State *L) { zero_result(console_nocursor()); }
+
+static int l_setattrib(lua_State *L) {
+	int n = lua_gettop(L);
+	if (n < 1) {
+		single_result(0);
+	}
+	zero_result(console_setattrib(luaL_check_number(L, 1)));
+}
+
+static int l_currticks(lua_State *L) { single_result(currticks()); }
+
+#if	ANSIMODE==-1
+static int l_ansiswitch(lua_State *L) {
+	int n = lua_gettop(L);
+	if (n < 1) {
+		single_result(0);
+	}
+	zero_result(ansiswitch(luaL_check_number(L, 1)));
+}
+#endif
+
+static const struct luaL_reg userlib[] = {
+	{"checkkey",l_checkkey},
+	{"cls",l_cls},
+	{"getkey",l_getkey},
+	{"getshift",l_getshift},
+	{"getxy",l_getxy},
+	{"gotoxy",l_gotoxy},
+	{"ischar",l_ischar},
+	{"nocursor",l_nocursor},
+	{"setattrib",l_setattrib},
+	{"currticks",l_currticks},
+#if	ANSIMODE==-1
+	{"ansiswitch",l_ansiswitch},
+#endif
+};
+
+/*
+** Open user library
+*/
+LUALIB_API void lua_userlibopen (lua_State *L) {
+  luaL_openl(L, userlib);
+}
diff -ur --exclude='*.a' --exclude='*.o' --exclude='*.map' --unidirectional-new-file /usr/local/src/lua-4.0.1/sa/Makefile lua-4.0.1/sa/Makefile
--- /usr/local/src/lua-4.0.1/sa/Makefile	1970-01-01 10:00:00.000000000 +1000
+++ lua-4.0.1/sa/Makefile	2003-01-13 01:08:33.000000000 +1100
@@ -0,0 +1,40 @@
+LUA=		..
+include		$(LUA)/config
+
+# Options for auxiliary menu program
+# Available: -DANSIESC -DANSIMODE -DCONSOLE_CRT/CONSOLE_SERIAL -DPOWERSAVE -DCOMCONSOLE -DCOMPRESERVE
+# ANSIMODE requires ANSIESC, see misc.c for choices
+# Might as well take the lot since code size is not a concern
+EXTRA_FLAGS=	-DCONSOLE_CRT -DANSIESC -DANSIMODE=-1 -DPOWERSAVE -DCOMCONSOLE=0x3f8 -DCOMPRESERVE
+
+# We steal the malloc .o's from uclibc. They have to be in libsalib.a
+# otherwise they bind to the s/brk in uclibc instead of our substitute
+UCLIBC=		/usr/i386-linux-uclibc/lib/libc.a
+MOBJS=		malloc.o realloc.o heap_alloc.o heap_alloc_at.o free.o heap_free.o
+
+all:	../lib/libsalib.a startmenu.o
+
+../lib/libsalib.a:	printf.o misc.o ansiesc.o brk.o luserlib.o $(UCLIBC)
+	ar xv $(UCLIBC) $(MOBJS)
+	$(AR) $@ printf.o misc.o ansiesc.o brk.o luserlib.o $(MOBJS)
+
+startmenu.o:	../../startmenu.S
+	gcc -E -Ui386 -DRELOC=$(LUA_RELOC) ../../startmenu.S | $(AS) -o startmenu.o
+
+printf.o:		../../printf.c
+	$(CC) $(CFLAGS) -c ../../$*.c
+
+misc.o:	../../misc.h ../../misc.c ../../ansiesc.h ../../etherboot.h
+	$(CC) $(CFLAGS) $(EXTRA_FLAGS) -c ../../$*.c
+
+ansiesc.o:	../../ansiesc.h ../../ansiesc.c ../../stddef.h ../../string.h ../../etherboot.h
+	$(CC) $(CFLAGS) $(EXTRA_FLAGS) -c ../../$*.c
+
+brk.o:	brk.c
+	$(CC) $(CFLAGS) -c $*.c
+
+luserlib.o:	luserlib.c
+	$(CC) $(CFLAGS) $(EXTRA_FLAGS) -c $*.c
+
+clean:
+	rm *.o
diff -ur --exclude='*.a' --exclude='*.o' --exclude='*.map' --unidirectional-new-file /usr/local/src/lua-4.0.1/src/ldo.c lua-4.0.1/src/ldo.c
--- /usr/local/src/lua-4.0.1/src/ldo.c	2002-06-21 00:24:40.000000000 +1000
+++ lua-4.0.1/src/ldo.c	2003-01-07 22:27:31.000000000 +1100
@@ -260,6 +260,7 @@
 
 
 static int parse_file (lua_State *L, const char *filename) {
+#if	0
   ZIO z;
   int status;
   int bin;  /* flag for file mode */
@@ -284,6 +285,9 @@
   if (f != stdin)
     fclose(f);
   return status;
+#else
+  return 0;
+#endif
 }
 
 
diff -ur --exclude='*.a' --exclude='*.o' --exclude='*.map' --unidirectional-new-file /usr/local/src/lua-4.0.1/src/lib/lbaselib.c lua-4.0.1/src/lib/lbaselib.c
--- /usr/local/src/lua-4.0.1/src/lib/lbaselib.c	2002-06-12 03:01:50.000000000 +1000
+++ lua-4.0.1/src/lib/lbaselib.c	2003-01-07 22:27:31.000000000 +1100
@@ -75,11 +75,15 @@
     s = lua_tostring(L, -1);  /* get result */
     if (s == NULL)
       lua_error(L, "`tostring' must return a string to `print'");
+#if	0
     if (i>1) fputs("\t", stdout);
+#endif
     fputs(s, stdout);
     lua_pop(L, 1);  /* pop result */
   }
+#if	0
   fputs("\n", stdout);
+#endif
   return 0;
 }
 
diff -ur --exclude='*.a' --exclude='*.o' --exclude='*.map' --unidirectional-new-file /usr/local/src/lua-4.0.1/src/lib/Makefile lua-4.0.1/src/lib/Makefile
--- /usr/local/src/lua-4.0.1/src/lib/Makefile	2000-09-20 13:13:52.000000000 +1100
+++ lua-4.0.1/src/lib/Makefile	2003-01-07 22:27:31.000000000 +1100
@@ -7,8 +7,8 @@
 # actually only used in liolib.c
 EXTRA_DEFS= $(POPEN)
 
-OBJS= lauxlib.o lbaselib.o ldblib.o liolib.o lmathlib.o lstrlib.o
-SRCS= lauxlib.c lbaselib.c ldblib.c liolib.c lmathlib.c lstrlib.c
+OBJS= lauxlib.o lbaselib.o ldblib.o lstrlib.o
+SRCS= lauxlib.c lbaselib.c ldblib.c lstrlib.c
 
 T= $(LIB)/liblualib.a
 
diff -ur --exclude='*.a' --exclude='*.o' --exclude='*.map' --unidirectional-new-file /usr/local/src/lua-4.0.1/src/llimits.h lua-4.0.1/src/llimits.h
--- /usr/local/src/lua-4.0.1/src/llimits.h	2000-10-26 23:47:05.000000000 +1100
+++ lua-4.0.1/src/llimits.h	2003-01-07 22:28:25.000000000 +1100
@@ -42,7 +42,7 @@
 typedef LUA_NUM_TYPE Number;
 
 /* function to convert a Number to a string */
-#define NUMBER_FMT	"%.16g"		/* LUA_NUMBER */
+#define NUMBER_FMT	"%d"		/* LUA_NUMBER */
 #define lua_number2str(s,n)	sprintf((s), NUMBER_FMT, (n))
 
 /* function to convert a string to a Number */
diff -ur --exclude='*.a' --exclude='*.o' --exclude='*.map' --unidirectional-new-file /usr/local/src/lua-4.0.1/src/lparser.c lua-4.0.1/src/lparser.c
--- /usr/local/src/lua-4.0.1/src/lparser.c	2000-11-29 22:57:42.000000000 +1100
+++ lua-4.0.1/src/lparser.c	2003-01-07 22:27:31.000000000 +1100
@@ -1019,7 +1019,7 @@
 }
 
 
-static int stat (LexState *ls) {
+static int statm (LexState *ls) {
   int line = ls->linenumber;  /* may be needed for error messages */
   switch (ls->t.token) {
     case TK_IF: {  /* stat -> ifstat */
@@ -1115,7 +1115,7 @@
   /* chunk -> { stat [';'] } */
   int islast = 0;
   while (!islast && !block_follow(ls->t.token)) {
-    islast = stat(ls);
+    islast = statm(ls);
     optional(ls, ';');
     LUA_ASSERT(ls->fs->stacklevel == ls->fs->nactloc,
                "stack size != # local vars");
diff -ur --exclude='*.a' --exclude='*.o' --exclude='*.map' --unidirectional-new-file /usr/local/src/lua-4.0.1/src/lua/lua.c lua-4.0.1/src/lua/lua.c
--- /usr/local/src/lua-4.0.1/src/lua/lua.c	2000-10-21 03:36:32.000000000 +1100
+++ lua-4.0.1/src/lua/lua.c	2003-01-10 13:03:11.000000000 +1100
@@ -15,6 +15,12 @@
 #include "luadebug.h"
 #include "lualib.h"
 
+#include "etherboot.h"
+#include "elf_boot.h"
+#include "byteswap.h"
+
+#define	LUA_VERSION_CHECK	0x04000100	/* 4.0.1.0 */
+
 
 static lua_State *L = NULL;
 
@@ -50,11 +56,16 @@
 
 static void userinit (void) {
   lua_baselibopen(L);
+#if	0
   lua_iolibopen(L);
+#endif
   lua_strlibopen(L);
+#if	0
   lua_mathlibopen(L);
+#endif
   lua_dblibopen(L);
   /* add your libraries here */
+  lua_userlibopen(L);
 }
 
 
@@ -150,6 +161,7 @@
 }
 
 
+#if	0
 static int file_input (const char *argv) {
   int result = ldo(lua_dofile, argv);
   if (result) {
@@ -283,6 +295,7 @@
   }
   return EXIT_SUCCESS;
 }
+#endif
 
 
 static void getstacksize (int argc, char *argv[], struct Options *opt) {
@@ -306,6 +319,7 @@
 }
 
 
+#if	0
 int main (int argc, char *argv[]) {
   struct Options opt;
   int status;
@@ -319,4 +333,86 @@
     lua_close(L);
   return status;
 }
+#endif
+
+static void parse_elf_boot_notes(
+	void *notes, union infoblock **rheader, struct bootp_t **rbootp)
+{
+	unsigned char *note, *end;
+	Elf_Bhdr *bhdr;
+	Elf_Nhdr *hdr;
+
+	bhdr = notes;
+	if (bhdr->b_signature != ELF_BHDR_MAGIC) {
+		return;
+	}
+
+	note = ((char *)bhdr) + sizeof(*bhdr);
+	end  = ((char *)bhdr) + bhdr->b_size;
+	while (note < end) {
+		unsigned char *n_name, *n_desc, *next;
+		hdr = (Elf_Nhdr *)note;
+		n_name = note + sizeof(*hdr);
+		n_desc = n_name + ((hdr->n_namesz + 3) & ~3);
+		next = n_desc + ((hdr->n_descsz + 3) & ~3);
+		if (next > end) 
+			break;
+#if 0
+		printf("n_type: %x n_name(%d): n_desc(%d): \n", 
+			hdr->n_type, hdr->n_namesz, hdr->n_descsz);
+#endif
 
+		if ((hdr->n_namesz == 10) &&
+			(memcmp(n_name, "Etherboot", 10) == 0)) {
+			switch(hdr->n_type) {
+			case EB_BOOTP_DATA:
+				*rbootp = *((void **)n_desc);
+				break;
+			case EB_HEADER:
+				*rheader = *((void **)n_desc);
+				break;
+			default:
+				break;
+			}
+		}
+		note = next;
+	}
+}
+
+static uint32_t getlong(const char *p) {
+  union {
+    uint8_t c[4];
+    uint32_t l;
+  } u;
+  memcpy(u.c, p, sizeof(uint32_t));
+  return (ntohl(u.l));
+}
+
+int menu(struct ebinfo *eb, union infoblock *header, struct bootp_t *bootp)
+{
+  uint32_t l;
+  parse_elf_boot_notes(eb, &header, &bootp);
+  L = lua_open(0);  /* create state */
+  userinit();  /* open libraries */
+  print_version();
+  const char *name = (const char *)DATA_START;
+  if ((l = getlong(name)) != LUA_VERSION_CHECK) {
+    fprintf(stderr, "Lua version mismatch (%#X != %#X)\n", l, LUA_VERSION_CHECK);
+    return 0;
+  }
+  name += sizeof(uint32_t);
+  int len = (strlen(name) + sizeof(uint32_t)) & ~(sizeof(uint32_t)-1);
+  int top = lua_gettop(L);
+  int res = lua_dobuffer(L, name + len + sizeof(uint32_t), getlong(name + len), name);
+  lua_settop(L, top);  /* remove eventual results */
+  lua_close(L);
+  /* Lua gives no message in such cases, so lua.c provides one */
+  if (res == LUA_ERRMEM) {
+    fprintf(stderr, "lua: memory allocation error\n");
+  }
+  else if (res == LUA_ERRERR)
+    fprintf(stderr, "lua: error in error message\n");
+  else if (res != 0)
+    fprintf(stderr, "lua: error %d\n", res);
+  return 0;
+}
diff -ur --exclude='*.a' --exclude='*.o' --exclude='*.map' --unidirectional-new-file /usr/local/src/lua-4.0.1/src/lua/Makefile lua-4.0.1/src/lua/Makefile
--- /usr/local/src/lua-4.0.1/src/lua/Makefile	2000-03-31 23:52:56.000000000 +1000
+++ lua-4.0.1/src/lua/Makefile	2003-01-07 22:27:31.000000000 +1100
@@ -4,7 +4,7 @@
 
 include $(LUA)/config
 
-EXTRA_DEFS= $(POSIX)
+EXTRA_DEFS+= $(POSIX)
 
 OBJS= lua.o
 SRCS= lua.c
@@ -13,8 +13,8 @@
 
 all: $T
 
-$T: $(OBJS) $(LIB)/liblua.a $(LIB)/liblualib.a
-	$(CC) -o $@ $(OBJS) -L$(LIB) -llua -llualib $(EXTRA_LIBS)
+$T: $(OBJS) $(LUA)/sa/startmenu.o $(LIB)/liblua.a $(LIB)/liblualib.a $(LIB)/libsalib.a
+	$(LD) -M --oformat binary -N -Ttext $(LUA_RELOC) -e _start -o $@ $(LUA)/sa/startmenu.o $(OBJS) -L$(LIB) -llua -llualib -lsalib $(EXTRA_LIBS) > lua.map
 
 $(LIB)/liblua.a:
 	cd ..; $(MAKE)
@@ -22,6 +22,12 @@
 $(LIB)/liblualib.a:
 	cd ../lib; $(MAKE)
 
+$(LUA)/sa/startmenu.o:
+	cd ../../sa; $(MAKE) startmenu.o
+
+$(LIB)/libsalib.a:
+	cd ../../sa; $(MAKE) ../lib/libsalib.a
+
 clean:
 	rm -f $(OBJS) $T
 
