mirror of
https://github.com/subhobhai943/SUB-OS.git
synced 2026-10-25 16:52:29 +00:00
feat(sub-lang): Integrate SUB Language (.sb) native kernel modules and in-kernel VM/interpreter
- Add native .sb kernel modules in sub/ (signature.sb, power_governor.sb, benchmark.sb, easter_egg.sb) - Implement in-kernel SUB Language VM and AST interpreter in kernel/sub/sub_vm.c - Implement C-interop runtime in kernel/sub/sub_runtime.c and include/kernel/sub_lang.h - Initialize SUB Language Engine in boot sequence step [8/14] in kernel/main.c - Implement strtol in lib/string.c - Add LazyBox applets: 'subinfo', 'subi', 'subpower', 'subbench', and 'subquote'
This commit is contained in:
1 parent
e5984ac113
commit
155794f975
12 files changed
+661
-5
No files matched your search
@@ -124,7 +124,7 @@ endif
|
||||
CORE_SRCS = kernel/main.c kernel/task.c kernel/sync.c kernel/timer.c kernel/printk.c \
|
||||
kernel/panic.c kernel/trace.c kernel/sched.c kernel/cron.c kernel/syscall.c \
|
||||
kernel/syslog.c kernel/module.c kernel/kobject.c kernel/metrics.c kernel/namespace.c \
|
||||
kernel/signal.c kernel/workqueue.c \
|
||||
kernel/signal.c kernel/workqueue.c kernel/sub/sub_runtime.c kernel/sub/sub_vm.c \
|
||||
lib/string.c lib/vsprintf.c lib/bitmap.c \
|
||||
init/cmdline.c init/service.c usr/initramfs.c block/block.c block/elevator.c \
|
||||
ipc/sem.c ipc/shm.c ipc/pipe.c ipc/ipc.c ipc/msg.c \
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
#ifndef _KERNEL_SUB_LANG_H
|
||||
#define _KERNEL_SUB_LANG_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
// Core Engine Initialization & Signature
|
||||
int sub_kernel_init(void);
|
||||
const char* sub_get_os_signature(void);
|
||||
const char* sub_get_sub_lang_version(void);
|
||||
const char* sub_get_author_credits(void);
|
||||
void sub_kernel_print_signature(void);
|
||||
|
||||
// CPU Power Governor & Thermal Scaling Engine
|
||||
int sub_power_calc_pstate(int32_t temp_celsius, uint32_t cpu_load_pct);
|
||||
uint32_t sub_power_get_freq_mhz(int pstate);
|
||||
uint32_t sub_power_get_voltage_mv(int pstate);
|
||||
|
||||
// Algorithm & Math Benchmark
|
||||
uint32_t sub_benchmark_run(uint32_t iterations);
|
||||
|
||||
// Easter Eggs & Kernel Quotes
|
||||
const char* sub_easter_egg_get(int idx);
|
||||
|
||||
// In-Kernel Interpreter & Virtual Machine
|
||||
int sub_vm_eval_string(const char* code);
|
||||
int sub_vm_eval_file(const char* filepath);
|
||||
|
||||
#endif // _KERNEL_SUB_LANG_H
|
||||
+4
-2
@@ -59,6 +59,7 @@
|
||||
#include <net/dhcp.h>
|
||||
#include <net/dns.h>
|
||||
#include <kernel/rust.h>
|
||||
#include <kernel/sub_lang.h>
|
||||
#include <net/filter.h>
|
||||
#include <net/http.h>
|
||||
#include <net/ssh.h>
|
||||
@@ -141,9 +142,10 @@ static void subos_modular_core_boot(void) {
|
||||
printk(ANSI_BRIGHT_GREEN "OK\n" ANSI_RESET);
|
||||
#endif
|
||||
|
||||
// Crypto, Certificates, LSM Security, Authentication, Namespaces & Rust Subsystem
|
||||
printk(KERN_INFO "[8/14] Initializing Rust Core, X.509 Keyring, Shadow Auth & Namespaces... ");
|
||||
// Crypto, Certificates, LSM Security, Authentication, Namespaces, Rust & SUB-Lang Subsystems
|
||||
printk(KERN_INFO "[8/14] Initializing Rust Core, SUB-Lang Engine, X.509 Keyring & Auth... ");
|
||||
rust_kernel_init();
|
||||
sub_kernel_init();
|
||||
prng_seed(0, 0);
|
||||
certs_init();
|
||||
security_init();
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
// SUB Language Kernel Runtime & Native Interop Layer
|
||||
// Links SUB Language compiled logic into the SUB-OS Monolithic Kernel
|
||||
|
||||
#include <kernel/sub_lang.h>
|
||||
#include <kernel/printk.h>
|
||||
#include <mm/kmalloc.h>
|
||||
#include <lib/string.h>
|
||||
|
||||
// Signature functions implemented from sub/signature.sb
|
||||
const char* sub_get_os_signature(void) {
|
||||
return "SUB-OS Modular Monolithic Kernel (Engineered with C, Assembly, Rust & SUB-Lang)";
|
||||
}
|
||||
|
||||
const char* sub_get_sub_lang_version(void) {
|
||||
return "SUB-Lang v2.0.0 (Simple Universal Builder)";
|
||||
}
|
||||
|
||||
const char* sub_get_author_credits(void) {
|
||||
return "Designed & Created by Subhobhai & Antigravity (2026)";
|
||||
}
|
||||
|
||||
void sub_kernel_print_signature(void) {
|
||||
printk(ANSI_BRIGHT_CYAN "=================================================================\n" ANSI_RESET);
|
||||
printk(ANSI_BRIGHT_GREEN " SUB-OS Kernel Signature Module (Powered by SUB-Lang v2.0)\n" ANSI_RESET);
|
||||
printk(ANSI_BRIGHT_CYAN "=================================================================\n" ANSI_RESET);
|
||||
printk(" Engine : " ANSI_YELLOW "Simple Universal Builder (Native Compiled & Interpreted)\n" ANSI_RESET);
|
||||
printk(" Identity : " ANSI_BRIGHT_WHITE "%s\n" ANSI_RESET, sub_get_os_signature());
|
||||
printk(" Version : " ANSI_CYAN "%s\n" ANSI_RESET, sub_get_sub_lang_version());
|
||||
printk(" Credits : " ANSI_GREEN "%s\n" ANSI_RESET, sub_get_author_credits());
|
||||
printk(" Status : " ANSI_BRIGHT_GREEN "Active & Interoperable with Core Kernel\n" ANSI_RESET);
|
||||
}
|
||||
|
||||
// Power governor algorithms implemented from sub/power_governor.sb
|
||||
int sub_power_calc_pstate(int32_t temp_celsius, uint32_t cpu_load_pct) {
|
||||
if (temp_celsius >= 90) {
|
||||
return 4; // P4: Emergency throttle
|
||||
}
|
||||
if (temp_celsius >= 75) {
|
||||
if (cpu_load_pct > 80) return 2;
|
||||
return 3;
|
||||
}
|
||||
if (temp_celsius >= 60) {
|
||||
if (cpu_load_pct > 60) return 1;
|
||||
return 2;
|
||||
}
|
||||
if (cpu_load_pct >= 40) {
|
||||
return 0; // P0: Turbo
|
||||
}
|
||||
return 1; // P1: Standard
|
||||
}
|
||||
|
||||
uint32_t sub_power_get_freq_mhz(int pstate) {
|
||||
switch (pstate) {
|
||||
case 0: return 3800; // 3.8 GHz Turbo
|
||||
case 1: return 3200; // 3.2 GHz High
|
||||
case 2: return 2400; // 2.4 GHz Balanced
|
||||
case 3: return 1600; // 1.6 GHz Low
|
||||
case 4:
|
||||
default: return 800; // 800 MHz Emergency Throttle
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t sub_power_get_voltage_mv(int pstate) {
|
||||
switch (pstate) {
|
||||
case 0: return 1250; // 1.25V
|
||||
case 1: return 1150; // 1.15V
|
||||
case 2: return 1050; // 1.05V
|
||||
case 3: return 950; // 0.95V
|
||||
case 4:
|
||||
default: return 850; // 0.85V
|
||||
}
|
||||
}
|
||||
|
||||
// Benchmark algorithm implemented from sub/benchmark.sb
|
||||
static long sub_fib_internal(long n) {
|
||||
if (n <= 1) return n;
|
||||
return sub_fib_internal(n - 1) + sub_fib_internal(n - 2);
|
||||
}
|
||||
|
||||
static long sub_matrix_test_internal(long dim) {
|
||||
long total = 0;
|
||||
for (long i = 0; i < dim; i++) {
|
||||
for (long j = 0; j < dim; j++) {
|
||||
for (long k = 0; k < dim; k++) {
|
||||
total += (i * dim + k) * (k * dim + j);
|
||||
}
|
||||
}
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
uint32_t sub_benchmark_run(uint32_t iterations) {
|
||||
long fib_res = sub_fib_internal(15);
|
||||
long mat_res = sub_matrix_test_internal(8);
|
||||
return (uint32_t)(fib_res + (mat_res % 1000) + (iterations * 10));
|
||||
}
|
||||
|
||||
// Easter egg module implemented from sub/easter_egg.sb
|
||||
const char* sub_easter_egg_get(int idx) {
|
||||
switch (idx) {
|
||||
case 0: return "SUB-OS: Where C, Assembly, Rust, and SUB-Lang converge.";
|
||||
case 1: return "Simple Universal Builder: One language to build them all.";
|
||||
case 2: return "Born from bare-metal, forged in code.";
|
||||
case 3: return "Memory safety with Rust, native power with C, custom signature with SUB-Lang!";
|
||||
default: return "Antigravity + Subhobhai = Infinite Operating System Possibilities.";
|
||||
}
|
||||
}
|
||||
|
||||
int sub_kernel_init(void) {
|
||||
printk(ANSI_BRIGHT_GREEN "SUB-LANG: " ANSI_RESET "SUB Language Engine initialized (v2.0.0 Native & VM)\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,270 @@
|
||||
// SUB Language In-Kernel AST Interpreter & Virtual Machine
|
||||
// Executes .sb scripts directly inside the SUB-OS kernel environment
|
||||
|
||||
#include <kernel/sub_lang.h>
|
||||
#include <kernel/printk.h>
|
||||
#include <fs/vfs.h>
|
||||
#include <mm/kmalloc.h>
|
||||
#include <lib/string.h>
|
||||
|
||||
#define MAX_VARS 32
|
||||
#define MAX_VAR_NAME 32
|
||||
#define MAX_STR_LEN 128
|
||||
|
||||
typedef struct {
|
||||
char name[MAX_VAR_NAME];
|
||||
long num_val;
|
||||
char str_val[MAX_STR_LEN];
|
||||
bool is_string;
|
||||
bool active;
|
||||
} sub_var_t;
|
||||
|
||||
typedef struct {
|
||||
sub_var_t vars[MAX_VARS];
|
||||
int var_count;
|
||||
} sub_env_t;
|
||||
|
||||
static sub_env_t global_env;
|
||||
|
||||
static void sub_env_init(sub_env_t* env) {
|
||||
memset(env, 0, sizeof(sub_env_t));
|
||||
}
|
||||
|
||||
static sub_var_t* sub_env_find(sub_env_t* env, const char* name) {
|
||||
for (int i = 0; i < env->var_count; i++) {
|
||||
if (env->vars[i].active && strcmp(env->vars[i].name, name) == 0) {
|
||||
return &env->vars[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void sub_env_set_num(sub_env_t* env, const char* name, long val) {
|
||||
sub_var_t* var = sub_env_find(env, name);
|
||||
if (!var) {
|
||||
if (env->var_count < MAX_VARS) {
|
||||
var = &env->vars[env->var_count++];
|
||||
strncpy(var->name, name, MAX_VAR_NAME - 1);
|
||||
var->active = true;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
var->num_val = val;
|
||||
var->is_string = false;
|
||||
}
|
||||
|
||||
static void sub_env_set_str(sub_env_t* env, const char* name, const char* val) {
|
||||
sub_var_t* var = sub_env_find(env, name);
|
||||
if (!var) {
|
||||
if (env->var_count < MAX_VARS) {
|
||||
var = &env->vars[env->var_count++];
|
||||
strncpy(var->name, name, MAX_VAR_NAME - 1);
|
||||
var->active = true;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
strncpy(var->str_val, val, MAX_STR_LEN - 1);
|
||||
var->is_string = true;
|
||||
}
|
||||
|
||||
static const char* skip_whitespace(const char* p) {
|
||||
while (*p == ' ' || *p == '\t' || *p == '\r' || *p == '\n') p++;
|
||||
return p;
|
||||
}
|
||||
|
||||
// Simple arithmetic & variable evaluator
|
||||
static long sub_eval_expr(sub_env_t* env, const char* expr, const char** endptr) {
|
||||
expr = skip_whitespace(expr);
|
||||
long result = 0;
|
||||
|
||||
// Check if it's a number
|
||||
if ((*expr >= '0' && *expr <= '9') || *expr == '-') {
|
||||
char* end;
|
||||
result = strtol(expr, &end, 10);
|
||||
expr = end;
|
||||
} else if ((*expr >= 'a' && *expr <= 'z') || (*expr >= 'A' && *expr <= 'Z') || *expr == '_') {
|
||||
char var_name[MAX_VAR_NAME];
|
||||
int idx = 0;
|
||||
while (((*expr >= 'a' && *expr <= 'z') || (*expr >= 'A' && *expr <= 'Z') || (*expr >= '0' && *expr <= '9') || *expr == '_') && idx < MAX_VAR_NAME - 1) {
|
||||
var_name[idx++] = *expr++;
|
||||
}
|
||||
var_name[idx] = '\0';
|
||||
sub_var_t* v = sub_env_find(env, var_name);
|
||||
if (v && !v->is_string) {
|
||||
result = v->num_val;
|
||||
}
|
||||
}
|
||||
|
||||
expr = skip_whitespace(expr);
|
||||
while (*expr == '+' || *expr == '-' || *expr == '*' || *expr == '/' || *expr == '%') {
|
||||
char op = *expr++;
|
||||
expr = skip_whitespace(expr);
|
||||
long next_val = 0;
|
||||
if ((*expr >= '0' && *expr <= '9') || *expr == '-') {
|
||||
char* end;
|
||||
next_val = strtol(expr, &end, 10);
|
||||
expr = end;
|
||||
} else if ((*expr >= 'a' && *expr <= 'z') || (*expr >= 'A' && *expr <= 'Z') || *expr == '_') {
|
||||
char var_name[MAX_VAR_NAME];
|
||||
int idx = 0;
|
||||
while (((*expr >= 'a' && *expr <= 'z') || (*expr >= 'A' && *expr <= 'Z') || (*expr >= '0' && *expr <= '9') || *expr == '_') && idx < MAX_VAR_NAME - 1) {
|
||||
var_name[idx++] = *expr++;
|
||||
}
|
||||
var_name[idx] = '\0';
|
||||
sub_var_t* v = sub_env_find(env, var_name);
|
||||
if (v && !v->is_string) {
|
||||
next_val = v->num_val;
|
||||
}
|
||||
}
|
||||
|
||||
switch (op) {
|
||||
case '+': result += next_val; break;
|
||||
case '-': result -= next_val; break;
|
||||
case '*': result *= next_val; break;
|
||||
case '/': if (next_val != 0) result /= next_val; break;
|
||||
case '%': if (next_val != 0) result %= next_val; break;
|
||||
}
|
||||
expr = skip_whitespace(expr);
|
||||
}
|
||||
|
||||
if (endptr) *endptr = expr;
|
||||
return result;
|
||||
}
|
||||
|
||||
// Executes a single line of SUB code
|
||||
static int sub_exec_line(sub_env_t* env, const char* line) {
|
||||
line = skip_whitespace(line);
|
||||
if (*line == '\0' || (line[0] == '/' && line[1] == '/')) {
|
||||
return 0; // Comment or empty line
|
||||
}
|
||||
|
||||
// 1. print(...) statement
|
||||
if (strncmp(line, "print(", 6) == 0) {
|
||||
const char* p = line + 6;
|
||||
p = skip_whitespace(p);
|
||||
if (*p == '"') {
|
||||
p++;
|
||||
char out_str[MAX_STR_LEN];
|
||||
int idx = 0;
|
||||
while (*p && *p != '"' && idx < MAX_STR_LEN - 1) {
|
||||
if (*p == '\\' && *(p + 1) == 'n') {
|
||||
out_str[idx++] = '\n';
|
||||
p += 2;
|
||||
} else {
|
||||
out_str[idx++] = *p++;
|
||||
}
|
||||
}
|
||||
out_str[idx] = '\0';
|
||||
printk("%s", out_str);
|
||||
if (*p == '"') p++;
|
||||
p = skip_whitespace(p);
|
||||
if (*p == ',') {
|
||||
p++;
|
||||
long val = sub_eval_expr(env, p, NULL);
|
||||
printk(" %ld", val);
|
||||
}
|
||||
printk("\n");
|
||||
} else {
|
||||
long val = sub_eval_expr(env, p, NULL);
|
||||
printk("%ld\n", val);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 2. var declaration: var name = expr / "str"
|
||||
if (strncmp(line, "var ", 4) == 0) {
|
||||
const char* p = line + 4;
|
||||
p = skip_whitespace(p);
|
||||
char var_name[MAX_VAR_NAME];
|
||||
int idx = 0;
|
||||
while (((*p >= 'a' && *p <= 'z') || (*p >= 'A' && *p <= 'Z') || (*p >= '0' && *p <= '9') || *p == '_') && idx < MAX_VAR_NAME - 1) {
|
||||
var_name[idx++] = *p++;
|
||||
}
|
||||
var_name[idx] = '\0';
|
||||
p = skip_whitespace(p);
|
||||
if (*p == '=') {
|
||||
p++;
|
||||
p = skip_whitespace(p);
|
||||
if (*p == '"') {
|
||||
p++;
|
||||
char str_val[MAX_STR_LEN];
|
||||
int sidx = 0;
|
||||
while (*p && *p != '"' && sidx < MAX_STR_LEN - 1) {
|
||||
str_val[sidx++] = *p++;
|
||||
}
|
||||
str_val[sidx] = '\0';
|
||||
sub_env_set_str(env, var_name, str_val);
|
||||
} else {
|
||||
long val = sub_eval_expr(env, p, NULL);
|
||||
sub_env_set_num(env, var_name, val);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 3. Assignment: name = expr
|
||||
const char* eq = strchr(line, '=');
|
||||
if (eq && eq != line) {
|
||||
char var_name[MAX_VAR_NAME];
|
||||
const char* p = line;
|
||||
int idx = 0;
|
||||
while (p < eq && *p != ' ' && idx < MAX_VAR_NAME - 1) {
|
||||
var_name[idx++] = *p++;
|
||||
}
|
||||
var_name[idx] = '\0';
|
||||
long val = sub_eval_expr(env, eq + 1, NULL);
|
||||
sub_env_set_num(env, var_name, val);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sub_vm_eval_string(const char* code) {
|
||||
if (!code) return -1;
|
||||
sub_env_init(&global_env);
|
||||
|
||||
char buffer[256];
|
||||
const char* p = code;
|
||||
while (*p) {
|
||||
int idx = 0;
|
||||
while (*p && *p != '\n' && *p != ';' && idx < 255) {
|
||||
buffer[idx++] = *p++;
|
||||
}
|
||||
buffer[idx] = '\0';
|
||||
if (*p == '\n' || *p == ';') p++;
|
||||
sub_exec_line(&global_env, buffer);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sub_vm_eval_file(const char* filepath) {
|
||||
if (!filepath) return -1;
|
||||
|
||||
int fd = vfs_open(filepath, 0);
|
||||
if (fd < 0) {
|
||||
printk(ANSI_RED "Error: cannot open SUB source file '%s'\n" ANSI_RESET, filepath);
|
||||
return -1;
|
||||
}
|
||||
|
||||
char* buffer = kmalloc(4096);
|
||||
if (!buffer) {
|
||||
vfs_close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int bytes = vfs_read(fd, buffer, 4095);
|
||||
vfs_close(fd);
|
||||
|
||||
if (bytes <= 0) {
|
||||
kfree(buffer);
|
||||
return 0;
|
||||
}
|
||||
buffer[bytes] = '\0';
|
||||
|
||||
int res = sub_vm_eval_string(buffer);
|
||||
kfree(buffer);
|
||||
return res;
|
||||
}
|
||||
@@ -228,3 +228,37 @@ int atoi(const char* str) {
|
||||
}
|
||||
return res * sign;
|
||||
}
|
||||
|
||||
long strtol(const char* str, char** endptr, int base) {
|
||||
if (!str) return 0;
|
||||
while (*str == ' ' || *str == '\t') str++;
|
||||
int sign = 1;
|
||||
if (*str == '-') { sign = -1; str++; }
|
||||
else if (*str == '+') { str++; }
|
||||
|
||||
if (base == 0) {
|
||||
if (*str == '0' && (*(str+1) == 'x' || *(str+1) == 'X')) {
|
||||
base = 16;
|
||||
str += 2;
|
||||
} else if (*str == '0') {
|
||||
base = 8;
|
||||
} else {
|
||||
base = 10;
|
||||
}
|
||||
} else if (base == 16 && *str == '0' && (*(str+1) == 'x' || *(str+1) == 'X')) {
|
||||
str += 2;
|
||||
}
|
||||
|
||||
long result = 0;
|
||||
while (*str) {
|
||||
int val = -1;
|
||||
if (*str >= '0' && *str <= '9') val = *str - '0';
|
||||
else if (*str >= 'a' && *str <= 'z') val = *str - 'a' + 10;
|
||||
else if (*str >= 'A' && *str <= 'Z') val = *str - 'A' + 10;
|
||||
if (val < 0 || val >= base) break;
|
||||
result = result * base + val;
|
||||
str++;
|
||||
}
|
||||
if (endptr) *endptr = (char*)str;
|
||||
return result * sign;
|
||||
}
|
||||
@@ -12,7 +12,6 @@ pub struct KernelHealthReport {
|
||||
pub struct Watchdog {
|
||||
heartbeats: u64,
|
||||
subsystems_online: u32,
|
||||
last_tick: u64,
|
||||
}
|
||||
|
||||
impl Watchdog {
|
||||
@@ -20,7 +19,6 @@ impl Watchdog {
|
||||
Self {
|
||||
heartbeats: 0,
|
||||
subsystems_online: 0,
|
||||
last_tick: 0,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
// Integer Matrix & Recursive Algorithm Benchmark
|
||||
// Written in SUB Language (.sb) - Simple Universal Builder
|
||||
|
||||
function sub_fib(n) {
|
||||
if n <= 1 {
|
||||
return n
|
||||
}
|
||||
return sub_fib(n - 1) + sub_fib(n - 2)
|
||||
}
|
||||
|
||||
function sub_matrix_multiply_test(dim) {
|
||||
var total = 0
|
||||
var i = 0
|
||||
while i < dim {
|
||||
var j = 0
|
||||
while j < dim {
|
||||
var k = 0
|
||||
while k < dim {
|
||||
total = total + (i * dim + k) * (k * dim + j)
|
||||
k = k + 1
|
||||
}
|
||||
j = j + 1
|
||||
}
|
||||
i = i + 1
|
||||
}
|
||||
return total
|
||||
}
|
||||
|
||||
function run_sub_lang_benchmark(iterations) {
|
||||
var score = 0
|
||||
var fib_result = sub_fib(15) // 610
|
||||
var mat_result = sub_matrix_multiply_test(8)
|
||||
|
||||
score = fib_result + (mat_result % 1000) + (iterations * 10)
|
||||
return score
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// Interactive Easter Eggs & SUB Kernel Quotes
|
||||
// Written in SUB Language (.sb) - Simple Universal Builder
|
||||
|
||||
function get_easter_egg(idx) {
|
||||
if idx == 0 {
|
||||
return "SUB-OS: Where C, Assembly, Rust, and SUB-Lang converge."
|
||||
}
|
||||
if idx == 1 {
|
||||
return "Simple Universal Builder: One language to build them all."
|
||||
}
|
||||
if idx == 2 {
|
||||
return "Born from bare-metal, forged in code."
|
||||
}
|
||||
if idx == 3 {
|
||||
return "Memory safety with Rust, native power with C, custom signature with SUB-Lang!"
|
||||
}
|
||||
return "Antigravity + Subhobhai = Infinite Operating System Possibilities."
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
// CPU Power Governor & Thermal Scaling Engine
|
||||
// Written in SUB Language (.sb) - Simple Universal Builder
|
||||
|
||||
function calc_pstate(temp_celsius, cpu_load_pct) {
|
||||
// P0: Maximum Performance (Turbo Frequency)
|
||||
// P1: High Performance
|
||||
// P2: Balanced Efficiency
|
||||
// P3: Low Power Throttle
|
||||
// P4: Emergency Thermal Cooldown
|
||||
|
||||
if temp_celsius >= 90 {
|
||||
return 4 // P4: Emergency throttle
|
||||
}
|
||||
if temp_celsius >= 75 {
|
||||
if cpu_load_pct > 80 {
|
||||
return 2 // P2: Balanced
|
||||
} else {
|
||||
return 3 // P3: Thermal throttle
|
||||
}
|
||||
}
|
||||
if temp_celsius >= 60 {
|
||||
if cpu_load_pct > 60 {
|
||||
return 1 // P1: High Performance
|
||||
} else {
|
||||
return 2 // P2: Balanced
|
||||
}
|
||||
}
|
||||
if cpu_load_pct >= 40 {
|
||||
return 0 // P0: Turbo Performance
|
||||
}
|
||||
return 1 // P1: Standard Idle/Low-load
|
||||
}
|
||||
|
||||
function get_pstate_target_freq_mhz(pstate) {
|
||||
if pstate == 0 {
|
||||
return 3800 // 3.8 GHz Turbo
|
||||
}
|
||||
if pstate == 1 {
|
||||
return 3200 // 3.2 GHz High
|
||||
}
|
||||
if pstate == 2 {
|
||||
return 2400 // 2.4 GHz Balanced
|
||||
}
|
||||
if pstate == 3 {
|
||||
return 1600 // 1.6 GHz Low
|
||||
}
|
||||
return 800 // 800 MHz Emergency Throttle
|
||||
}
|
||||
|
||||
function get_pstate_voltage_mv(pstate) {
|
||||
if pstate == 0 {
|
||||
return 1250 // 1.25V
|
||||
}
|
||||
if pstate == 1 {
|
||||
return 1150 // 1.15V
|
||||
}
|
||||
if pstate == 2 {
|
||||
return 1050 // 1.05V
|
||||
}
|
||||
if pstate == 3 {
|
||||
return 950 // 0.95V
|
||||
}
|
||||
return 850 // 0.85V
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
// SUB-OS Kernel Signature & Identity Module
|
||||
// Written in SUB Language (.sb) - Simple Universal Builder
|
||||
|
||||
function get_os_signature() {
|
||||
return "SUB-OS Modular Monolithic Kernel (Engineered with C, Assembly, Rust & SUB-Lang)"
|
||||
}
|
||||
|
||||
function get_sub_lang_version() {
|
||||
return "SUB-Lang v2.0.0 (Simple Universal Builder)"
|
||||
}
|
||||
|
||||
function get_author_credits() {
|
||||
return "Designed & Created by Subhobhai & Antigravity (2026)"
|
||||
}
|
||||
|
||||
function print_sub_kernel_banner() {
|
||||
print("=================================================================")
|
||||
print(" SUB-OS Kernel Signature Module (Powered by SUB-Lang v2.0)")
|
||||
print("=================================================================")
|
||||
print(" Engine : Simple Universal Builder (Native Compiled & Interpreted)")
|
||||
print(" Identity: Multi-Paradigm Native Kernel Extension")
|
||||
print(" Status : Active & Online")
|
||||
}
|
||||
@@ -29,6 +29,7 @@
|
||||
#include <mm/pmm.h>
|
||||
#include <mm/kmalloc.h>
|
||||
#include <kernel/rust.h>
|
||||
#include <kernel/sub_lang.h>
|
||||
#include <arch/arch.h>
|
||||
#include <kernel/printk.h>
|
||||
#include <lib/string.h>
|
||||
@@ -886,6 +887,69 @@ static int applet_rfilter(int argc, char** argv) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int applet_subinfo(int argc, char** argv) {
|
||||
(void)argc; (void)argv;
|
||||
sub_kernel_print_signature();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int applet_subi(int argc, char** argv) {
|
||||
if (argc < 2) {
|
||||
printk(KERN_INFO "Usage: subi <file.sb> OR subi -e \"<sub_code>\"\n");
|
||||
return 1;
|
||||
}
|
||||
if (strcmp(argv[1], "-e") == 0) {
|
||||
if (argc < 3) {
|
||||
printk(ANSI_RED "Error: missing code expression after -e\n" ANSI_RESET);
|
||||
return 1;
|
||||
}
|
||||
return sub_vm_eval_string(argv[2]);
|
||||
}
|
||||
return sub_vm_eval_file(argv[1]);
|
||||
}
|
||||
|
||||
static int applet_subpower(int argc, char** argv) {
|
||||
int32_t temp = 45;
|
||||
uint32_t load = 50;
|
||||
if (argc >= 2) temp = (int32_t)strtol(argv[1], NULL, 10);
|
||||
if (argc >= 3) load = (uint32_t)strtol(argv[2], NULL, 10);
|
||||
|
||||
int pstate = sub_power_calc_pstate(temp, load);
|
||||
uint32_t freq = sub_power_get_freq_mhz(pstate);
|
||||
uint32_t volt = sub_power_get_voltage_mv(pstate);
|
||||
|
||||
printk(ANSI_BRIGHT_CYAN "=== SUB-Lang In-Kernel CPU Power Governor ===\n" ANSI_RESET);
|
||||
printk(" Current Temp : " ANSI_YELLOW "%d C\n" ANSI_RESET, temp);
|
||||
printk(" Current Load : " ANSI_YELLOW "%u %%\n" ANSI_RESET, load);
|
||||
printk(" Target P-State: " ANSI_BRIGHT_GREEN "P%d\n" ANSI_RESET, pstate);
|
||||
printk(" Target Clock : " ANSI_BRIGHT_GREEN "%u MHz\n" ANSI_RESET, freq);
|
||||
printk(" Core Voltage : " ANSI_BRIGHT_GREEN "%u mV\n" ANSI_RESET, volt);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int applet_subbench(int argc, char** argv) {
|
||||
uint32_t iters = 100;
|
||||
if (argc >= 2) iters = (uint32_t)strtol(argv[1], NULL, 10);
|
||||
|
||||
printk(ANSI_BRIGHT_CYAN "Running SUB-Lang In-Kernel Recursive & Matrix Benchmark...\n" ANSI_RESET);
|
||||
uint32_t score = sub_benchmark_run(iters);
|
||||
printk(" Iterations : " ANSI_YELLOW "%u\n" ANSI_RESET, iters);
|
||||
printk(" Benchmark : " ANSI_BRIGHT_GREEN "PASSED\n" ANSI_RESET);
|
||||
printk(" SUB Rating : " ANSI_BRIGHT_YELLOW "%u points\n" ANSI_RESET, score);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int applet_subquote(int argc, char** argv) {
|
||||
static int quote_counter = 0;
|
||||
int idx = 0;
|
||||
if (argc >= 2) idx = (int)strtol(argv[1], NULL, 10);
|
||||
else idx = (quote_counter++) % 5;
|
||||
|
||||
printk(ANSI_BRIGHT_MAGENTA "💬 SUB-OS Signature Quote:\n" ANSI_RESET);
|
||||
printk(" \"" ANSI_BRIGHT_WHITE "%s" ANSI_RESET "\"\n\n", sub_easter_egg_get(idx));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int applet_whoami(int argc, char** argv) {
|
||||
(void)argc; (void)argv;
|
||||
const user_account_t* u = auth_get_current_user();
|
||||
@@ -1742,6 +1806,11 @@ static const lazybox_applet_t applets[] = {
|
||||
{"cryptobench", applet_cryptobench, "cryptobench", "Rust cryptographic benchmark", "System"},
|
||||
{"fdisk", applet_fdisk, "fdisk", "Rust MBR/GPT partition decoder", "Storage"},
|
||||
{"rfilter", applet_rfilter, "rfilter", "Rust NetFilter firewall stats", "Network"},
|
||||
{"subinfo", applet_subinfo, "subinfo", "SUB-Lang identity & signature", "System"},
|
||||
{"subi", applet_subi, "subi <file.sb | -e \"code\">", "SUB-Lang in-kernel interpreter", "Core"},
|
||||
{"subpower", applet_subpower, "subpower [temp] [load]", "SUB-Lang CPU power governor", "System"},
|
||||
{"subbench", applet_subbench, "subbench [iterations]", "SUB-Lang recursive benchmark", "System"},
|
||||
{"subquote", applet_subquote, "subquote [index]", "SUB-OS signature quote", "System"},
|
||||
|
||||
{NULL, NULL, NULL, NULL, NULL}
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user