From ce16fe524c14ccaae67fb634105da5aef08ead48 Mon Sep 17 00:00:00 2001 From: Miguel Date: Thu, 4 Oct 2018 00:53:30 +0200 Subject: moving framebuffer access completely to userspace --- kernel/scheduler.c | 151 +++++++++++++++++++++++++++-------------------------- 1 file changed, 77 insertions(+), 74 deletions(-) (limited to 'kernel/scheduler.c') diff --git a/kernel/scheduler.c b/kernel/scheduler.c index a4e3743..9fdff7d 100644 --- a/kernel/scheduler.c +++ b/kernel/scheduler.c @@ -74,10 +74,10 @@ volatile void scheduler_init(uint32_t cpu, void *dir) } current_task[cpu]=0; - last_task[cpu]=0; +// last_task[cpu]=0; // need to make space on the esp stacks for pushing vals vias task_pusha - + // this is our main kernel task at slot 0 (per cpu) task_list[cpu][0].parent=0; task_list[cpu][0].pid=nextPID(); @@ -85,10 +85,10 @@ volatile void scheduler_init(uint32_t cpu, void *dir) task_list[cpu][0].syscall=false; task_list[cpu][0].thread=false; task_list[cpu][0].vmem=dir; - task_list[cpu][0].esp = VMEM_CPU_STACK_TOP-0x200-8; - task_list[cpu][0].esp0 = 0; // esp0 not needed by kernel space tasks - strcpy(task_list[cpu][0].name,"kernel_worker"); - fd_init_std_streams(task_list[cpu][0].pid,0); + task_list[cpu][0].esp = kballoc(4)+4*4096-0x200-8; // 4 pages stack & prealign + task_list[cpu][0].esp0 = 0; // esp0 not required by kernel space tasks + strcpy(task_list[cpu][0].name,"kernel worker"); + //fd_init_std_streams(task_list[cpu][0].pid,0); // this will go to userspace task_list[cpu][1].parent=0; @@ -97,11 +97,11 @@ volatile void scheduler_init(uint32_t cpu, void *dir) task_list[cpu][1].thread=false; task_list[cpu][1].syscall=false; task_list[cpu][1].vmem=dir; - task_list[cpu][1].esp = kballoc(4)+4*4096-0x200-8; // 4 pages stack & prealign - task_list[cpu][1].esp0 =kballoc(4)+4*4096; // esp0 not needed by kernel space tasks - strcpy(task_list[cpu][1].name,"init"); - fd_init_std_streams(task_list[cpu][1].pid,0); - + task_list[cpu][1].esp = kballoc(4)+4*4096-0x200-8; // 4 pages stack & prealign + task_list[cpu][1].esp = VMEM_USER_STACK_TOP-0x200-8; + task_list[cpu][1].esp0 = kballoc(4)+4*4096; // esp0 needed by user space tasks + strcpy(task_list[cpu][1].name,"userspace init"); + //fd_init_std_streams(task_list[cpu][1].pid,0); // sleeper task_list[cpu][2].parent=0; @@ -111,9 +111,9 @@ volatile void scheduler_init(uint32_t cpu, void *dir) task_list[cpu][2].syscall=false; task_list[cpu][2].vmem=dir; task_list[cpu][2].esp = kballoc(4)+4*4096-0x200-8; // 4 pages stack & prealign - task_list[cpu][2].esp0 =kballoc(4)+4*4096; // esp0 not needed by kernel space tasks + task_list[cpu][2].esp0 =0; // esp0 not needed by kernel space tasks strcpy(task_list[cpu][2].name,"idle process"); - fd_init_std_streams(task_list[cpu][2].pid,0); + //fd_init_std_streams(task_list[cpu][2].pid,0); // stacks task_pusha(task_list[cpu][0].esp); @@ -128,8 +128,8 @@ static uint32_t scheduler_schedule(uint32_t idx) if(task_list[cpu][idx].active && !task_list[cpu][idx].syscall) { - if(current_task[cpu]!=0)last_task[cpu]=current_task[cpu]; - if(current_task[cpu]==idx)return task_list[cpu][idx].esp; + //if(current_task[cpu]!=0)last_task[cpu]=current_task[cpu]; + //if(current_task[cpu]==idx)return task_list[cpu][idx].esp; current_task[cpu]=idx; @@ -162,49 +162,26 @@ volatile uint32_t scheduler_run(uint32_t oldesp,uint32_t preference) uint32_t cpu=smp_get(SMP_APIC_ID); uint32_t init=smp_get(SMP_SCHEDULER_INIT); - if(init){ + if(init) + { scheduler_init(cpu,x86_get_page_directory()); smp_set(SMP_SCHEDULER_INIT,0); + klog("Scheduler initialized for cpu %d",cpu); + return task_list[cpu][current_task[cpu]].esp; } - else task_list[cpu][current_task[cpu]].esp=oldesp; - uint32_t esp; - - if(preference!=-1) - { - esp=scheduler_schedule(preference); // try preference - if(esp)return esp; - - if(current_task[cpu]==0)// we have interrupted a task with ring1 work - { - esp=scheduler_schedule(last_task[cpu]); // try preference - if(esp)return esp; - } - } - else - { - //klog("preempt %d", last_task[cpu]); - } - for(int i=0;i