| 1 |
2 |
alfik |
/******************************************************************************
|
| 2 |
|
|
* *
|
| 3 |
|
|
* License Agreement *
|
| 4 |
|
|
* *
|
| 5 |
|
|
* Copyright (c) 2003-2010 Altera Corporation, San Jose, California, USA. *
|
| 6 |
|
|
* All rights reserved. *
|
| 7 |
|
|
* *
|
| 8 |
|
|
* Permission is hereby granted, free of charge, to any person obtaining a *
|
| 9 |
|
|
* copy of this software and associated documentation files (the "Software"), *
|
| 10 |
|
|
* to deal in the Software without restriction, including without limitation *
|
| 11 |
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
| 12 |
|
|
* and/or sell copies of the Software, and to permit persons to whom the *
|
| 13 |
|
|
* Software is furnished to do so, subject to the following conditions: *
|
| 14 |
|
|
* *
|
| 15 |
|
|
* The above copyright notice and this permission notice shall be included in *
|
| 16 |
|
|
* all copies or substantial portions of the Software. *
|
| 17 |
|
|
* *
|
| 18 |
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
| 19 |
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
| 20 |
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
| 21 |
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
| 22 |
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
| 23 |
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
| 24 |
|
|
* DEALINGS IN THE SOFTWARE. *
|
| 25 |
|
|
* *
|
| 26 |
|
|
* This agreement shall be governed in all respects by the laws of the State *
|
| 27 |
|
|
* of California and by the laws of the United States of America. *
|
| 28 |
|
|
* *
|
| 29 |
|
|
******************************************************************************/
|
| 30 |
|
|
|
| 31 |
|
|
/* mcount or _mcount is inserted by GCC before the function prologue of every
|
| 32 |
|
|
* function when a program is compiled for profiling. At the start of mcount,
|
| 33 |
|
|
* we guarantee that:
|
| 34 |
|
|
* ra = self_pc (an address in the function which called mcount)
|
| 35 |
|
|
* r8 = from_pc (an address in the function which called mcount's caller)
|
| 36 |
|
|
*
|
| 37 |
|
|
* Because this is always called at the start of a function we can corrupt
|
| 38 |
|
|
* r2,r3 and r11-r15. We must not corrupt r4-r7 (because they might contain
|
| 39 |
|
|
* function arguments for the instrumented function) or r8 (which holds ra
|
| 40 |
|
|
* for the instrumented function).
|
| 41 |
|
|
*/
|
| 42 |
|
|
|
| 43 |
|
|
.global __mcount_fn_head
|
| 44 |
|
|
|
| 45 |
|
|
.global mcount
|
| 46 |
|
|
|
| 47 |
|
|
/* _mcount is used by gcc4 */
|
| 48 |
|
|
.global _mcount
|
| 49 |
|
|
|
| 50 |
|
|
_mcount:
|
| 51 |
|
|
mcount:
|
| 52 |
|
|
/* Use a hash to speed up locating fn_entry. We use bits 5 upwards to choose
|
| 53 |
|
|
* the bucket because bits 1:0 will always be 0, and because the distribution
|
| 54 |
|
|
* of values for bits 4:2 won't be even (aligning on cache line boundaries
|
| 55 |
|
|
* will skew it). Higher bits should be fairly random.
|
| 56 |
|
|
*/
|
| 57 |
|
|
/* fn_head = mcount_fn_head + (((unsigned int)self_pc >> 5) & (HASH_BUCKETS - 1)); */
|
| 58 |
|
|
|
| 59 |
|
|
srli r2, ra, 3
|
| 60 |
|
|
movhi r3, %hiadj(__mcount_fn_head)
|
| 61 |
|
|
addi r3, r3, %lo(__mcount_fn_head)
|
| 62 |
|
|
andi r2, r2, 0xFC
|
| 63 |
|
|
add r11, r2, r3
|
| 64 |
|
|
|
| 65 |
|
|
/* The fast case is where we have already allocated a function arc, and so
|
| 66 |
|
|
* also a function pointer.
|
| 67 |
|
|
*/
|
| 68 |
|
|
|
| 69 |
|
|
/* First find the function being called (using self_pc) */
|
| 70 |
|
|
mov r10, r11
|
| 71 |
|
|
0:
|
| 72 |
|
|
ldw r10, 0(r10)
|
| 73 |
|
|
beq r10, zero, .Lnew_arc
|
| 74 |
|
|
ldw r2, 4(r10)
|
| 75 |
|
|
bne r2, ra, 0b
|
| 76 |
|
|
|
| 77 |
|
|
/* Found a function entry for this PC. Now look for an arc with a matching
|
| 78 |
|
|
* from_pc value. There will always be at least one arc. */
|
| 79 |
|
|
ldw r3, 8(r10)
|
| 80 |
|
|
0:
|
| 81 |
|
|
ldw r2, 4(r3)
|
| 82 |
|
|
beq r2, r8, .Lfound_arc
|
| 83 |
|
|
ldw r3, 0(r3)
|
| 84 |
|
|
bne r3, zero, 0b
|
| 85 |
|
|
|
| 86 |
|
|
.Lnew_arc:
|
| 87 |
|
|
addi sp, sp, -24
|
| 88 |
|
|
|
| 89 |
|
|
.LCFI0:
|
| 90 |
|
|
stw ra, 0(sp)
|
| 91 |
|
|
stw r4, 4(sp)
|
| 92 |
|
|
stw r5, 8(sp)
|
| 93 |
|
|
stw r6, 12(sp)
|
| 94 |
|
|
stw r7, 16(sp)
|
| 95 |
|
|
stw r8, 20(sp)
|
| 96 |
|
|
|
| 97 |
|
|
.LCFI1:
|
| 98 |
|
|
/* __mcount_record(orig_ra, orig_r8, fn_entry, *fn_head); */
|
| 99 |
|
|
mov r4, ra
|
| 100 |
|
|
mov r5, r8
|
| 101 |
|
|
mov r6, r10
|
| 102 |
|
|
mov r7, r11
|
| 103 |
|
|
call __mcount_record
|
| 104 |
|
|
|
| 105 |
|
|
/* restore registers from the stack */
|
| 106 |
|
|
ldw ra, 0(sp)
|
| 107 |
|
|
ldw r4, 4(sp)
|
| 108 |
|
|
ldw r5, 8(sp)
|
| 109 |
|
|
ldw r6, 12(sp)
|
| 110 |
|
|
ldw r7, 16(sp)
|
| 111 |
|
|
ldw r8, 20(sp)
|
| 112 |
|
|
|
| 113 |
|
|
addi sp, sp, 24
|
| 114 |
|
|
|
| 115 |
|
|
.LCFI2:
|
| 116 |
|
|
ret
|
| 117 |
|
|
|
| 118 |
|
|
.Lfound_arc:
|
| 119 |
|
|
/* We've found the correct arc record. Increment the count and return */
|
| 120 |
|
|
ldw r2, 8(r3)
|
| 121 |
|
|
addi r2, r2, 1
|
| 122 |
|
|
stw r2, 8(r3)
|
| 123 |
|
|
ret
|
| 124 |
|
|
|
| 125 |
|
|
.Lmcount_end:
|
| 126 |
|
|
|
| 127 |
|
|
|
| 128 |
|
|
|
| 129 |
|
|
/*
|
| 130 |
|
|
* Dwarf2 debug information for the function. This provides GDB with the
|
| 131 |
|
|
* information it needs to backtrace out of this function.
|
| 132 |
|
|
*/
|
| 133 |
|
|
|
| 134 |
|
|
.section .debug_frame,"",@progbits
|
| 135 |
|
|
.LCIE:
|
| 136 |
|
|
.4byte 2f - 1f /* Length */
|
| 137 |
|
|
1:
|
| 138 |
|
|
.4byte 0xffffffff /* CIE id */
|
| 139 |
|
|
.byte 0x1 /* Version */
|
| 140 |
|
|
.string "" /* Augmentation */
|
| 141 |
|
|
.uleb128 0x1 /* Code alignment factor */
|
| 142 |
|
|
.sleb128 -4 /* Data alignment factor */
|
| 143 |
|
|
.byte 0x1f /* Return address register */
|
| 144 |
|
|
|
| 145 |
|
|
.byte 0xc /* Define CFA */
|
| 146 |
|
|
.uleb128 0x1b /* Register 27 (sp) */
|
| 147 |
|
|
.uleb128 0x0 /* Offset 0 */
|
| 148 |
|
|
|
| 149 |
|
|
.align 2 /* Padding */
|
| 150 |
|
|
2:
|
| 151 |
|
|
|
| 152 |
|
|
.LFDE_mcount:
|
| 153 |
|
|
.4byte 2f - 1f /* Length */
|
| 154 |
|
|
1:
|
| 155 |
|
|
.4byte .LCIE /* Pointer to CIE */
|
| 156 |
|
|
.4byte mcount /* Start of table entry */
|
| 157 |
|
|
.4byte .Lmcount_end - mcount /* Size of table entry */
|
| 158 |
|
|
|
| 159 |
|
|
.byte 0x4 /* Advance location */
|
| 160 |
|
|
.4byte .LCFI0 - mcount /* to .LCFI0 */
|
| 161 |
|
|
.byte 0xe /* Define CFA offset */
|
| 162 |
|
|
.uleb128 24 /* to 24 */
|
| 163 |
|
|
|
| 164 |
|
|
.byte 0x4 /* Advance location */
|
| 165 |
|
|
.4byte .LCFI1 - .LCFI0 /* to .LCFI1 */
|
| 166 |
|
|
.byte 0x9f /* Store ra */
|
| 167 |
|
|
.uleb128 0x6 /* at CFA-24 */
|
| 168 |
|
|
.byte 0x84 /* Store r4 */
|
| 169 |
|
|
.uleb128 0x5 /* at CFA-20 */
|
| 170 |
|
|
.byte 0x85 /* Store r5 */
|
| 171 |
|
|
.uleb128 0x4 /* at CFA-16 */
|
| 172 |
|
|
.byte 0x86 /* Store r6 */
|
| 173 |
|
|
.uleb128 0x3 /* at CFA-12 */
|
| 174 |
|
|
.byte 0x87 /* Store r7 */
|
| 175 |
|
|
.uleb128 0x2 /* at CFA-8 */
|
| 176 |
|
|
.byte 0x88 /* Store r8 */
|
| 177 |
|
|
.uleb128 0x1 /* at CFA-4 */
|
| 178 |
|
|
|
| 179 |
|
|
.byte 0x4 /* Advance location */
|
| 180 |
|
|
.4byte .LCFI2 - .LCFI1 /* to .LCFI2 */
|
| 181 |
|
|
.byte 0xe /* Define CFA offset */
|
| 182 |
|
|
.uleb128 0 /* to 0 */
|
| 183 |
|
|
.byte 0x8 /* Same value */
|
| 184 |
|
|
.uleb128 31 /* for ra */
|
| 185 |
|
|
.byte 0x8 /* Same value */
|
| 186 |
|
|
.uleb128 4 /* for r4 */
|
| 187 |
|
|
.byte 0x8 /* Same value */
|
| 188 |
|
|
.uleb128 5 /* for r5 */
|
| 189 |
|
|
.byte 0x8 /* Same value */
|
| 190 |
|
|
.uleb128 6 /* for r6 */
|
| 191 |
|
|
.byte 0x8 /* Same value */
|
| 192 |
|
|
.uleb128 7 /* for r7 */
|
| 193 |
|
|
.byte 0x8 /* Same value */
|
| 194 |
|
|
.uleb128 8 /* for r8 */
|
| 195 |
|
|
|
| 196 |
|
|
.align 2
|
| 197 |
|
|
2:
|
| 198 |
|
|
|