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.

console.h 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #ifndef _IPXE_CONSOLE_H
  2. #define _IPXE_CONSOLE_H
  3. #include <stdio.h>
  4. #include <ipxe/tables.h>
  5. /** @file
  6. *
  7. * User interaction.
  8. *
  9. * Various console devices can be selected via the build options
  10. * CONSOLE_FIRMWARE, CONSOLE_SERIAL etc. The console functions
  11. * putchar(), getchar() and iskey() delegate to the individual console
  12. * drivers.
  13. *
  14. */
  15. FILE_LICENCE ( GPL2_OR_LATER );
  16. /**
  17. * A console driver
  18. *
  19. * Defines the functions that implement a particular console type.
  20. * Must be made part of the console drivers table by using
  21. * #__console_driver.
  22. *
  23. * @note Consoles that cannot be used before their initialisation
  24. * function has completed should set #disabled=1 initially. This
  25. * allows other console devices to still be used to print out early
  26. * debugging messages.
  27. *
  28. */
  29. struct console_driver {
  30. /** Console is disabled.
  31. *
  32. * The console's putchar(), getchar() and iskey() methods will
  33. * not be called while #disabled==1. Typically the console's
  34. * initialisation functions will set #disabled=0 upon
  35. * completion.
  36. *
  37. */
  38. int disabled;
  39. /** Write a character to the console.
  40. *
  41. * @v character Character to be written
  42. * @ret None -
  43. * @err None -
  44. *
  45. */
  46. void ( *putchar ) ( int character );
  47. /** Read a character from the console.
  48. *
  49. * @v None -
  50. * @ret character Character read
  51. * @err None -
  52. *
  53. * If no character is available to be read, this method will
  54. * block. The character read should not be echoed back to the
  55. * console.
  56. *
  57. */
  58. int ( *getchar ) ( void );
  59. /** Check for available input.
  60. *
  61. * @v None -
  62. * @ret True Input is available
  63. * @ret False Input is not available
  64. * @err None -
  65. *
  66. * This should return True if a subsequent call to getchar()
  67. * will not block.
  68. *
  69. */
  70. int ( *iskey ) ( void );
  71. /** Console usage bitmask
  72. *
  73. * This is the bitwise OR of zero or more @c CONSOLE_USAGE_XXX
  74. * values.
  75. */
  76. int usage;
  77. };
  78. /** Console driver table */
  79. #define CONSOLES __table ( struct console_driver, "consoles" )
  80. /**
  81. * Mark a <tt> struct console_driver </tt> as being part of the
  82. * console drivers table.
  83. *
  84. * Use as e.g.
  85. *
  86. * @code
  87. *
  88. * struct console_driver my_console __console_driver = {
  89. * .putchar = my_putchar,
  90. * .getchar = my_getchar,
  91. * .iskey = my_iskey,
  92. * };
  93. *
  94. * @endcode
  95. *
  96. */
  97. #define __console_driver __table_entry ( CONSOLES, 01 )
  98. /**
  99. * @defgroup consoleusage Console usages
  100. * @{
  101. */
  102. /** Standard output */
  103. #define CONSOLE_USAGE_STDOUT 0x0001
  104. /** Debug messages */
  105. #define CONSOLE_USAGE_DEBUG 0x0002
  106. /** All console usages */
  107. #define CONSOLE_USAGE_ALL ( CONSOLE_USAGE_STDOUT | CONSOLE_USAGE_DEBUG )
  108. /** @} */
  109. /**
  110. * Test to see if console has an explicit usage
  111. *
  112. * @v console Console definition (e.g. CONSOLE_PCBIOS)
  113. * @ret explicit Console has an explicit usage
  114. *
  115. * This relies upon the trick that the expression ( 2 * N + 1 ) will
  116. * be valid even if N is defined to be empty, since it will then
  117. * evaluate to give ( 2 * + 1 ) == ( 2 * +1 ) == 2.
  118. */
  119. #define CONSOLE_EXPLICIT( console ) ( ( 2 * console + 1 ) != 2 )
  120. extern int console_usage;
  121. /**
  122. * Set console usage
  123. *
  124. * @v usage New console usage
  125. * @ret old_usage Previous console usage
  126. */
  127. static inline __attribute__ (( always_inline )) int
  128. console_set_usage ( int usage ) {
  129. int old_usage = console_usage;
  130. console_usage = usage;
  131. return old_usage;
  132. }
  133. extern int iskey ( void );
  134. extern int getkey ( unsigned long timeout );
  135. #endif /* _IPXE_CONSOLE_H */