1 /* 2 * mpatrol 3 * A library for controlling and tracing dynamic memory allocations. 4 * Copyright (C) 1997-2002 Graeme S. Roy <graeme.roy@analog.com> 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Library General Public 8 * License as published by the Free Software Foundation; either 9 * version 2 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Library General Public License for more details. 15 * 16 * You should have received a copy of the GNU Library General Public 17 * License along with this library; if not, write to the Free 18 * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, 19 * MA 02111-1307, USA. 20 */ 21 22 23 /* 24 * Processor-dependent assembler routines. This module contains any routines 25 * required to support a particular processor that could not be written in C 26 * or C++. Despite the filename extension, this is not a C source file, but 27 * is named this way so that it can be preprocessed by the C compiler before 28 * being assembled. 29 */ 30 31 32 #include "config.h" 33 34 35 #if MP_INIT_SUPPORT 36 /* Provide support for initialising the mpatrol mutexes and data structures 37 * before main() is called. This is preferred over any other such solutions 38 * on the following systems since it means that we can link with any compiler 39 * rather than relying on linking with the same compiler that built the mutex 40 * module. We can also use exactly the same system when terminating the 41 * mpatrol library. 42 */ 43 44 45 #if ARCH == ARCH_IX86 46 /* Define the __mp_initsection variable. 47 */ 48 49 .section .data,"aw" 50 .align 2 51 __mp_initsection: 52 .long 1 53 .globl __mp_initsection 54 .type __mp_initsection,@object 55 .size __mp_initsection,4 56 57 58 /* Place calls to initialise the mpatrol mutexes and data structures into 59 * the .init section and a call to terminate the mpatrol library in the 60 * .fini section. 61 */ 62 63 .section .init,"ax" 64 #if MP_THREADS_SUPPORT 65 call __mp_initmutexes 66 #endif /* MP_THREADS_SUPPORT */ 67 call __mp_init 68 69 #if !MP_USE_ATEXIT 70 .section .fini,"ax" 71 call __mp_fini 72 #endif /* MP_USE_ATEXIT */ 73 #elif ARCH == ARCH_M68K 74 /* Define the __mp_initsection variable. 75 */ 76 77 .section .data,"aw",@progbits 78 .align 2 79 __mp_initsection: 80 .long 1 81 .globl __mp_initsection 82 .type __mp_initsection,@object 83 .size __mp_initsection,4 84 85 86 /* Place calls to initialise the mpatrol mutexes and data structures into 87 * the .init section and a call to terminate the mpatrol library in the 88 * .fini section. 89 */ 90 91 .section .init,"ax",@progbits 92 #if MP_THREADS_SUPPORT 93 jbsr __mp_initmutexes 94 #endif /* MP_THREADS_SUPPORT */ 95 jbsr __mp_init 96 97 #if !MP_USE_ATEXIT 98 .section .fini,"ax",@progbits 99 jbsr __mp_fini 100 #endif /* MP_USE_ATEXIT */ 101 #elif ARCH == ARCH_M88K 102 /* Define the __mp_initsection variable. 103 */ 104 105 section .data,"aw",#progbits 106 align 4 107 ___mp_initsection: 108 word 1 109 global ___mp_initsection 110 type ___mp_initsection,#object 111 size ___mp_initsection,4 112 113 114 /* Place calls to initialise the mpatrol mutexes and data structures into 115 * the .init section and a call to terminate the mpatrol library in the 116 * .fini section. 117 */ 118 119 section .init,"ax",#progbits 120 #if MP_THREADS_SUPPORT 121 bsr ___mp_initmutexes 122 #endif /* MP_THREADS_SUPPORT */ 123 bsr ___mp_init 124 125 #if !MP_USE_ATEXIT 126 section .fini,"ax",#progbits 127 bsr ___mp_fini 128 #endif /* MP_USE_ATEXIT */ 129 #elif ARCH == ARCH_SPARC 130 /* Define the __mp_initsection variable. 131 */ 132 133 .section ".data",#alloc,#write 134 .align 4 135 __mp_initsection: 136 .word 1 137 .global __mp_initsection 138 .type __mp_initsection,#object 139 .size __mp_initsection,4 140 141 142 /* Place calls to initialise the mpatrol mutexes and data structures into 143 * the .init section and a call to terminate the mpatrol library in the 144 * .fini section. 145 */ 146 147 .section ".init",#alloc,#execinstr 148 #if MP_THREADS_SUPPORT 149 call __mp_initmutexes 150 nop 151 #endif /* MP_THREADS_SUPPORT */ 152 call __mp_init 153 nop 154 155 #if !MP_USE_ATEXIT 156 .section ".fini",#alloc,#execinstr 157 call __mp_fini 158 nop 159 #endif /* MP_USE_ATEXIT */ 160 #endif /* ARCH */ 161 #endif /* MP_INIT_SUPPORT */ 162 163 164 #if !MP_BUILTINSTACK_SUPPORT 165 #if MP_LIBRARYSTACK_SUPPORT 166 #if SYSTEM == SYSTEM_HPUX 167 /* A similar function to this also resides in the system traceback library, 168 * libcl, but it must belong to the executable module rather than reside in 169 * a shared library, hence its inclusion here. 170 */ 171 172 173 /* Fill in the frameinfo structure for the current function. 174 */ 175 176 .CODE 177 __mp_frameinfo 178 .PROC 179 .CALLINFO 180 .ENTRY 181 stw sp,4(arg0) 182 mfsp sr4,r20 183 stw r20,8(arg0) 184 stw rp,12(arg0) 185 stw dp,16(arg0) 186 stw r3,36(arg0) 187 stw r4,44(arg0) 188 stw r0,0(arg0) 189 stw r0,20(arg0) 190 stw r19,40(arg0) 191 bv r0(rp) 192 .EXIT 193 stw r0,24(arg0) 194 .PROCEND 195 .EXPORT __mp_frameinfo,CODE,PRIV_LEV=3 196 .END 197 #endif /* SYSTEM */ 198 #else /* MP_LIBRARYSTACK_SUPPORT */ 199 #if ARCH == ARCH_MIPS 200 /* Not all MIPS platforms have the getcontext() function, and even those that 201 * do may not enter the correct return address into the ucontext_t structure. 202 * So, unfortunately we have to provide assembler routines to obtain the 203 * correct information. 204 */ 205 206 207 /* Obtain the stack pointer for the current function. 208 */ 209 210 .text 211 .globl __mp_stackpointer 212 .ent __mp_stackpointer 213 __mp_stackpointer: 214 .frame $29,0,$31 215 move $2,$29 216 j $31 217 .end __mp_stackpointer 218 219 220 /* Obtain the return address for the current function. 221 */ 222 223 .text 224 .globl __mp_returnaddress 225 .ent __mp_returnaddress 226 __mp_returnaddress: 227 .frame $29,0,$31 228 move $2,$31 229 j $31 230 .end __mp_returnaddress 231 #elif ARCH == ARCH_SPARC 232 #if SYSTEM == SYSTEM_LINUX || SYSTEM == SYSTEM_SUNOS 233 /* Linux and SunOS platforms do not have the getcontext() function so 234 * unfortunately we have to provide an assembler routine to obtain the stack 235 * pointer. 236 */ 237 238 239 /* Obtain the stack pointer for the current function. 240 */ 241 242 #if SYSTEM == SYSTEM_LINUX 243 .text 244 __mp_stackpointer: 245 ta 0x03 246 retl 247 mov %sp,%o0 248 .global __mp_stackpointer 249 .type __mp_stackpointer,#function 250 .size __mp_stackpointer,.-__mp_stackpointer 251 #elif SYSTEM == SYSTEM_SUNOS 252 .text 253 .global ___mp_stackpointer 254 ___mp_stackpointer: 255 ta 0x03 256 retl 257 mov %sp,%o0 258 #endif /* SYSTEM */ 259 #endif /* SYSTEM */ 260 #endif /* ARCH */ 261 #endif /* MP_LIBRARYSTACK_SUPPORT */ 262 #endif /* MP_BUILTINSTACK_SUPPORT */ 263