[syslinux:master] com32: add proper sleep()/msleep() functions and make Lua use them

syslinux-bot for H. Peter Anvin hpa at zytor.com
Mon Jul 5 15:48:18 PDT 2010


Commit-ID:  0a984adcbd5130e790a774e0d78d66465ecc6c0a
Gitweb:     http://syslinux.zytor.com/commit/0a984adcbd5130e790a774e0d78d66465ecc6c0a
Author:     H. Peter Anvin <hpa at zytor.com>
AuthorDate: Mon, 5 Jul 2010 15:45:37 -0700
Committer:  H. Peter Anvin <hpa at zytor.com>
CommitDate: Mon, 5 Jul 2010 15:45:37 -0700

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 at zytor.com>


---
 com32/cmenu/libmenu/com32io.c |   11 -----------
 com32/cmenu/libmenu/com32io.h |    2 --
 com32/include/unistd.h        |    3 +++
 com32/lib/Makefile            |    2 +-
 com32/lib/sys/sleep.c         |   22 ++++++++++++++++++++++
 com32/lua/src/Makefile        |    2 --
 com32/lua/src/syslinux.c      |    7 ++++---
 7 files changed, 30 insertions(+), 19 deletions(-)

diff --git a/com32/cmenu/libmenu/com32io.c b/com32/cmenu/libmenu/com32io.c
index 6a27d1a..8e5016b 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 6ff6857..d9cce3d 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 c0b52d6..fc514f1 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 e8e89c0..2035df2 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 0000000..8a51c1c
--- /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 eac3b28..d31c9bd 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 be061c4..a272fc6 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;
 }
 



More information about the Syslinux-commits mailing list