tasking: a small cleanup
This commit is contained in:
@@ -63,7 +63,6 @@ typedef struct Process
|
|||||||
struct Process* next; // Следующий процесс
|
struct Process* next; // Следующий процесс
|
||||||
|
|
||||||
file_t* file_descriptors[MAX_OPEN_FILES];
|
file_t* file_descriptors[MAX_OPEN_FILES];
|
||||||
uint8_t zombie;
|
|
||||||
} Process;
|
} Process;
|
||||||
|
|
||||||
extern Process* current;
|
extern Process* current;
|
||||||
|
|||||||
@@ -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)
|
; void switchProcess(Process* next)
|
||||||
section .text
|
section .text
|
||||||
global switchProcess
|
global switchProcess
|
||||||
|
|||||||
@@ -49,11 +49,10 @@ const char* flags_to_mode_str(int flags) {
|
|||||||
int sys_exit(TrapFrame *tf)
|
int sys_exit(TrapFrame *tf)
|
||||||
{
|
{
|
||||||
int error_code = tf->ebx;
|
int error_code = tf->ebx;
|
||||||
printf("killing task\n");
|
debug_log("killing task\n");
|
||||||
task_kill(current);
|
task_kill(current);
|
||||||
asm("sti");
|
asm("sti");
|
||||||
while(1){}
|
while(1){}
|
||||||
printf("wtf??");
|
|
||||||
return error_code;
|
return error_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-20
@@ -8,21 +8,15 @@
|
|||||||
|
|
||||||
Process* current = 0;
|
Process* current = 0;
|
||||||
Process* queue = 0;
|
Process* queue = 0;
|
||||||
Process* zombie_list = 0;
|
|
||||||
|
|
||||||
uint32_t irq_disable_counter = 0;
|
uint32_t irq_disable_counter = 0;
|
||||||
uint32_t pid_counter;
|
uint32_t pid_counter;
|
||||||
uint32_t task_count;
|
uint32_t task_count;
|
||||||
|
|
||||||
#define KSTACKSIZE 4096
|
#define KSTACKSIZE 4096
|
||||||
#define USTACKSIZE 4096
|
|
||||||
|
|
||||||
extern void trapret(void);
|
extern void trapret(void);
|
||||||
extern void switchProcess(Process* next);
|
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)
|
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->eflags = FL_IF;
|
||||||
p->tf->eip = (uint32_t)func;
|
p->tf->eip = (uint32_t)func;
|
||||||
|
|
||||||
p->pagedir = pagedir;//(uint32_t*)create_page_dir();
|
p->pagedir = pagedir;
|
||||||
|
|
||||||
if(ring == 3)
|
if(ring == 3)
|
||||||
{
|
{
|
||||||
/*void* user_stack_physical = alloc_page();
|
p->tf->usermode_esp = user_esp;
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,7 +78,6 @@ Process* task_create(uint32_t func, uint32_t user_esp, uint32_t ring, uint32_t*
|
|||||||
curr = curr->next;
|
curr = curr->next;
|
||||||
curr->next = p;
|
curr->next = p;
|
||||||
}
|
}
|
||||||
task_count++;
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,8 +149,6 @@ void task2()
|
|||||||
while (1) { a++; printf("task2 %X\n", a); }
|
while (1) { a++; printf("task2 %X\n", a); }
|
||||||
}
|
}
|
||||||
|
|
||||||
void jump_usermode2(void) ;
|
|
||||||
|
|
||||||
void scheduler_init()
|
void scheduler_init()
|
||||||
{
|
{
|
||||||
uint32_t* kernel_tasks_pagedir = (uint32_t*)create_page_dir();
|
uint32_t* kernel_tasks_pagedir = (uint32_t*)create_page_dir();
|
||||||
@@ -174,7 +157,7 @@ void scheduler_init()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void task_kill(Process* proc) {
|
void task_kill(Process* proc) {
|
||||||
//that proc != current is sus
|
//TODO: that proc != current is sus
|
||||||
if (!proc || proc != current) return;
|
if (!proc || proc != current) return;
|
||||||
|
|
||||||
scheduler_lock();
|
scheduler_lock();
|
||||||
|
|||||||
Reference in New Issue
Block a user