aboutsummaryrefslogtreecommitdiff
path: root/circuitpython/lib/tinyusb/hw/mcu/bridgetek/ft9xx/scripts/crt0.S
blob: 62fa266eea2127deb84e7d815c07becc17888500 (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
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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
.equ SYS_REGMSC0CFG_B3  , 0x1001b
.equ SYS_REGIRQCTL_B3   , 0x100e3
.equ MAILBOX_MEMORY     , 0x13000

.equ	IS_IMG_SDBL_PRESENT, 0
.equ	IS_IMG_D2XX_PRESENT, 0
.equ	IS_IMG_DLOG_PRESENT, 0

.section .crt0
.global _start

_start:
# START Interrupt Vector Table [[
        jmp     __PMSIZE-4         # RESET Vector
        jmp     interrupt_33	   # Watchdog reset vector
        jmp     interrupt_0
        jmp     interrupt_1
        jmp     interrupt_2
        jmp     interrupt_3
        jmp     interrupt_4
        jmp     interrupt_5
        jmp     interrupt_6
        jmp     interrupt_7
        jmp     interrupt_8
        jmp     interrupt_9
        jmp     interrupt_10
        jmp     interrupt_11
        jmp     interrupt_12
        jmp     interrupt_13
        jmp     interrupt_14
        jmp     interrupt_15
        jmp     interrupt_16
        jmp     interrupt_17
        jmp     interrupt_18
        jmp     interrupt_19
        jmp     interrupt_20
        jmp     interrupt_21
        jmp     interrupt_22
        jmp     interrupt_23
        jmp     interrupt_24
        jmp     interrupt_25
        jmp     interrupt_26
        jmp     interrupt_27
        jmp     interrupt_28
        jmp     interrupt_29
        jmp     interrupt_30
        jmp     interrupt_31
        jmp     __PMSIZE-8				#Interrupt vector 32 (NMI)
# ]] END Interrupt Vector Table

codestart:
        jmp    init
        
.global _exithook
_exithook:               # Debugger uses '_exithook' at 0x90 to catch program exit
        return
        
init:
        # Disable all interrupts
        ldk     $r0,0x80
.ifdef __FT930__
        sta.b   0x10123, $r0
.else
        sta.b   0x100e3,$r0
.endif
        
        # Reset all peripherals
        # lda.l   $r0, 0x10018
        # bins.l  $r0, $r0, 0x23F  # Set bit 31
        # sta.l   0x10018, $r0
        
        # Initialize DATA by copying from program memory
        ldk.l   $r0,__data_load_start
        ldk.l   $r1,__data_load_end
        ldk.l   $r2,0   # Will use __data after binutils patch

        jmp     .dscopy
.dsloop:
        # Copy PM[$r0] to RAM $r2
        lpmi.l  $r3,$r0,0
        sti.l   $r2,0,$r3
        add.l   $r0,$r0,4
        add.l   $r2,$r2,4
.dscopy:
        cmp.l   $r0,$r1
        jmpc    lt,.dsloop

        # Zero BSS
        ldk.l   $r0,_bss_start
        ldk.l   $r2,_end
        sub.l   $r2,$r2,$r0
        ldk.l   $r1,0
        ldk    $r3,32764
1:
        cmp    $r2,$r3
        jmpc   lt,2f
        memset $r0,$r1,$r3
        add    $r0,$r0,$r3
        sub    $r2,$r2,$r3
        jmp    1b
2:
        memset $r0,$r1,$r2
.ifdef __FT930__
/*##############################################################*/
		# copy UserConfig DATA from flash to mailbox memory
/*##############################################################*/
        ldk.l   $r0,D2XX_Struct_start  /*start of d2xx config in PM memory */
        ldk.l   $r1,D2XX_Struct_end /*end of d2xx config in PM memory */
        ldk.l   $r2,D2XXTEST_UserD2xxConfig /* RAM cache where the d2xx config from PM to be copied*/
        jmp     .configcopy

.configloop:
        # Copy PM[$r0] to RAM[$r2]
        lpmi.l  $r3,$r0,0
        sti.l   $r2,0,$r3
        # Increment
        add.l   $r0,$r0,4
        add.l   $r2,$r2,4
.configcopy:
        cmp.l   $r0,$r1
        jmpc    lt,.configloop

        ldk.l   $r1,D2XX_Struct_start
        ldk.l   $r2,D2XX_Struct_end
        #compute size
        sub.l   $r2,$r2,$r1
        ldk.l   $r1,D2XXTEST_UserD2xxConfig
        ldk.l   $r0,MAILBOX_MEMORY		/* D2xx config from RAM cache to be copied to Mailbox memory */
        # Copy RAM[$r1] to Mailbox $r0, for $r2 bytes
        streamouti.b   $r0,$r1,$r2
/*############################################################*/
.endif
        sub.l   $sp,$sp,24  # Space for the caller argument frame
        call    main

.equ EXITEXIT    , 0x1fffc

.global _exit
_exit:
        sta.l   EXITEXIT,$r0    # simulator end of test
        jmp     _exithook

#_watchdog_isr:
#        ldk     $sp,__RAMSIZE
#        jmp     __PMSIZE-4

# Macro to construct the interrupt stub code.
# it just saves r0, loads r0 with the int vector
# and branches to interrupt_common.

.macro  inth i=0
interrupt_\i:
        push    $r0     # {
        lda     $r0,(vector_table + 4 * \i)
        jmp     interrupt_common
.endm

        inth    0
        inth    1
        inth    2
        inth    3
        inth    4
        inth    5
        inth    6
        inth    7
        inth    8
        inth    9
        inth    10
        inth    11
        inth    12
        inth    13
        inth    14
        inth    15
        inth    16
        inth    17
        inth    18
        inth    19
        inth    20
        inth    21
        inth    22
        inth    23
        inth    24
        inth    25
        inth    26
        inth    27
        inth    28
        inth    29
        inth    30
        inth    31
        inth    32
        inth    33

        # On entry: r0, already saved, holds the handler function
interrupt_common:
        push    $r1     # {
        push    $r2     # {
        push    $r3     # {
        push    $r4     # {
        push    $r5     # {
        push    $r6     # {
        push    $r7     # {
        push    $r8     # {
        push    $r9     # {
        push    $r10    # {
        push    $r11    # {
        push    $r12    # {
        push    $cc     # {

        calli   $r0

        pop     $cc     # }
        pop     $r12    # }
        pop     $r11    # }
        pop     $r10    # }
        pop     $r9     # }
        pop     $r8     # }
        pop     $r7     # }
        pop     $r6     # }
        pop     $r5     # }
        pop     $r4     # }
        pop     $r3     # }
        pop     $r2     # }
        pop     $r1     # }
        pop     $r0     # } matching push in interrupt_0-31 above
        reti

        # Null function for unassigned interrupt to point at
.global     nullvector
nullvector:
        return

.section .data
.global vector_table
	.align (4)			# assembler alignment is in the power of 2 (in this case 2^4)
vector_table:
        .rept 34
                .long   nullvector
        .endr


.section .text
.global __gxx_personality_sj0
__gxx_personality_sj0:


	.section ._flash_d2xx_config
.global __pD2XXDefaultConfiguration
	.align (10)

D2XX_partition_start = .

.if IS_IMG_D2XX_PRESENT
.ifdef __FT930__
.include "ft930_d2xx_default_config.inc"
.else
.include "ft900_d2xx_default_config.inc"
.endif
.endif

D2XX_partition_end = .

	.section ._flash_dlog_partition
	.align (10)
.global __dlog_partition
__dlog_partition:
dlog_partition_start = .
.if IS_IMG_DLOG_PRESENT
	.long	0xF7D1D106
	.rept  (0x1000-4)
	.byte	0xFF
	.endr
.endif
dlog_partition_end = .

	.section ._pm
.global	__sdbl_partition_sizeof
.global __D2XX_partition_sizeof
.global __dlog_partition_sizeof
	.if IS_IMG_SDBL_PRESENT
__sdbl_partition_sizeof = 0x2000
	.else
__sdbl_partition_sizeof = 0
	.endif

__D2XX_partition_sizeof = D2XX_partition_end - D2XX_partition_start
__dlog_partition_sizeof = dlog_partition_end - dlog_partition_start