1d6aed566Sopenharmony_ci/*
2d6aed566Sopenharmony_ci * Copyright (C) 2017 C-SKY Microsystems Co., Ltd. All rights reserved.
3d6aed566Sopenharmony_ci *
4d6aed566Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
5d6aed566Sopenharmony_ci * you may not use this file except in compliance with the License.
6d6aed566Sopenharmony_ci * You may obtain a copy of the License at
7d6aed566Sopenharmony_ci *
8d6aed566Sopenharmony_ci *   http://www.apache.org/licenses/LICENSE-2.0
9d6aed566Sopenharmony_ci *
10d6aed566Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
11d6aed566Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
12d6aed566Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13d6aed566Sopenharmony_ci * See the License for the specific language governing permissions and
14d6aed566Sopenharmony_ci * limitations under the License.
15d6aed566Sopenharmony_ci */
16d6aed566Sopenharmony_ci /******************************************************************************
17d6aed566Sopenharmony_ci * @file     startup.S
18d6aed566Sopenharmony_ci * @brief    startup file for smartl. Should use with
19d6aed566Sopenharmony_ci *           GCC for CSKY Embedded Processors
20d6aed566Sopenharmony_ci * @version  V1.0
21d6aed566Sopenharmony_ci * @date     02. June 2017
22d6aed566Sopenharmony_ci ******************************************************************************/
23d6aed566Sopenharmony_ci
24d6aed566Sopenharmony_ci.text
25d6aed566Sopenharmony_ci.long _start
26d6aed566Sopenharmony_ci.align   2
27d6aed566Sopenharmony_ci_start:
28d6aed566Sopenharmony_ci    .text
29d6aed566Sopenharmony_ci    .align   2
30d6aed566Sopenharmony_ci    .globl   Reset_Handler
31d6aed566Sopenharmony_ci    .type    Reset_Handler, %function
32d6aed566Sopenharmony_ciReset_Handler:
33d6aed566Sopenharmony_ci    lrw     r0, 0x80000200
34d6aed566Sopenharmony_ci    mtcr    r0, psr
35d6aed566Sopenharmony_ci
36d6aed566Sopenharmony_ci    lrw     r0, __init_stack_e
37d6aed566Sopenharmony_ci    mov     sp, r0
38d6aed566Sopenharmony_ci
39d6aed566Sopenharmony_ci/*
40d6aed566Sopenharmony_ci *  The ranges of copy from/to are specified by following symbols
41d6aed566Sopenharmony_ci *    __etext: LMA of start of the section to copy from. Usually end of text
42d6aed566Sopenharmony_ci *    __data_start__: VMA of start of the section to copy to
43d6aed566Sopenharmony_ci *    __data_end__: VMA of end of the section to copy to
44d6aed566Sopenharmony_ci *
45d6aed566Sopenharmony_ci *  All addresses must be aligned to 4 bytes boundary.
46d6aed566Sopenharmony_ci */
47d6aed566Sopenharmony_ci    lrw     r1, __erodata
48d6aed566Sopenharmony_ci    lrw     r2, __data_start__
49d6aed566Sopenharmony_ci    lrw     r3, __data_end__
50d6aed566Sopenharmony_ci
51d6aed566Sopenharmony_ci    subu    r3, r2
52d6aed566Sopenharmony_ci    cmpnei  r3, 0
53d6aed566Sopenharmony_ci    bf      .L_loop0_done
54d6aed566Sopenharmony_ci
55d6aed566Sopenharmony_ci.L_loop0:
56d6aed566Sopenharmony_ci    ldw     r0, (r1, 0)
57d6aed566Sopenharmony_ci    stw     r0, (r2, 0)
58d6aed566Sopenharmony_ci    addi    r1, 4
59d6aed566Sopenharmony_ci    addi    r2, 4
60d6aed566Sopenharmony_ci    subi    r3, 4
61d6aed566Sopenharmony_ci    cmpnei  r3, 0
62d6aed566Sopenharmony_ci    bt      .L_loop0
63d6aed566Sopenharmony_ci
64d6aed566Sopenharmony_ci.L_loop0_done:
65d6aed566Sopenharmony_ci
66d6aed566Sopenharmony_ci/*
67d6aed566Sopenharmony_ci *  The BSS section is specified by following symbols
68d6aed566Sopenharmony_ci *    __bss_start: start of the BSS section.
69d6aed566Sopenharmony_ci *    __bss_end: end of the BSS section.
70d6aed566Sopenharmony_ci *
71d6aed566Sopenharmony_ci *  Both addresses must be aligned to 4 bytes boundary.
72d6aed566Sopenharmony_ci */
73d6aed566Sopenharmony_ci    lrw     r1, __bss_start
74d6aed566Sopenharmony_ci    lrw     r2, __bss_end
75d6aed566Sopenharmony_ci
76d6aed566Sopenharmony_ci    movi    r0, 0
77d6aed566Sopenharmony_ci
78d6aed566Sopenharmony_ci    subu    r2, r1
79d6aed566Sopenharmony_ci    cmpnei  r2, 0
80d6aed566Sopenharmony_ci    bf      .L_loop1_done
81d6aed566Sopenharmony_ci
82d6aed566Sopenharmony_ci.L_loop1:
83d6aed566Sopenharmony_ci    stw     r0, (r1, 0)
84d6aed566Sopenharmony_ci    addi    r1, 4
85d6aed566Sopenharmony_ci    subi    r2, 4
86d6aed566Sopenharmony_ci    cmpnei  r2, 0
87d6aed566Sopenharmony_ci    bt      .L_loop1
88d6aed566Sopenharmony_ci.L_loop1_done:
89d6aed566Sopenharmony_ci    jbsr    main
90d6aed566Sopenharmony_ci    .size   Reset_Handler, . - Reset_Handler
91d6aed566Sopenharmony_ci__exit:
92d6aed566Sopenharmony_ci    br __exit
93