earlycon-arm-semihost.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright (C) 2012 ARM Ltd.
  3. * Author: Marc Zyngier <[email protected]>
  4. *
  5. * Adapted for ARM and earlycon:
  6. * Copyright (C) 2014 Linaro Ltd.
  7. * Author: Rob Herring <[email protected]>
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #include <linux/kernel.h>
  22. #include <linux/console.h>
  23. #include <linux/init.h>
  24. #include <linux/serial_core.h>
  25. #ifdef CONFIG_THUMB2_KERNEL
  26. #define SEMIHOST_SWI "0xab"
  27. #else
  28. #define SEMIHOST_SWI "0x123456"
  29. #endif
  30. /*
  31. * Semihosting-based debug console
  32. */
  33. static void smh_putc(struct uart_port *port, int c)
  34. {
  35. #ifdef CONFIG_ARM64
  36. asm volatile("mov x1, %0\n"
  37. "mov x0, #3\n"
  38. "hlt 0xf000\n"
  39. : : "r" (&c) : "x0", "x1", "memory");
  40. #else
  41. asm volatile("mov r1, %0\n"
  42. "mov r0, #3\n"
  43. "svc " SEMIHOST_SWI "\n"
  44. : : "r" (&c) : "r0", "r1", "memory");
  45. #endif
  46. }
  47. static void smh_write(struct console *con, const char *s, unsigned n)
  48. {
  49. struct earlycon_device *dev = con->data;
  50. uart_console_write(&dev->port, s, n, smh_putc);
  51. }
  52. static int
  53. __init early_smh_setup(struct earlycon_device *device, const char *opt)
  54. {
  55. device->con->write = smh_write;
  56. return 0;
  57. }
  58. EARLYCON_DECLARE(smh, early_smh_setup);