[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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user