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