Skip to content

Commit

Permalink
Add win32/q3asm.asm from jk2mv for MSVC builds.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daggolin committed Nov 2, 2023
1 parent cf10de6 commit d3f43ad
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 0 deletions.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Expand Up @@ -102,6 +102,11 @@ list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_SOURCE_DIR}/cmake/Modules")
# ${Architecture} must match ARCH_STRING in q_platform.h,
# and is used in DLL names (jagamex86.dll, jagamex86.dylib, jagamei386.so).
if(WIN32)

if(MSVC)
enable_language(ASM_MASM)
endif()

set(X86 ON)
if(CMAKE_SIZEOF_VOID_P MATCHES "8")
set(Architecture "x86_64")
Expand Down Expand Up @@ -216,6 +221,8 @@ if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:SSE2")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")

set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /safeseh:no")

# We don't try to control symbol visibility under MSVC.
set(OPENJK_VISIBILITY_FLAGS "")
elseif (("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") OR ("${CMAKE_C_COMPILER_ID}" MATCHES "Clang"))
Expand Down
6 changes: 6 additions & 0 deletions codemp/CMakeLists.txt
Expand Up @@ -271,6 +271,12 @@ if(BuildMPEngine OR BuildMPDed)
)
endif()

if(MSVC)
set(MPEngineAndDedCommonFiles ${MPEngineAndDedCommonFiles}
"${MPDir}/win32/q3asm.asm"
)
endif()

if(WIN32)
set(MPEngineAndDedCommonFiles ${MPEngineAndDedCommonFiles})
endif(WIN32)
Expand Down
83 changes: 83 additions & 0 deletions codemp/win32/q3asm.asm
@@ -0,0 +1,83 @@
; ===========================================================================
; Copyright (C) 2011 Thilo Schulz <thilo@tjps.eu>
;
; This file is part of Quake III Arena source code.
;
; Quake III Arena source code is free software; you can redistribute it
; and/or modify it under the terms of the GNU General Public License as
; published by the Free Software Foundation; either version 2 of the License,
; or (at your option) any later version.
;
; Quake III Arena source code is distributed in the hope that it will be
; useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with Quake III Arena source code; if not, write to the Free Software
; Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
; ===========================================================================

; MASM ftol conversion functions using SSE or FPU
; assume __cdecl calling convention is being used for x86, __fastcall for x64

IFNDEF WIN64
.686p
.xmm
.model flat, c
ENDIF

.data
ALIGN 16
ssemask DWORD 0FFFFFFFFh, 0FFFFFFFFh, 0FFFFFFFFh, 00000000h

.code

; dummy
IFNDEF WIN64
.safeseh SEH_handler
SEH_handler proc
ret
SEH_handler endp
ENDIF

IFDEF WIN64
Q_VMftol PROC
movss xmm0, dword ptr [rdi + rbx * 4]
cvttss2si eax, xmm0
ret
Q_VMftol ENDP

qvmcall64 PROC
push rsi ; push non-volatile registers to stack
push rdi
push rbx
push rcx ; need to save pointer in rcx so we can write back the programData value to caller

; registers r8 and r9 have correct value already thanx to __fastcall
xor rbx, rbx ; opStackOfs starts out being 0
mov rdi, rdx ; opStack
mov esi, dword ptr [rcx] ; programStack

call qword ptr [r8] ; instructionPointers[0] is also the entry point

pop rcx

mov dword ptr [rcx], esi ; write back the programStack value
mov al, bl ; return opStack offset

pop rbx
pop rdi
pop rsi

ret
qvmcall64 ENDP
ELSE
Q_VMftol PROC
movss xmm0, dword ptr [edi + ebx * 4]
cvttss2si eax, xmm0
ret
Q_VMftol ENDP
ENDIF

end

0 comments on commit d3f43ad

Please sign in to comment.