maybe i'm close to fixing multitasking

This commit is contained in:
2025-05-16 14:55:19 +03:00
parent 4fbaed321c
commit 2e372ae9c4
3 changed files with 209 additions and 195 deletions
+62 -19
View File
@@ -3,32 +3,75 @@
#include <stdint.h>
// Сегменты для ядра и пользователя
#define SEG_KCODE 1 // Сегмент кода ядра
#define SEG_KDATA 2 // Сегмент данных ядра
#define SEG_UCODE 3 // Сегмент кода пользователя
#define SEG_UDATA 4 // Сегмент данных пользователя
#define DPL_KERNEL 0 // Уровень привилегий ring 0
#define DPL_USER 3 // Уровень привилегий ring 3
// Флаги процессора
#define FL_IF 0x202 // Разрешить прерывания
typedef enum TaskState
{
Ready,
Running,
Waiting,
Terminated
Ready,
Running,
Waiting,
Terminated
} TaskState;
typedef void (*EntryPoint)(void);
// Структура контекста для переключения между процессами
typedef struct Context {
uint32_t edi;
uint32_t esi;
uint32_t ebx;
uint32_t ebp;
uint32_t eip;
} Context;
// Структура trap frame для перехода в ring 3
typedef struct TrapFrame {
uint32_t edi;
uint32_t esi;
uint32_t ebp;
uint32_t oesp;
uint32_t ebx;
uint32_t edx;
uint32_t ecx;
uint32_t eax;
uint16_t gs;
uint16_t fs;
uint16_t es;
uint16_t ds;
uint32_t trapno;
uint32_t err;
uint32_t eip;
uint32_t cs;
uint32_t eflags;
uint32_t esp;
uint32_t ss;
} TrapFrame;
typedef struct Process
{
uint32_t pid; // Process ID
TaskState state; // Process state
uintptr_t programCounter; // Program Counter
uintptr_t* stackBase; // Top of the stack
uintptr_t* stackPointer; // Stack Pointer
uint32_t flags; // Status/Flags register
struct Process* next; // Pointer to the next task in the list
uint32_t* page_directory;
uint32_t pid; // Process ID
TaskState state; // Состояние процесса
char* kstack; // Стек ядра
Context* context; // Контекст для переключения
TrapFrame* tf; // Trap frame (только для ring 3)
uint32_t ring; // Уровень привилегий (0 или 3)
struct Process* next; // Следующий процесс
uint32_t* page_directory; // Директория страниц
} Process;
Process* task_create(EntryPoint func, void** args, uint32_t arg_count);
void scheduler_init();
void schedule();
void scheduler_lock();
void scheduler_unlock();
#endif
Process* task_create(EntryPoint func, void** args, uint32_t arg_count, uint32_t ring);
void scheduler_init();
void schedule();
void scheduler_lock();
void scheduler_unlock();
#endif