148 lines
4.0 KiB
C
148 lines
4.0 KiB
C
/*
|
|
* VAS_EBOOT -- GRand Unified Bootloader
|
|
* Copyright (C) 2013 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 <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include <VasEBoot/term.h>
|
|
#include <VasEBoot/types.h>
|
|
#include <VasEBoot/misc.h>
|
|
#include <VasEBoot/mm.h>
|
|
#include <VasEBoot/time.h>
|
|
#include <VasEBoot/terminfo.h>
|
|
#include <VasEBoot/dl.h>
|
|
#include <VasEBoot/coreboot/lbio.h>
|
|
#include <VasEBoot/command.h>
|
|
#include <VasEBoot/normal.h>
|
|
|
|
VAS_EBOOT_MOD_LICENSE ("GPLv3+");
|
|
|
|
#define CURSOR_MASK ((1 << 28) - 1)
|
|
#define OVERFLOW (1 << 31)
|
|
|
|
struct VasEBoot_linuxbios_cbmemc
|
|
{
|
|
VasEBoot_uint32_t size;
|
|
VasEBoot_uint32_t cursor;
|
|
char body[0];
|
|
};
|
|
|
|
static struct VasEBoot_linuxbios_cbmemc *cbmemc;
|
|
|
|
static void
|
|
put (struct VasEBoot_term_output *term __attribute__ ((unused)), const int c)
|
|
{
|
|
VasEBoot_uint32_t flags, cursor;
|
|
if (!cbmemc)
|
|
return;
|
|
flags = cbmemc->cursor & ~CURSOR_MASK;
|
|
cursor = cbmemc->cursor & CURSOR_MASK;
|
|
if (cursor >= cbmemc->size)
|
|
return;
|
|
cbmemc->body[cursor++] = c;
|
|
if (cursor >= cbmemc->size)
|
|
{
|
|
cursor = 0;
|
|
flags |= OVERFLOW;
|
|
}
|
|
cbmemc->cursor = flags | cursor;
|
|
}
|
|
|
|
struct VasEBoot_terminfo_output_state VasEBoot_cbmemc_terminfo_output =
|
|
{
|
|
.put = put,
|
|
.size = { 80, 24 }
|
|
};
|
|
|
|
static struct VasEBoot_term_output VasEBoot_cbmemc_term_output =
|
|
{
|
|
.name = "cbmemc",
|
|
.init = VasEBoot_terminfo_output_init,
|
|
.fini = 0,
|
|
.putchar = VasEBoot_terminfo_putchar,
|
|
.getxy = VasEBoot_terminfo_getxy,
|
|
.getwh = VasEBoot_terminfo_getwh,
|
|
.gotoxy = VasEBoot_terminfo_gotoxy,
|
|
.cls = VasEBoot_terminfo_cls,
|
|
.setcolorstate = VasEBoot_terminfo_setcolorstate,
|
|
.setcursor = VasEBoot_terminfo_setcursor,
|
|
.flags = VAS_EBOOT_TERM_CODE_TYPE_ASCII,
|
|
.data = &VasEBoot_cbmemc_terminfo_output,
|
|
.progress_update_divisor = VAS_EBOOT_PROGRESS_NO_UPDATE
|
|
};
|
|
|
|
static int
|
|
iterate_linuxbios_table (VasEBoot_linuxbios_table_item_t table_item,
|
|
void *data __attribute__ ((unused)))
|
|
{
|
|
if (table_item->tag != VAS_EBOOT_LINUXBIOS_MEMBER_CBMEMC)
|
|
return 0;
|
|
cbmemc = (struct VasEBoot_linuxbios_cbmemc *) (VasEBoot_addr_t)
|
|
*(VasEBoot_uint64_t *) (table_item + 1);
|
|
return 1;
|
|
}
|
|
|
|
static VasEBoot_err_t
|
|
VasEBoot_cmd_cbmemc (struct VasEBoot_command *cmd __attribute__ ((unused)),
|
|
int argc __attribute__ ((unused)),
|
|
char *argv[] __attribute__ ((unused)))
|
|
{
|
|
VasEBoot_size_t size, cursor;
|
|
struct VasEBoot_linuxbios_cbmemc *real_cbmemc;
|
|
|
|
if (!cbmemc)
|
|
return VasEBoot_error (VAS_EBOOT_ERR_IO, "no CBMEM console found");
|
|
|
|
real_cbmemc = cbmemc;
|
|
cbmemc = 0;
|
|
cursor = real_cbmemc->cursor & CURSOR_MASK;
|
|
if (!(real_cbmemc->cursor & OVERFLOW) && cursor < real_cbmemc->size)
|
|
size = cursor;
|
|
else
|
|
size = real_cbmemc->size;
|
|
if (real_cbmemc->cursor & OVERFLOW)
|
|
{
|
|
if (cursor > size)
|
|
cursor = 0;
|
|
VasEBoot_xnputs(real_cbmemc->body + cursor, size - cursor);
|
|
VasEBoot_xnputs(real_cbmemc->body, cursor);
|
|
}
|
|
else
|
|
VasEBoot_xnputs(real_cbmemc->body, size);
|
|
cbmemc = real_cbmemc;
|
|
return 0;
|
|
}
|
|
|
|
static VasEBoot_command_t cmd;
|
|
|
|
VAS_EBOOT_MOD_INIT (cbmemc)
|
|
{
|
|
VasEBoot_linuxbios_table_iterate (iterate_linuxbios_table, 0);
|
|
|
|
if (cbmemc)
|
|
VasEBoot_term_register_output ("cbmemc", &VasEBoot_cbmemc_term_output);
|
|
|
|
cmd =
|
|
VasEBoot_register_command ("cbmemc", VasEBoot_cmd_cbmemc,
|
|
0, N_("Show CBMEM console content."));
|
|
}
|
|
|
|
|
|
VAS_EBOOT_MOD_FINI (cbmemc)
|
|
{
|
|
VasEBoot_term_unregister_output (&VasEBoot_cbmemc_term_output);
|
|
VasEBoot_unregister_command (cmd);
|
|
}
|