2 * linux/arch/i386/traps.c
4 * Copyright (C) 1991, 1992 Linus Torvalds
6 * Pentium III FXSR, SSE support
7 * Gareth Hughes <gareth@valinux.com>, May 2000
11 * 'Traps.c' handles hardware traps and faults after we have saved some
14 #include <linux/config.h>
15 #include <linux/sched.h>
16 #include <linux/kernel.h>
17 #include <linux/string.h>
18 #include <linux/errno.h>
19 #include <linux/ptrace.h>
20 #include <linux/timer.h>
22 #include <linux/init.h>
23 #include <linux/delay.h>
24 #include <linux/spinlock.h>
25 #include <linux/interrupt.h>
28 #include <linux/mca.h>
29 #include <asm/processor.h>
32 #include <asm/system.h>
33 #include <asm/uaccess.h>
35 #include <asm/atomic.h>
36 #include <asm/debugreg.h>
41 #include <asm/pgalloc.h>
43 #ifdef CONFIG_X86_VISWS_APIC
44 #include <asm/fixmap.h>
45 #include <asm/cobalt.h>
46 #include <asm/lithium.h>
49 #include <linux/irq.h>
51 asmlinkage
int system_call(void);
52 asmlinkage
void lcall7(void);
53 asmlinkage
void lcall27(void);
55 struct desc_struct default_ldt
[] = { { 0, 0 }, { 0, 0 }, { 0, 0 },
59 * The IDT has to be page-aligned to simplify the Pentium
60 * F0 0F bug workaround.. We have a special link segment
63 struct desc_struct idt_table
[256] __attribute__((__section__(".data.idt"))) = { {0, 0}, };
65 extern void bust_spinlocks(void);
67 asmlinkage
void divide_error(void);
68 asmlinkage
void debug(void);
69 asmlinkage
void nmi(void);
70 asmlinkage
void int3(void);
71 asmlinkage
void overflow(void);
72 asmlinkage
void bounds(void);
73 asmlinkage
void invalid_op(void);
74 asmlinkage
void device_not_available(void);
75 asmlinkage
void double_fault(void);
76 asmlinkage
void coprocessor_segment_overrun(void);
77 asmlinkage
void invalid_TSS(void);
78 asmlinkage
void segment_not_present(void);
79 asmlinkage
void stack_segment(void);
80 asmlinkage
void general_protection(void);
81 asmlinkage
void page_fault(void);
82 asmlinkage
void coprocessor_error(void);
83 asmlinkage
void simd_coprocessor_error(void);
84 asmlinkage
void alignment_check(void);
85 asmlinkage
void spurious_interrupt_bug(void);
86 asmlinkage
void machine_check(void);
88 int kstack_depth_to_print
= 24;
91 * These constants are for searching for possible module text
92 * segments. MODULE_RANGE is a guess of how much space is likely
95 #define MODULE_RANGE (8*1024*1024)
97 void show_stack(unsigned long * esp
)
99 unsigned long *stack
, addr
, module_start
, module_end
;
102 // debugging aid: "show_stack(NULL);" prints the
103 // back trace for this cpu.
106 esp
=(unsigned long*)&esp
;
109 for(i
=0; i
< kstack_depth_to_print
; i
++) {
110 if (((long) stack
& (THREAD_SIZE
-1)) == 0)
112 if (i
&& ((i
% 8) == 0))
114 printk("%08lx ", *stack
++);
117 printk("\nCall Trace: ");
120 module_start
= VMALLOC_START
;
121 module_end
= VMALLOC_END
;
122 while (((long) stack
& (THREAD_SIZE
-1)) != 0) {
125 * If the address is either in the text segment of the
126 * kernel, or in the region which contains vmalloc'ed
127 * memory, it *may* be the address of a calling
128 * routine; if so, print it so that someone tracing
129 * down the cause of the crash will be able to figure
130 * out the call path that was taken.
132 if (((addr
>= (unsigned long) &_stext
) &&
133 (addr
<= (unsigned long) &_etext
)) ||
134 ((addr
>= module_start
) && (addr
<= module_end
))) {
135 if (i
&& ((i
% 8) == 0))
137 printk("[<%08lx>] ", addr
);
143 static void show_registers(struct pt_regs
*regs
)
150 esp
= (unsigned long) (®s
->esp
);
155 ss
= regs
->xss
& 0xffff;
157 printk("CPU: %d\nEIP: %04x:[<%08lx>]\nEFLAGS: %08lx\n",
158 smp_processor_id(), 0xffff & regs
->xcs
, regs
->eip
, regs
->eflags
);
159 printk("eax: %08lx ebx: %08lx ecx: %08lx edx: %08lx\n",
160 regs
->eax
, regs
->ebx
, regs
->ecx
, regs
->edx
);
161 printk("esi: %08lx edi: %08lx ebp: %08lx esp: %08lx\n",
162 regs
->esi
, regs
->edi
, regs
->ebp
, esp
);
163 printk("ds: %04x es: %04x ss: %04x\n",
164 regs
->xds
& 0xffff, regs
->xes
& 0xffff, ss
);
165 printk("Process %s (pid: %d, stackpage=%08lx)",
166 current
->comm
, current
->pid
, 4096+(unsigned long)current
);
168 * When in-kernel, we also print out the stack and code at the
169 * time of the fault..
174 show_stack((unsigned long*)esp
);
177 if(regs
->eip
< PAGE_OFFSET
)
183 if(__get_user(c
, &((unsigned char*)regs
->eip
)[i
])) {
185 printk(" Bad EIP value.");
194 spinlock_t die_lock
= SPIN_LOCK_UNLOCKED
;
196 void die(const char * str
, struct pt_regs
* regs
, long err
)
199 spin_lock_irq(&die_lock
);
200 printk("%s: %04lx\n", str
, err
& 0xffff);
201 show_registers(regs
);
203 spin_unlock_irq(&die_lock
);
207 static inline void die_if_kernel(const char * str
, struct pt_regs
* regs
, long err
)
209 if (!(regs
->eflags
& VM_MASK
) && !(3 & regs
->xcs
))
213 static inline unsigned long get_cr2(void)
215 unsigned long address
;
217 /* get the address */
218 __asm__("movl %%cr2,%0":"=r" (address
));
222 static void inline do_trap(int trapnr
, int signr
, char *str
, int vm86
,
223 struct pt_regs
* regs
, long error_code
, siginfo_t
*info
)
225 if (vm86
&& regs
->eflags
& VM_MASK
)
227 if (!(regs
->xcs
& 3))
231 struct task_struct
*tsk
= current
;
232 tsk
->thread
.error_code
= error_code
;
233 tsk
->thread
.trap_no
= trapnr
;
235 force_sig_info(signr
, info
, tsk
);
237 force_sig(signr
, tsk
);
242 unsigned long fixup
= search_exception_table(regs
->eip
);
246 die(str
, regs
, error_code
);
251 int ret
= handle_vm86_trap((struct kernel_vm86_regs
*) regs
, error_code
, trapnr
);
252 if (ret
) goto trap_signal
;
257 #define DO_ERROR(trapnr, signr, str, name) \
258 asmlinkage void do_##name(struct pt_regs * regs, long error_code) \
260 do_trap(trapnr, signr, str, 0, regs, error_code, NULL); \
263 #define DO_ERROR_INFO(trapnr, signr, str, name, sicode, siaddr) \
264 asmlinkage void do_##name(struct pt_regs * regs, long error_code) \
267 info.si_signo = signr; \
269 info.si_code = sicode; \
270 info.si_addr = (void *)siaddr; \
271 do_trap(trapnr, signr, str, 0, regs, error_code, &info); \
274 #define DO_VM86_ERROR(trapnr, signr, str, name) \
275 asmlinkage void do_##name(struct pt_regs * regs, long error_code) \
277 do_trap(trapnr, signr, str, 1, regs, error_code, NULL); \
280 #define DO_VM86_ERROR_INFO(trapnr, signr, str, name, sicode, siaddr) \
281 asmlinkage void do_##name(struct pt_regs * regs, long error_code) \
284 info.si_signo = signr; \
286 info.si_code = sicode; \
287 info.si_addr = (void *)siaddr; \
288 do_trap(trapnr, signr, str, 1, regs, error_code, &info); \
291 DO_VM86_ERROR_INFO( 0, SIGFPE
, "divide error", divide_error
, FPE_INTDIV
, regs
->eip
)
292 DO_VM86_ERROR( 3, SIGTRAP
, "int3", int3
)
293 DO_VM86_ERROR( 4, SIGSEGV
, "overflow", overflow
)
294 DO_VM86_ERROR( 5, SIGSEGV
, "bounds", bounds
)
295 DO_ERROR_INFO( 6, SIGILL
, "invalid operand", invalid_op
, ILL_ILLOPN
, regs
->eip
)
296 DO_VM86_ERROR( 7, SIGSEGV
, "device not available", device_not_available
)
297 DO_ERROR( 8, SIGSEGV
, "double fault", double_fault
)
298 DO_ERROR( 9, SIGFPE
, "coprocessor segment overrun", coprocessor_segment_overrun
)
299 DO_ERROR(10, SIGSEGV
, "invalid TSS", invalid_TSS
)
300 DO_ERROR(11, SIGBUS
, "segment not present", segment_not_present
)
301 DO_ERROR(12, SIGBUS
, "stack segment", stack_segment
)
302 DO_ERROR_INFO(17, SIGBUS
, "alignment check", alignment_check
, BUS_ADRALN
, get_cr2())
304 asmlinkage
void do_general_protection(struct pt_regs
* regs
, long error_code
)
306 if (regs
->eflags
& VM_MASK
)
309 if (!(regs
->xcs
& 3))
312 current
->thread
.error_code
= error_code
;
313 current
->thread
.trap_no
= 13;
314 force_sig(SIGSEGV
, current
);
318 handle_vm86_fault((struct kernel_vm86_regs
*) regs
, error_code
);
324 fixup
= search_exception_table(regs
->eip
);
329 die("general protection fault", regs
, error_code
);
333 static void mem_parity_error(unsigned char reason
, struct pt_regs
* regs
)
335 printk("Uhhuh. NMI received. Dazed and confused, but trying to continue\n");
336 printk("You probably have a hardware problem with your RAM chips\n");
338 /* Clear and disable the memory parity error line. */
339 reason
= (reason
& 0xf) | 4;
343 static void io_check_error(unsigned char reason
, struct pt_regs
* regs
)
347 printk("NMI: IOCK error (debug interrupt?)\n");
348 show_registers(regs
);
350 /* Re-enable the IOCK line, wait for a few seconds */
351 reason
= (reason
& 0xf) | 8;
354 while (--i
) udelay(1000);
359 static void unknown_nmi_error(unsigned char reason
, struct pt_regs
* regs
)
362 /* Might actually be able to figure out what the guilty party
369 printk("Uhhuh. NMI received for unknown reason %02x.\n", reason
);
370 printk("Dazed and confused, but trying to continue\n");
371 printk("Do you have a strange power saving mode enabled?\n");
374 #if CONFIG_X86_IO_APIC
376 int nmi_watchdog
= 1;
378 static int __init
setup_nmi_watchdog(char *str
)
380 get_option(&str
, &nmi_watchdog
);
384 __setup("nmi_watchdog=", setup_nmi_watchdog
);
386 static spinlock_t nmi_print_lock
= SPIN_LOCK_UNLOCKED
;
388 inline void nmi_watchdog_tick(struct pt_regs
* regs
)
391 * the best way to detect wether a CPU has a 'hard lockup' problem
392 * is to check it's local APIC timer IRQ counts. If they are not
393 * changing then that CPU has some problem.
395 * as these watchdog NMI IRQs are broadcasted to every CPU, here
396 * we only have to check the current processor.
398 * since NMIs dont listen to _any_ locks, we have to be extremely
399 * careful not to rely on unsafe variables. The printk might lock
400 * up though, so we have to break up console_lock first ...
401 * [when there will be more tty-related locks, break them up
405 static unsigned int last_irq_sums
[NR_CPUS
],
406 alert_counter
[NR_CPUS
];
409 * Since current-> is always on the stack, and we always switch
410 * the stack NMI-atomically, it's safe to use smp_processor_id().
412 int sum
, cpu
= smp_processor_id();
414 sum
= apic_timer_irqs
[cpu
];
416 if (last_irq_sums
[cpu
] == sum
) {
418 * Ayiee, looks like this CPU is stuck ...
419 * wait a few IRQs (5 seconds) before doing the oops ...
421 alert_counter
[cpu
]++;
422 if (alert_counter
[cpu
] == 5*HZ
) {
423 spin_lock(&nmi_print_lock
);
425 * We are in trouble anyway, lets at least try
426 * to get a message out.
429 printk("NMI Watchdog detected LOCKUP on CPU%d, registers:\n", cpu
);
430 show_registers(regs
);
431 printk("console shuts up ...\n");
433 spin_unlock(&nmi_print_lock
);
437 last_irq_sums
[cpu
] = sum
;
438 alert_counter
[cpu
] = 0;
443 asmlinkage
void do_nmi(struct pt_regs
* regs
, long error_code
)
445 unsigned char reason
= inb(0x61);
448 ++nmi_count(smp_processor_id());
449 if (!(reason
& 0xc0)) {
450 #if CONFIG_X86_IO_APIC
452 * Ok, so this is none of the documented NMI sources,
453 * so it must be the NMI watchdog.
456 nmi_watchdog_tick(regs
);
459 unknown_nmi_error(reason
, regs
);
461 unknown_nmi_error(reason
, regs
);
466 mem_parity_error(reason
, regs
);
468 io_check_error(reason
, regs
);
470 * Reassert NMI in case it became active meanwhile
471 * as it's edge-triggered.
474 inb(0x71); /* dummy */
476 inb(0x71); /* dummy */
480 * Our handling of the processor debug registers is non-trivial.
481 * We do not clear them on entry and exit from the kernel. Therefore
482 * it is possible to get a watchpoint trap here from inside the kernel.
483 * However, the code in ./ptrace.c has ensured that the user can
484 * only set watchpoints on userspace addresses. Therefore the in-kernel
485 * watchpoint trap can only occur in code which is reading/writing
486 * from user space. Such code must not hold kernel locks (since it
487 * can equally take a page fault), therefore it is safe to call
488 * force_sig_info even though that claims and releases locks.
490 * Code in ./signal.c ensures that the debug control register
491 * is restored before we deliver any signal, and therefore that
492 * user code runs with the correct debug control register even though
495 * Being careful here means that we don't have to be as careful in a
496 * lot of more complicated places (task switching can be a bit lazy
497 * about restoring all the debug state, and ptrace doesn't have to
498 * find every occurrence of the TF bit that could be saved away even
501 asmlinkage
void do_debug(struct pt_regs
* regs
, long error_code
)
503 unsigned int condition
;
504 struct task_struct
*tsk
= current
;
507 __asm__
__volatile__("movl %%db6,%0" : "=r" (condition
));
509 /* Mask out spurious debug traps due to lazy DR7 setting */
510 if (condition
& (DR_TRAP0
|DR_TRAP1
|DR_TRAP2
|DR_TRAP3
)) {
511 if (!tsk
->thread
.debugreg
[7])
515 if (regs
->eflags
& VM_MASK
)
518 /* Save debug status register where ptrace can see it */
519 tsk
->thread
.debugreg
[6] = condition
;
521 /* Mask out spurious TF errors due to lazy TF clearing */
522 if (condition
& DR_STEP
) {
524 * The TF error should be masked out only if the current
525 * process is not traced and if the TRAP flag has been set
526 * previously by a tracing process (condition detected by
527 * the PT_DTRACE flag); remember that the i386 TRAP flag
528 * can be modified by the process itself in user mode,
529 * allowing programs to debug themselves without the ptrace()
532 if ((tsk
->ptrace
& (PT_DTRACE
|PT_PTRACED
)) == PT_DTRACE
)
536 /* Ok, finally something we can handle */
537 tsk
->thread
.trap_no
= 1;
538 tsk
->thread
.error_code
= error_code
;
539 info
.si_signo
= SIGTRAP
;
541 info
.si_code
= TRAP_BRKPT
;
543 /* If this is a kernel mode trap, save the user PC on entry to
544 * the kernel, that's what the debugger can make sense of.
546 info
.si_addr
= ((regs
->xcs
& 3) == 0) ? (void *)tsk
->thread
.eip
:
548 force_sig_info(SIGTRAP
, &info
, tsk
);
550 /* Disable additional traps. They'll be re-enabled when
551 * the signal is delivered.
554 __asm__("movl %0,%%db7"
560 handle_vm86_trap((struct kernel_vm86_regs
*) regs
, error_code
, 1);
564 regs
->eflags
&= ~TF_MASK
;
569 * Note that we play around with the 'TS' bit in an attempt to get
570 * the correct behaviour even in the presence of the asynchronous
573 void math_error(void *eip
)
575 struct task_struct
* task
;
577 unsigned short cwd
, swd
;
580 * Save the info for the exception handler and clear the error.
584 task
->thread
.trap_no
= 16;
585 task
->thread
.error_code
= 0;
586 info
.si_signo
= SIGFPE
;
588 info
.si_code
= __SI_FAULT
;
591 * (~cwd & swd) will mask out exceptions that are not set to unmasked
592 * status. 0x3f is the exception bits in these regs, 0x200 is the
593 * C1 reg you need in case of a stack fault, 0x040 is the stack
594 * fault bit. We should only be taking one exception at a time,
595 * so if this combination doesn't produce any single exception,
596 * then we have a bad program that isn't syncronizing its FPU usage
597 * and it will suffer the consequences since we won't be able to
598 * fully reproduce the context of the exception
600 cwd
= get_fpu_cwd(task
);
601 swd
= get_fpu_swd(task
);
602 switch (((~cwd
) & swd
& 0x3f) | (swd
& 0x240)) {
606 case 0x001: /* Invalid Op */
607 case 0x040: /* Stack Fault */
608 case 0x240: /* Stack Fault | Direction */
609 info
.si_code
= FPE_FLTINV
;
611 case 0x002: /* Denormalize */
612 case 0x010: /* Underflow */
613 info
.si_code
= FPE_FLTUND
;
615 case 0x004: /* Zero Divide */
616 info
.si_code
= FPE_FLTDIV
;
618 case 0x008: /* Overflow */
619 info
.si_code
= FPE_FLTOVF
;
621 case 0x020: /* Precision */
622 info
.si_code
= FPE_FLTRES
;
625 force_sig_info(SIGFPE
, &info
, task
);
628 asmlinkage
void do_coprocessor_error(struct pt_regs
* regs
, long error_code
)
631 math_error((void *)regs
->eip
);
634 void simd_math_error(void *eip
)
636 struct task_struct
* task
;
638 unsigned short mxcsr
;
641 * Save the info for the exception handler and clear the error.
645 task
->thread
.trap_no
= 19;
646 task
->thread
.error_code
= 0;
647 info
.si_signo
= SIGFPE
;
649 info
.si_code
= __SI_FAULT
;
652 * The SIMD FPU exceptions are handled a little differently, as there
653 * is only a single status/control register. Thus, to determine which
654 * unmasked exception was caught we must mask the exception mask bits
655 * at 0x1f80, and then use these to mask the exception bits at 0x3f.
657 mxcsr
= get_fpu_mxcsr(task
);
658 switch (~((mxcsr
& 0x1f80) >> 7) & (mxcsr
& 0x3f)) {
662 case 0x001: /* Invalid Op */
663 info
.si_code
= FPE_FLTINV
;
665 case 0x002: /* Denormalize */
666 case 0x010: /* Underflow */
667 info
.si_code
= FPE_FLTUND
;
669 case 0x004: /* Zero Divide */
670 info
.si_code
= FPE_FLTDIV
;
672 case 0x008: /* Overflow */
673 info
.si_code
= FPE_FLTOVF
;
675 case 0x020: /* Precision */
676 info
.si_code
= FPE_FLTRES
;
679 force_sig_info(SIGFPE
, &info
, task
);
682 asmlinkage
void do_simd_coprocessor_error(struct pt_regs
* regs
,
686 /* Handle SIMD FPU exceptions on PIII+ processors. */
688 simd_math_error((void *)regs
->eip
);
691 * Handle strange cache flush from user space exception
692 * in all other cases. This is undocumented behaviour.
694 if (regs
->eflags
& VM_MASK
) {
695 handle_vm86_fault((struct kernel_vm86_regs
*)regs
,
699 die_if_kernel("cache flush denied", regs
, error_code
);
700 current
->thread
.trap_no
= 19;
701 current
->thread
.error_code
= error_code
;
702 force_sig(SIGSEGV
, current
);
706 asmlinkage
void do_spurious_interrupt_bug(struct pt_regs
* regs
,
710 /* No need to warn about this any longer. */
711 printk("Ignoring P6 Local APIC Spurious Interrupt Bug...\n");
716 * 'math_state_restore()' saves the current math information in the
717 * old math state array, and gets the new ones from the current task
719 * Careful.. There are problems with IBM-designed IRQ13 behaviour.
720 * Don't touch unless you *really* know how it works.
722 asmlinkage
void math_state_restore(struct pt_regs regs
)
724 __asm__
__volatile__("clts"); /* Allow maths ops (or we recurse) */
726 if (current
->used_math
) {
727 restore_fpu(current
);
731 current
->flags
|= PF_USEDFPU
; /* So we fnsave on switch_to() */
734 #ifndef CONFIG_MATH_EMULATION
736 asmlinkage
void math_emulate(long arg
)
738 printk("math-emulation not enabled and no coprocessor found.\n");
739 printk("killing %s.\n",current
->comm
);
740 force_sig(SIGFPE
,current
);
744 #endif /* CONFIG_MATH_EMULATION */
747 void __init
trap_init_f00f_bug(void)
755 * Allocate a new page in virtual address space,
756 * move the IDT into it and write protect this page.
758 page
= (unsigned long) vmalloc(PAGE_SIZE
);
759 pgd
= pgd_offset(&init_mm
, page
);
760 pmd
= pmd_offset(pgd
, page
);
761 pte
= pte_offset(pmd
, page
);
762 __free_page(pte_page(*pte
));
763 *pte
= mk_pte_phys(__pa(&idt_table
), PAGE_KERNEL_RO
);
765 * Not that any PGE-capable kernel should have the f00f bug ...
770 * "idt" is magic - it overlaps the idt_descr
771 * variable so that updating idt will automatically
772 * update the idt descriptor..
774 idt
= (struct desc_struct
*)page
;
775 __asm__
__volatile__("lidt %0": "=m" (idt_descr
));
779 #define _set_gate(gate_addr,type,dpl,addr) \
782 __asm__ __volatile__ ("movw %%dx,%%ax\n\t" \
784 "movl %%eax,%0\n\t" \
786 :"=m" (*((long *) (gate_addr))), \
787 "=m" (*(1+(long *) (gate_addr))), "=&a" (__d0), "=&d" (__d1) \
788 :"i" ((short) (0x8000+(dpl<<13)+(type<<8))), \
789 "3" ((char *) (addr)),"2" (__KERNEL_CS << 16)); \
794 * This needs to use 'idt_table' rather than 'idt', and
795 * thus use the _nonmapped_ version of the IDT, as the
796 * Pentium F0 0F bugfix can have resulted in the mapped
797 * IDT being write-protected.
799 void set_intr_gate(unsigned int n
, void *addr
)
801 _set_gate(idt_table
+n
,14,0,addr
);
804 static void __init
set_trap_gate(unsigned int n
, void *addr
)
806 _set_gate(idt_table
+n
,15,0,addr
);
809 static void __init
set_system_gate(unsigned int n
, void *addr
)
811 _set_gate(idt_table
+n
,15,3,addr
);
814 static void __init
set_call_gate(void *a
, void *addr
)
816 _set_gate(a
,12,3,addr
);
819 #define _set_seg_desc(gate_addr,type,dpl,base,limit) {\
820 *((gate_addr)+1) = ((base) & 0xff000000) | \
821 (((base) & 0x00ff0000)>>16) | \
822 ((limit) & 0xf0000) | \
826 *(gate_addr) = (((base) & 0x0000ffff)<<16) | \
827 ((limit) & 0x0ffff); }
829 #define _set_tssldt_desc(n,addr,limit,type) \
830 __asm__ __volatile__ ("movw %w3,0(%2)\n\t" \
831 "movw %%ax,2(%2)\n\t" \
832 "rorl $16,%%eax\n\t" \
833 "movb %%al,4(%2)\n\t" \
834 "movb %4,5(%2)\n\t" \
835 "movb $0,6(%2)\n\t" \
836 "movb %%ah,7(%2)\n\t" \
838 : "=m"(*(n)) : "a" (addr), "r"(n), "ir"(limit), "i"(type))
840 void set_tss_desc(unsigned int n
, void *addr
)
842 _set_tssldt_desc(gdt_table
+__TSS(n
), (int)addr
, 235, 0x89);
845 void set_ldt_desc(unsigned int n
, void *addr
, unsigned int size
)
847 _set_tssldt_desc(gdt_table
+__LDT(n
), (int)addr
, ((size
<< 3)-1), 0x82);
850 #ifdef CONFIG_X86_VISWS_APIC
853 * On Rev 005 motherboards legacy device interrupt lines are wired directly
854 * to Lithium from the 307. But the PROM leaves the interrupt type of each
855 * 307 logical device set appropriate for the 8259. Later we'll actually use
856 * the 8259, but for now we have to flip the interrupt types to
857 * level triggered, active lo as required by Lithium.
860 #define REG 0x2e /* The register to read/write */
861 #define DEV 0x07 /* Register: Logical device select */
862 #define VAL 0x2f /* The value to read/write */
865 superio_outb(int dev
, int reg
, int val
)
873 static int __attribute__ ((unused
))
874 superio_inb(int dev
, int reg
)
882 #define FLOP 3 /* floppy logical device */
883 #define PPORT 4 /* parallel logical device */
884 #define UART5 5 /* uart2 logical device (not wired up) */
885 #define UART6 6 /* uart1 logical device (THIS is the serial port!) */
886 #define IDEST 0x70 /* int. destination (which 307 IRQ line) reg. */
887 #define ITYPE 0x71 /* interrupt type register */
889 /* interrupt type bits */
890 #define LEVEL 0x01 /* bit 0, 0 == edge triggered */
891 #define ACTHI 0x02 /* bit 1, 0 == active lo */
896 if (visws_board_type
== VISWS_320
&& visws_board_rev
== 5) {
897 superio_outb(UART6
, IDEST
, 0); /* 0 means no intr propagated */
898 printk("SGI 320 rev 5: disabling 307 uart1 interrupt\n");
905 set_fixmap(FIX_LI_PCIA
, LI_PCI_A_PHYS
);
906 printk("Lithium PCI Bridge A, Bus Number: %d\n",
907 li_pcia_read16(LI_PCI_BUSNUM
) & 0xff);
908 set_fixmap(FIX_LI_PCIB
, LI_PCI_B_PHYS
);
909 printk("Lithium PCI Bridge B (PIIX4), Bus Number: %d\n",
910 li_pcib_read16(LI_PCI_BUSNUM
) & 0xff);
912 /* XXX blindly enables all interrupts */
913 li_pcia_write16(LI_PCI_INTEN
, 0xffff);
914 li_pcib_write16(LI_PCI_INTEN
, 0xffff);
921 * On normal SMP PC this is used only with SMP, but we have to
922 * use it and set it up here to start the Cobalt clock
924 set_fixmap(FIX_APIC_BASE
, APIC_DEFAULT_PHYS_BASE
);
925 printk("Local APIC ID %lx\n", apic_read(APIC_ID
));
926 printk("Local APIC Version %lx\n", apic_read(APIC_LVR
));
928 set_fixmap(FIX_CO_CPU
, CO_CPU_PHYS
);
929 printk("Cobalt Revision %lx\n", co_cpu_read(CO_CPU_REV
));
931 set_fixmap(FIX_CO_APIC
, CO_APIC_PHYS
);
932 printk("Cobalt APIC ID %lx\n", co_apic_read(CO_APIC_ID
));
934 /* Enable Cobalt APIC being careful to NOT change the ID! */
935 co_apic_write(CO_APIC_ID
, co_apic_read(CO_APIC_ID
)|CO_APIC_ENABLE
);
937 printk("Cobalt APIC enabled: ID reg %lx\n", co_apic_read(CO_APIC_ID
));
940 void __init
trap_init(void)
943 if (isa_readl(0x0FFFD9) == 'E'+('I'<<8)+('S'<<16)+('A'<<24))
947 set_trap_gate(0,÷_error
);
948 set_trap_gate(1,&debug
);
949 set_intr_gate(2,&nmi
);
950 set_system_gate(3,&int3
); /* int3-5 can be called from all */
951 set_system_gate(4,&overflow
);
952 set_system_gate(5,&bounds
);
953 set_trap_gate(6,&invalid_op
);
954 set_trap_gate(7,&device_not_available
);
955 set_trap_gate(8,&double_fault
);
956 set_trap_gate(9,&coprocessor_segment_overrun
);
957 set_trap_gate(10,&invalid_TSS
);
958 set_trap_gate(11,&segment_not_present
);
959 set_trap_gate(12,&stack_segment
);
960 set_trap_gate(13,&general_protection
);
961 set_trap_gate(14,&page_fault
);
962 set_trap_gate(15,&spurious_interrupt_bug
);
963 set_trap_gate(16,&coprocessor_error
);
964 set_trap_gate(17,&alignment_check
);
965 set_trap_gate(18,&machine_check
);
966 set_trap_gate(19,&simd_coprocessor_error
);
968 set_system_gate(SYSCALL_VECTOR
,&system_call
);
971 * default LDT is a single-entry callgate to lcall7 for iBCS
972 * and a callgate to lcall27 for Solaris/x86 binaries
974 set_call_gate(&default_ldt
[0],lcall7
);
975 set_call_gate(&default_ldt
[4],lcall27
);
978 * Should be a barrier for any external CPU state.
982 #ifdef CONFIG_X86_VISWS_APIC