blob: 936d3d8582e7e56693e8b3ba7fc00f609ee2ee14 [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'Connor1d7d8932010-06-19 12:05:57 -0400198puthex(struct putcinfo *action, u32 val, int width, int spacepad)
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;
Kevin O'Connor1d7d8932010-06-19 12:05:57 -0400203 while (tmp >>= 4)
204 width++;
205 } else if (spacepad) {
206 u32 tmp = val;
207 u32 count = 1;
208 while (tmp >>= 4)
209 count++;
210 if (width > count) {
211 count = width - count;
212 width -= count;
213 while (count--)
214 putc(action, ' ');
Kevin O'Connor91b53a72009-05-05 22:52:09 -0400215 }
Kevin O'Connor91b53a72009-05-05 22:52:09 -0400216 }
217
218 switch (width) {
219 default: putsinglehex(action, (val >> 28) & 0xf);
220 case 7: putsinglehex(action, (val >> 24) & 0xf);
221 case 6: putsinglehex(action, (val >> 20) & 0xf);
222 case 5: putsinglehex(action, (val >> 16) & 0xf);
223 case 4: putsinglehex(action, (val >> 12) & 0xf);
224 case 3: putsinglehex(action, (val >> 8) & 0xf);
225 case 2: putsinglehex(action, (val >> 4) & 0xf);
226 case 1: putsinglehex(action, (val >> 0) & 0xf);
227 }
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500228}
229
Kevin O'Connor7d0f08a2008-03-04 22:27:55 -0500230static inline int
231isdigit(u8 c)
232{
Kevin O'Connord6e4b4c2008-08-29 21:20:32 -0400233 return ((u8)(c - '0')) < 10;
Kevin O'Connor7d0f08a2008-03-04 22:27:55 -0500234}
235
Kevin O'Connor567e4e32008-04-05 11:37:51 -0400236static void
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400237bvprintf(struct putcinfo *action, const char *fmt, va_list args)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500238{
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500239 const char *s = fmt;
240 for (;; s++) {
Kevin O'Connor15157a32008-12-13 11:10:37 -0500241 char c = GET_GLOBAL(*(u8*)s);
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500242 if (!c)
243 break;
244 if (c != '%') {
245 putc(action, c);
246 continue;
247 }
248 const char *n = s+1;
Kevin O'Connor91b53a72009-05-05 22:52:09 -0400249 int field_width = 0;
Kevin O'Connor1d7d8932010-06-19 12:05:57 -0400250 int spacepad = 1;
Kevin O'Connor7d0f08a2008-03-04 22:27:55 -0500251 for (;;) {
Kevin O'Connor15157a32008-12-13 11:10:37 -0500252 c = GET_GLOBAL(*(u8*)n);
Kevin O'Connor7d0f08a2008-03-04 22:27:55 -0500253 if (!isdigit(c))
254 break;
Kevin O'Connor1d7d8932010-06-19 12:05:57 -0400255 if (!field_width && (c == '0'))
256 spacepad = 0;
257 else
258 field_width = field_width * 10 + c - '0';
Kevin O'Connor7d0f08a2008-03-04 22:27:55 -0500259 n++;
260 }
Kevin O'Connora9096f42008-03-08 15:40:43 -0500261 if (c == 'l') {
262 // Ignore long format indicator
263 n++;
Kevin O'Connor15157a32008-12-13 11:10:37 -0500264 c = GET_GLOBAL(*(u8*)n);
Kevin O'Connora9096f42008-03-08 15:40:43 -0500265 }
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500266 s32 val;
267 const char *sarg;
268 switch (c) {
269 case '%':
270 putc(action, '%');
271 break;
272 case 'd':
273 val = va_arg(args, s32);
274 if (val < 0) {
275 putc(action, '-');
276 val = -val;
277 }
278 putuint(action, val);
279 break;
280 case 'u':
281 val = va_arg(args, s32);
282 putuint(action, val);
283 break;
Kevin O'Connorf06f03a2008-03-29 12:44:32 -0400284 case 'p':
Kevin O'Connor91b53a72009-05-05 22:52:09 -0400285 /* %p always has 0x prepended */
286 putc(action, '0');
287 putc(action, 'x');
288 field_width = 8;
Kevin O'Connor1d7d8932010-06-19 12:05:57 -0400289 spacepad = 0;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500290 case 'x':
291 val = va_arg(args, s32);
Kevin O'Connor1d7d8932010-06-19 12:05:57 -0400292 puthex(action, val, field_width, spacepad);
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500293 break;
Kevin O'Connor12dade52008-03-01 13:35:17 -0500294 case 'c':
295 val = va_arg(args, int);
296 putc(action, val);
297 break;
Kevin O'Connore0113c92008-04-05 15:51:12 -0400298 case '.':
299 // Hack to support "%.s" - meaning string on stack.
Kevin O'Connor15157a32008-12-13 11:10:37 -0500300 if (GET_GLOBAL(*(u8*)(n+1)) != 's')
Kevin O'Connore0113c92008-04-05 15:51:12 -0400301 break;
302 n++;
303 sarg = va_arg(args, const char *);
304 puts(action, sarg);
305 break;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500306 case 's':
307 sarg = va_arg(args, const char *);
308 puts_cs(action, sarg);
309 break;
310 default:
Kevin O'Connor4ce6a492008-02-29 00:21:27 -0500311 putc(action, '%');
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500312 n = s;
313 }
314 s = n;
315 }
Kevin O'Connor567e4e32008-04-05 11:37:51 -0400316}
317
318void
Kevin O'Connore07e18e2009-02-08 17:07:29 -0500319panic(const char *fmt, ...)
Kevin O'Connor567e4e32008-04-05 11:37:51 -0400320{
Kevin O'Connor79cb1192008-07-21 23:29:33 -0400321 if (CONFIG_DEBUG_LEVEL) {
322 va_list args;
323 va_start(args, fmt);
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400324 bvprintf(&debuginfo, fmt, args);
Kevin O'Connor79cb1192008-07-21 23:29:33 -0400325 va_end(args);
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400326 debug_serial_flush();
Kevin O'Connor79cb1192008-07-21 23:29:33 -0400327 }
Kevin O'Connor567e4e32008-04-05 11:37:51 -0400328
329 // XXX - use PANIC PORT.
330 irq_disable();
331 for (;;)
332 hlt();
333}
334
335void
Kevin O'Connorac8df8c2008-05-24 23:46:33 -0400336__dprintf(const char *fmt, ...)
Kevin O'Connor567e4e32008-04-05 11:37:51 -0400337{
Kevin O'Connor52a300f2009-12-26 23:32:57 -0500338 if (!MODESEGMENT && CONFIG_THREADS && CONFIG_DEBUG_LEVEL >= DEBUG_thread
Kevin O'Connorc604f2f2009-10-24 19:56:11 -0400339 && *fmt != '\\' && *fmt != '/') {
340 struct thread_info *cur = getCurThread();
341 if (cur != &MainThread) {
342 // Show "thread id" for this debug message.
343 putc_debug(&debuginfo, '|');
Kevin O'Connor1d7d8932010-06-19 12:05:57 -0400344 puthex(&debuginfo, (u32)cur, 8, 0);
Kevin O'Connorc604f2f2009-10-24 19:56:11 -0400345 putc_debug(&debuginfo, '|');
346 putc_debug(&debuginfo, ' ');
347 }
348 }
349
Kevin O'Connor567e4e32008-04-05 11:37:51 -0400350 va_list args;
351 va_start(args, fmt);
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400352 bvprintf(&debuginfo, fmt, args);
Kevin O'Connor567e4e32008-04-05 11:37:51 -0400353 va_end(args);
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400354 debug_serial_flush();
Kevin O'Connor567e4e32008-04-05 11:37:51 -0400355}
356
357void
358printf(const char *fmt, ...)
359{
Kevin O'Connor52a300f2009-12-26 23:32:57 -0500360 ASSERT32FLAT();
Kevin O'Connor567e4e32008-04-05 11:37:51 -0400361 va_list args;
362 va_start(args, fmt);
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400363 bvprintf(&screeninfo, fmt, args);
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500364 va_end(args);
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400365 if (CONFIG_SCREEN_AND_DEBUG)
366 debug_serial_flush();
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500367}
368
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400369
370/****************************************************************
371 * snprintf
372 ****************************************************************/
373
374struct snprintfinfo {
375 struct putcinfo info;
376 char *str, *end;
377};
378
379static void
380putc_str(struct putcinfo *info, char c)
381{
382 struct snprintfinfo *sinfo = container_of(info, struct snprintfinfo, info);
383 if (sinfo->str >= sinfo->end)
384 return;
385 *sinfo->str = c;
386 sinfo->str++;
387}
388
Kevin O'Connor2be312c2009-11-24 09:37:53 -0500389// Build a formatted string. Note, this function returns the actual
390// number of bytes used (not including null) even in the overflow
391// case.
392int
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400393snprintf(char *str, size_t size, const char *fmt, ...)
394{
Kevin O'Connor52a300f2009-12-26 23:32:57 -0500395 ASSERT32FLAT();
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400396 if (!size)
Kevin O'Connor2be312c2009-11-24 09:37:53 -0500397 return 0;
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400398 struct snprintfinfo sinfo = { { putc_str }, str, str + size };
399 va_list args;
400 va_start(args, fmt);
401 bvprintf(&sinfo.info, fmt, args);
402 va_end(args);
403 char *end = sinfo.str;
404 if (end >= sinfo.end)
Kevin O'Connor2be312c2009-11-24 09:37:53 -0500405 end = sinfo.end - 1;
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400406 *end = '\0';
Kevin O'Connor2be312c2009-11-24 09:37:53 -0500407 return end - str;
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400408}
409
410
411/****************************************************************
412 * Misc helpers
413 ****************************************************************/
414
Kevin O'Connor1eba4292009-02-17 23:14:25 -0500415void
Kevin O'Connor114592f2009-09-28 21:32:08 -0400416hexdump(const void *d, int len)
Kevin O'Connor1eba4292009-02-17 23:14:25 -0500417{
418 int count=0;
Kevin O'Connor114592f2009-09-28 21:32:08 -0400419 while (len > 0) {
Kevin O'Connor1eba4292009-02-17 23:14:25 -0500420 if (count % 8 == 0) {
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400421 putc(&debuginfo, '\n');
Kevin O'Connor1d7d8932010-06-19 12:05:57 -0400422 puthex(&debuginfo, count*4, 8, 0);
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400423 putc(&debuginfo, ':');
Kevin O'Connor1eba4292009-02-17 23:14:25 -0500424 } else {
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400425 putc(&debuginfo, ' ');
Kevin O'Connor1eba4292009-02-17 23:14:25 -0500426 }
Kevin O'Connor1d7d8932010-06-19 12:05:57 -0400427 puthex(&debuginfo, *(u32*)d, 8, 0);
Kevin O'Connor1eba4292009-02-17 23:14:25 -0500428 count++;
429 len-=4;
430 d+=4;
431 }
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400432 putc(&debuginfo, '\n');
Kevin O'Connor3e832bb2009-05-15 22:22:12 -0400433 debug_serial_flush();
Kevin O'Connor1eba4292009-02-17 23:14:25 -0500434}
435
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500436static void
Kevin O'Connora68aeaf2008-07-07 21:37:10 -0400437dump_regs(struct bregs *regs)
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500438{
439 if (!regs) {
Kevin O'Connora68aeaf2008-07-07 21:37:10 -0400440 dprintf(1, " NULL\n");
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500441 return;
442 }
Kevin O'Connor7da210c2009-05-16 23:57:08 -0400443 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 -0400444 , regs->eax, regs->ebx, regs->ecx, regs->edx
Kevin O'Connor7da210c2009-05-16 23:57:08 -0400445 , regs->ds, regs->es, GET_SEG(SS));
Kevin O'Connorf513c912009-05-27 22:27:10 -0400446 dprintf(1, " si=%08x di=%08x bp=%08x sp=%08x cs=%04x ip=%04x f=%04x\n"
447 , regs->esi, regs->edi, regs->ebp, (u32)&regs[1]
Kevin O'Connor9f985422009-09-09 11:34:39 -0400448 , regs->code.seg, regs->code.offset, regs->flags);
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500449}
450
Kevin O'Connor05600342009-01-02 13:10:58 -0500451// Report entry to an Interrupt Service Routine (ISR).
Kevin O'Connorc65a3802008-03-02 13:58:23 -0500452void
Kevin O'Connored128492008-03-11 11:14:59 -0400453__debug_isr(const char *fname)
Kevin O'Connorc65a3802008-03-02 13:58:23 -0500454{
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400455 puts_cs(&debuginfo, fname);
456 putc(&debuginfo, '\n');
Kevin O'Connor3e832bb2009-05-15 22:22:12 -0400457 debug_serial_flush();
Kevin O'Connorc65a3802008-03-02 13:58:23 -0500458}
459
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500460// Function called on handler startup.
461void
Kevin O'Connor05600342009-01-02 13:10:58 -0500462__debug_enter(struct bregs *regs, const char *fname)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500463{
Kevin O'Connora68aeaf2008-07-07 21:37:10 -0400464 dprintf(1, "enter %s:\n", fname);
465 dump_regs(regs);
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500466}
467
Kevin O'Connor05600342009-01-02 13:10:58 -0500468// Send debugging output info.
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500469void
Kevin O'Connor05600342009-01-02 13:10:58 -0500470__debug_stub(struct bregs *regs, int lineno, const char *fname)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500471{
Kevin O'Connora68aeaf2008-07-07 21:37:10 -0400472 dprintf(1, "stub %s:%d:\n", fname, lineno);
473 dump_regs(regs);
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500474}
Kevin O'Connor4ce6a492008-02-29 00:21:27 -0500475
Kevin O'Connordfefeb52009-12-13 13:04:17 -0500476// Report on an invalid parameter.
Kevin O'Connor4ce6a492008-02-29 00:21:27 -0500477void
Kevin O'Connordfefeb52009-12-13 13:04:17 -0500478__warn_invalid(struct bregs *regs, int lineno, const char *fname)
Kevin O'Connor4ce6a492008-02-29 00:21:27 -0500479{
Kevin O'Connordfefeb52009-12-13 13:04:17 -0500480 if (CONFIG_DEBUG_LEVEL >= DEBUG_invalid) {
481 dprintf(1, "invalid %s:%d:\n", fname, lineno);
482 dump_regs(regs);
483 }
Kevin O'Connora68aeaf2008-07-07 21:37:10 -0400484}
485
Kevin O'Connordfefeb52009-12-13 13:04:17 -0500486// Report on an unimplemented feature.
Kevin O'Connora68aeaf2008-07-07 21:37:10 -0400487void
Kevin O'Connordfefeb52009-12-13 13:04:17 -0500488__warn_unimplemented(struct bregs *regs, int lineno, const char *fname)
489{
490 if (CONFIG_DEBUG_LEVEL >= DEBUG_unimplemented) {
491 dprintf(1, "unimplemented %s:%d:\n", fname, lineno);
492 dump_regs(regs);
493 }
494}
495
Kevin O'Connor7fb8ba82010-02-26 08:45:00 -0500496// Report a detected internal inconsistency.
497void
498__warn_internalerror(int lineno, const char *fname)
499{
500 dprintf(1, "WARNING - internal error detected at %s:%d!\n"
501 , fname, lineno);
502}
503
Kevin O'Connorcfdc13f2010-02-14 13:07:54 -0500504// Report on an allocation failure.
505void
506__warn_noalloc(int lineno, const char *fname)
507{
508 dprintf(1, "WARNING - Unable to allocate resource at %s:%d!\n"
509 , fname, lineno);
510}
511
512// Report on a timeout exceeded.
513void
514__warn_timeout(int lineno, const char *fname)
515{
516 dprintf(1, "WARNING - Timeout at %s:%d!\n", fname, lineno);
517}
518
Kevin O'Connordfefeb52009-12-13 13:04:17 -0500519// Report a handler reporting an invalid parameter to the caller.
520void
521__set_invalid(struct bregs *regs, int lineno, const char *fname)
522{
523 __warn_invalid(regs, lineno, fname);
524 set_invalid_silent(regs);
525}
526
527// Report a call of an unimplemented function.
528void
529__set_unimplemented(struct bregs *regs, int lineno, const char *fname)
530{
531 __warn_unimplemented(regs, lineno, fname);
532 set_invalid_silent(regs);
533}
534
535// Report a handler reporting an invalid parameter code to the
536// caller. Note, the lineno and return code are encoded in the same
537// parameter as gcc does a better job of scheduling function calls
538// when there are 3 or less parameters.
539void
540__set_code_invalid(struct bregs *regs, u32 linecode, const char *fname)
Kevin O'Connora68aeaf2008-07-07 21:37:10 -0400541{
Kevin O'Connor05600342009-01-02 13:10:58 -0500542 u8 code = linecode;
543 u32 lineno = linecode >> 8;
Kevin O'Connordfefeb52009-12-13 13:04:17 -0500544 __warn_invalid(regs, lineno, fname);
545 set_code_invalid_silent(regs, code);
546}
547
548// Report a call of an unimplemented function.
549void
550__set_code_unimplemented(struct bregs *regs, u32 linecode, const char *fname)
551{
552 u8 code = linecode;
553 u32 lineno = linecode >> 8;
554 __warn_unimplemented(regs, lineno, fname);
555 set_code_invalid_silent(regs, code);
Kevin O'Connor4ce6a492008-02-29 00:21:27 -0500556}