annotate packages/hal/cortexm/arch/current/src/mcount.S @ 3357:0e7f32e78b4d

* src/mcount.S: Add mcount functions for call-graph profiling. * cdl/hal_cortexm.cdl: Add option to build mcount functions. [ Bugzilla 1001954 ]
author jld
date Mon, 03 Mar 2014 08:30:32 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3357
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
1 /*==========================================================================
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
2 //
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
3 // mcount.S
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
4 //
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
5 // Cortex-M mcount implementation
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
6 //
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
7 //==========================================================================
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
8 // ####ECOSGPLCOPYRIGHTBEGIN####
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
9 // -------------------------------------------
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
10 // This file is part of eCos, the Embedded Configurable Operating System.
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
11 // Copyright (C) 2014 Free Software Foundation, Inc.
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
12 //
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
13 // eCos is free software; you can redistribute it and/or modify it under
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
14 // the terms of the GNU General Public License as published by the Free
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
15 // Software Foundation; either version 2 or (at your option) any later
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
16 // version.
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
17 //
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
18 // eCos is distributed in the hope that it will be useful, but WITHOUT
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
19 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
20 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
21 // for more details.
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
22 //
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
23 // You should have received a copy of the GNU General Public License
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
24 // along with eCos; if not, write to the Free Software Foundation, Inc.,
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
25 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
26 //
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
27 // As a special exception, if other files instantiate templates or use
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
28 // macros or inline functions from this file, or you compile this file
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
29 // and link it with other works to produce a work based on this file,
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
30 // this file does not by itself cause the resulting work to be covered by
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
31 // the GNU General Public License. However the source code for this file
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
32 // must still be made available in accordance with section (3) of the GNU
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
33 // General Public License v2.
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
34 //
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
35 // This exception does not invalidate any other reasons why a work based
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
36 // on this file might be covered by the GNU General Public License.
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
37 // -------------------------------------------
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
38 // ####ECOSGPLCOPYRIGHTEND####
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
39 //==========================================================================
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
40 //#####DESCRIPTIONBEGIN####
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
41 //
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
42 // Author(s): jld
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
43 // Contributor(s):
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
44 // Date: 2014-02-28
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
45 // Description: This file provides mcount functions used for
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
46 // call-graph profiling.
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
47 //
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
48 //####DESCRIPTIONEND####
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
49 //
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
50 //========================================================================
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
51 */
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
52
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
53 #include <pkgconf/hal_cortexm.h>
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
54
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
55 /*
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
56 // GCC inserts mcount code at the start of every function when compiling
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
57 // with "-pg". For GCC prior to version 4.4 targeting Cortex-M,
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
58 // the following code is inserted:
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
59 //
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
60 // mov r12, lr
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
61 // bl mcount
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
62 // .word <data pointer>
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
63 //
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
64 // For GCC version 4.4 and later targeting Cortex-M, the following code is
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
65 // inserted:
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
66 //
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
67 // push { lr }
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
68 // bl __gnu_mcount_nc
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
69 //
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
70 // We provide implementations of both mcount() and __gnu_mcount_nc() to
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
71 // call the eCos __profile_mcount() function.
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
72 */
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
73
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
74 .syntax unified
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
75 .globl mcount
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
76 .section .text.mcount
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
77 .thumb_func
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
78 mcount:
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
79 // resume execution beyond the data pointer on return to caller
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
80 add lr, lr, #4
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
81
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
82 // caller assumes r0-r3 will be preserved (non-AAPCS), we use
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
83 // r6 and must preserve lr across our __profile_mcount() call
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
84 push { r0, r1, r2, r3, r6, lr }
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
85
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
86 // set up parameters for __profile_mcount()
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
87 sub r0, r12, #2
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
88 bic r0, r0, #1
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
89 bic r1, lr, #1
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
90
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
91 // disable interrupts
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
92 mov r2, #CYGNUM_HAL_CORTEXM_PRIORITY_MAX
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
93 mrs r6, basepri
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
94 msr basepri, r2
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
95
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
96 // call eCos __profile_mcount()
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
97 // r6 is preserved across the call per AAPCS
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
98 bl __profile_mcount
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
99
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
100 // restore interrupts
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
101 msr basepri, r6
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
102
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
103 // restore registers and return
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
104 pop { r0, r1, r2, r3, r6, pc }
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
105
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
106
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
107 .globl __gnu_mcount_nc
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
108 .section .text.__gnu_mcount_nc
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
109 .thumb_func
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
110 __gnu_mcount_nc:
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
111 // caller assumes r0-r3 will be preserved (non-AAPCS), we use
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
112 // r6 and must preserve lr across our __profile_mcount() call
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
113 push { r0, r1, r2, r3, r6, lr }
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
114
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
115 // set up parameters for __profile_mcount()
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
116 ldr r0, [ sp, #24 ]
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
117 sub r0, r0, #2
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
118 bic r0, r0, #1
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
119 bic r1, lr, #1
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
120
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
121 // disable interrupts
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
122 mov r2, #CYGNUM_HAL_CORTEXM_PRIORITY_MAX
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
123 mrs r6, basepri
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
124 msr basepri, r2
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
125
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
126 // call eCos __profile_mcount()
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
127 // r6 is preserved across the call per AAPCS
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
128 bl __profile_mcount
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
129
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
130 // restore interrupts
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
131 msr basepri, r6
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
132
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
133 // restore registers and return
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
134 pop { r0, r1, r2, r3, r6, r12, lr }
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
135 bx r12
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
136
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
137 //==========================================================================
0e7f32e78b4d * src/mcount.S: Add mcount functions for call-graph profiling.
jld
parents:
diff changeset
138 // end of mcount.S