1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#include <linux/kernel.h>
22#include <linux/console.h>
23#include <linux/init.h>
24#include <linux/serial_core.h>
25
26#ifdef CONFIG_THUMB2_KERNEL
27#define SEMIHOST_SWI "0xab"
28#else
29#define SEMIHOST_SWI "0x123456"
30#endif
31
32
33
34
35static void smh_putc(struct uart_port *port, int c)
36{
37#ifdef CONFIG_ARM64
38 asm volatile("mov x1, %0\n"
39 "mov x0, #3\n"
40 "hlt 0xf000\n"
41 : : "r" (&c) : "x0", "x1", "memory");
42#else
43 asm volatile("mov r1, %0\n"
44 "mov r0, #3\n"
45 "svc " SEMIHOST_SWI "\n"
46 : : "r" (&c) : "r0", "r1", "memory");
47#endif
48}
49
50static void smh_write(struct console *con, const char *s, unsigned n)
51{
52 struct earlycon_device *dev = con->data;
53 uart_console_write(&dev->port, s, n, smh_putc);
54}
55
56static int
57__init early_smh_setup(struct earlycon_device *device, const char *opt)
58{
59 device->con->write = smh_write;
60 return 0;
61}
62EARLYCON_DECLARE(smh, early_smh_setup);
63