Skip to content

Commit b696a0f

Browse files
aswatermanJJ-Gaisler
authored andcommitted
Fix pointer masking for misaligned accesses
Pointer masking needs to be reapplied after computing the address of the tail of a misaligned access in case there's a carry-out into the MSBs. Resolves #1895
1 parent 78ac785 commit b696a0f

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

riscv/mmu.cc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,10 @@ void mmu_t::load_slow_path(reg_t original_addr, reg_t len, uint8_t* bytes, xlate
241241

242242
reg_t len_page0 = std::min(len, PGSIZE - transformed_addr % PGSIZE);
243243
load_slow_path_intrapage(len_page0, bytes, access_info);
244-
if (len_page0 != len)
245-
load_slow_path_intrapage(len - len_page0, bytes + len_page0, access_info.split_misaligned_access(len_page0));
244+
if (len_page0 != len) {
245+
auto tail_access_info = generate_access_info(original_addr + len_page0, LOAD, xlate_flags);
246+
load_slow_path_intrapage(len - len_page0, bytes + len_page0, tail_access_info);
247+
}
246248
}
247249

248250
while (len > sizeof(reg_t)) {
@@ -306,8 +308,10 @@ void mmu_t::store_slow_path(reg_t original_addr, reg_t len, const uint8_t* bytes
306308

307309
reg_t len_page0 = std::min(len, PGSIZE - transformed_addr % PGSIZE);
308310
store_slow_path_intrapage(len_page0, bytes, access_info, actually_store);
309-
if (len_page0 != len)
310-
store_slow_path_intrapage(len - len_page0, bytes + len_page0, access_info.split_misaligned_access(len_page0), actually_store);
311+
if (len_page0 != len) {
312+
auto tail_access_info = generate_access_info(original_addr + len_page0, STORE, xlate_flags);
313+
store_slow_path_intrapage(len - len_page0, bytes + len_page0, tail_access_info, actually_store);
314+
}
311315
} else {
312316
store_slow_path_intrapage(len, bytes, access_info, actually_store);
313317
}

riscv/mmu.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,6 @@ struct mem_access_info_t {
5757
const bool effective_virt;
5858
const xlate_flags_t flags;
5959
const access_type type;
60-
61-
mem_access_info_t split_misaligned_access(reg_t offset) const {
62-
return {vaddr + offset, transformed_vaddr + offset, effective_priv, effective_virt, flags, type};
63-
}
6460
};
6561

6662
void throw_access_exception(bool virt, reg_t addr, access_type type);

0 commit comments

Comments
 (0)