Welcome to mirror list, hosted at ThFree Co, Russian Federation.

crt0.S « msp430 « libgloss - cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9ea25c13172b1480eec6b172a27ae2fddf8cc41f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/* Copyright (c) 2012-2013 Red Hat, Inc. All rights reserved.

   This copyrighted material is made available to anyone wishing to use, modify,
   copy, or redistribute it subject to the terms and conditions of the BSD
   License.   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY expressed or implied, including the implied warranties
   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  A copy of this license
   is available at http://www.opensource.org/licenses. Any Red Hat trademarks that
   are incorporated in the source code or documentation are not subject to the BSD
   License and may only be used or replicated with the express permission of
   Red Hat, Inc.
*/

#include "memmodel.h"

;; The linker links all .crt_* sections in asciibetical order at the
;; same place.  So, the four digits in .crt_NNNN determine the link
;; order, so, keep them in sequential order here.  The first two
;; digits are set here, the second two allow users to insert code
;; between code fragments here.

#if L0
	.section ".resetvec", "a"
__msp430_resetvec_hook:
	.word	__start

	.section ".crt_0000init", "ax", @progbits
	.refsym	__msp430_resetvec_hook
#ifdef MINRT
	.refsym	__crt0_call_just_main
#else
	.refsym	__crt0_call_init_then_main
#endif
	.global __start
__start:
	mov_	#__stack, R1

	;; Disable watchdog timer.
	MOV	#0x5a80, &0x15C
#endif

#if Lbss
	.section ".crt_0100bss", "ax", @progbits

	.global __crt0_init_bss
__crt0_init_bss:	
	
	mov_	#__bssstart, R12
	clr.w	R13
	mov.w	#__bsssize, R14
#ifdef __MSP430X_LARGE__
	clr.w	R15		; We assume that __bsssize is never > 64M
#endif
	call_	#memset
#endif

#if Lmovedata
	.section ".crt_0200movedata", "ax", @progbits

	.global __crt0_movedata
__crt0_movedata:	
	
	mov_	#__datastart, R12
	mov_	#__romdatastart, R13

	;;  memmove and memcpy do not currently work when src == dst
	cmp_	R12, R13
	jeq	1f

	mov.w	#__romdatacopysize, R14
#ifdef __MSP430X_LARGE__
	clr.w	R15		; We assume that __romdatacopysize is never > 64M
#endif
	call_	#memmove
1:	
#endif

#if Lmain_minrt
	.section ".crt_0300main", "ax", @progbits
	.global	__crt0_call_just_main
__crt0_call_just_main:
	clr.w	R12		; Set argc == 0
	call_	#main
#endif

#if Lmain
	.section ".crt_0300main", "ax", @progbits
	.global	__crt0_call_init_then_main
__crt0_call_init_then_main:
	call_	#__msp430_init

	clr.w	R12		; Set argc == 0
	call_	#main
#endif

#if Lcallexit
	.section ".crt_0400main_exit", "ax", @progbits
	.global	__crt0_call_exit
__crt0_call_exit:
	call_	#_exit
#endif

;----------------------------------------

#ifndef MINRT
#if L0
	.section ".crt_0500main_init", "ax", @progbits
	.global	_msp430_run_init_array
	.type	_msp430_run_init_array,@function
_msp430_run_init_array:
	mov_	#__init_array_start, R4
	mov_	#__init_array_end, R5
	mov_	#PTRsz, R6
	br_	#_msp430_run_array

	.global	_msp430_run_preinit_array
	.type	_msp430_run_preinit_array,@function
_msp430_run_preinit_array:
	mov_	#__preinit_array_start, R4
	mov_	#__preinit_array_end, R5
	mov_	#PTRsz, R6
	br_	#_msp430_run_array

	.global	_msp430_run_fini_array
	.type	_msp430_run_fini_array,@function
_msp430_run_fini_array:
	mov_	#__fini_array_start, R4
	mov_	#__fini_array_end, R5
	mov_	#-PTRsz, R6
	br_	#_msp430_run_array

_msp430_run_array:
	cmp_	R4, R5
	jeq	_msp430_run_done
	mov_	@R4, R7
	add_	R6, R4
	call_	@R7
	br_	_msp430_run_array

_msp430_run_done:
	ret_

;----------------------------------------

	.section	.init,"ax"

	.global __msp430_init
__msp430_init:

	.section	.fini,"ax"

	.global __msp430_fini
__msp430_fini:
	call_	#_msp430_run_fini_array
	
#endif
#endif