uart.c 1002 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * This file is part of the coreboot project.
  3. *
  4. * Copyright 2014 Google Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; version 2 of the License.
  9. *
  10. * This program 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. #include "u.h"
  16. #include "../port/lib.h"
  17. #include "mem.h"
  18. #include "dat.h"
  19. #include "fns.h"
  20. uintptr_t uart_platform_base(int idx)
  21. {
  22. return (uintptr_t) 0x40001000;
  23. }
  24. void putchar(uint8_t c)
  25. {
  26. uint8_t *cp = KADDR(uart_platform_base(0));
  27. *cp = c;
  28. }
  29. // Get a 7-bit char. < 0 means err.
  30. int getchar(void)
  31. {
  32. uint8_t *cp = KADDR(uart_platform_base(0));
  33. if (cp[5] & 1) {
  34. int c = cp[0];
  35. if (0) print("getchar: got 0x%x\n", c);
  36. return c;
  37. }
  38. return -1;
  39. }