skeleton_console.S 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. * Copyright (c) 2015-2020, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <asm_macros.S>
  7. #include <console_macros.S>
  8. /*
  9. * This file contains a skeleton console driver that can be used as a
  10. * basis for a real console driver. Console drivers in Trusted Firmware
  11. * can be instantiated multiple times. Each instance is described by a
  12. * separate console_t structure which must be registered with the common
  13. * console framework via console_register(). Console drivers should
  14. * define a console_xxx_register() function that initializes a new
  15. * console_t structure passed in from the caller and registers it after
  16. * initializing the console hardware. Drivers may define their own
  17. * structures extending console_t to store private driver information.
  18. * Console drivers *MUST* ensure that the console callbacks they
  19. * implement only change registers allowed in the clobber lists defined
  20. * in this file. (Note that in addition to the explicit clobber lists,
  21. * any function may always clobber the intra-procedure-call registers
  22. * X16 and X17, but may never depend on them retaining their values
  23. * across any function call.)
  24. */
  25. .globl console_xxx_register
  26. .globl console_xxx_putc
  27. .globl console_xxx_getc
  28. .globl console_xxx_flush
  29. /* -----------------------------------------------
  30. * int console_xxx_register(console_xxx_t *console,
  31. * ...additional parameters as desired...)
  32. * Function to initialize and register the console.
  33. * The caller needs to pass an empty console_xxx_t
  34. * structure in which *MUST* be allocated in
  35. * persistent memory (e.g. a global or static local
  36. * variable, *NOT* on the stack).
  37. * In : x0 - pointer to empty console_t structure
  38. * x1 through x7: additional parameters as desired
  39. * Out: x0 - 1 on success, 0 on error
  40. * Clobber list : x0 - x7
  41. * -----------------------------------------------
  42. */
  43. func console_xxx_register
  44. /*
  45. * Store parameters (e.g. hardware base address) in driver-specific
  46. * console_xxx_t structure field if they will need to be retrieved
  47. * by later console callback (e.g. putc).
  48. * Example:
  49. */
  50. str x1, [x0, #CONSOLE_T_BASE]
  51. str x2, [x0, #CONSOLE_T_XXX_SOME_OTHER_VALUE]
  52. /*
  53. * Initialize console hardware, using x1 - x7 parameters as needed.
  54. * Keep console_t pointer in x0 for later.
  55. */
  56. /*
  57. * Macro to finish up registration and return (needs valid x0 + x30).
  58. * If any of the argument is unspecified, then the corresponding
  59. * entry in console_t is set to 0.
  60. */
  61. finish_console_register xxx putc=1, getc=ENABLE_CONSOLE_GETC, flush=1
  62. /* Jump here if hardware init fails or parameters are invalid. */
  63. register_fail:
  64. mov w0, #0
  65. ret
  66. endfunc console_xxx_register
  67. /* --------------------------------------------------------
  68. * int console_xxx_putc(int c, console_xxx_t *console)
  69. * Function to output a character over the console. It
  70. * returns the character printed on success or -1 on error.
  71. * In : w0 - character to be printed
  72. * x1 - pointer to console_t struct
  73. * Out: w0 - printed character on success, < 0 on error.
  74. * Clobber list : x0, x1, x2
  75. * --------------------------------------------------------
  76. */
  77. func console_xxx_putc
  78. /*
  79. * Retrieve values we need (e.g. hardware base address) from
  80. * console_xxx_t structure pointed to by x1.
  81. * Example:
  82. */
  83. ldr x1, [x1, #CONSOLE_T_BASE]
  84. /*
  85. * Write w0 to hardware.
  86. */
  87. ret
  88. /* Jump here if output fails for any reason. */
  89. putc_error:
  90. mov w0, #-1
  91. ret
  92. endfunc console_xxx_putc
  93. /* ---------------------------------------------
  94. * int console_xxx_getc(console_xxx_t *console)
  95. * Function to get a character from the console.
  96. * Even though console_getc() is blocking, this
  97. * callback has to be non-blocking and always
  98. * return immediately to allow polling multiple
  99. * drivers concurrently.
  100. * Returns the character grabbed on success,
  101. * ERROR_NO_PENDING_CHAR if no character was
  102. * available at this time, or any value
  103. * between -2 and -127 if there was an error.
  104. * In : x0 - pointer to console_t struct
  105. * Out: w0 - character on success,
  106. * ERROR_NO_PENDING_CHAR if no char,
  107. * < -1 on error
  108. * Clobber list : x0, x1
  109. * ---------------------------------------------
  110. */
  111. func console_xxx_getc
  112. /*
  113. * Retrieve values we need (e.g. hardware base address) from
  114. * console_xxx_t structure pointed to by x0.
  115. * Example:
  116. */
  117. ldr x1, [x0, #CONSOLE_T_BASE]
  118. /*
  119. * Try to read character into w0 from hardware.
  120. */
  121. ret
  122. /* Jump here if there is no character available at this time. */
  123. getc_no_char:
  124. mov w0, #ERROR_NO_PENDING_CHAR
  125. ret
  126. /* Jump here if there was any hardware error. */
  127. getc_error:
  128. mov w0, #-2 /* may pick error codes between -2 and -127 */
  129. ret
  130. endfunc console_xxx_getc
  131. /* ---------------------------------------------
  132. * void console_xxx_flush(console_xxx_t *console)
  133. * Function to force a write of all buffered
  134. * data that hasn't been output.
  135. * In : x0 - pointer to console_xxx_t struct
  136. * Out: void
  137. * Clobber list : x0, x1, x2, x3, x4, x5
  138. * ---------------------------------------------
  139. */
  140. func console_xxx_flush
  141. /*
  142. * Retrieve values we need (e.g. hardware base address) from
  143. * console_xxx_t structure pointed to by x0.
  144. * Example:
  145. */
  146. ldr x1, [x0, #CONSOLE_T_BASE]
  147. /*
  148. * Flush all remaining output from hardware FIFOs. Do not return until
  149. * all data has been flushed or there was an unrecoverable error.
  150. */
  151. ret
  152. endfunc console_xxx_flush