Add new threads to runnable threads list

More safely handle nested interrupts.
Switch to newly created thread immediately.
This commit is contained in:
josh committed 2023-12-08 12:16:35 -05:00
1 parent 44a305721e
commit 9874802ee4
4 files changed
+73 -20

No files matched your search

+18 -3
View File
@@ -236,6 +236,7 @@ struct Him
mov %rsp, %rbp
mov %rsp, %rsi
and $$0xFFFFFFFFFFFFFFF0, %rsp
mov %rsp, %rdx
mov %rax, %rdi
movabs $$isr, %rax
callq *%rax
@@ -273,10 +274,13 @@ struct Him
* This function returns the stack pointer of the thread to execute when
* returning from this function.
*/
public extern(C) ulong * isr(ulong vector, ulong * stack_frame)
public extern(C) ulong * isr(ulong vector, ulong * stack_frame, ulong * rsp)
{
interrupt_level++;
Thread.current_thread.stack_pointer = stack_frame;
if (interrupt_level == 1)
{
Thread.current_thread.stack_pointer = stack_frame;
}
if ((vector >= INT_APIC_BASE) && (vector < (INT_APIC_BASE + INT_APIC_COUNT)))
{
Apic.isr(vector);
@@ -292,6 +296,10 @@ public extern(C) ulong * isr(ulong vector, ulong * stack_frame)
Apic.isr(vector);
break;
case INT_KERNEL_SWINT:
Thread.handle_swint(stack_frame);
break;
default:
Fb.rect(0, 0, Fb.width, Kfont.line_height, 0xCC0000u);
Klog.writefln("\n **** Unhandled ISR %u ****", vector);
@@ -310,5 +318,12 @@ public extern(C) ulong * isr(ulong vector, ulong * stack_frame)
}
Thread.current_thread = Thread.current_thread.list_next;
interrupt_level--;
return Thread.current_thread.stack_pointer;
if (interrupt_level == 0)
{
return Thread.current_thread.stack_pointer;
}
else
{
return rsp;
}
}