First commit, Vystem v0.1

This commit is contained in:
2026-03-31 22:15:00 +02:00
commit e15daed8c0
462 changed files with 134655 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
// SPDX-License-Identifier: MPL-2.0
#ifndef SH_LIB_CONF_H
#define SH_LIB_CONF_H
#include "std/type.h"
#include "std/status.h"
#include "memory/page.h"
#include "memory/vmem_layout.h"
#define SH_CONF_BOOT_CONFIG_VA SH_VMEM_LAYOUT_BOOT_CONFIG_VA
// Boot config structure.
typedef struct __attribute__((aligned(8))) {
sh_uint8 sig_start[8];
sh_uint8 log_level;
sh_uint16 page_table_allocator_level;
sh_page_PHYSICAL_ADDRESS page_table_pool_pa;
sh_page_VIRTUAL_ADDRESS page_table_pool_va;
sh_bool test_benchmark;
sh_uint64 bench_iterations;
sh_bool log_disable_serial_port;
sh_bool disable_serial_port;
sh_uint16 log_ring_size;
sh_uint8 sig_end[8];
} sh_conf_BOOT_CONFIG;
// Check and create boot config structure.
SH_STATUS sh_conf_get_boot_config(sh_conf_BOOT_CONFIG **config);
#endif

View File

