summaryrefslogtreecommitdiff
path: root/src/asm.hpp
blob: 4d5eb73843cad26637546a4958e58e48f5b1c229 (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#ifndef SRC_ASM_HPP_
#define SRC_ASM_HPP_

#include <cstdint>

enum class type_t {R, I, S, U, B, J};

struct r_type {
    uint32_t funct7 : 7;
    uint32_t rs2    : 5;
    uint32_t rs1    : 5;
    uint32_t funct3 : 3;
    uint32_t rd     : 5;
    uint32_t opcode : 7;
};

struct i_type {
    uint32_t imm    : 12;
    uint32_t rs1    : 5;
    uint32_t funct3 : 3;
    uint32_t rd     : 5;
    uint32_t opcode : 7;
};

struct s_type {
    uint32_t imm_hi : 7;
    uint32_t rs2    : 5;
    uint32_t rs1    : 5;
    uint32_t funct3 : 3;
    uint32_t imm_lo : 5;
    uint32_t opcode : 7;
};

struct u_type {
    uint32_t imm    : 10;
    uint32_t rd     : 5;
    uint32_t opcode : 7;
};

struct b_type {
    uint32_t a      : 1;
    uint32_t imm_hi : 6;
    uint32_t rs2    : 5;
    uint32_t rs1    : 5;
    uint32_t funct3 : 3;
    uint32_t imm_lo : 4;
    uint32_t b      : 1;
    uint32_t opcode : 7;
};

struct j_type {
    uint32_t a      : 1;
    uint32_t imm_lo : 10;
    uint32_t b      : 1;
    uint32_t imm_hi : 8;
    uint32_t rd     : 5;
    uint32_t opcode : 7;
};

struct instruction_t {
    type_t t;
    union {
        r_type   r;
        i_type   i;
        s_type   s;
        u_type   u;
        b_type   b;
        j_type   j;
        uint32_t value;
    };
};

#endif  // SRC_ASM_HPP_