Skip to content

Commit b5679a8

Browse files
committed
Xqccmp extension: Add stack exceptions and stack exceptions checks to IDL code of push/pop instructions
Signed-off-by: Albert Yosher <[email protected]>
1 parent bcf60bf commit b5679a8

File tree

6 files changed

+54
-1
lines changed

6 files changed

+54
-1
lines changed

cfgs/qc_iu/arch_overlay/ext/Xqccmp.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,18 @@ versions:
4343
4444
changes:
4545
- Fix qc.cm.pushfp instruction to avoid rlist == 4, since not saving s0 == fp but updating it, should not occur
46+
- Add list of supported custom exceptions - stack alignment check and stack range check
47+
- Add stack exception checks in all push/pop instructions
4648
requires:
4749
name: Zca
4850
version: ">= 1.0.0"
51+
exception_codes:
52+
- num: 27
53+
name: Illegal Stack Pointer
54+
var: IllegalStackPointer
55+
- num: 28
56+
name: Stack Pointer Out-Of-Range
57+
var: SpOutOfRange
4958
description: |
5059
The Xqccmp extension is a set of instructions which may be executed as a series of existing 32-bit RISC-V instructions.
5160

cfgs/qc_iu/arch_overlay/inst/Xqccmp/qc.cm.pop.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ operation(): |
4040
if (implemented?(ExtensionName::Xqccmp) && (CSR[misa].C == 1'b0)) {
4141
raise(ExceptionCode::IllegalInstruction, mode(), $encoding);
4242
}
43+
if (X[2] < CSR[qc.mstkbottomaddr]) {
44+
raise(ExceptionCode::SpOutOfRange, mode(), $encoding);
45+
}
46+
if (X[2] > CSR[qc.mstktopaddr]) {
47+
raise(ExceptionCode::SpOutOfRange, mode(), $encoding);
48+
}
49+
if (X[2] & 0xf != 0) {
50+
raise(ExceptionCode::IllegalStackPointer, mode(), $encoding);
51+
}
4352
4453
XReg size = xlen();
4554
XReg nreg = (rlist == 15) ? 13 : (rlist - 3);

cfgs/qc_iu/arch_overlay/inst/Xqccmp/qc.cm.popret.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ operation(): |
4040
if (implemented?(ExtensionName::Xqccmp) && (CSR[misa].C == 1'b0)) {
4141
raise(ExceptionCode::IllegalInstruction, mode(), $encoding);
4242
}
43+
if (X[2] < CSR[qc.mstkbottomaddr]) {
44+
raise(ExceptionCode::SpOutOfRange, mode(), $encoding);
45+
}
46+
if (X[2] > CSR[qc.mstktopaddr]) {
47+
raise(ExceptionCode::SpOutOfRange, mode(), $encoding);
48+
}
49+
if (X[2] & 0xf != 0) {
50+
raise(ExceptionCode::IllegalStackPointer, mode(), $encoding);
51+
}
4352
4453
XReg size = xlen();
4554
XReg nreg = (rlist == 15) ? 13 : (rlist - 3);

cfgs/qc_iu/arch_overlay/inst/Xqccmp/qc.cm.popretz.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ operation(): |
4040
if (implemented?(ExtensionName::Xqccmp) && (CSR[misa].C == 1'b0)) {
4141
raise(ExceptionCode::IllegalInstruction, mode(), $encoding);
4242
}
43+
if (X[2] < CSR[qc.mstkbottomaddr]) {
44+
raise(ExceptionCode::SpOutOfRange, mode(), $encoding);
45+
}
46+
if (X[2] > CSR[qc.mstktopaddr]) {
47+
raise(ExceptionCode::SpOutOfRange, mode(), $encoding);
48+
}
49+
if (X[2] & 0xf != 0) {
50+
raise(ExceptionCode::IllegalStackPointer, mode(), $encoding);
51+
}
4352
4453
XReg size = xlen();
4554
XReg nreg = (rlist == 15) ? 13 : (rlist - 3);
@@ -48,7 +57,6 @@ operation(): |
4857
XReg virtual_address_new_sp = virtual_address_sp + stack_aligned_adj + spimm;
4958
XReg virtual_address_base = virtual_address_new_sp - size;
5059
51-
5260
X[ 1] = read_memory_xlen(virtual_address_base - 0*size, $encoding);
5361
if (nreg > 1) {
5462
X[ 8] = read_memory_xlen(virtual_address_base - 1*size, $encoding);

cfgs/qc_iu/arch_overlay/inst/Xqccmp/qc.cm.push.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ operation(): |
4242
if (implemented?(ExtensionName::Xqccmp) && (CSR[misa].C == 1'b0)) {
4343
raise(ExceptionCode::IllegalInstruction, mode(), $encoding);
4444
}
45+
if (X[2] < CSR[qc.mstkbottomaddr]) {
46+
raise(ExceptionCode::SpOutOfRange, mode(), $encoding);
47+
}
48+
if (X[2] > CSR[qc.mstktopaddr]) {
49+
raise(ExceptionCode::SpOutOfRange, mode(), $encoding);
50+
}
51+
if (X[2] & 0xf != 0) {
52+
raise(ExceptionCode::IllegalStackPointer, mode(), $encoding);
53+
}
4554
4655
XReg size = xlen();
4756
XReg nreg = (rlist == 15) ? 13 : (rlist - 3);

cfgs/qc_iu/arch_overlay/inst/Xqccmp/qc.cm.pushfp.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ operation(): |
4242
if (implemented?(ExtensionName::Xqccmp) && (CSR[misa].C == 1'b0)) {
4343
raise(ExceptionCode::IllegalInstruction, mode(), $encoding);
4444
}
45+
if (X[2] < CSR[qc.mstkbottomaddr]) {
46+
raise(ExceptionCode::SpOutOfRange, mode(), $encoding);
47+
}
48+
if (X[2] > CSR[qc.mstktopaddr]) {
49+
raise(ExceptionCode::SpOutOfRange, mode(), $encoding);
50+
}
51+
if (X[2] & 0xf != 0) {
52+
raise(ExceptionCode::IllegalStackPointer, mode(), $encoding);
53+
}
4554
4655
XReg size = xlen();
4756
XReg nreg = (rlist == 15) ? 13 : (rlist - 3);

0 commit comments

Comments
 (0)