sim_printf.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Carsten Langgaard, carstenl@mips.com
  3. * Copyright (C) 1999,2000 MIPS Technologies, Inc. All rights reserved.
  4. *
  5. * This program is free software; you can distribute it and/or modify it
  6. * under the terms of the GNU General Public License (Version 2) as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. * for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with this program; if not, write to the Free Software Foundation, Inc.,
  16. * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  17. *
  18. * Putting things on the screen/serial line using YAMONs facilities.
  19. */
  20. #include <linux/init.h>
  21. #include <linux/kernel.h>
  22. #include <linux/serial_reg.h>
  23. #include <linux/spinlock.h>
  24. #include <asm/io.h>
  25. #include <asm/system.h>
  26. static inline unsigned int serial_in(int offset)
  27. {
  28. return inb(0x3f8 + offset);
  29. }
  30. static inline void serial_out(int offset, int value)
  31. {
  32. outb(value, 0x3f8 + offset);
  33. }
  34. int putPromChar(char c)
  35. {
  36. while ((serial_in(UART_LSR) & UART_LSR_THRE) == 0)
  37. ;
  38. serial_out(UART_TX, c);
  39. return 1;
  40. }
  41. char getPromChar(void)
  42. {
  43. while (!(serial_in(UART_LSR) & 1))
  44. ;
  45. return serial_in(UART_RX);
  46. }
  47. void prom_printf(char *fmt, ...)
  48. {
  49. va_list args;
  50. int l;
  51. char *p, *buf_end;
  52. char buf[1024];
  53. va_start(args, fmt);
  54. l = vsprintf(buf, fmt, args); /* hopefully i < sizeof(buf) */
  55. va_end(args);
  56. buf_end = buf + l;
  57. for (p = buf; p < buf_end; p++) {
  58. /* Crude cr/nl handling is better than none */
  59. if (*p == '\n')
  60. putPromChar('\r');
  61. putPromChar(*p);
  62. }
  63. }