Skip to content

Commit

Permalink
Fix prepare_virtual_memory_environment bug
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamos82 committed Aug 31, 2023
1 parent 19075db commit d8f8f9a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
11 changes: 7 additions & 4 deletions src/kernel/scheduling/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ task_t* create_task(char *name, void (*_entry_point)(void *), void *args) {
}

void prepare_virtual_memory_environment(task_t* task) {
loglinef(Verbose, "(prepare_virtual_memory_environment) Placeholder for virtual_memory");
// Steps:
// 1. Prepare resources: allocatin an array of VM_PAGES_PER_TABLE
// Make sure this address is physical, then it needs to be mapped to a virtual one.a
Expand All @@ -50,10 +49,14 @@ void prepare_virtual_memory_environment(task_t* task) {
// 2. We will map the whole higher half of the kernel, this means from pml4 item 256 to 511
// ((uint64_t *)task->vm_root_page_table)[0] = p4_table[0];
for(int i = 255; i < VM_PAGES_PER_TABLE; i++) {
((uint64_t *)vm_root_vaddress)[i] = p4_table[i];
if(p4_table[i] != 0) {
if ( i == 510 ) {
((uint64_t *)vm_root_vaddress)[i] = (uint64_t) (task->vm_root_page_table) | VMM_FLAGS_PRESENT | VMM_FLAGS_WRITE_ENABLE;
loglinef(Verbose, "(%s): Mapping recursive entry: 0x%x", __FUNCTION__, ((uint64_t *)vm_root_vaddress)[i]);
} else {
((uint64_t *)vm_root_vaddress)[i] = p4_table[i];
}
if (p4_table[i] != 0) {
loglinef(Verbose, "(prepare_virtual_memory_environment): %d: o:0x%x - c:0x%x - t:0x%x", i, p4_table[i], kernel_settings.paging.page_root_address[i], ((uint64_t*)vm_root_vaddress)[i]);

}
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/kernel/scheduling/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ thread_t* create_thread(char* thread_name, void (*_entry_point)(void *), void* a

if (parent_task != NULL) {
add_thread_to_task(parent_task, new_thread);
} else {
loglinef(Fatal, "(%s): Cannot create thread without parent task");
}

scheduler_add_thread(new_thread);
Expand Down Expand Up @@ -144,7 +146,9 @@ void noop3(char *c) {
loglinef(Verbose, "(noop3): test_addr[0] = %d", test_addr[0]);
task_t *current_task = current_executing_thread->parent_task;
uint64_t *tmp_var = vmm_alloc(0x1000, VMM_FLAGS_PRESENT | VMM_FLAGS_WRITE_ENABLE, &(current_task->vmm_data));
loglinef(Verbose, "(%s) Tmp var address returned by vmm_alloc: 0x%x", __FUNCTION__, tmp_var);
loglinef(Verbose, "(%s) task name: %s - Tmp var address returned by vmm_alloc: 0x%x", __FUNCTION__, current_task->task_name, tmp_var);
tmp_var[0] = 0x1234;
loglinef(Verbose, "(%s) Tmp var address returned by vmm_alloc: 0x%x==0x1234 ", __FUNCTION__, tmp_var[0]);
}

char *get_thread_status(thread_t *thread) {
Expand Down

0 comments on commit d8f8f9a

Please sign in to comment.