• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022 HPMicro
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15#include "hpm_csr_regs.h"
16
17    .section .start, "ax"
18
19    .global _start
20    .type _start,@function
21
22_start:
23    /* Initialize global pointer */
24    .option push
25    .option norelax
26    la gp, __global_pointer$
27    .option pop
28
29    /* reset mstatus to 0*/
30    csrrw x0, mstatus, x0
31#ifdef __riscv_flen
32    /* Enable FPU */
33    li t0, CSR_MSTATUS_FS_MASK
34    csrrs t0, mstatus, t0
35
36    /* Initialize FCSR */
37    fscsr zero
38#endif
39
40#ifdef INIT_EXT_RAM_FOR_DATA
41    la t0, _stack_safe
42    mv sp, t0
43    call _init_ext_ram
44#endif
45
46    /* Initialize stack pointer */
47    la t0, _stack
48    mv sp, t0
49
50#ifdef CONFIG_NOT_ENABLE_ICACHE
51    call l1c_ic_disable
52#else
53    call l1c_ic_enable
54#endif
55#ifdef CONFIG_NOT_ENABLE_DCACHE
56    call l1c_dc_invalidate_all
57    call l1c_dc_disable
58#else
59    call l1c_dc_enable
60    call l1c_dc_invalidate_all
61#endif
62
63    /*
64     * Initialize LMA/VMA sections.
65     * Relocation for any sections that need to be copied from LMA to VMA.
66     */
67    call c_startup
68
69#ifndef NO_CLEANUP_AT_START
70    /* clean up */
71    call _clean_up
72#endif
73
74#ifdef __nds_execit
75    /* Initialize EXEC.IT table */
76    la t0, _ITB_BASE_
77    csrw uitb, t0
78#endif
79
80#ifndef CONFIG_FREERTOS
81    #define HANDLER_TRAP irq_handler_trap
82#else
83    #define HANDLER_TRAP freertos_risc_v_trap_handler
84#endif
85
86    /* Initial machine trap-vector Base */
87    la t0, HalTrapVector
88    csrw mtvec, t0
89
90
91    /* System reset handler */
92    call reset_handler
93
94    /* Infinite loop, if returned accidently */
951:    j 1b
96
97    .weak exit
98exit:
991:    j 1b
100
101    .section .isr_vector, "ax"
102    .weak nmi_handler
103nmi_handler:
1041:    j 1b
105
106