^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Generate .byte code for some instructions not supported by old
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * binutils.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #ifndef X86_ASM_INST_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #define X86_ASM_INST_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #ifdef __ASSEMBLY__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #define REG_NUM_INVALID 100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #define REG_TYPE_R32 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #define REG_TYPE_R64 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #define REG_TYPE_INVALID 100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) .macro R32_NUM opd r32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) \opd = REG_NUM_INVALID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) .ifc \r32,%eax
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) \opd = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) .endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) .ifc \r32,%ecx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) \opd = 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) .endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) .ifc \r32,%edx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) \opd = 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) .endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) .ifc \r32,%ebx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) \opd = 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) .endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) .ifc \r32,%esp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) \opd = 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) .endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) .ifc \r32,%ebp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) \opd = 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) .endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) .ifc \r32,%esi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) \opd = 6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) .endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) .ifc \r32,%edi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) \opd = 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) .endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #ifdef CONFIG_X86_64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) .ifc \r32,%r8d
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) \opd = 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) .endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) .ifc \r32,%r9d
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) \opd = 9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) .endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) .ifc \r32,%r10d
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) \opd = 10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) .endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) .ifc \r32,%r11d
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) \opd = 11
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) .endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) .ifc \r32,%r12d
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) \opd = 12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) .endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) .ifc \r32,%r13d
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) \opd = 13
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) .endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) .ifc \r32,%r14d
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) \opd = 14
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) .endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) .ifc \r32,%r15d
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) \opd = 15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) .endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) .endm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) .macro R64_NUM opd r64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) \opd = REG_NUM_INVALID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) #ifdef CONFIG_X86_64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) .ifc \r64,%rax
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) \opd = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) .endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) .ifc \r64,%rcx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) \opd = 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) .endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) .ifc \r64,%rdx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) \opd = 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) .endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) .ifc \r64,%rbx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) \opd = 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) .endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) .ifc \r64,%rsp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) \opd = 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) .endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) .ifc \r64,%rbp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) \opd = 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) .endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) .ifc \r64,%rsi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) \opd = 6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) .endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) .ifc \r64,%rdi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) \opd = 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) .endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) .ifc \r64,%r8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) \opd = 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) .endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) .ifc \r64,%r9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) \opd = 9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) .endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) .ifc \r64,%r10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) \opd = 10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) .endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) .ifc \r64,%r11
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) \opd = 11
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) .endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) .ifc \r64,%r12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) \opd = 12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) .endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) .ifc \r64,%r13
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) \opd = 13
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) .endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) .ifc \r64,%r14
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) \opd = 14
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) .endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) .ifc \r64,%r15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) \opd = 15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) .endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) .endm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) .macro REG_TYPE type reg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) R32_NUM reg_type_r32 \reg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) R64_NUM reg_type_r64 \reg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) .if reg_type_r64 <> REG_NUM_INVALID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) \type = REG_TYPE_R64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) .elseif reg_type_r32 <> REG_NUM_INVALID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) \type = REG_TYPE_R32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) .else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) \type = REG_TYPE_INVALID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) .endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) .endm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) .macro PFX_REX opd1 opd2 W=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) .if ((\opd1 | \opd2) & 8) || \W
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) .byte 0x40 | ((\opd1 & 8) >> 3) | ((\opd2 & 8) >> 1) | (\W << 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) .endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) .endm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) .macro MODRM mod opd1 opd2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) .byte \mod | (\opd1 & 7) | ((\opd2 & 7) << 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) .endm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) .macro RDPID opd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) REG_TYPE rdpid_opd_type \opd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) .if rdpid_opd_type == REG_TYPE_R64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) R64_NUM rdpid_opd \opd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) .else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) R32_NUM rdpid_opd \opd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) .endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) .byte 0xf3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) .if rdpid_opd > 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) PFX_REX rdpid_opd 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) .endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) .byte 0x0f, 0xc7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) MODRM 0xc0 rdpid_opd 0x7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) .endm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) #endif