struct dev_info;
__extern int openconsole(const struct dev_info *);
+/* Standard line-oriented console */
extern const struct dev_info dev_stdcon;
+/* Raw character-oriented console */
+extern const struct dev_info dev_rawcon;
#endif /* _CONSOLE_H */
sys/entry.o sys/exit.o \
sys/fileinfo.o sys/opendev.o sys/read.o sys/write.o sys/close.o \
sys/open.o sys/fileread.o sys/fileclose.o \
- sys/isatty.o sys/openconsole.o \
- sys/stdcon.o sys/stdcon_write.o sys/stdcon_read.o
+ sys/isatty.o sys/openconsole.o sys/line_input.o \
+ sys/stdcon.o sys/stdcon_write.o sys/stdcon_read.o \
+ sys/rawcon.o sys/rawcon_write.o sys/rawcon_read.o
+
all: libcom32.a
if ( rv )
return rv;
}
-
- fp->ops = NULL; /* File structure unused */
+
+ memset(fp, 0, sizeof *fp); /* File structure unused */
return 0;
}
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 */
--- /dev/null
+#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;
+ }
+ }
+}
+
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;
}
}
fp->ops = dev;
+ fp->p.f.offset = 0;
+ fp->p.f.nbytes = 0;
+ fp->p.f.datap = fp->p.f.buf;
return fd;
}
--- /dev/null
+#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,
+};
--- /dev/null
+#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;
+}
--- /dev/null
+#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;
+}
/*
* stdcon_read.c
*
- * Reading from the console, with echo
+ * Line-oriented reading from the standard console
*/
#include <errno.h>
#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;
* ----------------------------------------------------------------------- */
/*
- * write.c
+ * stdcon_write.c
*
* Writing to the console
*/