dbcn.rs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //! Chapter 12. Debug Console Extension (EID #0x4442434E "DBCN")
  2. use crate::binary::{sbi_call_1, sbi_call_3};
  3. use sbi_spec::{
  4. binary::{Physical, SbiRet},
  5. dbcn::{CONSOLE_READ, CONSOLE_WRITE, CONSOLE_WRITE_BYTE, EID_DBCN},
  6. };
  7. /// Write bytes to the debug console from input memory.
  8. ///
  9. /// # Parameters
  10. ///
  11. /// The `bytes` parameter specifies the input memory, including its length
  12. /// and memory physical base address (both lower and upper bits).
  13. ///
  14. /// # Non-blocking function
  15. ///
  16. /// This is a non-blocking SBI call, and it may do partial or no write operations if
  17. /// the debug console is not able to accept more bytes.
  18. ///
  19. /// # Return value
  20. ///
  21. /// The number of bytes written is returned in `SbiRet.value` and the
  22. /// possible return error codes returned in `SbiRet.error` are shown in
  23. /// the table below:
  24. ///
  25. /// | Return code | Description
  26. /// |:--------------------------|:----------------------------------------------
  27. /// | `SbiRet::success()` | Bytes written successfully.
  28. /// | `SbiRet::invalid_param()` | The memory pointed to by `bytes` does not satisfy the requirements described in shared memory physical address range.
  29. /// | `SbiRet::failed()` | Failed to write due to I/O errors.
  30. ///
  31. /// This function is defined in RISC-V SBI Specification chapter 12.1.
  32. #[inline]
  33. pub fn console_write(bytes: Physical<&[u8]>) -> SbiRet {
  34. sbi_call_3(
  35. EID_DBCN,
  36. CONSOLE_WRITE,
  37. bytes.num_bytes(),
  38. bytes.phys_addr_lo(),
  39. bytes.phys_addr_hi(),
  40. )
  41. }
  42. /// Read bytes from the debug console into an output memory.
  43. ///
  44. /// # Parameters
  45. ///
  46. /// The `bytes` parameter specifies the output memory, including the maximum
  47. /// bytes which can be written, and its memory physical base address
  48. /// (both lower and upper bits).
  49. ///
  50. /// # Non-blocking function
  51. ///
  52. /// This is a non-blocking SBI call, and it will not write anything
  53. /// into the output memory if there are no bytes to be read in the
  54. /// debug console.
  55. ///
  56. /// # Return value
  57. ///
  58. /// The number of bytes read is returned in `SbiRet.value` and the
  59. /// possible return error codes returned in `SbiRet.error` are shown in
  60. /// the table below:
  61. ///
  62. /// | Return code | Description
  63. /// |:--------------------------|:----------------------------------------------
  64. /// | `SbiRet::success()` | Bytes read successfully.
  65. /// | `SbiRet::invalid_param()` | The memory pointed to by `bytes` does not satisfy the requirements described in shared memory physical address range.
  66. /// | `SbiRet::failed()` | Failed to read due to I/O errors.
  67. ///
  68. /// This function is defined in RISC-V SBI Specification chapter 12.2.
  69. pub fn console_read(bytes: Physical<&mut [u8]>) -> SbiRet {
  70. sbi_call_3(
  71. EID_DBCN,
  72. CONSOLE_READ,
  73. bytes.num_bytes(),
  74. bytes.phys_addr_lo(),
  75. bytes.phys_addr_hi(),
  76. )
  77. }
  78. /// Write a single byte to the debug console.
  79. ///
  80. /// # Blocking function
  81. ///
  82. /// This is a blocking SBI call, and it will only return after writing
  83. /// the specified byte to the debug console. It will also return with
  84. /// `SbiRet::failed()` if there are I/O errors.
  85. /// # Return value
  86. ///
  87. /// The `SbiRet.value` is set to zero, and the possible return error
  88. /// codes returned in `SbiRet.error` are shown in the table below:
  89. ///
  90. /// | Return code | Description
  91. /// |:--------------------------|:----------------------------------------------
  92. /// | `SbiRet::success()` | Byte written successfully.
  93. /// | `SbiRet::failed()` | Failed to write the byte due to I/O errors.
  94. ///
  95. /// This function is defined in RISC-V SBI Specification chapter 12.3.
  96. #[inline]
  97. pub fn console_write_byte(byte: u8) -> SbiRet {
  98. sbi_call_1(EID_DBCN, CONSOLE_WRITE_BYTE, byte as usize)
  99. }