mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
Previously had wonky line pointer in asm_main. New interface simpler and more portable. Add tests for ASSERT_EQ_ and family in arm and aarch64, previously on x86_64. ASSERT_EQ_ and family in ARM can now either take =123, =addr or var, before this the = was added on macros so var was not possible. Define the main function directly in assembly, the C driver was useless.
52 lines
1.3 KiB
ArmAsm
52 lines
1.3 KiB
ArmAsm
/* https://github.com/cirosantilli/linux-kernel-module-cheat#armv8-aarch64-x31-register */
|
|
|
|
#include <lkmc.h>
|
|
|
|
LKMC_PROLOGUE
|
|
/* ERROR: can never use the name x31. */
|
|
#if 0
|
|
mov x31, 31
|
|
#endif
|
|
|
|
/* mov (register) is an alias for ORR, which accepts xzr. */
|
|
mov x19, 1
|
|
mov x19, xzr
|
|
LKMC_ASSERT_EQ(x19, =0)
|
|
|
|
/* Same encoding as the mov version. */
|
|
mov x19, 1
|
|
orr x19, xzr, xzr
|
|
LKMC_ASSERT_EQ(x19, =0)
|
|
|
|
/* So, orr, which is not an alias, can only take xzr, not sp. */
|
|
#if 0
|
|
orr sp, sp, sp
|
|
#endif
|
|
|
|
/* Zero register discards result if written to. */
|
|
mov x19, 1
|
|
orr xzr, x19, x19
|
|
LKMC_ASSERT_EQ(xzr, =0)
|
|
|
|
/* MOV (to/from SP) is an alias for ADD (immediate). */
|
|
mov x19, sp
|
|
mov sp, 1
|
|
/* Alias to add. */
|
|
mov x20, sp
|
|
/* Exact same encoding as above. */
|
|
add x20, sp, 0
|
|
mov sp, x19
|
|
LKMC_ASSERT_EQ(x20, =1)
|
|
|
|
/* So, ADD (immediate), which is not an alias, can only take sp, not xzr. */
|
|
#if 0
|
|
/* Error: integer register expected in the extended/shifted operand register at operand 3 -- `add xzr,xzr,1' */
|
|
add xzr, xzr, 1
|
|
#endif
|
|
|
|
/* Note however that ADD (register), unlike ADD (immediate),
|
|
* does not say anything about SP, and so does accept xzr just fine.
|
|
*/
|
|
add xzr, xzr, xzr
|
|
LKMC_EPILOGUE
|