Skip to content

Commit

Permalink
Changes requested
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamos82 committed Dec 1, 2023
1 parent 4ff77ca commit 5e75873
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 22 deletions.
2 changes: 1 addition & 1 deletion docs/kernel/Initialization.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Loading the kernel

The kernel is loaded by grub2, using the multibtoo2 specifications.
The kernel is loaded by grub2, using the multiboot2 specifications.

The tags that are enabled at boot are:

Expand Down
4 changes: 3 additions & 1 deletion src/include/kernel/mem/vmm.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ typedef enum {
VMM_FLAGS_PRESENT = (1 << 0),
VMM_FLAGS_WRITE_ENABLE = (1 << 1),
VMM_FLAGS_USER_LEVEL = (1 << 2),
VMM_FLAGS_ADDRESS_ONLY = (1 << 7)
VMM_FLAGS_ADDRESS_ONLY = (1 << 7),
VMM_FLAGS_STACK = (1 << 8)
} paging_flags_t;

typedef enum {
Expand Down Expand Up @@ -86,6 +87,7 @@ uint8_t check_virt_address_status(uint64_t virtual_address);
void vmm_direct_map_physical_memory();

bool is_address_only(size_t flags);
bool is_address_stack(size_t flags);

void *vmm_get_variable_from_direct_map ( size_t phys_address );

Expand Down
2 changes: 0 additions & 2 deletions src/kernel/arch/x86_64/cpu/tss.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,5 @@ void load_tss() {
gdt64[TSS_ENTRY_HIGH] = entry_high;
loglinef(Verbose, "(%s) Loading TSS Register", __FUNCTION__);
loglinef(Verbose, "(%s) kernel_tss address = 0x%x", __FUNCTION__, &kernel_tss);
loglinef(Verbose, "(%s) gdt64[4] = 0x%x", __FUNCTION__, (uint64_t)gdt64[TSS_ENTRY_LOW]);
loglinef(Verbose, "(%s) gdt64[5] = 0x%x", __FUNCTION__, (uint64_t)gdt64[TSS_ENTRY_HIGH]);
_load_task_register();
}
16 changes: 3 additions & 13 deletions src/kernel/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,35 +189,25 @@ void kernel_start(unsigned long addr, unsigned long magic){
loglinef(Verbose, "(kernel_main) (END of Mapped memory: 0x%x)", end_of_mapped_memory);
vfs_init();
uint64_t unix_timestamp = read_rtc_time();

#if USE_FRAMEBUFFER == 1
_fb_printStrAndNumber("Epoch time: ", unix_timestamp, 0, 5, 0xf5c4f1, 0x000000);
#endif
init_scheduler();
char a = 'a';
char b = 'b';
char c = 'c';
char d = 'd';
task_t* idle_task = create_task("idle", noop, &a, true);
idle_thread = idle_task->threads;
//task_t* eldi_task = create_task("eldi", noop2, &b);
task_t* userspace_task = create_task("userspace_idle", NULL, &b, false);
task_t* userspace_task = create_task("userspace_idle", NULL, &a, false);
//create_thread("ledi", noop2, &c, eldi_task);
//create_task("sleeper", noop3, &d);
//print_thread_list(eldi_task->task_id);
//execute_runtime_tests();
start_apic_timer(kernel_settings.apic_timer.timer_ticks_base, APIC_TIMER_SET_PERIODIC, kernel_settings.apic_timer.timer_divisor);
loglinef(Verbose, "(kernel_main) (END of Mapped memory: 0x%x)", end_of_mapped_memory);
loglinef(Verbose, "(kernel_main) init_basic_system: Memory lower (in kb): %d - upper (in kb): %d", tagmem->mem_lower, tagmem->mem_upper);
// Testing that the hhdm is actually working
struct multiboot_tag_basic_meminfo *virt_phys_addr = (struct multiboot_tag_basic_meminfo *) hhdm_get_variable( (size_t) multiboot_basic_meminfo );
loglinef(Verbose, "(kernel_main) init_basic_system: Memory lower (in kb): %d - upper (in kb): %d", virt_phys_addr->mem_lower, virt_phys_addr->mem_upper);
logline(Info, "(kernel_main) Init end!! Starting infinite loop");
//prepare_userspace_function();
//uint64_t* vm_root_vaddress = (uint64_t *) vmm_alloc(PAGE_SIZE_IN_BYTES, VMM_FLAGS_ADDRESS_ONLY, NULL);
//void* temp_var = pmm_alloc_frame();
//map_phys_to_virt_addr_hh(temp_var, (void *) vm_root_vaddress, VMM_FLAGS_PRESENT | VMM_FLAGS_WRITE_ENABLE, NULL);
//vm_root_vaddress[0] = 5;
//loglinef(Verbose, "(%s): vm_root_vaddress value: 0x%x", __FUNCTION__, vm_root_vaddress[0]);
//map_phys_to_hh();

while(1);
}
15 changes: 14 additions & 1 deletion src/kernel/mem/vmm.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <logging.h>
#include <main.h>
#include <pmm.h>
#include <thread.h>
#include <video.h>
#include <vm.h>
#include <vmm.h>
Expand Down Expand Up @@ -157,11 +158,23 @@ void *vmm_alloc(size_t size, size_t flags, VmmInfo *vmm_info) {
loglinef(Verbose, "(vmm_alloc) newly allocated item base: %x, next available address: %x", vmm_info->status.vmm_cur_container->vmm_root[vmm_info->status.vmm_cur_index].base, vmm_info->status.next_available_address);
vmm_info->status.vmm_cur_index++;

if ( is_address_stack(flags) ) {
loglinef(Verbose, "(%s): The address will be a stack", __FUNCTION__);
return (void *) address_to_return + THREAD_DEFAULT_STACK_SIZE;
}

return (void *) address_to_return;
}

bool is_address_only(size_t flags) {
if(flags & VMM_FLAGS_ADDRESS_ONLY) {
if ( flags & VMM_FLAGS_ADDRESS_ONLY ) {
return true;
}
return false;
}

bool is_address_stack(size_t flags) {
if ( flags & VMM_FLAGS_STACK ) {
return true;
}
return false;
Expand Down
4 changes: 2 additions & 2 deletions src/kernel/scheduling/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ thread_t* create_thread(char* thread_name, void (*_entry_point)(void *), void* a
}
// We need to allocate a new stack for each thread
//void* stack_pointer = kmalloc(THREAD_DEFAULT_STACK_SIZE);
void* stack_pointer = vmm_alloc(THREAD_DEFAULT_STACK_SIZE, VMM_FLAGS_PRESENT | VMM_FLAGS_WRITE_ENABLE, &(parent_task->vmm_data));
void* stack_pointer = vmm_alloc(THREAD_DEFAULT_STACK_SIZE, VMM_FLAGS_PRESENT | VMM_FLAGS_WRITE_ENABLE | VMM_FLAGS_STACK, &(parent_task->vmm_data));
if (stack_pointer == NULL) {
loglinef(Fatal, "(create_thread): rsp is null - PANIC!");
while(1);
}

// The stack grow backward, so the pointer will be the end of the stack
new_thread->stack = (uintptr_t)stack_pointer + THREAD_DEFAULT_STACK_SIZE;
new_thread->stack = (uintptr_t)stack_pointer;
new_thread->execution_frame->rsp = (uint64_t) new_thread->stack;
new_thread->execution_frame->rbp = 0;
loglinef(Verbose, "(%s): thread: %s stack address returned: 0x%x", __FUNCTION__, new_thread->thread_name, new_thread->execution_frame->rsp);
Expand Down
2 changes: 0 additions & 2 deletions src/userpsace/test_userspace.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,5 @@ uint64_t prepare_userspace_function(VmmInfo *vmm_info) {
code_page[1] = infinite_loop[1];
char *user_code_page = vmm_alloc(PAGE_SIZE_IN_BYTES, VMM_FLAGS_ADDRESS_ONLY | VMM_FLAGS_WRITE_ENABLE | VMM_FLAGS_PRESENT | VMM_FLAGS_USER_LEVEL, vmm_info);
map_phys_to_virt_addr_hh(temp_var, (void *) user_code_page,VMM_FLAGS_USER_LEVEL | VMM_FLAGS_PRESENT | VMM_FLAGS_WRITE_ENABLE, (uint64_t *) vmm_info->root_table_hhdm);
//loglinef(Verbose, "(%s): user_code_page[0]: 0x%x - user_code_page[1]: 0x%x", __FUNCTION__, user_code_page[0], user_code_page[1]);
loglinef(Verbose, "(%s): leaving prparing userspace function", __FUNCTION__);
return (uint64_t) user_code_page;
}

0 comments on commit 5e75873

Please sign in to comment.