Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# splat Release Notes

### 0.36.0

* New yaml option: `include_asm_macro_style`:
* Allows configuring the style used by the generated `INCLUDE_ASM` macro. It currently allows two possible values:
* `default`: Uses the default definition for the macro. This is the default.
* `maspsx_hack`: Changes the definition of the generated `INCLUDE_ASM` to be compatible with the one expected by `maspsx` when using the [reordering workaround hack](https://github.com/mkst/maspsx?tab=readme-ov-file#include_asm-reordering-workaround-hack). This value is only relevant for psx projects.

### 0.35.2

* Miscellaneous updates to generated macro labels.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ The brackets corresponds to the optional dependencies to install while installin
If you use a `requirements.txt` file in your repository, then you can add this library with the following line:

```txt
splat64[mips]>=0.35.2,<1.0.0
splat64[mips]>=0.36.0,<1.0.0
```

### Optional dependencies
Expand Down
9 changes: 9 additions & 0 deletions docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,15 @@ Some files may not be generated depending on the selected platform and compiler,

Defaults to `True`.

### include_asm_macro_style

Allows configuring the style used by the generated `INCLUDE_ASM` macro. It currently allows two possible values:

- `default`: Uses the default definition for the macro. This is the default.
- `maspsx_hack`: Changes the definition of the generated `INCLUDE_ASM` to be compatible with the one expected by `maspsx` when using the [reordering workaround hack](https://github.com/mkst/maspsx?tab=readme-ov-file#include_asm-reordering-workaround-hack).

Defaults to `default`.

### o_as_suffix

Used to determine the file extension of the built files that will be listed on the linker script.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]
name = "splat64"
# Should be synced with src/splat/__init__.py
version = "0.35.2"
version = "0.36.0"
description = "A binary splitting tool to assist with decompilation and modding projects"
readme = "README.md"
license = {file = "LICENSE"}
Expand Down
2 changes: 1 addition & 1 deletion src/splat/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
__package_name__ = __name__

# Should be synced with pyproject.toml
__version__ = "0.35.2"
__version__ = "0.36.0"
__author__ = "ethteck"

from . import util as util
Expand Down
4 changes: 4 additions & 0 deletions src/splat/scripts/create_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,10 @@ def create_psx_config(exe_path: Path, exe_bytes: bytes):
data_string_encoding: ASCII
rodata_string_guesser_level: 2
data_string_guesser_level: 2

# Uncomment this line in case you need to use the maspsx reorder workaround hack
# https://github.com/mkst/maspsx?tab=readme-ov-file#include_asm-reordering-workaround-hack
# include_asm_macro_style: maspsx_hack
"""

segments = f"""\
Expand Down
18 changes: 9 additions & 9 deletions src/splat/segtypes/n64/i1.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import n64img.image
from .img import N64SegImg
class N64SegI1(N64SegImg):
def __init__(self, *args, **kwargs):
kwargs["img_cls"] = n64img.image.I1
super().__init__(*args, **kwargs)
import n64img.image

from .img import N64SegImg


class N64SegI1(N64SegImg):
def __init__(self, *args, **kwargs):
kwargs["img_cls"] = n64img.image.I1
super().__init__(*args, **kwargs)
42 changes: 33 additions & 9 deletions src/splat/util/file_presets.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,23 @@ def write_include_asm_h():
# These compilers do not use the `INCLUDE_ASM` macro.
return

file_data = """\
#ifndef INCLUDE_ASM_H
#define INCLUDE_ASM_H

#if !defined(M2CTX) && !defined(PERMUTER)

#ifndef INCLUDE_ASM
if options.opts.include_asm_macro_style == "maspsx_hack":
include_asm_macro = """\
#define INCLUDE_ASM(FOLDER, NAME) \\
void __maspsx_include_asm_hack_##NAME() { \\
__asm__( \\
".text # maspsx-keep \\n" \\
" .align 2 # maspsx-keep\\n" \\
" .set noat # maspsx-keep\\n" \\
" .set noreorder # maspsx-keep\\n" \\
" .include \\"" FOLDER "/" #NAME ".s\\" # maspsx-keep\\n" \\
" .set reorder # maspsx-keep\\n" \\
" .set at # maspsx-keep\\n" \\
); \\
}
"""
else: # default
include_asm_macro = """\
#define INCLUDE_ASM(FOLDER, NAME) \\
__asm__( \\
".section .text\\n" \\
Expand All @@ -49,14 +59,28 @@ def write_include_asm_h():
" .set reorder\\n" \\
" .set at\\n" \\
)
#endif
#ifndef INCLUDE_RODATA
"""

include_rodata_macro = """\
#define INCLUDE_RODATA(FOLDER, NAME) \\
__asm__( \\
".section .rodata\\n" \\
" .include \\"" FOLDER "/" #NAME ".s\\"\\n" \\
".section .text" \\
)
"""

file_data = f"""\
#ifndef INCLUDE_ASM_H
#define INCLUDE_ASM_H

