#include <idl4glue.h>
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <new>
#include <assert.h>
#include <l4/thread.h>
#include <l4/schedule.h>
#include <l4/ipc.h>
#include <string.h>
#include <sdi/panic.h>
#include <sdi/log.h>
#include <sdi/locator.h>
#include <if/iflocator.h>
#include <if/iffile.h>
#include <if/ifsyscall.h>
#include <sdi/panic.h>
namespace
{
static L4_ThreadId_t consoleid = L4_nilthread;
static CORBA_Environment env (idl4_default_environment);
static objectid_t consolehandle;
static char* consoleNr = NULL;
}
char kbgerman[128] =
{
0, 27, '1', '2', '3', '4', '5', '6', '7', '8',
'9', '0', 0, 0, '\b',
'\t',
'q', 'w', 'e', 'r',
't', 'z', 'u', 'i', 'o', 'p', 0, '+', '\n',
0,
'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 0,
0, '^', 0,
'#', 'y', 'x', 'c', 'v', 'b', 'n',
'm', ',', '.', '-', 0,
0,
0,
' ',
0,
0,
0, 0, 0, 0, 0, 0, 0, 0,
0,
0,
0,
0,
0,
0,
'-',
0,
0,
0,
'+',
0,
0,
0,
0,
127,
0, 0, '<',
0,
0,
0,
};
char kbgerman_shift[128] =
{
0, 27, '!', '"', '§', '$', '%', '&', '/', '(',
')', '=', '?', 0, '\b',
'\t',
'Q', 'W', 'E', 'R',
'T', 'Z', 'U', 'I', 'O', 'P', 0, '*', '\n',
0,
'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 0,
0, '°', 0,
'\'', 'Y', 'X', 'C', 'V', 'B', 'N',
'M', ';', ':', '_', 0,
0,
0,
' ',
0,
0,
0, 0, 0, 0, 0, 0, 0, 0,
0,
0,
0,
0,
0,
0,
'-',
0,
0,
0,
'+',
0,
0,
0,
0,
127,
0, 0, '>',
0,
0,
0,
};
int CTRLpressed(uint32_t keyStatus) {
return (keyStatus & 0x00000001) || (keyStatus & 0x00000002);
}
int ALTpressed(uint32_t keyStatus) {
return (keyStatus & 0x00000004) || (keyStatus & 0x00000008);
}
int SHIFTpressed(uint32_t keyStatus) {
return (keyStatus & 0x00000010) || (keyStatus & 0x00000020);
}
extern "C" {
char ScancodeToAscii(uint8_t scancode, uint32_t keyStatus) {
if(SHIFTpressed(keyStatus)) {
return kbgerman_shift[scancode];
} else {
return kbgerman[scancode];
}
}
L4_Bool_t isPrintable(uint8_t scancode, uint32_t keyStatus) {
uint8_t ascii = ScancodeToAscii(scancode, keyStatus);
if( 32 <= ascii && ascii <= 126) {
return 1;
} else {
return 0;
}
}
void writeConsole(const char* message, ...)
{
if(consoleid == L4_nilthread) {
if(consoleNr == NULL && getenv("STDOUT") != NULL) {
consoleNr = getenv("STDOUT");
LogMessage("Using env!");
} else {
consoleNr = "/console0";
}
LogMessage("Waiting for console");
while(GetObject(consoleNr, IF_FILE_ID, &consoleid, &consolehandle) != OK) {
L4_Yield();
printf(".");
}
}
char buf[160];
va_list ap;
va_start(ap, message);
vsnprintf(buf, sizeof(buf), message, ap);
va_end(ap);
idlsize_t byteswritten;
buffer_t msgbuf;
msgbuf._buffer = new char[160];
strcpy(msgbuf._buffer, buf);
msgbuf._length = strlen(msgbuf._buffer);
IF_FILE_Write((CORBA_Object)consoleid, consolehandle, 0, &byteswritten, &msgbuf, &env);
delete msgbuf._buffer;
}
void readConsole(const idlsize_t readsize, buffer_t *buffer) {
if(consoleid == L4_nilthread) {
if(consoleNr == NULL && getenv("STDIN") != NULL) {
consoleNr = getenv("STDIN");
LogMessage("Using env!");
} else {
consoleNr = "/console0";
}
LogMessage("Waiting for console");
while(GetObject(consoleNr, IF_FILE_ID, &consoleid, &consolehandle) != OK) {
L4_Yield();
LogMessage(".");
}
}
IF_FILE_Read((CORBA_Object)consoleid, consolehandle, 0, readsize, buffer, &env);
};
}