Blame view

arch/x86/kernel/traps.c 19 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
  /*
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2
   *  Copyright (C) 1991, 1992  Linus Torvalds
a8c1be9d2   Alexander van Heukelum   x86: initial chan...
3
   *  Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
4
5
6
7
8
9
   *
   *  Pentium III FXSR, SSE support
   *	Gareth Hughes <gareth@valinux.com>, May 2000
   */
  
  /*
c1d518c84   Alexander van Heukelum   traps: x86: vario...
10
   * Handle hardware traps and faults.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
11
   */
b5964405f   Ingo Molnar   x86: clean up tra...
12
13
14
  #include <linux/interrupt.h>
  #include <linux/kallsyms.h>
  #include <linux/spinlock.h>
b5964405f   Ingo Molnar   x86: clean up tra...
15
16
  #include <linux/kprobes.h>
  #include <linux/uaccess.h>
b5964405f   Ingo Molnar   x86: clean up tra...
17
  #include <linux/kdebug.h>
f503b5ae5   Jason Wessel   x86,kgdb: Add low...
18
  #include <linux/kgdb.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
19
  #include <linux/kernel.h>
b5964405f   Ingo Molnar   x86: clean up tra...
20
21
  #include <linux/module.h>
  #include <linux/ptrace.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
22
  #include <linux/string.h>
b5964405f   Ingo Molnar   x86: clean up tra...
23
  #include <linux/delay.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
24
  #include <linux/errno.h>
b5964405f   Ingo Molnar   x86: clean up tra...
25
26
  #include <linux/kexec.h>
  #include <linux/sched.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
27
  #include <linux/timer.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
28
  #include <linux/init.h>
91768d6c2   Jeremy Fitzhardinge   [PATCH] Generic B...
29
  #include <linux/bug.h>
b5964405f   Ingo Molnar   x86: clean up tra...
30
31
  #include <linux/nmi.h>
  #include <linux/mm.h>
c1d518c84   Alexander van Heukelum   traps: x86: vario...
32
33
  #include <linux/smp.h>
  #include <linux/io.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
34
35
36
37
38
39
40
41
42
  
  #ifdef CONFIG_EISA
  #include <linux/ioport.h>
  #include <linux/eisa.h>
  #endif
  
  #ifdef CONFIG_MCA
  #include <linux/mca.h>
  #endif
c0d121720   Dave Jiang   drivers/edac: add...
43
44
45
  #if defined(CONFIG_EDAC)
  #include <linux/edac.h>
  #endif
f85612967   Vegard Nossum   x86: add hooks fo...
46
  #include <asm/kmemcheck.h>
b5964405f   Ingo Molnar   x86: clean up tra...
47
  #include <asm/stacktrace.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
48
  #include <asm/processor.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
49
  #include <asm/debugreg.h>
60063497a   Arun Sharma   atomic: use <linu...
50
  #include <linux/atomic.h>
b5964405f   Ingo Molnar   x86: clean up tra...
51
  #include <asm/system.h>
c1d518c84   Alexander van Heukelum   traps: x86: vario...
52
  #include <asm/traps.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
53
54
  #include <asm/desc.h>
  #include <asm/i387.h>
9e55e44e3   Hidetoshi Seto   x86, mce: unify m...
55
  #include <asm/mce.h>
c1d518c84   Alexander van Heukelum   traps: x86: vario...
56

1164dd009   Ingo Molnar   x86: move mach-de...
57
  #include <asm/mach_traps.h>
c1d518c84   Alexander van Heukelum   traps: x86: vario...
58

081f75bbd   Alexander van Heukelum   traps: x86: make ...
59
  #ifdef CONFIG_X86_64
428cf9025   Thomas Gleixner   x86: Move traps_i...
60
  #include <asm/x86_init.h>
081f75bbd   Alexander van Heukelum   traps: x86: make ...
61
62
  #include <asm/pgalloc.h>
  #include <asm/proto.h>
081f75bbd   Alexander van Heukelum   traps: x86: make ...
63
  #else
c1d518c84   Alexander van Heukelum   traps: x86: vario...
64
  #include <asm/processor-flags.h>
8e6dafd6c   Ingo Molnar   x86: refactor x86...
65
  #include <asm/setup.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
66

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
67
  asmlinkage int system_call(void);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
68
  /* Do we ignore FPU interrupts ? */
b5964405f   Ingo Molnar   x86: clean up tra...
69
  char ignore_fpu_irq;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
70
71
72
  
  /*
   * The IDT has to be page-aligned to simplify the Pentium
07e81d616   Tim Abbott   x86: Use section ...
73
   * F0 0F bug workaround.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
74
   */
07e81d616   Tim Abbott   x86: Use section ...
75
  gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
081f75bbd   Alexander van Heukelum   traps: x86: make ...
76
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
77

b77b881f2   Yinghai Lu   x86: fix lguest u...
78
79
  DECLARE_BITMAP(used_vectors, NR_VECTORS);
  EXPORT_SYMBOL_GPL(used_vectors);
762db4347   Alexander van Heukelum   i386: remove kpro...
80
81
82
83
84
  static inline void conditional_sti(struct pt_regs *regs)
  {
  	if (regs->flags & X86_EFLAGS_IF)
  		local_irq_enable();
  }
3d2a71a59   Alexander van Heukelum   x86, traps: conve...
85
86
87
88
89
90
  static inline void preempt_conditional_sti(struct pt_regs *regs)
  {
  	inc_preempt_count();
  	if (regs->flags & X86_EFLAGS_IF)
  		local_irq_enable();
  }
be716615f   Thomas Gleixner   x86, vm86: fix pr...
91
92
93
94
95
  static inline void conditional_cli(struct pt_regs *regs)
  {
  	if (regs->flags & X86_EFLAGS_IF)
  		local_irq_disable();
  }
