#include #include #include #include #include #include #include #include #include #include #include #include extern volatile struct limine_framebuffer_request fb_liminereq; static size_t xs, ys, fbxs, fbys; // TODO make more efficient. works for now static void *internalalloc(size_t n) { void *addr = pmm_alloc(n / PAGE_SIZE + 1, PMM_SECTION_DEFAULT); __assert(addr); return MAKE_HHDM(addr); } static struct flanterm_context *term_ctx; static mutex_t term_mutex; void term_write(char *str, size_t count) { MUTEX_ACQUIRE(&term_mutex); flanterm_write(term_ctx, str, count); MUTEX_RELEASE(&term_mutex); } void term_putchar(char c) { flanterm_write(term_ctx, &c, 1); } void term_getsize(size_t *x, size_t *y, size_t *fbx, size_t *fby) { *x = xs; *y = ys; *fbx = fbxs; *fby = fbys; } static void noop(void *, size_t) { } void term_init() { __assert(fb_liminereq.response); __assert(fb_liminereq.response->framebuffer_count); struct limine_framebuffer *fb = fb_liminereq.response->framebuffers[0]; uint32_t defaultbg = 0x1b1c1b; uint32_t defaultfg = 0xffffff; // TODO add support for a background if desired by the user term_ctx = flanterm_fb_init(internalalloc, noop, fb->address, fb->width, fb->height, fb->pitch, fb->red_mask_size, fb->red_mask_shift, fb->green_mask_size, fb->green_mask_shift, fb->blue_mask_size, fb->blue_mask_shift, NULL, NULL, NULL, &defaultbg, &defaultfg, NULL, NULL, NULL, 0, 0, 1, 1, 1, 0); __assert(term_ctx); xs = term_ctx->cols; ys = term_ctx->rows; fbxs = fb->width; fbys = fb->height; MUTEX_INIT(&term_mutex); logging_sethook(term_putchar); } void term_update_framebuffer(void *fb) { ((struct flanterm_fb_context *)fb)->framebuffer = fb; } INIT_ROUTINE_DEFINE(term, INIT_ROUTINE_FLAGS_NONE, term_init, vmm);