]> git.proxmox.com Git - grub2.git/blob - grub-core/term/i386/coreboot/cbmemc.c
Lift 255x255 erminal sie restriction to 65535x65535. Also change from
[grub2.git] / grub-core / term / i386 / coreboot / cbmemc.c
1 /*
2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2013 Free Software Foundation, Inc.
4 *
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.
9 *
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.
14 *
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/>.
17 */
18
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/dl.h>
26 #include <grub/i386/coreboot/lbio.h>
27 #include <grub/command.h>
28 #include <grub/normal.h>
29
30 GRUB_MOD_LICENSE ("GPLv3+");
31
32 struct grub_linuxbios_cbmemc
33 {
34 grub_uint32_t size;
35 grub_uint32_t pointer;
36 char data[0];
37 };
38
39 static struct grub_linuxbios_cbmemc *cbmemc;
40
41 static void
42 put (struct grub_term_output *term __attribute__ ((unused)), const int c)
43 {
44 if (!cbmemc)
45 return;
46 if (cbmemc->pointer < cbmemc->size)
47 cbmemc->data[cbmemc->pointer] = c;
48 cbmemc->pointer++;
49 }
50
51 struct grub_terminfo_output_state grub_cbmemc_terminfo_output =
52 {
53 .put = put,
54 .size = { 80, 24 }
55 };
56
57 static struct grub_term_output grub_cbmemc_term_output =
58 {
59 .name = "cbmemc",
60 .init = grub_terminfo_output_init,
61 .fini = 0,
62 .putchar = grub_terminfo_putchar,
63 .getxy = grub_terminfo_getxy,
64 .getwh = grub_terminfo_getwh,
65 .gotoxy = grub_terminfo_gotoxy,
66 .cls = grub_terminfo_cls,
67 .setcolorstate = grub_terminfo_setcolorstate,
68 .setcursor = grub_terminfo_setcursor,
69 .flags = GRUB_TERM_CODE_TYPE_ASCII,
70 .data = &grub_cbmemc_terminfo_output,
71 };
72
73 static int
74 iterate_linuxbios_table (grub_linuxbios_table_item_t table_item,
75 void *data __attribute__ ((unused)))
76 {
77 if (table_item->tag != GRUB_LINUXBIOS_MEMBER_CBMEMC)
78 return 0;
79 cbmemc = (struct grub_linuxbios_cbmemc *) (grub_addr_t)
80 *(grub_uint64_t *) (table_item + 1);
81 return 1;
82 }
83
84 static grub_err_t
85 grub_cmd_cbmemc (struct grub_command *cmd __attribute__ ((unused)),
86 int argc __attribute__ ((unused)),
87 char *argv[] __attribute__ ((unused)))
88 {
89 grub_size_t len;
90 char *str;
91 struct grub_linuxbios_cbmemc *cbmemc_saved;
92
93 if (!cbmemc)
94 return grub_error (GRUB_ERR_IO, "no CBMEM console found");
95
96 len = cbmemc->pointer;
97 if (len > cbmemc->size)
98 len = cbmemc->size;
99 str = cbmemc->data;
100 cbmemc_saved = cbmemc;
101 cbmemc = 0;
102 grub_xnputs (str, len);
103 cbmemc = cbmemc_saved;
104 return 0;
105 }
106
107 static grub_command_t cmd;
108
109 GRUB_MOD_INIT (cbmemc)
110 {
111 grub_linuxbios_table_iterate (iterate_linuxbios_table, 0);
112
113 if (cbmemc)
114 grub_term_register_output ("cbmemc", &grub_cbmemc_term_output);
115
116 cmd =
117 grub_register_command ("cbmemc", grub_cmd_cbmemc,
118 0, N_("Show CBMEM console content."));
119 }
120
121
122 GRUB_MOD_FINI (cbmemc)
123 {
124 grub_term_unregister_output (&grub_cbmemc_term_output);
125 grub_unregister_command (cmd);
126 }