mirror of
https://github.com/usatiuk/ficus.git
synced 2025-10-29 00:27:52 +01:00
pretty up task switching a bit
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
|
||||
add_executable(kernel.elf)
|
||||
|
||||
target_compile_options(kernel.elf PUBLIC $<$<COMPILE_LANGUAGE:CXX>:-fstack-protector-all>)
|
||||
target_compile_options(kernel.elf PUBLIC $<$<COMPILE_LANGUAGE:C>:-fstack-protector-all>)
|
||||
target_compile_options(kernel.elf PUBLIC $<$<COMPILE_LANGUAGE:CXX>:-fstack-protector-all -Ofast -mno-sse>)
|
||||
target_compile_options(kernel.elf PUBLIC $<$<COMPILE_LANGUAGE:C>:-fstack-protector-all -Ofast -mno-sse>)
|
||||
|
||||
add_subdirectory(./arch/)
|
||||
add_subdirectory(./kernel/)
|
||||
|
||||
@@ -76,17 +76,12 @@ global pic1_irq_0
|
||||
pic1_irq_0:
|
||||
pushaq
|
||||
|
||||
mov rdi, 0xdeadbe3fdeadb3ef ; IDT_GUARD
|
||||
push rdi ; IDT_GUARD
|
||||
|
||||
; pass the "pointer" to the stack as pointer to the interrupt_frame argument,
|
||||
; the stack and the struct must match!
|
||||
mov rdi, rsp
|
||||
|
||||
call pic1_irq_real_0
|
||||
|
||||
add rsp, 8 ; remove IDT_GUARD
|
||||
|
||||
popaq
|
||||
iretq
|
||||
|
||||
|
||||
@@ -165,11 +165,7 @@ uint16_t pic_get_isr(void) {
|
||||
|
||||
extern "C" void pic1_irq_real_0(struct task_frame *frame) {
|
||||
timer_tick();
|
||||
assert2(frame->guard == IDT_GUARD, "IDT Guard wrong!");
|
||||
assert2((frame->ss == GDTSEL(gdt_data) || frame->ss == GDTSEL(gdt_data_user)), "SS wrong!");
|
||||
switch_task_int(frame);
|
||||
assert2(frame->guard == IDT_GUARD, "IDT Guard wrong!");
|
||||
assert2((frame->ss == GDTSEL(gdt_data) || frame->ss == GDTSEL(gdt_data_user)), "SS wrong!");
|
||||
switch_task(frame);
|
||||
PIC_sendEOI(0);
|
||||
}
|
||||
extern "C" void pic1_irq_real_1() {
|
||||
|
||||
@@ -26,17 +26,16 @@ _yield_self_kern:
|
||||
pushf ; eflags
|
||||
PUSH r11; Push code segment
|
||||
push rsi ; instruction address to return to
|
||||
pushaq
|
||||
|
||||
mov rdi, 0xdeadbe3fdeadb3ef ; IDT_GUARD
|
||||
push rdi ; IDT_GUARD
|
||||
|
||||
pushaq
|
||||
|
||||
; pass the "pointer" to the stack as pointer to the interrupt_frame argument,
|
||||
; the stack and the struct must match!
|
||||
mov rdi, rsp
|
||||
|
||||
call switch_task
|
||||
add rsp, 8 ; remove IDT_GUARD
|
||||
|
||||
popaq
|
||||
iretq
|
||||
.end:
|
||||
|
||||
@@ -226,9 +226,25 @@ void yield_self() {
|
||||
|
||||
|
||||
extern "C" void switch_task(struct task_frame *cur_frame) {
|
||||
assert2(!are_interrupts_enabled(), "Switching tasks with enabled interrupts!");
|
||||
if (!atomic_load(&initialized)) return;
|
||||
sanity_check_frame(cur_frame);
|
||||
|
||||
struct TaskListNode *node = WaitingTasks.cur;
|
||||
|
||||
while (node) {
|
||||
if (node->task->sleep_until <= micros && node->task->state == TS_TO_SLEEP) {
|
||||
assert2(node->task->sleep_until, "Sleeping until 0?");
|
||||
node->task->sleep_until = 0;
|
||||
node->task->state = TS_RUNNING;
|
||||
append_task_node(&NextTasks, pop_front_node(&WaitingTasks));
|
||||
node = WaitingTasks.cur;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
assert2(!are_interrupts_enabled(), "Switching tasks with enabled interrupts!");
|
||||
|
||||
if (RunningTask) {
|
||||
@@ -303,25 +319,6 @@ extern "C" void switch_task(struct task_frame *cur_frame) {
|
||||
sanity_check_frame(cur_frame);
|
||||
}
|
||||
|
||||
void switch_task_int(struct task_frame *cur_frame) {
|
||||
assert2(!are_interrupts_enabled(), "Switching tasks with enabled interrupts!");
|
||||
struct TaskListNode *node = WaitingTasks.cur;
|
||||
|
||||
while (node) {
|
||||
if (node->task->sleep_until <= micros && node->task->state == TS_TO_SLEEP) {
|
||||
assert2(node->task->sleep_until, "Sleeping until 0?");
|
||||
node->task->sleep_until = 0;
|
||||
node->task->state = TS_RUNNING;
|
||||
append_task_node(&NextTasks, pop_front_node(&WaitingTasks));
|
||||
node = WaitingTasks.cur;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch_task(cur_frame);
|
||||
}
|
||||
|
||||
void wait_m_on_self(struct Mutex *m) {
|
||||
if (!m->waiters) {
|
||||
m->waiters = static_cast<TaskList *>(kmalloc(sizeof(struct TaskList)));
|
||||
|
||||
@@ -43,7 +43,6 @@ struct Task *new_ktask(void (*fn)(), const char *name);
|
||||
void remove_self();
|
||||
void sleep_self(uint64_t diff);
|
||||
extern "C" void switch_task(struct task_frame *cur_frame);
|
||||
void switch_task_int(struct task_frame *cur_frame);
|
||||
void wait_m_on_self(struct Mutex *m);
|
||||
void m_unlock_sched_hook(struct Mutex *m);
|
||||
void wait_cv_on_self(struct CV *cv);
|
||||
|
||||
@@ -36,8 +36,12 @@
|
||||
|
||||
fxsave64 [rsi]
|
||||
|
||||
mov rdi, 0xdeadbe3fdeadb3ef ; IDT_GUARD
|
||||
push rdi ; IDT_GUARD
|
||||
|
||||
%endmacro
|
||||
%macro popaq 0
|
||||
add rsp, 8 ; remove IDT_GUARD
|
||||
|
||||
; Ensure 16-byte alignment
|
||||
; This works as last bunch of bits in fxsave state aren't used
|
||||
|
||||
Reference in New Issue
Block a user