Prex Home / Browse Source - Prex Version: 0.9.0

root/bsp/boot/x86/pc/debug.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. debug_putc
  2. debug_init

   1 /*-
   2  * Copyright (c) 2005-2009, 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 #include <sys/param.h>
  31 #include <boot.h>
  32 
  33 extern void     outb(int, u_char);
  34 extern u_char   inb(int);
  35 
  36 #define SCREEN_80x25 1
  37 /* #define SCREEN_80x50 1 */
  38 
  39 #define COM_BASE        CONFIG_NS16550_BASE
  40 
  41 /* Register offsets */
  42 #define COM_RBR         (COM_BASE + 0x00)       /* receive buffer register */
  43 #define COM_THR         (COM_BASE + 0x00)       /* transmit holding register */
  44 #define COM_IER         (COM_BASE + 0x01)       /* interrupt enable register */
  45 #define COM_FCR         (COM_BASE + 0x02)       /* FIFO control register */
  46 #define COM_IIR         (COM_BASE + 0x02)       /* interrupt identification register */
  47 #define COM_LCR         (COM_BASE + 0x03)       /* line control register */
  48 #define COM_MCR         (COM_BASE + 0x04)       /* modem control register */
  49 #define COM_LSR         (COM_BASE + 0x05)       /* line status register */
  50 #define COM_MSR         (COM_BASE + 0x06)       /* modem status register */
  51 #define COM_DLL         (COM_BASE + 0x00)       /* divisor latch LSB (LCR[7] = 1) */
  52 #define COM_DLM         (COM_BASE + 0x01)       /* divisor latch MSB (LCR[7] = 1) */
  53 
  54 /*
  55  * Print one chracter
  56  */
  57 void
  58 debug_putc(int c)
  59 {
  60 
  61 #if defined(DEBUG) && defined(CONFIG_DIAG_SERIAL)
  62         /*
  63          * output to serial port.
  64          */
  65         while (!(inb(COM_LSR) & 0x20))
  66                 ;
  67         outb(COM_THR, c);
  68 #endif
  69 
  70 #if defined(DEBUG) && defined(CONFIG_DIAG_BOCHS)
  71         /*
  72          * output to bochs emulater console.
  73          */
  74         if (inb(0xe9) == 0xe9)
  75                 outb(0xe9, (u_char)c);
  76 #endif
  77 }
  78 
  79 /*
  80  * Initialize debug port.
  81  */
  82 void
  83 debug_init(void)
  84 {
  85 
  86 #if defined(DEBUG) && defined(CONFIG_DIAG_SERIAL)
  87         /*
  88          * Initialize serial port.
  89          */
  90         if (inb(COM_LSR) == 0xff)
  91                 return;         /* Serial port is disabled */
  92 
  93         outb(COM_IER, 0x00);    /* Disable interrupt */
  94         outb(COM_LCR, 0x80);    /* Access baud rate */
  95         outb(COM_DLL, 0x01);    /* 115200 baud */
  96         outb(COM_DLM, 0x00);
  97         outb(COM_LCR, 0x03);    /* N, 8, 1 */
  98         outb(COM_MCR, 0x03);    /* Ready */
  99         outb(COM_FCR, 0x00);    /* Disable FIFO */
 100         inb(COM_RBR);
 101         inb(COM_RBR);
 102 #endif
 103 }

/* [<][>][^][v][top][bottom][index][help] */