arm64: perf: Prevent wraparound during overflow
[linux-2.6-block.git] / arch / arm64 / include / asm / alternative.h
CommitLineData
e039ee4e
AP
1#ifndef __ASM_ALTERNATIVE_H
2#define __ASM_ALTERNATIVE_H
3
4#include <linux/types.h>
5#include <linux/stddef.h>
6#include <linux/stringify.h>
7
8struct alt_instr {
9 s32 orig_offset; /* offset to original instruction */
10 s32 alt_offset; /* offset to replacement instruction */
11 u16 cpufeature; /* cpufeature bit set for replacement */
12 u8 orig_len; /* size of original instruction(s) */
13 u8 alt_len; /* size of new instruction(s), <= orig_len */
14};
15
16void apply_alternatives(void);
17void free_alternatives_memory(void);
18
19#define ALTINSTR_ENTRY(feature) \
20 " .word 661b - .\n" /* label */ \
21 " .word 663f - .\n" /* new instruction */ \
22 " .hword " __stringify(feature) "\n" /* feature bit */ \
23 " .byte 662b-661b\n" /* source len */ \
24 " .byte 664f-663f\n" /* replacement len */
25
26/* alternative assembly primitive: */
27#define ALTERNATIVE(oldinstr, newinstr, feature) \
28 "661:\n\t" \
29 oldinstr "\n" \
30 "662:\n" \
31 ".pushsection .altinstructions,\"a\"\n" \
32 ALTINSTR_ENTRY(feature) \
33 ".popsection\n" \
34 ".pushsection .altinstr_replacement, \"a\"\n" \
35 "663:\n\t" \
36 newinstr "\n" \
37 "664:\n\t" \
38 ".popsection\n\t" \
39 ".if ((664b-663b) != (662b-661b))\n\t" \
40 " .error \"Alternatives instruction length mismatch\"\n\t"\
41 ".endif\n"
42
43#endif /* __ASM_ALTERNATIVE_H */