u-boot: sync console implementation from raspberry port
* VT100 is much more common than VT52 which the u-boot port was previously using (a legacy of the Atari m68k port) * Implement serial_getc (again, code is identical to raspberry port...) so the boot menu can be used over the serial port. The enter key is recognized, arrows currently aren't.
This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2004-2005, Axel Dörfler, [email protected]. All rights reserved.
|
* Copyright 2004-2005, Axel D?rfler, [email protected].
|
||||||
* Distributed under the terms of the MIT License.
|
* All rights reserved. Distributed under the terms of the MIT License.
|
||||||
|
*
|
||||||
|
* Copyright 2009 Jonas Sundström, [email protected]
|
||||||
|
* All rights reserved. Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@@ -16,54 +19,57 @@
|
|||||||
|
|
||||||
|
|
||||||
class Console : public ConsoleNode {
|
class Console : public ConsoleNode {
|
||||||
public:
|
public:
|
||||||
Console();
|
Console();
|
||||||
|
|
||||||
virtual ssize_t ReadAt(void *cookie, off_t pos, void *buffer, size_t bufferSize);
|
virtual ssize_t ReadAt(void* cookie, off_t pos, void* buffer,
|
||||||
virtual ssize_t WriteAt(void *cookie, off_t pos, const void *buffer, size_t bufferSize);
|
size_t bufferSize);
|
||||||
|
virtual ssize_t WriteAt(void* cookie, off_t pos,
|
||||||
|
const void* buffer, size_t bufferSize);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class VTConsole : public ConsoleNode {
|
class VTConsole : public ConsoleNode {
|
||||||
public:
|
public:
|
||||||
VTConsole();
|
VTConsole();
|
||||||
void ClearScreen();
|
void ClearScreen();
|
||||||
void SetCursor(int32 x, int32 y);
|
void SetCursor(int32 x, int32 y);
|
||||||
void SetColor(int32 foreground, int32 background);
|
void SetColor(int32 foreground, int32 background);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class SerialConsole : public VTConsole {
|
class SerialConsole : public VTConsole {
|
||||||
public:
|
public:
|
||||||
SerialConsole();
|
SerialConsole();
|
||||||
|
|
||||||
virtual ssize_t ReadAt(void *cookie, off_t pos, void *buffer, size_t bufferSize);
|
virtual ssize_t ReadAt(void *cookie, off_t pos, void *buffer,
|
||||||
virtual ssize_t WriteAt(void *cookie, off_t pos, const void *buffer, size_t bufferSize);
|
size_t bufferSize);
|
||||||
|
virtual ssize_t WriteAt(void *cookie, off_t pos, const void *buffer,
|
||||||
|
size_t bufferSize);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static Console sInput, sOutput;
|
static Console sInput;
|
||||||
|
static Console sOutput;
|
||||||
static SerialConsole sSerial;
|
static SerialConsole sSerial;
|
||||||
FILE *stdin, *stdout, *stderr;
|
|
||||||
|
|
||||||
|
FILE* stdin;
|
||||||
/*
|
FILE* stdout;
|
||||||
static void
|
FILE* stderr;
|
||||||
scroll_up()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
Console::Console()
|
Console::Console()
|
||||||
: ConsoleNode()
|
:
|
||||||
|
ConsoleNode()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ssize_t
|
ssize_t
|
||||||
Console::ReadAt(void *cookie, off_t pos, void *buffer, size_t bufferSize)
|
Console::ReadAt(void* cookie, off_t pos, void* buffer, size_t bufferSize)
|
||||||
{
|
{
|
||||||
// don't seek in character devices
|
// don't seek in character devices
|
||||||
// not implemented (and not yet? needed)
|
// not implemented (and not yet? needed)
|
||||||
@@ -72,7 +78,8 @@ Console::ReadAt(void *cookie, off_t pos, void *buffer, size_t bufferSize)
|
|||||||
|
|
||||||
|
|
||||||
ssize_t
|
ssize_t
|
||||||
Console::WriteAt(void *cookie, off_t /*pos*/, const void *buffer, size_t bufferSize)
|
Console::WriteAt(void* cookie, off_t /*pos*/, const void* buffer,
|
||||||
|
size_t bufferSize)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -82,26 +89,28 @@ Console::WriteAt(void *cookie, off_t /*pos*/, const void *buffer, size_t bufferS
|
|||||||
|
|
||||||
|
|
||||||
VTConsole::VTConsole()
|
VTConsole::VTConsole()
|
||||||
: ConsoleNode()
|
:
|
||||||
|
ConsoleNode()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
VTConsole::ClearScreen()
|
VTConsole::ClearScreen()
|
||||||
{
|
{
|
||||||
WriteAt(NULL, 0LL, "\033E", 2);
|
WriteAt(NULL, 0LL, "\033[2J", 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
VTConsole::SetCursor(int32 x, int32 y)
|
VTConsole::SetCursor(int32 x, int32 y)
|
||||||
{
|
{
|
||||||
char buff[] = "\033Y ";
|
char buffer[9];
|
||||||
x = MIN(79,MAX(0,x));
|
x = MIN(80, MAX(1, x));
|
||||||
y = MIN(24,MAX(0,y));
|
y = MIN(25, MAX(1, y));
|
||||||
buff[3] += (char)x;
|
int len = snprintf(buffer, sizeof(buffer),
|
||||||
buff[2] += (char)y;
|
"\033[%" B_PRId32 ";%" B_PRId32 "H", y, x);
|
||||||
WriteAt(NULL, 0LL, buff, 4);
|
WriteAt(NULL, 0LL, buffer, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -109,22 +118,24 @@ void
|
|||||||
VTConsole::SetColor(int32 foreground, int32 background)
|
VTConsole::SetColor(int32 foreground, int32 background)
|
||||||
{
|
{
|
||||||
static const char cmap[] = {
|
static const char cmap[] = {
|
||||||
15, 4, 2, 6, 1, 5, 3, 7,
|
0, 4, 2, 6, 1, 5, 3, 7 };
|
||||||
8, 12, 10, 14, 9, 13, 11, 0 };
|
char buffer[12];
|
||||||
char buff[] = "\033b \033c ";
|
|
||||||
|
|
||||||
if (foreground < 0 && foreground >= 16)
|
if (foreground < 0 || foreground >= 8)
|
||||||
return;
|
return;
|
||||||
if (background < 0 && background >= 16)
|
if (background < 0 || background >= 8)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
buff[2] += cmap[foreground];
|
// We assume normal display attributes here
|
||||||
buff[5] += cmap[background];
|
int len = snprintf(buffer, sizeof(buffer),
|
||||||
WriteAt(NULL, 0LL, buff, 6);
|
"\033[%" B_PRId32 ";%" B_PRId32 "m",
|
||||||
|
cmap[foreground] + 30, cmap[background] + 40);
|
||||||
|
|
||||||
|
WriteAt(NULL, 0LL, buffer, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
SerialConsole::SerialConsole()
|
SerialConsole::SerialConsole()
|
||||||
@@ -143,14 +154,15 @@ SerialConsole::ReadAt(void *cookie, off_t pos, void *buffer, size_t bufferSize)
|
|||||||
|
|
||||||
|
|
||||||
ssize_t
|
ssize_t
|
||||||
SerialConsole::WriteAt(void *cookie, off_t /*pos*/, const void *buffer, size_t bufferSize)
|
SerialConsole::WriteAt(void *cookie, off_t /*pos*/, const void *buffer,
|
||||||
|
size_t bufferSize)
|
||||||
{
|
{
|
||||||
serial_puts((const char *)buffer, bufferSize);
|
serial_puts((const char *)buffer, bufferSize);
|
||||||
return bufferSize;
|
return bufferSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -193,6 +205,15 @@ console_hide_cursor(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
console_wait_for_key(void)
|
||||||
|
{
|
||||||
|
union key key;
|
||||||
|
key.ax = serial_getc(true);
|
||||||
|
return key.code.ascii;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
console_set_color(int32 foreground, int32 background)
|
console_set_color(int32 foreground, int32 background)
|
||||||
{
|
{
|
||||||
@@ -200,18 +221,12 @@ console_set_color(int32 foreground, int32 background)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
|
||||||
console_wait_for_key(void)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
console_init(void)
|
console_init(void)
|
||||||
{
|
{
|
||||||
stdin = (FILE *)&sSerial;
|
stdin = (FILE *)&sSerial;
|
||||||
stdout = stderr = (FILE *)&sSerial;
|
stdout = (FILE *)&sSerial;
|
||||||
|
stderr = (FILE *)&sSerial;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
/*
|
/*
|
||||||
** Copyright 2004, Axel Dörfler, [email protected]. All rights reserved.
|
* Copyright 2009 Jonas Sundström, [email protected]
|
||||||
** Distributed under the terms of the Haiku License.
|
* All rights reserved. Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
#ifndef CONSOLE_H
|
#ifndef _SYSTEM_BOOT_PLATFORM_STUB_CONSOLE_H
|
||||||
#define CONSOLE_H
|
#define _SYSTEM_BOOT_PLATFORM_STUB_CONSOLE_H
|
||||||
|
|
||||||
#include <boot/platform/generic/text_console.h>
|
#include <boot/platform/generic/text_console.h>
|
||||||
|
|
||||||
@@ -17,4 +17,4 @@ extern status_t console_init(void);
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* CONSOLE_H */
|
#endif /* _SYSTEM_BOOT_PLATFORM_STUB_CONSOLE_H */
|
||||||
|
|||||||
@@ -40,6 +40,13 @@ serial_putc(char c)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
extern "C" int
|
||||||
|
serial_getc(bool wait)
|
||||||
|
{
|
||||||
|
return gUART->GetChar(wait);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
extern "C" void
|
extern "C" void
|
||||||
serial_puts(const char* string, size_t size)
|
serial_puts(const char* string, size_t size)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ extern void serial_init(const void *fdt);
|
|||||||
extern void serial_cleanup(void);
|
extern void serial_cleanup(void);
|
||||||
|
|
||||||
extern void serial_puts(const char *string, size_t size);
|
extern void serial_puts(const char *string, size_t size);
|
||||||
|
extern int serial_getc(bool wait);
|
||||||
|
|
||||||
extern void serial_disable(void);
|
extern void serial_disable(void);
|
||||||
extern void serial_enable(void);
|
extern void serial_enable(void);
|
||||||
|
|||||||
Reference in New Issue
Block a user