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 $"
40 * Revision 1.1 1994/03/29 02:47:27 mycroft
41 * pcvt 3.0, with some performance enhancements by Joerg Wunsch and me.
43 * Revision 1.2 1994/01/08 17:42:58 j
45 * made multiple commands per line work
48 * Revision 1.3 21.12.1994 -hm
49 * Added mi command for accessing the misc out register
50 * hex values shown as 2 fixed chars, added binary output
55 #include <sys/fcntl.h>
56 #include <machine/cpufunc.h>
57 #include <machine/pcvt_ioctl.h>
60 #include <machine/pio.h>
65 void setreg(struct reg r, int val);
66 void getreg(struct reg r);
67 void yyerror(const char *msg);
71 unsigned short vgabase;
80 %token MI GR CR SR AR NEWLINE
94 line: statements NEWLINE
96 | error NEWLINE { fprintf(stderr, "bing!\n"); }
100 | statements ';' statement
103 statement: register '?' { getreg($1); }
104 | register '=' NUM { setreg($1, $3); }
108 register: reggroup NUM { $$.num = $2; $$.group = $1; }
111 reggroup: GR { $$ = GR; }
124 {GR, "gr"}, {CR, "cr"}, {SR, "sr"}, {AR, "ar"}, {MI, "mi"},
128 const char *getname(struct reg r) {
130 for(idx = 0; regnames[idx].id; idx++)
131 if(regnames[idx].id == r.group)
132 return regnames[idx].name;
136 /*---------------------------------------------------------------------------*
137 * return ptr to string of 1's and 0's for value
138 *---------------------------------------------------------------------------*/
140 bin_str(unsigned long val, int length)
142 static char buffer[80];
148 val = val << (32 - length);
152 if (val & 0x80000000)
156 if ((length % 4) == 0 && length)
163 void getreg(struct reg r) {
164 int val; /* FreeBSD gcc ONLY accepts an int !! */
174 (void)inb(vgabase + 0x0a);
175 outb(0x3c0, r.num + 0x20);
180 outb(vgabase + 4, r.num);
181 val = inb(vgabase + 5);
194 printf("%s%02x = 0x%02x = %s (bin)\n", getname(r), r.num, val, bin_str(val,8));
197 void setreg(struct reg r, int val) {
206 (void)inb(vgabase + 0x0a);
209 outb(0x3c0, r.num + 0x20);
213 outb(vgabase + 4, r.num);
214 outb(vgabase + 5, val);
227 printf("%s%02x set to 0x%02x = %s (bin) now\n", getname(r), r.num, val, bin_str(val,8));
230 void yyerror(const char *msg) {
231 fprintf(stderr, "yyerror: %s\n", msg);
234 int main(int argc, char **argv) {
237 if(argc > 1) yydebug = 1;
239 if((fd = open("/dev/console", O_RDONLY)) < 0)
242 if(ioctl(fd, KDENABIO, 0) < 0) {
243 perror("ioctl(KDENABIO)");
246 vgabase = (inb(0x3cc) & 1)? 0x3d0: 0x3b0;
249 (void)ioctl(fd, KDDISABIO, 0);