Closed TommyMurphyTM1234 closed 4 months ago
If .balign 16
means 'align to next 16 byte border', this should ensure that if the sequence occurs right at the end of a virtual memory page it is moved at the beginning of next page.
Thanks @ilg-ul - so the value of 16 comes from the fact that the semihosting instruction sequence is 16 bytes long (4 x 32-bit wide instructions)? Or is it 12 bytes long? Which is the actual authoritative/canonical sequence - this:
slli x0, x0, 0x1f # 0x01f01013 Entry NOP
ebreak # 0x00100073 Break to debugger
srai x0, x0, 7 # 0x40705013 NOP encoding the semihosting call number 7
or this:
slli zero, zero, 0x1f
ebreak
srai zero, zero, 0x7
ret
The constraint is that the entire breakpoint sequence must be present at the same time in memory, so that the debugger can inspect the memory and identify if the call is a semihosting breakpoint.
In this case the 3 instructions must be in the same virtual memory page. 16 is 12 rounded up.
As for the second question, as far as I remember, the ret
is not part of the mandatory sequence, which must not be a separate function, it can be a macro inlined in as many places as necessary.
I added a separate post with an example of actual code: https://github.com/riscv-non-isa/riscv-semihosting/issues/20.
I believe comments from @ilg-ul already explain why .balign 16
is needed hence closing this issue.
Why
.balign 16
?