2004-04-04 Yoshinori K. Okuji <okuji@enbug.org>
All symbols prefixed with PUPA_ and pupa_ are renamed to GRUB_ and grub_, respectively. Because the conversion is trivial and mechanical, I omit the details here. Please refer to the CVS if you need more information.
This commit is contained in:
parent
6a1425510d
commit
4b13b216f4
125 changed files with 6198 additions and 6181 deletions
|
@ -1,6 +1,6 @@
|
|||
/* ofconsole.c -- Open Firmware console for PUPA. */
|
||||
/* ofconsole.c -- Open Firmware console for GRUB. */
|
||||
/*
|
||||
* PUPA -- Preliminary Universal Programming Architecture for GRUB
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
|
@ -18,20 +18,20 @@
|
|||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <pupa/machine/console.h>
|
||||
#include <pupa/machine/ieee1275.h>
|
||||
#include <pupa/term.h>
|
||||
#include <pupa/types.h>
|
||||
#include <pupa/misc.h>
|
||||
#include <grub/machine/console.h>
|
||||
#include <grub/machine/ieee1275.h>
|
||||
#include <grub/term.h>
|
||||
#include <grub/types.h>
|
||||
#include <grub/misc.h>
|
||||
|
||||
static pupa_ieee1275_ihandle_t stdout_ihandle;
|
||||
static pupa_ieee1275_ihandle_t stdin_ihandle;
|
||||
static grub_ieee1275_ihandle_t stdout_ihandle;
|
||||
static grub_ieee1275_ihandle_t stdin_ihandle;
|
||||
|
||||
static int pupa_curr_x;
|
||||
static int pupa_curr_y;
|
||||
static int grub_curr_x;
|
||||
static int grub_curr_y;
|
||||
|
||||
static int pupa_keybuf;
|
||||
static int pupa_buflen;
|
||||
static int grub_keybuf;
|
||||
static int grub_buflen;
|
||||
|
||||
struct color
|
||||
{
|
||||
|
@ -58,32 +58,32 @@ static int bgcolor = 0;
|
|||
|
||||
/* Write control characters to the console. */
|
||||
static void
|
||||
pupa_ofconsole_writeesc (const char *str)
|
||||
grub_ofconsole_writeesc (const char *str)
|
||||
{
|
||||
while (*str)
|
||||
{
|
||||
char chr = *(str++);
|
||||
pupa_ieee1275_write (stdout_ihandle, &chr, 1, 0);
|
||||
grub_ieee1275_write (stdout_ihandle, &chr, 1, 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
pupa_ofconsole_putchar (pupa_uint32_t c)
|
||||
grub_ofconsole_putchar (grub_uint32_t c)
|
||||
{
|
||||
char chr = c;
|
||||
if (c == '\n')
|
||||
{
|
||||
pupa_curr_y++;
|
||||
pupa_curr_x = 0;
|
||||
grub_curr_y++;
|
||||
grub_curr_x = 0;
|
||||
}
|
||||
else
|
||||
pupa_curr_x++;
|
||||
pupa_ieee1275_write (stdout_ihandle, &chr, 1, 0);
|
||||
grub_curr_x++;
|
||||
grub_ieee1275_write (stdout_ihandle, &chr, 1, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
pupa_ofconsole_setcolorstate (pupa_term_color_state state)
|
||||
grub_ofconsole_setcolorstate (grub_term_color_state state)
|
||||
{
|
||||
char setcol[20];
|
||||
int fg;
|
||||
|
@ -91,12 +91,12 @@ pupa_ofconsole_setcolorstate (pupa_term_color_state state)
|
|||
|
||||
switch (state)
|
||||
{
|
||||
case PUPA_TERM_COLOR_STANDARD:
|
||||
case PUPA_TERM_COLOR_NORMAL:
|
||||
case GRUB_TERM_COLOR_STANDARD:
|
||||
case GRUB_TERM_COLOR_NORMAL:
|
||||
fg = fgcolor;
|
||||
bg = bgcolor;
|
||||
break;
|
||||
case PUPA_TERM_COLOR_HIGHLIGHT:
|
||||
case GRUB_TERM_COLOR_HIGHLIGHT:
|
||||
fg = bgcolor;
|
||||
bg = fgcolor;
|
||||
break;
|
||||
|
@ -104,29 +104,29 @@ pupa_ofconsole_setcolorstate (pupa_term_color_state state)
|
|||
return;
|
||||
}
|
||||
|
||||
pupa_sprintf (setcol, "\e[3%dm\e[4%dm", fg, bg);
|
||||
pupa_ofconsole_writeesc (setcol);
|
||||
grub_sprintf (setcol, "\e[3%dm\e[4%dm", fg, bg);
|
||||
grub_ofconsole_writeesc (setcol);
|
||||
}
|
||||
|
||||
static void
|
||||
pupa_ofconsole_setcolor (pupa_uint8_t normal_color,
|
||||
pupa_uint8_t highlight_color)
|
||||
grub_ofconsole_setcolor (grub_uint8_t normal_color,
|
||||
grub_uint8_t highlight_color)
|
||||
{
|
||||
fgcolor = normal_color;
|
||||
bgcolor = highlight_color;
|
||||
}
|
||||
|
||||
static int
|
||||
pupa_ofconsole_readkey (int *key)
|
||||
grub_ofconsole_readkey (int *key)
|
||||
{
|
||||
char c;
|
||||
int actual = 0;
|
||||
|
||||
pupa_ieee1275_read (stdin_ihandle, &c, 1, &actual);
|
||||
grub_ieee1275_read (stdin_ihandle, &c, 1, &actual);
|
||||
|
||||
if (actual && c == '\e')
|
||||
{
|
||||
pupa_ieee1275_read (stdin_ihandle, &c, 1, &actual);
|
||||
grub_ieee1275_read (stdin_ihandle, &c, 1, &actual);
|
||||
if (! actual)
|
||||
{
|
||||
*key = '\e';
|
||||
|
@ -136,7 +136,7 @@ pupa_ofconsole_readkey (int *key)
|
|||
if (c != 91)
|
||||
return 0;
|
||||
|
||||
pupa_ieee1275_read (stdin_ihandle, &c, 1, &actual);
|
||||
grub_ieee1275_read (stdin_ihandle, &c, 1, &actual);
|
||||
if (! actual)
|
||||
return 0;
|
||||
|
||||
|
@ -166,19 +166,19 @@ pupa_ofconsole_readkey (int *key)
|
|||
}
|
||||
|
||||
static int
|
||||
pupa_ofconsole_checkkey (void)
|
||||
grub_ofconsole_checkkey (void)
|
||||
{
|
||||
int key;
|
||||
int read;
|
||||
|
||||
if (pupa_buflen)
|
||||
if (grub_buflen)
|
||||
return 1;
|
||||
|
||||
read = pupa_ofconsole_readkey (&key);
|
||||
read = grub_ofconsole_readkey (&key);
|
||||
if (read)
|
||||
{
|
||||
pupa_keybuf = key;
|
||||
pupa_buflen = 1;
|
||||
grub_keybuf = key;
|
||||
grub_buflen = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -186,123 +186,123 @@ pupa_ofconsole_checkkey (void)
|
|||
}
|
||||
|
||||
static int
|
||||
pupa_ofconsole_getkey (void)
|
||||
grub_ofconsole_getkey (void)
|
||||
{
|
||||
int key;
|
||||
|
||||
if (pupa_buflen)
|
||||
if (grub_buflen)
|
||||
{
|
||||
pupa_buflen =0;
|
||||
return pupa_keybuf;
|
||||
grub_buflen =0;
|
||||
return grub_keybuf;
|
||||
}
|
||||
|
||||
while (! pupa_ofconsole_readkey (&key));
|
||||
while (! grub_ofconsole_readkey (&key));
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
static pupa_uint16_t
|
||||
pupa_ofconsole_getxy (void)
|
||||
static grub_uint16_t
|
||||
grub_ofconsole_getxy (void)
|
||||
{
|
||||
return ((pupa_curr_x - 1) << 8) | pupa_curr_y;
|
||||
return ((grub_curr_x - 1) << 8) | grub_curr_y;
|
||||
}
|
||||
|
||||
static void
|
||||
pupa_ofconsole_gotoxy (pupa_uint8_t x, pupa_uint8_t y)
|
||||
grub_ofconsole_gotoxy (grub_uint8_t x, grub_uint8_t y)
|
||||
{
|
||||
char s[11]; /* 5 + 3 + 3. */
|
||||
pupa_curr_x = x;
|
||||
pupa_curr_y = y;
|
||||
grub_curr_x = x;
|
||||
grub_curr_y = y;
|
||||
|
||||
pupa_sprintf (s, "\e[%d;%dH", y - 1, x + 1);
|
||||
pupa_ofconsole_writeesc (s);
|
||||
grub_sprintf (s, "\e[%d;%dH", y - 1, x + 1);
|
||||
grub_ofconsole_writeesc (s);
|
||||
}
|
||||
|
||||
static void
|
||||
pupa_ofconsole_cls (void)
|
||||
grub_ofconsole_cls (void)
|
||||
{
|
||||
/* Clear the screen. */
|
||||
pupa_ofconsole_writeesc ("");
|
||||
grub_ofconsole_writeesc ("");
|
||||
}
|
||||
|
||||
static void
|
||||
pupa_ofconsole_setcursor (int on __attribute ((unused)))
|
||||
grub_ofconsole_setcursor (int on __attribute ((unused)))
|
||||
{
|
||||
/* XXX: Not supported. */
|
||||
}
|
||||
|
||||
static void
|
||||
pupa_ofconsole_refresh (void)
|
||||
grub_ofconsole_refresh (void)
|
||||
{
|
||||
/* Do nothing, the current console state is ok. */
|
||||
}
|
||||
|
||||
static pupa_err_t
|
||||
pupa_ofconsole_init (void)
|
||||
static grub_err_t
|
||||
grub_ofconsole_init (void)
|
||||
{
|
||||
pupa_ieee1275_phandle_t chosen;
|
||||
grub_ieee1275_phandle_t chosen;
|
||||
char data[4];
|
||||
pupa_size_t actual;
|
||||
grub_size_t actual;
|
||||
int col;
|
||||
|
||||
if (pupa_ieee1275_finddevice ("/chosen", &chosen))
|
||||
return pupa_error (PUPA_ERR_UNKNOWN_DEVICE, "Cannot find /chosen");
|
||||
if (grub_ieee1275_finddevice ("/chosen", &chosen))
|
||||
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "Cannot find /chosen");
|
||||
|
||||
if (pupa_ieee1275_get_property (chosen, "stdout", data, sizeof data,
|
||||
if (grub_ieee1275_get_property (chosen, "stdout", data, sizeof data,
|
||||
&actual)
|
||||
|| actual != sizeof data)
|
||||
return pupa_error (PUPA_ERR_UNKNOWN_DEVICE, "Cannot find stdout");
|
||||
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "Cannot find stdout");
|
||||
|
||||
stdout_ihandle = pupa_ieee1275_decode_int_4 (data);
|
||||
stdout_ihandle = grub_ieee1275_decode_int_4 (data);
|
||||
|
||||
if (pupa_ieee1275_get_property (chosen, "stdin", data, sizeof data,
|
||||
if (grub_ieee1275_get_property (chosen, "stdin", data, sizeof data,
|
||||
&actual)
|
||||
|| actual != sizeof data)
|
||||
return pupa_error (PUPA_ERR_UNKNOWN_DEVICE, "Cannot find stdin");
|
||||
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "Cannot find stdin");
|
||||
|
||||
stdin_ihandle = pupa_ieee1275_decode_int_4 (data);
|
||||
stdin_ihandle = grub_ieee1275_decode_int_4 (data);
|
||||
|
||||
/* Initialize colors. */
|
||||
for (col = 0; col < 7; col++)
|
||||
pupa_ieee1275_set_color (stdout_ihandle, col, colors[col].red,
|
||||
grub_ieee1275_set_color (stdout_ihandle, col, colors[col].red,
|
||||
colors[col].green, colors[col].blue);
|
||||
|
||||
/* Set the right fg and bg colors. */
|
||||
pupa_ofconsole_setcolorstate (PUPA_TERM_COLOR_NORMAL);
|
||||
grub_ofconsole_setcolorstate (GRUB_TERM_COLOR_NORMAL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static pupa_err_t
|
||||
pupa_ofconsole_fini (void)
|
||||
static grub_err_t
|
||||
grub_ofconsole_fini (void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static struct pupa_term pupa_ofconsole_term =
|
||||
static struct grub_term grub_ofconsole_term =
|
||||
{
|
||||
.name = "ofconsole",
|
||||
.init = pupa_ofconsole_init,
|
||||
.fini = pupa_ofconsole_fini,
|
||||
.putchar = pupa_ofconsole_putchar,
|
||||
.checkkey = pupa_ofconsole_checkkey,
|
||||
.getkey = pupa_ofconsole_getkey,
|
||||
.getxy = pupa_ofconsole_getxy,
|
||||
.gotoxy = pupa_ofconsole_gotoxy,
|
||||
.cls = pupa_ofconsole_cls,
|
||||
.setcolorstate = pupa_ofconsole_setcolorstate,
|
||||
.setcolor = pupa_ofconsole_setcolor,
|
||||
.setcursor = pupa_ofconsole_setcursor,
|
||||
.refresh = pupa_ofconsole_refresh,
|
||||
.init = grub_ofconsole_init,
|
||||
.fini = grub_ofconsole_fini,
|
||||
.putchar = grub_ofconsole_putchar,
|
||||
.checkkey = grub_ofconsole_checkkey,
|
||||
.getkey = grub_ofconsole_getkey,
|
||||
.getxy = grub_ofconsole_getxy,
|
||||
.gotoxy = grub_ofconsole_gotoxy,
|
||||
.cls = grub_ofconsole_cls,
|
||||
.setcolorstate = grub_ofconsole_setcolorstate,
|
||||
.setcolor = grub_ofconsole_setcolor,
|
||||
.setcursor = grub_ofconsole_setcursor,
|
||||
.refresh = grub_ofconsole_refresh,
|
||||
.flags = 0,
|
||||
.next = 0
|
||||
};
|
||||
|
||||
void
|
||||
pupa_console_init (void)
|
||||
grub_console_init (void)
|
||||
{
|
||||
pupa_term_register (&pupa_ofconsole_term);
|
||||
pupa_term_set_current (&pupa_ofconsole_term);
|
||||
grub_term_register (&grub_ofconsole_term);
|
||||
grub_term_set_current (&grub_ofconsole_term);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue