summaryrefslogtreecommitdiff
path: root/nuttx/arch/sh/src/m16c/m16c_head.S
blob: 4709463139fe212ec60c31e2466a22d37feb0953 (plain) (blame)
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
/************************************************************************************
 * arch/sh/src/m16c/m16c_head.S
 *
 *	 Copyright (C) 2009, 2012 Gregory Nutt. All rights reserved.
 *	 Author: Gregory Nutt <gnutt@nuttx.org>
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *		notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *		notice, this list of conditions and the following disclaimer in
 *		the documentation and/or other materials provided with the
 *		distribution.
 * 3. Neither the name NuttX nor the names of its contributors may be
 *		used to endorse or promote products derived from this software
 *		without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 ************************************************************************************/

/************************************************************************************
 * Included Files
 ************************************************************************************/

#include <nuttx/config.h>
#include "chip.h"
#include "up_internal.h"

/************************************************************************************
 * Pre-processor Definitions
 ************************************************************************************/

/************************************************************************************
 * Macro Definitions
 ************************************************************************************/

/*****************************************************************************
 * Name: showprogress
 *
 * Description:
 *   Print a character on the UART to show boot status.
 *
 *****************************************************************************/

	.macro	showprogress, code
#ifdef CONFIG_DEBUG
	.globl	_up_lowputc
	mov.b	r#\code1l		/* Character to print */
	jsr.a	_up_lowputc		/* Print it */
#endif
	.endm

/************************************************************************************
 * Data
 ************************************************************************************/

/* The near RAM memory map is as follows:
 * 
 * 0x00400 - DATA		Size: Determined by linker
 *           BSS		Size: Determined by linker
 *           Interrupt stack	Size: CONFIG_ARCH_INTERRUPTSTACK
 *           Idle stack		Size: CONFIG_IDLETHREAD_STACKSIZE
 *           Heap		Size: Everything remaining
 * 0x00bff - (end+1)
 */

	.section .rodata
	.globl	_g_snbss
	.type	_g_snbss, object
_g_snbss:
	.word	_g_snbss
	.size	_g_snbss, .-_g_snbss

	.globl	_g_enbss
	.type	_g_enbss, object
_g_enbss:
	.word	_g_enbss
	.size	_g_enbss, .-_g_enbss

	.globl	_g_sndata
	.type	_g_sndata, object
_g_sndata:
	.word	_g_sndata
	.size	_g_sndata, .-_g_sndata

	.globl	_g_endata
	.type	_g_endata, object
_g_endata:
	.word	_g_endata
	.size	_g_endata, .-_g_endata

	.globl	_g_enronly
	.type	_g_enronly, object
_g_enronly:
	.long	_g_enronly
	.size	_g_enronly, .-_g_efronly

#ifdef CONFIG_M16C_HAVEFARRAM
	.globl	_g_sfbss
	.type	_g_sfbss, object
_g_sfbss:
	.long	_g_sfbss
	.size	_g_sfbss, .-_g_sfbss

	.globl	_g_efbss
	.type	_g_efbss, object
_g_efbss:
	.long	_g_efbss
	.size	_g_efbss, .-_g_efbss

	.globl	_g_sfdata
	.type	_g_sfdata, object
_g_sfdata:
	.long	_g_sfdata
	.size	_g_sfdata, .-_g_sfdata

	.globl	_g_efdata
	.type	_g_efdata, object
_g_efdata:
	.long	_g_efdata
	.size	_g_efdata, .-_g_efdata

	.globl	_g_efronly
	.type	_g_efronly, object
_g_efronly:
	.long	_g_efronly
	.size	_g_efronly, .-_g_efronly
#endif
	.globl	_g_svarvect
	.type	_g_svarvect, object
_g_svarvect:
	.long	_svarvect
	.size	_g_svarvect, .-_g_svarvect

	.globl	_g_idle_topstack
	.type	_g_idle_topstack, object
_g_idle_topstack:
	.long	_enbss+CONFIG_ARCH_INTERRUPTSTACK+CONFIG_IDLETHREAD_STACKSIZE
	.size	_g_idle_topstack, .-_g_idle_topstack

