mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
asm: make all text section labels .L local
To help with backtraces if we ever fix them due to the lkmc_asm_main_after_prologue debacle.
This commit is contained in:
@@ -15,7 +15,7 @@ LKMC_PROLOGUE
|
|||||||
mrs x1, mpidr_el1
|
mrs x1, mpidr_el1
|
||||||
ands x1, x1, 3
|
ands x1, x1, 3
|
||||||
beq cpu0_only
|
beq cpu0_only
|
||||||
cpu1_only:
|
.Lcpu1_only:
|
||||||
/* Only CPU 1 reaches this point and sets the spinlock. */
|
/* Only CPU 1 reaches this point and sets the spinlock. */
|
||||||
mov x0, 1
|
mov x0, 1
|
||||||
ldr x1, =spinlock
|
ldr x1, =spinlock
|
||||||
@@ -28,12 +28,12 @@ cpu1_only:
|
|||||||
* Optional, but could save power on a real system.
|
* Optional, but could save power on a real system.
|
||||||
*/
|
*/
|
||||||
sev
|
sev
|
||||||
cpu1_sleep_forever:
|
.Lcpu1_sleep_forever:
|
||||||
/* Hint CPU 1 to enter low power mode.
|
/* Hint CPU 1 to enter low power mode.
|
||||||
* Optional, but could save power on a real system.
|
* Optional, but could save power on a real system.
|
||||||
*/
|
*/
|
||||||
wfe
|
wfe
|
||||||
b cpu1_sleep_forever
|
b .Lcpu1_sleep_forever
|
||||||
cpu0_only:
|
cpu0_only:
|
||||||
/* Only CPU 0 reaches this point. */
|
/* Only CPU 0 reaches this point. */
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ cpu0_only:
|
|||||||
/* Argument 1: target_cpu */
|
/* Argument 1: target_cpu */
|
||||||
mov x1, 1
|
mov x1, 1
|
||||||
/* Argument 2: entry_point_address */
|
/* Argument 2: entry_point_address */
|
||||||
ldr x2, =cpu1_only
|
ldr x2, =.Lcpu1_only
|
||||||
/* Argument 3: context_id */
|
/* Argument 3: context_id */
|
||||||
mov x3, 0
|
mov x3, 0
|
||||||
/* Unused hvc args: the Linux kernel zeroes them,
|
/* Unused hvc args: the Linux kernel zeroes them,
|
||||||
|
|||||||
@@ -10,21 +10,21 @@ LKMC_PROLOGUE
|
|||||||
mrc p15, 0, r1, c0, c0, 5
|
mrc p15, 0, r1, c0, c0, 5
|
||||||
ands r1, r1, 3
|
ands r1, r1, 3
|
||||||
beq cpu0_only
|
beq cpu0_only
|
||||||
cpu1_only:
|
.Lcpu1_only:
|
||||||
mov r0, 1
|
mov r0, 1
|
||||||
ldr r1, =spinlock
|
ldr r1, =spinlock
|
||||||
str r0, [r1]
|
str r0, [r1]
|
||||||
dmb sy
|
dmb sy
|
||||||
sev
|
sev
|
||||||
cpu1_sleep_forever:
|
.Lcpu1_sleep_forever:
|
||||||
wfe
|
wfe
|
||||||
b cpu1_sleep_forever
|
b .Lcpu1_sleep_forever
|
||||||
cpu0_only:
|
cpu0_only:
|
||||||
#if !LKMC_GEM5
|
#if !LKMC_GEM5
|
||||||
/* PSCI CPU_ON. */
|
/* PSCI CPU_ON. */
|
||||||
ldr r0, =0x84000003
|
ldr r0, =0x84000003
|
||||||
mov r1, 1
|
mov r1, 1
|
||||||
ldr r2, =cpu1_only
|
ldr r2, =.Lcpu1_only
|
||||||
mov r3, 0
|
mov r3, 0
|
||||||
hvc 0
|
hvc 0
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -16,6 +16,5 @@ LKMC_PROLOGUE
|
|||||||
*/
|
*/
|
||||||
adr x0, data_label
|
adr x0, data_label
|
||||||
ldr x1, =data_label
|
ldr x1, =data_label
|
||||||
label:
|
|
||||||
LKMC_ASSERT_EQ_REG(x0, x1)
|
LKMC_ASSERT_EQ_REG(x0, x1)
|
||||||
LKMC_EPILOGUE
|
LKMC_EPILOGUE
|
||||||
|
|||||||
@@ -3,9 +3,9 @@
|
|||||||
#include <lkmc.h>
|
#include <lkmc.h>
|
||||||
|
|
||||||
LKMC_PROLOGUE
|
LKMC_PROLOGUE
|
||||||
adrp x0, label
|
adrp x0, .Llabel
|
||||||
adr x1, label
|
adr x1, .Llabel
|
||||||
label:
|
.Llabel:
|
||||||
/* Clear the lower 12 bits. */
|
/* Clear the lower 12 bits. */
|
||||||
bic x1, x1, 0xFF
|
bic x1, x1, 0xFF
|
||||||
bic x1, x1, 0xF00
|
bic x1, x1, 0xF00
|
||||||
|
|||||||
@@ -6,14 +6,13 @@ LKMC_PROLOGUE
|
|||||||
|
|
||||||
/* Branch. */
|
/* Branch. */
|
||||||
mov x0, 0x0
|
mov x0, 0x0
|
||||||
cbz x0, ok
|
cbz x0, .Lok
|
||||||
LKMC_ASSERT_FAIL
|
LKMC_ASSERT_FAIL
|
||||||
ok:
|
.Lok:
|
||||||
|
|
||||||
/* Don't branch. */
|
/* Don't branch. */
|
||||||
mov x0, 0x1
|
mov x0, 0x1
|
||||||
cbz x0, ko
|
cbz x0, .Lko
|
||||||
|
|
||||||
LKMC_EPILOGUE
|
LKMC_EPILOGUE
|
||||||
ko:
|
.Lko:
|
||||||
LKMC_ASSERT_FAIL
|
LKMC_ASSERT_FAIL
|
||||||
|
|||||||
@@ -17,10 +17,10 @@ LKMC_PROLOGUE
|
|||||||
* This could be used if the label is too far away for
|
* This could be used if the label is too far away for
|
||||||
* adr relative addressing.
|
* adr relative addressing.
|
||||||
*/
|
*/
|
||||||
movz x0, :abs_g2:label /* bits 32-47, overflow check */
|
movz x0, :abs_g2:.Llabel /* bits 32-47, overflow check */
|
||||||
movk x0, :abs_g1_nc:label /* bits 16-31, no overflow check */
|
movk x0, :abs_g1_nc:.Llabel /* bits 16-31, no overflow check */
|
||||||
movk x0, :abs_g0_nc:label /* bits 0-15, no overflow check */
|
movk x0, :abs_g0_nc:.Llabel /* bits 0-15, no overflow check */
|
||||||
adr x1, label
|
adr x1, .Llabel
|
||||||
label:
|
.Llabel:
|
||||||
LKMC_ASSERT_EQ_REG(x0, x1)
|
LKMC_ASSERT_EQ_REG(x0, x1)
|
||||||
LKMC_EPILOGUE
|
LKMC_EPILOGUE
|
||||||
|
|||||||
@@ -27,11 +27,11 @@ LKMC_PROLOGUE
|
|||||||
* "LDR (literal)" instead of "LDR (immediate)":
|
* "LDR (literal)" instead of "LDR (immediate)":
|
||||||
* https://stackoverflow.com/questions/28638981/howto-write-pc-relative-adressing-on-arm-asm/54480999#54480999
|
* https://stackoverflow.com/questions/28638981/howto-write-pc-relative-adressing-on-arm-asm/54480999#54480999
|
||||||
*/
|
*/
|
||||||
ldr x0, pc_relative_ldr
|
ldr x0, .Lpc_relative_ldr
|
||||||
b 1f
|
b 2f
|
||||||
pc_relative_ldr:
|
.Lpc_relative_ldr:
|
||||||
.quad 0x123456789ABCDEF0
|
.quad 0x123456789ABCDEF0
|
||||||
1:
|
2:
|
||||||
LKMC_ASSERT_EQ(x0, =0x123456789ABCDEF0)
|
LKMC_ASSERT_EQ(x0, =0x123456789ABCDEF0)
|
||||||
|
|
||||||
/* Just for fun, we can also use relative numbers instead of labels.
|
/* Just for fun, we can also use relative numbers instead of labels.
|
||||||
@@ -68,7 +68,7 @@ pc_relative_ldr:
|
|||||||
ldr x0, pc_relative_str
|
ldr x0, pc_relative_str
|
||||||
LKMC_ASSERT_EQ(x0, =0x0)
|
LKMC_ASSERT_EQ(x0, =0x0)
|
||||||
adr x1, pc_relative_str
|
adr x1, pc_relative_str
|
||||||
ldr x0, pc_relative_ldr
|
ldr x0, .Lpc_relative_ldr
|
||||||
str x0, [x1]
|
str x0, [x1]
|
||||||
ldr x0, pc_relative_str
|
ldr x0, pc_relative_str
|
||||||
LKMC_ASSERT_EQ(x0, =0x123456789ABCDEF0)
|
LKMC_ASSERT_EQ(x0, =0x123456789ABCDEF0)
|
||||||
|
|||||||
@@ -6,14 +6,14 @@
|
|||||||
data_label:
|
data_label:
|
||||||
.word 0x1234678
|
.word 0x1234678
|
||||||
LKMC_PROLOGUE
|
LKMC_PROLOGUE
|
||||||
adr r4, label
|
adr r4, .Llabel
|
||||||
/* objdump tells us that this uses the literal pool,
|
/* objdump tells us that this uses the literal pool,
|
||||||
* it does not get converted to adr, which is the better
|
* it does not get converted to adr, which is the better
|
||||||
* alternative here.
|
* alternative here.
|
||||||
*/
|
*/
|
||||||
ldr r5, =label
|
ldr r5, =.Llabel
|
||||||
adrl r6, label
|
adrl r6, .Llabel
|
||||||
label:
|
.Llabel:
|
||||||
LKMC_ASSERT_EQ_REG(r4, r5)
|
LKMC_ASSERT_EQ_REG(r4, r5)
|
||||||
LKMC_ASSERT_EQ_REG(r4, r6)
|
LKMC_ASSERT_EQ_REG(r4, r6)
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
#include <lkmc.h>
|
#include <lkmc.h>
|
||||||
LKMC_PROLOGUE
|
LKMC_PROLOGUE
|
||||||
/* Jump over the fail. 26-bit PC-relative. */
|
/* Jump over the fail. 26-bit PC-relative. */
|
||||||
b ok
|
b .Lok
|
||||||
LKMC_ASSERT_FAIL
|
LKMC_ASSERT_FAIL
|
||||||
ok:
|
.Lok:
|
||||||
LKMC_EPILOGUE
|
LKMC_EPILOGUE
|
||||||
|
|||||||
@@ -48,7 +48,6 @@ LKMC_PROLOGUE
|
|||||||
10:
|
10:
|
||||||
|
|
||||||
/* Another example with mov reading from pc. */
|
/* Another example with mov reading from pc. */
|
||||||
pc_addr:
|
|
||||||
mov r0, pc
|
mov r0, pc
|
||||||
/* Why sub 8:
|
/* Why sub 8:
|
||||||
* https://stackoverflow.com/questions/24091566/why-does-the-arm-pc-register-point-to-the-instruction-after-the-next-one-to-be-e
|
* https://stackoverflow.com/questions/24091566/why-does-the-arm-pc-register-point-to-the-instruction-after-the-next-one-to-be-e
|
||||||
|
|||||||
@@ -46,8 +46,8 @@ LKMC_PROLOGUE
|
|||||||
* This construct is not possible in ARMv8 for str:
|
* This construct is not possible in ARMv8 for str:
|
||||||
* https://github.com/cirosantilli/linux-kernel-module-cheat#armv8-aarch64-str-instruction
|
* https://github.com/cirosantilli/linux-kernel-module-cheat#armv8-aarch64-str-instruction
|
||||||
*/
|
*/
|
||||||
str r1, var_in_same_section
|
str r1, .Lvar_in_same_section
|
||||||
var_in_same_section:
|
.Lvar_in_same_section:
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* = sign just doesn't make sense for str, you can't set the
|
/* = sign just doesn't make sense for str, you can't set the
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
#include <lkmc.h>
|
#include <lkmc.h>
|
||||||
|
|
||||||
LKMC_PROLOGUE
|
LKMC_PROLOGUE
|
||||||
jmp after_fail
|
jmp .Lafter_fail
|
||||||
LKMC_ASSERT_FAIL
|
LKMC_ASSERT_FAIL
|
||||||
after_fail:
|
.Lafter_fail:
|
||||||
LKMC_EPILOGUE
|
LKMC_EPILOGUE
|
||||||
|
|||||||
@@ -8,15 +8,15 @@
|
|||||||
LKMC_PROLOGUE
|
LKMC_PROLOGUE
|
||||||
/* Address in memory. */
|
/* Address in memory. */
|
||||||
.section .rodata
|
.section .rodata
|
||||||
label_address: .quad memory_label
|
label_address: .quad .Lmemory_label
|
||||||
.text
|
.text
|
||||||
jmp *label_address
|
jmp *label_address
|
||||||
LKMC_ASSERT_FAIL
|
LKMC_ASSERT_FAIL
|
||||||
memory_label:
|
.Lmemory_label:
|
||||||
|
|
||||||
/* Address in register. */
|
/* Address in register. */
|
||||||
lea register_label(%rip), %rax
|
lea .Lregister_label(%rip), %rax
|
||||||
jmp *%rax
|
jmp *%rax
|
||||||
LKMC_ASSERT_FAIL
|
LKMC_ASSERT_FAIL
|
||||||
register_label:
|
.Lregister_label:
|
||||||
LKMC_EPILOGUE
|
LKMC_EPILOGUE
|
||||||
|
|||||||
@@ -13,9 +13,9 @@ LKMC_PROLOGUE
|
|||||||
*/
|
*/
|
||||||
mov $0, %rax
|
mov $0, %rax
|
||||||
mov $3, %rcx
|
mov $3, %rcx
|
||||||
loop_label:
|
.Lloop_label:
|
||||||
inc %rax
|
inc %rax
|
||||||
loop loop_label
|
loop .Lloop_label
|
||||||
LKMC_ASSERT_EQ(%rax, $3)
|
LKMC_ASSERT_EQ(%rax, $3)
|
||||||
|
|
||||||
/* LOOPE
|
/* LOOPE
|
||||||
@@ -37,10 +37,10 @@ loop_label:
|
|||||||
/* Array length. */
|
/* Array length. */
|
||||||
mov $4, %rcx
|
mov $4, %rcx
|
||||||
mov $-1, %rax
|
mov $-1, %rax
|
||||||
loope_label:
|
.Lloope_label:
|
||||||
inc %rax
|
inc %rax
|
||||||
cmpb $0, loope_array(%rax)
|
cmpb $0, loope_array(%rax)
|
||||||
loope loope_label
|
loope .Lloope_label
|
||||||
/* The first non-zero item (1) was at index 2. */
|
/* The first non-zero item (1) was at index 2. */
|
||||||
LKMC_ASSERT_EQ(%rax, $2)
|
LKMC_ASSERT_EQ(%rax, $2)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user