merge mainline into arm

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2013-05-11 10:24:24 +02:00
commit 8e71d87482
490 changed files with 29659 additions and 8612 deletions

View file

@ -50,10 +50,91 @@ put (struct grub_term_output *term __attribute__ ((unused)), const int c)
static struct grub_terminfo_output_state grub_console_terminfo_output;
static grub_err_t
grub_console_init_output (struct grub_term_output *term)
int
grub_arc_is_device_serial (const char *name, int alt_names)
{
if (name[0] == '\0')
return 0;
const char *ptr = name + grub_strlen (name) - 1;
int i;
/*
Recognize:
serial(N)
serial(N)line(M)
*/
for (i = 0; i < 2; i++)
{
if (!alt_names)
{
if (*ptr != ')')
return 0;
ptr--;
}
for (; ptr >= name && grub_isdigit (*ptr); ptr--);
if (ptr < name)
return 0;
if (!alt_names)
{
if (*ptr != '(')
return 0;
ptr--;
}
if (ptr + 1 >= name + sizeof ("serial") - 1
&& grub_memcmp (ptr + 1 - (sizeof ("serial") - 1),
"serial", sizeof ("serial") - 1) == 0)
return 1;
if (!(ptr + 1 >= name + sizeof ("line") - 1
&& grub_memcmp (ptr + 1 - (sizeof ("line") - 1),
"line", sizeof ("line") - 1) == 0))
return 0;
ptr -= sizeof ("line") - 1;
if (alt_names)
{
if (*ptr != '/')
return 0;
ptr--;
}
}
return 0;
}
static int
check_is_serial (void)
{
static int is_serial = -1;
if (is_serial != -1)
return is_serial;
const char *consout = 0;
/* Check for serial. It works unless user manually overrides ConsoleOut
variable. If he does there is nothing we can do. Fortunately failure
isn't critical.
*/
if (GRUB_ARC_SYSTEM_PARAMETER_BLOCK->firmware_vector_length
>= ((char *) (&GRUB_ARC_FIRMWARE_VECTOR->getenvironmentvariable + 1)
- (char *) GRUB_ARC_FIRMWARE_VECTOR)
&& GRUB_ARC_FIRMWARE_VECTOR->getenvironmentvariable)
consout = GRUB_ARC_FIRMWARE_VECTOR->getenvironmentvariable ("ConsoleOut");
if (!consout)
return is_serial = 0;
return is_serial = grub_arc_is_device_serial (consout, 0);
}
static void
set_console_dimensions (void)
{
struct grub_arc_display_status *info = NULL;
if (check_is_serial ())
{
grub_console_terminfo_output.width = 80;
grub_console_terminfo_output.height = 24;
return;
}
if (GRUB_ARC_SYSTEM_PARAMETER_BLOCK->firmware_vector_length
>= ((char *) (&GRUB_ARC_FIRMWARE_VECTOR->getdisplaystatus + 1)
- (char *) GRUB_ARC_FIRMWARE_VECTOR)
@ -64,6 +145,12 @@ grub_console_init_output (struct grub_term_output *term)
grub_console_terminfo_output.width = info->w + 1;
grub_console_terminfo_output.height = info->h + 1;
}
}
static grub_err_t
grub_console_init_output (struct grub_term_output *term)
{
set_console_dimensions ();
grub_terminfo_output_init (term);
return 0;
@ -115,5 +202,8 @@ void
grub_console_init_lately (void)
{
grub_terminfo_init ();
grub_terminfo_output_register (&grub_console_term_output, "arc");
if (check_is_serial ())
grub_terminfo_output_register (&grub_console_term_output, "vt100");
else
grub_terminfo_output_register (&grub_console_term_output, "arc");
}

147
grub-core/term/arc/serial.c Normal file
View file

@ -0,0 +1,147 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2013 Free Software Foundation, Inc.
*
* GRUB 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.
*
* GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/serial.h>
#include <grub/types.h>
#include <grub/dl.h>
#include <grub/misc.h>
#include <grub/mm.h>
#include <grub/time.h>
#include <grub/i18n.h>
#include <grub/arc/arc.h>
static void
do_real_config (struct grub_serial_port *port)
{
char *name;
if (port->configured)
return;
name = grub_arc_alt_name_to_norm (port->name, "");
if (GRUB_ARC_FIRMWARE_VECTOR->open (name,GRUB_ARC_FILE_ACCESS_OPEN_RW,
&port->handle))
port->handle_valid = 0;
else
port->handle_valid = 1;
port->configured = 1;
}
/* Fetch a key. */
static int
serial_hw_fetch (struct grub_serial_port *port)
{
unsigned long actual;
char c;
do_real_config (port);
if (!port->handle_valid)
return -1;
if (GRUB_ARC_FIRMWARE_VECTOR->read (port->handle, &c,
1, &actual) || actual <= 0)
return -1;
return c;
}
/* Put a character. */
static void
serial_hw_put (struct grub_serial_port *port, const int c)
{
unsigned long actual;
char c0 = c;
do_real_config (port);
if (!port->handle_valid)
return;
GRUB_ARC_FIRMWARE_VECTOR->write (port->handle, &c0,
1, &actual);
}
/* Initialize a serial device. PORT is the port number for a serial device.
SPEED is a DTE-DTE speed which must be one of these: 2400, 4800, 9600,
19200, 38400, 57600 and 115200. WORD_LEN is the word length to be used
for the device. Likewise, PARITY is the type of the parity and
STOP_BIT_LEN is the length of the stop bit. The possible values for
WORD_LEN, PARITY and STOP_BIT_LEN are defined in the header file as
macros. */
static grub_err_t
serial_hw_configure (struct grub_serial_port *port __attribute__ ((unused)),
struct grub_serial_config *config __attribute__ ((unused)))
{
/* FIXME: no ARC serial config available. */
return GRUB_ERR_NONE;
}
struct grub_serial_driver grub_arcserial_driver =
{
.configure = serial_hw_configure,
.fetch = serial_hw_fetch,
.put = serial_hw_put
};
const char *
grub_arcserial_add_port (const char *path)
{
struct grub_serial_port *port;
grub_err_t err;
port = grub_zalloc (sizeof (*port));
if (!port)
return NULL;
port->name = grub_strdup (path);
if (!port->name)
return NULL;
port->driver = &grub_arcserial_driver;
err = grub_serial_config_defaults (port);
if (err)
grub_print_error ();
grub_serial_register (port);
return port->name;
}
static int
dev_iterate (const char *name,
const struct grub_arc_component *comp __attribute__ ((unused)),
void *data __attribute__ ((unused)))
{
/* We should check consolein/consoleout flags as
well but some implementations are buggy. */
if ((comp->flags & (GRUB_ARC_COMPONENT_FLAG_IN | GRUB_ARC_COMPONENT_FLAG_OUT))
!= (GRUB_ARC_COMPONENT_FLAG_IN | GRUB_ARC_COMPONENT_FLAG_OUT))
return 0;
if (!grub_arc_is_device_serial (name, 1))
return 0;
grub_arcserial_add_port (name);
return 0;
}
void
grub_arcserial_init (void)
{
grub_arc_iterate_devs (dev_iterate, 0, 1);
}

View file

@ -97,7 +97,17 @@ static const grub_uint8_t set1_mapping[128] =
/* OLPC keys. Just mapped to normal keys. */
/* 0x64 */ 0, GRUB_KEYBOARD_KEY_UP,
/* 0x66 */ GRUB_KEYBOARD_KEY_DOWN, GRUB_KEYBOARD_KEY_LEFT,
/* 0x68 */ GRUB_KEYBOARD_KEY_RIGHT
/* 0x68 */ GRUB_KEYBOARD_KEY_RIGHT, 0,
/* 0x6a */ 0, 0,
/* 0x6c */ 0, 0,
/* 0x6e */ 0, 0,
/* 0x70 */ 0, 0,
/* 0x72 */ 0, GRUB_KEYBOARD_KEY_JP_RO,
/* 0x74 */ 0, 0,
/* 0x76 */ 0, 0,
/* 0x78 */ 0, 0,
/* 0x7a */ 0, 0,
/* 0x7c */ 0, GRUB_KEYBOARD_KEY_JP_YEN,
};
static const struct
@ -163,7 +173,7 @@ static const grub_uint8_t set2_mapping[256] =
/* 0x4a */ GRUB_KEYBOARD_KEY_SLASH, GRUB_KEYBOARD_KEY_L,
/* 0x4c */ GRUB_KEYBOARD_KEY_SEMICOLON, GRUB_KEYBOARD_KEY_P,
/* 0x4e */ GRUB_KEYBOARD_KEY_DASH, 0,
/* 0x50 */ 0, 0,
/* 0x50 */ 0, GRUB_KEYBOARD_KEY_JP_RO,
/* 0x52 */ GRUB_KEYBOARD_KEY_DQUOTE, 0,
/* 0x54 */ GRUB_KEYBOARD_KEY_LBRACKET, GRUB_KEYBOARD_KEY_EQUAL,
/* 0x56 */ 0, 0,
@ -176,7 +186,7 @@ static const grub_uint8_t set2_mapping[256] =
/* 0x64 */ 0, 0,
/* 0x66 */ GRUB_KEYBOARD_KEY_BACKSPACE, 0,
/* 0x68 */ 0, GRUB_KEYBOARD_KEY_NUM1,
/* 0x6a */ 0, GRUB_KEYBOARD_KEY_NUM4,
/* 0x6a */ GRUB_KEYBOARD_KEY_JP_YEN, GRUB_KEYBOARD_KEY_NUM4,
/* 0x6c */ GRUB_KEYBOARD_KEY_NUM7, 0,
/* 0x6e */ 0, 0,
/* 0x70 */ GRUB_KEYBOARD_KEY_NUMDOT, GRUB_KEYBOARD_KEY_NUM0,

