1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
|
/* $OpenBSD: vgaio.y,v 1.2 1999/01/13 07:26:07 niklas Exp $ */
/* Hello emacs, this should be edited in -*- Fundamental -*- mode */
%{
/*
* Copyright (c) 1994,1995 Joerg Wunsch
*
* All rights reserved.
*
* This program is free software.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Joerg Wunsch
* 4. The name of the developer may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ident "$Header: /cvs/OpenBSD/src/sys/arch/i386/isa/pcvt/Util/vgaio/Attic/vgaio.y,v 1.2 1999/01/13 07:26:07 niklas Exp $"
#include <stdio.h>
#include <stdlib.h>
#include <sys/fcntl.h>
#include <machine/cpufunc.h>
#include <machine/pcvt_ioctl.h>
#ifdef __NetBSD__
#include <machine/pio.h>
#endif
#include "vgaio.h"
void setreg(struct reg r, int val);
void getreg(struct reg r);
void yyerror(const char *msg);
#define YYDEBUG 1
unsigned short vgabase;
%}
%union {
int num;
struct reg reg;
}
%token MI GR CR SR AR NEWLINE
%token <num> NUM
%type <num> reggroup
%type <reg> register
%%
interpret: lines ;
lines: line
| lines line
;
line: statements NEWLINE
| NEWLINE
| error NEWLINE { fprintf(stderr, "bing!\n"); }
;
statements: statement
| statements ';' statement
;
statement: register '?' { getreg($1); }
| register '=' NUM { setreg($1, $3); }
| /* lambda */
;
register: reggroup NUM { $$.num = $2; $$.group = $1; }
/* useful for the MI register: */
| reggroup { $$.num = 0; $$.group = $1; }
;
reggroup: GR { $$ = GR; }
| CR { $$ = CR; }
| SR { $$ = SR; }
| AR { $$ = AR; }
| MI { $$ = MI; }
;
%%
static struct {
int id;
const char *name;
} regnames[] = {
{GR, "gr"}, {CR, "cr"}, {SR, "sr"}, {AR, "ar"}, {MI, "mi"},
{0, 0}
};
const char *getname(struct reg r) {
int idx;
for(idx = 0; regnames[idx].id; idx++)
if(regnames[idx].id == r.group)
return regnames[idx].name;
return "??";
}
/* return ptr to string of 1s and 0s for value */
char *
bin_str(unsigned long val, int length) {
static char buffer[80];
int i = 0;
if (length > 32)
length = 32;
val = val << (32 - length);
while (length--)
{
if (val & 0x80000000)
buffer[i++] = '1';
else
buffer[i++] = '0';
if ((length % 4) == 0 && length)
buffer[i++] = '.';
val = val << 1;
}
return (buffer);
}
void getreg(struct reg r) {
int val; /* FreeBSD gcc ONLY accepts an int */
switch(r.group) {
case GR:
outb(0x3ce, r.num);
val = inb(0x3cf);
break;
case AR:
r.num &= 0x1f;
(void)inb(vgabase + 0x0a);
outb(0x3c0, r.num + 0x20);
val = inb(0x3c1);
break;
case CR:
outb(vgabase + 4, r.num);
val = inb(vgabase + 5);
break;
case SR:
outb(0x3c4, r.num);
val = inb(0x3c5);
break;
case MI:
val = inb(0x3cc);
break;
}
printf("%s%02x = 0x%02x = %sB\n",
getname(r), r.num, val, bin_str(val, 8));
}
void setreg(struct reg r, int val) {
switch(r.group) {
case GR:
outb(0x3ce, r.num);
outb(0x3cf, val);
break;
case AR:
r.num &= 0x1f;
(void)inb(vgabase + 0x0a);
outb(0x3c0, r.num);
outb(0x3c0, val);
outb(0x3c0, r.num + 0x20);
break;
case CR:
outb(vgabase + 4, r.num);
outb(vgabase + 5, val);
break;
case SR:
outb(0x3c4, r.num);
outb(0x3c5, val);
break;
case MI:
outb(0x3c2, val);
break;
}
printf("%s%02x set to 0x%02x = %sB now\n",
getname(r), r.num, val, bin_str(val, 8));
}
void yyerror(const char *msg) {
fprintf(stderr, "yyerror: %s\n", msg);
}
void usage(void) {
fprintf(stderr, "usage: vgaio [-d] [-f devname]\n");
exit(2);
}
int main(int argc, char **argv) {
int fd, c;
const char *devname = "/dev/console";
while((c = getopt(argc, argv, "df:")) != EOF)
switch(c) {
case 'd':
yydebug = 1;
break;
case 'f':
devname = optarg;
break;
case '?':
default:
usage();
}
argc -= optind;
argv += optind;
if(argc > 0)
usage();
if((fd = open(devname, O_RDONLY)) < 0) {
perror("open(vga)");
return 1;
}
if(ioctl(fd, KDENABIO, 0) < 0) {
perror("ioctl(KDENABIO)");
return 1;
}
vgabase = (inb(0x3cc) & 1)? 0x3d0: 0x3b0;
yyparse();
(void)ioctl(fd, KDDISABIO, 0);
return 0;
}
|