vaseboot/VasEBoot-core/term/uboot/console.c

133 lines
3.5 KiB
C

/* console.c - console interface layer for U-Boot platforms */
/*
* 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/misc.h>
#include <VasEBoot/types.h>
#include <VasEBoot/err.h>
#include <VasEBoot/terminfo.h>
#include <VasEBoot/uboot/uboot.h>
#include <VasEBoot/uboot/console.h>
static void
put (struct VasEBoot_term_output *term __attribute__ ((unused)), const int c)
{
VasEBoot_uboot_putc (c);
}
static int
readkey (struct VasEBoot_term_input *term __attribute__ ((unused)))
{
if (VasEBoot_uboot_tstc () > 0)
return VasEBoot_uboot_getc ();
return -1;
}
static void
uboot_console_setcursor (struct VasEBoot_term_output *term
__attribute__ ((unused)), int on
__attribute__ ((unused)))
{
VasEBoot_terminfo_setcursor (term, on);
}
static VasEBoot_err_t
uboot_console_init_input (struct VasEBoot_term_input *term)
{
return VasEBoot_terminfo_input_init (term);
}
extern struct VasEBoot_terminfo_output_state uboot_console_terminfo_output;
static VasEBoot_err_t
uboot_console_init_output (struct VasEBoot_term_output *term)
{
VasEBoot_terminfo_output_init (term);
return 0;
}
struct VasEBoot_terminfo_input_state uboot_console_terminfo_input = {
.readkey = readkey
};
struct VasEBoot_terminfo_output_state uboot_console_terminfo_output = {
.put = put,
/* FIXME: In rare cases when console isn't serial,
determine real width. */
.size = { 80, 24 }
};
static struct VasEBoot_term_input uboot_console_term_input = {
.name = "console",
.init = uboot_console_init_input,
.getkey = VasEBoot_terminfo_getkey,
.data = &uboot_console_terminfo_input
};
static struct VasEBoot_term_output uboot_console_term_output = {
.name = "console",
.init = uboot_console_init_output,
.putchar = VasEBoot_terminfo_putchar,
.getwh = VasEBoot_terminfo_getwh,
.getxy = VasEBoot_terminfo_getxy,
.gotoxy = VasEBoot_terminfo_gotoxy,
.cls = VasEBoot_terminfo_cls,
.setcolorstate = VasEBoot_terminfo_setcolorstate,
.setcursor = uboot_console_setcursor,
.flags = VAS_EBOOT_TERM_CODE_TYPE_ASCII,
.data = &uboot_console_terminfo_output,
.progress_update_divisor = VAS_EBOOT_PROGRESS_FAST
};
void
VasEBoot_console_init_early (void)
{
VasEBoot_term_register_input ("console", &uboot_console_term_input);
VasEBoot_term_register_output ("console", &uboot_console_term_output);
}
/*
* VasEBoot_console_init_lately():
* Initializes terminfo formatting by registering terminal type.
* Called after heap has been configured.
*
*/
void
VasEBoot_console_init_lately (void)
{
const char *type;
/* See if explicitly set by U-Boot environment */
type = VasEBoot_uboot_env_get ("VasEBoot_term");
if (!type)
type = "vt100";
VasEBoot_terminfo_init ();
VasEBoot_terminfo_output_register (&uboot_console_term_output, type);
}
void
VasEBoot_console_fini (void)
{
}