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 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. #ifndef _IPXE_CONSOLE_H
  2. #define _IPXE_CONSOLE_H
  3. #include <stddef.h>
  4. #include <stdio.h>
  5. #include <ipxe/tables.h>
  6. /** @file
  7. *
  8. * User interaction.
  9. *
  10. * Various console devices can be selected via the build options
  11. * CONSOLE_FIRMWARE, CONSOLE_SERIAL etc. The console functions
  12. * putchar(), getchar() and iskey() delegate to the individual console
  13. * drivers.
  14. *
  15. */
  16. FILE_LICENCE ( GPL2_OR_LATER );
  17. struct pixel_buffer;
  18. /** A console configuration */
  19. struct console_configuration {
  20. /** Width */
  21. unsigned int width;
  22. /** Height */
  23. unsigned int height;
  24. /** Colour depth */
  25. unsigned int depth;
  26. /** Left margin */
  27. unsigned int left;
  28. /** Right margin */
  29. unsigned int right;
  30. /** Top margin */
  31. unsigned int top;
  32. /** Bottom margin */
  33. unsigned int bottom;
  34. /** Background picture, if any */
  35. struct pixel_buffer *pixbuf;
  36. };
  37. /**
  38. * A console driver
  39. *
  40. * Defines the functions that implement a particular console type.
  41. * Must be made part of the console drivers table by using
  42. * #__console_driver.
  43. *
  44. * @note Consoles that cannot be used before their initialisation
  45. * function has completed should set #disabled initially. This allows
  46. * other console devices to still be used to print out early debugging
  47. * messages.
  48. */
  49. struct console_driver {
  50. /**
  51. * Console disabled flags
  52. *
  53. * This is the bitwise OR of zero or more console disabled
  54. * flags.
  55. */
  56. int disabled;
  57. /**
  58. * Write a character to the console
  59. *
  60. * @v character Character to be written
  61. */
  62. void ( * putchar ) ( int character );
  63. /**
  64. * Read a character from the console
  65. *
  66. * @ret character Character read
  67. *
  68. * If no character is available to be read, this method will
  69. * block. The character read should not be echoed back to the
  70. * console.
  71. */
  72. int ( * getchar ) ( void );
  73. /**
  74. * Check for available input
  75. *
  76. * @ret is_available Input is available
  77. *
  78. * This should return true if a subsequent call to getchar()
  79. * will not block.
  80. */
  81. int ( * iskey ) ( void );
  82. /**
  83. * Configure console
  84. *
  85. * @v config Console configuration, or NULL to reset
  86. * @ret rc Return status code
  87. */
  88. int ( * configure ) ( struct console_configuration *config );
  89. /**
  90. * Console usage bitmask
  91. *
  92. * This is the bitwise OR of zero or more @c CONSOLE_USAGE_XXX
  93. * values.
  94. */
  95. int usage;
  96. };
  97. /** Console is disabled for input */
  98. #define CONSOLE_DISABLED_INPUT 0x0001
  99. /** Console is disabled for output */
  100. #define CONSOLE_DISABLED_OUTPUT 0x0002
  101. /** Console is disabled for all uses */
  102. #define CONSOLE_DISABLED ( CONSOLE_DISABLED_INPUT | CONSOLE_DISABLED_OUTPUT )
  103. /** Console driver table */
  104. #define CONSOLES __table ( struct console_driver, "consoles" )
  105. /**
  106. * Mark a <tt> struct console_driver </tt> as being part of the
  107. * console drivers table.
  108. *
  109. * Use as e.g.
  110. *
  111. * @code
  112. *
  113. * struct console_driver my_console __console_driver = {
  114. * .putchar = my_putchar,
  115. * .getchar = my_getchar,
  116. * .iskey = my_iskey,
  117. * };
  118. *
  119. * @endcode
  120. *
  121. */
  122. #define __console_driver __table_entry ( CONSOLES, 01 )
  123. /**
  124. * @defgroup consoleusage Console usages
  125. * @{
  126. */
  127. /** Standard output */
  128. #define CONSOLE_USAGE_STDOUT 0x0001
  129. /** Debug messages */
  130. #define CONSOLE_USAGE_DEBUG 0x0002
  131. /** Text-based user interface */
  132. #define CONSOLE_USAGE_TUI 0x0004
  133. /** Log messages */
  134. #define CONSOLE_USAGE_LOG 0x0008
  135. /** All console usages */
  136. #define CONSOLE_USAGE_ALL ( CONSOLE_USAGE_STDOUT | CONSOLE_USAGE_DEBUG | \
  137. CONSOLE_USAGE_TUI | CONSOLE_USAGE_LOG )
  138. /** @} */
  139. /**
  140. * Test to see if console has an explicit usage
  141. *
  142. * @v console Console definition (e.g. CONSOLE_PCBIOS)
  143. * @ret explicit Console has an explicit usage
  144. *
  145. * This relies upon the trick that the expression ( 2 * N + 1 ) will
  146. * be valid even if N is defined to be empty, since it will then
  147. * evaluate to give ( 2 * + 1 ) == ( 2 * +1 ) == 2.
  148. */
  149. #define CONSOLE_EXPLICIT( console ) ( ( 2 * console + 1 ) != 2 )
  150. /** Default console width */
  151. #define CONSOLE_DEFAULT_WIDTH 80
  152. /** Default console height */
  153. #define CONSOLE_DEFAULT_HEIGHT 25
  154. extern int console_usage;
  155. extern unsigned int console_width;
  156. extern unsigned int console_height;
  157. /**
  158. * Set console usage
  159. *
  160. * @v usage New console usage
  161. * @ret old_usage Previous console usage
  162. */
  163. static inline __attribute__ (( always_inline )) int
  164. console_set_usage ( int usage ) {
  165. int old_usage = console_usage;
  166. console_usage = usage;
  167. return old_usage;
  168. }
  169. /**
  170. * Set console size
  171. *
  172. * @v width Width, in characters
  173. * @v height Height, in characters
  174. */
  175. static inline __attribute__ (( always_inline )) void
  176. console_set_size ( unsigned int width, unsigned int height ) {
  177. console_width = width;
  178. console_height = height;
  179. }
  180. extern int iskey ( void );
  181. extern int getkey ( unsigned long timeout );
  182. extern int console_configure ( struct console_configuration *config );
  183. /**
  184. * Reset console
  185. *
  186. */
  187. static inline __attribute__ (( always_inline )) void console_reset ( void ) {
  188. console_configure ( NULL );
  189. }
  190. #endif /* _IPXE_CONSOLE_H */