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/thread2.h>
43 #include <sys/spinlock2.h>
45 #include <machine/stdarg.h>
48 #include <ddb/db_output.h>
51 * Character output - tracks position in line.
52 * To do this correctly, we should know how wide
53 * the output device is - then we could zero
54 * the line position when the output device wraps
55 * around to the start of the next line.
57 * Instead, we count the number of spaces printed
58 * since the last printing character so that we
59 * don't print trailing spaces. This avoids most
62 static int db_output_position = 0; /* output column */
63 static int db_last_non_space = 0; /* last non-space character */
64 db_expr_t db_tab_stop_width = 8; /* how wide are tab stops? */
66 ((((i) + db_tab_stop_width) / db_tab_stop_width) * db_tab_stop_width)
67 db_expr_t db_max_width = 79; /* output line width */
69 static void db_putchar (int c, void *arg);
72 * Force pending whitespace.
75 db_force_whitespace(void)
77 int last_print, next_tab;
79 last_print = db_last_non_space;
80 while (last_print < db_output_position) {
81 next_tab = NEXT_TAB(last_print);
82 if (next_tab <= db_output_position) {
83 while (last_print < next_tab) { /* DON'T send a tab!!! */
93 db_last_non_space = db_output_position;
97 * Output character. Buffer whitespace.
100 * arg: character to output
103 db_putchar(int c, void *arg)
106 * If not in the debugger, output data to both the console and
107 * the message buffer.
113 if (c == '\r' || c == '\n')
114 db_check_interrupt();
120 if (c > ' ' && c <= '~') {
122 * Printing character.
123 * If we have spaces to print, print them first.
124 * Use tabs if possible.
126 db_force_whitespace();
128 db_output_position++;
129 db_last_non_space = db_output_position;
131 else if (c == '\n') {
134 db_output_position = 0;
135 db_last_non_space = 0;
136 db_check_interrupt();
138 else if (c == '\r') {
141 db_output_position = 0;
142 db_last_non_space = 0;
143 db_check_interrupt();
145 else if (c == '\t') {
146 /* assume tabs every 8 positions */
147 db_output_position = NEXT_TAB(db_output_position);
151 db_output_position++;
153 else if (c == '\007') {
157 /* other characters are assumed non-printing */
162 * Return output position
165 db_print_position(void)
167 return (db_output_position);
173 * NOTE: We bypass subr_prf's cons_spin here by using our own putchar
177 db_printf(const char *fmt, ...)
181 __va_start(listp, fmt);
182 kvcprintf (fmt, db_putchar, NULL, db_radix, listp);
188 db_vprintf(const char *fmt, __va_list va)
190 kvcprintf (fmt, db_putchar, NULL, db_radix, va);
197 db_iprintf(const char *fmt,...)
202 for (i = db_indent; i >= 8; i -= 8)
206 __va_start(listp, fmt);
207 kvcprintf (fmt, db_putchar, NULL, db_radix, listp);
212 * End line if too long.
217 if (db_output_position >= db_max_width)
231 db_printf("--More--");
235 * A whole screenfull or just one line?
238 case '\n': /* just one line */
242 *nl = 0; /* another screenfull */
252 /* #define TEMPORARY_DEBUGGING */
253 #ifdef TEMPORARY_DEBUGGING
256 * Temporary Debugging, only turned on manually by kernel hackers trying
257 * to debug extremely low level code. Adjust PCHAR_ as required.
259 static void PCHAR_(int, void * __unused);
262 kprintf0(const char *fmt, ...)
267 kvcprintf(fmt, PCHAR_, NULL, 10, ap);
272 PCHAR_(int c, void *dummy __unused)
274 const int COMC_TXWAIT = 0x40000;
275 const int COMPORT = 0x2f8; /* 0x3f8 COM1, 0x2f8 COM2 */
276 const int LSR_TXRDY = 0x20;
277 const int BAUD = 9600;
278 const int com_lsr = 5;
279 const int com_data = 0;
285 outb(COMPORT+3, 0x83); /* DLAB + 8N1 */
286 outb(COMPORT+0, (115200 / BAUD) & 0xFF);
287 outb(COMPORT+1, (115200 / BAUD) >> 8);
288 outb(COMPORT+3, 0x03); /* 8N1 */
289 outb(COMPORT+4, 0x03); /* RTS+DTR */
290 outb(COMPORT+2, 0x01); /* FIFO_ENABLE */
293 for (wait = COMC_TXWAIT; wait > 0; wait--) {
294 if (inb(COMPORT + com_lsr) & LSR_TXRDY) {
295 outb(COMPORT + com_data, (u_char)c);