OpenCores
URL https://opencores.org/ocsvn/ao486/ao486/trunk

Subversion Repositories ao486

[/] [ao486/] [trunk/] [bochs486/] [cpu/] [apic.h] - Blame information for rev 7

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 alfik
/////////////////////////////////////////////////////////////////////////
2
// $Id: apic.h 11404 2012-09-06 15:21:08Z sshwarts $
3
/////////////////////////////////////////////////////////////////////////
4
//
5
//  Copyright (c) 2002-2012 Zwane Mwaikambo, Stanislav Shwartsman
6
//
7
//  This library is free software; you can redistribute it and/or
8
//  modify it under the terms of the GNU Lesser General Public
9
//  License as published by the Free Software Foundation; either
10
//  version 2 of the License, or (at your option) any later version.
11
//
12
//  This library is distributed in the hope that it will be useful,
13
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
//  Lesser General Public License for more details.
16
//
17
//  You should have received a copy of the GNU Lesser General Public
18
//  License along with this library; if not, write to the Free Software
19
//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20
//
21
/////////////////////////////////////////////////////////////////////////
22
 
23
#ifndef BX_CPU_APIC_H
24
#define BX_CPU_APIC_H 1
25
 
26
#if BX_SUPPORT_APIC
27
 
28
#define APIC_LEVEL_TRIGGERED    1
29
#define APIC_EDGE_TRIGGERED     0
30
 
31
#define BX_LAPIC_BASE_ADDR  0xfee00000  // default Local APIC address
32
#define BX_NUM_LOCAL_APICS  BX_SMP_PROCESSORS
33
#define BX_LAPIC_MAX_INTS   256
34
 
35
#define BX_APIC_GLOBALLY_DISABLED 0
36
#define BX_APIC_STATE_INVALID     1
37
#define BX_APIC_XAPIC_MODE        2
38
#define BX_APIC_X2APIC_MODE       3
39
 
40
#define BX_XAPIC_EXT_SUPPORT_IER  (1 << 0)
41
#define BX_XAPIC_EXT_SUPPORT_SEOI (1 << 1)
42
 
43
typedef Bit32u apic_dest_t; /* same definition in ioapic.h */
44
 
45
// local apic registers
46
 
47
#define BX_LAPIC_ID                   0x020
48
#define BX_LAPIC_VERSION              0x030
49
#define BX_LAPIC_TPR                  0x080
50
#define BX_LAPIC_ARBITRATION_PRIORITY 0x090
51
#define BX_LAPIC_PPR                  0x0A0
52
#define BX_LAPIC_EOI                  0x0B0
53
#define BX_LAPIC_RRD                  0x0C0
54
#define BX_LAPIC_LDR                  0x0D0
55
#define BX_LAPIC_DESTINATION_FORMAT   0x0E0
56
#define BX_LAPIC_SPURIOUS_VECTOR      0x0F0
57
#define BX_LAPIC_ISR1                 0x100
58
#define BX_LAPIC_ISR2                 0x110
59
#define BX_LAPIC_ISR3                 0x120
60
#define BX_LAPIC_ISR4                 0x130
61
#define BX_LAPIC_ISR5                 0x140
62
#define BX_LAPIC_ISR6                 0x150
63
#define BX_LAPIC_ISR7                 0x160
64
#define BX_LAPIC_ISR8                 0x170
65
#define BX_LAPIC_TMR1                 0x180
66
#define BX_LAPIC_TMR2                 0x190
67
#define BX_LAPIC_TMR3                 0x1A0
68
#define BX_LAPIC_TMR4                 0x1B0
69
#define BX_LAPIC_TMR5                 0x1C0
70
#define BX_LAPIC_TMR6                 0x1D0
71
#define BX_LAPIC_TMR7                 0x1E0
72
#define BX_LAPIC_TMR8                 0x1F0
73
#define BX_LAPIC_IRR1                 0x200
74
#define BX_LAPIC_IRR2                 0x210
75
#define BX_LAPIC_IRR3                 0x220
76
#define BX_LAPIC_IRR4                 0x230
77
#define BX_LAPIC_IRR5                 0x240
78
#define BX_LAPIC_IRR6                 0x250
79
#define BX_LAPIC_IRR7                 0x260
80
#define BX_LAPIC_IRR8                 0x270
81
#define BX_LAPIC_ESR                  0x280
82
#define BX_LAPIC_LVT_CMCI             0x2F0
83
#define BX_LAPIC_ICR_LO               0x300
84
#define BX_LAPIC_ICR_HI               0x310
85
#define BX_LAPIC_LVT_TIMER            0x320
86
#define BX_LAPIC_LVT_THERMAL          0x330
87
#define BX_LAPIC_LVT_PERFMON          0x340
88
#define BX_LAPIC_LVT_LINT0            0x350
89
#define BX_LAPIC_LVT_LINT1            0x360
90
#define BX_LAPIC_LVT_ERROR            0x370
91
#define BX_LAPIC_TIMER_INITIAL_COUNT  0x380
92
#define BX_LAPIC_TIMER_CURRENT_COUNT  0x390
93
#define BX_LAPIC_TIMER_DIVIDE_CFG     0x3E0
94
#define BX_LAPIC_SELF_IPI             0x3F0
95
 
