Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
target/riscv: Make translator stop before the end of a page
Right now the translator stops right *after* the end of a page, which breaks reporting of fault locations when the last instruction of a multi-insn translation block crosses a page boundary. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1155 Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Acked-by: Ilya Leoshkevich <iii@linux.ibm.com> Tested-by: Ilya Leoshkevich <iii@linux.ibm.com> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
- Loading branch information
Showing
3 changed files
with
93 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
|
||
VPATH += $(SRC_PATH)/tests/tcg/riscv64 | ||
TESTS += test-div | ||
TESTS += noexec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#include "../multiarch/noexec.c.inc" | ||
|
||
static void *arch_mcontext_pc(const mcontext_t *ctx) | ||
{ | ||
return (void *)ctx->__gregs[REG_PC]; | ||
} | ||
|
||
static int arch_mcontext_arg(const mcontext_t *ctx) | ||
{ | ||
return ctx->__gregs[REG_A0]; | ||
} | ||
|
||
static void arch_flush(void *p, int len) | ||
{ | ||
__builtin___clear_cache(p, p + len); | ||
} | ||
|
||
extern char noexec_1[]; | ||
extern char noexec_2[]; | ||
extern char noexec_end[]; | ||
|
||
asm(".option push\n" | ||
".option norvc\n" | ||
"noexec_1:\n" | ||
" li a0,1\n" /* a0 is 0 on entry, set 1. */ | ||
"noexec_2:\n" | ||
" li a0,2\n" /* a0 is 0/1; set 2. */ | ||
" ret\n" | ||
"noexec_end:\n" | ||
".option pop"); | ||
|
||
int main(void) | ||
{ | ||
struct noexec_test noexec_tests[] = { | ||
{ | ||
.name = "fallthrough", | ||
.test_code = noexec_1, | ||
.test_len = noexec_end - noexec_1, | ||
.page_ofs = noexec_1 - noexec_2, | ||
.entry_ofs = noexec_1 - noexec_2, | ||
.expected_si_ofs = 0, | ||
.expected_pc_ofs = 0, | ||
.expected_arg = 1, | ||
}, | ||
{ | ||
.name = "jump", | ||
.test_code = noexec_1, | ||
.test_len = noexec_end - noexec_1, | ||
.page_ofs = noexec_1 - noexec_2, | ||
.entry_ofs = 0, | ||
.expected_si_ofs = 0, | ||
.expected_pc_ofs = 0, | ||
.expected_arg = 0, | ||
}, | ||
{ | ||
.name = "fallthrough [cross]", | ||
.test_code = noexec_1, | ||
.test_len = noexec_end - noexec_1, | ||
.page_ofs = noexec_1 - noexec_2 - 2, | ||
.entry_ofs = noexec_1 - noexec_2 - 2, | ||
.expected_si_ofs = 0, | ||
.expected_pc_ofs = -2, | ||
.expected_arg = 1, | ||
}, | ||
{ | ||
.name = "jump [cross]", | ||
.test_code = noexec_1, | ||
.test_len = noexec_end - noexec_1, | ||
.page_ofs = noexec_1 - noexec_2 - 2, | ||
.entry_ofs = -2, | ||
.expected_si_ofs = 0, | ||
.expected_pc_ofs = -2, | ||
.expected_arg = 0, | ||
}, | ||
}; | ||
|
||
return test_noexec(noexec_tests, | ||
sizeof(noexec_tests) / sizeof(noexec_tests[0])); | ||
} |