tty.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* kernel/tty.c
  2. *
  3. * Copyright (C) 2021, 2022 intirain.
  4. *
  5. * This file is part of evx.
  6. *
  7. * evx is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * evx is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with evx. If not, see <https://www.gnu.org/licenses/>
  19. */
  20. #include <kernel/init.h>
  21. #include <kernel/module.h>
  22. #include <kernel/kernel.h>
  23. #include <kernel/tty.h>
  24. #include <kernel/mm.h>
  25. #include <sys/types.h>
  26. #include <lib/klist.h>
  27. struct klist_node ttys = KLIST_NODE_INIT(&ttys);
  28. int tty_register(struct tty *tty) {
  29. struct klist_node *n = kmalloc(sizeof(struct klist_node));
  30. if (!n)
  31. panic("tty_register: Out of memory");
  32. klist_init(n);
  33. n->data = tty;
  34. klist_add(&ttys, n);
  35. tty_write(tty, tty->dev_name);
  36. tty_write(tty, "\n\n");
  37. return 0;
  38. }
  39. int tty_write(struct tty *tty, char *s) {
  40. int err;
  41. while (*s) {
  42. if ((err = tty->putc(*s)))
  43. return err;
  44. s++;
  45. }
  46. return 0;
  47. }
  48. int tty_write_all(char *p) {
  49. struct tty *tty;
  50. struct klist_node *n;
  51. char *s;
  52. int err;
  53. for (n = ttys.next; n != &ttys; n = n->next) {
  54. s = p;
  55. tty = (struct tty *) n->data;
  56. while (*s) {
  57. if ((err = tty->putc(*s)))
  58. return err;
  59. s++;
  60. }
  61. }
  62. return 0;
  63. }