Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
143 commits
Select commit Hold shift + click to select a range
65fac65
include: sbi_scratch: fix typo sbi_scratch -> HART id
Jan 7, 2026
74434f2
lib: sbi: Fix behavior on platform without HART protection
michalsimek Jan 7, 2026
9ffacc8
lib: utils/hsm: factor out ATCSMU code into an HSM driver
ben717-linux Dec 29, 2025
85bff9c
platform: generic/andes: add CSR save and restore functions for AE350…
ben717-linux Dec 29, 2025
6d26b43
lib: utils/cache: add cache enable function
ben717-linux Dec 29, 2025
82b0961
lib: utils/cache: add Andes last level cache controller
ben717-linux Dec 29, 2025
b27ecec
lib: utils/suspend: add Andes ATCSMU suspend driver
ben717-linux Dec 29, 2025
ecdb6c9
firmware: Initialize stack guard via Zkr
wxjstz Jan 4, 2026
b07e449
lib: utils/serial: Add support for Altera JTAG UART
Icenowy Jan 4, 2026
a95c36f
lib: sbi_pmu: Fix multiple FW counter start operations with custom PM…
jamestiotio Jan 16, 2026
9656943
lib: sbi_pmu: Add FW counter index validation when reading high bits …
jamestiotio Jan 25, 2026
e58d528
lib: sbi: print hartid in hex
vlkondratiev Feb 23, 2026
ea45923
lib: sbi_hart_pmp: disable unconfigured PMP entries
vlkondratiev Feb 23, 2026
d2dd699
platform: generic: mips p8700: improve CM access tracing
vlkondratiev Feb 23, 2026
698ea04
platform: generic: mips p8700: reserve memory for M-mode peripherals
vlkondratiev Feb 23, 2026
6545b78
platform: generic: mips p8700: fix powering up other cluster
vlkondratiev Feb 23, 2026
52ac3de
platform: generic: mips p8700: faster core boot
vlkondratiev Feb 23, 2026
c69c159
platform: generic: mips p8700: use global CM addresses
vlkondratiev Feb 23, 2026
bc2722b
platform: generic: mips p8700: Add match data for CM info
benoitmonin Feb 23, 2026
fe82238
platform: generic: mips p8700: access CM registers via match data
vlkondratiev Feb 23, 2026
79dfc3a
platform: generic: mips: add P8700 based "eyeq7h" and "boston"
vlkondratiev Feb 23, 2026
26748d7
platform: generic: mips eyeq7h: power up clusters with OLB
vlkondratiev Feb 23, 2026
ee55329
platform: generic: mips eyeq7h: detect accelerators cluster presence
vlkondratiev Feb 23, 2026
8935f79
platform: generic: mips eyeq7h: deassert accelerator cluster resets
vlkondratiev Feb 23, 2026
df7bbe7
platform: generic: mips p8700: cache geometry detection
vlkondratiev Feb 23, 2026
bdec423
platform: generic: mips p8700: CPU clusters memranges
vlkondratiev Feb 23, 2026
76ecd8f
platform: generic: mips p8700: use SBI bitfield manipulator macros
vlkondratiev Feb 23, 2026
a3aeef7
platform: generic: mips p8700: synchronize hi-res timers
vlkondratiev Feb 23, 2026
2ca2e0c
platform: generic: mips eyeq7h: synchronize timers across clusters
vlkondratiev Feb 23, 2026
9169290
platform: generic: mips eyeq7h: fix NCORE registers access from clust…
vlkondratiev Feb 23, 2026
3b55e5c
platform: generic: mips p8700: dump MMIO regions
vlkondratiev Feb 23, 2026
331dae1
platform: generic: mips eyeq7h: prohibit accessing memory beyond DRAM
vlkondratiev Feb 23, 2026
f07be54
platform: generic: p8700: fix MIPS specific CSRs
vlkondratiev Feb 23, 2026
8d1c21b
platform: generic: eyeq7h: enable ECC on L1 cache
vlkondratiev Feb 23, 2026
3baca10
include: sbi: Fix illegal shift in sbi_domain.h
marcoos204 Feb 22, 2026
2727c43
lib: sbi: Fix undefined behavior in signed shifts in sbi_hart.c
marcoos204 Feb 23, 2026
4dc1b9f
lib: fdt_helper: Removed unnecessary dt parsing check
DiscreteVic Feb 19, 2026
ef1ee40
platform: generic: mips boston: update "compatible"
vlkondratiev Mar 1, 2026
b534800
lib: Use proper add opcode on RV32 with Zalrsc
martialonso Mar 1, 2026
6d5b2b9
lib: sbi: fix sse_event_inject() status setting
thecharlesjenkins Mar 2, 2026
51837c7
lib: sbi_irqchip: Use chip as variable name for irqchip device
avpatel Feb 13, 2026
2110aab
lib: sbi_irqchip: Rename irq_handle() callback to process_hwirqs()
avpatel Feb 13, 2026
6d68f3b
lib: utils/irqchip: Fix context_map init in irqchip_plic_update_conte…
avpatel Feb 13, 2026
5a300b3
lib: utils/irqchip: Add IDC to hartindex map in struct aplic_data
avpatel Feb 13, 2026
b55bb4c
lib: sbi_irqchip: Support irqchip device targetting subset of harts
avpatel Feb 13, 2026
e82d201
lib: utils/irqchip: Add unique_id to plic, aplic, and imsic data
avpatel Feb 13, 2026
e8ebd1f
lib: sbi_irqchip: Associate 32-bit unique ID for each irqchip device
avpatel Feb 13, 2026
0ab0c47
lib: sbi_irqchip: Allow registering interrupt handlers
avpatel Feb 13, 2026
4813a20
lib: sbi_init: Call hart init and timer init before platform early init
peterlin-sifive Feb 24, 2026
0402b8e
platform: sifive: Add initial support for SiFive development platform
peterlin-sifive Feb 24, 2026
9e14e03
sifive_dev_platform: Set default MMIO region when SmePMP is enabled
peterlin-sifive Feb 24, 2026
fdb78b0
lib: tests: Add test for string
cp0613 Mar 6, 2026
2bf0de8
lib: Fix sbi_strchr to correctly handle null terminator search
cp0613 Mar 6, 2026
0b041e5
lib: utils: Add MPXY client driver for RPMI MM service group
Feb 25, 2026
ff7d245
include: sbi_bitmap: add bitmap_empty() function
peterlin-sifive Mar 11, 2026
2257e99
lib: sbi_bitmap_test: add tests for bitmap_empty()
peterlin-sifive Mar 11, 2026
5d248a0
include: sbi_scratch: Add tmp1 scratch space for RNMI context saving
evvoevod May 7, 2026
b63606f
lib: sbi: Add Smrnmi extension macros for registers and bits
evvoevod May 7, 2026
00fec20
firmware: Add RNMI handler infrastructure
evvoevod May 7, 2026
882b8b0
lib: sbi: hart: Move device tree features detection before trap-based…
evvoevod May 7, 2026
0cfd6c0
lib: sbi: Move Zkr entropy initialization from fw_base.S to init_cold…
evvoevod May 7, 2026
2d211fe
lib: sbi: hart: Detect and enable Smrnmi before trap-based feature de…
evvoevod May 7, 2026
f34cf05
platform: Remove kendryte/k210 platform
avpatel Apr 9, 2026
d8c7dc9
include: sbi: Add sbi_scratch_hartindex() macro
avpatel Apr 25, 2026
357fae4
lib: sbi_timer: Introduce per-HART timer state
avpatel Apr 25, 2026
b7fa8a2
lib: sbi_timer: Add support for timer events
avpatel Apr 25, 2026
1932ee3
lib: sbi_timer: Introduce sbi_timer_compute_delta() and friends
avpatel Apr 25, 2026
6767861
platform: generic: Tenstorrent Atlantis support
npiggin Apr 24, 2026
ae8f28a
lib: utils: Fix LLVM compile error in MPXY client driver for RPMI MM
avpatel May 9, 2026
8cd279e
lib: fdt_domain: Default boot-hart to coldboot HART for multi-domain …
peterlin-sifive Mar 27, 2026
3d8f1f3
docs: platform: update qemu_virt.md
Mar 19, 2026
65bb705
lib/sbi_pmu: Don't fallback to fixed counters when sscofpmf && !smcnt…
mpe Mar 24, 2026
8536a35
lib: utils/regmap: Fix reg_stride calculation in syscon regmap
dgporras Apr 3, 2026
5f13f9e
lib: sbi: Fix hw a/d updating defaults
jones-drew Apr 1, 2026
b10e18e
lib: utils/i2c: add minimal SpacemiT I2C driver
aurel32 Apr 19, 2026
d9637d0
lib: utils/reset: add SpacemiT P1 PMIC support
aurel32 Apr 19, 2026
9595829
lib: sbi_domain: reject overflowing address range in check_addr_range()
takumihara Mar 19, 2026
0d81a78
lib: sbi_irqchip: Check full range for existing handlers in sbi_irqch…
avpatel Apr 23, 2026
255df5d
lib: sbi_irqchip: Keep the handler list in sorted order for irqchip
avpatel Apr 23, 2026
adb4caf
lib: sbi_irqchip: Allow interrupt client to specify line sensing
avpatel Apr 23, 2026
d861447
lib: sbi_irqchip: Allow marking hardware interrupts as reserved
avpatel Apr 23, 2026
c0d0dd0
lib: sbi_irqchip: Allow setting hardware interrupt affinity
avpatel Apr 23, 2026
79e63bc
lib: sbi_irqchip: Add support for registering MSI handlers
avpatel Apr 23, 2026
2146115
lib: sbi: Add RISC-V vector context save/restore support
dave-patel-riscstar May 18, 2026
718e1d1
lib: sbi: Add floating-point context save/restore support.
dave-patel-riscstar May 18, 2026
22d7e99
lib: sbi: domain FP/Vector context support for context switch
dave-patel-riscstar May 18, 2026
f36acae
lib: utils: fdt_domain: add root-regions-inheritance policy
peterlin-sifive May 16, 2026
e92c8fd
sbi: mpxy: define INVALID_ADDR using unsigned long width
hschauhan May 21, 2026
547a5bb
lib: utils/reset: Remove unused match data
SiFiveHolland May 13, 2026
243035c
include: mailbox: rpmi_msgprot: Add RPMI performance domain flag defines
dgporras Mar 28, 2026
73bc794
lib: sbi_domain_context: Flush TLB after SATP mode switch
ISCAS-Vulab Apr 29, 2026
8ae3b09
lib: sbi: Introduce pmp_t type
npiggin Apr 30, 2026
c93a89f
lib: sbi: split PMP encoding and CSR access
npiggin Apr 30, 2026
e9797b5
lib: sbi: Move RISC-V PMP encoding functions to sbi_pmp.c
npiggin Apr 30, 2026
8f1a616
lib: sbi: Add PMP CSR read and write accessors
npiggin Apr 30, 2026
f7738cc
lib: sbi: Add sbi_pmp_is_enabled() helper
npiggin Apr 30, 2026
63350c6
lib: sbi: Add hart_ prefix to PMP functions
npiggin Apr 30, 2026
a59c8fb
lib: sbi: Move hart PMP functions to sbi_hart_pmp.c
npiggin Apr 30, 2026
8570b93
lib: sbi_irqchip: Allow irqchip drivers advertise capabilities
avpatel Jun 8, 2026
d0ae6a9
lib: sbi_mpxy: Enable MPXY channel MSI availability determination
dgporras Jun 8, 2026
59fe435
include: mailbox: Update RPMI notification structs and add performanc…
dgporras Jun 8, 2026
b6e7c84
include: sbi: Add SBI MPXY notification related defines
dgporras Jun 8, 2026
895201c
platform: Fix payload alignment when FW_TEXT_START isn't 2M/4M aligned
May 8, 2026
c175c97
lib: sbi: Fix LLVM compile error observed in sbi_mpxy.c
avpatel Jun 12, 2026
7bdcf55
lib: sbi: add UBSan support
marcoos204 May 15, 2026
a62385a
lib: sbi_hart: No need to clear features in hart_detect_features()
avpatel May 21, 2026
ecc92e8
platform: generic: Optimize extensions_init() to parse ISA extensions…
avpatel May 21, 2026
b508e6e
lib: sbi: Apply budget restriction when polling Zkr CSR state transition
evvoevod May 19, 2026
3d29f38
lib: sbi_pmu: Honor CLEAR_VALUE/AUTO_START for all hardware event types
dgporras May 22, 2026
9c97675
lib: sbi: Drop fw_rw_offset alignment requirement for single fw region
npiggin May 22, 2026
dec9141
lib: utils/reset: Add litex SoC reset driver
inochisa May 29, 2026
1157eb3
lib: sbi_trap_v_ldst: Redirect unhandled traps
mpe May 29, 2026
dcb5179
gitignore: Ignore python cache directories
mpe Jun 2, 2026
0f42eff
include: utils/hsm: Add __noreturn attribute for sifive_cease
ganboing Jun 5, 2026
7bff4e5
platform: generic: eswin: Add eic770x_hsm and fix warm reset issues
ganboing Jun 5, 2026
3c4fa34
include: sbi: Add more mstatus and instruction encoding
ganboing Jun 5, 2026
bd986ed
include: sbi: Add sbi_regs_prev_xlen
ganboing Jun 5, 2026
1b3424d
include: sbi: Add GET_RDS_NUM/SET(_FP32/_FP64)_RDS macros
ganboing Jun 5, 2026
7dfaa46
include: sbi: set FS dirty in vsstatus when V=1
ganboing Jun 5, 2026
eba121b
lib: sbi: Do not override emulator callback for vector load/store
ganboing Jun 5, 2026
3aafbf5
Makefile: define OPENSBI_DEBUG if DEBUG builds
ganboing Jun 5, 2026
56c39d1
lib: sbi: Rework load/store emulator instruction decoding
ganboing Jun 5, 2026
d936372
lib: sbi: Make per-HART stack size configurable via Kconfig
uricata9 Jun 16, 2026
3afe63d
lib: sbi: dbtr: do not unconditionally access tdata2/tdata3 CSRs
dgporras Jun 16, 2026
4120e6d
lib: sbi: cosmetic changes to reduce indentation
ganboing Jun 9, 2026
1475f14
lib: sbi: Rework and split sbi_misaligned(_v)_tinst_fixup
ganboing Jun 9, 2026
914aedd
lib: sbi: Add variable-length unprivilege access functions
ganboing Jun 9, 2026
a8be5e9
lib: sbi: Rework misaligned vector load/store
ganboing Jun 9, 2026
a2077d4
platform: generic: mips eyeq7h: fix boot with JTAG
vlkondratiev Jun 18, 2026
cc9b4ef
platform: generic: spacemit: k1: fix wrong address definitions
pigmoral Jun 23, 2026
0dfe6be
lib: sbi_pmu: fix integer overflow in pmu_ctr_idx_validate
I3eg1nner Jun 28, 2026
bf10d3b
firmware: Fix comment after relocation completion
zongbox Jun 26, 2026
cbf9f67
include: Bump-up version to 1.9
avpatel Jun 30, 2026
2625712
lib: utils/mpxy: Add RPMI MPXY driver for logging service group
Jun 19, 2026
42a67c6
sg2042: add fence for store buffer in spinlock
RevySR Feb 3, 2026
78b8a34
lib: sbi: Workaround for FENCE(.I) errata on C906, C910.
roybaer Dec 27, 2025
9bb15a5
HACK: Disable SBI_FWFT_MISALIGNED_EXC_DELEG
dramforever Dec 25, 2025
9bcc2ee
Allows the platform to customize TLB operations
wxjstz Jan 7, 2026
f634dba
lib: sbi: ISA extension emulation.
roybaer Dec 27, 2025
a0737c9
lib: sbi: ISA extension emulation (Zvbb).
roybaer Dec 27, 2025
40c1b29
config: enable isa emu for rva23u64 & vlen=128
RevySR Nov 17, 2025
849a2b3
dt: fix dt for rva23 for sg2044
RevySR Oct 29, 2025
33abec0
lib: sbi: Set vector state as dirty after emulating
dramforever Jun 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
build/
install/