3d2a71a59   Alexander van Heukelum   x86, traps: conve...
96
97
98
99
100
101
  static inline void preempt_conditional_cli(struct pt_regs *regs)
  {
  	if (regs->flags & X86_EFLAGS_IF)
  		local_irq_disable();
  	dec_preempt_count();
  }
b5964405f   Ingo Molnar   x86: clean up tra...
102
  static void __kprobes
3c1326f8a   Alexander van Heukelum   traps: i386: make...
103
  do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
b5964405f   Ingo Molnar   x86: clean up tra...
104
  	long error_code, siginfo_t *info)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
105
  {
4f339ecb3   Alexander Nyberg   [PATCH] kdump: Sa...
106
  	struct task_struct *tsk = current;
4f339ecb3   Alexander Nyberg   [PATCH] kdump: Sa...
107

081f75bbd   Alexander van Heukelum   traps: x86: make ...
108
  #ifdef CONFIG_X86_32
6b6891f9c   gorcunov@gmail.com   x86: cleanup - re...
109
  	if (regs->flags & X86_VM_MASK) {
3c1326f8a   Alexander van Heukelum   traps: i386: make...
110
111
112
113
114
  		/*
  		 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
  		 * On nmi (interrupt 2), do_trap should not be called.
  		 */
  		if (trapnr < 6)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
115
116
117
  			goto vm86_trap;
  		goto trap_signal;
  	}
081f75bbd   Alexander van Heukelum   traps: x86: make ...
118
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
119

717b594a4   Vincent Hanquez   [PATCH] xen: x86:...
120
  	if (!user_mode(regs))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
121
  		goto kernel_trap;
081f75bbd   Alexander van Heukelum   traps: x86: make ...
122
  #ifdef CONFIG_X86_32
b5964405f   Ingo Molnar   x86: clean up tra...
123
  trap_signal:
081f75bbd   Alexander van Heukelum   traps: x86: make ...
124
  #endif
b5964405f   Ingo Molnar   x86: clean up tra...
125
126
127
128
129
130
131
132
133
134
135
  	/*
  	 * We want error_code and trap_no set for userspace faults and
  	 * kernelspace faults which result in die(), but not
  	 * kernelspace faults which are fixed up.  die() gives the
  	 * process no chance to handle the signal and notice the
  	 * kernel fault information, so that won't result in polluting
  	 * the information about previously queued, but not yet
  	 * delivered, faults.  See also do_general_protection below.
  	 */
  	tsk->thread.error_code = error_code;
  	tsk->thread.trap_no = trapnr;
d18951834   Andi Kleen   [PATCH] x86: Fix ...
136

081f75bbd   Alexander van Heukelum   traps: x86: make ...
137
138
139
140
141
142
143
144
145
146
147
148
  #ifdef CONFIG_X86_64
  	if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
  	    printk_ratelimit()) {
  		printk(KERN_INFO
  		       "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
  		       tsk->comm, tsk->pid, str,
  		       regs->ip, regs->sp, error_code);
  		print_vma_addr(" in ", regs->ip);
  		printk("
  ");
  	}
  #endif
b5964405f   Ingo Molnar   x86: clean up tra...
149
150
151
152
153
  	if (info)
  		force_sig_info(signr, info, tsk);
  	else
  		force_sig(signr, tsk);
  	return;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
154

b5964405f   Ingo Molnar   x86: clean up tra...
155
156
157
158
159
  kernel_trap:
  	if (!fixup_exception(regs)) {
  		tsk->thread.error_code = error_code;
  		tsk->thread.trap_no = trapnr;
  		die(str, regs, error_code);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
160
  	}
b5964405f   Ingo Molnar   x86: clean up tra...
161
  	return;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
162

081f75bbd   Alexander van Heukelum   traps: x86: make ...
163
  #ifdef CONFIG_X86_32
b5964405f   Ingo Molnar   x86: clean up tra...
164
165
166
167
168
  vm86_trap:
  	if (handle_vm86_trap((struct kernel_vm86_regs *) regs,
  						error_code, trapnr))
  		goto trap_signal;
  	return;
081f75bbd   Alexander van Heukelum   traps: x86: make ...
169
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
170
  }
b5964405f   Ingo Molnar   x86: clean up tra...
171
  #define DO_ERROR(trapnr, signr, str, name)				\
e407d6208   Alexander van Heukelum   x86, traps: intro...
172
  dotraplinkage void do_##name(struct pt_regs *regs, long error_code)	\
b5964405f   Ingo Molnar   x86: clean up tra...
173
174
  {									\
  	if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr)	\
a8c1be9d2   Alexander van Heukelum   x86: initial chan...
175
  							== NOTIFY_STOP)	\
b5964405f   Ingo Molnar   x86: clean up tra...
176
  		return;							\
61aef7d24   Alexander van Heukelum   i386: prepare to ...
177
  	conditional_sti(regs);						\
3c1326f8a   Alexander van Heukelum   traps: i386: make...
178
  	do_trap(trapnr, signr, str, regs, error_code, NULL);		\
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
179
  }
3c1326f8a   Alexander van Heukelum   traps: i386: make...
180
  #define DO_ERROR_INFO(trapnr, signr, str, name, sicode, siaddr)		\
e407d6208   Alexander van Heukelum   x86, traps: intro...
181
  dotraplinkage void do_##name(struct pt_regs *regs, long error_code)	\
b5964405f   Ingo Molnar   x86: clean up tra...
182
183
184
185
186
187
  {									\
  	siginfo_t info;							\
  	info.si_signo = signr;						\
  	info.si_errno = 0;						\
  	info.si_code = sicode;						\
  	info.si_addr = (void __user *)siaddr;				\
b5964405f   Ingo Molnar   x86: clean up tra...
188
  	if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr)	\
