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
|
$NetBSD: patch-ab,v 1.4 2007/10/29 18:41:24 joerg Exp $
--- vbetool.c.orig 2006-07-26 03:27:21.000000000 +0200
+++ vbetool.c
@@ -8,19 +8,39 @@ This program is released under the terms
version 2
*/
-#include <pci/pci.h>
#include <assert.h>
+#include <pciutils/pci.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/types.h>
+#ifdef __linux__
#include <sys/io.h>
#include <sys/kd.h>
+#endif
#include <sys/stat.h>
#include <errno.h>
+#ifdef __NetBSD__
+#include <machine/sysarch.h>
+#endif
+
+static uint8_t
+asm_inb(unsigned port)
+{
+ uint8_t data;
+ __asm volatile("inb %w1,%0" : "=a" (data) : "d" (port));
+ return data;
+}
+
+static __inline void
+asm_outb(uint8_t data, unsigned port)
+{
+ __asm volatile("outb %0,%w1" : : "a" (data), "d" (port));
+}
+
#include "include/lrmi.h"
#include "vbetool.h"
@@ -42,8 +62,16 @@ int vbetool_init (void) {
exit(1);
}
+#ifdef __NetBSD__
+# ifdef __i386__
+ i386_iopl(3);
+# else
+ x86_64_iopl(3);
+# endif
+#else
ioperm(0, 1024, 1);
iopl(3);
+#endif
pacc = pci_alloc();
pacc->numeric_ids = 1;
@@ -256,7 +284,9 @@ void restore_state_from(char *data)
LRMI_free_real(data);
+#ifdef __linux__
ioctl(0, KDSETMODE, KD_TEXT);
+#endif
}
@@ -476,23 +506,25 @@ int check_console()
return 11;
}
+#ifdef __linux__
ioctl(0, KDSETMODE, KD_GRAPHICS);
+#endif
return 0;
}
int enable_vga() {
- outb(0x03 | inb(0x3CC), 0x3C2);
- outb(0x01 | inb(0x3C3), 0x3C3);
- outb(0x08 | inb(0x46e8), 0x46e8);
- outb(0x01 | inb(0x102), 0x102);
+ asm_outb(0x03 | asm_inb(0x3CC), 0x3C2);
+ asm_outb(0x01 | asm_inb(0x3C3), 0x3C3);
+ asm_outb(0x08 | asm_inb(0x46e8), 0x46e8);
+ asm_outb(0x01 | asm_inb(0x102), 0x102);
return 0;
}
int disable_vga() {
- outb(~0x03 & inb(0x3CC), 0x3C2);
- outb(~0x01 & inb(0x3C3), 0x3C3);
- outb(~0x08 & inb(0x46e8), 0x46e8);
- outb(~0x01 & inb(0x102), 0x102);
+ asm_outb(~0x03 & asm_inb(0x3CC), 0x3C2);
+ asm_outb(~0x01 & asm_inb(0x3C3), 0x3C3);
+ asm_outb(~0x08 & asm_inb(0x46e8), 0x46e8);
+ asm_outb(~0x01 & asm_inb(0x102), 0x102);
return 0;
}
|