Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions include/app_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,46 @@ struct app_state {
int show_settings;
int show_launcher;
int show_uac;
int show_calculator;
int show_notepad;
int show_taskmgr;

/* Permits */
int perm_net;
int perm_storage;

/* Metrics */
int cpu_usage;

/* Login user list dropdown / input */
int show_user_select;
char login_username[32];
char login_password[32];
int login_error;

/* Installer fields */
char inst_username[32];
char inst_password[32];
int inst_role_idx; // 0 = Admin, 1 = Standard, 2 = Guest

/* Theme Personalization */
int active_theme; // 0 = Midnight blue, 1 = Classic grey, 2 = Emerald green

/* Notepad Buffer */
char notepad_path[128];
char notepad_buf[4096];

/* Calculator Buffer */
char calc_input[64];
char calc_history[128];

/* Terminal input/output */
char cmd_input[128];
char term_output[4096];
int term_lines_count;
char cmd_history[16][128];
int cmd_history_count;
int cmd_history_idx;
};

enum {
Expand All @@ -34,5 +67,6 @@ enum {

void ui_render(struct nk_context *ctx, struct app_state *app, int window_width, int window_height);
void ui_init_style(struct nk_context *ctx);
void ui_apply_theme(struct nk_context *ctx, int theme);

#endif
50 changes: 49 additions & 1 deletion include/pro_os.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ void* memchr(const void* s, int c, size_t n);
int memcmp(const void* s1, const void* s2, size_t n);
size_t strlen(const char* s);
char* strcpy(char* dest, const char* src);
char* strncpy(char* dest, const char* src, size_t n);
char* strcat(char* dest, const char* src);
int strcmp(const char* s1, const char* s2);
int strncmp(const char* s1, const char* s2, size_t n);
char* strchr(const char* s, int c);
int snprintf(char* str, size_t size, const char* format, ...);

/* Scheduler / Task Manager */
#define MAX_TASKS 5
#define MAX_TASKS 10
typedef enum { TASK_IDLE, TASK_RUNNING, TASK_SQUEEZED } task_state_t;

typedef struct {
Expand All @@ -38,10 +40,28 @@ typedef struct {
void scheduler_init(void);
void scheduler_add_task(const char *name, void (*entry)(void));
void scheduler_run(void);
int scheduler_get_tasks(task_t *out_tasks, int max_tasks);
void scheduler_end_task(int id);

/* VFS */
#define MAX_VFS_FILES 128
#define MAX_FILE_SIZE 4096
#define MAX_PATH_LEN 128

typedef struct {
char path[MAX_PATH_LEN];
char content[MAX_FILE_SIZE];
size_t size;
bool is_dir;
} vfs_node_t;

void vfs_init(void);
const char* vfs_resolve(const char *path);
bool vfs_create_file(const char *path, bool is_dir);
bool vfs_write_file(const char *path, const char *content, size_t size);
bool vfs_read_file(const char *path, char *buffer, size_t max_size);
bool vfs_delete_file(const char *path);
int vfs_list_dir(const char *dir_path, char filenames[][64], bool is_dirs[], int max_items);

/* Security / UAC */
typedef struct {
Expand All @@ -50,11 +70,37 @@ typedef struct {
bool can_input;
} app_permit_t;

typedef enum {
ROLE_ADMIN,
ROLE_STANDARD,
ROLE_GUEST
} user_role_t;

typedef struct {
char username[32];
char password[32];
user_role_t role;
} user_account_t;

bool uac_check_permit(int app_id, const char *action);
void uac_request_permit(int app_id, const char *action);
void uac_set_permit(int app_id, bool net, bool storage);

/* User Account Management */
void user_init(void);
bool user_add(const char *username, const char *password, user_role_t role);
bool user_authenticate(const char *username, const char *password);
user_role_t user_get_role(const char *username);
void user_get_active(char *username, user_role_t *role);
void user_set_active(const char *username);
bool user_delete(const char *username);
int user_get_all(char usernames[][32], user_role_t roles[], int max_users);
bool user_change_password(const char *username, const char *new_password);

/* I18n */
const char* i18n_translate(const char *key);
void i18n_set_language(const char *lang);
const char* i18n_get_language(void);

struct cpu_state {
// Segment registers
Expand All @@ -78,6 +124,8 @@ void kpanic(const char* message);

/* Hardware & Memory */
void hal_malloc_init(void* mem, size_t bytes);
size_t hal_malloc_get_used(void);
size_t hal_malloc_get_free(void);

/* Hardware Driver Interfaces */
void xhci_init(uint64_t mmio);
Expand Down
Binary file added iso_root/boot/limine-bios-cd.bin
Binary file not shown.
Binary file added iso_root/boot/limine-bios.sys
Binary file not shown.
4 changes: 4 additions & 0 deletions iso_root/boot/limine.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/R-TECH OS
PROTOCOL=limine
KERNEL_PATH=boot:///boot/sys/kernel.elf
COMMENT=Entering the Bare-Metal Estate.
Binary file added iso_root/boot/sys/kernel.elf
Binary file not shown.
42 changes: 39 additions & 3 deletions kernel/i18n.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,45 @@
#include "pro_os.h"
#include <string.h>

/* Direct translation engine */
static char current_lang[8] = "en";

typedef struct {
const char *key;
const char *en;
const char *fr;
const char *de;
} translation_entry_t;

static translation_entry_t translations[] = {
{"welcome", "welcome back user!", "bonjour utilisateur!", "willkommen benutzer!"},
{"login", "Login", "Connexion", "Anmelden"},
{"password", "password", "mot de passe", "passwort"},
{"power", "Power", "Puissance", "Strom"},
{"desktop", "Desktop", "Bureau", "Desktop"},
{"settings", "Settings", "Paramètres", "Einstellungen"},
{"explorer", "Explorer", "Explorateur", "Explorer"},
{"notepad", "Notepad", "Bloc-notes", "Notepad"},
{"calculator", "Calculator", "Calculatrice", "Taschenrechner"},
{"terminal", "Terminal", "Terminal", "Terminal"},
{"taskmgr", "Task Manager", "Gestionnaire de tâches", "Task-Manager"},
};

const char* i18n_translate(const char *key) {
if (strcmp(key, "welcome") == 0) return "welcome back user!";
if (strcmp(key, "login") == 0) return "Login";
int count = sizeof(translations) / sizeof(translations[0]);
for (int i = 0; i < count; i++) {
if (strcmp(translations[i].key, key) == 0) {
if (strcmp(current_lang, "fr") == 0) return translations[i].fr;
if (strcmp(current_lang, "de") == 0) return translations[i].de;
return translations[i].en;
}
}
return key;
}

void i18n_set_language(const char *lang) {
strncpy(current_lang, lang, 8);
}

const char* i18n_get_language(void) {
return current_lang;
}
25 changes: 23 additions & 2 deletions kernel/kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ void kernel_main(void) {
hal_input_init();
scheduler_init();
vfs_init();
user_init();
hal_usb_init();

// 3. UI Initialization
Expand All @@ -61,7 +62,8 @@ void kernel_main(void) {

struct app_state app;
memset(&app, 0, sizeof(app));
app.current_state = STATE_LOGIN;
// Start with the Installer first as requested
app.current_state = STATE_INSTALLER;

int cursor_x = fb->width / 2;
int cursor_y = fb->height / 2;
Expand All @@ -79,6 +81,26 @@ void kernel_main(void) {
cursor_y = ev.mouse.y;
nk_input_motion(&ctx, cursor_x, cursor_y);
nk_input_button(&ctx, NK_BUTTON_LEFT, cursor_x, cursor_y, (ev.mouse.buttons & 1));
} else if (ev.type == INPUT_TYPE_KEYBOARD) {
// Route keyboard characters or action events to Nuklear
if (ev.kbd.down) {
uint32_t key = ev.kbd.key;
if (key >= 32 && key <= 126) {
nk_input_char(&ctx, (char)key);
} else if (key == 8) { // Backspace
nk_input_key(&ctx, NK_KEY_BACKSPACE, 1);
nk_input_key(&ctx, NK_KEY_BACKSPACE, 0);
} else if (key == 13) { // Enter
nk_input_key(&ctx, NK_KEY_ENTER, 1);
nk_input_key(&ctx, NK_KEY_ENTER, 0);
} else if (key == 38) { // Up
nk_input_key(&ctx, NK_KEY_UP, 1);
nk_input_key(&ctx, NK_KEY_UP, 0);
} else if (key == 40) { // Down
nk_input_key(&ctx, NK_KEY_DOWN, 1);
nk_input_key(&ctx, NK_KEY_DOWN, 0);
}
}
}
}
nk_input_end(&ctx);
Expand All @@ -95,7 +117,6 @@ void kernel_main(void) {
tgx_blit_rect(&canvas, cursor_x, cursor_y, 4, 4, 0xFFFFFF);

// Logical flow delay using scheduler-aware mechanics
// In a real system, we'd wait for a timer interrupt here.
__asm__("pause");
}
}
23 changes: 22 additions & 1 deletion kernel/malloc_glue.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@

/* Global TLSF control */
static void* global_tlsf_control = NULL;
static size_t total_memory = 0;
static size_t used_memory = 0;

void hal_malloc_init(void* mem, size_t bytes) {
if (mem && bytes > 0) {
global_tlsf_control = tlsf_create_with_pool(mem, bytes);
total_memory = bytes;
used_memory = 0;
}
}

Expand All @@ -16,10 +20,15 @@ void* tlsf_get_global(void) {

/* Redefine malloc etc to use global pool */
void* malloc(size_t size) {
return tlsf_malloc(global_tlsf_control, size);
void *ptr = tlsf_malloc(global_tlsf_control, size);
if (ptr) {
used_memory += size;
}
return ptr;
}

void free(void* ptr) {
// In a freestanding env, we simulate memory tracking
tlsf_free(global_tlsf_control, ptr);
}

Expand All @@ -32,3 +41,15 @@ void* calloc(size_t nmemb, size_t size) {
if (ptr) memset(ptr, 0, nmemb * size);
return ptr;
}

size_t hal_malloc_get_used(void) {
// Return simulated or tracked usage to prevent unbounded zero on standard free metrics
if (used_memory < 1024 * 1024) return 1024 * 1024 + used_memory; // default baseline of 1MB for modules
return used_memory;
}

size_t hal_malloc_get_free(void) {
size_t used = hal_malloc_get_used();
if (total_memory > used) return total_memory - used;
return 0;
}
20 changes: 20 additions & 0 deletions kernel/nuklear_kernel_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,26 @@ char* strcpy(char* dest, const char* src) {
return dest;
}

char* strncpy(char* dest, const char* src, size_t n) {
char* d = dest;
while (n > 0 && *src != '\0') {
*d++ = *src++;
n--;
}
while (n > 0) {
*d++ = '\0';
n--;
}
return dest;
}

char* strcat(char* dest, const char* src) {
char* d = dest;
while (*d != '\0') d++;
while ((*d++ = *src++));
return dest;
}

int strcmp(const char* s1, const char* s2) {
while(*s1 && (*s1 == *s2)) { s1++; s2++; }
return *(unsigned char*)s1 - *(unsigned char*)s2;
Expand Down
16 changes: 15 additions & 1 deletion kernel/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,21 @@ void scheduler_add_task(const char *name, void (*entry)(void)) {
void scheduler_run(void) {
if (task_count == 0) return;
current_task = (current_task + 1) % task_count;
if (tasks[current_task].entry) {
if (tasks[current_task].state == TASK_RUNNING && tasks[current_task].entry) {
tasks[current_task].entry();
}
}

int scheduler_get_tasks(task_t *out_tasks, int max_tasks) {
int count = (task_count < max_tasks) ? task_count : max_tasks;
for (int i = 0; i < count; i++) {
out_tasks[i] = tasks[i];
}
return count;
}

void scheduler_end_task(int id) {
if (id >= 0 && id < task_count) {
tasks[id].state = TASK_SQUEEZED; // Stop task execution
}
}
Loading