#if !defined(M2CTX) && !defined(PERMUTER)

#ifndef INCLUDE_ASM
{include_asm_macro}\
#endif
#ifndef INCLUDE_RODATA
{include_rodata_macro}\
#endif
__asm__(".include \\"include/labels.inc\\"\\n");

Expand Down
21 changes: 21 additions & 0 deletions src/splat/util/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ class SplatOpts:
generated_s_preamble: str
# Determines any extra content to be added in the generated macro.inc file
generated_macro_inc_content: Optional[str]
# Determines if files related to assembly macros should be regenerated by splat
generate_asm_macros_files: bool
# Changes the definition of the generated `INCLUDE_ASM`.
# default: The default one.
# maspsx_hack: Use the maspsx hack workaround definition https://github.com/mkst/maspsx?tab=readme-ov-file#include_asm-reordering-workaround-hack
include_asm_macro_style: Literal["default", "maspsx_hack"]
# Determines whether to use .o as the suffix for all binary files?... TODO document
use_o_as_suffix: bool
# the value of the $gp register to correctly calculate offset to %gp_rel relocs
Expand Down Expand Up @@ -400,6 +405,21 @@ def parse_endianness() -> Literal["big", "little"]:
else:
raise ValueError(f"Invalid endianness: {endianness}")

def parse_include_asm_macro_style() -> Literal["default", "maspsx_hack"]:
include_asm_macro_style = p.parse_opt_within(
"include_asm_macro_style",
str,
["default", "maspsx_hack"],
"default",
)

if include_asm_macro_style == "default":
return "default"
elif include_asm_macro_style == "maspsx_hack":
return "maspsx_hack"
else:
raise ValueError(f"Invalid endianness: {include_asm_macro_style}")

