arch: added support for the riscv32 architecture
RISC-V is an open-source instruction set architecture.
Added support for the 32bit version of RISC-V to Zephyr.
1) exceptions/interrupts/faults are handled at the architecture
level via the __irq_wrapper handler. Context saving/restoring
of registers can be handled at both architecture and SOC levels.
If SOC-specific registers need to be saved, SOC level needs to
provide __soc_save_context and __soc_restore_context functions
that shall be accounted by the architecture level, when
corresponding config variable RISCV_SOC_CONTEXT_SAVE is set.
2) As RISC-V architecture does not provide a clear ISA specification
about interrupt handling, each RISC-V SOC handles it in its own
way. Hence, at the architecture level, the __irq_wrapper handler
expects the following functions to be provided by the SOC level:
__soc_is_irq: to check if the exception is the result of an
interrupt or not.
__soc_handle_irq: handle pending IRQ at SOC level (ex: clear
pending IRQ in SOC-specific IRQ register)
3) Thread/task scheduling, as well as IRQ offloading are handled via
the RISC-V system call ("ecall"), which is also handled via the
__irq_wrapper handler. The _Swap asm function just calls "ecall"
to generate an exception.
4) As there is no conventional way of handling CPU power save in
RISC-V, the default nano_cpu_idle and nano_cpu_atomic_idle
functions just unlock interrupts and return to the caller, without
issuing any CPU power saving instruction. Nonetheless, to allow
SOC-level to implement proper CPU power save, nano_cpu_idle and
nano_cpu_atomic_idle functions are defined as __weak
at the architecture level.
Change-Id: I980a161d0009f3f404ad22b226a6229fbb492389
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-11 00:24:30 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 Jean-Paul Etienne <fractalclone@gmail.com>
|
2018-11-01 22:25:13 -06:00
|
|
|
* Copyright (c) 2018 Foundries.io Ltd
|
2020-07-21 16:00:39 +02:00
|
|
|
* Copyright (c) 2020 BayLibre, SAS
|
arch: added support for the riscv32 architecture
RISC-V is an open-source instruction set architecture.
Added support for the 32bit version of RISC-V to Zephyr.
1) exceptions/interrupts/faults are handled at the architecture
level via the __irq_wrapper handler. Context saving/restoring
of registers can be handled at both architecture and SOC levels.
If SOC-specific registers need to be saved, SOC level needs to
provide __soc_save_context and __soc_restore_context functions
that shall be accounted by the architecture level, when
corresponding config variable RISCV_SOC_CONTEXT_SAVE is set.
2) As RISC-V architecture does not provide a clear ISA specification
about interrupt handling, each RISC-V SOC handles it in its own
way. Hence, at the architecture level, the __irq_wrapper handler
expects the following functions to be provided by the SOC level:
__soc_is_irq: to check if the exception is the result of an
interrupt or not.
__soc_handle_irq: handle pending IRQ at SOC level (ex: clear
pending IRQ in SOC-specific IRQ register)
3) Thread/task scheduling, as well as IRQ offloading are handled via
the RISC-V system call ("ecall"), which is also handled via the
__irq_wrapper handler. The _Swap asm function just calls "ecall"
to generate an exception.
4) As there is no conventional way of handling CPU power save in
RISC-V, the default nano_cpu_idle and nano_cpu_atomic_idle
functions just unlock interrupts and return to the caller, without
issuing any CPU power saving instruction. Nonetheless, to allow
SOC-level to implement proper CPU power save, nano_cpu_idle and
nano_cpu_atomic_idle functions are defined as __weak
at the architecture level.
Change-Id: I980a161d0009f3f404ad22b226a6229fbb492389
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-11 00:24:30 +01:00
|
|
|
*
|
2017-01-18 17:01:01 -08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
arch: added support for the riscv32 architecture
RISC-V is an open-source instruction set architecture.
Added support for the 32bit version of RISC-V to Zephyr.
1) exceptions/interrupts/faults are handled at the architecture
level via the __irq_wrapper handler. Context saving/restoring
of registers can be handled at both architecture and SOC levels.
If SOC-specific registers need to be saved, SOC level needs to
provide __soc_save_context and __soc_restore_context functions
that shall be accounted by the architecture level, when
corresponding config variable RISCV_SOC_CONTEXT_SAVE is set.
2) As RISC-V architecture does not provide a clear ISA specification
about interrupt handling, each RISC-V SOC handles it in its own
way. Hence, at the architecture level, the __irq_wrapper handler
expects the following functions to be provided by the SOC level:
__soc_is_irq: to check if the exception is the result of an
interrupt or not.
__soc_handle_irq: handle pending IRQ at SOC level (ex: clear
pending IRQ in SOC-specific IRQ register)
3) Thread/task scheduling, as well as IRQ offloading are handled via
the RISC-V system call ("ecall"), which is also handled via the
__irq_wrapper handler. The _Swap asm function just calls "ecall"
to generate an exception.
4) As there is no conventional way of handling CPU power save in
RISC-V, the default nano_cpu_idle and nano_cpu_atomic_idle
functions just unlock interrupts and return to the caller, without
issuing any CPU power saving instruction. Nonetheless, to allow
SOC-level to implement proper CPU power save, nano_cpu_idle and
nano_cpu_atomic_idle functions are defined as __weak
at the architecture level.
Change-Id: I980a161d0009f3f404ad22b226a6229fbb492389
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-11 00:24:30 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <toolchain.h>
|
2017-06-17 11:30:47 -04:00
|
|
|
#include <linker/sections.h>
|
arch: added support for the riscv32 architecture
RISC-V is an open-source instruction set architecture.
Added support for the 32bit version of RISC-V to Zephyr.
1) exceptions/interrupts/faults are handled at the architecture
level via the __irq_wrapper handler. Context saving/restoring
of registers can be handled at both architecture and SOC levels.
If SOC-specific registers need to be saved, SOC level needs to
provide __soc_save_context and __soc_restore_context functions
that shall be accounted by the architecture level, when
corresponding config variable RISCV_SOC_CONTEXT_SAVE is set.
2) As RISC-V architecture does not provide a clear ISA specification
about interrupt handling, each RISC-V SOC handles it in its own
way. Hence, at the architecture level, the __irq_wrapper handler
expects the following functions to be provided by the SOC level:
__soc_is_irq: to check if the exception is the result of an
interrupt or not.
__soc_handle_irq: handle pending IRQ at SOC level (ex: clear
pending IRQ in SOC-specific IRQ register)
3) Thread/task scheduling, as well as IRQ offloading are handled via
the RISC-V system call ("ecall"), which is also handled via the
__irq_wrapper handler. The _Swap asm function just calls "ecall"
to generate an exception.
4) As there is no conventional way of handling CPU power save in
RISC-V, the default nano_cpu_idle and nano_cpu_atomic_idle
functions just unlock interrupts and return to the caller, without
issuing any CPU power saving instruction. Nonetheless, to allow
SOC-level to implement proper CPU power save, nano_cpu_idle and
nano_cpu_atomic_idle functions are defined as __weak
at the architecture level.
Change-Id: I980a161d0009f3f404ad22b226a6229fbb492389
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-11 00:24:30 +01:00
|
|
|
#include <offsets_short.h>
|
2019-10-25 00:08:21 +09:00
|
|
|
#include <arch/cpu.h>
|
2020-03-11 18:15:29 -07:00
|
|
|
#include <sys/util.h>
|
|
|
|
#include <kernel.h>
|
2020-07-21 16:00:39 +02:00
|
|
|
#include <syscall.h>
|
|
|
|
#include <arch/riscv/csr.h>
|
2022-02-24 22:30:03 -05:00
|
|
|
#include <arch/riscv/syscall.h>
|
2022-02-22 14:09:55 -05:00
|
|
|
#include "asm_macros.inc"
|
2020-03-11 18:15:29 -07:00
|
|
|
|
|
|
|
/* Convenience macros for loading/storing register states. */
|
|
|
|
|
|
|
|
#define DO_FP_CALLER_SAVED(op, reg) \
|
|
|
|
op ft0, __z_arch_esf_t_ft0_OFFSET(reg) ;\
|
|
|
|
op ft1, __z_arch_esf_t_ft1_OFFSET(reg) ;\
|
|
|
|
op ft2, __z_arch_esf_t_ft2_OFFSET(reg) ;\
|
|
|
|
op ft3, __z_arch_esf_t_ft3_OFFSET(reg) ;\
|
|
|
|
op ft4, __z_arch_esf_t_ft4_OFFSET(reg) ;\
|
|
|
|
op ft5, __z_arch_esf_t_ft5_OFFSET(reg) ;\
|
|
|
|
op ft6, __z_arch_esf_t_ft6_OFFSET(reg) ;\
|
|
|
|
op ft7, __z_arch_esf_t_ft7_OFFSET(reg) ;\
|
|
|
|
op ft8, __z_arch_esf_t_ft8_OFFSET(reg) ;\
|
|
|
|
op ft9, __z_arch_esf_t_ft9_OFFSET(reg) ;\
|
|
|
|
op ft10, __z_arch_esf_t_ft10_OFFSET(reg) ;\
|
|
|
|
op ft11, __z_arch_esf_t_ft11_OFFSET(reg) ;\
|
|
|
|
op fa0, __z_arch_esf_t_fa0_OFFSET(reg) ;\
|
|
|
|
op fa1, __z_arch_esf_t_fa1_OFFSET(reg) ;\
|
|
|
|
op fa2, __z_arch_esf_t_fa2_OFFSET(reg) ;\
|
|
|
|
op fa3, __z_arch_esf_t_fa3_OFFSET(reg) ;\
|
|
|
|
op fa4, __z_arch_esf_t_fa4_OFFSET(reg) ;\
|
|
|
|
op fa5, __z_arch_esf_t_fa5_OFFSET(reg) ;\
|
|
|
|
op fa6, __z_arch_esf_t_fa6_OFFSET(reg) ;\
|
|
|
|
op fa7, __z_arch_esf_t_fa7_OFFSET(reg) ;
|
|
|
|
|
2020-07-21 16:00:39 +02:00
|
|
|
#define DO_CALLER_SAVED(op) \
|
|
|
|
op ra, __z_arch_esf_t_ra_OFFSET(sp) ;\
|
|
|
|
op t0, __z_arch_esf_t_t0_OFFSET(sp) ;\
|
|
|
|
op t1, __z_arch_esf_t_t1_OFFSET(sp) ;\
|
|
|
|
op t2, __z_arch_esf_t_t2_OFFSET(sp) ;\
|
|
|
|
op t3, __z_arch_esf_t_t3_OFFSET(sp) ;\
|
|
|
|
op t4, __z_arch_esf_t_t4_OFFSET(sp) ;\
|
|
|
|
op t5, __z_arch_esf_t_t5_OFFSET(sp) ;\
|
|
|
|
op t6, __z_arch_esf_t_t6_OFFSET(sp) ;\
|
|
|
|
op a0, __z_arch_esf_t_a0_OFFSET(sp) ;\
|
|
|
|
op a1, __z_arch_esf_t_a1_OFFSET(sp) ;\
|
|
|
|
op a2, __z_arch_esf_t_a2_OFFSET(sp) ;\
|
|
|
|
op a3, __z_arch_esf_t_a3_OFFSET(sp) ;\
|
|
|
|
op a4, __z_arch_esf_t_a4_OFFSET(sp) ;\
|
|
|
|
op a5, __z_arch_esf_t_a5_OFFSET(sp) ;\
|
|
|
|
op a6, __z_arch_esf_t_a6_OFFSET(sp) ;\
|
|
|
|
op a7, __z_arch_esf_t_a7_OFFSET(sp) ;
|
|
|
|
|
2022-03-09 23:47:38 -05:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
#define GET_CURRENT_CPU(dst, tmp) \
|
|
|
|
csrr tmp, mhartid ;\
|
|
|
|
la dst, _kernel + ___kernel_t_cpus_OFFSET ;\
|
|
|
|
shiftmul_add dst, tmp, ___cpu_t_SIZEOF
|
|
|
|
#else
|
|
|
|
#define GET_CURRENT_CPU(dst, tmp) \
|
|
|
|
la dst, _kernel + ___kernel_t_cpus_OFFSET
|
|
|
|
#endif
|
|
|
|
|
2022-02-24 22:30:03 -05:00
|
|
|
#define ASSUME_EQUAL(x, y) .if x != y; .err; .endif
|
2020-07-21 16:00:39 +02:00
|
|
|
|
arch: added support for the riscv32 architecture
RISC-V is an open-source instruction set architecture.
Added support for the 32bit version of RISC-V to Zephyr.
1) exceptions/interrupts/faults are handled at the architecture
level via the __irq_wrapper handler. Context saving/restoring
of registers can be handled at both architecture and SOC levels.
If SOC-specific registers need to be saved, SOC level needs to
provide __soc_save_context and __soc_restore_context functions
that shall be accounted by the architecture level, when
corresponding config variable RISCV_SOC_CONTEXT_SAVE is set.
2) As RISC-V architecture does not provide a clear ISA specification
about interrupt handling, each RISC-V SOC handles it in its own
way. Hence, at the architecture level, the __irq_wrapper handler
expects the following functions to be provided by the SOC level:
__soc_is_irq: to check if the exception is the result of an
interrupt or not.
__soc_handle_irq: handle pending IRQ at SOC level (ex: clear
pending IRQ in SOC-specific IRQ register)
3) Thread/task scheduling, as well as IRQ offloading are handled via
the RISC-V system call ("ecall"), which is also handled via the
__irq_wrapper handler. The _Swap asm function just calls "ecall"
to generate an exception.
4) As there is no conventional way of handling CPU power save in
RISC-V, the default nano_cpu_idle and nano_cpu_atomic_idle
functions just unlock interrupts and return to the caller, without
issuing any CPU power saving instruction. Nonetheless, to allow
SOC-level to implement proper CPU power save, nano_cpu_idle and
nano_cpu_atomic_idle functions are defined as __weak
at the architecture level.
Change-Id: I980a161d0009f3f404ad22b226a6229fbb492389
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-11 00:24:30 +01:00
|
|
|
/* imports */
|
|
|
|
GDATA(_sw_isr_table)
|
|
|
|
GTEXT(__soc_is_irq)
|
|
|
|
GTEXT(__soc_handle_irq)
|
|
|
|
GTEXT(_Fault)
|
2018-11-01 22:25:13 -06:00
|
|
|
#ifdef CONFIG_RISCV_SOC_CONTEXT_SAVE
|
|
|
|
GTEXT(__soc_save_context)
|
|
|
|
GTEXT(__soc_restore_context)
|
|
|
|
#endif /* CONFIG_RISCV_SOC_CONTEXT_SAVE */
|
arch: added support for the riscv32 architecture
RISC-V is an open-source instruction set architecture.
Added support for the 32bit version of RISC-V to Zephyr.
1) exceptions/interrupts/faults are handled at the architecture
level via the __irq_wrapper handler. Context saving/restoring
of registers can be handled at both architecture and SOC levels.
If SOC-specific registers need to be saved, SOC level needs to
provide __soc_save_context and __soc_restore_context functions
that shall be accounted by the architecture level, when
corresponding config variable RISCV_SOC_CONTEXT_SAVE is set.
2) As RISC-V architecture does not provide a clear ISA specification
about interrupt handling, each RISC-V SOC handles it in its own
way. Hence, at the architecture level, the __irq_wrapper handler
expects the following functions to be provided by the SOC level:
__soc_is_irq: to check if the exception is the result of an
interrupt or not.
__soc_handle_irq: handle pending IRQ at SOC level (ex: clear
pending IRQ in SOC-specific IRQ register)
3) Thread/task scheduling, as well as IRQ offloading are handled via
the RISC-V system call ("ecall"), which is also handled via the
__irq_wrapper handler. The _Swap asm function just calls "ecall"
to generate an exception.
4) As there is no conventional way of handling CPU power save in
RISC-V, the default nano_cpu_idle and nano_cpu_atomic_idle
functions just unlock interrupts and return to the caller, without
issuing any CPU power saving instruction. Nonetheless, to allow
SOC-level to implement proper CPU power save, nano_cpu_idle and
nano_cpu_atomic_idle functions are defined as __weak
at the architecture level.
Change-Id: I980a161d0009f3f404ad22b226a6229fbb492389
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-11 00:24:30 +01:00
|
|
|
|
2022-02-24 22:30:03 -05:00
|
|
|
GTEXT(z_riscv_fatal_error)
|
2022-03-07 17:01:36 -05:00
|
|
|
GTEXT(z_get_next_switch_handle)
|
|
|
|
GTEXT(z_riscv_switch)
|
|
|
|
GTEXT(z_riscv_thread_start)
|
arch: added support for the riscv32 architecture
RISC-V is an open-source instruction set architecture.
Added support for the 32bit version of RISC-V to Zephyr.
1) exceptions/interrupts/faults are handled at the architecture
level via the __irq_wrapper handler. Context saving/restoring
of registers can be handled at both architecture and SOC levels.
If SOC-specific registers need to be saved, SOC level needs to
provide __soc_save_context and __soc_restore_context functions
that shall be accounted by the architecture level, when
corresponding config variable RISCV_SOC_CONTEXT_SAVE is set.
2) As RISC-V architecture does not provide a clear ISA specification
about interrupt handling, each RISC-V SOC handles it in its own
way. Hence, at the architecture level, the __irq_wrapper handler
expects the following functions to be provided by the SOC level:
__soc_is_irq: to check if the exception is the result of an
interrupt or not.
__soc_handle_irq: handle pending IRQ at SOC level (ex: clear
pending IRQ in SOC-specific IRQ register)
3) Thread/task scheduling, as well as IRQ offloading are handled via
the RISC-V system call ("ecall"), which is also handled via the
__irq_wrapper handler. The _Swap asm function just calls "ecall"
to generate an exception.
4) As there is no conventional way of handling CPU power save in
RISC-V, the default nano_cpu_idle and nano_cpu_atomic_idle
functions just unlock interrupts and return to the caller, without
issuing any CPU power saving instruction. Nonetheless, to allow
SOC-level to implement proper CPU power save, nano_cpu_idle and
nano_cpu_atomic_idle functions are defined as __weak
at the architecture level.
Change-Id: I980a161d0009f3f404ad22b226a6229fbb492389
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-11 00:24:30 +01:00
|
|
|
|
2018-04-06 07:48:53 -04:00
|
|
|
#ifdef CONFIG_TRACING
|
2019-09-19 09:25:19 +02:00
|
|
|
GTEXT(sys_trace_isr_enter)
|
arch: added support for the riscv32 architecture
RISC-V is an open-source instruction set architecture.
Added support for the 32bit version of RISC-V to Zephyr.
1) exceptions/interrupts/faults are handled at the architecture
level via the __irq_wrapper handler. Context saving/restoring
of registers can be handled at both architecture and SOC levels.
If SOC-specific registers need to be saved, SOC level needs to
provide __soc_save_context and __soc_restore_context functions
that shall be accounted by the architecture level, when
corresponding config variable RISCV_SOC_CONTEXT_SAVE is set.
2) As RISC-V architecture does not provide a clear ISA specification
about interrupt handling, each RISC-V SOC handles it in its own
way. Hence, at the architecture level, the __irq_wrapper handler
expects the following functions to be provided by the SOC level:
__soc_is_irq: to check if the exception is the result of an
interrupt or not.
__soc_handle_irq: handle pending IRQ at SOC level (ex: clear
pending IRQ in SOC-specific IRQ register)
3) Thread/task scheduling, as well as IRQ offloading are handled via
the RISC-V system call ("ecall"), which is also handled via the
__irq_wrapper handler. The _Swap asm function just calls "ecall"
to generate an exception.
4) As there is no conventional way of handling CPU power save in
RISC-V, the default nano_cpu_idle and nano_cpu_atomic_idle
functions just unlock interrupts and return to the caller, without
issuing any CPU power saving instruction. Nonetheless, to allow
SOC-level to implement proper CPU power save, nano_cpu_idle and
nano_cpu_atomic_idle functions are defined as __weak
at the architecture level.
Change-Id: I980a161d0009f3f404ad22b226a6229fbb492389
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-11 00:24:30 +01:00
|
|
|
#endif
|
|
|
|
|
2020-07-21 16:00:39 +02:00
|
|
|
#ifdef CONFIG_USERSPACE
|
2022-02-24 22:30:03 -05:00
|
|
|
GDATA(_k_syscall_table)
|
2020-07-21 16:00:39 +02:00
|
|
|
#endif
|
|
|
|
|
arch: added support for the riscv32 architecture
RISC-V is an open-source instruction set architecture.
Added support for the 32bit version of RISC-V to Zephyr.
1) exceptions/interrupts/faults are handled at the architecture
level via the __irq_wrapper handler. Context saving/restoring
of registers can be handled at both architecture and SOC levels.
If SOC-specific registers need to be saved, SOC level needs to
provide __soc_save_context and __soc_restore_context functions
that shall be accounted by the architecture level, when
corresponding config variable RISCV_SOC_CONTEXT_SAVE is set.
2) As RISC-V architecture does not provide a clear ISA specification
about interrupt handling, each RISC-V SOC handles it in its own
way. Hence, at the architecture level, the __irq_wrapper handler
expects the following functions to be provided by the SOC level:
__soc_is_irq: to check if the exception is the result of an
interrupt or not.
__soc_handle_irq: handle pending IRQ at SOC level (ex: clear
pending IRQ in SOC-specific IRQ register)
3) Thread/task scheduling, as well as IRQ offloading are handled via
the RISC-V system call ("ecall"), which is also handled via the
__irq_wrapper handler. The _Swap asm function just calls "ecall"
to generate an exception.
4) As there is no conventional way of handling CPU power save in
RISC-V, the default nano_cpu_idle and nano_cpu_atomic_idle
functions just unlock interrupts and return to the caller, without
issuing any CPU power saving instruction. Nonetheless, to allow
SOC-level to implement proper CPU power save, nano_cpu_idle and
nano_cpu_atomic_idle functions are defined as __weak
at the architecture level.
Change-Id: I980a161d0009f3f404ad22b226a6229fbb492389
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-11 00:24:30 +01:00
|
|
|
/* exports */
|
|
|
|
GTEXT(__irq_wrapper)
|
|
|
|
|
|
|
|
/* use ABI name of registers for the sake of simplicity */
|
|
|
|
|
|
|
|
/*
|
2018-11-01 22:25:13 -06:00
|
|
|
* Generic architecture-level IRQ handling, along with callouts to
|
|
|
|
* SoC-specific routines.
|
|
|
|
*
|
|
|
|
* Architecture level IRQ handling includes basic context save/restore
|
|
|
|
* of standard registers and calling ISRs registered at Zephyr's driver
|
|
|
|
* level.
|
|
|
|
*
|
|
|
|
* Since RISC-V does not completely prescribe IRQ handling behavior,
|
|
|
|
* implementations vary (some implementations also deviate from
|
|
|
|
* what standard behavior is defined). Hence, the arch level code expects
|
|
|
|
* the following functions to be provided at the SOC level:
|
|
|
|
*
|
|
|
|
* - __soc_is_irq: decide if we're handling an interrupt or an exception
|
|
|
|
* - __soc_handle_irq: handle SoC-specific details for a pending IRQ
|
|
|
|
* (e.g. clear a pending bit in a SoC-specific register)
|
arch: added support for the riscv32 architecture
RISC-V is an open-source instruction set architecture.
Added support for the 32bit version of RISC-V to Zephyr.
1) exceptions/interrupts/faults are handled at the architecture
level via the __irq_wrapper handler. Context saving/restoring
of registers can be handled at both architecture and SOC levels.
If SOC-specific registers need to be saved, SOC level needs to
provide __soc_save_context and __soc_restore_context functions
that shall be accounted by the architecture level, when
corresponding config variable RISCV_SOC_CONTEXT_SAVE is set.
2) As RISC-V architecture does not provide a clear ISA specification
about interrupt handling, each RISC-V SOC handles it in its own
way. Hence, at the architecture level, the __irq_wrapper handler
expects the following functions to be provided by the SOC level:
__soc_is_irq: to check if the exception is the result of an
interrupt or not.
__soc_handle_irq: handle pending IRQ at SOC level (ex: clear
pending IRQ in SOC-specific IRQ register)
3) Thread/task scheduling, as well as IRQ offloading are handled via
the RISC-V system call ("ecall"), which is also handled via the
__irq_wrapper handler. The _Swap asm function just calls "ecall"
to generate an exception.
4) As there is no conventional way of handling CPU power save in
RISC-V, the default nano_cpu_idle and nano_cpu_atomic_idle
functions just unlock interrupts and return to the caller, without
issuing any CPU power saving instruction. Nonetheless, to allow
SOC-level to implement proper CPU power save, nano_cpu_idle and
nano_cpu_atomic_idle functions are defined as __weak
at the architecture level.
Change-Id: I980a161d0009f3f404ad22b226a6229fbb492389
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-11 00:24:30 +01:00
|
|
|
*
|
2019-01-31 04:40:07 -06:00
|
|
|
* If CONFIG_RISCV_SOC_CONTEXT_SAVE=y, calls to SoC-level context save/restore
|
2018-11-01 22:25:13 -06:00
|
|
|
* routines are also made here. For details, see the Kconfig help text.
|
arch: added support for the riscv32 architecture
RISC-V is an open-source instruction set architecture.
Added support for the 32bit version of RISC-V to Zephyr.
1) exceptions/interrupts/faults are handled at the architecture
level via the __irq_wrapper handler. Context saving/restoring
of registers can be handled at both architecture and SOC levels.
If SOC-specific registers need to be saved, SOC level needs to
provide __soc_save_context and __soc_restore_context functions
that shall be accounted by the architecture level, when
corresponding config variable RISCV_SOC_CONTEXT_SAVE is set.
2) As RISC-V architecture does not provide a clear ISA specification
about interrupt handling, each RISC-V SOC handles it in its own
way. Hence, at the architecture level, the __irq_wrapper handler
expects the following functions to be provided by the SOC level:
__soc_is_irq: to check if the exception is the result of an
interrupt or not.
__soc_handle_irq: handle pending IRQ at SOC level (ex: clear
pending IRQ in SOC-specific IRQ register)
3) Thread/task scheduling, as well as IRQ offloading are handled via
the RISC-V system call ("ecall"), which is also handled via the
__irq_wrapper handler. The _Swap asm function just calls "ecall"
to generate an exception.
4) As there is no conventional way of handling CPU power save in
RISC-V, the default nano_cpu_idle and nano_cpu_atomic_idle
functions just unlock interrupts and return to the caller, without
issuing any CPU power saving instruction. Nonetheless, to allow
SOC-level to implement proper CPU power save, nano_cpu_idle and
nano_cpu_atomic_idle functions are defined as __weak
at the architecture level.
Change-Id: I980a161d0009f3f404ad22b226a6229fbb492389
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-11 00:24:30 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handler called upon each exception/interrupt/fault
|
|
|
|
* In this architecture, system call (ECALL) is used to perform context
|
|
|
|
* switching or IRQ offloading (when enabled).
|
|
|
|
*/
|
|
|
|
SECTION_FUNC(exception.entry, __irq_wrapper)
|
|
|
|
|
2022-02-24 22:30:03 -05:00
|
|
|
#ifdef CONFIG_USERSPACE
|
2020-07-21 16:00:39 +02:00
|
|
|
/*
|
2022-02-24 22:30:03 -05:00
|
|
|
* The scratch register contains either the privileged stack pointer
|
|
|
|
* to use when interrupting a user mode thread, or 0 when interrupting
|
|
|
|
* kernel mode in which case the current stack should be used.
|
2020-07-21 16:00:39 +02:00
|
|
|
*/
|
2022-02-24 22:30:03 -05:00
|
|
|
csrrw sp, mscratch, sp
|
|
|
|
bnez sp, 1f
|
arch: added support for the riscv32 architecture
RISC-V is an open-source instruction set architecture.
Added support for the 32bit version of RISC-V to Zephyr.
1) exceptions/interrupts/faults are handled at the architecture
level via the __irq_wrapper handler. Context saving/restoring
of registers can be handled at both architecture and SOC levels.
If SOC-specific registers need to be saved, SOC level needs to
provide __soc_save_context and __soc_restore_context functions
that shall be accounted by the architecture level, when
corresponding config variable RISCV_SOC_CONTEXT_SAVE is set.
2) As RISC-V architecture does not provide a clear ISA specification
about interrupt handling, each RISC-V SOC handles it in its own
way. Hence, at the architecture level, the __irq_wrapper handler
expects the following functions to be provided by the SOC level:
__soc_is_irq: to check if the exception is the result of an
interrupt or not.
__soc_handle_irq: handle pending IRQ at SOC level (ex: clear
pending IRQ in SOC-specific IRQ register)
3) Thread/task scheduling, as well as IRQ offloading are handled via
the RISC-V system call ("ecall"), which is also handled via the
__irq_wrapper handler. The _Swap asm function just calls "ecall"
to generate an exception.
4) As there is no conventional way of handling CPU power save in
RISC-V, the default nano_cpu_idle and nano_cpu_atomic_idle
functions just unlock interrupts and return to the caller, without
issuing any CPU power saving instruction. Nonetheless, to allow
SOC-level to implement proper CPU power save, nano_cpu_idle and
nano_cpu_atomic_idle functions are defined as __weak
at the architecture level.
Change-Id: I980a161d0009f3f404ad22b226a6229fbb492389
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-11 00:24:30 +01:00
|
|
|
|
2022-02-24 22:30:03 -05:00
|
|
|
/* restore privileged stack pointer and zero the scratch reg */
|
|
|
|
csrrw sp, mscratch, sp
|
|
|
|
1:
|
|
|
|
#endif
|
2022-03-09 17:46:30 -05:00
|
|
|
|
2022-02-24 22:30:03 -05:00
|
|
|
/* Save caller-saved registers on current thread stack. */
|
|
|
|
addi sp, sp, -__z_arch_esf_t_SIZEOF
|
|
|
|
DO_CALLER_SAVED(sr) ;
|
2020-03-11 18:15:29 -07:00
|
|
|
|
2022-03-09 17:21:27 -05:00
|
|
|
/* Save s0 in the esf and load it with &_current_cpu. */
|
|
|
|
sr s0, __z_arch_esf_t_s0_OFFSET(sp)
|
2022-03-09 23:47:38 -05:00
|
|
|
GET_CURRENT_CPU(s0, t0)
|
2022-03-09 17:21:27 -05:00
|
|
|
|
2020-07-21 16:00:39 +02:00
|
|
|
#ifdef CONFIG_USERSPACE
|
|
|
|
/*
|
2022-02-24 22:30:03 -05:00
|
|
|
* The scratch register now contains either the user mode stack
|
|
|
|
* pointer, or 0 if entered from kernel mode. Retrieve that value
|
|
|
|
* and zero the scratch register as we are in kernel mode now.
|
2020-07-21 16:00:39 +02:00
|
|
|
*/
|
2022-02-24 22:30:03 -05:00
|
|
|
csrrw t0, mscratch, zero
|
|
|
|
bnez t0, 1f
|
2020-07-21 16:00:39 +02:00
|
|
|
|
2022-02-24 22:30:03 -05:00
|
|
|
/* came from kernel mode: adjust stack value */
|
|
|
|
add t0, sp, __z_arch_esf_t_SIZEOF
|
|
|
|
1:
|
|
|
|
/* save stack value to be restored later */
|
|
|
|
sr t0, __z_arch_esf_t_sp_OFFSET(sp)
|
2020-07-21 16:00:39 +02:00
|
|
|
|
|
|
|
/* Clear user mode variable */
|
|
|
|
la t0, is_user_mode
|
2022-02-21 23:18:20 -05:00
|
|
|
sw zero, 0(t0)
|
2022-02-24 22:30:03 -05:00
|
|
|
#endif
|
|
|
|
|
2022-03-07 17:31:13 -05:00
|
|
|
/* Save MEPC register */
|
|
|
|
csrr t0, mepc
|
|
|
|
sr t0, __z_arch_esf_t_mepc_OFFSET(sp)
|
|
|
|
|
|
|
|
/* Save MSTATUS register */
|
|
|
|
csrr t4, mstatus
|
|
|
|
sr t4, __z_arch_esf_t_mstatus_OFFSET(sp)
|
|
|
|
|
2022-02-24 22:30:03 -05:00
|
|
|
#if defined(CONFIG_FPU) && defined(CONFIG_FPU_SHARING)
|
|
|
|
/* Assess whether floating-point registers need to be saved. */
|
2022-03-07 17:31:13 -05:00
|
|
|
li t1, MSTATUS_FS_INIT
|
|
|
|
and t0, t4, t1
|
2022-02-24 22:30:03 -05:00
|
|
|
beqz t0, skip_store_fp_caller_saved
|
|
|
|
DO_FP_CALLER_SAVED(fsr, sp)
|
|
|
|
skip_store_fp_caller_saved:
|
|
|
|
#endif /* CONFIG_FPU && CONFIG_FPU_SHARING */
|
|
|
|
|
|
|
|
#ifdef CONFIG_RISCV_SOC_CONTEXT_SAVE
|
|
|
|
/* Handle context saving at SOC level. */
|
|
|
|
addi a0, sp, __z_arch_esf_t_soc_context_OFFSET
|
|
|
|
jal ra, __soc_save_context
|
|
|
|
#endif /* CONFIG_RISCV_SOC_CONTEXT_SAVE */
|
2020-07-21 16:00:39 +02:00
|
|
|
|
2022-03-09 17:46:30 -05:00
|
|
|
/*
|
|
|
|
* Check if exception is the result of an interrupt or not.
|
|
|
|
* (SOC dependent). Following the RISC-V architecture spec, the MSB
|
|
|
|
* of the mcause register is used to indicate whether an exception
|
|
|
|
* is the result of an interrupt or an exception/fault. But for some
|
|
|
|
* SOCs (like pulpino or riscv-qemu), the MSB is never set to indicate
|
|
|
|
* interrupt. Hence, check for interrupt/exception via the __soc_is_irq
|
|
|
|
* function (that needs to be implemented by each SOC). The result is
|
|
|
|
* returned via register a0 (1: interrupt, 0 exception)
|
|
|
|
*/
|
|
|
|
jal ra, __soc_is_irq
|
|
|
|
|
|
|
|
/* If a0 != 0, jump to is_interrupt */
|
|
|
|
bnez a0, is_interrupt
|
arch: added support for the riscv32 architecture
RISC-V is an open-source instruction set architecture.
Added support for the 32bit version of RISC-V to Zephyr.
1) exceptions/interrupts/faults are handled at the architecture
level via the __irq_wrapper handler. Context saving/restoring
of registers can be handled at both architecture and SOC levels.
If SOC-specific registers need to be saved, SOC level needs to
provide __soc_save_context and __soc_restore_context functions
that shall be accounted by the architecture level, when
corresponding config variable RISCV_SOC_CONTEXT_SAVE is set.
2) As RISC-V architecture does not provide a clear ISA specification
about interrupt handling, each RISC-V SOC handles it in its own
way. Hence, at the architecture level, the __irq_wrapper handler
expects the following functions to be provided by the SOC level:
__soc_is_irq: to check if the exception is the result of an
interrupt or not.
__soc_handle_irq: handle pending IRQ at SOC level (ex: clear
pending IRQ in SOC-specific IRQ register)
3) Thread/task scheduling, as well as IRQ offloading are handled via
the RISC-V system call ("ecall"), which is also handled via the
__irq_wrapper handler. The _Swap asm function just calls "ecall"
to generate an exception.
4) As there is no conventional way of handling CPU power save in
RISC-V, the default nano_cpu_idle and nano_cpu_atomic_idle
functions just unlock interrupts and return to the caller, without
issuing any CPU power saving instruction. Nonetheless, to allow
SOC-level to implement proper CPU power save, nano_cpu_idle and
nano_cpu_atomic_idle functions are defined as __weak
at the architecture level.
Change-Id: I980a161d0009f3f404ad22b226a6229fbb492389
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-11 00:24:30 +01:00
|
|
|
|
2022-02-24 22:30:03 -05:00
|
|
|
#ifdef CONFIG_PMP_STACK_GUARD
|
|
|
|
li t0, MSTATUS_MPRV
|
|
|
|
csrs mstatus, t0
|
|
|
|
#endif
|
2020-07-21 16:00:39 +02:00
|
|
|
|
2022-03-09 17:46:30 -05:00
|
|
|
/*
|
|
|
|
* If the exception is the result of an ECALL, check whether to
|
|
|
|
* perform a context-switch or an IRQ offload. Otherwise call _Fault
|
|
|
|
* to report the exception.
|
|
|
|
*/
|
|
|
|
csrr t0, mcause
|
|
|
|
li t2, SOC_MCAUSE_EXP_MASK
|
|
|
|
and t0, t0, t2
|
2021-12-21 16:44:57 -08:00
|
|
|
|
2022-03-09 17:46:30 -05:00
|
|
|
/*
|
|
|
|
* If mcause == SOC_MCAUSE_ECALL_EXP, handle system call from
|
|
|
|
* kernel thread.
|
2020-07-21 16:00:39 +02:00
|
|
|
*/
|
2022-02-24 22:30:03 -05:00
|
|
|
li t1, SOC_MCAUSE_ECALL_EXP
|
2022-03-09 17:46:30 -05:00
|
|
|
beq t0, t1, is_kernel_syscall
|
2020-07-21 16:00:39 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_USERSPACE
|
2022-03-09 17:46:30 -05:00
|
|
|
/*
|
2022-02-24 22:30:03 -05:00
|
|
|
* If mcause == SOC_MCAUSE_USER_ECALL_EXP, handle system call
|
|
|
|
* for user mode thread.
|
arch: added support for the riscv32 architecture
RISC-V is an open-source instruction set architecture.
Added support for the 32bit version of RISC-V to Zephyr.
1) exceptions/interrupts/faults are handled at the architecture
level via the __irq_wrapper handler. Context saving/restoring
of registers can be handled at both architecture and SOC levels.
If SOC-specific registers need to be saved, SOC level needs to
provide __soc_save_context and __soc_restore_context functions
that shall be accounted by the architecture level, when
corresponding config variable RISCV_SOC_CONTEXT_SAVE is set.
2) As RISC-V architecture does not provide a clear ISA specification
about interrupt handling, each RISC-V SOC handles it in its own
way. Hence, at the architecture level, the __irq_wrapper handler
expects the following functions to be provided by the SOC level:
__soc_is_irq: to check if the exception is the result of an
interrupt or not.
__soc_handle_irq: handle pending IRQ at SOC level (ex: clear
pending IRQ in SOC-specific IRQ register)
3) Thread/task scheduling, as well as IRQ offloading are handled via
the RISC-V system call ("ecall"), which is also handled via the
__irq_wrapper handler. The _Swap asm function just calls "ecall"
to generate an exception.
4) As there is no conventional way of handling CPU power save in
RISC-V, the default nano_cpu_idle and nano_cpu_atomic_idle
functions just unlock interrupts and return to the caller, without
issuing any CPU power saving instruction. Nonetheless, to allow
SOC-level to implement proper CPU power save, nano_cpu_idle and
nano_cpu_atomic_idle functions are defined as __weak
at the architecture level.
Change-Id: I980a161d0009f3f404ad22b226a6229fbb492389
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-11 00:24:30 +01:00
|
|
|
*/
|
2022-02-24 22:30:03 -05:00
|
|
|
li t1, SOC_MCAUSE_USER_ECALL_EXP
|
2022-03-09 17:46:30 -05:00
|
|
|
beq t0, t1, is_user_syscall
|
|
|
|
#endif /* CONFIG_USERSPACE */
|
2018-08-02 10:38:57 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Call _Fault to handle exception.
|
2019-07-16 15:21:19 -07:00
|
|
|
* Stack pointer is pointing to a z_arch_esf_t structure, pass it
|
2018-08-02 10:38:57 -07:00
|
|
|
* to _Fault (via register a0).
|
2020-07-21 16:00:39 +02:00
|
|
|
* If _Fault shall return, set return address to
|
|
|
|
* no_reschedule to restore stack.
|
2018-08-02 10:38:57 -07:00
|
|
|
*/
|
2022-02-21 21:36:55 -05:00
|
|
|
mv a0, sp
|
2021-07-18 02:07:48 +08:00
|
|
|
la ra, no_reschedule
|
2018-08-02 10:38:57 -07:00
|
|
|
tail _Fault
|
arch: added support for the riscv32 architecture
RISC-V is an open-source instruction set architecture.
Added support for the 32bit version of RISC-V to Zephyr.
1) exceptions/interrupts/faults are handled at the architecture
level via the __irq_wrapper handler. Context saving/restoring
of registers can be handled at both architecture and SOC levels.
If SOC-specific registers need to be saved, SOC level needs to
provide __soc_save_context and __soc_restore_context functions
that shall be accounted by the architecture level, when
corresponding config variable RISCV_SOC_CONTEXT_SAVE is set.
2) As RISC-V architecture does not provide a clear ISA specification
about interrupt handling, each RISC-V SOC handles it in its own
way. Hence, at the architecture level, the __irq_wrapper handler
expects the following functions to be provided by the SOC level:
__soc_is_irq: to check if the exception is the result of an
interrupt or not.
__soc_handle_irq: handle pending IRQ at SOC level (ex: clear
pending IRQ in SOC-specific IRQ register)
3) Thread/task scheduling, as well as IRQ offloading are handled via
the RISC-V system call ("ecall"), which is also handled via the
__irq_wrapper handler. The _Swap asm function just calls "ecall"
to generate an exception.
4) As there is no conventional way of handling CPU power save in
RISC-V, the default nano_cpu_idle and nano_cpu_atomic_idle
functions just unlock interrupts and return to the caller, without
issuing any CPU power saving instruction. Nonetheless, to allow
SOC-level to implement proper CPU power save, nano_cpu_idle and
nano_cpu_atomic_idle functions are defined as __weak
at the architecture level.
Change-Id: I980a161d0009f3f404ad22b226a6229fbb492389
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-11 00:24:30 +01:00
|
|
|
|
2022-03-09 17:46:30 -05:00
|
|
|
is_kernel_syscall:
|
|
|
|
/*
|
|
|
|
* A syscall is the result of an ecall instruction, in which case the
|
|
|
|
* MEPC will contain the address of the ecall instruction.
|
|
|
|
* Increment saved MEPC by 4 to prevent triggering the same ecall
|
|
|
|
* again upon exiting the ISR.
|
|
|
|
*
|
|
|
|
* It's safe to always increment by 4, even with compressed
|
|
|
|
* instructions, because the ecall instruction is always 4 bytes.
|
|
|
|
*/
|
2022-02-22 14:09:55 -05:00
|
|
|
lr t0, __z_arch_esf_t_mepc_OFFSET(sp)
|
2022-03-09 17:46:30 -05:00
|
|
|
addi t0, t0, 4
|
2022-02-22 14:09:55 -05:00
|
|
|
sr t0, __z_arch_esf_t_mepc_OFFSET(sp)
|
2022-03-09 17:46:30 -05:00
|
|
|
|
2022-02-24 22:30:03 -05:00
|
|
|
/* Determine what to do. Operation code is in a7. */
|
|
|
|
lr a7, __z_arch_esf_t_a7_OFFSET(sp)
|
2022-03-09 17:46:30 -05:00
|
|
|
|
2022-03-07 17:01:36 -05:00
|
|
|
ASSUME_EQUAL(RV_ECALL_RUNTIME_EXCEPT, 0)
|
|
|
|
beqz a7, do_fault
|
2020-07-21 16:00:39 +02:00
|
|
|
|
2022-02-24 22:30:03 -05:00
|
|
|
#if defined(CONFIG_IRQ_OFFLOAD)
|
|
|
|
addi a7, a7, -1
|
|
|
|
ASSUME_EQUAL(RV_ECALL_IRQ_OFFLOAD, 1)
|
|
|
|
beqz a7, do_irq_offload
|
|
|
|
#endif
|
2020-07-21 16:00:39 +02:00
|
|
|
|
2022-02-24 22:30:03 -05:00
|
|
|
/* default fault code is K_ERR_KERNEL_OOPS */
|
|
|
|
li a0, 3
|
|
|
|
j 1f
|
2020-07-21 16:00:39 +02:00
|
|
|
|
2022-02-24 22:30:03 -05:00
|
|
|
do_fault:
|
|
|
|
/* Handle RV_ECALL_RUNTIME_EXCEPT. Retrieve reason in a0, esf in A1. */
|
2022-02-22 14:09:55 -05:00
|
|
|
lr a0, __z_arch_esf_t_a0_OFFSET(sp)
|
2022-02-24 22:30:03 -05:00
|
|
|
1: mv a1, sp
|
|
|
|
tail z_riscv_fatal_error
|
2020-07-21 16:00:39 +02:00
|
|
|
|
2022-02-24 22:30:03 -05:00
|
|
|
#if defined(CONFIG_IRQ_OFFLOAD)
|
|
|
|
do_irq_offload:
|
2022-03-07 13:24:38 -05:00
|
|
|
/*
|
|
|
|
* Retrieve provided routine and argument from the stack.
|
|
|
|
* Routine pointer is in saved a0, argument in saved a1
|
|
|
|
* so we load them with a1/a0 (reversed).
|
|
|
|
*/
|
|
|
|
lr a1, __z_arch_esf_t_a0_OFFSET(sp)
|
|
|
|
lr a0, __z_arch_esf_t_a1_OFFSET(sp)
|
|
|
|
|
2022-03-09 17:21:27 -05:00
|
|
|
/* Increment _current_cpu->nested */
|
|
|
|
lw t3, ___cpu_t_nested_OFFSET(s0)
|
2022-03-14 14:51:04 -04:00
|
|
|
addi t4, t3, 1
|
2022-03-09 17:21:27 -05:00
|
|
|
sw t4, ___cpu_t_nested_OFFSET(s0)
|
2022-03-14 14:51:04 -04:00
|
|
|
bnez t3, 1f
|
arch: added support for the riscv32 architecture
RISC-V is an open-source instruction set architecture.
Added support for the 32bit version of RISC-V to Zephyr.
1) exceptions/interrupts/faults are handled at the architecture
level via the __irq_wrapper handler. Context saving/restoring
of registers can be handled at both architecture and SOC levels.
If SOC-specific registers need to be saved, SOC level needs to
provide __soc_save_context and __soc_restore_context functions
that shall be accounted by the architecture level, when
corresponding config variable RISCV_SOC_CONTEXT_SAVE is set.
2) As RISC-V architecture does not provide a clear ISA specification
about interrupt handling, each RISC-V SOC handles it in its own
way. Hence, at the architecture level, the __irq_wrapper handler
expects the following functions to be provided by the SOC level:
__soc_is_irq: to check if the exception is the result of an
interrupt or not.
__soc_handle_irq: handle pending IRQ at SOC level (ex: clear
pending IRQ in SOC-specific IRQ register)
3) Thread/task scheduling, as well as IRQ offloading are handled via
the RISC-V system call ("ecall"), which is also handled via the
__irq_wrapper handler. The _Swap asm function just calls "ecall"
to generate an exception.
4) As there is no conventional way of handling CPU power save in
RISC-V, the default nano_cpu_idle and nano_cpu_atomic_idle
functions just unlock interrupts and return to the caller, without
issuing any CPU power saving instruction. Nonetheless, to allow
SOC-level to implement proper CPU power save, nano_cpu_idle and
nano_cpu_atomic_idle functions are defined as __weak
at the architecture level.
Change-Id: I980a161d0009f3f404ad22b226a6229fbb492389
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-11 00:24:30 +01:00
|
|
|
|
2022-02-24 22:30:03 -05:00
|
|
|
/* Switch to interrupt stack */
|
|
|
|
mv t0, sp
|
2022-03-09 17:21:27 -05:00
|
|
|
lr sp, ___cpu_t_irq_stack_OFFSET(s0)
|
2020-07-21 16:00:39 +02:00
|
|
|
|
2022-03-14 14:51:04 -04:00
|
|
|
/* Save thread stack pointer on interrupt stack */
|
2022-02-24 22:30:03 -05:00
|
|
|
addi sp, sp, -16
|
|
|
|
sr t0, 0(sp)
|
2022-03-14 14:51:04 -04:00
|
|
|
1:
|
2022-03-07 13:24:38 -05:00
|
|
|
/* Execute provided routine (argument is in a0 already). */
|
|
|
|
jalr ra, a1, 0
|
2022-02-24 22:30:03 -05:00
|
|
|
|
2022-03-07 13:24:38 -05:00
|
|
|
/* Leave through the regular IRQ exit path */
|
|
|
|
j irq_done
|
2022-02-24 22:30:03 -05:00
|
|
|
#endif /* CONFIG_IRQ_OFFLOAD */
|
arch: added support for the riscv32 architecture
RISC-V is an open-source instruction set architecture.
Added support for the 32bit version of RISC-V to Zephyr.
1) exceptions/interrupts/faults are handled at the architecture
level via the __irq_wrapper handler. Context saving/restoring
of registers can be handled at both architecture and SOC levels.
If SOC-specific registers need to be saved, SOC level needs to
provide __soc_save_context and __soc_restore_context functions
that shall be accounted by the architecture level, when
corresponding config variable RISCV_SOC_CONTEXT_SAVE is set.
2) As RISC-V architecture does not provide a clear ISA specification
about interrupt handling, each RISC-V SOC handles it in its own
way. Hence, at the architecture level, the __irq_wrapper handler
expects the following functions to be provided by the SOC level:
__soc_is_irq: to check if the exception is the result of an
interrupt or not.
__soc_handle_irq: handle pending IRQ at SOC level (ex: clear
pending IRQ in SOC-specific IRQ register)
3) Thread/task scheduling, as well as IRQ offloading are handled via
the RISC-V system call ("ecall"), which is also handled via the
__irq_wrapper handler. The _Swap asm function just calls "ecall"
to generate an exception.
4) As there is no conventional way of handling CPU power save in
RISC-V, the default nano_cpu_idle and nano_cpu_atomic_idle
functions just unlock interrupts and return to the caller, without
issuing any CPU power saving instruction. Nonetheless, to allow
SOC-level to implement proper CPU power save, nano_cpu_idle and
nano_cpu_atomic_idle functions are defined as __weak
at the architecture level.
Change-Id: I980a161d0009f3f404ad22b226a6229fbb492389
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-11 00:24:30 +01:00
|
|
|
|
2020-07-21 16:00:39 +02:00
|
|
|
#ifdef CONFIG_USERSPACE
|
|
|
|
is_user_syscall:
|
2022-02-24 22:30:03 -05:00
|
|
|
/* It is safe to re-enable IRQs now */
|
|
|
|
csrs mstatus, MSTATUS_IEN
|
2020-07-21 16:00:39 +02:00
|
|
|
|
2022-03-09 17:46:30 -05:00
|
|
|
/*
|
2022-02-24 22:30:03 -05:00
|
|
|
* Same as for is_kernel_syscall: increment saved MEPC by 4 to
|
|
|
|
* prevent triggering the same ecall again upon exiting the ISR.
|
2022-03-09 17:46:30 -05:00
|
|
|
*/
|
2022-02-22 14:09:55 -05:00
|
|
|
lr t1, __z_arch_esf_t_mepc_OFFSET(sp)
|
2022-03-09 17:46:30 -05:00
|
|
|
addi t1, t1, 4
|
2022-02-22 14:09:55 -05:00
|
|
|
sr t1, __z_arch_esf_t_mepc_OFFSET(sp)
|
2022-02-24 22:30:03 -05:00
|
|
|
|
2020-07-21 16:00:39 +02:00
|
|
|
/* Restore argument registers from user stack */
|
2022-02-22 14:09:55 -05:00
|
|
|
lr a0, __z_arch_esf_t_a0_OFFSET(sp)
|
|
|
|
lr a1, __z_arch_esf_t_a1_OFFSET(sp)
|
|
|
|
lr a2, __z_arch_esf_t_a2_OFFSET(sp)
|
|
|
|
lr a3, __z_arch_esf_t_a3_OFFSET(sp)
|
|
|
|
lr a4, __z_arch_esf_t_a4_OFFSET(sp)
|
|
|
|
lr a5, __z_arch_esf_t_a5_OFFSET(sp)
|
2020-07-21 16:00:39 +02:00
|
|
|
mv a6, sp
|
2022-02-22 14:09:55 -05:00
|
|
|
lr a7, __z_arch_esf_t_a7_OFFSET(sp)
|
2020-07-21 16:00:39 +02:00
|
|
|
|
|
|
|
/* validate syscall limit */
|
|
|
|
li t0, K_SYSCALL_LIMIT
|
|
|
|
bltu a7, t0, valid_syscall_id
|
|
|
|
|
|
|
|
/* bad syscall id. Set arg1 to bad id and set call_id to SYSCALL_BAD */
|
|
|
|
mv a0, a7
|
|
|
|
li a7, K_SYSCALL_BAD
|
|
|
|
|
|
|
|
valid_syscall_id:
|
|
|
|
|
2022-02-24 22:30:03 -05:00
|
|
|
la t0, _k_syscall_table
|
2020-07-21 16:00:39 +02:00
|
|
|
|
2022-02-24 22:30:03 -05:00
|
|
|
slli t1, a7, RV_REGSHIFT # Determine offset from indice value
|
|
|
|
add t0, t0, t1 # Table addr + offset = function addr
|
|
|
|
lr t3, 0(t0) # Load function address
|
2020-07-21 16:00:39 +02:00
|
|
|
|
2022-02-24 22:30:03 -05:00
|
|
|
/* Execute syscall function */
|
|
|
|
jalr ra, t3, 0
|
2020-07-21 16:00:39 +02:00
|
|
|
|
2022-02-24 22:30:03 -05:00
|
|
|
/* Update a0 (return value) on the stack */
|
2022-02-22 14:09:55 -05:00
|
|
|
sr a0, __z_arch_esf_t_a0_OFFSET(sp)
|
2020-07-21 16:00:39 +02:00
|
|
|
|
2022-02-24 22:30:03 -05:00
|
|
|
/* Disable IRQs again before leaving */
|
|
|
|
csrc mstatus, MSTATUS_IEN
|
2022-03-09 17:21:27 -05:00
|
|
|
j might_have_rescheduled
|
2020-07-21 16:00:39 +02:00
|
|
|
#endif /* CONFIG_USERSPACE */
|
|
|
|
|
arch: added support for the riscv32 architecture
RISC-V is an open-source instruction set architecture.
Added support for the 32bit version of RISC-V to Zephyr.
1) exceptions/interrupts/faults are handled at the architecture
level via the __irq_wrapper handler. Context saving/restoring
of registers can be handled at both architecture and SOC levels.
If SOC-specific registers need to be saved, SOC level needs to
provide __soc_save_context and __soc_restore_context functions
that shall be accounted by the architecture level, when
corresponding config variable RISCV_SOC_CONTEXT_SAVE is set.
2) As RISC-V architecture does not provide a clear ISA specification
about interrupt handling, each RISC-V SOC handles it in its own
way. Hence, at the architecture level, the __irq_wrapper handler
expects the following functions to be provided by the SOC level:
__soc_is_irq: to check if the exception is the result of an
interrupt or not.
__soc_handle_irq: handle pending IRQ at SOC level (ex: clear
pending IRQ in SOC-specific IRQ register)
3) Thread/task scheduling, as well as IRQ offloading are handled via
the RISC-V system call ("ecall"), which is also handled via the
__irq_wrapper handler. The _Swap asm function just calls "ecall"
to generate an exception.
4) As there is no conventional way of handling CPU power save in
RISC-V, the default nano_cpu_idle and nano_cpu_atomic_idle
functions just unlock interrupts and return to the caller, without
issuing any CPU power saving instruction. Nonetheless, to allow
SOC-level to implement proper CPU power save, nano_cpu_idle and
nano_cpu_atomic_idle functions are defined as __weak
at the architecture level.
Change-Id: I980a161d0009f3f404ad22b226a6229fbb492389
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-11 00:24:30 +01:00
|
|
|
is_interrupt:
|
2022-03-09 17:21:27 -05:00
|
|
|
/* Increment _current_cpu->nested */
|
|
|
|
lw t3, ___cpu_t_nested_OFFSET(s0)
|
2022-02-24 22:30:03 -05:00
|
|
|
addi t4, t3, 1
|
2022-03-09 17:21:27 -05:00
|
|
|
sw t4, ___cpu_t_nested_OFFSET(s0)
|
2022-02-24 22:30:03 -05:00
|
|
|
bnez t3, on_irq_stack
|
arch: added support for the riscv32 architecture
RISC-V is an open-source instruction set architecture.
Added support for the 32bit version of RISC-V to Zephyr.
1) exceptions/interrupts/faults are handled at the architecture
level via the __irq_wrapper handler. Context saving/restoring
of registers can be handled at both architecture and SOC levels.
If SOC-specific registers need to be saved, SOC level needs to
provide __soc_save_context and __soc_restore_context functions
that shall be accounted by the architecture level, when
corresponding config variable RISCV_SOC_CONTEXT_SAVE is set.
2) As RISC-V architecture does not provide a clear ISA specification
about interrupt handling, each RISC-V SOC handles it in its own
way. Hence, at the architecture level, the __irq_wrapper handler
expects the following functions to be provided by the SOC level:
__soc_is_irq: to check if the exception is the result of an
interrupt or not.
__soc_handle_irq: handle pending IRQ at SOC level (ex: clear
pending IRQ in SOC-specific IRQ register)
3) Thread/task scheduling, as well as IRQ offloading are handled via
the RISC-V system call ("ecall"), which is also handled via the
__irq_wrapper handler. The _Swap asm function just calls "ecall"
to generate an exception.
4) As there is no conventional way of handling CPU power save in
RISC-V, the default nano_cpu_idle and nano_cpu_atomic_idle
functions just unlock interrupts and return to the caller, without
issuing any CPU power saving instruction. Nonetheless, to allow
SOC-level to implement proper CPU power save, nano_cpu_idle and
nano_cpu_atomic_idle functions are defined as __weak
at the architecture level.
Change-Id: I980a161d0009f3f404ad22b226a6229fbb492389
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-11 00:24:30 +01:00
|
|
|
|
|
|
|
/* Switch to interrupt stack */
|
2022-02-24 22:30:03 -05:00
|
|
|
mv t0, sp
|
2022-03-09 17:21:27 -05:00
|
|
|
lr sp, ___cpu_t_irq_stack_OFFSET(s0)
|
arch: added support for the riscv32 architecture
RISC-V is an open-source instruction set architecture.
Added support for the 32bit version of RISC-V to Zephyr.
1) exceptions/interrupts/faults are handled at the architecture
level via the __irq_wrapper handler. Context saving/restoring
of registers can be handled at both architecture and SOC levels.
If SOC-specific registers need to be saved, SOC level needs to
provide __soc_save_context and __soc_restore_context functions
that shall be accounted by the architecture level, when
corresponding config variable RISCV_SOC_CONTEXT_SAVE is set.
2) As RISC-V architecture does not provide a clear ISA specification
about interrupt handling, each RISC-V SOC handles it in its own
way. Hence, at the architecture level, the __irq_wrapper handler
expects the following functions to be provided by the SOC level:
__soc_is_irq: to check if the exception is the result of an
interrupt or not.
__soc_handle_irq: handle pending IRQ at SOC level (ex: clear
pending IRQ in SOC-specific IRQ register)
3) Thread/task scheduling, as well as IRQ offloading are handled via
the RISC-V system call ("ecall"), which is also handled via the
__irq_wrapper handler. The _Swap asm function just calls "ecall"
to generate an exception.
4) As there is no conventional way of handling CPU power save in
RISC-V, the default nano_cpu_idle and nano_cpu_atomic_idle
functions just unlock interrupts and return to the caller, without
issuing any CPU power saving instruction. Nonetheless, to allow
SOC-level to implement proper CPU power save, nano_cpu_idle and
nano_cpu_atomic_idle functions are defined as __weak
at the architecture level.
Change-Id: I980a161d0009f3f404ad22b226a6229fbb492389
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-11 00:24:30 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Save thread stack pointer on interrupt stack
|
|
|
|
* In RISC-V, stack pointer needs to be 16-byte aligned
|
|
|
|
*/
|
|
|
|
addi sp, sp, -16
|
2022-02-22 14:09:55 -05:00
|
|
|
sr t0, 0(sp)
|
arch: added support for the riscv32 architecture
RISC-V is an open-source instruction set architecture.
Added support for the 32bit version of RISC-V to Zephyr.
1) exceptions/interrupts/faults are handled at the architecture
level via the __irq_wrapper handler. Context saving/restoring
of registers can be handled at both architecture and SOC levels.
If SOC-specific registers need to be saved, SOC level needs to
provide __soc_save_context and __soc_restore_context functions
that shall be accounted by the architecture level, when
corresponding config variable RISCV_SOC_CONTEXT_SAVE is set.
2) As RISC-V architecture does not provide a clear ISA specification
about interrupt handling, each RISC-V SOC handles it in its own
way. Hence, at the architecture level, the __irq_wrapper handler
expects the following functions to be provided by the SOC level:
__soc_is_irq: to check if the exception is the result of an
interrupt or not.
__soc_handle_irq: handle pending IRQ at SOC level (ex: clear
pending IRQ in SOC-specific IRQ register)
3) Thread/task scheduling, as well as IRQ offloading are handled via
the RISC-V system call ("ecall"), which is also handled via the
__irq_wrapper handler. The _Swap asm function just calls "ecall"
to generate an exception.
4) As there is no conventional way of handling CPU power save in
RISC-V, the default nano_cpu_idle and nano_cpu_atomic_idle
functions just unlock interrupts and return to the caller, without
issuing any CPU power saving instruction. Nonetheless, to allow
SOC-level to implement proper CPU power save, nano_cpu_idle and
nano_cpu_atomic_idle functions are defined as __weak
at the architecture level.
Change-Id: I980a161d0009f3f404ad22b226a6229fbb492389
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-11 00:24:30 +01:00
|
|
|
|
|
|
|
on_irq_stack:
|
|
|
|
|
2020-01-28 16:44:59 +08:00
|
|
|
#ifdef CONFIG_TRACING_ISR
|
2019-09-19 09:25:19 +02:00
|
|
|
call sys_trace_isr_enter
|
arch: added support for the riscv32 architecture
RISC-V is an open-source instruction set architecture.
Added support for the 32bit version of RISC-V to Zephyr.
1) exceptions/interrupts/faults are handled at the architecture
level via the __irq_wrapper handler. Context saving/restoring
of registers can be handled at both architecture and SOC levels.
If SOC-specific registers need to be saved, SOC level needs to
provide __soc_save_context and __soc_restore_context functions
that shall be accounted by the architecture level, when
corresponding config variable RISCV_SOC_CONTEXT_SAVE is set.
2) As RISC-V architecture does not provide a clear ISA specification
about interrupt handling, each RISC-V SOC handles it in its own
way. Hence, at the architecture level, the __irq_wrapper handler
expects the following functions to be provided by the SOC level:
__soc_is_irq: to check if the exception is the result of an
interrupt or not.
__soc_handle_irq: handle pending IRQ at SOC level (ex: clear
pending IRQ in SOC-specific IRQ register)
3) Thread/task scheduling, as well as IRQ offloading are handled via
the RISC-V system call ("ecall"), which is also handled via the
__irq_wrapper handler. The _Swap asm function just calls "ecall"
to generate an exception.
4) As there is no conventional way of handling CPU power save in
RISC-V, the default nano_cpu_idle and nano_cpu_atomic_idle
functions just unlock interrupts and return to the caller, without
issuing any CPU power saving instruction. Nonetheless, to allow
SOC-level to implement proper CPU power save, nano_cpu_idle and
nano_cpu_atomic_idle functions are defined as __weak
at the architecture level.
Change-Id: I980a161d0009f3f404ad22b226a6229fbb492389
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-11 00:24:30 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Get IRQ causing interrupt */
|
|
|
|
csrr a0, mcause
|
2017-02-13 01:17:01 +01:00
|
|
|
li t0, SOC_MCAUSE_EXP_MASK
|
arch: added support for the riscv32 architecture
RISC-V is an open-source instruction set architecture.
Added support for the 32bit version of RISC-V to Zephyr.
1) exceptions/interrupts/faults are handled at the architecture
level via the __irq_wrapper handler. Context saving/restoring
of registers can be handled at both architecture and SOC levels.
If SOC-specific registers need to be saved, SOC level needs to
provide __soc_save_context and __soc_restore_context functions
that shall be accounted by the architecture level, when
corresponding config variable RISCV_SOC_CONTEXT_SAVE is set.
2) As RISC-V architecture does not provide a clear ISA specification
about interrupt handling, each RISC-V SOC handles it in its own
way. Hence, at the architecture level, the __irq_wrapper handler
expects the following functions to be provided by the SOC level:
__soc_is_irq: to check if the exception is the result of an
interrupt or not.
__soc_handle_irq: handle pending IRQ at SOC level (ex: clear
pending IRQ in SOC-specific IRQ register)
3) Thread/task scheduling, as well as IRQ offloading are handled via
the RISC-V system call ("ecall"), which is also handled via the
__irq_wrapper handler. The _Swap asm function just calls "ecall"
to generate an exception.
4) As there is no conventional way of handling CPU power save in
RISC-V, the default nano_cpu_idle and nano_cpu_atomic_idle
functions just unlock interrupts and return to the caller, without
issuing any CPU power saving instruction. Nonetheless, to allow
SOC-level to implement proper CPU power save, nano_cpu_idle and
nano_cpu_atomic_idle functions are defined as __weak
at the architecture level.
Change-Id: I980a161d0009f3f404ad22b226a6229fbb492389
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-11 00:24:30 +01:00
|
|
|
and a0, a0, t0
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear pending IRQ generating the interrupt at SOC level
|
|
|
|
* Pass IRQ number to __soc_handle_irq via register a0
|
|
|
|
*/
|
|
|
|
jal ra, __soc_handle_irq
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Call corresponding registered function in _sw_isr_table.
|
2019-07-24 16:21:58 -04:00
|
|
|
* (table is 2-word wide, we should shift index accordingly)
|
arch: added support for the riscv32 architecture
RISC-V is an open-source instruction set architecture.
Added support for the 32bit version of RISC-V to Zephyr.
1) exceptions/interrupts/faults are handled at the architecture
level via the __irq_wrapper handler. Context saving/restoring
of registers can be handled at both architecture and SOC levels.
If SOC-specific registers need to be saved, SOC level needs to
provide __soc_save_context and __soc_restore_context functions
that shall be accounted by the architecture level, when
corresponding config variable RISCV_SOC_CONTEXT_SAVE is set.
2) As RISC-V architecture does not provide a clear ISA specification
about interrupt handling, each RISC-V SOC handles it in its own
way. Hence, at the architecture level, the __irq_wrapper handler
expects the following functions to be provided by the SOC level:
__soc_is_irq: to check if the exception is the result of an
interrupt or not.
__soc_handle_irq: handle pending IRQ at SOC level (ex: clear
pending IRQ in SOC-specific IRQ register)
3) Thread/task scheduling, as well as IRQ offloading are handled via
the RISC-V system call ("ecall"), which is also handled via the
__irq_wrapper handler. The _Swap asm function just calls "ecall"
to generate an exception.
4) As there is no conventional way of handling CPU power save in
RISC-V, the default nano_cpu_idle and nano_cpu_atomic_idle
functions just unlock interrupts and return to the caller, without
issuing any CPU power saving instruction. Nonetheless, to allow
SOC-level to implement proper CPU power save, nano_cpu_idle and
nano_cpu_atomic_idle functions are defined as __weak
at the architecture level.
Change-Id: I980a161d0009f3f404ad22b226a6229fbb492389
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-11 00:24:30 +01:00
|
|
|
*/
|
|
|
|
la t0, _sw_isr_table
|
2019-07-24 16:21:58 -04:00
|
|
|
slli a0, a0, (RV_REGSHIFT + 1)
|
arch: added support for the riscv32 architecture
RISC-V is an open-source instruction set architecture.
Added support for the 32bit version of RISC-V to Zephyr.
1) exceptions/interrupts/faults are handled at the architecture
level via the __irq_wrapper handler. Context saving/restoring
of registers can be handled at both architecture and SOC levels.
If SOC-specific registers need to be saved, SOC level needs to
provide __soc_save_context and __soc_restore_context functions
that shall be accounted by the architecture level, when
corresponding config variable RISCV_SOC_CONTEXT_SAVE is set.
2) As RISC-V architecture does not provide a clear ISA specification
about interrupt handling, each RISC-V SOC handles it in its own
way. Hence, at the architecture level, the __irq_wrapper handler
expects the following functions to be provided by the SOC level:
__soc_is_irq: to check if the exception is the result of an
interrupt or not.
__soc_handle_irq: handle pending IRQ at SOC level (ex: clear
pending IRQ in SOC-specific IRQ register)
3) Thread/task scheduling, as well as IRQ offloading are handled via
the RISC-V system call ("ecall"), which is also handled via the
__irq_wrapper handler. The _Swap asm function just calls "ecall"
to generate an exception.
4) As there is no conventional way of handling CPU power save in
RISC-V, the default nano_cpu_idle and nano_cpu_atomic_idle
functions just unlock interrupts and return to the caller, without
issuing any CPU power saving instruction. Nonetheless, to allow
SOC-level to implement proper CPU power save, nano_cpu_idle and
nano_cpu_atomic_idle functions are defined as __weak
at the architecture level.
Change-Id: I980a161d0009f3f404ad22b226a6229fbb492389
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-11 00:24:30 +01:00
|
|
|
add t0, t0, a0
|
|
|
|
|
|
|
|
/* Load argument in a0 register */
|
2022-02-22 14:09:55 -05:00
|
|
|
lr a0, 0(t0)
|
arch: added support for the riscv32 architecture
RISC-V is an open-source instruction set architecture.
Added support for the 32bit version of RISC-V to Zephyr.
1) exceptions/interrupts/faults are handled at the architecture
level via the __irq_wrapper handler. Context saving/restoring
of registers can be handled at both architecture and SOC levels.
If SOC-specific registers need to be saved, SOC level needs to
provide __soc_save_context and __soc_restore_context functions
that shall be accounted by the architecture level, when
corresponding config variable RISCV_SOC_CONTEXT_SAVE is set.
2) As RISC-V architecture does not provide a clear ISA specification
about interrupt handling, each RISC-V SOC handles it in its own
way. Hence, at the architecture level, the __irq_wrapper handler
expects the following functions to be provided by the SOC level:
__soc_is_irq: to check if the exception is the result of an
interrupt or not.
__soc_handle_irq: handle pending IRQ at SOC level (ex: clear
pending IRQ in SOC-specific IRQ register)
3) Thread/task scheduling, as well as IRQ offloading are handled via
the RISC-V system call ("ecall"), which is also handled via the
__irq_wrapper handler. The _Swap asm function just calls "ecall"
to generate an exception.
4) As there is no conventional way of handling CPU power save in
RISC-V, the default nano_cpu_idle and nano_cpu_atomic_idle
functions just unlock interrupts and return to the caller, without
issuing any CPU power saving instruction. Nonetheless, to allow
SOC-level to implement proper CPU power save, nano_cpu_idle and
nano_cpu_atomic_idle functions are defined as __weak
at the architecture level.
Change-Id: I980a161d0009f3f404ad22b226a6229fbb492389
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-11 00:24:30 +01:00
|
|
|
|
|
|
|
/* Load ISR function address in register t1 */
|
2022-02-22 14:09:55 -05:00
|
|
|
lr t1, RV_REGSIZE(t0)
|
arch: added support for the riscv32 architecture
RISC-V is an open-source instruction set architecture.
Added support for the 32bit version of RISC-V to Zephyr.
1) exceptions/interrupts/faults are handled at the architecture
level via the __irq_wrapper handler. Context saving/restoring
of registers can be handled at both architecture and SOC levels.
If SOC-specific registers need to be saved, SOC level needs to
provide __soc_save_context and __soc_restore_context functions
that shall be accounted by the architecture level, when
corresponding config variable RISCV_SOC_CONTEXT_SAVE is set.
2) As RISC-V architecture does not provide a clear ISA specification
about interrupt handling, each RISC-V SOC handles it in its own
way. Hence, at the architecture level, the __irq_wrapper handler
expects the following functions to be provided by the SOC level:
__soc_is_irq: to check if the exception is the result of an
interrupt or not.
__soc_handle_irq: handle pending IRQ at SOC level (ex: clear
pending IRQ in SOC-specific IRQ register)
3) Thread/task scheduling, as well as IRQ offloading are handled via
the RISC-V system call ("ecall"), which is also handled via the
__irq_wrapper handler. The _Swap asm function just calls "ecall"
to generate an exception.
4) As there is no conventional way of handling CPU power save in
RISC-V, the default nano_cpu_idle and nano_cpu_atomic_idle
functions just unlock interrupts and return to the caller, without
issuing any CPU power saving instruction. Nonetheless, to allow
SOC-level to implement proper CPU power save, nano_cpu_idle and
nano_cpu_atomic_idle functions are defined as __weak
at the architecture level.
Change-Id: I980a161d0009f3f404ad22b226a6229fbb492389
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-11 00:24:30 +01:00
|
|
|
|
|
|
|
/* Call ISR function */
|
2021-12-14 22:46:42 +08:00
|
|
|
jalr ra, t1, 0
|
arch: added support for the riscv32 architecture
RISC-V is an open-source instruction set architecture.
Added support for the 32bit version of RISC-V to Zephyr.
1) exceptions/interrupts/faults are handled at the architecture
level via the __irq_wrapper handler. Context saving/restoring
of registers can be handled at both architecture and SOC levels.
If SOC-specific registers need to be saved, SOC level needs to
provide __soc_save_context and __soc_restore_context functions
that shall be accounted by the architecture level, when
corresponding config variable RISCV_SOC_CONTEXT_SAVE is set.
2) As RISC-V architecture does not provide a clear ISA specification
about interrupt handling, each RISC-V SOC handles it in its own
way. Hence, at the architecture level, the __irq_wrapper handler
expects the following functions to be provided by the SOC level:
__soc_is_irq: to check if the exception is the result of an
interrupt or not.
__soc_handle_irq: handle pending IRQ at SOC level (ex: clear
pending IRQ in SOC-specific IRQ register)
3) Thread/task scheduling, as well as IRQ offloading are handled via
the RISC-V system call ("ecall"), which is also handled via the
__irq_wrapper handler. The _Swap asm function just calls "ecall"
to generate an exception.
4) As there is no conventional way of handling CPU power save in
RISC-V, the default nano_cpu_idle and nano_cpu_atomic_idle
functions just unlock interrupts and return to the caller, without
issuing any CPU power saving instruction. Nonetheless, to allow
SOC-level to implement proper CPU power save, nano_cpu_idle and
nano_cpu_atomic_idle functions are defined as __weak
at the architecture level.
Change-Id: I980a161d0009f3f404ad22b226a6229fbb492389
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-11 00:24:30 +01:00
|
|
|
|
2022-03-07 13:24:38 -05:00
|
|
|
irq_done:
|
2022-03-09 17:21:27 -05:00
|
|
|
/* Decrement _current_cpu->nested */
|
|
|
|
lw t2, ___cpu_t_nested_OFFSET(s0)
|
arch: added support for the riscv32 architecture
RISC-V is an open-source instruction set architecture.
Added support for the 32bit version of RISC-V to Zephyr.
1) exceptions/interrupts/faults are handled at the architecture
level via the __irq_wrapper handler. Context saving/restoring
of registers can be handled at both architecture and SOC levels.
If SOC-specific registers need to be saved, SOC level needs to
provide __soc_save_context and __soc_restore_context functions
that shall be accounted by the architecture level, when
corresponding config variable RISCV_SOC_CONTEXT_SAVE is set.
2) As RISC-V architecture does not provide a clear ISA specification
about interrupt handling, each RISC-V SOC handles it in its own
way. Hence, at the architecture level, the __irq_wrapper handler
expects the following functions to be provided by the SOC level:
__soc_is_irq: to check if the exception is the result of an
interrupt or not.
__soc_handle_irq: handle pending IRQ at SOC level (ex: clear
pending IRQ in SOC-specific IRQ register)
3) Thread/task scheduling, as well as IRQ offloading are handled via
the RISC-V system call ("ecall"), which is also handled via the
__irq_wrapper handler. The _Swap asm function just calls "ecall"
to generate an exception.
4) As there is no conventional way of handling CPU power save in
RISC-V, the default nano_cpu_idle and nano_cpu_atomic_idle
functions just unlock interrupts and return to the caller, without
issuing any CPU power saving instruction. Nonetheless, to allow
SOC-level to implement proper CPU power save, nano_cpu_idle and
nano_cpu_atomic_idle functions are defined as __weak
at the architecture level.
Change-Id: I980a161d0009f3f404ad22b226a6229fbb492389
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-11 00:24:30 +01:00
|
|
|
addi t2, t2, -1
|
2022-03-09 17:21:27 -05:00
|
|
|
sw t2, ___cpu_t_nested_OFFSET(s0)
|
2022-02-24 22:30:03 -05:00
|
|
|
bnez t2, no_reschedule
|
arch: added support for the riscv32 architecture
RISC-V is an open-source instruction set architecture.
Added support for the 32bit version of RISC-V to Zephyr.
1) exceptions/interrupts/faults are handled at the architecture
level via the __irq_wrapper handler. Context saving/restoring
of registers can be handled at both architecture and SOC levels.
If SOC-specific registers need to be saved, SOC level needs to
provide __soc_save_context and __soc_restore_context functions
that shall be accounted by the architecture level, when
corresponding config variable RISCV_SOC_CONTEXT_SAVE is set.
2) As RISC-V architecture does not provide a clear ISA specification
about interrupt handling, each RISC-V SOC handles it in its own
way. Hence, at the architecture level, the __irq_wrapper handler
expects the following functions to be provided by the SOC level:
__soc_is_irq: to check if the exception is the result of an
interrupt or not.
__soc_handle_irq: handle pending IRQ at SOC level (ex: clear
pending IRQ in SOC-specific IRQ register)
3) Thread/task scheduling, as well as IRQ offloading are handled via
the RISC-V system call ("ecall"), which is also handled via the
__irq_wrapper handler. The _Swap asm function just calls "ecall"
to generate an exception.
4) As there is no conventional way of handling CPU power save in
RISC-V, the default nano_cpu_idle and nano_cpu_atomic_idle
functions just unlock interrupts and return to the caller, without
issuing any CPU power saving instruction. Nonetheless, to allow
SOC-level to implement proper CPU power save, nano_cpu_idle and
nano_cpu_atomic_idle functions are defined as __weak
at the architecture level.
Change-Id: I980a161d0009f3f404ad22b226a6229fbb492389
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-11 00:24:30 +01:00
|
|
|
|
2022-02-24 22:30:03 -05:00
|
|
|
/* nested count is back to 0: Return to thread stack */
|
|
|
|
lr sp, 0(sp)
|
2017-06-07 09:33:16 -07:00
|
|
|
|
2017-05-11 13:29:15 -07:00
|
|
|
#ifdef CONFIG_STACK_SENTINEL
|
2019-03-08 14:19:05 -07:00
|
|
|
call z_check_stack_sentinel
|
2017-05-11 13:29:15 -07:00
|
|
|
#endif
|
|
|
|
|
2022-02-24 22:30:03 -05:00
|
|
|
reschedule:
|
2022-03-09 17:46:30 -05:00
|
|
|
|
2022-03-09 17:21:27 -05:00
|
|
|
/* Get pointer to current thread on this CPU */
|
|
|
|
lr a1, ___cpu_t_current_OFFSET(s0)
|
2020-07-21 16:00:39 +02:00
|
|
|
|
arch: added support for the riscv32 architecture
RISC-V is an open-source instruction set architecture.
Added support for the 32bit version of RISC-V to Zephyr.
1) exceptions/interrupts/faults are handled at the architecture
level via the __irq_wrapper handler. Context saving/restoring
of registers can be handled at both architecture and SOC levels.
If SOC-specific registers need to be saved, SOC level needs to
provide __soc_save_context and __soc_restore_context functions
that shall be accounted by the architecture level, when
corresponding config variable RISCV_SOC_CONTEXT_SAVE is set.
2) As RISC-V architecture does not provide a clear ISA specification
about interrupt handling, each RISC-V SOC handles it in its own
way. Hence, at the architecture level, the __irq_wrapper handler
expects the following functions to be provided by the SOC level:
__soc_is_irq: to check if the exception is the result of an
interrupt or not.
__soc_handle_irq: handle pending IRQ at SOC level (ex: clear
pending IRQ in SOC-specific IRQ register)
3) Thread/task scheduling, as well as IRQ offloading are handled via
the RISC-V system call ("ecall"), which is also handled via the
__irq_wrapper handler. The _Swap asm function just calls "ecall"
to generate an exception.
4) As there is no conventional way of handling CPU power save in
RISC-V, the default nano_cpu_idle and nano_cpu_atomic_idle
functions just unlock interrupts and return to the caller, without
issuing any CPU power saving instruction. Nonetheless, to allow
SOC-level to implement proper CPU power save, nano_cpu_idle and
nano_cpu_atomic_idle functions are defined as __weak
at the architecture level.
Change-Id: I980a161d0009f3f404ad22b226a6229fbb492389
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-11 00:24:30 +01:00
|
|
|
/*
|
2022-03-07 17:01:36 -05:00
|
|
|
* Get next thread to schedule with z_get_next_switch_handle().
|
|
|
|
* We pass it a NULL as we didn't save the whole thread context yet.
|
|
|
|
* If no scheduling is necessary then NULL will be returned.
|
arch: added support for the riscv32 architecture
RISC-V is an open-source instruction set architecture.
Added support for the 32bit version of RISC-V to Zephyr.
1) exceptions/interrupts/faults are handled at the architecture
level via the __irq_wrapper handler. Context saving/restoring
of registers can be handled at both architecture and SOC levels.
If SOC-specific registers need to be saved, SOC level needs to
provide __soc_save_context and __soc_restore_context functions
that shall be accounted by the architecture level, when
corresponding config variable RISCV_SOC_CONTEXT_SAVE is set.
2) As RISC-V architecture does not provide a clear ISA specification
about interrupt handling, each RISC-V SOC handles it in its own
way. Hence, at the architecture level, the __irq_wrapper handler
expects the following functions to be provided by the SOC level:
__soc_is_irq: to check if the exception is the result of an
interrupt or not.
__soc_handle_irq: handle pending IRQ at SOC level (ex: clear
pending IRQ in SOC-specific IRQ register)
3) Thread/task scheduling, as well as IRQ offloading are handled via
the RISC-V system call ("ecall"), which is also handled via the
__irq_wrapper handler. The _Swap asm function just calls "ecall"
to generate an exception.
4) As there is no conventional way of handling CPU power save in
RISC-V, the default nano_cpu_idle and nano_cpu_atomic_idle
functions just unlock interrupts and return to the caller, without
issuing any CPU power saving instruction. Nonetheless, to allow
SOC-level to implement proper CPU power save, nano_cpu_idle and
nano_cpu_atomic_idle functions are defined as __weak
at the architecture level.
Change-Id: I980a161d0009f3f404ad22b226a6229fbb492389
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-11 00:24:30 +01:00
|
|
|
*/
|
2022-03-07 17:01:36 -05:00
|
|
|
addi sp, sp, -16
|
|
|
|
sr a1, 0(sp)
|
|
|
|
mv a0, zero
|
|
|
|
call z_get_next_switch_handle
|
|
|
|
lr a1, 0(sp)
|
|
|
|
addi sp, sp, 16
|
|
|
|
beqz a0, no_reschedule
|
2020-03-11 18:15:29 -07:00
|
|
|
|
|
|
|
/*
|
2022-03-07 17:01:36 -05:00
|
|
|
* Perform context switch:
|
|
|
|
* a0 = new thread
|
|
|
|
* a1 = old thread
|
2020-03-11 18:15:29 -07:00
|
|
|
*/
|
2022-03-07 17:01:36 -05:00
|
|
|
call z_riscv_switch
|
2018-07-23 15:54:22 +05:30
|
|
|
|
2022-03-07 17:01:36 -05:00
|
|
|
z_riscv_thread_start:
|
2022-03-09 17:21:27 -05:00
|
|
|
might_have_rescheduled:
|
2022-03-09 23:47:38 -05:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
/* reload s0 with &_current_cpu as it might have changed */
|
|
|
|
GET_CURRENT_CPU(s0, t0)
|
|
|
|
#endif
|
2022-03-09 17:21:27 -05:00
|
|
|
|
2022-02-24 22:30:03 -05:00
|
|
|
no_reschedule:
|
|
|
|
|
2020-07-21 16:00:39 +02:00
|
|
|
#ifdef CONFIG_RISCV_SOC_CONTEXT_SAVE
|
|
|
|
/* Restore context at SOC level */
|
|
|
|
addi a0, sp, __z_arch_esf_t_soc_context_OFFSET
|
|
|
|
jal ra, __soc_restore_context
|
|
|
|
#endif /* CONFIG_RISCV_SOC_CONTEXT_SAVE */
|
|
|
|
|
2017-06-29 22:45:55 +02:00
|
|
|
/* Restore MEPC register */
|
2022-02-22 14:09:55 -05:00
|
|
|
lr t0, __z_arch_esf_t_mepc_OFFSET(sp)
|
2017-06-29 22:45:55 +02:00
|
|
|
csrw mepc, t0
|
|
|
|
|
2022-02-24 22:30:03 -05:00
|
|
|
/* Restore MSTATUS register */
|
|
|
|
lr t4, __z_arch_esf_t_mstatus_OFFSET(sp)
|
2022-03-07 17:31:13 -05:00
|
|
|
csrrw t5, mstatus, t4
|
|
|
|
|
|
|
|
#if defined(CONFIG_FPU) && defined(CONFIG_FPU_SHARING)
|
|
|
|
/*
|
|
|
|
* Determine if we need to restore FP regs based on the previous
|
|
|
|
* (before the csr above) mstatus value available in t5.
|
|
|
|
*/
|
|
|
|
li t1, MSTATUS_FS_INIT
|
|
|
|
and t0, t5, t1
|
|
|
|
beqz t0, no_fp
|
|
|
|
|
|
|
|
/* make sure FP is enabled in the restored mstatus */
|
|
|
|
csrs mstatus, t1
|
|
|
|
DO_FP_CALLER_SAVED(flr, sp)
|
|
|
|
j 1f
|
|
|
|
|
|
|
|
no_fp: /* make sure this is reflected in the restored mstatus */
|
|
|
|
csrc mstatus, t1
|
|
|
|
1:
|
|
|
|
#endif /* CONFIG_FPU && CONFIG_FPU_SHARING */
|
2017-06-29 22:45:55 +02:00
|
|
|
|
2022-02-24 22:30:03 -05:00
|
|
|
#ifdef CONFIG_USERSPACE
|
2020-04-14 14:56:12 -07:00
|
|
|
/*
|
2022-02-24 22:30:03 -05:00
|
|
|
* Check if we are returning to user mode. If so then we must
|
|
|
|
* set is_user_mode to true and load the scratch register with
|
|
|
|
* the stack pointer to be used with the next exception to come.
|
2020-04-14 14:56:12 -07:00
|
|
|
*/
|
2022-02-24 22:30:03 -05:00
|
|
|
li t1, MSTATUS_MPP
|
|
|
|
and t0, t4, t1
|
|
|
|
bnez t0, 1f
|
2020-04-14 14:56:12 -07:00
|
|
|
|
2022-02-24 22:30:03 -05:00
|
|
|
/* Set user mode variable */
|
|
|
|
li t0, 1
|
|
|
|
la t1, is_user_mode
|
|
|
|
sw t0, 0(t1)
|
|
|
|
|
|
|
|
/* load scratch reg with stack pointer for next exception entry */
|
|
|
|
add t0, sp, __z_arch_esf_t_SIZEOF
|
|
|
|
csrw mscratch, t0
|
|
|
|
1:
|
|
|
|
#endif
|
2020-04-14 14:56:12 -07:00
|
|
|
|
2022-03-09 17:21:27 -05:00
|
|
|
/* Restore s0 (it is no longer ours) */
|
|
|
|
lr s0, __z_arch_esf_t_s0_OFFSET(sp)
|
|
|
|
|
arch: added support for the riscv32 architecture
RISC-V is an open-source instruction set architecture.
Added support for the 32bit version of RISC-V to Zephyr.
1) exceptions/interrupts/faults are handled at the architecture
level via the __irq_wrapper handler. Context saving/restoring
of registers can be handled at both architecture and SOC levels.
If SOC-specific registers need to be saved, SOC level needs to
provide __soc_save_context and __soc_restore_context functions
that shall be accounted by the architecture level, when
corresponding config variable RISCV_SOC_CONTEXT_SAVE is set.
2) As RISC-V architecture does not provide a clear ISA specification
about interrupt handling, each RISC-V SOC handles it in its own
way. Hence, at the architecture level, the __irq_wrapper handler
expects the following functions to be provided by the SOC level:
__soc_is_irq: to check if the exception is the result of an
interrupt or not.
__soc_handle_irq: handle pending IRQ at SOC level (ex: clear
pending IRQ in SOC-specific IRQ register)
3) Thread/task scheduling, as well as IRQ offloading are handled via
the RISC-V system call ("ecall"), which is also handled via the
__irq_wrapper handler. The _Swap asm function just calls "ecall"
to generate an exception.
4) As there is no conventional way of handling CPU power save in
RISC-V, the default nano_cpu_idle and nano_cpu_atomic_idle
functions just unlock interrupts and return to the caller, without
issuing any CPU power saving instruction. Nonetheless, to allow
SOC-level to implement proper CPU power save, nano_cpu_idle and
nano_cpu_atomic_idle functions are defined as __weak
at the architecture level.
Change-Id: I980a161d0009f3f404ad22b226a6229fbb492389
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-11 00:24:30 +01:00
|
|
|
/* Restore caller-saved registers from thread stack */
|
2022-02-24 22:30:03 -05:00
|
|
|
DO_CALLER_SAVED(lr)
|
|
|
|
|
|
|
|
#ifdef CONFIG_USERSPACE
|
|
|
|
/* retrieve saved stack pointer */
|
|
|
|
lr sp, __z_arch_esf_t_sp_OFFSET(sp)
|
|
|
|
#else
|
|
|
|
/* remove esf from the stack */
|
|
|
|
addi sp, sp, __z_arch_esf_t_SIZEOF
|
|
|
|
#endif
|
arch: added support for the riscv32 architecture
RISC-V is an open-source instruction set architecture.
Added support for the 32bit version of RISC-V to Zephyr.
1) exceptions/interrupts/faults are handled at the architecture
level via the __irq_wrapper handler. Context saving/restoring
of registers can be handled at both architecture and SOC levels.
If SOC-specific registers need to be saved, SOC level needs to
provide __soc_save_context and __soc_restore_context functions
that shall be accounted by the architecture level, when
corresponding config variable RISCV_SOC_CONTEXT_SAVE is set.
2) As RISC-V architecture does not provide a clear ISA specification
about interrupt handling, each RISC-V SOC handles it in its own
way. Hence, at the architecture level, the __irq_wrapper handler
expects the following functions to be provided by the SOC level:
__soc_is_irq: to check if the exception is the result of an
interrupt or not.
__soc_handle_irq: handle pending IRQ at SOC level (ex: clear
pending IRQ in SOC-specific IRQ register)
3) Thread/task scheduling, as well as IRQ offloading are handled via
the RISC-V system call ("ecall"), which is also handled via the
__irq_wrapper handler. The _Swap asm function just calls "ecall"
to generate an exception.
4) As there is no conventional way of handling CPU power save in
RISC-V, the default nano_cpu_idle and nano_cpu_atomic_idle
functions just unlock interrupts and return to the caller, without
issuing any CPU power saving instruction. Nonetheless, to allow
SOC-level to implement proper CPU power save, nano_cpu_idle and
nano_cpu_atomic_idle functions are defined as __weak
at the architecture level.
Change-Id: I980a161d0009f3f404ad22b226a6229fbb492389
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-11 00:24:30 +01:00
|
|
|
|
|
|
|
/* Call SOC_ERET to exit ISR */
|
|
|
|
SOC_ERET
|