blob: b8f3ca679e5e8ce1e02330722da40c9581ac4351 (
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
(** RV32I (and RV64I) ***********************************************)
| 'l' (('b'|'h') as width) ("u"? as u) (".aq"? as aq) (".rl"? as rl) as load
{ if (rl = ".rl") && not (aq = ".aq") then failwith ("'" ^ load ^ "' is not a valid instruction") else
LOAD { width = (match width with 'b' -> RISCVBYTE | 'h' -> RISCVHALF | _ -> failwith "bad width");
unsigned = (u = "u");
aq = (aq = ".aq");
rl = (rl = ".rl");
}
}
| "lw" (".aq"? as aq) (".rl"? as rl) as load
{ if (rl = ".rl") && not (aq = ".aq") then failwith ("'" ^ load ^ "' is not a valid instruction") else
LOAD { width = RISCVWORD;
unsigned = false;
aq = (aq = ".aq");
rl = (rl = ".rl");
}
}
| 's' (('b'|'h'|'w') as width) (".aq"? as aq) (".rl"? as rl) as store
{ if (aq = ".aq") && not (rl = ".rl") then failwith ("'" ^ store ^ "' is not a valid instruction") else
STORE { width = (match width with 'b' -> RISCVBYTE | 'h' -> RISCVHALF | 'w' -> RISCVWORD | _ -> failwith "bad width");
aq = (aq = ".aq");
rl = (rl = ".rl");
}
}
(** RV64I (in addition to RV32I) ************************************)
| "lwu" (".aq"? as aq) (".rl"? as rl) as load
{ if (rl = ".rl") && not (aq = ".aq") then failwith ("'" ^ load ^ "' is not a valid instruction") else
LOAD { width = RISCVWORD;
unsigned = true;
aq = (aq = ".aq");
rl = (rl = ".rl");
}
}
| "ld" (".aq"? as aq) (".rl"? as rl) as load
{ if (rl = ".rl") && not (aq = ".aq") then failwith ("'" ^ load ^ "' is not a valid instruction") else
LOAD { width = RISCVDOUBLE;
unsigned = false;
aq = (aq = ".aq");
rl = (rl = ".rl");
}
}
| "sd" (".aq"? as aq) (".rl"? as rl) as store
{ if (aq = ".aq") && not (rl = ".rl") then failwith ("'" ^ store ^ "' is not a valid instruction") else
STORE { width = RISCVDOUBLE;
aq = (aq = ".aq");
rl = (rl = ".rl");
}
}
(** RV32A (and RV64A) ***********************************************)
| "lr.w" (".aq"? as aq) (".rl"? as rl) as lr
{ if (rl = ".rl") && not (aq = ".aq") then failwith ("'" ^ lr ^ "' is not a valid instruction") else
LOADRES { width = RISCVWORD;
aq = (aq = ".aq");
rl = (rl = ".rl");
}
}
| "sc.w" (".aq"? as aq) (".rl"? as rl) as sc
{ if (aq = ".aq") && not (rl = ".rl") then failwith ("'" ^ sc ^ "' is not a valid instruction") else
STORECON { width = RISCVWORD;
aq = (aq = ".aq");
rl = (rl = ".rl");
}
}
| "amo" (("swap"|"add"|"and"|"or"|"xor"|"max"|"min"|"maxu"|"minu") as op) ".w" (".aq"? as aq) (".rl"? as rl)
{ AMO { op =
begin match op with
| "swap" -> RISCVAMOSWAP;
| "add" -> RISCVAMOADD;
| "and" -> RISCVAMOAND;
| "or" -> RISCVAMOOR;
| "xor" -> RISCVAMOXOR;
| "max" -> RISCVAMOMAX;
| "min" -> RISCVAMOMIN;
| "maxu" -> RISCVAMOMAXU;
| "minu" -> RISCVAMOMINU;
| _ -> failwith "bad amo"
end;
width = RISCVWORD;
aq = (aq = ".aq");
rl = (rl = ".rl");
}
}
(** RV64A (in addition to RV32A) ************************************)
| "lr.d" (".aq"? as aq) (".rl"? as rl) as lr
{ if (rl = ".rl") && not (aq = ".aq") then failwith ("'" ^ lr ^ "' is not a valid instruction") else
LOADRES { width = RISCVDOUBLE;
aq = (aq = ".aq");
rl = (rl = ".rl");
}
}
| "sc.d" (".aq"? as aq) (".rl"? as rl) as sc
{ if (aq = ".aq") && not (rl = ".rl") then failwith ("'" ^ sc ^ "' is not a valid instruction") else
STORECON { width = RISCVDOUBLE;
aq = (aq = ".aq");
rl = (rl = ".rl");
}
}
| "amo" (("swap"|"add"|"and"|"or"|"xor"|"max"|"min"|"maxu"|"minu") as op) ".d" (".aq"? as aq) (".rl"? as rl)
{ AMO { op =
begin match op with
| "swap" -> RISCVAMOSWAP;
| "add" -> RISCVAMOADD;
| "and" -> RISCVAMOAND;
| "or" -> RISCVAMOOR;
| "xor" -> RISCVAMOXOR;
| "max" -> RISCVAMOMAX;
| "min" -> RISCVAMOMIN;
| "maxu" -> RISCVAMOMAXU;
| "minu" -> RISCVAMOMINU;
| _ -> failwith "bad amo"
end;
width = RISCVDOUBLE;
aq = (aq = ".aq");
rl = (rl = ".rl");
}
}
|