"movlhpsXrm$movhpsXrm|movshdupXrm|movhpdXrm",
"movhpsXmr||movhpdXmr",
"$prefetcht!Bm","hintnopVm","hintnopVm","hintnopVm",
-"hintnopVm","hintnopVm","hintnopVm","hintnopVm",
+"hintnopVm","hintnopVm","endbr*hintnopVm","hintnopVm",
--2x
"movUmx$","movUmy$","movUxm$","movUym$","movUmz$",nil,"movUzm$",nil,
"movapsXrm||movapdXrm",
return dispatch(ctx, map_opcvm[ctx.mrm])
end,
+ -- Special NOP for endbr64/endbr32.
+ endbr = function(ctx, name, pat)
+ if ctx.rep then
+ local pos = ctx.pos
+ local b = byte(ctx.code, pos)
+ local text
+ if b == 0xfa then text = "endbr64"
+ elseif b == 0xfb then text = "endbr64"
+ end
+ if text then
+ ctx.pos = pos + 1
+ ctx.rep = nil
+ return putop(ctx, text)
+ end
+ end
+ return dispatch(ctx, pat)
+ end,
+
-- Floating point opcode dispatch.
fp = function(ctx, name, pat)
local mrm = getmrm(ctx); if not mrm then return incomplete(ctx) end
|
|.endif
|
+|//-- Control-Flow Enforcement Technique (CET) ---------------------------
+|
+|.if CET_BR
+|.macro endbr; endbr64; .endmacro
+|.else
+|.macro endbr; .endmacro
+|.endif
+|
|//-----------------------------------------------------------------------
|
|// Instruction headers.
-|.macro ins_A; .endmacro
-|.macro ins_AD; .endmacro
-|.macro ins_AJ; .endmacro
-|.macro ins_ABC; movzx RBd, RCH; movzx RCd, RCL; .endmacro
-|.macro ins_AB_; movzx RBd, RCH; .endmacro
-|.macro ins_A_C; movzx RCd, RCL; .endmacro
-|.macro ins_AND; not RD; .endmacro
+|.macro ins_A; endbr; .endmacro
+|.macro ins_AD; endbr; .endmacro
+|.macro ins_AJ; endbr; .endmacro
+|.macro ins_ABC; endbr; movzx RBd, RCH; movzx RCd, RCL; .endmacro
+|.macro ins_AB_; endbr; movzx RBd, RCH; .endmacro
+|.macro ins_A_C; endbr; movzx RCd, RCL; .endmacro
+|.macro ins_AND; endbr; not RD; .endmacro
|
|// Instruction decode+dispatch. Carefully tuned (nope, lodsd is not faster).
|.macro ins_NEXT
| jmp <3
|
|->vm_unwind_yield:
+ | endbr
| mov al, LUA_YIELD
| jmp ->vm_unwind_c_eh
|
|->vm_unwind_c: // Unwind C stack, return from vm_pcall.
+ | endbr
| // (void *cframe, int errcode)
| mov eax, CARG2d // Error return status for vm_pcall.
| mov rsp, CARG1
|->vm_unwind_c_eh: // Landing pad for external unwinder.
+ | endbr
| mov L:RB, SAVE_L
| mov GL:RB, L:RB->glref
| mov dword GL:RB->vmstate, ~LJ_VMST_C
| jmp ->vm_leave_unw
|
|->vm_unwind_rethrow:
+ | endbr
|.if not X64WIN
| mov CARG1, SAVE_L
| mov CARG2d, eax
|.endif
|
|->vm_unwind_ff: // Unwind C stack, return from ff pcall.
+ | endbr
| // (void *cframe)
| and CARG1, CFRAME_RAWMASK
| mov rsp, CARG1
|->vm_unwind_ff_eh: // Landing pad for external unwinder.
+ | endbr
| mov L:RB, SAVE_L
| mov RDd, 1+1 // Really 1+2 results, incr. later.
| mov BASE, L:RB->base
|//-- Continuation dispatch ----------------------------------------------
|
|->cont_dispatch:
+ | endbr
| // BASE = meta base, RA = resultofs, RD = nresults+1 (also in MULTRES)
| add RA, BASE
| and PC, -8
|.endif
|
|->cont_cat: // BASE = base, RC = result, RB = mbase
+ | endbr
| movzx RAd, PC_RB
| sub RB, 32
| lea RA, [BASE+RA*8]
| test RC, RC
| jz >3
|->cont_ra: // BASE = base, RC = result
+ | endbr
| movzx RAd, PC_RA
| mov RB, [RC]
| mov [BASE+RA*8], RB
| mov RB, [BASE+RA*8]
| mov [RC], RB
|->cont_nop: // BASE = base, (RC = result)
+ | endbr
| ins_next
|
|3: // Call __newindex metamethod.
| ins_next
|
|->cont_condt: // BASE = base, RC = result
+ | endbr
| add PC, 4
| mov ITYPE, [RC]
| sar ITYPE, 47
| jmp <6
|
|->cont_condf: // BASE = base, RC = result
+ | endbr
| mov ITYPE, [RC]
| sar ITYPE, 47
| cmp ITYPEd, LJ_TISTRUECOND // Branch if result is false.
|
|.macro .ffunc, name
|->ff_ .. name:
+ | endbr
|.endmacro
|
|.macro .ffunc_1, name
|->ff_ .. name:
- | cmp NARGS:RDd, 1+1; jb ->fff_fallback
+ | endbr; cmp NARGS:RDd, 1+1; jb ->fff_fallback
|.endmacro
|
|.macro .ffunc_2, name
|->ff_ .. name:
- | cmp NARGS:RDd, 2+1; jb ->fff_fallback
+ | endbr; cmp NARGS:RDd, 2+1; jb ->fff_fallback
|.endmacro
|
|.macro .ffunc_n, name, op
|
|->vm_record: // Dispatch target for recording phase.
|.if JIT
+ | endbr
| movzx RDd, byte [DISPATCH+DISPATCH_GL(hookmask)]
| test RDL, HOOK_VMEVENT // No recording while in vmevent.
| jnz >5
|.endif
|
|->vm_rethook: // Dispatch target for return hooks.
+ | endbr
| movzx RDd, byte [DISPATCH+DISPATCH_GL(hookmask)]
| test RDL, HOOK_ACTIVE // Hook already active?
| jnz >5
| jmp >1
|
|->vm_inshook: // Dispatch target for instr/line hooks.
+ | endbr
| movzx RDd, byte [DISPATCH+DISPATCH_GL(hookmask)]
| test RDL, HOOK_ACTIVE // Hook already active?
| jnz >5
| jmp aword [DISPATCH+OP*8+GG_DISP2STATIC] // Re-dispatch to static ins.
|
|->cont_hook: // Continue from hook yield.
+ | endbr
| add PC, 4
| mov RA, [RB-40]
| mov MULTRES, RAd // Restore MULTRES for *M ins.
|.endif
|
|->vm_callhook: // Dispatch target for call hooks.
+ | endbr
| mov SAVE_PC, PC
|.if JIT
| jmp >1
|
|->cont_stitch: // Trace stitching.
|.if JIT
+ | endbr
| // BASE = base, RC = result, RB = mbase
| mov TRACE:ITYPE, [RB-40] // Save previous trace.
| cleartp TRACE:ITYPE
|
|->vm_profhook: // Dispatch target for profiler hook.
#if LJ_HASPROFILE
+ | endbr
| mov L:RB, SAVE_L
| mov L:RB->base, BASE
| mov CARG2, PC // Caveat: CARG2 == BASE
|// The 16 bit exit number is stored with two (sign-extended) push imm8.
|->vm_exit_handler:
|.if JIT
+ | endbr
| push r13; push r12
| push r11; push r10; push r9; push r8
| push rdi; push rsi; push rbp; lea rbp, [rsp+88]; push rbp
| jmp >1
|.endif
|->vm_exit_interp:
+ | endbr
| // RD = MULTRES or negated error code, BASE, PC and DISPATCH set.
|.if JIT
| // Restore additional callee-save registers only used in compiled code.
|.macro vm_round, name, mode, cond
|->name:
|->name .. _sse:
+ | endbr
| sseconst_abs xmm2, RD
| sseconst_2p52 xmm3, RD
| movaps xmm1, xmm0
|// Next idx returned in edx.
|->vm_next:
|.if JIT
+ | endbr
| mov NEXT_ASIZE, NEXT_TAB->asize
|1: // Traverse array part.
| cmp NEXT_IDX, NEXT_ASIZE; jae >5
case BC_ITERN:
|.if JIT
+ | endbr
| hotloop RBd
|.endif
|->vm_IITERN:
| jnz >7 // Not returning to a fixarg Lua func?
switch (op) {
case BC_RET:
+ | endbr
|->BC_RET_Z:
| mov KBASE, BASE // Use KBASE for result move.
| sub RDd, 1
| ja >6
break;
case BC_RET1:
+ | endbr
| mov RB, [BASE+RA]
| mov [BASE-16], RB
/* fallthrough */
case BC_RET0:
+ | endbr
|5:
| cmp PC_RB, RDL // More results expected?
| ja >6
case BC_FORL:
|.if JIT
+ | endbr
| hotloop RBd
|.endif
| // Fall through. Assumes BC_IFORL follows and ins_AJ is a no-op.
case BC_ITERL:
|.if JIT
+ | endbr
| hotloop RBd
|.endif
| // Fall through. Assumes BC_IITERL follows and ins_AJ is a no-op.
case BC_FUNCF:
|.if JIT
+ | endbr
| hotcall RBd
|.endif
case BC_FUNCV: /* NYI: compiled vararg functions. */