iPXE
debugcon.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License as
00006  * published by the Free Software Foundation; either version 2 of the
00007  * License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017  * 02110-1301, USA.
00018  *
00019  * You can also choose to distribute this program under the terms of
00020  * the Unmodified Binary Distribution Licence (as given in the file
00021  * COPYING.UBDL), provided that you have satisfied its requirements.
00022  */
00023 
00024 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00025 
00026 /** @file
00027  *
00028  * Debug port console
00029  *
00030  * The debug port is supported by bochs (via the "port_e9_hack"
00031  * configuration file directive) and by qemu (via the "-debugcon"
00032  * command-line option).
00033  */
00034 
00035 #include <stdint.h>
00036 #include <ipxe/io.h>
00037 #include <ipxe/console.h>
00038 #include <ipxe/init.h>
00039 #include <config/console.h>
00040 
00041 /** Debug port */
00042 #define DEBUG_PORT 0xe9
00043 
00044 /** Debug port installation check magic value */
00045 #define DEBUG_PORT_CHECK 0xe9
00046 
00047 /* Set default console usage if applicable */
00048 #if ! ( defined ( CONSOLE_DEBUGCON ) && CONSOLE_EXPLICIT ( CONSOLE_DEBUGCON ) )
00049 #undef CONSOLE_DEBUGCON
00050 #define CONSOLE_DEBUGCON ( CONSOLE_USAGE_ALL & ~CONSOLE_USAGE_TUI )
00051 #endif
00052 
00053 /**
00054  * Print a character to debug port console
00055  *
00056  * @v character         Character to be printed
00057  */
00058 static void debugcon_putchar ( int character ) {
00059 
00060         /* Write character to debug port */
00061         outb ( character, DEBUG_PORT );
00062 }
00063 
00064 /** Debug port console driver */
00065 struct console_driver debugcon_console __console_driver = {
00066         .putchar = debugcon_putchar,
00067         .usage = CONSOLE_DEBUGCON,
00068 };
00069 
00070 /**
00071  * Initialise debug port console
00072  *
00073  */
00074 static void debugcon_init ( void ) {
00075         uint8_t check;
00076 
00077         /* Check if console is present */
00078         check = inb ( DEBUG_PORT );
00079         if ( check != DEBUG_PORT_CHECK ) {
00080                 DBG ( "Debug port not present; disabling console\n" );
00081                 debugcon_console.disabled = CONSOLE_DISABLED;
00082         }
00083 }
00084 
00085 /**
00086  * Debug port console initialisation function
00087  */
00088 struct init_fn debugcon_init_fn __init_fn ( INIT_EARLY ) = {
00089         .initialise = debugcon_init,
00090 };