1/*
2 * Copyright (c) 2021 Tokita, Hiroshi <tokita.hiroshi@gmail.com>
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#include "nuclei_csr.h"
8
9#include <zephyr/toolchain.h>
10#include <zephyr/arch/riscv/csr.h>
11
12GTEXT(__nuclei_start)
13SECTION_FUNC(init, __nuclei_start)
14	/* Disable Global Interrupt */
15	csrc mstatus, MSTATUS_MIE
16	/* Jump to logical address first to ensure correct operation of RAM region  */
17	la	a0, __nuclei_start
18	li	a1, 1
19	slli	a1, a1, 29 # 0x2000 0000
20	bleu	a1, a0, _start0800
21	srli	a1, a1, 2  # 0x0800 0000
22	bleu	a1, a0, _start0800
23	la	a0, _start0800
24	add	a0, a0, a1
25	jr	a0
26
27_start0800:
28	/* Set the the NMI base to share with mtvec by setting CSR_MMISC_CTL */
29	li	t0, 0x200
30	csrs	CSR_MMISC_CTL, t0
31
32	/* Disable performance counter */
33	csrsi	mcountinhibit, 0x5
34
35	/* Jump to common start */
36	tail __start
37