Skip to content

Commit 8490cb2

Browse files
authored
Merge branch 'main' into ext_impl_csr
2 parents 8cdd931 + 5e2d93c commit 8490cb2

File tree

634 files changed

+44117
-207
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

634 files changed

+44117
-207
lines changed

arch/crd/MC-1.yaml

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -77,59 +77,4 @@ MC-1:
7777
const: little
7878
XLEN:
7979
schema:
80-
const: 32
81-
82-
requirement_groups:
83-
- name: MC-Unpriv
84-
description: |
85-
The MC-Unpriv defines unprivileged ISA requirements.
86-
Note that unprivileged ISA features are those that are usable in all privilege modes;
87-
they aren't only usable in U-mode (User-mode).
88-
It is unfortunate that both “Unprivileged” and “User” start with the letter “U” but they
89-
aren't the same thing.
90-
91-
requirements:
92-
- name: REQ-UINST-001
93-
description: Should use little-endian byte order
94-
95-
- name: REQ-UCSR-001-a
96-
description: Should raise an Illegal Instruction exception when writing to the `cycle` CSR
97-
98-
- name: REQ-UCSR-001-b
99-
description: Should return the XLEN least-significant bits of the `mcycle` CSR when reading the `cycle` CSR
100-
101-
- name: REQ-UCSR-002-a
102-
description: Should raise an Illegal Instruction exception when writing to the `time` CSR
103-
104-
- name: REQ-UCSR-002-b
105-
description: Should return the XLEN least-significant bits of the `mtime` CSR when reading the `time` CSR
106-
when:
107-
param:
108-
TIME_CSR_IMPLEMENTED: true
109-
110-
- name: REQ-UCSR-002-c
111-
description: Should raise an Illegal Instruction exception when reading the `time` CSR
112-
when:
113-
param:
114-
TIME_CSR_IMPLEMENTED: false
115-
116-
- name: MC-Unpriv-32
117-
when:
118-
xlen: 32
119-
description: |
120-
The MC-Unpriv-32 defines unprivileged ISA requirements specific to 32-bit processors.
121-
requirements:
122-
- name: REQ-M32CSR-001-a
123-
description: Should raise an illegal instruction trap when writing the 'cycleh' CSR
124-
- name: REQ-M32CSR-001-b
125-
description: Should return the most-significant 32-bits of the `mcycle` CSR when reading `cycleh`
126-
- name: REQ-M32CSR-002
127-
description: Should return the most-significant 32-bits of the `minstret` CSR when reading `instreth`
128-
129-
- name: MC-Priv
130-
description: |
131-
The MC-Priv defines Privileged ISA requirements.
132-
requirements:
133-
- name: REQ-PRIV-HARTID
134-
description: |
135-
One hart in system has to have a HARTID of 0. Reading `mhartid` on other CSRs provides some value.
80+
const: 32

arch/csr/mip.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ mip:
55
address: 0x344
66
priv_mode: M
77
description: Machine Interrupt Pending bits
8-
length: 64
8+
length: MXLEN
99
definedBy: Sm
1010
fields:
1111
SSIP:

arch/csr/mscratch.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ mscratch:
44
long_name: Machine Scratch Register
55
address: 0x340
66
priv_mode: M
7-
length: 64
7+
length: MXLEN
88
description: Scratch register for software use. Bits are not interpreted by hardware.
9-
definedBy: U # actually, defined by RV64, but must implement U-mode for this CSR to exist
9+
definedBy: Sm
1010
fields:
1111
SCRATCH:
12-
location: 63-0
12+
location_rv32: 31-0
13+
location_rv64: 63-0
1314
description: Scratch value
1415
type: RW
1516
reset_value: 0

arch/csr/mtval.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ mtval:
55
address: 0x343
66
description: Holds trap-specific information
77
priv_mode: M
8-
length: 64
8+
length: MXLEN
99
definedBy: Sm
1010
fields:
1111
VALUE:
12-
location: 63-0
12+
location_rv32: 31-0
13+
location_rv64: 63-0
1314
description: |
1415
Written with trap-specific information when a trap is taken into M-mode.
1516

