|
| 1 | +; =========================================================================== |
| 2 | +; Copyright (C) 2011 Thilo Schulz <[email protected]> |
| 3 | +; |
| 4 | +; This file is part of Quake III Arena source code. |
| 5 | +; |
| 6 | +; Quake III Arena source code is free software; you can redistribute it |
| 7 | +; and/or modify it under the terms of the GNU General Public License as |
| 8 | +; published by the Free Software Foundation; either version 2 of the License, |
| 9 | +; or (at your option) any later version. |
| 10 | +; |
| 11 | +; Quake III Arena source code is distributed in the hope that it will be |
| 12 | +; useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | +; GNU General Public License for more details. |
| 15 | +; |
| 16 | +; You should have received a copy of the GNU General Public License |
| 17 | +; along with Quake III Arena source code; if not, write to the Free Software |
| 18 | +; Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | +; =========================================================================== |
| 20 | + |
| 21 | +; MASM ftol conversion functions using SSE or FPU |
| 22 | +; assume __cdecl calling convention is being used for x86, __fastcall for x64 |
| 23 | + |
| 24 | +IFNDEF WIN64 |
| 25 | +.686p |
| 26 | +.xmm |
| 27 | +.model flat, c |
| 28 | +ENDIF |
| 29 | + |
| 30 | +.data |
| 31 | +ALIGN 16 |
| 32 | +ssemask DWORD 0FFFFFFFFh, 0FFFFFFFFh, 0FFFFFFFFh, 00000000h |
| 33 | + |
| 34 | +.code |
| 35 | + |
| 36 | +; dummy |
| 37 | +IFNDEF WIN64 |
| 38 | + .safeseh SEH_handler |
| 39 | + SEH_handler proc |
| 40 | + ret |
| 41 | + SEH_handler endp |
| 42 | +ENDIF |
| 43 | + |
| 44 | +IFDEF WIN64 |
| 45 | + Q_VMftol PROC |
| 46 | + movss xmm0, dword ptr [rdi + rbx * 4] |
| 47 | + cvttss2si eax, xmm0 |
| 48 | + ret |
| 49 | + Q_VMftol ENDP |
| 50 | + |
| 51 | + qvmcall64 PROC |
| 52 | + push rsi ; push non-volatile registers to stack |
| 53 | + push rdi |
| 54 | + push rbx |
| 55 | + push rcx ; need to save pointer in rcx so we can write back the programData value to caller |
| 56 | + |
| 57 | + ; registers r8 and r9 have correct value already thanx to __fastcall |
| 58 | + xor rbx, rbx ; opStackOfs starts out being 0 |
| 59 | + mov rdi, rdx ; opStack |
| 60 | + mov esi, dword ptr [rcx] ; programStack |
| 61 | + |
| 62 | + call qword ptr [r8] ; instructionPointers[0] is also the entry point |
| 63 | + |
| 64 | + pop rcx |
| 65 | + |
| 66 | + mov dword ptr [rcx], esi ; write back the programStack value |
| 67 | + mov al, bl ; return opStack offset |
| 68 | + |
| 69 | + pop rbx |
| 70 | + pop rdi |
| 71 | + pop rsi |
| 72 | + |
| 73 | + ret |
| 74 | + qvmcall64 ENDP |
| 75 | +ELSE |
| 76 | + Q_VMftol PROC |
| 77 | + movss xmm0, dword ptr [edi + ebx * 4] |
| 78 | + cvttss2si eax, xmm0 |
| 79 | + ret |
| 80 | + Q_VMftol ENDP |
| 81 | +ENDIF |
| 82 | + |
| 83 | +end |
0 commit comments