Add dmadata vrom symbols. Link rom in two passes: first to generate dmadata, second to apply dmadata symbols. Clean up symbols at low addresses.

This commit is contained in:
rozlette
2019-11-16 03:28:05 -06:00
parent 6905647e4f
commit 08d128bdaa
12 changed files with 9435 additions and 1054 deletions
+55 -12
View File
@@ -40,10 +40,12 @@ BASEROM_FILES := $(wildcard baserom/*)
# Exclude dmadata, it will be generated right before packing the rom
BASEROM_FILES := $(subst baserom/dmadata ,,$(BASEROM_FILES))
BASEROM_BUILD_FILES := $(BASEROM_FILES:baserom/%=build/baserom/%)
BASEROM_PRE_DMADATA_FILES := $(BASEROM_BUILD_FILES:build/baserom/%=build/baserom_pre_dmadata/%)
BASE_DECOMP_FILES := $(wildcard decomp/*)
DECOMP_FILES := $(BASE_DECOMP_FILES:decomp/%=build/decomp/%)
COMP_FILES := $(DECOMP_FILES:decomp/%=comp/%.yaz0)
DECOMP_PRE_DMADATA_FILES := $(DECOMP_FILES:build/decomp/%=build/decomp_pre_dmadata/%)
COMP_FILES := $(DECOMP_FILES:build/decomp/%=build/comp/%.yaz0)
S_FILES := $(wildcard asm/*)
S_O_FILES = $(S_FILES:asm/%.asm=build/asm/%.o)
@@ -64,8 +66,10 @@ ROM := rom.z64
# make build directories
$(shell mkdir -p build/asm)
$(shell mkdir -p build/baserom)
$(shell mkdir -p build/baserom_pre_dmadata)
$(shell mkdir -p build/comp)
$(shell mkdir -p build/decomp)
$(shell mkdir -p build/decomp_pre_dmadata)
$(shell mkdir -p build/src)
$(shell mkdir -p build/src/libultra)
$(shell mkdir -p build/src/libultra/os)
@@ -82,34 +86,67 @@ check: $(ROM)
$(ROM): $(ROM_FILES)
@python3 ./tools/makerom.py ./tables/dmadata_table.py $@
boot.bin: code.elf
build/boot_pre_dmadata.bin: build/code_pre_dmadata.elf
$(MIPS_BINUTILS)objcopy --dump-section boot=$@ $<
code.bin: code.elf
build/code_pre_dmadata.bin: build/code_pre_dmadata.elf
$(MIPS_BINUTILS)objcopy --dump-section code=$@ $<
ovl_title.bin: code.elf
build/ovl_title_pre_dmadata.bin: build/code_pre_dmadata.elf
$(MIPS_BINUTILS)objcopy --dump-section ovl_title=$@ $<
code.elf: $(S_O_FILES) $(C_O_FILES) codescript.txt undef.txt
$(LD) -T codescript.txt -T undef.txt --no-check-sections --accept-unknown-input-arch -o $@
build/boot.bin: build/code.elf
$(MIPS_BINUTILS)objcopy --dump-section boot=$@ $<
build/code.bin: build/code.elf
$(MIPS_BINUTILS)objcopy --dump-section code=$@ $<
build/ovl_title.bin: build/code.elf
$(MIPS_BINUTILS)objcopy --dump-section ovl_title=$@ $<
build/code_pre_dmadata.elf: $(S_O_FILES) $(C_O_FILES) codescript.txt undef.txt
$(LD) -r -T codescript.txt -T undef.txt --no-check-sections --accept-unknown-input-arch -o $@
build/code.elf: $(S_O_FILES) $(C_O_FILES) codescript.txt undef.txt dmadata_script.txt
$(LD) -T codescript.txt -T undef.txt -T dmadata_script.txt --no-check-sections --accept-unknown-input-arch -o $@
dmadata_script.txt: $(DECOMP_PRE_DMADATA_FILES) $(BASEROM_PRE_DMADATA_FILES)
# TODO is there a better way to avoid this shuffling?
mv build/baserom build/baserom_temp
mv build/decomp build/decomp_temp
mv build/baserom_pre_dmadata build/baserom
mv build/decomp_pre_dmadata build/decomp
python3 ./tools/dmadata.py ./tables/dmadata_table.py /dev/null -u -l dmadata_script.txt
mv build/baserom build/baserom_pre_dmadata
mv build/decomp build/decomp_pre_dmadata
mv build/baserom_temp build/baserom
mv build/decomp_temp build/decomp
test.txt: build/src/test.o
$(MIPS_BINUTILS)objdump -d -z --adjust-vma=0x80080790 $< > test.txt
clean:
rm $(ROM) code.elf code.bin boot.bin -r build
rm $(ROM) -r build
build/baserom/dmadata: $(COMP_FILES) $(DECOMP_FILES) $(BASEROM_BUILD_FILES)
python3 ./tools/dmadata.py ./tables/dmadata_table.py $@
build/baserom/boot: boot.bin
build/baserom/boot: build/boot.bin
cp $< $@
build/decomp/code: code.bin
build/decomp/code: build/code.bin
cp $< $@
build/decomp/ovl_title: ovl_title.bin
build/decomp/ovl_title: build/ovl_title.bin
cp $< $@
build/baserom_pre_dmadata/boot: build/boot_pre_dmadata.bin
cp $< $@
build/decomp_pre_dmadata/code: build/code_pre_dmadata.bin
cp $< $@
build/decomp_pre_dmadata/ovl_title: build/ovl_title_pre_dmadata.bin
cp $< $@
@@ -121,7 +158,10 @@ disasm:
# Recipes
build/baserom/%: baserom/%
build/baserom/%: build/baserom_pre_dmadata/%
cp $< $@
build/baserom_pre_dmadata/%: baserom/%
cp $< $@
build/asm/%.o: asm/%.asm
@@ -130,7 +170,10 @@ build/asm/%.o: asm/%.asm
build/src/%.o: src/%.c include/*
$(CC) -c $(CFLAGS) $(MIPS_VERSION) $(OPTIMIZATION) -Iinclude -o $@ $<
build/decomp/%: decomp/%
build/decomp/%: build/decomp_pre_dmadata/%
cp $< $@
build/decomp_pre_dmadata/%: decomp/%
cp $< $@
build/comp/%.yaz0: build/decomp/%
+2 -2
View File
@@ -1,3 +1,3 @@
2a0a8acb61538235bc1094d297fb6556 rom.z64
4e8afbb44e6a4b9bc00eaa318bb1650c code.bin
b0145fad4be13d63d5d7aa75062db400 boot.bin
4e8afbb44e6a4b9bc00eaa318bb1650c build/code.bin
b0145fad4be13d63d5d7aa75062db400 build/boot.bin
+4605
View File
File diff suppressed because it is too large Load Diff
+4611
View File
File diff suppressed because it is too large Load Diff
+1 -514
View File
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -37,8 +37,8 @@ UNK_RET func_80080250(void) {
osCreateMesgQueue(&sp30, &sp2C, 1);
v1 = &D_00B3C000;
t7 = &D_00C7A4E0;
v1 = &code_vrom_start;
t7 = &code_vrom_end;
v0 = &D_80096B50;
sp28 = *v0;
*v0 = 0;
+1 -1
View File
@@ -223,7 +223,7 @@ void Dmamgr_Start() {
DmadataEntry* v0;
u32 v1;
// TODO register load ordering is wrong
Dmamgr_DoDmaTransfer(&dmadataRomStart, dmadata, (u8*)&dmadataRomEnd - (u8*)&dmadataRomStart);
Dmamgr_DoDmaTransfer(&dmadata_vrom_start, dmadata, (u8*)&dmadata_vrom_end - (u8*)&dmadata_vrom_start);
for (v0 = dmadata, v1 = 0; v0->vromEnd != 0; v0++, v1++);
+1
View File
@@ -4,3 +4,4 @@ boot_0x800968B0
z_std_dma
z_effect_soft_sprite
z_lib
z_actor
+72 -10
View File
@@ -1,15 +1,77 @@
# Follows the format of Address:(Name, Type, Is Array)
{
0x0001A500:("dmadataRomStart","u32",False), # Start of dmadata
0x00020700:("dmadataRomEnd","u32",False), # Byte immediately after end of dmadata
0x00AC4000:("","UNK_TYPE",False), # this seems low
0x00ACC000:("","UNK_TYPE",False), # this seems low
0x00B3C000:("","UNK_TYPE",False), # this seems low
0x00C7A4E0:("","UNK_TYPE",False), # this seems low
0x060005D0:("","UNK_TYPE",False), # this seems low
0x06001100:("","UNK_TYPE",False), # this seems low
0x06001228:("","UNK_TYPE",False), # this seems low
0x06002D30:("","UNK_TYPE",False), # this seems low
# NOTE These symbols could be one of two symbols: the start of a file or the end of a file before it.
# The choice for disassembly is arbitrary but in code it should be the one that makes sense.
0x0001A500:("dmadata_vrom_start","u32",False), # Start of dmadata
0x00020700:("dmadata_vrom_end","u32",False), # Byte immediately after end of dmadata
0x00046AF0:("Audioseq_vrom_start","UNK_TYPE",False),
0x00097F70:("Audioseq_vrom_end","UNK_TYPE",False),
0x0065D000:("link_animetion_vrom_start","UNK_TYPE",False),
0x00957000:("","UNK_TYPE",False), # ovl_kaleido_scope uses this. It is the start of vrom for a null entry in dmadata???
0x009ECEC0:("","UNK_TYPE",False), # ovl_kaleido_scope uses this. It is the end of vrom for a null entry in dmadata???
0x009ED000:("","UNK_TYPE",False), # ovl_kaleido_scope uses this. It is the start of vrom for a null entry in dmadata???
0x009F4700:("","UNK_TYPE",False), # ovl_kaleido_scope uses this. It is the end of vrom for a null entry in dmadata???
0x009F5000:("icon_item_field_static_vrom_start","UNK_TYPE",False),
0x00A09AF0:("icon_item_field_static_vrom_end","UNK_TYPE",False),
0x00A0A000:("icon_item_dungeon_static_vrom_start","UNK_TYPE",False),
0x00A0EB80:("icon_item_dungeon_static_vrom_end","UNK_TYPE",False),
0x00A0F000:("icon_item_gameover_static_vrom_start","UNK_TYPE",False),
0x00A12300:("icon_item_gameover_static_vrom_end","UNK_TYPE",False),
0x00A13000:("_013_0x00963540_vrom_start","UNK_TYPE",False),
0x00A1BA00:("_013_0x00963540_vrom_end","UNK_TYPE",False),
0x00A1C000:("_014_0x00967260_vrom_start","UNK_TYPE",False),
0x00A1C2E0:("_014_0x00967260_vrom_end","UNK_TYPE",False),
0x00A1D000:("map_i_static_vrom_start","UNK_TYPE",False),
0x00A1E310:("map_grand_static_vrom_start","UNK_TYPE",False),
0x00A27660:("item_name_static_vrom_start","UNK_TYPE",False),
0x00A352F0:("map_name_static_vrom_start","UNK_TYPE",False),
0x00A36C10:("_019_0x00980f60_vrom_start","UNK_TYPE",False),
0x00A7BEE0:("_020_0x009c6230_vrom_start","UNK_TYPE",False),
0x00A807A0:("_020_0x009c6230_vrom_end","UNK_TYPE",False),
0x00A8C000:("_022_0x009caaf0_vrom_start","UNK_TYPE",False),
0x00A92A10:("_023_0x009d1500_vrom_start","UNK_TYPE",False),
0x00A990E0:("_023_0x009d1500_vrom_end","UNK_TYPE",False),
0x00A9A000:("_024_0x009d3760_vrom_start","UNK_TYPE",False),
0x00ABFC00:("_024_0x009d3760_vrom_end","UNK_TYPE",False),
0x00AC0000:("do_action_static_vrom_start","UNK_TYPE",False),
0x00AC4000:("message_static_vrom_start","UNK_TYPE",False),
0x00ACA000:("message_texture_static_vrom_start","UNK_TYPE",False),
0x00ACC000:("nes_font_static_vrom_start","UNK_TYPE",False),
0x00AD1000:("en_message_data_static_vrom_start","UNK_TYPE",False),
0x00B3B000:("staff_message_data_static_vrom_start","UNK_TYPE",False),
0x00B3C000:("code_vrom_start","UNK_TYPE",False),
0x00C7A4E0:("code_vrom_end","UNK_TYPE",False),
0x01E85000:("nintendo_rogo_static_vrom_start","UNK_TYPE",False),
0x01E87DC0:("nintendo_rogo_static_vrom_end","UNK_TYPE",False),
0x01E88000:("title_static_vrom_start","UNK_TYPE",False),
0x01EB9730:("title_static_vrom_end","UNK_TYPE",False),
0x01EBA000:("_1124_0x0163f490_vrom_start","UNK_TYPE",False),
0x01EBB280:("_1124_0x0163f490_vrom_end","UNK_TYPE",False),
0x01EBC000:("_1125_0x0163fc10_vrom_start","UNK_TYPE",False),
0x01EBC680:("_1125_0x0163fc10_vrom_end","UNK_TYPE",False),
0x01EBD000:("_1126_0x0163ffc0_vrom_start","UNK_TYPE",False),
0x01EC8B20:("_1126_0x0163ffc0_vrom_end","UNK_TYPE",False),
0x01EC9000:("_1127_0x01643d50_vrom_start","UNK_TYPE",False),
0x01EC9F30:("_1127_0x01643d50_vrom_end","UNK_TYPE",False),
0x01ECA000:("_1128_0x01644c80_vrom_start","UNK_TYPE",False),
0x01ED3B00:("_1128_0x01644c80_vrom_end","UNK_TYPE",False),
0x01ED4000:("_1129_0x01646b60_vrom_start","UNK_TYPE",False),
0x01EDDB00:("_1129_0x01646b60_vrom_end","UNK_TYPE",False),
0x01EDE000:("_1130_0x01649020_vrom_start","UNK_TYPE",False),
0x01EE7B00:("_1130_0x01649020_vrom_end","UNK_TYPE",False),
0x01EE8000:("_1131_0x0164ad90_vrom_start","UNK_TYPE",False),
0x01EF1B00:("_1131_0x0164ad90_vrom_end","UNK_TYPE",False),
0x01EF2000:("vr_fine_static_vrom_start","UNK_TYPE",False),
0x01EFE000:("vr_cloud_static_vrom_start","UNK_TYPE",False),
0x01F0A000:("vr_pal_static_vrom_start","UNK_TYPE",False),
0x01F0A200:("vr_pal_static_vrom_end","UNK_TYPE",False),
# TODO These are object addresses.
0x060005D0:("","UNK_TYPE",False),
0x06001100:("","UNK_TYPE",False),
0x06001228:("","UNK_TYPE",False),
0x06002D30:("","UNK_TYPE",False),
0x80000300:("osTvType","UNK_TYPE",False),
0x80000304:("osRomType","UNK_TYPE",False),
0x80000308:("osRomBase","UNK_TYPE",False),
+11 -2
View File
@@ -468,7 +468,7 @@ class Disassembler:
# TODO workaround to avoid classifying loading constants as loading pointers
# This unfortunately causes it to not detect object addresses
if addr >= 0x2000000 and addr < 0x80000000:
if addr < 0x80000000:
return
if self.is_in_data_or_undef(addr):
@@ -481,6 +481,12 @@ class Disassembler:
elif is_load(next_inst) and (get_rt(cur_inst) == get_rs(next_inst)): # lui + load (load pointer)
addr = (get_imm(cur_inst) << 16) + get_signed_imm(next_inst)
# TODO workaround to avoid classifying loading constants as loading pointers
# This unfortunately causes it to not detect object addresses
if addr < 0x80000000:
return
if self.is_in_data_or_undef(addr):
self.add_variable(addr)
else:
@@ -687,9 +693,12 @@ class Disassembler:
with open(path + "/variables.h", 'w', newline='\n') as f:
f.write("#ifndef _VARIABLES_H_\n#define _VARIABLES_H_\n\n")
f.write('#include <PR/ultratypes.h>\n#include <osint.h>\n#include <viint.h>\n#include <guint.h>\n#include <unk.h>\n#include <structs.h>\n#include <stdlib.h>\n#include <xstdio.h>\n\n')
f.write('#include <PR/ultratypes.h>\n#include <osint.h>\n#include <viint.h>\n#include <guint.h>\n#include <unk.h>\n#include <structs.h>\n#include <stdlib.h>\n#include <xstdio.h>\n#include <dmadata.h>\n\n')
for addr in sorted(self.vars):
if addr < 0x02000000:
continue # Don't print out symbols of dmadata files' vrom addresses. These will be defined in another file.
if addr in known_vars:
f.write("extern %s %s%s; // D_%08X\n" % (known_vars[addr][1], self.make_load(addr), "[]" if known_vars[addr][2] else "", addr))
else:
+15 -1
View File
@@ -7,12 +7,15 @@ if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('files', help='file list')
parser.add_argument('out', help='output file')
parser.add_argument('-l', '--linkscript', help='output linker script for file VROM addresses', metavar='filename')
parser.add_argument('-u', '--uncompressed', help='build dmadata from only uncompressed files', action='store_true', default=False)
args = parser.parse_args()
with open(args.out, 'wb') as dmadata, open(args.files, 'r') as files:
curr_vrom = 0
curr_phys = 0
dmadata_table = ast.literal_eval(files.read())
linker_info = list()
for base_file, comp_file, alignment, size_if_missing in dmadata_table:
try:
uncompressed = comp_file == ''
@@ -30,7 +33,7 @@ if __name__ == "__main__":
phys_size = vrom_size
else:
vrom_size = os.path.getsize(base_file)
if uncompressed:
if uncompressed or args.uncompressed:
phys_size = vrom_size
else:
phys_size = os.path.getsize(comp_file)
@@ -59,6 +62,17 @@ if __name__ == "__main__":
dmadata.write(vrom_end.to_bytes(4, 'big'))
dmadata.write(phys_start.to_bytes(4, 'big'))
dmadata.write(phys_end.to_bytes(4, 'big'))
if base_file != '':
linker_info.append((os.path.basename(base_file), vrom_start, vrom_end))
except:
print('Error when processing entry ' + base_file)
sys.exit(1)
if args.linkscript:
with open(args.linkscript, 'w') as file:
for name, vrom_start, vrom_end in linker_info:
formatted_name = '_' + name if name[0].isdigit() else name
file.write('{}_vrom_start = 0x{:08X};\n'.format(formatted_name, vrom_start))
file.write('{}_vrom_end = 0x{:08X};\n'.format(formatted_name, vrom_end))
file.write('\n')
+59 -510
View File
File diff suppressed because it is too large Load Diff