Skip to content

Commit 9dafc2f

Browse files
authored
[iQue] Build some C files with EGCS (#2396)
1 parent ffc9f2d commit 9dafc2f

File tree

19 files changed

+121
-37
lines changed

19 files changed

+121
-37
lines changed

Makefile

Lines changed: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,6 @@ N64_EMULATOR ?=
5757
# This may also be used to disable debug features on debug ROMs by setting DEBUG_FEATURES to 0
5858
# DEBUG_FEATURES ?= 1
5959

60-
CFLAGS ?=
61-
CCASFLAGS ?=
62-
CPPFLAGS ?=
63-
CPP_DEFINES ?=
64-
6560
# Version-specific settings
6661
REGIONAL_CHECKSUM := 0
6762
ifeq ($(VERSION),ntsc-1.0)
@@ -209,7 +204,6 @@ EXTRACTED_DIR := extracted/$(VERSION)
209204
VENV := .venv
210205

211206
MAKE = make
212-
CPPFLAGS += -P -xc -fno-dollars-in-identifiers
213207

214208
ifeq ($(PLATFORM),N64)
215209
CPP_DEFINES += -DPLATFORM_N64=1 -DPLATFORM_GC=0 -DPLATFORM_IQUE=0
@@ -287,6 +281,9 @@ ifeq ($(ORIG_COMPILER),1)
287281
CCAS := $(CC)
288282
endif
289283

284+
EGCS_PREFIX := tools/egcs/$(DETECTED_OS)/
285+
EGCS_CC := $(EGCS_PREFIX)gcc -B $(EGCS_PREFIX)
286+
290287
AS := $(MIPS_BINUTILS_PREFIX)as
291288
LD := $(MIPS_BINUTILS_PREFIX)ld
292289
OBJCOPY := $(MIPS_BINUTILS_PREFIX)objcopy
@@ -335,10 +332,6 @@ SEQ_CPPFLAGS := -D_LANGUAGE_ASEQ -DMML_VERSION=MML_VERSION_OOT $(CPP_DEFINES) -
335332
SBCFLAGS := --matching
336333
SFCFLAGS := --matching
337334

338-
CFLAGS += $(CPP_DEFINES)
339-
CCASFLAGS := $(CPP_DEFINES)
340-
CPPFLAGS += $(CPP_DEFINES)
341-
342335
# Extra debugging steps
343336
ifeq ($(DEBUG_OBJECTS),1)
344337
OBJDUMP_CMD = @$(OBJDUMP) $(OBJDUMP_FLAGS) $@ > $(@:.o=.s)
@@ -360,20 +353,20 @@ ifeq ($(DEBUG_FEATURES),1)
360353
GBI_DEFINES += -DGBI_DEBUG
361354
endif
362355

363-
CFLAGS += $(GBI_DEFINES)
364-
365-
ASFLAGS := -march=vr4300 -32 -no-pad-sections -Iinclude -I$(EXTRACTED_DIR)
356+
CPPFLAGS += -P -xc -fno-dollars-in-identifiers $(CPP_DEFINES)
357+
ASFLAGS += -march=vr4300 -32 -no-pad-sections -Iinclude -I$(EXTRACTED_DIR)
366358

367359
ifeq ($(COMPILER),gcc)
368-
CFLAGS += -G 0 -nostdinc $(INC) -march=vr4300 -mfix4300 -mabi=32 -mno-abicalls -mdivide-breaks -fno-PIC -fno-common -ffreestanding -fbuiltin -fno-builtin-sinf -fno-builtin-cosf $(CHECK_WARNINGS) -funsigned-char
369-
CCASFLAGS += -G 0 -nostdinc $(INC) -march=vr4300 -mfix4300 -mabi=32 -mno-abicalls -fno-PIC -fno-common -Wa,-no-pad-sections
360+
CFLAGS += $(CPP_DEFINES) $(GBI_DEFINES) -G 0 -nostdinc $(INC) -march=vr4300 -mfix4300 -mabi=32 -mno-abicalls -mdivide-breaks -fno-PIC -fno-common -ffreestanding -funsigned-char -fbuiltin -fno-builtin-sinf -fno-builtin-cosf $(CHECK_WARNINGS)
361+
CCASFLAGS += $(CPP_DEFINES) $(GBI_DEFINES) -G 0 -nostdinc $(INC) -march=vr4300 -mfix4300 -mabi=32 -mno-abicalls -fno-PIC -fno-common -Wa,-no-pad-sections
370362
MIPS_VERSION := -mips3
371363
else
372364
# Suppress warnings for wrong number of macro arguments (to fake variadic
373365
# macros) and Microsoft extensions such as anonymous structs (which the
374366
# compiler does support but warns for their usage).
375-
CFLAGS += -G 0 -non_shared -fullwarn -verbose -Xcpluscomm $(INC) -Wab,-r4300_mul -woff 516,609,649,838,712,807
376-
CCASFLAGS += -G 0 -non_shared -fullwarn -verbose -Xcpluscomm $(INC) -Wab,-r4300_mul -woff 516,609,649,838,712,807 -o32
367+
CFLAGS += $(CPP_DEFINES) $(GBI_DEFINES) -G 0 -non_shared -fullwarn -verbose -Xcpluscomm $(INC) -Wab,-r4300_mul -woff 516,609,649,838,712,807
368+
CCASFLAGS += $(CPP_DEFINES) $(GBI_DEFINES) -G 0 -non_shared -fullwarn -verbose -Xcpluscomm $(INC) -Wab,-r4300_mul -woff 516,609,649,838,712,807 -o32
369+
EGCS_CFLAGS += $(CPP_DEFINES) $(GBI_DEFINES) -G 0 -nostdinc $(INC) -mcpu=vr4300 -mabi=32 -mgp32 -mfp32 -fno-PIC
377370
MIPS_VERSION := -mips2
378371
endif
379372

@@ -503,7 +496,7 @@ O_FILES := $(foreach f,$(S_FILES:.s=.o),$(BUILD_DIR)/$f) \
503496
$(foreach f,$(ASSET_C_FILES_COMMITTED:.c=.o),$(BUILD_DIR)/$f) \
504497
$(foreach f,$(BASEROM_BIN_FILES),$(BUILD_DIR)/baserom/$(notdir $f).o) \
505498
$(BUILD_DIR)/src/code/z_message_z_game_over.o \
506-
$(BUILD_DIR)/src/makerom/ipl3.o
499+
$(BUILD_DIR)/src/makerom/ipl3.o
507500

508501
OVL_RELOC_FILES := $(shell $(CPP) $(CPPFLAGS) $(SPEC) | $(BUILD_DIR_REPLACE) | grep -o '[^"]*_reloc.o' )
509502

@@ -564,6 +557,34 @@ endif
564557
$(BUILD_DIR)/src/code/jpegutils.o: CC := $(CC_OLD)
565558
$(BUILD_DIR)/src/code/jpegdecoder.o: CC := $(CC_OLD)
566559

560+
ifeq ($(PLATFORM),IQUE)
561+
# Some files are compiled with EGCS on iQue
562+
EGCS_O_FILES += $(BUILD_DIR)/src/boot/boot_main.o
563+
EGCS_O_FILES += $(BUILD_DIR)/src/boot/idle.o
564+
EGCS_O_FILES += $(BUILD_DIR)/src/boot/z_locale.o
565+
EGCS_O_FILES += $(BUILD_DIR)/src/boot/z_std_dma.o
566+
EGCS_O_FILES += $(BUILD_DIR)/src/boot/zlib.o
567+
# EGCS_O_FILES += (BUILD_DIR)/src/code/z_actor.o
568+
EGCS_O_FILES += $(BUILD_DIR)/src/code/z_common_data.o
569+
EGCS_O_FILES += $(BUILD_DIR)/src/code/z_construct.o
570+
# EGCS_O_FILES += (BUILD_DIR)/src/code/z_kanfont.o
571+
# EGCS_O_FILES += (BUILD_DIR)/src/code/z_message.o
572+
EGCS_O_FILES += $(BUILD_DIR)/src/code/z_parameter.o
573+
# EGCS_O_FILES += (BUILD_DIR)/src/code/z_sram.o
574+
EGCS_O_FILES += $(BUILD_DIR)/src/overlays/actors/ovl_En_Mag/z_en_mag.o
575+
EGCS_O_FILES += $(BUILD_DIR)/src/overlays/actors/ovl_End_Title/z_end_title.o
576+
EGCS_O_FILES += $(BUILD_DIR)/src/overlays/actors/ovl_Fishing/z_fishing.o
577+
# EGCS_O_FILES += (BUILD_DIR)/src/overlays/gamestates/ovl_file_choose/z_file_copy_erase.o
578+
EGCS_O_FILES += $(BUILD_DIR)/src/overlays/gamestates/ovl_opening/z_opening.o
579+
EGCS_O_FILES += $(BUILD_DIR)/src/overlays/gamestates/ovl_title/z_title.o
580+
EGCS_O_FILES += $(BUILD_DIR)/src/overlays/misc/ovl_kaleido_scope/z_kaleido_map.o
581+
EGCS_O_FILES += $(BUILD_DIR)/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope.o
582+
583+
$(EGCS_O_FILES): CC := $(EGCS_CC)
584+
$(EGCS_O_FILES): CFLAGS := $(EGCS_CFLAGS) -mno-abicalls
585+
$(EGCS_O_FILES): MIPS_VERSION := -mips3
586+
endif
587+
567588
ifeq ($(DEBUG_FEATURES),1)
568589
$(BUILD_DIR)/src/libc/%.o: OPTFLAGS := -g
569590
$(BUILD_DIR)/src/libc/%.o: ASOPTFLAGS := -g
@@ -589,7 +610,12 @@ endif
589610
$(BUILD_DIR)/src/audio/sfx.o: CFLAGS += -use_readwrite_const
590611
$(BUILD_DIR)/src/audio/sequence.o: CFLAGS += -use_readwrite_const
591612

613+
ifeq ($(PLATFORM),IQUE)
614+
$(BUILD_DIR)/src/libultra/%.o: CC := $(EGCS_CC)
615+
$(BUILD_DIR)/src/libultra/%.o: CFLAGS := $(EGCS_CFLAGS) -mno-abicalls
616+
else
592617
$(BUILD_DIR)/src/libultra/%.o: CC := $(CC_OLD)
618+
endif
593619

594620
$(BUILD_DIR)/src/libultra/libc/ll.o: OPTFLAGS := -O1
595621
$(BUILD_DIR)/src/libultra/libc/ll.o: MIPS_VERSION := -mips3 -32
@@ -648,6 +674,11 @@ endif
648674
$(BUILD_DIR)/src/libleo/%.o: CC := $(CC_OLD)
649675
$(BUILD_DIR)/src/libleo/%.o: OPTFLAGS := -O2
650676

677+
ifeq ($(PLATFORM),IQUE)
678+
$(BUILD_DIR)/src/libgcc/%.o: CC := $(EGCS_CC)
679+
$(BUILD_DIR)/src/libgcc/%.o: CFLAGS := $(EGCS_CFLAGS)
680+
endif
681+
651682
$(BUILD_DIR)/assets/misc/z_select_static/%.o: GBI_DEFINES := -DF3DEX_GBI
652683

653684
# For using asm_processor on some files:

include/attributes.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,22 @@
88
#endif
99

1010
#define UNUSED __attribute__((unused))
11-
#define FALLTHROUGH __attribute__((fallthrough))
12-
#define NORETURN __attribute__((noreturn))
1311
#define NO_REORDER __attribute__((no_reorder))
1412
#define SECTION_DATA __attribute__((section(".data")))
1513

16-
#ifdef __GNUC__
14+
#if __GNUC__ >= 7
15+
#define FALLTHROUGH __attribute__((fallthrough))
16+
#else
17+
#define FALLTHROUGH
18+
#endif
19+
20+
#if defined(__GNUC__) && defined(NON_MATCHING)
21+
#define NORETURN __attribute__((noreturn))
22+
#else
23+
#define NORETURN
24+
#endif
25+
26+
#if defined(__GNUC__) && defined(NON_MATCHING)
1727
#define UNREACHABLE() __builtin_unreachable()
1828
#else
1929
#define UNREACHABLE()

include/libc/assert.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ __attribute__((noreturn)) void __assert(const char* assertion, const char* file,
2929

3030
// Static/compile-time assertions
3131

32-
#if !defined(__sgi) && (defined(__GNUC__) || (__STDC_VERSION__ >= 201112L))
32+
#if !defined(__sgi) && (__GNUC__ >= 5 || __STDC_VERSION__ >= 201112L)
3333
# define static_assert(cond, msg) _Static_assert(cond, msg)
3434
#else
3535
# ifndef GLUE

include/libc/stdarg.h

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
#ifndef STDARG_H
22
#define STDARG_H
33

4-
// When building with GCC, use the official vaarg macros to avoid warnings and possibly bad codegen.
4+
// When building with modern GCC, use the official vaarg macros to avoid warnings and possibly bad codegen.
55

6-
#ifdef __GNUC__
6+
#if __GNUC__ >= 3
77

88
#define va_list __builtin_va_list
99
#define va_start __builtin_va_start
1010
#define va_arg __builtin_va_arg
1111
#define va_end __builtin_va_end
1212

13-
#else
13+
#elif defined(__sgi) /* IDO */
1414

1515
#ifndef _VA_LIST_
1616
# define _VA_LIST_
@@ -52,6 +52,28 @@ typedef char* va_list;
5252
/* No cleanup processing is required for the end of a varargs list: */
5353
#define va_end(__list)
5454

55-
#endif /* __GNUC__ */
55+
#else /* EGCS */
56+
57+
typedef char * __gnuc_va_list;
58+
59+
#define __va_rounded_size(__TYPE) \
60+
(((sizeof (__TYPE) + sizeof (int) - 1) / sizeof (int)) * sizeof (int))
61+
62+
#define va_start(__AP, __LASTARG) \
63+
(__AP = (__gnuc_va_list) __builtin_next_arg (__LASTARG))
64+
65+
#define va_end(__AP) ((void)0)
66+
67+
/* We cast to void * and then to TYPE * because this avoids
68+
a warning about increasing the alignment requirement. */
69+
#define va_arg(__AP, __type) \
70+
((__type *) (void *) (__AP = (char *) ((__alignof__(__type) > 4 \
71+
? ((__PTRDIFF_TYPE__)__AP + 8 - 1) & -8 \
72+
: ((__PTRDIFF_TYPE__)__AP + 4 - 1) & -4) \
73+
+ __va_rounded_size(__type))))[-1]
74+
75+
typedef __gnuc_va_list va_list;
76+
77+
#endif
5678

5779
#endif

include/libc/stddef.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ typedef unsigned long size_t;
1515

1616
#endif
1717

18-
#ifdef __GNUC__
18+
#if __GNUC__ >= 4
1919
#define offsetof(structure, member) __builtin_offsetof (structure, member)
2020
#else
2121
#define offsetof(structure, member) ((size_t)&(((structure*)0)->member))

include/macros.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
#define PRINTF osSyncPrintf
5454
#elif IDO_PRINTF_WORKAROUND
5555
#define PRINTF(args) (void)0
56+
#elif defined(__GNUC__) && __GNUC__ < 3
57+
#define PRINTF(format, args...) (void)0
5658
#else
5759
#define PRINTF(format, ...) (void)0
5860
#endif

include/ultra64/libc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
void osSyncPrintf(const char* fmt, ...);
77

8-
#ifdef __GNUC__
8+
#if defined(__GNUC__) && defined(NON_MATCHING)
99
void bzero(void* __s, unsigned int __n);
1010
int bcmp(const void* __sl, const void* __s2, unsigned int __n);
1111
void bcopy(const void* __src, void* __dest, unsigned int __n);

include/z64audio.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,9 @@ typedef struct AdpcmBookHeader {
201201
* The procedure used to design the codeBook is based on an adaptive clustering algorithm.
202202
* The size of the codeBook is (8 * order * numPredictors) and is 8-byte aligned
203203
*/
204-
typedef s16 AdpcmBookData[];
205-
206204
typedef struct AdpcmBook {
207205
/* 0x00 */ AdpcmBookHeader header;
208-
/* 0x08 */ AdpcmBookData book; // size 8 * order * numPredictors. 8-byte aligned
206+
/* 0x08 */ s16 book[1]; // size 8 * order * numPredictors. 8-byte aligned
209207
} AdpcmBook; // size >= 0x8
210208

211209
typedef struct Sample {

src/audio/general.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#define AUDIO_PRINTF osSyncPrintf
99
#elif IDO_PRINTF_WORKAROUND
1010
#define AUDIO_PRINTF(args) (void)0
11+
#elif defined(__GNUC__) && __GNUC__ < 3
12+
#define AUDIO_PRINTF(format, args...) (void)0
1113
#else
1214
#define AUDIO_PRINTF(format, ...) (void)0
1315
#endif

src/code/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ extern struct IrqMgr gIrqMgr;
2424
#endif
2525

2626
#pragma increment_block_number "gc-eu:160 gc-eu-mq:160 gc-jp:160 gc-jp-ce:160 gc-jp-mq:160 gc-us:160 gc-us-mq:160" \
27-
"ntsc-1.0:141 ntsc-1.1:141 ntsc-1.2:141 pal-1.0:139 pal-1.1:139"
27+
"ntsc-1.0:142 ntsc-1.1:142 ntsc-1.2:142 pal-1.0:140 pal-1.1:140"
2828

2929
extern u8 _buffersSegmentEnd[];
3030

0 commit comments

Comments
 (0)