Implemented console output for x86 boot loader.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@7029 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2004-03-19 18:28:26 +00:00
parent 5afca6b536
commit 788d2b04ea
2 changed files with 128 additions and 0 deletions
@@ -0,0 +1,106 @@
/*
** Copyright 2004, Axel Dörfler, [email protected]. All rights reserved.
** Distributed under the terms of the OpenBeOS License.
*/
#include <SupportDefs.h>
#include <string.h>
#include <util/kernel_cpp.h>
#include "console.h"
class Console : public ConsoleNode {
public:
Console();
virtual ssize_t ReadAt(void *cookie, off_t pos, void *buffer, size_t bufferSize);
virtual ssize_t WriteAt(void *cookie, off_t pos, const void *buffer, size_t bufferSize);
};
static uint16 *sScreenBase = (uint16 *)0xb8000;
static uint32 sScreenWidth = 80;
static uint32 sScreenHeight = 24;
static uint32 sScreenOffset = 0;
static Console sInput, sOutput;
FILE *stdin, *stdout, *stderr;
static void
clear_screen()
{
for (uint32 i = 0; i < sScreenWidth * sScreenHeight; i++)
sScreenBase[i] = 0xf20;
}
static void
scroll_up()
{
memcpy(sScreenBase, sScreenBase + sScreenWidth,
sScreenWidth * sScreenHeight * 2 - sScreenWidth * 2);
sScreenOffset = (sScreenHeight - 1) * sScreenWidth;
for (uint32 i = 0; i < sScreenWidth; i++)
sScreenBase[sScreenOffset + i] = 0x0720;
}
// #pragma mark -
Console::Console()
: ConsoleNode()
{
}
ssize_t
Console::ReadAt(void *cookie, off_t pos, void *buffer, size_t bufferSize)
{
// don't seek in character devices
// not implemented (and not yet? needed)
return B_ERROR;
}
ssize_t
Console::WriteAt(void *cookie, off_t /*pos*/, const void *buffer, size_t bufferSize)
{
const char *string = (const char *)buffer;
for (uint32 i = 0; i < bufferSize; i++) {
if (string[0] == '\n')
sScreenOffset += sScreenWidth - (sScreenOffset % sScreenWidth);
else
sScreenBase[sScreenOffset++] = 0xf00 | string[0];
if (sScreenOffset >= sScreenWidth * sScreenHeight)
scroll_up();
string++;
}
return bufferSize;
}
// #pragma mark -
status_t
console_init(void)
{
// ToDo: make screen size changeable via stage2_args
clear_screen();
// enable stdio functionality
stdin = (FILE *)&sInput;
stdout = stderr = (FILE *)&sOutput;
return B_OK;
}
@@ -0,0 +1,22 @@
/*
** Copyright 2004, Axel Dörfler, [email protected]. All rights reserved.
** Distributed under the terms of the OpenBeOS License.
*/
#ifndef CONSOLE_H
#define CONSOLE_H
#include <boot/vfs.h>
#include <boot/stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
extern status_t console_init(void);
#ifdef __cplusplus
}
#endif
#endif /* CONSOLE_H */