tty.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 klist_node *n;
  50. int err;
  51. for (n = ttys.next; n != &ttys; n = n->next)
  52. if ((err = tty_write((struct tty *) n->data, p)))
  53. return err;
  54. return 0;
  55. }