feat: native .opc executable binary format, hardware PCI GPU driver, terminal text editor, and web browser

This commit is contained in:
RarDog
2026-09-03 10:20:25 +03:00
parent e9d9b8e365
commit ca75e961f9
17 changed files with 1213 additions and 19 deletions
+249 -5
View File
@@ -6,6 +6,7 @@
#include "abi/net.h"
#include "fb.h"
#include "rtl8139.h"
#include "pci.h"
#define UART_ENDPOINT 2
#define PROCMGR_ENDPOINT 4
@@ -13,11 +14,11 @@
// In-Memory Virtual File System (Ramdisk)
struct VfsFile {
char name[32];
char content[512];
char content[2048];
bool is_dir;
};
static VfsFile vfs_nodes[32] = {
static VfsFile vfs_nodes[64] = {
{ "/etc", "", true },
{ "/bin", "", true },
{ "/boot", "", true },
@@ -31,8 +32,9 @@ static VfsFile vfs_nodes[32] = {
{ "/dev/null", "", false },
{ "/dev/uart0", "16550 Serial COM1 Port\n", false },
{ "/dev/net0", "Realtek RTL8139 Fast Ethernet PCI\n", false },
{ "/boot/hello.opc", "OpenCore Native Executable Binary (.OPC v1.0)\n", false },
};
static size_t vfs_count = 13;
static size_t vfs_count = 14;
// Shell Environment Variables
struct EnvVar {
@@ -66,6 +68,9 @@ static void print_fastfetch() {
rdi = (uint64_t)&fb;
__asm__ volatile("syscall" : "+r"(rax) : "r"(rdi) : "rcx", "r11", "memory");
gpu_info_t gpu;
bool has_gpu = (pci_detect_gpu(&gpu) == 0);
printf("\n");
printf(" \033[1;36m ___ \033[1;32mroot\033[0m@\033[1;36mopencoreC\033[0m\n");
printf(" \033[1;36m / \\ \033[0;37m-----------------\033[0m\n");
@@ -80,7 +85,16 @@ static void print_fastfetch() {
}
printf(" \033[1;35m x86_64 SMP \033[1;34mDE / WM:\033[0m LVGL v8.3 Windows/KDE Compositor\n");
printf(" \033[1;35m Ring 3 Userspace \033[1;34mCPU:\033[0m QEMU Virtual CPU (4 Cores SMP)\n");
printf(" \033[1;35m Fast-Path IPC Cap \033[1;34mMemory:\033[0m %u MiB / %u MiB (%u%%)\n",
if (has_gpu) {
if (gpu.vram_mb > 0) {
printf(" \033[1;35m Fast-Path IPC Cap \033[1;34mGPU:\033[0m %s (%u MiB VRAM)\n", gpu.model_name, (unsigned int)gpu.vram_mb);
} else {
printf(" \033[1;35m Fast-Path IPC Cap \033[1;34mGPU:\033[0m %s\n", gpu.model_name);
}
} else {
printf(" \033[1;35m Fast-Path IPC Cap \033[1;34mGPU:\033[0m Linear UEFI GOP Framebuffer\n");
}
printf(" \033[1;34mMemory:\033[0m %u MiB / %u MiB (%u%%)\n",
(unsigned int)used_mb, (unsigned int)total_mb,
total_mb > 0 ? (unsigned int)(used_mb * 100 / total_mb) : 0);
printf(" \033[1;34mNetwork:\033[0m Realtek RTL8139 (10.0.2.15)\n");
@@ -127,6 +141,211 @@ static const char *thread_state_str(uint32_t state) {
}
}
static void lspci_device_cb(const pci_device_t *dev) {
const char *class_str = pci_class_to_string(dev->class_code, dev->subclass);
const char *vendor_str = pci_vendor_to_string(dev->vendor_id);
printf(" \033[1;33m%02x:%02x.%d\033[0m \033[1;36m[%04x:%04x]\033[0m \033[1;32m%-30s\033[0m : %s\n",
dev->bus, dev->slot, dev->func,
dev->vendor_id, dev->device_id,
class_str, vendor_str);
}
static void cmd_lspci() {
printf("\n\033[1;37mPCI Bus Topology & Hardware Inventory:\033[0m\n");
printf("--------------------------------------------------------------------------------\n");
pci_scan_bus(lspci_device_cb);
printf("--------------------------------------------------------------------------------\n\n");
}
static void cmd_gpu() {
gpu_info_t gpu;
if (pci_detect_gpu(&gpu) == 0) {
printf("\n\033[1;32mHardware GPU Accelerator Detected:\033[0m\n");
printf(" Vendor: %s (0x%04x)\n", gpu.vendor_name, gpu.vendor_id);
printf(" Model: \033[1;36m%s\033[0m (Device ID: 0x%04x)\n", gpu.model_name, gpu.device_id);
printf(" PCI Slot: Bus %02x, Device %02x, Function %d\n", gpu.bus, gpu.slot, gpu.func);
if (gpu.vram_mb > 0) {
printf(" VRAM: \033[1;33m%u MiB\033[0m Physical Video Memory (BAR Aperture)\n", (unsigned int)gpu.vram_mb);
} else {
printf(" VRAM: Linear GOP Framebuffer\n");
}
printf(" Display: 1280x800 32bpp Double-Buffered SSE2 SIMD Compositor\n\n");
} else {
puts("GPU: No dedicated PCI 3D/VGA controller detected; using UEFI GOP framebuffer.");
}
}
static void editor_render(const char *filename, const char *buf, size_t cursor_pos, const char *status) {
(void)cursor_pos;
sys_log_debug("\033[2J\033[H", 7);
printf("\033[7m opencoreC Editor (kilo/nano) | File: %-18s | Length: %-4u bytes \033[0m\r\n",
filename, (unsigned int)strlen(buf));
int line_num = 1;
printf("\033[1;30m%3d │ \033[0m", line_num);
const char *p = buf;
while (*p) {
putchar(*p);
if (*p == '\n') {
line_num++;
printf("\033[1;30m%3d │ \033[0m", line_num);
}
p++;
}
printf("\r\n\r\n\033[7m [Ctrl+S] Save | [Ctrl+Q / ESC] Exit | Status: %-26s \033[0m\r\n",
status ? status : "Ready (Type text)");
}
static void cmd_edit(const char *filename) {
if (!filename || !*filename) {
puts("Usage: edit <filename>");
return;
}
int file_idx = -1;
for (size_t i = 0; i < vfs_count; i++) {
if (strcmp(vfs_nodes[i].name, filename) == 0) {
file_idx = (int)i;
break;
}
}
if (file_idx < 0) {
if (vfs_count >= 64) {
puts("edit: Ramdisk full, cannot create new file.");
return;
}
file_idx = (int)vfs_count++;
strncpy(vfs_nodes[file_idx].name, filename, 31);
vfs_nodes[file_idx].content[0] = '\0';
vfs_nodes[file_idx].is_dir = false;
}
char buf[2048];
memset(buf, 0, sizeof(buf));
strncpy(buf, vfs_nodes[file_idx].content, sizeof(buf) - 1);
size_t cursor_pos = strlen(buf);
const char *status = "Editing (Ctrl+S to save, Ctrl+Q to exit)";
editor_render(filename, buf, cursor_pos, status);
while (true) {
int c = sys_key_read();
if (c <= 0) {
sys_yield();
continue;
}
if (c == 17 || c == 27) { // Ctrl+Q or ESC -> Exit
break;
} else if (c == 19) { // Ctrl+S -> Save
strncpy(vfs_nodes[file_idx].content, buf, sizeof(vfs_nodes[file_idx].content) - 1);
status = "FILE SAVED TO RAMDISK!";
editor_render(filename, buf, cursor_pos, status);
} else if (c == '\b' || c == 127 || c == 8) { // Backspace
if (cursor_pos > 0) {
memmove(&buf[cursor_pos - 1], &buf[cursor_pos], strlen(&buf[cursor_pos]) + 1);
cursor_pos--;
status = "Modified";
editor_render(filename, buf, cursor_pos, status);
}
} else if (c == '\r' || c == '\n') { // Enter
if (strlen(buf) < sizeof(buf) - 2) {
memmove(&buf[cursor_pos + 1], &buf[cursor_pos], strlen(&buf[cursor_pos]) + 1);
buf[cursor_pos] = '\n';
cursor_pos++;
status = "Modified";
editor_render(filename, buf, cursor_pos, status);
}
} else if (c >= 32 && c <= 126) { // Printable
if (strlen(buf) < sizeof(buf) - 2) {
memmove(&buf[cursor_pos + 1], &buf[cursor_pos], strlen(&buf[cursor_pos]) + 1);
buf[cursor_pos] = (char)c;
cursor_pos++;
status = "Modified";
editor_render(filename, buf, cursor_pos, status);
}
}
}
sys_log_debug("\033[2J\033[H", 7);
printf("Exited editor. File '%s' saved in ramdisk.\n", filename);
}
static void cmd_run_module(const char *mod_name) {
while (*mod_name == '.' || *mod_name == '/') {
mod_name++;
}
printf("[osh] Launching native program '%s' via kernel loader...\n", mod_name);
int64_t tid = sys_module_exec(mod_name);
if (tid >= 0) {
printf("[osh] Process successfully spawned with TID %ld on Ring 3!\n", (long)tid);
for (int i = 0; i < 6; i++) sys_yield();
} else {
printf("osh: failed to execute '%s' (module not found or invalid format)\n", mod_name);
puts("Hint: Type 'modules' to see all available in-memory boot modules.");
}
}
static void cmd_modules() {
char buf[512] = {0};
int len = sys_module_list(buf, sizeof(buf) - 1);
if (len > 0) {
printf("\n\033[1;37mIn-Memory Boot Modules (Available for Execution):\033[0m\n");
printf("------------------------------------------------------\n");
char *p = buf;
while (*p) {
char mod[64] = {0};
int mi = 0;
while (*p && *p != ' ' && mi < 63) {
mod[mi++] = *p++;
}
while (*p == ' ') p++;
if (strstr(mod, ".opc")) {
printf(" • \033[1;32m%-24s\033[0m [Native OpenCore Binary]\n", mod);
} else if (strstr(mod, ".elf")) {
printf(" • \033[1;36m%-24s\033[0m [Standard ELF64 Binary]\n", mod);
} else {
printf(" • %-24s\n", mod);
}
}
printf("------------------------------------------------------\n");
puts("To run: type './hello.opc' or 'run hello.opc'\n");
} else {
puts("modules: No boot modules detected.");
}
}
static void cmd_curl(const char *target) {
char body[1024];
memset(body, 0, sizeof(body));
uint32_t ip = g_net_cfg.gateway;
uint16_t port = 80;
const char *path = "/";
if (target && *target) {
if (strncmp(target, "http://", 7) == 0) target += 7;
char host[64] = {0};
int hi = 0;
while (*target && *target != '/' && *target != ':' && hi < 63) {
host[hi++] = *target++;
}
if (*host) ip = parse_ip(host);
if (*target == '/') path = target;
}
char ip_str[32];
format_ip(ip, ip_str);
printf("[curl] Connecting to %s:%u (Path: %s) via TCP/IPv4...\n", ip_str, port, path);
int status = net_http_get(ip, port, path, body, sizeof(body));
if (status == 200) {
printf("\033[1;32mHTTP/1.1 200 OK\033[0m (TCP Connected)\n\n");
puts(body);
} else {
printf("[curl] Connection to %s:%u failed.\n", ip_str, port);
}
}
static void handle_command(char *cmd) {
while (*cmd && ((unsigned char)*cmd <= ' ' || (unsigned char)*cmd > 126)) {
cmd++;
@@ -148,6 +367,7 @@ static void handle_command(char *cmd) {
puts(" ls / dir - List directory contents in ramdisk");
puts(" cat <file> - Display contents of a virtual file");
puts(" touch <file> - Create a new file in ramdisk");
puts(" edit / nano <fl> - Fullscreen interactive terminal text editor");
puts(" mkdir <dir> - Create a new directory");
puts(" cp <src> <dst> - Copy a file in ramdisk");
puts(" rm <file> - Remove a file from ramdisk");
@@ -165,6 +385,12 @@ static void handle_command(char *cmd) {
puts(" shm - Demonstrate Zero-Copy Shared Memory");
puts(" ifconfig / ip - Display network interface (RTL8139) status");
puts(" ping [ip] - Real ICMP Echo ping over virtual network");
puts(" curl / fetch <u - Fetch webpage via TCP/IPv4 stack");
puts(" lspci - Enumerate hardware devices on PCI bus");
puts(" gpu - Display detected GPU accelerator & VRAM");
puts(" modules - List in-memory boot modules available to run");
puts(" run / ./<module> - Execute native .opc or .elf binary (e.g. ./hello.opc)");
puts(" notify <msg> - Send desktop notification toast to GUI");
puts(" gui - Launch Framebuffer graphics & window desktop");
puts(" write <str> - Send Rendezvous IPC message to UART driver");
puts(" clear - Clear terminal display");
@@ -595,7 +821,25 @@ static void handle_command(char *cmd) {
puts("[CRASH-TEST] Expected outcome: Kernel delivers SIGSEGV, terminates this thread, kernel stays alive!");
volatile int *bad_ptr = (volatile int *)0;
*bad_ptr = 42;
} else if (strcmp(cmd, "fastfetch") == 0 || strcmp(cmd, "neofetch") == 0 || strcmp(cmd, "fetch") == 0) {
} else if (strcmp(cmd, "lspci") == 0) {
cmd_lspci();
} else if (strcmp(cmd, "gpu") == 0) {
cmd_gpu();
} else if (strncmp(cmd, "edit ", 5) == 0) {
cmd_edit(cmd + 5);
} else if (strncmp(cmd, "nano ", 5) == 0) {
cmd_edit(cmd + 5);
} else if (strncmp(cmd, "./", 2) == 0) {
cmd_run_module(cmd + 2);
} else if (strncmp(cmd, "run ", 4) == 0) {
cmd_run_module(cmd + 4);
} else if (strcmp(cmd, "modules") == 0) {
cmd_modules();
} else if (strncmp(cmd, "curl ", 5) == 0) {
cmd_curl(cmd + 5);
} else if (strncmp(cmd, "fetch ", 6) == 0) {
cmd_curl(cmd + 6);
} else if (strcmp(cmd, "fastfetch") == 0 || strcmp(cmd, "neofetch") == 0) {
print_fastfetch();
} else if (strcmp(cmd, "clear") == 0) {
sys_log_debug("\033[2J\033[H", 7);