NEORV32 Software Framework Documentation
The NEORV32 RISC-V Processor
Loading...
Searching...
No Matches
neorv32_cpu_amo.h
Go to the documentation of this file.
1// ================================================================================ //
2// The NEORV32 RISC-V Processor - https://github.com/stnolting/neorv32 //
3// Copyright (c) NEORV32 contributors. //
4// Copyright (c) 2020 - 2024 Stephan Nolting. All rights reserved. //
5// Licensed under the BSD-3-Clause license, see LICENSE for details. //
6// SPDX-License-Identifier: BSD-3-Clause //
7// ================================================================================ //
8
16#ifndef neorv32_cpu_amo_h
17#define neorv32_cpu_amo_h
18
19#include <stdint.h>
20
21
22/**********************************************************************/
31inline uint32_t __attribute__ ((always_inline)) neorv32_cpu_amolr(uint32_t addr) {
32
33#if defined __riscv_atomic
34 uint32_t amo_addr = addr;
35 uint32_t amo_rdata;
36
37 asm volatile ("lr.w %[dst], 0(%[addr])" : [dst] "=r" (amo_rdata) : [addr] "r" (amo_addr));
38
39 return amo_rdata;
40#else
41 (void)addr;
42
43 return 0;
44#endif
45}
46
47
48/**********************************************************************/
58inline uint32_t __attribute__ ((always_inline)) neorv32_cpu_amosc(uint32_t addr, uint32_t wdata) {
59
60#if defined __riscv_atomic
61 uint32_t amo_addr = addr;
62 uint32_t amo_wdata = wdata;
63 uint32_t amo_status;
64
65 asm volatile ("sc.w %[dst], %[src], (%[addr])" : [dst] "=r" (amo_status) : [src] "r" (amo_wdata), [addr] "r" (amo_addr));
66
67 return amo_status;
68#else
69 (void)addr;
70 (void)wdata;
71
72 return 1; // always fail
73#endif
74}
75
76
77/**********************************************************************/
81uint32_t neorv32_cpu_amoswapw(uint32_t addr, uint32_t wdata);
82uint32_t neorv32_cpu_amoaddw(uint32_t addr, uint32_t wdata);
83uint32_t neorv32_cpu_amoandw(uint32_t addr, uint32_t wdata);
84uint32_t neorv32_cpu_amoorw(uint32_t addr, uint32_t wdata);
85uint32_t neorv32_cpu_amoxorw(uint32_t addr, uint32_t wdata);
86int32_t neorv32_cpu_amomaxw(uint32_t addr, int32_t wdata);
87uint32_t neorv32_cpu_amomaxuw(uint32_t addr, uint32_t wdata);
88int32_t neorv32_cpu_amominw(uint32_t addr, int32_t wdata);
89uint32_t neorv32_cpu_amominuw(uint32_t addr, uint32_t wdata);
93#endif // neorv32_cpu_amo_h
uint32_t neorv32_cpu_amominuw(uint32_t addr, uint32_t wdata)
Definition neorv32_cpu_amo.c:315
uint32_t neorv32_cpu_amomaxuw(uint32_t addr, uint32_t wdata)
Definition neorv32_cpu_amo.c:243
uint32_t neorv32_cpu_amosc(uint32_t addr, uint32_t wdata)
Definition neorv32_cpu_amo.h:58
int32_t neorv32_cpu_amomaxw(uint32_t addr, int32_t wdata)
Definition neorv32_cpu_amo.c:207
uint32_t neorv32_cpu_amoxorw(uint32_t addr, uint32_t wdata)
Definition neorv32_cpu_amo.c:171
int32_t neorv32_cpu_amominw(uint32_t addr, int32_t wdata)
Definition neorv32_cpu_amo.c:279
uint32_t neorv32_cpu_amoandw(uint32_t addr, uint32_t wdata)
Definition neorv32_cpu_amo.c:99
uint32_t neorv32_cpu_amoswapw(uint32_t addr, uint32_t wdata)
Definition neorv32_cpu_amo.c:29
uint32_t neorv32_cpu_amolr(uint32_t addr)
Definition neorv32_cpu_amo.h:31
uint32_t neorv32_cpu_amoaddw(uint32_t addr, uint32_t wdata)
Definition neorv32_cpu_amo.c:63
uint32_t neorv32_cpu_amoorw(uint32_t addr, uint32_t wdata)
Definition neorv32_cpu_amo.c:135