Kernel stack setup is now platform-dependent
This commit is contained in:
parent
ace6b4397d
commit
ea574dbf23
@ -5,7 +5,6 @@
|
||||
#define FRAME_SZ PAGE_SZ
|
||||
#define KMALLOC_START 0xFE800000
|
||||
#define KMALLOC_SZ 16384
|
||||
#define KSTACKS_START 0xC8000000
|
||||
#define NUM_FRAMES 1024*1024
|
||||
#define FRAME_NO_OFFSET 12
|
||||
#define NUM_KERN_FRAMES 4096
|
||||
|
@ -5,7 +5,6 @@
|
||||
#define FRAME_SZ PAGE_SZ
|
||||
#define KMALLOC_START 0xFE800000
|
||||
#define KMALLOC_SZ 16384
|
||||
#define KSTACKS_START 0xC8000000
|
||||
#define NUM_FRAMES 1024*1024
|
||||
#define FRAME_NO_OFFSET 12
|
||||
#define NUM_KERN_FRAMES 4096
|
||||
|
31
kernel/cpu/i386/tasking_helpers_c.c
Normal file
31
kernel/cpu/i386/tasking_helpers_c.c
Normal file
@ -0,0 +1,31 @@
|
||||
#include "../../tasking.h"
|
||||
#include "../paging.h"
|
||||
#include "../tasking_helpers.h"
|
||||
|
||||
static uint32_t* kstacks=(uint32_t*)0xC8000000;
|
||||
|
||||
void setup_kstack(Thread* thread,uint32_t param1,uint32_t param2,char kmode,void* eip) {
|
||||
void* old_cr3=get_cr3();
|
||||
uint32_t kstack_num=new_kstack();
|
||||
load_address_space(thread->cr3);
|
||||
if (kmode) {
|
||||
uint32_t top_idx=(1024*(kstack_num+1));
|
||||
thread->kernel_esp=((uint32_t)(&kstacks[top_idx-5]));
|
||||
thread->kernel_esp_top=thread->kernel_esp;
|
||||
kstacks[top_idx-1]=(uint32_t)eip;
|
||||
} else {
|
||||
uint32_t top_idx=(1024*(kstack_num+1));
|
||||
thread->kernel_esp=((uint32_t)(&kstacks[top_idx-7]));
|
||||
thread->kernel_esp_top=thread->kernel_esp;
|
||||
kstacks[top_idx-3]=(uint32_t)task_init;
|
||||
uint32_t* user_stack=(uint32_t*)(((uint32_t)alloc_pages(2))+0x2000);
|
||||
int buffer_pg_num=(((uint32_t)user_stack)-0x2000)>>12;
|
||||
make_protector(buffer_pg_num);
|
||||
user_stack-=2;
|
||||
user_stack[0]=param1;
|
||||
user_stack[1]=param2;
|
||||
kstacks[top_idx-2]=(uint32_t)user_stack;
|
||||
kstacks[top_idx-1]=(uint32_t)eip;
|
||||
}
|
||||
load_address_space(old_cr3);
|
||||
}
|
@ -6,5 +6,6 @@
|
||||
void switch_to_thread_asm(Thread* thread);
|
||||
void task_init();
|
||||
void wait_for_unblocked_thread_asm();
|
||||
void setup_kstack(Thread* thread,uint32_t param1,uint32_t param2,char kmode,void* eip);
|
||||
|
||||
#endif
|
||||
|
@ -18,7 +18,6 @@ char proc_schedule_bmap[MAX_PROCS/8];
|
||||
Thread* currentThread;
|
||||
static Thread* readyToRunHead=NULL;
|
||||
static Thread* readyToRunTail=NULL;
|
||||
static uint32_t* kstacks=(uint32_t*)KSTACKS_START;
|
||||
|
||||
static char is_proc_scheduled(uint32_t index) {
|
||||
uint32_t byte=index/8;
|
||||
@ -90,29 +89,7 @@ void tasking_createTask(void* eip,void* cr3,char kmode,char param1_exists,uint32
|
||||
thread->errno=0;
|
||||
thread->tid=proc->next_tid;
|
||||
proc->next_tid++;
|
||||
void* old_cr3=get_cr3();
|
||||
uint32_t kstack_num=new_kstack();
|
||||
load_address_space(thread->cr3);
|
||||
if (kmode) {
|
||||
uint32_t top_idx=(1024*(kstack_num+1));
|
||||
thread->kernel_esp=((uint32_t)(&kstacks[top_idx-5]));
|
||||
thread->kernel_esp_top=thread->kernel_esp;
|
||||
kstacks[top_idx-1]=(uint32_t)eip;
|
||||
} else {
|
||||
uint32_t top_idx=(1024*(kstack_num+1));
|
||||
thread->kernel_esp=((uint32_t)(&kstacks[top_idx-7]));
|
||||
thread->kernel_esp_top=thread->kernel_esp;
|
||||
kstacks[top_idx-3]=(uint32_t)task_init;
|
||||
uint32_t* user_stack=(uint32_t*)(((uint32_t)alloc_pages(2))+0x2000);
|
||||
int buffer_pg_num=(((uint32_t)user_stack)-0x2000)>>12;
|
||||
make_protector(buffer_pg_num);
|
||||
user_stack-=2;
|
||||
user_stack[0]=param1;
|
||||
user_stack[1]=param2;
|
||||
kstacks[top_idx-2]=(uint32_t)user_stack;
|
||||
kstacks[top_idx-1]=(uint32_t)eip;
|
||||
}
|
||||
load_address_space(old_cr3);
|
||||
setup_kstack(thread,param1,param2,kmode,eip);
|
||||
thread->prevReadyToRun=NULL;
|
||||
thread->nextReadyToRun=NULL;
|
||||
if (isThread) {
|
||||
|
Loading…
Reference in New Issue
Block a user