You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

bios_console.c 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Copyright (C) 2006 Michael Brown <mbrown@fensystems.co.uk>.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. #include <realmode.h>
  19. #include <console.h>
  20. /**
  21. * Print a character to BIOS console
  22. *
  23. * @v character Character to be printed
  24. */
  25. static void bios_putchar ( int character ) {
  26. __asm__ __volatile__ ( REAL_CODE ( "sti\n\t"
  27. "int $0x10\n\t"
  28. "cli\n\t" )
  29. : : "a" ( character | 0x0e00 ), "b" ( 1 )
  30. : "ebp" );
  31. }
  32. /**
  33. * Get character from BIOS console
  34. *
  35. * @ret character Character read from console
  36. */
  37. static int bios_getchar ( void ) {
  38. uint8_t character;
  39. __asm__ __volatile__ ( REAL_CODE ( "sti\n\t"
  40. "int $0x16\n\t"
  41. "cli\n\t" )
  42. : "=a" ( character ) : "a" ( 0x0000 ) );
  43. return character;
  44. }
  45. /**
  46. * Check for character ready to read from BIOS console
  47. *
  48. * @ret True Character available to read
  49. * @ret False No character available to read
  50. */
  51. static int bios_iskey ( void ) {
  52. unsigned int discard_a;
  53. unsigned int flags;
  54. __asm__ __volatile__ ( REAL_CODE ( "sti\n\t"
  55. "int $0x16\n\t"
  56. "pushfw\n\t"
  57. "popw %w0\n\t"
  58. "cli\n\t" )
  59. : "=r" ( flags ), "=a" ( discard_a )
  60. : "a" ( 0x0100 ) );
  61. return ( ! ( flags & ZF ) );
  62. }
  63. struct console_driver bios_console __console_driver = {
  64. .putchar = bios_putchar,
  65. .getchar = bios_getchar,
  66. .iskey = bios_iskey,
  67. };