summaryrefslogtreecommitdiffstats
path: root/bsps/sh/gensh4/start/start.S
blob: 711583ed6d170dd29869c2b598a624bb91af97bb (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
/*
 * start.S -- Initialization code for SH7750 generic BSP
 *
 * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
 * Author: Victor V. Vengerov <vvv@oktet.ru>
 *
 * Based on work:
 *  Authors: Ralf Corsepius (corsepiu@faw.uni-ulm.de) and
 *           Bernd Becker (becker@faw.uni-ulm.de)
 *
 *  COPYRIGHT (c) 1997-1998, FAW Ulm, Germany
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 *  Modified to reflect Hitachi EDK SH7045F:
 *  John M. Mills (jmills@tga.com)
 *  TGA Technologies, Inc.
 *  100 Pinnacle Way, Suite 140
 *  Norcross, GA 30071 U.S.A.
 *
 *
 *  This modified file may be copied and distributed in accordance
 *  the above-referenced license. It is provided for critique and
 *  developmental purposes without any warranty nor representation
 *  by the authors or by TGA Technologies.
 *
 *  COPYRIGHT (c) 1999-2001.
 *  On-Line Applications Research Corporation (OAR).
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *  http://www.rtems.org/license/LICENSE.
 */

#include <rtems/asm.h>
#include "rtems/score/sh4_regs.h"
#include "rtems/score/sh7750_regs.h"

        BEGIN_CODE
        PUBLIC(start)

/*
 * Algorithm of the first part of the start():
 *
 * 1. Initialize stack
 * 2. Are we from reset or from gdb? Set value for boot_mode in r9.
 * 3. Initialize hardware if we are from reset. Cache is off.
 * 4. Copy data from flash to ram; set up boot mode and jump to real address.
 * 5. Zero out bss.
 * 6. Turn memory cach on.
 */

SYM (start):
        ! install the stack pointer
        mov.l	stack_k,r15

        mov.l   initial_sr_k,r0
        ldc     r0,ssr
        ldc     r0,sr

        ! let us see if we are from gdb stub or from power-on reset
        bsr     fake_func
        nop
fake_func:

        sts     pr, r0
        shlr8   r0
        mov.l   reset_pc_value_shift_8_k, r1
        cmp/eq  r0, r1
        movt    r9      ! r9 == ! boot_mode
        neg     r9, r9
        add     #1, r9  ! r9 == boot_mode

        ! what is in boot_mode?
        cmp/pl  r9      ! r9 > 0  ->  T = 1

        ! if boot_mode != SH4_BOOT_MODE_FLASH
        bt      hw_init_end
        nop

#if START_HW_INIT	/* from $RTEMS_BSP.cfg */
        ! Initialize minimal hardware
        ! to run hw_init we need to calculate its address
        ! as it is before data copying
        mov.l	hw_init_k, r0
        mov.l   copy_start_k, r1
        mov.l   copy_end_k, r2
        cmp/ge  r0, r1
        bt      0f
        cmp/ge  r0, r2
        bf      0f
        ! if  copy_start <= hw_init <= copy_end  then
        neg     r1, r1
        mov.l   copy_start_in_rom_k, r3
        add     r1,r0
        add     r3, r0
0:
        jsr @r0
        nop		!delay slot
#endif /* START_HW_INIT */
hw_init_end:

#if COPY_DATA_FROM_ROM
        ! copy data from rom to ram
        mov.l   copy_start_k, r0
        mov.l   copy_end_k, r1
        mov.l   copy_start_in_rom_k, r2

        ! if copy_from == copy_to do not copy anything
        cmp/eq  r0, r2
        bt      real_address
        nop

copy_data_cycle:
        cmp/ge  r1, r0
        bt      end_of_copy_data_cycle
        nop
        mov.l   @r2+, r3
        mov.l   r3, @r0
        add     #4, r0
        bra     copy_data_cycle
        nop

end_of_copy_data_cycle:
#endif
        ! go to 0x8....... adresses
        mov.l   real_address_k, r0
        lds     r0, pr
        rts
        nop
real_address:
        ! write boot_mode to ram
        mov.l   boot_mode_k, r5
        mov.l   r9, @r5

zero_bss:
        ! zero out bss
        mov.l	__bss_start_k,r0
        mov.l	__bss_end_k,r1
        mov	#0,r2
0:
        mov.l	r2,@r0
        add	#4,r0
        cmp/ge	r0,r1
        bt	0b
        nop

        ! Turn cache on
        mov.l   cache_on_k, r0
        jsr @r0
        nop     !delay slot

        ! Save old value of VBR register. We will need it to allow
        ! debugger agent hook exceptions.
        mov.l   __VBR_Saved_k,r0
        stc     vbr,r5
        mov.l   r5,@r0
        ! Set up VBR register
        mov.l   _vbr_base_k,r0
        ldc     r0,vbr

        ! initialise fpscr for gcc
        mov.l set_fpscr_k, r1
        jsr @r1
        nop

        ! Set FPSCR register
        mov.l   initial_fpscr_k,r0
        lds     r0,fpscr

        ! call the mainline
        mov #0,r4		! argc
        mov.l main_k,r0
        jsr @r0
        nop

        ! call exit
        mov	r0,r4
        mov.l	exit_k,r0
        jsr	@r0
        or	r0,r0

        .global _stop
_stop:
        mov     #11,r0
        mov     #0,r4
        trapa   #0x3f
        nop
__stop:
        bra     __stop
        nop

        END_CODE

        .align 2
#if START_HW_INIT
copy_start_k:
        .long copy_start
copy_end_k:
        .long copy_end
#endif
#if COPY_DATA_FROM_ROM
copy_start_in_rom_k:
        .long copy_start_in_rom
#endif

real_address_k:
        .long real_address
set_fpscr_k:
    .long   ___set_fpscr
_vbr_base_k:
        .long   SYM(_vbr_base)
__VBR_Saved_k:
        .long   SYM(_VBR_Saved)
stack_k:
        .long	SYM(_Configuration_Interrupt_stack_area_end)
__bss_start_k:
        .long   __bss_start
__bss_end_k:
        .LONG   __bss_end
main_k:
        .long	SYM(boot_card)
exit_k:
        .long	SYM(_exit)

#if	START_HW_INIT	/* from $RTEMS_BSP.cfg */
hw_init_k:
        .long	SYM(early_hw_init)
#endif /* START_HW_INIT */

cache_on_k:
        .long   SYM(bsp_cache_on)

vects_k:
        .long	SYM(vectab)
vects_size:
        .word	255

    .align 2
initial_sr_k:
        .long   SH4_SR_MD | SH4_SR_IMASK
initial_fpscr_k:
#ifdef __SH4__
        .long   SH4_FPSCR_DN | SH4_FPSCR_PR | SH4_FPSCR_RM
#else
        .long   SH4_FPSCR_DN | SH4_FPSCR_RM
#endif

reset_pc_value_shift_8_k:
        .long   0xa00000

boot_mode_k:
        .long   _boot_mode

#ifdef __ELF__
        .section .bss,"aw"
#else
        .section .bss
#endif

        .global __sh4sim_dummy_register
__sh4sim_dummy_register:
        .long	0

        .section    .data
        .global _boot_mode
_boot_mode:
        .long   0