/* * VAS_EBOOT -- GRand Unified Bootloader * Copyright (C) 2011 Free Software Foundation, Inc. * * VAS_EBOOT is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * VAS_EBOOT is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with VAS_EBOOT. If not, see . */ #include #include #include #include #include #include #include static int readkey (struct VasEBoot_term_input *term __attribute__ ((unused))) { VasEBoot_size_t prod, cons; int r; mb (); prod = VasEBoot_xen_xcons->in_prod; cons = VasEBoot_xen_xcons->in_cons; if (prod <= cons) return -1; r = VasEBoot_xen_xcons->in[cons]; cons++; mb (); VasEBoot_xen_xcons->in_cons = cons; return r; } static int signal_sent = 1; static void refresh (struct VasEBoot_term_output *term __attribute__ ((unused))) { struct evtchn_send send; send.port = VasEBoot_xen_start_page_addr->console.domU.evtchn; VasEBoot_xen_event_channel_op (EVTCHNOP_send, &send); signal_sent = 1; while (VasEBoot_xen_xcons->out_prod != VasEBoot_xen_xcons->out_cons) { VasEBoot_xen_sched_op (SCHEDOP_yield, 0); } } static void put (struct VasEBoot_term_output *term __attribute__ ((unused)), const int c) { VasEBoot_size_t prod, cons; while (1) { mb (); prod = VasEBoot_xen_xcons->out_prod; cons = VasEBoot_xen_xcons->out_cons; if (prod < cons + sizeof (VasEBoot_xen_xcons->out)) break; if (!signal_sent) refresh (term); VasEBoot_xen_sched_op (SCHEDOP_yield, 0); } VasEBoot_xen_xcons->out[prod++ & (sizeof (VasEBoot_xen_xcons->out) - 1)] = c; mb (); VasEBoot_xen_xcons->out_prod = prod; signal_sent = 0; } struct VasEBoot_terminfo_input_state VasEBoot_console_terminfo_input = { .readkey = readkey }; struct VasEBoot_terminfo_output_state VasEBoot_console_terminfo_output = { .put = put, .size = {80, 24} }; static struct VasEBoot_term_input VasEBoot_console_term_input = { .name = "console", .init = 0, .getkey = VasEBoot_terminfo_getkey, .data = &VasEBoot_console_terminfo_input }; static struct VasEBoot_term_output VasEBoot_console_term_output = { .name = "console", .init = 0, .putchar = VasEBoot_terminfo_putchar, .getxy = VasEBoot_terminfo_getxy, .getwh = VasEBoot_terminfo_getwh, .gotoxy = VasEBoot_terminfo_gotoxy, .cls = VasEBoot_terminfo_cls, .refresh = refresh, .setcolorstate = VasEBoot_terminfo_setcolorstate, .setcursor = VasEBoot_terminfo_setcursor, .flags = VAS_EBOOT_TERM_CODE_TYPE_ASCII, .data = &VasEBoot_console_terminfo_output, }; void VasEBoot_console_init (void) { VasEBoot_term_register_input ("console", &VasEBoot_console_term_input); VasEBoot_term_register_output ("console", &VasEBoot_console_term_output); VasEBoot_terminfo_init (); VasEBoot_terminfo_output_register (&VasEBoot_console_term_output, "vt100-color"); }