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,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