NOVA
Stripped down NOVA kernel for the OSY course
Loading...
Searching...
No Matches
lapic.h
1/*
2 * Local Advanced Programmable Interrupt Controller (Local APIC)
3 *
4 * Copyright (C) 2009-2011 Udo Steinberg <udo@hypervisor.org>
5 * Economic rights: Technische Universitaet Dresden (Germany)
6 *
7 * This file is part of the NOVA microhypervisor.
8 *
9 * NOVA is free software: you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 *
13 * NOVA is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License version 2 for more details.
17 */
18
19#pragma once
20
21#include "apic.h"
22#include "compiler.h"
23//#include "config.h"
24#include "memory.h"
25#include "types.h"
26
27class Lapic : public Apic
28{
29 private:
30 enum Register
31 {
32 LAPIC_IDR = 0x2,
33 LAPIC_LVR = 0x3,
34 LAPIC_TPR = 0x8,
35 LAPIC_PPR = 0xa,
36 LAPIC_EOI = 0xb,
37 LAPIC_LDR = 0xd,
38 LAPIC_DFR = 0xe,
39 LAPIC_SVR = 0xf,
40 LAPIC_ISR = 0x10,
41 LAPIC_TMR = 0x18,
42 LAPIC_IRR = 0x20,
43 LAPIC_ESR = 0x28,
44 LAPIC_ICR_LO = 0x30,
45 LAPIC_ICR_HI = 0x31,
46 LAPIC_LVT_TIMER = 0x32,
47 LAPIC_LVT_THERM = 0x33,
48 LAPIC_LVT_PERFM = 0x34,
49 LAPIC_LVT_LINT0 = 0x35,
50 LAPIC_LVT_LINT1 = 0x36,
51 LAPIC_LVT_ERROR = 0x37,
52 LAPIC_TMR_ICR = 0x38,
53 LAPIC_TMR_CCR = 0x39,
54 LAPIC_TMR_DCR = 0x3e,
55 LAPIC_IPI_SELF = 0x3f,
56 };
57
58 ALWAYS_INLINE
59 static inline uint32 read (Register reg)
60 {
61 return *reinterpret_cast<uint32 volatile *>(LAPIC_ADDR + (reg << 4));
62 }
63
64 ALWAYS_INLINE
65 static inline void write (Register reg, uint32 val)
66 {
67 *reinterpret_cast<uint32 volatile *>(LAPIC_ADDR + (reg << 4)) = val;
68 }
69
70 ALWAYS_INLINE
71 static inline void set_lvt (Register reg, unsigned vector, Delivery_mode dlv, Mask msk = UNMASKED)
72 {
73 write (reg, msk | dlv | vector);
74 }
75
76 ALWAYS_INLINE
77 static inline void timer_handler();
78
79 ALWAYS_INLINE
80 static inline void error_handler();
81
82 ALWAYS_INLINE
83 static inline void perfm_handler();
84
85 ALWAYS_INLINE
86 static inline void therm_handler();
87
88 public:
89 static unsigned freq_tsc;
90 static unsigned freq_bus;
91
92 ALWAYS_INLINE
93 static inline unsigned id()
94 {
95 return read (LAPIC_IDR) >> 24 & 0xff;
96 }
97
98 ALWAYS_INLINE
99 static inline unsigned version()
100 {
101 return read (LAPIC_LVR) & 0xff;
102 }
103
104 ALWAYS_INLINE
105 static inline unsigned lvt_max()
106 {
107 return read (LAPIC_LVR) >> 16 & 0xff;
108 }
109
110 ALWAYS_INLINE
111 static inline void eoi()
112 {
113 write (LAPIC_EOI, 0);
114 }
115
116 ALWAYS_INLINE
117 static inline void set_timer (unsigned val)
118 {
119 write (LAPIC_TMR_ICR, val);
120 }
121
122 ALWAYS_INLINE
123 static inline unsigned get_timer()
124 {
125 return read (LAPIC_TMR_CCR);
126 }
127
128 static void init();
129 static void calibrate();
130
131 REGPARM (1)
132 static void lvt_vector (unsigned) asm ("lvt_vector");
133};
Definition apic.h:22
Definition lapic.h:28