From e49b738ccfb422db6bbf5abb39aa6975bef8d32a Mon Sep 17 00:00:00 2001 From: Keir Fraser Date: Tue, 3 Jun 2008 09:32:50 +0100 Subject: stubdom: Add console reading support Signed-off-by: Samuel Thibault --- extras/mini-os/console/console.c | 7 ++---- extras/mini-os/console/xencons_ring.c | 44 +++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 5 deletions(-) (limited to 'extras/mini-os/console') diff --git a/extras/mini-os/console/console.c b/extras/mini-os/console/console.c index 29fdd99f3b..94379ddb33 100644 --- a/extras/mini-os/console/console.c +++ b/extras/mini-os/console/console.c @@ -49,17 +49,13 @@ of standard dom0 handled console */ #define USE_XEN_CONSOLE -/* Low level functions defined in xencons_ring.c */ -extern int xencons_ring_init(void); -extern int xencons_ring_send(const char *data, unsigned len); -extern int xencons_ring_send_no_notify(const char *data, unsigned len); - /* If console not initialised the printk will be sent to xen serial line NOTE: you need to enable verbose in xen/Rules.mk for it to work. */ static int console_initialised = 0; +#ifndef HAVE_LIBC void xencons_rx(char *buf, unsigned len, struct pt_regs *regs) { if(len > 0) @@ -77,6 +73,7 @@ void xencons_tx(void) { /* Do nothing, handled by _rx */ } +#endif void console_print(char *data, int length) diff --git a/extras/mini-os/console/xencons_ring.c b/extras/mini-os/console/xencons_ring.c index 583e4bcb92..251a4f95f1 100644 --- a/extras/mini-os/console/xencons_ring.c +++ b/extras/mini-os/console/xencons_ring.c @@ -8,6 +8,7 @@ #include #include +DECLARE_WAIT_QUEUE_HEAD(console_queue); static inline struct xencons_interface *xencons_interface(void) { @@ -52,6 +53,9 @@ int xencons_ring_send(const char *data, unsigned len) static void handle_input(evtchn_port_t port, struct pt_regs *regs, void *ign) { +#ifdef HAVE_LIBC + wake_up(&console_queue); +#else struct xencons_interface *intf = xencons_interface(); XENCONS_RING_IDX cons, prod; @@ -71,8 +75,48 @@ static void handle_input(evtchn_port_t port, struct pt_regs *regs, void *ign) notify_daemon(); xencons_tx(); +#endif } +#ifdef HAVE_LIBC +int xencons_ring_avail(void) +{ + struct xencons_interface *intf = xencons_interface(); + XENCONS_RING_IDX cons, prod; + + cons = intf->in_cons; + prod = intf->in_prod; + mb(); + BUG_ON((prod - cons) > sizeof(intf->in)); + + return prod - cons; +} + +int xencons_ring_recv(char *data, unsigned len) +{ + struct xencons_interface *intf = xencons_interface(); + XENCONS_RING_IDX cons, prod; + unsigned filled = 0; + + cons = intf->in_cons; + prod = intf->in_prod; + mb(); + BUG_ON((prod - cons) > sizeof(intf->in)); + + while (filled < len && cons + filled != prod) { + data[filled] = *(intf->in + MASK_XENCONS_IDX(cons + filled, intf->in)); + filled++; + } + + mb(); + intf->in_cons = cons + filled; + + notify_daemon(); + + return filled; +} +#endif + int xencons_ring_init(void) { int err; -- cgit v1.2.3