int trace (const char *format, ...) { // prep variable arguments va_list arg; va_start (arg, format); // copy formatted output to buffer int count = vsnprintf (buffer, sizeof(buffer)-1, format, arg); // term variable arguments va_end (arg); if ((count > 0) && (count < sizeof(buffer))) { // write buffer to system output/log // xen::Hypercall::console_io (buffer); HYPERVISOR_console_io(CONSOLEIO_write, count, buffer); // return the number characters written return count; } HYPERVISOR_console_io(CONSOLEIO_write, 16, "vsnprintf error\n"); return 0; }
void xenconscn_putc(dev_t dev, int c) { int s = spltty(); XENCONS_RING_IDX cons, prod; if (xendomain_is_dom0()) { u_char buf[1]; buf[0] = c; (void)HYPERVISOR_console_io(CONSOLEIO_write, 1, buf); } else { XENPRINTK(("xenconscn_putc(%c)\n", c)); cons = xencons_interface->out_cons; prod = xencons_interface->out_prod; xen_rmb(); while (prod == cons + sizeof(xencons_interface->out)) { cons = xencons_interface->out_cons; prod = xencons_interface->out_prod; xen_rmb(); } xencons_interface->out[MASK_XENCONS_IDX(xencons_interface->out_prod, xencons_interface->out)] = c; xen_rmb(); xencons_interface->out_prod++; xen_rmb(); hypervisor_notify_via_evtchn(xen_start_info.console.domU.evtchn); splx(s); } }
/* * Either for a dom0 to write to the system console, or a domU with a * debug version of Xen */ static int dom0_write_console(uint32_t vtermno, const char *str, int len) { int rc = HYPERVISOR_console_io(CONSOLEIO_write, len, (char *)str); if (rc < 0) return 0; return len; }
void print(int direct, const char *fmt, va_list args) { static char buf[1024]; (void)vsnprintf(buf, sizeof(buf), fmt, args); if(direct) { (void)HYPERVISOR_console_io(CONSOLEIO_write, strlen(buf), buf); return; } else { #ifndef USE_XEN_CONSOLE if(!console_initialised) #endif (void)HYPERVISOR_console_io(CONSOLEIO_write, strlen(buf), buf); console_print(NULL, buf, strlen(buf)); } }
static void raw_console_write(const char *str, int len) { while(len > 0) { int rc = HYPERVISOR_console_io(CONSOLEIO_write, len, (char *)str); if (rc <= 0) break; str += rc; len -= rc; } }
static void xencons_priv_interrupt(void *arg) { static char rbuf[16]; int l; while ((l = HYPERVISOR_console_io(CONSOLEIO_read, 16, rbuf)) > 0) xencons_rx(rbuf, l); xencons_tx(); }
static void kcons_write_dom0(struct console *c, const char *s, unsigned int count) { while (count > 0) { int rc; rc = HYPERVISOR_console_io( CONSOLEIO_write, count, (char *)s); if (rc <= 0) break; count -= rc; s += rc; } }
/*PRINTFLIKE1*/ void xen_printf(const char *fmt, ...) { va_list ap; va_start(ap, fmt); (void) vsnprintf(xen_printf_buffer, XEN_PRINTF_BUFSIZE, fmt, ap); va_end(ap); (void) HYPERVISOR_console_io(CONSOLEIO_write, strlen(xen_printf_buffer), xen_printf_buffer); }
/* Privileged receive callback and transmit kicker. */ static irqreturn_t xencons_priv_interrupt(int irq, void *dev_id, struct pt_regs *regs) { static char rbuf[16]; int l; while ((l = HYPERVISOR_console_io(CONSOLEIO_read, 16, rbuf)) > 0) xencons_rx(rbuf, l, regs); xencons_tx(); return IRQ_HANDLED; }
static void print(int debug, const char *fmt, va_list args, void *call_addr) { char buf[256]; char buf2[200]; int len; (void)vsnprintf(buf2, sizeof(buf2), fmt, args); len = snprintf(buf, sizeof(buf), "[%x] %s", (int) call_addr, buf2); if (configUSE_XEN_CONSOLE && !debug && console_initialised) console_print(xen_console, buf, len); else (void)HYPERVISOR_console_io(CONSOLEIO_write, len, buf); }
int xenconscn_getc(dev_t dev) { char c; int s = spltty(); XENCONS_RING_IDX cons, prod; if (xencons_console_device && xencons_console_device->polling == 0) { printf("xenconscn_getc() but not polling\n"); splx(s); return 0; } if (xendomain_is_dom0()) { while (HYPERVISOR_console_io(CONSOLEIO_read, 1, &c) == 0) ; cn_check_magic(dev, c, xencons_cnm_state); splx(s); return c; } if (xencons_console_device == NULL) { printf("xenconscn_getc(): not console\n"); while (1) ; /* loop here instead of in ddb */ splx(s); return 0; } if (xencons_console_device->polling == 0) { printf("xenconscn_getc() but not polling\n"); splx(s); return 0; } cons = xencons_interface->in_cons; prod = xencons_interface->in_prod; xen_rmb(); while (cons == prod) { HYPERVISOR_yield(); prod = xencons_interface->in_prod; } xen_rmb(); c = xencons_interface->in[MASK_XENCONS_IDX(xencons_interface->in_cons, xencons_interface->in)]; xen_rmb(); xencons_interface->in_cons = cons + 1; cn_check_magic(dev, c, xencons_cnm_state); splx(s); return c; }
/* * INITIAL C ENTRY POINT. */ void start_kernel(start_info_t *si) { static char hello[] = "Bootstrapping...\n"; (void)HYPERVISOR_console_io(CONSOLEIO_write, strlen(hello), hello); arch_init(si); trap_init(); /* print out some useful information */ printk("Mirage OS!\n"); printk(" start_info: %p(VA)\n", si); printk(" nr_pages: 0x%lx\n", si->nr_pages); printk(" shared_inf: 0x%08lx(MA)\n", si->shared_info); printk(" pt_base: %p(VA)\n", (void *)si->pt_base); printk("nr_pt_frames: 0x%lx\n", si->nr_pt_frames); printk(" mfn_list: %p(VA)\n", (void *)si->mfn_list); printk(" mod_start: 0x%lx(VA)\n", si->mod_start); printk(" mod_len: %lu\n", si->mod_len); printk(" flags: 0x%x\n", (unsigned int)si->flags); printk(" cmd_line: %s\n", si->cmd_line ? (const char *)si->cmd_line : "NULL"); /* Set up events. */ init_events(); /* ENABLE EVENT DELIVERY. This is disabled at start of day. */ __sti(); arch_print_info(); setup_xen_features(); /* Init memory management. */ init_mm(); /* Init time and timers. */ init_time(); /* Call (possibly overridden) app_main() */ app_main(&start_info); }
/* privileged receive callback */ int xencons_intr(void *p) { static char rbuf[16]; int len; struct xencons_softc *sc = p; if (sc == NULL) /* Interrupt may happen during resume */ return 1; if (sc->polling) return 1; while ((len = HYPERVISOR_console_io(CONSOLEIO_read, sizeof(rbuf), rbuf)) > 0) { xencons_tty_input(sc, rbuf, len); } return 1; }
static void __xencons_tx_flush(void) { int sz; CN_LOCK(cn_mtx); while (wc != wp) { int sent; sz = wp - wc; if (sz > (WBUF_SIZE - WBUF_MASK(wc))) sz = WBUF_SIZE - WBUF_MASK(wc); if (xen_initial_domain()) { HYPERVISOR_console_io(CONSOLEIO_write, sz, &wbuf[WBUF_MASK(wc)]); wc += sz; } else { sent = xencons_ring_send(&wbuf[WBUF_MASK(wc)], sz); if (sent == 0) break; wc += sent; } } CN_UNLOCK(cn_mtx); }
/* * INITIAL C ENTRY POINT. */ void start_kernel(start_info_t *si) { static char hello[] = "Bootstrapping...\n"; (void)HYPERVISOR_console_io(CONSOLEIO_write, strlen(hello), hello); setup_xen_features(); pvh_early_init(); arch_init(si); trap_init(); /* print out some useful information */ printk("Xen Minimal OS!\n"); printk(" start_info: %p(VA)\n", si); printk(" nr_pages: 0x%lx\n", si->nr_pages); printk(" shared_inf: 0x%08lx(MA)\n", si->shared_info); printk(" pt_base: %p(VA)\n", (void *)si->pt_base); printk("nr_pt_frames: 0x%lx\n", si->nr_pt_frames); printk(" mfn_list: %p(VA)\n", (void *)si->mfn_list); printk(" mod_start: 0x%lx(VA)\n", si->mod_start); printk(" mod_len: %lu\n", si->mod_len); printk(" flags: 0x%x\n", (unsigned int)si->flags); printk(" cmd_line: %s\n", si->cmd_line ? (const char *)si->cmd_line : "NULL"); /* Set up events. */ init_events(); /* ENABLE EVENT DELIVERY. This is disabled at start of day. */ __sti(); arch_print_info(); /* Init memory management. */ init_mm(); /* Init time and timers. */ init_time(); /* Init the console driver. */ init_console(); /* Init grant tables */ init_gnttab(); /* Init scheduler. */ init_sched(); /* Init XenBus */ init_xenbus(); #ifdef CONFIG_XENBUS /* Init shutdown thread */ init_shutdown(si); #endif /* Call (possibly overridden) app_main() */ app_main(&start_info); /* Everything initialised, start idle thread */ run_idle_thread(); }
static int dom0_read_console(uint32_t vtermno, char *buf, int len) { return HYPERVISOR_console_io(CONSOLEIO_read, len, buf); }
void ser_cons_write(const char *msg, int len) { HYPERVISOR_console_io(CONSOLEIO_write, len, (char *)msg); }
int xencons_ring_send(const char *data, unsigned len) { struct xencons_interface *intf; XENCONS_RING_IDX cons, prod; int sent; struct evtchn_send send = { .port = HYPERVISOR_start_info->console_evtchn }; intf = xencons_interface(); cons = intf->out_cons; prod = intf->out_prod; sent = 0; mb(); KASSERT((prod - cons) <= sizeof(intf->out), ("console send ring inconsistent")); while ((sent < len) && ((prod - cons) < sizeof(intf->out))) intf->out[MASK_XENCONS_IDX(prod++, intf->out)] = data[sent++]; wmb(); intf->out_prod = prod; if (cnsl_evt_reg) xen_intr_signal(console_handle); else HYPERVISOR_event_channel_op(EVTCHNOP_send, &send); return sent; } static xencons_receiver_func *xencons_receiver; void xencons_handle_input(void *unused) { struct xencons_interface *intf; XENCONS_RING_IDX cons, prod; CN_LOCK(cn_mtx); if (xen_initial_domain()) { static char rbuf[DOM0_BUFFER_SIZE]; int l; while ((l = HYPERVISOR_console_io(CONSOLEIO_read, DOM0_BUFFER_SIZE, rbuf)) > 0) xencons_rx(rbuf, l); CN_UNLOCK(cn_mtx); return; } intf = xencons_interface(); cons = intf->in_cons; prod = intf->in_prod; CN_UNLOCK(cn_mtx); /* XXX needs locking */ while (cons != prod) { xencons_rx(intf->in + MASK_XENCONS_IDX(cons, intf->in), 1); cons++; } mb(); intf->in_cons = cons; CN_LOCK(cn_mtx); xen_intr_signal(console_handle); xencons_tx(); CN_UNLOCK(cn_mtx); } void xencons_ring_register_receiver(xencons_receiver_func *f) { xencons_receiver = f; } int xencons_ring_init(void) { int err; if (HYPERVISOR_start_info->console_evtchn == 0) return 0; err = xen_intr_bind_local_port(xencons_dev, HYPERVISOR_start_info->console_evtchn, NULL, xencons_handle_input, NULL, INTR_TYPE_MISC | INTR_MPSAFE, &console_handle); if (err) { return err; } return 0; }
static void xc_cnputc_dom0(struct consdev *dev, int c) { HYPERVISOR_console_io(CONSOLEIO_write, 1, (char *)&c); }
void xencons_start(struct tty *tp) { struct clist *cl; int s; s = spltty(); if (tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP)) goto out; tp->t_state |= TS_BUSY; splx(s); /* * We need to do this outside spl since it could be fairly * expensive and we don't want our serial ports to overflow. */ cl = &tp->t_outq; if (xendomain_is_dom0()) { int len, r; u_char buf[XENCONS_BURST+1]; len = q_to_b(cl, buf, XENCONS_BURST); while (len > 0) { r = HYPERVISOR_console_io(CONSOLEIO_write, len, buf); if (r <= 0) break; len -= r; } } else { XENCONS_RING_IDX cons, prod, len; #define XNC_OUT (xencons_interface->out) cons = xencons_interface->out_cons; prod = xencons_interface->out_prod; xen_rmb(); while (prod != cons + sizeof(xencons_interface->out)) { if (MASK_XENCONS_IDX(prod, XNC_OUT) < MASK_XENCONS_IDX(cons, XNC_OUT)) { len = MASK_XENCONS_IDX(cons, XNC_OUT) - MASK_XENCONS_IDX(prod, XNC_OUT); } else { len = sizeof(XNC_OUT) - MASK_XENCONS_IDX(prod, XNC_OUT); } len = q_to_b(cl, __UNVOLATILE( &XNC_OUT[MASK_XENCONS_IDX(prod, XNC_OUT)]), len); if (len == 0) break; prod = prod + len; } xen_wmb(); xencons_interface->out_prod = prod; xen_wmb(); hypervisor_notify_via_evtchn(xen_start_info.console.domU.evtchn); #undef XNC_OUT } s = spltty(); tp->t_state &= ~TS_BUSY; if (ttypull(tp)) { tp->t_state |= TS_TIMEOUT; callout_schedule(&tp->t_rstrt_ch, 1); } out: splx(s); }
/* Main kernel entry point, called by trampoline */ void start_kernel(start_info_t * start_info) { HYPERVISOR_console_io(CONSOLEIO_write,12,"Hello World\n"); while(1); }