[BACK]Return to debug.c CVS log [TXT][DIR] Up to [local] / prex-old / boot / common

Annotation of prex-old/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: #include <prex/bootinfo.h>
        !            34: #include <platform.h>
        !            35: #include <boot.h>
        !            36:
        !            37: #undef printk
        !            38:
        !            39: /*
        !            40:  * printk - print formated string
        !            41:  */
        !            42: void
        !            43: printk(const char *fmt, ...)
        !            44: {
        !            45: #ifdef DEBUG
        !            46:        static const char digits[16] = "0123456789abcdef";
        !            47:        va_list ap;
        !            48:        char buf[10];
        !            49:        char *s;
        !            50:        unsigned r, u;
        !            51:        int c;
        !            52:
        !            53:        va_start(ap, fmt);
        !            54:        while ((c = *fmt++)) {
        !            55:                if (c == '%') {
        !            56:                        c = *fmt++;
        !            57:                        switch (c) {
        !            58:                        case 'c':
        !            59:                                putc(va_arg(ap, int));
        !            60:                                continue;
        !            61:                        case 's':
        !            62:                                for (s = va_arg(ap, char *); *s; s++)
        !            63:                                        putc((int)*s);
        !            64:                                continue;
        !            65:                        case 'u':
        !            66:                        case 'x':
        !            67:                                r = c == 'u' ? 10U : 16U;
        !            68:                                u = va_arg(ap, unsigned);
        !            69:                                s = buf;
        !            70:                                do
        !            71:                                        *s++ = digits[u % r];
        !            72:                                while (u /= r);
        !            73:                                while (--s >= buf)
        !            74:                                        putc((int)*s);
        !            75:                                continue;
        !            76:                        }
        !            77:                }
        !            78:                putc((int)c);
        !            79:        }
        !            80:        va_end(ap);
        !            81: #endif /* DEBUG */
        !            82: }
        !            83:
        !            84: /*
        !            85:  * Show error and hang up.
        !            86:  */
        !            87: void
        !            88: panic(const char *msg)
        !            89: {
        !            90:
        !            91:        printk("Panic: %s\n", msg);
        !            92:        for (;;);
        !            93: }

CVSweb