96
// extended AMD 
97
#define BX_LAPIC_EXT_APIC_FEATURE     0x400
98
#define BX_LAPIC_EXT_APIC_CONTROL     0x410
99
#define BX_LAPIC_SPECIFIC_EOI         0x420
100
#define BX_LAPIC_IER1                 0x480
101
#define BX_LAPIC_IER2                 0x490
102
#define BX_LAPIC_IER3                 0x4A0
103
#define BX_LAPIC_IER4                 0x4B0
104
#define BX_LAPIC_IER5                 0x4C0
105
#define BX_LAPIC_IER6                 0x4D0
106
#define BX_LAPIC_IER7                 0x4E0
107
#define BX_LAPIC_IER8                 0x4F0
108
 
109
class BOCHSAPI bx_local_apic_c : public logfunctions
110
{
111
  bx_phy_address base_addr;
112
  unsigned mode;
113
  bx_bool xapic;
114
#if BX_CPU_LEVEL >= 6
115
  Bit32u xapic_ext;             // enabled extended XAPIC features
116
#endif
117
  Bit32u apic_id;               //  4 bit in legacy mode, 8 bit in XAPIC mode
118
                                // 32 bit in X2APIC mode
119
  Bit32u apic_version_id;
120
 
121
  bx_bool software_enabled;
122
  Bit8u  spurious_vector;
123
  bx_bool focus_disable;
124
 
125
  Bit32u task_priority;         // Task priority (TPR)
126
  Bit32u ldr;                   // Logical destination (LDR)
127
  Bit32u dest_format;           // Destination format (DFR)
128
 
129
  // ISR=in-service register. When an IRR bit is cleared, the corresponding
130
  // bit in ISR is set.
131
  Bit8u isr[BX_LAPIC_MAX_INTS];
132
  // TMR=trigger mode register.  Cleared for edge-triggered interrupts
133
  // and set for level-triggered interrupts. If set, local APIC must send
134
  // EOI message to all other APICs.
135
  Bit8u tmr[BX_LAPIC_MAX_INTS];
136
  // IRR=interrupt request register. When an interrupt is triggered by
137
  // the I/O APIC or another processor, it sets a bit in irr. The bit is
138
  // cleared when the interrupt is acknowledged by the processor.
139
  Bit8u irr[BX_LAPIC_MAX_INTS];
140
#if BX_CPU_LEVEL >= 6
141
  // IER=interrupt enable register. Only vectors that are enabled in IER
142
  // participare in APIC's computation of highest priority pending interrupt.
143
  Bit8u ier[BX_LAPIC_MAX_INTS];
144
#endif
145
 
146
#define APIC_ERR_ILLEGAL_ADDR    0x80
147
#define APIC_ERR_RX_ILLEGAL_VEC  0x40
148
#define APIC_ERR_TX_ILLEGAL_VEC  0x20
149
#define X2APIC_ERR_REDIRECTIBLE_IPI 0x08
150
#define APIC_ERR_RX_ACCEPT_ERR   0x08
151
#define APIC_ERR_TX_ACCEPT_ERR   0x04
152
#define APIC_ERR_RX_CHECKSUM     0x02
153
#define APIC_ERR_TX_CHECKSUM     0x01
154
 
155
  // Error status Register (ESR)
156
  Bit32u error_status, shadow_error_status;
157
 
158
  Bit32u icr_hi;                // Interrupt command register (ICR)
159
  Bit32u icr_lo;
160
 
161
#define APIC_LVT_ENTRIES 6
162
  Bit32u lvt[APIC_LVT_ENTRIES];
163
#define APIC_LVT_TIMER   0
164
#define APIC_LVT_THERMAL 1
165
#define APIC_LVT_PERFMON 2
166
#define APIC_LVT_LINT0   3
167
#define APIC_LVT_LINT1   4
168
#define APIC_LVT_ERROR   5
169
 
170
  Bit32u timer_initial;         // Initial timer count (in order to reload periodic timer)
171
  Bit32u timer_current;         // Current timer count
172
  Bit64u ticksInitial;          // Timer value when it started to count, also holds TSC-Deadline value
173
 
174
  Bit32u timer_divconf;         // Timer divide configuration register
175
  Bit32u timer_divide_factor;
176
 
177
  // Internal timer state, not accessible from bus
178
  bx_bool timer_active;
179
  int timer_handle;
180
 
181
/* APIC delivery modes */
182
#define APIC_DM_FIXED   0
183
#define APIC_DM_LOWPRI  1
184
#define APIC_DM_SMI     2
185
/* RESERVED             3 */
186
#define APIC_DM_NMI     4
187
#define APIC_DM_INIT    5
188
#define APIC_DM_SIPI    6
189
#define APIC_DM_EXTINT  7
190
 
191
#if BX_SUPPORT_VMX >= 2
192
  int vmx_timer_handle;
193
  Bit32u vmx_preemption_timer_value;
194
  Bit64u vmx_preemption_timer_initial;    //The value of system tick when set the timer (absolute value)
195
  Bit64u vmx_preemption_timer_fire;       //The value of system tick when fire the exception (absolute value)
196
  Bit32u vmx_preemption_timer_rate;       //rate stated in MSR_VMX_MISC
197
  bx_bool vmx_timer_active;
198
#endif 
199
 
200
  BX_CPU_C *cpu;
201
 
202
public:
203
  bx_bool INTR;
204
  bx_local_apic_c(BX_CPU_C *cpu, unsigned id);
205
 ~bx_local_apic_c() { }
206
  void reset(unsigned type);
207
  bx_phy_address get_base(void) const { return base_addr; }
208
  void set_base(bx_phy_address newbase);
209
  Bit32u get_id() const { return apic_id; }
210
  bx_bool is_xapic() const { return xapic; }
211
  bx_bool is_selected(bx_phy_address addr);
212
  void read(bx_phy_address addr, void *data, unsigned len);
213
  void write(bx_phy_address addr, void *data, unsigned len);
214
  void write_aligned(bx_phy_address addr, Bit32u data);
215
  Bit32u read_aligned(bx_phy_address address);
216
#if BX_CPU_LEVEL >= 6
217
  bx_bool read_x2apic(unsigned index, Bit64u *msr);
218
  bx_bool write_x2apic(unsigned index, Bit32u msr_hi, Bit32u msr_lo);
219
#endif
220
  // on local APIC, trigger means raise the CPU's INTR line. For now
221
  // I also have to raise pc_system.INTR but that should be replaced
222
  // with the cpu-specific INTR signals.
223
  void trigger_irq(Bit8u vector, unsigned trigger_mode, bx_bool bypass_irr_isr = 0);
224
  void untrigger_irq(Bit8u vector, unsigned trigger_mode);
225
  Bit8u acknowledge_int(void);  // only the local CPU should call this
226
  int highest_priority_int(Bit8u *array);
227
  void receive_EOI(Bit32u value);
228
  void send_ipi(apic_dest_t dest, Bit32u lo_cmd);
229
  void write_spurious_interrupt_register(Bit32u value);
230
  void service_local_apic(void);
231
  void print_status(void);
232
  bx_bool match_logical_addr(apic_dest_t address);
233
  bx_bool deliver(Bit8u vector, Bit8u delivery_mode, Bit8u trig_mode);
234
  Bit8u get_tpr(void) { return task_priority; }
235
  void  set_tpr(Bit8u tpr);
236
  Bit8u get_ppr(void);
237
  Bit8u get_apr(void);
238
  bx_bool is_focus(Bit8u vector);
239
  void set_lvt_entry(unsigned apic_reg, Bit32u val);
240
 
241
  static void periodic_smf(void *);
242
  void periodic(void);
243
  void set_divide_configuration(Bit32u value);
244
  void set_initial_timer_count(Bit32u value);
245
  Bit32u get_current_timer_count(void);
246
 
247
#if BX_CPU_LEVEL >= 6
248
  Bit64u get_tsc_deadline(void);
249
  void set_tsc_deadline(Bit64u value);
250
  void receive_SEOI(Bit8u vec);
251
  void enable_xapic_extensions(void);
252
#endif
253
 
254
  void startup_msg(Bit8u vector);
255
  void register_state(bx_param_c *parent);
256
#if BX_SUPPORT_VMX >= 2
257
  Bit32u read_vmx_preemption_timer(void);
258
  void set_vmx_preemption_timer(Bit32u value);
259
  void deactivate_vmx_preemption_timer(void);
260
  static void vmx_preemption_timer_expired(void *);
261
#endif  
262
};
263
 
264
int apic_bus_deliver_lowest_priority(Bit8u vector, apic_dest_t dest, bx_bool trig_mode, bx_bool broadcast);
265
BOCHSAPI_MSVCONLY int apic_bus_deliver_interrupt(Bit8u vector, apic_dest_t dest, Bit8u delivery_mode, bx_bool logical_dest, bx_bool level, bx_bool trig_mode);
266
int apic_bus_broadcast_interrupt(Bit8u vector, Bit8u delivery_mode, bx_bool trig_mode, int exclude_cpu);
267
 
268
#endif // if BX_SUPPORT_APIC
269
 
270
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.