summaryrefslogtreecommitdiff
path: root/com32/lib/sys
diff options
context:
space:
mode:
authorhpa <hpa>2004-11-17 06:24:12 +0000
committerhpa <hpa>2004-11-17 06:24:12 +0000
commit8dcc0d0d5536fc35b3fd746a51f9b373e334aa09 (patch)
treec2e83cf8a22d1e6fe1c998260ebd0663431ef181 /com32/lib/sys
parent8aada67545460566c9be6a3e021260509e8edaee (diff)
downloadsyslinux-8dcc0d0d5536fc35b3fd746a51f9b373e334aa09.tar.gz
Separate rawcon and stdcon; actually make input work
Diffstat (limited to 'com32/lib/sys')
-rw-r--r--com32/lib/sys/close.c4
-rw-r--r--com32/lib/sys/file.h4
-rw-r--r--com32/lib/sys/line_input.c78
-rw-r--r--com32/lib/sys/open.c1
-rw-r--r--com32/lib/sys/opendev.c3
-rw-r--r--com32/lib/sys/rawcon.c53
-rw-r--r--com32/lib/sys/rawcon_read.c68
-rw-r--r--com32/lib/sys/rawcon_write.c59
-rw-r--r--com32/lib/sys/stdcon_read.c35
-rw-r--r--com32/lib/sys/stdcon_write.c2
10 files changed, 286 insertions, 21 deletions
diff --git a/com32/lib/sys/close.c b/com32/lib/sys/close.c
index 7af7ff13..9837d4b0 100644
--- a/com32/lib/sys/close.c
+++ b/com32/lib/sys/close.c
@@ -50,7 +50,7 @@ int close(int fd)
if ( rv )
return rv;
}
-
- fp->ops = NULL; /* File structure unused */
+
+ memset(fp, 0, sizeof *fp); /* File structure unused */
return 0;
}
diff --git a/com32/lib/sys/file.h b/com32/lib/sys/file.h
index 194c35df..aae8e60f 100644
--- a/com32/lib/sys/file.h
+++ b/com32/lib/sys/file.h
@@ -80,4 +80,8 @@ struct file_info {
extern struct file_info __file_info[NFILES];
+/* Line input discipline */
+ssize_t __line_input(struct file_info *fp, char *buf, size_t bufsize,
+ ssize_t (*get_char)(struct file_info *, void *, size_t));
+
#endif /* _COM32_SYS_FILE_H */
diff --git a/com32/lib/sys/line_input.c b/com32/lib/sys/line_input.c
new file mode 100644
index 00000000..c4dd8a5b
--- /dev/null
+++ b/com32/lib/sys/line_input.c
@@ -0,0 +1,78 @@
+#ident "$Id$"
+/* ----------------------------------------------------------------------- *
+ *
+ * Copyright 2004 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.
+ *
+ * ----------------------------------------------------------------------- */
+
+/*
+ * line_input.c
+ *
+ * Line-oriented input discupline
+ */
+
+#include "file.h"
+
+ssize_t __line_input(struct file_info *fp, char *buf, size_t bufsize,
+ ssize_t (*get_char)(struct file_info *, void *, size_t))
+{
+ size_t n = 0;
+ char ch;
+
+ for(;;) {
+ if ( get_char(fp, &ch, 1) != 1 )
+ return n;
+
+ switch ( ch ) {
+ case '\r':
+ *buf = '\n';
+ fp->ops->write(fp, "\n", 1);
+ return n+1;
+
+ case '\b':
+ if ( n > 0 ) {
+ n--; buf--;
+ fp->ops->write(fp, "\b \b", 3);
+ }
+ break;
+
+ case '\x15': /* Ctrl-U */
+ while ( n ) {
+ n--; buf--;
+ fp->ops->write(fp, "\b \b", 3);
+ }
+ break;
+
+ default:
+ if ( n < bufsize-1 ) {
+ *buf = ch;
+ fp->ops->write(fp, buf, 1);
+ n++;
+ buf++;
+ }
+ break;
+ }
+ }
+}
+
diff --git a/com32/lib/sys/open.c b/com32/lib/sys/open.c
index 27c22cec..139d1045 100644
--- a/com32/lib/sys/open.c
+++ b/com32/lib/sys/open.c
@@ -86,7 +86,6 @@ int open(const char *pathname, int flags, ...)
fp->p.f.filedes = regs.esi.w[0];
fp->p.f.offset = 0;
fp->p.f.nbytes = 0;
- fp->p.f.datap = fp->p.f.buf;
return fd;
}
diff --git a/com32/lib/sys/opendev.c b/com32/lib/sys/opendev.c
index 0d49a954..4ef2fe93 100644
--- a/com32/lib/sys/opendev.c
+++ b/com32/lib/sys/opendev.c
@@ -57,6 +57,9 @@ int opendev(const struct dev_info *dev, int flags)
}
fp->ops = dev;
+ fp->p.f.offset = 0;
+ fp->p.f.nbytes = 0;
+ fp->p.f.datap = fp->p.f.buf;
return fd;
}
diff --git a/com32/lib/sys/rawcon.c b/com32/lib/sys/rawcon.c
new file mode 100644
index 00000000..4f168c02
--- /dev/null
+++ b/com32/lib/sys/rawcon.c
@@ -0,0 +1,53 @@
+#ident "$Id$"
+/* ----------------------------------------------------------------------- *
+ *
+ * Copyright 2004 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.
+ *
+ * ----------------------------------------------------------------------- */
+
+/*
+ * rawcon.c
+ *
+ * Raw console
+ */
+
+#include <errno.h>
+#include <string.h>
+#include <com32.h>
+#include <minmax.h>
+#include <fcntl.h>
+#include <console.h>
+#include "file.h"
+
+extern ssize_t __rawcon_read(struct file_info *, void *, size_t);
+extern ssize_t __rawcon_write(struct file_info *, const void *, size_t);
+
+const struct dev_info dev_rawcon = {
+ .dev_magic = __DEV_MAGIC,
+ .flags = __DEV_TTY,
+ .fileflags = O_RDWR|O_CREAT|O_TRUNC|O_APPEND,
+ .read = __rawcon_read,
+ .write = __rawcon_write,
+ .close = NULL,
+};
diff --git a/com32/lib/sys/rawcon_read.c b/com32/lib/sys/rawcon_read.c
new file mode 100644
index 00000000..dfea96b8
--- /dev/null
+++ b/com32/lib/sys/rawcon_read.c
@@ -0,0 +1,68 @@
+#ident "$Id$"
+/* ----------------------------------------------------------------------- *
+ *
+ * Copyright 2004 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.
+ *
+ * ----------------------------------------------------------------------- */
+
+/*
+ * rawcon_read.c
+ *
+ * Character-oriented reading from the console without echo
+ */
+
+#include <errno.h>
+#include <string.h>
+#include <com32.h>
+#include <minmax.h>
+#include "file.h"
+
+ssize_t __rawcon_read(struct file_info *fp, void *buf, size_t count)
+{
+ com32sys_t ireg, oreg;
+ char *bufp = buf;
+ size_t n = 0;
+
+ (void)fp;
+
+ memset(&ireg, 0, sizeof ireg);
+
+ while ( count ) {
+ ireg.eax.b[1] = 0x08;
+ __intcall(0x21, &ireg, &oreg);
+ *bufp++ = oreg.eax.b[0];
+ n++;
+
+ if ( ! --count )
+ break;
+
+ /* Only return more than one if there is stuff in the buffer */
+ ireg.eax.b[1] = 0x0B;
+ __intcall(0x21, &ireg, &oreg);
+ if ( !oreg.eax.b[0] )
+ break;
+ }
+
+ return n;
+}
diff --git a/com32/lib/sys/rawcon_write.c b/com32/lib/sys/rawcon_write.c
new file mode 100644
index 00000000..8a037d26
--- /dev/null
+++ b/com32/lib/sys/rawcon_write.c
@@ -0,0 +1,59 @@
+#ident "$Id$"
+/* ----------------------------------------------------------------------- *
+ *
+ * Copyright 2004 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.
+ *
+ * ----------------------------------------------------------------------- */
+
+/*
+ * rawcon_write.c
+ *
+ * Raw writing to the console; no \n -> \r\n translation
+ */
+
+#include <errno.h>
+#include <string.h>
+#include <com32.h>
+#include <minmax.h>
+#include "file.h"
+
+ssize_t __rawcon_write(struct file_info *fp, const void *buf, size_t count)
+{
+ com32sys_t ireg;
+ const char *bufp = buf;
+ size_t n = 0;
+
+ (void)fp;
+
+ memset(&ireg, 0, sizeof ireg);
+ ireg.eax.b[1] = 0x02;
+
+ while ( count-- ) {
+ ireg.edx.b[0] = *bufp++;
+ __intcall(0x21, &ireg, NULL);
+ n++;
+ }
+
+ return n;
+}
diff --git a/com32/lib/sys/stdcon_read.c b/com32/lib/sys/stdcon_read.c
index 0e5df19a..840e095e 100644
--- a/com32/lib/sys/stdcon_read.c
+++ b/com32/lib/sys/stdcon_read.c
@@ -29,7 +29,7 @@
/*
* stdcon_read.c
*
- * Reading from the console, with echo
+ * Line-oriented reading from the standard console
*/
#include <errno.h>
@@ -38,30 +38,31 @@
#include <minmax.h>
#include "file.h"
+extern ssize_t __rawcon_read(struct file_info *fp, void *buf, size_t count);
+
ssize_t __stdcon_read(struct file_info *fp, void *buf, size_t count)
{
- com32sys_t ireg, oreg;
char *bufp = buf;
size_t n = 0;
+ char ch;
(void)fp;
- memset(&ireg, 0, sizeof ireg);
-
- while ( count ) {
- ireg.eax.b[1] = 0x01;
- __intcall(0x21, &ireg, &oreg);
- *bufp++ = oreg.eax.b[0];
- n++;
-
- if ( ! --count )
- break;
+ while ( n < count ) {
+ if ( fp->p.f.nbytes ) {
+ ch = *bufp++ = *fp->p.f.datap++;
+ fp->p.f.nbytes--;
+ n++;
+ if ( ch == '\n' )
+ return n;
+ } else {
+ fp->p.f.nbytes = __line_input(fp, fp->p.f.buf, MAXBLOCK,
+ __rawcon_read);
+ fp->p.f.datap = fp->p.f.buf;
- /* Only return more than one if there is stuff in the buffer */
- ireg.eax.b[1] = 0x0B;
- __intcall(0x21, &ireg, &oreg);
- if ( !oreg.eax.b[0] )
- break;
+ if ( fp->p.f.nbytes == 0 )
+ return n;
+ }
}
return n;
diff --git a/com32/lib/sys/stdcon_write.c b/com32/lib/sys/stdcon_write.c
index 62bc4cce..9cfd07f5 100644
--- a/com32/lib/sys/stdcon_write.c
+++ b/com32/lib/sys/stdcon_write.c
@@ -27,7 +27,7 @@
* ----------------------------------------------------------------------- */
/*
- * write.c
+ * stdcon_write.c
*
* Writing to the console
*/