[gem5-dev] [S] Change in gem5/gem5[develop]: arch-riscv: Fix the address check of pmp

2023-04-11 Thread Roger Chang (Gerrit) via gem5-dev
Roger Chang has submitted this change. (  
https://gem5-review.googlesource.com/c/public/gem5/+/69577?usp=email )


Change subject: arch-riscv: Fix the address check of pmp
..

arch-riscv: Fix the address check of pmp

Fix the AddrRange of pmp region. the contains of AddrRange(start, end)
will be valid if the address y is in start <= y < end. It should not
minus 1 in end parameter.

Change-Id: I1a0eb51f2d5881b8aa90d310884922b16f2019fb
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/69577
Tested-by: kokoro 
Maintainer: Bobby Bruce 
Reviewed-by: Yu-hsin Wang 
---
M src/arch/riscv/pmp.cc
1 file changed, 6 insertions(+), 6 deletions(-)

Approvals:
  Yu-hsin Wang: Looks good to me, approved
  kokoro: Regressions pass
  Bobby Bruce: Looks good to me, approved




diff --git a/src/arch/riscv/pmp.cc b/src/arch/riscv/pmp.cc
index 49dc7ba..6275104 100644
--- a/src/arch/riscv/pmp.cc
+++ b/src/arch/riscv/pmp.cc
@@ -83,9 +83,9 @@
 for (int i = 0; i < pmpTable.size(); i++) {
 AddrRange pmp_range = pmpTable[i].pmpAddr;
 if (pmp_range.contains(req->getPaddr()) &&
-pmp_range.contains(req->getPaddr() + req->getSize())) {
+pmp_range.contains(req->getPaddr() + req->getSize() - 1)) {
 // according to specs address is only matched,
-// when (addr) and (addr + request_size) are both
+// when (addr) and (addr + request_size - 1) are both
 // within the pmp range
 match_index = i;
 }
@@ -197,11 +197,11 @@
 break;
   case PMP_TOR:
 // top of range mode
-this_range = AddrRange(prevAddr << 2, (this_addr << 2) - 1);
+this_range = AddrRange(prevAddr << 2, (this_addr << 2));
 break;
   case PMP_NA4:
 // naturally aligned four byte region
-this_range = AddrRange(this_addr << 2, (this_addr + 4) - 1);
+this_range = AddrRange(this_addr << 2, ((this_addr << 2) + 4));
 break;
   case PMP_NAPOT:
 // naturally aligned power of two region, >= 8 bytes
@@ -246,7 +246,7 @@
 }

 DPRINTF(PMP, "Update pmp addr %#x for pmp entry %u \n",
-  this_addr, pmp_index);
+  (this_addr << 2), pmp_index);

 if (pmpTable[pmp_index].pmpCfg & PMP_LOCK) {
 DPRINTF(PMP, "Update pmp entry %u failed because the lock bit  
set\n",

@@ -303,7 +303,7 @@
 return this_range;
 } else {
 uint64_t t1 = ctz64(~pmpaddr);
-uint64_t range = (std::pow(2,t1+3))-1;
+uint64_t range = (1ULL << (t1+3));

 // pmpaddr reg encodes bits 55-2 of a
 // 56 bit physical address for RV64

--
To view, visit  
https://gem5-review.googlesource.com/c/public/gem5/+/69577?usp=email
To unsubscribe, or for help writing mail filters, visit  
https://gem5-review.googlesource.com/settings


Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I1a0eb51f2d5881b8aa90d310884922b16f2019fb
Gerrit-Change-Number: 69577
Gerrit-PatchSet: 3
Gerrit-Owner: Roger Chang 
Gerrit-Reviewer: Ayaz Akram 
Gerrit-Reviewer: Bobby Bruce 
Gerrit-Reviewer: Hoa Nguyen 
Gerrit-Reviewer: Jui-min Lee 
Gerrit-Reviewer: Roger Chang 
Gerrit-Reviewer: Yu-hsin Wang 
Gerrit-Reviewer: kokoro 
Gerrit-MessageType: merged
___
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org


[gem5-dev] [S] Change in gem5/gem5[develop]: arch-riscv: Fix the address check of pmp

2023-04-09 Thread Roger Chang (Gerrit) via gem5-dev
Roger Chang has uploaded this change for review. (  
https://gem5-review.googlesource.com/c/public/gem5/+/69577?usp=email )



Change subject: arch-riscv: Fix the address check of pmp
..

arch-riscv: Fix the address check of pmp

Fix the AddrRange of pmp region. the contains of AddrRange(start, end)
will be valid if the address y is in start <= y < end. It should not
minus 1 in end parameter.

Change-Id: I1a0eb51f2d5881b8aa90d310884922b16f2019fb
---
M src/arch/riscv/pmp.cc
1 file changed, 5 insertions(+), 5 deletions(-)



diff --git a/src/arch/riscv/pmp.cc b/src/arch/riscv/pmp.cc
index 49dc7ba..636ea89 100644
--- a/src/arch/riscv/pmp.cc
+++ b/src/arch/riscv/pmp.cc
@@ -83,9 +83,9 @@
 for (int i = 0; i < pmpTable.size(); i++) {
 AddrRange pmp_range = pmpTable[i].pmpAddr;
 if (pmp_range.contains(req->getPaddr()) &&
-pmp_range.contains(req->getPaddr() + req->getSize())) {
+pmp_range.contains(req->getPaddr() + req->getSize() - 1)) {
 // according to specs address is only matched,
-// when (addr) and (addr + request_size) are both
+// when (addr) and (addr + request_size - 1) are both
 // within the pmp range
 match_index = i;
 }
@@ -197,11 +197,11 @@
 break;
   case PMP_TOR:
 // top of range mode
-this_range = AddrRange(prevAddr << 2, (this_addr << 2) - 1);
+this_range = AddrRange(prevAddr << 2, (this_addr << 2));
 break;
   case PMP_NA4:
 // naturally aligned four byte region
-this_range = AddrRange(this_addr << 2, (this_addr + 4) - 1);
+this_range = AddrRange(this_addr << 2, (this_addr + 4));
 break;
   case PMP_NAPOT:
 // naturally aligned power of two region, >= 8 bytes
@@ -303,7 +303,7 @@
 return this_range;
 } else {
 uint64_t t1 = ctz64(~pmpaddr);
-uint64_t range = (std::pow(2,t1+3))-1;
+uint64_t range = (std::pow(2,t1+3));

 // pmpaddr reg encodes bits 55-2 of a
 // 56 bit physical address for RV64

--
To view, visit  
https://gem5-review.googlesource.com/c/public/gem5/+/69577?usp=email
To unsubscribe, or for help writing mail filters, visit  
https://gem5-review.googlesource.com/settings


Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I1a0eb51f2d5881b8aa90d310884922b16f2019fb
Gerrit-Change-Number: 69577
Gerrit-PatchSet: 1
Gerrit-Owner: Roger Chang 
Gerrit-MessageType: newchange
___
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org