More x64 improvements

This commit is contained in:
dbalatoni13 2025-04-11 19:43:16 +02:00
parent 9e062adfa4
commit 3832edba89
6 changed files with 120 additions and 89 deletions

3
.gitmodules vendored
View file

@ -4,3 +4,6 @@
[submodule "extern/aurora"]
path = extern/aurora
url = https://github.com/dbalatoni13/aurora.git
[submodule "extern/longjmp_win64"]
path = extern/longjmp_win64
url = https://github.com/GlinkieGamesInc/longjmp_win64.git

View file

@ -1,8 +1,8 @@
cmake_minimum_required(VERSION 3.13)
if (APPLE)
project(marioparty4 LANGUAGES C CXX OBJC)
project(marioparty4 LANGUAGES C CXX OBJC)
else ()
project(marioparty4 LANGUAGES C CXX)
project(marioparty4 LANGUAGES C CXX)
endif ()
set(CMAKE_C_STANDARD 11)
@ -11,88 +11,88 @@ set(CMAKE_CXX_STANDARD 20)
set(VERSION 0)
# Set build type to Debug if not specified
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif()
if (CMAKE_SYSTEM_NAME STREQUAL Linux)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unknown-pragmas -Wno-unused-variable -Wno-unused-parameter")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32 -fsanitize=address -fsanitize-address-use-after-scope")
set(CMAKE_PREFIX_PATH /usr)
set(CMAKE_LIBRARY_ARCHITECTURE i386-linux-gnu)
set(CMAKE_LIBRARY_PATH "/usr/lib32" CACHE PATH "")
set(CMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX 32)
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif ()
if(APPLE)
add_compile_options(-Wno-declaration-after-statement)
if (CMAKE_SYSTEM_NAME STREQUAL Linux)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unknown-pragmas -Wno-unused-variable -Wno-unused-parameter")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32 -fsanitize=address -fsanitize-address-use-after-scope")
set(CMAKE_PREFIX_PATH /usr)
set(CMAKE_LIBRARY_ARCHITECTURE i386-linux-gnu)
set(CMAKE_LIBRARY_PATH "/usr/lib32" CACHE PATH "")
set(CMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX 32)
endif ()
if (APPLE)
add_compile_options(-Wno-declaration-after-statement)
endif ()
add_compile_options(-fsanitize=address)
if (MSVC)
add_compile_options(/bigobj)
add_compile_options(/bigobj)
endif ()
add_subdirectory(extern/aurora EXCLUDE_FROM_ALL)
add_subdirectory(extern/musyx EXCLUDE_FROM_ALL)
set(DOLPHIN_FILES
src/dolphin/mtx/mtx.c
src/dolphin/mtx/mtx44.c
src/dolphin/mtx/vec.c
src/dolphin/os/OSAlloc.c
src/dolphin/os/OSArena.c
src/dolphin/os/OSStopwatch.c
src/dolphin/mtx/mtx.c
src/dolphin/mtx/mtx44.c
src/dolphin/mtx/vec.c
src/dolphin/os/OSAlloc.c
src/dolphin/os/OSArena.c
src/dolphin/os/OSStopwatch.c
)
set(GAME_FILES
src/game/armem.c
src/game/card.c
src/game/ClusterExec.c
src/game/data.c
src/game/decode.c
src/game/dvd.c
src/game/EnvelopeExec.c
src/game/esprite.c
src/game/fault.c
src/game/flag.c
src/game/font.c
src/game/frand.c
src/game/gamework.c
src/game/hsfanim.c
src/game/hsfdraw.c
src/game/hsfex.c
src/game/hsfload.c
src/game/hsfman.c
src/game/hsfmotion.c
src/game/init.c
src/game/main.c
src/game/malloc.c
src/game/memory.c
src/game/objdll.c
src/game/objmain.c
src/game/ovllist.c
src/game/ShapeExec.c
src/game/sprman.c
src/game/sprput.c
src/game/pad.c
src/game/perf.c
src/game/printfunc.c
src/game/process.c
src/game/window.c
src/game/wipe.c
src/game/armem.c
src/game/card.c
src/game/ClusterExec.c
src/game/data.c
src/game/decode.c
src/game/dvd.c
src/game/EnvelopeExec.c
src/game/esprite.c
src/game/fault.c
src/game/flag.c
src/game/font.c
src/game/frand.c
src/game/gamework.c
src/game/hsfanim.c
src/game/hsfdraw.c
src/game/hsfex.c
src/game/hsfload.c
src/game/hsfman.c
src/game/hsfmotion.c
src/game/init.c
src/game/main.c
src/game/malloc.c
src/game/memory.c
src/game/objdll.c
src/game/objmain.c
src/game/ovllist.c
src/game/ShapeExec.c
src/game/sprman.c
src/game/sprput.c
src/game/pad.c
src/game/perf.c
src/game/printfunc.c
src/game/process.c
src/game/window.c
src/game/wipe.c
)
set(PORT_FILES
src/port/ar.c
src/port/arq.c
src/port/audio.c
src/port/byteswap.cpp
src/port/dvd.c
src/port/imgui.cpp
src/port/OS.c
src/port/stubs.c
src/port/ar.c
src/port/arq.c
src/port/audio.c
src/port/byteswap.cpp
src/port/dvd.c
src/port/imgui.cpp
src/port/OS.c
src/port/stubs.c
)
source_group("Dolphin" FILES ${DOLPHIN_FILES})
@ -100,12 +100,12 @@ source_group("Game" FILES ${GAME_FILES})
source_group("Port" FILES ${PORT_FILES})
if (NOT MSVC)
foreach(file ${DOLPHIN_FILES})
set_source_files_properties(${file} PROPERTIES COMPILE_FLAGS "-std=c89 -Dinline=")
endforeach()
foreach(file ${GAME_FILES})
set_source_files_properties(${file} PROPERTIES COMPILE_FLAGS "-std=c89 -Dinline=")
endforeach()
foreach (file ${DOLPHIN_FILES})
set_source_files_properties(${file} PROPERTIES COMPILE_FLAGS "-std=c89 -Dinline=")
endforeach ()
foreach (file ${GAME_FILES})
set_source_files_properties(${file} PROPERTIES COMPILE_FLAGS "-std=c89 -Dinline=")
endforeach ()
endif ()
@ -114,23 +114,38 @@ target_compile_definitions(dol PRIVATE TARGET_PC TARGET_DOL VERSION=${VERSION} M
target_include_directories(dol PRIVATE include build/GMPE01_00/include)
target_link_libraries(dol PRIVATE aurora::core aurora::gx aurora::vi musyx)
if (MSVC)
target_link_options(dol PRIVATE "/DEF:${CMAKE_SOURCE_DIR}/dol.def")
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
enable_language(ASM_MASM)
target_sources(dol PRIVATE extern/longjmp_win64/longjmp_win64.asm)
set_source_files_properties(extern/longjmp_win64/longjmp_win64.asm PROPERTIES LANGUAGE ASM_MASM)
endif ()
target_link_options(dol PRIVATE "/DEF:${CMAKE_SOURCE_DIR}/dol.def")
else ()
target_compile_options(dol PRIVATE "-fvisibility=default")
endif()
target_compile_options(dol PRIVATE "-fvisibility=default")
endif ()
add_executable(marioparty4 src/port/portmain.c)
target_compile_definitions(marioparty4 PRIVATE TARGET_PC VERSION=${VERSION})
target_include_directories(marioparty4 PRIVATE include)
target_link_libraries(marioparty4 PRIVATE dol aurora::main)
add_library(bootDll SHARED src/REL/bootDll/main.c src/REL/bootDll/language.c)
target_compile_definitions(bootDll PRIVATE TARGET_PC VERSION=${VERSION})
target_include_directories(bootDll PRIVATE include build/GMPE01_00/include)
if (MSVC)
set_target_properties(bootDll PROPERTIES LINK_FLAGS "/EXPORT:ObjectSetup")
else ()
endif()
set(CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS OFF)
target_link_libraries(bootDll PRIVATE dol musyx)
file(GLOB REL_DIRS RELATIVE ${CMAKE_SOURCE_DIR}/src/REL ${CMAKE_SOURCE_DIR}/src/REL/*)
foreach (dir ${REL_DIRS})
if (IS_DIRECTORY ${CMAKE_SOURCE_DIR}/src/REL/${dir})
file(GLOB_RECURSE REL_FILES src/REL/${dir}/*.c)
if (REL_FILES)
add_library(${dir} SHARED ${REL_FILES})
target_compile_definitions(${dir} PRIVATE TARGET_PC VERSION=${VERSION})
target_include_directories(${dir} PRIVATE include build/GMPE01_00/include)
if (MSVC)
set_target_properties(${dir} PROPERTIES LINK_FLAGS "/EXPORT:ObjectSetup")
else ()
endif ()
target_link_libraries(${dir} PRIVATE dol musyx)
endif ()
endif ()
endforeach ()
add_dependencies(marioparty4 bootDll)

1
extern/longjmp_win64 vendored Submodule

@ -0,0 +1 @@
Subproject commit d04c5b7b486dbd2b80610fe2a5880e833933807f

View file

@ -2,12 +2,20 @@
#define _GAME_JMP_H
#ifdef TARGET_PC
#include <setjmp.h>
#include <stdint.h>
#ifdef _M_X64
#include "../extern/longjmp_win64/longjmp_win64.h"
#define SETJMP setjmp_win64
#define LONGJMP longjmp_win64
#define JMPBUF JMP_BUF_WIN64
#else
#include <setjmp.h>
#define SETJMP setjmp
#define LONGJMP longjmp
#define JMPBUF jmp_buf
#endif
#ifndef _JMP_BUF_DEFINED
#if defined(_M_IX86) || defined(__i386__)
@ -24,7 +32,7 @@ typedef struct __JUMP_BUFFER {
uint32_t UnwindFunc;
uint32_t UnwindData[6];
} _JUMP_BUFFER;
#elif defined(_M_X64) || defined(__x86_64__)
#elif defined(__x86_64__)
#ifndef SETJMP_FLOAT128
// TODO do we need to align this?
typedef struct _SETJMP_FLOAT128 {
@ -136,9 +144,12 @@ typedef struct _JUMP_BUFFER {
#if defined(_M_IX86) || defined(__i386__)
#define SETJMP_SET_IP(jump, func) ((_JUMP_BUFFER *)((jump)))->Eip = (uintptr_t)func
#define SETJMP_SET_SP(jump, sp) ((_JUMP_BUFFER *)((jump)))->Esp = (uintptr_t)sp
#elif defined(_M_X64) || defined(__x86_64__)
#elif defined(__x86_64__)
#define SETJMP_SET_IP(jump, func) ((_JUMP_BUFFER *)((jump)))->Rip = (uintptr_t)func
#define SETJMP_SET_SP(jump, sp) ((_JUMP_BUFFER *)((jump)))->Rsp = (uintptr_t)sp
#elif defined(_M_X64)
#define SETJMP_SET_IP(jump, func) (jump)->rip_getjmp = (uintptr_t)func
#define SETJMP_SET_SP(jump, sp) (jump)->rsp_getjmp = (uintptr_t)sp
#elif defined(_M_ARM) || defined(__arm__)
#define SETJMP_SET_IP(jump, func) ((_JUMP_BUFFER *)((jump)))->Pc = (uintptr_t)func
#define SETJMP_SET_SP(jump, sp) ((_JUMP_BUFFER *)((jump)))->Sp = (uintptr_t)sp
@ -166,6 +177,7 @@ typedef struct jmp_buf {
s32 gcsetjmp(jmp_buf *jump);
s32 gclongjmp(jmp_buf *jump, s32 status);
#define JMPBUF jmp_buf
#define SETJMP(jump) gcsetjmp(&(jump))
#define LONGJMP(jump, status) gclongjmp(&(jump), (status))

View file

@ -27,7 +27,7 @@ typedef struct process {
u16 prio;
s32 sleep_time;
uintptr_t base_sp;
jmp_buf jump;
JMPBUF jump;
void (*dtor)(void);
void *user_data;
} Process;

View file

@ -14,7 +14,7 @@
#define EXEC_CHILDWATCH 2
#define EXEC_KILLED 3
static jmp_buf processjmpbuf;
static JMPBUF processjmpbuf;
static Process *processtop;
static Process *processcur;
static u16 processcnt;