sim-console.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * arch/h8300/kernel/early_printk.c
  3. *
  4. * Copyright (C) 2009 Yoshinori Sato <ysato@users.sourceforge.jp>
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file "COPYING" in the main directory of this archive
  8. * for more details.
  9. */
  10. #include <linux/console.h>
  11. #include <linux/tty.h>
  12. #include <linux/init.h>
  13. #include <linux/io.h>
  14. #include <linux/platform_device.h>
  15. static void sim_write(struct console *co, const char *ptr,
  16. unsigned len)
  17. {
  18. register const int fd __asm__("er0") = 1; /* stdout */
  19. register const char *_ptr __asm__("er1") = ptr;
  20. register const unsigned _len __asm__("er2") = len;
  21. __asm__(".byte 0x5e,0x00,0x00,0xc7\n\t" /* jsr @0xc7 (sys_write) */
  22. : : "g"(fd), "g"(_ptr), "g"(_len));
  23. }
  24. static struct console sim_console = {
  25. .name = "sim_console",
  26. .write = sim_write,
  27. .setup = NULL,
  28. .flags = CON_PRINTBUFFER,
  29. .index = -1,
  30. };
  31. static char sim_console_buf[32];
  32. static int sim_probe(struct platform_device *pdev)
  33. {
  34. if (sim_console.data)
  35. return -EEXIST;
  36. if (!strstr(sim_console_buf, "keep"))
  37. sim_console.flags |= CON_BOOT;
  38. register_console(&sim_console);
  39. return 0;
  40. }
  41. static int sim_remove(struct platform_device *pdev)
  42. {
  43. return 0;
  44. }
  45. static struct platform_driver sim_driver = {
  46. .probe = sim_probe,
  47. .remove = sim_remove,
  48. .driver = {
  49. .name = "h8300-sim",
  50. .owner = THIS_MODULE,
  51. },
  52. };
  53. early_platform_init_buffer("earlyprintk", &sim_driver,
  54. sim_console_buf, ARRAY_SIZE(sim_console_buf));
  55. static struct platform_device sim_console_device = {
  56. .name = "h8300-sim",
  57. .id = 0,
  58. };
  59. static struct platform_device *devices[] __initdata = {
  60. &sim_console_device,
  61. };
  62. void __init sim_console_register(void)
  63. {
  64. early_platform_add_devices(devices,
  65. ARRAY_SIZE(devices));
  66. }