From: hpa Date: Wed, 17 Nov 2004 06:24:12 +0000 (+0000) Subject: Separate rawcon and stdcon; actually make input work X-Git-Tag: syslinux-3.11~394 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8dcc0d0d5536fc35b3fd746a51f9b373e334aa09;p=platform%2Fupstream%2Fsyslinux.git Separate rawcon and stdcon; actually make input work --- diff --git a/com32/include/console.h b/com32/include/console.h index 78025fb..5db9165 100644 --- a/com32/include/console.h +++ b/com32/include/console.h @@ -40,7 +40,10 @@ 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 */ diff --git a/com32/lib/Makefile b/com32/lib/Makefile index 857f8fb..f89dd13 100644 --- a/com32/lib/Makefile +++ b/com32/lib/Makefile @@ -79,8 +79,10 @@ LIBOBJS = \ 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 diff --git a/com32/lib/sys/close.c b/com32/lib/sys/close.c index 7af7ff1..9837d4b 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 194c35d..aae8e60 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 0000000..c4dd8a5 --- /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 27c22ce..139d104 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 0d49a95..4ef2fe9 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 0000000..4f168c0 --- /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 +#include +#include +#include +#include +#include +#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 0000000..dfea96b --- /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 +#include +#include +#include +#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 0000000..8a037d2 --- /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 +#include +#include +#include +#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 0e5df19..840e095 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 @@ -38,30 +38,31 @@ #include #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 62bc4cc..9cfd07f 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 */