summaryrefslogtreecommitdiff
path: root/arch/x86/machine/trap.h
blob: 449ee953e4937ec5454b83cb1488e4480edadd6c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
 * Copyright (c) 2011, 2012, 2013 Richard Braun.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *
 * Trap (interrupt and exception) handling.
 */

#ifndef _X86_TRAP_H
#define _X86_TRAP_H

/*
 * Architecture defined traps.
 */
#define TRAP_DE             0   /* Divide Error */
#define TRAP_DB             1   /* Debug */
#define TRAP_NMI            2   /* NMI Interrupt */
#define TRAP_BP             3   /* Breakpoint */
#define TRAP_OF             4   /* Overflow */
#define TRAP_BR             5   /* BOUND Range Exceeded */
#define TRAP_UD             6   /* Invalid Opcode (Undefined Opcode) */
#define TRAP_NM             7   /* Device Not Available (No Math Coprocessor) */
#define TRAP_DF             8   /* Double Fault */
#define TRAP_TS             10  /* Invalid TSS */
#define TRAP_NP             11  /* Segment Not Present */
#define TRAP_SS             12  /* Stack-Segment Fault */
#define TRAP_GP             13  /* General Protection */
#define TRAP_PF             14  /* Page Fault */
#define TRAP_MF             16  /* x87 FPU Floating-Point Error (Math Fault) */
#define TRAP_AC             17  /* Alignment Check */
#define TRAP_MC             18  /* Machine Check */
#define TRAP_XM             19  /* SIMD Floating-Point Exception */

/*
 * Interrupts reserved for the legacy PIC.
 */
#define TRAP_PIC_BASE       32

/*
 * System defined traps.
 *
 * The local APIC assigns one priority every 16 vectors.
 */
#define TRAP_LLSYNC_RESET       237
#define TRAP_THREAD_SCHEDULE    238
#define TRAP_PMAP_UPDATE        239
#define TRAP_CPU_HALT           240
#define TRAP_LAPIC_TIMER        253
#define TRAP_LAPIC_ERROR        254
#define TRAP_LAPIC_SPURIOUS     255

/*
 * Vector identifying an unhandled trap.
 */
#define TRAP_DEFAULT        256

#ifndef __ASSEMBLER__

#include <kern/macros.h>
#include <kern/printk.h>

#ifdef __LP64__

struct trap_frame {
    unsigned long rax;
    unsigned long rbx;
    unsigned long rcx;
    unsigned long rdx;
    unsigned long rbp;
    unsigned long rsi;
    unsigned long rdi;
    unsigned long r8;
    unsigned long r9;
    unsigned long r10;
    unsigned long r11;
    unsigned long r12;
    unsigned long r13;
    unsigned long r14;
    unsigned long r15;
    unsigned long vector;
    unsigned long error;
    unsigned long rip;
    unsigned long cs;
    unsigned long rflags;
    unsigned long rsp;
    unsigned long ss;
} __packed;

#else /* __LP64__ */

struct trap_frame {
    unsigned long eax;
    unsigned long ebx;
    unsigned long ecx;
    unsigned long edx;
    unsigned long ebp;
    unsigned long esi;
    unsigned long edi;
    unsigned long ds;
    unsigned long es;
    unsigned long fs;
    unsigned long gs;
    unsigned long vector;
    unsigned long error;
    unsigned long eip;
    unsigned long cs;
    unsigned long eflags;
    unsigned long esp;      /* esp and ss are undefined if trapped in kernel */
    unsigned long ss;
} __packed;

#endif /* __LP64__ */

static inline void
trap_test_double_fault(void)
{
    printk("trap: double fault test\n");
    asm volatile("movl $0x1234, %esp; push $0");
}

/*
 * Set up the trap module.
 */
void trap_setup(void);

/*
 * Unified trap entry point.
 */
void trap_main(struct trap_frame *frame);

/*
 * Display the content of a trap frame.
 */
void trap_frame_show(struct trap_frame *frame);

/*
 * Display the call trace interrupted by the trap of the given frame.
 */
void trap_stack_show(struct trap_frame *frame);

#endif /* __ASSEMBLER__ */

#endif /* _X86_TRAP_H */