early_printk.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright 2010 Tilera Corporation. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation, version 2.
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  11. * NON INFRINGEMENT. See the GNU General Public License for
  12. * more details.
  13. */
  14. #include <linux/console.h>
  15. #include <linux/kernel.h>
  16. #include <linux/init.h>
  17. #include <linux/string.h>
  18. #include <linux/irqflags.h>
  19. #include <linux/printk.h>
  20. #include <asm/setup.h>
  21. #include <hv/hypervisor.h>
  22. static void early_hv_write(struct console *con, const char *s, unsigned n)
  23. {
  24. tile_console_write(s, n);
  25. /*
  26. * Convert NL to NLCR (close enough to CRNL) during early boot.
  27. * We assume newlines are at the ends of strings, which turns out
  28. * to be good enough for early boot console output.
  29. */
  30. if (n && s[n-1] == '\n')
  31. tile_console_write("\r", 1);
  32. }
  33. static struct console early_hv_console = {
  34. .name = "earlyhv",
  35. .write = early_hv_write,
  36. .flags = CON_PRINTBUFFER | CON_BOOT,
  37. .index = -1,
  38. };
  39. void early_panic(const char *fmt, ...)
  40. {
  41. va_list ap;
  42. arch_local_irq_disable_all();
  43. va_start(ap, fmt);
  44. early_printk("Kernel panic - not syncing: ");
  45. early_vprintk(fmt, ap);
  46. early_printk("\n");
  47. va_end(ap);
  48. dump_stack();
  49. hv_halt();
  50. }
  51. static int __init setup_early_printk(char *str)
  52. {
  53. if (early_console)
  54. return 1;
  55. early_console = &early_hv_console;
  56. register_console(early_console);
  57. return 0;
  58. }
  59. early_param("earlyprintk", setup_early_printk);