a8c1be9d2   Alexander van Heukelum   x86: initial chan...
189
  							== NOTIFY_STOP)	\
b5964405f   Ingo Molnar   x86: clean up tra...
190
  		return;							\
61aef7d24   Alexander van Heukelum   i386: prepare to ...
191
  	conditional_sti(regs);						\
3c1326f8a   Alexander van Heukelum   traps: i386: make...
192
  	do_trap(trapnr, signr, str, regs, error_code, &info);		\
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
193
  }
3c1326f8a   Alexander van Heukelum   traps: i386: make...
194
195
196
197
  DO_ERROR_INFO(0, SIGFPE, "divide error", divide_error, FPE_INTDIV, regs->ip)
  DO_ERROR(4, SIGSEGV, "overflow", overflow)
  DO_ERROR(5, SIGSEGV, "bounds", bounds)
  DO_ERROR_INFO(6, SIGILL, "invalid opcode", invalid_op, ILL_ILLOPN, regs->ip)
51bc1ed60   Alexander van Heukelum   i386: convert har...
198
  DO_ERROR(9, SIGFPE, "coprocessor segment overrun", coprocessor_segment_overrun)
6bf77bf93   Alexander van Heukelum   i386: convert har...
199
  DO_ERROR(10, SIGSEGV, "invalid TSS", invalid_TSS)
36d936c79   Alexander van Heukelum   i386: convert har...
200
  DO_ERROR(11, SIGBUS, "segment not present", segment_not_present)
081f75bbd   Alexander van Heukelum   traps: x86: make ...
201
  #ifdef CONFIG_X86_32
f5ca81878   Alexander van Heukelum   i386: convert har...
202
  DO_ERROR(12, SIGBUS, "stack segment", stack_segment)
081f75bbd   Alexander van Heukelum   traps: x86: make ...
203
  #endif
3c1326f8a   Alexander van Heukelum   traps: i386: make...
204
  DO_ERROR_INFO(17, SIGBUS, "alignment check", alignment_check, BUS_ADRALN, 0)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
205

081f75bbd   Alexander van Heukelum   traps: x86: make ...
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
  #ifdef CONFIG_X86_64
  /* Runs on IST stack */
  dotraplinkage void do_stack_segment(struct pt_regs *regs, long error_code)
  {
  	if (notify_die(DIE_TRAP, "stack segment", regs, error_code,
  			12, SIGBUS) == NOTIFY_STOP)
  		return;
  	preempt_conditional_sti(regs);
  	do_trap(12, SIGBUS, "stack segment", regs, error_code, NULL);
  	preempt_conditional_cli(regs);
  }
  
  dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code)
  {
  	static const char str[] = "double fault";
  	struct task_struct *tsk = current;
  
  	/* Return not checked because double check cannot be ignored */
  	notify_die(DIE_TRAP, str, regs, error_code, 8, SIGSEGV);
  
  	tsk->thread.error_code = error_code;
  	tsk->thread.trap_no = 8;
bd8b96dfc   Ingo Molnar   x86: clean up com...
228
229
230
231
  	/*
  	 * This is always a kernel trap and never fixable (and thus must
  	 * never return).
  	 */
081f75bbd   Alexander van Heukelum   traps: x86: make ...
232
233
234
235
  	for (;;)
  		die(str, regs, error_code);
  }
  #endif
e407d6208   Alexander van Heukelum   x86, traps: intro...
236
  dotraplinkage void __kprobes
13485ab55   Alexander van Heukelum   x86: traps_xx: re...
237
  do_general_protection(struct pt_regs *regs, long error_code)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
