1/*
2** Assembler VM interface definitions.
3** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h
4*/
5
6#ifndef _LJ_VM_H
7#define _LJ_VM_H
8
9#include "lj_obj.h"
10
11/* Entry points for ASM parts of VM. */
12LJ_ASMF void lj_vm_call(lua_State *L, TValue *base, int nres1);
13LJ_ASMF int lj_vm_pcall(lua_State *L, TValue *base, int nres1, ptrdiff_t ef);
14typedef TValue *(*lua_CPFunction)(lua_State *L, lua_CFunction func, void *ud);
15LJ_ASMF int lj_vm_cpcall(lua_State *L, lua_CFunction func, void *ud,
16 lua_CPFunction cp);
17LJ_ASMF int lj_vm_resume(lua_State *L, TValue *base, int nres1, ptrdiff_t ef);
18LJ_ASMF_NORET void LJ_FASTCALL lj_vm_unwind_c(void *cframe, int errcode);
19LJ_ASMF_NORET void LJ_FASTCALL lj_vm_unwind_ff(void *cframe);
20LJ_ASMF void lj_vm_unwind_c_eh(void);
21LJ_ASMF void lj_vm_unwind_ff_eh(void);
22#if LJ_TARGET_X86ORX64
23LJ_ASMF void lj_vm_unwind_rethrow(void);
24#endif
25
26/* Miscellaneous functions. */
27#if LJ_TARGET_X86ORX64
28LJ_ASMF int lj_vm_cpuid(uint32_t f, uint32_t res[4]);
29#endif
30#if LJ_TARGET_PPC
31void lj_vm_cachesync(void *start, void *end);
32#endif
33LJ_ASMF double lj_vm_foldarith(double x, double y, int op);
34#if LJ_HASJIT
35LJ_ASMF double lj_vm_foldfpm(double x, int op);
36#endif
37#if !LJ_ARCH_HASFPU
38/* Declared in lj_obj.h: LJ_ASMF int32_t lj_vm_tobit(double x); */
39#endif
40
41/* Dispatch targets for recording and hooks. */
42LJ_ASMF void lj_vm_record(void);
43LJ_ASMF void lj_vm_inshook(void);
44LJ_ASMF void lj_vm_rethook(void);
45LJ_ASMF void lj_vm_callhook(void);
46
47/* Trace exit handling. */
48LJ_ASMF void lj_vm_exit_handler(void);
49LJ_ASMF void lj_vm_exit_interp(void);
50
51/* Internal math helper functions. */
52#if LJ_TARGET_X86ORX64 || LJ_TARGET_PPC
53#define lj_vm_floor floor
54#define lj_vm_ceil ceil
55#else
56LJ_ASMF double lj_vm_floor(double);
57LJ_ASMF double lj_vm_ceil(double);
58#if LJ_TARGET_ARM
59LJ_ASMF double lj_vm_floor_sf(double);
60LJ_ASMF double lj_vm_ceil_sf(double);
61#endif
62#endif
63#if defined(LUAJIT_NO_LOG2) || LJ_TARGET_X86ORX64
64LJ_ASMF double lj_vm_log2(double);
65#else
66#define lj_vm_log2 log2
67#endif
68
69#if LJ_HASJIT
70#if LJ_TARGET_X86ORX64
71LJ_ASMF void lj_vm_floor_sse(void);
72LJ_ASMF void lj_vm_ceil_sse(void);
73LJ_ASMF void lj_vm_trunc_sse(void);
74LJ_ASMF void lj_vm_exp_x87(void);
75LJ_ASMF void lj_vm_exp2_x87(void);
76LJ_ASMF void lj_vm_pow_sse(void);
77LJ_ASMF void lj_vm_powi_sse(void);
78#else
79#if LJ_TARGET_PPC
80#define lj_vm_trunc trunc
81#else
82LJ_ASMF double lj_vm_trunc(double);
83#if LJ_TARGET_ARM
84LJ_ASMF double lj_vm_trunc_sf(double);
85#endif
86#endif
87LJ_ASMF double lj_vm_powi(double, int32_t);
88#ifdef LUAJIT_NO_EXP2
89LJ_ASMF double lj_vm_exp2(double);
90#else
91#define lj_vm_exp2 exp2
92#endif
93#endif
94LJ_ASMF int32_t LJ_FASTCALL lj_vm_modi(int32_t, int32_t);
95#if LJ_HASFFI
96LJ_ASMF int lj_vm_errno(void);
97#endif
98#endif
99
100/* Continuations for metamethods. */
101LJ_ASMF void lj_cont_cat(void); /* Continue with concatenation. */
102LJ_ASMF void lj_cont_ra(void); /* Store result in RA from instruction. */
103LJ_ASMF void lj_cont_nop(void); /* Do nothing, just continue execution. */
104LJ_ASMF void lj_cont_condt(void); /* Branch if result is true. */
105LJ_ASMF void lj_cont_condf(void); /* Branch if result is false. */
106LJ_ASMF void lj_cont_hook(void); /* Continue from hook yield. */
107
108enum { LJ_CONT_TAILCALL, LJ_CONT_FFI_CALLBACK }; /* Special continuations. */
109
110/* Start of the ASM code. */
111LJ_ASMF char lj_vm_asm_begin[];
112
113/* Bytecode offsets are relative to lj_vm_asm_begin. */
114#define makeasmfunc(ofs) ((ASMFunction)(lj_vm_asm_begin + (ofs)))
115
116#endif
117