mirror of
https://github.com/subhobhai943/SUB-OS.git
synced 2026-10-25 16:52:29 +00:00
- Implement AArch64 HAL, vector table (16 aligned vectors), GICv2, Generic Timer, Stage-1 MMU (39-bit VA), PL011 UART - Build unified multi-architecture abstraction layer in include/arch/arch.h - Create interactive Linux-like Kconfig TUI menuconfig in scripts/kconfig/menuconfig.py - Support make menuconfig, defconfig, x86_64_defconfig, aarch64_defconfig - Update master Makefile for cross-compiling x86_64 (x86_64-elf-) and AArch64 (aarch64-linux-gnu-) - Dynamic architecture awareness across printk, uname, neofetch, and LazyBox
43 lines
873 B
C
43 lines
873 B
C
#ifndef _KERNEL_SYNC_H
|
|
#define _KERNEL_SYNC_H
|
|
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
|
|
typedef struct {
|
|
volatile uint32_t lock;
|
|
} spinlock_t;
|
|
|
|
#define SPINLOCK_INIT { .lock = 0 }
|
|
|
|
static inline void spinlock_init(spinlock_t* lock) {
|
|
lock->lock = 0;
|
|
}
|
|
|
|
static inline void spin_lock(spinlock_t* lock) {
|
|
while (__atomic_test_and_set(&lock->lock, __ATOMIC_ACQUIRE)) {
|
|
#if defined(__x86_64__)
|
|
__asm__ volatile ("pause");
|
|
#elif defined(__aarch64__)
|
|
__asm__ volatile ("yield");
|
|
#else
|
|
__asm__ volatile ("");
|
|
#endif
|
|
}
|
|
}
|
|
|
|
static inline void spin_unlock(spinlock_t* lock) {
|
|
__atomic_clear(&lock->lock, __ATOMIC_RELEASE);
|
|
}
|
|
|
|
typedef struct {
|
|
spinlock_t lock;
|
|
volatile int count;
|
|
} semaphore_t;
|
|
|
|
void sem_init(semaphore_t* sem, int value);
|
|
void sem_wait(semaphore_t* sem);
|
|
void sem_post(semaphore_t* sem);
|
|
|
|
#endif // _KERNEL_SYNC_H
|