2016-10-26 Edward Smith-Rowland <3dw4rd@verizon.net>
[official-gcc.git] / libgcc / config / ft32 / crti-hw.S
blobc2951fc3c28104fc38196cd5d382adffe9611886
1 .global _start
2 _start:
3 # START Interrupt Vector Table [[
4         jmp     __PMSIZE-4
5         jmp     watchdog_init
6         jmp     interrupt_0
7         jmp     interrupt_1
8         jmp     interrupt_2
9         jmp     interrupt_3
10         jmp     interrupt_4
11         jmp     interrupt_5
12         jmp     interrupt_6
13         jmp     interrupt_7
14         jmp     interrupt_8
15         jmp     interrupt_9
16         jmp     interrupt_10
17         jmp     interrupt_11
18         jmp     interrupt_12
19         jmp     interrupt_13
20         jmp     interrupt_14
21         jmp     interrupt_15
22         jmp     interrupt_16
23         jmp     interrupt_17
24         jmp     interrupt_18
25         jmp     interrupt_19
26         jmp     interrupt_20
27         jmp     interrupt_21
28         jmp     interrupt_22
29         jmp     interrupt_23
30         jmp     interrupt_24
31         jmp     interrupt_25
32         jmp     interrupt_26
33         jmp     interrupt_27
34         jmp     interrupt_28
35         jmp     interrupt_29
36         jmp     interrupt_30
37         jmp     interrupt_31
38         jmp     __PMSIZE-8
39 # ]] END Interrupt Vector Table
41 codestart:
42         jmp    init
43         
44 .global _exithook
45 _exithook:               # Debugger uses '_exithook' at 0x90 to catch program exit
46         return
47         
48 watchdog_init:
49         ldk     $r0,1
50 init:
51         ldk     $sp,__RAMSIZE
52         # Disable all interrupts
53         ldk     $r4,0x80
54         sta.b   0x100e3,$r4
55         
56         # Initialize DATA by copying from program memory
57         ldk.l   $r4,__data_load_start
58         ldk.l   $r1,__data_load_end
59         ldk.l   $r2,0   # Will use __data after binutils patch
61         jmp     .dscopy
62 .dsloop:
63         # Copy PM[$r4] to RAM $r2
64         lpmi.l  $r3,$r4,0
65         sti.l   $r2,0,$r3
66         add.l   $r4,$r4,4
67         add.l   $r2,$r2,4
68 .dscopy:
69         cmp.l   $r4,$r1
70         jmpc    lt,.dsloop
72         # Zero BSS
73         ldk.l   $r4,_bss_start
74         ldk.l   $r2,_end
75         sub.l   $r2,$r2,$r4
76         ldk.l   $r1,0
77         ldk    $r3,32764
79         cmp    $r2,$r3
80         jmpc   lt,2f
81         memset $r4,$r1,$r3
82         add    $r4,$r4,$r3
83         sub    $r2,$r2,$r3
84         jmp    1b
86         memset $r4,$r1,$r2
88         sub.l   $sp,$sp,24  # Space for the caller argument frame
89         call    main
91 .equ EXITEXIT,0x1fffc
93 .global _exit
94 _exit:
95         sta.l   EXITEXIT,$r0    # simulator end of test
96         jmp     _exithook
98 # Macro to construct the interrupt stub code.
99 # it just saves r0, loads r0 with the int vector
100 # and branches to interrupt_common.
102 .macro  inth i=0
103 interrupt_\i:
104         push    $r0     # {
105         lda     $r0,(vector_table + 4 * \i)
106         jmp     interrupt_common
107 .endm
109         inth    0
110         inth    1
111         inth    2
112         inth    3
113         inth    4
114         inth    5
115         inth    6
116         inth    7
117         inth    8
118         inth    9
119         inth    10
120         inth    11
121         inth    12
122         inth    13
123         inth    14
124         inth    15
125         inth    16
126         inth    17
127         inth    18
128         inth    19
129         inth    20
130         inth    21
131         inth    22
132         inth    23
133         inth    24
134         inth    25
135         inth    26
136         inth    27
137         inth    28
138         inth    29
139         inth    30
140         inth    31
141         inth    32
143         # On entry: r0, already saved, holds the handler function
144 interrupt_common:
145         push    $r1     # {
146         push    $r2     # {
147         push    $r3     # {
148         push    $r4     # {
149         push    $r5     # {
150         push    $r6     # {
151         push    $r7     # {
152         push    $r8     # {
153         push    $r9     # {
154         push    $r10    # {
155         push    $r11    # {
156         push    $r12    # {
157         push    $cc     # {
159         calli   $r0
161         pop     $cc     # }
162         pop     $r12    # }
163         pop     $r11    # }
164         pop     $r10    # }
165         pop     $r9     # }
166         pop     $r8     # }
167         pop     $r7     # }
168         pop     $r6     # }
169         pop     $r5     # }
170         pop     $r4     # }
171         pop     $r3     # }
172         pop     $r2     # }
173         pop     $r1     # }
174         pop     $r0     # } matching push in interrupt_0-31 above
175         reti
177         # Null function for unassigned interrupt to point at
178 .global     nullvector
179 nullvector:
180         return
182 .section .data
183 .global vector_table
184 vector_table:
185         .rept 33
186                 .long   nullvector
187         .endr
190 .section .text
191 .global __gxx_personality_sj0
192 __gxx_personality_sj0: