Skip to content

Commit 7751fbc

Browse files
stephanosiocarlescufi
authored andcommitted
arch: riscv: Align semihost_exec function at 16-byte boundary
QEMU requires that the semihosting trap instruction sequence, which consists of three uncompressed instructions, lie in the same page, and refuses to interpret the trap sequence if these instructions are placed across two different pages. This commit adds 16-byte alignment requirement to the `semihost_exec` function, which occupies 12 bytes, to ensure that the three trap sequence instructions in this function are never placed across two different pages. Signed-off-by: Stephanos Ioannidis <[email protected]>
1 parent 56d67df commit 7751fbc

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

arch/riscv/core/semihost.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,20 @@
55
* SPDX-License-Identifier: Apache-2.0
66
*/
77

8+
#include <zephyr/toolchain.h>
89
#include <zephyr/arch/common/semihost.h>
910

10-
long semihost_exec(enum semihost_instr instr, void *args)
11+
/*
12+
* QEMU requires that the semihosting trap instruction sequence, consisting of
13+
* three uncompressed instructions, lie in the same page, and refuses to
14+
* interpret the trap sequence if these instructions are placed across two
15+
* different pages.
16+
*
17+
* The `semihost_exec` function, which occupies 12 bytes, is aligned at a
18+
* 16-byte boundary to ensure that the three trap sequence instructions are
19+
* never placed across two different pages.
20+
*/
21+
long __aligned(16) semihost_exec(enum semihost_instr instr, void *args)
1122
{
1223
register unsigned long a0 __asm__ ("a0") = instr;
1324
register void *a1 __asm__ ("a1") = args;

0 commit comments

Comments
 (0)