From 57b20298190219adf9b7022f1dd824a51be80c4d Mon Sep 17 00:00:00 2001 From: Antonio Castelli Date: Fri, 28 May 2021 13:22:40 -0700 Subject: [PATCH] Added glabels for unsigned types --- .../unknown_080500/func_80087F14.s | 8 +++---- .../unknown_080500/func_800890AC.s | 4 ++-- .../unknown_080500/func_8008DC7C.s | 1 + .../unknown_080500/func_800998E0.s | 4 ++-- .../unknown_09F8F0/func_800A4154.s | 4 ++-- .../unknown_09F8F0/func_800A4F50.s | 4 ++-- .../unknown_09F8F0/func_800A7B68.s | 4 ++-- tools/python/find_glabels.py | 24 ++++++++++++++++--- 8 files changed, 36 insertions(+), 17 deletions(-) diff --git a/asm/non_matchings/unknown_080500/func_80087F14.s b/asm/non_matchings/unknown_080500/func_80087F14.s index 757a65fe..1a9478bf 100644 --- a/asm/non_matchings/unknown_080500/func_80087F14.s +++ b/asm/non_matchings/unknown_080500/func_80087F14.s @@ -41,7 +41,7 @@ glabel func_80087F14 /* 088BAC 80087FAC 8FAE0074 */ lw $t6, 0x74($sp) /* 088BB0 80087FB0 A2150000 */ sb $s5, ($s0) /* 088BB4 80087FB4 11C00005 */ beqz $t6, .L80087FCC -/* 088BB8 80087FB8 3C188012 */ lui $t8, 0x8012 +/* 088BB8 80087FB8 3C188012 */ lui $t8, %hi(D_80126A60) #$t8, 0x8012 /* 088BBC 80087FBC 8FAF0070 */ lw $t7, 0x70($sp) /* 088BC0 80087FC0 00000000 */ nop /* 088BC4 80087FC4 15E00008 */ bnez $t7, .L80087FE8 @@ -49,7 +49,7 @@ glabel func_80087F14 .L80087FCC: /* 088BCC 80087FCC A2750000 */ sb $s5, ($s3) /* 088BD0 80087FD0 0311C021 */ addu $t8, $t8, $s1 -/* 088BD4 80087FD4 93186A60 */ lbu $t8, 0x6a60($t8) +/* 088BD4 80087FD4 93186A60 */ lbu $t8, %lo(D_80126A60)($t8) /* 088BD8 80087FD8 00000000 */ nop /* 088BDC 80087FDC 17000002 */ bnez $t8, .L80087FE8 /* 088BE0 80087FE0 00000000 */ nop @@ -121,9 +121,9 @@ glabel func_80087F14 /* 088CC4 800880C4 10000024 */ b .L80088158 /* 088CC8 800880C8 8FAF0090 */ lw $t7, 0x90($sp) .L800880CC: -/* 088CCC 800880CC 3C188012 */ lui $t8, 0x8012 +/* 088CCC 800880CC 3C188012 */ lui $t8, %hi(D_80126A30) #$t8, 0x8012 /* 088CD0 800880D0 0302C021 */ addu $t8, $t8, $v0 -/* 088CD4 800880D4 93186A30 */ lbu $t8, 0x6a30($t8) +/* 088CD4 800880D4 93186A30 */ lbu $t8, %lo(D_80126A30)($t8) /* 088CD8 800880D8 8FB90094 */ lw $t9, 0x94($sp) /* 088CDC 800880DC 13000002 */ beqz $t8, .L800880E8 /* 088CE0 800880E0 3C0E8012 */ lui $t6, %hi(D_80126A30) # $t6, 0x8012 diff --git a/asm/non_matchings/unknown_080500/func_800890AC.s b/asm/non_matchings/unknown_080500/func_800890AC.s index ae0c7854..c78525bd 100644 --- a/asm/non_matchings/unknown_080500/func_800890AC.s +++ b/asm/non_matchings/unknown_080500/func_800890AC.s @@ -236,9 +236,9 @@ glabel func_800890AC /* 08A010 80089410 AFB80034 */ sw $t8, 0x34($sp) .L80089414: /* 08A014 80089414 10400013 */ beqz $v0, .L80089464 -/* 08A018 80089418 3C028012 */ lui $v0, 0x8012 +/* 08A018 80089418 3C028012 */ lui $v0, %hi(D_80126B60) #$v0, 0x8012 /* 08A01C 8008941C 00431021 */ addu $v0, $v0, $v1 -/* 08A020 80089420 90426B60 */ lbu $v0, 0x6b60($v0) +/* 08A020 80089420 90426B60 */ lbu $v0, %lo(D_80126B60)($v0) /* 08A024 80089424 00000000 */ nop /* 08A028 80089428 28410003 */ slti $at, $v0, 3 /* 08A02C 8008942C 1420000A */ bnez $at, .L80089458 diff --git a/asm/non_matchings/unknown_080500/func_8008DC7C.s b/asm/non_matchings/unknown_080500/func_8008DC7C.s index ceedd274..91283e66 100644 --- a/asm/non_matchings/unknown_080500/func_8008DC7C.s +++ b/asm/non_matchings/unknown_080500/func_8008DC7C.s @@ -41,6 +41,7 @@ glabel func_8008DC7C /* 08E910 8008DD10 3C068012 */ lui $a2, %hi(D_8012648C) # $a2, 0x8012 /* 08E914 8008DD14 24C6648C */ addiu $a2, %lo(D_8012648C) # addiu $a2, $a2, 0x648c /* 08E918 8008DD18 8CC90000 */ lw $t1, ($a2) +# This is accessing unk801264A0->unk1 /* 08E91C 8008DD1C 3C0B8012 */ lui $t3, 0x8012 /* 08E920 8008DD20 00095080 */ sll $t2, $t1, 2 /* 08E924 8008DD24 01495023 */ subu $t2, $t2, $t1 diff --git a/asm/non_matchings/unknown_080500/func_800998E0.s b/asm/non_matchings/unknown_080500/func_800998E0.s index 61bd59d5..115d49e9 100644 --- a/asm/non_matchings/unknown_080500/func_800998E0.s +++ b/asm/non_matchings/unknown_080500/func_800998E0.s @@ -15,9 +15,9 @@ glabel func_800998E0 /* 09A514 80099914 0C000741 */ jal func_80001D04 /* 09A518 80099918 AFA60020 */ sw $a2, 0x20($sp) /* 09A51C 8009991C 8FA60020 */ lw $a2, 0x20($sp) -/* 09A520 80099920 3C108012 */ lui $s0, 0x8012 +/* 09A520 80099920 3C108012 */ lui $s0, %hi(D_80126540) #$s0, 0x8012 /* 09A524 80099924 02068021 */ addu $s0, $s0, $a2 -/* 09A528 80099928 92106540 */ lbu $s0, 0x6540($s0) +/* 09A528 80099928 92106540 */ lbu $s0, %lo(D_80126540)($s0) /* 09A52C 8009992C 3C048012 */ lui $a0, %hi(D_801264D0) # $a0, 0x8012 /* 09A530 80099930 8C8464D0 */ lw $a0, %lo(D_801264D0)($a0) /* 09A534 80099934 0C01D4F6 */ jal func_800753D8 diff --git a/asm/non_matchings/unknown_09F8F0/func_800A4154.s b/asm/non_matchings/unknown_09F8F0/func_800A4154.s index 6bdb7caf..9767ed53 100644 --- a/asm/non_matchings/unknown_09F8F0/func_800A4154.s +++ b/asm/non_matchings/unknown_09F8F0/func_800A4154.s @@ -9,12 +9,12 @@ glabel func_800A4154 /* 0A4D70 800A4170 1041002B */ beq $v0, $at, .L800A4220 /* 0A4D74 800A4174 3C038012 */ lui $v1, %hi(D_80126D0C) # $v1, 0x8012 /* 0A4D78 800A4178 8C636D0C */ lw $v1, %lo(D_80126D0C)($v1) -/* 0A4D7C 800A417C 3C19800E */ lui $t9, 0x800e +/* 0A4D7C 800A417C 3C19800E */ lui $t9, %hi(D_800E2794) #$t9, 0x800e /* 0A4D80 800A4180 1860000F */ blez $v1, .L800A41C0 /* 0A4D84 800A4184 00037880 */ sll $t7, $v1, 2 /* 0A4D88 800A4188 01E2C021 */ addu $t8, $t7, $v0 /* 0A4D8C 800A418C 0338C821 */ addu $t9, $t9, $t8 -/* 0A4D90 800A4190 93392794 */ lbu $t9, 0x2794($t9) +/* 0A4D90 800A4190 93392794 */ lbu $t9, %lo(D_800E2794)($t9) /* 0A4D94 800A4194 24010002 */ li $at, 2 /* 0A4D98 800A4198 13210009 */ beq $t9, $at, .L800A41C0 /* 0A4D9C 800A419C 3C0A8012 */ lui $t2, %hi(D_80126D60) # $t2, 0x8012 diff --git a/asm/non_matchings/unknown_09F8F0/func_800A4F50.s b/asm/non_matchings/unknown_09F8F0/func_800A4F50.s index 9984f39c..e93a9ec8 100644 --- a/asm/non_matchings/unknown_09F8F0/func_800A4F50.s +++ b/asm/non_matchings/unknown_09F8F0/func_800A4F50.s @@ -27,10 +27,10 @@ glabel func_800A4F50 /* 0A5BB0 800A4FB0 8FAD0018 */ lw $t5, 0x18($sp) /* 0A5BB4 800A4FB4 00026080 */ sll $t4, $v0, 2 /* 0A5BB8 800A4FB8 85AF0000 */ lh $t7, ($t5) -/* 0A5BBC 800A4FBC 3C18800E */ lui $t8, 0x800e +/* 0A5BBC 800A4FBC 3C18800E */ lui $t8, %hi(D_800E2794) #$t8, 0x800e /* 0A5BC0 800A4FC0 018F7021 */ addu $t6, $t4, $t7 /* 0A5BC4 800A4FC4 030EC021 */ addu $t8, $t8, $t6 -/* 0A5BC8 800A4FC8 93182794 */ lbu $t8, 0x2794($t8) +/* 0A5BC8 800A4FC8 93182794 */ lbu $t8, %lo(D_800E2794)($t8) /* 0A5BCC 800A4FCC 24010003 */ li $at, 3 /* 0A5BD0 800A4FD0 1701006F */ bne $t8, $at, .L800A5190 /* 0A5BD4 800A4FD4 00000000 */ nop diff --git a/asm/non_matchings/unknown_09F8F0/func_800A7B68.s b/asm/non_matchings/unknown_09F8F0/func_800A7B68.s index 8af39425..5f3e27dd 100644 --- a/asm/non_matchings/unknown_09F8F0/func_800A7B68.s +++ b/asm/non_matchings/unknown_09F8F0/func_800A7B68.s @@ -9,10 +9,10 @@ glabel func_800A7B68 /* 0A8784 800A7B84 00803025 */ move $a2, $a0 /* 0A8788 800A7B88 848F0000 */ lh $t7, ($a0) /* 0A878C 800A7B8C 00077080 */ sll $t6, $a3, 2 -/* 0A8790 800A7B90 3C19800E */ lui $t9, 0x800e +/* 0A8790 800A7B90 3C19800E */ lui $t9, %hi(D_800E2794) #$t9, 0x800e /* 0A8794 800A7B94 01CFC021 */ addu $t8, $t6, $t7 /* 0A8798 800A7B98 0338C821 */ addu $t9, $t9, $t8 -/* 0A879C 800A7B9C 93392794 */ lbu $t9, 0x2794($t9) +/* 0A879C 800A7B9C 93392794 */ lbu $t9, %lo(D_800E2794)($t9) /* 0A87A0 800A7BA0 24010001 */ li $at, 1 /* 0A87A4 800A7BA4 1321000D */ beq $t9, $at, .L800A7BDC /* 0A87A8 800A7BA8 00000000 */ nop diff --git a/tools/python/find_glabels.py b/tools/python/find_glabels.py index cb052e3b..d6a66ca9 100644 --- a/tools/python/find_glabels.py +++ b/tools/python/find_glabels.py @@ -5,21 +5,39 @@ from file_util import FileUtil LINE_START_REGEX = r'\n(/\* ([0-9A-F]{6}) [0-9A-F]{8} [0-9A-F]{8} \*/\s+|\.L80[0-9A-F]{6}:)' REG_REGEX = r'(\$(at|v[0-1]|a[0-3]|t[0-9]|s[0-7]|k[0-1]|gp|sp|fp|ra))' GLABEL_UPPER_REGEX = '(' + LINE_START_REGEX + r'lui\s+' + REG_REGEX + r',\s+(0x80[0-9a-f]{2}))' -GLABEL_LOWER_REGEX = '(' + LINE_START_REGEX + r'[sl][bhw]\s+' + REG_REGEX + r',\s+(0x[0-9a-f]{4})\(\4\))' +GLABEL_LOWER_REGEX = '(' + LINE_START_REGEX + r'[sl][bhw]u?\s+' + REG_REGEX + r',\s+(0x[0-9a-f]{4})\(\4\))' GLABEL_REGEX = GLABEL_UPPER_REGEX + '(' + LINE_START_REGEX + '[^\n]*){0,10}' + GLABEL_LOWER_REGEX +UPPER_INSTR_REGEX_TMPL = r'(/\* %s[^\n]*lui\s+)([^\n]*)' +LOWER_INSTR_REGEX_TMPL = r'(/\* %s[^\n]*[ls][bhw]u?\s+' + REG_REGEX + r',\s+)0x[0-9a-f]{4}([^\n]*)' + +IGNORE_GLABELS = ['D_800E389E', 'D_801264A1'] + def _find_glabels(asm): glabels = [] for file in FileUtil.get_filenames_from_directory_recursive('.', '.s'): - matches = re.findall(GLABEL_REGEX, FileUtil.get_text_from_file(file)) + contents = FileUtil.get_text_from_file(file) + matches = re.findall(GLABEL_REGEX, contents) for match in matches: + reg = match[3] offsets = (match[2], match[11]) # ROM offsets of the lui and [sl][bhw] glabel_upper = int(match[5], 16) # upper immediate of glabel glabel_lower = int(match[14], 16) # lower immediate of the glabel if glabel_lower & 0x8000: glabel_upper -= 1 glabel = 'D_%08X' % (glabel_upper << 16 | glabel_lower) - glabels.append((glabel, *offsets)) + if glabel not in IGNORE_GLABELS: + glabels.append((glabel, *offsets)) + # replace upper instruction + contents = re.sub(UPPER_INSTR_REGEX_TMPL % offsets[0], + r'\1' + '%s, %%hi(%s) #' % (reg, glabel) + r'\2', + contents) + # replace lower instruction + contents = re.sub(LOWER_INSTR_REGEX_TMPL % offsets[1], + r'\1' + '%%lo(%s)' % (glabel) + r'\4', + contents) + if len(matches): + FileUtil.write_text_to_file(file, contents) return glabels def main():