Move kernel stacks into common memory and fix tasking.
This commit is contained in:
parent
997927fea4
commit
8bdbe06b8c
@ -8,6 +8,7 @@
|
||||
|
||||
static uint32_t page_directory[1024] __attribute__((aligned(4096)));
|
||||
static uint32_t kern_page_tables[NUM_KERN_DIRS*1024] __attribute__((aligned(4096)));
|
||||
static uint32_t kstack_page_tables[32*1024] __attribute__((aligned(4096)));
|
||||
static uint32_t kmalloc_page_tables[1024] __attribute__((aligned(4096)));
|
||||
static uint32_t smap_page_tables[2048] __attribute__((aligned(4096)));
|
||||
static uint32_t* smap=(uint32_t*)0xFF800000;
|
||||
@ -44,6 +45,12 @@ void map_pages(void* virt_addr_ptr,void* phys_addr_ptr,int num_pages,char usr,ch
|
||||
}
|
||||
}
|
||||
|
||||
void map_kstack(uint32_t pid) {
|
||||
if (kstack_page_tables[pid]==NULL) {
|
||||
kstack_page_tables[pid]=(uint32_t)pmem_alloc(1)|0x3;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t find_free_pages(int num_pages) {
|
||||
uint32_t bmap_index;
|
||||
uint32_t remaining_blks;
|
||||
@ -129,6 +136,10 @@ void* paging_new_address_space() {
|
||||
uint32_t entry_virt=(uint32_t)&(kern_page_tables[i*1024]);
|
||||
smap[i+768]=(entry_virt-0xC0000000)|0x3;
|
||||
}
|
||||
for (uint32_t i=0;i<32;i++) {
|
||||
uint32_t entry_virt=(uint32_t)&(kstack_page_tables[i*1024]);
|
||||
smap[i+989]=(entry_virt-0xC0000000)|0x3;
|
||||
}
|
||||
smap[1021]=(((uint32_t)kmalloc_page_tables)-0xC0000000)|0x3;
|
||||
for (uint32_t i=0;i<2;i++) {
|
||||
uint32_t entry_virt=(uint32_t)&(smap_page_tables[i*1024]);
|
||||
@ -175,6 +186,9 @@ void paging_init() {
|
||||
for (uint32_t i=0;i<NUM_KERN_DIRS*1024;i++) {
|
||||
kern_page_tables[i]=(i<<12)|0x3;
|
||||
}
|
||||
for (uint32_t i=0;i<32*1024;i++) {
|
||||
kstack_page_tables[i]=0;
|
||||
}
|
||||
for (uint32_t i=0;i<1024;i++) {
|
||||
kmalloc_page_tables[i]=(uint32_t)pmem_alloc(1)|0x3;
|
||||
}
|
||||
@ -186,6 +200,10 @@ void paging_init() {
|
||||
uint32_t entry_virt=(uint32_t)&(kern_page_tables[i*1024]);
|
||||
page_directory[i+768]=(entry_virt-0xC0000000)|0x3;
|
||||
}
|
||||
for (uint32_t i=0;i<32;i++) {
|
||||
uint32_t entry_virt=(uint32_t)&(kstack_page_tables[i*1024]);
|
||||
page_directory[i+989]=(entry_virt-0xC0000000)|0x3;
|
||||
}
|
||||
page_directory[1021]=(((uint32_t)kmalloc_page_tables)-0xC0000000)|0x3;
|
||||
for (uint32_t i=0;i<2;i++) {
|
||||
uint32_t entry_virt=(uint32_t)&(smap_page_tables[i*1024]);
|
||||
|
@ -7,6 +7,7 @@
|
||||
#define NUM_KERN_DIRS 1
|
||||
|
||||
void map_pages(void* virt_addr_ptr,void* phys_addr_ptr,int num_pages,char usr,char wr);
|
||||
void map_kstack(uint32_t pid);
|
||||
void unmap_pages(void* start_virt,uint32_t num_pages);
|
||||
void* alloc_pages(int num_pages);
|
||||
void alloc_pages_virt(int num_pages,void* addr);
|
||||
|
@ -13,7 +13,7 @@
|
||||
#define STACK_PAGES 2
|
||||
|
||||
extern void task_init();
|
||||
static uint32_t* kstacks=(uint32_t*)0xF7400000;
|
||||
static uint32_t* kstacks=(char*)0xF7400000;
|
||||
|
||||
|
||||
uint32_t next_pid;
|
||||
@ -31,6 +31,7 @@ void tasking_init(void* esp) {
|
||||
|
||||
Task* tasking_createTaskCr3KmodeParam(void* eip,void* cr3,char kmode,char param1_exists,uint32_t param1_arg,char param2_exists,uint32_t param2_arg) {
|
||||
Task* task=kmalloc(sizeof(Task));
|
||||
map_kstack(next_pid);
|
||||
uint32_t param1;
|
||||
if (param1_exists) {
|
||||
param1=param1_arg;
|
||||
@ -47,30 +48,30 @@ Task* tasking_createTaskCr3KmodeParam(void* eip,void* cr3,char kmode,char param1
|
||||
uint32_t old_cr3;
|
||||
asm volatile("movl %%cr3, %%eax; movl %%eax, %0;":"=m"(old_cr3)::"%eax");
|
||||
load_address_space(task->cr3);
|
||||
task->kernel_esp=(((uint32_t)alloc_pages(1))+0xfff);
|
||||
task->kernel_esp_top=task->kernel_esp;
|
||||
if (kmode) {
|
||||
task->kernel_esp-=5*4;
|
||||
uint32_t* stack_top_val=(uint32_t*)task->kernel_esp;
|
||||
stack_top_val[0]=0;
|
||||
stack_top_val[1]=0;
|
||||
stack_top_val[2]=0;
|
||||
stack_top_val[3]=0;
|
||||
stack_top_val[4]=eip;
|
||||
uint32_t top_idx=(1024*(next_pid+1));
|
||||
task->kernel_esp=((uint32_t)(&kstacks[top_idx-5]));
|
||||
task->kernel_esp_top=task->kernel_esp;
|
||||
kstacks[top_idx-5]=0;
|
||||
kstacks[top_idx-4]=0;
|
||||
kstacks[top_idx-3]=0;
|
||||
kstacks[top_idx-2]=0;
|
||||
kstacks[top_idx-1]=eip;
|
||||
} else {
|
||||
task->kernel_esp-=7*4;
|
||||
uint32_t* stack_top_val=(uint32_t*)task->kernel_esp;
|
||||
stack_top_val[0]=0;
|
||||
stack_top_val[1]=0;
|
||||
stack_top_val[2]=0;
|
||||
stack_top_val[3]=0;
|
||||
stack_top_val[4]=task_init;
|
||||
uint32_t* user_stack=(((uint32_t)alloc_pages(1))+0xfff);
|
||||
user_stack-=4*2;
|
||||
uint32_t top_idx=(1024*(next_pid+1));
|
||||
task->kernel_esp=((uint32_t)(&kstacks[top_idx-7]));
|
||||
task->kernel_esp_top=task->kernel_esp;
|
||||
kstacks[top_idx-7]=0;
|
||||
kstacks[top_idx-6]=0;
|
||||
kstacks[top_idx-5]=0;
|
||||
kstacks[top_idx-4]=0;
|
||||
kstacks[top_idx-3]=task_init;
|
||||
uint32_t* user_stack=(((uint32_t)alloc_pages(1))+0x1000);
|
||||
user_stack-=2;
|
||||
user_stack[0]=param1;
|
||||
user_stack[1]=param2;
|
||||
stack_top_val[5]=user_stack;
|
||||
stack_top_val[6]=eip;
|
||||
kstacks[top_idx-2]=user_stack;
|
||||
kstacks[top_idx-1]=eip;
|
||||
}
|
||||
load_address_space(old_cr3);
|
||||
task->next=NULL;
|
||||
@ -91,6 +92,7 @@ Task* tasking_createTaskCr3KmodeParam(void* eip,void* cr3,char kmode,char param1
|
||||
currentTask->next=task;
|
||||
}
|
||||
return task;
|
||||
|
||||
}
|
||||
|
||||
int* tasking_get_errno_address() {
|
||||
|
Loading…
Reference in New Issue
Block a user