# Python bytecode (e.g. from scripts/Kconfiglib)
__pycache__

# Development friendly files
tags
cscope*
Expand Down
2 changes: 2 additions & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ List of OpenSBI Contributors (Alphabetically sorted)

* Atish Patra <atish.patra@wdc.com>

* Benedikt Freisen <b.freisen@gmx.net>

* Bin Meng <bmeng.cn@gmail.com>

* Damien Le Moal <damien.lemoal@wdc.com>
Expand Down
18 changes: 18 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -451,10 +451,28 @@ DTSCPPFLAGS = $(CPPFLAGS) -nostdinc -nostdlib -fno-builtin -D__DTS__ -x assemble

ifneq ($(DEBUG),)
CFLAGS += -O0
CPPFLAGS += -DOPENSBI_DEBUG
else
CFLAGS += -O2
endif

ifeq ($(UBSAN),y)
UBSAN_CC_FLAGS := -fsanitize=undefined
UBSAN_CC_FLAGS += -DUBSAN_ENABLED
UBSAN_CC_FLAGS += -fno-sanitize=vptr
UBSAN_CC_FLAGS += -fno-sanitize=float-cast-overflow
UBSAN_CC_FLAGS += -fno-sanitize=float-divide-by-zero
UBSAN_CC_FLAGS += -fsanitize-recover=undefined
UBSAN_CC_FLAGS += -fsanitize=pointer-overflow
UBSAN_CC_FLAGS += -fsanitize=alignment
UBSAN_CC_FLAGS += -fno-sanitize-recover=alignment
UBSAN_CC_FLAGS += -fno-stack-protector
ifeq ($(LLVM), y)
UBSAN_CC_FLAGS += -fno-sanitize-link-runtime
endif
CFLAGS += $(UBSAN_CC_FLAGS)
endif

