kernel: Use a common kidle thread that always calls switch_next

This commit is contained in:
K. Lange 2024-01-22 07:29:34 +09:00
parent 231f708c62
commit 4c9f9a68e0
2 changed files with 4 additions and 16 deletions

View File

@ -66,11 +66,9 @@ int pit_interrupt(struct regs *r) {
irq_ack(0); irq_ack(0);
if (r->cs == 0x08) return 1;
switch_task(1); switch_task(1);
asm volatile (
".global _ret_from_preempt_source\n"
"_ret_from_preempt_source:"
);
return 1; return 1;
} }

View File

@ -156,8 +156,6 @@ void switch_next(void) {
__builtin_unreachable(); __builtin_unreachable();
} }
extern void * _ret_from_preempt_source;
/** /**
* @brief Yield the processor to the next available task. * @brief Yield the processor to the next available task.
* *
@ -173,7 +171,7 @@ void switch_task(uint8_t reschedule) {
/* switch_task() called but the scheduler isn't enabled? Resume... this is probably a bug. */ /* switch_task() called but the scheduler isn't enabled? Resume... this is probably a bug. */
if (!this_core->current_process) return; if (!this_core->current_process) return;
if (this_core->current_process == this_core->kernel_idle_task && __builtin_return_address(0) != &_ret_from_preempt_source) { if (this_core->current_process == this_core->kernel_idle_task) {
arch_fatal_prepare(); arch_fatal_prepare();
printf("Context switch from kernel_idle_task triggered from somewhere other than pre-emption source. Halting.\n"); printf("Context switch from kernel_idle_task triggered from somewhere other than pre-emption source. Halting.\n");
printf("This generally means that a driver responding to interrupts has attempted to yield in its interrupt context.\n"); printf("This generally means that a driver responding to interrupts has attempted to yield in its interrupt context.\n");
@ -316,15 +314,7 @@ pid_t get_next_pid(void) {
static void _kidle(void) { static void _kidle(void) {
while (1) { while (1) {
arch_pause(); arch_pause();
}
}
static void _kburn(void) {
while (1) {
arch_pause();
#ifndef __aarch64__
switch_next(); switch_next();
#endif
} }
} }
@ -361,7 +351,7 @@ process_t * spawn_kidle(int bsp) {
MMU_FLAG_KERNEL); MMU_FLAG_KERNEL);
/* TODO arch_initialize_context(uintptr_t) ? */ /* TODO arch_initialize_context(uintptr_t) ? */
idle->thread.context.ip = bsp ? (uintptr_t)&_kidle : (uintptr_t)&_kburn; idle->thread.context.ip = (uintptr_t)&_kidle;
idle->thread.context.sp = idle->image.stack; idle->thread.context.sp = idle->image.stack;
idle->thread.context.bp = idle->image.stack; idle->thread.context.bp = idle->image.stack;