1 #ifndef _M88K_PROFILE_H_ 2 #define _M88K_PROFILE_H_ 3 /* $OpenBSD: profile.h,v 1.7 2013/02/14 05:56:02 miod Exp $ */ 4 /* 5 * Copyright (c) 2004, Miodrag Vallat. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 25 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 #define _MCOUNT_DECL void _mcount 30 31 /* 32 * On OpenBSD, calls to the function profiler save r2-r9 on stack. The 33 * monitor point is found in r2. The function's return address is taken 34 * from the stack frame pointed to by r30, and needs to be restored as 35 * r1 hasn't have had a chance to be saved yet. 36 */ 37 38 #ifdef __PIC__ 39 #define MCOUNT_SYMBOL "_mcount#plt" 40 #else 41 #define MCOUNT_SYMBOL "_mcount" 42 #endif 43 44 #define MCOUNT \ 45 __asm__ (".text;" \ 46 ".align 3;" \ 47 ".globl __mcount;" \ 48 ".type __mcount,@function;" \ 49 "__mcount:" \ 50 " subu %r31, %r31, 16;" \ 51 " st %r1, %r31, 4;" \ 52 " bsr.n " MCOUNT_SYMBOL ";" \ 53 " ld %r3, %r30, 4;" /* function return address */ \ 54 " ld %r2, %r31, 4;" \ 55 " addu %r31, %r31, 16;" \ 56 " jmp.n %r2;" \ 57 " ld %r1, %r30, 4;" /* restore r1 */ \ 58 ".size __mcount, .-__mcount"); 59 60 #ifdef _KERNEL 61 #define MCOUNT_ENTER do { s = get_psr(); set_psr(s | PSR_IND); } while (0) 62 #define MCOUNT_EXIT set_psr(s) 63 #endif /* _KERNEL */ 64 65 #endif /* _M88K_PROFILE_H_ */ 66