2 * Mach Operating System
3 * Copyright (c) 1991,1990 Carnegie Mellon University
6 * Permission to use, copy, modify and distribute this software and its
7 * documentation is hereby granted, provided that both the copyright
8 * notice and this permission notice appear in all copies of the
9 * software, derivative works or modified versions, and any portions
10 * thereof, and that both notices appear in supporting documentation.
12 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
13 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
16 * Carnegie Mellon requests users of this software to return to
18 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
19 * School of Computer Science
20 * Carnegie Mellon University
21 * Pittsburgh PA 15213-3890
23 * any improvements or extensions that they make and grant Carnegie the
24 * rights to redistribute these changes.
26 * $FreeBSD: src/sys/ddb/db_output.c,v 1.26 1999/08/28 00:41:09 peter Exp $
27 * $DragonFly: src/sys/ddb/db_output.c,v 1.9 2008/09/25 13:30:15 sephe Exp $
31 * Author: David B. Golub, Carnegie Mellon University
36 * Printf and character output for debugger.
39 #include <sys/param.h>
40 #include <sys/systm.h>
42 #include <sys/ctype.h>
43 #include <sys/thread2.h>
44 #include <sys/spinlock2.h>
46 #include <machine/stdarg.h>
49 #include <ddb/db_output.h>
52 * Character output - tracks position in line.
53 * To do this correctly, we should know how wide
54 * the output device is - then we could zero
55 * the line position when the output device wraps
56 * around to the start of the next line.
58 * Instead, we count the number of spaces printed
59 * since the last printing character so that we
60 * don't print trailing spaces. This avoids most
63 static int db_output_position = 0; /* output column */
64 static int db_last_non_space = 0; /* last non-space character */
65 db_expr_t db_tab_stop_width = 8; /* how wide are tab stops? */
67 ((((i) + db_tab_stop_width) / db_tab_stop_width) * db_tab_stop_width)
68 db_expr_t db_max_width = 79; /* output line width */
70 static void db_putchar (int c, void *arg);
73 * Force pending whitespace.
76 db_force_whitespace(void)
78 int last_print, next_tab;
80 last_print = db_last_non_space;
81 while (last_print < db_output_position) {
82 next_tab = NEXT_TAB(last_print);
83 if (next_tab <= db_output_position) {
84 while (last_print < next_tab) { /* DON'T send a tab!!! */
94 db_last_non_space = db_output_position;
98 * Output character. Buffer whitespace.
101 * arg: character to output
104 db_putchar(int c, void *arg)
107 * If not in the debugger, output data to both the console and
108 * the message buffer.
111 if (c == '\r' || c == '\n' || c == '\t' ||
119 if (c == '\r' || c == '\n')
120 db_check_interrupt();
126 if (c > ' ' && c <= '~') {
128 * Printing character.
129 * If we have spaces to print, print them first.
130 * Use tabs if possible.
132 db_force_whitespace();
134 db_output_position++;
135 db_last_non_space = db_output_position;
137 else if (c == '\n') {
140 db_output_position = 0;
141 db_last_non_space = 0;
142 db_check_interrupt();
144 else if (c == '\r') {
147 db_output_position = 0;
148 db_last_non_space = 0;
149 db_check_interrupt();
151 else if (c == '\t') {
152 /* assume tabs every 8 positions */
153 db_output_position = NEXT_TAB(db_output_position);
157 db_output_position++;
159 else if (c == '\007') {
163 /* other characters are assumed non-printing */
168 * Return output position
171 db_print_position(void)
173 return (db_output_position);
179 * NOTE: We bypass subr_prf's cons_spin here by using our own putchar
183 db_printf(const char *fmt, ...)
187 __va_start(listp, fmt);
188 kvcprintf (fmt, db_putchar, NULL, db_radix, listp);
194 db_vprintf(const char *fmt, __va_list va)
196 kvcprintf (fmt, db_putchar, NULL, db_radix, va);
203 db_iprintf(const char *fmt,...)
208 for (i = db_indent; i >= 8; i -= 8)
212 __va_start(listp, fmt);
213 kvcprintf (fmt, db_putchar, NULL, db_radix, listp);
218 * End line if too long.
223 if (db_output_position >= db_max_width)
237 db_printf("--More--");
241 * A whole screenfull or just one line?
244 case '\n': /* just one line */
248 *nl = 0; /* another screenfull */
258 /* #define TEMPORARY_DEBUGGING */
259 #ifdef TEMPORARY_DEBUGGING
262 * Temporary Debugging, only turned on manually by kernel hackers trying
263 * to debug extremely low level code. Adjust PCHAR_ as required.
265 static void PCHAR_(int, void * __unused);
268 kprintf0(const char *fmt, ...)
273 kvcprintf(fmt, PCHAR_, NULL, 10, ap);
278 PCHAR_(int c, void *dummy __unused)
280 const int COMC_TXWAIT = 0x40000;
281 const int COMPORT = 0x2f8; /* 0x3f8 COM1, 0x2f8 COM2 */
282 const int LSR_TXRDY = 0x20;
283 const int BAUD = 9600;
284 const int com_lsr = 5;
285 const int com_data = 0;
291 outb(COMPORT+3, 0x83); /* DLAB + 8N1 */
292 outb(COMPORT+0, (115200 / BAUD) & 0xFF);
293 outb(COMPORT+1, (115200 / BAUD) >> 8);
294 outb(COMPORT+3, 0x03); /* 8N1 */
295 outb(COMPORT+4, 0x03); /* RTS+DTR */
296 outb(COMPORT+2, 0x01); /* FIFO_ENABLE */
299 for (wait = COMC_TXWAIT; wait > 0; wait--) {
300 if (inb(COMPORT + com_lsr) & LSR_TXRDY) {
301 outb(COMPORT + com_data, (u_char)c);