printf spinlock + remove DEPRECATED stuff + begin separating x86 stuff

This commit is contained in:
2026-03-20 09:01:57 +01:00
parent 424b4c4632
commit 3607a7179c
12 changed files with 77 additions and 138 deletions
+1 -1
View File
@@ -4,7 +4,7 @@
* @license GPL-3.0-only
*/
#include <idt/idt.h>
#include <arch/x86.h>
#include <stdint.h>
#include <stddef.h>
#include <io/serial/serial.h>
+1 -1
View File
@@ -5,7 +5,7 @@
*/
#include <stddef.h>
#include <idt/idt.h>
#include <arch/x86.h>
#include <io/serial/serial.h>
#include <kernel.h>
+3 -3
View File
@@ -216,10 +216,10 @@ void keyboard_handler()
if (c) {
if (c == '\n') {
_putchar('\r');
internal_putc('\r', NULL);
}
// Should probably have a keyboard buffer here... instead of this
_putchar(c);
internal_putc(c, NULL);
keyboard_putchar(c);
}
}
+19 -32
View File
@@ -30,19 +30,10 @@ extern struct flanterm_context* ft_ctx;
extern struct init_status init;
struct spinlock_t term_lock = {0};
struct spinlock_t printf_lock = {0};
extern int panic_count;
/*
* _putchar - Writes a character to terminal (DEPRECATED)
* @character: character to write
*/
void _putchar(char character)
{
// TODO: Spinlock here (terminal access)
flanterm_write(ft_ctx, &character, 1);
}
/*
* internal_putc - Internal putchar function
* @c: char to print
@@ -83,14 +74,26 @@ void internal_putc(int c, void *_)
*
* Return:
* <ret> - number of characters sent to the callback
* %-1 - error
*/
int printf(const char* fmt, ...)
{
va_list args;
va_start(args, fmt);
int ret = npf_vpprintf(internal_putc, NULL, fmt, args);
va_end(args);
return ret;
if (panic_count == 0) {
spinlock_acquire(&printf_lock);
va_list args;
va_start(args, fmt);
int ret = npf_vpprintf(internal_putc, NULL, fmt, args);
va_end(args);
spinlock_release(&printf_lock);
return ret;
} else {
va_list args;
va_start(args, fmt);
int ret = npf_vpprintf(internal_putc, NULL, fmt, args);
va_end(args);
return ret;
}
return -1;
}
/*
@@ -103,30 +106,14 @@ void kputs(const char* str)
{
size_t i=0;
while (str[i] != 0) {
_putchar(str[i]);
internal_putc(str[i], NULL);
i++;
}
_putchar('\r');
}
extern struct flanterm_context* ft_ctx;
extern struct boot_context boot_ctx;
/*
* flanterm_free_wrapper - free() wrapper for Flanterm (DEPRECATED)
* @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
*
-1
View File
@@ -12,7 +12,6 @@
#include <io/serial/serial.h>
#include <mem/gdt.h>
#include <mem/utils.h>
#include <idt/idt.h>
#include <kernel.h>
#include <time/timer.h>
#include <io/kbd/ps2.h>
-37
View File
@@ -25,43 +25,6 @@ First we'll have to discover the physical memory layout,
and for that we can use a Limine request.
*/
// DEPRECATED
struct limine_memmap_entry* biggest_entry;
/*
* pmm_find_biggest_usable_region - Finding the biggest free memory region (DEPRECATED)
* @memmap: Limine memory map
* @hhdm: Limine HHDM offset
*
* This function uses the memory map provided by the bootloader
* to find the single biggest free memory region we can use.
*/
static void pmm_find_biggest_usable_region(struct limine_memmap_response* memmap, struct limine_hhdm_response* hhdm)
{
// Max length of a usable memory region
uint64_t length_max = 0;
uint64_t offset = hhdm->offset;
DEBUG("Usable Memory:");
for (size_t i=0; i<memmap->entry_count; i++) {
struct limine_memmap_entry* entry = memmap->entries[i];
if (entry->type == LIMINE_MEMMAP_USABLE) {
DEBUG("0x%p-0x%p mapped at 0x%p-0x%p", entry->base, entry->base+entry->length,
entry->base+offset, entry->base+entry->length+offset);
if (entry->length > length_max)
{
length_max = entry->length;
biggest_entry = entry;
}
}
}
DEBUG("Biggest usable memory region:");
DEBUG("0x%p-0x%p mapped at 0x%p-0x%p", biggest_entry->base, biggest_entry->base + biggest_entry->length,
biggest_entry->base+offset, biggest_entry->base+biggest_entry->length+offset);
}
// Offset from Higher Half Direct Map
uint64_t hhdm_off;