95 lines
2.1 KiB
C
95 lines
2.1 KiB
C
/*
|
|
* @author xamidev <xamidev@riseup.net>
|
|
* @brief Framebuffer-based terminal driver
|
|
* @license GPL-3.0-only
|
|
*/
|
|
|
|
// Terminal output
|
|
/*
|
|
There are a couple of bugs here and there but for now I don't care too much
|
|
because this shitty implementation will be replaced one day by Flanterm
|
|
(once memory management is okay: paging & kernel malloc)
|
|
*/
|
|
|
|
#include <stddef.h>
|
|
#include <kernel.h>
|
|
#include "term.h"
|
|
#include "config.h"
|
|
#include "flanterm.h"
|
|
#include "flanterm_backends/fb.h"
|
|
#include "mem/heap/kheap.h"
|
|
#include "limine.h"
|
|
|
|
extern struct flanterm_context* ft_ctx;
|
|
extern struct init_status init;
|
|
|
|
/*
|
|
* _putchar - Writes a character to terminal
|
|
* @character: character to write
|
|
*/
|
|
void _putchar(char character)
|
|
{
|
|
// TODO: Spinlock here (terminal access)
|
|
flanterm_write(ft_ctx, &character, 1);
|
|
}
|
|
|
|
/*
|
|
* kputs - Kernel puts
|
|
* @str: String to write
|
|
*
|
|
* Writes a non-formatted string to terminal
|
|
*/
|
|
void kputs(const char* str)
|
|
{
|
|
size_t i=0;
|
|
while (str[i] != 0) {
|
|
_putchar(str[i]);
|
|
i++;
|
|
}
|
|
_putchar('\r');
|
|
}
|
|
|
|
extern struct flanterm_context* ft_ctx;
|
|
extern struct boot_context boot_ctx;
|
|
|
|
/*
|
|
* flanterm_free_wrapper - free() wrapper for Flanterm
|
|
* @ptr: pointer to free
|
|
* @size: amount of bytes to free
|
|
*
|
|
* This function exists solely because the Flanterm initialization
|
|
* function only accepts a free() function with a size parameter,
|
|
* and the default one doesn't have it.
|
|
*/
|
|
void flanterm_free_wrapper(void* ptr, size_t size)
|
|
{
|
|
(void)size;
|
|
kfree(ptr);
|
|
}
|
|
|
|
/*
|
|
* term_init - Video output/terminal initialization
|
|
*
|
|
* Uses Flanterm and the framebuffer given by Limine.
|
|
*/
|
|
void term_init()
|
|
{
|
|
uint32_t bgColor = 0x252525;
|
|
ft_ctx = flanterm_fb_init(
|
|
kmalloc,
|
|
flanterm_free_wrapper,
|
|
boot_ctx.fb->address, boot_ctx.fb->width, boot_ctx.fb->height, boot_ctx.fb->pitch,
|
|
boot_ctx.fb->red_mask_size, boot_ctx.fb->red_mask_shift,
|
|
boot_ctx.fb->green_mask_size, boot_ctx.fb->green_mask_shift,
|
|
boot_ctx.fb->blue_mask_size, boot_ctx.fb->blue_mask_shift,
|
|
NULL,
|
|
NULL, NULL,
|
|
&bgColor, NULL,
|
|
NULL, NULL,
|
|
NULL, 0, 0, 1,
|
|
0, 0,
|
|
0,
|
|
0
|
|
);
|
|
init.terminal = true;
|
|
} |