arch/ext/Sm.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ Sm:
231231
description: |
232232
Does the implementation perform non-atomic misaligned loads and stores to main memory
233233
(does *not* affect misaligned support to device memory)?
234-
If not, the implementation throws a misaligned exception.
234+
If not, the implementation always throws a misaligned exception.
235235
schema:
236236
type: boolean
237237
MISALIGNED_LDST_EXCEPTION_PRIORITY:
@@ -247,21 +247,21 @@ Sm:
247247
! high ! Misaligned load/store/AMO exceptions are always higher priority than load/store/AMO page-fault and access-fault exceptions.
248248
!===
249249
250-
MISALIGNED_LDST_EXCEPTION_PRIORITY cannot be "high" when MAX_MISALIGNED_ATOMICITY_GRANULE_SIZE
250+
MISALIGNED_LDST_EXCEPTION_PRIORITY cannot be "high" when MISALIGNED_MAX_ATOMICITY_GRANULE_SIZE
251251
is non-zero, since the atomicity of an access cannot be determined in that case until after
252252
address translation.
253253
schema:
254254
type: string
255255
enum: ["low", "high"]
256256
extra_validation: |
257-
assert (MISALIGNED_LDST_EXCEPTION_PRIORITY == "low") if MAX_MISALIGNED_ATOMICITY_GRANULE_SIZE.positive?
258-
MAX_MISALIGNED_ATOMICITY_GRANULE_SIZE:
257+
assert (MISALIGNED_LDST_EXCEPTION_PRIORITY == "low") if MISALIGNED_MAX_ATOMICITY_GRANULE_SIZE.positive?
258+
MISALIGNED_MAX_ATOMICITY_GRANULE_SIZE:
259259
description: |
260260
The maximum granule size, in bytes, that the hart can atomically perform a
261-
misaligned load/store/AMO without raising a Misaligned exception. When MAX_MISALIGNED_ATOMICITY_GRANULE_SIZE is 0, the hart
261+
misaligned load/store/AMO without raising a Misaligned exception. When MISALIGNED_MAX_ATOMICITY_GRANULE_SIZE is 0, the hart
262262
cannot atomically perform a misaligned load/store/AMO. When a power of two, the hart can
263263
atomically load/store/AMO a misaligned access that is fully contained in a
264-
MAX_MISALIGNED_ATOMICITY_GRANULE_SIZE-aligned region.
264+
MISALIGNED_MAX_ATOMICITY_GRANULE_SIZE-aligned region.
265265
266266
[NOTE]
267267
Even if the hart is capable of performing a misaligned load/store/AMO atomically,

arch/ext/V.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# yaml-language-server: $schema=../../schemas/ext_schema.json
2+
3+
V:
4+
type: unprivileged
5+
long_name: Variable-length vector
6+
versions:
7+
- version: "1.0.0"
8+
state: ratified
9+
ratification_date: null
10+
description: |
11+
TODO
12+
params:
13+
MUTABLE_MISA_V:
14+
description: |
15+
Indicates whether or not the `V` extension can be disabled with the `misa.V` bit.
16+
schema:
17+
type: boolean

