add console emulation into serial terminal support using vt100-compatible escape sequences, add --enable-serial into configure, and fix some bugs in the support.

This commit is contained in:
okuji committed 2000-08-20 12:14:14 +00:00
1 parent 7d54a86a52
commit 2455b65f2e
16 files changed
+485 -144

No files matched your search

+14 -4
View File
@@ -19,7 +19,8 @@ libgrub_a_SOURCES = boot.c builtins.c common.c char_io.c cmdline.c \
fsys_minix.c fsys_reiserfs.c stage2.c
libgrub_a_CFLAGS = $(GRUB_CFLAGS) -I$(top_srcdir)/lib \
-DGRUB_UTIL=1 -DFSYS_EXT2FS=1 -DFSYS_FAT=1 -DFSYS_FFS=1 \
-DFSYS_MINIX=1 -DFSYS_REISERFS=1 -fwritable-strings
-DFSYS_MINIX=1 -DFSYS_REISERFS=1 -DSUPPORT_SERIAL \
-fwritable-strings
# Stage 2 and Stage 1.5's.
pkgdatadir = $(datadir)/$(PACKAGE)/$(host_cpu)-$(host_vendor)
@@ -48,13 +49,22 @@ PRE_STAGE2_LINK = -nostdlib -Wl,-N -Wl,-Ttext -Wl,8200
START_LINK = -nostdlib -Wl,-N -Wl,-Ttext -Wl,8000
NBLOADER_LINK = -nostdlib -Wl,-N -Wl,-Ttext -Wl,0
PXELOADER_LINK = -nostdlib -Wl,-N -Wl,-Ttext -Wl,7C00
if NETBOOT_SUPPORT
STAGE2_COMPILE = $(STAGE2_CFLAGS) -fno-builtin -nostdinc \
-I$(top_srcdir)/netboot -DSUPPORT_NETBOOT=1
NETBOOT_FLAGS = -I$(top_srcdir)/netboot -DSUPPORT_NETBOOT=1
else
STAGE2_COMPILE = $(STAGE2_CFLAGS) -fno-builtin -nostdinc
NETBOOT_FLAGS =
endif
if SERIAL_SUPPORT
SERIAL_FLAGS = -DSUPPORT_SERIAL=1
else
SERIAL_FLAGS =
endif
STAGE2_COMPILE = $(STAGE2_CFLAGS) -fno-builtin -nostdinc \
$(NETBOOT_FLAGS) $(SERIAL_FLAGS)
STAGE1_5_LINK = -nostdlib -Wl,-N -Wl,-Ttext -Wl,2000
STAGE1_5_COMPILE = $(STAGE2_COMPILE) -DNO_DECOMPRESSION=1 -DSTAGE1_5=1
+10 -4
View File
@@ -109,7 +109,8 @@ libgrub_a_SOURCES = boot.c builtins.c common.c char_io.c cmdline.c \
libgrub_a_CFLAGS = $(GRUB_CFLAGS) -I$(top_srcdir)/lib \
-DGRUB_UTIL=1 -DFSYS_EXT2FS=1 -DFSYS_FAT=1 -DFSYS_FFS=1 \
-DFSYS_MINIX=1 -DFSYS_REISERFS=1 -fwritable-strings
-DFSYS_MINIX=1 -DFSYS_REISERFS=1 -DSUPPORT_SERIAL \
-fwritable-strings
# Stage 2 and Stage 1.5's.
@@ -135,9 +136,14 @@ PRE_STAGE2_LINK = -nostdlib -Wl,-N -Wl,-Ttext -Wl,8200
START_LINK = -nostdlib -Wl,-N -Wl,-Ttext -Wl,8000
NBLOADER_LINK = -nostdlib -Wl,-N -Wl,-Ttext -Wl,0
PXELOADER_LINK = -nostdlib -Wl,-N -Wl,-Ttext -Wl,7C00
@NETBOOT_SUPPORT_TRUE@STAGE2_COMPILE = @NETBOOT_SUPPORT_TRUE@$(STAGE2_CFLAGS) -fno-builtin -nostdinc \
@NETBOOT_SUPPORT_TRUE@ -I$(top_srcdir)/netboot -DSUPPORT_NETBOOT=1
@NETBOOT_SUPPORT_FALSE@STAGE2_COMPILE = @NETBOOT_SUPPORT_FALSE@$(STAGE2_CFLAGS) -fno-builtin -nostdinc
@NETBOOT_SUPPORT_TRUE@NETBOOT_FLAGS = @NETBOOT_SUPPORT_TRUE@-I$(top_srcdir)/netboot -DSUPPORT_NETBOOT=1
@NETBOOT_SUPPORT_FALSE@NETBOOT_FLAGS =
@SERIAL_SUPPORT_TRUE@SERIAL_FLAGS = @SERIAL_SUPPORT_TRUE@-DSUPPORT_SERIAL=1
@SERIAL_SUPPORT_FALSE@SERIAL_FLAGS =
STAGE2_COMPILE = $(STAGE2_CFLAGS) -fno-builtin -nostdinc \
$(NETBOOT_FLAGS) $(SERIAL_FLAGS)
STAGE1_5_LINK = -nostdlib -Wl,-N -Wl,-Ttext -Wl,2000
STAGE1_5_COMPILE = $(STAGE2_COMPILE) -DNO_DECOMPRESSION=1 -DSTAGE1_5=1
+6 -6
View File
@@ -1756,7 +1756,7 @@ ENTRY(multi_boot)
/*
* cls()
* console_cls()
* BIOS call "INT 10H Function 0Fh" to get current video mode
* Call with %ah = 0x0f
* Returns %al = (video mode)
@@ -1767,7 +1767,7 @@ ENTRY(multi_boot)
*/
ENTRY(cls)
ENTRY(console_cls)
push %ebp
push %eax
push %ebx /* save EBX */
@@ -1821,7 +1821,7 @@ ENTRY(nocursor)
/*
* getxy()
* console_getxy()
* BIOS call "INT 10H Function 03h" to get cursor position
* Call with %ah = 0x03
* %bh = page
@@ -1832,7 +1832,7 @@ ENTRY(nocursor)
*/
ENTRY(getxy)
ENTRY(console_getxy)
push %ebp
push %ebx /* save EBX */
push %ecx /* save ECX */
@@ -1859,7 +1859,7 @@ ENTRY(getxy)
/*
* gotoxy(x,y)
* console_gotoxy(x,y)
* BIOS call "INT 10H Function 02h" to set cursor position
* Call with %ah = 0x02
* %bh = page
@@ -1868,7 +1868,7 @@ ENTRY(getxy)
*/
ENTRY(gotoxy)
ENTRY(console_gotoxy)
push %ebp
push %eax
push %ebx /* save EBX */
+6
View File
@@ -3319,6 +3319,12 @@ terminal_func (char *arg, int flags)
{
terminal = TERMINAL_SERIAL;
(void) getkey ();
if (flags & BUILTIN_CMDLINE)
{
/* FIXME: It is better to restart enter_cmdline except
for init_cmdline. */
init_page ();
}
break;
}
+143
View File
@@ -815,6 +815,149 @@ grub_putchar (int c)
#endif /* ! STAGE1_5 */
}
#ifndef STAGE1_5
void
gotoxy (int x, int y)
{
if (terminal & TERMINAL_CONSOLE)
console_gotoxy (x, y);
#ifdef SUPPORT_SERIAL
else if (terminal & TERMINAL_SERIAL)
serial_gotoxy (x, y);
#endif
}
#ifdef SUPPORT_SERIAL
/* The serial part of gotoxy. */
void
serial_gotoxy (int x, int y)
{
grub_printf ("\e[%d;%dH", y + 1, x + 1);
}
#endif /* SUPPORT_SERIAL */
int
getxy (void)
{
int ret = 0;
if (terminal & TERMINAL_CONSOLE)
ret = console_getxy ();
#ifdef SUPPORT_SERIAL
else if (terminal & TERMINAL_SERIAL)
ret = serial_getxy ();
#endif
return ret;
}
#ifdef SUPPORT_SERIAL
/* The serial part of getxy. */
int
serial_getxy (void)
{
int x, y;
int start, now;
char buf[32]; /* XXX */
int i;
int c;
char *p;
/* Drain the input buffer. */
while (serial_checkkey () != -1)
serial_getkey ();
/* CPR. */
grub_printf ("\e[6n");
/* Get current time. */
while ((start = getrtsecs ()) == 0xFF)
;
again:
i = 0;
c = 0;
do
{
if (serial_checkkey () != -1)
{
c = serial_getkey ();
if (i == 1 && c != '[')
i = 0;
if (i == 0 && c != '\e')
continue;
if (i != 0 && c == '\e')
i = 0;
buf[i] = c;
i++;
}
else
{
/* Get current time. */
while ((now = getrtsecs ()) == 0xFF)
;
/* FIXME: Remove this magic number. */
if (now - start > 10)
{
/* Something is quite wrong. */
return 0;
}
}
}
while (c != 'R' && i < sizeof (buf));
if (c != 'R')
goto again;
p = buf + 2;
if (! safe_parse_maxint (&p, &y))
{
errnum = 0;
goto again;
}
if (*p != ';')
goto again;
p++;
if (! safe_parse_maxint (&p, &x))
{
errnum = 0;
goto again;
}
if (*p != 'R')
goto again;
return ((x - 1) << 8) | (y - 1);
}
#endif /* SUPPORT_SERIAL */
void
cls (void)
{
if (terminal & TERMINAL_CONSOLE)
console_cls ();
#ifdef SUPPORT_SERIAL
else if (terminal & TERMINAL_SERIAL)
serial_cls ();
#endif
}
#ifdef SUPPORT_SERIAL
/* The serial part of cls. */
void
serial_cls (void)
{
grub_printf ("\e[H\e[J");
}
#endif /* SUPPORT_SERIAL */
#endif /* ! STAGE1_5 */
int
substring (char *s1, char *s2)
{
+9
View File
@@ -77,6 +77,15 @@ int serial_getkey (void);
/* The serial part of checkkey. */
int serial_checkkey (void);
/* The serial part of cls. */
void serial_cls (void);
/* The serial part of getxy. */
int serial_getxy (void);
/* The serial part of gotoxy. */
void serial_gotoxy (int x, int y);
/* Return the port number for the UNITth serial device. */
unsigned short serial_get_port (int unit);
+9
View File
@@ -639,6 +639,9 @@ int currticks (void);
/* Clear the screen. */
void cls (void);
/* The console part of cls. */
void console_cls (void);
#ifndef GRUB_UTIL
/* Turn off cursor. */
void nocursor (void);
@@ -649,9 +652,15 @@ void nocursor (void);
(RET & 0xff) is y. */
int getxy (void);
/* The console part of getxy. */
int console_getxy (void);
/* Set the cursor position. */
void gotoxy (int x, int y);
/* The console part of gotoxy. */
void console_gotoxy (int x, int y);
/* Displays an ASCII character. IBM displays will translate some
characters to special graphical ones (see the DISP_* constants). */
void grub_putchar (int c);
+110 -40
View File
@@ -44,13 +44,23 @@ static void
print_entries (int y, int size, int first, char *menu_entries)
{
int i;
int disp_up = DISP_UP;
int disp_down = DISP_DOWN;
#ifdef SUPPORT_SERIAL
if (terminal & TERMINAL_SERIAL)
{
disp_up = ACS_UARROW;
disp_down = ACS_DARROW;
}
#endif /* SUPPORT_SERIAL */
gotoxy (77, y + 1);
if (first)
putchar (DISP_UP);
grub_putchar (disp_up);
else
putchar (' ');
grub_putchar (' ');
menu_entries = get_entry (menu_entries, first, 0);
@@ -64,7 +74,7 @@ print_entries (int y, int size, int first, char *menu_entries)
{
if (j < 71)
{
putchar (*menu_entries);
grub_putchar (*menu_entries);
j++;
}
@@ -75,15 +85,15 @@ print_entries (int y, int size, int first, char *menu_entries)
menu_entries++;
for (; j < 71; j++)
putchar (' ');
grub_putchar (' ');
}
gotoxy (77, y + size);
if (*menu_entries)
putchar (DISP_DOWN);
grub_putchar (disp_down);
else
putchar (' ');
grub_putchar (' ');
}
@@ -91,26 +101,49 @@ static void
print_border (int y, int size)
{
int i;
int disp_ul = DISP_UL;
int disp_ur = DISP_UR;
int disp_ll = DISP_LL;
int disp_lr = DISP_LR;
int disp_horiz = DISP_HORIZ;
int disp_vert = DISP_VERT;
#ifdef SUPPORT_SERIAL
if (terminal & TERMINAL_SERIAL)
{
disp_ul = ACS_ULCORNER;
disp_ur = ACS_URCORNER;
disp_ll = ACS_LLCORNER;
disp_lr = ACS_LRCORNER;
disp_horiz = ACS_HLINE;
disp_vert = ACS_VLINE;
}
#endif /* SUPPORT_SERIAL */
#ifndef GRUB_UTIL
/* Color the menu. The menu is 75 * 14 characters. */
for (i = 0; i < 14; i++)
#ifdef SUPPORT_SERIAL
if (terminal & TERMINAL_CONSOLE)
#endif
{
int j;
for (j = 0; j < 75; j++)
for (i = 0; i < 14; i++)
{
gotoxy (j + 1, i + y);
set_attrib (normal_color);
int j;
for (j = 0; j < 75; j++)
{
gotoxy (j + 1, i + y);
set_attrib (normal_color);
}
}
}
#endif
gotoxy (1, y);
putchar (DISP_UL);
grub_putchar (disp_ul);
for (i = 0; i < 73; i++)
putchar (DISP_HORIZ);
putchar (DISP_UR);
grub_putchar (disp_horiz);
grub_putchar (disp_ur);
i = 1;
@@ -121,51 +154,79 @@ print_border (int y, int size)
if (i > size)
break;
putchar (DISP_VERT);
grub_putchar (disp_vert);
gotoxy (75, y + i);
putchar (DISP_VERT);
grub_putchar (disp_vert);
i++;
}
putchar (DISP_LL);
grub_putchar (disp_ll);
for (i = 0; i < 73; i++)
putchar (DISP_HORIZ);
putchar (DISP_LR);
grub_putchar (disp_horiz);
grub_putchar (disp_lr);
}
static void
set_line (int y, int attr)
set_line (int y, int entryno, int attr, char *menu_entries)
{
int x;
for (x = 2; x < 75; x++)
#ifdef SUPPORT_SERIAL
if (terminal & TERMINAL_SERIAL)
{
gotoxy (x, y);
set_attrib (attr);
menu_entries = get_entry (menu_entries, entryno, 0);
gotoxy (2, y);
grub_putchar (' ');
for (x = 3; x < 75; x++)
{
if (*menu_entries && x < 71)
grub_putchar (*menu_entries++);
else
grub_putchar (' ');
}
}
else
#endif /* SUPPORT_SERIAL */
{
for (x = 2; x < 75; x++)
{
gotoxy (x, y);
set_attrib (attr);
}
}
}
/* Set the attribute of the line Y to normal state. */
static void
set_line_normal (int y)
set_line_normal (int y, int entryno, char *menu_entries)
{
#ifdef GRUB_UTIL
set_line (y, A_NORMAL);
set_line (y, entryno, A_NORMAL, menu_entries);
#else
set_line (y, normal_color);
set_line (y, entryno, normal_color, menu_entries);
#endif
}
/* Set the attribute of the line Y to highlight state. */
static void
set_line_highlight (int y)
set_line_highlight (int y, int entryno, char *menu_entries)
{
#ifdef SUPPORT_SERIAL
if (terminal & TERMINAL_SERIAL)
grub_printf ("\e[7m");
#endif /* SUPPORT_SERIAL */
#ifdef GRUB_UTIL
set_line (y, A_REVERSE);
set_line (y, entryno, A_REVERSE, menu_entries);
#else
set_line (y, highlight_color);
set_line (y, entryno, highlight_color, menu_entries);
#endif
#ifdef SUPPORT_SERIAL
if (terminal & TERMINAL_SERIAL)
grub_printf ("\e[0m");
#endif /* SUPPORT_SERIAL */
}
static void
@@ -228,8 +289,11 @@ restart:
{
init_page ();
#ifndef GRUB_UTIL
nocursor ();
#endif
# ifdef SUPPORT_SERIAL
if (terminal & TERMINAL_CONSOLE)
# endif /* SUPPORT_SERIAL */
nocursor ();
#endif /* ! GRUB_UTIL */
print_border (3, 12);
@@ -265,7 +329,7 @@ restart:
print_entries (3, 12, first_entry, menu_entries);
/* highlight initial line */
set_line_highlight (4 + entryno);
set_line_highlight (4 + entryno, first_entry + entryno, menu_entries);
}
/* XX using RT clock now, need to initialize value */
@@ -309,15 +373,17 @@ restart:
{
if (entryno > 0)
{
set_line_normal (4 + entryno);
set_line_normal (4 + entryno, first_entry + entryno,
menu_entries);
entryno--;
set_line_highlight (4 + entryno);
set_line_highlight (4 + entryno, first_entry + entryno,
menu_entries);
}
else if (first_entry > 0)
{
first_entry--;
print_entries (3, 12, first_entry, menu_entries);
set_line_highlight (4);
set_line_highlight (4, first_entry + entryno, menu_entries);
}
}
if (((c == KEY_DOWN) || (ASCII_CHAR (c) == 14))
@@ -325,15 +391,17 @@ restart:
{
if (entryno < 11)
{
set_line_normal (4 + entryno);
set_line_normal (4 + entryno, first_entry + entryno,
menu_entries);
entryno++;
set_line_highlight (4 + entryno);
set_line_highlight (4 + entryno, first_entry + entryno,
menu_entries);
}
else if (num_entries > 12 + first_entry)
{
first_entry++;
print_entries (3, 12, first_entry, menu_entries);
set_line_highlight (15);
set_line_highlight (15, first_entry + entryno, menu_entries);
}
}
@@ -348,7 +416,8 @@ restart:
{
if ((c == 'd') || (c == 'o') || (c == 'O'))
{
set_line_normal (4 + entryno);
set_line_normal (4 + entryno, first_entry + entryno,
menu_entries);
/* insert after is almost exactly like insert before */
if (c == 'o')
@@ -397,7 +466,8 @@ restart:
}
print_entries (3, 12, first_entry, menu_entries);
set_line_highlight (4 + entryno);
set_line_highlight (4 + entryno, first_entry + entryno,
menu_entries);
}
cur_entry = menu_entries;