[PATCH v2 02/22] ARM: add self test for runtime patch mechanism
From: Nicolas Pitre <hidden>
Date: 2012-08-13 03:19:52
Also in:
lkml
On Sun, 12 Aug 2012, Cyril Chemparathy wrote:
On 08/11/12 22:35, Nicolas Pitre wrote:quoted
On Fri, 10 Aug 2012, Cyril Chemparathy wrote:quoted
This patch adds basic sanity tests to ensure that the instruction patching results in valid instruction encodings. This is done by verifying the output of the patch process against a vector of assembler generated instructions at init time. Signed-off-by: Cyril Chemparathy <redacted> ---[...]quoted
quoted
+ __asm__ __volatile__ ( + " .irp shift1, 0, 6, 12, 18\n" + " .irp shift2, 0, 1, 2, 3, 4, 5\n" + " add r1, r2, #(0x41 << (\\shift1 + \\shift2))\n" + " .endr\n" + " .endr\n"Maybe adding a "add r1, r2 #0x81 << 24" here might be a good thing since this is the most used case but missing from the above.Indeed. I've now replaced this with something a bit more extensive. Does the following look better? +struct patch_test_imm8 { + u16 imm; + u16 shift; + u32 insn; +}; + +static void __init __used __naked __patch_test_code_imm8(void) +{ + __asm__ __volatile__ ( + + /* a single test case */ + " .macro test_one, imm, sft\n" + " .hword \\imm\n" + " .hword \\sft\n" + " add r1, r2, #(\\imm << \\sft)\n" + " .endm\n" + + /* a sequence of tests at 'inc' increments of shift */ + " .macro test_seq, imm, sft, max, inc\n" + " test_one \\imm, \\sft\n" + " .if \\sft < \\max\n" + " test_seq \\imm, (\\sft + \\inc), \\max, \\inc\n" + " .endif\n" + " .endm\n" + + /* an empty record to mark the end */ + " .macro test_end\n" + " .hword 0, 0\n" + " .word 0\n" + " .endm\n" + + /* finally generate the test sequences */ + " test_seq 0x41, 0, 24, 1\n" + " test_seq 0x81, 0, 24, 2\n" + " test_end\n" + : : : + ); +}
Yes, this is certainly quite extensive. :-) Nicolas