printf.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * printf.c: Internal prom library printf facility.
  3. *
  4. * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
  5. * Copyright (C) 1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
  6. * Copyright (c) 2002 Pete Zaitcev (zaitcev@yahoo.com)
  7. *
  8. * We used to warn all over the code: DO NOT USE prom_printf(),
  9. * and yet people do. Anton's banking code was outputting banks
  10. * with prom_printf for most of the 2.4 lifetime. Since an effective
  11. * stick is not available, we deployed a carrot: an early printk
  12. * through PROM by means of -p boot option. This ought to fix it.
  13. * USE printk; if you need, deploy -p.
  14. */
  15. #include <linux/kernel.h>
  16. #include <linux/compiler.h>
  17. #include <linux/spinlock.h>
  18. #include <asm/openprom.h>
  19. #include <asm/oplib.h>
  20. #define CONSOLE_WRITE_BUF_SIZE 1024
  21. static char ppbuf[1024];
  22. static char console_write_buf[CONSOLE_WRITE_BUF_SIZE];
  23. static DEFINE_RAW_SPINLOCK(console_write_lock);
  24. void notrace prom_write(const char *buf, unsigned int n)
  25. {
  26. unsigned int dest_len;
  27. unsigned long flags;
  28. char *dest;
  29. dest = console_write_buf;
  30. raw_spin_lock_irqsave(&console_write_lock, flags);
  31. dest_len = 0;
  32. while (n-- != 0) {
  33. char ch = *buf++;
  34. if (ch == '\n') {
  35. *dest++ = '\r';
  36. dest_len++;
  37. }
  38. *dest++ = ch;
  39. dest_len++;
  40. if (dest_len >= CONSOLE_WRITE_BUF_SIZE - 1) {
  41. prom_console_write_buf(console_write_buf, dest_len);
  42. dest = console_write_buf;
  43. dest_len = 0;
  44. }
  45. }
  46. if (dest_len)
  47. prom_console_write_buf(console_write_buf, dest_len);
  48. raw_spin_unlock_irqrestore(&console_write_lock, flags);
  49. }
  50. void notrace prom_printf(const char *fmt, ...)
  51. {
  52. va_list args;
  53. int i;
  54. va_start(args, fmt);
  55. i = vscnprintf(ppbuf, sizeof(ppbuf), fmt, args);
  56. va_end(args);
  57. prom_write(ppbuf, i);
  58. }