Initial commit: SUB-OS 64-Bit Production Monolithic Operating System with LazyBox userland suite

This commit is contained in:
subhobhai943 committed 2026-08-16 21:23:52 +05:30
commit cd9c786d14
88 files changed
+7132

No files matched your search

+15
View File
@@ -0,0 +1,15 @@
#ifndef _KERNEL_MAIN_H
#define _KERNEL_MAIN_H
#include "types.h"
#include "printk.h"
#include <arch/x86_64/io.h>
#define KERNEL_NAME "SUB-OS"
#define KERNEL_VERSION "0.2.0-lts"
#define KERNEL_ARCH "x86_64"
#define KERNEL_AUTHOR "SUB-OS Development Team"
void kernel_main(void* memory_map, uint64_t memory_map_count);
#endif // _KERNEL_MAIN_H
+9
View File
@@ -0,0 +1,9 @@
#ifndef _KERNEL_PANIC_H
#define _KERNEL_PANIC_H
#include <arch/x86_64/isr.h>
void panic(const char* message);
void panic_with_regs(const char* message, const registers_t* regs);
#endif // _KERNEL_PANIC_H
+48
View File
@@ -0,0 +1,48 @@
#ifndef _KERNEL_PRINTK_H
#define _KERNEL_PRINTK_H
#include <stddef.h>
#include <stdint.h>
#include <stdarg.h>
// Linux-compatible log level prefixes
#define KERN_EMERG "\0010" /* system is unusable */
#define KERN_ALERT "\0011" /* action must be taken immediately */
#define KERN_CRIT "\0012" /* critical conditions */
#define KERN_ERR "\0013" /* error conditions */
#define KERN_WARNING "\0014" /* warning conditions */
#define KERN_NOTICE "\0015" /* normal but significant condition */
#define KERN_INFO "\0016" /* informational */
#define KERN_DEBUG "\0017" /* debug-level messages */
// ANSI Color Escape Sequences
#define ANSI_RESET "\033[0m"
#define ANSI_BOLD "\033[1m"
#define ANSI_BLACK "\033[30m"
#define ANSI_RED "\033[31m"
#define ANSI_GREEN "\033[32m"
#define ANSI_YELLOW "\033[33m"
#define ANSI_BLUE "\033[34m"
#define ANSI_MAGENTA "\033[35m"
#define ANSI_CYAN "\033[36m"
#define ANSI_WHITE "\033[37m"
#define ANSI_BRIGHT_BLACK "\033[90m"
#define ANSI_BRIGHT_RED "\033[91m"
#define ANSI_BRIGHT_GREEN "\033[92m"
#define ANSI_BRIGHT_YELLOW "\033[93m"
#define ANSI_BRIGHT_BLUE "\033[94m"
#define ANSI_BRIGHT_MAGENTA "\033[95m"
#define ANSI_BRIGHT_CYAN "\033[96m"
#define ANSI_BRIGHT_WHITE "\033[97m"
// Printk API
void printk_init(void);
int printk(const char* fmt, ...);
int vprintk(const char* fmt, va_list args);
int kprintf(const char* fmt, ...); // Alias for compatibility
// Kernel Dmesg Ring Buffer API
void dmesg_dump(void);
const char* dmesg_get_buffer(size_t* size_out);
#endif // _KERNEL_PRINTK_H
+13
View File
@@ -0,0 +1,13 @@
#ifndef _KERNEL_SCHED_H
#define _KERNEL_SCHED_H
#include "task.h"
void sched_init(void);
void sched_yield(void);
void sched_schedule(void);
void sched_tick(void);
void sched_add_task(task_t* task);
void sched_remove_task(task_t* task);
#endif // _KERNEL_SCHED_H
+36
View File
@@ -0,0 +1,36 @@
#ifndef _KERNEL_SYNC_H
#define _KERNEL_SYNC_H
#include <stdint.h>
#include <stdbool.h>
typedef struct {
volatile uint32_t lock;
} spinlock_t;
#define SPINLOCK_INIT { .lock = 0 }
static inline void spinlock_init(spinlock_t* lock) {
lock->lock = 0;
}
static inline void spin_lock(spinlock_t* lock) {
while (__atomic_test_and_set(&lock->lock, __ATOMIC_ACQUIRE)) {
__asm__ volatile ("pause");
}
}
static inline void spin_unlock(spinlock_t* lock) {
__atomic_clear(&lock->lock, __ATOMIC_RELEASE);
}
typedef struct {
spinlock_t lock;
volatile int count;
} semaphore_t;
void sem_init(semaphore_t* sem, int value);
void sem_wait(semaphore_t* sem);
void sem_post(semaphore_t* sem);
#endif // _KERNEL_SYNC_H
+36
View File
@@ -0,0 +1,36 @@
#ifndef _KERNEL_TASK_H
#define _KERNEL_TASK_H
#include "types.h"
#include <lib/list.h>
typedef enum {
TASK_STATE_READY,
TASK_STATE_RUNNING,
TASK_STATE_BLOCKED,
TASK_STATE_SLEEPING,
TASK_STATE_ZOMBIE,
TASK_STATE_DEAD
} task_state_t;
typedef struct task_struct {
pid_t pid;
char name[32];
task_state_t state;
uint64_t rsp;
uint64_t stack_base;
size_t stack_size;
uint64_t sleep_until_ticks;
int priority;
int time_slice;
struct list_head list;
} task_t;
typedef void (*task_entry_fn_t)(void* arg);
task_t* task_create(const char* name, task_entry_fn_t entry, void* arg, int priority);
void task_exit(int exit_code);
task_t* task_current(void);
pid_t task_get_pid(void);
#endif // _KERNEL_TASK_H
+30
View File
@@ -0,0 +1,30 @@
#ifndef _KERNEL_TYPES_H
#define _KERNEL_TYPES_H
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
typedef int32_t pid_t;
typedef int32_t tid_t;
typedef uint32_t uid_t;
typedef uint32_t gid_t;
typedef int64_t off_t;
typedef int64_t ssize_t;
typedef uint32_t mode_t;
typedef uint32_t dev_t;
typedef uint64_t ino_t;
typedef uint64_t time_t;
#ifndef NULL
#define NULL ((void*)0)
#endif
#define ALIGN_UP(addr, align) (((addr) + (align) - 1) & ~((align) - 1))
#define ALIGN_DOWN(addr, align) ((addr) & ~((align) - 1))
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#endif // _KERNEL_TYPES_H