Wed May 29 00:57:37 1996 David Mosberger-Tang <davidm@azstarnet.com>
[platform/upstream/glibc.git] / sysdeps / alpha / bb_init_func.S
1 /* Copyright (C) 1996 Free Software Foundation, Inc.
2    Contributed by David Mosberger (davidm@cs.arizona.edu).
3
4 This file is part of the GNU C Library.
5
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
10
11 The GNU C 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 the GNU C Library; see the file COPYING.LIB.  If
18 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
19 Cambridge, MA 02139, USA.  */
20
21 /* __bb_init_func is invoked at the beginning of each function, before
22 any registers have been saved.  It is therefore safe to use any
23 caller-saved (call-used) registers (except for argument registers
24 a1-a5). */
25
26 #include <sysdep.h>
27
28 /*
29  * These offsets should match with "struct bb" declared in gcc/libgcc2.c.
30  */
31 #define ZERO_WORD       0x00
32 #define NEXT            0x20
33
34         .set    noat
35         .set    noreorder
36
37 ENTRY(__bb_init_func)
38         .prologue 0
39
40         ldq     t0, ZERO_WORD(a0)       /* t0 <- blocks->zero_word */
41         beq     t0, init                /* not initialized yet -> */
42         ret
43         
44 END(__bb_init_func)
45
46 .ent init
47 init:
48         .frame  sp, 0x38, ra, 0
49         subq    sp, 0x38, sp
50         .prologue 0
51
52         stq     pv, 0x30(sp)
53         br      pv, 1f
54 1:      ldgp    gp, 0(pv)
55
56         lda     t1, __bb_head
57         lda     t3, _gmonparam
58         ldq     t2, 0(t1)
59         ldl     t3, 0(t3)               /* t3 = _gmonparam.state */
60         ldi     t0, 1
61         stq     t0, ZERO_WORD(a0)       /* blocks->zero_word = 1 */
62         stq     t2, NEXT(a0)            /* blocks->next = __bb_head */
63         stq     a0, 0(t1)
64         bne     t2, leave
65         beq     t3, leave               /* t3 == GMON_PROF_ON? yes -> */
66
67         /* also need to initialize destructor: */
68         stq     ra, 0x00(sp)
69         lda     a0, __bb_exit_func
70         stq     a1, 0x08(sp)
71         lda     pv, atexit
72         stq     a2, 0x10(sp)
73         stq     a3, 0x18(sp)
74         stq     a4, 0x20(sp)
75         stq     a5, 0x28(sp)
76         jsr     ra, (pv), atexit
77         ldq     ra, 0x00(sp)
78         ldq     a1, 0x08(sp)
79         ldq     a2, 0x10(sp)
80         ldq     a3, 0x18(sp)
81         ldq     a4, 0x20(sp)
82         ldq     a5, 0x28(sp)
83
84 leave:  ldq     pv, 0x30(sp)
85         addq    sp, 0x38, sp
86         ret
87
88 .end init