Vystem 0.2

This commit is contained in:
2026-05-27 19:34:54 +02:00
parent a43c08b893
commit d238606b75
372 changed files with 51320 additions and 83217 deletions

View File

@@ -0,0 +1,29 @@
// SPDX-License-Identifier: MPL-2.0
#ifndef SH_LIB_PRINT_H
#define SH_LIB_PRINT_H
#include "std/status.h"
#include "std/type.h"
#include "kernel/log.h"
#include "kernel/conf.h"
#include "cpu/ap.h"
#define SH_DEBUG SH_LOG_DEBUG
#define SH_LOG SH_LOG_LOG
#define SH_WARNING SH_LOG_WARNING
#define SH_ERROR SH_LOG_ERROR
#define SH_CRITICAL SH_LOG_CRITICAL
#define SH_FATAL SH_LOG_FATAL
#define SH_TEST SH_LOG_TEST
#define SH_FAULT SH_LOG_FAULT
// Setup rings buffer for APs
SH_STATUS sh_print_setup_ring_buffers_per_ap(sh_conf_BOOT_CONFIG *boot_config);
// Print string
SH_STATUS sh_print(sh_log_OUTPUT_TYPE output_type,char* text);
// Print string, format it before hand
SH_STATUS sh_printf(sh_log_OUTPUT_TYPE output_type,char* format,...);
// Priority print string, reserved to IRQ handler
SH_STATUS sh_iprint(sh_log_OUTPUT_TYPE output_type,char* text);
// Priority print string, reserved to IRQ handler, format it before hand
SH_STATUS sh_iprintf(sh_log_OUTPUT_TYPE output_type,char* text,...);
// Format a string and put it into the provided buffer
SH_STATUS sh_sprintf(char* output_string,sh_uint64 output_len,char* format,...);
#endif

View File

@@ -0,0 +1,19 @@
// SPDX-License-Identifier: MPL-2.0
#ifndef SH_LIB_QUEUE_H
#define SH_LIB_QUEUE_H
#include "std/type.h"
#include "std/status.h"
#include "devs/input/event.h"
// Keyboard events queue structure
typedef struct {
sh_kbd_EVENT *buffer;
sh_uint32 capacity;
sh_uint32 write_index;
} sh_queue_KBD_EVENT;
// Initialize an event queue
SH_STATUS sh_queue_event_init(sh_queue_KBD_EVENT *q,sh_uint32 capacity);
// Push a keyboard event to the provided queue
SH_STATUS sh_queue_event_push(sh_queue_KBD_EVENT *q,sh_kbd_EVENT ev);
// Destroy the provided keyboard event queue
SH_STATUS sh_queue_event_destroy(sh_queue_KBD_EVENT *q);
#endif

View File

@@ -0,0 +1,74 @@
// SPDX-License-Identifier: MPL-2.0
#ifndef SH_LIB_SMP_H
#define SH_LIB_SMP_H
#include "std/type.h"
#include "std/status.h"
#include "cpu/ap.h"
#include "cpu/serial.h"
#include "cpu/asm.h"
// Write GS base register
inline void sh_smp_write_gs_base(sh_uint64 value) {
sh_uint32 low=(sh_uint32)(value);
sh_uint32 high=(sh_uint32)(value>>32);
__asm__ volatile ("wrmsr"::"c"(0xC0000101),"a"(low),"d"(high));
}
// Return CPU struct of this CPU
inline sh_ap_CPU_STRUCT *sh_smp_gs_base() {
sh_uint32 low,high;
__asm__ volatile ("rdmsr":"=a"(low),"=d"(high):"c"(0xC0000101));
return (sh_ap_CPU_STRUCT*)(((sh_uint64)high<<32)|low);
}
// Lock structure, unlocked lock have lapic_id to SH_UINT32_MAX
typedef struct {
volatile sh_uint32 spinlock;
sh_uint32 lapic_id;
} sh_SPIN_LOCK;
// Create an unlocked lock, intended for creation of global variables.
#define SH_LOCK() {.spinlock=0,.lapic_id=SH_UINT32_MAX}
// Create an unlocked lock, intended for creation of local variables
#define SH_LOCK_LOCAL() ((sh_SPIN_LOCK){.spinlock=0,.lapic_id=SH_UINT32_MAX})
// Lock a spinlock
inline void sh_spin_lock(sh_SPIN_LOCK *lock) {
while (__atomic_test_and_set(&lock->spinlock,__ATOMIC_ACQUIRE)) {
while (lock->spinlock) {
__asm__ volatile ("pause");
}
}
if (sh_smp_gs_base()==SH_NULLPTR) {
sh_serial_send_byte('!');
while (SH_TRUE) {}
}
lock->lapic_id=sh_smp_gs_base()->lapic_id;
}
// Unlock a spinlock
inline void sh_spin_unlock(sh_SPIN_LOCK *lock) {
lock->lapic_id=SH_UINT32_MAX;
__atomic_clear(&lock->spinlock,__ATOMIC_RELEASE);
}
// Try to lock a spinlock, doesn't wait for it to be unlocked, return SH_TRUE if lock is now owned by us
inline sh_bool sh_spin_trylock(sh_SPIN_LOCK *lock) {
if (__atomic_test_and_set(&lock->spinlock,__ATOMIC_ACQUIRE)) return SH_FALSE;
lock->lapic_id=sh_smp_gs_base()->lapic_id;
return SH_TRUE;
}
// Return which CPU is locking the lock
inline sh_uint32 sh_spin_wholock(sh_SPIN_LOCK *lock) {
return lock->lapic_id;
}
// Set CPU count (aka max_cpu_id+1)
void sh_smp_set_cpu_count(sh_int16 cpu_count);
// Return CPU count, return -1 if this value isn't initialized
sh_int16 sh_smp_get_cpu_count();
// Memory barrier
inline void sh_mb() {
sh_asm_mfence();
}
// Read memory barrier
inline void sh_rmb() {
sh_asm_lfence();
}
// Write memory barrier
inline void sh_wmb() {
sh_asm_sfence();
}
#endif

