reset.S
9.1 KB
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
/* reset.S -- Reset Vector
*
* This code is taken from example code in the Xtensa Microprocessor
* Programmer's Guide.
*
* WARNING: It is highly unlikely that this code works as is on your
* particular Xtensa processor configuration. It is hardcoded
* for the specific processor configuration used for the
* examples in the Xtensa Microprocessor Programmer's Guide.
* (The example code did not use the Xtensa HAL to address this
* portability issue, for clarity's sake.) Getting it to work
* on another processor configuration requires some modifications.
*/
/*
* Copyright (c) 2003-2005 by Tensilica Inc. ALL RIGHTS RESERVED.
* These coded instructions, statements, and computer programs are the
* copyrighted works and confidential proprietary information of Tensilica Inc.
* They may not be modified, copied, reproduced, distributed, or disclosed to
* third parties in any manner, medium, or form, in whole or in part, without
* the prior written consent of Tensilica Inc.
*/
#include <xtensa/coreasm.h>
#include <xtensa/simcall.h>
#include "os_type.h"
//#include "flash_boot.h"
.global _ResetVector
#define JUMP_ADDR1 0x412355aa
#define JUMP_ADDR2 0x40000000
//#define JUMP_TEST
.section .ResetVector.text, "ax"
.align 4
_ResetVector:
j Reset // jump around literal pool
.literal_position // tells assembler place literals here
.align 4
jumpAddr1:
.word JUMP_ADDR2
.align 4
Reset:
#ifdef JUMP_TEST
l32r a0, jumpAddr1
jx a0
nop.N
#endif
#if 1//def SPI_FLASH_4BIT_ENABLE
//set spi flash 4 i/o
movi a2, 0x58ff0520
l8ui a2, a2,0
#endif
#if 0
//set usb phy to power down mode
movi a0, 0x0
movi a2, 0x16000400
s32i a0, a2, 0
#endif
//version D
// movi a2, 0x3FFFFC00 /* 0x60000000 */
movi a2, VECTOR_BASE_ADDR /* 0x60000000 */
wsr a2, VECBASE /* interrupt vector */
movi a0, 0
wsr a0, INTENABLE /* disable interrupt */
wsr a0, IBREAKA_0
wsr a0, IBREAKA_1
wsr a0, IBREAKENABLE
wsr a0, DBREAKA_0
wsr a0, DBREAKA_1
wsr a0, DBREAKC_0
wsr a0, DBREAKC_1
wsr a0, ICOUNT
wsr a0, ICOUNTLEVEL
isync
rsil a1, XCHAL_DEBUGLEVEL - 1 /* XCHAL_DEBUGLEVEL = 6 in core-isa.h */
wsr a0, CCOUNT
wsr a0, WINDOWBASE
rsync
movi a1, 1
wsr a1, WINDOWSTART /* 1->WINDOWSTART 0->WINDOWBASE */
ssai 0
//Level-1 interrupt
wsr a0, EXCSAVE_1
wsr a0, EPC_1
wsr a0, EXCCAUSE
//Medium priority interrupts
wsr a0, EPC_2
wsr a0, EPS_2
wsr a0, EXCSAVE_2
wsr a0, EPC_3
wsr a0, EPS_3
wsr a0, EXCSAVE_3
//High priority interrupts
wsr a0, EPC_4
wsr a0, EPS_4
wsr a0, EXCSAVE_4
wsr a0, EPC_5
wsr a0, EPS_5
wsr a0, EXCSAVE_5
//Debug EPC, EPS and EXCSAVE
wsr a0, EPC_6
wsr a0, EPS_6
wsr a0, EXCSAVE_6
//NMI EPC, EPS and EXCSAVE
wsr a0, EPC_7
wsr a0, EPS_7
wsr a0, EXCSAVE_7
//3 timers
wsr a0, CCOMPARE_0
wsr a0, CCOMPARE_1
wsr a0, CCOMPARE_2
movi a2, XCHAL_INTTYPE_MASK_EXTERN_EDGE | XCHAL_INTTYPE_MASK_SOFTWARE /* in core-isa.h */
wsr a2, INTCLEAR
#if XCHAL_HAVE_CP
wsr a0, BR /* XCHAL_HAVE CP 1 in core-isa.h */
wsr a0, CPENABLE
#endif
movi a2, XCHAL_DEBUGLEVEL - 1
wsr a2, PS
rsync
// set all region as bypass
movi a5, 0xE0000000
movi a4, 2
movi a3, 0
j 3f
2: sub a3, a3, a5 /* just like plus 0x20000000 */
3: wdtlb a4, a3
witlb a4, a3 /* a4 = 2 -> tlb, bypass */
bne a3, a5, 2b
isync
/* HiFi 330 XCHAL_ICACHE_SIZE = 4096, XCHAL_DCACHE_SIZE = 8192, CACHE LINE 64 Bytes */
#if 1
movi a2, 32 /* HiFi 330 XCHAL_ICACHE_SIZE = 4096 */
movi a3, 0
loop a2, .L0
iiu a3, 0
iiu a3, 64
addi a3, a3, 128
.L0:
movi a2, 32 /* CACHE LINE 64 Bytes */
movi a3, 0
loop a2, .L1
iii a3, 0
iii a3, 64
addi a3, a3, 128
.L1:
isync
#endif
#if 0
#if (XCHAL_ICACHE_SIZE != 0)
#if 0
#if (XCHAL_ICACHE_SIZE == 8192) //212GP and 330HiFi //?????
movi a2, 64
#elif (XCHAL_ICACHE_SIZE == 16384) //232L and 570T
movi a2, 128
#endif
#endif
movi a2, 32 /* HiFi 330 XCHAL_ICACHE_SIZE = 4096 */
movi a3, 0
loop a2, .L0
iiu a3, 0
iiu a3, 32
iiu a3, 64
iiu a3, 96
addi a3, a3, 128
.L0:
#if 0
#ifdef PROC_PCC_570T
movi a2, 64
#else
movi a2, 32
#endif
#endif
movi a2, 64 /* CACHE LINE 64 Bytes */
movi a3, 0
loop a2, .L1
iii a3, 0
iii a3, 32
iii a3, 64
iii a3, 96
addi a3, a3, 128
.L1:
isync
#endif
#endif
#if 1
movi a2,64 /* XCHAL_DCACHE_SIZE = 8192 */
movi a3, 0
loop a2, .L2
diu a3, 0
// diu a3, 32
diu a3, 64
// diu a3, 96
addi a3, a3, 128
.L2:
movi a2, 64 /* CACHE LINE 64 Bytes */
movi a3, 0
loop a2, .L3
dii a3, 0
// dii a3, 32
dii a3, 64
// dii a3, 96
addi a3, a3, 128
.L3:
dsync
#endif
#if 0
#if (XCHAL_DCACHE_SIZE != 0)
#if (XCHAL_DCACHE_SIZE == 8192) //212GP and 330HiFi
movi a2, 64
#elif (XCHAL_DCACHE_SIZE == 16384) //232L and 570T
movi a2, 128
#endif
#endif
movi a2,64 /* XCHAL_DCACHE_SIZE = 8192 */
movi a3, 0
loop a2, .L2
diu a3, 0
diu a3, 32
diu a3, 64
diu a3, 96
addi a3, a3, 128
.L2:
#if 0
#ifdef PROC_PCC_570T
movi a2, 64
#else
movi a2, 32
#endif
#endif
movi a2, 64 /* CACHE LINE 64 Bytes */
movi a3, 0
loop a2, .L3
dii a3, 0
dii a3, 32
dii a3, 64
dii a3, 96
addi a3, a3, 128
.L3:
dsync
#endif
.macro set_access_mode am
movi a4, \am
wdtlb a4, a3
witlb a4, a3
.endm
// Turn caches on for regions 0x40000000 and 0x60000000
// Disable all accesses for 0, 0x00000000, and 0xE0000000
// Leave all other regions unchanged (i.e bypassed for devices)
// 1: cached 2: bypass 15: invalid compare MSB 3 bits
#define CACHE_ON
movi a3, 0
set_access_mode 2
//set_access_mode 15
movi a3, 0x40000000 // ROM
#ifdef CACHE_ON
set_access_mode 1 //cache on for 0x40000000-0x5fffffff
#else
set_access_mode 2 //cache off for 0x40000000-0x5fffffff
#endif
movi a3, 0x60000000 // RAM
#ifdef CACHE_ON
// set_access_mode 2 //cache off for 0x60000000-0x7fffffff
set_access_mode 1 //cache on for 0x60000000-0x7fffffff
#else
set_access_mode 2 //cache off for 0x60000000-0x7fffffff
#endif
movi a3, 0xE0000000
set_access_mode 15
//bypass cache
// movi a3, 0xA0000000
// set_access_mode 2
#if 1
/* struct rom_table {
void *unpack_start,
void *unpack_end,
void *archive_start
};
*/
movi a2, _vector_text_msg_start
// movi a2, _rom_store_table
beqz a2, unpackdone
unpack:
l32i a3, a2, 0 // start vaddr
l32i a4, a2, 4 // end vaddr
l32i a5, a2, 8 // store vaddr
bltu a3, a4, unpack1
bnez a3, unpacknext
bnez a5, unpacknext
j unpackdone
unpack1:
l32i a6, a5, 0
addi a5, a5, 4
s32i a6, a3, 0
addi a3, a3, 4
bltu a3, a4, unpack1
unpacknext:
addi a2, a2, 12
j unpack
#endif
unpackdone:
movi sp, __stack
movi a2, PS_WOE_MASK | PS_PROGSTACK_MASK //in corebits.h
wsr a2, PS
rsync
//caLL4 System_Stack_Space_Init
#ifdef SPI_FLASH_PRESENT
call4 SpiFlash_Enable
call4 SpiFlash_4Bit_Enable
#endif
caLL4 Sdram_Init
caLL4 Flash_Boot_Switch
caLL4 Flash_Boot_Copy
#ifdef BSS_SLOW // clear BSS, porgram execute goes to else
movi a8, _bss_start
movi a10, _bss_end
sub a11, a10, a8
srli a11, a11, 2
movi a9, 0
#if XCHAL_HAVE_LOOPS
loopnez a11, zerodone
#else
beqz a11, zerodone
branch_zero:
#endif
s32i a9, a8, 0
addi a8, a8, 4
#if !XCHAL_HAVE_LOOPS
addi a11, a11, -1
bnez a11, branch_zero
#endif
zerodone:
#else // ifdef BSS_SLOW
movi a8, _bss_start
movi a10, _bss_end
sub a11, a10, a8
slli a12, a11, 28 /* last 4 bits */
srli a12, a12, 30 /* last 4 bits / 4 */
movi a9, 0
#if XCHAL_HAVE_LOOPS
loopnez a12, zerodone_fourbyte
#else
beqz a12, zerodone_fourbyte
branch_4byte:
#endif
s32i a9, a8, 0
addi a8, a8, 4
#if !XCHAL_HAVE_LOOPS
addi a12, a12, -1
bnez a12, branch_4byte
#endif
zerodone_fourbyte:
srli a11, a11, 4
#if XCHAL_HAVE_LOOPS
loopnez a11, zerodone_16byte
#else
beqz a11, zerodone_16byte
branch_16byte:
#endif
s32i a9, a8, 0
s32i a9, a8, 4
s32i a9, a8, 8
s32i a9, a8, 12
addi a8, a8, 16
#if !XCHAL_HAVE_LOOPS
addi a11, a11, -1
bnez a11, branch_16byte
#endif
zerodone_16byte: // how about last 2 bits ?
#endif // ifdef BSS_SLOW
//caLL4 Flash_Boot_Copy
callmain:
movi a0, 0
movi a6, 0 // clear argc
movi a7, 0 // clear argv
movi a8, 0 // clear envp
movi a4, main
callx4 a4
reset_exit:
//movi a2, SYS_exit
//simcall
break 1,1