tasking: a small cleanup

This commit is contained in:
2025-06-23 00:36:07 +03:00
parent c047dd687b
commit 29de6e6f43
4 changed files with 4 additions and 34 deletions
-11
View File
@@ -1,14 +1,3 @@
struc PCB
.PID resd 1 ; Offset: 0
.STATE resd 1 ; Offset: 4
.KSTACK resd 1 ; Offset: 8
.CONTEXT resd 1 ; Offset: 12
.TF resd 1 ; Offset: 16
.FLAGS resd 1 ; Offset: 20
.NEXT resd 1 ; Offset: 24
.PAGE_DIRECTORY resd 1 ; Offset: 28
endstruc
; void switchProcess(Process* next)
section .text
global switchProcess
+1 -2
View File
@@ -49,11 +49,10 @@ const char* flags_to_mode_str(int flags) {
int sys_exit(TrapFrame *tf)
{
int error_code = tf->ebx;
printf("killing task\n");
debug_log("killing task\n");
task_kill(current);
asm("sti");
while(1){}
printf("wtf??");
return error_code;
}
+3 -20
View File
@@ -8,21 +8,15 @@
Process* current = 0;
Process* queue = 0;
Process* zombie_list = 0;
uint32_t irq_disable_counter = 0;
uint32_t pid_counter;
uint32_t task_count;
#define KSTACKSIZE 4096
#define USTACKSIZE 4096
extern void trapret(void);
extern void switchProcess(Process* next);
//extern Process* queue;
extern uint32_t pid_counter;
extern uint32_t task_count;
Process* task_create(uint32_t func, uint32_t user_esp, uint32_t ring, uint32_t* pagedir)
{
@@ -58,19 +52,11 @@ Process* task_create(uint32_t func, uint32_t user_esp, uint32_t ring, uint32_t*
p->tf->eflags = FL_IF;
p->tf->eip = (uint32_t)func;
p->pagedir = pagedir;//(uint32_t*)create_page_dir();
p->pagedir = pagedir;
if(ring == 3)
{
/*void* user_stack_physical = alloc_page();
uint32_t user_stack_virtual_top = 0xBFFFF000 - ((p->pid -1) * (USTACKSIZE + 4096)); // Уникальный верх стека для каждого процесса
uint32_t user_stack_virtual_base = user_stack_virtual_top - USTACKSIZE;
map_page_in_directory(p->pagedir, user_stack_physical, (void*)user_stack_virtual_base, PAGE_PRESENT | PAGE_RW | PAGE_USER); // Флаги 0x7
*/
p->tf->usermode_esp = user_esp;//user_stack_virtual_top;
p->tf->usermode_esp = user_esp;
}
@@ -92,7 +78,6 @@ Process* task_create(uint32_t func, uint32_t user_esp, uint32_t ring, uint32_t*
curr = curr->next;
curr->next = p;
}
task_count++;
return p;
}
@@ -164,8 +149,6 @@ void task2()
while (1) { a++; printf("task2 %X\n", a); }
}
void jump_usermode2(void) ;
void scheduler_init()
{
uint32_t* kernel_tasks_pagedir = (uint32_t*)create_page_dir();
@@ -174,7 +157,7 @@ void scheduler_init()
}
void task_kill(Process* proc) {
//that proc != current is sus
//TODO: that proc != current is sus
if (!proc || proc != current) return;
scheduler_lock();