ia64/xen-unstable

view extras/mini-os/console/console.c @ 15281:736e7cf0a3a5

Fix pv-on-hvm mkbuildtree script for new repo layout.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Wed Jun 06 17:32:58 2007 +0100 (2007-06-06)
parents aab3cd33d2ba
children 5c38568d90df
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
52 /* Low level functions defined in xencons_ring.c */
53 extern int xencons_ring_init(void);
54 extern int xencons_ring_send(const char *data, unsigned len);
55 extern int xencons_ring_send_no_notify(const char *data, unsigned len);
58 /* If console not initialised the printk will be sent to xen serial line
59 NOTE: you need to enable verbose in xen/Rules.mk for it to work. */
60 static int console_initialised = 0;
63 void xencons_rx(char *buf, unsigned len, struct pt_regs *regs)
64 {
65 if(len > 0)
66 {
67 /* Just repeat what's written */
68 buf[len] = '\0';
69 printk("%s", buf);
71 if(buf[len-1] == '\r')
72 printk("\nNo console input handler.\n");
73 }
74 }
76 void xencons_tx(void)
77 {
78 /* Do nothing, handled by _rx */
79 }
82 void console_print(char *data, int length)
83 {
84 char *curr_char, saved_char;
85 int part_len;
86 int (*ring_send_fn)(const char *data, unsigned length);
88 if(!console_initialised)
89 ring_send_fn = xencons_ring_send_no_notify;
90 else
91 ring_send_fn = xencons_ring_send;
93 for(curr_char = data; curr_char < data+length-1; curr_char++)
94 {
95 if(*curr_char == '\n')
96 {
97 saved_char = *(curr_char+1);
98 *(curr_char+1) = '\r';
99 part_len = curr_char - data + 2;
100 ring_send_fn(data, part_len);
101 *(curr_char+1) = saved_char;
102 data = curr_char+1;
103 length -= part_len - 1;
104 }
105 }
107 ring_send_fn(data, length);
109 if(data[length-1] == '\n')
110 ring_send_fn("\r", 1);
111 }
113 void print(int direct, const char *fmt, va_list args)
114 {
115 static char buf[1024];
117 (void)vsnprintf(buf, sizeof(buf), fmt, args);
119 if(direct)
120 {
121 (void)HYPERVISOR_console_io(CONSOLEIO_write, strlen(buf), buf);
122 return;
123 } else {
124 #ifndef USE_XEN_CONSOLE
125 if(!console_initialised)
126 #endif
127 (void)HYPERVISOR_console_io(CONSOLEIO_write, strlen(buf), buf);
129 console_print(buf, strlen(buf));
130 }
131 }
133 void printk(const char *fmt, ...)
134 {
135 va_list args;
136 va_start(args, fmt);
137 print(0, fmt, args);
138 va_end(args);
139 }
141 void xprintk(const char *fmt, ...)
142 {
143 va_list args;
144 va_start(args, fmt);
145 print(1, fmt, args);
146 va_end(args);
147 }
148 void init_console(void)
149 {
150 printk("Initialising console ... ");
151 xencons_ring_init();
152 console_initialised = 1;
153 /* This is also required to notify the daemon */
154 printk("done.\n");
155 }