1/****************************************************************************** 2 * Copyright (c) 2022 Telink Semiconductor (Shanghai) Co., Ltd. ("TELINK") 3 * All rights reserved. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 *****************************************************************************/ 18#if 1 /*default is open*/ 19 .section .vectors, "ax" 20 21 //.org and linker's relaxation (-flto) cannot be used at the same time 22 //Pop corresponds to push. Before using .option norelax, use push to save the current .option configuration 23 //and then modify .option. After using norelax, use pop to restore 24 .option push 25 .option norelax 26 .org 0x0 27 28 29 .global _RESET_ENTRY 30 .type _RESET_ENTRY,@function 31 32 .align 2 33_RESET_ENTRY: 34 j _START 35 //free the 6th ~ 7th byte to store the crc type of the bin file 36 .org 0x18 37 .word (BIN_SIZE) 38 39 .org 0x20 40 .word ('T'<<24 | 'L'<<16 | 'N'<<8 | 'K') 41 42 .org 0x26 43 //.short (0x0003) //READ: cmd:1x, addr:1x, data:1x, dummy:0 44 //.short (0x070B) //FREAD: cmd:1x, addr:1x, data:1x, dummy:8 45 .short (0x173B) //DREAD: cmd:1x, addr:1x, data:2x, dummy:8 46 //.short (0x53BB) //X2READ: cmd:1x, addr:2x, data:2x, dummy:4 47 //.short (0x276B) //QREAD: cmd:1x, addr:1x, data:4x, dummy:8 48 //.short (0x65EB) //X4READ: cmd:1x, addr:4x, data:4x, dummy:6 49 .option pop 50 .align 2 51 52_START: 53 54#if 0 55 // add debug, PB4 output 1 56 lui t0,0x80140 //0x8014030a 57 li t1, 0xef 58 li t2, 0x10 59 sb t1 , 0x30a(t0) //0x8014030a PB oen = 0xef 60 sb t2 , 0x30b(t0) //0x8014030b PB output = 0x10 61#endif 62 /* Initialize global pointer */ 63 .option push 64 .option norelax 65 la gp, __global_pointer$ 66 .option pop 67 68 /* Initialize stack pointer */ 69 la t0, _STACK_TOP 70 mv sp, t0 71 72#ifdef __nds_execit 73 /* Initialize EXEC.IT table */ 74 la t0, _ITB_BASE_ 75 csrw uitb, t0 76#endif 77 78#ifdef __riscv_flen 79 /* Enable FPU */ 80 li t0, 0x00006000 81 csrrs t0, mstatus, t0 82 /* Initialize FCSR */ 83 fscsr zero 84#endif 85 86 /* Initial machine trap-vector Base */ 87 la t0, __vectors 88 csrw mtvec, t0 89 90 /* Enable vectored external plic interrupt */ 91 csrsi mmisc_ctl, 2 92/* 93*#if (SUPPORT_PFT_ARCH) 94* plic_set_feature(FLD_FEATURE_PREEMPT_PRIORITY_INT_EN | FLD_FEATURE_VECTOR_MODE_EN);//enable vectored in PLIC 95* =(0xe4000000))= 0x03 96*#else 97* plic_set_feature(FLD_FEATURE_VECTOR_MODE_EN);//enable vectored in PLIC 98* =(0xe4000000))= 0x02 99*#endif 100*/ 101 /*vector mode enable bit (VECTORED) of the Feature Enable Register */ 102 lui t0, 0xe4000 103 li t1, 0x03 104 sw t1, 0x0(t0) //(*(volatile unsigned long*)(0xe4000000))= 0x02 105 106 /* Enable I/D-Cache */ 107 csrr t0, mcache_ctl 108 ori t0, t0, 1 #/I-Cache 109 ori t0, t0, 2 #/D-Cache 110 csrw mcache_ctl, t0 111 fence.i 112 /* Move retention reset from flash to sram */ 113_RETENTION_RESET_INIT: 114 115 la t1, _RETENTION_RESET_LMA_START 116 la t2, _RETENTION_RESET_VMA_START 117 la t3, _RETENTION_RESET_VMA_END 118_RETENTION_RESET_BEGIN: 119 bleu t3, t2, _RETENTION_DATA_INIT 120 lw t0, 0(t1) 121 sw t0, 0(t2) 122 addi t1, t1, 4 123 addi t2, t2, 4 124 j _RETENTION_RESET_BEGIN 125 126 /* Move retention from flash to sram */ 127_RETENTION_DATA_INIT: 128 129 la t1, _RETENTION_DATA_LMA_START 130 la t2, _RETENTION_DATA_VMA_START 131 la t3, _RETENTION_DATA_VMA_END 132_RETENTION_DATA_INIT_BEGIN: 133 bleu t3, t2, _RAMCODE_INIT 134 lw t0, 0(t1) 135 sw t0, 0(t2) 136 addi t1, t1, 4 137 addi t2, t2, 4 138 j _RETENTION_DATA_INIT_BEGIN 139 140 /* Move ramcode from flash to sram */ 141_RAMCODE_INIT: 142 143 la t1, _RAMCODE_LMA_START 144 la t2, _RAMCODE_VMA_START 145 la t3, _RAMCODE_VMA_END 146_RAMCODE_INIT_BEGIN: 147 bleu t3, t2, _DATA_INIT 148 lw t0, 0(t1) 149 sw t0, 0(t2) 150 addi t1, t1, 4 151 addi t2, t2, 4 152 j _RAMCODE_INIT_BEGIN 153 154 155 /* Move Data from flash to sram */ 156_DATA_INIT: 157 la t1, _DATA_LMA_START 158 la t2, _DATA_VMA_START 159 la t3, _DATA_VMA_END 160_DATA_INIT_BEGIN: 161 bleu t3, t2, _ZERO_BSS 162 lw t0, 0(t1) 163 sw t0, 0(t2) 164 addi t1, t1, 4 165 addi t2, t2, 4 166 j _DATA_INIT_BEGIN 167 168 169 170 /* Zero .bss section in sram */ 171_ZERO_BSS: 172 lui t0, 0 173 la t2, _BSS_VMA_START 174 la t3, _BSS_VMA_END 175_ZERO_BSS_BEGIN: 176 bleu t3, t2, _ZERO_AES 177 sw t0, 0(t2) 178 addi t2, t2, 4 179 j _ZERO_BSS_BEGIN 180 181 /* Zero .aes section in sram */ 182_ZERO_AES: 183 lui t0, 0 184 la t2, _AES_VMA_START 185 la t3, _AES_VMA_END 186_ZERO_AES_BEGIN: 187 bleu t3, t2, _FILL_STK 188 sw t0, 0(t2) 189 addi t2, t2, 4 190 j _ZERO_AES_BEGIN 191 192 /* Fill the remaining section in sram */ 193_FILL_STK: 194#if 0 195 lui t0, 0x55555 196 addi t0, t0, 0x555 197 la t2, _BSS_VMA_END 198 la t3, _STACK_TOP 199_FILL_STK_BEGIN: 200 bleu t3, t2, _MAIN_FUNC 201 sw t0, 0(t2) 202 addi t2, t2, 4 203 j _FILL_STK_BEGIN 204#endif 205 /* Jump to the main function */ 206_MAIN_FUNC: 207 nop 208 209 la t0, main 210 jalr t0 211 212 nop 213 nop 214 nop 215 nop 216 nop 217_END: 218 j _END 219 220 221 .section .retention_reset, "ax" 222 .option push 223 .option norelax 224 .global _IRESET_ENTRY 225 .type _IRESET_ENTRY,@function 226 227 .align 2 228_IRESET_ENTRY: 229 /* Decide whether this is an NMI or cold reset */ 230 j _ISTART 231 232 .org 0x22 233_ISTART: 234 235 236/* GPIO_DEBUG */ 237#if 0 238 // add debug, PE1 output 1 239 lui t0, 0x80140 //0x80140322 240 li t1, 0xfd 241 li t2, 0x02 242 sb t1 , 0x322(t0) //0x8014030a Pe oen = 0xfd 243 sb t2 , 0x323(t0) //0x8014030b Pe output = 0x02 244#endif 245#if 0 246 // add debug, PD0 output 1 247 lui t0,0x80140 //0x8014031a 248 li t1, 0xfe 249 li t2, 0x01 250 sb t1 , 0x31a(t0) //0x8014031a PD oen = 0xfe 251 sb t2 , 0x31b(t0) //0x8014031b PD output = 0x01 252#endif 253 254 /* Initialize global pointer */ 255 256 la gp, __global_pointer$ 257 .option pop 258 259 /* Initialize stack pointer */ 260 la t0, _STACK_TOP 261 mv sp, t0 262 263#ifdef __nds_execit 264 /* Initialize EXEC.IT table */ 265 la t0, _ITB_BASE_ 266 csrw uitb, t0 267#endif 268 269#ifdef __riscv_flen 270 /* Enable FPU */ 271 li t0, 0x00006000 272 csrrs t0, mstatus, t0 273 /* Initialize FCSR */ 274 fscsr zero 275#endif 276 277 /* Initial machine trap-vector Base */ 278 la t0, __vectors 279 csrw mtvec, t0 280 281 /* Enable vectored external plic interrupt */ 282 csrsi mmisc_ctl, 2 283 284/* 285*#if (SUPPORT_PFT_ARCH) 286* plic_set_feature(FLD_FEATURE_PREEMPT_PRIORITY_INT_EN | FLD_FEATURE_VECTOR_MODE_EN);//enable vectored in PLIC 287* =(0xe4000000))= 0x03 288*#else 289* plic_set_feature(FLD_FEATURE_VECTOR_MODE_EN);//enable vectored in PLIC 290* =(0xe4000000))= 0x02 291*#endif 292*/ 293 /*vector mode enable bit (VECTORED) of the Feature Enable Register */ 294 lui t0, 0xe4000 295 li t1, 0x03 296 sw t1, 0x0(t0) //(*(volatile unsigned long*)(0xe4000000))= 0x03 297 298 /* Enable I/D-Cache */ 299 csrr t0, mcache_ctl 300 ori t0, t0, 1 #/I-Cache 301 ori t0, t0, 2 #/D-Cache 302 csrw mcache_ctl, t0 303 fence.i 304 305 306/* flash wakeup */ 307_WAKEUP_FLASH: 308 lui t0 , 0x80140 309 li t1 , 0xff 310 li t2 , 0x0 311 li t3 , 0xab 312 sb t1 , 0x329(t0) //mspi ie enable :0x140329:0x1f 313 sb t2 , 0x101(t0) //cs_low :0x140101:0x00 314 sb t3 , 0x100(t0) //wakeup_cmd :0x140100:0xab 315_MSPI_WAIT: 316 lui t0 , 0x80140 317 lb t2 , 0x102(t0) //read reg_mspi_status FLD_MSPI_BUSY(bit0) 318 li t3 , 0x1 319 li t4 , 0x10 320 beq t3 , t2 ,_MSPI_WAIT 321 sb t4 , 0x101(t0) //cs_high :0x140101:0x10 322#if 0 323 // add debug, PB4 output 1 324 lui t0,0x80140 //0x8014030a 325 li t1, 0x00 326 sb t1 , 0x30b(t0) //0x8014030b PB output = 0x00 327#endif 328/*efuse load need delay about 18us */ 329 li t0 , 0 330 li t1 , 226 331_WAIT_EFUSE_LOAD_FINISH: 332 addi t0 , t0 , 1 333 bgeu t1 , t0 , _WAIT_EFUSE_LOAD_FINISH 334 335#if 0 336 // add debug, PB4 output 1 337 lui t0,0x80140 //0x8014030a 338 li t1, 0x10 339 sb t1 , 0x30b(t0) //0x8014030b PB output = 0x00 340#endif 341 342 343_MULTI_ADDRESS_BEGIN: 344 lui t0 , 0x80140 345 la t1 , g_pm_multi_addr 346 lw t2 , 0(t1) 347 sw t2 , 0x104(t0) //g_pm_multi_addr->0x80140104 348 349 350#if 0 351 /* Move ramcode from flash to sram */ 352_IRAMCODE_INIT: 353 354 la t1, _RAMCODE_LMA_START 355 la t2, _RAMCODE_VMA_START 356 la t3, _RAMCODE_VMA_END 357_IRAMCODE_INIT_BEGIN: 358 bleu t3, t2, _IDATA_INIT 359 lw t0, 0(t1) 360 sw t0, 0(t2) 361 addi t1, t1, 4 362 addi t2, t2, 4 363 j _IRAMCODE_INIT_BEGIN 364#endif 365 366 /* Move Data from flash to sram */ 367_IDATA_INIT: 368 la t1, _DATA_LMA_START 369 la t2, _DATA_VMA_START 370 la t3, _DATA_VMA_END 371_IDATA_INIT_BEGIN: 372 bleu t3, t2, _IZERO_BSS 373 lw t0, 0(t1) 374 sw t0, 0(t2) 375 addi t1, t1, 4 376 addi t2, t2, 4 377 j _IDATA_INIT_BEGIN 378 379 380 381 /* Zero .bss section in sram */ 382_IZERO_BSS: 383 lui t0, 0 384 la t2, _BSS_VMA_START 385 la t3, _BSS_VMA_END 386_IZERO_BSS_BEGIN: 387 bleu t3, t2, _IZERO_AES 388 sw t0, 0(t2) 389 addi t2, t2, 4 390 j _IZERO_BSS_BEGIN 391 392 /* Zero .aes section in sram */ 393_IZERO_AES: 394 lui t0, 0 395 la t2, _AES_VMA_START 396 la t3, _AES_VMA_END 397_IZERO_AES_BEGIN: 398 bleu t3, t2, _IFILL_STK 399 sw t0, 0(t2) 400 addi t2, t2, 4 401 j _IZERO_AES_BEGIN 402 403 404 /* Fill the remaining section in sram */ 405_IFILL_STK: 406#if 0 407 lui t0, 0x55555 408 addi t0, t0, 0x555 409 la t2, _BSS_VMA_END 410 la t3, _STACK_TOP 411_IFILL_STK_BEGIN: 412 bleu t3, t2, _IMAIN_FUNC 413 sw t0, 0(t2) 414 addi t2, t2, 4 415 j _IFILL_STK_BEGIN 416#endif 417 /* Jump to the main function */ 418_IMAIN_FUNC: 419 nop 420 421 la t0, main 422 jalr t0 423 424 nop 425 nop 426 nop 427 nop 428 nop 429_IEND: 430 j _IEND 431 432 433.text 434 .global default_irq_entry 435 .align 2 436 437default_irq_entry: 4381: j 1b 439 440 .weak trap_handler 441 442 trap_handler: 4431: j 1b 444 445 .macro INTERRUPT num 446 .weak entry_irq\num 447 .set entry_irq\num, default_irq_entry 448 .long entry_irq\num 449 .endm 450 451#define VECTOR_NUMINTRS 63 452 453 .section .ram_code, "ax" 454 455 .global __vectors 456 .balign 256 457 458 459__vectors: 460 /* Trap vector */ 461 .long trap_entry 462 463 /* PLIC interrupt vector */ 464 .altmacro 465 .set irqno, 1 466 .rept VECTOR_NUMINTRS/* .rept .endr */ 467 INTERRUPT %irqno 468 .set irqno, irqno+1 469 .endr 470#endif 471