2018-12-11 21:54:06 +08:00
|
|
|
/*
|
2019-01-24 14:11:10 +08:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*
|
|
|
|
* Copyright (c) 2019 Western Digital Corporation or its affiliates.
|
2018-12-11 21:54:06 +08:00
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Anup Patel <anup.patel@wdc.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sbi/riscv_asm.h>
|
|
|
|
#include <sbi/riscv_barrier.h>
|
|
|
|
#include <sbi/riscv_encoding.h>
|
2019-01-03 13:07:43 +08:00
|
|
|
#include <sbi/riscv_fp.h>
|
2020-03-04 13:38:35 +08:00
|
|
|
#include <sbi/sbi_bitops.h>
|
2018-12-11 21:54:06 +08:00
|
|
|
#include <sbi/sbi_console.h>
|
2020-05-10 07:47:28 +08:00
|
|
|
#include <sbi/sbi_csr_detect.h>
|
2018-12-11 21:54:06 +08:00
|
|
|
#include <sbi/sbi_error.h>
|
|
|
|
#include <sbi/sbi_hart.h>
|
2020-05-10 07:47:25 +08:00
|
|
|
#include <sbi/sbi_math.h>
|
2018-12-11 21:54:06 +08:00
|
|
|
#include <sbi/sbi_platform.h>
|
|
|
|
|
2020-05-10 07:47:23 +08:00
|
|
|
extern void __sbi_expected_trap(void);
|
|
|
|
extern void __sbi_expected_trap_hext(void);
|
2020-03-19 19:43:16 +08:00
|
|
|
|
2020-05-10 07:47:23 +08:00
|
|
|
void (*sbi_hart_expected_trap)(void) = &__sbi_expected_trap;
|
2020-05-10 07:47:27 +08:00
|
|
|
static unsigned long hart_features_offset;
|
2020-03-19 19:43:16 +08:00
|
|
|
|
2018-12-21 08:13:37 +08:00
|
|
|
static void mstatus_init(struct sbi_scratch *scratch, u32 hartid)
|
2018-12-11 21:54:06 +08:00
|
|
|
{
|
2020-04-17 09:56:30 +08:00
|
|
|
unsigned long mstatus_val = 0;
|
2018-12-21 08:13:37 +08:00
|
|
|
|
2018-12-11 21:54:06 +08:00
|
|
|
/* Enable FPU */
|
|
|
|
if (misa_extension('D') || misa_extension('F'))
|
2020-04-17 09:56:30 +08:00
|
|
|
mstatus_val |= MSTATUS_FS;
|
|
|
|
|
|
|
|
/* Enable Vector context */
|
|
|
|
if (misa_extension('V'))
|
|
|
|
mstatus_val |= MSTATUS_VS;
|
|
|
|
|
|
|
|
csr_write(CSR_MSTATUS, mstatus_val);
|
2018-12-11 21:54:06 +08:00
|
|
|
|
|
|
|
/* Enable user/supervisor use of perf counters */
|
2020-05-10 07:47:28 +08:00
|
|
|
if (misa_extension('S') &&
|
|
|
|
sbi_hart_has_feature(hartid, SBI_HART_HAS_SCOUNTEREN))
|
2019-02-13 10:32:06 +08:00
|
|
|
csr_write(CSR_SCOUNTEREN, -1);
|
2020-05-10 07:47:28 +08:00
|
|
|
if (!sbi_hart_has_feature(hartid, SBI_HART_HAS_MCOUNTEREN))
|
2019-02-13 10:32:06 +08:00
|
|
|
csr_write(CSR_MCOUNTEREN, -1);
|
2018-12-11 21:54:06 +08:00
|
|
|
|
|
|
|
/* Disable all interrupts */
|
2019-02-13 10:32:06 +08:00
|
|
|
csr_write(CSR_MIE, 0);
|
2018-12-11 21:54:06 +08:00
|
|
|
|
|
|
|
/* Disable S-mode paging */
|
|
|
|
if (misa_extension('S'))
|
2019-02-13 10:32:06 +08:00
|
|
|
csr_write(CSR_SATP, 0);
|
2018-12-11 21:54:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int fp_init(u32 hartid)
|
|
|
|
{
|
|
|
|
#ifdef __riscv_flen
|
|
|
|
int i;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!misa_extension('D') && !misa_extension('F'))
|
|
|
|
return 0;
|
|
|
|
|
2019-02-13 10:32:06 +08:00
|
|
|
if (!(csr_read(CSR_MSTATUS) & MSTATUS_FS))
|
2018-12-11 21:54:06 +08:00
|
|
|
return SBI_EINVAL;
|
|
|
|
|
|
|
|
#ifdef __riscv_flen
|
|
|
|
for (i = 0; i < 32; i++)
|
|
|
|
init_fp_reg(i);
|
2019-02-13 10:32:06 +08:00
|
|
|
csr_write(CSR_FCSR, 0);
|
2018-12-11 21:54:06 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-12-21 18:19:54 +08:00
|
|
|
static int delegate_traps(struct sbi_scratch *scratch, u32 hartid)
|
2018-12-11 21:54:06 +08:00
|
|
|
{
|
2019-03-06 15:29:34 +08:00
|
|
|
const struct sbi_platform *plat = sbi_platform_ptr(scratch);
|
2018-12-21 14:05:33 +08:00
|
|
|
unsigned long interrupts, exceptions;
|
|
|
|
|
2019-01-22 10:17:45 +08:00
|
|
|
if (!misa_extension('S'))
|
2020-03-09 11:52:41 +08:00
|
|
|
/* No delegation possible as mideleg does not exist */
|
2019-01-22 10:17:45 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Send M-mode interrupts and most exceptions to S-mode */
|
|
|
|
interrupts = MIP_SSIP | MIP_STIP | MIP_SEIP;
|
2019-04-11 08:41:52 +08:00
|
|
|
exceptions = (1U << CAUSE_MISALIGNED_FETCH) | (1U << CAUSE_BREAKPOINT) |
|
2019-01-22 10:17:45 +08:00
|
|
|
(1U << CAUSE_USER_ECALL);
|
|
|
|
if (sbi_platform_has_mfaults_delegation(plat))
|
|
|
|
exceptions |= (1U << CAUSE_FETCH_PAGE_FAULT) |
|
|
|
|
(1U << CAUSE_LOAD_PAGE_FAULT) |
|
|
|
|
(1U << CAUSE_STORE_PAGE_FAULT);
|
2018-12-11 21:54:06 +08:00
|
|
|
|
2019-04-05 15:47:42 +08:00
|
|
|
/*
|
2019-12-12 09:30:59 +08:00
|
|
|
* If hypervisor extension available then we only handle hypervisor
|
|
|
|
* calls (i.e. ecalls from HS-mode) in M-mode.
|
|
|
|
*
|
|
|
|
* The HS-mode will additionally handle supervisor calls (i.e. ecalls
|
|
|
|
* from VS-mode), Guest page faults and Virtual interrupts.
|
2019-04-05 15:47:42 +08:00
|
|
|
*/
|
2019-12-12 09:30:59 +08:00
|
|
|
if (misa_extension('H')) {
|
2019-04-05 15:47:42 +08:00
|
|
|
exceptions |= (1U << CAUSE_SUPERVISOR_ECALL);
|
2019-12-12 09:30:59 +08:00
|
|
|
exceptions |= (1U << CAUSE_FETCH_GUEST_PAGE_FAULT);
|
|
|
|
exceptions |= (1U << CAUSE_LOAD_GUEST_PAGE_FAULT);
|
|
|
|
exceptions |= (1U << CAUSE_STORE_GUEST_PAGE_FAULT);
|
|
|
|
}
|
2019-04-05 15:47:42 +08:00
|
|
|
|
2019-02-13 10:32:06 +08:00
|
|
|
csr_write(CSR_MIDELEG, interrupts);
|
|
|
|
csr_write(CSR_MEDELEG, exceptions);
|
2018-12-11 21:54:06 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-02-18 14:23:52 +08:00
|
|
|
void sbi_hart_delegation_dump(struct sbi_scratch *scratch)
|
|
|
|
{
|
|
|
|
#if __riscv_xlen == 32
|
|
|
|
sbi_printf("MIDELEG : 0x%08lx\n", csr_read(CSR_MIDELEG));
|
|
|
|
sbi_printf("MEDELEG : 0x%08lx\n", csr_read(CSR_MEDELEG));
|
|
|
|
#else
|
|
|
|
sbi_printf("MIDELEG : 0x%016lx\n", csr_read(CSR_MIDELEG));
|
|
|
|
sbi_printf("MEDELEG : 0x%016lx\n", csr_read(CSR_MEDELEG));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-12-21 08:13:37 +08:00
|
|
|
void sbi_hart_pmp_dump(struct sbi_scratch *scratch)
|
2018-12-11 21:54:06 +08:00
|
|
|
{
|
2020-03-17 22:59:38 +08:00
|
|
|
unsigned long prot, addr, size;
|
2018-12-21 08:13:37 +08:00
|
|
|
unsigned int i;
|
|
|
|
|
2020-05-10 07:47:28 +08:00
|
|
|
if (!sbi_hart_has_feature(current_hartid(), SBI_HART_HAS_PMP))
|
2018-12-21 08:13:37 +08:00
|
|
|
return;
|
2018-12-11 21:54:06 +08:00
|
|
|
|
|
|
|
for (i = 0; i < PMP_COUNT; i++) {
|
2020-03-17 22:59:38 +08:00
|
|
|
pmp_get(i, &prot, &addr, &size);
|
2018-12-11 21:54:06 +08:00
|
|
|
if (!(prot & PMP_A))
|
|
|
|
continue;
|
|
|
|
#if __riscv_xlen == 32
|
2020-02-18 14:23:52 +08:00
|
|
|
sbi_printf("PMP%d : 0x%08lx-0x%08lx (A",
|
2018-12-11 21:54:06 +08:00
|
|
|
#else
|
2020-02-18 14:23:52 +08:00
|
|
|
sbi_printf("PMP%d : 0x%016lx-0x%016lx (A",
|
2018-12-11 21:54:06 +08:00
|
|
|
#endif
|
|
|
|
i, addr, addr + size - 1);
|
|
|
|
if (prot & PMP_L)
|
|
|
|
sbi_printf(",L");
|
|
|
|
if (prot & PMP_R)
|
|
|
|
sbi_printf(",R");
|
|
|
|
if (prot & PMP_W)
|
|
|
|
sbi_printf(",W");
|
|
|
|
if (prot & PMP_X)
|
|
|
|
sbi_printf(",X");
|
|
|
|
sbi_printf(")\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-12 09:32:37 +08:00
|
|
|
int sbi_hart_pmp_check_addr(struct sbi_scratch *scratch, unsigned long addr,
|
|
|
|
unsigned long attr)
|
|
|
|
{
|
2020-03-17 22:59:38 +08:00
|
|
|
unsigned long prot, size, i, tempaddr;
|
2020-02-12 09:32:37 +08:00
|
|
|
|
2020-05-10 07:47:28 +08:00
|
|
|
if (!sbi_hart_has_feature(current_hartid(), SBI_HART_HAS_PMP))
|
2020-02-12 09:32:37 +08:00
|
|
|
return SBI_OK;
|
|
|
|
|
|
|
|
for (i = 0; i < PMP_COUNT; i++) {
|
2020-03-17 22:59:38 +08:00
|
|
|
pmp_get(i, &prot, &tempaddr, &size);
|
2020-02-12 09:32:37 +08:00
|
|
|
if (!(prot & PMP_A))
|
|
|
|
continue;
|
|
|
|
if (tempaddr <= addr && addr <= tempaddr + size)
|
|
|
|
if (!(prot & attr))
|
|
|
|
return SBI_INVALID_ADDR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SBI_OK;
|
|
|
|
}
|
|
|
|
|
2018-12-11 21:54:06 +08:00
|
|
|
static int pmp_init(struct sbi_scratch *scratch, u32 hartid)
|
|
|
|
{
|
2020-04-23 14:22:30 +08:00
|
|
|
u32 i, pmp_idx = 0, count;
|
2018-12-11 21:54:06 +08:00
|
|
|
unsigned long fw_start, fw_size_log2;
|
|
|
|
ulong prot, addr, log2size;
|
2019-03-06 15:29:34 +08:00
|
|
|
const struct sbi_platform *plat = sbi_platform_ptr(scratch);
|
2018-12-11 21:54:06 +08:00
|
|
|
|
2020-05-10 07:47:28 +08:00
|
|
|
if (!sbi_hart_has_feature(current_hartid(), SBI_HART_HAS_PMP))
|
2018-12-21 08:13:37 +08:00
|
|
|
return 0;
|
|
|
|
|
2020-04-23 14:22:30 +08:00
|
|
|
/* Firmware PMP region to protect OpenSBI firmware */
|
2018-12-11 21:54:06 +08:00
|
|
|
fw_size_log2 = log2roundup(scratch->fw_size);
|
2020-04-23 14:22:30 +08:00
|
|
|
fw_start = scratch->fw_start & ~((1UL << fw_size_log2) - 1UL);
|
|
|
|
pmp_set(pmp_idx++, 0, fw_start, fw_size_log2);
|
2018-12-11 21:54:06 +08:00
|
|
|
|
2020-04-23 14:22:30 +08:00
|
|
|
/* Platform specific PMP regions */
|
2018-12-11 21:54:06 +08:00
|
|
|
count = sbi_platform_pmp_region_count(plat, hartid);
|
2020-04-23 14:22:30 +08:00
|
|
|
for (i = 0; i < count && pmp_idx < (PMP_COUNT - 1); i++) {
|
2019-04-11 08:41:52 +08:00
|
|
|
if (sbi_platform_pmp_region_info(plat, hartid, i, &prot, &addr,
|
|
|
|
&log2size))
|
2018-12-11 21:54:06 +08:00
|
|
|
continue;
|
2020-04-23 14:22:30 +08:00
|
|
|
pmp_set(pmp_idx++, prot, addr, log2size);
|
2018-12-11 21:54:06 +08:00
|
|
|
}
|
|
|
|
|
2020-04-23 14:22:30 +08:00
|
|
|
/*
|
|
|
|
* Default PMP region for allowing S-mode and U-mode access to
|
|
|
|
* memory not covered by:
|
|
|
|
* 1) Firmware PMP region
|
|
|
|
* 2) Platform specific PMP regions
|
|
|
|
*/
|
|
|
|
pmp_set(pmp_idx++, PMP_R | PMP_W | PMP_X, 0, __riscv_xlen);
|
|
|
|
|
2018-12-11 21:54:06 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-10 07:47:27 +08:00
|
|
|
bool sbi_hart_has_feature(u32 hartid, unsigned long feature)
|
|
|
|
{
|
|
|
|
unsigned long *hart_features;
|
|
|
|
struct sbi_scratch *scratch;
|
|
|
|
|
|
|
|
scratch = sbi_hartid_to_scratch(hartid);
|
|
|
|
hart_features = sbi_scratch_offset_ptr(scratch, hart_features_offset);
|
|
|
|
|
|
|
|
if (*hart_features & feature)
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-05-10 07:47:28 +08:00
|
|
|
static void sbi_hart_set_feature(u32 hartid, unsigned long feature)
|
|
|
|
{
|
|
|
|
unsigned long *hart_features;
|
|
|
|
struct sbi_scratch *scratch;
|
|
|
|
|
|
|
|
scratch = sbi_hartid_to_scratch(hartid);
|
|
|
|
hart_features = sbi_scratch_offset_ptr(scratch, hart_features_offset);
|
|
|
|
|
|
|
|
*hart_features = *hart_features | feature;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sbi_hart_detect_features(u32 hartid)
|
|
|
|
{
|
|
|
|
struct sbi_trap_info trap = {0};
|
|
|
|
unsigned long feature = 0;
|
|
|
|
unsigned long csr_val;
|
|
|
|
|
|
|
|
if (hartid != current_hartid())
|
|
|
|
sbi_hart_hang();
|
|
|
|
|
|
|
|
/* Detect if hart supports PMP feature */
|
|
|
|
csr_val = csr_read_allowed(CSR_PMPCFG0, (unsigned long)&trap);
|
|
|
|
if (!trap.cause) {
|
|
|
|
csr_write_allowed(CSR_PMPCFG0, (unsigned long)&trap, csr_val);
|
|
|
|
if (!trap.cause)
|
|
|
|
feature |= SBI_HART_HAS_PMP;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Detect if hart supports SCOUNTEREN feature */
|
|
|
|
trap.cause = 0;
|
|
|
|
csr_val = csr_read_allowed(CSR_SCOUNTEREN, (unsigned long)&trap);
|
|
|
|
if (!trap.cause) {
|
|
|
|
csr_write_allowed(CSR_SCOUNTEREN, (unsigned long)&trap,
|
|
|
|
csr_val);
|
|
|
|
if (!trap.cause)
|
|
|
|
feature |= SBI_HART_HAS_SCOUNTEREN;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Detect if hart supports MCOUNTEREN feature */
|
|
|
|
trap.cause = 0;
|
|
|
|
csr_val = csr_read_allowed(CSR_MCOUNTEREN, (unsigned long)&trap);
|
|
|
|
if (!trap.cause) {
|
|
|
|
csr_write_allowed(CSR_MCOUNTEREN, (unsigned long)&trap,
|
|
|
|
csr_val);
|
|
|
|
if (!trap.cause)
|
|
|
|
feature |= SBI_HART_HAS_MCOUNTEREN;
|
|
|
|
}
|
|
|
|
|
2020-05-10 07:47:30 +08:00
|
|
|
/* Detect if hart supports time CSR */
|
|
|
|
trap.cause = 0;
|
|
|
|
csr_read_allowed(CSR_TIME, (unsigned long)&trap);
|
|
|
|
if (!trap.cause)
|
|
|
|
feature |= SBI_HART_HAS_TIME;
|
|
|
|
|
2020-05-10 07:47:28 +08:00
|
|
|
sbi_hart_set_feature(hartid, feature);
|
|
|
|
}
|
|
|
|
|
2019-05-21 19:25:04 +08:00
|
|
|
int sbi_hart_init(struct sbi_scratch *scratch, u32 hartid, bool cold_boot)
|
2018-12-11 21:54:06 +08:00
|
|
|
{
|
|
|
|
int rc;
|
2020-05-10 07:47:27 +08:00
|
|
|
unsigned long *hart_features;
|
2018-12-11 21:54:06 +08:00
|
|
|
|
2019-05-21 19:25:04 +08:00
|
|
|
if (cold_boot) {
|
2020-03-19 19:43:16 +08:00
|
|
|
if (misa_extension('H'))
|
2020-05-10 07:47:23 +08:00
|
|
|
sbi_hart_expected_trap = &__sbi_expected_trap_hext;
|
2020-05-10 07:47:27 +08:00
|
|
|
hart_features_offset = sbi_scratch_alloc_offset(
|
|
|
|
sizeof(hart_features),
|
|
|
|
"HART_FEATURES");
|
|
|
|
if (!hart_features_offset)
|
|
|
|
return SBI_ENOMEM;
|
2019-05-21 19:25:04 +08:00
|
|
|
}
|
2020-05-10 07:47:27 +08:00
|
|
|
hart_features = sbi_scratch_offset_ptr(scratch, hart_features_offset);
|
|
|
|
*hart_features = 0;
|
2019-05-21 19:25:04 +08:00
|
|
|
|
2018-12-21 08:13:37 +08:00
|
|
|
mstatus_init(scratch, hartid);
|
2018-12-11 21:54:06 +08:00
|
|
|
|
|
|
|
rc = fp_init(hartid);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
2018-12-21 18:19:54 +08:00
|
|
|
rc = delegate_traps(scratch, hartid);
|
2018-12-11 21:54:06 +08:00
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
2020-05-10 07:47:28 +08:00
|
|
|
sbi_hart_detect_features(hartid);
|
|
|
|
|
2018-12-11 21:54:06 +08:00
|
|
|
return pmp_init(scratch, hartid);
|
|
|
|
}
|
|
|
|
|
|
|
|
void __attribute__((noreturn)) sbi_hart_hang(void)
|
|
|
|
{
|
|
|
|
while (1)
|
|
|
|
wfi();
|
|
|
|
__builtin_unreachable();
|
|
|
|
}
|
|
|
|
|
2019-04-11 08:41:52 +08:00
|
|
|
void __attribute__((noreturn))
|
|
|
|
sbi_hart_switch_mode(unsigned long arg0, unsigned long arg1,
|
2019-04-05 16:38:57 +08:00
|
|
|
unsigned long next_addr, unsigned long next_mode,
|
|
|
|
bool next_virt)
|
2018-12-11 21:54:06 +08:00
|
|
|
{
|
2019-04-05 16:38:57 +08:00
|
|
|
#if __riscv_xlen == 32
|
|
|
|
unsigned long val, valH;
|
|
|
|
#else
|
2018-12-11 21:54:06 +08:00
|
|
|
unsigned long val;
|
2019-04-05 16:38:57 +08:00
|
|
|
#endif
|
2018-12-21 15:44:53 +08:00
|
|
|
|
|
|
|
switch (next_mode) {
|
|
|
|
case PRV_M:
|
|
|
|
break;
|
|
|
|
case PRV_S:
|
|
|
|
if (!misa_extension('S'))
|
|
|
|
sbi_hart_hang();
|
|
|
|
break;
|
|
|
|
case PRV_U:
|
|
|
|
if (!misa_extension('U'))
|
|
|
|
sbi_hart_hang();
|
|
|
|
break;
|
|
|
|
default:
|
2018-12-21 13:36:20 +08:00
|
|
|
sbi_hart_hang();
|
2018-12-21 15:44:53 +08:00
|
|
|
}
|
2018-12-11 21:54:06 +08:00
|
|
|
|
2019-02-13 10:32:06 +08:00
|
|
|
val = csr_read(CSR_MSTATUS);
|
2018-12-11 21:54:06 +08:00
|
|
|
val = INSERT_FIELD(val, MSTATUS_MPP, next_mode);
|
|
|
|
val = INSERT_FIELD(val, MSTATUS_MPIE, 0);
|
2019-04-05 16:38:57 +08:00
|
|
|
#if __riscv_xlen == 32
|
|
|
|
if (misa_extension('H')) {
|
|
|
|
valH = csr_read(CSR_MSTATUSH);
|
|
|
|
if (next_virt)
|
|
|
|
valH = INSERT_FIELD(valH, MSTATUSH_MPV, 1);
|
|
|
|
else
|
|
|
|
valH = INSERT_FIELD(valH, MSTATUSH_MPV, 0);
|
|
|
|
csr_write(CSR_MSTATUSH, valH);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if (misa_extension('H')) {
|
|
|
|
if (next_virt)
|
|
|
|
val = INSERT_FIELD(val, MSTATUS_MPV, 1);
|
|
|
|
else
|
|
|
|
val = INSERT_FIELD(val, MSTATUS_MPV, 0);
|
|
|
|
}
|
|
|
|
#endif
|
2019-02-13 10:32:06 +08:00
|
|
|
csr_write(CSR_MSTATUS, val);
|
|
|
|
csr_write(CSR_MEPC, next_addr);
|
2018-12-11 21:54:06 +08:00
|
|
|
|
|
|
|
if (next_mode == PRV_S) {
|
2019-02-13 10:32:06 +08:00
|
|
|
csr_write(CSR_STVEC, next_addr);
|
|
|
|
csr_write(CSR_SSCRATCH, 0);
|
|
|
|
csr_write(CSR_SIE, 0);
|
|
|
|
csr_write(CSR_SATP, 0);
|
2018-12-11 21:54:06 +08:00
|
|
|
} else if (next_mode == PRV_U) {
|
2019-02-13 10:32:06 +08:00
|
|
|
csr_write(CSR_UTVEC, next_addr);
|
|
|
|
csr_write(CSR_USCRATCH, 0);
|
|
|
|
csr_write(CSR_UIE, 0);
|
2018-12-11 21:54:06 +08:00
|
|
|
}
|
|
|
|
|
2019-04-11 08:41:52 +08:00
|
|
|
register unsigned long a0 asm("a0") = arg0;
|
|
|
|
register unsigned long a1 asm("a1") = arg1;
|
|
|
|
__asm__ __volatile__("mret" : : "r"(a0), "r"(a1));
|
2018-12-11 21:54:06 +08:00
|
|
|
__builtin_unreachable();
|
|
|
|
}
|