18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef _ASM_X86_NOPS_H
38c2ecf20Sopenharmony_ci#define _ASM_X86_NOPS_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci/*
68c2ecf20Sopenharmony_ci * Define nops for use with alternative() and for tracing.
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * *_NOP5_ATOMIC must be a single instruction.
98c2ecf20Sopenharmony_ci */
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#define NOP_DS_PREFIX 0x3e
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci/* generic versions from gas
148c2ecf20Sopenharmony_ci   1: nop
158c2ecf20Sopenharmony_ci   the following instructions are NOT nops in 64-bit mode,
168c2ecf20Sopenharmony_ci   for 64-bit mode use K8 or P6 nops instead
178c2ecf20Sopenharmony_ci   2: movl %esi,%esi
188c2ecf20Sopenharmony_ci   3: leal 0x00(%esi),%esi
198c2ecf20Sopenharmony_ci   4: leal 0x00(,%esi,1),%esi
208c2ecf20Sopenharmony_ci   6: leal 0x00000000(%esi),%esi
218c2ecf20Sopenharmony_ci   7: leal 0x00000000(,%esi,1),%esi
228c2ecf20Sopenharmony_ci*/
238c2ecf20Sopenharmony_ci#define GENERIC_NOP1 0x90
248c2ecf20Sopenharmony_ci#define GENERIC_NOP2 0x89,0xf6
258c2ecf20Sopenharmony_ci#define GENERIC_NOP3 0x8d,0x76,0x00
268c2ecf20Sopenharmony_ci#define GENERIC_NOP4 0x8d,0x74,0x26,0x00
278c2ecf20Sopenharmony_ci#define GENERIC_NOP5 GENERIC_NOP1,GENERIC_NOP4
288c2ecf20Sopenharmony_ci#define GENERIC_NOP6 0x8d,0xb6,0x00,0x00,0x00,0x00
298c2ecf20Sopenharmony_ci#define GENERIC_NOP7 0x8d,0xb4,0x26,0x00,0x00,0x00,0x00
308c2ecf20Sopenharmony_ci#define GENERIC_NOP8 GENERIC_NOP1,GENERIC_NOP7
318c2ecf20Sopenharmony_ci#define GENERIC_NOP5_ATOMIC NOP_DS_PREFIX,GENERIC_NOP4
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci/* Opteron 64bit nops
348c2ecf20Sopenharmony_ci   1: nop
358c2ecf20Sopenharmony_ci   2: osp nop
368c2ecf20Sopenharmony_ci   3: osp osp nop
378c2ecf20Sopenharmony_ci   4: osp osp osp nop
388c2ecf20Sopenharmony_ci*/
398c2ecf20Sopenharmony_ci#define K8_NOP1 GENERIC_NOP1
408c2ecf20Sopenharmony_ci#define K8_NOP2	0x66,K8_NOP1
418c2ecf20Sopenharmony_ci#define K8_NOP3	0x66,K8_NOP2
428c2ecf20Sopenharmony_ci#define K8_NOP4	0x66,K8_NOP3
438c2ecf20Sopenharmony_ci#define K8_NOP5	K8_NOP3,K8_NOP2
448c2ecf20Sopenharmony_ci#define K8_NOP6	K8_NOP3,K8_NOP3
458c2ecf20Sopenharmony_ci#define K8_NOP7	K8_NOP4,K8_NOP3
468c2ecf20Sopenharmony_ci#define K8_NOP8	K8_NOP4,K8_NOP4
478c2ecf20Sopenharmony_ci#define K8_NOP5_ATOMIC 0x66,K8_NOP4
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci/* K7 nops
508c2ecf20Sopenharmony_ci   uses eax dependencies (arbitrary choice)
518c2ecf20Sopenharmony_ci   1: nop
528c2ecf20Sopenharmony_ci   2: movl %eax,%eax
538c2ecf20Sopenharmony_ci   3: leal (,%eax,1),%eax
548c2ecf20Sopenharmony_ci   4: leal 0x00(,%eax,1),%eax
558c2ecf20Sopenharmony_ci   6: leal 0x00000000(%eax),%eax
568c2ecf20Sopenharmony_ci   7: leal 0x00000000(,%eax,1),%eax
578c2ecf20Sopenharmony_ci*/
588c2ecf20Sopenharmony_ci#define K7_NOP1	GENERIC_NOP1
598c2ecf20Sopenharmony_ci#define K7_NOP2	0x8b,0xc0
608c2ecf20Sopenharmony_ci#define K7_NOP3	0x8d,0x04,0x20
618c2ecf20Sopenharmony_ci#define K7_NOP4	0x8d,0x44,0x20,0x00
628c2ecf20Sopenharmony_ci#define K7_NOP5	K7_NOP4,K7_NOP1
638c2ecf20Sopenharmony_ci#define K7_NOP6	0x8d,0x80,0,0,0,0
648c2ecf20Sopenharmony_ci#define K7_NOP7	0x8D,0x04,0x05,0,0,0,0
658c2ecf20Sopenharmony_ci#define K7_NOP8	K7_NOP7,K7_NOP1
668c2ecf20Sopenharmony_ci#define K7_NOP5_ATOMIC NOP_DS_PREFIX,K7_NOP4
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci/* P6 nops
698c2ecf20Sopenharmony_ci   uses eax dependencies (Intel-recommended choice)
708c2ecf20Sopenharmony_ci   1: nop
718c2ecf20Sopenharmony_ci   2: osp nop
728c2ecf20Sopenharmony_ci   3: nopl (%eax)
738c2ecf20Sopenharmony_ci   4: nopl 0x00(%eax)
748c2ecf20Sopenharmony_ci   5: nopl 0x00(%eax,%eax,1)
758c2ecf20Sopenharmony_ci   6: osp nopl 0x00(%eax,%eax,1)
768c2ecf20Sopenharmony_ci   7: nopl 0x00000000(%eax)
778c2ecf20Sopenharmony_ci   8: nopl 0x00000000(%eax,%eax,1)
788c2ecf20Sopenharmony_ci   Note: All the above are assumed to be a single instruction.
798c2ecf20Sopenharmony_ci	There is kernel code that depends on this.
808c2ecf20Sopenharmony_ci*/
818c2ecf20Sopenharmony_ci#define P6_NOP1	GENERIC_NOP1
828c2ecf20Sopenharmony_ci#define P6_NOP2	0x66,0x90
838c2ecf20Sopenharmony_ci#define P6_NOP3	0x0f,0x1f,0x00
848c2ecf20Sopenharmony_ci#define P6_NOP4	0x0f,0x1f,0x40,0
858c2ecf20Sopenharmony_ci#define P6_NOP5	0x0f,0x1f,0x44,0x00,0
868c2ecf20Sopenharmony_ci#define P6_NOP6	0x66,0x0f,0x1f,0x44,0x00,0
878c2ecf20Sopenharmony_ci#define P6_NOP7	0x0f,0x1f,0x80,0,0,0,0
888c2ecf20Sopenharmony_ci#define P6_NOP8	0x0f,0x1f,0x84,0x00,0,0,0,0
898c2ecf20Sopenharmony_ci#define P6_NOP5_ATOMIC P6_NOP5
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci#ifdef __ASSEMBLY__
928c2ecf20Sopenharmony_ci#define _ASM_MK_NOP(x) .byte x
938c2ecf20Sopenharmony_ci#else
948c2ecf20Sopenharmony_ci#define _ASM_MK_NOP(x) ".byte " __stringify(x) "\n"
958c2ecf20Sopenharmony_ci#endif
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci#if defined(CONFIG_MK7)
988c2ecf20Sopenharmony_ci#define ASM_NOP1 _ASM_MK_NOP(K7_NOP1)
998c2ecf20Sopenharmony_ci#define ASM_NOP2 _ASM_MK_NOP(K7_NOP2)
1008c2ecf20Sopenharmony_ci#define ASM_NOP3 _ASM_MK_NOP(K7_NOP3)
1018c2ecf20Sopenharmony_ci#define ASM_NOP4 _ASM_MK_NOP(K7_NOP4)
1028c2ecf20Sopenharmony_ci#define ASM_NOP5 _ASM_MK_NOP(K7_NOP5)
1038c2ecf20Sopenharmony_ci#define ASM_NOP6 _ASM_MK_NOP(K7_NOP6)
1048c2ecf20Sopenharmony_ci#define ASM_NOP7 _ASM_MK_NOP(K7_NOP7)
1058c2ecf20Sopenharmony_ci#define ASM_NOP8 _ASM_MK_NOP(K7_NOP8)
1068c2ecf20Sopenharmony_ci#define ASM_NOP5_ATOMIC _ASM_MK_NOP(K7_NOP5_ATOMIC)
1078c2ecf20Sopenharmony_ci#elif defined(CONFIG_X86_P6_NOP)
1088c2ecf20Sopenharmony_ci#define ASM_NOP1 _ASM_MK_NOP(P6_NOP1)
1098c2ecf20Sopenharmony_ci#define ASM_NOP2 _ASM_MK_NOP(P6_NOP2)
1108c2ecf20Sopenharmony_ci#define ASM_NOP3 _ASM_MK_NOP(P6_NOP3)
1118c2ecf20Sopenharmony_ci#define ASM_NOP4 _ASM_MK_NOP(P6_NOP4)
1128c2ecf20Sopenharmony_ci#define ASM_NOP5 _ASM_MK_NOP(P6_NOP5)
1138c2ecf20Sopenharmony_ci#define ASM_NOP6 _ASM_MK_NOP(P6_NOP6)
1148c2ecf20Sopenharmony_ci#define ASM_NOP7 _ASM_MK_NOP(P6_NOP7)
1158c2ecf20Sopenharmony_ci#define ASM_NOP8 _ASM_MK_NOP(P6_NOP8)
1168c2ecf20Sopenharmony_ci#define ASM_NOP5_ATOMIC _ASM_MK_NOP(P6_NOP5_ATOMIC)
1178c2ecf20Sopenharmony_ci#elif defined(CONFIG_X86_64)
1188c2ecf20Sopenharmony_ci#define ASM_NOP1 _ASM_MK_NOP(K8_NOP1)
1198c2ecf20Sopenharmony_ci#define ASM_NOP2 _ASM_MK_NOP(K8_NOP2)
1208c2ecf20Sopenharmony_ci#define ASM_NOP3 _ASM_MK_NOP(K8_NOP3)
1218c2ecf20Sopenharmony_ci#define ASM_NOP4 _ASM_MK_NOP(K8_NOP4)
1228c2ecf20Sopenharmony_ci#define ASM_NOP5 _ASM_MK_NOP(K8_NOP5)
1238c2ecf20Sopenharmony_ci#define ASM_NOP6 _ASM_MK_NOP(K8_NOP6)
1248c2ecf20Sopenharmony_ci#define ASM_NOP7 _ASM_MK_NOP(K8_NOP7)
1258c2ecf20Sopenharmony_ci#define ASM_NOP8 _ASM_MK_NOP(K8_NOP8)
1268c2ecf20Sopenharmony_ci#define ASM_NOP5_ATOMIC _ASM_MK_NOP(K8_NOP5_ATOMIC)
1278c2ecf20Sopenharmony_ci#else
1288c2ecf20Sopenharmony_ci#define ASM_NOP1 _ASM_MK_NOP(GENERIC_NOP1)
1298c2ecf20Sopenharmony_ci#define ASM_NOP2 _ASM_MK_NOP(GENERIC_NOP2)
1308c2ecf20Sopenharmony_ci#define ASM_NOP3 _ASM_MK_NOP(GENERIC_NOP3)
1318c2ecf20Sopenharmony_ci#define ASM_NOP4 _ASM_MK_NOP(GENERIC_NOP4)
1328c2ecf20Sopenharmony_ci#define ASM_NOP5 _ASM_MK_NOP(GENERIC_NOP5)
1338c2ecf20Sopenharmony_ci#define ASM_NOP6 _ASM_MK_NOP(GENERIC_NOP6)
1348c2ecf20Sopenharmony_ci#define ASM_NOP7 _ASM_MK_NOP(GENERIC_NOP7)
1358c2ecf20Sopenharmony_ci#define ASM_NOP8 _ASM_MK_NOP(GENERIC_NOP8)
1368c2ecf20Sopenharmony_ci#define ASM_NOP5_ATOMIC _ASM_MK_NOP(GENERIC_NOP5_ATOMIC)
1378c2ecf20Sopenharmony_ci#endif
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ci#define ASM_NOP_MAX 8
1408c2ecf20Sopenharmony_ci#define NOP_ATOMIC5 (ASM_NOP_MAX+1)	/* Entry for the 5-byte atomic NOP */
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__
1438c2ecf20Sopenharmony_ciextern const unsigned char * const *ideal_nops;
1448c2ecf20Sopenharmony_ciextern void arch_init_ideal_nops(void);
1458c2ecf20Sopenharmony_ci#endif
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ci#endif /* _ASM_X86_NOPS_H */
148