ia64/xen-unstable

view extras/mini-os/console/console.c @ 18811:390ef36eb596

Remove Xen-private definitions from kexec public header.

Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Nov 19 13:13:39 2008 +0000 (2008-11-19)
parents 2197a263a300
children 11d8ca329b54
line source
1 /*
2 ****************************************************************************
3 * (C) 2006 - Grzegorz Milos - Cambridge University
4 ****************************************************************************
5 *
6 * File: console.h
7 * Author: Grzegorz Milos
8 * Changes:
9 *
10 * Date: Mar 2006
11 *
12 * Environment: Xen Minimal OS
13 * Description: Console interface.
14 *
15 * Handles console I/O. Defines printk.
16 *
17 ****************************************************************************
18 * Permission is hereby granted, free of charge, to any person obtaining a copy
19 * of this software and associated documentation files (the "Software"), to
20 * deal in the Software without restriction, including without limitation the
21 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
22 * sell copies of the Software, and to permit persons to whom the Software is
23 * furnished to do so, subject to the following conditions:
24 *
25 * The above copyright notice and this permission notice shall be included in
26 * all copies or substantial portions of the Software.
27 *
28 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
29 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
30 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
31 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
32 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
33 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
34 * DEALINGS IN THE SOFTWARE.
35 */
37 #include <types.h>
38 #include <wait.h>
39 #include <mm.h>
40 #include <hypervisor.h>
41 #include <events.h>
42 #include <os.h>
43 #include <lib.h>
44 #include <xenbus.h>
45 #include <xen/io/console.h>
48 /* Copies all print output to the Xen emergency console apart
49 of standard dom0 handled console */
50 #define USE_XEN_CONSOLE
53 /* If console not initialised the printk will be sent to xen serial line
54 NOTE: you need to enable verbose in xen/Rules.mk for it to work. */
55 static int console_initialised = 0;
58 #ifndef HAVE_LIBC
59 void xencons_rx(char *buf, unsigned len, struct pt_regs *regs)
60 {
61 if(len > 0)
62 {
63 /* Just repeat what's written */
64 buf[len] = '\0';
65 printk("%s", buf);
67 if(buf[len-1] == '\r')
68 printk("\nNo console input handler.\n");
69 }
70 }
72 void xencons_tx(void)
73 {
74 /* Do nothing, handled by _rx */
75 }
76 #endif
79 void console_print(char *data, int length)
80 {
81 char *curr_char, saved_char;
82 int part_len;
83 int (*ring_send_fn)(const char *data, unsigned length);
85 if(!console_initialised)
86 ring_send_fn = xencons_ring_send_no_notify;
87 else
88 ring_send_fn = xencons_ring_send;
90 for(curr_char = data; curr_char < data+length-1; curr_char++)
91 {
92 if(*curr_char == '\n')
93 {
94 saved_char = *(curr_char+1);
95 *(curr_char+1) = '\r';
96 part_len = curr_char - data + 2;
97 ring_send_fn(data, part_len);
98 *(curr_char+1) = saved_char;
99 data = curr_char+1;
100 length -= part_len - 1;
101 }
102 }
104 ring_send_fn(data, length);
106 if(data[length-1] == '\n')
107 ring_send_fn("\r", 1);
108 }
110 void print(int direct, const char *fmt, va_list args)
111 {
112 static char buf[1024];
114 (void)vsnprintf(buf, sizeof(buf), fmt, args);
116 if(direct)
117 {
118 (void)HYPERVISOR_console_io(CONSOLEIO_write, strlen(buf), buf);
119 return;
120 } else {
121 #ifndef USE_XEN_CONSOLE
122 if(!console_initialised)
123 #endif
124 (void)HYPERVISOR_console_io(CONSOLEIO_write, strlen(buf), buf);
126 console_print(buf, strlen(buf));
127 }
128 }
130 void printk(const char *fmt, ...)
131 {
132 va_list args;
133 va_start(args, fmt);
134 print(0, fmt, args);
135 va_end(args);
136 }
138 void xprintk(const char *fmt, ...)
139 {
140 va_list args;
141 va_start(args, fmt);
142 print(1, fmt, args);
143 va_end(args);
144 }
145 void init_console(void)
146 {
147 printk("Initialising console ... ");
148 xencons_ring_init();
149 console_initialised = 1;
150 /* This is also required to notify the daemon */
151 printk("done.\n");
152 }
154 void fini_console(void)
155 {
156 /* Destruct the console and get the parameters of the restarted one */
157 }