Console.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include <Kernel/Console.h>
  2. #include <Kernel/IO.h>
  3. #include <Kernel/kstdio.h>
  4. // Bytes output to 0xE9 end up on the Bochs console. It's very handy.
  5. #define CONSOLE_OUT_TO_E9
  6. static Console* s_the;
  7. Console& Console::the()
  8. {
  9. ASSERT(s_the);
  10. return *s_the;
  11. }
  12. bool Console::is_initialized()
  13. {
  14. return s_the != nullptr;
  15. }
  16. Console::Console()
  17. : CharacterDevice(5, 1)
  18. {
  19. s_the = this;
  20. }
  21. Console::~Console()
  22. {
  23. }
  24. bool Console::can_read(FileDescription&) const
  25. {
  26. return false;
  27. }
  28. ssize_t Console::read(FileDescription&, u8*, ssize_t)
  29. {
  30. // FIXME: Implement reading from the console.
  31. // Maybe we could use a ring buffer for this device?
  32. return 0;
  33. }
  34. ssize_t Console::write(FileDescription&, const u8* data, ssize_t size)
  35. {
  36. if (!size)
  37. return 0;
  38. if (!m_implementation)
  39. return 0;
  40. for (ssize_t i = 0; i < size; ++i)
  41. put_char(data[i]);
  42. return size;
  43. }
  44. void Console::put_char(char ch)
  45. {
  46. #ifdef CONSOLE_OUT_TO_E9
  47. //if (ch != 27)
  48. IO::out8(0xe9, ch);
  49. #endif
  50. m_logbuffer.enqueue(ch);
  51. if (m_implementation)
  52. m_implementation->on_sysconsole_receive(ch);
  53. }
  54. ConsoleImplementation::~ConsoleImplementation()
  55. {
  56. }