View file

@ -86,7 +86,7 @@ grub_console_putchar (struct grub_term_output *term __attribute__ ((unused)),
j = 1;
for (i = 0; i < c->ncomb; i++)
if (c->base < 0xffff)
str[j++] = c->combining[i].code;
str[j++] = grub_unicode_get_comb (c)[i].code;
str[j] = 0;
/* Should this test be cached? */

View file

@ -1,7 +1,7 @@
/* console.c -- Ncurses console for GRUB. */
/* console.c -- console for GRUB. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2003,2005,2007,2008 Free Software Foundation, Inc.
* Copyright (C) 2013 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -20,274 +20,159 @@
#include <config.h>
#include <config-util.h>
/* For compatibility. */
#ifndef A_NORMAL
# define A_NORMAL 0
#endif /* ! A_NORMAL */
#ifndef A_STANDOUT
# define A_STANDOUT 0
#endif /* ! A_STANDOUT */
#include <grub/emu/console.h>
#include <grub/term.h>
#include <grub/types.h>
#include <grub/misc.h>
#include <grub/mm.h>
#include <grub/time.h>
#include <grub/terminfo.h>
#include <grub/dl.h>
#if defined(HAVE_NCURSES_CURSES_H)
# include <ncurses/curses.h>
#elif defined(HAVE_NCURSES_H)
# include <ncurses.h>
#elif defined(HAVE_CURSES_H)
# include <curses.h>
#else
#error What the hell?
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <termios.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <langinfo.h>
static int grub_console_attr = A_NORMAL;
#include <grub/emu/console.h>
grub_uint8_t grub_console_cur_color = 7;
static const grub_uint8_t grub_console_standard_color = 0x7;
#define NUM_COLORS 8
static grub_uint8_t color_map[NUM_COLORS] =
{
COLOR_BLACK,
COLOR_BLUE,
COLOR_GREEN,
COLOR_CYAN,
COLOR_RED,
COLOR_MAGENTA,
COLOR_YELLOW,
COLOR_WHITE
};
static int use_color;
extern struct grub_terminfo_output_state grub_console_terminfo_output;
static int original_fl;
static int saved_orig;
static struct termios orig_tty;
static struct termios new_tty;
static void
grub_ncurses_putchar (struct grub_term_output *term __attribute__ ((unused)),
const struct grub_unicode_glyph *c)
put (struct grub_term_output *term __attribute__ ((unused)), const int c)
{
addch (c->base | grub_console_attr);
}
char chr = c;
static void
grub_ncurses_setcolorstate (struct grub_term_output *term,
grub_term_color_state state)
{
switch (state)
{
case GRUB_TERM_COLOR_STANDARD:
grub_console_cur_color = grub_console_standard_color;
grub_console_attr = A_NORMAL;
break;
case GRUB_TERM_COLOR_NORMAL:
grub_console_cur_color = grub_term_normal_color;
grub_console_attr = A_NORMAL;
break;
case GRUB_TERM_COLOR_HIGHLIGHT:
grub_console_cur_color = grub_term_highlight_color;
grub_console_attr = A_STANDOUT;
break;
default:
break;
}
if (use_color)
{
grub_uint8_t fg, bg;
fg = (grub_console_cur_color & 7);
bg = (grub_console_cur_color >> 4) & 7;
grub_console_attr = (grub_console_cur_color & 8) ? A_BOLD : A_NORMAL;
color_set ((bg << 3) + fg, 0);
}
write (STDOUT_FILENO, &chr, 1);
}
static int
grub_ncurses_getkey (struct grub_term_input *term __attribute__ ((unused)))
readkey (struct grub_term_input *term __attribute__ ((unused)))
{
int c;
grub_uint8_t c;
ssize_t actual;
wtimeout (stdscr, 100);
c = getch ();
switch (c)
{
case ERR:
return GRUB_TERM_NO_KEY;
case KEY_LEFT:
c = GRUB_TERM_KEY_LEFT;
break;
case KEY_RIGHT:
c = GRUB_TERM_KEY_RIGHT;
break;
case KEY_UP:
c = GRUB_TERM_KEY_UP;
break;
case KEY_DOWN:
c = GRUB_TERM_KEY_DOWN;
break;
case KEY_IC:
c = 24;
break;
case KEY_DC:
c = GRUB_TERM_KEY_DC;
break;
case KEY_BACKSPACE:
/* XXX: For some reason ncurses on xterm does not return
KEY_BACKSPACE. */
case 127:
c = '\b';
break;
case KEY_HOME:
c = GRUB_TERM_KEY_HOME;
break;
case KEY_END:
c = GRUB_TERM_KEY_END;
break;
case KEY_NPAGE:
c = GRUB_TERM_KEY_NPAGE;
break;
case KEY_PPAGE:
c = GRUB_TERM_KEY_PPAGE;
break;
}
return c;
}
static grub_uint16_t
grub_ncurses_getxy (struct grub_term_output *term __attribute__ ((unused)))
{
int x;
int y;
getyx (stdscr, y, x);
return (x << 8) | y;
}
static grub_uint16_t
grub_ncurses_getwh (struct grub_term_output *term __attribute__ ((unused)))
{
int x;
int y;
getmaxyx (stdscr, y, x);
return (x << 8) | y;
}
static void
grub_ncurses_gotoxy (struct grub_term_output *term __attribute__ ((unused)),
grub_uint8_t x, grub_uint8_t y)
{
move (y, x);
}
static void
grub_ncurses_cls (struct grub_term_output *term __attribute__ ((unused)))
{
clear ();
refresh ();
}
static void
grub_ncurses_setcursor (struct grub_term_output *term __attribute__ ((unused)),
int on)
{
curs_set (on ? 1 : 0);
}
static void
grub_ncurses_refresh (struct grub_term_output *term __attribute__ ((unused)))
{
refresh ();
actual = read (STDIN_FILENO, &c, 1);
if (actual > 0)
return c;
return -1;
}
static grub_err_t
grub_ncurses_init (struct grub_term_output *term __attribute__ ((unused)))
grub_console_init_input (struct grub_term_input *term)
{
initscr ();
raw ();
noecho ();
scrollok (stdscr, TRUE);
nonl ();
intrflush (stdscr, FALSE);
keypad (stdscr, TRUE);
if (has_colors ())
if (!saved_orig)
{
start_color ();
if ((COLORS >= NUM_COLORS) && (COLOR_PAIRS >= NUM_COLORS * NUM_COLORS))
{
int i, j, n;
n = 0;
for (i = 0; i < NUM_COLORS; i++)
for (j = 0; j < NUM_COLORS; j++)
init_pair(n++, color_map[j], color_map[i]);
use_color = 1;
}
original_fl = fcntl (STDIN_FILENO, F_GETFL);
fcntl (STDIN_FILENO, F_SETFL, original_fl | O_NONBLOCK);
}
return 0;
saved_orig = 1;
tcgetattr(STDIN_FILENO, &orig_tty);
new_tty = orig_tty;
new_tty.c_lflag &= ~(ICANON | ECHO);
new_tty.c_cc[VMIN] = 1;
tcsetattr(STDIN_FILENO, TCSANOW, &new_tty);
return grub_terminfo_input_init (term);
}
static grub_err_t
grub_ncurses_fini (struct grub_term_output *term __attribute__ ((unused)))
grub_console_fini_input (struct grub_term_input *term
__attribute__ ((unused)))
{
endwin ();
fcntl (STDIN_FILENO, F_SETFL, original_fl);
tcsetattr(STDIN_FILENO, TCSANOW, &orig_tty);
saved_orig = 0;
return GRUB_ERR_NONE;
}
static grub_err_t
grub_console_init_output (struct grub_term_output *term)
{
struct winsize size;
if (ioctl (STDOUT_FILENO, TIOCGWINSZ, &size) >= 0)
{
grub_console_terminfo_output.width = size.ws_col;
grub_console_terminfo_output.height = size.ws_row;
}
else
{
grub_console_terminfo_output.width = 80;
grub_console_terminfo_output.height = 24;
}
grub_terminfo_output_init (term);
return 0;
}
static struct grub_term_input grub_ncurses_term_input =
struct grub_terminfo_input_state grub_console_terminfo_input =
{
.name = "console",
.getkey = grub_ncurses_getkey,
.readkey = readkey
};
static struct grub_term_output grub_ncurses_term_output =
struct grub_terminfo_output_state grub_console_terminfo_output =
{
.put = put,
.width = 80,
.height = 24
};
static struct grub_term_input grub_console_term_input =
{
.name = "console",
.init = grub_ncurses_init,
.fini = grub_ncurses_fini,
.putchar = grub_ncurses_putchar,
.getxy = grub_ncurses_getxy,
.getwh = grub_ncurses_getwh,
.gotoxy = grub_ncurses_gotoxy,
.cls = grub_ncurses_cls,
.setcolorstate = grub_ncurses_setcolorstate,
.setcursor = grub_ncurses_setcursor,
.refresh = grub_ncurses_refresh,
.flags = GRUB_TERM_CODE_TYPE_ASCII
.init = grub_console_init_input,
.fini = grub_console_fini_input,
.getkey = grub_terminfo_getkey,
.data = &grub_console_terminfo_input
};
static struct grub_term_output grub_console_term_output =
{
.name = "console",
.init = grub_console_init_output,
.putchar = grub_terminfo_putchar,
.getxy = grub_terminfo_getxy,
.getwh = grub_terminfo_getwh,
.gotoxy = grub_terminfo_gotoxy,
.cls = grub_terminfo_cls,
.setcolorstate = grub_terminfo_setcolorstate,
.setcursor = grub_terminfo_setcursor,
.data = &grub_console_terminfo_output,
};
void
grub_console_init (void)
{
grub_term_register_output ("console", &grub_ncurses_term_output);
grub_term_register_input ("console", &grub_ncurses_term_input);
const char *cs = nl_langinfo (CODESET);
if (cs && grub_strcasecmp (cs, "UTF-8"))
grub_console_term_output.flags = GRUB_TERM_CODE_TYPE_UTF8_LOGICAL;
else
grub_console_term_output.flags = GRUB_TERM_CODE_TYPE_ASCII;
grub_term_register_input ("console", &grub_console_term_input);
grub_term_register_output ("console", &grub_console_term_output);
grub_terminfo_init ();
grub_terminfo_output_register (&grub_console_term_output, "vt100-color");
}
void
grub_console_fini (void)
{
grub_ncurses_fini (&grub_ncurses_term_output);
if (saved_orig)
{
fcntl (STDIN_FILENO, F_SETFL, original_fl);
tcsetattr(STDIN_FILENO, TCSANOW, &orig_tty);
}
saved_orig = 0;
}

View file

@ -49,7 +49,7 @@ struct grub_dirty_region
struct grub_colored_char
{
/* An Unicode codepoint. */
struct grub_unicode_glyph *code;
struct grub_unicode_glyph code;
/* Color values. */
grub_video_color_t fg_color;
@ -175,10 +175,8 @@ set_term_color (grub_uint8_t term_color)
static void
clear_char (struct grub_colored_char *c)
{
grub_free (c->code);
c->code = grub_unicode_glyph_from_code (' ');
if (!c->code)
grub_errno = GRUB_ERR_NONE;
grub_unicode_destroy_glyph (&c->code);
grub_unicode_set_glyph_from_code (&c->code, ' ');
c->fg_color = virtual_screen.fg_color;
c->bg_color = virtual_screen.bg_color;
}
@ -188,7 +186,14 @@ grub_virtual_screen_free (void)
{
/* If virtual screen has been allocated, free it. */
if (virtual_screen.text_buffer != 0)
grub_free (virtual_screen.text_buffer);
{
unsigned i;
for (i = 0;
i < virtual_screen.columns * virtual_screen.rows;
i++)
grub_unicode_destroy_glyph (&virtual_screen.text_buffer[i].code);
grub_free (virtual_screen.text_buffer);
}
/* Reset virtual screen data. */
grub_memset (&virtual_screen, 0, sizeof (virtual_screen));
@ -239,7 +244,7 @@ grub_virtual_screen_setup (unsigned int x, unsigned int y,
grub_video_create_render_target (&text_layer,
virtual_screen.width,
virtual_screen.height,
GRUB_VIDEO_MODE_TYPE_RGB
GRUB_VIDEO_MODE_TYPE_INDEX_COLOR
| GRUB_VIDEO_MODE_TYPE_ALPHA);
if (grub_errno != GRUB_ERR_NONE)
return grub_errno;
@ -262,7 +267,7 @@ grub_virtual_screen_setup (unsigned int x, unsigned int y,
/* Clear out text buffer. */
for (i = 0; i < virtual_screen.columns * virtual_screen.rows; i++)
{
virtual_screen.text_buffer[i].code = 0;
virtual_screen.text_buffer[i].code.ncomb = 0;
clear_char (&(virtual_screen.text_buffer[i]));
}
@ -403,8 +408,9 @@ grub_gfxterm_term_fini (struct grub_term_output *term __attribute__ ((unused)))
for (i = 0; i < virtual_screen.columns * virtual_screen.rows; i++)
{
grub_free (virtual_screen.text_buffer[i].code);
virtual_screen.text_buffer[i].code = 0;
grub_unicode_destroy_glyph (&virtual_screen.text_buffer[i].code);
virtual_screen.text_buffer[i].code.ncomb = 0;
virtual_screen.text_buffer[i].code.base = 0;
}
/* Clear error state. */
@ -615,11 +621,11 @@ paint_char (unsigned cx, unsigned cy)
p = (virtual_screen.text_buffer
+ cx + (cy * virtual_screen.columns));
if (!p->code)
if (!p->code.base)
return;
/* Get glyph for character. */
glyph = grub_font_construct_glyph (virtual_screen.font, p->code);
glyph = grub_font_construct_glyph (virtual_screen.font, &p->code);
if (!glyph)
{
grub_errno = GRUB_ERR_NONE;
@ -645,7 +651,6 @@ paint_char (unsigned cx, unsigned cy)
/* Mark character to be drawn. */
dirty_region_add (virtual_screen.offset_x + x, virtual_screen.offset_y + y,
width, height);
grub_free (glyph);
}
static inline void
@ -798,8 +803,8 @@ scroll_up (void)
/* Clear first line in text buffer. */
for (i = 0; i < virtual_screen.columns; i++)
grub_free (virtual_screen.text_buffer[i].code);
grub_unicode_destroy_glyph (&virtual_screen.text_buffer[i].code);
/* Scroll text buffer with one line to up. */
grub_memmove (virtual_screen.text_buffer,
virtual_screen.text_buffer + virtual_screen.columns,
@ -811,10 +816,7 @@ scroll_up (void)
for (i = virtual_screen.columns * (virtual_screen.rows - 1);
i < virtual_screen.columns * virtual_screen.rows;
i++)
{
virtual_screen.text_buffer[i].code = 0;
clear_char (&(virtual_screen.text_buffer[i]));
}
clear_char (&(virtual_screen.text_buffer[i]));
virtual_screen.total_scroll++;
}
@ -874,10 +876,9 @@ grub_gfxterm_putchar (struct grub_term_output *term,
p = (virtual_screen.text_buffer +
virtual_screen.cursor_x +
virtual_screen.cursor_y * virtual_screen.columns);
grub_free (p->code);
p->code = grub_unicode_glyph_dup (c);
if (!p->code)
grub_errno = GRUB_ERR_NONE;
grub_unicode_destroy_glyph (&p->code);
grub_unicode_set_glyph (&p->code, c);
grub_errno = GRUB_ERR_NONE;
p->fg_color = virtual_screen.fg_color;
p->bg_color = virtual_screen.bg_color;
@ -889,10 +890,10 @@ grub_gfxterm_putchar (struct grub_term_output *term,
for (i = 1; i < char_width && p + i <
virtual_screen.text_buffer + virtual_screen.columns
* virtual_screen.rows; i++)
{
grub_free (p[i].code);
p[i].code = NULL;
}
{
grub_unicode_destroy_glyph (&p[i].code);
p[i].code.base = 0;
}
}
/* Draw glyph. */

View file

@ -86,13 +86,9 @@ grub_console_gotoxy (struct grub_term_output *term __attribute__ ((unused)),
* Put the character C on the console. Because GRUB wants to write a
* character with an attribute, this implementation is a bit tricky.
* If C is a control character (CR, LF, BEL, BS), use INT 10, AH = 0Eh
* (TELETYPE OUTPUT). Otherwise, save the original position, put a space,
* save the current position, restore the original position, write the
* character and the attribute, and restore the current position.
*
* The reason why this is so complicated is that there is no easy way to
* get the height of the screen, and the TELETYPE OUTPUT BIOS call doesn't
* support setting a background attribute.
* (TELETYPE OUTPUT). Otherwise, use INT 10, AH = 9 to write character
* with attributes and advance cursor. If we are on the last column,
* let BIOS to wrap line correctly.
*/
static void
grub_console_putchar_real (grub_uint8_t c)
@ -112,19 +108,18 @@ grub_console_putchar_real (grub_uint8_t c)
/* get the current position */
pos = grub_console_getxy (NULL);
/* write the character with the attribute */
int10_9 (c, 1);
/* check the column with the width */
if ((pos & 0xff00) >= (79 << 8))
{
grub_console_putchar_real (0x0d);
grub_console_putchar_real (0x0a);
/* get the current position */
pos = grub_console_getxy (NULL);
}
else
grub_console_gotoxy (NULL, ((pos & 0xff00) >> 8) + 1, (pos & 0xff));
/* write the character with the attribute */
int10_9 (c, 1);
grub_console_gotoxy (NULL, ((pos & 0xff00) >> 8) + 1, (pos & 0xff));
}
static void
@ -255,8 +250,7 @@ grub_console_getkeystatus (struct grub_term_input *term __attribute__ ((unused))
static grub_uint16_t
grub_console_getwh (struct grub_term_output *term __attribute__ ((unused)))
{
/* Due to current cursor moving algorithm we lost the last column. */
return (79 << 8) | 25;
return (80 << 8) | 25;
}
static void

View file

@ -123,6 +123,14 @@ grub_console_dimensions (void)
}
}
/* Bogus default value on SLOF in QEMU. */
if (grub_console_terminfo_output.width == 200
&& grub_console_terminfo_output.height == 200)
{
grub_console_terminfo_output.width = 80;
grub_console_terminfo_output.height = 24;
}
/* Use a small console by default. */
if (! grub_console_terminfo_output.width)
grub_console_terminfo_output.width = 80;

View file

@ -23,6 +23,7 @@
#include <grub/mm.h>
#include <grub/time.h>
#include <grub/i18n.h>
#include <grub/ieee1275/console.h>
#define IEEE1275_IHANDLE_INVALID ((grub_ieee1275_cell_t) 0)
@ -216,11 +217,59 @@ dev_iterate (struct grub_ieee1275_devalias *alias)
return 0;
}
static const char *
add_port (struct ofserial_hash_ent *ent)
{
struct grub_serial_port *port;
char *ptr;
grub_err_t err;
if (!ent->shortest)
return NULL;
port = grub_zalloc (sizeof (*port));
if (!port)
return NULL;
port->name = grub_malloc (sizeof ("ieee1275/")
+ grub_strlen (ent->shortest));
port->elem = ent;
if (!port->name)
return NULL;
ptr = grub_stpcpy (port->name, "ieee1275/");
grub_strcpy (ptr, ent->shortest);
port->driver = &grub_ofserial_driver;
err = grub_serial_config_defaults (port);
if (err)
grub_print_error ();
grub_serial_register (port);
return port->name;
}
const char *
grub_ofserial_add_port (const char *path)
{
struct ofserial_hash_ent *ent;
char *name = grub_strdup (path);
char *can = grub_strdup (path);
if (!name || ! can)
{
grub_free (name);
grub_free (can);
return NULL;
}
ent = ofserial_hash_add (name, can);
return add_port (ent);
}
void
grub_ofserial_init (void)
{
unsigned i;
grub_err_t err;
struct grub_ieee1275_devalias alias;
FOR_IEEE1275_DEVALIASES(alias)
@ -230,32 +279,9 @@ grub_ofserial_init (void)
for (i = 0; i < ARRAY_SIZE (ofserial_hash); i++)
{
static struct ofserial_hash_ent *ent;
struct ofserial_hash_ent *ent;
for (ent = ofserial_hash[i]; ent; ent = ent->next)
{
struct grub_serial_port *port;
char *ptr;
if (!ent->shortest)
continue;
port = grub_zalloc (sizeof (*port));
if (!port)
return;
port->name = grub_malloc (sizeof ("ieee1275/")
+ grub_strlen (ent->shortest));
port->elem = ent;
if (!port->name)
return;
ptr = grub_stpcpy (port->name, "ieee1275/");
grub_strcpy (ptr, ent->shortest);
port->driver = &grub_ofserial_driver;
err = grub_serial_config_defaults (port);
if (err)
grub_print_error ();
grub_serial_register (port);
}
add_port (ent);
}
}

View file

@ -27,45 +27,48 @@
GRUB_MOD_LICENSE ("GPLv3+");
#define BASE_TIME 250
#define DIH 1
#define DAH 3
#define END 0
static const char codes[0x80][6] =
{
['0'] = { 3, 3, 3, 3, 3, 0 },
['1'] = { 1, 3, 3, 3, 3, 0 },
['2'] = { 1, 1, 3, 3, 3, 0 },
['3'] = { 1, 1, 1, 3, 3, 0 },
['4'] = { 1, 1, 1, 1, 3, 0 },
['5'] = { 1, 1, 1, 1, 1, 0 },
['6'] = { 3, 1, 1, 1, 1, 0 },
['7'] = { 3, 3, 1, 1, 1, 0 },
['8'] = { 3, 3, 3, 1, 1, 0 },
['9'] = { 3, 3, 3, 3, 1, 0 },
['a'] = { 1, 3, 0 },
['b'] = { 3, 1, 1, 1, 0 },
['c'] = { 3, 1, 3, 1, 0 },
['d'] = { 3, 1, 1, 0 },
['e'] = { 1, 0 },
['f'] = { 1, 1, 3, 1, 0 },
['g'] = { 3, 3, 1, 0 },
['h'] = { 1, 1, 1, 1, 0 },
['i'] = { 1, 1, 0 },
['j'] = { 1, 3, 3, 3, 0 },
['k'] = { 3, 1, 3, 0 },
['l'] = { 1, 3, 1, 1, 0 },
['m'] = { 3, 3, 0 },
['n'] = { 3, 1, 0 },
['o'] = { 3, 3, 3, 0 },
['p'] = { 1, 3, 3, 1, 0 },
['q'] = { 3, 3, 1, 3, 0 },
['r'] = { 1, 3, 1, 0 },
['s'] = { 1, 1, 1, 0 },
['t'] = { 3, 0 },
['u'] = { 1, 1, 3, 0 },
['v'] = { 1, 1, 1, 3, 0 },
['w'] = { 1, 3, 3, 0 },
['x'] = { 3, 1, 1, 3, 0 },
['y'] = { 3, 1, 3, 3, 0 },
['z'] = { 3, 3, 1, 1, 0 }
['0'] = { DAH, DAH, DAH, DAH, DAH, END },
['1'] = { DIH, DAH, DAH, DAH, DAH, END },
['2'] = { DIH, DIH, DAH, DAH, DAH, END },
['3'] = { DIH, DIH, DIH, DAH, DAH, END },
['4'] = { DIH, DIH, DIH, DIH, DAH, END },
['5'] = { DIH, DIH, DIH, DIH, DIH, END },
['6'] = { DAH, DIH, DIH, DIH, DIH, END },
['7'] = { DAH, DAH, DIH, DIH, DIH, END },
['8'] = { DAH, DAH, DAH, DIH, DIH, END },
['9'] = { DAH, DAH, DAH, DAH, DIH, END },
['a'] = { DIH, DAH, END },
['b'] = { DAH, DIH, DIH, DIH, END },
['c'] = { DAH, DIH, DAH, DIH, END },
['d'] = { DAH, DIH, DIH, END },
['e'] = { DIH, END },
['f'] = { DIH, DIH, DAH, DIH, END },
['g'] = { DAH, DAH, DIH, END },
['h'] = { DIH, DIH, DIH, DIH, END },
['i'] = { DIH, DIH, END },
['j'] = { DIH, DAH, DAH, DAH, END },
['k'] = { DAH, DIH, DAH, END },
['l'] = { DIH, DAH, DIH, DIH, END },
['m'] = { DAH, DAH, END },
['n'] = { DAH, DIH, END },
['o'] = { DAH, DAH, DAH, END },
['p'] = { DIH, DAH, DAH, DIH, END },
['q'] = { DAH, DAH, DIH, DAH, END },
['r'] = { DIH, DAH, DIH, END },
['s'] = { DIH, DIH, DIH, END },
['t'] = { DAH, END },
['u'] = { DIH, DIH, DAH, END },
['v'] = { DIH, DIH, DIH, DAH, END },
['w'] = { DIH, DAH, DAH, END },
['x'] = { DAH, DIH, DIH, DAH, END },
['y'] = { DAH, DIH, DAH, DAH, END },
['z'] = { DAH, DAH, DIH, DIH, END }
};
static void

View file

@ -36,6 +36,8 @@ static const grub_port_t serial_hw_io_addr[] = GRUB_MACHINE_SERIAL_PORTS;
#define GRUB_SERIAL_PORT_NUM (ARRAY_SIZE(serial_hw_io_addr))
#endif
static int dead_ports = 0;
/* Convert speed to divisor. */
static unsigned short
serial_get_divisor (const struct grub_serial_port *port __attribute__ ((unused)),
@ -83,6 +85,8 @@ do_real_config (struct grub_serial_port *port)
{
int divisor;
unsigned char status = 0;
grub_uint64_t endtime;
const unsigned char parities[] = {
[GRUB_SERIAL_PARITY_NONE] = UART_NO_PARITY,
[GRUB_SERIAL_PARITY_ODD] = UART_ODD_PARITY,
@ -132,8 +136,16 @@ do_real_config (struct grub_serial_port *port)
#endif
/* Drain the input buffer. */
endtime = grub_get_time_ms () + 1000;
while (grub_inb (port->port + UART_LSR) & UART_DATA_READY)
grub_inb (port->port + UART_RX);
{
grub_inb (port->port + UART_RX);
if (grub_get_time_ms () > endtime)
{
port->broken = 1;
break;
}
}
port->configured = 1;
}
@ -239,6 +251,20 @@ grub_ns8250_init (void)
if (serial_hw_io_addr[i])
{
grub_err_t err;
grub_outb (0x5a, serial_hw_io_addr[i] + UART_SR);
if (grub_inb (serial_hw_io_addr[i] + UART_SR) != 0x5a)
{
dead_ports |= (1 << i);
continue;
}
grub_outb (0xa5, serial_hw_io_addr[i] + UART_SR);
if (grub_inb (serial_hw_io_addr[i] + UART_SR) != 0xa5)
{
dead_ports |= (1 << i);
continue;
}
grub_snprintf (com_names[i], sizeof (com_names[i]), "com%d", i);
com_ports[i].name = com_names[i];
com_ports[i].driver = &grub_ns8250_driver;
@ -255,7 +281,8 @@ grub_ns8250_init (void)
grub_port_t
grub_ns8250_hw_get_port (const unsigned int unit)
{
if (unit < GRUB_SERIAL_PORT_NUM)
if (unit < GRUB_SERIAL_PORT_NUM
&& !(dead_ports & (1 << unit)))
return serial_hw_io_addr[unit];
else
return 0;
@ -268,7 +295,20 @@ grub_serial_ns8250_add_port (grub_port_t port)
unsigned i;
for (i = 0; i < GRUB_SERIAL_PORT_NUM; i++)
if (com_ports[i].port == port)
return com_names[i];
{
if (dead_ports & (1 << i))
return NULL;
return com_names[i];
}
grub_outb (0x5a, port + UART_SR);
if (grub_inb (port + UART_SR) != 0x5a)
return NULL;
grub_outb (0xa5, port + UART_SR);
if (grub_inb (port + UART_SR) != 0xa5)
return NULL;
p = grub_malloc (sizeof (*p));
if (!p)
return NULL;

View file

@ -31,6 +31,9 @@
#ifdef GRUB_MACHINE_MIPS_LOONGSON
#include <grub/machine/kernel.h>
#endif
#ifdef GRUB_MACHINE_IEEE1275
#include <grub/ieee1275/console.h>
#endif
GRUB_MOD_LICENSE ("GPLv3+");
@ -134,7 +137,7 @@ grub_serial_find (const char *name)
if (grub_strcmp (port->name, name) == 0)
break;
#if (defined(__mips__) || defined (__i386__) || defined (__x86_64__)) && !defined(GRUB_MACHINE_EMU)
#if (defined(__mips__) || defined (__i386__) || defined (__x86_64__)) && !defined(GRUB_MACHINE_EMU) && !defined(GRUB_MACHINE_ARC)
if (!port && grub_memcmp (name, "port", sizeof ("port") - 1) == 0
&& grub_isxdigit (name [sizeof ("port") - 1]))
{
@ -149,6 +152,19 @@ grub_serial_find (const char *name)
}
#endif
#ifdef GRUB_MACHINE_IEEE1275
if (!port && grub_memcmp (name, "ieee1275/", sizeof ("ieee1275/") - 1) == 0)
{
name = grub_ofserial_add_port (&name[sizeof ("ieee1275/") - 1]);
if (!name)
return NULL;
FOR_SERIAL_PORTS (port)
if (grub_strcmp (port->name, name) == 0)
break;
}
#endif
return port;
}
@ -226,7 +242,7 @@ grub_cmd_serial (grub_extcmd_context_t ctxt, int argc, char **args)
err = port->driver->configure (port, &config);
if (err)
return err;
#if !defined (GRUB_MACHINE_EMU) && (defined(__mips__) || defined (__i386__) || defined (__x86_64__))
#if !defined (GRUB_MACHINE_EMU) && !defined(GRUB_MACHINE_ARC) && (defined(__mips__) || defined (__i386__) || defined (__x86_64__))
/* Compatibility kludge. */
if (port->driver == &grub_ns8250_driver)
@ -380,7 +396,7 @@ GRUB_MOD_INIT(serial)
&grub_serial_terminfo_input_template,
sizeof (grub_serial_terminfo_input));
#if !defined (GRUB_MACHINE_EMU) && (defined(__mips__) || defined (__i386__) || defined (__x86_64__))
#if !defined (GRUB_MACHINE_EMU) && !defined(GRUB_MACHINE_ARC) && (defined(__mips__) || defined (__i386__) || defined (__x86_64__))
grub_ns8250_init ();
#endif
#ifdef GRUB_MACHINE_IEEE1275
@ -389,6 +405,9 @@ GRUB_MOD_INIT(serial)
#ifdef GRUB_MACHINE_EFI
grub_efiserial_init ();
#endif
#ifdef GRUB_MACHINE_ARC
grub_arcserial_init ();
#endif
}
#if defined (GRUB_MACHINE_MIPS_LOONGSON) || defined (GRUB_MACHINE_MIPS_QEMU_MIPS)

View file

@ -39,8 +39,8 @@
GRUB_MOD_LICENSE ("GPLv3+");
#define ANSI_C0 0x9b
#define ANSI_C0_STR "\x9b"
#define ANSI_CSI 0x9b
#define ANSI_CSI_STR "\x9b"
static struct grub_term_output *terminfo_outputs;
@ -132,14 +132,14 @@ grub_terminfo_set_current (struct grub_term_output *term,
if (grub_strcmp ("arc", str) == 0)
{
data->name = grub_strdup ("arc");
data->gotoxy = grub_strdup (ANSI_C0_STR "%i%p1%d;%p2%dH");
data->cls = grub_strdup (ANSI_C0_STR "2J");
data->reverse_video_on = grub_strdup (ANSI_C0_STR "7m");
data->reverse_video_off = grub_strdup (ANSI_C0_STR "0m");
data->gotoxy = grub_strdup (ANSI_CSI_STR "%i%p1%d;%p2%dH");
data->cls = grub_strdup (ANSI_CSI_STR "2J");
data->reverse_video_on = grub_strdup (ANSI_CSI_STR "7m");
data->reverse_video_off = grub_strdup (ANSI_CSI_STR "0m");
data->cursor_on = 0;
data->cursor_off = 0;
data->setcolor = grub_strdup (ANSI_C0_STR "3%p1%dm"
ANSI_C0_STR "4%p2%dm");
data->setcolor = grub_strdup (ANSI_CSI_STR "3%p1%dm"
ANSI_CSI_STR "4%p2%dm");
return grub_errno;
}
@ -427,7 +427,7 @@ grub_terminfo_readkey (struct grub_term_input *term, int *keys, int *len,
}
*len = 1;
keys[0] = c;
if (c != ANSI_C0 && c != '\e')
if (c != ANSI_CSI && c != '\e')
{
/* Backspace: Ctrl-h. */
if (c == 0x7f)