summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2010-07-05 15:45:37 -0700
committerH. Peter Anvin <hpa@zytor.com>2010-07-05 15:45:37 -0700
commit0a984adcbd5130e790a774e0d78d66465ecc6c0a (patch)
tree469e7e367aa7b683a4b3419444aa8153e4f98ac3
parenta393bcdefd525c43fce16a9f50a03402533b55f4 (diff)
downloadsyslinux-0a984adcbd5130e790a774e0d78d66465ecc6c0a.tar.gz
syslinux-0a984adcbd5130e790a774e0d78d66465ecc6c0a.tar.xz
syslinux-0a984adcbd5130e790a774e0d78d66465ecc6c0a.zip
com32: add proper sleep()/msleep() functions and make Lua use them
Add proper sleep() and msleep() functions, which among other things call syslinux_idle(), and make Lua use them. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
-rw-r--r--com32/cmenu/libmenu/com32io.c11
-rw-r--r--com32/cmenu/libmenu/com32io.h2
-rw-r--r--com32/include/unistd.h3
-rw-r--r--com32/lib/Makefile2
-rw-r--r--com32/lib/sys/sleep.c22
-rw-r--r--com32/lua/src/Makefile2
-rw-r--r--com32/lua/src/syslinux.c7
7 files changed, 30 insertions, 19 deletions
diff --git a/com32/cmenu/libmenu/com32io.c b/com32/cmenu/libmenu/com32io.c
index 6a27d1a1..8e5016be 100644
--- a/com32/cmenu/libmenu/com32io.c
+++ b/com32/cmenu/libmenu/com32io.c
@@ -27,17 +27,6 @@ void getpos(char *row, char *col, char page)
*col = REG_DL(outreg);
}
-unsigned char sleep(unsigned int msec)
-{
- unsigned long micro = 1000 * msec;
-
- REG_AH(inreg) = 0x86;
- REG_CX(inreg) = (micro >> 16);
- REG_DX(inreg) = (micro & 0xFFFF);
- __intcall(0x15, &inreg, &outreg);
- return REG_AH(outreg);
-}
-
char inputc(char *scancode)
{
syslinux_idle(); /* So syslinux can perform periodic activity */
diff --git a/com32/cmenu/libmenu/com32io.h b/com32/cmenu/libmenu/com32io.h
index 6ff6857e..d9cce3d6 100644
--- a/com32/cmenu/libmenu/com32io.h
+++ b/com32/cmenu/libmenu/com32io.h
@@ -63,6 +63,4 @@ static inline char getvideomode(void) // Get the current video mode
return readbiosb(0x449);
}
-unsigned char sleep(unsigned int msec); // Sleep for specified time
-
#endif
diff --git a/com32/include/unistd.h b/com32/include/unistd.h
index c0b52d60..fc514f10 100644
--- a/com32/include/unistd.h
+++ b/com32/include/unistd.h
@@ -25,6 +25,9 @@ __extern int getscreensize(int, int *, int *);
__extern char *getcwd(char *, int);
__extern int chdir(const char *);
+__extern unsigned int sleep(unsigned int);
+__extern unsigned int msleep(unsigned int);
+
/* Standard file descriptor numbers. */
#define STDIN_FILENO 0
#define STDOUT_FILENO 1
diff --git a/com32/lib/Makefile b/com32/lib/Makefile
index e8e89c08..2035df22 100644
--- a/com32/lib/Makefile
+++ b/com32/lib/Makefile
@@ -40,7 +40,7 @@ LIBOBJS = \
libgcc/__divdi3.o libgcc/__moddi3.o \
\
sys/intcall.o sys/farcall.o sys/cfarcall.o sys/zeroregs.o \
- sys/entry.o sys/exit.o sys/argv.o sys/times.o \
+ sys/entry.o sys/exit.o sys/argv.o sys/times.o sys/sleep.o \
sys/fileinfo.o sys/opendev.o sys/read.o sys/write.o sys/ftell.o \
sys/close.o sys/open.o sys/fileread.o sys/fileclose.o \
sys/openmem.o \
diff --git a/com32/lib/sys/sleep.c b/com32/lib/sys/sleep.c
new file mode 100644
index 00000000..8a51c1c0
--- /dev/null
+++ b/com32/lib/sys/sleep.c
@@ -0,0 +1,22 @@
+/*
+ * sys/sleep.c
+ */
+
+#include <unistd.h>
+#include <sys/times.h>
+#include <syslinux/idle.h>
+
+unsigned int msleep(unsigned int msec)
+{
+ clock_t start = times(NULL);
+
+ while (times(NULL) - start < msec)
+ syslinux_idle();
+
+ return 0;
+}
+
+unsigned int sleep(unsigned int seconds)
+{
+ return msleep(seconds * 1000);
+}
diff --git a/com32/lua/src/Makefile b/com32/lua/src/Makefile
index eac3b281..d31c9bdc 100644
--- a/com32/lua/src/Makefile
+++ b/com32/lua/src/Makefile
@@ -43,8 +43,6 @@ LIBLUA_OBJS += dmi.o
LIBLUA_OBJS += pci.o
LIBLUA_OBJS += vesa.o
-# For function sleep() -- XXX: FIX THIS
-LIBLUA_OBJS += ../../cmenu/libmenu/com32io.o
CFLAGS += -DLUA_ANSI
diff --git a/com32/lua/src/syslinux.c b/com32/lua/src/syslinux.c
index be061c4c..a272fc61 100644
--- a/com32/lua/src/syslinux.c
+++ b/com32/lua/src/syslinux.c
@@ -27,6 +27,7 @@
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
#include <syslinux/boot.h>
#define lnetlib_c /* Define the library */
@@ -209,7 +210,7 @@ static int sl_boot_linux(lua_State * L)
/* DEBUG
printf("Command line: %s\n", newcmdline);
- sleep(1000);
+ msleep(1000);
*/
/* Look for specific command-line arguments we care about */
@@ -269,7 +270,7 @@ static int sl_boot_linux(lua_State * L)
printf("Loading extra file failed\n");
/* DEBUG
- sleep(10000);
+ msleep(10000);
*/
ret = syslinux_boot_linux(kernel_data, kernel_len, initramfs, newcmdline);
@@ -283,7 +284,7 @@ static int sl_boot_linux(lua_State * L)
static int sl_sleep(lua_State * L)
{
unsigned int msec = luaL_checkint(L, 1);
- sleep(msec);
+ msleep(msec);
return 0;
}