Annotation of sys/arch/arm/include/profile.h, Revision 1.1.1.1
1.1 nbrk 1: /* $OpenBSD: profile.h,v 1.1 2004/02/01 05:09:49 drahn Exp $ */
2: /* $NetBSD: profile.h,v 1.5 2002/03/24 15:49:40 bjh21 Exp $ */
3:
4: /*
5: * Copyright (c) 2001 Ben Harris
6: * Copyright (c) 1995-1996 Mark Brinicombe
7: *
8: * Redistribution and use in source and binary forms, with or without
9: * modification, are permitted provided that the following conditions
10: * are met:
11: * 1. Redistributions of source code must retain the above copyright
12: * notice, this list of conditions and the following disclaimer.
13: * 2. Redistributions in binary form must reproduce the above copyright
14: * notice, this list of conditions and the following disclaimer in the
15: * documentation and/or other materials provided with the distribution.
16: * 3. All advertising materials mentioning features or use of this software
17: * must display the following acknowledgement:
18: * This product includes software developed by Mark Brinicombe.
19: * 4. The name of the author may not be used to endorse or promote products
20: * derived from this software without specific prior written permission.
21: *
22: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32: */
33:
34: #define _MCOUNT_DECL void _mcount
35:
36: /*
37: * Cannot implement mcount in C as GCC will trash the ip register when it
38: * pushes a trapframe. Pity we cannot insert assembly before the function
39: * prologue.
40: */
41:
42: #ifdef __ELF__
43: #define MCOUNT_ASM_NAME "__mcount"
44: #ifdef PIC
45: #define PLTSYM "(PLT)"
46: #endif
47: #else
48: #define MCOUNT_ASM_NAME "mcount"
49: #endif
50:
51: #ifndef PLTSYM
52: #define PLTSYM
53: #endif
54:
55: #define MCOUNT \
56: __asm__(".text"); \
57: __asm__(".align 0"); \
58: __asm__(".type " MCOUNT_ASM_NAME ",%function"); \
59: __asm__(".global " MCOUNT_ASM_NAME); \
60: __asm__(MCOUNT_ASM_NAME ":"); \
61: /* \
62: * Preserve registers that are trashed during mcount \
63: */ \
64: __asm__("stmfd sp!, {r0-r3, ip, lr}"); \
65: /* Check what mode we're in. EQ => 32, NE => 26 */ \
66: __asm__("teq r0, r0"); \
67: __asm__("teq pc, r15"); \
68: /* \
69: * find the return address for mcount, \
70: * and the return address for mcount's caller. \
71: * \
72: * frompcindex = pc pushed by call into self. \
73: */ \
74: __asm__("moveq r0, ip"); \
75: __asm__("bicne r0, ip, #0xfc000003"); \
76: /* \
77: * selfpc = pc pushed by mcount call \
78: */ \
79: __asm__("moveq r1, lr"); \
80: __asm__("bicne r1, lr, #0xfc000003"); \
81: /* \
82: * Call the real mcount code \
83: */ \
84: __asm__("bl " __STRING(_mcount) PLTSYM); \
85: /* \
86: * Restore registers that were trashed during mcount \
87: */ \
88: __asm__("ldmfd sp!, {r0-r3, lr, pc}");
89:
90: #ifdef _KERNEL
91: #ifdef __PROG26
92: extern int int_off_save(void);
93: extern void int_restore(int);
94: #define MCOUNT_ENTER (s = int_off_save())
95: #define MCOUNT_EXIT int_restore(s)
96: #else
97: #include <arm/cpufunc.h>
98: /*
99: * splhigh() and splx() are heavyweight, and call mcount(). Therefore
100: * we disabled interrupts (IRQ, but not FIQ) directly on the CPU.
101: *
102: * We're lucky that the CPSR and 's' both happen to be 'int's.
103: */
104: #define MCOUNT_ENTER s = __set_cpsr_c(0x0080, 0x0080); /* kill IRQ */
105: #define MCOUNT_EXIT __set_cpsr_c(0xffffffff, s); /* restore old value */
106: #endif /* !acorn26 */
107: #endif /* _KERNEL */
CVSweb