Indentation fix, cleanup.
[AROS.git] / arch / all-pc / boot / grub2-aros / grub-core / term / xen / console.c
bloba1f15f71a6d1f11b6187fb3b767d68ae04906ecd
1 /*
2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2011 Free Software Foundation, Inc.
5 * GRUB is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * GRUB is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
19 #include <grub/term.h>
20 #include <grub/types.h>
21 #include <grub/misc.h>
22 #include <grub/mm.h>
23 #include <grub/time.h>
24 #include <grub/terminfo.h>
25 #include <grub/xen.h>
27 static int
28 readkey (struct grub_term_input *term __attribute__ ((unused)))
30 grub_size_t prod, cons;
31 int r;
32 mb ();
33 prod = grub_xen_xcons->in_prod;
34 cons = grub_xen_xcons->in_cons;
35 if (prod <= cons)
36 return -1;
37 r = grub_xen_xcons->in[cons];
38 cons++;
39 mb ();
40 grub_xen_xcons->in_cons = cons;
41 return r;
44 static int signal_sent = 1;
46 static void
47 refresh (struct grub_term_output *term __attribute__ ((unused)))
49 struct evtchn_send send;
50 send.port = grub_xen_start_page_addr->console.domU.evtchn;
51 grub_xen_event_channel_op (EVTCHNOP_send, &send);
52 signal_sent = 1;
53 while (grub_xen_xcons->out_prod != grub_xen_xcons->out_cons)
55 grub_xen_sched_op (SCHEDOP_yield, 0);
59 static void
60 put (struct grub_term_output *term __attribute__ ((unused)), const int c)
62 grub_size_t prod, cons;
64 while (1)
66 mb ();
67 prod = grub_xen_xcons->out_prod;
68 cons = grub_xen_xcons->out_cons;
69 if (prod < cons + sizeof (grub_xen_xcons->out))
70 break;
71 if (!signal_sent)
72 refresh (term);
73 grub_xen_sched_op (SCHEDOP_yield, 0);
75 grub_xen_xcons->out[prod++ & (sizeof (grub_xen_xcons->out) - 1)] = c;
76 mb ();
77 grub_xen_xcons->out_prod = prod;
78 signal_sent = 0;
82 struct grub_terminfo_input_state grub_console_terminfo_input = {
83 .readkey = readkey
86 struct grub_terminfo_output_state grub_console_terminfo_output = {
87 .put = put,
88 .size = {80, 24}
91 static struct grub_term_input grub_console_term_input = {
92 .name = "console",
93 .init = 0,
94 .getkey = grub_terminfo_getkey,
95 .data = &grub_console_terminfo_input
98 static struct grub_term_output grub_console_term_output = {
99 .name = "console",
100 .init = 0,
101 .putchar = grub_terminfo_putchar,
102 .getxy = grub_terminfo_getxy,
103 .getwh = grub_terminfo_getwh,
104 .gotoxy = grub_terminfo_gotoxy,
105 .cls = grub_terminfo_cls,
106 .refresh = refresh,
107 .setcolorstate = grub_terminfo_setcolorstate,
108 .setcursor = grub_terminfo_setcursor,
109 .flags = GRUB_TERM_CODE_TYPE_ASCII,
110 .data = &grub_console_terminfo_output,
114 void
115 grub_console_init (void)
117 grub_term_register_input ("console", &grub_console_term_input);
118 grub_term_register_output ("console", &grub_console_term_output);
120 grub_terminfo_init ();
121 grub_terminfo_output_register (&grub_console_term_output, "vt100-color");