2 // assembly portion of the IA64 MCA handling
4 // Mods by cfleck to integrate into kernel build
5 // 00/03/15 davidm Added various stop bits to get a clean compile
7 // 00/03/29 cfleck Added code to save INIT handoff state in pt_regs format, switch to temp
8 // kstack, switch modes, jump to C INIT handler
10 // 02/01/04 J.Hall <jenna.s.hall@intel.com>
11 // Before entering virtual mode code:
12 // 1. Check for TLB CPU error
13 // 2. Restore current thread pointer to kr6
14 // 3. Move stack ptr 16 bytes to conform to C calling convention
16 // 04/11/12 Russ Anderson <rja@sgi.com>
17 // Added per cpu MCA/INIT stack save areas.
19 #include <linux/config.h>
20 #include <linux/threads.h>
22 #include <asm/asmmacro.h>
23 #include <asm/pgtable.h>
24 #include <asm/processor.h>
25 #include <asm/mca_asm.h>
29 * When we get a machine check, the kernel stack pointer is no longer
30 * valid, so we need to set a new stack pointer.
32 #define MINSTATE_PHYS /* Make sure stack access is physical for MINSTATE */
35 * Needed for return context to SAL
37 #define IA64_MCA_SAME_CONTEXT 0
38 #define IA64_MCA_COLD_BOOT -2
43 * SAL_TO_OS_MCA_HANDOFF_STATE (SAL 3.0 spec)
45 * 2. GR8 = PAL_PROC physical address
46 * 3. GR9 = SAL_PROC physical address
47 * 4. GR10 = SAL GP (physical)
48 * 5. GR11 = Rendez state
49 * 6. GR12 = Return address to location within SAL_CHECK
51 #define SAL_TO_OS_MCA_HANDOFF_STATE_SAVE(_tmp) \
52 LOAD_PHYSICAL(p0, _tmp, ia64_sal_to_os_handoff_state);; \
53 st8 [_tmp]=r1,0x08;; \
54 st8 [_tmp]=r8,0x08;; \
55 st8 [_tmp]=r9,0x08;; \
56 st8 [_tmp]=r10,0x08;; \
57 st8 [_tmp]=r11,0x08;; \
58 st8 [_tmp]=r12,0x08;; \
59 st8 [_tmp]=r17,0x08;; \
63 * OS_MCA_TO_SAL_HANDOFF_STATE (SAL 3.0 spec)
64 * (p6) is executed if we never entered virtual mode (TLB error)
65 * (p7) is executed if we entered virtual mode as expected (normal case)
66 * 1. GR8 = OS_MCA return status
67 * 2. GR9 = SAL GP (physical)
68 * 3. GR10 = 0/1 returning same/new context
69 * 4. GR22 = New min state save area pointer
70 * returns ptr to SAL rtn save loc in _tmp
72 #define OS_MCA_TO_SAL_HANDOFF_STATE_RESTORE(_tmp) \
73 movl _tmp=ia64_os_to_sal_handoff_state;; \
74 DATA_VA_TO_PA(_tmp);; \
75 ld8 r8=[_tmp],0x08;; \
76 ld8 r9=[_tmp],0x08;; \
77 ld8 r10=[_tmp],0x08;; \
79 // now _tmp is pointing to SAL rtn save location
82 * COLD_BOOT_HANDOFF_STATE() sets ia64_mca_os_to_sal_state
83 * imots_os_status=IA64_MCA_COLD_BOOT
85 * imots_context=IA64_MCA_SAME_CONTEXT
86 * imots_new_min_state=Min state save area pointer
87 * imots_sal_check_ra=Return address to location within SAL_CHECK
90 #define COLD_BOOT_HANDOFF_STATE(sal_to_os_handoff,os_to_sal_handoff,tmp)\
91 movl tmp=IA64_MCA_COLD_BOOT; \
92 movl sal_to_os_handoff=__pa(ia64_sal_to_os_handoff_state); \
93 movl os_to_sal_handoff=__pa(ia64_os_to_sal_handoff_state);; \
94 st8 [os_to_sal_handoff]=tmp,8;; \
95 ld8 tmp=[sal_to_os_handoff],48;; \
96 st8 [os_to_sal_handoff]=tmp,8;; \
97 movl tmp=IA64_MCA_SAME_CONTEXT;; \
98 st8 [os_to_sal_handoff]=tmp,8;; \
99 ld8 tmp=[sal_to_os_handoff],-8;; \
100 st8 [os_to_sal_handoff]=tmp,8;; \
101 ld8 tmp=[sal_to_os_handoff];; \
102 st8 [os_to_sal_handoff]=tmp;;
104 #define GET_IA64_MCA_DATA(reg) \
105 GET_THIS_PADDR(reg, ia64_mca_data) \
109 .global ia64_os_mca_dispatch
110 .global ia64_os_mca_dispatch_end
111 .global ia64_sal_to_os_handoff_state
112 .global ia64_os_to_sal_handoff_state
117 ia64_os_mca_dispatch:
119 // Serialize all MCA processing
121 LOAD_PHYSICAL(p0,r2,ia64_mca_serialize);;
125 (p6) br ia64_os_mca_spin
127 // Save the SAL to OS MCA handoff state as defined
129 // NOTE : The order in which the state gets saved
130 // is dependent on the way the C-structure
131 // for ia64_mca_sal_to_os_state_t has been
132 // defined in include/asm/mca.h
133 SAL_TO_OS_MCA_HANDOFF_STATE_SAVE(r2)
136 // LOG PROCESSOR STATE INFO FROM HERE ON..
138 br ia64_os_mca_proc_state_dump;;
140 ia64_os_mca_done_dump:
142 LOAD_PHYSICAL(p0,r16,ia64_sal_to_os_handoff_state+56)
144 ld8 r18=[r16] // Get processor state parameter on existing PALE_CHECK.
147 (p7) br.spnt done_tlb_purge_and_reload
149 // The following code purges TC and TR entries. Then reload all TC entries.
150 // Purge percpu data TC entries.
151 begin_tlb_purge_and_reload:
153 #define O(member) IA64_CPUINFO_##member##_OFFSET
155 GET_THIS_PADDR(r2, cpu_info) // load phys addr of cpu_info into r2
157 addl r17=O(PTCE_STRIDE),r2
158 addl r2=O(PTCE_BASE),r2
160 ld8 r18=[r2],(O(PTCE_COUNT)-O(PTCE_BASE));; // r18=ptce_base
161 ld4 r19=[r2],4 // r19=ptce_count[0]
162 ld4 r21=[r17],4 // r21=ptce_stride[0]
164 ld4 r20=[r2] // r20=ptce_count[1]
165 ld4 r22=[r17] // r22=ptce_stride[1]
173 cmp.ltu p6,p7=r24,r19
174 (p7) br.cond.dpnt.few 4f
187 srlz.i // srlz.i implies srlz.d
190 // Now purge addresses formerly mapped by TR registers
191 // 1. Purge ITR&DTR for kernel.
192 movl r16=KERNEL_START
193 mov r18=KERNEL_TR_PAGE_SHIFT<<2
202 // 2. Purge DTR for PERCPU data.
204 mov r18=PERCPU_PAGE_SHIFT<<2
210 // 3. Purge ITR for PAL code.
211 GET_THIS_PADDR(r2, ia64_mca_pal_base)
214 mov r18=IA64_GRANULE_SHIFT<<2
220 // 4. Purge DTR for stack.
221 mov r16=IA64_KR(CURRENT_STACK)
223 shl r16=r16,IA64_GRANULE_SHIFT
227 mov r18=IA64_GRANULE_SHIFT<<2
233 // Finally reload the TR registers.
234 // 1. Reload DTR/ITR registers for kernel.
235 mov r18=KERNEL_TR_PAGE_SHIFT<<2
236 movl r17=KERNEL_START
240 mov r16=IA64_TR_KERNEL
244 dep r17=0,r19,0, KERNEL_TR_PAGE_SHIFT
255 // 2. Reload DTR register for PERCPU data.
256 GET_THIS_PADDR(r2, ia64_mca_per_cpu_pte)
258 movl r16=PERCPU_ADDR // vaddr
259 movl r18=PERCPU_PAGE_SHIFT<<2
264 ld8 r18=[r2] // load per-CPU PTE
265 mov r16=IA64_TR_PERCPU_DATA;
271 // 3. Reload ITR for PAL code.
272 GET_THIS_PADDR(r2, ia64_mca_pal_pte)
274 ld8 r18=[r2] // load PAL PTE
276 GET_THIS_PADDR(r2, ia64_mca_pal_base)
278 ld8 r16=[r2] // load PAL vaddr
279 mov r19=IA64_GRANULE_SHIFT<<2
283 mov r20=IA64_TR_PALCODE
289 // 4. Reload DTR for stack.
290 mov r16=IA64_KR(CURRENT_STACK)
292 shl r16=r16,IA64_GRANULE_SHIFT
299 mov r19=IA64_GRANULE_SHIFT<<2
303 mov r20=IA64_TR_CURRENT_STACK
309 br.sptk.many done_tlb_purge_and_reload
311 COLD_BOOT_HANDOFF_STATE(r20,r21,r22)
312 br.sptk.many ia64_os_mca_done_restore
314 done_tlb_purge_and_reload:
316 // Setup new stack frame for OS_MCA handling
317 GET_IA64_MCA_DATA(r2)
319 add r3 = IA64_MCA_CPU_STACKFRAME_OFFSET, r2
320 add r2 = IA64_MCA_CPU_RBSTORE_OFFSET, r2
322 rse_switch_context(r6,r3,r2);; // RSC management in this new context
324 GET_IA64_MCA_DATA(r2)
326 add r2 = IA64_MCA_CPU_STACK_OFFSET+IA64_MCA_STACK_SIZE-16, r2
328 mov r12=r2 // establish new stack-pointer
330 // Enter virtual mode from physical mode
331 VIRTUAL_MODE_ENTER(r2, r3, ia64_os_mca_virtual_begin, r4)
332 ia64_os_mca_virtual_begin:
334 // Call virtual mode handler
335 movl r2=ia64_mca_ucmc_handler;;
337 br.call.sptk.many b0=b6;;
339 // Revert back to physical mode before going back to SAL
340 PHYSICAL_MODE_ENTER(r2, r3, ia64_os_mca_virtual_end, r4)
341 ia64_os_mca_virtual_end:
343 // restore the original stack frame here
344 GET_IA64_MCA_DATA(r2)
346 add r2 = IA64_MCA_CPU_STACKFRAME_OFFSET, r2
350 rse_return_context(r4,r3,r2) // switch from interrupt context for RSE
352 // let us restore all the registers from our PSI structure
355 begin_os_mca_restore:
356 br ia64_os_mca_proc_state_restore;;
358 ia64_os_mca_done_restore:
359 OS_MCA_TO_SAL_HANDOFF_STATE_RESTORE(r2);;
360 // branch back to SALE_CHECK
362 mov b0=r3;; // SAL_CHECK return address
365 movl r3=ia64_mca_serialize;;
371 ia64_os_mca_dispatch_end:
372 //EndMain//////////////////////////////////////////////////////////////////////
377 // ia64_os_mca_proc_state_dump()
381 // This stub dumps the processor state during MCHK to a data area
385 ia64_os_mca_proc_state_dump:
386 // Save bank 1 GRs 16-31 which will be used by c-language code when we switch
387 // to virtual addressing mode.
388 GET_IA64_MCA_DATA(r2)
390 add r2 = IA64_MCA_CPU_PROC_STATE_DUMP_OFFSET, r2
393 mov r5=ar.unat // ar.unat
395 // save banked GRs 16-31 along with NaT bits
397 st8.spill [r2]=r16,8;;
398 st8.spill [r2]=r17,8;;
399 st8.spill [r2]=r18,8;;
400 st8.spill [r2]=r19,8;;
401 st8.spill [r2]=r20,8;;
402 st8.spill [r2]=r21,8;;
403 st8.spill [r2]=r22,8;;
404 st8.spill [r2]=r23,8;;
405 st8.spill [r2]=r24,8;;
406 st8.spill [r2]=r25,8;;
407 st8.spill [r2]=r26,8;;
408 st8.spill [r2]=r27,8;;
409 st8.spill [r2]=r28,8;;
410 st8.spill [r2]=r29,8;;
411 st8.spill [r2]=r30,8;;
412 st8.spill [r2]=r31,8;;
415 st8 [r2]=r4,8 // save User NaT bits for r16-r31
416 mov ar.unat=r5 // restore original unat
420 add r4=8,r2 // duplicate r2 in r4
421 add r6=2*8,r2 // duplicate r2 in r4
444 add r4=8,r2 // duplicate r2 in r4
445 add r6=2*8,r2 // duplicate r2 in r4
453 st8 [r6]=r7,3*8;; // 48 byte rements
456 st8 [r2]=r3,8*8;; // 64 byte rements
458 // if PSR.ic=0, reading interruption registers causes an illegal operation fault
460 tbit.nz.unc p6,p0=r3,PSR_IC;; // PSI Valid Log bit pos. test
461 (p6) st8 [r2]=r0,9*8+160 // increment by 232 byte inc.
462 begin_skip_intr_regs:
463 (p6) br SkipIntrRegs;;
465 add r4=8,r2 // duplicate r2 in r4
466 add r6=2*8,r2 // duplicate r2 in r6
489 mov r3=cr25;; // cr.iha
490 st8 [r2]=r3,160;; // 160 byte rement
493 st8 [r2]=r0,152;; // another 152 byte .
495 add r4=8,r2 // duplicate r2 in r4
496 add r6=2*8,r2 // duplicate r2 in r6
499 // mov r5=cr.ivr // cr.ivr, don't read it
505 mov r3=r0 // cr.eoi => cr67
506 mov r5=r0 // cr.irr0 => cr68
507 mov r7=r0;; // cr.irr1 => cr69
512 mov r3=r0 // cr.irr2 => cr70
513 mov r5=r0 // cr.irr3 => cr71
524 mov r3=r0 // cr.lrr0 => cr80
525 mov r5=r0;; // cr.lrr1 => cr81
533 add r4=8,r2 // duplicate r2 in r4
534 add r6=2*8,r2 // duplicate r2 in r6
552 mov r7=r0;; // ar.kr8
555 st8 [r6]=r7,10*8;; // rement by 72 bytes
558 mov ar.rsc=r0 // put RSE in enforced lazy mode
567 st8 [r2]=r3,8*13 // increment by 13x8 bytes
579 st8 [r2]=r3,160 // 160
589 add r2=8*62,r2 //padding
600 br.cloop.sptk.few cStRR
603 br ia64_os_mca_done_dump;;
605 //EndStub//////////////////////////////////////////////////////////////////////
610 // ia64_os_mca_proc_state_restore()
614 // This is a stub to restore the saved processor state during MCHK
618 ia64_os_mca_proc_state_restore:
620 // Restore bank1 GR16-31
621 GET_IA64_MCA_DATA(r2)
623 add r2 = IA64_MCA_CPU_PROC_STATE_DUMP_OFFSET, r2
625 restore_GRs: // restore bank-1 GRs 16-31
627 add r3=16*8,r2;; // to get to NaT of GR 16-31
629 mov ar.unat=r3;; // first restore NaT
631 ld8.fill r16=[r2],8;;
632 ld8.fill r17=[r2],8;;
633 ld8.fill r18=[r2],8;;
634 ld8.fill r19=[r2],8;;
635 ld8.fill r20=[r2],8;;
636 ld8.fill r21=[r2],8;;
637 ld8.fill r22=[r2],8;;
638 ld8.fill r23=[r2],8;;
639 ld8.fill r24=[r2],8;;
640 ld8.fill r25=[r2],8;;
641 ld8.fill r26=[r2],8;;
642 ld8.fill r27=[r2],8;;
643 ld8.fill r28=[r2],8;;
644 ld8.fill r29=[r2],8;;
645 ld8.fill r30=[r2],8;;
646 ld8.fill r31=[r2],8;;
648 ld8 r3=[r2],8;; // increment to skip NaT
652 add r4=8,r2 // duplicate r2 in r4
653 add r6=2*8,r2;; // duplicate r2 in r4
675 add r4=8,r2 // duplicate r2 in r4
676 add r6=2*8,r2;; // duplicate r2 in r4
680 ld8 r7=[r6],3*8;; // 48 byte increments
685 ld8 r3=[r2],8*8;; // 64 byte increments
689 // if PSR.ic=1, reading interruption registers causes an illegal operation fault
691 tbit.nz.unc p6,p0=r3,PSR_IC;; // PSI Valid Log bit pos. test
692 (p6) st8 [r2]=r0,9*8+160 // increment by 232 byte inc.
694 begin_rskip_intr_regs:
695 (p6) br rSkipIntrRegs;;
697 add r4=8,r2 // duplicate r2 in r4
698 add r6=2*8,r2;; // duplicate r2 in r4
704 // mov cr.isr=r5 // cr.isr is read only
720 ld8 r3=[r2],160;; // 160 byte increment
724 ld8 r3=[r2],152;; // another 152 byte inc.
726 add r4=8,r2 // duplicate r2 in r4
727 add r6=2*8,r2;; // duplicate r2 in r6
733 // mov cr.ivr=r5 // cr.ivr is read only
740 // mov cr.irr0=r5 // cr.irr0 is read only
741 // mov cr.irr1=r7;; // cr.irr1 is read only
746 // mov cr.irr2=r3 // cr.irr2 is read only
747 // mov cr.irr3=r5 // cr.irr3 is read only
765 add r4=8,r2 // duplicate r2 in r4
766 add r6=2*8,r2;; // duplicate r2 in r4
793 // mov ar.bsp=r5 // ar.bsp is read only
794 mov ar.rsc=r0 // make sure that RSE is in enforced lazy mode
811 ld8 r3=[r2],160;; // 160
822 add r2=8*62,r2;; // padding
831 mov rr[r7]=r3 // what are its access previledges?
833 br.cloop.sptk.few cStRRr
838 br ia64_os_mca_done_restore;;
840 //EndStub//////////////////////////////////////////////////////////////////////
843 // ok, the issue here is that we need to save state information so
844 // it can be useable by the kernel debugger and show regs routines.
845 // In order to do this, our best bet is save the current state (plus
846 // the state information obtain from the MIN_STATE_AREA) into a pt_regs
847 // format. This way we can pass it on in a useable format.
851 // SAL to OS entry point for INIT on the monarch processor
852 // This has been defined for registration purposes with SAL
853 // as a part of ia64_mca_init.
855 // When we get here, the following registers have been
856 // set by the SAL for our use
858 // 1. GR1 = OS INIT GP
859 // 2. GR8 = PAL_PROC physical address
860 // 3. GR9 = SAL_PROC physical address
861 // 4. GR10 = SAL GP (physical)
862 // 5. GR11 = Init Reason
863 // 0 = Received INIT for event other than crash dump switch
864 // 1 = Received wakeup at the end of an OS_MCA corrected machine check
865 // 2 = Received INIT dude to CrashDump switch assertion
867 // 6. GR12 = Return address to location within SAL_INIT procedure
870 GLOBAL_ENTRY(ia64_monarch_init_handler)
872 // stash the information the SAL passed to os
873 SAL_TO_OS_MCA_HANDOFF_STATE_SAVE(r2)
879 adds r3=8,r2 // set up second base pointer
883 // ok, enough should be saved at this point to be dangerous, and supply
884 // information for a dump
885 // We need to switch to Virtual mode before hitting the C functions.
887 movl r2=IA64_PSR_IT|IA64_PSR_IC|IA64_PSR_DT|IA64_PSR_RT|IA64_PSR_DFH|IA64_PSR_BN
888 mov r3=psr // get the current psr, minimum enabled at this point
892 movl r3=IVirtual_Switch
894 mov cr.iip=r3 // short return to set the appropriate bits
895 mov cr.ipsr=r2 // need to do an rfi to set appropriate bits
901 // We should now be running virtual
903 // Let's call the C handler to get the rest of the state info
905 alloc r14=ar.pfs,0,0,2,0 // now it's safe (must be first in insn group!)
907 adds out0=16,sp // out0 = pointer to pt_regs
911 adds out1=16,sp // out0 = pointer to switch_stack
913 br.call.sptk.many rp=ia64_init_handler
917 br.sptk return_from_init
918 END(ia64_monarch_init_handler)
921 // SAL to OS entry point for INIT on the slave processor
922 // This has been defined for registration purposes with SAL
923 // as a part of ia64_mca_init.
926 GLOBAL_ENTRY(ia64_slave_init_handler)
928 END(ia64_slave_init_handler)