2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2013 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>
23 #include <grub/time.h>
24 #include <grub/terminfo.h>
26 #include <grub/i386/coreboot/lbio.h>
27 #include <grub/command.h>
28 #include <grub/normal.h>
30 GRUB_MOD_LICENSE ("GPLv3+");
32 struct grub_linuxbios_cbmemc
35 grub_uint32_t pointer
;
39 static struct grub_linuxbios_cbmemc
*cbmemc
;
42 put (struct grub_term_output
*term
__attribute__ ((unused
)), const int c
)
46 if (cbmemc
->pointer
< cbmemc
->size
)
47 cbmemc
->data
[cbmemc
->pointer
] = c
;
51 struct grub_terminfo_output_state grub_cbmemc_terminfo_output
=
57 static struct grub_term_output grub_cbmemc_term_output
=
60 .init
= grub_terminfo_output_init
,
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
,
74 iterate_linuxbios_table (grub_linuxbios_table_item_t table_item
,
75 void *data
__attribute__ ((unused
)))
77 if (table_item
->tag
!= GRUB_LINUXBIOS_MEMBER_CBMEMC
)
79 cbmemc
= (struct grub_linuxbios_cbmemc
*) (grub_addr_t
)
80 *(grub_uint64_t
*) (table_item
+ 1);
85 grub_cmd_cbmemc (struct grub_command
*cmd
__attribute__ ((unused
)),
86 int argc
__attribute__ ((unused
)),
87 char *argv
[] __attribute__ ((unused
)))
91 struct grub_linuxbios_cbmemc
*cbmemc_saved
;
94 return grub_error (GRUB_ERR_IO
, "no CBMEM console found");
96 len
= cbmemc
->pointer
;
97 if (len
> cbmemc
->size
)
100 cbmemc_saved
= cbmemc
;
102 grub_xnputs (str
, len
);
103 cbmemc
= cbmemc_saved
;
107 static grub_command_t cmd
;
109 GRUB_MOD_INIT (cbmemc
)
111 grub_linuxbios_table_iterate (iterate_linuxbios_table
, 0);
114 grub_term_register_output ("cbmemc", &grub_cbmemc_term_output
);
117 grub_register_command ("cbmemc", grub_cmd_cbmemc
,
118 0, N_("Show CBMEM console content."));
122 GRUB_MOD_FINI (cbmemc
)
124 grub_term_unregister_output (&grub_cbmemc_term_output
);
125 grub_unregister_command (cmd
);