Line 320... |
Line 320... |
: : [input_imm] "i" ((1<<CSR_MSTATUS_MPP_H) | (1<<CSR_MSTATUS_MPP_L)));
|
: : [input_imm] "i" ((1<<CSR_MSTATUS_MPP_H) | (1<<CSR_MSTATUS_MPP_L)));
|
}
|
}
|
|
|
|
|
/**********************************************************************//**
|
/**********************************************************************//**
|
* Atomic compare-and-swap operation (for implemeneting semaphores and mutexes).
|
|
*
|
|
* @warning This function requires the A (atomic) CPU extension.
|
|
*
|
|
* @param[in] addr Address of memory location.
|
|
* @param[in] expected Expected value (for comparison).
|
|
* @param[in] desired Desired value (new value).
|
|
* @return Returns 0 on success, 1 on failure.
|
|
**************************************************************************/
|
|
int __attribute__ ((noinline)) neorv32_cpu_atomic_cas(uint32_t addr, uint32_t expected, uint32_t desired) {
|
|
#ifdef __riscv_atomic
|
|
|
|
register uint32_t addr_reg = addr;
|
|
register uint32_t des_reg = desired;
|
|
register uint32_t tmp_reg;
|
|
|
|
// load original value + reservation (lock)
|
|
asm volatile ("lr.w %[result], (%[input])" : [result] "=r" (tmp_reg) : [input] "r" (addr_reg));
|
|
|
|
if (tmp_reg != expected) {
|
|
asm volatile ("lw x0, 0(%[input])" : : [input] "r" (addr_reg)); // clear reservation lock
|
|
return 1;
|
|
}
|
|
|
|
// store-conditional
|
|
asm volatile ("sc.w %[result], %[input_i], (%[input_j])" : [result] "=r" (tmp_reg) : [input_i] "r" (des_reg), [input_j] "r" (addr_reg));
|
|
|
|
if (tmp_reg) {
|
|
return 1;
|
|
}
|
|
|
|
return 0;
|
|
#else
|
|
return 1; // A extension not implemented - function always fails
|
|
#endif
|
|
}
|
|
|
|
|
|
/**********************************************************************//**
|
|
* Physical memory protection (PMP): Get number of available regions.
|
* Physical memory protection (PMP): Get number of available regions.
|
*
|
*
|
* @warning This function overrides all available PMPCFG* CSRs.
|
* @warning This function overrides all available PMPCFG* CSRs.
|
* @warning This function requires the PMP CPU extension.
|
* @warning This function requires the PMP CPU extension.
|
*
|
*
|