summaryrefslogtreecommitdiff
path: root/emulator/csr.h
blob: 89452b0cc963b1607e3292d2e5171e574c936981 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#pragma once

#include <stdint.h>

typedef struct Hart Hart;

#define CSR_CYCLE        0xC00
#define CSR_CYCLEH       0xC80
#define CSR_INSTRET      0xC02
#define CSR_INSTRETH     0xC82
#define CSR_TIME         0xC01
#define CSR_TIMEH        0xC81

#define CSR_MVENDORID    0xF11
#define CSR_MARCHID      0xF12
#define CSR_MIMPID       0xF13
#define CSR_MHARTID      0xF14

#define CSR_MISA         0x301

enum CsrAction
{
    CSR_R    = 0,
    CSR_W    = 1,
    CSR_RW   = 3,
    CSR_RC   = 5,
    CSR_RS   = 7,
};

struct Csr
{
    uint32_t (*action)(Hart* hart, uint32_t value_mask, enum CsrAction action);
};
typedef struct Csr Csr;

uint32_t csr_action(Hart* hart, uint16_t id, uint32_t value, enum CsrAction action);