2 /// Low level IPF routines used by the debug support driver
4 /// Copyright (c) 2006 - 2008, Intel Corporation
5 /// All rights reserved. This program and the accompanying materials
6 /// are licensed and made available under the terms and conditions of the BSD License
7 /// which accompanies this distribution. The full text of the license may be found at
8 /// http://opensource.org/licenses/bsd-license.php
10 /// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 /// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 /// Module Name: AsmFuncs.s
19 #include "Ds64Macros.i"
21 .globl PatchSaveBuffer
24 .globl ExternalInterruptCount
27 /////////////////////////////////////////////
30 // InstructionCacheFlush
33 // Flushes instruction cache for specified number of bytes
35 .globl InstructionCacheFlush
36 .proc InstructionCacheFlush
38 InstructionCacheFlush::
41 cmp4.leu p0,p6=32, r33;;
52 (p7) adds r28=1, r28;;
68 cmp.ltu p14,p15=r32, r31
73 //(p14) br.cond.dptk.few $L143#;;
74 (p14) br.cond.dptk.few LoopBack;;
86 .endp InstructionCacheFlush
89 /////////////////////////////////////////////
95 // Chains an interrupt handler
97 // The purpose of this function is to enable chaining of the external interrupt.
98 // Since there's no clean SAL abstraction for doing this, we must do it
101 // The reserved IVT entry at offset 0x3400 is coopted for use by this handler.
102 // According to Itanium architecture, it is reserved. Strictly speaking, this is
103 // not safe, as we're cheating and violating the Itanium architecture. However,
104 // as long as we're the only ones cheating, we should be OK. Without hooks in
105 // the SAL to enable IVT management, there aren't many good options.
107 // The strategy is to replace the first bundle of the external interrupt handler
108 // with our own that will branch into a piece of code we've supplied and located
109 // in the reserved IVT entry. Only the first bundle of the external interrupt
110 // IVT entry is modified.
112 // The original bundle is moved and relocated to space
113 // allocated within the reserved IVT entry. The next bundle following is
114 // is generated to go a hard coded branch back to the second bundle of the
115 // external interrupt IVT entry just in case the first bundle had no branch.
117 // Our new code will execute our handler, and then fall through to the
118 // original bundle after restoring all context appropriately.
120 // The following is a representation of what the IVT memory map looks like with
121 // our chained handler installed:
127 // This IVT entry is Failsafe bundle
129 // Itanium architecture Original bundle 0
133 // original bundle Patch code...
137 // RSVD (3400) Unused
150 // EXT_INT (3000) Bundle 0 Bundle zero - This one is
151 // modified, all other bundles
152 // in the EXT_INT entry are
167 NESTED_SETUP( 0,2+3,3,0 )
169 mov r8=1 // r8 = success
172 // NOTE: There's a potential hazard here in that we're simply stealing a bunch of
173 // bundles (memory) from the IVT and assuming there's no catastrophic side effect.
175 // First, save IVT area we're taking over with the patch so we can restore it later
177 addl out0=PATCH_ENTRY_OFFSET, r2 // out0 = source buffer
178 movl out1=PatchSaveBuffer // out1 = destination buffer
179 mov out2=0x40;; // out2 = number of bundles to copy... save entire IDT entry
180 br.call.sptk.few b0 = CopyBundles
182 // Next, copy the patch code into the IVT
183 movl out0=PatchCode // out0 = source buffer of patch code
184 addl out1=PATCH_OFFSET, r2 // out1 = destination buffer - in IVT
185 mov out2=PATCH_CODE_SIZE;;
186 shr out2=out2, 4;; // out2 = number of bundles to copy
187 br.call.sptk.few b0 = CopyBundles
190 // copy original bundle 0 from the external interrupt handler to the
191 // appropriate place in the reserved IVT interrupt slot
192 addl out0=EXT_INT_ENTRY_OFFSET, r2 // out0 = source buffer
193 addl out1=RELOCATED_EXT_INT, r2 // out1 = destination buffer - in reserved IVT
194 mov out2=1;; // out2 = copy 1 bundle
195 br.call.sptk.few b0 = CopyBundles
197 // Now relocate it there because it very likely had a branch instruction that
198 // that must now be fixed up.
199 addl out0=RELOCATED_EXT_INT, r2 // out0 = new runtime address of bundle - in reserved IVT
200 addl out1=EXT_INT_ENTRY_OFFSET, r2;;// out1 = IP address of previous location
201 mov out2=out0;; // out2 = IP address of new location
202 br.call.sptk.few b0 = RelocateBundle
204 // Now copy into the failsafe branch into the next bundle just in case
205 // the original ext int bundle 0 bundle did not contain a branch instruction
206 movl out0=FailsafeBranch // out0 = source buffer
207 addl out1=FAILSAFE_BRANCH_OFFSET, r2 // out1 = destination buffer - in reserved IVT
208 mov out2=1;; // out2 = copy 1 bundle
209 br.call.sptk.few b0 = CopyBundles
211 // Last, copy in our replacement for the external interrupt IVT entry bundle 0
212 movl out0=PatchCodeNewBun0 // out0 = source buffer - our replacement bundle 0
213 addl out1=EXT_INT_ENTRY_OFFSET, r2 // out1 = destination buffer - bundle 0 of External interrupt entry
214 mov out2=1;; // out2 = copy 1 bundle
215 br.call.sptk.few b0 = CopyBundles
223 /////////////////////////////////////////////
229 // Unchains an interrupt handler
238 .globl UnchainHandler
243 NESTED_SETUP( 0,2+3,3,0 )
245 mov r8=1 // r8 = success
246 mov r2=cr.iva;; // r2 = interrupt vector address
248 // First copy original Ext Int bundle 0 back to it's proper home...
249 addl out0=RELOCATED_EXT_INT, r2 // out0 = source - in reserved IVT
250 addl out1=EXT_INT_ENTRY_OFFSET, r2 // out1 = destination buffer - first bundle of Ext Int entry
251 mov out2=1;; // out2 = copy 1 bundle
252 br.call.sptk.few b0 = CopyBundles
254 // Now, relocate it again...
255 addl out0=EXT_INT_ENTRY_OFFSET, r2 // out1 = New runtime address
256 addl out1=RELOCATED_EXT_INT, r2;; // out0 = IP address of previous location
257 mov out2=out0;; // out2 = IP address of new location
258 br.call.sptk.few b0 = RelocateBundle
260 // Last, restore the patch area
261 movl out0=PatchSaveBuffer // out0 = source buffer
262 addl out1=PATCH_ENTRY_OFFSET, r2 // out1 = destination buffer
263 mov out2=0x40;; // out2 = number of bundles to copy... save entire IDT entry
264 br.call.sptk.few b0 = CopyBundles
272 /////////////////////////////////////////////
278 // Copies instruction bundles - flushes icache as necessary
281 // in0 - Bundle source
282 // in1 - Bundle destination
283 // in2 - Bundle count
288 // This procedure is a leaf routine
294 NESTED_SETUP(3,2+1,0,0)
296 shl in2=in2, 1;; // in2 = count of 8 byte blocks to copy
300 cmp.eq p14, p15 = 0, in2;; // Check if done
301 (p14) br.sptk.few CopyBundlesDone;;
303 ld8 loc2=[in0], 0x8;; // loc2 = source bytes
304 st8 [in1]=loc2;; // [in1] = destination bytes
305 fc in1;; // Flush instruction cache
306 sync.i;; // Ensure local and remote data/inst caches in sync
307 srlz.i;; // Ensure sync has been observed
308 add in1=0x8, in1;; // in1 = next destination
309 add in2=-1, in2;; // in2 = decrement 8 bytes blocks to copy
310 br.sptk.few CopyBundlesLoop;;
318 /////////////////////////////////////////////
324 // Relocates an instruction bundle by updating any ip-relative branch instructions.
327 // in0 - Runtime address of bundle
328 // in1 - IP address of previous location of bundle
329 // in2 - IP address of new location of bundle
332 // in0 - 1 if successful or 0 if unsuccessful
335 // This routine examines all slots in the given bundle that are destined for the
336 // branch execution unit. If any of these slots contain an IP-relative branch
337 // namely instructions B1, B2, B3, or B6, the slot is fixed-up with a new relative
338 // address. Errors can occur if a branch cannot be reached.
344 NESTED_SETUP(3,2+4,3,0)
346 mov loc2=SLOT0 // loc2 = slot index
347 mov loc5=in0;; // loc5 = runtime address of bundle
348 mov in0=1;; // in0 = success
350 RelocateBundleNextSlot:
352 cmp.ge p14, p15 = SLOT2, loc2;; // Check if maximum slot
353 (p15) br.sptk.few RelocateBundleDone
355 mov out0=loc5;; // out0 = runtime address of bundle
356 br.call.sptk.few b0 = GetTemplate
357 mov loc3=out0;; // loc3 = instruction template
358 mov out0=loc5 // out0 = runtime address of bundle
359 mov out1=loc2;; // out1 = instruction slot number
360 br.call.sptk.few b0 = GetSlot
361 mov loc4=out0;; // loc4 = instruction encoding
362 mov out0=loc4 // out0 = instuction encoding
363 mov out1=loc2 // out1 = instruction slot number
364 mov out2=loc3;; // out2 = instruction template
365 br.call.sptk.few b0 = IsSlotBranch
366 cmp.eq p14, p15 = 1, out0;; // Check if branch slot
367 (p15) add loc2=1,loc2 // Increment slot
368 (p15) br.sptk.few RelocateBundleNextSlot
369 mov out0=loc4 // out0 = instuction encoding
370 mov out1=in1 // out1 = IP address of previous location
371 mov out2=in2;; // out2 = IP address of new location
372 br.call.sptk.few b0 = RelocateSlot
373 cmp.eq p14, p15 = 1, out1;; // Check if relocated slot
374 (p15) mov in0=0 // in0 = failure
375 (p15) br.sptk.few RelocateBundleDone
376 mov out2=out0;; // out2 = instruction encoding
377 mov out0=loc5 // out0 = runtime address of bundle
378 mov out1=loc2;; // out1 = instruction slot number
379 br.call.sptk.few b0 = SetSlot
380 add loc2=1,loc2;; // Increment slot
381 br.sptk.few RelocateBundleNextSlot
389 /////////////////////////////////////////////
395 // Relocates an instruction bundle by updating any ip-relative branch instructions.
398 // in0 - Instruction encoding (41-bits, right justified)
399 // in1 - IP address of previous location of bundle
400 // in2 - IP address of new location of bundle
403 // in0 - Instruction encoding (41-bits, right justified)
404 // in1 - 1 if successful otherwise 0
407 // This procedure is a leaf routine
412 NESTED_SETUP(3,2+5,0,0)
413 extr.u loc2=in0, 37, 4;; // loc2 = instruction opcode
414 cmp.eq p14, p15 = 4, loc2;; // IP-relative branch (B1) or
415 // IP-relative counted branch (B2)
416 (p15) cmp.eq p14, p15 = 5, loc2;; // IP-relative call (B3)
417 (p15) cmp.eq p14, p15 = 7, loc2;; // IP-relative predict (B6)
418 (p15) mov in1=1 // Instruction did not need to be reencoded
419 (p15) br.sptk.few RelocateSlotDone
420 tbit.nz p14, p15 = in0, 36;; // put relative offset sign bit in p14
421 extr.u loc2=in0, 13, 20;; // loc2 = relative offset in instruction
422 (p14) movl loc3=0xfffffffffff00000;; // extend sign
423 (p14) or loc2=loc2, loc3;;
424 shl loc2=loc2,4;; // convert to byte offset instead of bundle offset
425 add loc3=loc2, in1;; // loc3 = physical address of branch target
426 (p14) sub loc2=r0,loc2;; // flip sign in loc2 if offset is negative
427 sub loc4=loc3,in2;; // loc4 = relative offset from new ip to branch target
428 cmp.lt p15, p14 = 0, loc4;; // get new sign bit
429 (p14) sub loc5=r0,loc4 // get absolute value of offset
430 (p15) mov loc5=loc4;;
431 movl loc6=0x0FFFFFF;; // maximum offset in bytes for ip-rel branch
432 cmp.gt p14, p15 = loc5, loc6;; // check to see we're not out of range for an ip-relative branch
433 (p14) br.sptk.few RelocateSlotError
434 cmp.lt p15, p14 = 0, loc4;; // store sign in p14 again
435 (p14) dep in0=-1,in0,36,1 // store sign bit in instruction
436 (p15) dep in0=0,in0,36,1
437 shr loc4=loc4, 4;; // convert back to bundle offset
438 dep in0=loc4,in0,13,16;; // put first 16 bits of new offset into instruction
440 dep in0=loc4,in0,13+16,4 // put last 4 bits of new offset into instruction
441 mov in1=1;; // in1 = success
442 br.sptk.few RelocateSlotDone;;
445 mov in1=0;; // in1 = failure
453 /////////////////////////////////////////////
459 // Determines if the given instruction is a branch instruction.
462 // in0 - Instruction encoding (41-bits, right justified)
463 // in1 - Instruction slot number
464 // in2 - Bundle template
467 // in0 - 1 if branch or 0 if not branch
470 // This procedure is a leaf routine
472 // IsSlotBranch recognizes all branch instructions by looking at the provided template.
473 // The instruction encoding is only passed to this routine for future expansion.
479 NESTED_SETUP (3,2+0,0,0)
481 mov in0=1;; // in0 = 1 which destroys the instruction
482 andcm in2=in2,in0;; // in2 = even template to reduce compares
483 mov in0=0;; // in0 = not a branch
484 cmp.eq p14, p15 = 0x16, in2;; // Template 0x16 is BBB
485 (p14) br.sptk.few IsSlotBranchTrue
486 cmp.eq p14, p15 = SLOT0, in1;; // Slot 0 has no other possiblities
487 (p14) br.sptk.few IsSlotBranchDone
488 cmp.eq p14, p15 = 0x12, in2;; // Template 0x12 is MBB
489 (p14) br.sptk.few IsSlotBranchTrue
490 cmp.eq p14, p15 = SLOT1, in1;; // Slot 1 has no other possiblities
491 (p14) br.sptk.few IsSlotBranchDone
492 cmp.eq p14, p15 = 0x10, in2;; // Template 0x10 is MIB
493 (p14) br.sptk.few IsSlotBranchTrue
494 cmp.eq p14, p15 = 0x18, in2;; // Template 0x18 is MMB
495 (p14) br.sptk.few IsSlotBranchTrue
496 cmp.eq p14, p15 = 0x1C, in2;; // Template 0x1C is MFB
497 (p14) br.sptk.few IsSlotBranchTrue
498 br.sptk.few IsSlotBranchDone
501 mov in0=1;; // in0 = branch
509 /////////////////////////////////////////////
515 // Retrieves the instruction template for an instruction bundle
518 // in0 - Runtime address of bundle
521 // in0 - Instruction template (5-bits, right-justified)
524 // This procedure is a leaf routine
530 NESTED_SETUP (1,2+2,0,0)
532 ld8 loc2=[in0], 0x8 // loc2 = first 8 bytes of branch bundle
533 movl loc3=MASK_0_4;; // loc3 = template mask
534 and loc2=loc2,loc3;; // loc2 = template, right justified
535 mov in0=loc2;; // in0 = template, right justified
542 /////////////////////////////////////////////
548 // Gets the instruction encoding for an instruction slot and bundle
551 // in0 - Runtime address of bundle
552 // in1 - Instruction slot (either 0, 1, or 2)
555 // in0 - Instruction encoding (41-bits, right justified)
558 // This procedure is a leaf routine
560 // Slot0 - [in0 + 0x8] Bits 45-5
561 // Slot1 - [in0 + 0x8] Bits 63-46 and [in0] Bits 22-0
562 // Slot2 - [in0] Bits 63-23
567 NESTED_SETUP (2,2+3,0,0)
569 ld8 loc2=[in0], 0x8;; // loc2 = first 8 bytes of branch bundle
570 ld8 loc3=[in0];; // loc3 = second 8 bytes of branch bundle
571 cmp.eq p14, p15 = 2, in1;; // check if slot 2 specified
572 (p14) br.cond.sptk.few GetSlot2;; // get slot 2
573 cmp.eq p14, p15 = 1, in1;; // check if slot 1 specified
574 (p14) br.cond.sptk.few GetSlot1;; // get slot 1
577 extr.u in0=loc2, 5, 45 // in0 = extracted slot 0
578 br.sptk.few GetSlotDone;;
581 extr.u in0=loc2, 46, 18 // in0 = bits 63-46 of loc2 right-justified
582 extr.u loc4=loc3, 0, 23;; // loc4 = bits 22-0 of loc3 right-justified
583 dep in0=loc4, in0, 18, 15;;
585 dep in0=loc4, in0, 33, 8;; // in0 = extracted slot 1
586 br.sptk.few GetSlotDone;;
589 extr.u in0=loc3, 23, 41;; // in0 = extracted slot 2
597 /////////////////////////////////////////////
603 // Sets the instruction encoding for an instruction slot and bundle
606 // in0 - Runtime address of bundle
607 // in1 - Instruction slot (either 0, 1, or 2)
608 // in2 - Instruction encoding (41-bits, right justified)
613 // This procedure is a leaf routine
618 NESTED_SETUP (3,2+3,0,0)
620 ld8 loc2=[in0], 0x8;; // loc2 = first 8 bytes of bundle
621 ld8 loc3=[in0];; // loc3 = second 8 bytes of bundle
622 cmp.eq p14, p15 = 2, in1;; // check if slot 2 specified
623 (p14) br.cond.sptk.few SetSlot2;; // set slot 2
624 cmp.eq p14, p15 = 1, in1;; // check if slot 1 specified
625 (p14) br.cond.sptk.few SetSlot1;; // set slot 1
628 dep loc2=0, loc2, 5, 41;; // remove old instruction from slot 0
629 shl loc4=in2, 5;; // loc4 = new instruction ready to be inserted
630 or loc2=loc2, loc4;; // loc2 = updated first 8 bytes of bundle
631 add loc4=0x8,in0;; // loc4 = address to store first 8 bytes of bundle
632 st8 [loc4]=loc2 // [loc4] = updated bundle
633 br.sptk.few SetSlotDone;;
637 dep loc2=0, loc2, 46, 18 // remove old instruction from slot 1
638 dep loc3=0, loc3, 0, 23;;
639 shl loc4=in2, 46;; // loc4 = partial instruction ready to be inserted
640 or loc2=loc2, loc4;; // loc2 = updated first 8 bytes of bundle
641 add loc4=0x8,in0;; // loc4 = address to store first 8 bytes of bundle
642 st8 [loc4]=loc2;; // [loc4] = updated bundle
643 shr.u loc4=in2, 18;; // loc4 = partial instruction ready to be inserted
644 or loc3=loc3, loc4;; // loc3 = updated second 8 bytes of bundle
645 st8 [in0]=loc3;; // [in0] = updated bundle
646 br.sptk.few SetSlotDone;;
649 dep loc3=0, loc3, 23, 41;; // remove old instruction from slot 2
650 shl loc4=in2, 23;; // loc4 = instruction ready to be inserted
651 or loc3=loc3, loc4;; // loc3 = updated second 8 bytes of bundle
652 st8 [in0]=loc3;; // [in0] = updated bundle
660 /////////////////////////////////////////////
666 // C callable function to obtain the current value of IVA
669 // Current value if IVA
680 /////////////////////////////////////////////
683 // ProgramInterruptFlags
686 // C callable function to enable/disable interrupts
689 // Previous state of psr.ic
691 .globl ProgramInterruptFlags
692 .proc ProgramInterruptFlags
693 ProgramInterruptFlags:
697 and r8=loc0, loc1 // obtain current psr.ic and psr.i state
698 and in0=in0, loc1 // insure no extra bits set in input
699 andcm loc0=loc0,loc1;; // clear original psr.i and psr.ic
700 or loc0=loc0,in0;; // OR in new psr.ic value
701 mov psr.l=loc0;; // write new psr
703 br.ret.sptk.many b0 // return
705 .endp ProgramInterruptFlags
708 /////////////////////////////////////////////
714 // Saves system context to context record.
717 // in0 = 512 byte aligned context record address
719 // in2 = original ar.bsp
720 // in3 = original ar.bspstore
721 // in4 = original ar.rnat
722 // in5 = original ar.pfs
727 // loc2 - temporary application unat storage
728 // loc3 - temporary exception handler unat storage
733 alloc loc0=6,4,0,0;; // alloc 6 input, 4 locals, 0 outs
734 mov loc2=ar.unat;; // save application context unat (spilled later)
735 mov ar.unat=r0;; // set UNAT=0
736 st8.spill [in0]=r0,8;;
737 st8.spill [in0]=r1,8;; // save R1 - R31
738 st8.spill [in0]=r2,8;;
739 st8.spill [in0]=r3,8;;
740 st8.spill [in0]=r4,8;;
741 st8.spill [in0]=r5,8;;
742 st8.spill [in0]=r6,8;;
743 st8.spill [in0]=r7,8;;
744 st8.spill [in0]=r8,8;;
745 st8.spill [in0]=r9,8;;
746 st8.spill [in0]=r10,8;;
747 st8.spill [in0]=r11,8;;
748 st8.spill [in0]=r12,8;;
749 st8.spill [in0]=r13,8;;
750 st8.spill [in0]=r14,8;;
751 st8.spill [in0]=r15,8;;
752 st8.spill [in0]=r16,8;;
753 st8.spill [in0]=r17,8;;
754 st8.spill [in0]=r18,8;;
755 st8.spill [in0]=r19,8;;
756 st8.spill [in0]=r20,8;;
757 st8.spill [in0]=r21,8;;
758 st8.spill [in0]=r22,8;;
759 st8.spill [in0]=r23,8;;
760 st8.spill [in0]=r24,8;;
761 st8.spill [in0]=r25,8;;
762 st8.spill [in0]=r26,8;;
763 st8.spill [in0]=r27,8;;
764 st8.spill [in0]=r28,8;;
765 st8.spill [in0]=r29,8;;
766 st8.spill [in0]=r30,8;;
767 st8.spill [in0]=r31,8;;
768 mov loc3=ar.unat;; // save debugger context unat (spilled later)
769 stf.spill [in0]=f2,16;; // save f2 - f31
770 stf.spill [in0]=f3,16;;
771 stf.spill [in0]=f4,16;;
772 stf.spill [in0]=f5,16;;
773 stf.spill [in0]=f6,16;;
774 stf.spill [in0]=f7,16;;
775 stf.spill [in0]=f8,16;;
776 stf.spill [in0]=f9,16;;
777 stf.spill [in0]=f10,16;;
778 stf.spill [in0]=f11,16;;
779 stf.spill [in0]=f12,16;;
780 stf.spill [in0]=f13,16;;
781 stf.spill [in0]=f14,16;;
782 stf.spill [in0]=f15,16;;
783 stf.spill [in0]=f16,16;;
784 stf.spill [in0]=f17,16;;
785 stf.spill [in0]=f18,16;;
786 stf.spill [in0]=f19,16;;
787 stf.spill [in0]=f20,16;;
788 stf.spill [in0]=f21,16;;
789 stf.spill [in0]=f22,16;;
790 stf.spill [in0]=f23,16;;
791 stf.spill [in0]=f24,16;;
792 stf.spill [in0]=f25,16;;
793 stf.spill [in0]=f26,16;;
794 stf.spill [in0]=f27,16;;
795 stf.spill [in0]=f28,16;;
796 stf.spill [in0]=f29,16;;
797 stf.spill [in0]=f30,16;;
798 stf.spill [in0]=f31,16;;
799 mov loc0=pr;; // save predicates
800 st8.spill [in0]=loc0,8;;
801 st8.spill [in0]=in1,8;; // save b0 - b7... in1 already equals saved b0
803 st8.spill [in0]=loc0,8;;
805 st8.spill [in0]=loc0,8;;
807 st8.spill [in0]=loc0,8;;
809 st8.spill [in0]=loc0,8;;
811 st8.spill [in0]=loc0,8;;
813 st8.spill [in0]=loc0,8;;
815 st8.spill [in0]=loc0,8;;
816 mov loc0=ar.rsc;; // save ar.rsc
817 st8.spill [in0]=loc0,8;;
818 st8.spill [in0]=in2,8;; // save ar.bsp (in2)
819 st8.spill [in0]=in3,8;; // save ar.bspstore (in3)
820 st8.spill [in0]=in4,8;; // save ar.rnat (in4)
821 mov loc0=ar.fcr;; // save ar.fcr (ar21 - IA32 floating-point control register)
822 st8.spill [in0]=loc0,8;;
823 mov loc0=ar.eflag;; // save ar.eflag (ar24)
824 st8.spill [in0]=loc0,8;;
825 mov loc0=ar.csd;; // save ar.csd (ar25 - ia32 CS descriptor)
826 st8.spill [in0]=loc0,8;;
827 mov loc0=ar.ssd;; // save ar.ssd (ar26 - ia32 ss descriptor)
828 st8.spill [in0]=loc0,8;;
829 mov loc0=ar.cflg;; // save ar.cflg (ar27 - ia32 cr0 and cr4)
830 st8.spill [in0]=loc0,8;;
831 mov loc0=ar.fsr;; // save ar.fsr (ar28 - ia32 floating-point status register)
832 st8.spill [in0]=loc0,8;;
833 mov loc0=ar.fir;; // save ar.fir (ar29 - ia32 floating-point instruction register)
834 st8.spill [in0]=loc0,8;;
835 mov loc0=ar.fdr;; // save ar.fdr (ar30 - ia32 floating-point data register)
836 st8.spill [in0]=loc0,8;;
837 mov loc0=ar.ccv;; // save ar.ccv
838 st8.spill [in0]=loc0,8;;
839 st8.spill [in0]=loc2,8;; // save ar.unat (saved to loc2 earlier)
840 mov loc0=ar.fpsr;; // save floating point status register
841 st8.spill [in0]=loc0,8;;
842 st8.spill [in0]=in5,8;; // save ar.pfs
843 mov loc0=ar.lc;; // save ar.lc
844 st8.spill [in0]=loc0,8;;
845 mov loc0=ar.ec;; // save ar.ec
846 st8.spill [in0]=loc0,8;;
848 // save control registers
849 mov loc0=cr.dcr;; // save dcr
850 st8.spill [in0]=loc0,8;;
851 mov loc0=cr.itm;; // save itm
852 st8.spill [in0]=loc0,8;;
853 mov loc0=cr.iva;; // save iva
854 st8.spill [in0]=loc0,8;;
855 mov loc0=cr.pta;; // save pta
856 st8.spill [in0]=loc0,8;;
857 mov loc0=cr.ipsr;; // save ipsr
858 st8.spill [in0]=loc0,8;;
859 mov loc0=cr.isr;; // save isr
860 st8.spill [in0]=loc0,8;;
861 mov loc0=cr.iip;; // save iip
862 st8.spill [in0]=loc0,8;;
863 mov loc0=cr.ifa;; // save ifa
864 st8.spill [in0]=loc0,8;;
865 mov loc0=cr.itir;; // save itir
866 st8.spill [in0]=loc0,8;;
867 mov loc0=cr.iipa;; // save iipa
868 st8.spill [in0]=loc0,8;;
869 mov loc0=cr.ifs;; // save ifs
870 st8.spill [in0]=loc0,8;;
871 mov loc0=cr.iim;; // save iim
872 st8.spill [in0]=loc0,8;;
873 mov loc0=cr.iha;; // save iha
874 st8.spill [in0]=loc0,8;;
876 // save debug registers
877 mov loc0=dbr[r0];; // save dbr0 - dbr7
878 st8.spill [in0]=loc0,8;;
881 st8.spill [in0]=loc0,8;;
884 st8.spill [in0]=loc0,8;;
887 st8.spill [in0]=loc0,8;;
890 st8.spill [in0]=loc0,8;;
893 st8.spill [in0]=loc0,8;;
896 st8.spill [in0]=loc0,8;;
899 st8.spill [in0]=loc0,8;;
900 mov loc0=ibr[r0];; // save ibr0 - ibr7
901 st8.spill [in0]=loc0,8;;
904 st8.spill [in0]=loc0,8;;
907 st8.spill [in0]=loc0,8;;
910 st8.spill [in0]=loc0,8;;
913 st8.spill [in0]=loc0,8;;
916 st8.spill [in0]=loc0,8;;
919 st8.spill [in0]=loc0,8;;
922 st8.spill [in0]=loc0,8;;
923 st8.spill [in0]=loc3;;
930 /////////////////////////////////////////////
936 // Restores register context from context record.
939 // in0 = address of last element 512 byte aligned context record address
941 // in2 = modified ar.bsp
942 // in3 = modified ar.bspstore
943 // in4 = modified ar.rnat
944 // in5 = modified ar.pfs
949 // loc2 - temporary application unat storage
950 // loc3 - temporary exception handler unat storage
954 alloc loc0=6,4,0,0;; // alloc 6 inputs, 4 locals, 0 outs
955 ld8.fill loc3=[in0],-8;; // int_nat (nat bits for R1-31)
956 movl loc1=7;; // ibr7
957 ld8.fill loc0=[in0],-8;;
959 movl loc1=6;; // ibr6
960 ld8.fill loc0=[in0],-8;;
962 movl loc1=5;; // ibr5
963 ld8.fill loc0=[in0],-8;;
965 movl loc1=4;; // ibr4
966 ld8.fill loc0=[in0],-8;;
968 movl loc1=3;; // ibr3
969 ld8.fill loc0=[in0],-8;;
971 movl loc1=2;; // ibr2
972 ld8.fill loc0=[in0],-8;;
974 movl loc1=1;; // ibr1
975 ld8.fill loc0=[in0],-8;;
977 ld8.fill loc0=[in0],-8;; // ibr0
979 movl loc1=7;; // dbr7
980 ld8.fill loc0=[in0],-8;;
982 movl loc1=6;; // dbr6
983 ld8.fill loc0=[in0],-8;;
985 movl loc1=5;; // dbr5
986 ld8.fill loc0=[in0],-8;;
988 movl loc1=4;; // dbr4
989 ld8.fill loc0=[in0],-8;;
991 movl loc1=3;; // dbr3
992 ld8.fill loc0=[in0],-8;;
994 movl loc1=2;; // dbr2
995 ld8.fill loc0=[in0],-8;;
997 movl loc1=1;; // dbr1
998 ld8.fill loc0=[in0],-8;;
1000 ld8.fill loc0=[in0],-8;; // dbr0
1002 ld8.fill loc0=[in0],-8;; // iha
1004 ld8.fill loc0=[in0],-8;; // iim
1006 ld8.fill loc0=[in0],-8;; // ifs
1008 ld8.fill loc0=[in0],-8;; // iipa
1010 ld8.fill loc0=[in0],-8;; // itir
1012 ld8.fill loc0=[in0],-8;; // ifa
1014 ld8.fill loc0=[in0],-8;; // iip
1016 ld8.fill loc0=[in0],-8;; // isr
1018 ld8.fill loc0=[in0],-8;; // ipsr
1020 ld8.fill loc0=[in0],-8;; // pta
1022 ld8.fill loc0=[in0],-8;; // iva
1024 ld8.fill loc0=[in0],-8;; // itm
1026 ld8.fill loc0=[in0],-8;; // dcr
1028 ld8.fill loc0=[in0],-8;; // ec
1030 ld8.fill loc0=[in0],-8;; // lc
1032 ld8.fill in5=[in0],-8;; // ar.pfs
1033 ld8.fill loc0=[in0],-8;; // ar.fpsr
1035 ld8.fill loc2=[in0],-8;; // ar.unat - restored later...
1036 ld8.fill loc0=[in0],-8;; // ar.ccv
1038 ld8.fill loc0=[in0],-8;; // ar.fdr
1040 ld8.fill loc0=[in0],-8;; // ar.fir
1042 ld8.fill loc0=[in0],-8;; // ar.fsr
1044 ld8.fill loc0=[in0],-8;; // ar.cflg
1046 ld8.fill loc0=[in0],-8;; // ar.ssd
1048 ld8.fill loc0=[in0],-8;; // ar.csd
1050 ld8.fill loc0=[in0],-8;; // ar.eflag
1052 ld8.fill loc0=[in0],-8;; // ar.fcr
1054 ld8.fill in4=[in0],-8;; // ar.rnat
1055 ld8.fill in3=[in0],-8;; // bspstore
1056 ld8.fill in2=[in0],-8;; // bsp
1057 ld8.fill loc0=[in0],-8;; // ar.rsc
1059 ld8.fill loc0=[in0],-8;; // B7 - B0
1061 ld8.fill loc0=[in0],-8;;
1063 ld8.fill loc0=[in0],-8;;
1065 ld8.fill loc0=[in0],-8;;
1067 ld8.fill loc0=[in0],-8;;
1069 ld8.fill loc0=[in0],-8;;
1071 ld8.fill loc0=[in0],-8;;
1073 ld8.fill in1=[in0],-8;; // b0 is temporarily stored in in1
1074 ld8.fill loc0=[in0],-16;; // predicates
1076 ldf.fill f31=[in0],-16;;
1077 ldf.fill f30=[in0],-16;;
1078 ldf.fill f29=[in0],-16;;
1079 ldf.fill f28=[in0],-16;;
1080 ldf.fill f27=[in0],-16;;
1081 ldf.fill f26=[in0],-16;;
1082 ldf.fill f25=[in0],-16;;
1083 ldf.fill f24=[in0],-16;;
1084 ldf.fill f23=[in0],-16;;
1085 ldf.fill f22=[in0],-16;;
1086 ldf.fill f21=[in0],-16;;
1087 ldf.fill f20=[in0],-16;;
1088 ldf.fill f19=[in0],-16;;
1089 ldf.fill f18=[in0],-16;;
1090 ldf.fill f17=[in0],-16;;
1091 ldf.fill f16=[in0],-16;;
1092 ldf.fill f15=[in0],-16;;
1093 ldf.fill f14=[in0],-16;;
1094 ldf.fill f13=[in0],-16;;
1095 ldf.fill f12=[in0],-16;;
1096 ldf.fill f11=[in0],-16;;
1097 ldf.fill f10=[in0],-16;;
1098 ldf.fill f9=[in0],-16;;
1099 ldf.fill f8=[in0],-16;;
1100 ldf.fill f7=[in0],-16;;
1101 ldf.fill f6=[in0],-16;;
1102 ldf.fill f5=[in0],-16;;
1103 ldf.fill f4=[in0],-16;;
1104 ldf.fill f3=[in0],-16;;
1105 ldf.fill f2=[in0],-8;;
1106 mov ar.unat=loc3;; // restore unat (int_nat) before fill of general registers
1107 ld8.fill r31=[in0],-8;;
1108 ld8.fill r30=[in0],-8;;
1109 ld8.fill r29=[in0],-8;;
1110 ld8.fill r28=[in0],-8;;
1111 ld8.fill r27=[in0],-8;;
1112 ld8.fill r26=[in0],-8;;
1113 ld8.fill r25=[in0],-8;;
1114 ld8.fill r24=[in0],-8;;
1115 ld8.fill r23=[in0],-8;;
1116 ld8.fill r22=[in0],-8;;
1117 ld8.fill r21=[in0],-8;;
1118 ld8.fill r20=[in0],-8;;
1119 ld8.fill r19=[in0],-8;;
1120 ld8.fill r18=[in0],-8;;
1121 ld8.fill r17=[in0],-8;;
1122 ld8.fill r16=[in0],-8;;
1123 ld8.fill r15=[in0],-8;;
1124 ld8.fill r14=[in0],-8;;
1125 ld8.fill r13=[in0],-8;;
1126 ld8.fill r12=[in0],-8;;
1127 ld8.fill r11=[in0],-8;;
1128 ld8.fill r10=[in0],-8;;
1129 ld8.fill r9=[in0],-8;;
1130 ld8.fill r8=[in0],-8;;
1131 ld8.fill r7=[in0],-8;;
1132 ld8.fill r6=[in0],-8;;
1133 ld8.fill r5=[in0],-8;;
1134 ld8.fill r4=[in0],-8;;
1135 ld8.fill r3=[in0],-8;;
1136 ld8.fill r2=[in0],-8;;
1137 ld8.fill r1=[in0],-8;;
1138 mov ar.unat=loc2;; // restore application context unat
1145 /////////////////////////////////////////////
1151 // Common branch target from hooked IVT entries. Runs in interrupt context.
1152 // Responsible for saving and restoring context and calling common C
1153 // handler. Banked registers running on bank 0 at entry.
1156 // All arguments are passed in banked registers:
1157 // B0_REG = Original B0
1158 // SCRATCH_REG1 = IVT entry index
1166 // loc2 - vector number / mask
1167 // loc3 - 16 byte aligned context record address
1168 // loc4 - temporary storage of last address in context record
1171 flushrs;; // Synch RSE with backing store
1172 mov SCRATCH_REG2=ar.bsp // save interrupted context bsp
1173 mov SCRATCH_REG3=ar.bspstore // save interrupted context bspstore
1174 mov SCRATCH_REG4=ar.rnat // save interrupted context rnat
1175 mov SCRATCH_REG6=cr.ifs;; // save IFS in case we need to chain...
1176 cover;; // creates new frame, moves old
1178 alloc SCRATCH_REG5=0,5,6,0 // alloc 5 locals, 6 outs
1180 // save banked registers to locals
1181 mov out1=B0_REG // out1 = Original B0
1182 mov out2=SCRATCH_REG2 // out2 = original ar.bsp
1183 mov out3=SCRATCH_REG3 // out3 = original ar.bspstore
1184 mov out4=SCRATCH_REG4 // out4 = original ar.rnat
1185 mov out5=SCRATCH_REG5 // out5 = original ar.pfs
1186 mov loc2=SCRATCH_REG1;; // loc2 = vector number + chain flag
1187 bsw.1;; // switch banked registers to bank 1
1188 srlz.d // explicit serialize required
1189 // now fill in context record structure
1190 movl loc3=IpfContextBuf // Insure context record is aligned
1191 add loc0=-0x200,r0;; // mask the lower 9 bits (align on 512 byte boundary)
1192 and loc3=loc3,loc0;;
1193 add loc3=0x200,loc3;; // move to next 512 byte boundary
1194 // loc3 now contains the 512 byte aligned context record
1195 // spill register context into context record
1196 mov out0=loc3;; // Context record base in out0
1197 // original B0 in out1 already
1198 // original ar.bsp in out2 already
1199 // original ar.bspstore in out3 already
1200 br.call.sptk.few b0=SpillContext;; // spill context
1201 mov loc4=out0 // save modified address
1203 // At this point, the context has been saved to the context record and we're
1204 // ready to call the C part of the handler...
1206 movl loc0=CommonHandler;; // obtain address of plabel
1207 ld8 loc1=[loc0];; // get entry point of CommonHandler
1208 mov b6=loc1;; // put it in a branch register
1209 adds loc1= 8, loc0;; // index to GP in plabel
1210 ld8 r1=[loc1];; // set up gp for C call
1211 mov loc1=0xfffff;; // mask off so only vector bits are present
1212 and out0=loc2,loc1;; // pass vector number (exception type)
1213 mov out1=loc3;; // pass context record address
1214 br.call.sptk.few b0=b6;; // call C handler
1216 // We've returned from the C call, so restore the context and either rfi
1217 // back to interrupted thread, or chain into the SAL if this was an external interrupt
1218 mov out0=loc4;; // pass address of last element in context record
1219 br.call.sptk.few b0=FillContext;; // Fill context
1220 mov b0=out1 // fill in b0
1224 // Loadrs is necessary because the debugger may have changed some values in
1225 // the backing store. The processor, however may not be aware that the
1226 // stacked registers need to be reloaded from the backing store. Therefore,
1227 // we explicitly cause the RSE to refresh the stacked register's contents
1228 // from the backing store.
1229 mov loc0=ar.rsc // get RSC value
1230 mov loc1=ar.rsc // save it so we can restore it
1231 movl loc3=0xffffffffc000ffff;; // create mask for clearing RSC.loadrs
1232 and loc0=loc0,loc3;; // create value for RSC with RSC.loadrs==0
1233 mov ar.rsc=loc0;; // modify RSC
1234 loadrs;; // invalidate register stack
1235 mov ar.rsc=loc1;; // restore original RSC
1237 bsw.0;; // switch banked registers back to bank 0
1238 srlz.d;; // explicit serialize required
1239 mov PR_REG=pr // save predicates - to be restored after chaining decision
1240 mov B0_REG=b0 // save b0 - required by chain code
1241 mov loc2=EXCPT_EXTERNAL_INTERRUPT;;
1242 cmp.eq p7,p0=SCRATCH_REG1,loc2;; // check to see if this is the timer tick
1243 (p7) br.cond.dpnt.few DO_CHAIN;;
1247 rfi;; // we're outa here.
1251 mov SCRATCH_REG1=cr.iva
1252 mov SCRATCH_REG2=PATCH_RETURN_OFFSET;;
1253 add SCRATCH_REG1=SCRATCH_REG1, SCRATCH_REG2;;
1254 mov b0=SCRATCH_REG1;;
1255 br.cond.sptk.few b0;;
1260 /////////////////////////////////////////////
1266 // HookStub will be copied from it's loaded location into the IVT when
1267 // an IVT entry is hooked. The IVT entry does an indirect jump via B0 to
1268 // HookHandler, which in turn calls into the default C handler, which calls
1269 // the user-installed C handler. The calls return and HookHandler executes
1273 // Saves B0 to B0_REG
1274 // Saves IVT index to SCRATCH_REG1 (immediate value is fixed up when code is copied
1275 // to the IVT entry.
1282 movl SCRATCH_REG1=HookHandler;;
1283 mov b0=SCRATCH_REG1;;
1284 mov SCRATCH_REG1=0;;// immediate value is fixed up during install of handler to be the vector number
1290 /////////////////////////////////////////////
1291 // The following code is moved into IVT entry 14 (offset 3400) which is reserved
1292 // in the Itanium architecture. The patch code is located at the end of the
1296 mov SCRATCH_REG0=psr
1297 mov SCRATCH_REG6=cr.ipsr
1301 // turn off any virtual translations
1302 movl SCRATCH_REG1 = ~( MASK(PSR_DT,1) | MASK(PSR_RT,1));;
1303 and SCRATCH_REG1 = SCRATCH_REG0, SCRATCH_REG1;;
1304 mov psr.l = SCRATCH_REG1;;
1306 tbit.z p14, p15 = SCRATCH_REG6, PSR_IS;; // Check to see if we were
1307 // interrupted from IA32
1308 // context. If so, bail out
1309 // and chain to SAL immediately
1310 (p15) br.cond.sptk.few Stub_IVT_Passthru;;
1311 // we only want to take 1 out of 32 external interrupts to minimize the
1312 // impact to system performance. Check our interrupt count and bail
1313 // out if we're not up to 32
1314 movl SCRATCH_REG1=ExternalInterruptCount;;
1315 ld8 SCRATCH_REG2=[SCRATCH_REG1];; // ExternalInterruptCount
1316 tbit.z p14, p15 = SCRATCH_REG2, 5;; // bit 5 set?
1317 (p14) add SCRATCH_REG2=1, SCRATCH_REG2;; // No? Then increment
1318 // ExternalInterruptCount
1321 (p14) st8 [SCRATCH_REG1]=SCRATCH_REG2;;
1322 (p14) br.cond.sptk.few Stub_IVT_Passthru;;
1323 (p15) mov SCRATCH_REG2=0;; // Yes? Then reset
1324 // ExternalInterruptCount
1327 (p15) st8 [SCRATCH_REG1]=SCRATCH_REG2;;
1329 movl SCRATCH_REG1=HookHandler;; // SCRATCH_REG1 = entrypoint of HookHandler
1330 mov b0=SCRATCH_REG1;; // b0 = entrypoint of HookHandler
1331 mov SCRATCH_REG1=EXCPT_EXTERNAL_INTERRUPT;;
1332 br.sptk.few b0;; // branch to HookHandler
1335 // fake-up an rfi to get RSE back to being coherent and insure psr has
1336 // original contents when interrupt occured, then exit to SAL
1338 // cr.ifs has been modified by previous "cover"
1339 // SCRATCH_REG6 has original cr.ifs
1341 mov SCRATCH_REG5=cr.ipsr
1342 mov SCRATCH_REG4=cr.iip;;
1343 mov cr.ipsr=SCRATCH_REG0
1344 mov SCRATCH_REG1=ip;;
1345 add SCRATCH_REG1=0x30, SCRATCH_REG1;;
1346 mov cr.iip=SCRATCH_REG1;;
1347 rfi;; // rfi to next instruction
1350 mov cr.ifs=SCRATCH_REG6
1351 mov cr.ipsr=SCRATCH_REG5
1352 mov cr.iip=SCRATCH_REG4;;
1355 mov pr=PR_REG // pr = saved predicate registers
1356 mov b0=B0_REG;; // b0 = saved b0
1360 /////////////////////////////////////////////
1361 // The following bundle is moved into IVT entry 14 (offset 0x3400) which is reserved
1362 // in the Itanium architecture. This bundle will be the last bundle and will
1363 // be located at offset 0x37F0 in the IVT.
1370 br.sptk.few -(FAILSAFE_BRANCH_OFFSET - EXT_INT_ENTRY_OFFSET - 0x10)
1374 /////////////////////////////////////////////
1375 // The following bundle is moved into IVT entry 13 (offset 0x3000) which is the
1376 // external interrupt. It branches to the patch code.
1383 br.cond.sptk.few PATCH_BRANCH