Additional fixes

Rearrange gbafix to not modify file in the event of failure
Fix bug where Dma3Manager may get stuck when compiled with gcc-9.1.0
This commit is contained in:
PikalaxALT 2019-06-29 11:41:26 -04:00
parent 4b759da714
commit f9d8678db4
3 changed files with 27 additions and 20 deletions

View File

@ -49,7 +49,7 @@ OBJ_DIR := build/emerald
LIBPATH := -L ../../tools/agbcc/lib LIBPATH := -L ../../tools/agbcc/lib
else else
CC1 := $(shell $(PREFIX)gcc --print-prog-name=cc1) CC1 := $(shell $(PREFIX)gcc --print-prog-name=cc1)
override CFLAGS += -mthumb -mthumb-interwork -O2 -mabi=apcs-gnu -mtune=arm7tdmi -march=armv4t -quiet -fno-toplevel-reorder -Wno-aggressive-loop-optimizations -Wno-pointer-to-int-cast override CFLAGS += -mthumb -mthumb-interwork -O2 -mabi=apcs-gnu -mtune=arm7tdmi -march=armv4t -quiet -fno-toplevel-reorder -fno-aggressive-loop-optimizations -Wno-pointer-to-int-cast
ROM := pokeemerald_modern.gba ROM := pokeemerald_modern.gba
OBJ_DIR := build/modern OBJ_DIR := build/modern
LIBPATH := -L $(DEVKITARM)/lib/gcc/arm-none-eabi/*/thumb -L $(DEVKITARM)/arm-none-eabi/lib/thumb LIBPATH := -L $(DEVKITARM)/lib/gcc/arm-none-eabi/*/thumb -L $(DEVKITARM)/arm-none-eabi/lib/thumb
@ -233,7 +233,7 @@ $(OBJ_DIR)/ld_script.ld: $(LD_SCRIPT) $(LD_SCRIPT_DEPS)
$(ELF): $(OBJ_DIR)/ld_script.ld $(OBJS) $(ELF): $(OBJ_DIR)/ld_script.ld $(OBJS)
cd $(OBJ_DIR) && $(LD) $(LDFLAGS) -T ld_script.ld -o ../../$@ $(OBJS_REL) $(LIB) cd $(OBJ_DIR) && $(LD) $(LDFLAGS) -T ld_script.ld -o ../../$@ $(OBJS_REL) $(LIB)
$(FIX) $@ -p -t"$(TITLE)" -c$(GAME_CODE) -m$(MAKER_CODE) -r$(REVISION) --silent $(FIX) $@ -t"$(TITLE)" -c$(GAME_CODE) -m$(MAKER_CODE) -r$(REVISION) --silent
$(ROM): $(ELF) $(ROM): $(ELF)
$(OBJCOPY) -O binary --gap-fill 0xFF --pad-to 0x9000000 $< $@ $(OBJCOPY) -O binary --gap-fill 0xFF --pad-to 0x9000000 $< $@

View File

@ -17,7 +17,7 @@ BSS_DATA struct
u32 value; u32 value;
} gDma3Requests[MAX_DMA_REQUESTS]; } gDma3Requests[MAX_DMA_REQUESTS];
static bool8 gDma3ManagerLocked; static volatile bool8 gDma3ManagerLocked;
static u8 gDma3RequestCursor; static u8 gDma3RequestCursor;
void ClearDma3Requests(void) void ClearDma3Requests(void)

View File

@ -138,6 +138,7 @@ int main(int argc, char *argv[])
char *argfile = 0; char *argfile = 0;
FILE *infile; FILE *infile;
int silent = 0; int silent = 0;
int schedule_pad = 0;
int size,bit; int size,bit;
@ -172,28 +173,27 @@ int main(int argc, char *argv[])
return -1; return -1;
} }
uint32_t sh_offset = 0;
// read file // read file
infile = fopen(argfile, "r+b"); infile = fopen(argfile, "r+b");
if (!infile) { fprintf(stderr, "Error opening input file!\n"); return -1; } if (!infile) { fprintf(stderr, "Error opening input file!\n"); return -1; }
fseek(infile, 0, SEEK_SET); fseek(infile, sh_offset, SEEK_SET);
fread(&header, sizeof(header), 1, infile); fread(&header, sizeof(header), 1, infile);
// elf check // elf check
uint32_t sh_offset = 0; Elf32_Shdr secHeader;
if (memcmp(&header, ELFMAG, 4) == 0) { if (memcmp(&header, ELFMAG, 4) == 0) {
Elf32_Ehdr *elfHeader = (Elf32_Ehdr *)&header; Elf32_Ehdr *elfHeader = (Elf32_Ehdr *)&header;
fseek(infile, elfHeader->e_shoff, SEEK_SET); fseek(infile, elfHeader->e_shoff, SEEK_SET);
int i; int i;
for (i = 0; i < elfHeader->e_shnum; i++) { for (i = 0; i < elfHeader->e_shnum; i++) {
Elf32_Shdr secHeader;
fread(&secHeader, sizeof(Elf32_Shdr), 1, infile); fread(&secHeader, sizeof(Elf32_Shdr), 1, infile);
if (secHeader.sh_type == SHT_PROGBITS && secHeader.sh_addr == elfHeader->e_entry) { if (secHeader.sh_type == SHT_PROGBITS && secHeader.sh_addr == elfHeader->e_entry) break;
fseek(infile, secHeader.sh_offset, SEEK_SET);
sh_offset = secHeader.sh_offset;
break;
}
} }
if (i == elfHeader->e_shnum) { fprintf(stderr, "Error finding entry point!\n"); return 1; } if (i == elfHeader->e_shnum) { fprintf(stderr, "Error finding entry point!\n"); return 1; }
fseek(infile, secHeader.sh_offset, SEEK_SET);
sh_offset = secHeader.sh_offset;
fread(&header, sizeof(header), 1, infile); fread(&header, sizeof(header), 1, infile);
} }
@ -211,15 +211,7 @@ int main(int argc, char *argv[])
{ {
case 'p': // pad case 'p': // pad
{ {
fseek(infile, 0, SEEK_END); schedule_pad = 1;
size = ftell(infile);
for (bit=31; bit>=0; bit--) if (size & (1<<bit)) break;
if (size != (1<<bit))
{
int todo = (1<<(bit+1)) - size;
while (todo--) fputc(0xFF, infile);
}
fseek(infile, 0, SEEK_SET);
break; break;
} }
@ -299,6 +291,21 @@ int main(int argc, char *argv[])
header.complement = HeaderComplement(); header.complement = HeaderComplement();
//header.checksum = checksum_without_header + HeaderChecksum(); //header.checksum = checksum_without_header + HeaderChecksum();
if (schedule_pad) {
if (sh_offset != 0) {
fprintf(stderr, "Warning: Cannot safely pad an ELF\n");
} else {
fseek(infile, 0, SEEK_END);
size = ftell(infile);
for (bit=31; bit>=0; bit--) if (size & (1<<bit)) break;
if (size != (1<<bit))
{
int todo = (1<<(bit+1)) - size;
while (todo--) fputc(0xFF, infile);
}
}
}
fseek(infile, sh_offset, SEEK_SET); fseek(infile, sh_offset, SEEK_SET);
fwrite(&header, sizeof(header), 1, infile); fwrite(&header, sizeof(header), 1, infile);
fclose(infile); fclose(infile);