mirror of
https://github.com/subhobhai943/SUB-OS.git
synced 2026-10-25 16:52:29 +00:00
feat: Add SLAB allocator, Ramdisk, Kernel Namespaces, Event Tracing, NetFilter Firewall, 8-Bit Melodies, and Shell Scripting (sh)
This commit is contained in:
1 parent
9f9a19bab0
commit
2f1f785cee
17 files changed
+1021
-115
No files matched your search
+24
-11
@@ -7,6 +7,8 @@
|
||||
#include <kernel/timer.h>
|
||||
#include <kernel/workqueue.h>
|
||||
#include <kernel/module.h>
|
||||
#include <kernel/trace.h>
|
||||
#include <kernel/namespace.h>
|
||||
#include <arch/x86_64/gdt.h>
|
||||
#include <arch/x86_64/idt.h>
|
||||
#include <arch/x86_64/isr.h>
|
||||
@@ -16,6 +18,7 @@
|
||||
#include <arch/x86_64/paging.h>
|
||||
#include <mm/pmm.h>
|
||||
#include <mm/kmalloc.h>
|
||||
#include <mm/slab.h>
|
||||
#include <drivers/tty.h>
|
||||
#include <drivers/serial.h>
|
||||
#include <drivers/keyboard.h>
|
||||
@@ -28,9 +31,11 @@
|
||||
#include <drivers/rtc.h>
|
||||
#include <drivers/acpi.h>
|
||||
#include <drivers/usb.h>
|
||||
#include <drivers/ramdisk.h>
|
||||
#include <block/block.h>
|
||||
#include <ipc/ipc.h>
|
||||
#include <sound/sound.h>
|
||||
#include <sound/melody.h>
|
||||
#include <fs/vfs.h>
|
||||
#include <fs/fat32.h>
|
||||
#include <fs/ext2.h>
|
||||
@@ -41,6 +46,7 @@
|
||||
#include <net/tcp.h>
|
||||
#include <net/dhcp.h>
|
||||
#include <net/dns.h>
|
||||
#include <net/filter.h>
|
||||
#include <crypto/crypto.h>
|
||||
#include <certs/certs.h>
|
||||
#include <security/security.h>
|
||||
@@ -50,6 +56,7 @@
|
||||
#include <init/init.h>
|
||||
#include <init/version.h>
|
||||
#include <userland/lazybox.h>
|
||||
#include <userland/sh.h>
|
||||
#include <userland/shell.h>
|
||||
|
||||
void kernel_main(void* memory_map, uint64_t memory_map_count) {
|
||||
@@ -92,16 +99,18 @@ void kernel_main(void* memory_map, uint64_t memory_map_count) {
|
||||
acpi_init();
|
||||
printk(ANSI_BRIGHT_GREEN "OK\n" ANSI_RESET);
|
||||
|
||||
// 5. Memory Management
|
||||
printk(KERN_INFO "[6/18] Initializing Physical & Dynamic Heap Memory (PMM + Heap)... ");
|
||||
// 5. Memory Management: PMM + Dynamic Heap + SLAB Cache
|
||||
printk(KERN_INFO "[6/18] Initializing Physical PMM, Dynamic Heap & SLAB Cache... ");
|
||||
pmm_init(memory_map, memory_map_count);
|
||||
heap_init();
|
||||
slab_init();
|
||||
paging_init();
|
||||
printk(ANSI_BRIGHT_GREEN "OK\n" ANSI_RESET);
|
||||
|
||||
// 6. Block Storage & Hardware Busses
|
||||
printk(KERN_INFO "[7/18] Initializing Block Layer & Storage Controllers... ");
|
||||
// 6. Block Storage, Ramdisk & Hardware Busses
|
||||
printk(KERN_INFO "[7/18] Initializing Block Layer, Ramdisk & Storage Controllers... ");
|
||||
block_init();
|
||||
ramdisk_init();
|
||||
if (ata_init()) {
|
||||
printk(ANSI_BRIGHT_GREEN "ATA Primary Master Active\n" ANSI_RESET);
|
||||
} else {
|
||||
@@ -115,8 +124,9 @@ void kernel_main(void* memory_map, uint64_t memory_map_count) {
|
||||
usb_init();
|
||||
printk(ANSI_BRIGHT_GREEN "OK\n" ANSI_RESET);
|
||||
|
||||
// 7. Network Subsystem
|
||||
printk(KERN_INFO "[9/18] Initializing Network Protocol Stack (L2-L4)... ");
|
||||
// 7. Network Subsystem & Firewall
|
||||
printk(KERN_INFO "[9/18] Initializing Network Protocol Stack & NetFilter Firewall... ");
|
||||
filter_init();
|
||||
if (e1000_init()) {
|
||||
net_init();
|
||||
socket_subsystem_init();
|
||||
@@ -130,15 +140,17 @@ void kernel_main(void* memory_map, uint64_t memory_map_count) {
|
||||
}
|
||||
|
||||
// 8. Sound & Voice Synthesizer
|
||||
printk(KERN_INFO "[10/18] Initializing Sound Architecture & Formant TTS Synthesizer... ");
|
||||
printk(KERN_INFO "[10/18] Initializing Sound Architecture, Melody Player & Formant TTS... ");
|
||||
sound_init();
|
||||
melody_init();
|
||||
printk(ANSI_BRIGHT_GREEN "OK\n" ANSI_RESET);
|
||||
|
||||
// 9. Crypto, Certificates & LSM Security
|
||||
printk(KERN_INFO "[11/18] Initializing X.509 Keyring & Linux Security Module... ");
|
||||
// 9. Crypto, Certificates, LSM Security & Container Namespaces
|
||||
printk(KERN_INFO "[11/18] Initializing X.509 Keyring, LSM Security & Namespaces... ");
|
||||
prng_seed(0, 0);
|
||||
certs_init();
|
||||
security_init();
|
||||
namespace_init();
|
||||
printk(ANSI_BRIGHT_GREEN "OK\n" ANSI_RESET);
|
||||
|
||||
// 10. Inter-Process Communication
|
||||
@@ -160,12 +172,13 @@ void kernel_main(void* memory_map, uint64_t memory_map_count) {
|
||||
initramfs_init();
|
||||
printk(ANSI_BRIGHT_GREEN "OK\n" ANSI_RESET);
|
||||
|
||||
// 13. Kernel Core: Signals, Workqueues, Modules, Syscalls
|
||||
printk(KERN_INFO "[15/18] Initializing Signals, Workqueues, Syscalls & Module Loader... ");
|
||||
// 13. Kernel Core: Signals, Workqueues, Modules, Syscalls & Tracing
|
||||
printk(KERN_INFO "[15/18] Initializing Signals, Workqueues, Syscalls, Modules & Tracing... ");
|
||||
signal_init();
|
||||
workqueue_init();
|
||||
syscall_init();
|
||||
module_init_subsystem();
|
||||
trace_init();
|
||||
printk(ANSI_BRIGHT_GREEN "OK\n" ANSI_RESET);
|
||||
|
||||
// 14. Preemptive Multi-Tasking & Userland
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
#include <kernel/namespace.h>
|
||||
#include <lib/string.h>
|
||||
#include <kernel/printk.h>
|
||||
|
||||
static nsproxy_t ns_table[MAX_NAMESPACES];
|
||||
static uint32_t current_ns_id = 0;
|
||||
|
||||
void namespace_init(void) {
|
||||
memset(ns_table, 0, sizeof(ns_table));
|
||||
|
||||
// Root / Global Namespace (ID 0)
|
||||
ns_table[0].id = 0;
|
||||
ns_table[0].in_use = true;
|
||||
strcpy(ns_table[0].name, "root_ns");
|
||||
strcpy(ns_table[0].uts.hostname, "sub-os");
|
||||
strcpy(ns_table[0].uts.domainname, "localdomain");
|
||||
ns_table[0].pid_offset = 0;
|
||||
ns_table[0].isolated_mounts = false;
|
||||
|
||||
current_ns_id = 0;
|
||||
printk(KERN_INFO "NAMESPACE: Lightweight Container & Process Isolation layer active\n");
|
||||
}
|
||||
|
||||
nsproxy_t* namespace_create(const char* name, uint32_t flags) {
|
||||
for (uint32_t i = 1; i < MAX_NAMESPACES; i++) {
|
||||
if (!ns_table[i].in_use) {
|
||||
nsproxy_t* ns = &ns_table[i];
|
||||
ns->id = i;
|
||||
ns->in_use = true;
|
||||
strncpy(ns->name, name ? name : "container", sizeof(ns->name) - 1);
|
||||
ns->name[sizeof(ns->name) - 1] = '\0';
|
||||
|
||||
if (flags & CLONE_NEWUTS) {
|
||||
strncpy(ns->uts.hostname, ns->name, sizeof(ns->uts.hostname) - 1);
|
||||
} else {
|
||||
strcpy(ns->uts.hostname, ns_table[0].uts.hostname);
|
||||
}
|
||||
strcpy(ns->uts.domainname, "container.local");
|
||||
|
||||
ns->pid_offset = (flags & CLONE_NEWPID) ? (i * 1000) : 0;
|
||||
ns->isolated_mounts = (flags & CLONE_NEWNS) ? true : false;
|
||||
return ns;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
nsproxy_t* namespace_get_current(void) {
|
||||
return &ns_table[current_ns_id];
|
||||
}
|
||||
|
||||
int namespace_switch(uint32_t id) {
|
||||
if (id >= MAX_NAMESPACES || !ns_table[id].in_use) return -1;
|
||||
current_ns_id = id;
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t namespace_get_count(void) {
|
||||
size_t c = 0;
|
||||
for (size_t i = 0; i < MAX_NAMESPACES; i++) {
|
||||
if (ns_table[i].in_use) c++;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
const nsproxy_t* namespace_get(size_t index) {
|
||||
if (index >= MAX_NAMESPACES || !ns_table[index].in_use) return NULL;
|
||||
return &ns_table[index];
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
#include <kernel/trace.h>
|
||||
#include <kernel/task.h>
|
||||
#include <arch/x86_64/pit.h>
|
||||
#include <lib/string.h>
|
||||
#include <kernel/printk.h>
|
||||
|
||||
static trace_entry_t trace_buffer[TRACE_BUFFER_SIZE];
|
||||
static size_t trace_head = 0;
|
||||
static size_t trace_total = 0;
|
||||
static bool trace_enabled = true;
|
||||
|
||||
void trace_init(void) {
|
||||
memset(trace_buffer, 0, sizeof(trace_buffer));
|
||||
trace_head = 0;
|
||||
trace_total = 0;
|
||||
trace_enabled = true;
|
||||
|
||||
trace_record(TRACE_CAT_SYS, "Kernel Tracing Ringbuffer initialized");
|
||||
printk(KERN_INFO "TRACE: High-performance Kernel Event & Latency Tracer active\n");
|
||||
}
|
||||
|
||||
void trace_record(trace_category_t cat, const char* msg) {
|
||||
if (!trace_enabled || !msg) return;
|
||||
|
||||
trace_entry_t* entry = &trace_buffer[trace_head];
|
||||
entry->timestamp = pit_get_ticks();
|
||||
entry->cpu_id = 0;
|
||||
entry->pid = (uint32_t)task_get_pid();
|
||||
entry->category = cat;
|
||||
strncpy(entry->message, msg, TRACE_MSG_LEN - 1);
|
||||
entry->message[TRACE_MSG_LEN - 1] = '\0';
|
||||
|
||||
trace_head = (trace_head + 1) % TRACE_BUFFER_SIZE;
|
||||
if (trace_total < TRACE_BUFFER_SIZE) {
|
||||
trace_total++;
|
||||
}
|
||||
}
|
||||
|
||||
void trace_enable(bool enable) {
|
||||
trace_enabled = enable;
|
||||
}
|
||||
|
||||
bool trace_is_enabled(void) {
|
||||
return trace_enabled;
|
||||
}
|
||||
|
||||
void trace_clear(void) {
|
||||
memset(trace_buffer, 0, sizeof(trace_buffer));
|
||||
trace_head = 0;
|
||||
trace_total = 0;
|
||||
}
|
||||
|
||||
size_t trace_get_count(void) {
|
||||
return trace_total;
|
||||
}
|
||||
|
||||
const trace_entry_t* trace_get_entry(size_t index) {
|
||||
if (index >= trace_total) return NULL;
|
||||
size_t actual_idx = (trace_head - trace_total + index + TRACE_BUFFER_SIZE) % TRACE_BUFFER_SIZE;
|
||||
return &trace_buffer[actual_idx];
|
||||
}
|
||||
Reference in new issue
Block a user