asm: make use regular asserts that will just work on baremetal

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.
This commit is contained in:
Ciro Santilli 六四事件 法轮功
2019-05-23 00:00:00 +00:00
parent 72200dee4e
commit c8c4f89854
90 changed files with 1003 additions and 978 deletions

View File

@@ -1,8 +1,8 @@
/* https://github.com/cirosantilli/linux-kernel-module-cheat#arm-ldr-instruction-pseudo-instruction */
#include "common.h"
#include <lkmc.h>
LKMC_ENTRY
LKMC_PROLOGUE
/* Mnemonic for a PC relative load:
*
@@ -12,13 +12,13 @@ LKMC_ENTRY
* ....
*/
ldr r0, myvar
LKMC_ASSERT_EQ(r0, 0x12345678)
LKMC_ASSERT_EQ(r0, =0x12345678)
/* Mnemonic PC relative load with an offset.
* Load myvar2 instead of myvar.
*/
ldr r0, myvar + 4
LKMC_ASSERT_EQ(r0, 0x9ABCDEF0)
LKMC_ASSERT_EQ(r0, =0x9ABCDEF0)
/* First store the address in r0 using a magic =myvar, which creates
* a new variable containing the address and PC-relative addresses it
@@ -33,17 +33,17 @@ LKMC_ENTRY
*/
ldr r0, =myvar
ldr r1, [r0]
LKMC_ASSERT_EQ(r1, 0x12345678)
LKMC_ASSERT_EQ(r1, =0x12345678)
/* More efficiently, use r0 as the address to read, and write to r0 itself. */
ldr r0, =myvar
ldr r0, [r0]
LKMC_ASSERT_EQ(r0, 0x12345678)
LKMC_ASSERT_EQ(r0, =0x12345678)
/* Same as =myvar but store a constant to a register.
* Can also be done with movw and movt. */
ldr r0, =0x11112222
LKMC_ASSERT_EQ(r0, 0x11112222)
LKMC_ASSERT_EQ(r0, =0x11112222)
/* We can also use GAS tolower16 and topper16 and movw and movt
* to load the address of myvar into r0 with two immediates.
@@ -56,9 +56,9 @@ LKMC_ENTRY
movw r0, #:lower16:myvar
movt r0, #:upper16:myvar
ldr r1, [r0]
LKMC_ASSERT_EQ(r1, 0x12345678)
LKMC_ASSERT_EQ(r1, =0x12345678)
LKMC_EXIT
LKMC_EPILOGUE
myvar:
.word 0x12345678
myvar2: