Switch to nanoprintf + good spinlock (rflags) = no more FLANTERM ISSUES???

This commit is contained in:
2026-03-15 09:34:17 +01:00
parent 6a3abb0f55
commit af3a9e27fd
15 changed files with 1708 additions and 1039 deletions

29
src/sched/spinlock.c Normal file
View File

@@ -0,0 +1,29 @@
/*
* @author xamidev <xamidev@riseup.net>
* @brief Spinlock implementation
* @license GPL-3.0-only
*/
#include <stdatomic.h>
#include <stdbool.h>
#include "kernel.h"
#include "spinlock.h"
void spinlock_acquire(struct spinlock_t* lock)
{
uint64_t rflags;
asm volatile("pushfq ; pop %0 ; cli" : "=rm"(rflags) : : "memory");
while (__atomic_test_and_set(&lock->locked, __ATOMIC_ACQUIRE)) {
__builtin_ia32_pause();
}
lock->rflags = rflags;
}
void spinlock_release(struct spinlock_t* lock)
{
uint64_t rflags = lock->rflags;
__atomic_clear(&lock->locked, __ATOMIC_RELEASE);
asm volatile("push %0 ; popfq" : : "rm"(rflags) : "memory");
}

22
src/sched/spinlock.h Normal file
View File

@@ -0,0 +1,22 @@
/*
* @author xamidev <xamidev@riseup.net>
* @brief Spinlock implementation
* @license GPL-3.0-only
*/
#ifndef SPINLOCK_H
#define SPINLOCK_H
#include <stdbool.h>
#include <stdint.h>
struct spinlock_t
{
bool locked;
uint64_t rflags;
};
void spinlock_acquire(struct spinlock_t* lock);
void spinlock_release(struct spinlock_t* lock);
#endif