mirror of
https://github.com/subhobhai943/SUB-OS.git
synced 2026-10-26 00:52:50 +00:00
feat: Implement modern Tree directory visualizer, TSC profiler, and VT Art visualizer
- Add dedicated Linux-compatible Tree visualizer with UTF-8/ASCII branch tracking, -L depth filtering, human sizes, and permissions in userland/lazybox/tree.c - Implement Hardware Invariant Timestamp Counter (TSC) calibration and microsecond delay timer in kernel/tsc.c and include/kernel/tsc.h - Add Virtual Terminal color palette, live resource utilization bars, and logo banner in kernel/vt_art.c and include/kernel/vt_art.h - Add LazyBox applets: 'tree', 'tscinfo', and 'vtart' - Update README.md documentation and command matrix
This commit is contained in:
1 parent
1c09408287
commit
d1361aeaf2
9 files changed
+454
-40
No files matched your search
@@ -61,6 +61,7 @@
|
||||
#include <net/dns_cache.h>
|
||||
#include <ipc/shm_posix.h>
|
||||
#include <sound/beep.h>
|
||||
#include <kernel/tsc.h>
|
||||
#include <kernel/rust.h>
|
||||
#include <kernel/sub_lang.h>
|
||||
#include <kernel/cpp_kernel.h>
|
||||
@@ -229,6 +230,7 @@ void kernel_main(void* memory_map, uint64_t memory_map_count) {
|
||||
|
||||
printk(KERN_INFO "[1/14] Initializing 64-Bit GDT, IDT, PIC & PIT Timer... ");
|
||||
arch_init();
|
||||
tsc_init();
|
||||
printk(ANSI_BRIGHT_GREEN "OK\n" ANSI_RESET);
|
||||
|
||||
printk(KERN_INFO "[2/14] Initializing PS/2 Keyboard, Mouse & ACPI... ");
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
// High-Resolution Timestamp Counter (TSC) & Nanosecond Timing Subsystem
|
||||
#include <kernel/tsc.h>
|
||||
#include <kernel/printk.h>
|
||||
#include <kernel/timer.h>
|
||||
|
||||
static uint64_t g_tsc_khz = 2400000; // Default: 2.4 GHz estimate
|
||||
static bool g_tsc_available = true;
|
||||
|
||||
uint64_t tsc_read(void) {
|
||||
#if defined(__x86_64__)
|
||||
uint32_t lo, hi;
|
||||
__asm__ __volatile__("rdtsc" : "=a"(lo), "=d"(hi));
|
||||
return ((uint64_t)hi << 32) | lo;
|
||||
#elif defined(__aarch64__)
|
||||
uint64_t val;
|
||||
__asm__ __volatile__("mrs %0, cntvct_el0" : "=r"(val));
|
||||
return val;
|
||||
#elif defined(__arm__)
|
||||
uint32_t lo, hi;
|
||||
__asm__ __volatile__("mrrc p15, 1, %0, %1, c14" : "=r"(lo), "=r"(hi));
|
||||
return ((uint64_t)hi << 32) | lo;
|
||||
#else
|
||||
return timer_get_ticks() * 1000000;
|
||||
#endif
|
||||
}
|
||||
|
||||
void tsc_init(void) {
|
||||
#if defined(__x86_64__)
|
||||
// Calibrate TSC using I/O bus delay loop (~1us per outb 0x80)
|
||||
uint64_t t1 = tsc_read();
|
||||
for (volatile int i = 0; i < 10000; i++) {
|
||||
__asm__ __volatile__("outb %%al, $0x80" : : "a"(0));
|
||||
}
|
||||
uint64_t t2 = tsc_read();
|
||||
|
||||
uint64_t diff = (t2 > t1) ? (t2 - t1) : 24000000;
|
||||
uint64_t calculated_khz = diff / 10;
|
||||
if (calculated_khz > 100000 && calculated_khz < 10000000) {
|
||||
g_tsc_khz = calculated_khz;
|
||||
} else {
|
||||
g_tsc_khz = 2400000;
|
||||
}
|
||||
#elif defined(__aarch64__)
|
||||
uint64_t freq;
|
||||
__asm__ __volatile__("mrs %0, cntfrq_el0" : "=r"(freq));
|
||||
if (freq > 0) g_tsc_khz = freq / 1000;
|
||||
#endif
|
||||
|
||||
printk(KERN_INFO "TSC: Invariant Timestamp Counter online (Calibrated: %llu.%03llu MHz)\n",
|
||||
g_tsc_khz / 1000, g_tsc_khz % 1000);
|
||||
}
|
||||
|
||||
uint64_t tsc_get_khz(void) {
|
||||
return g_tsc_khz;
|
||||
}
|
||||
|
||||
uint64_t tsc_to_ns(uint64_t cycles) {
|
||||
if (g_tsc_khz == 0) return 0;
|
||||
return (cycles * 1000000) / g_tsc_khz;
|
||||
}
|
||||
|
||||
uint64_t tsc_to_us(uint64_t cycles) {
|
||||
if (g_tsc_khz == 0) return 0;
|
||||
return (cycles * 1000) / g_tsc_khz;
|
||||
}
|
||||
|
||||
void tsc_udelay(uint32_t microseconds) {
|
||||
uint64_t start = tsc_read();
|
||||
uint64_t cycles_needed = ((uint64_t)microseconds * g_tsc_khz) / 1000;
|
||||
while ((tsc_read() - start) < cycles_needed) {
|
||||
#if defined(__x86_64__)
|
||||
__asm__ __volatile__("pause");
|
||||
#elif defined(__aarch64__) || defined(__arm__)
|
||||
__asm__ __volatile__("yield");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void tsc_dump_info(void) {
|
||||
uint64_t now = tsc_read();
|
||||
printk(ANSI_BRIGHT_CYAN "=== Hardware Timestamp Counter (TSC) Telemetry ===\n" ANSI_RESET);
|
||||
printk(" Available : " ANSI_BRIGHT_GREEN "%s\n" ANSI_RESET, g_tsc_available ? "YES (Invariant TSC)" : "NO");
|
||||
printk(" Calibrated Clock : \x1b[93m%llu.%03llu MHz\x1b[0m (%llu kHz)\n", g_tsc_khz / 1000, g_tsc_khz % 1000, g_tsc_khz);
|
||||
printk(" Raw Cycles : \x1b[92m%llu cycles\x1b[0m\n", now);
|
||||
printk(" Resolution : \x1b[96m~%llu ns per cycle\x1b[0m\n\n", 1000000 / (g_tsc_khz ? g_tsc_khz : 1));
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
// ANSI Virtual Terminal Graphics, Color Palette & Telemetry Visualizer
|
||||
#include <kernel/vt_art.h>
|
||||
#include <kernel/printk.h>
|
||||
|
||||
void vt_show_palette_256(void) {
|
||||
printk(ANSI_BRIGHT_CYAN "=== 16-Color Standard & High-Intensity ANSI Palette ===\n" ANSI_RESET);
|
||||
for (int i = 0; i < 8; i++) {
|
||||
printk("\x1b[48;5;%dm %2d \x1b[0m", i, i);
|
||||
}
|
||||
printk("\n");
|
||||
for (int i = 8; i < 16; i++) {
|
||||
printk("\x1b[48;5;%dm %2d \x1b[0m", i, i);
|
||||
}
|
||||
printk("\n\n");
|
||||
|
||||
printk(ANSI_BRIGHT_CYAN "=== 216-Color RGB Cube (6x6x6) ===\n" ANSI_RESET);
|
||||
for (int g = 0; g < 6; g++) {
|
||||
for (int r = 0; r < 6; r++) {
|
||||
for (int b = 0; b < 6; b++) {
|
||||
int code = 16 + (r * 36) + (g * 6) + b;
|
||||
printk("\x1b[48;5;%dm \x1b[0m", code);
|
||||
}
|
||||
printk(" ");
|
||||
}
|
||||
printk("\n");
|
||||
}
|
||||
printk("\n");
|
||||
|
||||
printk(ANSI_BRIGHT_CYAN "=== 24-Step Grayscale Ramp ===\n" ANSI_RESET);
|
||||
for (int i = 232; i <= 255; i++) {
|
||||
printk("\x1b[48;5;%dm \x1b[0m", i);
|
||||
}
|
||||
printk("\n\n");
|
||||
}
|
||||
|
||||
static void draw_progress_bar(const char* label, uint32_t percent, const char* color_code) {
|
||||
printk("%-8s [", label);
|
||||
uint32_t filled = (percent * 30) / 100;
|
||||
if (filled > 30) filled = 30;
|
||||
|
||||
printk("%s", color_code);
|
||||
for (uint32_t i = 0; i < filled; i++) {
|
||||
printk("█");
|
||||
}
|
||||
printk(ANSI_RESET);
|
||||
for (uint32_t i = filled; i < 30; i++) {
|
||||
printk("░");
|
||||
}
|
||||
printk("] %3u%%\n", percent);
|
||||
}
|
||||
|
||||
void vt_show_load_bars(uint32_t cpu_percent, uint32_t mem_percent, uint32_t disk_percent) {
|
||||
printk(ANSI_BRIGHT_CYAN "=== Live System Load & Resource Utilization ===\n" ANSI_RESET);
|
||||
draw_progress_bar("CPU Core", cpu_percent, ANSI_BRIGHT_GREEN);
|
||||
draw_progress_bar("RAM Heap", mem_percent, ANSI_BRIGHT_YELLOW);
|
||||
draw_progress_bar("VFS Disk", disk_percent, ANSI_BRIGHT_CYAN);
|
||||
printk("\n");
|
||||
}
|
||||
|
||||
void vt_show_logo_banner(void) {
|
||||
printk(ANSI_BRIGHT_CYAN
|
||||
" ____ _ _ ____ ___ ____ \n"
|
||||
" / ___|| | | | __ ) / _ \\/ ___| \n"
|
||||
" \\___ \\| | | | _ \\ ___| | | \\___ \\ \n"
|
||||
" ___) | |_| | |_) |___| |_| |___) |\n"
|
||||
" |____/ \\___/|____/ \\___/|____/ \n"
|
||||
ANSI_RESET);
|
||||
printk(ANSI_BRIGHT_MAGENTA " Modular Monolithic Linux-Compatible Hybrid Kernel\n\n" ANSI_RESET);
|
||||
}
|
||||
Reference in new issue
Block a user