Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Generate .byte code for some instructions not supported by old
0004  * binutils.
0005  */
0006 #ifndef X86_ASM_INST_H
0007 #define X86_ASM_INST_H
0008 
0009 #ifdef __ASSEMBLY__
0010 
0011 #define REG_NUM_INVALID     100
0012 
0013 #define REG_TYPE_R32        0
0014 #define REG_TYPE_R64        1
0015 #define REG_TYPE_INVALID    100
0016 
0017     .macro R32_NUM opd r32
0018     \opd = REG_NUM_INVALID
0019     .ifc \r32,%eax
0020     \opd = 0
0021     .endif
0022     .ifc \r32,%ecx
0023     \opd = 1
0024     .endif
0025     .ifc \r32,%edx
0026     \opd = 2
0027     .endif
0028     .ifc \r32,%ebx
0029     \opd = 3
0030     .endif
0031     .ifc \r32,%esp
0032     \opd = 4
0033     .endif
0034     .ifc \r32,%ebp
0035     \opd = 5
0036     .endif
0037     .ifc \r32,%esi
0038     \opd = 6
0039     .endif
0040     .ifc \r32,%edi
0041     \opd = 7
0042     .endif
0043 #ifdef CONFIG_X86_64
0044     .ifc \r32,%r8d
0045     \opd = 8
0046     .endif
0047     .ifc \r32,%r9d
0048     \opd = 9
0049     .endif
0050     .ifc \r32,%r10d
0051     \opd = 10
0052     .endif
0053     .ifc \r32,%r11d
0054     \opd = 11
0055     .endif
0056     .ifc \r32,%r12d
0057     \opd = 12
0058     .endif
0059     .ifc \r32,%r13d
0060     \opd = 13
0061     .endif
0062     .ifc \r32,%r14d
0063     \opd = 14
0064     .endif
0065     .ifc \r32,%r15d
0066     \opd = 15
0067     .endif
0068 #endif
0069     .endm
0070 
0071     .macro R64_NUM opd r64
0072     \opd = REG_NUM_INVALID
0073 #ifdef CONFIG_X86_64
0074     .ifc \r64,%rax
0075     \opd = 0
0076     .endif
0077     .ifc \r64,%rcx
0078     \opd = 1
0079     .endif
0080     .ifc \r64,%rdx
0081     \opd = 2
0082     .endif
0083     .ifc \r64,%rbx
0084     \opd = 3
0085     .endif
0086     .ifc \r64,%rsp
0087     \opd = 4
0088     .endif
0089     .ifc \r64,%rbp
0090     \opd = 5
0091     .endif
0092     .ifc \r64,%rsi
0093     \opd = 6
0094     .endif
0095     .ifc \r64,%rdi
0096     \opd = 7
0097     .endif
0098     .ifc \r64,%r8
0099     \opd = 8
0100     .endif
0101     .ifc \r64,%r9
0102     \opd = 9
0103     .endif
0104     .ifc \r64,%r10
0105     \opd = 10
0106     .endif
0107     .ifc \r64,%r11
0108     \opd = 11
0109     .endif
0110     .ifc \r64,%r12
0111     \opd = 12
0112     .endif
0113     .ifc \r64,%r13
0114     \opd = 13
0115     .endif
0116     .ifc \r64,%r14
0117     \opd = 14
0118     .endif
0119     .ifc \r64,%r15
0120     \opd = 15
0121     .endif
0122 #endif
0123     .endm
0124 
0125     .macro REG_TYPE type reg
0126     R32_NUM reg_type_r32 \reg
0127     R64_NUM reg_type_r64 \reg
0128     .if reg_type_r64 <> REG_NUM_INVALID
0129     \type = REG_TYPE_R64
0130     .elseif reg_type_r32 <> REG_NUM_INVALID
0131     \type = REG_TYPE_R32
0132     .else
0133     \type = REG_TYPE_INVALID
0134     .endif
0135     .endm
0136 
0137     .macro PFX_REX opd1 opd2 W=0
0138     .if ((\opd1 | \opd2) & 8) || \W
0139     .byte 0x40 | ((\opd1 & 8) >> 3) | ((\opd2 & 8) >> 1) | (\W << 3)
0140     .endif
0141     .endm
0142 
0143     .macro MODRM mod opd1 opd2
0144     .byte \mod | (\opd1 & 7) | ((\opd2 & 7) << 3)
0145     .endm
0146 #endif
0147 
0148 #endif