|
| 1 | +/* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | +#ifndef _ASM_X86_NOPS_H |
| 3 | +#define _ASM_X86_NOPS_H |
| 4 | + |
| 5 | +/* |
| 6 | + * Define nops for use with alternative() and for tracing. |
| 7 | + */ |
| 8 | + |
| 9 | +#ifndef CONFIG_64BIT |
| 10 | + |
| 11 | +/* |
| 12 | + * Generic 32bit nops from GAS: |
| 13 | + * |
| 14 | + * 1: nop |
| 15 | + * 2: movl %esi,%esi |
| 16 | + * 3: leal 0x0(%esi),%esi |
| 17 | + * 4: leal 0x0(%esi,%eiz,1),%esi |
| 18 | + * 5: leal %ds:0x0(%esi,%eiz,1),%esi |
| 19 | + * 6: leal 0x0(%esi),%esi |
| 20 | + * 7: leal 0x0(%esi,%eiz,1),%esi |
| 21 | + * 8: leal %ds:0x0(%esi,%eiz,1),%esi |
| 22 | + * |
| 23 | + * Except 5 and 8, which are DS prefixed 4 and 7 resp, where GAS would emit 2 |
| 24 | + * nop instructions. |
| 25 | + */ |
| 26 | +#define BYTES_NOP1 0x90 |
| 27 | +#define BYTES_NOP2 0x89,0xf6 |
| 28 | +#define BYTES_NOP3 0x8d,0x76,0x00 |
| 29 | +#define BYTES_NOP4 0x8d,0x74,0x26,0x00 |
| 30 | +#define BYTES_NOP5 0x3e,BYTES_NOP4 |
| 31 | +#define BYTES_NOP6 0x8d,0xb6,0x00,0x00,0x00,0x00 |
| 32 | +#define BYTES_NOP7 0x8d,0xb4,0x26,0x00,0x00,0x00,0x00 |
| 33 | +#define BYTES_NOP8 0x3e,BYTES_NOP7 |
| 34 | + |
| 35 | +#else |
| 36 | + |
| 37 | +/* |
| 38 | + * Generic 64bit nops from GAS: |
| 39 | + * |
| 40 | + * 1: nop |
| 41 | + * 2: osp nop |
| 42 | + * 3: nopl (%eax) |
| 43 | + * 4: nopl 0x00(%eax) |
| 44 | + * 5: nopl 0x00(%eax,%eax,1) |
| 45 | + * 6: osp nopl 0x00(%eax,%eax,1) |
| 46 | + * 7: nopl 0x00000000(%eax) |
| 47 | + * 8: nopl 0x00000000(%eax,%eax,1) |
| 48 | + */ |
| 49 | +#define BYTES_NOP1 0x90 |
| 50 | +#define BYTES_NOP2 0x66,BYTES_NOP1 |
| 51 | +#define BYTES_NOP3 0x0f,0x1f,0x00 |
| 52 | +#define BYTES_NOP4 0x0f,0x1f,0x40,0x00 |
| 53 | +#define BYTES_NOP5 0x0f,0x1f,0x44,0x00,0x00 |
| 54 | +#define BYTES_NOP6 0x66,BYTES_NOP5 |
| 55 | +#define BYTES_NOP7 0x0f,0x1f,0x80,0x00,0x00,0x00,0x00 |
| 56 | +#define BYTES_NOP8 0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00 |
| 57 | + |
| 58 | +#endif /* CONFIG_64BIT */ |
| 59 | + |
| 60 | +#ifdef __ASSEMBLY__ |
| 61 | +#define _ASM_MK_NOP(x) .byte x |
| 62 | +#else |
| 63 | +#define _ASM_MK_NOP(x) ".byte " __stringify(x) "\n" |
| 64 | +#endif |
| 65 | + |
| 66 | +#define ASM_NOP1 _ASM_MK_NOP(BYTES_NOP1) |
| 67 | +#define ASM_NOP2 _ASM_MK_NOP(BYTES_NOP2) |
| 68 | +#define ASM_NOP3 _ASM_MK_NOP(BYTES_NOP3) |
| 69 | +#define ASM_NOP4 _ASM_MK_NOP(BYTES_NOP4) |
| 70 | +#define ASM_NOP5 _ASM_MK_NOP(BYTES_NOP5) |
| 71 | +#define ASM_NOP6 _ASM_MK_NOP(BYTES_NOP6) |
| 72 | +#define ASM_NOP7 _ASM_MK_NOP(BYTES_NOP7) |
| 73 | +#define ASM_NOP8 _ASM_MK_NOP(BYTES_NOP8) |
| 74 | + |
| 75 | +#define ASM_NOP_MAX 8 |
| 76 | + |
| 77 | +#ifndef __ASSEMBLY__ |
| 78 | +extern const unsigned char * const x86_nops[]; |
| 79 | +#endif |
| 80 | + |
| 81 | +#endif /* _ASM_X86_NOPS_H */ |
0 commit comments