Skip to content

Commit 7657d87

Browse files
committed
Add endbr32 for i386
1 parent 854d6c5 commit 7657d87

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

i386-asm.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,21 +1002,24 @@ ST_FUNC void asm_opcode(TCCState *s1, int opcode)
10021002
modrm_index = -1;
10031003
modreg_index = -1;
10041004
if (pa->instr_type & OPC_MODRM) {
1005-
#ifdef TCC_TARGET_X86_64
10061005
if (!nb_ops) {
10071006
/* A modrm opcode without operands is a special case (e.g. mfence).
10081007
It has a group and acts as if there's an register operand 0 */
10091008
i = 0;
10101009
ops[i].type = OP_REG;
1010+
#ifdef TCC_TARGET_X86_64
10111011
if (pa->sym == TOK_ASM_endbr64)
10121012
ops[i].reg = 2; // dx
10131013
else if (pa->sym >= TOK_ASM_lfence && pa->sym <= TOK_ASM_sfence)
10141014
ops[i].reg = 0; // ax
1015+
#else
1016+
if (pa->sym == TOK_ASM_endbr32)
1017+
ops[i].reg = 3; // bx
1018+
#endif
10151019
else
10161020
tcc_error("bad MODR/M opcode without operands");
10171021
goto modrm_found;
10181022
}
1019-
#endif
10201023
/* first look for an ea operand */
10211024
for(i = 0;i < nb_ops; i++) {
10221025
if (op_type[i] & OP_EA)

i386-asm.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@
3737
DEF_ASM_OP0(pause, 0xf390)
3838
DEF_ASM_OP0(xlat, 0xd7)
3939

40-
/* strings */
40+
/* Control-Flow Enforcement */
41+
DEF_ASM_OP0L(endbr32, 0xf30f1e, 7, OPC_MODRM)
42+
43+
/* strings */
4144
ALT(DEF_ASM_OP0L(cmpsb, 0xa6, 0, OPC_BWLX))
4245
ALT(DEF_ASM_OP0L(scmpb, 0xa6, 0, OPC_BWLX))
4346

0 commit comments

Comments
 (0)