Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * Copyright (C) 2012 ARM Ltd.
0004  * Author: Marc Zyngier <marc.zyngier@arm.com>
0005  *
0006  * Adapted for ARM and earlycon:
0007  * Copyright (C) 2014 Linaro Ltd.
0008  * Author: Rob Herring <robh@kernel.org>
0009  */
0010 #include <linux/kernel.h>
0011 #include <linux/console.h>
0012 #include <linux/init.h>
0013 #include <linux/serial_core.h>
0014 
0015 #ifdef CONFIG_THUMB2_KERNEL
0016 #define SEMIHOST_SWI    "0xab"
0017 #else
0018 #define SEMIHOST_SWI    "0x123456"
0019 #endif
0020 
0021 /*
0022  * Semihosting-based debug console
0023  */
0024 static void smh_putc(struct uart_port *port, unsigned char c)
0025 {
0026 #ifdef CONFIG_ARM64
0027     asm volatile("mov  x1, %0\n"
0028              "mov  x0, #3\n"
0029              "hlt  0xf000\n"
0030              : : "r" (&c) : "x0", "x1", "memory");
0031 #else
0032     asm volatile("mov  r1, %0\n"
0033              "mov  r0, #3\n"
0034              "svc  " SEMIHOST_SWI "\n"
0035              : : "r" (&c) : "r0", "r1", "memory");
0036 #endif
0037 }
0038 
0039 static void smh_write(struct console *con, const char *s, unsigned n)
0040 {
0041     struct earlycon_device *dev = con->data;
0042     uart_console_write(&dev->port, s, n, smh_putc);
0043 }
0044 
0045 static int
0046 __init early_smh_setup(struct earlycon_device *device, const char *opt)
0047 {
0048     device->con->write = smh_write;
0049     return 0;
0050 }
0051 EARLYCON_DECLARE(smh, early_smh_setup);