ifeq ($(V), 1)
ELFFLAGS += -Wl,--print-gc-sections
endif
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,5 @@ make I=<install_directory> install_docs
[Firmware Documentation]: docs/firmware/fw.md
[Domain Support]: docs/domain_support.md
[Doxygen manual]: http://www.doxygen.nl/manual/index.html
[Kendryte standalone SDK]: https://github.com/kendryte/kendryte-standalone-sdk
[third party notices]: ThirdPartyNotices.md
[reproducible builds]: https://reproducible-builds.org
13 changes: 10 additions & 3 deletions docs/domain_support.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@ The DT properties of a domain instance DT node are as follows:
* **possible-harts** (Optional) - The list of CPU DT node phandles for the
the domain instance. This list represents the possible HARTs of the
domain instance.
* **root-regions-inheritance** (Optional) - A string property controlling
how memory regions are inherited from **the ROOT domain**, which are then
overlaid with regions specified in the **regions** property for additional
restrictions. The allowed values are:
* "all" - inherit all memory regions from **the ROOT domain**
* "m-only" - inherit M-mode only memory regions from **the ROOT domain**
If this DT property is absent, behavior is the same as "m-only".
* **regions** (Optional) - The list of domain memory region DT node phandle
and access permissions for the domain instance. Each list entry is a pair
of DT node phandle and access permissions. The access permissions are
Expand All @@ -173,9 +180,9 @@ The DT properties of a domain instance DT node are as follows:
Any region of a domain defined in DT node cannot have only M-bits set
in access permissions i.e. it cannot be an m-mode only accessible region.
* **boot-hart** (Optional) - The DT node phandle of the HART booting the
domain instance. If coldboot HART is assigned to the domain instance then
this DT property is ignored and the coldboot HART is assumed to be the
boot HART of the domain instance.
domain instance. If not specified, defaults to the coldboot HART. Note that
if the coldboot HART is assigned to this domain, it will be forced as
the boot HART regardless of this property.
* **next-arg1** (Optional) - The 64 bit next booting stage arg1 for the
domain instance. If this DT property is not available and coldboot HART
is not assigned to the domain instance then **next booting stage arg1 of coldboot HART**
Expand Down
2 changes: 2 additions & 0 deletions docs/platform/generic.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ RISC-V Platforms Using Generic Platform
* **SiFive HiFive Unleashed** (*[sifive_fu540.md]*)
* **Spike** (*[spike.md]*)
* **T-HEAD C9xx series Processors** (*[thead-c9xx.md]*)
* **Tenstorrent Atlantis Platform** (*[tt-atlantis.md]*)
* **OpenPiton FPGA SoC** (*[fpga-openpiton.md]*)
* **Ariane FPGA SoC** (*[fpga-ariane.md]*)

