Files
SUB-OS/include/kernel/sync.h
T
subhobhai943 7b646c8cc4 feat(arch): Add armv8i (32-bit ARM/AArch32) architecture & complete TUI configurator
- Support ARMv8i / ARM32 (AArch32) baremetal target with arm-linux-gnueabihf toolchain
- Implement ARMv8i boot entry point, banked exception mode stacks (IRQ, ABT, UND, SVC)
- Implement 8 exception vectors, GICv2 distributor/CPU interface, CP15 Generic Timer (100 Hz), flat Section MMU
- Support PL011 UART for early console & interactive LazyBox TTY input
- Update Makefile with make armv8i_defconfig and automated cross-compilation
- Update scripts/kconfig/menuconfig.py with dedicated armv8i options
2026-08-18 11:13:23 +05:30

51 lines
1.1 KiB
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) {
#if defined(__x86_64__)
while (__atomic_test_and_set(&lock->lock, __ATOMIC_ACQUIRE)) {
__asm__ volatile ("pause");
}
#elif defined(__aarch64__)
while (__atomic_test_and_set(&lock->lock, __ATOMIC_ACQUIRE)) {
__asm__ volatile ("yield");
}
#elif defined(__arm__) || defined(__armv8i__)
while (__atomic_test_and_set(&lock->lock, __ATOMIC_ACQUIRE)) {
__asm__ volatile ("nop");
}
#else
while (__atomic_test_and_set(&lock->lock, __ATOMIC_ACQUIRE)) {
__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