[fb] Output klog to fb if video exists

If there's no video, do as we did before, otherwise route logs to the fb
driver instead. (Need to clean this up to just have a log consumer
general interface?) Also added a "scrollback" class to fb driver and
updated the system_get_log syscall.
This commit is contained in:
Justin C. Miller
2021-01-03 18:13:41 -08:00
parent dccb136c99
commit e477dea5c7
12 changed files with 181 additions and 29 deletions

View File

@@ -1,5 +1,6 @@
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include "j6/init.h"
#include "j6/errors.h"
@@ -10,12 +11,24 @@
#include "font.h"
#include "screen.h"
#include "scrollback.h"
extern "C" {
int main(int, const char **);
void _get_init(size_t *initc, struct j6_init_value **initv);
}
extern j6_handle_t __handle_sys;
struct entry
{
uint8_t bytes;
uint8_t area;
uint8_t severity;
uint8_t sequence;
char message[0];
};
int
main(int argc, const char **argv)
{
@@ -44,25 +57,45 @@ main(int argc, const char **argv)
screen scr(fb->addr, fb->horizontal, fb->vertical, order);
font fnt;
screen::pixel_t fg = scr.color(255, 255, 255);
screen::pixel_t fg = scr.color(0xb0, 0xb0, 0xb0);
screen::pixel_t bg = scr.color(49, 79, 128);
scr.fill(bg);
constexpr int margin = 4;
constexpr int margin = 2;
const unsigned xstride = (margin + fnt.width());
const unsigned ystride = (margin + fnt.height());
const unsigned rows = (scr.height() - margin) / ystride;
const unsigned cols = (scr.width() - margin) / xstride;
int y = margin;
char g = 0;
scrollback scroll(rows, cols);
while (y < scr.height() - margin - fnt.height()) {
int x = margin;
while (x < scr.width() - margin - fnt.width()) {
fnt.draw_glyph(scr, g+' ', fg, bg, x, y);
x += fnt.width() + fnt.width() / 4;
g = ++g % ('~' - ' ' + 1);
int pending = 0;
constexpr int pending_threshold = 10;
char message_buffer[256];
while (true) {
size_t size = sizeof(message_buffer);
_syscall_system_get_log(__handle_sys, message_buffer, &size);
if (size != 0) {
entry *e = reinterpret_cast<entry*>(&message_buffer);
size_t eom = e->bytes - sizeof(entry);
e->message[eom] = 0;
scroll.add_line(e->message, eom);
if (++pending > pending_threshold) {
scroll.render(scr, fnt);
pending = 0;
}
} else {
if (pending) {
scroll.render(scr, fnt);
pending = 0;
}
}
y += fnt.height() + fnt.height() / 4;
}
_syscall_system_log("fb driver done, exiting");
return 0;
}

View File

@@ -0,0 +1,61 @@
#include <stdlib.h>
#include <string.h>
#include "font.h"
#include "screen.h"
#include "scrollback.h"
scrollback::scrollback(unsigned lines, unsigned cols, unsigned margin) :
m_rows {lines},
m_cols {cols},
m_start {0},
m_count {0},
m_margin {margin}
{
m_data = reinterpret_cast<char*>(malloc(lines*cols));
m_lines = reinterpret_cast<char**>(malloc(lines*sizeof(char*)));
for (unsigned i = 0; i < lines; ++i)
m_lines[i] = &m_data[i*cols];
memset(m_data, ' ', lines*cols);
}
void
scrollback::add_line(const char *line, size_t len)
{
unsigned i = 0;
if (m_count < m_rows)
i = m_count++;
else
i = m_start++;
if (len > m_cols)
len = m_cols;
memcpy(m_lines[i % m_rows], line, len);
if (len < m_cols)
memset(m_lines[i % m_rows]+len, ' ', m_cols - len);
}
char *
scrollback::get_line(unsigned i)
{
return m_lines[(i+m_start)%m_rows];
}
void
scrollback::render(screen &scr, font &fnt)
{
screen::pixel_t fg = scr.color(0xb0, 0xb0, 0xb0);
screen::pixel_t bg = scr.color(49, 79, 128);
const unsigned xstride = (m_margin + fnt.width());
const unsigned ystride = (m_margin + fnt.height());
for (unsigned y = 0; y < m_rows; ++y) {
char *line = get_line(y);
for (unsigned x = 0; x < m_cols; ++x) {
fnt.draw_glyph(scr, line[x], fg, bg, m_margin+x*xstride, m_margin+y*ystride);
}
}
}

View File

@@ -0,0 +1,26 @@
#pragma once
/// \file scrollback.h
class screen;
class font;
class scrollback
{
public:
scrollback(unsigned lines, unsigned cols, unsigned margin = 2);
void add_line(const char *line, size_t len);
char * get_line(unsigned i);
void render(screen &scr, font &fnt);
private:
char *m_data;
char **m_lines;
unsigned m_rows, m_cols;
unsigned m_start;
unsigned m_count;
unsigned m_margin;
};