Skip to content

dkrnl.h

RedstoneShell edited this page Oct 10, 2026 · 1 revision

DKRNL_H

Linking by #include <dkrnl.h.

dtask_saved

Special structure that used in multitask, he use only for saving task data between switching to next tasks.

typedef struct dtask_saved {
    u64 r15, r14, r13, r12, r11, r10, r9, r8; // General Purpose Registers
    u64 rdi, rsi, rbp, rdx, rcx, rbx, rax; // General Purpose Registers
    u64 vector;
    u64 error_code;
    u64 rip, cs, rflags; // Instruction Pointer, Code Segment, Flags Register
    u64 rsp; // Stack Pointer
    u64 simd[DTASK_SIMD_SLOTS * 2]; // SSE/AVX saved data. Here saves XMM0..15 if program uses SIMD, DTASK_SIMD_SLOTS=16
} dtask_saved_t;

dtask

typedef struct dtask {
    const char *name; // Name of task
    void (*func)(void); // Entry point of task, that registered in kernel
    u64 period; // Period of calling in mcs (MicroSeconds)
    u64 next_tick; // Calc by kernel, g_tick+period, g_tick is internal in kernel variable that increment by 1 at every task tick
    u32 active; // Bit that means: Are task is working?
    u32 uses_simd; // Flag that select: Save/Load or not XMM0..15(SIMD Registers)?
    u64 stack_base; // Address of stack
    u64 stack_size; // Size of stack
    u64 stack_top; // Top of stack
    dtask_saved_t saved; // Pointer to Registry Map.
} dtask_t;

dkernel_api

A giant structure that contains every Global Kernel API. Use for registering in multitask, working with disk, management with storages and etc.

typedef struct dkernel_api {
    u32 version; // Kernel API ver
    u32 _pad;
    int (*register_driver)(void *drv); // Registers driver in kernel, you can see how to work with this function in "wiki/Writing my first driver"
    int (*task_add)(const char *name, void (*func)(void), u64 period); // Add task in multitask, `name` is name of task, `func` is handler of task that call by kernel, `period` is after what microseconds call this handler.
    int (*task_add_simd)(const char *name, void (*func)(void), u64 period); // Equals to `task_add`, but signals for kernel about SSE/AVX usage in task.
    int (*task_remove)(const char *name); // You know what he do
    u64 (*write_file)(const u16 *path, const void *buf, u64 size); // Write in file data, `path` is path where write file (path+filename.exension) cast to null-term u16 path[] = { 'A', 'B', 'C', ..., 0 }, `buf` is buffer with data to write in file, `size` is size of buffer
    u64 (*read_file)(const u16 *path, void *buf, u64 size); // Read file data, `path` is path where read file (path+filename.exension) cast to null-term u16 path[] = { 'A', 'B', 'C', ..., 0 }, `buf` is buffer that fill by file data, `size` is size of buffer
    u32 (*smp_get_ncpu)(void); // Returns count of cores in CPU
    u32 (*smp_get_load)(u32 core_id); // Returns load of core, selected by `core_id`.
    u64 (*get_total_ram)(void); // Return total ram in bytes
    u64 (*get_storage_bytes)(void); // Get bytes of every storage sum
    u32 (*get_storage_count)(void); // Get count of storages
    u64 (*get_storage_device_size)(u32 index); // Get size in bytes of storage selected by index
    void (*smp_add_metrics)(u32 core_id, u64 active, u64 total); // Add metrics for selected core, `core_id` is num of core, `active` is ticks that core active, `total` is total ticks active+idle.
    ddriver_t *(*DFindAndGetDriver)(const char *name); // Very good function, need to easy getting interface of driver selected by `name`.
    volatile hpet_system_info_t *hpet_info; // ACPI HPET info.
} dkernel_api_t;

dkrnl_task_yield(void): void

Yield current task.

pit_init(u32 hz): void

Program PIT controller, at selected Hz.

Variables

#define DTASK_MAX            16 // Max tasks in Depressure
#define DTASK_STACK_SIZE     0x8000 // Stack of every task
#define DTASK_SIMD_SLOTS     16 // Slot of SSE/AVX registers (XMM0..15)

Clone this wiki locally