small fixes for linux

This commit is contained in:
water 2020-09-04 20:00:45 -04:00
parent fa40b68a37
commit 7d1625734f
4 changed files with 54 additions and 7 deletions

View file

@ -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 \

View file

@ -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
ret

View file

@ -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);

View file

@ -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);
}
}