amd64: entry: rework timer_handler

Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
Michael Shaw 2026-07-27 20:35:20 -04:00
commit be49cc4839
2 changed files with 27 additions and 14 deletions

View file

@ -99,11 +99,31 @@ irq_common:
add rsp, 8
iretq
.global sched_save_state
sched_save_state:
.global _timer_handler
_timer_handler:
test qword ptr [rsp + 8], 3
jz 1f
swapgs
1:
sub rsp, 8 /* reserve return address slot */
push_all
mov [rdi + 8], rsp /* save RSP to thread->kstack_ptr */
ret
lea rax, [rip + 2f]
mov [rsp + 120], rax /* return address */
mov rdi, gs:[0] /* cur_thread */
mov [rdi + 8], rsp /* cur_thread->kstack_ptr */
call sched_add_thread
call lapic_eoi
call schedule
2:
/* after reschedule */
test qword ptr [rsp + 8], 3
jz 3f
swapgs
3:
iretq
.global sched_restore_state
sched_restore_state:

View file

@ -72,15 +72,6 @@ uint8_t lapic_idno()
return lapic_read(lapic_addr, LAPIC_ID) >> 24;
}
static void timer_handler()
{
struct thread *cur = get_cur_thread();
sched_save_state(cur);
sched_add_thread(cur);
lapic_eoi();
schedule();
}
static void ipi_handle_kill()
{
schedule();
@ -126,7 +117,9 @@ void apic_init()
/* Register timer interrupt handler and enable APIC timer */
extern int irq_map(uint8_t irq, void *func);
irq_map(0, timer_handler);
void _timer_handler();
irq_map(0, _timer_handler);
lapic_write(lapic_addr, LAPIC_TPR, 0);
lapic_write(lapic_addr, LAPIC_TIMER_DIV, 0x3);