merge mainline into asprintf

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2010-01-20 07:36:17 +01:00
commit 2d49abe9e7
342 changed files with 14569 additions and 4699 deletions

View file

@ -17,13 +17,14 @@
*/
#include <grub/dl.h>
#include <grub/i386/pc/console.h>
#include <grub/i386/at_keyboard.h>
#include <grub/i386/io.h>
#include <grub/at_keyboard.h>
#include <grub/cpu/at_keyboard.h>
#include <grub/cpu/io.h>
#include <grub/misc.h>
#include <grub/term.h>
static short at_keyboard_status = 0;
static int pending_key = -1;
#define KEYBOARD_STATUS_SHIFT_L (1 << 0)
#define KEYBOARD_STATUS_SHIFT_R (1 << 1)
@ -72,7 +73,7 @@ static char keyboard_map_shift[128] =
static grub_uint8_t grub_keyboard_controller_orig;
static void
keyboard_controller_wait_untill_ready (void)
keyboard_controller_wait_until_ready (void)
{
while (! KEYBOARD_COMMAND_ISREADY (grub_inb (KEYBOARD_REG_STATUS)));
}
@ -80,7 +81,7 @@ keyboard_controller_wait_untill_ready (void)
static void
grub_keyboard_controller_write (grub_uint8_t c)
{
keyboard_controller_wait_untill_ready ();
keyboard_controller_wait_until_ready ();
grub_outb (KEYBOARD_COMMAND_WRITE, KEYBOARD_REG_STATUS);
grub_outb (c, KEYBOARD_REG_DATA);
}
@ -88,7 +89,7 @@ grub_keyboard_controller_write (grub_uint8_t c)
static grub_uint8_t
grub_keyboard_controller_read (void)
{
keyboard_controller_wait_untill_ready ();
keyboard_controller_wait_until_ready ();
grub_outb (KEYBOARD_COMMAND_READ, KEYBOARD_REG_STATUS);
return grub_inb (KEYBOARD_REG_DATA);
}
@ -96,9 +97,9 @@ grub_keyboard_controller_read (void)
static void
keyboard_controller_led (grub_uint8_t leds)
{
keyboard_controller_wait_untill_ready ();
keyboard_controller_wait_until_ready ();
grub_outb (0xed, KEYBOARD_REG_DATA);
keyboard_controller_wait_untill_ready ();
keyboard_controller_wait_until_ready ();
grub_outb (leds & 0x7, KEYBOARD_REG_DATA);
}
@ -237,14 +238,27 @@ grub_at_keyboard_getkey_noblock (void)
static int
grub_at_keyboard_checkkey (void)
{
/* FIXME: this will be triggered by BREAK events. */
return KEYBOARD_ISREADY (grub_inb (KEYBOARD_REG_STATUS)) ? 1 : -1;
if (pending_key != -1)
return 1;
pending_key = grub_at_keyboard_getkey_noblock ();
if (pending_key != -1)
return 1;
return -1;
}
static int
grub_at_keyboard_getkey (void)
{
int key;
if (pending_key != -1)
{
key = pending_key;
pending_key = -1;
return key;
}
do
{
key = grub_at_keyboard_getkey_noblock ();
@ -255,6 +269,8 @@ grub_at_keyboard_getkey (void)
static grub_err_t
grub_keyboard_controller_init (void)
{
pending_key = -1;
at_keyboard_status = 0;
grub_keyboard_controller_orig = grub_keyboard_controller_read ();
grub_keyboard_controller_write (grub_keyboard_controller_orig | KEYBOARD_SCANCODE_SET1);
return GRUB_ERR_NONE;

View file

@ -351,8 +351,7 @@ static struct grub_term_output grub_console_term_output =
.setcolorstate = grub_console_setcolorstate,
.setcolor = grub_console_setcolor,
.getcolor = grub_console_getcolor,
.setcursor = grub_console_setcursor,
.flags = 0,
.setcursor = grub_console_setcursor
};
void

View file

@ -27,7 +27,7 @@
#include <grub/bitmap.h>
#include <grub/command.h>
#define DEFAULT_VIDEO_MODE "1024x768,800x600,640x480"
#define DEFAULT_VIDEO_MODE "auto"
#define DEFAULT_BORDER_WIDTH 10
#define DEFAULT_STANDARD_COLOR 0x07
@ -95,6 +95,7 @@ struct grub_virtual_screen
/* Color settings. */
grub_video_color_t fg_color;
grub_video_color_t bg_color;
grub_video_color_t bg_color_display;
/* Text buffer for virtual screen. Contains (columns * rows) number
of entries. */
@ -237,6 +238,8 @@ grub_virtual_screen_setup (unsigned int x, unsigned int y,
grub_video_set_active_render_target (GRUB_VIDEO_RENDER_TARGET_DISPLAY);
virtual_screen.bg_color_display = grub_video_map_rgba(0, 0, 0, 0);
/* Clear out text buffer. */
for (i = 0; i < virtual_screen.columns * virtual_screen.rows; i++)
clear_char (&(virtual_screen.text_buffer[i]));
@ -244,12 +247,6 @@ grub_virtual_screen_setup (unsigned int x, unsigned int y,
return grub_errno;
}
static int NESTED_FUNC_ATTR video_hook (grub_video_adapter_t p __attribute__ ((unused)),
struct grub_video_mode_info *info)
{
return ! (info->mode_type & GRUB_VIDEO_MODE_TYPE_PURE_TEXT);
}
static grub_err_t
grub_gfxterm_init (void)
{
@ -269,13 +266,14 @@ grub_gfxterm_init (void)
/* Parse gfxmode environment variable if set. */
modevar = grub_env_get ("gfxmode");
if (! modevar || *modevar == 0)
err = grub_video_set_mode (DEFAULT_VIDEO_MODE, video_hook);
err = grub_video_set_mode (DEFAULT_VIDEO_MODE,
GRUB_VIDEO_MODE_TYPE_PURE_TEXT, 0);
else
{
tmp = grub_asprintf ("%s;" DEFAULT_VIDEO_MODE, modevar);
if (!tmp)
return grub_errno;
err = grub_video_set_mode (tmp, video_hook);
err = grub_video_set_mode (tmp, GRUB_VIDEO_MODE_TYPE_PURE_TEXT, 0);
grub_free (tmp);
}
@ -345,7 +343,7 @@ redraw_screen_rect (unsigned int x, unsigned int y,
/* If bitmap is smaller than requested blit area, use background
color. */
color = virtual_screen.bg_color;
color = virtual_screen.bg_color_display;
/* Fill right side of the bitmap if needed. */
if ((x + width >= bitmap_width) && (y < bitmap_height))
@ -392,7 +390,7 @@ redraw_screen_rect (unsigned int x, unsigned int y,
else
{
/* Render background layer. */
color = virtual_screen.bg_color;
color = virtual_screen.bg_color_display;
grub_video_fill_rect (color, x, y, width, height);
/* Render text layer as replaced (to get texts background color). */
@ -814,7 +812,8 @@ grub_gfxterm_cls (void)
/* Clear text layer. */
grub_video_set_active_render_target (text_layer);
color = virtual_screen.bg_color;
grub_video_fill_rect (color, 0, 0, mode_info.width, mode_info.height);
grub_video_fill_rect (color, 0, 0, virtual_screen.width,
virtual_screen.height);
grub_video_set_active_render_target (GRUB_VIDEO_RENDER_TARGET_DISPLAY);
/* Mark virtual screen to be redrawn. */

View file

@ -65,8 +65,7 @@ static struct grub_term_output grub_console_term_output =
.setcolorstate = grub_console_setcolorstate,
.setcolor = grub_console_setcolor,
.getcolor = grub_console_getcolor,
.setcursor = grub_console_setcursor,
.flags = 0,
.setcursor = grub_console_setcursor
};
void
@ -79,10 +78,6 @@ grub_console_init (void)
void
grub_console_fini (void)
{
/* This is to make sure the console is restored to text mode before
we boot. */
grub_term_set_current_output (&grub_console_term_output);
grub_term_unregister_input (&grub_console_term_input);
grub_term_unregister_output (&grub_console_term_output);
}

View file

@ -77,7 +77,7 @@ inc_y (void)
static void
inc_x (void)
{
if (grub_curr_x >= COLS - 2)
if (grub_curr_x >= COLS - 1)
inc_y ();
else
grub_curr_x++;

View file

@ -83,12 +83,17 @@ grub_ofconsole_putchar (grub_uint32_t c)
grub_curr_y++;
grub_curr_x = 0;
}
else if (c == '\r')
{
grub_curr_x = 0;
}
else
{
grub_curr_x++;
if (grub_curr_x > grub_ofconsole_width)
if (grub_curr_x >= grub_ofconsole_width)
{
grub_putcode ('\n');
grub_ofconsole_putchar ('\n');
grub_ofconsole_putchar ('\r');
grub_curr_x++;
}
}
@ -236,16 +241,13 @@ grub_ofconsole_getxy (void)
return ((grub_curr_x - 1) << 8) | grub_curr_y;
}
static grub_uint16_t
grub_ofconsole_getwh (void)
static void
grub_ofconsole_dimensions (void)
{
grub_ieee1275_ihandle_t options;
char *val;
grub_ssize_t lval;
if (grub_ofconsole_width && grub_ofconsole_height)
return (grub_ofconsole_width << 8) | grub_ofconsole_height;
if (! grub_ieee1275_finddevice ("/options", &options)
&& options != (grub_ieee1275_ihandle_t) -1)
{
@ -282,7 +284,11 @@ grub_ofconsole_getwh (void)
grub_ofconsole_width = 80;
if (! grub_ofconsole_height)
grub_ofconsole_height = 24;
}
static grub_uint16_t
grub_ofconsole_getwh (void)
{
return (grub_ofconsole_width << 8) | grub_ofconsole_height;
}
@ -322,7 +328,7 @@ grub_ofconsole_cls (void)
* ANSI escape sequence. Using video console, Apple Open Firmware (version
* 3.1.1) only recognizes the literal ^L. So use both. */
grub_ofconsole_writeesc (" \e[2J");
grub_gotoxy (0, 0);
grub_ofconsole_gotoxy (0, 0);
}
static void
@ -382,6 +388,8 @@ grub_ofconsole_init_output (void)
grub_ofconsole_setcolorstate (GRUB_TERM_COLOR_NORMAL);
}
grub_ofconsole_dimensions ();
return 0;
}
@ -417,8 +425,7 @@ static struct grub_term_output grub_ofconsole_term_output =
.setcolor = grub_ofconsole_setcolor,
.getcolor = grub_ofconsole_getcolor,
.setcursor = grub_ofconsole_setcursor,
.refresh = grub_ofconsole_refresh,
.flags = 0,
.refresh = grub_ofconsole_refresh
};
void

View file

@ -17,8 +17,7 @@
*/
#include <grub/machine/memory.h>
#include <grub/machine/serial.h>
#include <grub/machine/console.h>
#include <grub/serial.h>
#include <grub/term.h>
#include <grub/types.h>
#include <grub/dl.h>
@ -26,9 +25,10 @@
#include <grub/terminfo.h>
#include <grub/cpu/io.h>
#include <grub/extcmd.h>
#include <grub/i18n.h>
#define TEXT_WIDTH 80
#define TEXT_HEIGHT 25
#define TEXT_HEIGHT 24
static unsigned int xpos, ypos;
static unsigned int keep_track = 1;
@ -38,22 +38,24 @@ static unsigned int registered = 0;
static char input_buf[8];
static unsigned int npending = 0;
static struct grub_term_output grub_serial_term_output;
/* Argument options. */
static const struct grub_arg_option options[] =
{
{"unit", 'u', 0, "Set the serial unit", 0, ARG_TYPE_INT},
{"port", 'p', 0, "Set the serial port address", 0, ARG_TYPE_STRING},
{"speed", 's', 0, "Set the serial port speed", 0, ARG_TYPE_INT},
{"word", 'w', 0, "Set the serial port word length", 0, ARG_TYPE_INT},
{"parity", 'r', 0, "Set the serial port parity", 0, ARG_TYPE_STRING},
{"stop", 't', 0, "Set the serial port stop bits", 0, ARG_TYPE_INT},
{"unit", 'u', 0, N_("Set the serial unit."), 0, ARG_TYPE_INT},
{"port", 'p', 0, N_("Set the serial port address."), 0, ARG_TYPE_STRING},
{"speed", 's', 0, N_("Set the serial port speed."), 0, ARG_TYPE_INT},
{"word", 'w', 0, N_("Set the serial port word length."), 0, ARG_TYPE_INT},
{"parity", 'r', 0, N_("Set the serial port parity."), 0, ARG_TYPE_STRING},
{"stop", 't', 0, N_("Set the serial port stop bits."), 0, ARG_TYPE_INT},
{0, 0, 0, 0, 0, 0}
};
/* Serial port settings. */
struct serial_port
{
unsigned short port;
grub_port_t port;
unsigned short divisor;
unsigned short word_len;
unsigned int parity;
@ -67,12 +69,13 @@ static struct serial_port serial_settings;
static const unsigned short *serial_hw_io_addr = (const unsigned short *) GRUB_MEMORY_MACHINE_BIOS_DATA_AREA_ADDR;
#define GRUB_SERIAL_PORT_NUM 4
#else
static const unsigned short serial_hw_io_addr[] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 };
#include <grub/machine/serial.h>
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
/* Return the port number for the UNITth serial device. */
static inline unsigned short
static inline grub_port_t
serial_hw_get_port (const unsigned int unit)
{
if (unit < GRUB_SERIAL_PORT_NUM)
@ -148,7 +151,7 @@ serial_translate_key_sequence (void)
if (input_buf[0] != '\e' || input_buf[1] != '[')
return;
for (i = 0; ARRAY_SIZE (three_code_table); i++)
for (i = 0; i < ARRAY_SIZE (three_code_table); i++)
if (three_code_table[i].key == input_buf[2])
{
input_buf[0] = three_code_table[i].ascii;
@ -253,6 +256,9 @@ grub_serial_getkey (void)
;
c = input_buf[0];
if (c == 0x7f)
c = GRUB_TERM_BACKSPACE;
grub_memmove (input_buf, input_buf + 1, --npending);
return c;
@ -363,7 +369,7 @@ grub_serial_putchar (grub_uint32_t c)
break;
case '\n':
if (ypos < TEXT_HEIGHT)
if (ypos < TEXT_HEIGHT - 1)
ypos++;
break;
@ -413,7 +419,7 @@ grub_serial_gotoxy (grub_uint8_t x, grub_uint8_t y)
else
{
keep_track = 0;
grub_terminfo_gotoxy (x, y);
grub_terminfo_gotoxy (x, y, &grub_serial_term_output);
keep_track = 1;
xpos = x;
@ -425,7 +431,7 @@ static void
grub_serial_cls (void)
{
keep_track = 0;
grub_terminfo_cls ();
grub_terminfo_cls (&grub_serial_term_output);
keep_track = 1;
xpos = ypos = 0;
@ -439,10 +445,10 @@ grub_serial_setcolorstate (const grub_term_color_state state)
{
case GRUB_TERM_COLOR_STANDARD:
case GRUB_TERM_COLOR_NORMAL:
grub_terminfo_reverse_video_off ();
grub_terminfo_reverse_video_off (&grub_serial_term_output);
break;
case GRUB_TERM_COLOR_HIGHLIGHT:
grub_terminfo_reverse_video_on ();
grub_terminfo_reverse_video_on (&grub_serial_term_output);
break;
default:
break;
@ -454,9 +460,9 @@ static void
grub_serial_setcursor (const int on)
{
if (on)
grub_terminfo_cursor_on ();
grub_terminfo_cursor_on (&grub_serial_term_output);
else
grub_terminfo_cursor_off ();
grub_terminfo_cursor_off (&grub_serial_term_output);
}
static struct grub_term_input grub_serial_term_input =
@ -502,7 +508,7 @@ grub_cmd_serial (grub_extcmd_t cmd,
}
if (state[1].set)
serial_settings.port = (unsigned short) grub_strtoul (state[1].arg, 0, 0);
serial_settings.port = (grub_port_t) grub_strtoul (state[1].arg, 0, 0);
if (state[2].set)
{

View file

@ -108,52 +108,52 @@ grub_terminfo_set_current (const char *str)
/* Wrapper for grub_putchar to write strings. */
static void
putstr (const char *str)
putstr (const char *str, grub_term_output_t oterm)
{
while (*str)
grub_putchar (*str++);
grub_putcode (*str++, oterm);
}
/* Move the cursor to the given position starting with "0". */
void
grub_terminfo_gotoxy (grub_uint8_t x, grub_uint8_t y)
grub_terminfo_gotoxy (grub_uint8_t x, grub_uint8_t y, grub_term_output_t oterm)
{
putstr (grub_terminfo_tparm (term.gotoxy, y, x));
putstr (grub_terminfo_tparm (term.gotoxy, y, x), oterm);
}
/* Clear the screen. */
void
grub_terminfo_cls (void)
grub_terminfo_cls (grub_term_output_t oterm)
{
putstr (grub_terminfo_tparm (term.cls));
putstr (grub_terminfo_tparm (term.cls), oterm);
}
/* Set reverse video mode on. */
void
grub_terminfo_reverse_video_on (void)
grub_terminfo_reverse_video_on (grub_term_output_t oterm)
{
putstr (grub_terminfo_tparm (term.reverse_video_on));
putstr (grub_terminfo_tparm (term.reverse_video_on), oterm);
}
/* Set reverse video mode off. */
void
grub_terminfo_reverse_video_off (void)
grub_terminfo_reverse_video_off (grub_term_output_t oterm)
{
putstr (grub_terminfo_tparm (term.reverse_video_off));
putstr (grub_terminfo_tparm (term.reverse_video_off), oterm);
}
/* Show cursor. */
void
grub_terminfo_cursor_on (void)
grub_terminfo_cursor_on (grub_term_output_t oterm)
{
putstr (grub_terminfo_tparm (term.cursor_on));
putstr (grub_terminfo_tparm (term.cursor_on), oterm);
}
/* Hide cursor. */
void
grub_terminfo_cursor_off (void)
grub_terminfo_cursor_off (grub_term_output_t oterm)
{
putstr (grub_terminfo_tparm (term.cursor_off));
putstr (grub_terminfo_tparm (term.cursor_off), oterm);
}
/* GRUB Command. */