MOS Source Code
Loading...
Searching...
No Matches
cpu.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
2
3#pragma once
4
5#include <mos/mos_global.h>
6#include <mos/types.h>
7
8typedef struct _platform_regs
9{
10 reg_t ra, sp, gp, tp;
11 reg_t t0, t1, t2;
12 reg_t fp, s1;
13 reg_t a0, a1, a2, a3, a4, a5, a6, a7;
14 reg_t s2, s3, s4, s5, s6, s7, s8, s9, s10, s11;
15 reg_t t3, t4, t5, t6;
16
17 // below are the CSR registers
18 reg_t sstatus, sepc;
20
21MOS_STATIC_ASSERT(sizeof(platform_regs_t) == 264, "please also change cpu/interrupt.S");
22
23#define read_csr(reg) statement_expr(reg_t, { asm volatile("csrr %0, " #reg : "=r"(retval)); })
24#define write_csr(reg, val) __asm__ volatile("csrw " #reg ", %0" ::"r"(val))
25
26#define make_satp(mode, asid, ppn) ((u64) (mode) << 60 | ((u64) (asid) << 44) | (ppn))
27
28#define SATP_MODE_SV39 8
29#define SATP_MODE_SV48 9
30#define SATP_MODE_SV57 10
31
32#define SSTATUS_SIE BIT(1) // Supervisor Interrupt Enable
33#define SSTATUS_SPIE BIT(5) // Supervisor Previous Interrupt Enable
34#define SSTATUS_SPP BIT(8) // Supervisor Previous Privilege
35#define SSTATUS_SUM BIT(18) // Supervisor User Memory Access Enable
36
37#define SSTATUS_FS_OFF 0
38#define SSTATUS_FS_INITIAL BIT(13)
39#define SSTATUS_FS_CLEAN BIT(14)
40#define SSTATUS_FS_DIRTY (BIT(13) | BIT(14))
41
42#define SIE_SEIE BIT(9)
43#define SIE_STIE BIT(5)
44#define SIE_SSIE BIT(1)
45
46[[noreturn]] extern void riscv64_trap_exit(platform_regs_t *regs);
47
48extern const char __riscv64_trap_entry[];
49extern const char __riscv64_usermode_trap_entry[];
#define __packed
Definition mos_global.h:29
#define MOS_STATIC_ASSERT
Definition mos_global.h:14
struct _platform_regs platform_regs_t
Definition platform.h:86
const char __riscv64_usermode_trap_entry[]
void riscv64_trap_exit(platform_regs_t *regs)
const char __riscv64_trap_entry[]
reg_t sepc
Definition cpu.h:18
reg_t t3
Definition cpu.h:15
reg_t a0
Definition cpu.h:13
reg_t gp
Definition cpu.h:10
reg_t s10
Definition cpu.h:14
reg_t t0
Definition cpu.h:11
reg_t fp
Definition cpu.h:12
uintn reg_t
Definition types.h:51
signed char s8
Definition types.h:13