[6d85e05] | 1 | /* |
---|
| 2 | * Copyright (c) 2015 University of York. |
---|
| 3 | * Hesham Almatary <hesham@alumni.york.ac.uk> |
---|
| 4 | * |
---|
| 5 | * Copyright (c) 2013, The Regents of the University of California (Regents). |
---|
| 6 | * All Rights Reserved. |
---|
| 7 | * |
---|
| 8 | * Redistribution and use in source and binary forms, with or without |
---|
| 9 | * modification, are permitted provided that the following conditions |
---|
| 10 | * are met: |
---|
| 11 | * 1. Redistributions of source code must retain the above copyright |
---|
| 12 | * notice, this list of conditions and the following disclaimer. |
---|
| 13 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
| 14 | * notice, this list of conditions and the following disclaimer in the |
---|
| 15 | * documentation and/or other materials provided with the distribution. |
---|
| 16 | * |
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
---|
| 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
| 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
| 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
---|
| 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
---|
| 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
---|
| 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
---|
| 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
---|
| 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
---|
| 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
---|
| 27 | * SUCH DAMAGE. |
---|
| 28 | */ |
---|
[52f4fb6] | 29 | |
---|
[6d85e05] | 30 | #include <rtems/asm.h> |
---|
[fe2cd01b] | 31 | #include <rtems/score/cpu.h> |
---|
| 32 | #include <rtems/score/riscv-utility.h> |
---|
| 33 | #include <bsp/linker-symbols.h> |
---|
| 34 | #include <bspopts.h> |
---|
[6d85e05] | 35 | |
---|
| 36 | EXTERN(bsp_section_bss_begin) |
---|
| 37 | EXTERN(bsp_section_bss_end) |
---|
| 38 | EXTERN(ISR_Handler) |
---|
| 39 | EXTERN(bsp_section_stack_begin) |
---|
| 40 | |
---|
| 41 | PUBLIC(bsp_start_vector_table_begin) |
---|
| 42 | PUBLIC(bsp_start_vector_table_end) |
---|
| 43 | PUBLIC(_start) |
---|
| 44 | |
---|
[5f5c450] | 45 | .section .bsp_start_text, "wax", @progbits |
---|
[52f4fb6] | 46 | .align 2 |
---|
| 47 | |
---|
[6d85e05] | 48 | TYPE_FUNC(_start) |
---|
| 49 | SYM(_start): |
---|
[9b2ef07f] | 50 | /* Load global pointer */ |
---|
| 51 | .option push |
---|
| 52 | .option norelax |
---|
| 53 | la gp, __global_pointer$ |
---|
| 54 | .option pop |
---|
| 55 | |
---|
[2086948a] | 56 | #ifdef RTEMS_SMP |
---|
| 57 | csrr s0, mhartid |
---|
[5f5c450] | 58 | bnez s0, .Lwait_for_go |
---|
[2086948a] | 59 | #endif |
---|
| 60 | |
---|
[52f4fb6] | 61 | /* load stack and frame pointers */ |
---|
| 62 | la sp, _Configuration_Interrupt_stack_area_end |
---|
[6d85e05] | 63 | |
---|
[fe2cd01b] | 64 | #ifdef BSP_START_COPY_FDT_FROM_U_BOOT |
---|
| 65 | mv a0, a1 |
---|
| 66 | call bsp_fdt_copy |
---|
| 67 | #endif |
---|
| 68 | |
---|
| 69 | la t0, ISR_Handler |
---|
| 70 | csrw mtvec, t0 |
---|
| 71 | |
---|
[b0ee789] | 72 | /* Clear .bss */ |
---|
| 73 | la a0, bsp_section_bss_begin |
---|
| 74 | li a1, 0 |
---|
| 75 | la a2, bsp_section_bss_size |
---|
| 76 | call memset |
---|
[6d85e05] | 77 | |
---|
[5f5c450] | 78 | #ifdef RTEMS_SMP |
---|
| 79 | /* Give go to secondary processors */ |
---|
| 80 | la t0, .Lsecondary_processor_go |
---|
| 81 | fence iorw,ow |
---|
| 82 | amoswap.w zero, zero, 0(t0) |
---|
| 83 | #endif |
---|
| 84 | |
---|
[52f4fb6] | 85 | /* Init FPU unit if it's there */ |
---|
| 86 | li t0, MSTATUS_FS |
---|
| 87 | csrs mstatus, t0 |
---|
[6d85e05] | 88 | |
---|
[52f4fb6] | 89 | j boot_card |
---|
[6d85e05] | 90 | |
---|
[2086948a] | 91 | #ifdef RTEMS_SMP |
---|
[5f5c450] | 92 | /* Wait for go issued by the boot processor (mhartid == 0) */ |
---|
| 93 | .Lwait_for_go: |
---|
| 94 | la t0, .Lsecondary_processor_go |
---|
| 95 | .Lwait_for_go_again: |
---|
| 96 | lw t1, 0(t0) |
---|
| 97 | fence iorw, iorw |
---|
| 98 | sext.w t1, t1 |
---|
| 99 | bnez t1, .Lwait_for_go_again |
---|
[2086948a] | 100 | .Lloop_forever: |
---|
| 101 | j .Lloop_forever |
---|
[5f5c450] | 102 | |
---|
| 103 | .Lsecondary_processor_go: |
---|
| 104 | .word 0xdeadbeef |
---|
[2086948a] | 105 | #endif |
---|
| 106 | |
---|
[52f4fb6] | 107 | .align 4 |
---|
[6d85e05] | 108 | bsp_start_vector_table_begin: |
---|
[52f4fb6] | 109 | .word _RISCV_Exception_default /* User int */ |
---|
| 110 | .word _RISCV_Exception_default /* Supervisor int */ |
---|
| 111 | .word _RISCV_Exception_default /* Reserved */ |
---|
| 112 | .word _RISCV_Exception_default /* Machine int */ |
---|
| 113 | .word _RISCV_Exception_default /* User timer int */ |
---|
| 114 | .word _RISCV_Exception_default /* Supervisor Timer int */ |
---|
| 115 | .word _RISCV_Exception_default /* Reserved */ |
---|
| 116 | .word _RISCV_Exception_default /* Machine Timer int */ |
---|
| 117 | .word _RISCV_Exception_default /* User external int */ |
---|
| 118 | .word _RISCV_Exception_default /* Supervisor external int */ |
---|
| 119 | .word _RISCV_Exception_default /* Reserved */ |
---|
| 120 | .word _RISCV_Exception_default /* Machine external int */ |
---|
| 121 | .word _RISCV_Exception_default |
---|
| 122 | .word _RISCV_Exception_default |
---|
| 123 | .word _RISCV_Exception_default |
---|
| 124 | .word _RISCV_Exception_default |
---|
[6d85e05] | 125 | bsp_start_vector_table_end: |
---|