2 * Jailhouse, a Linux-based partitioning hypervisor
4 * Copyright (c) Siemens AG, 2013-2016
5 * Copyright (c) Toshiba, 2016
8 * Jan Kiszka <jan.kiszka@siemens.com>
9 * Daniel Sangorrin <daniel.sangorrin@toshiba.co.jp>
11 * This work is licensed under the terms of the GNU GPL, version 2. See
12 * the COPYING file in the top-level directory.
15 #include <jailhouse/control.h>
16 #include <jailhouse/entry.h>
17 #include <jailhouse/printk.h>
18 #include <jailhouse/processor.h>
25 #define UART_LCR_8N1 0x03
26 #define UART_LCR_DLAB 0x80
28 #define UART_LSR_THRE 0x20
32 static void uart_init(void)
34 if (system_config->debug_console.phys_start == 0 ||
35 system_config->debug_console.flags & JAILHOUSE_MEM_IO)
38 uart_base = system_config->debug_console.phys_start;
40 outb(UART_LCR_DLAB, uart_base + UART_LCR);
41 #ifdef CONFIG_UART_OXPCIE952
42 outb(0x22, uart_base + UART_DLL);
44 outb(1, uart_base + UART_DLL);
46 outb(0, uart_base + UART_DLM);
47 outb(UART_LCR_8N1, uart_base + UART_LCR);
50 static void uart_write(const char *msg)
61 while (!(inb(uart_base + UART_LSR) & UART_LSR_THRE))
63 if (panic_in_progress && panic_cpu != phys_processor_id())
65 outb(c, uart_base + UART_TX);
72 #define VGA_BRIGHT_GREEN 0xA
73 #define VGA_BG_COLOR VGA_BLACK
74 #define VGA_FG_COLOR VGA_BRIGHT_GREEN
75 #define VGA_ATTRIBUTE ((VGA_BG_COLOR | VGA_FG_COLOR) << 8)
76 #define VGA_U16(c) ((u16)(c) | (u16)VGA_ATTRIBUTE)
77 #define ASCII_NONPRINTABLE '?'
81 static void vga_init(void)
83 vga_mem = hypervisor_header.debug_console_base;
86 static void vga_scroll(void)
90 for (i = 0; i < (VGA_HEIGHT - 1) * VGA_WIDTH; i++)
91 vga_mem[i] = vga_mem[i + VGA_WIDTH];
93 for (i = 0; i < VGA_WIDTH; i++)
94 vga_mem[(VGA_HEIGHT - 1) * VGA_WIDTH + i] = VGA_U16(' ');
97 static void vga_write(const char *msg)
103 /* panic_printk avoids locking 'printk_lock' due to a potential
104 deadlock in case a crash occurs while holding it. For avoiding
105 a data race between printk and panic_printk we take a local
106 snapshot of both static variables and update them on return */
107 row = (u16)((row_line & 0xFFFF0000) >> 16);
108 line = (u16)(row_line & 0x0000FFFF);
111 if (panic_in_progress && panic_cpu != phys_processor_id())
113 if (row == VGA_WIDTH || *msg == '\n') {
115 if (line == (VGA_HEIGHT - 1))
120 pos = line * VGA_WIDTH + row;
126 vga_mem[pos] = VGA_U16(*msg);
129 vga_mem[pos] = VGA_U16(ASCII_NONPRINTABLE);
135 row_line = ((u32)row << 16) | (u32)line;
138 void arch_dbg_write_init(void)
144 void arch_dbg_write(const char *msg)