Remove now unnecessary messing with PCI command register.
[dragonfly.git] / sys / ddb / db_output.c
CommitLineData
984263bc
MD
1/*
2 * Mach Operating System
3 * Copyright (c) 1991,1990 Carnegie Mellon University
4 * All Rights Reserved.
5 *
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.
11 *
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.
15 *
16 * Carnegie Mellon requests users of this software to return to
17 *
18 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
19 * School of Computer Science
20 * Carnegie Mellon University
21 * Pittsburgh PA 15213-3890
22 *
23 * any improvements or extensions that they make and grant Carnegie the
24 * rights to redistribute these changes.
25 *
26 * $FreeBSD: src/sys/ddb/db_output.c,v 1.26 1999/08/28 00:41:09 peter Exp $
fcb52d8a 27 * $DragonFly: src/sys/ddb/db_output.c,v 1.6 2004/09/03 08:50:47 eirikn Exp $
984263bc
MD
28 */
29
30/*
31 * Author: David B. Golub, Carnegie Mellon University
32 * Date: 7/90
33 */
34
35/*
36 * Printf and character output for debugger.
37 */
38
39#include <sys/param.h>
40#include <sys/systm.h>
41#include <sys/cons.h>
42
43#include <machine/stdarg.h>
44
45#include <ddb/ddb.h>
46#include <ddb/db_output.h>
47
48/*
49 * Character output - tracks position in line.
50 * To do this correctly, we should know how wide
51 * the output device is - then we could zero
52 * the line position when the output device wraps
53 * around to the start of the next line.
54 *
55 * Instead, we count the number of spaces printed
56 * since the last printing character so that we
57 * don't print trailing spaces. This avoids most
58 * of the wraparounds.
59 */
60static int db_output_position = 0; /* output column */
61static int db_last_non_space = 0; /* last non-space character */
62db_expr_t db_tab_stop_width = 8; /* how wide are tab stops? */
63#define NEXT_TAB(i) \
64 ((((i) + db_tab_stop_width) / db_tab_stop_width) * db_tab_stop_width)
65db_expr_t db_max_width = 79; /* output line width */
66
43c0ece6 67static void db_putchar (int c, void *arg);
984263bc
MD
68
69/*
70 * Force pending whitespace.
71 */
72void
73db_force_whitespace()
74{
ad0290bd 75 int last_print, next_tab;
984263bc
MD
76
77 last_print = db_last_non_space;
78 while (last_print < db_output_position) {
79 next_tab = NEXT_TAB(last_print);
80 if (next_tab <= db_output_position) {
81 while (last_print < next_tab) { /* DON'T send a tab!!! */
82 cnputc(' ');
83 last_print++;
84 }
85 }
86 else {
87 cnputc(' ');
88 last_print++;
89 }
90 }
91 db_last_non_space = db_output_position;
92}
93
94/*
95 * Output character. Buffer whitespace.
96 */
97static void
98db_putchar(c, arg)
99 int c; /* character to output */
100 void * arg;
101{
102 if (c > ' ' && c <= '~') {
103 /*
104 * Printing character.
105 * If we have spaces to print, print them first.
106 * Use tabs if possible.
107 */
108 db_force_whitespace();
109 cnputc(c);
110 db_output_position++;
111 db_last_non_space = db_output_position;
112 }
113 else if (c == '\n') {
114 /* Newline */
115 cnputc(c);
116 db_output_position = 0;
117 db_last_non_space = 0;
118 db_check_interrupt();
119 }
120 else if (c == '\r') {
121 /* Return */
122 cnputc(c);
123 db_output_position = 0;
124 db_last_non_space = 0;
125 db_check_interrupt();
126 }
127 else if (c == '\t') {
128 /* assume tabs every 8 positions */
129 db_output_position = NEXT_TAB(db_output_position);
130 }
131 else if (c == ' ') {
132 /* space */
133 db_output_position++;
134 }
135 else if (c == '\007') {
136 /* bell */
137 cnputc(c);
138 }
139 /* other characters are assumed non-printing */
140}
141
142/*
143 * Return output position
144 */
145int
146db_print_position()
147{
148 return (db_output_position);
149}
150
151/*
152 * Printing
153 */
154void
984263bc 155db_printf(const char *fmt, ...)
984263bc 156{
e2565a42 157 __va_list listp;
984263bc 158
e2565a42 159 __va_start(listp, fmt);
984263bc 160 kvprintf (fmt, db_putchar, NULL, db_radix, listp);
e2565a42 161 __va_end(listp);
984263bc
MD
162}
163
164int db_indent;
165
166void
984263bc 167db_iprintf(const char *fmt,...)
984263bc 168{
ad0290bd 169 int i;
e2565a42 170 __va_list listp;
984263bc
MD
171
172 for (i = db_indent; i >= 8; i -= 8)
173 db_printf("\t");
174 while (--i >= 0)
175 db_printf(" ");
e2565a42 176 __va_start(listp, fmt);
984263bc 177 kvprintf (fmt, db_putchar, NULL, db_radix, listp);
e2565a42 178 __va_end(listp);
984263bc
MD
179}
180
181/*
182 * End line if too long.
183 */
184void
185db_end_line()
186{
187 if (db_output_position >= db_max_width)
188 db_printf("\n");
189}
fcb52d8a
EN
190
191/*
192 * Simple pager
193 */
194int
195db_more(int *nl)
196{
197 ++*nl;
198 if (*nl == 20) {
199 int c;
200
201 db_printf("--More--");
202 c = cngetc();
203 db_printf("\r");
204 /*
205 * A whole screenfull or just one line?
206 */
207 switch (c) {
208 case '\n': /* just one line */
209 *nl = 19;
210 break;
211 case ' ':
212 *nl = 0; /* another screenfull */
213 break;
214 default: /* exit */
215 db_printf("\n");
216 return(-1);
217 }
218 }
219 return(0);
220}
221