Hello, after some days of deeply working with thread blocking and unblocking issue, I finally solved the problem. Now I can block any thread, and unblock any thread. Blocking a thread move it to block list, unblocking a thread move from block list to ready list with state modification. My problem was with kernel_esp {Kernel Stack per user thread}. When a system call occurs with "syscall" instruction the kernel stack is loaded, which was pointing to some invalid address. So I modified that, now the kernel stack is loaded directly from current_thread() structure like this,
Code:
mov rdx, rsp ; store the user stack in rdx
mov r9, [rel current_thread] ;current_thread is an external global variable pointing to currently running thread
mov rsp, [r9 + 0xC8] ;already we stored current_thread address in r9, now from r9 we get kernel stack at 0xC8
; ....do syscall stuff and restore the stack and return from here
This is, how I fixed.
And my scheduling_isr code is
Code:
//! Simple round robin scheduler for now!!
if (store_context(current_thread) == 0) {
current_thread->cr3 = get_pml4();
if (current_thread->privl == USER_THREAD)
current_thread->kernel_stack = get_kernel_tss()->rsp[0];
//! before moving to next we send EOI to interrupt controller
apic_local_eoi ();
//! call the scheduler thread switcher
next_thread ();
//! now current thread points to the next thread
if (current_thread->privl == USER_THREAD)
get_kernel_tss()->rsp[0] = current_thread->kernel_stack;
set_pml4 (current_thread->cr3);
//! finally execute the thread context from here
execute_context (current_thread);
}
Thank you so much to everyone, for your replies...Now I can happily go for the Composite Window Manager and other GUI applications.
Manas Kamal