tty.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include <asm/port_io.h>
  2. #include <kernel/hw/serial.h>
  3. #include <kernel/mem.hpp>
  4. #include <kernel/stdio.h>
  5. #include <kernel/tty.h>
  6. #include <kernel/vga.h>
  7. static void serial_tty_put_char(struct tty* p_tty, char c)
  8. {
  9. serial_send_data(*(port_id_t*)&p_tty->data, c);
  10. }
  11. static void vga_tty_put_char(struct tty* _unused, char c)
  12. {
  13. static struct vga_char vc = { .c = '\0', .color = VGA_CHAR_COLOR_WHITE };
  14. vc.c = c;
  15. vga_put_char(&vc);
  16. }
  17. static struct tty_operations serial_tty_ops = {
  18. .put_char = serial_tty_put_char,
  19. };
  20. static struct tty_operations vga_tty_ops = {
  21. .put_char = vga_tty_put_char,
  22. };
  23. void tty_print(struct tty* p_tty, const char* str)
  24. {
  25. while (*str != '\0') {
  26. p_tty->ops->put_char(p_tty, *str);
  27. ++str;
  28. }
  29. }
  30. int make_serial_tty(struct tty* p_tty, int id)
  31. {
  32. *(port_id_t*)&p_tty->data = id;
  33. snprintf(p_tty->name, sizeof(p_tty->name), "ttyS%x", id);
  34. p_tty->ops = &serial_tty_ops;
  35. return GB_OK;
  36. }
  37. int make_vga_tty(struct tty* p_tty)
  38. {
  39. snprintf(p_tty->name, sizeof(p_tty->name), "ttyVGA");
  40. p_tty->ops = &vga_tty_ops;
  41. return GB_OK;
  42. }