Annotation of prex-old/sys/arch/i386/pc/diag.c, Revision 1.1.1.1.2.1
1.1 nbrk 1: /*-
2: * Copyright (c) 2005-2007, Kohsuke Ohtani
3: * All rights reserved.
4: *
5: * Redistribution and use in source and binary forms, with or without
6: * modification, are permitted provided that the following conditions
7: * are met:
8: * 1. Redistributions of source code must retain the above copyright
9: * notice, this list of conditions and the following disclaimer.
10: * 2. Redistributions in binary form must reproduce the above copyright
11: * notice, this list of conditions and the following disclaimer in the
12: * documentation and/or other materials provided with the distribution.
13: * 3. Neither the name of the author nor the names of any co-contributors
14: * may be used to endorse or promote products derived from this software
15: * without specific prior written permission.
16: *
17: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20: * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27: * SUCH DAMAGE.
28: */
29:
30: /*
31: * diag.c - diagnostic message support
32: */
33:
34: #include <kernel.h>
35: #include <page.h>
36: #include <cpu.h>
1.1.1.1.2.1! nbrk 37: #include <locore.h>
1.1 nbrk 38:
39: #ifdef DEBUG
40: #ifdef CONFIG_DIAG_SCREEN
41:
42: #define VID_ATTR 0x0F00
43: #define VID_PORT 0x03d4
44: #define VID_RAM 0xB8000
45:
46: /* Screen info */
47: static short *vram;
48: static int pos_x;
49: static int pos_y;
50: static int screen_x;
51: static int screen_y;
52:
53: static void
54: screen_scrollup(void)
55: {
56: int i;
57:
1.1.1.1.2.1! nbrk 58: memcpy(vram, vram + screen_x, (size_t)(screen_x * (screen_y - 1) * 2));
1.1 nbrk 59: for (i = 0; i < screen_x; i++)
60: vram[screen_x * (screen_y - 1) + i] = ' ';
61: }
62:
63: static void
64: screen_update(void)
65: {
66: int pos = pos_y * screen_x + pos_x;
67:
68: outb(0x0e, VID_PORT);
1.1.1.1.2.1! nbrk 69: outb((u_int)pos >> 8, VID_PORT + 1);
1.1 nbrk 70:
71: outb(0x0f, VID_PORT);
1.1.1.1.2.1! nbrk 72: outb((u_int)pos & 0xff, VID_PORT + 1);
1.1 nbrk 73: }
74:
75: static void
76: screen_newline(void)
77: {
78:
79: pos_x = 0;
80: pos_y++;
81: if (pos_y >= screen_y) {
82: pos_y = screen_y - 1;
83: screen_scrollup();
84: }
85: screen_update();
86: }
87:
88: static void
89: screen_putchar(char c)
90: {
91:
92: switch (c) {
93: case '\n':
94: screen_newline();
95: return;
96: case '\r':
97: pos_x = 0;
98: screen_update();
99: return;
100: case '\b':
101: if (pos_x == 0)
102: return;
103: pos_x--;
104: screen_update();
105: return;
106: }
107: vram[pos_y * screen_x + pos_x] = c | VID_ATTR;
108: pos_x++;
109: if (pos_x >= screen_x) {
110: pos_x = 0;
111: pos_y++;
112: if (pos_y >= screen_y) {
113: pos_y = screen_y - 1;
114: screen_scrollup();
115: }
116: }
117: screen_update();
118: }
119:
120: static int
121: screen_init(void)
122: {
123:
124: vram = (short *)phys_to_virt(VID_RAM);
125: pos_x = 0;
126: pos_y = 0;
127: screen_x = boot_info->video.text_x;
128: screen_y = boot_info->video.text_y;
129: return 0;
130: }
131: #endif /* CONFIG_DIAG_SCREEN */
132:
133:
134: #ifdef CONFIG_DIAG_BOCHS
135: static void
136: bochs_putchar(char c)
137: {
138: /*
139: * Bochs debug port
140: */
141: if (inb(0xe9) == 0xe9)
1.1.1.1.2.1! nbrk 142: outb((u_char)c, 0xe9);
1.1 nbrk 143: }
144: #endif /* CONFIG_DIAG_BOCHS */
145:
146: void
147: diag_print(char *buf)
148: {
149:
150: while (*buf) {
151: #ifdef CONFIG_DIAG_SCREEN
152: screen_putchar(*buf);
153: #endif
154: #ifdef CONFIG_DIAG_BOCHS
155: bochs_putchar(*buf);
156: #endif
157: ++buf;
158: }
159: }
160: #endif /* DEBUG */
161:
162: void
163: diag_init(void)
164: {
165: #if defined(DEBUG) && defined(CONFIG_DIAG_SCREEN)
166: screen_init();
167: #endif
168: }
CVSweb