summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Norton2016-05-04 13:31:31 +0100
committerRobert Norton2016-05-04 13:31:31 +0100
commitd26a230b63e5e6ba528d3d5930521d23c8bdd727 (patch)
treef7962289a933b53d276cbcf1a53c9239864484b5
parent87c56d3a270c4f7cf151a5e2519227bc80ee29b9 (diff)
check for PC alignment on instruction fetch.
-rw-r--r--cheri/cheri_prelude.sail4
-rw-r--r--mips/mips_wrappers.sail5
2 files changed, 7 insertions, 2 deletions
diff --git a/cheri/cheri_prelude.sail b/cheri/cheri_prelude.sail
index 8fa3b180..7853caad 100644
--- a/cheri/cheri_prelude.sail
+++ b/cheri/cheri_prelude.sail
@@ -412,7 +412,9 @@ function (bit[64]) TranslateAddress ((bit[64]) vAddr, (MemAccessType) accessType
let (bit[64]) base = x[127..64] in
let (bit[64]) length = x[63..0] in
let (bit[64]) absPC = (base + vAddr) in
- if ((unsigned(vAddr) + 4) > unsigned(length)) then
+ if (absPC[1..0] != 0b00) then (* bad PC alignment *)
+ exit (SignalExceptionBadAddr(AdEL, absPC))
+ else if ((unsigned(vAddr) + 4) > unsigned(length)) then
exit (raise_c2_exception_noreg(CapEx_LengthViolation)) (* XXX take exception properly *)
else
TLBTranslate(absPC, accessType)
diff --git a/mips/mips_wrappers.sail b/mips/mips_wrappers.sail
index 8fe1b4d4..25b8936b 100644
--- a/mips/mips_wrappers.sail
+++ b/mips/mips_wrappers.sail
@@ -6,7 +6,10 @@ function bit[64] addrWrapper((bit[64]) addr, (MemAccessType) accessType, (WordTy
addr
function (bit[64]) TranslateAddress ((bit[64]) vAddr, (MemAccessType) accessType) =
- TLBTranslate(vAddr, accessType)
+ if (vAddr[1..0] != 0b00) then (* bad PC alignment *)
+ exit (SignalExceptionBadAddr(AdEL, vAddr))
+ else
+ TLBTranslate(vAddr, accessType)
function unit SignalException ((Exception) ex) = SignalExceptionMIPS(ex)