238
  {
13485ab55   Alexander van Heukelum   x86: traps_xx: re...
239
  	struct task_struct *tsk;
b5964405f   Ingo Molnar   x86: clean up tra...
240

c6df0d71b   Alexander van Heukelum   i386: convert har...
241
  	conditional_sti(regs);
081f75bbd   Alexander van Heukelum   traps: x86: make ...
242
  #ifdef CONFIG_X86_32
6b6891f9c   gorcunov@gmail.com   x86: cleanup - re...
243
  	if (regs->flags & X86_VM_MASK)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
244
  		goto gp_in_vm86;
081f75bbd   Alexander van Heukelum   traps: x86: make ...
245
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
246

13485ab55   Alexander van Heukelum   x86: traps_xx: re...
247
  	tsk = current;
717b594a4   Vincent Hanquez   [PATCH] xen: x86:...
248
  	if (!user_mode(regs))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
249
  		goto gp_in_kernel;
13485ab55   Alexander van Heukelum   x86: traps_xx: re...
250
251
  	tsk->thread.error_code = error_code;
  	tsk->thread.trap_no = 13;
b5964405f   Ingo Molnar   x86: clean up tra...
252

13485ab55   Alexander van Heukelum   x86: traps_xx: re...
253
254
  	if (show_unhandled_signals && unhandled_signal(tsk, SIGSEGV) &&
  			printk_ratelimit()) {
abd4f7505   Masoud Asgharifard Sharbiani   x86: i386-show-un...
255
  		printk(KERN_INFO
13485ab55   Alexander van Heukelum   x86: traps_xx: re...
256
257
258
  			"%s[%d] general protection ip:%lx sp:%lx error:%lx",
  			tsk->comm, task_pid_nr(tsk),
  			regs->ip, regs->sp, error_code);
03252919b   Andi Kleen   x86: print which ...
259
260
261
262
  		print_vma_addr(" in ", regs->ip);
  		printk("
  ");
  	}
abd4f7505   Masoud Asgharifard Sharbiani   x86: i386-show-un...
263

13485ab55   Alexander van Heukelum   x86: traps_xx: re...
264
  	force_sig(SIGSEGV, tsk);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
265
  	return;
081f75bbd   Alexander van Heukelum   traps: x86: make ...
266
  #ifdef CONFIG_X86_32
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
267
268
269
270
  gp_in_vm86:
  	local_irq_enable();
  	handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
  	return;
081f75bbd   Alexander van Heukelum   traps: x86: make ...
271
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
272
273
  
  gp_in_kernel:
13485ab55   Alexander van Heukelum   x86: traps_xx: re...
274
275
276
277
278
279
  	if (fixup_exception(regs))
  		return;
  
  	tsk->thread.error_code = error_code;
  	tsk->thread.trap_no = 13;
  	if (notify_die(DIE_GPF, "general protection fault", regs,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
280
  				error_code, 13, SIGSEGV) == NOTIFY_STOP)
13485ab55   Alexander van Heukelum   x86: traps_xx: re...
281
282
  		return;
  	die("general protection fault", regs, error_code);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
283
  }
c1d518c84   Alexander van Heukelum   traps: x86: vario...
284
  /* May run on IST stack. */
e407d6208   Alexander van Heukelum   x86, traps: intro...
285
  dotraplinkage void __kprobes do_int3(struct pt_regs *regs, long error_code)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
286
  {
f503b5ae5   Jason Wessel   x86,kgdb: Add low...
287
288
289
290
291
  #ifdef CONFIG_KGDB_LOW_LEVEL_TRAP
  	if (kgdb_ll_trap(DIE_INT3, "int3", regs, error_code, 3, SIGTRAP)
  			== NOTIFY_STOP)
  		return;
  #endif /* CONFIG_KGDB_LOW_LEVEL_TRAP */
cc3a1bf52   Srikar Dronamraju   x86: Clean up and...
292

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
293
294
  	if (notify_die(DIE_INT3, "int3", regs, error_code, 3, SIGTRAP)
  			== NOTIFY_STOP)
48c88211a   Stas Sergeev   [PATCH] x86: entr...
295
  		return;
b5964405f   Ingo Molnar   x86: clean up tra...
296

42181186a   Steven Rostedt   x86: Add counter ...
297
298
299
300
301
  	/*
  	 * Let others (NMI) know that the debug stack is in use
  	 * as we may switch to the interrupt stack.
  	 */
  	debug_stack_usage_inc();
4915a35e3   Alexander van Heukelum   traps: i386: use ...
302
  	preempt_conditional_sti(regs);
3c1326f8a   Alexander van Heukelum   traps: i386: make...
303
  	do_trap(3, SIGTRAP, "int3", regs, error_code, NULL);
4915a35e3   Alexander van Heukelum   traps: i386: use ...
304
  	preempt_conditional_cli(regs);
42181186a   Steven Rostedt   x86: Add counter ...
305
  	debug_stack_usage_dec();
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
306
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
307

081f75bbd   Alexander van Heukelum   traps: x86: make ...
308
  #ifdef CONFIG_X86_64
bd8b96dfc   Ingo Molnar   x86: clean up com...
309
310
311
312
313
  /*
   * Help handler running on IST stack to switch back to user stack
   * for scheduling or signal handling. The actual stack switch is done in
   * entry.S
   */
081f75bbd   Alexander van Heukelum   traps: x86: make ...
314
315
316
317
318
319
320
321
322
  asmlinkage __kprobes struct pt_regs *sync_regs(struct pt_regs *eregs)
  {
  	struct pt_regs *regs = eregs;
  	/* Did already sync */
  	if (eregs == (struct pt_regs *)eregs->sp)
  		;
  	/* Exception from user space */
  	else if (user_mode(eregs))
  		regs = task_pt_regs(current);
bd8b96dfc   Ingo Molnar   x86: clean up com...
323
324
325
326
  	/*
  	 * Exception from kernel and interrupts are enabled. Move to
  	 * kernel process stack.
  	 */
081f75bbd   Alexander van Heukelum   traps: x86: make ...
327
328
329
330
331
332
333
  	else if (eregs->flags & X86_EFLAGS_IF)
  		regs = (struct pt_regs *)(eregs->sp -= sizeof(struct pt_regs));
  	if (eregs != regs)
  		*regs = *eregs;
  	return regs;
  }
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
334
335
336
337
338
339
340
341
342
343
  /*
   * Our handling of the processor debug registers is non-trivial.
   * We do not clear them on entry and exit from the kernel. Therefore
   * it is possible to get a watchpoint trap here from inside the kernel.
   * However, the code in ./ptrace.c has ensured that the user can
   * only set watchpoints on userspace addresses. Therefore the in-kernel
   * watchpoint trap can only occur in code which is reading/writing
   * from user space. Such code must not hold kernel locks (since it
   * can equally take a page fault), therefore it is safe to call
   * force_sig_info even though that claims and releases locks.
b5964405f   Ingo Molnar   x86: clean up tra...
344
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
345
346
347
348
349
350
351
352
353
354
   * Code in ./signal.c ensures that the debug control register
   * is restored before we deliver any signal, and therefore that
   * user code runs with the correct debug control register even though
   * we clear it here.
   *
   * Being careful here means that we don't have to be as careful in a
   * lot of more complicated places (task switching can be a bit lazy
   * about restoring all the debug state, and ptrace doesn't have to
   * find every occurrence of the TF bit that could be saved away even
   * by user code)
c1d518c84   Alexander van Heukelum   traps: x86: vario...
355
356
   *
   * May run on IST stack.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
357
   */
e407d6208   Alexander van Heukelum   x86, traps: intro...
358
  dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
359
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
360
  	struct task_struct *tsk = current;
a1e80fafc   Frederic Weisbecker   x86: Send a SIGTR...
361
  	int user_icebp = 0;
08d68323d   K.Prasad   hw-breakpoints: m...
362
  	unsigned long dr6;
da654b74b   Srinivasa Ds   signals: demultip...
363
  	int si_code;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
364

08d68323d   K.Prasad   hw-breakpoints: m...
365
  	get_debugreg(dr6, 6);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
366

40f9249a7   K.Prasad   x86/debug: Clear ...
367
368
  	/* Filter out all the reserved bits which are preset to 1 */
  	dr6 &= ~DR6_RESERVED;
a1e80fafc   Frederic Weisbecker   x86: Send a SIGTR...
369
370
371
372
373
374
375
  	/*
  	 * If dr6 has no reason to give us about the origin of this trap,
  	 * then it's very likely the result of an icebp/int01 trap.
  	 * User wants a sigtrap for that.
  	 */
  	if (!dr6 && user_mode(regs))
  		user_icebp = 1;
f85612967   Vegard Nossum   x86: add hooks fo...
376
  	/* Catch kmemcheck conditions first of all! */
eadb8a091   Ingo Molnar   Merge branch 'lin...
377
  	if ((dr6 & DR_STEP) && kmemcheck_trap(regs))
f85612967   Vegard Nossum   x86: add hooks fo...
378
  		return;
08d68323d   K.Prasad   hw-breakpoints: m...
379
380
  	/* DR6 may or may not be cleared by the CPU */
  	set_debugreg(0, 6);
10faa81e1   Roland McGrath   x86: debugctlmsr ...
381

ea8e61b7b   Peter Zijlstra   x86, ptrace: Fix ...
382
383
384
385
  	/*
  	 * The processor cleared BTF, so don't mark that we need it set.
  	 */
  	clear_tsk_thread_flag(tsk, TIF_BLOCKSTEP);
08d68323d   K.Prasad   hw-breakpoints: m...
386
387
  	/* Store the virtualized DR6 value */
  	tsk->thread.debugreg6 = dr6;
62edab905   K.Prasad   hw-breakpoints: r...
388
389
  	if (notify_die(DIE_DEBUG, "debug", regs, PTR_ERR(&dr6), error_code,
  							SIGTRAP) == NOTIFY_STOP)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
390
  		return;
3d2a71a59   Alexander van Heukelum   x86, traps: conve...
391

42181186a   Steven Rostedt   x86: Add counter ...
392
393
394
395
396
  	/*
  	 * Let others (NMI) know that the debug stack is in use
  	 * as we may switch to the interrupt stack.
  	 */
  	debug_stack_usage_inc();
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
397
  	/* It's safe to allow irq's after DR6 has been saved */
3d2a71a59   Alexander van Heukelum   x86, traps: conve...
398
  	preempt_conditional_sti(regs);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
399

08d68323d   K.Prasad   hw-breakpoints: m...
400
401
402
  	if (regs->flags & X86_VM_MASK) {
  		handle_vm86_trap((struct kernel_vm86_regs *) regs,
  				error_code, 1);
6554287b1   Bart Oldeman   x86, vm86: Fix pr...
403
  		preempt_conditional_cli(regs);
42181186a   Steven Rostedt   x86: Add counter ...
404
  		debug_stack_usage_dec();
08d68323d   K.Prasad   hw-breakpoints: m...
405
  		return;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
406
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
407
  	/*
08d68323d   K.Prasad   hw-breakpoints: m...
408
409
410
411
412
  	 * Single-stepping through system calls: ignore any exceptions in
  	 * kernel space, but re-enable TF when returning to user mode.
  	 *
  	 * We already checked v86 mode above, so we can check for kernel mode
  	 * by just checking the CPL of CS.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
413
  	 */
08d68323d   K.Prasad   hw-breakpoints: m...
414
415
416
417
  	if ((dr6 & DR_STEP) && !user_mode(regs)) {
  		tsk->thread.debugreg6 &= ~DR_STEP;
  		set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
  		regs->flags &= ~X86_EFLAGS_TF;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
418
  	}
08d68323d   K.Prasad   hw-breakpoints: m...
419
  	si_code = get_si_code(tsk->thread.debugreg6);
a1e80fafc   Frederic Weisbecker   x86: Send a SIGTR...
420
  	if (tsk->thread.debugreg6 & (DR_STEP | DR_TRAP_BITS) || user_icebp)
08d68323d   K.Prasad   hw-breakpoints: m...
421
  		send_sigtrap(tsk, regs, error_code, si_code);
3d2a71a59   Alexander van Heukelum   x86, traps: conve...
422
  	preempt_conditional_cli(regs);
42181186a   Steven Rostedt   x86: Add counter ...
423
  	debug_stack_usage_dec();
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
424

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
425
426
427
428
429
430
431
432
  	return;
  }
  
  /*
   * Note that we play around with the 'TS' bit in an attempt to get
   * the correct behaviour even in the presence of the asynchronous
   * IRQ13 behaviour
   */
9b6dba9e0   Brian Gerst   x86: Merge simd_m...
433
  void math_error(struct pt_regs *regs, int error_code, int trapnr)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
434
  {
e2e75c915   Brian Gerst   x86: Merge kernel...
435
  	struct task_struct *task = current;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
436
  	siginfo_t info;
9b6dba9e0   Brian Gerst   x86: Merge simd_m...
437
  	unsigned short err;
e2e75c915   Brian Gerst   x86: Merge kernel...
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
  	char *str = (trapnr == 16) ? "fpu exception" : "simd exception";
  
  	if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, SIGFPE) == NOTIFY_STOP)
  		return;
  	conditional_sti(regs);
  
  	if (!user_mode_vm(regs))
  	{
  		if (!fixup_exception(regs)) {
  			task->thread.error_code = error_code;
  			task->thread.trap_no = trapnr;
  			die(str, regs, error_code);
  		}
  		return;
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
453
454
455
456
  
  	/*
  	 * Save the info for the exception handler and clear the error.
  	 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
457
  	save_init_fpu(task);
9b6dba9e0   Brian Gerst   x86: Merge simd_m...
458
459
  	task->thread.trap_no = trapnr;
  	task->thread.error_code = error_code;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
460
461
  	info.si_signo = SIGFPE;
  	info.si_errno = 0;
9b6dba9e0   Brian Gerst   x86: Merge simd_m...
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
  	info.si_addr = (void __user *)regs->ip;
  	if (trapnr == 16) {
  		unsigned short cwd, swd;
  		/*
  		 * (~cwd & swd) will mask out exceptions that are not set to unmasked
  		 * status.  0x3f is the exception bits in these regs, 0x200 is the
  		 * C1 reg you need in case of a stack fault, 0x040 is the stack
  		 * fault bit.  We should only be taking one exception at a time,
  		 * so if this combination doesn't produce any single exception,
  		 * then we have a bad program that isn't synchronizing its FPU usage
  		 * and it will suffer the consequences since we won't be able to
  		 * fully reproduce the context of the exception
  		 */
  		cwd = get_fpu_cwd(task);
  		swd = get_fpu_swd(task);
adf77bac0   H. Peter Anvin   x86: prioritize t...
477

9b6dba9e0   Brian Gerst   x86: Merge simd_m...
478
479
480
481
482
483
484
485
486
487
488
  		err = swd & ~cwd;
  	} else {
  		/*
  		 * The SIMD FPU exceptions are handled a little differently, as there
  		 * is only a single status/control register.  Thus, to determine which
  		 * unmasked exception was caught we must mask the exception mask bits
  		 * at 0x1f80, and then use these to mask the exception bits at 0x3f.
  		 */
  		unsigned short mxcsr = get_fpu_mxcsr(task);
  		err = ~(mxcsr >> 7) & mxcsr;
  	}
adf77bac0   H. Peter Anvin   x86: prioritize t...
489
490
  
  	if (err & 0x001) {	/* Invalid op */
b5964405f   Ingo Molnar   x86: clean up tra...
491
492
493
494
495
496
  		/*
  		 * swd & 0x240 == 0x040: Stack Underflow
  		 * swd & 0x240 == 0x240: Stack Overflow
  		 * User must clear the SF bit (0x40) if set
  		 */
  		info.si_code = FPE_FLTINV;
adf77bac0   H. Peter Anvin   x86: prioritize t...
497
  	} else if (err & 0x004) { /* Divide by Zero */
b5964405f   Ingo Molnar   x86: clean up tra...
498
  		info.si_code = FPE_FLTDIV;
adf77bac0   H. Peter Anvin   x86: prioritize t...
499
  	} else if (err & 0x008) { /* Overflow */
b5964405f   Ingo Molnar   x86: clean up tra...
500
  		info.si_code = FPE_FLTOVF;
adf77bac0   H. Peter Anvin   x86: prioritize t...
501
502
503
  	} else if (err & 0x012) { /* Denormal, Underflow */
  		info.si_code = FPE_FLTUND;
  	} else if (err & 0x020) { /* Precision */
b5964405f   Ingo Molnar   x86: clean up tra...
504
  		info.si_code = FPE_FLTRES;
adf77bac0   H. Peter Anvin   x86: prioritize t...
505
  	} else {
bd8b96dfc   Ingo Molnar   x86: clean up com...
506
507
508
509
  		/*
  		 * If we're using IRQ 13, or supposedly even some trap 16
  		 * implementations, it's possible we get a spurious trap...
  		 */
a73ad3331   H. Peter Anvin   x86: unify the im...
510
  		return;		/* Spurious trap, no error */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
511
512
513
  	}
  	force_sig_info(SIGFPE, &info, task);
  }