Expand All @@ -57,5 +58,6 @@ RISC-V Platforms Using Generic Platform
[sifive_fu540.md]: sifive_fu540.md
[spike.md]: spike.md
[thead-c9xx.md]: thead-c9xx.md
[tt-atlantis.md]: tt-atlantis.md
[fpga-openpiton.md]: fpga-openpiton.md
[fpga-ariane.md]: fpga-ariane.md
3 changes: 0 additions & 3 deletions docs/platform/platform.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ OpenSBI currently supports the following virtual and hardware platforms:
machine. More details on this platform can be found in the file
*[sifive_fu540.md]*.

* **Kendryte K210 SoC**: Platform support for the Kendryte K210 SoC used on
boards such as the Kendryte KD233 or the Sipeed MAIX Dock.

* **Andes AE350 SoC**: Platform support for the Andes's SoC (AE350). More
details on this platform can be found in the file *[andes-ae350.md]*.

Expand Down
3 changes: 3 additions & 0 deletions docs/platform/qemu_virt.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ qemu-system-riscv32 -M virt -m 256M -nographic \
Debugging with GDB
------------------

Note: the command line examples here assume that OpenSBI was compiled using
the `DEBUG=1 FW_TEXT_START=0x80000000` configuration.

In a first console start OpenSBI with QEMU:

