1; Copyright (c) 2002-2005 ARC International
2	.file	"crti.s"
3	.option	%reg
4	.global _init, _fini
5	.extern __mw_cpp_init, __mw_cpp_exit
6	.macro jmpl,target
7	    .if $core_version > 5
8		jl	target		; "large" model call
9	    .else
10		lr	%blink, [%status]
11		add	%blink, %blink, 3
12		j	target
13	    .endif
14	.endm
15    .if	$isa == "ARCompact"
16    	.on	assume_short
17    .endif
18
19	.section ".init",text
20_init:
21    .if	$isa == "ARC"
22	st	%fp, [%sp, 0]
23	st	%blink, [%sp, 4]
24	mov	%fp, %sp
25	sub	%sp, %sp, 16
26    .else
27	.cfa_bf	_init
28	push	%blink
29	.cfa_push	{%blink}
30    .endif
31
32	.section ".init$999999", text, 1, 2, check_text_align=0
33; this is now brought in by a reference generated by the compiler
34;	jmpl	__mw_cpp_init
35    .if	$isa == "ARC"
36        ld      %blink, [%fp, 4]
37        j.d     [%blink]
38        ld.a    %fp, [%sp, 16]
39    .else
40	pop	%blink
41	.cfa_pop	{%blink}
42	j	[%blink]
43	.cfa_ef
44    .endif
45
46	.section ".fini", text
47_fini:
48    .if	$isa == "ARC"
49	st	%fp, [%sp, 0]
50	st	%blink, [%sp, 4]
51	mov	%fp, %sp
52	sub	%sp, %sp, 16
53    .else
54	.cfa_bf	_fini
55	push	%blink
56	.cfa_push	{%blink}
57    .endif
58
59	.section ".fini$999999", text, 1, 2, check_text_align=0
60;	jmpl	__mw_cpp_exit
61    .if	$isa == "ARC"
62        ld      %blink, [%fp, 4]
63        j.d     [%blink]
64        ld.a    %fp, [%sp, 16]
65    .else
66	pop	%blink
67	.cfa_pop	{%blink}
68	j	[%blink]
69	.cfa_ef
70    .endif
71	.end
72
73