[BACK]Return to diag.c CVS log [TXT][DIR] Up to [local] / prex-old / sys / arch / i386 / pc

Annotation of prex-old/sys/arch/i386/pc/diag.c, Revision 1.1.1.1

1.1       nbrk        1: /*-
                      2:  * Copyright (c) 2005-2007, 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:  * diag.c - diagnostic message support
                     32:  */
                     33:
                     34: #include <kernel.h>
                     35: #include <page.h>
                     36: #include <cpu.h>
                     37:
                     38: #ifdef DEBUG
                     39: #ifdef CONFIG_DIAG_SCREEN
                     40:
                     41: #define VID_ATTR       0x0F00
                     42: #define VID_PORT       0x03d4
                     43: #define VID_RAM                0xB8000
                     44:
                     45: /* Screen info */
                     46: static short *vram;
                     47: static int pos_x;
                     48: static int pos_y;
                     49: static int screen_x;
                     50: static int screen_y;
                     51:
                     52: static void
                     53: screen_scrollup(void)
                     54: {
                     55:        int i;
                     56:
                     57:        memcpy(vram, vram + screen_x, screen_x * (screen_y - 1) * 2);
                     58:        for (i = 0; i < screen_x; i++)
                     59:                vram[screen_x * (screen_y - 1) + i] = ' ';
                     60: }
                     61:
                     62: static void
                     63: screen_update(void)
                     64: {
                     65:        int pos = pos_y * screen_x + pos_x;
                     66:
                     67:        outb(0x0e, VID_PORT);
                     68:        outb(pos >> 8, VID_PORT + 1);
                     69:
                     70:        outb(0x0f, VID_PORT);
                     71:        outb(pos & 0xff, VID_PORT + 1);
                     72: }
                     73:
                     74: static void
                     75: screen_newline(void)
                     76: {
                     77:
                     78:        pos_x = 0;
                     79:        pos_y++;
                     80:        if (pos_y >= screen_y) {
                     81:                pos_y = screen_y - 1;
                     82:                screen_scrollup();
                     83:        }
                     84:        screen_update();
                     85: }
                     86:
                     87: static void
                     88: screen_putchar(char c)
                     89: {
                     90:
                     91:        switch (c) {
                     92:        case '\n':
                     93:                screen_newline();
                     94:                return;
                     95:        case '\r':
                     96:                pos_x = 0;
                     97:                screen_update();
                     98:                return;
                     99:        case '\b':
                    100:                if (pos_x == 0)
                    101:                        return;
                    102:                pos_x--;
                    103:                screen_update();
                    104:                return;
                    105:        }
                    106:        vram[pos_y * screen_x + pos_x] = c | VID_ATTR;
                    107:        pos_x++;
                    108:        if (pos_x >= screen_x) {
                    109:                pos_x = 0;
                    110:                pos_y++;
                    111:                if (pos_y >= screen_y) {
                    112:                        pos_y = screen_y - 1;
                    113:                        screen_scrollup();
                    114:                }
                    115:        }
                    116:        screen_update();
                    117: }
                    118:
                    119: static int
                    120: screen_init(void)
                    121: {
                    122:
                    123:        vram = (short *)phys_to_virt(VID_RAM);
                    124:        pos_x = 0;
                    125:        pos_y = 0;
                    126:        screen_x = boot_info->video.text_x;
                    127:        screen_y = boot_info->video.text_y;
                    128:        return 0;
                    129: }
                    130: #endif /* CONFIG_DIAG_SCREEN */
                    131:
                    132:
                    133: #ifdef CONFIG_DIAG_BOCHS
                    134: static void
                    135: bochs_putchar(char c)
                    136: {
                    137:        /*
                    138:         * Bochs debug port
                    139:         */
                    140:        if (inb(0xe9) == 0xe9)
                    141:                outb(c, 0xe9);
                    142: }
                    143: #endif /* CONFIG_DIAG_BOCHS */
                    144:
                    145: void
                    146: diag_print(char *buf)
                    147: {
                    148:
                    149:        while (*buf) {
                    150: #ifdef CONFIG_DIAG_SCREEN
                    151:                screen_putchar(*buf);
                    152: #endif
                    153: #ifdef CONFIG_DIAG_BOCHS
                    154:                bochs_putchar(*buf);
                    155: #endif
                    156:                ++buf;
                    157:        }
                    158: }
                    159: #endif /* DEBUG */
                    160:
                    161: void
                    162: diag_init(void)
                    163: {
                    164: #if defined(DEBUG) && defined(CONFIG_DIAG_SCREEN)
                    165:        screen_init();
                    166: #endif
                    167: }

CVSweb