Skip to content

Commit 6e9175b

Browse files
hensldmThar0cadmic
authored
Modern GCC (#88)
* Add modern gcc makefile * Add MODERN define to actually be able to build * Better modern gcc builds Co-authored-by: Tharo <[email protected]> Co-authored-by: cadmic <[email protected]> * Warnings * MODERN_CC * OPTFLAGS * no-strict-aliasing --------- Co-authored-by: Tharo <[email protected]> Co-authored-by: cadmic <[email protected]>
1 parent bcca1c8 commit 6e9175b

14 files changed

+255
-1
lines changed

Makefile

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
COMPARE ?= 1
22
FIXUPS ?= 0
3+
MODERN_GCC ?= 0
34

45
ifneq ($(FIXUPS),0)
56
COMPARE := 0
@@ -20,6 +21,12 @@ else
2021
$(error Invalid Target)
2122
endif
2223

24+
ifneq ($(MODERN_GCC),0)
25+
COMPILER := modern_gcc
26+
COMPARE := 0
27+
FIXUPS := 0
28+
endif
29+
2330
BASE_DIR := extracted/$(VERSION)/$(TARGET)
2431
BASE_AR := base/$(VERSION)/$(TARGET).a
2532
BUILD_ROOT := build
@@ -43,6 +50,8 @@ ifeq ($(COMPILER),gcc)
4350
-include makefiles/gcc.mk
4451
else ifeq ($(COMPILER),ido)
4552
-include makefiles/ido.mk
53+
else ifeq ($(COMPILER),modern_gcc)
54+
-include makefiles/modern_gcc.mk
4655
else
4756
$(error Invalid Compiler)
4857
endif

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,9 @@ If building for use with modern linkers, than you can use `FIXUPS=1` like the th
7070
- `make VERSION=L TARGET=libgultra_rom FIXUPS=1`
7171

7272
note that running with `FIXUPS=1` will automatically set `COMPARE=0`.
73+
74+
It is also possible to build archives using modern gcc by using `MODERN_GCC=1` like the following:
75+
76+
- `make VERSION=L TARGET=libgultra_rom MODERN_GCC=1`
77+
78+
note that running with `MODERN_GCC=1` will automatically set `COMPARE=0` and `FIXUPS=0`.

include/PR/os_libc.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,15 @@ extern "C" {
8080

8181
/* byte string operations */
8282

83-
83+
#ifndef MODERN_CC
8484
extern void bcopy(const void *, void *, int);
8585
extern int bcmp(const void *, const void *, int);
8686
extern void bzero(void *, int);
87+
#else
88+
extern void bcopy(const void *, void *, size_t);
89+
extern int bcmp(const void *, const void *, size_t);
90+
extern void bzero(void *, size_t);
91+
#endif
8792

8893
/* Printf */
8994

include/modern_gcc/math.h

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Nothing needed here

include/modern_gcc/memory.h

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#ifndef _MEMORY_H
2+
#define _MEMORY_H
3+
/*
4+
memory.h
5+
*/
6+
7+
#ifndef _SIZE_T_DEF
8+
#define _SIZE_T_DEF
9+
typedef unsigned size_t;
10+
#endif
11+
12+
void *memccpy(void *,void *,int,size_t);
13+
void *memchr(void *,int,size_t);
14+
int memcmp(const void *,const void *,size_t);
15+
void *memcpy(void *,const void *,size_t);
16+
int memicmp(void *,void *,size_t);
17+
void *memmove(void *,void *,size_t);
18+
void *memset(void *,int,size_t);
19+
20+
void movmem(void *,void *,unsigned);
21+
void setmem(void *,unsigned,int);
22+
23+
#endif

include/modern_gcc/sgidefs.h

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/* Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
2+
This file is part of the GNU C Library.
3+
Contributed by Ralf Baechle <[email protected]>.
4+
5+
The GNU C Library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Library General Public License as
7+
published by the Free Software Foundation; either version 2 of the
8+
License, or (at your option) any later version.
9+
10+
The GNU C Library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
Library General Public License for more details.
14+
15+
You should have received a copy of the GNU Library General Public
16+
License along with the GNU C Library; see the file COPYING.LIB. If not,
17+
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18+
Boston, MA 02111-1307, USA. */
19+
20+
#ifndef _SGIDEFS_H
21+
#define _SGIDEFS_H 1
22+
23+
/*
24+
* Definitions for the ISA level
25+
*/
26+
#define _MIPS_ISA_MIPS1 1
27+
#define _MIPS_ISA_MIPS2 2
28+
#define _MIPS_ISA_MIPS3 3
29+
#define _MIPS_ISA_MIPS4 4
30+
#define _MIPS_ISA_MIPS5 5
31+
32+
/*
33+
* Subprogram calling convention
34+
*
35+
* At the moment only _MIPS_SIM_ABI32 is in use. This will change rsn.
36+
* Until GCC 2.8.0 is released don't rely on this definitions because the
37+
* 64bit code is essentially using the 32bit interface model just with
38+
* 64bit registers.
39+
*/
40+
#define _MIPS_SIM_ABI32 1
41+
#define _MIPS_SIM_NABI32 2
42+
#define _MIPS_SIM_ABI64 3
43+
44+
#endif /* sgidefs.h */

include/modern_gcc/stdarg.h

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#ifndef _STDARG_H
2+
#define _STDARG_H
3+
4+
#define va_list __builtin_va_list
5+
#define va_start __builtin_va_start
6+
#define va_arg __builtin_va_arg
7+
#define va_end __builtin_va_end
8+
9+
#endif

include/modern_gcc/stdio.h

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Nothing needed here

include/modern_gcc/stdlib.h

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#ifndef _STDLIB_H
2+
#define _STDLIB_H
3+
/*
4+
stdlib.h
5+
*/
6+
7+
#ifndef _SIZE_T_DEF
8+
#define _SIZE_T_DEF
9+
typedef unsigned size_t;
10+
#endif
11+
12+
#ifndef _DIV_T_DEF
13+
#define _DIV_T_DEF
14+
typedef struct DIV_T {
15+
int quot;
16+
int rem;
17+
} div_t;
18+
#endif
19+
20+
#ifndef _LDIV_T_DEF
21+
#define _LDIV_T_DEF
22+
typedef struct LDIV_T {
23+
long quot;
24+
long rem;
25+
} ldiv_t;
26+
#endif
27+
28+
#ifndef _LLDIV_T_DEF
29+
#define _LLDIV_T_DEF
30+
typedef struct lldiv_t
31+
{
32+
long long quot;
33+
long long rem;
34+
} lldiv_t;
35+
#endif
36+
37+
#ifndef NULL
38+
#define NULL 0
39+
#endif
40+
41+
#define _max(a,b) (((a) > (b)) ? (a) : (b))
42+
#define _min(a,b) (((a) < (b)) ? (a) : (b))
43+
44+
#define RAND_MAX 32767
45+
46+
int rand(void);
47+
void srand(unsigned);
48+
49+
int abs(int);
50+
long labs(long);
51+
52+
div_t div(int,int);
53+
ldiv_t ldiv(long,long);
54+
lldiv_t lldiv(long long, long long);
55+
56+
int atoi(const char *);
57+
long atol(const char *);
58+
59+
long strtol(const char *,char **,int);
60+
unsigned long strtoul(const char *,char **,int);
61+
62+
char *itoa(int,char *,int);
63+
char *ltoa(long,char *,int);
64+
char *ultoa(unsigned long,char *,int);
65+
66+
double atof(const char *);
67+
double strtod(const char *,char **);
68+
69+
void qsort(void *,size_t,size_t,int (*)(const void *,const void *));
70+
void *bsearch(const void *,const void *,size_t,size_t,int (*)(const void *,const void *));
71+
72+
void *malloc(size_t);
73+
void *calloc(size_t,size_t);
74+
void *realloc(void *,size_t);
75+
void free(void *);
76+
77+
void exit(int);
78+
79+
void abort(void);
80+
81+
#endif

include/modern_gcc/string.h

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#ifndef _STRING_H
2+
#define _STRING_H
3+
/*
4+
string.h
5+
*/
6+
7+
#ifndef _SIZE_T_DEF
8+
#define _SIZE_T_DEF
9+
typedef unsigned size_t;
10+
#endif
11+
12+
#include "memory.h"
13+
14+
char *stpcpy(char *,const char *);
15+
char *strcat(char *,const char *);
16+
char *strchr(const char *,int);
17+
int strcmp(const char *,const char *);
18+
char *strcpy(char *,const char *);
19+
size_t strcspn(const char *,const char *);
20+
char *strdup(const char *);
21+
char *strerror(int);
22+
int stricmp(const char *,const char *);
23+
size_t strlen(const char *);
24+
char *strlwr(char *);
25+
char *strncat(char *,const char *,size_t);
26+
int strncmp(const char *,const char *,size_t);
27+
char *strncpy(char *,const char *,size_t);
28+
int strnicmp(const char *,const char *,size_t);
29+
char *strnset(char *,int,size_t);
30+
char *strpbrk(const char *,const char *);
31+
char *strrchr(const char *,int);
32+
char *strrev(char *);
33+
char *strset(char *,int);
34+
size_t strspn(const char *,const char *);
35+
char *strstr(const char *,const char *);
36+
char *strtok(char *,const char *);
37+
char *strupr(char *);
38+
39+
#define strcmpi(s1,s2) stricmp(s1,s2)
40+
#define strncmpi(s1,s2,n) strnicmp(s1,s2,n)
41+
42+
#endif

makefiles/modern_gcc.mk

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
COMPILER_DIR := $(dir $(which $(CROSS)gcc))
3+
AS := $(CROSS)gcc -x assembler-with-cpp
4+
CC := $(CROSS)gcc
5+
AR_OLD := $(CROSS)ar
6+
7+
WARNINGS := -Wall -Wextra -Wno-format-security -Wno-unused-function -Wno-unused-parameter -Wno-unused-variable -Wno-builtin-declaration-mismatch
8+
WARNINGS += -Wno-int-conversion -Wno-incompatible-pointer-types -Wno-implicit-function-declaration # TODO: Try adjusting code to remove these
9+
CFLAGS := -G 0 -c -nostdinc -march=vr4300 -mfix4300 -mabi=32 -mno-abicalls -mdivide-breaks -fno-PIC -fno-common -ffreestanding -fbuiltin -fno-builtin-sinf -fno-builtin-cosf -funsigned-char $(WARNINGS)
10+
CFLAGS += -fno-strict-aliasing # TODO: Try adjusting code to remove this
11+
ASFLAGS := -w -nostdinc -c -G 0 -march=vr4300 -mgp32 -mfp32 -DMIPSEB -D_LANGUAGE_ASSEMBLY -D_MIPS_SIM=1 -D_ULTRA64
12+
CPPFLAGS = -DMODERN_CC -D_MIPS_SZLONG=32 -D__USE_ISOC99 $(GBIDEFINE) $(VERSION_DEFINE) $(DEBUGFLAG)
13+
IINC = -I . -I $(WORKING_DIR)/include -I $(WORKING_DIR)/include/modern_gcc -I $(WORKING_DIR)/include/PR
14+
MIPS_VERSION := -mips3
15+
ASOPTFLAGS :=
16+
17+
ifeq ($(findstring _d,$(TARGET)),_d)
18+
OPTFLAGS := -Og -ggdb3 -ffast-math -fno-unsafe-math-optimizations
19+
else
20+
OPTFLAGS := -Os -ggdb3 -ffast-math -fno-unsafe-math-optimizations
21+
endif

src/os/exceptasm.s

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
#ifdef MODERN_CC
2+
.set gp=64
3+
#endif
4+
15
#include "PR/R4300.h"
26
#include "sys/asm.h"
37
#include "sys/regdef.h"

src/os/getfpccsr.s

+4
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@
66
LEAF(__osGetFpcCsr)
77
CFC1( v0, fcr31)
88
jr ra
9+
#ifndef MODERN_CC
910
END(__osGetSR) # @bug: Should be __osGetFpcCsr
11+
#else
12+
END(__osGetFpcCsr)
13+
#endif

src/os/setfpccsr.s

+4
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,8 @@ LEAF(__osSetFpcCsr)
77
CFC1( v0, fcr31)
88
CTC1( a0, fcr31)
99
jr ra
10+
#ifndef MODERN_CC
1011
END(__osSetSR) # @bug: Should be __osSetFpcCsr
12+
#else
13+
END(__osSetFpcCsr)
14+
#endif

0 commit comments

Comments
 (0)