View File

@@ -36,6 +36,17 @@ typedef sh_int64 SH_STATUS;
#define SH_STATUS_PAGE_ALREADY_FREE 25LL
#define SH_STATUS_TOO_MUCH_DATA 26LL
#define SH_STATUS_HEAP_NOT_INITIALIZED 27LL
#define SH_STATUS_MEMORY_SUBSYSTEM_NOT_INITIALIZED 28LL
#define SH_STATUS_INVALID_CHECKSUM 29LL
#define SH_STATUS_BAD_SIZE 30LL
#define SH_STATUS_INVALID_STATE 31LL
#define SH_STATUS_DEVS_NOT_INITIALIZED 32LL
#define SH_STATUS_UNAVAILABLE 33LL
#define SH_STATUS_ALREADY_INITIALIZED 34LL
#define SH_STATUS_AP_NO_LAPIC 35LL
#define SH_STATUS_ISO_UNKNOW_BUS 36LL
#define SH_STATUS_INVALID_HANDLE 37LL
#define SH_STATUS_DEVICE_NOT_PRESENT 38LL
// Return SH_TRUE if provided status is an error
static inline sh_bool sh_status_error(SH_STATUS s) {
return s>=SH_STATUS_INVALID_PARAMETER;

View File

@@ -1,7 +1,11 @@
// SPDX-License-Identifier: MPL-2.0
// This header is just here to include all standard header
// If you are looking for printing functions, take a look at kernel/log.h
// If you are looking for non-thread safe/more direct printing functions, take a look at kernel/log.h
#include "std/mem.h"
#include "std/malloc.h"
#include "std/status.h"
#include "std/print.h"
#include "std/smp.h"
#include "std/type.h"
#include "std/status.h"
#include "std/string.h"
#include "std/queue.h"

View File

@@ -0,0 +1,17 @@
// SPDX-License-Identifier: MPL-2.0
#ifndef SH_LIB_STRING_H
#define SH_LIB_STRING_H
#include "std/type.h"
// Return the length of a null terminated string
sh_uint64 sh_string_len(char *str);
// Compare two null terminated string, both strings must not exceed the provided length. Return SH_TRUE if both strings are equals on the provided length
sh_bool sh_string_compare(char *str1,char* str2,sh_uint64 length);
// Return the index of the first occurence of the provided character into the string, return SH_UINT64_MAX if not found or error
sh_uint64 sh_string_find_char(char *str,char character);
// Return the index of the start of the first occurence of the provided substring into the string, return SH_UINT64_MAX if not found or error
sh_uint64 sh_string_find(char *str,char *substr);
// Copy a substring from a string to another string, and return the pointer to the new string
char *sh_string_substring(char *source_str,sh_uint64 start_index,sh_uint64 length,char *output);
// Convert a string to a sh_uint64
sh_uint64 sh_string_to_uint64(char *str);
#endif