summaryrefslogtreecommitdiff
path: root/bsp/bluetrum/libraries/hal_libraries/bmsis/source/startup.S
blob: e1140cb090036f5bc58a5d90dbaaa75a089f2211 (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
/*
 * Copyright (c) 2020-2020, BLUETRUM Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include "ab32vg1.h"

.global _start
.section .reset, "ax"
_start:
    la      tp, _tp
    la      gp, _gp

    //load comm
    la      a0, __comm_vma
    la      a1, __comm_lma
    la      a2, __comm_size
    call    _memcpy

    //load ram1
    la      a0, __ram1_vma
    la      a1, __ram1_lma
    la      a2, __ram1_size
    call    _memcpy

    la      a0, __irq_stack_start           //Stack清成0x23
    li      a1, 0x23
    la      a2, __irq_stack_size
    call    rt_memset
    la      ra, __irq_stack
    lui	    a5, 0x1
    sw	    zero, -1920(a5)
    sw	    zero, -1916(a5)

    //clear bss
    la      a0, __bss_start
    li      a1, 0
    la      a2, __bss_size
    call    rt_memset

    call    cache_init

    la      a0, __comm_vma
    sw      a0, PICADR(zero)

    call    entry
    la      ra, __exception
    jr      ra

.section .vector, "ax"
    .org    0x10
__exception:
    li      sp, 0x10600                     //出错后,不破坏错误点的堆栈数据
    jal     exception_isr
    1: j       1b
    mret

    .org    0x40
    jal x0, low_prio_irq

    .org    0x80
#define METHOD 1
#if METHOD == 1
    addi    sp, sp, -6*4
    # lw      a0, PICEN(zero)
    lw      a1, EPC(zero)
    lw      a2, EPICCON(zero)
    # sw      a0, 3*4(sp)
    sw      a1, 4*4(sp)
    sw      a2, 5*4(sp)
    # andi    a0, a0, 1
    # sw      a0, PICEN(zero)
    li      a2, 0
    sw      a2, EPICCON(zero)
    la      a0, 0f
    sw      a0, EPC(zero)
    j       isr_cache
0:
    sw      a0, 0(sp)
    sw      a1, 4(sp)
    sw      a2, 8(sp)

    # lw      a0, 3*4(sp)
    lw      a1, 4*4(sp)
    lw      a2, 5*4(sp)
    # sw      a0, PICEN(zero)
    sw      a1, EPC(zero)
    sw      a2, EPICCON(zero)

    lw      a0, 0(sp)
    lw      a1, 4(sp)
    lw      a2, 8(sp)
    addi    sp, sp, 6*4
    mret
#endif

    .org    0x1e0
    1: j       1b
    nop
    mret

    .global cpu_irq_comm
cpu_irq_comm:
    la      a5, __irq_stack
    mv      sp, a5
    j       cpu_irq_comm_do

    ret

    .global _tp
    .set    _tp,        0x84800

    .set    _memcpy,    0x84044