source: rtems/c/src/lib/libbsp/sh/gensh4/start/start.S @ cb33a86f

4.104.114.84.95
Last change on this file since cb33a86f was cb33a86f, checked in by Ralf Corsepius <ralf.corsepius@…>, on 04/02/04 at 11:20:52
  • start/start.S: Include <rtems/asm.h> instead of <asm.h>.
  • Property mode set to 100644
File size: 6.1 KB
Line 
1/*
2 * start.S -- Initialization code for SH7750 generic BSP
3 *
4 * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
5 * Author: Victor V. Vengerov <vvv@oktet.ru>
6 *
7 * Based on work:
8 *  Authors: Ralf Corsepius (corsepiu@faw.uni-ulm.de) and
9 *           Bernd Becker (becker@faw.uni-ulm.de)
10 *
11 *  COPYRIGHT (c) 1997-1998, FAW Ulm, Germany
12 *
13 *  This program is distributed in the hope that it will be useful,
14 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 *
17 *  Modified to reflect Hitachi EDK SH7045F:
18 *  John M. Mills (jmills@tga.com)
19 *  TGA Technologies, Inc.
20 *  100 Pinnacle Way, Suite 140
21 *  Norcross, GA 30071 U.S.A.
22 * 
23 *
24 *  This modified file may be copied and distributed in accordance
25 *  the above-referenced license. It is provided for critique and
26 *  developmental purposes without any warranty nor representation
27 *  by the authors or by TGA Technologies.
28 *
29 *  COPYRIGHT (c) 1999-2001.
30 *  On-Line Applications Research Corporation (OAR).
31 *
32 *  The license and distribution terms for this file may be
33 *  found in the file LICENSE in this distribution or at
34 *  http://www.rtems.com/license/LICENSE.
35 *
36 *  $Id$
37 */
38
39#include <rtems/asm.h>
40#include "rtems/score/sh4_regs.h"
41#include "rtems/score/sh7750_regs.h"
42
43        BEGIN_CODE
44        PUBLIC(start)
45
46/*
47 * Algorithm of the first part of the start():
48 *
49 * 1. Initialize stack
50 * 2. Are we from reset or from gdb? Set value for boot_mode in r9.
51 * 3. Initialize hardware if we are from reset. Cache is off.
52 * 4. Copy data from flash to ram; set up boot mode and jump to real address.
53 * 5. Zero out bss.
54 * 6. Turn memory cach on.
55 */
56
57SYM (start):
58        ! install the stack pointer
59        mov.l   stack_k,r15
60
61        mov.l   initial_sr_k,r0
62        ldc     r0,ssr
63        ldc     r0,sr
64
65        ! let us see if we are from gdb stub or from power-on reset
66        bsr     fake_func
67        nop
68fake_func:
69
70        sts     pr, r0
71        shlr8   r0
72        mov.l   reset_pc_value_shift_8_k, r1
73        cmp/eq  r0, r1
74        movt    r9      ! r9 == ! boot_mode
75        neg     r9, r9
76        add     #1, r9  ! r9 == boot_mode
77       
78        ! what is in boot_mode?
79        cmp/pl  r9      ! r9 > 0  ->  T = 1
80
81        ! if boot_mode != SH4_BOOT_MODE_FLASH
82        bt      hw_init_end
83        nop
84
85#if defined(START_HW_INIT)      /* from $RTEMS_BSP.cfg */
86        ! Initialize minimal hardware
87        ! to run hw_init we need to calculate its address
88        ! as it is before data coping
89        mov.l   hw_init_k, r0
90        mov.l   copy_start_k, r1
91        mov.l   copy_end_k, r2
92        cmp/ge  r0, r1
93        bt      0f
94        cmp/ge  r0, r2
95        bf      0f
96        ! if  copy_start <= hw_init <= copy_end  then
97        neg     r1, r1
98        mov.l   copy_start_in_rom_k, r3
99        add     r1,r0
100        add     r3, r0
1010:
102        jsr @r0
103        nop             !delay slot
104#endif /* START_HW_INIT */
105hw_init_end:
106
107        ! copy data from rom to ram
108        mov.l   copy_start_k, r0
109        mov.l   copy_end_k, r1
110        mov.l   copy_start_in_rom_k, r2
111
112
113        ! if copy_from == copy_to do not copy anything
114        cmp/eq  r0, r2
115        bt      real_address
116        nop
117
118copy_data_cycle:
119        cmp/ge  r1, r0
120        bt      end_of_copy_data_cycle
121        nop
122        mov.l   @r2+, r3
123        mov.l   r3, @r0
124        add     #4, r0
125        bra     copy_data_cycle
126        nop
127
128end_of_copy_data_cycle:
129        ! go to 0x8....... adresses
130        mov.l   real_address_k, r0
131        lds     r0, pr
132        rts
133        nop
134real_address:
135        ! write boot_mode to ram
136        mov.l   boot_mode_k, r5
137        mov.l   r9, @r5
138
139zero_bss:
140        ! zero out bss
141        mov.l   __bss_start_k,r0
142        mov.l   __bss_end_k,r1
143        mov     #0,r2
1440:
145        mov.l   r2,@r0
146        add     #4,r0
147        cmp/ge  r0,r1
148        bt      0b
149        nop
150
151        ! Turn cache on
152        mov.l   cache_on_k, r0
153        jsr @r0
154        nop     !delay slot
155
156        ! Save old value of VBR register. We will need it to allow
157        ! debugger agent hook exceptions.
158        mov.l   __VBR_Saved_k,r0
159        stc     vbr,r5
160        mov.l   r5,@r0
161        ! Set up VBR register
162        mov.l   _vbr_base_k,r0
163        ldc     r0,vbr
164
165        ! initialise fpscr for gcc
166        mov.l set_fpscr_k, r1
167        jsr @r1
168        nop
169
170        ! Set FPSCR register
171        mov.l   initial_fpscr_k,r0
172        lds     r0,fpscr
173
174
175        ! call the mainline     
176        mov #0,r4               ! argc
177        mov.l main_k,r0
178        jsr @r0
179        mov #0,r5               ! argv - can place in dead slot
180
181        ! call exit
182        mov     r0,r4
183        mov.l   exit_k,r0
184        jsr     @r0
185        or      r0,r0
186
187        .global _stop
188_stop:
189        mov     #11,r0
190        mov     #0,r4
191        trapa   #0x3f
192        nop
193__stop:
194        bra     __stop
195        nop
196
197        END_CODE
198
199        .align 2
200copy_start_k:
201        .long copy_start
202copy_end_k:
203        .long copy_end
204copy_start_in_rom_k:
205        .long copy_start_in_rom
206
207real_address_k:
208        .long real_address
209set_fpscr_k:
210    .long   ___set_fpscr
211_vbr_base_k:
212        .long   SYM(_vbr_base)
213__VBR_Saved_k:
214        .long   SYM(_VBR_Saved)
215stack_k:
216        .long   SYM(stack)     
217__bss_start_k:
218        .long   __bss_start
219__bss_end_k:
220        .LONG   __bss_end
221main_k:
222        .long   SYM(boot_card)
223exit_k:
224        .long   SYM(_exit)
225
226#ifdef  START_HW_INIT   /* from $RTEMS_BSP.cfg */
227hw_init_k:
228        .long   SYM(early_hw_init)
229#endif /* START_HW_INIT */
230
231cache_on_k:
232        .long   SYM(bsp_cache_on)
233
234vects_k:
235        .long   SYM(vectab)
236vects_size:
237        .word   255
238
239    .align 2
240initial_sr_k:
241        .long   SH4_SR_MD | SH4_SR_IMASK
242initial_fpscr_k:
243#ifdef __SH4__
244        .long   SH4_FPSCR_DN | SH4_FPSCR_PR | SH4_FPSCR_RM
245#else
246        .long   SH4_FPSCR_DN | SH4_FPSCR_RM
247#endif
248
249reset_pc_value_shift_8_k:
250        .long   0xa00000
251
252boot_mode_k:
253        .long   _boot_mode
254
255#ifdef __ELF__
256        .section .stack,"aw"
257#else
258        .section .stack
259#endif
260SYM(stack):
261        .long   0xdeaddead
262
263#ifdef __ELF__
264        .section .bss,"aw"
265#else
266        .section .bss
267#endif
268
269        .global __sh4sim_dummy_register
270__sh4sim_dummy_register:
271        .long   0
272
273        .section    .data
274        .global _boot_mode
275_boot_mode:
276        .long   0
277
Note: See TracBrowser for help on using the repository browser.