2006-05-24 13:24:22 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2006 Michael Brown <mbrown@fensystems.co.uk>.
|
2005-04-08 15:01:17 +00:00
|
|
|
*
|
2006-05-24 13:24:22 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
|
|
* License, or any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
2005-04-08 15:01:17 +00:00
|
|
|
*/
|
|
|
|
|
2006-05-24 13:24:22 +00:00
|
|
|
#include <realmode.h>
|
|
|
|
#include <console.h>
|
2005-04-08 15:01:17 +00:00
|
|
|
|
2006-05-24 13:24:22 +00:00
|
|
|
/**
|
|
|
|
* Print a character to BIOS console
|
|
|
|
*
|
|
|
|
* @v character Character to be printed
|
|
|
|
*/
|
2005-04-08 15:01:17 +00:00
|
|
|
static void bios_putchar ( int character ) {
|
|
|
|
|
2006-05-24 13:24:22 +00:00
|
|
|
__asm__ __volatile__ ( REAL_CODE ( "sti\n\t"
|
|
|
|
"int $0x10\n\t"
|
|
|
|
"cli\n\t" )
|
|
|
|
: : "a" ( character | 0x0e00 ), "b" ( 1 )
|
|
|
|
: "ebp" );
|
2005-04-08 15:01:17 +00:00
|
|
|
}
|
|
|
|
|
2006-05-24 13:24:22 +00:00
|
|
|
/**
|
|
|
|
* Get character from BIOS console
|
|
|
|
*
|
|
|
|
* @ret character Character read from console
|
|
|
|
*/
|
2005-04-08 15:01:17 +00:00
|
|
|
static int bios_getchar ( void ) {
|
2006-05-24 13:24:22 +00:00
|
|
|
uint8_t character;
|
2005-04-08 15:01:17 +00:00
|
|
|
|
2006-05-24 13:24:22 +00:00
|
|
|
__asm__ __volatile__ ( REAL_CODE ( "sti\n\t"
|
|
|
|
"int $0x16\n\t"
|
|
|
|
"cli\n\t" )
|
|
|
|
: "=a" ( character ) : "a" ( 0x0000 ) );
|
|
|
|
|
|
|
|
return character;
|
2005-04-08 15:01:17 +00:00
|
|
|
}
|
|
|
|
|
2006-05-24 13:24:22 +00:00
|
|
|
/**
|
|
|
|
* Check for character ready to read from BIOS console
|
|
|
|
*
|
|
|
|
* @ret True Character available to read
|
|
|
|
* @ret False No character available to read
|
|
|
|
*/
|
2005-04-08 15:01:17 +00:00
|
|
|
static int bios_iskey ( void ) {
|
2006-05-24 13:24:22 +00:00
|
|
|
unsigned int discard_a;
|
|
|
|
unsigned int flags;
|
2005-04-08 15:01:17 +00:00
|
|
|
|
2006-05-24 13:24:22 +00:00
|
|
|
__asm__ __volatile__ ( REAL_CODE ( "sti\n\t"
|
|
|
|
"int $0x16\n\t"
|
|
|
|
"pushfw\n\t"
|
|
|
|
"popw %w0\n\t"
|
|
|
|
"cli\n\t" )
|
|
|
|
: "=r" ( flags ), "=a" ( discard_a )
|
2006-05-25 00:00:53 +00:00
|
|
|
: "a" ( 0x0100 ) );
|
2005-04-08 15:01:17 +00:00
|
|
|
|
2006-05-24 13:24:22 +00:00
|
|
|
return ( ! ( flags & ZF ) );
|
2005-04-08 15:01:17 +00:00
|
|
|
}
|
|
|
|
|
2006-04-24 18:31:37 +00:00
|
|
|
struct console_driver bios_console __console_driver = {
|
2005-04-08 15:01:17 +00:00
|
|
|
.putchar = bios_putchar,
|
|
|
|
.getchar = bios_getchar,
|
|
|
|
.iskey = bios_iskey,
|
|
|
|
};
|