From 19651447d53e96d727e9bcf65cd7901ded8f6d8f Mon Sep 17 00:00:00 2001 From: hondew Date: Sun, 14 Mar 2021 23:46:12 -0400 Subject: Make asmproc produce a linkable obj Document compile.sh --- .../nonmatchings/GenerateFontHalfRowLookupTable.s | 12 ++++---- arm9/temp.c | 0 tools/asm_processor/asm_processor.py | 12 ++++---- tools/asm_processor/compile.sh | 34 +++++++++++++--------- 4 files changed, 33 insertions(+), 25 deletions(-) delete mode 100644 arm9/temp.c diff --git a/arm9/asm/nonmatchings/GenerateFontHalfRowLookupTable.s b/arm9/asm/nonmatchings/GenerateFontHalfRowLookupTable.s index 2d51a2ae..a083bf2e 100644 --- a/arm9/asm/nonmatchings/GenerateFontHalfRowLookupTable.s +++ b/arm9/asm/nonmatchings/GenerateFontHalfRowLookupTable.s @@ -1,11 +1,11 @@ - .include "asm/macros.inc" - .include "global.inc" - .extern UNK_021C570C - .extern UNK_021C5734 +.section .text + +glabel GenerateFontHalfRowLookupTable + +.extern UNK_021C570C +.extern UNK_021C5734 - thumb_func_start GenerateFontHalfRowLookupTable -GenerateFontHalfRowLookupTable: ; 0x0201C05C push {r3-r7, lr} sub sp, #0x30 ldr r3, _0201C0F8 ; =UNK_021C570C diff --git a/arm9/temp.c b/arm9/temp.c deleted file mode 100644 index e69de29b..00000000 diff --git a/tools/asm_processor/asm_processor.py b/tools/asm_processor/asm_processor.py index e3226cb2..e1540c0c 100644 --- a/tools/asm_processor/asm_processor.py +++ b/tools/asm_processor/asm_processor.py @@ -575,7 +575,7 @@ class GlobalAsmBlock: self.add_sized(int(line.split()[1], 0), real_line) elif line.startswith('.balign') or line.startswith('.align'): align = int(line.split()[1]) - if align != 2: + if align != 4: self.fail("only .balign 4 is supported", real_line) self.align4() elif line.startswith('.asci'): @@ -586,9 +586,6 @@ class GlobalAsmBlock: # Branches are 4 bytes long elif line.startswith('bl'): self.add_sized(4, real_line) - elif line.startswith('.'): - # .macro, ... - self.fail("asm directive not supported", real_line) else: # Unfortunately, macros are hard to support for .rodata -- # we don't know how how space they will expand to before @@ -1027,8 +1024,11 @@ def fixup_objfile(objfile_name, functions, asm_prelude, assembler, output_enc): loc1 = asm_objfile.symtab.find_symbol_in_section(temp_name + '_asm_start', source) loc2 = asm_objfile.symtab.find_symbol_in_section(temp_name + '_asm_end', source) assert loc1 == pos, "assembly and C files don't line up for section " + sectype + ", " + fn_desc - if loc2 - loc1 != count: - raise Failure("incorrectly computed size for section " + sectype + ", " + fn_desc + ". If using .double, make sure to provide explicit alignment padding.") + # Since we are nonmatching whole functions, we don't need to insert the correct + # amount of padding into the src file. We don't actually need to insert padding + # at all. We can just plop the asm's text section into the objfile. + # if loc2 - loc1 != count: + # raise Failure("incorrectly computed size for section " + sectype + ", " + fn_desc + ". If using .double, make sure to provide explicit alignment padding.") if sectype == '.bss' or sectype == '.sbss2': continue target = objfile.find_section(sectype, n_text if sectype == '.text' else 0) diff --git a/tools/asm_processor/compile.sh b/tools/asm_processor/compile.sh index 786da404..8c367b3e 100644 --- a/tools/asm_processor/compile.sh +++ b/tools/asm_processor/compile.sh @@ -1,19 +1,27 @@ #!/bin/bash CC="$1" -shift -AS="$1" -shift +AS="$2" +OBJ="$3" +SRC="$4" -temp="$(mktemp)" -../tools/asm_processor/asm_processor.py "$2" --assembler "$AS" > "$temp.c" && -$CC -c "$temp.c" -o "$1" +PADDED_SRC="$(mktemp --suffix=.c padded-XXXXXX)" +PADDED_OBJ="$(mktemp --suffix=.o padded-XXXXXX)" -prelude=$(mktemp prelude.XXXXXX) -cat ../include/macros.inc >> "$prelude" -cat global.inc >> "$prelude" +# Create a .c file replacing the nonmatching function with volatile int writes, +# and compile. +../tools/asm_processor/asm_processor.py "$SRC" --assembler "$AS" > "$PADDED_SRC" +$CC -c "$PADDED_SRC" -o "$PADDED_OBJ" -../tools/asm_processor/asm_processor.py "$2" --post-process "$1" --assembler "$AS" --asm-prelude "$prelude" -arm-none-eabi-objcopy --remove-section .comment "$1" "$1" -rm "$prelude" -rm "$temp" +PRELUDE=$(mktemp) +cat ../include/macros.inc >> "$PRELUDE" +cat global.inc >> "$PRELUDE" + +# Inject the matching assembly into the padded obj file. +../tools/asm_processor/asm_processor.py "$SRC" --post-process "$PADDED_OBJ" --assembler "$AS" --asm-prelude "$PRELUDE" + +$DEVKITARM/bin/arm-none-eabi-objcopy --remove-section .comment "$PADDED_OBJ" "$OBJ" + +rm "$PADDED_SRC" +rm "$PADDED_OBJ" +rm "$PRELUDE" -- cgit v1.2.3 From 5156636c2bb46c34c2dd0f97fd2ffb9ed9790dc9 Mon Sep 17 00:00:00 2001 From: hondew Date: Mon, 15 Mar 2021 00:28:57 -0400 Subject: Fix build error --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 582fad70..6c5bade0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,7 +18,7 @@ jobs: - name: Update and Install Software run: | sudo apt update - sudo ACCEPT_EULA=Y apt -y --fix-missing upgrade + sudo ACCEPT_EULA=Y apt -y --fix-missing upgrade --allow-downgrade sudo apt -y install g++-8-multilib linux-libc-dev binutils-arm-none-eabi sudo dpkg --add-architecture i386 wget -qO - https://dl.winehq.org/wine-builds/winehq.key | sudo apt-key add - -- cgit v1.2.3 From b2732f46318cb0061c65c1c5ef083963dcdd4df7 Mon Sep 17 00:00:00 2001 From: hondew Date: Mon, 15 Mar 2021 00:33:05 -0400 Subject: Retry build fix --- .github/workflows/build.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6c5bade0..4e0f34ea 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,13 +18,13 @@ jobs: - name: Update and Install Software run: | sudo apt update - sudo ACCEPT_EULA=Y apt -y --fix-missing upgrade --allow-downgrade - sudo apt -y install g++-8-multilib linux-libc-dev binutils-arm-none-eabi + sudo ACCEPT_EULA=Y apt -y --fix-missing --allow-downgrades upgrade + sudo apt -y --allow-downgrades install g++-8-multilib linux-libc-dev binutils-arm-none-eabi sudo dpkg --add-architecture i386 wget -qO - https://dl.winehq.org/wine-builds/winehq.key | sudo apt-key add - sudo add-apt-repository ppa:cybermax-dexter/sdl2-backport sudo apt-add-repository "deb https://dl.winehq.org/wine-builds/ubuntu $(lsb_release -cs) main" - sudo apt install --install-recommends winehq-stable + sudo apt -y --allow-downgrades install --install-recommends winehq-stable - name: Checkout Repo uses: actions/checkout@v2 - name: Setup Repo -- cgit v1.2.3 From ff109c169cb508e0811bd1f0097f97ee594bfd54 Mon Sep 17 00:00:00 2001 From: James Luke <5251299+ethanpepro@users.noreply.github.com> Date: Mon, 15 Mar 2021 13:37:17 -0400 Subject: Decompile unk_0204AEA8.s --- arm9/asm/unk_0204AEA8.s | 67 ------------------------------------------------- arm9/src/unk_0204AEA8.c | 45 +++++++++++++++++++++++++++++++++ include/unk_0204AEA8.h | 7 ++++++ 3 files changed, 52 insertions(+), 67 deletions(-) delete mode 100644 arm9/asm/unk_0204AEA8.s create mode 100644 arm9/src/unk_0204AEA8.c create mode 100644 include/unk_0204AEA8.h diff --git a/arm9/asm/unk_0204AEA8.s b/arm9/asm/unk_0204AEA8.s deleted file mode 100644 index 018a64e2..00000000 --- a/arm9/asm/unk_0204AEA8.s +++ /dev/null @@ -1,67 +0,0 @@ - .include "asm/macros.inc" - .include "global.inc" - - .text - - thumb_func_start FUN_0204AEA8 -FUN_0204AEA8: ; 0x0204AEA8 - push {r3-r5, lr} - add r4, r0, #0x0 - bl FUN_02046528 - add r5, r0, #0x0 - add r0, r4, #0x0 - bl FUN_0204652C - add r4, r0, #0x0 - ldr r1, [r4, #0x0] - cmp r1, #0x0 - beq _0204AEC6 - cmp r1, #0x1 - beq _0204AEE6 - b _0204AEF4 -_0204AEC6: - ldr r0, [r4, #0x8] - add r1, r5, #0x0 - add r2, r4, #0x4 - bl MOD05_021E3444 - ldr r1, [r4, #0xc] - mov r0, #0x5 - lsl r1, r1, #0x10 - lsr r1, r1, #0x10 - mov r2, #0x1 - bl FUN_0200433C - ldr r0, [r4, #0x0] - add r0, r0, #0x1 - str r0, [r4, #0x0] - b _0204AEF4 -_0204AEE6: - ldr r1, [r4, #0x4] - cmp r1, #0x1 - bne _0204AEF4 - bl FreeToHeap - mov r0, #0x1 - pop {r3-r5, pc} -_0204AEF4: - mov r0, #0x0 - pop {r3-r5, pc} - - thumb_func_start FUN_0204AEF8 -FUN_0204AEF8: ; 0x0204AEF8 - push {r4-r6, lr} - add r6, r0, #0x0 - add r5, r1, #0x0 - mov r0, #0xb - mov r1, #0x10 - add r4, r2, #0x0 - bl AllocFromHeapAtEnd - add r2, r0, #0x0 - mov r0, #0x0 - str r0, [r2, #0x0] - str r0, [r2, #0x4] - str r5, [r2, #0x8] - ldr r1, _0204AF20 ; =FUN_0204AEA8 - add r0, r6, #0x0 - str r4, [r2, #0xc] - bl FUN_0204640C - pop {r4-r6, pc} - nop -_0204AF20: .word FUN_0204AEA8 diff --git a/arm9/src/unk_0204AEA8.c b/arm9/src/unk_0204AEA8.c new file mode 100644 index 00000000..23dd6960 --- /dev/null +++ b/arm9/src/unk_0204AEA8.c @@ -0,0 +1,45 @@ +#include "global.h" +#include "heap.h" +#include "unk_0204639C.h" +#include "unk_0204AEA8.h" + +#pragma thumb on + +extern void MOD05_021E3444(u32, struct UnkStruct_0204639C *, u32); +extern void FUN_0200433C(u32, u32, u32); + +BOOL FUN_0204AEA8(struct UnkStruct_0204639C *a0) +{ + struct UnkStruct_0204639C *v0 = FUN_02046528(a0); + u32 *v1 = FUN_0204652C(a0); + + switch (v1[0]) + { + case 0: + MOD05_021E3444(v1[2], v0, (u32)v1 + 4); + FUN_0200433C(5, ((v1[3] << 16) >> 16), 1); + v1[0]++; + break; + case 1: + if (v1[1] == 1) + { + FreeToHeap(v1); + return TRUE; + } + break; + } + + return FALSE; +} + +void FUN_0204AEF8(struct UnkStruct_0204639C *a0, u32 a1, u32 a2) +{ + u32 *v0 = AllocFromHeapAtEnd(11, 4 * sizeof(u32)); + + v0[0] = 0; + v0[1] = 0; + v0[2] = a1; + v0[3] = a2; + + FUN_0204640C(a0, FUN_0204AEA8, v0); +} diff --git a/include/unk_0204AEA8.h b/include/unk_0204AEA8.h new file mode 100644 index 00000000..90e13cc2 --- /dev/null +++ b/include/unk_0204AEA8.h @@ -0,0 +1,7 @@ +#ifndef POKEDIAMOND_UNK_0204AEA8_H +#define POKEDIAMOND_UNK_0204AEA8_H + +BOOL FUN_0204AEA8(struct UnkStruct_0204639C *a0); +void FUN_0204AEF8(struct UnkStruct_0204639C *a0, u32 a1, u32 a2); + +#endif -- cgit v1.2.3 From 119f9d3310a64d04a874aa3bb04b8c13b05dab5b Mon Sep 17 00:00:00 2001 From: James Luke <5251299+ethanpepro@users.noreply.github.com> Date: Mon, 15 Mar 2021 14:44:23 -0400 Subject: Update with the requested changes --- arm9/src/unk_0204AEA8.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/arm9/src/unk_0204AEA8.c b/arm9/src/unk_0204AEA8.c index 23dd6960..9c572a8e 100644 --- a/arm9/src/unk_0204AEA8.c +++ b/arm9/src/unk_0204AEA8.c @@ -3,12 +3,10 @@ #include "unk_0204639C.h" #include "unk_0204AEA8.h" -#pragma thumb on - extern void MOD05_021E3444(u32, struct UnkStruct_0204639C *, u32); -extern void FUN_0200433C(u32, u32, u32); +extern void FUN_0200433C(u32, u16, u32); -BOOL FUN_0204AEA8(struct UnkStruct_0204639C *a0) +THUMB_FUNC BOOL FUN_0204AEA8(struct UnkStruct_0204639C *a0) { struct UnkStruct_0204639C *v0 = FUN_02046528(a0); u32 *v1 = FUN_0204652C(a0); @@ -17,7 +15,7 @@ BOOL FUN_0204AEA8(struct UnkStruct_0204639C *a0) { case 0: MOD05_021E3444(v1[2], v0, (u32)v1 + 4); - FUN_0200433C(5, ((v1[3] << 16) >> 16), 1); + FUN_0200433C(5, (u16)v1[3], 1); v1[0]++; break; case 1: @@ -32,7 +30,7 @@ BOOL FUN_0204AEA8(struct UnkStruct_0204639C *a0) return FALSE; } -void FUN_0204AEF8(struct UnkStruct_0204639C *a0, u32 a1, u32 a2) +THUMB_FUNC void FUN_0204AEF8(struct UnkStruct_0204639C *a0, u32 a1, u32 a2) { u32 *v0 = AllocFromHeapAtEnd(11, 4 * sizeof(u32)); -- cgit v1.2.3