default_ld_bss_is_noload = True
if platform == "psx":
default_ld_bss_is_noload = False
Expand Down Expand Up @@ -431,6 +451,7 @@ def parse_endianness() -> Literal["big", "little"]:
"generated_macro_inc_content", str
),
generate_asm_macros_files=p.parse_opt("generate_asm_macros_files", bool, True),
include_asm_macro_style=parse_include_asm_macro_style(),
use_o_as_suffix=p.parse_opt("o_as_suffix", bool, False),
gp=p.parse_optional_opt("gp_value", int),
check_consecutive_segment_types=p.parse_opt(
Expand Down
3 changes: 2 additions & 1 deletion test/basic_app/expected/asm/data/main.bss.s
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

.section .bss, "wa"

dlabel D_80000540
nonmatching D_80000540, 0x80

dlabel D_80000540
/* 80000540 */ .space 0x80
6 changes: 4 additions & 2 deletions test/basic_app/expected/asm/data/main.data.s
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

.section .data, "wa"

dlabel D_80000500
nonmatching D_80000500

dlabel D_80000500
/* 1100 80000500 00000001 */ .word 0x00000001
enddlabel D_80000500

dlabel D_80000504
nonmatching D_80000504

dlabel D_80000504
/* 1104 80000504 00000000 */ .word 0x00000000
/* 1108 80000508 00000000 */ .word 0x00000000
/* 110C 8000050C 00000000 */ .word 0x00000000
Expand Down
6 changes: 4 additions & 2 deletions test/basic_app/expected/asm/data/main.rodata.s
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

.section .rodata, "a"

dlabel D_80000510
nonmatching D_80000510

dlabel D_80000510
/* 1110 80000510 00010203 */ .word 0x00010203
/* 1114 80000514 04050607 */ .word 0x04050607
enddlabel D_80000510

.align 3
dlabel jtbl_80000518
nonmatching jtbl_80000518

dlabel jtbl_80000518
/* 1118 80000518 80000448 */ .word .L80000448
/* 111C 8000051C 80000450 */ .word .L80000450
/* 1120 80000520 80000458 */ .word .L80000458
Expand Down
3 changes: 2 additions & 1 deletion test/basic_app/expected/asm/handwritten.s
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
.section .text, "ax"

/* Handwritten function */
glabel func_800004F0
nonmatching func_800004F0, 0xC

glabel func_800004F0
/* 10F0 800004F0 00851020 */ add $v0, $a0, $a1 /* handwritten instruction */
/* 10F4 800004F4 03E00008 */ jr $ra
/* 10F8 800004F8 00000000 */ nop
Expand Down
6 changes: 4 additions & 2 deletions test/basic_app/expected/asm/main.s
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

.section .text, "ax"

glabel func_80000400
nonmatching func_80000400, 0xA0

glabel func_80000400
/* 1000 80000400 27BDFFF8 */ addiu $sp, $sp, -0x8
/* 1004 80000404 AFBE0000 */ sw $fp, 0x0($sp)
/* 1008 80000408 03A0F021 */ addu $fp, $sp, $zero
Expand Down Expand Up @@ -60,8 +61,9 @@ nonmatching func_80000400, 0xA0
/* 109C 8000049C 27BD0008 */ addiu $sp, $sp, 0x8
endlabel func_80000400

glabel func_800004A0
nonmatching func_800004A0, 0x4C

glabel func_800004A0
/* 10A0 800004A0 27BDFFE8 */ addiu $sp, $sp, -0x18
/* 10A4 800004A4 AFBF0014 */ sw $ra, 0x14($sp)
/* 10A8 800004A8 AFBE0010 */ sw $fp, 0x10($sp)
Expand Down
3 changes: 2 additions & 1 deletion test/basic_app/expected/asm/nonmatchings/main/D_80000510.s
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
.section .rodata

dlabel D_80000510
nonmatching D_80000510

dlabel D_80000510
/* 1110 80000510 00010203 */ .word 0x00010203
/* 1114 80000514 04050607 */ .word 0x04050607
enddlabel D_80000510
6 changes: 4 additions & 2 deletions test/basic_app/expected/asm/nonmatchings/main/func_80000400.s
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
.section .rodata
.align 3
dlabel jtbl_80000518
nonmatching jtbl_80000518

dlabel jtbl_80000518
/* 1118 80000518 80000448 */ .word .L80000448
/* 111C 8000051C 80000450 */ .word .L80000450
/* 1120 80000520 80000458 */ .word .L80000458
Expand All @@ -16,8 +17,9 @@ enddlabel jtbl_80000518


.section .text
glabel func_80000400
nonmatching func_80000400, 0xA0

glabel func_80000400
/* 1000 80000400 27BDFFF8 */ addiu $sp, $sp, -0x8
/* 1004 80000404 AFBE0000 */ sw $fp, 0x0($sp)
/* 1008 80000408 03A0F021 */ addu $fp, $sp, $zero
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
glabel func_800004A0
nonmatching func_800004A0, 0x4C

glabel func_800004A0
/* 10A0 800004A0 27BDFFE8 */ addiu $sp, $sp, -0x18
/* 10A4 800004A4 AFBF0014 */ sw $ra, 0x14($sp)
/* 10A8 800004A8 AFBE0010 */ sw $fp, 0x10($sp)
Expand Down
Loading