e407d6208   Alexander van Heukelum   x86, traps: intro...
514
  dotraplinkage void do_coprocessor_error(struct pt_regs *regs, long error_code)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
515
  {
081f75bbd   Alexander van Heukelum   traps: x86: make ...
516
  #ifdef CONFIG_X86_32
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
517
  	ignore_fpu_irq = 1;
081f75bbd   Alexander van Heukelum   traps: x86: make ...
518
  #endif
9b6dba9e0   Brian Gerst   x86: Merge simd_m...
519
  	math_error(regs, error_code, 16);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
520
  }
e407d6208   Alexander van Heukelum   x86, traps: intro...
521
522
  dotraplinkage void
  do_simd_coprocessor_error(struct pt_regs *regs, long error_code)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
523
  {
9b6dba9e0   Brian Gerst   x86: Merge simd_m...
524
  	math_error(regs, error_code, 19);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
525
  }
e407d6208   Alexander van Heukelum   x86, traps: intro...
526
527
  dotraplinkage void
  do_spurious_interrupt_bug(struct pt_regs *regs, long error_code)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
528
  {
cf81978d5   Alexander van Heukelum   i386: convert har...
529
  	conditional_sti(regs);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
530
531
  #if 0
  	/* No need to warn about this any longer. */
b5964405f   Ingo Molnar   x86: clean up tra...
532
533
  	printk(KERN_INFO "Ignoring P6 Local APIC Spurious Interrupt Bug...
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
534
535
  #endif
  }
081f75bbd   Alexander van Heukelum   traps: x86: make ...
536
  asmlinkage void __attribute__((weak)) smp_thermal_interrupt(void)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
537
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
538
  }
