3 * Copyright (c) 1994 Joerg Wunsch
7 * This program is free software.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by Joerg Wunsch
20 * 4. The name of the developer may not be used to endorse or promote
21 * products derived from this software without specific prior written
24 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 #ident "$FreeBSD: src/usr.sbin/pcvt/vgaio/vgaio.y,v 1.5 1999/09/06 07:39:30 peter Exp $"
37 #ident "$DragonFly: src/usr.sbin/pcvt/vgaio/Attic/vgaio.y,v 1.3 2004/12/18 22:48:04 swildner Exp $"
41 * Revision 1.1 1994/03/29 02:47:27 mycroft
42 * pcvt 3.0, with some performance enhancements by Joerg Wunsch and me.
44 * Revision 1.2 1994/01/08 17:42:58 j
46 * made multiple commands per line work
49 * Revision 1.3 21.12.1994 -hm
50 * Added mi command for accessing the misc out register
51 * hex values shown as 2 fixed chars, added binary output
56 #include <sys/fcntl.h>
57 #include <machine/cpufunc.h>
58 #include <machine/pcvt_ioctl.h>
61 #include <machine/pio.h>
66 void setreg(struct reg r, int val);
67 void getreg(struct reg r);
68 void yyerror(const char *msg);
72 unsigned short vgabase;
81 %token MI GR CR SR AR NEWLINE
95 line: statements NEWLINE
97 | error NEWLINE { fprintf(stderr, "bing!\n"); }
100 statements: statement
101 | statements ';' statement
104 statement: register '?' { getreg($1); }
105 | register '=' NUM { setreg($1, $3); }
109 register: reggroup NUM { $$.num = $2; $$.group = $1; }
112 reggroup: GR { $$ = GR; }
125 {GR, "gr"}, {CR, "cr"}, {SR, "sr"}, {AR, "ar"}, {MI, "mi"},
129 const char *getname(struct reg r) {
131 for(idx = 0; regnames[idx].id; idx++)
132 if(regnames[idx].id == r.group)
133 return regnames[idx].name;
137 /*---------------------------------------------------------------------------*
138 * return ptr to string of 1's and 0's for value
139 *---------------------------------------------------------------------------*/
141 bin_str(unsigned long val, int length)
143 static char buffer[80];
149 val = val << (32 - length);
153 if (val & 0x80000000)
157 if ((length % 4) == 0 && length)
164 void getreg(struct reg r) {
165 int val; /* FreeBSD gcc ONLY accepts an int !! */
176 outb(0x3c0, r.num + 0x20);
181 outb(vgabase + 4, r.num);
182 val = inb(vgabase + 5);
195 printf("%s%02x = 0x%02x = %s (bin)\n", getname(r), r.num, val, bin_str(val,8));
198 void setreg(struct reg r, int val) {
210 outb(0x3c0, r.num + 0x20);
214 outb(vgabase + 4, r.num);
215 outb(vgabase + 5, val);
228 printf("%s%02x set to 0x%02x = %s (bin) now\n", getname(r), r.num, val, bin_str(val,8));
231 void yyerror(const char *msg) {
232 fprintf(stderr, "yyerror: %s\n", msg);
235 int main(int argc, char **argv) {
238 if(argc > 1) yydebug = 1;
240 if((fd = open("/dev/console", O_RDONLY)) < 0)
243 if(ioctl(fd, KDENABIO, 0) < 0) {
244 perror("ioctl(KDENABIO)");
247 vgabase = (inb(0x3cc) & 1)? 0x3d0: 0x3b0;
250 ioctl(fd, KDDISABIO, 0);