From 7d1625734f00add0b080dbfcc481e354b64ecb1f Mon Sep 17 00:00:00 2001 From: water Date: Fri, 4 Sep 2020 20:00:45 -0400 Subject: [PATCH] small fixes for linux --- game/CMakeLists.txt | 1 + game/kernel/asm_funcs.asm | 42 +++++++++++++++++++++++++++++++++++--- game/kernel/kscheme.cpp | 13 +++++++++--- game/overlord/fake_iso.cpp | 5 ++++- 4 files changed, 54 insertions(+), 7 deletions(-) diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index a6b6357ee5..59cacdf7af 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -7,6 +7,7 @@ if(CMAKE_COMPILER_IS_GNUCXX) message(STATUS "GCC detected, adding compile flags") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \ + -ggdb \ -Wall \ -Winit-self \ -Wextra \ diff --git a/game/kernel/asm_funcs.asm b/game/kernel/asm_funcs.asm index e0e1f3b0fb..2b41efe59d 100644 --- a/game/kernel/asm_funcs.asm +++ b/game/kernel/asm_funcs.asm @@ -14,8 +14,8 @@ SECTION .TEXT ;; a pointer to this array of GOAL arguments as the argument. The reason for this is that GOAL and ;; the standard System V ABI used in Linux are different for 8 argument function calls. -global _format -_format: +global _format_win32 +_format_win32: ; GOAL will call with regs RDI, RSI, RDX, RCX, R8, R9, R10, R11 ; to make sure the stack frame is aligned @@ -39,6 +39,42 @@ _format: call format_impl add rsp, 32 + ; restore + ; (note - this could probably just be add rsp 72, we don't care about the value of these register) + pop rdi + pop rsi + pop rdx + pop rcx + pop r8 + pop r9 + pop r10 + pop r11 + add rsp, 8 + ret + +global _format_linux +_format_linux: + ; GOAL will call with regs RDI, RSI, RDX, RCX, R8, R9, R10, R11 + + ; to make sure the stack frame is aligned + sub rsp, 8 + + ; push all registers and create the register array on the stack + push r11 + push r10 + push r9 + push r8 + push rcx + push rdx + push rsi + push rdi + + ; set the first argument register to the stack argument array + mov rdi, rsp + + ; call C function to do format, result will go in RAX + call format_impl + ; restore ; (note - this could probably just be add rsp 72, we don't care about the value of these register) pop rdi @@ -148,4 +184,4 @@ _call_goal_asm_win32: pop rbx pop rdx - ret \ No newline at end of file + ret diff --git a/game/kernel/kscheme.cpp b/game/kernel/kscheme.cpp index 5d32b9e649..d2c41a96cb 100644 --- a/game/kernel/kscheme.cpp +++ b/game/kernel/kscheme.cpp @@ -1517,7 +1517,11 @@ s32 test_function(s32 arg0, s32 arg1, s32 arg2, s32 arg3) { extern "C" { // defined in asm_funcs. It calls format_impl and sets up arguments correctly. -void _format(); +#ifdef __linux__ +void _format_linux(); +#elif _WIN32 +void _format_win32(); +#endif } /*! @@ -1769,8 +1773,11 @@ s32 InitHeapAndSymbol() { make_function_symbol_from_c("load", (void*)load); make_function_symbol_from_c("loado", (void*)loado); make_function_symbol_from_c("unload", (void*)unload); - - make_function_symbol_from_c("_format", (void*)_format); +#ifdef __linux__ + make_function_symbol_from_c("_format", (void*)_format_linux); +#elif _WIN32 + make_function_symbol_from_c("_format", (void*)_format_win32); +#endif // allocations make_function_symbol_from_c("malloc", (void*)alloc_heap_memory); diff --git a/game/overlord/fake_iso.cpp b/game/overlord/fake_iso.cpp index 91840ec4f9..f06c22ba83 100644 --- a/game/overlord/fake_iso.cpp +++ b/game/overlord/fake_iso.cpp @@ -194,6 +194,9 @@ static const char* get_file_path(FileRecord* fr) { assert(fr->location < fake_iso_entry_count); static char path_buffer[1024]; strcpy(path_buffer, next_dir); +#ifdef __linux__ + strcat(path_buffer, "/"); +#endif strcat(path_buffer, fake_iso_entries[fr->location].file_path); return path_buffer; } @@ -352,4 +355,4 @@ uint32_t FS_LoadSoundBank(char* name, void* buffer) { (void)name; (void)buffer; assert(false); -} \ No newline at end of file +}