early_printk.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. struct va_format vaf;
  42. va_list args;
  43. arch_local_irq_disable_all();
  44. va_start(args, fmt);
  45. vaf.fmt = fmt;
  46. vaf.va = &args;
  47. early_printk("Kernel panic - not syncing: %pV", &vaf);
  48. va_end(args);
  49. dump_stack();
  50. hv_halt();
  51. }
  52. static int __init setup_early_printk(char *str)
  53. {
  54. if (early_console)
  55. return 1;
  56. early_console = &early_hv_console;
  57. register_console(early_console);
  58. return 0;
  59. }
  60. early_param("earlyprintk", setup_early_printk);