2 * Copyright (C) 2012 ARM Ltd.
3 * Author: Marc Zyngier <marc.zyngier@arm.com>
5 * Adapted for ARM and earlycon:
6 * Copyright (C) 2014 Linaro Ltd.
7 * Author: Rob Herring <robh@kernel.org>
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.
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.
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/>.
21 #include <linux/kernel.h>
22 #include <linux/console.h>
23 #include <linux/init.h>
24 #include <linux/serial_core.h>
26 #ifdef CONFIG_THUMB2_KERNEL
27 #define SEMIHOST_SWI "0xab"
29 #define SEMIHOST_SWI "0x123456"
33 * Semihosting-based debug console
35 static void smh_putc(struct uart_port
*port
, int c
)
38 asm volatile("mov x1, %0\n"
41 : : "r" (&c
) : "x0", "x1", "memory");
43 asm volatile("mov r1, %0\n"
45 "svc " SEMIHOST_SWI
"\n"
46 : : "r" (&c
) : "r0", "r1", "memory");
50 static void smh_write(struct console
*con
, const char *s
, unsigned n
)
52 struct earlycon_device
*dev
= con
->data
;
53 uart_console_write(&dev
->port
, s
, n
, smh_putc
);
57 __init
early_smh_setup(struct earlycon_device
*device
, const char *opt
)
59 device
->con
->write
= smh_write
;
62 EARLYCON_DECLARE(smh
, early_smh_setup
);