| 1969 | } |
| 1970 | |
| 1971 | void GenCodeCmdCall(VMCmd cmd) |
| 1972 | { |
| 1973 | static unsigned int ret[128]; |
| 1974 | EMIT_COMMENT("CALL"); |
| 1975 | |
| 1976 | if(x86Functions[cmd.argument].address != -1) |
| 1977 | { |
| 1978 | GenCodeCmdCallEpilog(x86Functions[cmd.argument].bytesToPop); |
| 1979 | |
| 1980 | EMIT_OP_ADDR(o_push, sDWORD, paramBase-4); |
| 1981 | EMIT_OP_ADDR_REG(o_mov, sDWORD, paramBase-4, rESP); |
| 1982 | EMIT_OP_ADDR(o_call, sNONE, cmd.argument * 8 + (unsigned int)(uintptr_t)x86FuncAddr); // Index array of function addresses |
| 1983 | EMIT_OP_ADDR(o_pop, sDWORD, paramBase-4); |
| 1984 | |
| 1985 | GenCodeCmdCallProlog(cmd); |
| 1986 | }else{ |
| 1987 | unsigned int bytesToPop = x86Functions[cmd.argument].bytesToPop; |
| 1988 | |
| 1989 | if(x86Functions[cmd.argument].retType == ExternFuncInfo::RETURN_UNKNOWN && x86Functions[cmd.argument].returnShift) |
| 1990 | EMIT_OP_NUM(o_push, (int)(intptr_t)ret); |
| 1991 | EMIT_OP_ADDR_REG(o_mov, sDWORD, paramBase-12, rEDI); |
| 1992 | EMIT_OP_ADDR_REG(o_mov, sDWORD, paramBase-8, rESP); |
| 1993 | EMIT_OP_ADDR(o_call, sNONE, cmd.argument * 8 + (unsigned int)(uintptr_t)x86FuncAddr); // Index array of function addresses |
| 1994 | |
| 1995 | EMIT_OP_REG_ADDR(o_mov, rECX, sDWORD, (int)(intptr_t)x86Continue); |
| 1996 | EMIT_OP_REG_REG(o_test, rECX, rECX); |
| 1997 | EMIT_OP_LABEL(o_jnz, aluLabels); |
| 1998 | #ifdef __linux |
| 1999 | // call siglongjmp(target_env, EXCEPTION_STOP_EXECUTION); |
| 2000 | EMIT_OP_NUM(o_push, EXCEPTION_STOP_EXECUTION); |
| 2001 | EMIT_OP_NUM(o_push, nullcJmpTarget); |
| 2002 | EMIT_OP_RPTR(o_call, sDWORD, rNONE, 1, rNONE, (unsigned)(intptr_t)&siglongjmpPtr); |
| 2003 | #else |
| 2004 | EMIT_OP_REG_REG(o_mov, rECX, rESP); // esp is very likely to contain neither 0 or ~0, so we can distinguish |
| 2005 | EMIT_OP(o_int); // array out of bounds and function with no return errors from this one |
| 2006 | #endif |
| 2007 | EMIT_LABEL(aluLabels); |
| 2008 | aluLabels++; |
| 2009 | |
| 2010 | EMIT_OP_REG_NUM(o_add, rESP, bytesToPop); |
| 2011 | if(x86Functions[cmd.argument].retType == ExternFuncInfo::RETURN_INT) |
| 2012 | { |
| 2013 | EMIT_OP_REG(o_push, rEAX); |
| 2014 | }else if(x86Functions[cmd.argument].retType == ExternFuncInfo::RETURN_DOUBLE){ |
| 2015 | EMIT_OP_REG_NUM(o_sub, rESP, 8); |
| 2016 | EMIT_OP_RPTR(o_fstp, sQWORD, rESP, 0); |
| 2017 | }else if(x86Functions[cmd.argument].retType == ExternFuncInfo::RETURN_LONG){ |
| 2018 | EMIT_OP_REG(o_push, rEDX); |
| 2019 | EMIT_OP_REG(o_push, rEAX); |
| 2020 | }else if(x86Functions[cmd.argument].retType == ExternFuncInfo::RETURN_UNKNOWN && x86Functions[cmd.argument].returnShift){ |
| 2021 | // adjust new stack top |
| 2022 | EMIT_OP_REG_NUM(o_sub, rESP, x86Functions[cmd.argument].returnShift * 4); |
| 2023 | // copy return value on top of the stack |
| 2024 | EMIT_OP_REG_REG(o_mov, rEBX, rEDI); |
| 2025 | |
| 2026 | //EMIT_OP_REG_RPTR(o_lea, rESI, sNONE, rEAX, paramBase); |
| 2027 | EMIT_OP_REG_NUM(o_mov, rESI, (int)(intptr_t)ret); |
| 2028 | EMIT_OP_REG_REG(o_mov, rEDI, rESP); |
nothing calls this directly
no test coverage detected