1// SPDX-License-Identifier: GPL-3.0-or-later
2
3#pragma once
4
5#include "mos/x86/x86_platform.h"
6
7#include <mos/lib/structures/list.h>
8#include <mos/mos_global.h>
9#include <mos/types.h>
10
11#define IRQ_BASE 0x20
12#define IPI_BASE 0x50
13
14#define ISR_MAX_COUNT 32
15#define IRQ_MAX_COUNT 16
16#define IDT_ENTRY_COUNT 256
17
18typedef enum
19{
20 EXCEPTION_DIVIDE_ERROR = 0,
21 EXCEPTION_DEBUG = 1,
22 EXCEPTION_NMI = 2,
23 EXCEPTION_BREAKPOINT = 3,
24 EXCEPTION_OVERFLOW = 4,
25 EXCEPTION_BOUND_RANGE_EXCEEDED = 5,
26 EXCEPTION_INVALID_OPCODE = 6,
27 EXCEPTION_DEVICE_NOT_AVAILABLE = 7,
28 EXCEPTION_DOUBLE_FAULT = 8,
29 EXCEPTION_COPROCESSOR_SEGMENT_OVERRUN = 9,
30 EXCEPTION_INVALID_TSS = 10,
31 EXCEPTION_SEGMENT_NOT_PRESENT = 11,
32 EXCEPTION_STACK_SEGMENT_FAULT = 12,
33 EXCEPTION_GENERAL_PROTECTION_FAULT = 13,
34 EXCEPTION_PAGE_FAULT = 14,
35 // 15 is reserved
36 EXCEPTION_FPU_ERROR = 16,
37 EXCEPTION_ALIGNMENT_CHECK = 17,
38 EXCEPTION_MACHINE_CHECK = 18,
39 EXCEPTION_SIMD_ERROR = 19,
40 EXCEPTION_VIRTUALIZATION_EXCEPTION = 20,
41 EXCEPTION_CONTROL_PROTECTION_EXCEPTION = 21,
42 // 22-27 are reserved
43 EXCEPTION_HYPERVISOR_EXCEPTION = 28,
44 EXCEPTION_VMM_COMMUNICATION_EXCEPTION = 29,
45 EXCEPTION_SECURITY_EXCEPTION = 30,
46 // 31 is reserved
47 EXCEPTION_MAX = 31,
48 EXCEPTION_COUNT = 32
49} x86_exception_enum_t;
50
51MOS_STATIC_ASSERT(IRQ_BASE > EXCEPTION_MAX, "IRQ_BASE is too small, possibly overlapping with exceptions");
52
53typedef enum
54{
55 IRQ_PIT_TIMER = 0,
56 IRQ_KEYBOARD = 1,
57 IRQ_CASCADE = 2,
58 IRQ_COM2 = 3,
59 IRQ_COM1 = 4,
60 IRQ_LPT2 = 5,
61 IRQ_FLOPPY = 6,
62 IRQ_LPT1 = 7,
63 IRQ_CMOS_RTC = 8,
64 IRQ_FREE1 = 9,
65 IRQ_FREE2 = 10,
66 IRQ_FREE3 = 11,
67 IRQ_PS2_MOUSE = 12,
68 IRQ_FPU = 13,
69 IRQ_ATA_PRIMARY = 14,
70 IRQ_ATA_SECONDARY = 15,
71 IRQ_MAX = 16,
72} x86_irq_enum_t;
73
74MOS_STATIC_ASSERT(IRQ_MAX_COUNT == IRQ_MAX, "IRQ_MAX_COUNT is not equal to IRQ_MAX");
75
76void pic_remap_irq(void);
77
78// The following `extern` symbols are defined in the interrupt_handler.asm file.
79extern void *isr_stub_table[];
80extern void *irq_stub_table[];
81
82void x86_interrupt_entry(ptr_t esp);
83
84[[noreturn]] extern void x86_interrupt_return_impl(const platform_regs_t *regs);
85