earlycon-arm-semihost.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2012 ARM Ltd.
  4. * Author: Marc Zyngier <marc.zyngier@arm.com>
  5. *
  6. * Adapted for ARM and earlycon:
  7. * Copyright (C) 2014 Linaro Ltd.
  8. * Author: Rob Herring <robh@kernel.org>
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/console.h>
  12. #include <linux/init.h>
  13. #include <linux/serial_core.h>
  14. #ifdef CONFIG_THUMB2_KERNEL
  15. #define SEMIHOST_SWI "0xab"
  16. #else
  17. #define SEMIHOST_SWI "0x123456"
  18. #endif
  19. /*
  20. * Semihosting-based debug console
  21. */
  22. static void smh_putc(struct uart_port *port, int c)
  23. {
  24. #ifdef CONFIG_ARM64
  25. asm volatile("mov x1, %0\n"
  26. "mov x0, #3\n"
  27. "hlt 0xf000\n"
  28. : : "r" (&c) : "x0", "x1", "memory");
  29. #else
  30. asm volatile("mov r1, %0\n"
  31. "mov r0, #3\n"
  32. "svc " SEMIHOST_SWI "\n"
  33. : : "r" (&c) : "r0", "r1", "memory");
  34. #endif
  35. }
  36. static void smh_write(struct console *con, const char *s, unsigned n)
  37. {
  38. struct earlycon_device *dev = con->data;
  39. uart_console_write(&dev->port, s, n, smh_putc);
  40. }
  41. static int
  42. __init early_smh_setup(struct earlycon_device *device, const char *opt)
  43. {
  44. device->con->write = smh_write;
  45. return 0;
  46. }
  47. EARLYCON_DECLARE(smh, early_smh_setup);