arm: signed LDR example with LDRSW

This commit is contained in:
Ciro Santilli 六四事件 法轮功
2019-08-25 00:00:00 +00:00
parent 0acff266e2
commit 6dfc95d73a
2 changed files with 34 additions and 0 deletions

View File

@@ -14696,6 +14696,10 @@ There are LDR variants that load less than full 4 bytes:
* link:userland/arch/arm/ldrb.S[]: load byte * link:userland/arch/arm/ldrb.S[]: load byte
* link:userland/arch/arm/ldrh.S[]: load half word * link:userland/arch/arm/ldrh.S[]: load half word
These also have signed and unsigned versions to either zero or one extend the result:
* link:userland/arch/aarch64/ldrsw.S[]: load byte and sign extend
==== ARM STR instruction ==== ARM STR instruction
Store from memory into registers. Store from memory into registers.

View File

@@ -0,0 +1,30 @@
/* https://cirosantilli.com/linux-kernel-module-cheat#arm-ldrh-and-ldrb-instructions */
#include <lkmc.h>
LKMC_PROLOGUE
ldr x19, =zero_extend
mov x0, 0x0
ldr w0, [x19]
LKMC_ASSERT_EQ(x0, =0x0000000012345678)
mov x0, 0x0
ldrsw x0, [x19]
LKMC_ASSERT_EQ(x0, =0x0000000012345678)
ldr x19, =one_extend
mov x0, 0x0
ldr w0, [x19]
LKMC_ASSERT_EQ(x0, =0x0000000082345678)
mov x0, 0x0
ldrsw x0, [x19]
LKMC_ASSERT_EQ(x0, =0xFFFFFFFF82345678)
LKMC_EPILOGUE
zero_extend:
.word 0x12345678
one_extend:
.word 0x82345678