blob: ae105fb403001d47e01e2ff234cefd7e78c04ec0 [file] [log] [blame]
Kevin O'Connor65e63422008-07-19 14:12:32 -04001// Raw screen writing and debug output code.
Kevin O'Connorf076a3e2008-02-25 22:25:15 -05002//
Kevin O'Connor43562762009-10-12 09:48:12 -04003// Copyright (C) 2008,2009 Kevin O'Connor <kevin@koconnor.net>
Kevin O'Connorf076a3e2008-02-25 22:25:15 -05004//
Kevin O'Connorb1b7c2a2009-01-15 20:52:58 -05005// This file may be distributed under the terms of the GNU LGPLv3 license.
Kevin O'Connorf076a3e2008-02-25 22:25:15 -05006
7#include <stdarg.h> // va_list
8
9#include "farptr.h" // GET_VAR
Kevin O'Connor567e4e32008-04-05 11:37:51 -040010#include "util.h" // printf
Kevin O'Connor9521e262008-07-04 13:04:29 -040011#include "bregs.h" // struct bregs
12#include "config.h" // CONFIG_*
Kevin O'Connor15157a32008-12-13 11:10:37 -050013#include "biosvar.h" // GET_GLOBAL
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050014
Kevin O'Connor9ed6b622009-10-07 21:41:08 -040015struct putcinfo {
16 void (*func)(struct putcinfo *info, char c);
17};
18
19
20/****************************************************************
21 * Debug output
22 ****************************************************************/
23
Kevin O'Connorc151b3b2009-05-12 22:59:41 -040024#define DEBUG_PORT PORT_SERIAL1
Kevin O'Connor5c732402008-06-07 10:43:07 -040025#define DEBUG_TIMEOUT 100000
26
Kevin O'Connor61d6b062008-06-21 12:15:10 -040027void
Kevin O'Connor1ca05b02010-01-03 17:43:37 -050028debug_serial_setup(void)
Kevin O'Connor61d6b062008-06-21 12:15:10 -040029{
30 if (!CONFIG_DEBUG_SERIAL)
31 return;
32 // setup for serial logging: 8N1
33 u8 oldparam, newparam = 0x03;
Kevin O'Connorc151b3b2009-05-12 22:59:41 -040034 oldparam = inb(DEBUG_PORT+SEROFF_LCR);
35 outb(newparam, DEBUG_PORT+SEROFF_LCR);
Kevin O'Connor61d6b062008-06-21 12:15:10 -040036 // Disable irqs
37 u8 oldier, newier = 0;
Kevin O'Connorc151b3b2009-05-12 22:59:41 -040038 oldier = inb(DEBUG_PORT+SEROFF_IER);
39 outb(newier, DEBUG_PORT+SEROFF_IER);
Kevin O'Connor61d6b062008-06-21 12:15:10 -040040
41 if (oldparam != newparam || oldier != newier)
42 dprintf(1, "Changing serial settings was %x/%x now %x/%x\n"
43 , oldparam, oldier, newparam, newier);
44}
45
Kevin O'Connor65e63422008-07-19 14:12:32 -040046// Write a character to the serial port.
Kevin O'Connor5c732402008-06-07 10:43:07 -040047static void
48debug_serial(char c)
49{
Kevin O'Connor3e832bb2009-05-15 22:22:12 -040050 if (!CONFIG_DEBUG_SERIAL)
51 return;
Kevin O'Connor5c732402008-06-07 10:43:07 -040052 int timeout = DEBUG_TIMEOUT;
Kevin O'Connorc151b3b2009-05-12 22:59:41 -040053 while ((inb(DEBUG_PORT+SEROFF_LSR) & 0x60) != 0x60)
Kevin O'Connor5c732402008-06-07 10:43:07 -040054 if (!timeout--)
55 // Ran out of time.
56 return;
Kevin O'Connorc151b3b2009-05-12 22:59:41 -040057 outb(c, DEBUG_PORT+SEROFF_DATA);
Kevin O'Connor5c732402008-06-07 10:43:07 -040058}
59
Kevin O'Connorb9e62d22009-08-02 13:18:27 -040060// Make sure all serial port writes have been completely sent.
Kevin O'Connor3e832bb2009-05-15 22:22:12 -040061static void
Kevin O'Connor1ca05b02010-01-03 17:43:37 -050062debug_serial_flush(void)
Kevin O'Connor3e832bb2009-05-15 22:22:12 -040063{
64 if (!CONFIG_DEBUG_SERIAL)
65 return;
66 int timeout = DEBUG_TIMEOUT;
67 while ((inb(DEBUG_PORT+SEROFF_LSR) & 0x40) != 0x40)
68 if (!timeout--)
69 // Ran out of time.
70 return;
71}
72
Kevin O'Connor9ed6b622009-10-07 21:41:08 -040073// Write a character to debug port(s).
74static void
75putc_debug(struct putcinfo *action, char c)
76{
77 if (! CONFIG_DEBUG_LEVEL)
78 return;
79 if (! CONFIG_COREBOOT)
80 // Send character to debug port.
81 outb(c, PORT_BIOS_DEBUG);
82 if (c == '\n')
83 debug_serial('\r');
84 debug_serial(c);
85}
86
Kevin O'Connor52a300f2009-12-26 23:32:57 -050087// In segmented mode just need a dummy variable (putc_debug is always
88// used anyway), and in 32bit flat mode need a pointer to the 32bit
89// instance of putc_debug().
Kevin O'Connor871e0a02009-12-30 12:14:53 -050090#if MODE16
Kevin O'Connor43562762009-10-12 09:48:12 -040091static struct putcinfo debuginfo VAR16;
Kevin O'Connor871e0a02009-12-30 12:14:53 -050092#elif MODESEGMENT
93static struct putcinfo debuginfo VAR32SEG;
Kevin O'Connorebd426b2009-10-08 08:51:24 -040094#else
95static struct putcinfo debuginfo = { putc_debug };
96#endif
Kevin O'Connor9ed6b622009-10-07 21:41:08 -040097
98
99/****************************************************************
100 * Screen writing
101 ****************************************************************/
102
Kevin O'Connor65e63422008-07-19 14:12:32 -0400103// Show a character on the screen.
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500104static void
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400105screenc(char c)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500106{
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500107 struct bregs br;
108 memset(&br, 0, sizeof(br));
Kevin O'Connorf8e800d2009-09-24 21:01:16 -0400109 br.flags = F_IF;
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500110 br.ah = 0x0e;
111 br.al = c;
112 call16_int(0x10, &br);
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500113}
114
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400115// Handle a character from a printf request.
116static void
117putc_screen(struct putcinfo *action, char c)
118{
119 if (CONFIG_SCREEN_AND_DEBUG)
Kevin O'Connorc604f2f2009-10-24 19:56:11 -0400120 putc_debug(&debuginfo, c);
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400121 if (c == '\n')
122 screenc('\r');
123 screenc(c);
124}
125
126static struct putcinfo screeninfo = { putc_screen };
127
128
129/****************************************************************
130 * Xprintf code
131 ****************************************************************/
132
Kevin O'Connor65e63422008-07-19 14:12:32 -0400133// Output a character.
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500134static void
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400135putc(struct putcinfo *action, char c)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500136{
Kevin O'Connor52a300f2009-12-26 23:32:57 -0500137 if (MODESEGMENT) {
138 // Only debugging output supported in segmented mode.
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400139 putc_debug(action, c);
140 return;
Kevin O'Connorac8df8c2008-05-24 23:46:33 -0400141 }
Kevin O'Connor1812e202008-05-07 21:29:50 -0400142
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400143 void (*func)(struct putcinfo *info, char c) = GET_GLOBAL(action->func);
144 func(action, c);
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500145}
146
Kevin O'Connor65e63422008-07-19 14:12:32 -0400147// Ouptut a string.
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500148static void
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400149puts(struct putcinfo *action, const char *s)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500150{
151 for (; *s; s++)
152 putc(action, *s);
153}
154
Kevin O'Connor65e63422008-07-19 14:12:32 -0400155// Output a string that is in the CS segment.
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500156static void
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400157puts_cs(struct putcinfo *action, const char *s)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500158{
Kevin O'Connor462cb502009-10-07 20:59:45 -0400159 char *vs = (char*)s;
160 for (;; vs++) {
161 char c = GET_GLOBAL(*vs);
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500162 if (!c)
163 break;
164 putc(action, c);
165 }
166}
167
Kevin O'Connor65e63422008-07-19 14:12:32 -0400168// Output an unsigned integer.
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500169static void
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400170putuint(struct putcinfo *action, u32 val)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500171{
172 char buf[12];
173 char *d = &buf[sizeof(buf) - 1];
174 *d-- = '\0';
175 for (;;) {
Kevin O'Connor4b60c002008-02-25 22:29:55 -0500176 *d = (val % 10) + '0';
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500177 val /= 10;
178 if (!val)
179 break;
180 d--;
181 }
182 puts(action, d);
183}
184
Kevin O'Connor65e63422008-07-19 14:12:32 -0400185// Output a single digit hex character.
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500186static inline void
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400187putsinglehex(struct putcinfo *action, u32 val)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500188{
189 if (val <= 9)
190 val = '0' + val;
191 else
192 val = 'a' + val - 10;
193 putc(action, val);
194}
195
Kevin O'Connor65e63422008-07-19 14:12:32 -0400196// Output an integer in hexadecimal.
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500197static void
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400198puthex(struct putcinfo *action, u32 val, int width)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500199{
Kevin O'Connor91b53a72009-05-05 22:52:09 -0400200 if (!width) {
201 u32 tmp = val;
202 width = 1;
203 if (tmp > 0xffff) {
204 width += 4;
205 tmp >>= 16;
206 }
207 if (tmp > 0xff) {
208 width += 2;
209 tmp >>= 8;
210 }
211 if (tmp > 0xf)
212 width += 1;
213 }
214
215 switch (width) {
216 default: putsinglehex(action, (val >> 28) & 0xf);
217 case 7: putsinglehex(action, (val >> 24) & 0xf);
218 case 6: putsinglehex(action, (val >> 20) & 0xf);
219 case 5: putsinglehex(action, (val >> 16) & 0xf);
220 case 4: putsinglehex(action, (val >> 12) & 0xf);
221 case 3: putsinglehex(action, (val >> 8) & 0xf);
222 case 2: putsinglehex(action, (val >> 4) & 0xf);
223 case 1: putsinglehex(action, (val >> 0) & 0xf);
224 }
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500225}
226
Kevin O'Connor7d0f08a2008-03-04 22:27:55 -0500227static inline int
228isdigit(u8 c)
229{
Kevin O'Connord6e4b4c2008-08-29 21:20:32 -0400230 return ((u8)(c - '0')) < 10;
Kevin O'Connor7d0f08a2008-03-04 22:27:55 -0500231}
232
Kevin O'Connor567e4e32008-04-05 11:37:51 -0400233static void
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400234bvprintf(struct putcinfo *action, const char *fmt, va_list args)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500235{
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500236 const char *s = fmt;
237 for (;; s++) {
Kevin O'Connor15157a32008-12-13 11:10:37 -0500238 char c = GET_GLOBAL(*(u8*)s);
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500239 if (!c)
240 break;
241 if (c != '%') {
242 putc(action, c);
243 continue;
244 }
245 const char *n = s+1;
Kevin O'Connor91b53a72009-05-05 22:52:09 -0400246 int field_width = 0;
Kevin O'Connor7d0f08a2008-03-04 22:27:55 -0500247 for (;;) {
Kevin O'Connor15157a32008-12-13 11:10:37 -0500248 c = GET_GLOBAL(*(u8*)n);
Kevin O'Connor7d0f08a2008-03-04 22:27:55 -0500249 if (!isdigit(c))
250 break;
Kevin O'Connor91b53a72009-05-05 22:52:09 -0400251 field_width = field_width * 10 + c - '0';
Kevin O'Connor7d0f08a2008-03-04 22:27:55 -0500252 n++;
253 }
Kevin O'Connora9096f42008-03-08 15:40:43 -0500254 if (c == 'l') {
255 // Ignore long format indicator
256 n++;
Kevin O'Connor15157a32008-12-13 11:10:37 -0500257 c = GET_GLOBAL(*(u8*)n);
Kevin O'Connora9096f42008-03-08 15:40:43 -0500258 }
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500259 s32 val;
260 const char *sarg;
261 switch (c) {
262 case '%':
263 putc(action, '%');
264 break;
265 case 'd':
266 val = va_arg(args, s32);
267 if (val < 0) {
268 putc(action, '-');
269 val = -val;
270 }
271 putuint(action, val);
272 break;
273 case 'u':
274 val = va_arg(args, s32);
275 putuint(action, val);
276 break;
Kevin O'Connorf06f03a2008-03-29 12:44:32 -0400277 case 'p':
Kevin O'Connor91b53a72009-05-05 22:52:09 -0400278 /* %p always has 0x prepended */
279 putc(action, '0');
280 putc(action, 'x');
281 field_width = 8;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500282 case 'x':
283 val = va_arg(args, s32);
Kevin O'Connor91b53a72009-05-05 22:52:09 -0400284 puthex(action, val, field_width);
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500285 break;
Kevin O'Connor12dade52008-03-01 13:35:17 -0500286 case 'c':
287 val = va_arg(args, int);
288 putc(action, val);
289 break;
Kevin O'Connore0113c92008-04-05 15:51:12 -0400290 case '.':
291 // Hack to support "%.s" - meaning string on stack.
Kevin O'Connor15157a32008-12-13 11:10:37 -0500292 if (GET_GLOBAL(*(u8*)(n+1)) != 's')
Kevin O'Connore0113c92008-04-05 15:51:12 -0400293 break;
294 n++;
295 sarg = va_arg(args, const char *);
296 puts(action, sarg);
297 break;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500298 case 's':
299 sarg = va_arg(args, const char *);
300 puts_cs(action, sarg);
301 break;
302 default:
Kevin O'Connor4ce6a492008-02-29 00:21:27 -0500303 putc(action, '%');
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500304 n = s;
305 }
306 s = n;
307 }
Kevin O'Connor567e4e32008-04-05 11:37:51 -0400308}
309
310void
Kevin O'Connore07e18e2009-02-08 17:07:29 -0500311panic(const char *fmt, ...)
Kevin O'Connor567e4e32008-04-05 11:37:51 -0400312{
Kevin O'Connor79cb1192008-07-21 23:29:33 -0400313 if (CONFIG_DEBUG_LEVEL) {
314 va_list args;
315 va_start(args, fmt);
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400316 bvprintf(&debuginfo, fmt, args);
Kevin O'Connor79cb1192008-07-21 23:29:33 -0400317 va_end(args);
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400318 debug_serial_flush();
Kevin O'Connor79cb1192008-07-21 23:29:33 -0400319 }
Kevin O'Connor567e4e32008-04-05 11:37:51 -0400320
321 // XXX - use PANIC PORT.
322 irq_disable();
323 for (;;)
324 hlt();
325}
326
327void
Kevin O'Connorac8df8c2008-05-24 23:46:33 -0400328__dprintf(const char *fmt, ...)
Kevin O'Connor567e4e32008-04-05 11:37:51 -0400329{
Kevin O'Connor52a300f2009-12-26 23:32:57 -0500330 if (!MODESEGMENT && CONFIG_THREADS && CONFIG_DEBUG_LEVEL >= DEBUG_thread
Kevin O'Connorc604f2f2009-10-24 19:56:11 -0400331 && *fmt != '\\' && *fmt != '/') {
332 struct thread_info *cur = getCurThread();
333 if (cur != &MainThread) {
334 // Show "thread id" for this debug message.
335 putc_debug(&debuginfo, '|');
336 puthex(&debuginfo, (u32)cur, 8);
337 putc_debug(&debuginfo, '|');
338 putc_debug(&debuginfo, ' ');
339 }
340 }
341
Kevin O'Connor567e4e32008-04-05 11:37:51 -0400342 va_list args;
343 va_start(args, fmt);
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400344 bvprintf(&debuginfo, fmt, args);
Kevin O'Connor567e4e32008-04-05 11:37:51 -0400345 va_end(args);
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400346 debug_serial_flush();
Kevin O'Connor567e4e32008-04-05 11:37:51 -0400347}
348
349void
350printf(const char *fmt, ...)
351{
Kevin O'Connor52a300f2009-12-26 23:32:57 -0500352 ASSERT32FLAT();
Kevin O'Connor567e4e32008-04-05 11:37:51 -0400353 va_list args;
354 va_start(args, fmt);
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400355 bvprintf(&screeninfo, fmt, args);
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500356 va_end(args);
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400357 if (CONFIG_SCREEN_AND_DEBUG)
358 debug_serial_flush();
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500359}
360
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400361
362/****************************************************************
363 * snprintf
364 ****************************************************************/
365
366struct snprintfinfo {
367 struct putcinfo info;
368 char *str, *end;
369};
370
371static void
372putc_str(struct putcinfo *info, char c)
373{
374 struct snprintfinfo *sinfo = container_of(info, struct snprintfinfo, info);
375 if (sinfo->str >= sinfo->end)
376 return;
377 *sinfo->str = c;
378 sinfo->str++;
379}
380
Kevin O'Connor2be312c2009-11-24 09:37:53 -0500381// Build a formatted string. Note, this function returns the actual
382// number of bytes used (not including null) even in the overflow
383// case.
384int
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400385snprintf(char *str, size_t size, const char *fmt, ...)
386{
Kevin O'Connor52a300f2009-12-26 23:32:57 -0500387 ASSERT32FLAT();
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400388 if (!size)
Kevin O'Connor2be312c2009-11-24 09:37:53 -0500389 return 0;
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400390 struct snprintfinfo sinfo = { { putc_str }, str, str + size };
391 va_list args;
392 va_start(args, fmt);
393 bvprintf(&sinfo.info, fmt, args);
394 va_end(args);
395 char *end = sinfo.str;
396 if (end >= sinfo.end)
Kevin O'Connor2be312c2009-11-24 09:37:53 -0500397 end = sinfo.end - 1;
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400398 *end = '\0';
Kevin O'Connor2be312c2009-11-24 09:37:53 -0500399 return end - str;
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400400}
401
402
403/****************************************************************
404 * Misc helpers
405 ****************************************************************/
406
Kevin O'Connor1eba4292009-02-17 23:14:25 -0500407void
Kevin O'Connor114592f2009-09-28 21:32:08 -0400408hexdump(const void *d, int len)
Kevin O'Connor1eba4292009-02-17 23:14:25 -0500409{
410 int count=0;
Kevin O'Connor114592f2009-09-28 21:32:08 -0400411 while (len > 0) {
Kevin O'Connor1eba4292009-02-17 23:14:25 -0500412 if (count % 8 == 0) {
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400413 putc(&debuginfo, '\n');
414 puthex(&debuginfo, count*4, 8);
415 putc(&debuginfo, ':');
Kevin O'Connor1eba4292009-02-17 23:14:25 -0500416 } else {
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400417 putc(&debuginfo, ' ');
Kevin O'Connor1eba4292009-02-17 23:14:25 -0500418 }
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400419 puthex(&debuginfo, *(u32*)d, 8);
Kevin O'Connor1eba4292009-02-17 23:14:25 -0500420 count++;
421 len-=4;
422 d+=4;
423 }
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400424 putc(&debuginfo, '\n');
Kevin O'Connor3e832bb2009-05-15 22:22:12 -0400425 debug_serial_flush();
Kevin O'Connor1eba4292009-02-17 23:14:25 -0500426}
427
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500428static void
Kevin O'Connora68aeaf2008-07-07 21:37:10 -0400429dump_regs(struct bregs *regs)
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500430{
431 if (!regs) {
Kevin O'Connora68aeaf2008-07-07 21:37:10 -0400432 dprintf(1, " NULL\n");
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500433 return;
434 }
Kevin O'Connor7da210c2009-05-16 23:57:08 -0400435 dprintf(1, " a=%08x b=%08x c=%08x d=%08x ds=%04x es=%04x ss=%04x\n"
Kevin O'Connora68aeaf2008-07-07 21:37:10 -0400436 , regs->eax, regs->ebx, regs->ecx, regs->edx
Kevin O'Connor7da210c2009-05-16 23:57:08 -0400437 , regs->ds, regs->es, GET_SEG(SS));
Kevin O'Connorf513c912009-05-27 22:27:10 -0400438 dprintf(1, " si=%08x di=%08x bp=%08x sp=%08x cs=%04x ip=%04x f=%04x\n"
439 , regs->esi, regs->edi, regs->ebp, (u32)&regs[1]
Kevin O'Connor9f985422009-09-09 11:34:39 -0400440 , regs->code.seg, regs->code.offset, regs->flags);
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500441}
442
Kevin O'Connor05600342009-01-02 13:10:58 -0500443// Report entry to an Interrupt Service Routine (ISR).
Kevin O'Connorc65a3802008-03-02 13:58:23 -0500444void
Kevin O'Connored128492008-03-11 11:14:59 -0400445__debug_isr(const char *fname)
Kevin O'Connorc65a3802008-03-02 13:58:23 -0500446{
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400447 puts_cs(&debuginfo, fname);
448 putc(&debuginfo, '\n');
Kevin O'Connor3e832bb2009-05-15 22:22:12 -0400449 debug_serial_flush();
Kevin O'Connorc65a3802008-03-02 13:58:23 -0500450}
451
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500452// Function called on handler startup.
453void
Kevin O'Connor05600342009-01-02 13:10:58 -0500454__debug_enter(struct bregs *regs, const char *fname)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500455{
Kevin O'Connora68aeaf2008-07-07 21:37:10 -0400456 dprintf(1, "enter %s:\n", fname);
457 dump_regs(regs);
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500458}
459
Kevin O'Connor05600342009-01-02 13:10:58 -0500460// Send debugging output info.
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500461void
Kevin O'Connor05600342009-01-02 13:10:58 -0500462__debug_stub(struct bregs *regs, int lineno, const char *fname)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500463{
Kevin O'Connora68aeaf2008-07-07 21:37:10 -0400464 dprintf(1, "stub %s:%d:\n", fname, lineno);
465 dump_regs(regs);
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500466}
Kevin O'Connor4ce6a492008-02-29 00:21:27 -0500467
Kevin O'Connordfefeb52009-12-13 13:04:17 -0500468// Report on an invalid parameter.
Kevin O'Connor4ce6a492008-02-29 00:21:27 -0500469void
Kevin O'Connordfefeb52009-12-13 13:04:17 -0500470__warn_invalid(struct bregs *regs, int lineno, const char *fname)
Kevin O'Connor4ce6a492008-02-29 00:21:27 -0500471{
Kevin O'Connordfefeb52009-12-13 13:04:17 -0500472 if (CONFIG_DEBUG_LEVEL >= DEBUG_invalid) {
473 dprintf(1, "invalid %s:%d:\n", fname, lineno);
474 dump_regs(regs);
475 }
Kevin O'Connora68aeaf2008-07-07 21:37:10 -0400476}
477
Kevin O'Connordfefeb52009-12-13 13:04:17 -0500478// Report on an unimplemented feature.
Kevin O'Connora68aeaf2008-07-07 21:37:10 -0400479void
Kevin O'Connordfefeb52009-12-13 13:04:17 -0500480__warn_unimplemented(struct bregs *regs, int lineno, const char *fname)
481{
482 if (CONFIG_DEBUG_LEVEL >= DEBUG_unimplemented) {
483 dprintf(1, "unimplemented %s:%d:\n", fname, lineno);
484 dump_regs(regs);
485 }
486}
487
Kevin O'Connorcfdc13f2010-02-14 13:07:54 -0500488// Report on an allocation failure.
489void
490__warn_noalloc(int lineno, const char *fname)
491{
492 dprintf(1, "WARNING - Unable to allocate resource at %s:%d!\n"
493 , fname, lineno);
494}
495
496// Report on a timeout exceeded.
497void
498__warn_timeout(int lineno, const char *fname)
499{
500 dprintf(1, "WARNING - Timeout at %s:%d!\n", fname, lineno);
501}
502
Kevin O'Connordfefeb52009-12-13 13:04:17 -0500503// Report a handler reporting an invalid parameter to the caller.
504void
505__set_invalid(struct bregs *regs, int lineno, const char *fname)
506{
507 __warn_invalid(regs, lineno, fname);
508 set_invalid_silent(regs);
509}
510
511// Report a call of an unimplemented function.
512void
513__set_unimplemented(struct bregs *regs, int lineno, const char *fname)
514{
515 __warn_unimplemented(regs, lineno, fname);
516 set_invalid_silent(regs);
517}
518
519// Report a handler reporting an invalid parameter code to the
520// caller. Note, the lineno and return code are encoded in the same
521// parameter as gcc does a better job of scheduling function calls
522// when there are 3 or less parameters.
523void
524__set_code_invalid(struct bregs *regs, u32 linecode, const char *fname)
Kevin O'Connora68aeaf2008-07-07 21:37:10 -0400525{
Kevin O'Connor05600342009-01-02 13:10:58 -0500526 u8 code = linecode;
527 u32 lineno = linecode >> 8;
Kevin O'Connordfefeb52009-12-13 13:04:17 -0500528 __warn_invalid(regs, lineno, fname);
529 set_code_invalid_silent(regs, code);
530}
531
532// Report a call of an unimplemented function.
533void
534__set_code_unimplemented(struct bregs *regs, u32 linecode, const char *fname)
535{
536 u8 code = linecode;
537 u32 lineno = linecode >> 8;
538 __warn_unimplemented(regs, lineno, fname);
539 set_code_invalid_silent(regs, code);
Kevin O'Connor4ce6a492008-02-29 00:21:27 -0500540}