port: linux support; horrible hack to avoid segmented address funny moments

linux support only tested a little bit in a VM
This commit is contained in:
fgsfds committed 2023-08-04 23:44:20 +02:00
1 parent 172f943891
commit ea8e49c870
14 files changed
+52 -19

No files matched your search

+18 -8
View File
@@ -67,7 +67,7 @@ ifeq ($(HOST_PLATFORM),)
else # TODO
UNAME_ARCH := $(shell uname -p)
UNAME_OS := $(shell uname -s)
UNAME_OS := `echo $(UNAME_OS) | tr A-Z a-z`
UNAME_OS := $(shell echo $(UNAME_OS) | tr A-Z a-z)
HOST_PLATFORM := $(UNAME_ARCH)-$(UNAME_OS)
endif
endif
@@ -84,7 +84,7 @@ $(info Target platform: $(TARGET_PLATFORM))
# Set whether the target arch is 64- or 32-bit.
ifneq (,$(findstring 64,$(TARGET_PLATFORM)))
# TODO: we're not 64-bit compatible yet
$(error 64-bit target platforms are not supported yet.)
$(error 64-bit target platforms are not supported yet)
TARGET_64BIT = 1
else # TODO
TARGET_64BIT = 0
@@ -97,7 +97,7 @@ TARGET_BIG_ENDIAN = 0 # TODO
ifeq ($(ROMID),ntsc-final)
VERSION = 2
else
$(error ROM version $(VERSION) is not supported.)
$(error ROM version $(VERSION) is not supported)
endif
DEFINES := \
@@ -126,12 +126,21 @@ endif
ifneq (,$(findstring windows,$(TARGET_PLATFORM)))
TOOLCHAIN := $(TOOLCHAIN_ARCH)-w64-mingw32
TARGET_LDFLAGS := $(shell pkg-config sdl2 --libs) -lz -lopengl32
TARGET_CFLAGS := $(shell pkg-config sdl2 --cflags-only-I)
TARGET_LDFLAGS := $(shell pkg-config sdl2 --libs) -lz -lopengl32
# HACKHACKHACK: big one, done to avoid possible collisions with segmented addresses
# by default windows places imagebase for 32-bit EXEs at 0x00400000, so it could easily overflow 0x01000000
# proper solution required instead of this bullshit, like patching all segmented pointers to have the LSB set
TARGET_CFLAGS += -fno-pie
TARGET_LDFLAGS += -Wl,-no-pie -Wl,--image-base=0x12000000
else # TODO
TOOLCHAIN := $(TOOLCHAIN_ARCH)-linux-gnu
TARGET_LDFLAGS := $(shell pkg-config sdl2 --libs) -lGL -lz
TARGET_CFLAGS := $(shell pkg-config sdl2 --cflags-only-I)
TARGET_LDFLAGS := $(shell pkg-config sdl2 --libs) -lGL -lz
# HACKHACKHACK: see above
# I think 32-bit Linux USUALLY places imagebase at 0x08000000-ish, so it's already in rsp seg territory
TARGET_CFLAGS += -fno-pie
TARGET_LDFLAGS += -Wl,-no-pie -Wl,--section-start=.text=0x10000000
endif
# These are still used in the port, but only to generate headers.
@@ -192,8 +201,8 @@ INCLUDES = \
-I src/lib/ultra/audio \
-I port/include
CC := $(TOOLCHAIN)-gcc -std=gnu11
CXX := $(TOOLCHAIN)-g++ -std=gnu++20
CC := $(TOOLCHAIN)-gcc -std=c11
CXX := $(TOOLCHAIN)-g++ -std=c++20
ifneq (,$(CXX_O_FILES))
LD := $(CXX)
else
@@ -251,4 +260,5 @@ allclean:
# rm -rf src/generated
codeclean:
find $(B_DIR)/game $(B_DIR)/inflate $(B_DIR)/lib -name '*.o' -delete
find $(B_DIR)/game $(B_DIR)/inflate $(B_DIR)/lib $(B_DIR)/port -name '*.o' -delete
+3 -3
View File
@@ -80,9 +80,9 @@ extern "C" {
/* byte string operations */
extern void bcopy(const void *, void *, int);
extern int bcmp(const void *, const void *, int);
extern void bzero(void *, int);
extern void bcopy(const void *, void *, size_t);
extern int bcmp(const void *, const void *, size_t);
extern void bzero(void *, size_t);
/* Printf */
File renamed without changes.
+8
View File
@@ -57,6 +57,8 @@ typedef volatile long long vs64; /* signed 64-bit */
typedef float f32; /* single prec floating point */
typedef double f64; /* double prec floating point */
#ifdef PLATFORM_N64
#if !defined(_SIZE_T) && !defined(_SIZE_T_) && !defined(_SIZE_T_DEF)
#define _SIZE_T
#define _SIZE_T_DEF /* exeGCC size_t define label */
@@ -68,6 +70,12 @@ typedef unsigned long size_t;
#endif
#endif
#else
#include <stddef.h>
#endif
#endif /* _LANGUAGE_C */
+3
View File
@@ -3,6 +3,9 @@
#ifdef __MINGW32__
// mingw has its nanosleep implementation in pthread.h for some reson
#include <pthread.h>
#else
#include <unistd.h>
#include <time.h>
#endif
#include "gfx_window_manager_api.h"
+4 -3
View File
@@ -1,6 +1,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdint.h>
#include <string.h>
#include <PR/os_internal.h>
#include <PR/rcp.h>
@@ -425,21 +426,21 @@ OSIntMask osSetIntMask(OSIntMask mask)
/* libc compatibility wrappers */
#ifndef HAVE_BZERO
void bzero(void *ptr, s32 size)
void bzero(void *ptr, size_t size)
{
memset(ptr, 0, size);
}
#endif
#ifndef HAVE_BCOPY
void bcopy(const void *src, void *dst, s32 n)
void bcopy(const void *src, void *dst, size_t n)
{
memcpy(dst, src, n);
}
#endif
#ifndef HAVE_BCMP
s32 bcmp(const void *s1, const void *s2, s32 n)
s32 bcmp(const void *s1, const void *s2, size_t n)
{
return memcmp(s1, s2, n);
}
+1 -1
View File
@@ -1,7 +1,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <PR/ultratypes.h>
#include <PR/sched.h>
#include <PR/ultrasched.h>
#include <PR/os_message.h>
#include "lib/main.h"
+1 -1
View File
@@ -2,7 +2,7 @@
#include <assert.h>
#include <ultra64.h>
#include <PR/sched.h>
#include <PR/ultrasched.h>
#include "lib/sched.h"
#include "lib/vars.h"
#include "constants.h"
+1 -1
View File
@@ -1,5 +1,5 @@
#include <PR/ultratypes.h>
#include <PR/sched.h>
#include <PR/ultrasched.h>
#include "lib/boot.h"
#include "lib/sched.h"
#include "constants.h"
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef _IN_BOOT_SCHED_H
#define _IN_BOOT_SCHED_H
#include <ultra64.h>
#include <sched.h>
#include <PR/ultrasched.h>
#include "types.h"
void schedSetCrashEnable2(s32 enable);
+10
View File
@@ -1,6 +1,8 @@
#ifndef N64_STDARG_H
#define N64_STDARG_H
#ifdef TARGET_N64
// When not building with IDO, use the builtin vaarg macros for portability.
#ifndef __sgi
#define va_list __builtin_va_list
@@ -39,4 +41,12 @@ typedef char *va_list;
#define va_end(__list)
#endif
#else // TARGET_N64
#include_next <stdarg.h>
#warning fuck
#endif
#endif
View File
File renamed without changes.
+1
View File
@@ -58,6 +58,7 @@ extern size_t strlen(const char *);
#else
#include <stddef.h>
#include_next <string.h>
#endif
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef _IN_TYPES_H
#define _IN_TYPES_H
#include <ultra64.h>
#include <sched.h>
#include <PR/ultrasched.h>
#include "n_libaudio.h"
#include "constants.h"
#include "lang.h"