feat(core): implement Linux-grade architecture (printk with loglevels, list.h, errno.h, procfs, devfs, slab cache, CMOS RTC & 16550A UART serial)

This commit is contained in:
Adam Eehan committed 2026-10-23 18:40:54 +05:30
1 parent 2bbeb3f345
commit 1832e7ecff
19 files changed
+805 -6

No files matched your search

+23 -5
View File
@@ -12,6 +12,13 @@
#include <airlys/vfs.h>
#include <airlys/ramfs.h>
#include <airlys/shell.h>
#include <airlys/printk.h>
#include <airlys/rtc.h>
#include <airlys/serial.h>
#include <airlys/procfs.h>
#include <airlys/devfs.h>
#include <airlys/slab.h>
#include <airlys/security.h>
static void aira_sentinel_task(void) {
/* Background Sovereign Sentinel Health Daemon */
@@ -109,17 +116,28 @@ void kernel_main(uint64_t magic, uint64_t addr) {
vga_puts("] running\n");
}
/* Step 11: Phase 5 - Virtual File System (VFS) & In-Memory RamFS */
/* Step 11: Linux Core Subsystems - Slab Cache & Security Sentinel */
slab_init();
security_init();
rtc_init();
serial_init();
vga_set_color(VGA_COLOR_LIGHT_CYAN, VGA_COLOR_BLACK);
vga_puts(" [OK] Linux Slab Cache Allocator : kmem_cache subsystem online\n");
vga_puts(" [OK] 16550A UART Serial Driver : COM1 (0x3F8) 115200 baud active\n");
vga_puts(" [OK] CMOS Real Time Clock (RTC) : Synchronized with hardware clock\n");
/* Step 12: Phase 5 - Virtual File System (VFS), In-Memory RamFS, /proc & /dev */
vfs_init();
ramfs_init();
vga_set_color(VGA_COLOR_LIGHT_CYAN, VGA_COLOR_BLACK);
vga_puts(" [OK] Virtual File System (VFS) : In-Memory RamFS mounted on '/'\n");
devfs_init();
procfs_init();
vga_puts(" [OK] Virtual File System (VFS) : In-Memory RamFS, /proc & /dev mounted\n");
/* Step 12: Phase 5 - Interactive Userland Shell (airlys-sh) */
/* Step 13: Phase 5 - Interactive Userland Shell (airlys-sh) */
shell_init();
vga_puts(" [OK] Sovereign Userland Shell : airlys-sh active & command dispatcher ready\n");
/* Step 13: Enable CPU Hardware Interrupts */
/* Step 14: Enable CPU Hardware Interrupts */
__asm__ volatile ("sti");
vga_set_color(VGA_COLOR_GREEN, VGA_COLOR_BLACK);
vga_puts(" [OK] Hardware Interrupts Active : STI executed (IF=1)\n");
+153
View File
@@ -0,0 +1,153 @@
#include <airlys/printk.h>
#include <airlys/vga.h>
#include <airlys/string.h>
static char printk_ringbuf[PRINTK_BUF_SIZE];
static size_t ringbuf_pos = 0;
static void ringbuf_putc(char c) {
printk_ringbuf[ringbuf_pos] = c;
ringbuf_pos = (ringbuf_pos + 1) % PRINTK_BUF_SIZE;
}
static void print_num(uint64_t val, int base, bool is_signed) {
if (is_signed && (int64_t)val < 0) {
vga_putchar('-');
ringbuf_putc('-');
val = (uint64_t)(-(int64_t)val);
}
char buf[32];
int i = 0;
const char digits[] = "0123456789abcdef";
if (val == 0) {
buf[i++] = '0';
} else {
while (val > 0) {
buf[i++] = digits[val % base];
val /= base;
}
}
while (--i >= 0) {
vga_putchar(buf[i]);
ringbuf_putc(buf[i]);
}
}
int printk(const char* fmt, ...) {
if (!fmt) return 0;
__builtin_va_list args;
__builtin_va_start(args, fmt);
/* Check for Linux log level prefix "\001[0-7]" */
if (fmt[0] == '\001' && fmt[1] >= '0' && fmt[1] <= '7') {
char level = fmt[1];
fmt += 2;
switch (level) {
case '0': /* EMERG */
case '1': /* ALERT */
case '2': /* CRIT */
case '3': /* ERR */
vga_set_color(VGA_COLOR_LIGHT_RED, VGA_COLOR_BLACK);
break;
case '4': /* WARNING */
vga_set_color(VGA_COLOR_LIGHT_BROWN, VGA_COLOR_BLACK);
break;
case '5': /* NOTICE */
case '6': /* INFO */
vga_set_color(VGA_COLOR_LIGHT_CYAN, VGA_COLOR_BLACK);
break;
case '7': /* DEBUG */
default:
vga_set_color(VGA_COLOR_LIGHT_GREY, VGA_COLOR_BLACK);
break;
}
}
int chars_written = 0;
while (*fmt) {
if (*fmt == '%') {
fmt++;
switch (*fmt) {
case 's': {
const char* s = __builtin_va_arg(args, const char*);
if (!s) s = "(null)";
while (*s) {
vga_putchar(*s);
ringbuf_putc(*s);
s++;
chars_written++;
}
break;
}
case 'd':
case 'i': {
int val = __builtin_va_arg(args, int);
print_num((uint64_t)val, 10, true);
break;
}
case 'u': {
unsigned int val = __builtin_va_arg(args, unsigned int);
print_num((uint64_t)val, 10, false);
break;
}
case 'x': {
unsigned int val = __builtin_va_arg(args, unsigned int);
print_num((uint64_t)val, 16, false);
break;
}
case 'p': {
uintptr_t val = __builtin_va_arg(args, uintptr_t);
vga_puts("0x");
ringbuf_putc('0');
ringbuf_putc('x');
print_num((uint64_t)val, 16, false);
break;
}
case 'c': {
char c = (char)__builtin_va_arg(args, int);
vga_putchar(c);
ringbuf_putc(c);
chars_written++;
break;
}
case '%': {
vga_putchar('%');
ringbuf_putc('%');
chars_written++;
break;
}
default:
vga_putchar('%');
vga_putchar(*fmt);
ringbuf_putc('%');
ringbuf_putc(*fmt);
break;
}
} else {
vga_putchar(*fmt);
ringbuf_putc(*fmt);
chars_written++;
}
fmt++;
}
__builtin_va_end(args);
return chars_written;
}
void printk_dump_dmesg(void) {
vga_set_color(VGA_COLOR_LIGHT_GREY, VGA_COLOR_BLACK);
for (size_t i = 0; i < PRINTK_BUF_SIZE; i++) {
size_t idx = (ringbuf_pos + i) % PRINTK_BUF_SIZE;
char c = printk_ringbuf[idx];
if (c != '\0') {
vga_putchar(c);
}
}
}
+21 -1
View File
@@ -7,6 +7,8 @@
#include <airlys/sched.h>
#include <airlys/timer.h>
#include <airlys/io.h>
#include <airlys/rtc.h>
#include <airlys/printk.h>
static char shell_buffer[SHELL_MAX_INPUT];
static size_t shell_pos = 0;
@@ -423,8 +425,26 @@ static void cmd_uptime(void) {
}
static void cmd_date(void) {
rtc_time_t t = rtc_get_time();
vga_set_color(VGA_COLOR_LIGHT_CYAN, VGA_COLOR_BLACK);
vga_puts("System Clock: Fri Oct 23 2026 12:45:00 UTC (Sovereign Hardware Clock Sync)\n");
vga_puts("Hardware RTC Clock: ");
vga_putdec(t.year);
vga_putchar('-');
if (t.month < 10) vga_putchar('0');
vga_putdec(t.month);
vga_putchar('-');
if (t.day < 10) vga_putchar('0');
vga_putdec(t.day);
vga_putchar(' ');
if (t.hour < 10) vga_putchar('0');
vga_putdec(t.hour);
vga_putchar(':');
if (t.minute < 10) vga_putchar('0');
vga_putdec(t.minute);
vga_putchar(':');
if (t.second < 10) vga_putchar('0');
vga_putdec(t.second);
vga_puts(" UTC (Motherboard CMOS Sync)\n");
}
static void cmd_dmesg(void) {