logger fixes

This commit is contained in:
2026-10-12 15:51:58 +02:00
parent eabce70866
commit 350e65837b
5 changed files with 69 additions and 25 deletions
+26 -5
View File
@@ -26,6 +26,7 @@ enum esc_state {
static struct {
struct boot_framebuffer fb;
uint32_t* back;
uint32_t fg, bg;
size_t cols, rows;
size_t offset_x, offset_y;
@@ -37,6 +38,15 @@ static inline uint8_t* fb_ptr() {
return HHDM_PTR(fbcon.fb.base);
}
static inline uint32_t* back_row(size_t y) {
return fbcon.back + y * fbcon.fb.width;
}
static void flush_rect(size_t x, size_t y, size_t w, size_t h) {
for (size_t j = 0; j < h; j++)
memcpy((uint32_t*)(fb_ptr() + (y + j) * fbcon.fb.pitch) + x, back_row(y + j) + x, w * sizeof(uint32_t));
}
static uint32_t pack_color(uint32_t rgb) {
const struct boot_framebuffer* fb = &fbcon.fb;
uint32_t r = (rgb >> 16) & 0xff;
@@ -48,10 +58,11 @@ static uint32_t pack_color(uint32_t rgb) {
static void fill_rect(size_t x, size_t y, size_t w, size_t h, uint32_t color) {
for (size_t j = 0; j < h; j++) {
uint32_t* row = (uint32_t*)(fb_ptr() + (y + j) * fbcon.fb.pitch) + x;
uint32_t* row = back_row(y + j) + x;
for (size_t i = 0; i < w; i++)
row[i] = color;
}
flush_rect(x, y, w, h);
}
static void clear_screen() {
@@ -65,19 +76,25 @@ static void draw_glyph(size_t col, size_t row, uint8_t ch) {
size_t y = fbcon.offset_y + row * FONT_HEIGHT;
for (size_t j = 0; j < FONT_HEIGHT; j++) {
uint32_t* line = (uint32_t*)(fb_ptr() + (y + j) * fbcon.fb.pitch) + x;
uint32_t* line = back_row(y + j) + x;
for (size_t i = 0; i < FONT_WIDTH; i++)
line[i] = (glyph[j] & (0x80 >> i)) ? fbcon.fg : fbcon.bg;
}
flush_rect(x, y, FONT_WIDTH, FONT_HEIGHT);
}
static void scroll_up() {
const size_t pitch = fbcon.fb.pitch;
const size_t width = fbcon.fb.width;
const size_t text_y = fbcon.offset_y;
const size_t text_h = fbcon.rows * FONT_HEIGHT;
memmove(fb_ptr() + text_y * pitch, fb_ptr() + (text_y + FONT_HEIGHT) * pitch, (text_h - FONT_HEIGHT) * pitch);
fill_rect(0, text_y + text_h - FONT_HEIGHT, fbcon.fb.width, FONT_HEIGHT, fbcon.bg);
memmove(back_row(text_y), back_row(text_y + FONT_HEIGHT), (text_h - FONT_HEIGHT) * width * sizeof(uint32_t));
for (size_t j = text_y + text_h - FONT_HEIGHT; j < text_y + text_h; j++) {
uint32_t* row = back_row(j);
for (size_t i = 0; i < width; i++)
row[i] = fbcon.bg;
}
flush_rect(0, text_y, width, text_h);
}
static void newline() {
@@ -178,6 +195,10 @@ void fbcon_init(struct boot_info* info) {
return;
}
fbcon.back = mem_alloc(fb->width * fb->height * sizeof(uint32_t), ALLOC_NOZERO);
if (!fbcon.back)
return;
console_register(&fbcon_con);
}
INIT_TASK(fbcon_stage, "core.fbcon", fbcon_init);