Skip to content

Commit

Permalink
Add overload operators for virtaddr
Browse files Browse the repository at this point in the history
Add a subtraction operator overload for `virtaddr` and use it in the CMO code.
  • Loading branch information
trdthg authored Jan 14, 2025
1 parent ff4077c commit fca81a3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions model/prelude_mem_addrtype.sail
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ newtype virtaddr = virtaddr : xlenbits
function physaddr_bits(physaddr(paddr) : physaddr) -> physaddrbits = paddr

function virtaddr_bits(virtaddr(vaddr) : virtaddr) -> xlenbits = vaddr

function sub_virtaddr_xlenbits(virtaddr(addr) : virtaddr, offset : xlenbits) -> virtaddr = virtaddr(addr - offset)

overload operator - = { sub_virtaddr_xlenbits }
2 changes: 1 addition & 1 deletion model/riscv_insts_zicbom.sail
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function process_clean_inval(rs1, cbop) = {
};
// Errors report the address that was encoded in the instruction rather
// than the address that caused the fault (i.e. the aligned address).
handle_mem_exception(virtaddr(virtaddr_bits(vaddr) - offset), e);
handle_mem_exception(vaddr - offset, e);
RETIRE_FAIL
}
}
Expand Down
2 changes: 1 addition & 1 deletion model/riscv_insts_zicboz.sail
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function clause execute(RISCV_ZICBOZ(rs1)) = {
MemException(e) => {
// Errors report the address that was encoded in the instruction rather
// than the address that caused the fault (i.e. the aligned address).
handle_mem_exception(virtaddr(virtaddr_bits(vaddr) - offset), e);
handle_mem_exception(vaddr - offset, e);
RETIRE_FAIL
},
}
Expand Down

0 comments on commit fca81a3

Please sign in to comment.