Upgraded GRUB2 to 2.00 release.
[AROS.git] / arch / all-pc / boot / grub2-aros / grub-core / term / arc / console.c
blob45ff26760a2e8b7b1b0bf7a16c7738b2d4c08999
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/arc/arc.h>
20 #include <grub/arc/console.h>
21 #include <grub/term.h>
22 #include <grub/terminfo.h>
24 /* FIXME: use unicode. */
26 static int
27 readkey (struct grub_term_input *term __attribute__ ((unused)))
29 unsigned long count;
30 char chr;
32 if (GRUB_ARC_FIRMWARE_VECTOR->get_read_status (GRUB_ARC_STDIN))
33 return -1;
35 if (GRUB_ARC_FIRMWARE_VECTOR->read (GRUB_ARC_STDIN, &chr, 1, &count))
36 return -1;
37 if (!count)
38 return -1;
39 return chr;
42 static void
43 put (struct grub_term_output *term __attribute__ ((unused)), const int c)
45 unsigned long count;
46 char chr = c;
48 GRUB_ARC_FIRMWARE_VECTOR->write (GRUB_ARC_STDOUT, &chr, 1, &count);
51 static struct grub_terminfo_output_state grub_console_terminfo_output;
53 static grub_err_t
54 grub_console_init_output (struct grub_term_output *term)
56 struct grub_arc_display_status *info = NULL;
57 if (GRUB_ARC_SYSTEM_PARAMETER_BLOCK->firmware_vector_length
58 >= ((char *) (&GRUB_ARC_FIRMWARE_VECTOR->getdisplaystatus + 1)
59 - (char *) GRUB_ARC_FIRMWARE_VECTOR)
60 && GRUB_ARC_FIRMWARE_VECTOR->getdisplaystatus)
61 info = GRUB_ARC_FIRMWARE_VECTOR->getdisplaystatus (GRUB_ARC_STDOUT);
62 if (info)
64 grub_console_terminfo_output.width = info->w + 1;
65 grub_console_terminfo_output.height = info->h + 1;
67 grub_terminfo_output_init (term);
69 return 0;
72 static struct grub_terminfo_input_state grub_console_terminfo_input =
74 .readkey = readkey
77 static struct grub_terminfo_output_state grub_console_terminfo_output =
79 .put = put,
80 .width = 80,
81 .height = 20
84 static struct grub_term_input grub_console_term_input =
86 .name = "console",
87 .init = grub_terminfo_input_init,
88 .getkey = grub_terminfo_getkey,
89 .data = &grub_console_terminfo_input
92 static struct grub_term_output grub_console_term_output =
94 .name = "console",
95 .init = grub_console_init_output,
96 .putchar = grub_terminfo_putchar,
97 .getxy = grub_terminfo_getxy,
98 .getwh = grub_terminfo_getwh,
99 .gotoxy = grub_terminfo_gotoxy,
100 .cls = grub_terminfo_cls,
101 .setcolorstate = grub_terminfo_setcolorstate,
102 .setcursor = grub_terminfo_setcursor,
103 .flags = GRUB_TERM_CODE_TYPE_ASCII,
104 .data = &grub_console_terminfo_output,
105 .normal_color = GRUB_TERM_DEFAULT_NORMAL_COLOR,
106 .highlight_color = GRUB_TERM_DEFAULT_HIGHLIGHT_COLOR,
109 void
110 grub_console_init_early (void)
112 grub_term_register_input ("console", &grub_console_term_input);
113 grub_term_register_output ("console", &grub_console_term_output);
116 void
117 grub_console_init_lately (void)
119 grub_terminfo_init ();
120 grub_terminfo_output_register (&grub_console_term_output, "arc");