@@ -0,0 +1,146 @@
// SPDX-License-Identifier: MPL-2.0
#ifndef SH_LIB_LOG_H
#define SH_LIB_LOG_H
#include "std/type.h"
#include "std/status.h"
#include "cpu/tsc.h"
typedef sh_uint8 sh_log_OUTPUT_TYPE;
#define SH_LOG_DEBUG ((sh_log_OUTPUT_TYPE)0)
#define SH_LOG_LOG ((sh_log_OUTPUT_TYPE)1)
#define SH_LOG_WARNING ((sh_log_OUTPUT_TYPE)2)
#define SH_LOG_ERROR ((sh_log_OUTPUT_TYPE)3)
#define SH_LOG_CRITICAL ((sh_log_OUTPUT_TYPE)4)
#define SH_LOG_FATAL ((sh_log_OUTPUT_TYPE)5)
#define SH_LOG_TEST ((sh_log_OUTPUT_TYPE)6)
typedef sh_uint16 sh_log_OUTPUT_SOURCE;
#define SH_LOG_SOURCE_MAIN ((sh_log_OUTPUT_SOURCE)0)
#define SH_LOG_SOURCE_CONF ((sh_log_OUTPUT_SOURCE)1)
#define SH_LOG_SOURCE_PAGE ((sh_log_OUTPUT_SOURCE)2)
#define SH_LOG_SOURCE_SLAB ((sh_log_OUTPUT_SOURCE)3)
#define SH_LOG_SOURCE_TEST ((sh_log_OUTPUT_SOURCE)4)
#define SH_LOG_SOURCE_PEZ ((sh_log_OUTPUT_SOURCE)5)
#define SH_LOG_SOURCE_PBA ((sh_log_OUTPUT_SOURCE)6)
#define SH_LOG_SOURCE_HEAP ((sh_log_OUTPUT_SOURCE)7)
#define SH_LOG_SOURCE_STD ((sh_log_OUTPUT_SOURCE)8)
typedef struct {
sh_log_OUTPUT_TYPE output_type;
sh_log_OUTPUT_SOURCE output_source;
sh_tsc_TSC_VALUE tsc_value;
const char* message_pointer;
} sh_log_OUTPUT_PAYLOAD;
// Return SH_TRUE if provided output type is valid.
static inline sh_bool sh_log_output_type_valid(sh_log_OUTPUT_TYPE t) {
return t<=SH_LOG_TEST;
}
// Return SH_TRUE if provided source type is valid.
static inline sh_bool sh_log_output_source_valid(sh_log_OUTPUT_SOURCE s) {
return s<=SH_LOG_SOURCE_STD;
}
// Load serial logging setting
void sh_log_load_serial_setting(sh_bool is_disabled);
// Return current serial logging setting
sh_bool sh_log_get_serial_setting();
// Load logging ring size in pages
void sh_log_load_logging_ring_size(sh_uint16 pages_count);
// Return logging ring size in bytes
sh_uint32 sh_log_get_logging_ring_size();
// Return total bytes written to the ring buffer
sh_uint64 sh_log_get_total_bytes_written();
// Log a byte
void sh_log_byte(sh_uint8 byte);
// Log a string
SH_STATUS sh_log_string(const char* str);
// Log an sh_int8 encoded in decimal
SH_STATUS sh_log_int8(sh_int8 n);
// Log an sh_int16 encoded in decimal
SH_STATUS sh_log_int16(sh_int16 n);
// Log an sh_int32 encoded in decimal
SH_STATUS sh_log_int32(sh_int32 n);
// Log an sh_int64 encoded in decimal
SH_STATUS sh_log_int64(sh_int64 n);
// Log an sh_uint8 encoded in decimal
SH_STATUS sh_log_uint8(sh_uint8 n);
// Log an sh_uint16 encoded in decimal
SH_STATUS sh_log_uint16(sh_uint16 n);
// Log an sh_uint32 encoded in decimal
SH_STATUS sh_log_uint32(sh_uint32 n);
// Log an sh_uint64 encoded in decimal
SH_STATUS sh_log_uint64(sh_uint64 n);
// Log an sh_uint8 encoded in hexadecimal
SH_STATUS sh_log_uint8_hex(sh_uint8 n);
// Log an sh_uint16 encoded in hexadecimal
SH_STATUS sh_log_uint16_hex(sh_uint16 n);
// Log an sh_uint32 encoded in hexadecimal
SH_STATUS sh_log_uint32_hex(sh_uint32 n);
// Log an sh_uint64 encoded in hexadecimal
SH_STATUS sh_log_uint64_hex(sh_uint64 n);
// Log an sh_uint64 encoded in hexadecimal without trimming useless zeros
SH_STATUS sh_log_uint64_hex_fixed(sh_uint64 n);
// Log a double encoded in decimal
SH_STATUS sh_log_double(double value);
// Format a string using the following format string
SH_STATUS sh_log_format(const char* format,va_list args);
// All logs functions starting below take into account log_level.
// Send an output payload to logging system.
SH_STATUS sh_log_payload(sh_log_OUTPUT_PAYLOAD *payload);
// Send an output payload to logging system, format it before sending it.
SH_STATUS sh_log_payload_format(sh_log_OUTPUT_PAYLOAD *payload,va_list args);
// Change log level. Intended for single use only.
SH_STATUS sh_log_load_log_level(sh_uint8 log_level);
// Return log level.
sh_uint8 sh_log_get_log_level();
// Print a string to test channel.
SH_STATUS sh_log_test(const char* str);
// Print a string to debug channel, from provided source.
SH_STATUS sh_log_debug(const char* str,sh_log_OUTPUT_SOURCE source);
// Print a string to log channel, from provided source.
SH_STATUS sh_log_log(const char* str,sh_log_OUTPUT_SOURCE source);
// Print a string to warning channel, from provided source.
SH_STATUS sh_log_warning(const char* str,sh_log_OUTPUT_SOURCE source);
// Print a string to error channel, from provided source.
SH_STATUS sh_log_error(const char* str,sh_log_OUTPUT_SOURCE source);
// Print a string to critical channel, from provided source.
SH_STATUS sh_log_critical(const char* str,sh_log_OUTPUT_SOURCE source);
// Print a string to fatal channel, from provided source.
SH_STATUS sh_log_fatal(const char* str,sh_log_OUTPUT_SOURCE source);
// Print a string to test channel. Doesn't include the new line caracter.
SH_STATUS sh_log_ltest(const char* str);
// Print a string to debug channel, from provided source. Doesn't include the new line caracter.
SH_STATUS sh_log_ldebug(const char* str,sh_log_OUTPUT_SOURCE source);
// Print a string to log channel, from provided source. Doesn't include the new line caracter.
SH_STATUS sh_log_llog(const char* str,sh_log_OUTPUT_SOURCE source);
// Print a string to warning channel, from provided source. Doesn't include the new line caracter.
SH_STATUS sh_log_lwarning(const char* str,sh_log_OUTPUT_SOURCE source);
// Print a string to error channel, from provided source. Doesn't include the new line caracter.
SH_STATUS sh_log_lerror(const char* str,sh_log_OUTPUT_SOURCE source);
// Print a string to critical channel, from provided source. Doesn't include the new line caracter.
SH_STATUS sh_log_lcritical(const char* str,sh_log_OUTPUT_SOURCE source);
// Print a string to fatal channel, from provided source. Doesn't include the new line caracter.
SH_STATUS sh_log_lfatal(const char* str,sh_log_OUTPUT_SOURCE source);
// The following functions format the output before logging it. The syntax is as follow:
// - %s : char*
// - %d : double
// - %x : sh_uint64 outputed in hexadecimal without trimming useless zeros
// - %c : char
// - %% : just insert a %
// The syntax for formating integers is as follow : %[1|2|4|8][u|s|U] :
// - the number indicate the size in bytes of the integer
// - the letter indicate the formatting mode : u for unsigned, s for signed, U for hexadecimal unsigned
// Somes examples for integers : %1s (8 bits signed integer), %4u (32 bits unsigned integers), %8U (64 bits hexadecimal unsigned)
// Print a string to test channel. Format it before hand
SH_STATUS sh_log_ftest(const char* format,...);
// Print a string to debug channel, from provided source. Format it before hand
SH_STATUS sh_log_fdebug(const sh_log_OUTPUT_SOURCE source,const char* format,...);
// Print a string to log channel, from provided source. Format it before hand
SH_STATUS sh_log_flog(const sh_log_OUTPUT_SOURCE source,const char* format,...);
// Print a string to warning channel, from provided source. Format it before hand
SH_STATUS sh_log_fwarning(const sh_log_OUTPUT_SOURCE source,const char* format,...);
// Print a string to error channel, from provided source. Format it before hand
SH_STATUS sh_log_ferror(const sh_log_OUTPUT_SOURCE source,const char* format,...);
// Print a string to critical channel, from provided source. Format it before hand
SH_STATUS sh_log_fcritical(const sh_log_OUTPUT_SOURCE source,const char* format,...);
// Print a string to fatal channel, from provided source. Format it before hand
SH_STATUS sh_log_ffatal(const sh_log_OUTPUT_SOURCE source,const char* format,...);
// Print every information about memory statictics. Require log level to be 1 or 0
SH_STATUS sh_log_mem_stats(sh_log_OUTPUT_SOURCE source);
#endif

