amd64: add support for IPIs
Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
parent
dda38aa265
commit
a5c0597830
3 changed files with 30 additions and 2 deletions
|
|
@ -12,14 +12,13 @@
|
|||
#define GDT_SEGMENT_DATA_RING0 0x30
|
||||
#define GDT_SEGMENT_CODE_RING3 0x38
|
||||
#define GDT_SEGMENT_DATA_RING3 0x40
|
||||
#define GDT_SEGMENT_TSS 0x48
|
||||
#define GDT_SEGMENT_TSS 0x48
|
||||
|
||||
#define GATE_INTR 0x8E
|
||||
#define GATE_TRAP 0x8F
|
||||
|
||||
#define GATE_INTR_DPL3 0xEE
|
||||
|
||||
|
||||
#include <kernel/common.h>
|
||||
|
||||
struct cpu_local;
|
||||
|
|
@ -90,6 +89,7 @@ extern struct irq_desc __idt[64];
|
|||
|
||||
void gdt_init();
|
||||
void idt_init();
|
||||
void idt_insert(uint16_t gate, uint8_t type, uint8_t ist, uint16_t segment, void *func);
|
||||
void tss_init(int cpu_id, struct cpu_local *local);
|
||||
|
||||
#endif /* _DESCRIPTOR_H_ */
|
||||
|
|
|
|||
|
|
@ -81,6 +81,27 @@ static void timer_handler()
|
|||
schedule();
|
||||
}
|
||||
|
||||
static void ipi_handle_kill()
|
||||
{
|
||||
schedule();
|
||||
lapic_eoi();
|
||||
}
|
||||
|
||||
static void ipi_handle_tlb_flush()
|
||||
{
|
||||
tlb_flush();
|
||||
lapic_eoi();
|
||||
}
|
||||
|
||||
void lapic_send_ipi(u32 lapic_id, u8 vector)
|
||||
{
|
||||
/* check for current IPI */
|
||||
while (lapic_read(lapic_addr, LAPIC_ICR) & (1 << 12))
|
||||
;
|
||||
lapic_write(lapic_addr, LAPIC_ICR + 0x10, lapic_id << 24);
|
||||
lapic_write(lapic_addr, LAPIC_ICR, vector | (1 << 14));
|
||||
}
|
||||
|
||||
void apic_init()
|
||||
{
|
||||
ioapic_addr += hhdm_start;
|
||||
|
|
@ -112,6 +133,9 @@ void apic_init()
|
|||
lapic_write(lapic_addr, LAPIC_TIMER_INIT_COUNT, 0xFFFF0);
|
||||
lapic_write(lapic_addr, LAPIC_TIMER, 0x20 | 0x20000);
|
||||
|
||||
idt_insert(IPI_KILL, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, ipi_handle_kill);
|
||||
idt_insert(IPI_TLB_FLUSH, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, ipi_handle_tlb_flush);
|
||||
|
||||
krdy("APIC initialized\n");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,9 @@
|
|||
#include <kernel/common.h>
|
||||
#include <kernel/types.h>
|
||||
|
||||
#define IPI_KILL 0x30
|
||||
#define IPI_TLB_FLUSH 0x31
|
||||
|
||||
struct thread;
|
||||
struct cpu_local {
|
||||
struct thread *cur_thread;
|
||||
|
|
@ -14,6 +17,7 @@ struct cpu_local {
|
|||
u32 cpu_id;
|
||||
vaddr_t irq_rsp;
|
||||
struct tss tss;
|
||||
u32 apic_id;
|
||||
} PACKED;
|
||||
|
||||
struct pt_regs {
|
||||
|
|
|
|||
Loading…
Reference in a new issue