Files
linux-kernel-module-cheat/userland/arch/arm/str.S
Ciro Santilli 六四事件 法轮功 5f935ee53d readme: verify all non-README links with asciidoctor/extract-header-ids and git grep
Fix all the ~30 failures it found!
2019-06-09 00:00:00 +00:00

61 lines
1.5 KiB
ArmAsm

/* https://github.com/cirosantilli/linux-kernel-module-cheat#arm-str-instruction */
#include <lkmc.h>
.data;
/* Must be in the .data section, since we want to modify it. */
myvar:
.word 0x12345678
LKMC_PROLOGUE
/* Sanity check. */
ldr r0, =myvar
ldr r1, [r0]
movw r2, 0x5678
movt r2, 0x1234
LKMC_ASSERT_EQ_REG(r1, r2)
/* Modify the value. */
ldr r0, =myvar
movw r1, 0xDEF0
movt r1, 0x9ABC
str r1, [r0]
/* Check that it changed. */
ldr r0, =myvar
ldr r1, [r0]
movw r2, 0xDEF0
movt r2, 0x9ABC
LKMC_ASSERT_EQ_REG(r1, r2)
/* Cannot use PC relative addressing to a different segment,
* or else it fails with:
*
* ....
* Error: internal_relocation (type: OFFSET_IMM) not fixed up
* ....
*
* https://stackoverflow.com/questions/10094282/internal-relocation-not-fixed-up
*/
/*ldr r0, myvar*/
#if 0
/* We could in theory write this to set the address of myvar,
* but it will always segfault under Linux because the text segment is read-only.
* This is however useful in baremetal programming.
* This construct is not possible in ARMv8 for str:
* https://github.com/cirosantilli/linux-kernel-module-cheat#armv8-aarch64-str-instruction
*/
str r1, var_in_same_section
var_in_same_section:
#endif
/* = sign just doesn't make sense for str, you can't set the
* address of a variable.
*/
#if 0
str r1, =myvar
#endif
LKMC_EPILOGUE