View File

@@ -0,0 +1,7 @@
// SPDX-License-Identifier: MPL-2.0
// This file serve the purpose of including all types of tests
#include "kernel/tests/test_slabs.h"
#include "kernel/tests/test_radix.h"
#include "kernel/tests/test_pez.h"
#include "kernel/tests/test_malloc.h"
#include "kernel/tests/test_utils.h"

View File

@@ -0,0 +1,9 @@
// SPDX-License-Identifier: MPL-2.0
#ifndef SH_LIB_TEST_MALLOC_H
#define SH_LIB_TEST_MALLOC_H
#include "std/type.h"
#include "std/status.h"
#include "cpu/tsc.h"
// Test and benchmark malloc subsystem
SH_STATUS sh_test_malloc_benchmark();
#endif

View File

@@ -0,0 +1,11 @@
// SPDX-License-Identifier: MPL-2.0
#ifndef SH_LIB_TEST_PEZ_H
#define SH_LIB_TEST_PEZ_H
#include "std/type.h"
#include "std/status.h"
#include "memory/pez/pez.h"
#include "cpu/tsc.h"
#define SH_TEST_PEZ_TOTAL_TSC_TIME_COUNT 4000
// Test and benchmark pez subsystem
SH_STATUS sh_test_pez_benchmark_physical(sh_pez_PHYSICAL_PLANE *phys_plane);
#endif

View File

@@ -0,0 +1,14 @@
// SPDX-License-Identifier: MPL-2.0
#ifndef SH_LIB_TEST_RADIX_H
#define SH_LIB_TEST_RADIX_H
#include "std/type.h"
#include "std/status.h"
#include "memory/page.h"
#include "memory/slab.h"
#include "memory/pez/radix.h"
#include "cpu/tsc.h"
// Load the number of iterations for benchmakrs for radix test.
void sh_test_radix_load_iterations_count(sh_uint64 iterations_num);
// Test and benchmark radix trees subsystem
SH_STATUS sh_test_radix_benchmark(struct sh_slab_radix_node_SLAB_ALLOCATOR *alloc,sh_page_PAGE_TABLE_POOL *ptp);
#endif

View File

@@ -0,0 +1,19 @@
// SPDX-License-Identifier: MPL-2.0
#ifndef SH_LIB_TEST_SLABS_H
#define SH_LIB_TEST_SLABS_H
#include "std/type.h"
#include "std/status.h"
#include "memory/page.h"
#include "memory/slab.h"
#include "cpu/tsc.h"
// Load the number of iterations for benchmakrs for slabs test.
void sh_test_slabs_load_iterations_count(sh_uint64 iterations_num);
// Test and benchmark physical region objects slab allocator
SH_STATUS sh_test_slabs_benchmark_region_physical(sh_slab_reg_phys_SLAB_ALLOCATOR *alloc,sh_page_PAGE_TABLE_POOL *ptp);
// Test and benchmark virtual region objects slab allocator
SH_STATUS sh_test_slabs_benchmark_region_virtual(sh_slab_reg_virt_SLAB_ALLOCATOR *alloc,sh_page_PAGE_TABLE_POOL *ptp);
// Test and benchmark radix nodes objects slab allocator
SH_STATUS sh_test_slabs_benchmark_radix_node(struct sh_slab_radix_node_SLAB_ALLOCATOR *alloc,sh_page_PAGE_TABLE_POOL *ptp);
// Test and benchmark all slab allocators
SH_STATUS sh_test_slabs_benchmark(sh_slab_reg_phys_SLAB_ALLOCATOR *alloc_reg_phys,sh_slab_reg_virt_SLAB_ALLOCATOR *alloc_reg_virt,struct sh_slab_radix_node_SLAB_ALLOCATOR *alloc_radix_node,sh_page_PAGE_TABLE_POOL *ptp);
#endif

View File

@@ -0,0 +1,13 @@
// SPDX-License-Identifier: MPL-2.0
#ifndef SH_LIB_TEST_UTILS_H
#define SH_LIB_TEST_UTILS_H
#include "std/type.h"
#include "std/status.h"
#include "cpu/tsc.h"
// Compute and print time stats based on provided list of TSC values.
SH_STATUS sh_test_compute_print_stats(char* benchname,sh_tsc_TSC_VALUE *tsc_value_array,sh_uint64 array_size);
// Return pointer to TSC values buffer
sh_tsc_TSC_VALUE* sh_test_get_tsc_values_buffer_ptr();
// Load the number of iterations for benchmarks.
void sh_test_load_iterations_count(sh_uint64 iterations_num);
#endif