#define PAGESIZE (4*1024)
#include <l4io.h>
#include <l4/types.h>
#include "kickstart.h"
#include "mbi.h"
#include "kipmgr.h"
#include "lib.h"
loader_format_t loader_formats[] = {
{ "multiboot compliant loader", mbi_probe, mbi_init },
NULL_LOADER
};
void fail(int ec)
{
printf("PANIC: FAIL in line %d\n", ec);
while(1);
}
void flush_cache()
{
__asm__ __volatile__ ("wbinvd");
}
void launch_kernel(L4_Word_t entry)
{
__asm__ __volatile__ ("jmp *%0" : : "r"(entry));
}
#if defined(CONFIG_COMPORT)
#if CONFIG_COMPORT == 0
# define COMPORT 0x3f8
#elif CONFIG_COMPORT == 1
# define COMPORT 0x2f8
#elif CONFIG_COMPORT == 2
# define COMPORT 0x3e8
#elif CONFIG_COMPORT == 3
# define COMPORT 0x2e8
#else
#define COMPORT CONFIG_COMPORT
#endif
extern inline L4_Word8_t inb(L4_Word_t port)
{
L4_Word8_t tmp;
if (port < 0x100)
__asm__ __volatile__ ("inb %w1, %0" :"=al"(tmp) :"dN"(port));
else
__asm__ __volatile__ ("inb %%dx, %0" :"=al"(tmp) :"d"(port));
return tmp;
}
extern inline void outb(L4_Word_t port, L4_Word8_t val)
{
if (port < 0x100)
__asm__ __volatile__ ("outb %1, %w0" : :"dN"(port), "al"(val));
else
__asm__ __volatile__ ("outb %1, %%dx" : :"d"(port), "al"(val));
}
static void init_serial(void)
{
#define IER (COMPORT+1)
#define EIR (COMPORT+2)
#define LCR (COMPORT+3)
#define MCR (COMPORT+4)
#define LSR (COMPORT+5)
#define MSR (COMPORT+6)
#define DLLO (COMPORT+0)
#define DLHI (COMPORT+1)
outb(LCR, 0x80);
for (volatile int i = 10000000; i--; );
outb(DLLO, (((115200/CONFIG_COMSPEED) >> 0) & 0x00FF));
outb(DLHI, (((115200/CONFIG_COMSPEED) >> 8) & 0x00FF));
outb(LCR, 0x03);
outb(IER, 0x00);
outb(EIR, 0x07);
inb(IER);
inb(EIR);
inb(LCR);
inb(MCR);
inb(LSR);
inb(MSR);
}
#define DISPLAY ((char*)0xb8000)
#define COLOR 15
#define NUM_LINES 25
void __vga_putc(int c)
{
unsigned int i;
static unsigned __cursor = 160 * (NUM_LINES - 1);
switch(c) {
case '\r':
break;
case '\n':
do
{
DISPLAY[__cursor++] = ' ';
DISPLAY[__cursor++] = COLOR;
}
while (__cursor % 160 != 0);
break;
case '\t':
do
{
DISPLAY[__cursor++] = ' ';
DISPLAY[__cursor++] = COLOR;
}
while (__cursor % 16 != 0);
break;
default:
DISPLAY[__cursor++] = c;
DISPLAY[__cursor++] = COLOR;
}
if (__cursor == (160 * NUM_LINES)) {
for (i = (160 / sizeof (L4_Word_t));
i < (160 / sizeof (L4_Word_t)) * NUM_LINES;
i++)
((L4_Word_t *) DISPLAY)[i - 160 / sizeof (L4_Word_t)]
= ((L4_Word_t *) DISPLAY)[i];
for (i = 0; i < 160 / sizeof (L4_Word_t); i++)
((L4_Word_t *) DISPLAY)[160 / sizeof (L4_Word_t)
* (NUM_LINES-1) + i] = 0;
__cursor -= 160;
}
}
extern "C" void putc(int c)
{
static bool do_init = true;
if( do_init )
{
do_init = false;
init_serial();
}
extern void __l4_putc(int c);
__l4_putc(c);
__vga_putc(c);
}
#endif