Skip to content

Commit 27938c3

Browse files
JasonChenCJwenlingz
authored andcommitted
move idt fixup out of cpu_primary.S
we will not enable interrupt until interrupt_init, so we can defer idt fixup and lidt to interrupt_init. Tracked-On: #1842 Signed-off-by: Jason Chen CJ <jason.cj.chen@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent 6b42b34 commit 27938c3

File tree

2 files changed

+19
-26
lines changed

2 files changed

+19
-26
lines changed

hypervisor/arch/x86/boot/cpu_primary.S

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -163,31 +163,6 @@ after:
163163
mov %eax,%fs // Was 32bit POC Data
164164
mov %eax,%gs // Was 32bit POC CLS
165165

166-
/*
167-
* Fix up the IDT desciptors
168-
* The relocation delta in IDT tables has been fixed in relocate()
169-
*/
170-
movl %eax, %edx
171-
leal HOST_IDT(%rip), %edx
172-
movl $HOST_IDT_ENTRIES, %ecx
173-
174-
.fixup_idt_entries:
175-
xorl %eax, %eax
176-
xchgl %eax, 12(%edx) /* Set rsvd bits to 0; eax now has
177-
high 32 of entry point */
178-
xchgl %eax, 8(%edx) /* Set bits 63..32 of entry point;
179-
eax now has low 32 of entry point */
180-
movw %ax, (%edx) /* Set bits 0-15 of procedure entry
181-
point */
182-
shr $16, %eax
183-
movw %ax, 6(%edx) /* Set bits 16-31 of entry point */
184-
addl $X64_IDT_DESC_SIZE,%edx
185-
loop .fixup_idt_entries
186-
187-
/* Load IDT */
188-
lea HOST_IDTR(%rip), %rbx
189-
lidtq (%rbx)
190-
191166
/* continue with chipset level initialization */
192167
call bsp_boot_init
193168

hypervisor/arch/x86/irq.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,9 +445,24 @@ void init_default_irqs(uint16_t cpu_id)
445445
}
446446
}
447447

448-
static void set_idt(struct host_idt_descriptor *idtd)
448+
static inline void fixup_idt(struct host_idt_descriptor *idtd)
449449
{
450+
int i;
451+
union idt_64_descriptor *idt_desc = (union idt_64_descriptor *)idtd->idt;
452+
uint32_t entry_hi_32, entry_lo_32;
453+
454+
for (i = 0; i < HOST_IDT_ENTRIES; i++) {
455+
entry_lo_32 = idt_desc[i].fields.offset_63_32;
456+
entry_hi_32 = idt_desc[i].fields.rsvd;
457+
idt_desc[i].fields.rsvd = 0U;
458+
idt_desc[i].fields.offset_63_32 = entry_hi_32;
459+
idt_desc[i].fields.high32.bits.offset_31_16 = entry_lo_32 >> 16U;
460+
idt_desc[i].fields.low32.bits.offset_15_0 = entry_lo_32 & 0xffffUL;
461+
}
462+
}
450463

464+
static inline void set_idt(struct host_idt_descriptor *idtd)
465+
{
451466
asm volatile (" lidtq %[idtd]\n" : /* no output parameters */
452467
: /* input parameters */
453468
[idtd] "m"(*idtd));
@@ -457,6 +472,9 @@ void interrupt_init(uint16_t pcpu_id)
457472
{
458473
struct host_idt_descriptor *idtd = &HOST_IDTR;
459474

475+
if (pcpu_id == BOOT_CPU_ID) {
476+
fixup_idt(idtd);
477+
}
460478
set_idt(idtd);
461479
init_lapic(pcpu_id);
462480
init_default_irqs(pcpu_id);

0 commit comments

Comments
 (0)