1/* libunwind - a platform-independent unwind library 2 Copyright (C) 2003 Hewlett-Packard Co 3 Contributed by David Mosberger-Tang <davidm@hpl.hp.com> 4 5This file is part of libunwind. 6 7Permission is hereby granted, free of charge, to any person obtaining 8a copy of this software and associated documentation files (the 9"Software"), to deal in the Software without restriction, including 10without limitation the rights to use, copy, modify, merge, publish, 11distribute, sublicense, and/or sell copies of the Software, and to 12permit persons to whom the Software is furnished to do so, subject to 13the following conditions: 14 15The above copyright notice and this permission notice shall be 16included in all copies or substantial portions of the Software. 17 18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 22LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 24WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 25 26#include "ia64-test-stack.h" 27 28 .common stackmem, NSTACKS*STACK_SIZE, 16 29 30 .global do_unwind_tests 31 32 .text 33 34#define SAVED_SP_OFF 0 35#define SAVED_RP_OFF 8 36#define SAVED_PFS_OFF 16 37#define SAVED_RNAT_OFF 24 38#define SAVED_BSP_OFF 32 39#define SAVED_BSPSTORE_OFF 40 40#define FRAME_SIZE 48 41 42 .proc stack_it 43stack_it: 44 .prologue 45 alloc r18 = ar.pfs, 0, 0, 0, 0 // read ar.pfs 46 // first, calculate address of new stack: 47 addl r2 = @ltoff(stackmem), gp 48 shl r3 = r8, STACK_SIZE_SHIFT 49 ;; 50 ld8 r2 = [r2] // r2 = &stackmem 51 ;; 52 add r2 = r2, r3 // r2 = stackmem[iteration] 53 ;; 54 addl r3 = STACK_SIZE-FRAME_SIZE, r2 // r3 = &stackframe 55 ;; 56 st8 [r3] = sp 57 .vframesp SAVED_SP_OFF+16 58 adds sp = -16, r3 // switch the memory stack 59 ;; 60 adds r3 = (SAVED_RP_OFF - SAVED_SP_OFF), r3 61 mov r16 = rp 62 ;; 63 .savesp rp, SAVED_RP_OFF+16 64 st8 [r3] = r16, (SAVED_PFS_OFF - SAVED_RP_OFF) 65 ;; 66 .savesp ar.pfs, SAVED_PFS_OFF+16 67 st8 [r3] = r18, (SAVED_BSP_OFF - SAVED_PFS_OFF) 68 69 mov r16 = ar.bsp 70 mov r17 = ar.bspstore 71 mov r18 = ar.rnat 72 ;; 73 .savesp ar.bsp, SAVED_BSP_OFF+16 74 st8 [r3] = r16, (SAVED_BSPSTORE_OFF - SAVED_BSP_OFF) 75 ;; 76 .savesp ar.bspstore, SAVED_BSPSTORE_OFF+16 77 st8 [r3] = r17, (SAVED_RNAT_OFF - SAVED_BSPSTORE_OFF) 78 ;; 79 .savesp ar.rnat, SAVED_RNAT_OFF+16 80 st8 [r3] = r18 81 ;; 82 mov ar.bspstore = r2 // switch the backing store 83 84 .body 85 86 // for even iterations, allocate a local variable: 87 tbit.nz p6, p0 = r8, 0 88(p6) br.cond.sptk.few .skip 89 ;; 90 alloc r2 = ar.pfs, 0, 1, 0, 0 91 mov loc0 = r8 92 ;; 93.skip: cmp.ne p6, p7 = 0, r8 94 ;; 95{ .mbb 96(p6) adds r8 = -1, r8 97(p6) br.call.sptk.many rp = stack_it // next iteration 98(p7) br.call.sptk.many rp = do_unwind_tests // time for introspection... 99} 100 // switch back to stack: 101 102 adds r3 = SAVED_SP_OFF+16, sp 103 ;; 104 ld8 r16 = [r3], (SAVED_RP_OFF-SAVED_SP_OFF);; // saved sp 105 ld8 r17 = [r3], (SAVED_PFS_OFF-SAVED_RP_OFF);; // saved rp 106 ld8 r18 = [r3], (SAVED_RNAT_OFF-SAVED_PFS_OFF);; // saved pfs 107 ld8 r19 = [r3], (SAVED_BSP_OFF-SAVED_RNAT_OFF);; // saved rnat 108 ld8 r20 = [r3], (SAVED_BSPSTORE_OFF-SAVED_BSP_OFF);; // saved bsp 109 ld8 r21 = [r3];; // saved bspstore 110 111 mov rp = r17 112 mov ar.pfs = r18 113 mov ar.bspstore = r21 // this also restores ar.bsp 114 ;; 115 mov ar.rnat = r19 116 117 .restore sp 118 mov sp = r16 119 br.ret.sptk.many rp 120 .endp stack_it 121 122 123#define SET_LOC(n) add loc##n = n, r8 124#define SET_NAT(n) ld8.s loc##n = [r0] 125 126 .global touch_all 127 .proc touch_all 128touch_all: 129 .prologue 130 .save ar.pfs, r34 131 alloc loc1 = ar.pfs, 1, 94, 1, 0 132 .save rp, loc0 133 mov loc0 = rp 134 .body 135 136 mov ar.rsc = 0 // put RSE into enforced lazy mode 137 shl r8 = in0, 32 // store iteration # in top 32 bits 138 add out0 = -1, in0 139 cmp.eq p6, p7 = 1, in0 140 ;; 141 SET_LOC( 2); SET_LOC( 3) 142 SET_LOC( 4); SET_LOC( 5); SET_LOC( 6); SET_LOC( 7) 143 SET_LOC( 8); SET_LOC( 9); SET_LOC(10); SET_LOC(11) 144 SET_LOC(12); SET_LOC(13); SET_LOC(14); SET_LOC(15) 145 SET_LOC(16); SET_LOC(17); SET_LOC(18); SET_LOC(19) 146 SET_LOC(20); SET_LOC(21); SET_LOC(22); SET_LOC(23) 147 SET_LOC(24); SET_LOC(25); SET_LOC(26); SET_LOC(27) 148 SET_LOC(28); SET_LOC(29); SET_LOC(30); SET_LOC(31) 149 SET_LOC(32); SET_LOC(33); SET_LOC(34); SET_LOC(35) 150 SET_LOC(36); SET_LOC(37); SET_LOC(38); SET_LOC(39) 151 SET_LOC(40); SET_LOC(41); SET_LOC(42); SET_LOC(43) 152 SET_LOC(44); SET_LOC(45); SET_LOC(46); SET_LOC(47) 153 SET_LOC(48); SET_LOC(49); SET_LOC(50); SET_LOC(51) 154 SET_LOC(52); SET_LOC(53); SET_LOC(54); SET_LOC(55) 155 SET_LOC(56); SET_LOC(57); SET_LOC(58); SET_LOC(59) 156 SET_LOC(60); SET_LOC(61); SET_LOC(62); SET_LOC(63) 157 SET_LOC(64); SET_LOC(65); SET_LOC(66); SET_LOC(67) 158 SET_LOC(68); SET_LOC(69); SET_LOC(70); SET_LOC(71) 159 SET_LOC(72); SET_LOC(73); SET_LOC(74); SET_LOC(75) 160 SET_LOC(76); SET_LOC(77); SET_LOC(78); SET_LOC(79) 161 SET_LOC(80); SET_LOC(81); SET_LOC(82); SET_LOC(83) 162 SET_LOC(84); SET_LOC(85); SET_LOC(86); SET_LOC(87) 163 SET_LOC(88); SET_LOC(89); SET_LOC(90); SET_LOC(91) 164 SET_LOC(92); SET_LOC(93) 165 ;; 166 SET_NAT(2); SET_NAT(31); SET_NAT(73); SET_NAT(93) 167 ;; 168{ .mbb 169 mov r8=NSTACKS-1 170(p6) br.call.sptk.many rp = stack_it 171(p7) br.call.sptk.many rp = touch_all 172} 173 ;; 174 175 mov rp = loc0 176 mov ar.pfs = loc1 177 br.ret.sptk.many rp 178 .endp touch_all 179 180#ifdef __linux__ 181 /* We do not need executable stack. */ 182 .section .note.GNU-stack,"",@progbits 183#endif 184