source: rtems/bsps/riscv/riscv/start/start.S @ 8db3f0e

Last change on this file since 8db3f0e was 8db3f0e, checked in by Sebastian Huber <sebastian.huber@…>, on Jul 19, 2018 at 10:11:19 AM

riscv: Rework exception handling

Remove _CPU_ISR_install_raw_handler() and _CPU_ISR_install_vector()
functions. Applications can install an exception handler via the fatal
error handler to handle synchronous exceptions.

Handle interrupt exceptions via _RISCV_Interrupt_dispatch() which must
be provided by the BSP.

Update #3433.

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