]> git.ipfire.org Git - people/ms/u-boot.git/blob - board/MAI/bios_emulator/scitech/src/v86bios/console.c
* Code cleanup:
[people/ms/u-boot.git] / board / MAI / bios_emulator / scitech / src / v86bios / console.c
1 /*
2 * Copyright 1999 Egbert Eich
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of the authors not be used in
9 * advertising or publicity pertaining to distribution of the software without
10 * specific, written prior permission. The authors makes no representations
11 * about the suitability of this software for any purpose. It is provided
12 * "as is" without express or implied warranty.
13 *
14 * THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20 * PERFORMANCE OF THIS SOFTWARE.
21 */
22 #include <sys/ioctl.h>
23 #include <sys/vt.h>
24 #include <sys/kd.h>
25 #include <stdio.h>
26 #include <fcntl.h>
27 #include <unistd.h>
28 #include "debug.h"
29 #include "v86bios.h"
30
31 console
32 open_console(void)
33 {
34 int fd;
35 int VTno;
36 char VTname[11];
37 console Con = {-1,-1};
38 struct vt_stat vts;
39
40 if (NO_CONSOLE)
41 return Con;
42
43 if ((fd = open("/dev/tty0",O_WRONLY,0)) < 0)
44 return Con;
45
46 if ((ioctl(fd, VT_OPENQRY, &VTno) < 0) || (VTno == -1)) {
47 fprintf(stderr,"cannot get a vt\n");
48 return Con;
49 }
50
51 close(fd);
52 sprintf(VTname,"/dev/tty%i",VTno);
53
54 if ((fd = open(VTname, O_RDWR|O_NDELAY, 0)) < 0) {
55 fprintf(stderr,"cannot open console\n");
56 return Con;
57 }
58
59 if (ioctl(fd, VT_GETSTATE, &vts) == 0)
60 Con.vt = vts.v_active;
61
62 if (ioctl(fd, VT_ACTIVATE, VTno) != 0) {
63 fprintf(stderr,"cannot activate console\n");
64 close(fd);
65 return Con;
66 }
67 if (ioctl(fd, VT_WAITACTIVE, VTno) != 0) {
68 fprintf(stderr,"wait for active console failed\n");
69 close(fd);
70 return Con;
71 }
72 #if 0
73 if (ioctl(fd, KDSETMODE, KD_GRAPHICS) < 0) {
74 close(fd);
75 return Con;
76 }
77 #endif
78 Con.fd = fd;
79 return Con;
80 }
81
82 void
83 close_console(console Con)
84 {
85 if (Con.fd == -1)
86 return;
87
88 #if 0
89 ioctl(Con.fd, KDSETMODE, KD_TEXT);
90 #endif
91 if (Con.vt >=0)
92 ioctl(Con.fd, VT_ACTIVATE, Con.vt);
93
94 close(Con.fd);
95 }