tty.c 1.6 KB

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