arch/inst/A/amoadd.d.yaml

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,192 @@ amoadd.d:
4141
XReg virtual_address = X[rs1];
4242
4343
X[rd] = amo<64>(virtual_address, X[rs2], AmoOperation::Add, aq, rl, $encoding);
44+
45+
46+
47+
sail(): |
48+
{
49+
if extension("A") then {
50+
/* Get the address, X(rs1) (no offset).
51+
* Some extensions perform additional checks on address validity.
52+
*/
53+
match ext_data_get_addr(rs1, zeros(), ReadWrite(Data, Data), width) {
54+
Ext_DataAddr_Error(e) => { ext_handle_data_check_error(e); RETIRE_FAIL },
55+
Ext_DataAddr_OK(vaddr) => {
56+
match translateAddr(vaddr, ReadWrite(Data, Data)) {
57+
TR_Failure(e, _) => { handle_mem_exception(vaddr, e); RETIRE_FAIL },
58+
TR_Address(addr, _) => {
59+
let eares : MemoryOpResult(unit) = match (width, sizeof(xlen)) {
60+
(BYTE, _) => mem_write_ea(addr, 1, aq & rl, rl, true),
61+
(HALF, _) => mem_write_ea(addr, 2, aq & rl, rl, true),
62+
(WORD, _) => mem_write_ea(addr, 4, aq & rl, rl, true),
63+
(DOUBLE, 64) => mem_write_ea(addr, 8, aq & rl, rl, true),
64+
_ => internal_error(__FILE__, __LINE__, "Unexpected AMO width")
65+
};
66+
let is_unsigned : bool = match op {
67+
AMOMINU => true,
68+
AMOMAXU => true,
69+
_ => false
70+
};
71+
let rs2_val : xlenbits = match width {
72+
BYTE => if is_unsigned then zero_extend(X(rs2)[7..0]) else sign_extend(X(rs2)[7..0]),
73+
HALF => if is_unsigned then zero_extend(X(rs2)[15..0]) else sign_extend(X(rs2)[15..0]),
74+
WORD => if is_unsigned then zero_extend(X(rs2)[31..0]) else sign_extend(X(rs2)[31..0]),
75+
DOUBLE => X(rs2)
76+
};
77+
match (eares) {
78+
MemException(e) => { handle_mem_exception(vaddr, e); RETIRE_FAIL },
79+
MemValue(_) => {
80+
let mval : MemoryOpResult(xlenbits) = match (width, sizeof(xlen)) {
81+
(BYTE, _) => extend_value(is_unsigned, mem_read(ReadWrite(Data, Data), addr, 1, aq, aq & rl, true)),
82+
(HALF, _) => extend_value(is_unsigned, mem_read(ReadWrite(Data, Data), addr, 2, aq, aq & rl, true)),
83+
(WORD, _) => extend_value(is_unsigned, mem_read(ReadWrite(Data, Data), addr, 4, aq, aq & rl, true)),
84+
(DOUBLE, 64) => extend_value(is_unsigned, mem_read(ReadWrite(Data, Data), addr, 8, aq, aq & rl, true)),
85+
_ => internal_error(__FILE__, __LINE__, "Unexpected AMO width")
86+
};
87+
match (mval) {
88+
MemException(e) => { handle_mem_exception(vaddr, e); RETIRE_FAIL },
89+
MemValue(loaded) => {
90+
let result : xlenbits =
91+
match op {
92+
AMOSWAP => rs2_val,
93+
AMOADD => rs2_val + loaded,
94+
AMOXOR => rs2_val ^ loaded,
95+
AMOAND => rs2_val & loaded,
96+
AMOOR => rs2_val | loaded,
97+
98+
/* These operations convert bitvectors to integer values using [un]signed,
99+
* and back using to_bits().
100+
*/
101+
AMOMIN => to_bits(sizeof(xlen), min(signed(rs2_val), signed(loaded))),
102+
AMOMAX => to_bits(sizeof(xlen), max(signed(rs2_val), signed(loaded))),
103+
AMOMINU => to_bits(sizeof(xlen), min(unsigned(rs2_val), unsigned(loaded))),
104+
AMOMAXU => to_bits(sizeof(xlen), max(unsigned(rs2_val), unsigned(loaded)))
105+
};
106+
let rval : xlenbits = match width {
107+
BYTE => sign_extend(loaded[7..0]),
108+
HALF => sign_extend(loaded[15..0]),
109+
WORD => sign_extend(loaded[31..0]),
110+
DOUBLE => loaded
111+
};
112+
let wval : MemoryOpResult(bool) = match (width, sizeof(xlen)) {
113+
(BYTE, _) => mem_write_value(addr, 1, result[7..0], aq & rl, rl, true),
114+
(HALF, _) => mem_write_value(addr, 2, result[15..0], aq & rl, rl, true),
115+
(WORD, _) => mem_write_value(addr, 4, result[31..0], aq & rl, rl, true),
116+
(DOUBLE, 64) => mem_write_value(addr, 8, result, aq & rl, rl, true),
117+
_ => internal_error(__FILE__, __LINE__, "Unexpected AMO width")
118+
};
119+
match (wval) {
120+
MemValue(true) => { X(rd) = rval; RETIRE_SUCCESS },
121+
MemValue(false) => { internal_error(__FILE__, __LINE__, "AMO got false from mem_write_value") },
122+
MemException(e) => { handle_mem_exception(vaddr, e); RETIRE_FAIL }
123+
}
124+
}
125+
}
126+
}
127+
}
128+
}
129+
}
130+
}
131+
}
132+
} else {
133+
handle_illegal();
134+
RETIRE_FAIL
135+
}
136+
}
137+
138+
139+
140+
141+
sail(): |
142+
{
143+
if extension("A") then {
144+
/* Get the address, X(rs1) (no offset).
145+
* Some extensions perform additional checks on address validity.
146+
*/
147+
match ext_data_get_addr(rs1, zeros(), ReadWrite(Data, Data), width) {
148+
Ext_DataAddr_Error(e) => { ext_handle_data_check_error(e); RETIRE_FAIL },
149+
Ext_DataAddr_OK(vaddr) => {
150+
match translateAddr(vaddr, ReadWrite(Data, Data)) {
151+
TR_Failure(e, _) => { handle_mem_exception(vaddr, e); RETIRE_FAIL },
152+
TR_Address(addr, _) => {
153+
let eares : MemoryOpResult(unit) = match (width, sizeof(xlen)) {
154+
(BYTE, _) => mem_write_ea(addr, 1, aq & rl, rl, true),
155+
(HALF, _) => mem_write_ea(addr, 2, aq & rl, rl, true),
156+
(WORD, _) => mem_write_ea(addr, 4, aq & rl, rl, true),
157+
(DOUBLE, 64) => mem_write_ea(addr, 8, aq & rl, rl, true),
158+
_ => internal_error(__FILE__, __LINE__, "Unexpected AMO width")
159+
};
160+
let is_unsigned : bool = match op {
161+
AMOMINU => true,
162+
AMOMAXU => true,
163+
_ => false
164+
};
165+
let rs2_val : xlenbits = match width {
166+
BYTE => if is_unsigned then zero_extend(X(rs2)[7..0]) else sign_extend(X(rs2)[7..0]),
167+
HALF => if is_unsigned then zero_extend(X(rs2)[15..0]) else sign_extend(X(rs2)[15..0]),
168+
WORD => if is_unsigned then zero_extend(X(rs2)[31..0]) else sign_extend(X(rs2)[31..0]),
169+
DOUBLE => X(rs2)
170+
};
171+
match (eares) {
172+
MemException(e) => { handle_mem_exception(vaddr, e); RETIRE_FAIL },
173+
MemValue(_) => {
174+
let mval : MemoryOpResult(xlenbits) = match (width, sizeof(xlen)) {
175+
(BYTE, _) => extend_value(is_unsigned, mem_read(ReadWrite(Data, Data), addr, 1, aq, aq & rl, true)),
176+
(HALF, _) => extend_value(is_unsigned, mem_read(ReadWrite(Data, Data), addr, 2, aq, aq & rl, true)),
177+
(WORD, _) => extend_value(is_unsigned, mem_read(ReadWrite(Data, Data), addr, 4, aq, aq & rl, true)),
178+
(DOUBLE, 64) => extend_value(is_unsigned, mem_read(ReadWrite(Data, Data), addr, 8, aq, aq & rl, true)),
179+
_ => internal_error(__FILE__, __LINE__, "Unexpected AMO width")
180+
};
181+
match (mval) {
182+
MemException(e) => { handle_mem_exception(vaddr, e); RETIRE_FAIL },
183+
MemValue(loaded) => {
184+
let result : xlenbits =
185+
match op {
186+
AMOSWAP => rs2_val,
187+
AMOADD => rs2_val + loaded,
188+
AMOXOR => rs2_val ^ loaded,
189+
AMOAND => rs2_val & loaded,
190+
AMOOR => rs2_val | loaded,
191+
192+
/* These operations convert bitvectors to integer values using [un]signed,
193+
* and back using to_bits().
194+
*/
195+
AMOMIN => to_bits(sizeof(xlen), min(signed(rs2_val), signed(loaded))),
196+
AMOMAX => to_bits(sizeof(xlen), max(signed(rs2_val), signed(loaded))),
197+
AMOMINU => to_bits(sizeof(xlen), min(unsigned(rs2_val), unsigned(loaded))),
198+
AMOMAXU => to_bits(sizeof(xlen), max(unsigned(rs2_val), unsigned(loaded)))
199+
};
200+
let rval : xlenbits = match width {
201+
BYTE => sign_extend(loaded[7..0]),
202+
HALF => sign_extend(loaded[15..0]),
203+
WORD => sign_extend(loaded[31..0]),
204+
DOUBLE => loaded
205+
};
206+
let wval : MemoryOpResult(bool) = match (width, sizeof(xlen)) {
207+
(BYTE, _) => mem_write_value(addr, 1, result[7..0], aq & rl, rl, true),
208+
(HALF, _) => mem_write_value(addr, 2, result[15..0], aq & rl, rl, true),
209+
(WORD, _) => mem_write_value(addr, 4, result[31..0], aq & rl, rl, true),
210+
(DOUBLE, 64) => mem_write_value(addr, 8, result, aq & rl, rl, true),
211+
_ => internal_error(__FILE__, __LINE__, "Unexpected AMO width")
212+
};
213+
match (wval) {
214+
MemValue(true) => { X(rd) = rval; RETIRE_SUCCESS },
215+
MemValue(false) => { internal_error(__FILE__, __LINE__, "AMO got false from mem_write_value") },
216+
MemException(e) => { handle_mem_exception(vaddr, e); RETIRE_FAIL }
217+
}
218+
}
219+
}
220+
}
221+
}
222+
}
223+
}
224+
}
225+
}
226+
} else {
227+
handle_illegal();
228+
RETIRE_FAIL
229+
}
230+
}
231+
232+

0 commit comments

Comments
 (0)