/************************************************************************************
 * Code
 ************************************************************************************/

/************************************************************************************
 * Name: __start
 *
 * Description:
 *   After reset, program execution starts here.
 *
 ************************************************************************************/

 	.text
	.globl	__start
	.globl	_enbss
	.type	__start, #function
__start:

/* Set the interrupt and user stack pointers */

	mov.w	#_enbss, R0
	ldc	R0, isp			/* Set the interrupt stack pointer to the end of BSS */
	add.w	#CONFIG_IDLETHREAD_STACKSIZE, R0
	fset	U			/* Set bit 7 (U) to select the user stack pointer */
	ldc	R0, sp			/* Set the user stack pointer */

/* Set BCLK speed. At reset, the processor clock  (BLCK) defaults to a divisor of 8.
 * This sets clock to F1 (divide by 1) on XIN: BCLK = XIN frequency.
 */

 	mov.b	#0x01, M16C_PRCR	/* Unprotect CM0 to change clock setting */
	mov.b	#0x08, M16C_CM0		/* enable CM17 and CM16 to set BCLK to F1
					 * CM17 & CM16 defaults to 0 after reset and
					 * so we only need to reset CM06 to 0 */
	mov.b	#0x00,M16C_PRCR		/* protect CM0 */

/* The two MS bits of the interrupt cause select register must be set to
 * enable the use of INT4 and INT5
 */

 	mov.b	#0xc0, M16C_IFSR	/* Set b7 & b6 if application will use INT4 & INT5 */
	ldc	#M16C_IRAM_BASE, sb	/* Set sb register (to what?) */

/* Set up INTB to point to location of variable vector table */

	mov.w	_g_svarvect, r0		/* R0 = lower 16-bits */
	mov.w	_g_svarvect+2, r1	/* R1 = upper 4-bits */
	ldc	r1, intbh
	ldc	r0, intbl

/* Configure the uart so that we can get debug output as soon as possible. */

	.globl	_up_lowsetup		/* Early initialization of UART */
	jsr.a	_up_lowsetup
	showprogress 'A'

/* Clear near .bss sections */

	mov.b	#0x00, r0l		/* r0l: 0 */
	mov.w	_g_snbss, a1		/* a1: start of near .bss */
	mov.w	_g_enbss, r3		/* r3: end of near .bss */
	sub.w	a1, r3			/* r3: size of near .bss */
	sstr.b				/* Clear near .bss */

/* Clear far .bss sections */

	showprogress 'B'

#ifdef CONFIG_M16C_HAVEFARRAM
# warning "Far RAM support not implemented"
#endif

/* Initialize near .data sections (.rodata is not moved) */

	mov.w	_g_enronly, a0		/* a0: Low 16 bits of source address */
	mov.b	_g_enronly+2, r1h	/* 4 MS of 20-bit source address */
	mov.w	_g_sndata, a1		/* a1: start of near .data */
	mov.w	_g_endata, r3		/* r3: end of near .data */
	sub.w	a1, r3			/* r3: size of near .data */
	smovf.b				/* Copy source to near .data */

/* Initialize far .data sections (.rodata is not moved) */

	showprogress 'C'

#ifdef CONFIG_M16C_HAVEFARRAM
# warning "Far RAM support not implemented"
#endif

/* Perform early console initialization */

#ifdef USE_EARLYSERIALINIT
	.globl	_up_earlyconsoleinit	/* Early initialization of console driver */
	jsr.a	 _up_earlyconsoleinit	/* Call it */
	showprogress 'D'
#endif

/* Call C++ constructors */

#ifdef CONFIG_CPLUSPLUS
#  warning "No C++ support yet"
	showprogress 'E'
#endif

/* Initialize onboard LEDs */

#ifdef CONFIG_ARCH_LEDS
	.globl	_up_ledinit		/* Boot LED setup */
	jsr.a	_up_ledinit		/* Call it */
#endif
	showprogress '\n'

/* Pass control to NuttX */

	.globl	_os_start
	jsr.a	_os_start

/* NuttX will not return, but just in case... */

_os_exit:
	jmp.s	_os_exit
	.size	__start, .-__start
	.end