```
Expand Down
35 changes: 35 additions & 0 deletions docs/platform/tt-atlantis.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Tenstorrent Atlantis Platform
=============================

The Tenstorrent Atlantis is an SoC and development board from
Tenstorrent in partnership with CoreLab Technology. It contains 8 RISC-V
RVA23 compliant Tenstorrent Ascalon cores with RISC-V AIA, RISC-V IOMMU,
and a range of devices and IO connectivity.

To build the platform-specific library and firmware images, provide the
*PLATFORM=generic* parameter to the top level `make` command.

Platform Options
----------------

The *Tenstorrent Atlantis* platform does not have any platform-specific
options.

Building Tenstorrent Atlantis Platform
--------------------------------------

The Atlantis Platform is still under development. This section will be
expanded as firmware and support become available.

QEMU support is currently being developed and initial support has been
proposed for upstream. To run QEMU that is patched with 'tt-atlantis'
machine support, run:

```
qemu-system-riscv64 -M tt-atlantis -nographic \
-bios build/platform/generic/firmware/fw_payload.bin \
-kernel <linux_build_dir>/Image
```

Recent (6.18) Linux/riscv 64-bit defconfig kernels should run the QEMU
tt-atlantis machine.
134 changes: 124 additions & 10 deletions firmware/fw_base.S
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ _sc_fail:
addi t0, t0, (__SIZEOF_LONG__ * 3)
blt t0, t1, 2b
_relocate_done:
/* At this point we are running from link address */
/* At this point we are running from load address */

/* Reset all registers except ra, a0, a1, a2, a3 and a4 for boot HART */
li ra, 0
Expand Down Expand Up @@ -234,9 +234,10 @@ _scratch_init:
/* Store hartid-to-scratch function address in scratch space */
lla a4, _hartid_to_scratch
REG_S a4, SBI_SCRATCH_HARTID_TO_SCRATCH_OFFSET(tp)
/* Clear trap_context and tmp0 in scratch space */
/* Clear trap_context, tmp0 and tmp1 in scratch space */
REG_S zero, SBI_SCRATCH_TRAP_CONTEXT_OFFSET(tp)
REG_S zero, SBI_SCRATCH_TMP0_OFFSET(tp)
REG_S zero, SBI_SCRATCH_TMP1_OFFSET(tp)
/* Store firmware options in scratch space */
MOV_3R s0, a0, s1, a1, s2, a2
#ifdef FW_OPTIONS
Expand Down Expand Up @@ -504,6 +505,45 @@ memcmp:
csrrw tp, CSR_MSCRATCH, tp
.endm

.macro TRAP_SAVE_AND_SETUP_SP_T0_NMI
/* Swap TP and MNSCRATCH (for RNMI) */
csrrw tp, CSR_MNSCRATCH, tp

/* Save T0 in scratch space */
REG_S t0, SBI_SCRATCH_TMP1_OFFSET(tp)

/*
* Set T0 to appropriate exception stack
*
* Came_From_M_Mode = ((MNSTATUS.MNPP < PRV_M) ? 1 : 0) - 1;
* Exception_Stack = TP ^ (Came_From_M_Mode & (SP ^ TP))
*/
csrr t0, CSR_MNSTATUS
srl t0, t0, 11 /* MNPP is at bits 11-12 */
and t0, t0, PRV_M
slti t0, t0, PRV_M
add t0, t0, -1
xor sp, sp, tp
and t0, t0, sp
xor sp, sp, tp
xor t0, tp, t0

/* Save original SP on exception stack */
REG_S sp, (SBI_TRAP_REGS_OFFSET(sp) - SBI_TRAP_CONTEXT_SIZE)(t0)

/* Set SP to exception stack and make room for trap context */
add sp, t0, -(SBI_TRAP_CONTEXT_SIZE)

/* Restore T0 from scratch space */
REG_L t0, SBI_SCRATCH_TMP1_OFFSET(tp)

/* Save T0 on stack */
REG_S t0, SBI_TRAP_REGS_OFFSET(t0)(sp)

/* Swap TP and MNSCRATCH */
csrrw tp, CSR_MNSCRATCH, tp
.endm

.macro TRAP_SAVE_MEPC_MSTATUS have_mstatush
/* Save MEPC and MSTATUS CSRs */
csrr t0, CSR_MEPC
Expand All @@ -518,6 +558,20 @@ memcmp:
.endif
.endm

.macro TRAP_SAVE_MNEPC_MNSTATUS have_mstatush
/*
* Save MNEPC and MNSTATUS CSRs (for RNMI)
* Note: Trap context structure has generic field names (mepc, mstatus),
* we store MN* CSR values into these same structure fields.
*/
csrr t0, CSR_MNEPC
REG_S t0, SBI_TRAP_REGS_OFFSET(mepc)(sp)
csrr t0, CSR_MNSTATUS
REG_S t0, SBI_TRAP_REGS_OFFSET(mstatus)(sp)
/* MNSTATUSH doesn't exist in SMRNMI spec */
REG_S zero, SBI_TRAP_REGS_OFFSET(mstatusH)(sp)
.endm

.macro TRAP_SAVE_GENERAL_REGS_EXCEPT_SP_T0
/* Save all general regisers except SP and T0 */
REG_S zero, SBI_TRAP_REGS_OFFSET(zero)(sp)
Expand Down Expand Up @@ -581,12 +635,36 @@ memcmp:
CLEAR_MDT t0
.endm

.macro TRAP_SAVE_NMI_INFO
/*
* Save NMI trap info (MNCAUSE, no MNTVAL in spec)
* Note: Trap info structure has generic field names (cause, tval, etc.),
* we store MN* CSR values into these same structure fields.
*/
csrr t0, CSR_MNCAUSE
REG_S t0, (SBI_TRAP_REGS_SIZE + SBI_TRAP_INFO_OFFSET(cause))(sp)
/* MNTVAL doesn't exist in SMRNMI spec */
REG_S zero, (SBI_TRAP_REGS_SIZE + SBI_TRAP_INFO_OFFSET(tval))(sp)
REG_S zero, (SBI_TRAP_REGS_SIZE + SBI_TRAP_INFO_OFFSET(tval2))(sp)
REG_S zero, (SBI_TRAP_REGS_SIZE + SBI_TRAP_INFO_OFFSET(tinst))(sp)
REG_S zero, (SBI_TRAP_REGS_SIZE + SBI_TRAP_INFO_OFFSET(gva))(sp)

/* We are ready to take another trap, clear MDT */
CLEAR_MDT t0
.endm

.macro TRAP_CALL_C_ROUTINE
/* Call C routine */
add a0, sp, zero
call sbi_trap_handler
.endm

.macro TRAP_CALL_C_RNMI_ROUTINE
/* Call C routine */
add a0, sp, zero
call sbi_trap_rnmi_handler
.endm

.macro TRAP_RESTORE_GENERAL_REGS_EXCEPT_A0_T0
/* Restore all general regisers except A0 and T0 */
REG_L ra, SBI_TRAP_REGS_OFFSET(ra)(a0)
Expand Down Expand Up @@ -635,6 +713,19 @@ memcmp:
csrw CSR_MEPC, t0
.endm

.macro TRAP_RESTORE_MNEPC_MNSTATUS
/*
* Restore MNSTATUS and MNEPC CSRs (for RNMI)
* Note: Load from generic structure fields (mstatus, mepc) and
* restore to NMI-specific CSRs (MNSTATUS, MNEPC).
* No MNSTATUSH in SMRNMI spec.
*/
REG_L t0, SBI_TRAP_REGS_OFFSET(mstatus)(a0)
csrw CSR_MNSTATUS, t0
REG_L t0, SBI_TRAP_REGS_OFFSET(mepc)(a0)
csrw CSR_MNEPC, t0
.endm

.macro TRAP_RESTORE_A0_T0
/* Restore T0 */
REG_L t0, SBI_TRAP_REGS_OFFSET(t0)(a0)
Expand Down Expand Up @@ -699,6 +790,37 @@ _trap_handler_hyp:

mret

.section .entry, "ax", %progbits
.align 3
.globl _trap_rnmi_handler
_trap_rnmi_handler:
/*
* NMI interrupt handler using MN* CSRs
*
* Context detection via MNPP (previous privilege mode):
* - If MNPP < M-mode: use exception stack (TP)
* - If MNPP == M-mode: use current stack (SP)
* This handles nested interrupt cases.
*/
TRAP_SAVE_AND_SETUP_SP_T0_NMI

TRAP_SAVE_MNEPC_MNSTATUS 0

TRAP_SAVE_GENERAL_REGS_EXCEPT_SP_T0

TRAP_SAVE_NMI_INFO

TRAP_CALL_C_RNMI_ROUTINE

TRAP_RESTORE_GENERAL_REGS_EXCEPT_A0_T0

TRAP_RESTORE_MNEPC_MNSTATUS

TRAP_RESTORE_A0_T0

/* mnret - return from NMI (SMRNMI extension) */
.word 0x70200073

.section .entry, "ax", %progbits
.align 3
.globl _reset_regs
Expand Down Expand Up @@ -749,14 +871,6 @@ __stack_chk_fail:
la a0, .Lstack_corrupt_msg
call sbi_panic

/* Initial value of the stack guard variable */
.section .data
.align 3
.globl __stack_chk_guard
.type __stack_chk_guard, %object
__stack_chk_guard:
RISCV_PTR 0x95B5FF5A

#ifdef FW_FDT_PATH
.section .rodata
.align 4
Expand Down
3 changes: 2 additions & 1 deletion firmware/payloads/test_head.S
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#define REG_L __REG_SEL(ld, lw)
#define REG_S __REG_SEL(sd, sw)
#define REG_ADDW __REG_SEL(addw, add)

.section .entry, "ax", %progbits
.align 3
Expand All @@ -35,7 +36,7 @@ _start:
#elif defined(__riscv_zalrsc)
_sc_fail:
lr.w t0, (a3)
addw t1, t0, a2
REG_ADDW t1, t0, a2
sc.w t1, t1, (a3)
bnez t1, _sc_fail
move a3, t0
Expand Down
12 changes: 0 additions & 12 deletions include/sbi/riscv_asm.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,18 +209,6 @@ int misa_xlen(void);
/* Get RISC-V ISA string representation */
void misa_string(int xlen, char *out, unsigned int out_sz);

/* Disable pmp entry at a given index */
int pmp_disable(unsigned int n);

/* Check if the matching field is set */
int is_pmp_entry_mapped(unsigned long entry);

int pmp_set(unsigned int n, unsigned long prot, unsigned long addr,
unsigned long log2len);

int pmp_get(unsigned int n, unsigned long *prot_out, unsigned long *addr_out,
unsigned long *log2len);

#endif /* !__ASSEMBLER__ */

#endif
Loading