Skip to main content

kernel/types/
panic_codes.rs

1// SPDX-License-Identifier: GPL-3.0-only
2//! Panic codes for classifying kernel panics.
3//!
4//! Authors: MarioS271
5
6/// Numeric (`u16`) classification of the reason for a kernel panic.
7#[repr(u16)]
8pub enum PanicCode {
9    // General
10    Unknown = 0x0000,
11    ManuallyTriggeredPanic = 0x0001,
12    InitFailure = 0x0002,
13
14    // Exceptions
15    IllegalInterrupt = 0x0099,
16    DivideError = 0x0100,
17    NmiHardwareFailiure = 0x0102,
18    Overflow = 0x0104,
19    InvalidOpcode = 0x0106,
20    DeviceNotAvail = 0x0107,
21    DoubleFault = 0x0108,
22    InvalidTss = 0x0110,
23    SegmentNotPresent = 0x0111,
24    StackSegmentFault = 0x0112,
25    GeneralProtectionFault = 0x0113,
26    PageFault = 0x0114,
27    X87FloatingPoint = 0x0116,
28    AlignmentCheck = 0x0117,
29    MachineCheck = 0x0118,
30    SimdFloatingPoint = 0x0119,
31    Virtualization = 0x0120,
32    VmmCommunicationException = 0x0129,
33    SecurityException = 0x0130,
34
35    // Memory
36    NoValidMemMapEntry = 0x0300,
37    DoubleFree = 0x0301,
38    IllegalFree = 0x0302,
39    OutOfMemory = 0x0303,
40    // Memory: Paging
41    InvalidPageOperation = 0x320,
42
43    // Display
44    InvalidPsf2MagicNumber = 0x1000,
45}
46
47impl PanicCode {
48    /// Return the variant name as a static string, suitable for printing in a panic message.
49    pub fn as_str(&self) -> &'static str {
50        match self {
51            // General
52            PanicCode::Unknown => "Unknown",
53            PanicCode::ManuallyTriggeredPanic => "ManuallyTriggeredPanic",
54            PanicCode::InitFailure => "InitFailure",
55
56            // Exceptions
57            PanicCode::IllegalInterrupt => "IllegalInterrupt",
58            PanicCode::DivideError => "DivideError",
59            PanicCode::NmiHardwareFailiure => "NmiHardwareFailiure",
60            PanicCode::Overflow => "Overflow",
61            PanicCode::InvalidOpcode => "InvalidOpcode",
62            PanicCode::DeviceNotAvail => "DeviceNotAvail",
63            PanicCode::DoubleFault => "DoubleFault",
64            PanicCode::InvalidTss => "InvalidTss",
65            PanicCode::SegmentNotPresent => "SegmentNotPresent",
66            PanicCode::StackSegmentFault => "StackSegmentFault",
67            PanicCode::GeneralProtectionFault => "GeneralProtectionFault",
68            PanicCode::PageFault => "PageFault",
69            PanicCode::X87FloatingPoint => "X87FloatingPoint",
70            PanicCode::AlignmentCheck => "AlignmentCheck",
71            PanicCode::MachineCheck => "MachineCheck",
72            PanicCode::SimdFloatingPoint => "SimdFloatingPoint",
73            PanicCode::Virtualization => "Virtualization",
74            PanicCode::VmmCommunicationException => "VmmCommunicationException",
75            PanicCode::SecurityException => "SecurityException",
76
77            // Memory
78            PanicCode::NoValidMemMapEntry => "NoValidMemMapEntry",
79            PanicCode::DoubleFree => "DoubleFree",
80            PanicCode::IllegalFree => "IllegalFree",
81            PanicCode::OutOfMemory => "OutOfMemory",
82            // Memory: Paging
83            PanicCode::InvalidPageOperation => "InvalidPageOperation",
84
85            // Display
86            PanicCode::InvalidPsf2MagicNumber => "InvalidPsf2MagicNumber",
87        }
88    }
89}