4efc0670b   Andi Kleen   x86, mce: use 64b...
539

7856f6cce   Andi Kleen   x86, mce: enable ...
540
  asmlinkage void __attribute__((weak)) smp_threshold_interrupt(void)
081f75bbd   Alexander van Heukelum   traps: x86: make ...
541
542
  {
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
543
  /*
e6e9cac8c   Jeremy Fitzhardinge   x86: split out co...
544
545
546
547
   * __math_state_restore assumes that cr0.TS is already clear and the
   * fpu state is all ready for use.  Used during context switch.
   */
  void __math_state_restore(void)
081f75bbd   Alexander van Heukelum   traps: x86: make ...
548
  {
e6e9cac8c   Jeremy Fitzhardinge   x86: split out co...
549
550
551
552
553
554
555
556
557
558
559
560
561
562
  	struct thread_info *thread = current_thread_info();
  	struct task_struct *tsk = thread->task;
  
  	/*
  	 * Paranoid restore. send a SIGSEGV if we fail to restore the state.
  	 */
  	if (unlikely(restore_fpu_checking(tsk))) {
  		stts();
  		force_sig(SIGSEGV, tsk);
  		return;
  	}
  
  	thread->status |= TS_USEDFPU;	/* So we fnsave on switch_to() */
  	tsk->fpu_counter++;
081f75bbd   Alexander van Heukelum   traps: x86: make ...
563
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
564
565
  
  /*
b5964405f   Ingo Molnar   x86: clean up tra...
566
   * 'math_state_restore()' saves the current math information in the
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
567
568
569
570
571
572
573
574
   * old math state array, and gets the new ones from the current task
   *
   * Careful.. There are problems with IBM-designed IRQ13 behaviour.
   * Don't touch unless you *really* know how it works.
   *
   * Must be called with kernel preemption disabled (in this case,
   * local interrupts are disabled at the call-site in entry.S).
   */
acc207616   Chuck Ebbert   [PATCH] i386: add...
575
  asmlinkage void math_state_restore(void)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
576
577
578
  {
  	struct thread_info *thread = current_thread_info();
  	struct task_struct *tsk = thread->task;
aa283f492   Suresh Siddha   x86, fpu: lazy al...
579
580
581
582
583
584
585
586
587
588
589
590
591
592
  	if (!tsk_used_math(tsk)) {
  		local_irq_enable();
  		/*
  		 * does a slab alloc which can sleep
  		 */
  		if (init_fpu(tsk)) {
  			/*
  			 * ran out of memory!
  			 */
  			do_group_exit(SIGKILL);
  			return;
  		}
  		local_irq_disable();
  	}
b5964405f   Ingo Molnar   x86: clean up tra...
593
  	clts();				/* Allow maths ops (or we recurse) */
fcb2ac5bd   Jiri Slaby   x86_32: introduce...
594

e6e9cac8c   Jeremy Fitzhardinge   x86: split out co...
595
  	__math_state_restore();
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
596
  }
5992b6dac   Rusty Russell   lguest: export sy...
597
  EXPORT_SYMBOL_GPL(math_state_restore);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
598

e407d6208   Alexander van Heukelum   x86, traps: intro...
599
  dotraplinkage void __kprobes
aa78bcfa0   Brian Gerst   x86: use pt_regs ...
600
  do_device_not_available(struct pt_regs *regs, long error_code)
7643e9b93   Alexander van Heukelum   i386: convert har...
601
  {
a334fe43d   Brian Gerst   x86-32, fpu: Remo...
602
  #ifdef CONFIG_MATH_EMULATION
7643e9b93   Alexander van Heukelum   i386: convert har...
603
  	if (read_cr0() & X86_CR0_EM) {
d315760ff   Tejun Heo   x86: fix math_emu...
604
  		struct math_emu_info info = { };
7643e9b93   Alexander van Heukelum   i386: convert har...
605
  		conditional_sti(regs);
d315760ff   Tejun Heo   x86: fix math_emu...
606

aa78bcfa0   Brian Gerst   x86: use pt_regs ...
607
  		info.regs = regs;
d315760ff   Tejun Heo   x86: fix math_emu...
608
  		math_emulate(&info);
a334fe43d   Brian Gerst   x86-32, fpu: Remo...
609
  		return;
7643e9b93   Alexander van Heukelum   i386: convert har...
610
  	}
a334fe43d   Brian Gerst   x86-32, fpu: Remo...
611
612
613
614
  #endif
  	math_state_restore(); /* interrupts still off */
  #ifdef CONFIG_X86_32
  	conditional_sti(regs);
081f75bbd   Alexander van Heukelum   traps: x86: make ...
615
  #endif
7643e9b93   Alexander van Heukelum   i386: convert har...
616
  }
081f75bbd   Alexander van Heukelum   traps: x86: make ...
617
  #ifdef CONFIG_X86_32
e407d6208   Alexander van Heukelum   x86, traps: intro...
618
  dotraplinkage void do_iret_error(struct pt_regs *regs, long error_code)
f8e0870f5   Alexander van Heukelum   i386: remove temp...
619
620
621
622
623
624
625
  {
  	siginfo_t info;
  	local_irq_enable();
  
  	info.si_signo = SIGILL;
  	info.si_errno = 0;
  	info.si_code = ILL_BADSTK;
fc6fcdfbb   Hannes Eder   x86: kexec/i386: ...
626
  	info.si_addr = NULL;
f8e0870f5   Alexander van Heukelum   i386: remove temp...
627
628
629
  	if (notify_die(DIE_TRAP, "iret exception",
  			regs, error_code, 32, SIGILL) == NOTIFY_STOP)
  		return;
3c1326f8a   Alexander van Heukelum   traps: i386: make...
630
  	do_trap(32, SIGILL, "iret exception", regs, error_code, &info);
f8e0870f5   Alexander van Heukelum   i386: remove temp...
631
  }
081f75bbd   Alexander van Heukelum   traps: x86: make ...
632
  #endif
f8e0870f5   Alexander van Heukelum   i386: remove temp...
633

29c843912   Jan Kiszka   x86, kgdb: early ...
634
635
636
637
638
639
640
641
642
  /* Set of traps needed for early debugging. */
  void __init early_trap_init(void)
  {
  	set_intr_gate_ist(1, &debug, DEBUG_STACK);
  	/* int3 can be called from all */
  	set_system_intr_gate_ist(3, &int3, DEBUG_STACK);
  	set_intr_gate(14, &page_fault);
  	load_idt(&idt_descr);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
643
644
  void __init trap_init(void)
  {
dbeb2be21   Rusty Russell   i386: introduce "...
645
  	int i;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
646
  #ifdef CONFIG_EISA
927222b10   Ingo Molnar   x86: fix EISA ior...
647
  	void __iomem *p = early_ioremap(0x0FFFD9, 4);
b5964405f   Ingo Molnar   x86: clean up tra...
648
649
  
  	if (readl(p) == 'E' + ('I'<<8) + ('S'<<16) + ('A'<<24))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
650
  		EISA_bus = 1;
927222b10   Ingo Molnar   x86: fix EISA ior...
651
  	early_iounmap(p, 4);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
652
  #endif
976382dcb   Alexander van Heukelum   i386: convert har...
653
  	set_intr_gate(0, &divide_error);
699d2937d   Alexander van Heukelum   traps: x86: conve...
654
  	set_intr_gate_ist(2, &nmi, NMI_STACK);
699d2937d   Alexander van Heukelum   traps: x86: conve...
655
656
  	/* int4 can be called from all */
  	set_system_intr_gate(4, &overflow);
64f644c0b   Alexander van Heukelum   i386: convert har...
657
  	set_intr_gate(5, &bounds);
12394cf56   Alexander van Heukelum   i386: convert har...
658
  	set_intr_gate(6, &invalid_op);
7643e9b93   Alexander van Heukelum   i386: convert har...
659
  	set_intr_gate(7, &device_not_available);
081f75bbd   Alexander van Heukelum   traps: x86: make ...
660
  #ifdef CONFIG_X86_32
a8c1be9d2   Alexander van Heukelum   x86: initial chan...
661
  	set_task_gate(8, GDT_ENTRY_DOUBLEFAULT_TSS);
081f75bbd   Alexander van Heukelum   traps: x86: make ...
662
663
664
  #else
  	set_intr_gate_ist(8, &double_fault, DOUBLEFAULT_STACK);
  #endif
51bc1ed60   Alexander van Heukelum   i386: convert har...
665
  	set_intr_gate(9, &coprocessor_segment_overrun);
6bf77bf93   Alexander van Heukelum   i386: convert har...
666
  	set_intr_gate(10, &invalid_TSS);
36d936c79   Alexander van Heukelum   i386: convert har...
667
  	set_intr_gate(11, &segment_not_present);
699d2937d   Alexander van Heukelum   traps: x86: conve...
668
  	set_intr_gate_ist(12, &stack_segment, STACKFAULT_STACK);
c6df0d71b   Alexander van Heukelum   i386: convert har...
669
  	set_intr_gate(13, &general_protection);
cf81978d5   Alexander van Heukelum   i386: convert har...
670
  	set_intr_gate(15, &spurious_interrupt_bug);
252d28fe6   Alexander van Heukelum   i386: convert har...
671
  	set_intr_gate(16, &coprocessor_error);
5feedfd40   Alexander van Heukelum   i386: convert har...
672
  	set_intr_gate(17, &alignment_check);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
673
  #ifdef CONFIG_X86_MCE
699d2937d   Alexander van Heukelum   traps: x86: conve...
674
  	set_intr_gate_ist(18, &machine_check, MCE_STACK);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
675
  #endif
b939bde27   Alexander van Heukelum   i386: convert har...
676
  	set_intr_gate(19, &simd_coprocessor_error);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
677

bb3f0b59a   Yinghai Lu   x86: make irqinit...
678
679
680
  	/* Reserve all the builtin and the syscall vector: */
  	for (i = 0; i < FIRST_EXTERNAL_VECTOR; i++)
  		set_bit(i, used_vectors);
081f75bbd   Alexander van Heukelum   traps: x86: make ...
681
682
  #ifdef CONFIG_IA32_EMULATION
  	set_system_intr_gate(IA32_SYSCALL_VECTOR, ia32_syscall);
bb3f0b59a   Yinghai Lu   x86: make irqinit...
683
  	set_bit(IA32_SYSCALL_VECTOR, used_vectors);
081f75bbd   Alexander van Heukelum   traps: x86: make ...
684
685
686
  #endif
  
  #ifdef CONFIG_X86_32
699d2937d   Alexander van Heukelum   traps: x86: conve...
687
  	set_system_trap_gate(SYSCALL_VECTOR, &system_call);
dbeb2be21   Rusty Russell   i386: introduce "...
688
  	set_bit(SYSCALL_VECTOR, used_vectors);
081f75bbd   Alexander van Heukelum   traps: x86: make ...
689
  #endif
bb3f0b59a   Yinghai Lu   x86: make irqinit...
690

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
691
  	/*
b5964405f   Ingo Molnar   x86: clean up tra...
692
  	 * Should be a barrier for any external CPU state:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
693
694
  	 */
  	cpu_init();
428cf9025   Thomas Gleixner   x86: Move traps_i...
695
  	x86_init.irqs.trap_init();
228bdaa95   Steven Rostedt   x86: Keep current...
696
697
698
699
700
701
  
  #ifdef CONFIG_X86_64
  	memcpy(&nmi_idt_table, &idt_table, IDT_ENTRIES * 16);
  	set_nmi_gate(1, &debug);
  	set_nmi_gate(3, &int3);
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
702
  }