amd64: entry: rework timer_handler
Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
parent
a5c0597830
commit
be49cc4839
2 changed files with 27 additions and 14 deletions
|
|
@ -99,11 +99,31 @@ irq_common:
|
||||||
add rsp, 8
|
add rsp, 8
|
||||||
iretq
|
iretq
|
||||||
|
|
||||||
.global sched_save_state
|
.global _timer_handler
|
||||||
sched_save_state:
|
_timer_handler:
|
||||||
|
test qword ptr [rsp + 8], 3
|
||||||
|
jz 1f
|
||||||
|
swapgs
|
||||||
|
1:
|
||||||
|
sub rsp, 8 /* reserve return address slot */
|
||||||
push_all
|
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
|
.global sched_restore_state
|
||||||
sched_restore_state:
|
sched_restore_state:
|
||||||
|
|
|
||||||
|
|
@ -72,15 +72,6 @@ uint8_t lapic_idno()
|
||||||
return lapic_read(lapic_addr, LAPIC_ID) >> 24;
|
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()
|
static void ipi_handle_kill()
|
||||||
{
|
{
|
||||||
schedule();
|
schedule();
|
||||||
|
|
@ -126,7 +117,9 @@ void apic_init()
|
||||||
|
|
||||||
/* Register timer interrupt handler and enable APIC timer */
|
/* Register timer interrupt handler and enable APIC timer */
|
||||||
extern int irq_map(uint8_t irq, void *func);
|
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_TPR, 0);
|
||||||
lapic_write(lapic_addr, LAPIC_TIMER_DIV, 0x3);
|
lapic_write(lapic_addr, LAPIC_TIMER_DIV, 0x3);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue