Annotation of prex/boot/common/debug.c, Revision 1.1
1.1 ! nbrk 1: /*-
! 2: * Copyright (c) 2005, Kohsuke Ohtani
! 3: * All rights reserved.
! 4: *
! 5: * Redistribution and use in source and binary forms, with or without
! 6: * modification, are permitted provided that the following conditions
! 7: * are met:
! 8: * 1. Redistributions of source code must retain the above copyright
! 9: * notice, this list of conditions and the following disclaimer.
! 10: * 2. Redistributions in binary form must reproduce the above copyright
! 11: * notice, this list of conditions and the following disclaimer in the
! 12: * documentation and/or other materials provided with the distribution.
! 13: * 3. Neither the name of the author nor the names of any co-contributors
! 14: * may be used to endorse or promote products derived from this software
! 15: * without specific prior written permission.
! 16: *
! 17: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
! 18: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
! 19: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
! 20: * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
! 21: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
! 22: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
! 23: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
! 24: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
! 25: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
! 26: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
! 27: * SUCH DAMAGE.
! 28: */
! 29:
! 30: /*
! 31: * debug.c - loader debug functions
! 32: */
! 33:
! 34: #include <prex/bootinfo.h>
! 35: #include <platform.h>
! 36: #include <boot.h>
! 37:
! 38: #ifdef DEBUG
! 39: /*
! 40: * printf - print formated string
! 41: */
! 42: void
! 43: printf(const char *fmt, ...)
! 44: {
! 45: static const char digits[] = "0123456789abcdef";
! 46: va_list ap;
! 47: char buf[10];
! 48: char *s;
! 49: unsigned r, u;
! 50: int c;
! 51:
! 52: va_start(ap, fmt);
! 53: while ((c = *fmt++)) {
! 54: if (c == '%') {
! 55: c = *fmt++;
! 56: switch (c) {
! 57: case 'c':
! 58: putchar(va_arg(ap, int));
! 59: continue;
! 60: case 's':
! 61: s = va_arg(ap, char *);
! 62: if (s == NULL)
! 63: s = "<NULL>";
! 64: for (; *s; s++) {
! 65: putchar((int)*s);
! 66: }
! 67: continue;
! 68: case 'u':
! 69: case 'x':
! 70: r = c == 'u' ? 10U : 16U;
! 71: u = va_arg(ap, unsigned);
! 72: s = buf;
! 73: do
! 74: *s++ = digits[u % r];
! 75: while (u /= r);
! 76: while (--s >= buf)
! 77: putchar((int)*s);
! 78: continue;
! 79: }
! 80: }
! 81: putchar((int)c);
! 82: }
! 83: va_end(ap);
! 84: }
! 85: #endif /* DEBUG */
! 86:
! 87: /*
! 88: * Show error and hang up.
! 89: */
! 90: void
! 91: panic(const char *msg)
! 92: {
! 93:
! 94: #ifdef DEBUG
! 95: printf("Panic: %s\n", msg);
! 96: #endif
! 97: machine_panic();
! 98: /* NOTREACHED */
! 99: }
CVSweb