Coverage Report

Created: 2026-10-31 08:12

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/qemu/hw/i386/x86-cpu.c
Line
Count
Source
1
/*
2
 * Copyright (c) 2003-2004 Fabrice Bellard
3
 * Copyright (c) 2019, 2024 Red Hat, Inc.
4
 *
5
 * Permission is hereby granted, free of charge, to any person obtaining a copy
6
 * of this software and associated documentation files (the "Software"), to deal
7
 * in the Software without restriction, including without limitation the rights
8
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
 * copies of the Software, and to permit persons to whom the Software is
10
 * furnished to do so, subject to the following conditions:
11
 *
12
 * The above copyright notice and this permission notice shall be included in
13
 * all copies or substantial portions of the Software.
14
 *
15
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
 * THE SOFTWARE.
22
 */
23
#include "qemu/osdep.h"
24
#include "system/whpx.h"
25
#include "system/mshv.h"
26
#include "system/cpu-timers.h"
27
#include "trace.h"
28
29
#include "hw/i386/x86.h"
30
#include "target/i386/cpu.h"
31
#include "hw/intc/i8259.h"
32
#include "hw/core/irq.h"
33
#include "system/kvm.h"
34
35
/* TSC handling */
36
uint64_t cpu_get_tsc(CPUX86State *env)
37
0
{
38
0
    return cpus_get_elapsed_ticks();
39
0
}
40
41
/* IRQ handling */
42
static void pic_irq_request(void *opaque, int irq, int level)
43
29.8M
{
44
29.8M
    CPUState *cs = first_cpu;
45
29.8M
    X86CPU *cpu = X86_CPU(cs);
46
47
29.8M
    trace_x86_pic_interrupt(irq, level);
48
49
29.8M
    if (mshv_irqchip_in_kernel()) {
50
0
        return;
51
0
    }
52
53
29.8M
    if (cpu_is_apic_enabled(cpu->apic_state) && !kvm_irqchip_in_kernel() &&
54
29.8M
        !whpx_irqchip_in_kernel()) {
55
29.8M
        CPU_FOREACH(cs) {
56
29.8M
            cpu = X86_CPU(cs);
57
29.8M
            if (apic_accept_pic_intr(cpu->apic_state)) {
58
379
                apic_deliver_pic_intr(cpu->apic_state, level);
59
379
            }
60
29.8M
        }
61
29.8M
    } else {
62
0
        if (level) {
63
0
            cpu_interrupt(cs, CPU_INTERRUPT_HARD);
64
0
        } else {
65
0
            cpu_reset_interrupt(cs, CPU_INTERRUPT_HARD);
66
0
        }
67
0
    }
68
29.8M
}
69
70
qemu_irq x86_allocate_cpu_irq(void)
71
61
{
72
61
    return qemu_allocate_irq(pic_irq_request, NULL, 0);
73
61
}
74
75
int cpu_get_pic_interrupt(CPUX86State *env)
76
0
{
77
0
    X86CPU *cpu = env_archcpu(env);
78
0
    int intno;
79
80
0
    if (!kvm_irqchip_in_kernel() && !whpx_irqchip_in_kernel()) {
81
0
        intno = apic_get_interrupt(cpu->apic_state);
82
0
        if (intno >= 0) {
83
0
            return intno;
84
0
        }
85
        /* read the irq from the PIC */
86
0
        if (!apic_accept_pic_intr(cpu->apic_state)) {
87
0
            return -1;
88
0
        }
89
0
    }
90
91
0
    intno = pic_read_irq(isa_pic);
92
0
    return intno;
93
0
}
94
95
APICCommonState *cpu_get_current_apic(void)
96
13.8M
{
97
13.8M
    if (current_cpu) {
98
0
        X86CPU *cpu = X86_CPU(current_cpu);
99
0
        return cpu->apic_state;
100
13.8M
    } else {
101
        return NULL;
102
13.8M
    }
103
13.8M
}