1d8315c79SWarner Losh /*- 26fc729afSOlivier Houchard * Copyright (c) 1992, 1993 36fc729afSOlivier Houchard * The Regents of the University of California. All rights reserved. 46fc729afSOlivier Houchard * 56fc729afSOlivier Houchard * Redistribution and use in source and binary forms, with or without 66fc729afSOlivier Houchard * modification, are permitted provided that the following conditions 76fc729afSOlivier Houchard * are met: 86fc729afSOlivier Houchard * 1. Redistributions of source code must retain the above copyright 96fc729afSOlivier Houchard * notice, this list of conditions and the following disclaimer. 106fc729afSOlivier Houchard * 2. Redistributions in binary form must reproduce the above copyright 116fc729afSOlivier Houchard * notice, this list of conditions and the following disclaimer in the 126fc729afSOlivier Houchard * documentation and/or other materials provided with the distribution. 136fc729afSOlivier Houchard * 3. All advertising materials mentioning features or use of this software 146fc729afSOlivier Houchard * must display the following acknowledgement: 156fc729afSOlivier Houchard * This product includes software developed by the University of 166fc729afSOlivier Houchard * California, Berkeley and its contributors. 176fc729afSOlivier Houchard * 4. Neither the name of the University nor the names of its contributors 186fc729afSOlivier Houchard * may be used to endorse or promote products derived from this software 196fc729afSOlivier Houchard * without specific prior written permission. 206fc729afSOlivier Houchard * 216fc729afSOlivier Houchard * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 226fc729afSOlivier Houchard * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 236fc729afSOlivier Houchard * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 246fc729afSOlivier Houchard * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 256fc729afSOlivier Houchard * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 266fc729afSOlivier Houchard * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 276fc729afSOlivier Houchard * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 286fc729afSOlivier Houchard * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 296fc729afSOlivier Houchard * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 306fc729afSOlivier Houchard * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 316fc729afSOlivier Houchard * SUCH DAMAGE. 326fc729afSOlivier Houchard * 336fc729afSOlivier Houchard * @(#)profile.h 8.1 (Berkeley) 6/11/93 346fc729afSOlivier Houchard * $FreeBSD$ 356fc729afSOlivier Houchard */ 366fc729afSOlivier Houchard 376fc729afSOlivier Houchard #ifndef _MACHINE_PROFILE_H_ 386fc729afSOlivier Houchard #define _MACHINE_PROFILE_H_ 396fc729afSOlivier Houchard 406fc729afSOlivier Houchard /* 41ffa589bfSOlivier Houchard * Config generates something to tell the compiler to align functions on 32 426fc729afSOlivier Houchard * byte boundaries. A strict alignment is good for keeping the tables small. 436fc729afSOlivier Houchard */ 446fc729afSOlivier Houchard #define FUNCTION_ALIGNMENT 16 456fc729afSOlivier Houchard 46ffa589bfSOlivier Houchard 476fc729afSOlivier Houchard #define _MCOUNT_DECL void mcount 486fc729afSOlivier Houchard 49ffa589bfSOlivier Houchard typedef u_long fptrdiff_t; 50ffa589bfSOlivier Houchard 51ffa589bfSOlivier Houchard /* 52ffa589bfSOlivier Houchard * Cannot implement mcount in C as GCC will trash the ip register when it 53ffa589bfSOlivier Houchard * pushes a trapframe. Pity we cannot insert assembly before the function 54ffa589bfSOlivier Houchard * prologue. 55ffa589bfSOlivier Houchard */ 56ffa589bfSOlivier Houchard 57ffa589bfSOlivier Houchard #ifndef PLTSYM 58ffa589bfSOlivier Houchard #define PLTSYM 596fc729afSOlivier Houchard #endif 606fc729afSOlivier Houchard 61ffa589bfSOlivier Houchard #define MCOUNT \ 62ffa589bfSOlivier Houchard __asm__(".text"); \ 63301e1601SIan Lepore __asm__(".align 2"); \ 64705fda84SOlivier Houchard __asm__(".type __mcount ,%function"); \ 65705fda84SOlivier Houchard __asm__(".global __mcount"); \ 66705fda84SOlivier Houchard __asm__("__mcount:"); \ 67ffa589bfSOlivier Houchard /* \ 68ffa589bfSOlivier Houchard * Preserve registers that are trashed during mcount \ 69ffa589bfSOlivier Houchard */ \ 70ffa589bfSOlivier Houchard __asm__("stmfd sp!, {r0-r3, ip, lr}"); \ 71ffa589bfSOlivier Houchard /* \ 72ffa589bfSOlivier Houchard * find the return address for mcount, \ 73ffa589bfSOlivier Houchard * and the return address for mcount's caller. \ 74ffa589bfSOlivier Houchard * \ 75ffa589bfSOlivier Houchard * frompcindex = pc pushed by call into self. \ 76ffa589bfSOlivier Houchard */ \ 77ffa589bfSOlivier Houchard __asm__("mov r0, ip"); \ 78ffa589bfSOlivier Houchard /* \ 79ffa589bfSOlivier Houchard * selfpc = pc pushed by mcount call \ 80ffa589bfSOlivier Houchard */ \ 81ffa589bfSOlivier Houchard __asm__("mov r1, lr"); \ 82ffa589bfSOlivier Houchard /* \ 83ffa589bfSOlivier Houchard * Call the real mcount code \ 84ffa589bfSOlivier Houchard */ \ 85ffa589bfSOlivier Houchard __asm__("bl mcount"); \ 86ffa589bfSOlivier Houchard /* \ 87ffa589bfSOlivier Houchard * Restore registers that were trashed during mcount \ 88ffa589bfSOlivier Houchard */ \ 89*8e35ef81SAndrew Turner __asm__("ldmfd sp!, {r0-r3, lr}"); \ 90*8e35ef81SAndrew Turner /* \ 91*8e35ef81SAndrew Turner * Return to the caller. Loading lr and pc in one instruction \ 92*8e35ef81SAndrew Turner * is deprecated on ARMv7 so we need this on it's own. \ 93*8e35ef81SAndrew Turner */ \ 94*8e35ef81SAndrew Turner __asm__("ldmfd sp!, {pc}"); 950f2fe153SMarcel Moolenaar void bintr(void); 960f2fe153SMarcel Moolenaar void btrap(void); 970f2fe153SMarcel Moolenaar void eintr(void); 980f2fe153SMarcel Moolenaar void user(void); 990f2fe153SMarcel Moolenaar 1000f2fe153SMarcel Moolenaar #define MCOUNT_FROMPC_USER(pc) \ 1010f2fe153SMarcel Moolenaar ((pc < (uintfptr_t)VM_MAXUSER_ADDRESS) ? (uintfptr_t)user : pc) 1020f2fe153SMarcel Moolenaar 1030f2fe153SMarcel Moolenaar #define MCOUNT_FROMPC_INTR(pc) \ 1040f2fe153SMarcel Moolenaar ((pc >= (uintfptr_t)btrap && pc < (uintfptr_t)eintr) ? \ 1050f2fe153SMarcel Moolenaar ((pc >= (uintfptr_t)bintr) ? (uintfptr_t)bintr : \ 1060f2fe153SMarcel Moolenaar (uintfptr_t)btrap) : ~0U) 1070f2fe153SMarcel Moolenaar 1086fc729afSOlivier Houchard 1096fc729afSOlivier Houchard #ifdef _KERNEL 1106fc729afSOlivier Houchard 111ffa589bfSOlivier Houchard #define MCOUNT_DECL(s) register_t s; 112ffa589bfSOlivier Houchard 113ffa589bfSOlivier Houchard #include <machine/asm.h> 114ffa589bfSOlivier Houchard #include <machine/cpufunc.h> 115ffa589bfSOlivier Houchard /* 116ffa589bfSOlivier Houchard * splhigh() and splx() are heavyweight, and call mcount(). Therefore 117ffa589bfSOlivier Houchard * we disabled interrupts (IRQ, but not FIQ) directly on the CPU. 118ffa589bfSOlivier Houchard * 119ffa589bfSOlivier Houchard * We're lucky that the CPSR and 's' both happen to be 'int's. 120ffa589bfSOlivier Houchard */ 121ffa589bfSOlivier Houchard #define MCOUNT_ENTER(s) {s = intr_disable(); } /* kill IRQ */ 122ffa589bfSOlivier Houchard #define MCOUNT_EXIT(s) {intr_restore(s); } /* restore old value */ 123ffa589bfSOlivier Houchard 1246fc729afSOlivier Houchard void mcount(uintfptr_t frompc, uintfptr_t selfpc); 1256fc729afSOlivier Houchard 126ffa589bfSOlivier Houchard #else 127ffa589bfSOlivier Houchard typedef u_int uintfptr_t; 1286fc729afSOlivier Houchard #endif /* _KERNEL */ 1296fc729afSOlivier Houchard 1306fc729afSOlivier Houchard #endif /* !_MACHINE_PROFILE_H_ */ 131