From 571ffde3c552328e5a89b973f8765f71aec9c5e6 Mon Sep 17 00:00:00 2001 From: sup39 Date: Fri, 14 Oct 2022 20:44:43 +0900 Subject: [PATCH] [v0.0.1] rename tool, update README --- MANIFEST.in | 4 +- README.md | 114 ++++++++++++++++-- setup.cfg | 12 +- src/{supGeckoASM => supSMSASM}/__init__.py | 0 src/{supGeckoASM => supSMSASM}/cli.py | 5 +- .../include/macros.inc | 0 .../ldscript/NTSC-J_1.0.ld | 0 .../ldscript/NTSC-J_1.1.ld | 0 .../ldscript/common.ld | 0 9 files changed, 117 insertions(+), 18 deletions(-) rename src/{supGeckoASM => supSMSASM}/__init__.py (100%) rename src/{supGeckoASM => supSMSASM}/cli.py (98%) rename src/{supGeckoASM => supSMSASM}/include/macros.inc (100%) rename src/{supGeckoASM => supSMSASM}/ldscript/NTSC-J_1.0.ld (100%) rename src/{supGeckoASM => supSMSASM}/ldscript/NTSC-J_1.1.ld (100%) rename src/{supGeckoASM => supSMSASM}/ldscript/common.ld (100%) diff --git a/MANIFEST.in b/MANIFEST.in index 1606358..5f187e7 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,2 +1,2 @@ -include src/supGeckoASM/include/* -include src/supGeckoASM/ldscript/* +include src/supSMSASM/include/* +include src/supSMSASM/ldscript/* diff --git a/README.md b/README.md index dba7e89..d46d21f 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,114 @@ -# supGeckoASM -A tool to make gecko code from ASM +# supSMSASM +A tool to make Gecko code from ASM for SMS -## Supported code type +This tool only runs on Windows currently. + +## Installation +First, install [devkitPro](https://github.com/devkitPro/installer/releases). + +Then, use pip to install supSMSASM: +``` +pip install supSMSASM +``` + +## Usage +This tool can make C0, C2, and Fixed-Location-C2 code from ASM code. +See [Supported Code Type](#supported-code-type) for more information. + +With all files prepared, use the following command to generate the Gecko code: +``` +supSMSASM {*.s} [JP|JPA] +``` + +The generated code will be copied to your clipboard. + +## Symbols +Symbols defined in [ldscript/](src/supSMSASM/ldscript) can be used in `*.s` and `*.ld`. + +## Supported Code Type ### C0 +Simply write your ASM code in `*.s` and use `supSMSASM` to convert it into Gecko code. + ### C2 +You will need the following two files: +- `*.s`: ASM source code +- `*.ld`: LD script for defining the entry points of C2. You need to define a symbol `$$` and set the value to `0`. + +To define a C2 entry, +define a symbol with `$C2$` prepending to the symbol defined in `*.s` file. + +For example, to make 2 C2 codes, first write the body of the code in your `xxx.s` file: +```asm +SomeC2Code: + # ... + +AnotherC2Code: + # ... +``` + +Then, in your `xxx.ld` file, define the entry points: ```ld +/* The following line is required for C2 code type */ $$ = 0; -$C2$.xxx = ...; + +$C2$SomeC2Code = 0x80345678; +$C2$AnotherC2Code = 0x80DEFABC; ``` -### 06 + +Finally, use `supGeckoCode xxx.s` to generate Gecko code. +The result will be like: +``` +C2345678 XXXXXXXX +... (instructions in SomeC2Code) +C2DEFABC XXXXXXXX +... (instructions in AnotherC2Code) +``` + +Note that you can't branch to absolute address with `bl` or `b` directly +since the location of the code is unknown. +You will need to set the destination to register and use `blr`, `bctr` etc. instead. + +### Fixed-Location-C2 +To solve the problem that `C2` code type can't branch to absolute address directly, +you can use `06` to place the code into a fixed location +and then use `04` to replace the instruction with `b` or `bl` to the code. + +You will need the following two files (same as C2): +- `*.s`: ASM source code +- `*.ld`: LD script for defining the entry points and the address to place the code + +To define a entry, +define a symbol with `$b$` or `$bl$` prepending to the symbol defined in `*.s` file. +This will replace the instruction at the given address with `b` or `bl` to the the symbol. + +For example, to make 2 Fixed-Location-C2 codes, first write the body of the code in your `xxx.s` file: +```asm +SomeCodeWithB: + b $b$SomeCodeWithB+4 + +AnotherCodeWithBL: + # ... + blr +``` + +Then, in your `xxx.ld` file, define the entry points: ```ld -$$ = ...; -$b$.xxx = ...; -$bl$.yyy = ...; +/* The following line defines the address to place the code. + It will be 0x817F9800 if you don't specify */ +$$ = 0x817F9800; + +$b$SomeCodeWithB = 0x80345678; +$bl$AnotherCodeWithBL = 0x80DEFABC; ``` + +Finally, use `supGeckoCode xxx.s` to generate Gecko code. +The result will be like: +``` +04345678 494B4188 <-- b from 80345678 to SomeCodeWithB +04DEFABC 48A09D49 <-- bl from 80DEFABC to AnotherCodeWithBL +077F9800 XXXXXXXX +... (instructions in SomeCodeWithB and AnotherCodeWithBL) +``` + +Note that unlike C2, you have to explicitly do `b` or `blr` back to the original program. +In addition, just like C2, you have to put the original instruction manually if needed. diff --git a/setup.cfg b/setup.cfg index 48cc7c4..7539ac6 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,15 +1,15 @@ [metadata] -name = supGeckoASM -version = 0.0.1a2 +name = supSMSASM +version = 0.0.1 author = sup39 author_email = sms@sup39.dev -description = A tool to make gecko code from ASM +description = A tool to make Gecko code from ASM for SMS long_description = file: README.md long_description_content_type = text/markdown -url = https://github.com/sup39/supGeckoASM +url = https://github.com/sup39/supSMSASM license = MIT project_urls = - Bug Tracker = https://github.com/sup39/supGeckoASM/issues + Bug Tracker = https://github.com/sup39/supSMSASM/issues classifiers = Programming Language :: Python :: 3 License :: OSI Approved :: MIT License @@ -27,4 +27,4 @@ where = src [options.entry_points] console_scripts = - supGeckoASM = supGeckoASM.cli:main + supSMSASM = supSMSASM.cli:main diff --git a/src/supGeckoASM/__init__.py b/src/supSMSASM/__init__.py similarity index 100% rename from src/supGeckoASM/__init__.py rename to src/supSMSASM/__init__.py diff --git a/src/supGeckoASM/cli.py b/src/supSMSASM/cli.py similarity index 98% rename from src/supGeckoASM/cli.py rename to src/supSMSASM/cli.py index f2d7571..4b3b011 100644 --- a/src/supGeckoASM/cli.py +++ b/src/supSMSASM/cli.py @@ -18,6 +18,8 @@ def pbcopy(content): win32clipboard.SetClipboardText(content) win32clipboard.CloseClipboard() +logger = logging.getLogger('supGeckoCode') + def normalize_dolver(s): if re.match(r'^(?:JP?|N(?:TSC)?[-_]?J)(?:1\.?0|\.0)?$|^1\.0$', s): return 'NTSC-J_1.0' @@ -97,7 +99,7 @@ def asm2gecko(fnIn, dolver): if sec == '.text': asmSymbs[name] = addr else: - if name == '$$' and int(addr) == 0: + if name == '$$' and int(addr, 16) == 0: isC2 = True m = re.match(r'\$(bl?|C2)\$(.*)', name) if m is None: continue @@ -185,7 +187,6 @@ def asm2gecko(fnIn, dolver): def main(): logging.basicConfig() - logger = logging.getLogger('supGeckoCode') # check required bin for exe in ['powerpc-eabi-as', 'powerpc-eabi-ld', 'powerpc-eabi-objdump', 'powerpc-eabi-objcopy']: diff --git a/src/supGeckoASM/include/macros.inc b/src/supSMSASM/include/macros.inc similarity index 100% rename from src/supGeckoASM/include/macros.inc rename to src/supSMSASM/include/macros.inc diff --git a/src/supGeckoASM/ldscript/NTSC-J_1.0.ld b/src/supSMSASM/ldscript/NTSC-J_1.0.ld similarity index 100% rename from src/supGeckoASM/ldscript/NTSC-J_1.0.ld rename to src/supSMSASM/ldscript/NTSC-J_1.0.ld diff --git a/src/supGeckoASM/ldscript/NTSC-J_1.1.ld b/src/supSMSASM/ldscript/NTSC-J_1.1.ld similarity index 100% rename from src/supGeckoASM/ldscript/NTSC-J_1.1.ld rename to src/supSMSASM/ldscript/NTSC-J_1.1.ld diff --git a/src/supGeckoASM/ldscript/common.ld b/src/supSMSASM/ldscript/common.ld similarity index 100% rename from src/supGeckoASM/ldscript/common.ld rename to src/supSMSASM/ldscript/common.ld