8#include <sys/kassert.h>
11#include <machine/amd64.h>
12#include <machine/amd64op.h>
13#include <machine/pmap.h>
14#include <machine/trap.h>
16#define CPUID_FLAG_APIC 0x100
18#define IA32_APIC_BASE_MSR 0x1B
19#define IA32_APIC_BASE_MSR_BSP 0x100
20#define IA32_APIC_BASE_MSR_ENABLE 0x800
22#define LAPIC_ID 0x0020
23#define LAPIC_VERSION 0x0030
24#define LAPIC_VERSION_LVTMASK 0x00FF0000
25#define LAPIC_VERSION_LVTSHIFT 0x10
26#define LAPIC_TPR 0x0080
27#define LAPIC_EOI 0x00B0
28#define LAPIC_SIV 0x00F0
29#define LAPIC_SIV_ENABLE 0x100
31#define LAPIC_ESR 0x0280
32#define LAPIC_LVT_CMCI 0x02F0
34#define LAPIC_ICR_LO 0x0300
35#define LAPIC_ICR_HI 0x0310
36#define LAPIC_ICR_FIXED 0x0000
37#define LAPIC_ICR_NMI 0x0400
38#define LAPIC_ICR_INIT 0x0500
39#define LAPIC_ICR_STARTUP 0x0600
40#define LAPIC_ICR_ASSERT 0x4000
41#define LAPIC_ICR_TRIG 0x8000
42#define LAPIC_ICR_SELF 0x00080000
43#define LAPIC_ICR_INCSELF 0x00080000
44#define LAPIC_ICR_EXCSELF 0x000C0000
45#define LAPIC_ICR_DELIVERY_PENDING 0x1000
47#define LAPIC_LVT_TIMER 0x0320
48#define LAPIC_LVT_TIMER_ONESHOT 0x00000000
49#define LAPIC_LVT_TIMER_PERIODIC 0x00020000
50#define LAPIC_LVT_TIMER_TSCDEADLINE 0x00040000
51#define LAPIC_LVT_THERMAL 0x0330
52#define LAPIC_LVT_PMCR 0x0340
53#define LAPIC_LVT_LINT0 0x0350
54#define LAPIC_LVT_LINT1 0x0360
55#define LAPIC_LVT_ERROR 0x0370
56#define LAPIC_LVT_FLAG_MASKED 0x00010000
57#define LAPIC_LVT_FLAG_NMI 0x00000400
58#define LAPIC_LVT_FLAG_EXTINT 0x00000700
60#define LAPIC_TICR 0x0380
61#define LAPIC_TCCR 0x0390
62#define LAPIC_TDCR 0x03E0
63#define LAPIC_TDCR_X1 0x000B
80 return lapic[reg >> 2];
88 lapic[reg >> 2] = val;
123 cmosStartup[1] =
addr >> 4;
152 kprintf(
"IPI not delivered?\n");
170 kprintf(
"IPI not delivered?\n");
188 Panic(
"APIC is required!\n");
static INLINE uint64_t rdmsr(uint32_t addr)
static INLINE void outb(uint16_t port, uint8_t data)
static INLINE void wrmsr(uint32_t addr, uint64_t val)
static INLINE void pause()
static INLINE void cpuid(uint32_t info, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)
int kprintf(const char *fmt,...)
#define REGISTER_DBGCMD(_NAME, _DESC, _FUNC)
#define LAPIC_ICR_EXCSELF
#define LAPIC_LVT_THERMAL
#define LAPIC_VERSION_LVTMASK
#define LAPIC_ICR_STARTUP
#define LAPIC_LVT_FLAG_MASKED
int LAPIC_BroadcastNMI(int vector)
int LAPIC_Broadcast(int vector)
static void Debug_LAPIC(int argc, const char *argv[])
#define LAPIC_ICR_DELIVERY_PENDING
#define IA32_APIC_BASE_MSR
#define LAPIC_VERSION_LVTSHIFT
void LAPIC_Periodic(uint64_t rate)
uint32_t LAPIC_Read(uint16_t reg)
#define LAPIC_LVT_FLAG_NMI
static uint32_t * LAPIC_GetBase()
#define LAPIC_LVT_FLAG_EXTINT
#define LAPIC_LVT_TIMER_PERIODIC
void LAPIC_Write(uint16_t reg, uint32_t val)
#define IA32_APIC_BASE_MSR_ENABLE
#define LAPIC_ICR_INCSELF
void LAPIC_StartAP(uint8_t apicid, uint32_t addr)
void Panic(const char *str)