From 6709aa9de5dc2a5d18ea27fac678ac27a2cfa8f9 Mon Sep 17 00:00:00 2001 From: antifallobst Date: Tue, 2 May 2023 21:19:23 +0200 Subject: [PATCH] feature (threads): added default end point for thread execution --- src/proc/scheduler.c | 4 ---- src/proc/thread.c | 9 +++++++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/proc/scheduler.c b/src/proc/scheduler.c index b85751e..aa3de50 100644 --- a/src/proc/scheduler.c +++ b/src/proc/scheduler.c @@ -111,7 +111,6 @@ thread_T* scheduler_register_thread(thread_T* thread) { thread->process->num_threads++; g_scheduler.num_threads++; - log(LOG_INFO, " Registered thread"); scheduler_update_info(); return thread; @@ -119,13 +118,11 @@ thread_T* scheduler_register_thread(thread_T* thread) { void scheduler_pause_thread(thread_T* thread) { scheduler_queue_remove_thread(thread); - log(LOG_INFO, " Paused thread"); scheduler_update_info(); } void scheduler_start_thread(thread_T* thread) { scheduler_queue_add_thread(thread); - log(LOG_INFO, " Started thread"); scheduler_update_info(); } @@ -147,7 +144,6 @@ void scheduler_kill_thread(thread_T* thread) { thread->process->num_threads--; g_scheduler.num_threads--; - log(LOG_INFO, " Killed thread"); scheduler_update_info(); } diff --git a/src/proc/thread.c b/src/proc/thread.c index 3e4591b..c42eb18 100644 --- a/src/proc/thread.c +++ b/src/proc/thread.c @@ -9,6 +9,11 @@ #include "utils/memory.h" #include "utils/logger.h" +void thread_end_point() { + // this has to kill the thread in future + while (1) asm("hlt"); +} + thread_T* thread_spawn(pid_t process, void* function) { thread_T* thread = memory_allocate(sizeof(thread_T)); @@ -29,8 +34,6 @@ thread_T* thread_spawn(pid_t process, void* function) { uint8_t* base = (uint8_t*)((process == PROCESS_KERNEL ? MEM_REGION_KERNEL_THREAD_BASE : MEM_REGION_PROCESS_THREAD_BASE) + (MEM_REGION_THREAD_OFFSET * thread->local_id)); - log(LOG_DEBUG, "spawning thread with base address: 0x%x", base); - thread->cpu_time = 0; thread->stack_size = PFRAME_SIZE * 4; @@ -41,6 +44,8 @@ thread_T* thread_spawn(pid_t process, void* function) { page_map_map_memory(g_kernel_page_map, MEM_REGION_KERNEL_STACK_DUMMY + i * PFRAME_SIZE, physical_address, PM_FLAG_READ_WRITE); } + *((uint64_t*)(MEM_REGION_KERNEL_STACK_DUMMY + (thread->stack_size - sizeof(cpu_state_T) - 8))) = (uint64_t)thread_end_point; + cpu_state_T state = { .cr3 = (uint64_t)thread->process->page_map, .rax = 0,