mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-20 16:49:58 -04:00
Import the base tree (MIT, see LICENSE)
This commit is contained in:
144
recomp/flags.py
Normal file
144
recomp/flags.py
Normal file
@@ -0,0 +1,144 @@
|
||||
"""Function-local NZCV for recomp/gen.py.
|
||||
|
||||
The lifter writes flags the way the guest does: every flag-setting instruction packs N, Z, C and V into c->nzcv
|
||||
(subs64() and friends in runtime/cpu.h) and every reader unpacks them (COND_xx(c)). Compilers keep NZCV inside a
|
||||
function, and AAPCS64 neither passes it to a callee nor preserves it across a call. So a generated function keeps its
|
||||
flags in a local `Flags F` (runtime/cpu.h), which clang holds in registers, and writes c->nzcv only where it leaves
|
||||
for another function other than by a call or a return (see plan()).
|
||||
|
||||
A flag-setting instruction of a known kind (subtract, add or logic result; 32 or 64 bits) stores its operands in F.a
|
||||
and F.b. A reader all of whose reaching definitions are of one kind computes its condition from those operands, so
|
||||
`cmp x1, x2; b.lt` becomes a signed compare in C. Instructions whose result is only known packed (CCMP, FCMP, MSR
|
||||
NZCV, ADCS) write F.nz, the packed form; a reader whose definitions are of several kinds reads F.nz, and those
|
||||
definitions then also write it.
|
||||
|
||||
A read that can see flags a callee left reads the caller's flags from before the call instead. AAPCS64 code never
|
||||
reads a callee's flags, so such a read only sits on a path that does not run: in NX2navi it follows calls to noreturn
|
||||
functions (asserts) that the compiler placed before another branch's target. Plan.after_call counts them.
|
||||
"""
|
||||
import re
|
||||
|
||||
KIND_DEF = re.compile(r'\b(subs|adds|logic)(32|64)\(c, ')
|
||||
CARRY_DEF = re.compile(r'\b(adcs|sbcs)(32|64)\(c, ')
|
||||
CARRY_USE = re.compile(r'\b(adc|sbc)(32|64)\(c, ')
|
||||
COND = re.compile(r'COND_([A-Z]{2})\(c\)')
|
||||
NZ_DEF = 'c->nzcv = '
|
||||
NZ_USE = '(c->nzcv)'
|
||||
KIND_NAME = {'subs': 'sub', 'adds': 'add', 'logic': 'logic'}
|
||||
|
||||
ENTRY, CALL = 'entry', 'call'
|
||||
|
||||
|
||||
class FlagError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def effect(code):
|
||||
"""(reads flags, kind of the flags written or None) of one instruction's C."""
|
||||
reads = bool(COND.search(code) or CARRY_USE.search(code) or CARRY_DEF.search(code) or NZ_USE in code)
|
||||
if NZ_DEF in code or CARRY_DEF.search(code):
|
||||
return reads, 'nz'
|
||||
defs = KIND_DEF.findall(code)
|
||||
if len(defs) > 1:
|
||||
raise FlagError(f'several flag definitions in one instruction: {code}')
|
||||
if defs:
|
||||
op, size = defs[0]
|
||||
return reads, KIND_NAME[op] + size
|
||||
return reads, None
|
||||
|
||||
|
||||
class Plan:
|
||||
"""Per instruction: the kind its flag reads use, whether its flag definition also writes F.nz, and what it writes
|
||||
to c->nzcv before it leaves for another function."""
|
||||
|
||||
def __init__(self, n):
|
||||
self.reader = [None] * n
|
||||
self.pack = [False] * n
|
||||
self.exit = [None] * n # kind of the flags to publish in c->nzcv at a tail exit, or None
|
||||
self.entry = False # F.nz starts as c->nzcv: flags from the entry reach a read or an exit
|
||||
self.entry_read = False # they reach a read, not only an exit
|
||||
self.after_call = 0 # reads that can see flags a callee left (see the module docstring)
|
||||
self.used = False
|
||||
|
||||
def decl(self):
|
||||
"""Declaration of F at the top of the function."""
|
||||
return 'Flags F = {.nz = c->nzcv};' if self.entry else 'Flags F = {0};'
|
||||
|
||||
def publish(self, i):
|
||||
"""Statement writing the flags to c->nzcv at instruction i's tail exit ('' when it need not)."""
|
||||
k = self.exit[i]
|
||||
return f'c->nzcv = fnz_{k}(&F); ' if k else ''
|
||||
|
||||
def rewrite(self, i, code):
|
||||
"""code of instruction i with its flag reads and writes on F."""
|
||||
rk = self.reader[i]
|
||||
_, dk = effect(code)
|
||||
if rk:
|
||||
code = COND.sub(lambda m: f'fc_{rk}(&F, CC_{m.group(1)})', code)
|
||||
code = CARRY_DEF.sub(lambda m: f'{m.group(1)}{m.group(2)}f(&F, fc_{rk}(&F, CC_CS), ', code)
|
||||
code = CARRY_USE.sub(lambda m: f'{m.group(1)}{m.group(2)}f(fc_{rk}(&F, CC_CS), ', code)
|
||||
code = code.replace(NZ_USE, f'(fnz_{rk}(&F))')
|
||||
if dk == 'nz':
|
||||
code = code.replace(NZ_DEF, 'F.nz = ')
|
||||
code = re.sub(r'\(void\)(subs|adds)(32|64)\(c, ', lambda m: f'F.nz = nz_{KIND_NAME[m.group(1)]}{m.group(2)}(',
|
||||
code)
|
||||
elif dk:
|
||||
code = KIND_DEF.sub(lambda m: f'f{KIND_NAME[m.group(1)]}{m.group(2)}(&F, ', code)
|
||||
if self.pack[i]:
|
||||
code += f' F.nz = fnz_{dk}(&F);'
|
||||
if 'c->nzcv' in code or COND.search(code) or KIND_DEF.search(code) or CARRY_USE.search(code):
|
||||
raise FlagError(f'flag access left after the rewrite: {code}')
|
||||
return code
|
||||
|
||||
|
||||
def plan(effects, succ, calls, exits):
|
||||
"""effects[i]: (reads, kind or None); succ[i]: successor indices inside the function; calls: indices of calls,
|
||||
whose callee may leave any flags; exits: indices that can leave for another function other than by a call or a
|
||||
return (a tail branch, falling into the next function, a br through rt_dispatch).
|
||||
|
||||
Discovery can start a function inside another one (a branch target, a materialised address), and the code
|
||||
before it then falls or branches into it with live flags. So a tail exit publishes the flags in c->nzcv, and a
|
||||
function whose reads can see its entry flags starts F.nz from c->nzcv. Calls and returns publish nothing: AAPCS64
|
||||
code neither passes flags to a callee nor reads a callee's, so a call's flags count as no definition."""
|
||||
n = len(effects)
|
||||
p = Plan(n)
|
||||
if not any(r or k for r, k in effects):
|
||||
return p
|
||||
p.used = True
|
||||
reach = [set() for _ in range(n)]
|
||||
reach[0].add(ENTRY)
|
||||
work = [0]
|
||||
while work:
|
||||
i = work.pop()
|
||||
out = {i} if effects[i][1] else ({CALL} if i in calls else reach[i])
|
||||
for s in succ[i]:
|
||||
if not out <= reach[s]:
|
||||
reach[s] |= out
|
||||
work.append(s)
|
||||
|
||||
def kind(d):
|
||||
return 'nz' if d == ENTRY else effects[d][1]
|
||||
|
||||
def use(r):
|
||||
"""Kind a use of the definitions r reads; several kinds read the packed form, which they then all write."""
|
||||
kinds = {kind(d) for d in r}
|
||||
if ENTRY in r:
|
||||
p.entry = True
|
||||
if len(kinds) == 1:
|
||||
return kinds.pop()
|
||||
for d in r:
|
||||
if d != ENTRY:
|
||||
p.pack[d] = True
|
||||
return 'nz' # several kinds, or none (unreachable)
|
||||
|
||||
for i, (reads, _) in enumerate(effects):
|
||||
if reads:
|
||||
p.after_call += CALL in reach[i]
|
||||
p.reader[i] = use(reach[i] - {CALL})
|
||||
p.entry_read |= ENTRY in reach[i]
|
||||
for i in exits:
|
||||
# Entry flags alone are still in c->nzcv.
|
||||
r = reach[i] - {CALL}
|
||||
if r and r != {ENTRY}:
|
||||
p.exit[i] = use(r)
|
||||
return p
|
||||
818
recomp/gen.py
Normal file
818
recomp/gen.py
Normal file
@@ -0,0 +1,818 @@
|
||||
# Adapted from LAS Recomp tools/gen.py @ da35b83 (MIT, Copyright (c) 2026 Peiikai).
|
||||
"""Generate C for the ExeFS modules: function discovery, then parallel emission into chunked C files.
|
||||
|
||||
Usage: gen.py --exefs build/extracted/v121/exefs --out generated/v121 [--modules main,subsdk0,sdk] [--jobs N]
|
||||
[--limit N] [--chunk-fns N] [--chunk-bytes B] [--big-fn B] [--patches FILE]
|
||||
|
||||
Output, under --out:
|
||||
layout.h, layout.json module bases (recomp/layout.py)
|
||||
<mod>/<mod>_NNNN.c one `void f_<addr>(Cpu *c)` per guest function, about --chunk-bytes of C per file
|
||||
<mod>/<mod>_table.c sorted <mod>_fn_addrs[] / <mod>_fn_ptrs[] / <mod>_fn_count for rt_dispatch
|
||||
<mod>/manifest.json chunk list, function count, statistics and timings
|
||||
patches.h code patch sets for the runtime (recomp/patches.py; no sets without --patches)
|
||||
|
||||
Function discovery runs in this process, vectorised over the module's .text words. Function starts are the module
|
||||
seeds (.eh_frame_hdr, exported FUNC symbols, RELATIVE relocation targets), every BL target, and code addresses
|
||||
materialised by ADR or ADRP+ADD (except an ADR that anchors a jump table: one with a `br` in the next 16
|
||||
instructions, or one an ADD register form uses as its base right after). A function is [start, next start). A direct branch whose target lies outside its
|
||||
function makes the target a new start, until no new start appears.
|
||||
|
||||
Emission runs in worker processes, one chunk per task. Each worker loads the modules itself, lifts one function at a
|
||||
time and resolves its jump tables (recomp/jumptables.py), so memory per worker does not grow with the module.
|
||||
Chunks are sized from a per-instruction estimate of the C they produce, so their names and contents only depend on
|
||||
the input; a chunk whose text did not change is not rewritten and keeps its mtime.
|
||||
"""
|
||||
import argparse
|
||||
import json
|
||||
import multiprocessing as mp
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import time
|
||||
from collections import Counter
|
||||
from pathlib import Path
|
||||
|
||||
import numpy as np
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(ROOT / 'tools'))
|
||||
sys.path.insert(0, str(ROOT / 'recomp'))
|
||||
|
||||
import flags # noqa: E402
|
||||
import hostmem # noqa: E402
|
||||
import jumptables # noqa: E402
|
||||
import patches # noqa: E402
|
||||
import regs # noqa: E402
|
||||
from check_content import GENERATED_MARKER # noqa: E402
|
||||
from layout import layout, write as write_layout # noqa: E402
|
||||
from lifter import hx # noqa: E402
|
||||
from module import Module # noqa: E402
|
||||
|
||||
TERMINATORS = ('b', 'br', 'ret', 'trap')
|
||||
MUSTTAIL = '__attribute__((musttail)) return'
|
||||
|
||||
# Estimated bytes of C per instruction, by class, for chunking (estimate_sizes()).
|
||||
# Least squares over every function of main, subsdk0 and sdk (1.2.1) gives 62 / 75 / 48 bytes per instruction, 38
|
||||
# per function and 4.5 per instruction of a function with a `br` (switches; the all-label fallback costs about 60
|
||||
# per instruction but is rare); the median error per function is 7 %.
|
||||
EST_INT = 62
|
||||
EST_SIMD = 75
|
||||
EST_SIMD_LDST = 48
|
||||
EST_FN = 38 # per function: signature, FN_ENTER, closing brace
|
||||
EST_BR_LABELS = 10 # per instruction of a function with a `br`: switch cases, or labels if it falls back
|
||||
|
||||
|
||||
def fname(a):
|
||||
return f'f_{a:x}'
|
||||
|
||||
|
||||
def header(what):
|
||||
return f'// {GENERATED_MARKER}: {what}, generated by recomp/gen.py from game code. Do not edit or commit.\n'
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------------------------ discovery
|
||||
|
||||
def _sext(v, n):
|
||||
v = v.astype(np.int64)
|
||||
return np.where(v & (1 << (n - 1)), v - (1 << n), v)
|
||||
|
||||
|
||||
def discover(mod):
|
||||
"""Function starts of mod as a sorted int64 array of word indices into mod.words, plus discovery statistics."""
|
||||
w = mod.words
|
||||
n = len(w)
|
||||
|
||||
def idx(mask):
|
||||
return np.flatnonzero(mask).astype(np.int64)
|
||||
|
||||
seeds = (np.asarray(mod.seeds(), dtype=np.int64) - mod.lo) >> 2
|
||||
|
||||
# B and BL: imm26. BL targets are function starts; B targets join the fixpoint below.
|
||||
b_all = idx((w & 0x7C000000) == 0x14000000)
|
||||
imm = _sext(w[b_all] & 0x03FFFFFF, 26)
|
||||
is_bl = (w[b_all] >> 31).astype(bool)
|
||||
bl_tgt = b_all[is_bl] + imm[is_bl]
|
||||
br_src, br_tgt = [b_all[~is_bl]], [b_all[~is_bl] + imm[~is_bl]]
|
||||
# B.cond (the lifter accepts o1 = 1 too), CBZ/CBNZ: imm19 at bit 5. TBZ/TBNZ: imm14 at bit 5.
|
||||
for mask, val, nb in ((0xFE000010, 0x54000000, 19), (0x7E000000, 0x34000000, 19), (0x7E000000, 0x36000000, 14)):
|
||||
s = idx((w & mask) == val)
|
||||
br_src.append(s)
|
||||
br_tgt.append(s + _sext((w[s] >> 5) & ((1 << nb) - 1), nb))
|
||||
br_src, br_tgt = np.concatenate(br_src), np.concatenate(br_tgt)
|
||||
ok = (br_tgt >= 0) & (br_tgt < n)
|
||||
br_src, br_tgt = br_src[ok], br_tgt[ok]
|
||||
|
||||
# ADR: pc + imm21. ADRP: page + (imm21 << 12), then ADD (imm, 64-bit, unshifted) of the same register within
|
||||
# 8 instructions. Targets must be aligned and in .text.
|
||||
def imm21(s):
|
||||
v = w[s]
|
||||
return _sext(((v >> 5) & 0x7FFFF) << 2 | ((v >> 29) & 3), 21)
|
||||
|
||||
pc0 = np.int64(mod.lo)
|
||||
adr = idx((w & 0x9F000000) == 0x10000000)
|
||||
# Clang's jump tables add a table entry to an ADR anchor, the first case block, then `br`. That anchor is not a
|
||||
# function (it would split the switch): an ADR with a `br` in the next 16 instructions is not a seed, nor is one
|
||||
# whose register is the base of an ADD (shifted or extended register) in the next 4 instructions
|
||||
# (`adr xA, L; ldrb wO, [..]; add xA, xA, wO, lsl #2`), however far the scheduler moved the `br`.
|
||||
br = idx((w & 0xFFFFFC1F) == 0xD61F0000)
|
||||
nxt = np.searchsorted(br, adr)
|
||||
has_br = nxt < len(br)
|
||||
near = np.zeros(len(adr), dtype=bool)
|
||||
near[has_br] = br[nxt[has_br]] - adr[has_br] <= 16
|
||||
rd = w[adr] & 31
|
||||
for k in range(1, 5):
|
||||
x = w[np.minimum(adr + k, n - 1)]
|
||||
near |= (((x & 0xFF200000) == 0x8B000000) | ((x & 0xFFE00000) == 0x8B200000)) & (((x >> 5) & 31) == rd)
|
||||
adr = adr[~near]
|
||||
adr_bytes = pc0 + adr * 4 + imm21(adr)
|
||||
is_adrp = (w & 0x9F000000) == 0x90000000
|
||||
add = idx((w & 0xFFC00000) == 0x91000000)
|
||||
rn = ((w[add] >> 5) & 31).astype(np.int64)
|
||||
found = np.full(len(add), -1, dtype=np.int64)
|
||||
for k in range(1, 9):
|
||||
p = add - k
|
||||
cand = (found < 0) & (p >= 0)
|
||||
pc = np.where(cand, p, 0)
|
||||
cand &= is_adrp[pc] & ((w[pc] & 31).astype(np.int64) == rn)
|
||||
found[cand] = p[cand]
|
||||
hit = found >= 0
|
||||
p = found[hit]
|
||||
page = ((pc0 + p * 4) & ~np.int64(0xFFF)) + (imm21(p) << 12)
|
||||
add_bytes = page + ((w[add[hit]] >> 10) & 0xFFF).astype(np.int64)
|
||||
mat = np.concatenate([adr_bytes, add_bytes])
|
||||
mat = mat[(mat >= mod.lo) & (mat < mod.hi) & (mat % 4 == 0)]
|
||||
mat = (mat - pc0) >> 2
|
||||
|
||||
bl_tgt = bl_tgt[(bl_tgt >= 0) & (bl_tgt < n)]
|
||||
starts = np.unique(np.concatenate([seeds, bl_tgt, mat]))
|
||||
stats = {'seeds': int(len(seeds)), 'bl_targets': int(len(np.unique(bl_tgt))),
|
||||
'materialised_targets': int(len(np.unique(mat))), 'initial_starts': int(len(starts))}
|
||||
|
||||
rounds = 0
|
||||
while True:
|
||||
rounds += 1
|
||||
f = np.searchsorted(starts, br_src, side='right') - 1
|
||||
live = f >= 0
|
||||
f = np.where(live, f, 0)
|
||||
lo = starts[f]
|
||||
hi = np.where(f + 1 < len(starts), starts[np.minimum(f + 1, len(starts) - 1)], n)
|
||||
out = live & ((br_tgt < lo) | (br_tgt >= hi))
|
||||
new = np.setdiff1d(br_tgt[out], starts, assume_unique=False)
|
||||
if not len(new):
|
||||
break
|
||||
starts = np.union1d(starts, new)
|
||||
stats['rounds'] = rounds
|
||||
stats['functions'] = int(len(starts))
|
||||
return starts, stats
|
||||
|
||||
|
||||
def estimate_sizes(mod, starts):
|
||||
"""Estimated bytes of C per function (for chunking only; the manifest records the real sizes)."""
|
||||
w = mod.words
|
||||
cost = np.full(len(w), EST_INT, dtype=np.int64)
|
||||
cost[(w & 0x0E000000) == 0x0E000000] = EST_SIMD # FP/AdvSIMD data processing
|
||||
cost[((w & 0x0A000000) == 0x08000000) & (((w >> 26) & 1) == 1)] = EST_SIMD_LDST # FP/SIMD load/store
|
||||
has_br = np.zeros(len(w), dtype=np.int64)
|
||||
has_br[np.flatnonzero((w & 0xFFFFFC1F) == 0xD61F0000)] = 1 # BR Xn
|
||||
csum = np.concatenate([[0], np.cumsum(cost)])
|
||||
bsum = np.concatenate([[0], np.cumsum(has_br)])
|
||||
ends = np.append(starts[1:], len(w))
|
||||
size = csum[ends] - csum[starts] + EST_FN
|
||||
with_br = (bsum[ends] - bsum[starts]) > 0
|
||||
size[with_br] += (ends[with_br] - starts[with_br]) * EST_BR_LABELS
|
||||
return size
|
||||
|
||||
|
||||
def partition(est, max_fns, max_bytes, big_fn):
|
||||
"""Contiguous [i0, i1) function ranges: at most max_fns functions and about max_bytes of C each; a function
|
||||
estimated above big_fn gets a file of its own so large functions compile in parallel."""
|
||||
chunks, i0, size = [], 0, 0
|
||||
for i, s in enumerate(est.tolist()):
|
||||
if s > big_fn:
|
||||
if i > i0:
|
||||
chunks.append((i0, i))
|
||||
chunks.append((i, i + 1))
|
||||
i0, size = i + 1, 0
|
||||
continue
|
||||
if i > i0 and (i - i0 >= max_fns or size + s > max_bytes):
|
||||
chunks.append((i0, i))
|
||||
i0, size = i, 0
|
||||
size += s
|
||||
if len(est) > i0:
|
||||
chunks.append((i0, len(est)))
|
||||
return chunks
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------------------------ emission
|
||||
|
||||
class Emitter:
|
||||
"""C for the functions of one module. starts is the set of every function start of the module."""
|
||||
|
||||
def __init__(self, mod, starts, patched=None, reg_locals=regs.LOCALS, callee_saved=True, spins=None):
|
||||
self.mod = mod
|
||||
self.starts = starts
|
||||
self.patched = patched or {} # {address: [(set index, [replacement words])]} (recomp/patches.py)
|
||||
self.spins = spins or {} # {spin wait back-edge: its head} (recomp/patches.py `spin`)
|
||||
self.reg_locals = reg_locals # recomp/regs.py: registers per function in C locals
|
||||
self.kept = regs.CALLEE_SAVED if callee_saved else frozenset() # not reloaded after a call
|
||||
self.uses_patches = False
|
||||
self.stats = Counter()
|
||||
self.unsupported = Counter()
|
||||
|
||||
def scan(self, insns, entry, end):
|
||||
"""Labels and jump tables of one function: {pc: sorted targets} for resolved tables, 'all' for an
|
||||
unresolved computed br."""
|
||||
mod, labels, tables = self.mod, set(), {}
|
||||
for i, ins in enumerate(insns):
|
||||
k = ins.kind
|
||||
if k in ('b', 'bcond'):
|
||||
if entry <= ins.target < end:
|
||||
labels.add(ins.target)
|
||||
elif k == 'br':
|
||||
a = entry + 4 * i
|
||||
jt = jumptables.resolve(mod, a, entry, end)
|
||||
if jt:
|
||||
tables[a] = jt
|
||||
labels.update(jt)
|
||||
self.stats['jump_tables'] += 1
|
||||
self.stats['jump_table_targets'] += len(jt)
|
||||
elif jumptables.is_computed(mod, a, entry):
|
||||
tables[a] = 'all'
|
||||
self.stats['all_label_fallbacks'] += 1
|
||||
else:
|
||||
self.stats['br_dispatch'] += 1
|
||||
elif k == 'trap':
|
||||
self.stats['traps'] += 1
|
||||
c = ins.code
|
||||
if c.startswith('rt_udf') and '/*' in c:
|
||||
self.stats['unsupported'] += 1
|
||||
msg = c[c.index('/*') + 2:c.rindex('*/')].strip()
|
||||
self.unsupported[re.sub(r'\b[0-9a-f]{8}\b', '', msg).strip()] += 1
|
||||
elif k == 'asm':
|
||||
raise ValueError(f'{entry + 4 * i:#x}: asm instruction from the portable lifter')
|
||||
for a in self.patched: # a replacement's branch into the function needs its label
|
||||
if entry <= a < end:
|
||||
for words in self.replacements(a):
|
||||
r = words[-1]
|
||||
if r.kind in ('b', 'bcond') and entry <= r.target < end:
|
||||
labels.add(r.target)
|
||||
return labels, tables
|
||||
|
||||
def replacements(self, a):
|
||||
"""The lifted words of each alternative of the patched site a, in set order. Only the last word of an
|
||||
alternative may branch (bl, b, b.cond / cbz / tbz, ret)."""
|
||||
out = []
|
||||
for _, words in self.patched[a]:
|
||||
lifted = [self.mod.lifter.lift(w, a) for w in words]
|
||||
for j, r in enumerate(lifted):
|
||||
last = j == len(lifted) - 1
|
||||
if r.kind != 'op' and not (last and r.kind in ('bl', 'b', 'bcond', 'ret')):
|
||||
raise patches.PatchError(f'{a:#x}: replacement word {words[j]:08x} is a {r.kind}')
|
||||
out.append(lifted)
|
||||
return out
|
||||
|
||||
def flow(self, insns, entry, end, tables):
|
||||
"""Successors of each instruction inside the function [entry, end). Index len(insns) stands for falling
|
||||
through into the next function and has none. A patched site has the successors of all its alternatives."""
|
||||
def idx(t):
|
||||
return [(t - entry) // 4] if entry <= t < end else []
|
||||
|
||||
def of(ins, i):
|
||||
k = ins.kind
|
||||
if k in ('op', 'bl', 'blr'):
|
||||
return [i + 1]
|
||||
if k == 'b':
|
||||
return idx(ins.target)
|
||||
if k == 'bcond':
|
||||
return idx(ins.target) + [i + 1]
|
||||
if k == 'br':
|
||||
jt = tables.get(entry + 4 * i)
|
||||
return [t for x in jt for t in idx(x)] if jt and jt != 'all' else []
|
||||
return [] # ret, trap
|
||||
|
||||
succ = []
|
||||
for i, ins in enumerate(insns):
|
||||
s = of(ins, i)
|
||||
a = entry + 4 * i
|
||||
if a in self.patched:
|
||||
for words in self.replacements(a):
|
||||
s += [t for t in of(words[-1], i) if t not in s]
|
||||
succ.append(s)
|
||||
succ.append([])
|
||||
return succ
|
||||
|
||||
def flag_plan(self, insns, entry, end, tables, succ):
|
||||
"""recomp/flags.py plan for the function: each instruction's flag use over the flow succ (flow())."""
|
||||
n = len(insns)
|
||||
calls, effects, exits = set(), [], {n}
|
||||
for i, ins in enumerate(insns):
|
||||
k, a = ins.kind, entry + 4 * i
|
||||
if k in ('bl', 'blr'):
|
||||
calls.add(i)
|
||||
elif k in ('b', 'bcond') and not entry <= ins.target < end:
|
||||
exits.add(i)
|
||||
elif k == 'br':
|
||||
exits.add(i) # through rt_dispatch, also a table's default
|
||||
if a in self.patched:
|
||||
effects.append(self.patched_effect(ins, a))
|
||||
for words in self.replacements(a):
|
||||
r = words[-1]
|
||||
if r.kind == 'bl':
|
||||
calls.add(i)
|
||||
elif r.kind in ('b', 'bcond') and not entry <= r.target < end:
|
||||
exits.add(i)
|
||||
else:
|
||||
effects.append(flags.effect(ins.cond if k == 'bcond' else ins.code or ''))
|
||||
effects.append((False, None))
|
||||
return flags.plan(effects, succ, calls, exits)
|
||||
|
||||
def patched_effect(self, ins, a):
|
||||
"""Flag effect of a patched site: every alternative (the original and each replacement) must write the same
|
||||
flags, in at most one word each; the site reads flags when any alternative does (a b.cond reads them)."""
|
||||
alts = []
|
||||
for words in [[ins]] + self.replacements(a):
|
||||
fx = [flags.effect(w.code or '') if w.kind == 'op' else flags.effect(w.cond) for w in words
|
||||
if w.kind in ('op', 'bcond')]
|
||||
fx = [e for e in fx if e[0] or e[1]]
|
||||
if len(fx) > 1:
|
||||
raise patches.PatchError(f'{a:#x}: several flag-using words in one alternative')
|
||||
alts.append(fx[0] if fx else (False, None))
|
||||
if any(e[1] != alts[0][1] for e in alts):
|
||||
raise patches.PatchError(f'{a:#x}: the alternatives write different flags ({[e[1] for e in alts]})')
|
||||
reads = any(e[0] for e in alts)
|
||||
if (alts[0][1] or reads) and (ins.kind == 'bl' or any(w[-1].kind == 'bl' for w in self.replacements(a))):
|
||||
raise patches.PatchError(f'{a:#x}: a patched call that uses flags')
|
||||
return reads, alts[0][1]
|
||||
|
||||
def function(self, entry, end):
|
||||
"""(lines of C, referenced function starts) for the guest function [entry, end)."""
|
||||
mod, starts = self.mod, self.starts
|
||||
insns = [mod.lift(a) for a in range(entry, end, 4)]
|
||||
labels, tables = self.scan(insns, entry, end)
|
||||
refs = set()
|
||||
all_labels = 'all' in tables.values()
|
||||
if all_labels:
|
||||
labels = set(range(entry, end, 4))
|
||||
# An unresolved computed br re-enters the function through fb_<entry>, a C function of its own, which local
|
||||
# flags would not survive; such functions keep NZCV in c->nzcv.
|
||||
# The same holds for registers in locals (recomp/regs.py): fb_<entry> keeps them in the Cpu too.
|
||||
local = not all_labels
|
||||
spill, reload, reload_call = (regs.SPILL, regs.RELOAD, regs.RELOAD_CALL) if local else ('', '', '')
|
||||
succ = self.flow(insns, entry, end, tables) if local else None
|
||||
fp = self.flag_plan(insns, entry, end, tables, succ) if local else None
|
||||
if fp and fp.used:
|
||||
self.stats['local_flag_functions'] += 1
|
||||
self.stats['flag_reads_direct'] += sum(1 for k in fp.reader if k and k != 'nz')
|
||||
self.stats['flag_reads_packed'] += sum(1 for k in fp.reader if k == 'nz')
|
||||
self.stats['flag_entry_functions'] += fp.entry
|
||||
self.stats['flag_entry_reads'] += fp.entry_read
|
||||
self.stats['flag_reads_after_call'] += fp.after_call
|
||||
self.stats['flag_publishing_exits'] += sum(1 for k in fp.exit if k)
|
||||
|
||||
def fx(i, code):
|
||||
return fp.rewrite(i, code) if fp and fp.used else code
|
||||
|
||||
def publish(i):
|
||||
return fp.publish(i) if fp and fp.used else ''
|
||||
|
||||
def jump(t, i):
|
||||
if entry <= t < end:
|
||||
return f'goto L_{t:x};'
|
||||
if t in starts:
|
||||
refs.add(t)
|
||||
return f'{publish(i)}{spill}{MUSTTAIL} {fname(t)}(c);'
|
||||
self.stats['external_branches'] += 1
|
||||
return f'{publish(i)}{spill}c->pc = {hx(t)}; {MUSTTAIL} rt_dispatch(c);'
|
||||
|
||||
if all_labels:
|
||||
# An unresolved computed br re-enters the function through fb_<entry>, which switches on c->pc to any
|
||||
# instruction. A goto to a shared dispatch block inside the body instead turns every instruction into
|
||||
# a loop header, and clang's loop passes then take tens of seconds on one function.
|
||||
fb = f'fb_{entry:x}'
|
||||
cases = ' '.join(f'case {hx(t)}: goto L_{t:x};' for t in range(entry, end, 4))
|
||||
redispatch = f'{MUSTTAIL} {fb}(c);'
|
||||
out = [f'static void {fb}(Cpu *c);',
|
||||
f'void {fname(entry)}(Cpu *c) {{', f' FN_ENTER({hx(entry)});', f' c->pc = {hx(entry)};',
|
||||
f' {redispatch}', '}',
|
||||
f'static void {fb}(Cpu *c) {{', f' switch (c->pc) {{ {cases} default: break; }}',
|
||||
f' {MUSTTAIL} rt_dispatch(c);']
|
||||
else:
|
||||
redispatch = f'{MUSTTAIL} rt_dispatch(c);'
|
||||
out = [f'void {fname(entry)}(Cpu *c) {{', f' FN_ENTER({hx(entry)});']
|
||||
if fp.used:
|
||||
out.append(' ' + fp.decl())
|
||||
|
||||
def call(t, a):
|
||||
if t in starts:
|
||||
refs.add(t)
|
||||
return f'c->x[30] = {hx(a + 4)}; {spill}{fname(t)}(c);{reload_call}'
|
||||
self.stats['external_calls'] += 1
|
||||
return f'c->x[30] = {hx(a + 4)}; {spill}c->pc = {hx(t)}; rt_dispatch(c);{reload_call}'
|
||||
|
||||
def op(i, code):
|
||||
code = fx(i, code)
|
||||
return f'{spill}{code}{reload}' if regs.ESCAPE.search(code) else code
|
||||
|
||||
def one(i, r, a):
|
||||
"""C of one lifted word of a patched site."""
|
||||
if r.kind == 'op':
|
||||
return op(i, r.code)
|
||||
if r.kind == 'bl':
|
||||
return call(r.target, a)
|
||||
if r.kind == 'b':
|
||||
return jump(r.target, i)
|
||||
if r.kind == 'bcond':
|
||||
return f'if ({fx(i, r.cond)}) {{ {jump(r.target, i)} }}'
|
||||
if r.kind == 'ret':
|
||||
return f'{spill}return;'
|
||||
raise patches.PatchError(f'{a:#x}: patched instruction is a {r.kind}')
|
||||
|
||||
def patch(i, ins, a):
|
||||
"""if (switch) { replacement } else if ... else { original } for a patched site (recomp/patches.py)."""
|
||||
if ins.kind not in ('op', 'bl', 'b', 'bcond'):
|
||||
raise patches.PatchError(f'{a:#x}: patched instruction is a {ins.kind}')
|
||||
line = ' '
|
||||
for (k, _), words in zip(self.patched[a], self.replacements(a)):
|
||||
line += f' if (rt_patch_on[{k}]) {{ {" ".join(one(i, r, a) for r in words)} }} else'
|
||||
self.uses_patches = True
|
||||
self.stats['patched_sites'] += 1
|
||||
return f'{line} {{ {one(i, ins, a)} }}'
|
||||
|
||||
body = [] # (instruction index or None for a label, line); a line belongs to the instruction it lifts
|
||||
|
||||
def emit(i, line):
|
||||
body.append((i, line))
|
||||
|
||||
k = None
|
||||
for i, ins in enumerate(insns):
|
||||
a = entry + 4 * i
|
||||
if a in labels:
|
||||
emit(None, f'L_{a:x}:;')
|
||||
k = ins.kind
|
||||
if a in self.patched:
|
||||
emit(i, patch(i, ins, a))
|
||||
elif k == 'op':
|
||||
emit(i, ' ' + op(i, ins.code))
|
||||
elif k == 'trap':
|
||||
emit(i, f' {spill}{fx(i, ins.code)}')
|
||||
elif k in ('b', 'bcond'):
|
||||
j = jump(ins.target, i)
|
||||
if self.spins.get(a) == ins.target and entry <= ins.target < end:
|
||||
j = f'rt_spin_gate(c, {hx(ins.target)}); {j}' # a pass of a spin wait
|
||||
self.stats['spin_gates'] += 1
|
||||
emit(i, ' ' + j if k == 'b' else f' if ({fx(i, ins.cond)}) {{ {j} }}')
|
||||
elif k == 'bl':
|
||||
emit(i, ' ' + call(ins.target, a))
|
||||
elif k == 'blr':
|
||||
emit(i, f' c->pc = {ins.target}; c->x[30] = {hx(a + 4)}; {spill}rt_dispatch(c);{reload_call}')
|
||||
elif k == 'br':
|
||||
jt = tables.get(a)
|
||||
if jt == 'all':
|
||||
emit(i, f' c->pc = {ins.target}; {redispatch}')
|
||||
elif jt:
|
||||
cases = ' '.join(f'case {hx(t)}: goto L_{t:x};' for t in jt)
|
||||
emit(i, f' switch ({ins.target}) {{ {cases} default: break; }}')
|
||||
emit(i, f' {publish(i)}{spill}c->pc = {ins.target}; {redispatch}')
|
||||
else:
|
||||
emit(i, f' {publish(i)}{spill}c->pc = {ins.target}; {MUSTTAIL} rt_dispatch(c);')
|
||||
elif k == 'ret':
|
||||
emit(i, f' {spill}return;')
|
||||
else:
|
||||
raise ValueError(f'{a:#x}: unknown instruction kind {k!r}')
|
||||
n = len(insns)
|
||||
if k not in TERMINATORS or end - 4 in self.patched: # falls through into the next function
|
||||
if end < mod.hi:
|
||||
emit(n, ' ' + jump(end, n))
|
||||
else:
|
||||
emit(n, f' {spill}rt_udf(c, {hx(end)});')
|
||||
if local:
|
||||
texts = [''] * (n + 1)
|
||||
for i, line in body:
|
||||
if i is not None:
|
||||
texts[i] += line
|
||||
clean = {i for i, ins in enumerate(insns) if entry + 4 * i not in self.patched
|
||||
and (ins.kind in ('bl', 'blr') or (ins.kind == 'op' and regs.RELOAD in texts[i]))}
|
||||
rp = regs.plan(texts, succ, clean, self.reg_locals, self.kept)
|
||||
if rp.regs:
|
||||
out.append(' ' + rp.decl())
|
||||
self.stats['local_reg_functions'] += bool(rp.regs)
|
||||
self.stats['reg_spills'] += sum(len(s) for s in rp.spill)
|
||||
out += [line if i is None else rp.resolve(i, line) for i, line in body]
|
||||
else:
|
||||
out += [line for _, line in body]
|
||||
out.append('}')
|
||||
self.stats['functions'] += 1
|
||||
self.stats['instructions'] += len(insns)
|
||||
return out, refs
|
||||
|
||||
|
||||
def chunk_text(name, number, emitter, fns):
|
||||
"""C text of one chunk. fns: [(entry, end)]."""
|
||||
body, refs = [], set()
|
||||
emitter.uses_patches = False
|
||||
for entry, end in fns:
|
||||
lines, r = emitter.function(entry, end)
|
||||
body.append('\n'.join(lines))
|
||||
refs |= r
|
||||
# Every referenced function gets a prototype, including ones defined later in this chunk.
|
||||
protos = ''.join(f'void {fname(r)}(Cpu *c);\n' for r in sorted(refs))
|
||||
if emitter.uses_patches:
|
||||
protos += 'extern uint8_t rt_patch_on[];\n'
|
||||
return (header(f'{name} chunk {number:04d}') + '#include "cpu.h"\n#include "simd.h"\n\n' + protos + '\n'
|
||||
+ '\n\n'.join(body) + '\n')
|
||||
|
||||
|
||||
def write_if_changed(path, text):
|
||||
"""Returns True if the file was written. An unchanged file keeps its mtime, so the build skips it. A changed one
|
||||
is written under a temporary name and renamed into place, so a reader never sees it half written."""
|
||||
data = text.encode()
|
||||
try:
|
||||
if path.stat().st_size == len(data) and path.read_bytes() == data:
|
||||
return False
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
tmp = path.with_name(f'.{path.name}.{os.getpid()}.tmp')
|
||||
tmp.write_bytes(data)
|
||||
try:
|
||||
_retry(os.replace, tmp, path)
|
||||
except OSError:
|
||||
tmp.unlink(missing_ok=True)
|
||||
raise
|
||||
return True
|
||||
|
||||
|
||||
def _retry(fn, *args):
|
||||
"""Windows refuses to rewrite or delete a file another process has open or mapped (clang maps its sources, so a
|
||||
build running on the output holds them; so can a scanner or an editor). Waits up to 30 s for it."""
|
||||
for i in range(120):
|
||||
try:
|
||||
return fn(*args)
|
||||
except OSError as e:
|
||||
if i == 119 or isinstance(e, FileNotFoundError):
|
||||
raise
|
||||
time.sleep(0.25)
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------------------------ workers
|
||||
|
||||
_W = {} # worker state: 'mods' {name: (path, base)}, 'starts' {name: sorted array}, 'emitters' {name: Emitter}
|
||||
|
||||
|
||||
def _worker_init(mods, starts, table, opts, jobs):
|
||||
_W['jobs'] = jobs
|
||||
_W['mods'] = mods
|
||||
_W['starts'] = starts
|
||||
_W['patches'] = table
|
||||
_W['opts'] = opts # Emitter keyword arguments
|
||||
_W['emitters'] = {}
|
||||
|
||||
|
||||
def _emitter(name):
|
||||
e = _W['emitters'].get(name)
|
||||
if e is None:
|
||||
path, base = _W['mods'][name]
|
||||
mod = Module(name, path, base, 'c')
|
||||
e = _W['emitters'][name] = Emitter(mod, set(_W['starts'][name].tolist()),
|
||||
_W['patches'].for_module(name, base),
|
||||
spins=_W['patches'].spins_for(name, base), **_W['opts'])
|
||||
return e
|
||||
|
||||
|
||||
def _emit_chunk(task):
|
||||
"""Worker: write one chunk. Returns its statistics."""
|
||||
name, number, path, fns = task
|
||||
t0 = time.perf_counter()
|
||||
# Test hook: a pool wider than this raises the MemoryError a busy machine does, so the retry can be exercised.
|
||||
limit = os.environ.get('NX2NAVI_LIFT_TEST_OOM_ABOVE')
|
||||
if limit and _W['jobs'] > int(limit) and number % 2 == 1:
|
||||
raise MemoryError
|
||||
e = _emitter(name)
|
||||
e.stats.clear()
|
||||
e.unsupported.clear()
|
||||
text = chunk_text(name, number, e, fns)
|
||||
error = None
|
||||
try:
|
||||
written = write_if_changed(Path(path), text)
|
||||
except OSError as ex:
|
||||
written, error = False, f'{path}: {ex}'
|
||||
return {'module': name, 'number': number, 'file': Path(path).name, 'functions': len(fns), 'bytes': len(text),
|
||||
'written': written, 'error': error, 'seconds': time.perf_counter() - t0, 'stats': dict(e.stats),
|
||||
'unsupported': dict(e.unsupported)}
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------------------------ driver
|
||||
|
||||
def table_text(name, addrs):
|
||||
lines = [header(f'{name} function table'), '#include "cpu.h"\n\n']
|
||||
lines += [f'void {fname(a)}(Cpu *c);\n' for a in addrs]
|
||||
lines.append(f'\nconst uint64_t {name}_fn_addrs[] = {{\n')
|
||||
lines.append(',\n'.join(hx(a) for a in addrs))
|
||||
lines.append(f'\n}};\nconst GuestFn {name}_fn_ptrs[] = {{\n')
|
||||
lines.append(',\n'.join(fname(a) for a in addrs))
|
||||
lines.append(f'\n}};\nconst uint64_t {name}_fn_count = {len(addrs)};\n')
|
||||
return ''.join(lines)
|
||||
|
||||
|
||||
def remove_stale(moddir, name, nchunks, errors):
|
||||
"""Delete chunks an earlier run wrote beyond this run's count, and temporary files an interrupted run left."""
|
||||
pat = re.compile(re.escape(name) + r'_(\d{4})\.c')
|
||||
removed = 0
|
||||
for p in moddir.iterdir():
|
||||
m = pat.fullmatch(p.name)
|
||||
if (m and int(m.group(1)) >= nchunks) or (p.name.startswith('.') and p.name.endswith('.tmp')):
|
||||
try:
|
||||
_retry(p.unlink)
|
||||
removed += 1
|
||||
except OSError as ex:
|
||||
errors.append(f'{p}: {ex}')
|
||||
return removed
|
||||
|
||||
|
||||
# Peak memory of one emit worker on 1.4.3 is 1.3 GiB (1.5 GiB with margin); the parent holds about 0.7 GiB.
|
||||
WORKER_MEM = 1536 << 20
|
||||
MEM_SHARE = 0.8 # of the free memory the workers may take, the rest is for the system and other programs
|
||||
|
||||
|
||||
def pick_jobs(requested):
|
||||
"""Worker count and the reason for it: --jobs if given, else the CPU count capped by the free memory."""
|
||||
if requested:
|
||||
return requested, '--jobs'
|
||||
env = os.environ.get('NX2NAVI_LIFT_JOBS', '').strip()
|
||||
if env:
|
||||
try:
|
||||
if int(env) >= 1:
|
||||
return int(env), 'NX2NAVI_LIFT_JOBS'
|
||||
except ValueError:
|
||||
pass
|
||||
print(f'ignoring NX2NAVI_LIFT_JOBS={env!r}: not a positive integer', file=sys.stderr, flush=True)
|
||||
cpus = os.cpu_count() or 4
|
||||
free = hostmem.available_ram()
|
||||
if free is None:
|
||||
return cpus, f'{cpus} CPUs, free memory unknown'
|
||||
by_mem = max(1, int(free * MEM_SHARE) // WORKER_MEM)
|
||||
return min(cpus, by_mem), f'{cpus} CPUs, {free / 2**30:.1f} GiB free memory allows {by_mem}'
|
||||
|
||||
|
||||
def main():
|
||||
ap = argparse.ArgumentParser(description=__doc__.splitlines()[0])
|
||||
ap.add_argument('--exefs', type=Path, required=True)
|
||||
ap.add_argument('--out', type=Path, required=True)
|
||||
ap.add_argument('--modules', default='main,subsdk0,sdk')
|
||||
ap.add_argument('--jobs', type=int, help='emit workers (default: by free memory and CPU count)')
|
||||
ap.add_argument('--limit', type=int, default=0, help='emit only the first N functions of each module')
|
||||
ap.add_argument('--chunk-fns', type=int, default=3000, help='functions per chunk at most')
|
||||
ap.add_argument('--chunk-bytes', type=int, default=3000000, help='estimated bytes of C per chunk')
|
||||
ap.add_argument('--big-fn', type=int, default=300000, help='estimated bytes of C from which a function gets '
|
||||
'its own chunk')
|
||||
ap.add_argument('--patches', type=Path, help='code patch table (recomp/patches.py)')
|
||||
ap.add_argument('--reg-locals', type=int, default=regs.LOCALS,
|
||||
help=f'guest registers per function kept in C locals (recomp/regs.py; default {regs.LOCALS}, 0: none)')
|
||||
ap.add_argument('--no-callee-saved-trust', action='store_true',
|
||||
help='reload X19-X29 and SP after every call too, instead of trusting AAPCS64 (slower; for '
|
||||
'telling a broken callee from a generator bug)')
|
||||
args = ap.parse_args()
|
||||
opts = {'reg_locals': args.reg_locals, 'callee_saved': not args.no_callee_saved_trust}
|
||||
|
||||
t0 = time.perf_counter()
|
||||
mods = layout(args.exefs)
|
||||
write_layout(mods, args.out)
|
||||
table = patches.load(args.patches, mods) if args.patches else patches.Table()
|
||||
write_if_changed(args.out / 'patches.h', patches.header_text(table, GENERATED_MARKER))
|
||||
want = args.modules.split(',')
|
||||
unknown = set(want) - {n for n, _, _ in mods}
|
||||
if unknown:
|
||||
raise SystemExit(f'not in {args.exefs}: {", ".join(sorted(unknown))}')
|
||||
|
||||
paths, starts_abs, info, tasks = {}, {}, {}, []
|
||||
for name, base, _ in mods:
|
||||
if name not in want:
|
||||
continue
|
||||
t = time.perf_counter()
|
||||
path = args.exefs / name
|
||||
mod = Module(name, path, base, 'c')
|
||||
patches.check(table, mod, name)
|
||||
starts, dstats = discover(mod)
|
||||
est = estimate_sizes(mod, starts)
|
||||
abs_starts = mod.lo + starts * 4
|
||||
n = len(starts) if not args.limit else min(args.limit, len(starts))
|
||||
ends = np.append(abs_starts[1:], mod.hi)
|
||||
chunks = partition(est[:n], args.chunk_fns, args.chunk_bytes, args.big_fn)
|
||||
moddir = args.out / name
|
||||
moddir.mkdir(parents=True, exist_ok=True)
|
||||
for number, (i0, i1) in enumerate(chunks):
|
||||
fns = list(zip(abs_starts[i0:i1].tolist(), ends[i0:i1].tolist()))
|
||||
tasks.append((int(est[i0:i1].sum()), (name, number, str(moddir / f'{name}_{number:04d}.c'), fns)))
|
||||
paths[name] = (str(path), base)
|
||||
starts_abs[name] = abs_starts
|
||||
info[name] = {'base': base, 'lo': mod.lo, 'hi': mod.hi, 'emitted': abs_starts[:n].tolist(),
|
||||
'chunks': len(chunks), 'discover': dstats, 'discover_seconds': time.perf_counter() - t,
|
||||
'moddir': moddir}
|
||||
print(f'{name}: {dstats["functions"]} functions ({dstats["seeds"]} seeds, {dstats["rounds"]} rounds), '
|
||||
f'{len(chunks)} chunks, discovery {time.perf_counter() - t:.1f}s', file=sys.stderr, flush=True)
|
||||
del mod
|
||||
|
||||
# Largest chunks first, so the pool does not end on a long tail.
|
||||
tasks.sort(key=lambda t: -t[0])
|
||||
results = {name: [] for name in info}
|
||||
done_at, errors = {}, []
|
||||
t_emit = time.perf_counter()
|
||||
ctx = mp.get_context('spawn')
|
||||
jobs, why = pick_jobs(args.jobs)
|
||||
pending = [t for _, t in tasks]
|
||||
emitted = 0
|
||||
while True:
|
||||
print(f'emitting with {jobs} workers ({why})', file=sys.stderr, flush=True)
|
||||
try:
|
||||
# Chunk writes are atomic and idempotent, so a chunk lost with a failed pool is simply emitted again.
|
||||
with ctx.Pool(jobs, initializer=_worker_init, initargs=(paths, starts_abs, table, opts, jobs)) as pool:
|
||||
for r in pool.imap_unordered(_emit_chunk, pending, chunksize=1):
|
||||
results[r['module']].append(r)
|
||||
if r['error']:
|
||||
errors.append(r['error'])
|
||||
done_at[r['module']] = time.perf_counter() - t_emit
|
||||
emitted += 1
|
||||
if emitted % 200 == 0 or emitted == len(tasks):
|
||||
print(f'emitted {emitted}/{len(tasks)} chunks, {time.perf_counter() - t_emit:.0f}s',
|
||||
file=sys.stderr, flush=True)
|
||||
break
|
||||
except MemoryError:
|
||||
if jobs == 1:
|
||||
raise
|
||||
smaller = jobs // 2
|
||||
print(f'emit: out of memory with {jobs} workers, retrying with {smaller}', file=sys.stderr, flush=True)
|
||||
jobs, why = smaller, 'after out of memory'
|
||||
done = {(r['module'], r['number']) for rs in results.values() for r in rs}
|
||||
pending = [t for t in pending if (t[0], t[1]) not in done]
|
||||
|
||||
for name, d in info.items():
|
||||
rs = sorted(results[name], key=lambda r: r['number'])
|
||||
moddir = d['moddir']
|
||||
stats, unsupported = Counter(), Counter()
|
||||
for r in rs:
|
||||
stats.update(r['stats'])
|
||||
unsupported.update(r['unsupported'])
|
||||
t = time.perf_counter()
|
||||
table_written = write_if_changed(moddir / f'{name}_table.c', table_text(name, d['emitted']))
|
||||
removed = remove_stale(moddir, name, d['chunks'], errors)
|
||||
manifest = {
|
||||
'module': name,
|
||||
'marker': GENERATED_MARKER,
|
||||
'base': f'{d["base"]:#x}',
|
||||
'text': [f'{d["lo"]:#x}', f'{d["hi"]:#x}'],
|
||||
'function_count': len(d['emitted']),
|
||||
'chunks': [r['file'] for r in rs],
|
||||
'table': f'{name}_table.c',
|
||||
'chunk_info': [{'file': r['file'], 'functions': r['functions'], 'bytes': r['bytes'],
|
||||
'seconds': round(r['seconds'], 2)} for r in rs],
|
||||
'stats': {
|
||||
**d['discover'],
|
||||
'emitted_functions': stats['functions'],
|
||||
'instructions': stats['instructions'],
|
||||
'jump_tables': stats['jump_tables'],
|
||||
'jump_table_targets': stats['jump_table_targets'],
|
||||
'all_label_fallbacks': stats['all_label_fallbacks'],
|
||||
'br_dispatch': stats['br_dispatch'],
|
||||
'traps': stats['traps'],
|
||||
'patched_sites': stats['patched_sites'],
|
||||
'local_flag_functions': stats['local_flag_functions'],
|
||||
'flag_reads_direct': stats['flag_reads_direct'],
|
||||
'flag_reads_packed': stats['flag_reads_packed'],
|
||||
'flag_entry_functions': stats['flag_entry_functions'],
|
||||
'flag_entry_reads': stats['flag_entry_reads'],
|
||||
'flag_reads_after_call': stats['flag_reads_after_call'],
|
||||
'flag_publishing_exits': stats['flag_publishing_exits'],
|
||||
'spin_gates': stats['spin_gates'],
|
||||
'unsupported': stats['unsupported'],
|
||||
'external_branches': stats['external_branches'],
|
||||
'external_calls': stats['external_calls'],
|
||||
'c_bytes': sum(r['bytes'] for r in rs),
|
||||
'largest_chunk_bytes': max((r['bytes'] for r in rs), default=0),
|
||||
'chunks_written': sum(r['written'] for r in rs) + table_written,
|
||||
'stale_chunks_removed': removed,
|
||||
},
|
||||
'unsupported_census': dict(unsupported.most_common(50)),
|
||||
'timings': {
|
||||
'discover_s': round(d['discover_seconds'], 2),
|
||||
'emit_wall_s': round(done_at.get(name, 0.0), 2),
|
||||
'emit_worker_s': round(sum(r['seconds'] for r in rs), 2),
|
||||
'table_s': round(time.perf_counter() - t, 2),
|
||||
},
|
||||
}
|
||||
write_if_changed(moddir / 'manifest.json', json.dumps(manifest, indent=1) + '\n')
|
||||
s = manifest['stats']
|
||||
print(f'{name}: {s["emitted_functions"]} functions, {len(rs)} chunks, {s["c_bytes"] / 1e6:.0f} MB of C, '
|
||||
f'{s["jump_tables"]} jump tables, {s["all_label_fallbacks"]} all-label fallbacks, '
|
||||
f'{s["br_dispatch"]} br via dispatch, {s["traps"]} traps ({s["unsupported"]} unsupported)',
|
||||
file=sys.stderr)
|
||||
print(f'total {time.perf_counter() - t0:.0f}s', file=sys.stderr)
|
||||
if errors:
|
||||
print(f'{len(errors)} files could not be written or removed (held open by another process?):',
|
||||
file=sys.stderr)
|
||||
for e in errors:
|
||||
print(f' {e}', file=sys.stderr)
|
||||
return 1
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
||||
1345
recomp/jumptables.py
Normal file
1345
recomp/jumptables.py
Normal file
File diff suppressed because it is too large
Load Diff
61
recomp/layout.py
Normal file
61
recomp/layout.py
Normal file
@@ -0,0 +1,61 @@
|
||||
"""Guest address layout of the loaded modules, computed from their sizes.
|
||||
|
||||
Guest addresses equal host addresses, and the lifter writes absolute addresses into the generated C, so the
|
||||
generator and the runtime must agree on every module base. This is the single place that decides them: the generator
|
||||
calls layout() and writes the result into generated/<version>/layout.h and layout.json, which the runtime and the
|
||||
build read.
|
||||
|
||||
Modules are placed in Horizon's load order (rtld is dropped; the host links the modules):
|
||||
main, subsdk0..9, sdk. Each base is aligned to 2 MiB. Everything must stay below 2^39, the limit of the addresses
|
||||
IPC buffers can encode.
|
||||
"""
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from nso import Nso
|
||||
|
||||
FIRST_BASE = 0x7000000000
|
||||
ALIGN = 0x200000
|
||||
ADDRESS_LIMIT = 1 << 39
|
||||
ORDER = ['main'] + [f'subsdk{i}' for i in range(10)] + ['sdk']
|
||||
|
||||
|
||||
def align_up(v, a=ALIGN):
|
||||
return (v + a - 1) & ~(a - 1)
|
||||
|
||||
|
||||
def layout(exefs):
|
||||
"""[(name, base, size)] for the modules present in the ExeFS directory, in load order."""
|
||||
exefs = Path(exefs)
|
||||
out, base = [], FIRST_BASE
|
||||
for name in ORDER:
|
||||
path = exefs / name
|
||||
if not path.exists():
|
||||
continue
|
||||
size = Nso(str(path)).size
|
||||
out.append((name, base, size))
|
||||
base = align_up(base + size)
|
||||
if base > ADDRESS_LIMIT:
|
||||
raise ValueError(f'modules end at {base:#x}, above 2^39')
|
||||
return out
|
||||
|
||||
|
||||
def write(mods, outdir):
|
||||
"""layout.json for Python tools and layout.h for the runtime."""
|
||||
outdir = Path(outdir)
|
||||
outdir.mkdir(parents=True, exist_ok=True)
|
||||
(outdir / 'layout.json').write_text(json.dumps(
|
||||
[{'name': n, 'base': f'{b:#x}', 'size': f'{s:#x}'} for n, b, s in mods], indent=1) + '\n')
|
||||
lines = ['// Module layout chosen by recomp/layout.py. Generated; do not edit.', '#pragma once', '']
|
||||
for n, b, s in mods:
|
||||
lines.append(f'#define MOD_{n.upper()}_BASE {b:#x}ull')
|
||||
lines.append(f'#define MOD_{n.upper()}_SIZE {s:#x}ull')
|
||||
lines += ['', f'#define MOD_COUNT {len(mods)}',
|
||||
'#define MOD_LIST(X) ' + ' '.join(f'X({n}, {n.upper()})' for n, _, _ in mods), '']
|
||||
(outdir / 'layout.h').write_text('\n'.join(lines))
|
||||
|
||||
|
||||
def read(outdir):
|
||||
"""[(name, base, size)] from a layout.json written by write()."""
|
||||
data = json.loads((Path(outdir) / 'layout.json').read_text())
|
||||
return [(m['name'], int(m['base'], 16), int(m['size'], 16)) for m in data]
|
||||
805
recomp/lifter.py
Normal file
805
recomp/lifter.py
Normal file
@@ -0,0 +1,805 @@
|
||||
# Adapted from LAS Recomp tools/lifter.py @ da35b83 (MIT, Copyright (c) 2026 Peiikai).
|
||||
"""AArch64 -> C static recompiler.
|
||||
|
||||
Integer, memory, and control flow are translated to C. FP/SIMD instructions (and CRC32) are
|
||||
either re-emitted as inline assembly (simd='asm', AArch64 hosts), with guest V registers
|
||||
loaded from / stored to the Cpu struct around each batch, so their semantics are
|
||||
bit-exact by construction, or lowered to portable C (simd='c', tools/simd_c.py + runtime/simd.h).
|
||||
"""
|
||||
import struct
|
||||
|
||||
# Cpu struct offsets (must match runtime/cpu.h)
|
||||
OFF_X = 0
|
||||
OFF_SP = 256
|
||||
OFF_PC = 264
|
||||
OFF_NZCV = 272
|
||||
OFF_V = 512
|
||||
|
||||
COND_NAMES = ['eq', 'ne', 'cs', 'cc', 'mi', 'pl', 'vs', 'vc', 'hi', 'ls', 'ge', 'lt', 'gt', 'le', 'al', 'nv']
|
||||
SCRATCH = [9, 10, 11, 12, 13, 14, 15, 16, 17]
|
||||
|
||||
|
||||
class Unsupported(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def bits(w, lo, n):
|
||||
return (w >> lo) & ((1 << n) - 1)
|
||||
|
||||
|
||||
def sext(v, n):
|
||||
return v - (1 << n) if v & (1 << (n - 1)) else v
|
||||
|
||||
|
||||
def ones(n):
|
||||
return (1 << n) - 1
|
||||
|
||||
|
||||
def ror(v, r, size):
|
||||
r %= size
|
||||
return ((v >> r) | (v << (size - r))) & ones(size) if r else v
|
||||
|
||||
|
||||
def replicate(v, esize, size):
|
||||
out = 0
|
||||
for i in range(0, size, esize):
|
||||
out |= v << i
|
||||
return out
|
||||
|
||||
|
||||
def decode_bit_masks(N, imms, immr, size, immediate):
|
||||
x = (N << 6) | (~imms & 0x3F)
|
||||
if x == 0:
|
||||
raise Unsupported('reserved bitmask')
|
||||
length = x.bit_length() - 1
|
||||
if length < 1:
|
||||
raise Unsupported('reserved bitmask')
|
||||
levels = ones(length)
|
||||
if immediate and (imms & levels) == levels:
|
||||
raise Unsupported('reserved bitmask')
|
||||
S = imms & levels
|
||||
R = immr & levels
|
||||
diff = (S - R) & 0x3F
|
||||
esize = 1 << length
|
||||
d = diff & ones(length)
|
||||
welem = ones(S + 1)
|
||||
telem = ones(d + 1)
|
||||
wmask = replicate(ror(welem, R, esize), esize, size)
|
||||
tmask = replicate(telem, esize, size)
|
||||
return wmask, tmask
|
||||
|
||||
|
||||
def hx(v):
|
||||
return f'0x{v:x}ull'
|
||||
|
||||
|
||||
# ---------------------------------------------------------------- register helpers
|
||||
|
||||
def X(r):
|
||||
return '0ull' if r == 31 else f'c->x[{r}]'
|
||||
|
||||
|
||||
def XS(r):
|
||||
return 'c->sp' if r == 31 else f'c->x[{r}]'
|
||||
|
||||
|
||||
def W(r):
|
||||
return '0u' if r == 31 else f'(uint32_t)c->x[{r}]'
|
||||
|
||||
|
||||
def WS(r):
|
||||
return '(uint32_t)c->sp' if r == 31 else f'(uint32_t)c->x[{r}]'
|
||||
|
||||
|
||||
def R(sf, r, sp=False):
|
||||
if sf:
|
||||
return XS(r) if sp else X(r)
|
||||
return WS(r) if sp else W(r)
|
||||
|
||||
|
||||
def set_reg(sf, r, expr, sp=False):
|
||||
"""Statement writing expr to Rd (zero-extending 32-bit results)."""
|
||||
if r == 31 and not sp:
|
||||
return f'(void)({expr});'
|
||||
dst = 'c->sp' if r == 31 else f'c->x[{r}]'
|
||||
if sf:
|
||||
return f'{dst} = (uint64_t)({expr});'
|
||||
return f'{dst} = (uint32_t)({expr});'
|
||||
|
||||
|
||||
def shift_expr(sf, val, typ, amt):
|
||||
if amt == 0 and typ != 3:
|
||||
return val
|
||||
if typ == 0:
|
||||
return f'({val} << {amt})'
|
||||
if typ == 1:
|
||||
return f'({val} >> {amt})'
|
||||
if typ == 2:
|
||||
return f'(uint64_t)((int64_t){val} >> {amt})' if sf else f'(uint32_t)((int32_t){val} >> {amt})'
|
||||
return f'ROR{64 if sf else 32}({val}, {amt})'
|
||||
|
||||
|
||||
def extend_expr(r, option, shift):
|
||||
base = X(r)
|
||||
e = {
|
||||
0: f'(uint64_t)(uint8_t){base}',
|
||||
1: f'(uint64_t)(uint16_t){base}',
|
||||
2: f'(uint64_t)(uint32_t){base}',
|
||||
3: base,
|
||||
4: f'(uint64_t)(int64_t)(int8_t){base}',
|
||||
5: f'(uint64_t)(int64_t)(int16_t){base}',
|
||||
6: f'(uint64_t)(int64_t)(int32_t){base}',
|
||||
7: base,
|
||||
}[option]
|
||||
return f'({e} << {shift})' if shift else e
|
||||
|
||||
|
||||
# ---------------------------------------------------------------- instruction classes
|
||||
|
||||
class Insn:
|
||||
"""Result of lifting one instruction."""
|
||||
__slots__ = ('kind', 'code', 'target', 'cond', 'asm')
|
||||
|
||||
def __init__(self, kind, code='', target=None, cond=None, asm=None):
|
||||
self.kind = kind # 'op', 'asm', 'b', 'bcond', 'bl', 'blr', 'br', 'ret', 'trap'
|
||||
self.code = code # C statements (for 'op'), or condition expr for 'bcond'
|
||||
self.target = target # branch target (int) or register expr
|
||||
self.cond = cond
|
||||
self.asm = asm # AsmInsn for 'asm'
|
||||
|
||||
|
||||
class AsmInsn:
|
||||
"""An FP/SIMD instruction to pass through as inline asm."""
|
||||
__slots__ = ('word', 'vregs', 'gprs', 'flags', 'consts')
|
||||
|
||||
def __init__(self, word, vregs, gprs, flags=False, consts=None):
|
||||
self.word = word
|
||||
self.vregs = vregs # set of V register numbers touched
|
||||
self.gprs = gprs # list of (bit position, guest reg or 'sp')
|
||||
self.flags = flags
|
||||
self.consts = consts or [] # list of (bit position, constant) loaded into scratch
|
||||
|
||||
|
||||
def is_fp_simd_dp(w):
|
||||
return bits(w, 25, 3) == 0b111
|
||||
|
||||
|
||||
def is_ldst(w):
|
||||
return bits(w, 25, 1) == 0 and bits(w, 27, 1) == 1
|
||||
|
||||
|
||||
class Lifter:
|
||||
def __init__(self, base, simd='asm'):
|
||||
self.base = base # absolute load address of the module (guest == host)
|
||||
if simd not in ('asm', 'c'):
|
||||
raise ValueError(f'simd={simd!r}')
|
||||
self.sc = None
|
||||
if simd == 'c':
|
||||
# simd_c imports lifter at module level, so this import cannot move to the top.
|
||||
from simd_c import SimdC
|
||||
self.sc = SimdC()
|
||||
|
||||
def lift(self, w, pc):
|
||||
"""pc is absolute. Returns an Insn."""
|
||||
op0 = bits(w, 25, 4)
|
||||
if (op0 & 0b1110) == 0b1000:
|
||||
return self.dp_imm(w, pc)
|
||||
if (op0 & 0b1110) == 0b1010:
|
||||
return self.branch_sys(w, pc)
|
||||
if (op0 & 0b0101) == 0b0100:
|
||||
return self.ldst(w, pc)
|
||||
if (op0 & 0b0111) == 0b0101:
|
||||
return self.dp_reg(w, pc)
|
||||
if (op0 & 0b0111) == 0b0111:
|
||||
return self.fp_simd(w, pc)
|
||||
# padding, trap words (e7ffdefe), header data: trap if ever executed
|
||||
return Insn('trap', f'rt_udf(c, {hx(pc)});')
|
||||
|
||||
# ------------------------------------------------------------ data processing (imm)
|
||||
|
||||
def dp_imm(self, w, pc):
|
||||
op = bits(w, 23, 3)
|
||||
sf = bits(w, 31, 1)
|
||||
rd, rn = bits(w, 0, 5), bits(w, 5, 5)
|
||||
if op in (0, 1): # PC-relative
|
||||
imm = sext((bits(w, 5, 19) << 2) | bits(w, 29, 2), 21)
|
||||
if bits(w, 31, 1):
|
||||
val = (pc & ~0xFFF) + (imm << 12)
|
||||
else:
|
||||
val = pc + imm
|
||||
return Insn('op', set_reg(1, rd, hx(val & ones(64))))
|
||||
if op == 2: # add/sub imm
|
||||
opc, S, sh = bits(w, 30, 1), bits(w, 29, 1), bits(w, 22, 1)
|
||||
imm = bits(w, 10, 12) << (12 if sh else 0)
|
||||
a = R(sf, rn, sp=True)
|
||||
if S:
|
||||
fn = ('subs' if opc else 'adds') + ('64' if sf else '32')
|
||||
return Insn('op', set_reg(sf, rd, f'{fn}(c, {a}, {hx(imm)})'))
|
||||
return Insn('op', set_reg(sf, rd, f'{a} {"-" if opc else "+"} {hx(imm)}', sp=True))
|
||||
if op == 4: # logical imm
|
||||
opc, N = bits(w, 29, 2), bits(w, 22, 1)
|
||||
if not sf and N:
|
||||
raise Unsupported('logical imm N=1 32-bit')
|
||||
size = 64 if sf else 32
|
||||
imm, _ = decode_bit_masks(N, bits(w, 10, 6), bits(w, 16, 6), size, True)
|
||||
a = R(sf, rn)
|
||||
if opc == 0:
|
||||
return Insn('op', set_reg(sf, rd, f'{a} & {hx(imm)}', sp=True))
|
||||
if opc == 1:
|
||||
return Insn('op', set_reg(sf, rd, f'{a} | {hx(imm)}', sp=True))
|
||||
if opc == 2:
|
||||
return Insn('op', set_reg(sf, rd, f'{a} ^ {hx(imm)}', sp=True))
|
||||
return Insn('op', set_reg(sf, rd, f'logic{size}(c, {a} & {hx(imm)})'))
|
||||
if op == 5: # move wide
|
||||
opc, hw = bits(w, 29, 2), bits(w, 21, 2)
|
||||
if not sf and hw > 1:
|
||||
raise Unsupported('movw hw')
|
||||
imm = bits(w, 5, 16) << (hw * 16)
|
||||
if opc == 0:
|
||||
return Insn('op', set_reg(sf, rd, hx(~imm & ones(64 if sf else 32))))
|
||||
if opc == 2:
|
||||
return Insn('op', set_reg(sf, rd, hx(imm)))
|
||||
if opc == 3:
|
||||
mask = ~(0xFFFF << (hw * 16)) & ones(64)
|
||||
return Insn('op', set_reg(sf, rd, f'({X(rd)} & {hx(mask)}) | {hx(imm)}'))
|
||||
raise Unsupported('movw opc')
|
||||
if op == 6: # bitfield
|
||||
opc, N = bits(w, 29, 2), bits(w, 22, 1)
|
||||
immr, imms = bits(w, 16, 6), bits(w, 10, 6)
|
||||
size = 64 if sf else 32
|
||||
if N != sf:
|
||||
raise Unsupported('bitfield N')
|
||||
wmask, tmask = decode_bit_masks(N, imms, immr, size, False)
|
||||
src = R(sf, rn)
|
||||
rot = f'ROR{size}({src}, {immr})' if immr else src
|
||||
if opc == 2: # UBFM
|
||||
return Insn('op', set_reg(sf, rd, f'{rot} & {hx(wmask & tmask)}'))
|
||||
if opc == 0: # SBFM
|
||||
top = f'(uint{size}_t)(-(int{size}_t)(({src} >> {imms}) & 1))'
|
||||
return Insn('op', set_reg(
|
||||
sf, rd, f'({top} & {hx(~tmask & ones(size))}) | ({rot} & {hx(wmask & tmask)})'))
|
||||
if opc == 1: # BFM
|
||||
dst = R(sf, rd)
|
||||
bot = f'(({dst} & {hx(~wmask & ones(size))}) | ({rot} & {hx(wmask)}))'
|
||||
return Insn('op', set_reg(
|
||||
sf, rd, f'({dst} & {hx(~tmask & ones(size))}) | ({bot} & {hx(tmask)})'))
|
||||
raise Unsupported('bitfield opc')
|
||||
if op == 7: # EXTR
|
||||
rm, lsb = bits(w, 16, 5), bits(w, 10, 6)
|
||||
size = 64 if sf else 32
|
||||
if lsb == 0:
|
||||
return Insn('op', set_reg(sf, rd, R(sf, rm)))
|
||||
return Insn('op', set_reg(
|
||||
sf, rd, f'({R(sf, rm)} >> {lsb}) | ((uint{size}_t){R(sf, rn)} << {size - lsb})'))
|
||||
raise Unsupported(f'dp_imm {w:08x}')
|
||||
|
||||
# ------------------------------------------------------------ branches / system
|
||||
|
||||
def branch_sys(self, w, pc):
|
||||
if bits(w, 26, 5) == 0b00101: # B / BL
|
||||
t = (pc + sext(bits(w, 0, 26), 26) * 4) & ones(64)
|
||||
return Insn('bl' if bits(w, 31, 1) else 'b', target=t)
|
||||
if bits(w, 25, 7) == 0b0101010 and not bits(w, 4, 1): # B.cond
|
||||
t = pc + sext(bits(w, 5, 19), 19) * 4
|
||||
cond = bits(w, 0, 4)
|
||||
if cond >= 14:
|
||||
return Insn('b', target=t)
|
||||
return Insn('bcond', target=t, cond=f'COND_{COND_NAMES[cond].upper()}(c)')
|
||||
if bits(w, 25, 6) == 0b011010: # CBZ/CBNZ
|
||||
sf, nz, rt = bits(w, 31, 1), bits(w, 24, 1), bits(w, 0, 5)
|
||||
t = pc + sext(bits(w, 5, 19), 19) * 4
|
||||
return Insn('bcond', target=t, cond=f'{R(sf, rt)} {"!=" if nz else "=="} 0')
|
||||
if bits(w, 25, 6) == 0b011011: # TBZ/TBNZ
|
||||
b = (bits(w, 31, 1) << 5) | bits(w, 19, 5)
|
||||
nz, rt = bits(w, 24, 1), bits(w, 0, 5)
|
||||
t = pc + sext(bits(w, 5, 14), 14) * 4
|
||||
return Insn('bcond', target=t, cond=f'(({X(rt)} >> {b}) & 1) {"!=" if nz else "=="} 0')
|
||||
if bits(w, 25, 7) == 0b1101011: # branch register
|
||||
opc, rn = bits(w, 21, 4), bits(w, 5, 5)
|
||||
if bits(w, 16, 5) != 31 or bits(w, 10, 6) or bits(w, 0, 5):
|
||||
raise Unsupported('branch reg variant')
|
||||
if opc == 0:
|
||||
return Insn('br', target=X(rn))
|
||||
if opc == 1:
|
||||
return Insn('blr', target=X(rn))
|
||||
if opc == 2:
|
||||
return Insn('ret')
|
||||
raise Unsupported('branch reg opc')
|
||||
if bits(w, 24, 8) == 0b11010100: # exception generation
|
||||
opc, ll, imm = bits(w, 21, 3), bits(w, 0, 5), bits(w, 5, 16)
|
||||
if opc == 0 and ll == 1:
|
||||
return Insn('op', f'rt_svc(c, {imm}, {hx(pc)});')
|
||||
if opc == 1 and ll == 0:
|
||||
return Insn('trap', f'rt_brk(c, {imm}, {hx(pc)});')
|
||||
raise Unsupported('exception')
|
||||
if bits(w, 22, 10) == 0b1101010100:
|
||||
return self.system(w, pc)
|
||||
raise Unsupported(f'branch_sys {w:08x}')
|
||||
|
||||
def system(self, w, pc):
|
||||
L = bits(w, 21, 1)
|
||||
op0, op1, crn, crm, op2, rt = (bits(w, 19, 2), bits(w, 16, 3), bits(w, 12, 4),
|
||||
bits(w, 8, 4), bits(w, 5, 3), bits(w, 0, 5))
|
||||
if op0 == 0 and not L:
|
||||
if crn == 2 and op1 == 3 and rt == 31: # hints
|
||||
return Insn('op', '/* hint */')
|
||||
if crn == 3 and op1 == 3 and rt == 31: # barriers
|
||||
if op2 == 2:
|
||||
return Insn('op', 'c->excl_addr = ~0ull;')
|
||||
return Insn('op', '__atomic_thread_fence(__ATOMIC_SEQ_CST);')
|
||||
raise Unsupported(f'pstate/system {w:08x}')
|
||||
if op0 == 1: # SYS
|
||||
if not L and op1 == 3 and crn == 7 and crm == 4 and op2 == 1: # DC ZVA
|
||||
return Insn('op', f'memset((void*)(uintptr_t)({X(rt)} & ~63ull), 0, 64);')
|
||||
return Insn('op', '/* cache maintenance */')
|
||||
key = (op0, op1, crn, crm, op2)
|
||||
if L: # MRS
|
||||
src = {
|
||||
(3, 3, 13, 0, 3): 'c->tpidrro',
|
||||
(3, 3, 13, 0, 2): 'c->tpidr',
|
||||
(3, 3, 14, 0, 0): '19200000ull',
|
||||
(3, 3, 14, 0, 1): 'rt_ticks()',
|
||||
(3, 3, 14, 0, 2): 'rt_ticks()',
|
||||
(3, 3, 4, 2, 0): 'c->nzcv',
|
||||
(3, 3, 4, 4, 0): 'c->fpcr' if self.sc else 'rt_get_fpcr()',
|
||||
(3, 3, 4, 4, 1): 'c->fpsr' if self.sc else 'rt_get_fpsr()',
|
||||
(3, 3, 0, 0, 7): '4ull',
|
||||
(3, 3, 0, 0, 1): '0x8444c004ull',
|
||||
}.get(key)
|
||||
if src is None:
|
||||
raise Unsupported(f'mrs {key}')
|
||||
return Insn('op', set_reg(1, rt, src))
|
||||
dst = {
|
||||
(3, 3, 13, 0, 2): 'c->tpidr = {v};',
|
||||
(3, 3, 4, 2, 0): 'c->nzcv = {v} & 0xf0000000ull;',
|
||||
(3, 3, 4, 4, 0): 'c->fpcr = {v} & 0x7c00000ull; rt_fpcr_sync(c);' if self.sc else 'rt_set_fpcr({v});',
|
||||
(3, 3, 4, 4, 1): 'c->fpsr = {v} & 0xf800009full;' if self.sc else 'rt_set_fpsr({v});',
|
||||
}.get(key)
|
||||
if dst is None:
|
||||
raise Unsupported(f'msr {key}')
|
||||
return Insn('op', dst.format(v=X(rt)))
|
||||
|
||||
# ------------------------------------------------------------ loads / stores
|
||||
|
||||
def ldst(self, w, pc):
|
||||
V = bits(w, 26, 1)
|
||||
if V:
|
||||
if self.sc:
|
||||
return Insn('op', self.sc.ldst(w, pc))
|
||||
return self.ldst_simd(w, pc)
|
||||
if bits(w, 24, 6) == 0b001000:
|
||||
return self.ldst_excl(w, pc)
|
||||
if bits(w, 27, 3) == 0b011 and bits(w, 24, 2) == 0: # literal
|
||||
opc, rt = bits(w, 30, 2), bits(w, 0, 5)
|
||||
addr = pc + sext(bits(w, 5, 19), 19) * 4
|
||||
if opc == 0:
|
||||
return Insn('op', set_reg(0, rt, f'LD32({hx(addr)})'))
|
||||
if opc == 1:
|
||||
return Insn('op', set_reg(1, rt, f'LD64({hx(addr)})'))
|
||||
if opc == 2:
|
||||
return Insn('op', set_reg(1, rt, f'(int64_t)(int32_t)LD32({hx(addr)})'))
|
||||
return Insn('op', '/* prfm */')
|
||||
if bits(w, 27, 3) == 0b101:
|
||||
return self.ldst_pair(w)
|
||||
if bits(w, 27, 3) == 0b111:
|
||||
return self.ldst_reg(w)
|
||||
if (w & 0xFFE00000) == 0xD9200000 and bits(w, 10, 2):
|
||||
return self.stg(w)
|
||||
raise Unsupported(f'ldst {w:08x}')
|
||||
|
||||
def stg(self, w):
|
||||
"""STG (post-index, signed offset, pre-index). Horizon runs without MTE, so storing an allocation tag
|
||||
changes no memory; only the base writeback remains (1.4.3 sdk+0x640050)."""
|
||||
mode, rn = bits(w, 10, 2), bits(w, 5, 5)
|
||||
if mode == 2:
|
||||
return Insn('op', '/* stg */')
|
||||
off = sext(bits(w, 12, 9), 9) << 4
|
||||
dst = 'c->sp' if rn == 31 else f'c->x[{rn}]'
|
||||
return Insn('op', f'{dst} = {XS(rn)} + {hx(off & 0xFFFFFFFFFFFFFFFF)}; /* stg */')
|
||||
|
||||
def ldst_excl(self, w, pc):
|
||||
size, o2, L, o1, rs, o0, rn, rt = (bits(w, 30, 2), bits(w, 23, 1), bits(w, 22, 1), bits(w, 21, 1),
|
||||
bits(w, 16, 5), bits(w, 15, 1), bits(w, 5, 5), bits(w, 0, 5))
|
||||
nbits = 8 << size
|
||||
addr = XS(rn)
|
||||
if o1:
|
||||
if o2:
|
||||
return self.cas(size, rs, rt, addr)
|
||||
if bits(w, 31, 1):
|
||||
return self.excl_pair(bits(w, 30, 1), L, rs, bits(w, 10, 5), rt, addr)
|
||||
return self.casp(bits(w, 30, 1), rs, rt, addr)
|
||||
if o2 == 0:
|
||||
if L:
|
||||
return Insn('op', set_reg(1, rt, f'ldx{nbits}(c, {addr})'))
|
||||
return Insn('op', f'{{ uint32_t st = stx{nbits}(c, {addr}, {X(rt)}); {set_reg(0, rs, "st")} }}')
|
||||
if L:
|
||||
return Insn('op', set_reg(1, rt, f'lda{nbits}({addr})'))
|
||||
return Insn('op', f'stl{nbits}({addr}, {X(rt)});')
|
||||
|
||||
def excl_pair(self, sz, L, rs, rt2, rt, addr):
|
||||
"""LDXP/LDAXP/STXP/STLXP. Two W registers form one 64-bit exclusive, two X registers one 128-bit."""
|
||||
if L:
|
||||
if sz:
|
||||
return Insn('op', f'{{ __uint128_t p = ldxp128(c, {addr}); '
|
||||
f'{set_reg(1, rt, "(uint64_t)p")} {set_reg(1, rt2, "(uint64_t)(p >> 64)")} }}')
|
||||
return Insn('op', f'{{ uint64_t p = ldx64(c, {addr}); '
|
||||
f'{set_reg(0, rt, "p")} {set_reg(0, rt2, "p >> 32")} }}')
|
||||
if sz:
|
||||
st = f'stxp128(c, {addr}, {X(rt)}, {X(rt2)})'
|
||||
else:
|
||||
st = f'stx64(c, {addr}, (uint64_t){W(rt)} | ((uint64_t){W(rt2)} << 32))'
|
||||
return Insn('op', f'{{ uint32_t st = {st}; {set_reg(0, rs, "st")} }}')
|
||||
|
||||
def cas(self, size, rs, rt, addr):
|
||||
"""CAS{A}{L}{B,H}: Rs is the compare value and receives the old memory value."""
|
||||
t = f'uint{8 << size}_t'
|
||||
return Insn('op', f'{{ {t} e = ({t}){X(rs)}; __atomic_compare_exchange_n(({t} *)(uintptr_t)({addr}), &e, '
|
||||
f'({t}){X(rt)}, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); {set_reg(size == 3, rs, "e")} }}')
|
||||
|
||||
def casp(self, sz, rs, rt, addr):
|
||||
"""CASP{A}{L}: register pairs (Rs, Rs+1) compared and (Rt, Rt+1) stored as one 64- or 128-bit access."""
|
||||
if rs & 1 or rt & 1:
|
||||
raise Unsupported('casp odd register')
|
||||
if sz:
|
||||
t = '__uint128_t'
|
||||
e = f'(({t}){X(rs + 1)} << 64) | {X(rs)}'
|
||||
v = f'(({t}){X(rt + 1)} << 64) | {X(rt)}'
|
||||
lo, hi = set_reg(1, rs, '(uint64_t)e'), set_reg(1, rs + 1, '(uint64_t)(e >> 64)')
|
||||
else:
|
||||
t = 'uint64_t'
|
||||
e = f'(uint64_t){W(rs)} | ((uint64_t){W(rs + 1)} << 32)'
|
||||
v = f'(uint64_t){W(rt)} | ((uint64_t){W(rt + 1)} << 32)'
|
||||
lo, hi = set_reg(0, rs, 'e'), set_reg(0, rs + 1, 'e >> 32')
|
||||
return Insn('op', f'{{ {t} e = {e}; __atomic_compare_exchange_n(({t} *)(uintptr_t)({addr}), &e, {v}, 0, '
|
||||
f'__ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); {lo} {hi} }}')
|
||||
|
||||
def atomic(self, w):
|
||||
"""LSE LD<op>{A}{L}{B,H} and SWP{A}{L}{B,H}: Rt receives the old memory value, Rs is the operand."""
|
||||
size, A, R, rs, o3, opc, rn, rt = (bits(w, 30, 2), bits(w, 23, 1), bits(w, 22, 1), bits(w, 16, 5),
|
||||
bits(w, 15, 1), bits(w, 12, 3), bits(w, 5, 5), bits(w, 0, 5))
|
||||
nbits = 8 << size
|
||||
t = f'uint{nbits}_t'
|
||||
p, v = f'({t} *)(uintptr_t)({XS(rn)})', f'({t}){X(rs)}'
|
||||
order = ('__ATOMIC_RELAXED', '__ATOMIC_RELEASE', '__ATOMIC_ACQUIRE', '__ATOMIC_ACQ_REL')[A << 1 | R]
|
||||
if o3:
|
||||
if opc:
|
||||
raise Unsupported('ldapr')
|
||||
expr = f'__atomic_exchange_n({p}, {v}, {order})'
|
||||
elif opc < 4:
|
||||
fn, operand = (('add', v), ('and', f'({t})~{X(rs)}'), ('xor', v), ('or', v))[opc]
|
||||
expr = f'__atomic_fetch_{fn}({p}, {operand}, {order})'
|
||||
else:
|
||||
fn = ('smax', 'smin', 'umax', 'umin')[opc - 4]
|
||||
expr = f'atomic_{fn}{nbits}({XS(rn)}, {v})'
|
||||
return Insn('op', set_reg(size == 3, rt, expr))
|
||||
|
||||
def ldst_pair(self, w):
|
||||
opc, mode, L = bits(w, 30, 2), bits(w, 23, 2), bits(w, 22, 1)
|
||||
imm7, rt2, rn, rt = sext(bits(w, 15, 7), 7), bits(w, 10, 5), bits(w, 5, 5), bits(w, 0, 5)
|
||||
if opc == 3:
|
||||
raise Unsupported('pair opc 3')
|
||||
scale = 3 if opc == 2 else 2
|
||||
off = imm7 << scale
|
||||
base = XS(rn)
|
||||
post = mode == 1
|
||||
wb = mode in (1, 3)
|
||||
ea = base if post else (f'{base} + {off}' if off >= 0 else f'{base} - {-off}')
|
||||
lines = [f'uint64_t ea = {ea};']
|
||||
if L:
|
||||
if opc == 2:
|
||||
lines.append('uint64_t a = LD64(ea), b = LD64(ea + 8);')
|
||||
elif opc == 1: # LDPSW
|
||||
lines.append('uint64_t a = (int64_t)(int32_t)LD32(ea), b = (int64_t)(int32_t)LD32(ea + 4);')
|
||||
else:
|
||||
lines.append('uint64_t a = LD32(ea), b = LD32(ea + 4);')
|
||||
else:
|
||||
if opc == 2:
|
||||
lines.append(f'ST64(ea, {X(rt)}); ST64(ea + 8, {X(rt2)});')
|
||||
else:
|
||||
lines.append(f'ST32(ea, {W(rt)}); ST32(ea + 4, {W(rt2)});')
|
||||
if wb:
|
||||
dst = 'c->sp' if rn == 31 else f'c->x[{rn}]'
|
||||
if not post:
|
||||
lines.append(f'{dst} = ea;')
|
||||
else:
|
||||
lines.append(f'{dst} = ea + {off};' if off >= 0 else f'{dst} = ea - {-off};')
|
||||
if L:
|
||||
lines.append(set_reg(1, rt, 'a'))
|
||||
lines.append(set_reg(1, rt2, 'b'))
|
||||
return Insn('op', '{ ' + ' '.join(lines) + ' }')
|
||||
|
||||
def ldst_reg(self, w):
|
||||
size, opc, rn, rt = bits(w, 30, 2), bits(w, 22, 2), bits(w, 5, 5), bits(w, 0, 5)
|
||||
base = XS(rn)
|
||||
wb = None
|
||||
if bits(w, 24, 2) == 1:
|
||||
ea = f'{base} + {hx(bits(w, 10, 12) << size)}'
|
||||
else:
|
||||
kind = bits(w, 10, 2)
|
||||
if bits(w, 21, 1):
|
||||
if kind == 0:
|
||||
return self.atomic(w)
|
||||
if kind != 2:
|
||||
raise Unsupported('ldst reg pac')
|
||||
rm, option, S = bits(w, 16, 5), bits(w, 13, 3), bits(w, 12, 1)
|
||||
if option not in (2, 3, 6, 7):
|
||||
raise Unsupported('ldst reg option')
|
||||
ea = f'{base} + {extend_expr(rm, option, size if S else 0)}'
|
||||
else:
|
||||
imm9 = sext(bits(w, 12, 9), 9)
|
||||
sign_imm = f'+ {imm9}' if imm9 >= 0 else f'- {-imm9}'
|
||||
if kind in (0, 2): # unscaled, unprivileged
|
||||
ea = f'{base} {sign_imm}'
|
||||
elif kind == 1: # post
|
||||
ea = base
|
||||
wb = f'{base} {sign_imm}'
|
||||
else: # pre
|
||||
ea = f'{base} {sign_imm}'
|
||||
wb = 'ea'
|
||||
nbits = 8 << size
|
||||
if opc == 0:
|
||||
parts = [f'ST{nbits}(ea, {X(rt) if size == 3 else W(rt)});']
|
||||
load = None
|
||||
elif opc == 1:
|
||||
parts = [f'uint64_t v = LD{nbits}(ea);']
|
||||
load = set_reg(1, rt, 'v')
|
||||
elif size == 3:
|
||||
return Insn('op', '/* prfm */')
|
||||
elif size == 2 and opc == 3:
|
||||
raise Unsupported('ldst size2 opc3')
|
||||
else:
|
||||
parts = [f'uint64_t v = (uint64_t)(int64_t)(int{nbits}_t)LD{nbits}(ea);']
|
||||
load = set_reg(1 if opc == 2 else 0, rt, 'v')
|
||||
parts.insert(0, f'uint64_t ea = {ea};')
|
||||
if wb:
|
||||
# writeback before the register load, so a load into rn wins
|
||||
parts.append(f'{"c->sp" if rn == 31 else f"c->x[{rn}]"} = {wb};')
|
||||
if load:
|
||||
parts.append(load)
|
||||
return Insn('op', '{ ' + ' '.join(parts) + ' }')
|
||||
|
||||
def ldst_simd(self, w, pc):
|
||||
"""FP/SIMD loads and stores are passed through as asm; GPR address regs are remapped."""
|
||||
rt = bits(w, 0, 5)
|
||||
if bits(w, 27, 3) == 0b011 and bits(w, 24, 2) == 0: # literal -> LDR (imm, offset 0) via scratch
|
||||
opc = bits(w, 30, 2)
|
||||
size, o = {0: (2, 1), 1: (3, 1), 2: (0, 3)}[opc]
|
||||
addr = pc + sext(bits(w, 5, 19), 19) * 4
|
||||
new = (size << 30) | 0x3D000000 | (o << 22) | (31 << 5) | rt
|
||||
return Insn('asm', asm=AsmInsn(new, {rt}, [], consts=[(5, addr)]))
|
||||
if bits(w, 31, 1) == 0 and bits(w, 24, 6) in (0b001100, 0b001101): # structures
|
||||
post = bits(w, 23, 1)
|
||||
rn, rm = bits(w, 5, 5), bits(w, 16, 5)
|
||||
if bits(w, 24, 1) == 0:
|
||||
n = {0: 4, 2: 4, 4: 3, 6: 3, 7: 1, 8: 2, 10: 2}.get(bits(w, 12, 4))
|
||||
if n is None:
|
||||
raise Unsupported('ldst multiple opcode')
|
||||
else:
|
||||
n = ((bits(w, 13, 1) << 1) | bits(w, 21, 1)) + 1
|
||||
vregs = {(rt + i) % 32 for i in range(n)}
|
||||
gprs = [(5, 'sp' if rn == 31 else rn)]
|
||||
if post and rm != 31:
|
||||
gprs.append((16, rm))
|
||||
return Insn('asm', asm=AsmInsn(w, vregs, gprs))
|
||||
rn = bits(w, 5, 5)
|
||||
gprs = [(5, 'sp' if rn == 31 else rn)]
|
||||
vregs = {rt}
|
||||
if bits(w, 27, 3) == 0b101: # pair
|
||||
vregs.add(bits(w, 10, 5))
|
||||
elif bits(w, 27, 3) == 0b111 and bits(w, 24, 2) == 0 and bits(w, 21, 1) and bits(w, 10, 2) == 2:
|
||||
rm = bits(w, 16, 5)
|
||||
if rm != 31:
|
||||
gprs.append((16, rm))
|
||||
return Insn('asm', asm=AsmInsn(w, vregs, gprs))
|
||||
|
||||
# ------------------------------------------------------------ data processing (reg)
|
||||
|
||||
def dp_reg(self, w, pc):
|
||||
sf = bits(w, 31, 1)
|
||||
rd, rn, rm = bits(w, 0, 5), bits(w, 5, 5), bits(w, 16, 5)
|
||||
size = 64 if sf else 32
|
||||
op1 = bits(w, 28, 1)
|
||||
if not op1:
|
||||
if bits(w, 24, 4) == 0b1010: # logical shifted
|
||||
opc, sh, N, amt = bits(w, 29, 2), bits(w, 22, 2), bits(w, 21, 1), bits(w, 10, 6)
|
||||
if not sf and amt >= 32:
|
||||
raise Unsupported('logical shift amount')
|
||||
b = shift_expr(sf, R(sf, rm), sh, amt)
|
||||
if N:
|
||||
b = f'(uint{size}_t)~{b}'
|
||||
a = R(sf, rn)
|
||||
expr = {0: f'{a} & {b}', 1: f'{a} | {b}', 2: f'{a} ^ {b}', 3: f'{a} & {b}'}[opc]
|
||||
if opc == 3:
|
||||
return Insn('op', set_reg(sf, rd, f'logic{size}(c, (uint{size}_t)({expr}))'))
|
||||
return Insn('op', set_reg(sf, rd, expr))
|
||||
if bits(w, 24, 4) == 0b1011: # add/sub shifted or extended
|
||||
op, S = bits(w, 30, 1), bits(w, 29, 1)
|
||||
if bits(w, 21, 1) == 0:
|
||||
sh, amt = bits(w, 22, 2), bits(w, 10, 6)
|
||||
if sh == 3:
|
||||
raise Unsupported('add shift ror')
|
||||
a = R(sf, rn)
|
||||
b = shift_expr(sf, R(sf, rm), sh, amt)
|
||||
sp_ok = False
|
||||
else:
|
||||
if bits(w, 22, 2):
|
||||
raise Unsupported('add ext opt')
|
||||
option, amt = bits(w, 13, 3), bits(w, 10, 3)
|
||||
a = R(sf, rn, sp=True)
|
||||
b = extend_expr(rm, option, amt)
|
||||
if not sf:
|
||||
b = f'(uint32_t)({b})'
|
||||
sp_ok = not S
|
||||
if S:
|
||||
fn = ('subs' if op else 'adds') + str(size)
|
||||
return Insn('op', set_reg(sf, rd, f'{fn}(c, {a}, (uint{size}_t)({b}))'))
|
||||
return Insn('op', set_reg(sf, rd, f'{a} {"-" if op else "+"} {b}', sp=sp_ok))
|
||||
raise Unsupported(f'dp_reg {w:08x}')
|
||||
op2 = bits(w, 21, 4)
|
||||
if bits(w, 24, 4) == 0b1011: # 3-source
|
||||
op54, op31, o0, ra = bits(w, 29, 2), bits(w, 21, 3), bits(w, 15, 1), bits(w, 10, 5)
|
||||
if op54:
|
||||
raise Unsupported('dp3 op54')
|
||||
sgn = '-' if o0 else '+'
|
||||
if op31 == 0:
|
||||
return Insn('op', set_reg(sf, rd, f'{R(sf, ra)} {sgn} {R(sf, rn)} * {R(sf, rm)}'))
|
||||
if op31 == 1:
|
||||
return Insn('op', set_reg(1, rd, f'{X(ra)} {sgn} (uint64_t)((int64_t)(int32_t){W(rn)} * (int64_t)(int32_t){W(rm)})'))
|
||||
if op31 == 5:
|
||||
return Insn('op', set_reg(1, rd, f'{X(ra)} {sgn} (uint64_t){W(rn)} * (uint64_t){W(rm)}'))
|
||||
if op31 == 2:
|
||||
return Insn('op', set_reg(
|
||||
1, rd, f'(uint64_t)(((__int128)(int64_t){X(rn)} * (__int128)(int64_t){X(rm)}) >> 64)'))
|
||||
if op31 == 6:
|
||||
return Insn('op', set_reg(1, rd, f'(uint64_t)(((unsigned __int128){X(rn)} * {X(rm)}) >> 64)'))
|
||||
raise Unsupported('dp3')
|
||||
if op2 == 0: # add/sub with carry
|
||||
op, S = bits(w, 30, 1), bits(w, 29, 1)
|
||||
fn = ('sbc' if op else 'adc') + ('s' if S else '') + str(size)
|
||||
return Insn('op', set_reg(sf, rd, f'{fn}(c, {R(sf, rn)}, {R(sf, rm)})'))
|
||||
if op2 == 2: # conditional compare
|
||||
op, imm_form, cond, nzcv = bits(w, 30, 1), bits(w, 11, 1), bits(w, 12, 4), bits(w, 0, 4)
|
||||
b = hx(rm) if imm_form else R(sf, rm)
|
||||
fn = ('subs' if op else 'adds') + str(size)
|
||||
return Insn('op', f'if ({cond_expr(cond)}) (void){fn}(c, {R(sf, rn)}, {b}); '
|
||||
f'else c->nzcv = {hx(nzcv << 28)};')
|
||||
if op2 == 4: # conditional select
|
||||
op, o2, cond = bits(w, 30, 1), bits(w, 10, 2), bits(w, 12, 4)
|
||||
b = R(sf, rm)
|
||||
alt = {(0, 0): b, (0, 1): f'{b} + 1', (1, 0): f'~{b}', (1, 1): f'-{b}'}.get((op, o2))
|
||||
if alt is None:
|
||||
raise Unsupported('csel variant')
|
||||
return Insn('op', set_reg(sf, rd, f'({cond_expr(cond)}) ? {R(sf, rn)} : (uint{size}_t)({alt})'))
|
||||
if op2 == 6:
|
||||
opcode = bits(w, 10, 6)
|
||||
if bits(w, 30, 1): # 1-source
|
||||
if bits(w, 16, 5):
|
||||
raise Unsupported('dp1 opcode2')
|
||||
a = R(sf, rn)
|
||||
expr = {
|
||||
0: f'rbit{size}({a})',
|
||||
1: f'rev16_{size}({a})',
|
||||
2: f'__builtin_bswap32({a})' if not sf else f'rev32_64({a})',
|
||||
3: f'__builtin_bswap64({a})' if sf else None,
|
||||
4: f'clz{size}({a})',
|
||||
5: f'cls{size}({a})',
|
||||
}.get(opcode)
|
||||
if expr is None:
|
||||
raise Unsupported('dp1')
|
||||
return Insn('op', set_reg(sf, rd, expr))
|
||||
if 16 <= opcode <= 23: # CRC32: host has the same instruction
|
||||
if self.sc:
|
||||
return Insn('op', self.sc.crc(w))
|
||||
gprs = [(p, r) for p, r in ((0, rd), (5, rn), (16, rm)) if r != 31]
|
||||
return Insn('asm', asm=AsmInsn(w, set(), gprs))
|
||||
a, b = R(sf, rn), R(sf, rm)
|
||||
expr = {
|
||||
2: f'udiv{size}({a}, {b})',
|
||||
3: f'sdiv{size}({a}, {b})',
|
||||
8: f'{a} << ({b} & {size - 1})',
|
||||
9: f'{a} >> ({b} & {size - 1})',
|
||||
10: f'(uint{size}_t)((int{size}_t){a} >> ({b} & {size - 1}))',
|
||||
11: f'ROR{size}({a}, {b} & {size - 1})',
|
||||
}.get(opcode)
|
||||
if expr is None:
|
||||
raise Unsupported('dp2')
|
||||
return Insn('op', set_reg(sf, rd, expr))
|
||||
raise Unsupported(f'dp_reg {w:08x}')
|
||||
|
||||
# ------------------------------------------------------------ FP / SIMD data processing
|
||||
|
||||
def fp_simd(self, w, pc):
|
||||
if self.sc:
|
||||
return Insn('op', self.sc.dp(w, pc))
|
||||
rd, rn, rm, ra = bits(w, 0, 5), bits(w, 5, 5), bits(w, 16, 5), bits(w, 10, 5)
|
||||
vregs = {rd, rn, rm, ra}
|
||||
gprs = []
|
||||
flags = False
|
||||
if (w & 0x5F20FC00) == 0x1E200000: # FP <-> integer
|
||||
opcode = bits(w, 16, 3)
|
||||
if opcode in (0, 1, 4, 5, 6):
|
||||
gprs = [(0, rd)]
|
||||
vregs = {rn}
|
||||
else:
|
||||
gprs = [(5, rn)]
|
||||
vregs = {rd}
|
||||
elif (w & 0x5F200000) == 0x1E000000: # FP <-> fixed point
|
||||
opcode = bits(w, 16, 3)
|
||||
if opcode in (0, 1):
|
||||
gprs = [(0, rd)]
|
||||
vregs = {rn}
|
||||
else:
|
||||
gprs = [(5, rn)]
|
||||
vregs = {rd}
|
||||
elif (w & 0x9FE08400) == 0x0E000400 and bits(w, 29, 1) == 0: # AdvSIMD copy
|
||||
imm4 = bits(w, 11, 4)
|
||||
if imm4 in (1, 3):
|
||||
gprs = [(5, rn)]
|
||||
vregs = {rd}
|
||||
elif imm4 in (5, 7):
|
||||
gprs = [(0, rd)]
|
||||
vregs = {rn}
|
||||
else:
|
||||
vregs = {rd, rn}
|
||||
elif (w & 0xBFE08C00) == 0x0E000000: # TBL/TBX
|
||||
n = bits(w, 13, 2) + 1
|
||||
vregs = {rd, rm} | {(rn + i) % 32 for i in range(n)}
|
||||
if (w & 0x5F203C00) == 0x1E202000 or (w & 0x5F200C00) in (0x1E200400, 0x1E200C00):
|
||||
flags = True
|
||||
gprs = [(p, r) for p, r in gprs if r != 31] # register 31 is zr in these encodings
|
||||
return Insn('asm', asm=AsmInsn(w, vregs, gprs, flags))
|
||||
|
||||
|
||||
def cond_expr(cond):
|
||||
return f'COND_{COND_NAMES[cond].upper()}(c)' if cond < 14 else '1'
|
||||
|
||||
|
||||
def emit_asm_batch(batch):
|
||||
"""Emit one inline-asm block for a run of FP/SIMD instructions."""
|
||||
vregs = set()
|
||||
gmap = {}
|
||||
flags = False
|
||||
consts = []
|
||||
words = []
|
||||
for a in batch:
|
||||
vregs |= a.vregs
|
||||
flags |= a.flags
|
||||
w = a.word
|
||||
for pos, g in a.gprs:
|
||||
if g not in gmap:
|
||||
if len(gmap) + len(consts) >= len(SCRATCH):
|
||||
raise Unsupported('scratch exhausted')
|
||||
gmap[g] = SCRATCH[len(gmap) + len(consts)]
|
||||
w = (w & ~(31 << pos)) | (gmap[g] << pos)
|
||||
for pos, val in a.consts:
|
||||
s = SCRATCH[len(gmap) + len(consts)]
|
||||
consts.append((s, val))
|
||||
w = (w & ~(31 << pos)) | (s << pos)
|
||||
words.append(w)
|
||||
lines = []
|
||||
ins = ['"r"(c)']
|
||||
for g, s in gmap.items():
|
||||
off = OFF_SP if g == 'sp' else OFF_X + 8 * g
|
||||
lines.append(f'ldr x{s}, [%0, #{off}]')
|
||||
for i, (s, val) in enumerate(consts):
|
||||
ins.append(f'"r"({hx(val)})')
|
||||
lines.append(f'mov x{s}, %{len(ins) - 1}')
|
||||
for v in sorted(vregs):
|
||||
lines.append(f'ldr q{v}, [%0, #{OFF_V + 16 * v}]')
|
||||
if flags:
|
||||
lines.append(f'ldr x16, [%0, #{OFF_NZCV}]')
|
||||
lines.append('msr nzcv, x16')
|
||||
lines += [f'.inst 0x{x:08x}' for x in words]
|
||||
if flags:
|
||||
lines.append('mrs x16, nzcv')
|
||||
lines.append(f'str x16, [%0, #{OFF_NZCV}]')
|
||||
for v in sorted(vregs):
|
||||
lines.append(f'str q{v}, [%0, #{OFF_V + 16 * v}]')
|
||||
for g, s in gmap.items():
|
||||
off = OFF_SP if g == 'sp' else OFF_X + 8 * g
|
||||
lines.append(f'str x{s}, [%0, #{off}]')
|
||||
clob = [f'"v{v}"' for v in sorted(vregs)]
|
||||
clob += [f'"x{s}"' for s in sorted(set(gmap.values()) | {s for s, _ in consts} | ({16} if flags else set()))]
|
||||
clob += ['"cc"', '"memory"']
|
||||
body = '\\n\\t'.join(lines)
|
||||
return f'__asm__ volatile("{body}" :: {", ".join(ins)} : {", ".join(clob)});'
|
||||
112
recomp/module.py
Normal file
112
recomp/module.py
Normal file
@@ -0,0 +1,112 @@
|
||||
"""One loaded NSO module as the generator and its analyses see it: image at a guest base, .text as words,
|
||||
function seeds, and bounded-cache instruction lifting.
|
||||
|
||||
The function seeds and the .eh_frame_hdr reader are adapted from LAS Recomp tools/analyze.py and tools/gen.py
|
||||
@ da35b83 (MIT, Copyright (c) 2026 Peiikai).
|
||||
"""
|
||||
import struct
|
||||
from collections import OrderedDict
|
||||
|
||||
import numpy as np
|
||||
|
||||
from lifter import Insn, Lifter, Unsupported, hx
|
||||
from nso import Nso, R_AARCH64_RELATIVE
|
||||
|
||||
LIFT_CACHE = 1 << 16 # lifted instructions kept per module; analyses revisit nearby addresses only
|
||||
|
||||
|
||||
def _read_encoded(img, off, enc, pc_base):
|
||||
fmt, app = enc & 0x0F, enc & 0x70
|
||||
if fmt == 0x0B: # sdata4
|
||||
v, size = struct.unpack_from('<i', img, off)[0], 4
|
||||
elif fmt == 0x03: # udata4
|
||||
v, size = struct.unpack_from('<I', img, off)[0], 4
|
||||
elif fmt in (0x0C, 0x04): # sdata8, udata8
|
||||
v, size = struct.unpack_from('<q' if fmt == 0x0C else '<Q', img, off)[0], 8
|
||||
else:
|
||||
raise ValueError(f'unsupported pointer encoding {enc:#x}')
|
||||
if app == 0x10: # pcrel
|
||||
v += off
|
||||
elif app == 0x30: # datarel
|
||||
v += pc_base
|
||||
return v, size
|
||||
|
||||
|
||||
class Module:
|
||||
def __init__(self, name, path, base, simd='c'):
|
||||
self.name = name
|
||||
self.nso = Nso(str(path))
|
||||
self.base = base
|
||||
n = self.nso
|
||||
self.image = bytes(n.image)
|
||||
self.lo = base + n.text[0]
|
||||
self.hi = self.lo + n.text[1]
|
||||
self.words = np.frombuffer(self.image, dtype='<u4', count=n.text[1] // 4, offset=n.text[0])
|
||||
self.lifter = Lifter(base, simd)
|
||||
self._cache = OrderedDict()
|
||||
|
||||
# ---- memory
|
||||
|
||||
def in_text(self, a):
|
||||
return self.lo <= a < self.hi and a % 4 == 0
|
||||
|
||||
def in_image(self, a, n=1):
|
||||
return self.base <= a and a + n <= self.base + len(self.image)
|
||||
|
||||
def word(self, a):
|
||||
return int(self.words[(a - self.lo) >> 2])
|
||||
|
||||
def read(self, a, n, signed=False):
|
||||
"""Little-endian integer of n bytes at guest address a (unrelocated image)."""
|
||||
o = a - self.base
|
||||
return int.from_bytes(self.image[o:o + n], 'little', signed=signed)
|
||||
|
||||
# ---- lifting
|
||||
|
||||
def lift(self, a):
|
||||
"""Lifted instruction at a; Unsupported becomes an rt_udf trap."""
|
||||
ins = self._cache.get(a)
|
||||
if ins is not None:
|
||||
self._cache.move_to_end(a)
|
||||
return ins
|
||||
try:
|
||||
ins = self.lifter.lift(self.word(a), a)
|
||||
except Unsupported as e:
|
||||
ins = Insn('trap', f'rt_udf(c, {hx(a)}); /* {e} */')
|
||||
self._cache[a] = ins
|
||||
if len(self._cache) > LIFT_CACHE:
|
||||
self._cache.popitem(last=False)
|
||||
return ins
|
||||
|
||||
# ---- function seeds
|
||||
|
||||
def eh_frame_functions(self):
|
||||
"""Function starts from .eh_frame_hdr's binary search table (absolute addresses)."""
|
||||
img, hdr = self.image, self.nso.eh_start
|
||||
if not hdr or hdr >= len(img):
|
||||
return []
|
||||
_, ptr_enc, cnt_enc, tbl_enc = img[hdr:hdr + 4]
|
||||
off = hdr + 4
|
||||
_, sz = _read_encoded(img, off, ptr_enc, hdr)
|
||||
off += sz
|
||||
count, sz = _read_encoded(img, off, cnt_enc, hdr)
|
||||
off += sz
|
||||
starts = []
|
||||
for _ in range(count):
|
||||
loc, sz = _read_encoded(img, off, tbl_enc, hdr)
|
||||
off += sz
|
||||
_, sz = _read_encoded(img, off, tbl_enc, hdr)
|
||||
off += sz
|
||||
starts.append(self.base + loc)
|
||||
return starts
|
||||
|
||||
def seeds(self):
|
||||
"""Known function starts: .eh_frame_hdr, exported FUNC symbols, R_AARCH64_RELATIVE targets in .text."""
|
||||
starts = set(self.eh_frame_functions())
|
||||
for _, info, shndx, value, _ in self.nso.syms:
|
||||
if shndx and (info & 0xF) == 2:
|
||||
starts.add(self.base + value)
|
||||
for _, typ, _, add in self.nso.relocs:
|
||||
if typ == R_AARCH64_RELATIVE:
|
||||
starts.add(self.base + add)
|
||||
return sorted(a for a in starts if self.in_text(a))
|
||||
134
recomp/nso.py
Normal file
134
recomp/nso.py
Normal file
@@ -0,0 +1,134 @@
|
||||
# Adapted from LAS Recomp tools/nso.py @ da35b83 (MIT, Copyright (c) 2026 Peiikai).
|
||||
"""NSO loader: decompress segments, build the memory image, parse MOD0/dynamic info."""
|
||||
import struct
|
||||
import sys
|
||||
from collections import Counter
|
||||
|
||||
import lz4.block
|
||||
|
||||
DT_NULL, DT_NEEDED, DT_PLTRELSZ, DT_HASH, DT_STRTAB, DT_SYMTAB, DT_RELA, DT_RELASZ = 0, 1, 2, 4, 5, 6, 7, 8
|
||||
DT_STRSZ, DT_JMPREL, DT_RELACOUNT = 10, 23, 0x6FFFFFF9
|
||||
DT_RELRSZ, DT_RELR, DT_GNU_HASH = 0x23, 0x24, 0x6FFFFEF5
|
||||
R_AARCH64_ABS64, R_AARCH64_GLOB_DAT, R_AARCH64_JUMP_SLOT, R_AARCH64_RELATIVE = 257, 1025, 1026, 1027
|
||||
|
||||
|
||||
class Nso:
|
||||
def __init__(self, path):
|
||||
raw = open(path, 'rb').read()
|
||||
assert raw[:4] == b'NSO0', path
|
||||
flags = struct.unpack_from('<I', raw, 0xC)[0]
|
||||
self.build_id = raw[0x40:0x60].rstrip(b'\0').hex()
|
||||
segs = []
|
||||
for i in range(3):
|
||||
file_off, mem_off, dec_size = struct.unpack_from('<III', raw, 0x10 + i * 0x10)
|
||||
comp_size = struct.unpack_from('<I', raw, 0x60 + i * 4)[0]
|
||||
data = raw[file_off:file_off + comp_size]
|
||||
if flags & (1 << i):
|
||||
data = lz4.block.decompress(data, uncompressed_size=dec_size)
|
||||
segs.append((mem_off, data))
|
||||
self.bss_size = struct.unpack_from('<I', raw, 0x3C)[0]
|
||||
self.text = (segs[0][0], len(segs[0][1]))
|
||||
self.rodata = (segs[1][0], len(segs[1][1]))
|
||||
self.data = (segs[2][0], len(segs[2][1]))
|
||||
end = segs[2][0] + len(segs[2][1]) + self.bss_size
|
||||
self.size = (end + 0xFFF) & ~0xFFF
|
||||
img = bytearray(self.size)
|
||||
for off, d in segs:
|
||||
img[off:off + len(d)] = d
|
||||
self.image = img
|
||||
self._parse_mod0()
|
||||
|
||||
def u32(self, off): return struct.unpack_from('<I', self.image, off)[0]
|
||||
def u64(self, off): return struct.unpack_from('<Q', self.image, off)[0]
|
||||
|
||||
def _parse_mod0(self):
|
||||
mod0 = self.u32(4)
|
||||
assert self.image[mod0:mod0 + 4] == b'MOD0'
|
||||
rel = lambda i: mod0 + struct.unpack_from('<i', self.image, mod0 + 4 + i * 4)[0]
|
||||
self.dynamic, self.bss_start, self.bss_end = rel(0), rel(1), rel(2)
|
||||
self.eh_start, self.eh_end, self.module_obj = rel(3), rel(4), rel(5)
|
||||
dyn = {}
|
||||
needed = []
|
||||
off = self.dynamic
|
||||
while True:
|
||||
tag, val = self.u64(off), self.u64(off + 8)
|
||||
off += 16
|
||||
if tag == DT_NULL:
|
||||
break
|
||||
if tag == DT_NEEDED:
|
||||
needed.append(val)
|
||||
dyn.setdefault(tag, val)
|
||||
self.dyn = dyn
|
||||
strtab = dyn.get(DT_STRTAB, 0)
|
||||
self.strtab = strtab
|
||||
self.needed = [self.cstr(strtab + n) for n in needed]
|
||||
# dynsym count from DT_HASH nchain, or from DT_GNU_HASH (1.4.3 sdk and subsdk0 have no DT_HASH)
|
||||
self.syms = []
|
||||
nsyms = self.symbol_count()
|
||||
if nsyms and DT_SYMTAB in dyn:
|
||||
st = dyn[DT_SYMTAB]
|
||||
for i in range(nsyms):
|
||||
o = st + i * 24
|
||||
name, info, other, shndx = struct.unpack_from('<IBBH', self.image, o)
|
||||
value, size = struct.unpack_from('<QQ', self.image, o + 8)
|
||||
self.syms.append((self.cstr(strtab + name), info, shndx, value, size))
|
||||
self.relocs = []
|
||||
for base_tag, size_tag in ((DT_RELA, DT_RELASZ), (DT_JMPREL, DT_PLTRELSZ)):
|
||||
if base_tag in dyn:
|
||||
b, n = dyn[base_tag], dyn[size_tag] // 24
|
||||
for i in range(n):
|
||||
r_off, r_info, r_add = struct.unpack_from('<QQq', self.image, b + i * 24)
|
||||
self.relocs.append((r_off, r_info & 0xFFFFFFFF, r_info >> 32, r_add))
|
||||
# DT_RELR (1.4.3): packed RELATIVE relocations whose addend is the word in place. An even entry is an address
|
||||
# (relocate it, continue after it); an odd entry is a bitmap of the next 63 words.
|
||||
if DT_RELR in dyn:
|
||||
where = 0
|
||||
for i in range(dyn[DT_RELRSZ] // 8):
|
||||
e = self.u64(dyn[DT_RELR] + i * 8)
|
||||
if e & 1 == 0:
|
||||
self.relocs.append((e, R_AARCH64_RELATIVE, 0, self.u64(e)))
|
||||
where = e + 8
|
||||
continue
|
||||
for k in range(63):
|
||||
if e >> (k + 1) & 1:
|
||||
a = where + k * 8
|
||||
self.relocs.append((a, R_AARCH64_RELATIVE, 0, self.u64(a)))
|
||||
where += 63 * 8
|
||||
|
||||
def symbol_count(self):
|
||||
"""Number of .dynsym entries: DT_HASH nchain, else one past the last symbol a DT_GNU_HASH chain reaches."""
|
||||
dyn = self.dyn
|
||||
if DT_HASH in dyn:
|
||||
return self.u32(dyn[DT_HASH] + 4)
|
||||
if DT_GNU_HASH not in dyn:
|
||||
return 0
|
||||
h = dyn[DT_GNU_HASH]
|
||||
nbuckets, symoffset, bloom_size = self.u32(h), self.u32(h + 4), self.u32(h + 8)
|
||||
buckets = h + 16 + bloom_size * 8
|
||||
last = max([self.u32(buckets + 4 * i) for i in range(nbuckets)] + [0])
|
||||
if last < symoffset:
|
||||
return symoffset
|
||||
chains = buckets + 4 * nbuckets
|
||||
while not self.u32(chains + 4 * (last - symoffset)) & 1:
|
||||
last += 1
|
||||
return last + 1
|
||||
|
||||
def cstr(self, off):
|
||||
end = self.image.index(b'\0', off)
|
||||
return self.image[off:end].decode('utf-8', 'replace')
|
||||
|
||||
def imports(self):
|
||||
return [s for s in self.syms if s[0] and s[2] == 0]
|
||||
|
||||
def exports(self):
|
||||
return [s for s in self.syms if s[0] and s[2] != 0]
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
for p in sys.argv[1:]:
|
||||
n = Nso(p)
|
||||
print(f'== {p} build {n.build_id[:16]} image 0x{n.size:x}')
|
||||
print(f' text 0x{n.text[0]:x}+0x{n.text[1]:x} ro 0x{n.rodata[0]:x}+0x{n.rodata[1]:x} '
|
||||
f'data 0x{n.data[0]:x}+0x{n.data[1]:x} bss 0x{n.bss_size:x}')
|
||||
print(f' needed {n.needed} syms {len(n.syms)} imports {len(n.imports())} exports {len(n.exports())}')
|
||||
print(f' relocs {dict(Counter(r[1] for r in n.relocs))}')
|
||||
957
recomp/patches-v110.txt
Normal file
957
recomp/patches-v110.txt
Normal file
@@ -0,0 +1,957 @@
|
||||
# Code patches for NX2navi 1.1.0 main (recomp/patches.py). The sites come from MacNativeGames
|
||||
# games/<game>/runtime/game_patches.c (MIT, Copyright (c) 2026 MacNativeGames contributors) at upstream ebe621d, through
|
||||
# its 1.2.1 addresses in game_version.h (2db612b); each one was located again in 1.1.0 by instruction-window matching
|
||||
# and its original words checked against this build's main. The patch page holds two floats the runtime writes at every
|
||||
# present (frame_rate.c): +0 the 30 Hz ratio (seconds * 30), +4 the frame step in seconds.
|
||||
|
||||
set fps60 NX2NAVI_FPS60 1
|
||||
set realtime NX2NAVI_REALTIME 1
|
||||
set cloth NX2NAVI_CLOTH_REALTIME 1
|
||||
set bounce NX2NAVI_HIGHFPS_FIX 1
|
||||
set output NX2NAVI_PATCH_OUTPUT 0
|
||||
set scene NX2NAVI_PATCH_SCENE 0
|
||||
|
||||
# 60 fps: the adaptive present-interval controller (main+0x8f26c8, 1.0.0 0x8f6bec) gets the minimum interval 1.
|
||||
site fps60 main 90e978 6b08015f 7100055f # clamp: cmp w10, #1 (was cmp w10, w8 = minimum)
|
||||
site fps60 main 90e97c 1a89b10a 1a9fa52a # clamp: csinc w10, w9, wzr, ge (desired = max(desired, 1))
|
||||
site fps60 main 90e9a0 b9401a8a d503201f # lower trigger: nop the stored-candidate load
|
||||
site fps60 main 90ea30 6b08015f 7100055f # raise path: cmp w10, #1
|
||||
site fps60 main 90ea40 1a88c1ac 1a9fc5ac # raise path: csinc w12, w13, wzr, gt (next lower candidate floors at 1)
|
||||
site fps60 main 90ea94 b9400288 52800028 # lower path: mov w8, #1 (minimum interval 1)
|
||||
site fps60 main 90eab0 2a0a03f5 1a9fa555 # lower path: csinc w21, w10, wzr, ge (result never below 1)
|
||||
|
||||
# Real-time step: the VFR step (main+0x7ede6c, 1.0.0 0x7a83e4) and the global ratio after the controller call
|
||||
# (main+0x8f2394, 1.0.0 0x8f68b8) read ratio and seconds from the patch page instead of interval * 0.5 and interval / 60.
|
||||
site realtime main 833e4c 1e220020 @page:x9 # scvtf s0, w1 -> adrp x9, page
|
||||
site realtime main 833e50 52a84e08 bd400120 # mov w8, #60.0 -> ldr s0, [x9] (ratio)
|
||||
site realtime main 833e54 1e270101 bd400521 # fmov s1, w8 -> ldr s1, [x9, #4] (seconds)
|
||||
site realtime main 833e58 1e2c1002 d503201f # fmov s2, #0.5 -> nop
|
||||
site realtime main 833e64 1e211801 d503201f # fdiv s1, s0, s1 -> nop
|
||||
site realtime main 833e68 1e220800 d503201f # fmul s0, s0, s2 -> nop
|
||||
site realtime main 90e5d0 bd425e60 @page:x9 # ldr s0, [x19, #0x25c] -> adrp x9, page
|
||||
site realtime main 90e5d4 1e2c1001 bd400120 # fmov s1, #0.5 -> ldr s0, [x9] (global ratio)
|
||||
site realtime main 90e5e4 5e21d800 d503201f # scvtf s0, s0 -> nop
|
||||
site realtime main 90e5e8 1e210800 d503201f # fmul s0, s0, s1 -> nop
|
||||
|
||||
# Hair and cloth (upstream 290ec9f, 8f8022f): the actor animation update builds a second clock {seconds = factor / 30,
|
||||
# ratio = factor} per rendered frame. Three inlined places: at the fmul, seconds = measured seconds * factor; at the
|
||||
# store of the factor into the ratio slot, measured ratio * factor. The call of the shared update (1.1.0
|
||||
# main+0x8ecb40, 1.2.1 main+0x89822c) scales s2 (seconds) and s3 (ratio) by the measured ratio. Upstream's
|
||||
# veneer bodies, inlined at the site.
|
||||
site cloth main 9efc20 1e200900 f81f0fe9 @page:x9 bd400520 1e200900 f84107e9 # fmul s0, s8, s0
|
||||
site cloth main 9efc1c bd0117e8 d10083ff f90003e9 3d8007ff @page:x9 bd40013f 1e3f091f bd0137ff 3dc007ff f94003e9 910083ff # str s8, [sp, #0x114]
|
||||
site cloth main 9f0bcc 1e200900 f81f0fe9 @page:x9 bd400520 1e200900 f84107e9 # fmul s0, s8, s0
|
||||
site cloth main 9f0ba8 bd0117e8 d10083ff f90003e9 3d8007ff @page:x9 bd40013f 1e3f091f bd0137ff 3dc007ff f94003e9 910083ff # str s8, [sp, #0x114]
|
||||
site cloth main a05a04 1e210801 f81f0fe9 @page:x9 bd400521 1e210801 f84107e9 # fmul s1, s0, s1
|
||||
site cloth main a05a08 bd0137e0 d10083ff f90003e9 3d8007ff @page:x9 bd40013f 1e3f081f bd0157ff 3dc007ff f94003e9 910083ff # str s0, [sp, #0x134]
|
||||
site cloth main 9f044c 97fbf1bd @page:x8 bd400104 1e240842 1e240863 97fbf1bd # bl 0x8ecb40
|
||||
|
||||
# Trampolines (upstream 27c3b43): the slow-motion check compares time object +0x28 (30 / (ratio * time scale)) with
|
||||
# 100; compare +0x28 * +0x38 (30 / time scale) instead, the same value at 30 Hz and independent of the frame rate.
|
||||
site bounce main bee7e0 bd402900 bd402900 bd403901 1e210800 # ldr s0, [x8, #0x28]; ldr s1, [x8, #0x38]; fmul s0, s0, s1
|
||||
|
||||
# Output size (upstream games/<game>/runtime/game_patches.c patch_output_res; runtime/resolution.c switches the set on).
|
||||
# The swapchain size nnMain writes before NvInitializeGraphics comes from page +48 ({w, h} as one 64-bit value), and
|
||||
# the output size the renderer lays out its canvas, crop and UI in (main+0xcc3f00, read from the graphics parameters
|
||||
# through main+0xcc4160) from page +32; the renderer itself goes to page +40.
|
||||
site output main eb8cfc d280f008 @page:x8 # mov x8, #0x780 -> adrp x8, page
|
||||
site output main eb8d00 f2c08708 f9401908 # movk x8, #0x438, lsl #32 -> ldr x8, [x8, #48]
|
||||
site output main cea5c8 aa1403e0 @page:x21 # mov x0, x20 -> adrp x21, page
|
||||
site output main cea5cc 94000081 f90016b3 # bl 0xcc4160 -> str x19, [x21, #40]
|
||||
site output main cea5d0 f9400015 f94012b5 # ldr x21, [x0] -> ldr x21, [x21, #32]
|
||||
|
||||
# Scene render size (upstream patch_render_res): the renderer's +0xcc4 / +0xcc8, which size every scene render target,
|
||||
# take two floats from page +16 instead of the graphics parameters' docked 1600x900.
|
||||
site scene main cea5e0 5e21d900 @page:x9 # scvtf s0, s8 -> adrp x9, page
|
||||
site scene main cea5e8 bd0cc660 2d420520 # str s0, [x19, #0xcc4] -> ldp s0, s1, [x9, #16]
|
||||
site scene main cea5ec 5e21d921 bd0cc660 # scvtf s1, s9 -> str s0, [x19, #0xcc4]
|
||||
|
||||
# Spin waits, from tools/spin_waits.py --exefs build/extracted/v110/exefs --patches recomp/patches-v110.txt: loops that only
|
||||
# another thread can end; their back-edges pass rt_spin_gate (runtime/kernel.c), NX2NAVI_SPIN=0 keeps the core.
|
||||
|
||||
# spin waits found by tools/spin_waits.py on the 1.1.x modules
|
||||
# main: 869 spin waits
|
||||
spin main ac600 ac620 ac630 # 13 instructions; loads
|
||||
spin main ac680 ac6a8 ac6b8 # 15 instructions; loads
|
||||
spin main ac6f0 ac718 ac728 # 15 instructions; loads
|
||||
spin main e8544 e854c # 3 instructions; loads
|
||||
spin main 2457f0 245804 # 6 instructions; loads
|
||||
spin main 644bbc 644bd0 # 6 instructions; loads
|
||||
spin main 6456ac 6456c0 # 6 instructions; loads
|
||||
spin main 6459d4 6459e8 # 6 instructions; loads
|
||||
spin main 645d58 645d6c # 6 instructions; loads
|
||||
spin main 6460c4 6460d8 # 6 instructions; loads
|
||||
spin main 64649c 6464b0 # 6 instructions; loads
|
||||
spin main 646740 646754 # 6 instructions; loads
|
||||
spin main 6467d4 6467e8 # 6 instructions; loads
|
||||
spin main 646e6c 646e80 # 6 instructions; loads
|
||||
spin main 647080 647094 # 6 instructions; loads
|
||||
spin main 6484f4 648510 # 8 instructions; loads
|
||||
spin main 6485a4 6485c0 # 8 instructions; loads
|
||||
spin main 649fb0 649fc4 # 6 instructions; loads
|
||||
spin main 64a064 64a078 # 6 instructions; loads
|
||||
spin main 64a3d0 64a3e4 # 6 instructions; loads
|
||||
spin main 64afac 64afc8 # 8 instructions; loads
|
||||
spin main 64b404 64b418 # 6 instructions; loads
|
||||
spin main 64b980 64b994 # 6 instructions; loads
|
||||
spin main 64c68c 64c6a0 # 6 instructions; loads
|
||||
spin main 64c978 64c98c # 6 instructions; loads
|
||||
spin main 64ca28 64ca3c # 6 instructions; loads
|
||||
spin main 64d378 64d38c # 6 instructions; loads
|
||||
spin main 64d8d8 64d8ec # 6 instructions; loads
|
||||
spin main 64db90 64dba4 # 6 instructions; loads
|
||||
spin main 64de18 64de2c # 6 instructions; loads
|
||||
spin main 64de40 64de54 # 6 instructions; loads
|
||||
spin main 64de68 64de7c # 6 instructions; loads
|
||||
spin main 64e6c8 64e6dc # 6 instructions; loads
|
||||
spin main 64e6f0 64e704 # 6 instructions; loads
|
||||
spin main 64e8ac 64e8c0 # 6 instructions; loads
|
||||
spin main 64e9a4 64e9b8 # 6 instructions; loads
|
||||
spin main 64fb50 64fb64 # 6 instructions; loads
|
||||
spin main 652eac 652ec0 # 6 instructions; loads
|
||||
spin main 652ed4 652ee8 # 6 instructions; loads
|
||||
spin main 652efc 652f10 # 6 instructions; loads
|
||||
spin main 654590 6545a4 # 6 instructions; loads
|
||||
spin main 654c5c 654c70 # 6 instructions; loads
|
||||
spin main 654cfc 654d10 # 6 instructions; loads
|
||||
spin main 655124 655138 # 6 instructions; loads
|
||||
spin main 655c14 655c28 # 6 instructions; loads
|
||||
spin main 656f80 656f94 # 6 instructions; loads
|
||||
spin main 658e60 658e74 # 6 instructions; loads
|
||||
spin main 658ebc 658ed0 # 6 instructions; loads
|
||||
spin main 659b28 659b3c # 6 instructions; loads
|
||||
spin main 659b50 659b64 # 6 instructions; loads
|
||||
spin main 65c9e0 65c9f4 # 6 instructions; loads
|
||||
spin main 65ca08 65ca1c # 6 instructions; loads
|
||||
spin main 65ca30 65ca44 # 6 instructions; loads
|
||||
spin main 65ca58 65ca6c # 6 instructions; loads
|
||||
spin main 65ca80 65ca94 # 6 instructions; loads
|
||||
spin main 65caa8 65cabc # 6 instructions; loads
|
||||
spin main 65cad0 65cae4 # 6 instructions; loads
|
||||
spin main 65caf8 65cb0c # 6 instructions; loads
|
||||
spin main 65cb20 65cb34 # 6 instructions; loads
|
||||
spin main 65cb48 65cb5c # 6 instructions; loads
|
||||
spin main 65cb70 65cb84 # 6 instructions; loads
|
||||
spin main 65cb98 65cbac # 6 instructions; loads
|
||||
spin main 65cbc0 65cbd4 # 6 instructions; loads
|
||||
spin main 65d4b0 65d4c4 # 6 instructions; loads
|
||||
spin main 65d4d8 65d4ec # 6 instructions; loads
|
||||
spin main 65d500 65d514 # 6 instructions; loads
|
||||
spin main 65d528 65d53c # 6 instructions; loads
|
||||
spin main 65da54 65da68 # 6 instructions; loads
|
||||
spin main 65de00 65de14 # 6 instructions; loads
|
||||
spin main 65e200 65e214 # 6 instructions; loads
|
||||
spin main 65e6ec 65e700 # 6 instructions; loads
|
||||
spin main 65ecbc 65ecd0 # 6 instructions; loads
|
||||
spin main 65ece4 65ecf8 # 6 instructions; loads
|
||||
spin main 663588 66359c # 6 instructions; loads
|
||||
spin main 663b0c 663b20 # 6 instructions; loads
|
||||
spin main 663da0 663db4 # 6 instructions; loads
|
||||
spin main 663dec 663e00 # 6 instructions; loads
|
||||
spin main 6645a4 6645b8 # 6 instructions; loads
|
||||
spin main 6645cc 6645e0 # 6 instructions; loads
|
||||
spin main 666530 666544 # 6 instructions; loads
|
||||
spin main 666570 666584 # 6 instructions; loads
|
||||
spin main 6671d4 6671e8 # 6 instructions; loads
|
||||
spin main 6671fc 667210 # 6 instructions; loads
|
||||
spin main 6676c0 6676d4 # 6 instructions; loads
|
||||
spin main 667cfc 667d10 # 6 instructions; loads
|
||||
spin main 66f34c 66f360 # 6 instructions; loads
|
||||
spin main 6708f8 67090c # 6 instructions; loads
|
||||
spin main 670920 670934 # 6 instructions; loads
|
||||
spin main 670948 67095c # 6 instructions; loads
|
||||
spin main 673f34 673f48 # 6 instructions; loads
|
||||
spin main 67556c 675580 # 6 instructions; loads
|
||||
spin main 676954 676968 # 6 instructions; loads
|
||||
spin main 676994 6769a8 # 6 instructions; loads
|
||||
spin main 676e6c 676e80 # 6 instructions; loads
|
||||
spin main 677148 67715c # 6 instructions; loads
|
||||
spin main 6771c8 6771dc # 6 instructions; loads
|
||||
spin main 677484 677498 # 6 instructions; loads
|
||||
spin main 677df0 677e04 # 6 instructions; loads
|
||||
spin main 6792a8 6792bc # 6 instructions; loads
|
||||
spin main 67a984 67a998 # 6 instructions; loads
|
||||
spin main 698ef8 698f0c # 6 instructions; loads
|
||||
spin main 6b6d8c 6b6da0 # 6 instructions; loads
|
||||
spin main 6b922c 6b9240 # 6 instructions; loads
|
||||
spin main 6c5408 6c541c # 6 instructions; loads
|
||||
spin main 6c5614 6c5628 # 6 instructions; loads
|
||||
spin main 6ccce0 6cccf4 # 6 instructions; loads
|
||||
spin main 6ccd98 6ccdac # 6 instructions; loads
|
||||
spin main 6d3c9c 6d3cb0 # 6 instructions; loads
|
||||
spin main 6d3ff8 6d400c # 6 instructions; loads
|
||||
spin main 6d61cc 6d61e0 # 6 instructions; loads
|
||||
spin main 6d6210 6d6224 # 6 instructions; loads
|
||||
spin main 6d6254 6d6268 # 6 instructions; loads
|
||||
spin main 6d6298 6d62ac # 6 instructions; loads
|
||||
spin main 6d75c4 6d75d8 # 6 instructions; loads
|
||||
spin main 6d79dc 6d79f0 # 6 instructions; loads
|
||||
spin main 6d9398 6d93ac # 6 instructions; loads
|
||||
spin main 6dd8d0 6dd8e4 # 6 instructions; loads
|
||||
spin main 6de150 6de164 # 6 instructions; loads
|
||||
spin main 6e073c 6e0750 # 6 instructions; loads
|
||||
spin main 6e0a94 6e0aa8 # 6 instructions; loads
|
||||
spin main 6e4eb8 6e4ecc # 6 instructions; loads
|
||||
spin main 6eb590 6eb5a4 # 6 instructions; loads
|
||||
spin main 6eccac 6eccc0 # 6 instructions; loads
|
||||
spin main 6ed9b4 6ed9c8 # 6 instructions; loads
|
||||
spin main 6ee69c 6ee6b0 # 6 instructions; loads
|
||||
spin main 6f94c0 6f94d4 # 6 instructions; loads
|
||||
spin main 6f9738 6f974c # 6 instructions; loads
|
||||
spin main 6fa324 6fa338 # 6 instructions; loads
|
||||
spin main 70d844 70d858 # 6 instructions; loads
|
||||
spin main 70dc74 70dc88 # 6 instructions; loads
|
||||
spin main 710a70 710a84 # 6 instructions; loads
|
||||
spin main 711848 71185c # 6 instructions; loads
|
||||
spin main 7125a4 7125b8 # 6 instructions; loads
|
||||
spin main 716474 716488 # 6 instructions; loads
|
||||
spin main 719a30 719a44 # 6 instructions; loads
|
||||
spin main 72cd78 72cd8c # 6 instructions; loads
|
||||
spin main 72f66c 72f680 # 6 instructions; loads
|
||||
spin main 737684 737698 # 6 instructions; loads
|
||||
spin main 73e0dc 73e0f0 # 6 instructions; loads
|
||||
spin main 73ed14 73ed28 # 6 instructions; loads
|
||||
spin main 783520 783534 # 6 instructions; loads
|
||||
spin main 797924 797938 # 6 instructions; loads
|
||||
spin main 79794c 797960 # 6 instructions; loads
|
||||
spin main 797c08 797c1c # 6 instructions; loads
|
||||
spin main 797c64 797c78 # 6 instructions; loads
|
||||
spin main 798ff4 799008 # 6 instructions; loads
|
||||
spin main 79cbec 79cc00 # 6 instructions; loads
|
||||
spin main 7ae134 7ae148 # 6 instructions; loads
|
||||
spin main 7ae388 7ae39c # 6 instructions; loads
|
||||
spin main 7c292c 7c2940 # 6 instructions; loads
|
||||
spin main 7d618c 7d61a0 # 6 instructions; loads
|
||||
spin main 7d904c 7d9060 # 6 instructions; loads
|
||||
spin main 7e11c0 7e11d4 # 6 instructions; loads
|
||||
spin main 7e1c9c 7e1cb0 # 6 instructions; loads
|
||||
spin main 7e24a0 7e24b4 # 6 instructions; loads
|
||||
spin main 7ed89c 7ed8b0 # 6 instructions; loads
|
||||
spin main 7eef28 7eef3c # 6 instructions; loads
|
||||
spin main 7f515c 7f5170 # 6 instructions; loads
|
||||
spin main 801468 80147c # 6 instructions; loads
|
||||
spin main 801490 8014a4 # 6 instructions; loads
|
||||
spin main 8014b8 8014cc # 6 instructions; loads
|
||||
spin main 80a0a4 80a0b8 # 6 instructions; loads
|
||||
spin main 811500 811514 # 6 instructions; loads
|
||||
spin main 816c40 816c54 # 6 instructions; loads
|
||||
spin main 819450 819464 # 6 instructions; loads
|
||||
spin main 85df6c 85e068 # 4 instructions; loads
|
||||
spin main 863220 863234 # 6 instructions; loads
|
||||
spin main 86352c 863540 # 6 instructions; loads
|
||||
spin main 863a80 863a94 # 6 instructions; loads
|
||||
spin main 863b94 863ba8 # 6 instructions; loads
|
||||
spin main 86543c 865450 # 6 instructions; loads
|
||||
spin main 865464 865478 # 6 instructions; loads
|
||||
spin main 87e564 87e578 # 6 instructions; loads
|
||||
spin main 87e58c 87e5a0 # 6 instructions; loads
|
||||
spin main 880d44 880d58 # 6 instructions; loads
|
||||
spin main 8810f4 881108 # 6 instructions; loads
|
||||
spin main 8814c8 8814dc # 6 instructions; loads
|
||||
spin main 88189c 8818b0 # 6 instructions; loads
|
||||
spin main 887ce8 887cfc # 6 instructions; loads
|
||||
spin main 887f50 887f64 # 6 instructions; loads
|
||||
spin main 8884ec 888500 # 6 instructions; loads
|
||||
spin main 888618 88862c # 6 instructions; loads
|
||||
spin main 888748 88875c # 6 instructions; loads
|
||||
spin main 8888e0 8888f4 # 6 instructions; loads
|
||||
spin main 89183c 891850 # 6 instructions; loads
|
||||
spin main 892ccc 892cec # 9 instructions; loads
|
||||
spin main 89540c 89541c # 5 instructions; loads
|
||||
spin main 895668 895694 # 12 instructions; loads
|
||||
spin main 8956a8 8956b8 # 5 instructions; loads
|
||||
spin main 8da7dc 8da7e4 # 3 instructions; loads
|
||||
spin main 8da7ec 8da7f0 # 2 instructions; loads
|
||||
spin main 8da858 8da860 # 3 instructions; loads
|
||||
spin main 8fb190 8fb1a4 # 6 instructions; loads
|
||||
spin main 9045bc 9045d0 # 6 instructions; loads
|
||||
spin main 9045e4 9045f8 # 6 instructions; loads
|
||||
spin main 90460c 904620 # 6 instructions; loads
|
||||
spin main 904634 904648 # 6 instructions; loads
|
||||
spin main 905b20 905b34 # 6 instructions; loads
|
||||
spin main 9062f0 906304 # 6 instructions; loads
|
||||
spin main 91019c 9101b0 # 6 instructions; loads
|
||||
spin main 910720 910734 # 6 instructions; loads
|
||||
spin main 9363cc 9363e0 # 6 instructions; loads
|
||||
spin main 93655c 936570 # 6 instructions; loads
|
||||
spin main 93819c 9381b0 # 6 instructions; loads
|
||||
spin main 940060 94007c # 8 instructions; loads
|
||||
spin main 94012c 940148 # 8 instructions; loads
|
||||
spin main 97864c 978660 # 6 instructions; loads
|
||||
spin main 99aa8c 99aabc # 13 instructions; loads
|
||||
spin main 99aad0 99aae0 # 5 instructions; loads
|
||||
spin main 9a5fd4 9a6004 # 13 instructions; loads
|
||||
spin main 9a6018 9a6028 # 5 instructions; loads
|
||||
spin main 9b2700 9b2710 # 5 instructions; loads
|
||||
spin main 9f395c 9f3970 # 6 instructions; loads
|
||||
spin main 9f39e0 9f39f4 # 6 instructions; loads
|
||||
spin main 9f3b2c 9f3b40 # 6 instructions; loads
|
||||
spin main 9f3bf8 9f3c0c # 6 instructions; loads
|
||||
spin main 9f6f5c 9f6f70 # 6 instructions; loads
|
||||
spin main a11908 a1191c # 6 instructions; loads
|
||||
spin main a1257c a12590 # 6 instructions; loads
|
||||
spin main a14d6c a14d80 # 6 instructions; loads
|
||||
spin main a1b0a4 a1b0b8 # 6 instructions; loads
|
||||
spin main a1b0ec a1b100 # 6 instructions; loads
|
||||
spin main a1c3dc a1c3f0 # 6 instructions; loads
|
||||
spin main a2b268 a2b27c # 6 instructions; loads
|
||||
spin main a2cab8 a2cacc # 6 instructions; loads
|
||||
spin main a2f228 a2f23c # 6 instructions; loads
|
||||
spin main a8e920 a8e934 # 6 instructions; loads
|
||||
spin main aa2c20 aa2c34 # 6 instructions; loads
|
||||
spin main aa5108 aa511c # 6 instructions; loads
|
||||
spin main aa9f94 aa9fa8 # 6 instructions; loads
|
||||
spin main aaa674 aaa688 # 6 instructions; loads
|
||||
spin main aad564 aad578 # 6 instructions; loads
|
||||
spin main ab245c ab24b4 # 7 instructions; loads
|
||||
spin main ac8874 ac88fc # 35 instructions; loads
|
||||
spin main af4040 af4054 # 6 instructions; loads
|
||||
spin main af4068 af407c # 6 instructions; loads
|
||||
spin main af4090 af40a4 # 6 instructions; loads
|
||||
spin main af40cc af40e0 # 6 instructions; loads
|
||||
spin main af40f4 af4108 # 6 instructions; loads
|
||||
spin main af411c af4130 # 6 instructions; loads
|
||||
spin main b47a74 b47a88 # 6 instructions; loads
|
||||
spin main b4e080 b4e094 # 6 instructions; loads
|
||||
spin main b529f4 b52a08 # 6 instructions; loads
|
||||
spin main b52a7c b52a90 # 6 instructions; loads
|
||||
spin main b52cfc b52d10 # 6 instructions; loads
|
||||
spin main b52dd0 b52de4 # 6 instructions; loads
|
||||
spin main b53458 b5346c # 6 instructions; loads
|
||||
spin main b535a8 b535bc # 6 instructions; loads
|
||||
spin main b54320 b54334 # 6 instructions; loads
|
||||
spin main b545fc b54610 # 6 instructions; loads
|
||||
spin main b5662c b56640 # 6 instructions; loads
|
||||
spin main b56654 b56668 # 6 instructions; loads
|
||||
spin main b71800 b71814 # 6 instructions; loads
|
||||
spin main b71828 b7183c # 6 instructions; loads
|
||||
spin main b7b82c b7b840 # 6 instructions; loads
|
||||
spin main b80970 b80984 # 6 instructions; loads
|
||||
spin main b86fe8 b86ffc # 6 instructions; loads
|
||||
spin main b8702c b87040 # 6 instructions; loads
|
||||
spin main b87070 b87084 # 6 instructions; loads
|
||||
spin main b8775c b87770 # 6 instructions; loads
|
||||
spin main b97d6c b97d80 # 6 instructions; loads
|
||||
spin main b97ed4 b97ee8 # 6 instructions; loads
|
||||
spin main b9c628 b9c63c # 6 instructions; loads
|
||||
spin main b9c6c8 b9c6dc # 6 instructions; loads
|
||||
spin main b9c6f0 b9c704 # 6 instructions; loads
|
||||
spin main b9c7b8 b9c7cc # 6 instructions; loads
|
||||
spin main ba1db4 ba1dc8 # 6 instructions; loads
|
||||
spin main ba72e8 ba72fc # 6 instructions; loads
|
||||
spin main bb1070 bb1084 # 6 instructions; loads
|
||||
spin main bb1098 bb10ac # 6 instructions; loads
|
||||
spin main bb6c38 bb6c4c # 6 instructions; loads
|
||||
spin main bb7fa0 bb7fb4 # 6 instructions; loads
|
||||
spin main bd27c8 bd27d8 # 5 instructions; loads
|
||||
spin main bdd678 bdd68c # 6 instructions; loads
|
||||
spin main bf2ccc bf2ce0 # 6 instructions; loads
|
||||
spin main bf2e24 bf2e38 # 6 instructions; loads
|
||||
spin main bf32a0 bf32b4 # 6 instructions; loads
|
||||
spin main bf3730 bf3744 # 6 instructions; loads
|
||||
spin main c0a554 c0a568 # 6 instructions; loads
|
||||
spin main c0a6b4 c0a6c8 # 6 instructions; loads
|
||||
spin main c0a850 c0a864 # 6 instructions; loads
|
||||
spin main c0d758 c0d76c # 6 instructions; loads
|
||||
spin main c0d8b0 c0d8c4 # 6 instructions; loads
|
||||
spin main c0dd3c c0dd50 # 6 instructions; loads
|
||||
spin main c15ffc c16010 # 6 instructions; loads
|
||||
spin main c1665c c16670 # 6 instructions; loads
|
||||
spin main c2315c c23170 # 6 instructions; loads
|
||||
spin main c2374c c23760 # 6 instructions; loads
|
||||
spin main c23998 c239ac # 6 instructions; loads
|
||||
spin main c2d128 c2d13c # 6 instructions; loads
|
||||
spin main c3a9cc c3a9e0 # 6 instructions; loads
|
||||
spin main c5ab4c c5ab60 # 6 instructions; loads
|
||||
spin main c70388 c7039c # 6 instructions; loads
|
||||
spin main c703b0 c703c4 # 6 instructions; loads
|
||||
spin main c94f70 c94f84 # 6 instructions; loads
|
||||
spin main c95a00 c95a14 # 6 instructions; loads
|
||||
spin main c96764 c96778 # 6 instructions; loads
|
||||
spin main c96948 c9695c # 6 instructions; loads
|
||||
spin main c96ce4 c96cf8 # 6 instructions; loads
|
||||
spin main c96d54 c96d68 # 6 instructions; loads
|
||||
spin main c97400 c97414 # 6 instructions; loads
|
||||
spin main c97ca0 c97cb4 # 6 instructions; loads
|
||||
spin main c99ba0 c99bb4 # 6 instructions; loads
|
||||
spin main c99c90 c99ca4 # 6 instructions; loads
|
||||
spin main c9abac c9abc0 # 6 instructions; loads
|
||||
spin main c9ac8c c9aca0 # 6 instructions; loads
|
||||
spin main c9b2e0 c9b2f4 # 6 instructions; loads
|
||||
spin main c9d9f4 c9da08 # 6 instructions; loads
|
||||
spin main c9db3c c9db50 # 6 instructions; loads
|
||||
spin main c9df14 c9df30 # 8 instructions; loads
|
||||
spin main ccaaa8 ccaabc # 6 instructions; loads
|
||||
spin main cd38a4 cd38b8 # 6 instructions; loads
|
||||
spin main cda7c4 cda7d8 # 6 instructions; loads
|
||||
spin main cdb388 cdb39c # 6 instructions; loads
|
||||
spin main cdb3cc cdb3e0 # 6 instructions; loads
|
||||
spin main cdbab4 cdbac8 # 6 instructions; loads
|
||||
spin main cdbaf8 cdbb0c # 6 instructions; loads
|
||||
spin main cdbce4 cdbcf8 # 6 instructions; loads
|
||||
spin main cdce0c cdce20 # 6 instructions; loads
|
||||
spin main cecedc cecef0 # 6 instructions; loads
|
||||
spin main d0fbb4 d0fbc8 # 6 instructions; loads
|
||||
spin main d1acd0 d1ace4 # 6 instructions; loads
|
||||
spin main d1dc54 d1dc60 d1dcac d1dcc4 # 29 instructions; loads
|
||||
spin main d2273c d22750 # 6 instructions; loads
|
||||
spin main d231bc d231d0 # 6 instructions; loads
|
||||
spin main d23398 d233ac # 6 instructions; loads
|
||||
spin main d2e810 d2e824 # 6 instructions; loads
|
||||
spin main d3d8dc d3d8f0 # 6 instructions; loads
|
||||
spin main d4c3a8 d4c3bc # 6 instructions; loads
|
||||
spin main d4ffc4 d4ffd8 # 6 instructions; loads
|
||||
spin main d50a78 d50a8c # 6 instructions; loads
|
||||
spin main d50b04 d50b18 # 6 instructions; loads
|
||||
spin main d50bfc d50c10 # 6 instructions; loads
|
||||
spin main d50e60 d50e74 # 6 instructions; loads
|
||||
spin main d50e88 d50e9c # 6 instructions; loads
|
||||
spin main d50ebc d50ed0 # 6 instructions; loads
|
||||
spin main d510b8 d510cc # 6 instructions; loads
|
||||
spin main d51afc d51b18 # 8 instructions; loads
|
||||
spin main d52478 d5248c # 6 instructions; loads
|
||||
spin main d527f4 d52808 # 6 instructions; loads
|
||||
spin main d5283c d52850 # 6 instructions; loads
|
||||
spin main d52864 d52878 # 6 instructions; loads
|
||||
spin main d5288c d528a0 # 6 instructions; loads
|
||||
spin main d528f8 d5290c # 6 instructions; loads
|
||||
spin main d52920 d52934 # 6 instructions; loads
|
||||
spin main d529a8 d529bc # 6 instructions; loads
|
||||
spin main d52ab0 d52ac4 # 6 instructions; loads
|
||||
spin main d91344 d91358 # 6 instructions; loads
|
||||
spin main d91970 d91984 # 6 instructions; loads
|
||||
spin main d91cc0 d91cd4 # 6 instructions; loads
|
||||
spin main d91dc0 d91dd4 # 6 instructions; loads
|
||||
spin main d92280 d92294 # 6 instructions; loads
|
||||
spin main d923cc d923e0 # 6 instructions; loads
|
||||
spin main d93600 d93614 # 6 instructions; loads
|
||||
spin main d94100 d94114 # 6 instructions; loads
|
||||
spin main d9412c d94140 # 6 instructions; loads
|
||||
spin main d99098 d990ac # 6 instructions; loads
|
||||
spin main d9c260 d9c298 # 8 instructions; loads
|
||||
spin main d9c2c8 d9c300 # 8 instructions; loads
|
||||
spin main d9fe34 d9fe48 # 6 instructions; loads
|
||||
spin main da1eb4 da1ec8 # 6 instructions; loads
|
||||
spin main da1edc da1ef0 # 6 instructions; loads
|
||||
spin main da7010 da7024 # 6 instructions; loads
|
||||
spin main da70f8 da710c # 6 instructions; loads
|
||||
spin main dade1c dade30 # 6 instructions; loads
|
||||
spin main db58dc db58f0 # 6 instructions; loads
|
||||
spin main dbb0e4 dbb0f8 # 6 instructions; loads
|
||||
spin main dbca30 dbca4c # 8 instructions; loads
|
||||
spin main dbfc20 dbfc34 # 6 instructions; loads
|
||||
spin main dbff00 dbff14 # 6 instructions; loads
|
||||
spin main dc78fc dc7910 # 6 instructions; loads
|
||||
spin main dcaa88 dcaa9c # 6 instructions; loads
|
||||
spin main dcb2ac dcb2c0 # 6 instructions; loads
|
||||
spin main dcb9c8 dcb9dc # 6 instructions; loads
|
||||
spin main dd4a28 dd4a3c # 6 instructions; loads
|
||||
spin main dd6414 dd6428 # 6 instructions; loads
|
||||
spin main dd7498 dd74ac # 6 instructions; loads
|
||||
spin main dd78b4 dd78c8 # 6 instructions; loads
|
||||
spin main ddf338 ddf34c # 6 instructions; loads
|
||||
spin main de7324 de7338 # 6 instructions; loads
|
||||
spin main deb218 deb22c # 6 instructions; loads
|
||||
spin main df249c df24b0 # 6 instructions; loads
|
||||
spin main df2930 df2944 # 6 instructions; loads
|
||||
spin main dfab0c dfab20 # 6 instructions; loads
|
||||
spin main e1a248 e1a25c # 6 instructions; loads
|
||||
spin main e27b10 e27b24 # 6 instructions; loads
|
||||
spin main e28428 e2843c # 6 instructions; loads
|
||||
spin main e38cac e38cc0 # 6 instructions; loads
|
||||
spin main e38f90 e38fa4 # 6 instructions; loads
|
||||
spin main e39274 e39288 # 6 instructions; loads
|
||||
spin main e39558 e3956c # 6 instructions; loads
|
||||
spin main e40b1c e40b30 # 6 instructions; loads
|
||||
spin main e41478 e4148c # 6 instructions; loads
|
||||
spin main e450bc e450d0 # 6 instructions; loads
|
||||
spin main e45400 e45414 # 6 instructions; loads
|
||||
spin main e51aa0 e51ab4 # 6 instructions; loads
|
||||
spin main e51c08 e51c1c # 6 instructions; loads
|
||||
spin main e51cf4 e51d08 # 6 instructions; loads
|
||||
spin main e8e42c e8e440 # 6 instructions; loads
|
||||
spin main e90628 e9063c # 6 instructions; loads
|
||||
spin main e930d8 e930ec # 6 instructions; loads
|
||||
spin main e94c64 e94c78 # 6 instructions; loads
|
||||
spin main e9557c e95590 # 6 instructions; loads
|
||||
spin main e966e4 e966f8 # 6 instructions; loads
|
||||
spin main e9711c e97130 # 6 instructions; loads
|
||||
spin main e97164 e97178 # 6 instructions; loads
|
||||
spin main e9c134 e9c148 # 6 instructions; loads
|
||||
spin main ea4c28 ea4c3c # 6 instructions; loads
|
||||
spin main ea4c78 ea4c8c # 6 instructions; loads
|
||||
spin main ea4cc4 ea4cd8 # 6 instructions; loads
|
||||
spin main ea4d10 ea4d24 # 6 instructions; loads
|
||||
spin main eb07cc eb07d4 # 3 instructions; loads
|
||||
spin main eb07dc eb07e0 # 2 instructions; loads
|
||||
spin main eb0808 eb0810 # 3 instructions; loads
|
||||
spin main eb1548 eb155c # 6 instructions; loads
|
||||
spin main eb4240 eb4254 # 6 instructions; loads
|
||||
spin main eb5aa8 eb5abc # 6 instructions; loads
|
||||
spin main eb637c eb6390 # 6 instructions; loads
|
||||
spin main eb7954 eb7968 # 6 instructions; loads
|
||||
spin main ebf63c ebf650 # 6 instructions; loads
|
||||
spin main ebfb5c ebfb70 # 6 instructions; loads
|
||||
spin main ebfb98 ebfbac # 6 instructions; loads
|
||||
spin main ebfd50 ebfd64 # 6 instructions; loads
|
||||
spin main ebffb4 ebffc8 # 6 instructions; loads
|
||||
spin main eca534 eca548 # 6 instructions; loads
|
||||
spin main eca6f8 eca70c # 6 instructions; loads
|
||||
spin main ecb088 ecb09c # 6 instructions; loads
|
||||
spin main ed26e8 ed26fc # 6 instructions; loads
|
||||
spin main ed293c ed2950 # 6 instructions; loads
|
||||
spin main ed2ab0 ed2ac4 # 6 instructions; loads
|
||||
spin main ed2c24 ed2c38 # 6 instructions; loads
|
||||
spin main ed2ed0 ed2ee4 # 6 instructions; loads
|
||||
spin main ed3348 ed335c # 6 instructions; loads
|
||||
spin main ed351c ed3530 # 6 instructions; loads
|
||||
spin main ed3cf4 ed3d08 # 6 instructions; loads
|
||||
spin main ed42e0 ed42f4 # 6 instructions; loads
|
||||
spin main ed430c ed4320 # 6 instructions; loads
|
||||
spin main ed5294 ed52a8 # 6 instructions; loads
|
||||
spin main ed5658 ed566c # 6 instructions; loads
|
||||
spin main ed5680 ed5694 # 6 instructions; loads
|
||||
spin main ed79e8 ed79fc # 6 instructions; loads
|
||||
spin main ed7a28 ed7a3c # 6 instructions; loads
|
||||
spin main ed7a50 ed7a64 # 6 instructions; loads
|
||||
spin main ed7a78 ed7a8c # 6 instructions; loads
|
||||
spin main ed80ac ed80c0 # 6 instructions; loads
|
||||
spin main ed80d4 ed80e8 # 6 instructions; loads
|
||||
spin main ed934c ed9360 # 6 instructions; loads
|
||||
spin main ed94a0 ed94b4 # 6 instructions; loads
|
||||
spin main ed9a50 ed9a64 # 6 instructions; loads
|
||||
spin main ede7fc ede810 # 6 instructions; loads
|
||||
spin main ee0ce4 ee0cf8 # 6 instructions; loads
|
||||
spin main eebd28 eebd3c # 6 instructions; loads
|
||||
spin main ef9ed4 ef9ee8 # 6 instructions; loads
|
||||
spin main efa7a4 efa7b8 # 6 instructions; loads
|
||||
spin main efa7d4 efa7e8 # 6 instructions; loads
|
||||
spin main efad94 efada8 # 6 instructions; loads
|
||||
spin main efadc4 efadd8 # 6 instructions; loads
|
||||
spin main efdac8 efdadc # 6 instructions; loads
|
||||
spin main f01fa4 f01fb8 # 6 instructions; loads
|
||||
spin main f022e4 f022f8 # 6 instructions; loads
|
||||
spin main f02394 f023a8 # 6 instructions; loads
|
||||
spin main f02434 f02448 # 6 instructions; loads
|
||||
spin main f024e4 f024f8 # 6 instructions; loads
|
||||
spin main f3c87c f3c890 # 6 instructions; loads
|
||||
spin main f3d54c f3d560 # 6 instructions; loads
|
||||
spin main f3dba8 f3dbbc # 6 instructions; loads
|
||||
spin main f3dbd4 f3dbe8 # 6 instructions; loads
|
||||
spin main f547a4 f547b8 # 6 instructions; loads
|
||||
spin main f54d60 f54d74 # 6 instructions; loads
|
||||
spin main f57494 f574a8 # 6 instructions; loads
|
||||
spin main f66ef8 f66f0c # 6 instructions; loads
|
||||
spin main f66f20 f66f34 # 6 instructions; loads
|
||||
spin main f67170 f67184 # 6 instructions; loads
|
||||
spin main f671fc f67210 # 6 instructions; loads
|
||||
spin main f67224 f67238 # 6 instructions; loads
|
||||
spin main f67254 f67268 # 6 instructions; loads
|
||||
spin main f684f0 f68504 # 6 instructions; loads
|
||||
spin main f6a1ec f6a200 # 6 instructions; loads
|
||||
spin main f6a3f8 f6a40c # 6 instructions; loads
|
||||
spin main f6afc4 f6afd8 # 6 instructions; loads
|
||||
spin main f712a4 f712b8 # 6 instructions; loads
|
||||
spin main f71400 f71414 # 6 instructions; loads
|
||||
spin main f7155c f71570 # 6 instructions; loads
|
||||
spin main f716b8 f716cc # 6 instructions; loads
|
||||
spin main f729dc f729f0 # 6 instructions; loads
|
||||
spin main f73084 f73098 # 6 instructions; loads
|
||||
spin main f73148 f7315c # 6 instructions; loads
|
||||
spin main f76574 f76588 # 6 instructions; loads
|
||||
spin main f7c8ec f7c900 # 6 instructions; loads
|
||||
spin main f83bd0 f83be4 # 6 instructions; loads
|
||||
spin main f870f0 f87104 # 6 instructions; loads
|
||||
spin main f94eac f94ec0 # 6 instructions; loads
|
||||
spin main fa6580 fa6594 # 6 instructions; loads
|
||||
spin main fa65a8 fa65bc # 6 instructions; loads
|
||||
spin main fabb50 fabb64 # 6 instructions; loads
|
||||
spin main fabe74 fabe88 # 6 instructions; loads
|
||||
spin main fac8a0 fac8b4 # 6 instructions; loads
|
||||
spin main fac8c4 fac8d8 # 6 instructions; loads
|
||||
spin main face58 face6c # 6 instructions; loads
|
||||
spin main fc0a28 fc0a3c # 6 instructions; loads
|
||||
spin main fc0c68 fc0c7c # 6 instructions; loads
|
||||
spin main fc0e8c fc0ea0 # 6 instructions; loads
|
||||
spin main fc1054 fc1068 # 6 instructions; loads
|
||||
spin main fc1178 fc118c # 6 instructions; loads
|
||||
spin main fcb18c fcb1a8 # 8 instructions; loads
|
||||
spin main fccfe8 fccffc # 6 instructions; loads
|
||||
spin main fcd554 fcd640 # 4 instructions; loads
|
||||
spin main fcdc5c fcdce4 # 4 instructions; loads
|
||||
spin main fd2d30 fd2d44 # 6 instructions; loads
|
||||
spin main fd6250 fd6264 # 6 instructions; loads
|
||||
spin main fdf818 fdf82c # 6 instructions; loads
|
||||
spin main fdfb30 fdfb44 # 6 instructions; loads
|
||||
spin main fe0fa8 fe0fbc # 6 instructions; loads
|
||||
spin main fe1ad8 fe1aec # 6 instructions; loads
|
||||
spin main fea3a0 fea3b4 # 6 instructions; loads
|
||||
spin main fead08 fead1c # 6 instructions; loads
|
||||
spin main feb168 feb17c # 6 instructions; loads
|
||||
spin main feb1d0 feb1e4 # 6 instructions; loads
|
||||
spin main ff2af8 ff2b0c # 6 instructions; loads
|
||||
spin main ff5680 ff5694 # 6 instructions; loads
|
||||
spin main ff58e0 ff58f4 # 6 instructions; loads
|
||||
spin main ff9660 ff9674 # 6 instructions; loads
|
||||
spin main ffacec ffad00 # 6 instructions; loads
|
||||
spin main 1001500 1001514 # 6 instructions; loads
|
||||
spin main 1002c28 1002c3c # 6 instructions; loads
|
||||
spin main 1010b3c 1010b50 # 6 instructions; loads
|
||||
spin main 1010ef4 1010f08 # 6 instructions; loads
|
||||
spin main 1011244 1011258 # 6 instructions; loads
|
||||
spin main 1011544 1011558 # 6 instructions; loads
|
||||
spin main 1011a9c 1011ab0 # 6 instructions; loads
|
||||
spin main 1011e34 1011e48 # 6 instructions; loads
|
||||
spin main 10121b4 10121c8 # 6 instructions; loads
|
||||
spin main 1012228 101223c # 6 instructions; loads
|
||||
spin main 1013150 1013164 # 6 instructions; loads
|
||||
spin main 101349c 10134b0 # 6 instructions; loads
|
||||
spin main 1013920 1013934 # 6 instructions; loads
|
||||
spin main 1013b6c 1013b80 # 6 instructions; loads
|
||||
spin main 1014950 1014964 # 6 instructions; loads
|
||||
spin main 10149e8 10149fc # 6 instructions; loads
|
||||
spin main 1015bac 1015bc0 # 6 instructions; loads
|
||||
spin main 10160c0 10160d4 # 6 instructions; loads
|
||||
spin main 10166f8 101670c # 6 instructions; loads
|
||||
spin main 10167b4 10167c8 # 6 instructions; loads
|
||||
spin main 1016870 1016884 # 6 instructions; loads
|
||||
spin main 101692c 1016940 # 6 instructions; loads
|
||||
spin main 10170f0 1017104 # 6 instructions; loads
|
||||
spin main 10191dc 10191f0 # 6 instructions; loads
|
||||
spin main 101948c 10194a0 # 6 instructions; loads
|
||||
spin main 1019778 101978c # 6 instructions; loads
|
||||
spin main 1019a2c 1019a40 # 6 instructions; loads
|
||||
spin main 1019cf0 1019d04 # 6 instructions; loads
|
||||
spin main 1019ff4 101a008 # 6 instructions; loads
|
||||
spin main 101a054 101a068 # 6 instructions; loads
|
||||
spin main 101b594 101b5b0 # 8 instructions; loads
|
||||
spin main 101c7b4 101c7c8 # 6 instructions; loads
|
||||
spin main 101c7fc 101c810 # 6 instructions; loads
|
||||
spin main 101c844 101c858 # 6 instructions; loads
|
||||
spin main 101c88c 101c8a0 # 6 instructions; loads
|
||||
spin main 101c8d4 101c8e8 # 6 instructions; loads
|
||||
spin main 1023190 10231a4 # 6 instructions; loads
|
||||
spin main 10461ac 10461c0 # 6 instructions; loads
|
||||
spin main 1047278 104728c # 6 instructions; loads
|
||||
spin main 1050a8c 1050aa0 # 6 instructions; loads
|
||||
spin main 1055074 10550bc # 3 instructions; loads
|
||||
spin main 1056bd4 1056be8 # 6 instructions; loads
|
||||
spin main 106037c 1060390 # 6 instructions; loads
|
||||
spin main 1066bf4 1066c08 # 6 instructions; loads
|
||||
spin main 106bc38 106bc4c # 6 instructions; loads
|
||||
spin main 106be80 106be94 # 6 instructions; loads
|
||||
spin main 1070220 1070234 # 6 instructions; loads
|
||||
spin main 1071264 1071278 # 6 instructions; loads
|
||||
spin main 1071788 107179c # 6 instructions; loads
|
||||
spin main 1073910 1073924 # 6 instructions; loads
|
||||
spin main 10815e0 10815f4 # 6 instructions; loads
|
||||
spin main 108cb28 108cb3c # 6 instructions; loads
|
||||
spin main 1095678 109568c # 6 instructions; loads
|
||||
spin main 10956c0 10956d4 # 6 instructions; loads
|
||||
spin main 109f134 109f148 # 6 instructions; loads
|
||||
spin main 10bc820 10bc834 # 6 instructions; loads
|
||||
spin main 10be4c8 10be4dc # 6 instructions; loads
|
||||
spin main 10be4f0 10be504 # 6 instructions; loads
|
||||
spin main 10c2d4c 10c2d60 # 6 instructions; loads
|
||||
spin main 10c3748 10c375c # 6 instructions; loads
|
||||
spin main 10d5ef8 10d5f0c # 6 instructions; loads
|
||||
spin main 10da208 10da21c # 6 instructions; loads
|
||||
spin main 10e3edc 10e3ef0 # 6 instructions; loads
|
||||
spin main 10e5ee4 10e5ef8 # 6 instructions; loads
|
||||
spin main 10ec860 10ec874 # 6 instructions; loads
|
||||
spin main 10ec8dc 10ec8f0 # 6 instructions; loads
|
||||
spin main 10f1db4 10f1dc8 # 6 instructions; loads
|
||||
spin main 10ff3b4 10ff3c8 # 6 instructions; loads
|
||||
spin main 10ff788 10ff79c # 6 instructions; loads
|
||||
spin main 10ffef0 10fff04 # 6 instructions; loads
|
||||
spin main 1100500 1100514 # 6 instructions; loads
|
||||
spin main 1103e80 1103e94 # 6 instructions; loads
|
||||
spin main 110ca34 110cb68 # 4 instructions; loads
|
||||
spin main 110cab8 110cb4c # 4 instructions; loads
|
||||
spin main 1117420 1117434 # 6 instructions; loads
|
||||
spin main 1117448 111745c # 6 instructions; loads
|
||||
spin main 111bf5c 111bf70 # 6 instructions; loads
|
||||
spin main 111c1bc 111c1d0 # 6 instructions; loads
|
||||
spin main 111c918 111c92c # 6 instructions; loads
|
||||
spin main 112aef0 112af04 # 6 instructions; loads
|
||||
spin main 1143e28 1143e3c # 6 instructions; loads
|
||||
spin main 1145110 1145124 # 6 instructions; loads
|
||||
spin main 1145138 114514c # 6 instructions; loads
|
||||
spin main 1149244 1149258 # 6 instructions; loads
|
||||
spin main 114b868 114b87c # 6 instructions; loads
|
||||
spin main 114f850 114f864 # 6 instructions; loads
|
||||
spin main 114fcdc 114fcf0 # 6 instructions; loads
|
||||
spin main 1150cbc 1150cd0 # 6 instructions; loads
|
||||
spin main 115aa38 115aa4c # 6 instructions; loads
|
||||
spin main 117d7c8 117d7dc # 6 instructions; loads
|
||||
spin main 118a000 118a014 # 6 instructions; loads
|
||||
spin main 118a3d8 118a3ec # 6 instructions; loads
|
||||
spin main 118f65c 118f670 # 6 instructions; loads
|
||||
spin main 1193d30 1193d44 # 6 instructions; loads
|
||||
spin main 1198130 1198144 # 6 instructions; loads
|
||||
spin main 1198158 119816c # 6 instructions; loads
|
||||
spin main 1198e48 1198e5c # 6 instructions; loads
|
||||
spin main 119c414 119c428 # 6 instructions; loads
|
||||
spin main 11a0778 11a078c # 6 instructions; loads
|
||||
spin main 11a0fcc 11a0fe0 # 6 instructions; loads
|
||||
spin main 11a5884 11a5898 # 6 instructions; loads
|
||||
spin main 11bbd80 11bbd94 # 6 instructions; loads
|
||||
spin main 11bd154 11bd168 # 6 instructions; loads
|
||||
spin main 11bd17c 11bd190 # 6 instructions; loads
|
||||
spin main 11e5fc8 11e5fdc # 6 instructions; loads
|
||||
spin main 11e5ff0 11e6004 # 6 instructions; loads
|
||||
spin main 11ea5b8 11ea5cc # 6 instructions; loads
|
||||
spin main 11eccf8 11ecd0c # 6 instructions; loads
|
||||
spin main 11f50d8 11f50ec # 6 instructions; loads
|
||||
spin main 11f5624 11f5638 # 6 instructions; loads
|
||||
spin main 12010e8 12010fc # 6 instructions; loads
|
||||
spin main 120ecc0 120ecd4 # 6 instructions; loads
|
||||
spin main 12171d8 12171ec # 6 instructions; loads
|
||||
spin main 1217cd8 1217cec # 6 instructions; loads
|
||||
spin main 1219124 1219138 # 6 instructions; loads
|
||||
spin main 1231ca8 1231cbc # 6 instructions; loads
|
||||
spin main 1231e58 1231e6c # 6 instructions; loads
|
||||
spin main 1234784 1234798 # 6 instructions; loads
|
||||
spin main 1234d14 1234d28 # 6 instructions; loads
|
||||
spin main 1236974 1236988 # 6 instructions; loads
|
||||
spin main 1236b1c 1236b30 # 6 instructions; loads
|
||||
spin main 12479cc 12479e0 # 6 instructions; loads
|
||||
spin main 1261af8 1261b0c # 6 instructions; loads
|
||||
spin main 1261f20 1261f34 # 6 instructions; loads
|
||||
spin main 1262200 1262214 # 6 instructions; loads
|
||||
spin main 1268448 126845c # 6 instructions; loads
|
||||
spin main 1283a80 1283a94 # 6 instructions; loads
|
||||
spin main 128ba28 128ba3c # 6 instructions; loads
|
||||
spin main 128ba90 128baa4 # 6 instructions; loads
|
||||
spin main 128bc40 128bc54 # 6 instructions; loads
|
||||
spin main 128bc6c 128bc80 # 6 instructions; loads
|
||||
spin main 128bc98 128bcac # 6 instructions; loads
|
||||
spin main 128bcc4 128bcd8 # 6 instructions; loads
|
||||
spin main 128c468 128c47c # 6 instructions; loads
|
||||
spin main 128c490 128c4a4 # 6 instructions; loads
|
||||
spin main 12924ec 1292500 # 6 instructions; loads
|
||||
spin main 1292e4c 1292e60 # 6 instructions; loads
|
||||
spin main 1292eb4 1292ec8 # 6 instructions; loads
|
||||
spin main 129458c 12945a0 # 6 instructions; loads
|
||||
spin main 12966e0 12966f4 # 6 instructions; loads
|
||||
spin main 129e62c 129e640 # 6 instructions; loads
|
||||
spin main 129f954 129f968 # 6 instructions; loads
|
||||
spin main 12a61b0 12a61c4 # 6 instructions; loads
|
||||
spin main 12ab4cc 12ab4e0 # 6 instructions; loads
|
||||
spin main 12ab4f4 12ab508 # 6 instructions; loads
|
||||
spin main 12c1228 12c123c # 6 instructions; loads
|
||||
spin main 12c1250 12c1264 # 6 instructions; loads
|
||||
spin main 12ca068 12ca07c # 6 instructions; loads
|
||||
spin main 12d040c 12d0420 # 6 instructions; loads
|
||||
spin main 12e3820 12e3834 # 6 instructions; loads
|
||||
spin main 12e8e80 12e8e94 # 6 instructions; loads
|
||||
spin main 12e9640 12e9654 # 6 instructions; loads
|
||||
spin main 1309bc8 1309bdc # 6 instructions; loads
|
||||
spin main 1314ed8 1314eec # 6 instructions; loads
|
||||
spin main 131553c 1315550 # 6 instructions; loads
|
||||
spin main 1322ccc 1322dac # 11 instructions; loads
|
||||
spin main 13277f4 1327808 # 6 instructions; loads
|
||||
spin main 1327ab8 1327acc # 6 instructions; loads
|
||||
spin main 132a1e0 132a1f4 # 6 instructions; loads
|
||||
spin main 132b0a8 132b0bc # 6 instructions; loads
|
||||
spin main 132b87c 132b890 # 6 instructions; loads
|
||||
spin main 1332fc0 1332fd4 # 6 instructions; loads
|
||||
spin main 1363450 1363464 # 6 instructions; loads
|
||||
spin main 13feca8 13fecbc # 6 instructions; loads
|
||||
spin main 13fee40 13fee54 # 6 instructions; loads
|
||||
spin main 157c12c 157c140 # 6 instructions; loads
|
||||
spin main 157dfe0 157dff4 # 6 instructions; loads
|
||||
spin main 1585a20 1585a34 # 6 instructions; loads
|
||||
spin main 1585ee0 1585ef4 # 6 instructions; loads
|
||||
spin main 158c4c8 158c4dc # 6 instructions; loads
|
||||
spin main 1599a14 1599a28 # 6 instructions; loads
|
||||
spin main 159aed0 159aee4 # 6 instructions; loads
|
||||
spin main 159aef8 159af0c # 6 instructions; loads
|
||||
spin main 15a2a20 15a2a34 # 6 instructions; loads
|
||||
spin main 15a3228 15a323c # 6 instructions; loads
|
||||
spin main 15a34e8 15a34fc # 6 instructions; loads
|
||||
spin main 15a3510 15a3524 # 6 instructions; loads
|
||||
spin main 15a3f44 15a3f58 # 6 instructions; loads
|
||||
spin main 15ae678 15ae68c # 6 instructions; loads
|
||||
spin main 15b8d78 15b8d8c # 6 instructions; loads
|
||||
spin main 15b9218 15b922c # 6 instructions; loads
|
||||
spin main 15b9320 15b9334 # 6 instructions; loads
|
||||
spin main 15b9638 15b964c # 6 instructions; loads
|
||||
spin main 15c6c9c 15c6cb0 # 6 instructions; loads
|
||||
spin main 15d5380 15d5394 # 6 instructions; loads
|
||||
spin main 15e8a0c 15e8a20 # 6 instructions; loads
|
||||
spin main 15e9ad4 15e9ae8 # 6 instructions; loads
|
||||
spin main 15e9b7c 15e9b90 # 6 instructions; loads
|
||||
spin main 15ef1c4 15ef1d8 # 6 instructions; loads
|
||||
spin main 15ef304 15ef318 # 6 instructions; loads
|
||||
spin main 15ef32c 15ef340 # 6 instructions; loads
|
||||
spin main 1607238 160724c # 6 instructions; loads
|
||||
spin main 160779c 16077b0 # 6 instructions; loads
|
||||
spin main 16173e0 16173f4 # 6 instructions; loads
|
||||
spin main 1623748 162375c # 6 instructions; loads
|
||||
spin main 1627bdc 1627bf0 # 6 instructions; loads
|
||||
spin main 1627c2c 1627c40 # 6 instructions; loads
|
||||
spin main 1628eb8 1628ecc # 6 instructions; loads
|
||||
spin main 16298a8 16298bc # 6 instructions; loads
|
||||
spin main 16340f8 163410c # 6 instructions; loads
|
||||
spin main 1636748 163675c # 6 instructions; loads
|
||||
spin main 1636ed4 1636ee8 # 6 instructions; loads
|
||||
spin main 163b7f0 163b804 # 6 instructions; loads
|
||||
spin main 1648354 1648368 # 6 instructions; loads
|
||||
spin main 1651478 165148c # 6 instructions; loads
|
||||
spin main 1653730 1653744 # 6 instructions; loads
|
||||
spin main 1656c5c 1656c70 # 6 instructions; loads
|
||||
spin main 16596b0 16596b8 # 3 instructions; loads
|
||||
spin main 16596c0 16596c4 # 2 instructions; loads
|
||||
spin main 16596f8 1659700 # 3 instructions; loads
|
||||
spin main 165cb68 165cb7c # 6 instructions; loads
|
||||
spin main 1677368 167737c # 6 instructions; loads
|
||||
spin main 16dc224 16dc238 # 6 instructions; loads
|
||||
spin main 173d61c 173d630 # 6 instructions; loads
|
||||
spin main 1747354 1747368 # 6 instructions; loads
|
||||
spin main 1747918 174792c # 6 instructions; loads
|
||||
spin main 17a0a20 17a0a34 # 6 instructions; loads
|
||||
spin main 1932774 1932788 # 6 instructions; loads
|
||||
spin main 1933ea8 1933ebc # 6 instructions; loads
|
||||
spin main 1962e88 1962e90 # 3 instructions; loads
|
||||
spin main 1962e98 1962e9c # 2 instructions; loads
|
||||
spin main 1962f20 1962f28 # 3 instructions; loads
|
||||
spin main 196300c 1963014 # 3 instructions; loads
|
||||
spin main 196301c 1963020 # 2 instructions; loads
|
||||
spin main 19630c8 19630d0 # 3 instructions; loads
|
||||
spin main 1975850 1975858 # 3 instructions; loads
|
||||
spin main 1975860 1975864 # 2 instructions; loads
|
||||
spin main 1975888 1975890 # 3 instructions; loads
|
||||
spin main 19758c0 19758c8 # 3 instructions; loads
|
||||
spin main 19758d0 19758d4 # 2 instructions; loads
|
||||
spin main 19758fc 1975904 # 3 instructions; loads
|
||||
spin main 19e5048 19e505c # 6 instructions; loads
|
||||
spin main 1a8b8b4 1a8b8c4 # 5 instructions; loads
|
||||
spin main 1b65f9c 1b65fb0 # 6 instructions; loads
|
||||
spin main 1b66058 1b6606c # 6 instructions; loads
|
||||
spin main 1b66114 1b66128 # 6 instructions; loads
|
||||
spin main 1b66714 1b66728 # 6 instructions; loads
|
||||
spin main 1b667d0 1b667e4 # 6 instructions; loads
|
||||
spin main 1b6688c 1b668a0 # 6 instructions; loads
|
||||
spin main 1dff370 1dff37c # 4 instructions; loads
|
||||
spin main 21e6508 21e6530 # 4 instructions; loads
|
||||
spin main 222a3e0 222a3fc # 8 instructions; loads
|
||||
spin main 22322d0 22322d8 # 3 instructions; loads
|
||||
spin main 2232358 2232360 # 3 instructions; loads
|
||||
spin main 22323e8 2232410 # 3 instructions; loads
|
||||
spin main 223931c 223932c # 5 instructions; loads
|
||||
spin main 225dc10 225dc18 # 3 instructions; loads
|
||||
spin main 225dc20 225dc24 # 2 instructions; loads
|
||||
spin main 225dcac 225dcb4 # 3 instructions; loads
|
||||
spin main 225dd38 225dd40 # 3 instructions; loads
|
||||
spin main 225dd48 225dd4c # 2 instructions; loads
|
||||
spin main 225dd64 225dd6c # 3 instructions; loads
|
||||
spin main 22b72dc 22b72f0 # 6 instructions; loads
|
||||
spin main 22b7440 22b7454 # 6 instructions; loads
|
||||
spin main 22c60ac 22c60d0 # 4 instructions; loads
|
||||
spin main 22c619c 22c61a8 # 4 instructions; loads
|
||||
spin main 233ce40 233ce54 # 6 instructions; loads
|
||||
spin main 240ccb0 240ccb8 # 3 instructions; loads
|
||||
spin main 240ccc0 240ccc4 # 2 instructions; loads
|
||||
spin main 240cd40 240cd48 # 3 instructions; loads
|
||||
spin main 240d57c 240d584 # 3 instructions; loads
|
||||
spin main 240d58c 240d590 # 2 instructions; loads
|
||||
spin main 240d5fc 240d604 # 3 instructions; loads
|
||||
spin main 240da9c 240daa4 # 3 instructions; loads
|
||||
spin main 240daac 240dab0 # 2 instructions; loads
|
||||
spin main 240db3c 240db44 # 3 instructions; loads
|
||||
spin main 240dc80 240dc88 # 3 instructions; loads
|
||||
spin main 240dc90 240dc94 # 2 instructions; loads
|
||||
spin main 240dce8 240dcf0 # 3 instructions; loads
|
||||
spin main 240dd34 240dd3c # 3 instructions; loads
|
||||
spin main 240dd44 240dd48 # 2 instructions; loads
|
||||
spin main 240ddfc 240de04 # 3 instructions; loads
|
||||
spin main 240de0c 240de10 # 2 instructions; loads
|
||||
spin main 240de50 240de58 # 3 instructions; loads
|
||||
spin main 240de80 240de88 # 3 instructions; loads
|
||||
spin main 240df74 240df7c # 3 instructions; loads
|
||||
spin main 240df84 240df88 # 2 instructions; loads
|
||||
spin main 240e068 240e070 # 3 instructions; loads
|
||||
spin main 240e0fc 240e104 # 3 instructions; loads
|
||||
spin main 240e10c 240e110 # 2 instructions; loads
|
||||
spin main 240e1c4 240e1cc # 3 instructions; loads
|
||||
spin main 240e1e4 240e1e8 # 2 instructions; loads
|
||||
spin main 240e288 240e290 # 3 instructions; loads
|
||||
spin main 240e2b8 240e2c0 # 3 instructions; loads
|
||||
spin main 240e300 240e308 # 3 instructions; loads
|
||||
spin main 240e310 240e314 # 2 instructions; loads
|
||||
spin main 240e338 240e340 # 3 instructions; loads
|
||||
spin main 240e384 240e38c # 3 instructions; loads
|
||||
spin main 240e394 240e398 # 2 instructions; loads
|
||||
spin main 240e3c0 240e3c8 # 3 instructions; loads
|
||||
spin main 240e91c 240e924 # 3 instructions; loads
|
||||
spin main 240e92c 240e930 # 2 instructions; loads
|
||||
spin main 240e954 240e95c # 3 instructions; loads
|
||||
spin main 240f088 240f090 # 3 instructions; loads
|
||||
spin main 240f098 240f09c # 2 instructions; loads
|
||||
spin main 240f0c0 240f0c8 # 3 instructions; loads
|
||||
spin main 2410984 241098c # 3 instructions; loads
|
||||
spin main 2410994 2410998 # 2 instructions; loads
|
||||
spin main 2410a18 2410a20 # 3 instructions; loads
|
||||
spin main 2410a40 2410a48 # 3 instructions; loads
|
||||
spin main 2410a50 2410a54 # 2 instructions; loads
|
||||
spin main 2410ad4 2410adc # 3 instructions; loads
|
||||
spin main 2410e70 2410e78 # 3 instructions; loads
|
||||
spin main 2410e80 2410e84 # 2 instructions; loads
|
||||
spin main 2410ed4 2410edc # 3 instructions; loads
|
||||
spin main 2410f1c 2410f24 # 3 instructions; loads
|
||||
spin main 2410f2c 2410f30 # 2 instructions; loads
|
||||
spin main 2410fcc 2410fd4 # 3 instructions; loads
|
||||
spin main 241102c 2411034 # 3 instructions; loads
|
||||
spin main 241103c 2411040 # 2 instructions; loads
|
||||
spin main 24110c4 24110cc # 3 instructions; loads
|
||||
spin main 2413d28 2413d30 # 3 instructions; loads
|
||||
spin main 2413d38 2413d3c # 2 instructions; loads
|
||||
spin main 2413dc8 2413dd0 # 3 instructions; loads
|
||||
spin main 2413e04 2413e0c # 3 instructions; loads
|
||||
spin main 2413e14 2413e18 # 2 instructions; loads
|
||||
spin main 2413e84 2413e8c # 3 instructions; loads
|
||||
spin main 2416358 2416360 # 3 instructions; loads
|
||||
spin main 2416368 241636c # 2 instructions; loads
|
||||
spin main 2416388 2416390 # 3 instructions; loads
|
||||
spin main 2462470 2462484 # 6 instructions; loads
|
||||
spin main 2462498 24624ac # 6 instructions; loads
|
||||
spin main 24651f4 2465208 # 6 instructions; loads
|
||||
spin main 2465688 246569c # 6 instructions; loads
|
||||
spin main 2474d20 2474d34 # 6 instructions; loads
|
||||
spin main 2475154 2475168 # 6 instructions; loads
|
||||
spin main 2479134 2479148 # 6 instructions; loads
|
||||
spin main 2479b7c 2479b90 # 6 instructions; loads
|
||||
spin main 247a378 247a38c # 6 instructions; loads
|
||||
spin main 2493050 2493064 # 6 instructions; loads
|
||||
spin main 2886500 2886514 # 6 instructions; loads
|
||||
spin main 28865bc 28865d0 # 6 instructions; loads
|
||||
spin main 2886678 288668c # 6 instructions; loads
|
||||
spin main 2887484 2887498 # 6 instructions; loads
|
||||
spin main 2887540 2887554 # 6 instructions; loads
|
||||
spin main 28875fc 2887610 # 6 instructions; loads
|
||||
spin main 28876b8 28876cc # 6 instructions; loads
|
||||
spin main 2887774 2887788 # 6 instructions; loads
|
||||
spin main 2887830 2887844 # 6 instructions; loads
|
||||
spin main 28878ec 2887900 # 6 instructions; loads
|
||||
spin main 28879a8 28879bc # 6 instructions; loads
|
||||
spin main 2887e70 2887e84 # 6 instructions; loads
|
||||
spin main 2887f2c 2887f40 # 6 instructions; loads
|
||||
spin main 2a3e540 2a3e548 # 3 instructions; loads
|
||||
spin main 2a3e550 2a3e554 # 2 instructions; loads
|
||||
spin main 2a3e58c 2a3e594 # 3 instructions; loads
|
||||
# subsdk0: 8 spin waits
|
||||
spin subsdk0 2090 20a4 # 6 instructions; loads
|
||||
spin subsdk0 278b4 278c8 # 6 instructions; loads
|
||||
spin subsdk0 bcf28 bcfd0 bcfd8 # 14 instructions; loads
|
||||
spin subsdk0 bd0d0 bd178 bd180 # 14 instructions; loads
|
||||
spin subsdk0 c03a0 c03b4 # 6 instructions; loads
|
||||
spin subsdk0 1bbefc 1bbf08 # 4 instructions; loads
|
||||
spin subsdk0 1bd838 1bd84c # 6 instructions; loads
|
||||
spin subsdk0 1c0c68 1c0c74 # 4 instructions; loads
|
||||
# sdk: 5 spin waits
|
||||
spin sdk f5218 f5350 # 14 instructions; loads
|
||||
spin sdk 23a590 23a5d8 # 19 instructions; loads
|
||||
spin sdk 23a658 23a6a0 # 19 instructions; loads
|
||||
spin sdk 23a7fc 23a918 # 19 instructions; loads
|
||||
spin sdk 3d3250 3d3270 # 9 instructions; loads
|
||||
980
recomp/patches-v121.txt
Normal file
980
recomp/patches-v121.txt
Normal file
@@ -0,0 +1,980 @@
|
||||
# Code patches for NX2navi 1.2.1 main (recomp/patches.py). Ported from MacNativeGames games/<game>/runtime/game_patches.c
|
||||
# (MIT, Copyright (c) 2026 MacNativeGames contributors) at upstream ebe621d; 1.2.1 sites from its game_version.h
|
||||
# (2db612b), each original word checked against the 1.2.1 main. The patch page holds two floats the runtime writes at
|
||||
# every present (frame_rate.c): +0 the 30 Hz ratio (seconds * 30), +4 the frame step in seconds.
|
||||
|
||||
set fps60 NX2NAVI_FPS60 1
|
||||
set realtime NX2NAVI_REALTIME 1
|
||||
set cloth NX2NAVI_CLOTH_REALTIME 1
|
||||
set bounce NX2NAVI_HIGHFPS_FIX 1
|
||||
set output NX2NAVI_PATCH_OUTPUT 0
|
||||
set scene NX2NAVI_PATCH_SCENE 0
|
||||
set shadow NX2NAVI_PATCH_SHADOW 0
|
||||
|
||||
# 60 fps: the adaptive present-interval controller (main+0x8f26c8, 1.0.0 0x8f6bec) gets the minimum interval 1.
|
||||
site fps60 main 8f273c 6b08015f 7100055f # clamp: cmp w10, #1 (was cmp w10, w8 = minimum)
|
||||
site fps60 main 8f2740 1a89b10a 1a9fa52a # clamp: csinc w10, w9, wzr, ge (desired = max(desired, 1))
|
||||
site fps60 main 8f2764 b9401a8a d503201f # lower trigger: nop the stored-candidate load
|
||||
site fps60 main 8f27f4 6b08015f 7100055f # raise path: cmp w10, #1
|
||||
site fps60 main 8f2804 1a88c1ac 1a9fc5ac # raise path: csinc w12, w13, wzr, gt (next lower candidate floors at 1)
|
||||
site fps60 main 8f2858 b9400288 52800028 # lower path: mov w8, #1 (minimum interval 1)
|
||||
site fps60 main 8f2874 2a0a03f5 1a9fa555 # lower path: csinc w21, w10, wzr, ge (result never below 1)
|
||||
|
||||
# Real-time step: the VFR step (main+0x7ede6c, 1.0.0 0x7a83e4) and the global ratio after the controller call
|
||||
# (main+0x8f2394, 1.0.0 0x8f68b8) read ratio and seconds from the patch page instead of interval * 0.5 and interval / 60.
|
||||
site realtime main 7ede7c 1e220020 @page:x9 # scvtf s0, w1 -> adrp x9, page
|
||||
site realtime main 7ede80 52a84e08 bd400120 # mov w8, #60.0 -> ldr s0, [x9] (ratio)
|
||||
site realtime main 7ede84 1e270101 bd400521 # fmov s1, w8 -> ldr s1, [x9, #4] (seconds)
|
||||
site realtime main 7ede88 1e2c1002 d503201f # fmov s2, #0.5 -> nop
|
||||
site realtime main 7ede94 1e211801 d503201f # fdiv s1, s0, s1 -> nop
|
||||
site realtime main 7ede98 1e220800 d503201f # fmul s0, s0, s2 -> nop
|
||||
site realtime main 8f2394 bd425e60 @page:x9 # ldr s0, [x19, #0x25c] -> adrp x9, page
|
||||
site realtime main 8f2398 1e2c1001 bd400120 # fmov s1, #0.5 -> ldr s0, [x9] (global ratio)
|
||||
site realtime main 8f23a8 5e21d800 d503201f # scvtf s0, s0 -> nop
|
||||
site realtime main 8f23ac 1e210800 d503201f # fmul s0, s0, s1 -> nop
|
||||
|
||||
# Equipment-switch cooldown (issue #18, found by JieML1100 on 1.4.3): the player update (main+0x852d24) steps the
|
||||
# countdown at player state +0x109c through the timer step (main+0xec98cc) only while it is above FLT_EPSILON, but the
|
||||
# equipment gate (main+0xcae6f8) blocks weapon, shield and bow changes while it is above 0. A measured ratio can leave
|
||||
# a remainder in (0, FLT_EPSILON] that is never stepped again; stepping while above 0 takes it below 0.
|
||||
site realtime main 852d28 1e270101 1e2703e1 # fmov s1, w8 (FLT_EPSILON) -> fmov s1, wzr
|
||||
|
||||
# Hair and cloth (upstream 290ec9f, 8f8022f): the actor animation update builds a second clock {seconds = factor / 30,
|
||||
# ratio = factor} per rendered frame. Three inlined places: at the fmul, seconds = measured seconds * factor; at the
|
||||
# store of the factor into the ratio slot, measured ratio * factor. The call of the shared update (main+0x89822c)
|
||||
# scales s2 (seconds) and s3 (ratio) by the measured ratio. Upstream's veneer bodies, inlined at the site.
|
||||
site cloth main 82192c 1e200900 f81f0fe9 @page:x9 bd400520 1e200900 f84107e9 # fmul s0, s8, s0
|
||||
site cloth main 821928 bd0127e8 d10083ff f90003e9 3d8007ff @page:x9 bd40013f 1e3f091f bd0147ff 3dc007ff f94003e9 910083ff # str s8, [sp, #0x124]
|
||||
site cloth main 822a64 1e200900 f81f0fe9 @page:x9 bd400520 1e200900 f84107e9 # fmul s0, s8, s0
|
||||
site cloth main 822a40 bd0127e8 d10083ff f90003e9 3d8007ff @page:x9 bd40013f 1e3f091f bd0147ff 3dc007ff f94003e9 910083ff # str s8, [sp, #0x124]
|
||||
site cloth main 83182c 1e210801 f81f0fe9 @page:x9 bd400521 1e210801 f84107e9 # fmul s1, s0, s1
|
||||
site cloth main 831830 bd0137e0 d10083ff f90003e9 3d8007ff @page:x9 bd40013f 1e3f081f bd0157ff 3dc007ff f94003e9 910083ff # str s0, [sp, #0x134]
|
||||
site cloth main 8222f0 9401d7cf @page:x8 bd400104 1e240842 1e240863 9401d7cf # bl 0x89822c
|
||||
|
||||
# Trampolines (upstream 27c3b43): the slow-motion check compares time object +0x28 (30 / (ratio * time scale)) with
|
||||
# 100; compare +0x28 * +0x38 (30 / time scale) instead, the same value at 30 Hz and independent of the frame rate.
|
||||
site bounce main bda798 bd402900 bd402900 bd403901 1e210800 # ldr s0, [x8, #0x28]; ldr s1, [x8, #0x38]; fmul s0, s0, s1
|
||||
|
||||
# Cursor and aim steps (upstream game_patches.c patch_cursor_speed, 363a6eb). These updates read the game's 30 Hz frame
|
||||
# ratio for their smoothing but leave it out of the step itself, so the map cursor and the vertical object aim moved
|
||||
# 2x as fast at 60 fps and 4x at 120 as at the shipping 30 fps (issue #44). Each site multiplies the step by that ratio,
|
||||
# so the speed is the shipping one at any frame rate. x9 and s16 are free: the next read of x9 follows a write, the
|
||||
# function does not touch s16, and x20 keeps the update's frame object for the whole function.
|
||||
set cursor NX2NAVI_HIGHFPS_FIX 1
|
||||
site cursor main ec3d9c bd400361 f94002e9 bd400930 1e300800 bd400361 # map pan speed s0 *= [[x23] + 8], then ldr s1, [x27]
|
||||
site cursor main 1d48d64 1e2a198c 1e2a198c bd400a90 1e30098c # fdiv s12, s12, s10, then s12 *= [x20 + 8]: vertical object aim
|
||||
site cursor main 1d484e4 1e200923 1e200923 bd400a90 1e300863 # fmul s3, s9, s0, then s3 *= [x20 + 8]: vertical gyro aim (Recall)
|
||||
|
||||
# Output size (upstream games/<game>/runtime/game_patches.c patch_output_res; runtime/resolution.c switches the set on).
|
||||
# The swapchain size nnMain writes before NvInitializeGraphics comes from page +48 ({w, h} as one 64-bit value), and
|
||||
# the output size the renderer lays out its canvas, crop and UI in (main+0xcc3f00, read from the graphics parameters
|
||||
# through main+0xcc4160) from page +32; the renderer itself goes to page +40.
|
||||
site output main e7aa3c d280f008 @page:x8 # mov x8, #0x780 -> adrp x8, page
|
||||
site output main e7aa40 f2c08708 f9401908 # movk x8, #0x438, lsl #32 -> ldr x8, [x8, #48]
|
||||
site output main cc3f50 aa1403e0 @page:x21 # mov x0, x20 -> adrp x21, page
|
||||
site output main cc3f54 94000083 f90016b3 # bl 0xcc4160 -> str x19, [x21, #40]
|
||||
site output main cc3f58 f9400015 f94012b5 # ldr x21, [x0] -> ldr x21, [x21, #32]
|
||||
|
||||
# Scene render size (upstream patch_render_res): the renderer's +0xcc4 / +0xcc8, which size every scene render target,
|
||||
# take two floats from page +16 instead of the graphics parameters' docked 1600x900.
|
||||
site scene main cc3f68 5e21d900 @page:x9 # scvtf s0, s8 -> adrp x9, page
|
||||
site scene main cc3f70 bd0cc660 2d420520 # str s0, [x19, #0xcc4] -> ldp s0, s1, [x9, #16]
|
||||
site scene main cc3f74 5e21d921 bd0cc660 # scvtf s1, s9 -> str s0, [x19, #0xcc4]
|
||||
|
||||
# Camera aspect ratio for a game resolution that is not 16:9 (upstream game_patches.c, the 1.2.1 sites of aspect_install;
|
||||
# runtime/resolution.c res_init writes the output's width / height to page +56 and switches the set on). The same four
|
||||
# sites as patches-v143.txt, with the same original words: two camera sites (update and setup) load the camera's copy of
|
||||
# DefaultAspect 1.777778, two viewport routines divide width by height. The replacement loads the ratio from the page
|
||||
# instead (Hor+). x10 is kept on the stack, so no register liveness is assumed.
|
||||
set aspect NX2NAVI_ASPECT_PATCH 0
|
||||
site aspect main cb4b10 bd414260 f81f0fea @page:x10 bd403940 f84107ea # ldr s0, [x19, #0x140] (camera update)
|
||||
site aspect main 12521cc bd414260 f81f0fea @page:x10 bd403940 f84107ea # ldr s0, [x19, #0x140] (camera setup)
|
||||
site aspect main 19b36f0 1e211800 f81f0fea @page:x10 bd403940 f84107ea # fdiv s0, s0, s1 (viewport)
|
||||
site aspect main 1ecdf68 1e211800 f81f0fea @page:x10 bd403940 f84107ea # fdiv s0, s0, s1 (viewport)
|
||||
|
||||
# Texture pool offsets past 2 GiB (MacNativeGames ca311e2d). The texture loader keeps a texture's place in its pool as a
|
||||
# 32-bit offset (main+0xad4294: sub x25, x9, x10, stored as the word w25) and widens it as a signed number for
|
||||
# nvnTextureBuilderSetStorage's offset and for SetPackagedTextureData's source (the pool's CPU address + offset). The
|
||||
# shipped heap table keeps every pool far below 2 GiB; a texture pack's heap table with NX2NAVI_APP_POOL raised can make
|
||||
# one larger (MacNativeGames saw a 3.58 GiB pool), and every texture past 2 GiB then got storage 4 GiB below its pool.
|
||||
# The offset is widened unsigned instead, the same value below 2 GiB, right up to 4 GiB. 1.4.3 needs no patch: its
|
||||
# loaders (main+0x583c34, main+0x27ed214) keep the offset in 64 bits.
|
||||
set pooloff NX2NAVI_POOL_OFFSET_PATCH 1
|
||||
site pooloff main ad43f0 93407f22 2a1903e2 # sxtw x2, w25 -> mov w2, w25 (SetStorage offset)
|
||||
site pooloff main ad440c 8b39c101 8b394101 # add x1, x8, w25, sxtw -> add x1, x8, w25, uxtw (packaged data source)
|
||||
|
||||
# Spin waits, from tools/spin_waits.py --exefs build/extracted/v121/exefs --patches recomp/patches-v121.txt: loops that only
|
||||
# another thread can end; their back-edges pass rt_spin_gate (runtime/kernel.c), NX2NAVI_SPIN=0 keeps the core.
|
||||
spin main ac600 ac620 ac630 # 13 instructions; loads
|
||||
spin main ac680 ac6a8 ac6b8 # 15 instructions; loads
|
||||
spin main ac6f0 ac718 ac728 # 15 instructions; loads
|
||||
spin main e8544 e854c # 3 instructions; loads
|
||||
spin main 2457f0 245804 # 6 instructions; loads
|
||||
spin main 634d3c 634d50 # 6 instructions; loads
|
||||
spin main 65ddf8 65de0c # 6 instructions; loads
|
||||
spin main 65fe1c 65fe30 # 6 instructions; loads
|
||||
spin main 664350 664364 # 6 instructions; loads
|
||||
spin main 664558 66456c # 6 instructions; loads
|
||||
spin main 66764c 667660 # 6 instructions; loads
|
||||
spin main 66fce0 66fcf4 # 6 instructions; loads
|
||||
spin main 66fe64 66fe78 # 6 instructions; loads
|
||||
spin main 670af8 670b0c # 6 instructions; loads
|
||||
spin main 670ee8 670efc # 6 instructions; loads
|
||||
spin main 671214 671228 # 6 instructions; loads
|
||||
spin main 673a3c 673a50 # 6 instructions; loads
|
||||
spin main 673a80 673a94 # 6 instructions; loads
|
||||
spin main 673ac4 673ad8 # 6 instructions; loads
|
||||
spin main 673b08 673b1c # 6 instructions; loads
|
||||
spin main 678774 678788 # 6 instructions; loads
|
||||
spin main 678814 678828 # 6 instructions; loads
|
||||
spin main 67a270 67a284 # 6 instructions; loads
|
||||
spin main 67a5c8 67a5dc # 6 instructions; loads
|
||||
spin main 67b8a4 67b8b8 # 6 instructions; loads
|
||||
spin main 67dde8 67ddfc # 6 instructions; loads
|
||||
spin main 682650 682664 # 6 instructions; loads
|
||||
spin main 683c5c 683c70 # 6 instructions; loads
|
||||
spin main 68b1fc 68b210 # 6 instructions; loads
|
||||
spin main 68ff0c 68ff20 # 6 instructions; loads
|
||||
spin main 6917ec 691800 # 6 instructions; loads
|
||||
spin main 6a5338 6a534c # 6 instructions; loads
|
||||
spin main 6a55b4 6a55c8 # 6 instructions; loads
|
||||
spin main 6a9488 6a949c # 6 instructions; loads
|
||||
spin main 6a98b8 6a98cc # 6 instructions; loads
|
||||
spin main 6ac5bc 6ac5d0 # 6 instructions; loads
|
||||
spin main 6afad0 6afae4 # 6 instructions; loads
|
||||
spin main 6bb02c 6bb040 # 6 instructions; loads
|
||||
spin main 6bb078 6bb08c # 6 instructions; loads
|
||||
spin main 6c8680 6c8694 # 6 instructions; loads
|
||||
spin main 6ca094 6ca0a8 # 6 instructions; loads
|
||||
spin main 6d1404 6d1418 # 6 instructions; loads
|
||||
spin main 6d8280 6d8294 # 6 instructions; loads
|
||||
spin main 6de7b4 6de7c8 # 6 instructions; loads
|
||||
spin main 6e0740 6e0754 # 6 instructions; loads
|
||||
spin main 6ec574 6ec588 # 6 instructions; loads
|
||||
spin main 6ec6d4 6ec6e8 # 6 instructions; loads
|
||||
spin main 708250 708264 # 6 instructions; loads
|
||||
spin main 708d1c 708d30 # 6 instructions; loads
|
||||
spin main 7090dc 7090f0 # 6 instructions; loads
|
||||
spin main 7093ec 709400 # 6 instructions; loads
|
||||
spin main 709754 709768 # 6 instructions; loads
|
||||
spin main 709b2c 709b40 # 6 instructions; loads
|
||||
spin main 709dd0 709de4 # 6 instructions; loads
|
||||
spin main 709e64 709e78 # 6 instructions; loads
|
||||
spin main 70a444 70a458 # 6 instructions; loads
|
||||
spin main 70a718 70a72c # 6 instructions; loads
|
||||
spin main 70bb8c 70bba8 # 8 instructions; loads
|
||||
spin main 70bc3c 70bc58 # 8 instructions; loads
|
||||
spin main 70d6e4 70d6f8 # 6 instructions; loads
|
||||
spin main 70d8c4 70d8d8 # 6 instructions; loads
|
||||
spin main 70db14 70db28 # 6 instructions; loads
|
||||
spin main 70e7b4 70e7d0 # 8 instructions; loads
|
||||
spin main 70ec04 70ec18 # 6 instructions; loads
|
||||
spin main 70f140 70f154 # 6 instructions; loads
|
||||
spin main 70fd10 70fd24 # 6 instructions; loads
|
||||
spin main 70fe4c 70fe60 # 6 instructions; loads
|
||||
spin main 7101b8 7101cc # 6 instructions; loads
|
||||
spin main 7109a4 7109b8 # 6 instructions; loads
|
||||
spin main 710f04 710f18 # 6 instructions; loads
|
||||
spin main 7111a4 7111b8 # 6 instructions; loads
|
||||
spin main 711424 711438 # 6 instructions; loads
|
||||
spin main 71144c 711460 # 6 instructions; loads
|
||||
spin main 711474 711488 # 6 instructions; loads
|
||||
spin main 711ccc 711ce0 # 6 instructions; loads
|
||||
spin main 711cf4 711d08 # 6 instructions; loads
|
||||
spin main 712cd0 712ce4 # 6 instructions; loads
|
||||
spin main 712dc0 712dd4 # 6 instructions; loads
|
||||
spin main 7130f8 71310c # 6 instructions; loads
|
||||
spin main 716398 7163ac # 6 instructions; loads
|
||||
spin main 7163c0 7163d4 # 6 instructions; loads
|
||||
spin main 7163e8 7163fc # 6 instructions; loads
|
||||
spin main 717b40 717b54 # 6 instructions; loads
|
||||
spin main 7180fc 718110 # 6 instructions; loads
|
||||
spin main 71819c 7181b0 # 6 instructions; loads
|
||||
spin main 7187c8 7187dc # 6 instructions; loads
|
||||
spin main 719124 719138 # 6 instructions; loads
|
||||
spin main 71a638 71a64c # 6 instructions; loads
|
||||
spin main 71cec8 71cedc # 6 instructions; loads
|
||||
spin main 71cef0 71cf04 # 6 instructions; loads
|
||||
spin main 71fcac 71fcc0 # 6 instructions; loads
|
||||
spin main 71fcd4 71fce8 # 6 instructions; loads
|
||||
spin main 71fcfc 71fd10 # 6 instructions; loads
|
||||
spin main 71fd24 71fd38 # 6 instructions; loads
|
||||
spin main 71fd4c 71fd60 # 6 instructions; loads
|
||||
spin main 71fd74 71fd88 # 6 instructions; loads
|
||||
spin main 71fd9c 71fdb0 # 6 instructions; loads
|
||||
spin main 71fdc4 71fdd8 # 6 instructions; loads
|
||||
spin main 71fdec 71fe00 # 6 instructions; loads
|
||||
spin main 71fe14 71fe28 # 6 instructions; loads
|
||||
spin main 71fe3c 71fe50 # 6 instructions; loads
|
||||
spin main 71fe64 71fe78 # 6 instructions; loads
|
||||
spin main 71fe8c 71fea0 # 6 instructions; loads
|
||||
spin main 720678 72068c # 6 instructions; loads
|
||||
spin main 7206a0 7206b4 # 6 instructions; loads
|
||||
spin main 7206c8 7206dc # 6 instructions; loads
|
||||
spin main 7206f0 720704 # 6 instructions; loads
|
||||
spin main 720b0c 720b20 # 6 instructions; loads
|
||||
spin main 720f40 720f54 # 6 instructions; loads
|
||||
spin main 7214d0 7214e4 # 6 instructions; loads
|
||||
spin main 721a90 721aa4 # 6 instructions; loads
|
||||
spin main 721f28 721f3c # 6 instructions; loads
|
||||
spin main 721f50 721f64 # 6 instructions; loads
|
||||
spin main 72590c 725920 # 6 instructions; loads
|
||||
spin main 726340 726354 # 6 instructions; loads
|
||||
spin main 7265d4 7265e8 # 6 instructions; loads
|
||||
spin main 726620 726634 # 6 instructions; loads
|
||||
spin main 727d28 727d3c # 6 instructions; loads
|
||||
spin main 727d50 727d64 # 6 instructions; loads
|
||||
spin main 729da0 729db4 # 6 instructions; loads
|
||||
spin main 729de8 729dfc # 6 instructions; loads
|
||||
spin main 72aa08 72aa1c # 6 instructions; loads
|
||||
spin main 72aa30 72aa44 # 6 instructions; loads
|
||||
spin main 72aef4 72af08 # 6 instructions; loads
|
||||
spin main 72b4cc 72b4e0 # 6 instructions; loads
|
||||
spin main 732c8c 732ca0 # 6 instructions; loads
|
||||
spin main 732cd0 732ce4 # 6 instructions; loads
|
||||
spin main 732cf8 732d0c # 6 instructions; loads
|
||||
spin main 733be8 733bfc # 6 instructions; loads
|
||||
spin main 737fc4 737fd8 # 6 instructions; loads
|
||||
spin main 7395fc 739610 # 6 instructions; loads
|
||||
spin main 73a8b8 73a8cc # 6 instructions; loads
|
||||
spin main 73a8f8 73a90c # 6 instructions; loads
|
||||
spin main 73add0 73ade4 # 6 instructions; loads
|
||||
spin main 73aff4 73b008 # 6 instructions; loads
|
||||
spin main 73b074 73b088 # 6 instructions; loads
|
||||
spin main 73b3f0 73b404 # 6 instructions; loads
|
||||
spin main 73bd4c 73bd60 # 6 instructions; loads
|
||||
spin main 73d330 73d344 # 6 instructions; loads
|
||||
spin main 73ea0c 73ea20 # 6 instructions; loads
|
||||
spin main 7877ac 7877c0 # 6 instructions; loads
|
||||
spin main 78c7b0 78c7c4 # 6 instructions; loads
|
||||
spin main 78c8ac 78c8c0 # 6 instructions; loads
|
||||
spin main 78d5ec 78d600 # 6 instructions; loads
|
||||
spin main 78d7d0 78d7e4 # 6 instructions; loads
|
||||
spin main 78db70 78db84 # 6 instructions; loads
|
||||
spin main 78dbe0 78dbf4 # 6 instructions; loads
|
||||
spin main 78e298 78e2ac # 6 instructions; loads
|
||||
spin main 78ebb8 78ebcc # 6 instructions; loads
|
||||
spin main 791164 791178 # 6 instructions; loads
|
||||
spin main 7911b8 7911cc # 6 instructions; loads
|
||||
spin main 791c28 791c3c # 6 instructions; loads
|
||||
spin main 791cac 791cc0 # 6 instructions; loads
|
||||
spin main 7923dc 7923f0 # 6 instructions; loads
|
||||
spin main 7946f8 79470c # 6 instructions; loads
|
||||
spin main 79474c 794760 # 6 instructions; loads
|
||||
spin main 795dfc 795e10 # 6 instructions; loads
|
||||
spin main 795f58 795f6c # 6 instructions; loads
|
||||
spin main 79632c 796348 # 8 instructions; loads
|
||||
spin main 7a23ac 7a23c0 # 6 instructions; loads
|
||||
spin main 7a23d4 7a23e8 # 6 instructions; loads
|
||||
spin main 7a267c 7a2690 # 6 instructions; loads
|
||||
spin main 7a26d8 7a26ec # 6 instructions; loads
|
||||
spin main 7a3a5c 7a3a70 # 6 instructions; loads
|
||||
spin main 7aec90 7aeca4 # 6 instructions; loads
|
||||
spin main 7b5c70 7b5c84 # 6 instructions; loads
|
||||
spin main 7bc3b8 7bc3cc # 6 instructions; loads
|
||||
spin main 7bc60c 7bc620 # 6 instructions; loads
|
||||
spin main 7db040 7db054 # 6 instructions; loads
|
||||
spin main 7ddfb0 7ddfc4 # 6 instructions; loads
|
||||
spin main 809758 80976c # 6 instructions; loads
|
||||
spin main 825de4 825df8 # 6 instructions; loads
|
||||
spin main 825e68 825e7c # 6 instructions; loads
|
||||
spin main 825fb4 825fc8 # 6 instructions; loads
|
||||
spin main 826080 826094 # 6 instructions; loads
|
||||
spin main 828158 82816c # 6 instructions; loads
|
||||
spin main 838340 838354 # 6 instructions; loads
|
||||
spin main 842fbc 842fd0 # 6 instructions; loads
|
||||
spin main 8440e8 8440fc # 6 instructions; loads
|
||||
spin main 8464f4 846508 # 6 instructions; loads
|
||||
spin main 84cbb0 84cbc4 # 6 instructions; loads
|
||||
spin main 84cbf8 84cc0c # 6 instructions; loads
|
||||
spin main 84d430 84d444 # 6 instructions; loads
|
||||
spin main 85db98 85dbac # 6 instructions; loads
|
||||
spin main 85ed2c 85ed40 # 6 instructions; loads
|
||||
spin main 860d64 860d78 # 6 instructions; loads
|
||||
spin main 867f4c 868048 # 4 instructions; loads
|
||||
spin main 8876e0 8876f4 # 6 instructions; loads
|
||||
spin main 887c50 887c64 # 6 instructions; loads
|
||||
spin main 892ff4 893008 # 6 instructions; loads
|
||||
spin main 893448 89345c # 6 instructions; loads
|
||||
spin main 893a04 893a18 # 6 instructions; loads
|
||||
spin main 893b14 893b28 # 6 instructions; loads
|
||||
spin main 895210 895224 # 6 instructions; loads
|
||||
spin main 895238 89524c # 6 instructions; loads
|
||||
spin main 8b6b60 8b6b74 # 6 instructions; loads
|
||||
spin main 8b7ff0 8b8010 # 9 instructions; loads
|
||||
spin main 8ceed8 8ceeec # 6 instructions; loads
|
||||
spin main 8cf204 8cf218 # 6 instructions; loads
|
||||
spin main 8cf520 8cf534 # 6 instructions; loads
|
||||
spin main 8cf6b8 8cf6cc # 6 instructions; loads
|
||||
spin main 8cf940 8cf954 # 6 instructions; loads
|
||||
spin main 8cfb94 8cfba8 # 6 instructions; loads
|
||||
spin main 8e763c 8e764c # 5 instructions; loads
|
||||
spin main 8e7898 8e78c4 # 12 instructions; loads
|
||||
spin main 8e78d8 8e78e8 # 5 instructions; loads
|
||||
spin main 8e8114 8e8128 # 6 instructions; loads
|
||||
spin main 90750c 907520 # 6 instructions; loads
|
||||
spin main 907534 907548 # 6 instructions; loads
|
||||
spin main 90755c 907570 # 6 instructions; loads
|
||||
spin main 907584 907598 # 6 instructions; loads
|
||||
spin main 908a84 908a98 # 6 instructions; loads
|
||||
spin main 909250 909264 # 6 instructions; loads
|
||||
spin main 91b3f4 91b408 # 6 instructions; loads
|
||||
spin main 91b41c 91b430 # 6 instructions; loads
|
||||
spin main 91dc0c 91dc20 # 6 instructions; loads
|
||||
spin main 91dfbc 91dfd0 # 6 instructions; loads
|
||||
spin main 91e390 91e3a4 # 6 instructions; loads
|
||||
spin main 91e764 91e778 # 6 instructions; loads
|
||||
spin main 923cc4 923cd8 # 6 instructions; loads
|
||||
spin main 95517c 9551ac # 13 instructions; loads
|
||||
spin main 9551c0 9551d0 # 5 instructions; loads
|
||||
spin main 95f63c 95f66c # 13 instructions; loads
|
||||
spin main 95f680 95f690 # 5 instructions; loads
|
||||
spin main 96bb74 96bb84 # 5 instructions; loads
|
||||
spin main 97266c 972688 # 8 instructions; loads
|
||||
spin main 972738 972754 # 8 instructions; loads
|
||||
spin main 9b677c 9b6790 # 6 instructions; loads
|
||||
spin main 9d73b8 9d73cc # 6 instructions; loads
|
||||
spin main 9e10ac 9e10c0 # 6 instructions; loads
|
||||
spin main 9e9470 9e9484 # 6 instructions; loads
|
||||
spin main 9ed71c 9ed730 # 6 instructions; loads
|
||||
spin main 9f7adc 9f7af0 # 6 instructions; loads
|
||||
spin main 9f7b04 9f7b18 # 6 instructions; loads
|
||||
spin main 9f7b2c 9f7b40 # 6 instructions; loads
|
||||
spin main a06cd8 a06cec # 6 instructions; loads
|
||||
spin main a0cfe8 a0cffc # 6 instructions; loads
|
||||
spin main a2abc0 a2abd4 # 6 instructions; loads
|
||||
spin main a6d6f8 a6d70c # 6 instructions; loads
|
||||
spin main a6edec a6ee00 # 6 instructions; loads
|
||||
spin main a6ee30 a6ee44 # 6 instructions; loads
|
||||
spin main a6ee74 a6ee88 # 6 instructions; loads
|
||||
spin main a6f560 a6f574 # 6 instructions; loads
|
||||
spin main a7e134 a7e1bc # 35 instructions; loads
|
||||
spin main a84b24 a84b38 # 6 instructions; loads
|
||||
spin main a84e3c a84e50 # 6 instructions; loads
|
||||
spin main a84eec a84f00 # 6 instructions; loads
|
||||
spin main a84f8c a84fa0 # 6 instructions; loads
|
||||
spin main a8503c a85050 # 6 instructions; loads
|
||||
spin main ab8898 ab88ac # 6 instructions; loads
|
||||
spin main ac3cd8 ac3cec # 6 instructions; loads
|
||||
spin main ac3d64 ac3d78 # 6 instructions; loads
|
||||
spin main ac3fe4 ac3ff8 # 6 instructions; loads
|
||||
spin main ac40e4 ac40f8 # 6 instructions; loads
|
||||
spin main ac4740 ac4754 # 6 instructions; loads
|
||||
spin main ac4890 ac48a4 # 6 instructions; loads
|
||||
spin main ac5604 ac5618 # 6 instructions; loads
|
||||
spin main ac58e0 ac58f4 # 6 instructions; loads
|
||||
spin main ac798c ac79a0 # 6 instructions; loads
|
||||
spin main ac79b4 ac79c8 # 6 instructions; loads
|
||||
spin main ae567c ae5690 # 6 instructions; loads
|
||||
spin main ae6da0 ae6db4 # 6 instructions; loads
|
||||
spin main b1267c b12690 # 6 instructions; loads
|
||||
spin main b12d5c b12d70 # 6 instructions; loads
|
||||
spin main b15df0 b15e04 # 6 instructions; loads
|
||||
spin main b1afbc b1b014 # 7 instructions; loads
|
||||
spin main b2fa8c b2faa0 # 6 instructions; loads
|
||||
spin main b35374 b35388 # 6 instructions; loads
|
||||
spin main b386f4 b38708 # 6 instructions; loads
|
||||
spin main b3871c b38730 # 6 instructions; loads
|
||||
spin main b38744 b38758 # 6 instructions; loads
|
||||
spin main b38780 b38794 # 6 instructions; loads
|
||||
spin main b387a8 b387bc # 6 instructions; loads
|
||||
spin main b387d0 b387e4 # 6 instructions; loads
|
||||
spin main b53ce8 b53cfc # 6 instructions; loads
|
||||
spin main b53e04 b53e18 # 6 instructions; loads
|
||||
spin main b54178 b5418c # 6 instructions; loads
|
||||
spin main b54688 b5469c # 6 instructions; loads
|
||||
spin main b599f0 b59a04 # 6 instructions; loads
|
||||
spin main b59a18 b59a2c # 6 instructions; loads
|
||||
spin main b5f4ec b5f4fc # 5 instructions; loads
|
||||
spin main b6f988 b6f99c # 6 instructions; loads
|
||||
spin main b6faa4 b6fab8 # 6 instructions; loads
|
||||
spin main b6fe28 b6fe3c # 6 instructions; loads
|
||||
spin main b707b0 b707c4 # 6 instructions; loads
|
||||
spin main b70814 b70828 # 6 instructions; loads
|
||||
spin main b70974 b70988 # 6 instructions; loads
|
||||
spin main b70b08 b70b1c # 6 instructions; loads
|
||||
spin main b74104 b74118 # 6 instructions; loads
|
||||
spin main b7426c b74280 # 6 instructions; loads
|
||||
spin main b7e57c b7e590 # 6 instructions; loads
|
||||
spin main b940fc b94110 # 6 instructions; loads
|
||||
spin main b973a0 b973b4 # 6 instructions; loads
|
||||
spin main b97998 b979ac # 6 instructions; loads
|
||||
spin main b97be4 b97bf8 # 6 instructions; loads
|
||||
spin main bbaaf4 bbab08 # 6 instructions; loads
|
||||
spin main bbab1c bbab30 # 6 instructions; loads
|
||||
spin main bc1fd8 bc1fec # 6 instructions; loads
|
||||
spin main bc2078 bc208c # 6 instructions; loads
|
||||
spin main bc20a0 bc20b4 # 6 instructions; loads
|
||||
spin main bc2168 bc217c # 6 instructions; loads
|
||||
spin main be3d24 be3d38 # 6 instructions; loads
|
||||
spin main bf9fc4 bf9fd8 # 6 instructions; loads
|
||||
spin main bfb184 bfb198 # 6 instructions; loads
|
||||
spin main c1e5c0 c1e5d4 # 6 instructions; loads
|
||||
spin main c4657c c46590 # 6 instructions; loads
|
||||
spin main c50574 c50588 # 6 instructions; loads
|
||||
spin main c51810 c51824 # 6 instructions; loads
|
||||
spin main cb300c cb3020 # 6 instructions; loads
|
||||
spin main cb3f68 cb3f7c # 6 instructions; loads
|
||||
spin main cb3fac cb3fc0 # 6 instructions; loads
|
||||
spin main cb4694 cb46a8 # 6 instructions; loads
|
||||
spin main cb46d8 cb46ec # 6 instructions; loads
|
||||
spin main cb48c4 cb48d8 # 6 instructions; loads
|
||||
spin main cb59ec cb5a00 # 6 instructions; loads
|
||||
spin main cb6f68 cb6f7c # 6 instructions; loads
|
||||
spin main cba458 cba46c # 6 instructions; loads
|
||||
spin main cce918 cce92c # 6 instructions; loads
|
||||
spin main cd0144 cd0150 cd019c cd01b4 # 29 instructions; loads
|
||||
spin main cd1fc0 cd1fd4 # 6 instructions; loads
|
||||
spin main cf3c94 cf3ca8 # 6 instructions; loads
|
||||
spin main d0b2a8 d0b2bc # 6 instructions; loads
|
||||
spin main d105b4 d105c8 # 6 instructions; loads
|
||||
spin main d11018 d1102c # 6 instructions; loads
|
||||
spin main d1109c d110b0 # 6 instructions; loads
|
||||
spin main d11148 d1115c # 6 instructions; loads
|
||||
spin main d113a0 d113b4 # 6 instructions; loads
|
||||
spin main d113c8 d113dc # 6 instructions; loads
|
||||
spin main d113fc d11410 # 6 instructions; loads
|
||||
spin main d11644 d11658 # 6 instructions; loads
|
||||
spin main d12028 d12044 # 8 instructions; loads
|
||||
spin main d129a8 d129bc # 6 instructions; loads
|
||||
spin main d12d80 d12d94 # 6 instructions; loads
|
||||
spin main d12dc8 d12ddc # 6 instructions; loads
|
||||
spin main d12df0 d12e04 # 6 instructions; loads
|
||||
spin main d12e18 d12e2c # 6 instructions; loads
|
||||
spin main d12e84 d12e98 # 6 instructions; loads
|
||||
spin main d12eb0 d12ec4 # 6 instructions; loads
|
||||
spin main d12ed8 d12eec # 6 instructions; loads
|
||||
spin main d12fe0 d12ff4 # 6 instructions; loads
|
||||
spin main d17248 d1725c # 6 instructions; loads
|
||||
spin main d17f58 d17f6c # 6 instructions; loads
|
||||
spin main d189d0 d189e4 # 6 instructions; loads
|
||||
spin main d18bac d18bc0 # 6 instructions; loads
|
||||
spin main d2d2a0 d2d2b4 # 6 instructions; loads
|
||||
spin main d2d430 d2d444 # 6 instructions; loads
|
||||
spin main d337e4 d337f8 # 6 instructions; loads
|
||||
spin main d33e1c d33e30 # 6 instructions; loads
|
||||
spin main d34178 d3418c # 6 instructions; loads
|
||||
spin main d34278 d3428c # 6 instructions; loads
|
||||
spin main d3472c d34740 # 6 instructions; loads
|
||||
spin main d3486c d34880 # 6 instructions; loads
|
||||
spin main d35a9c d35ab0 # 6 instructions; loads
|
||||
spin main d365a8 d365bc # 6 instructions; loads
|
||||
spin main d365d4 d365e8 # 6 instructions; loads
|
||||
spin main d38898 d388ac # 6 instructions; loads
|
||||
spin main d3d6c0 d3d6d4 # 6 instructions; loads
|
||||
spin main d3d6e8 d3d6fc # 6 instructions; loads
|
||||
spin main d3f05c d3f070 # 6 instructions; loads
|
||||
spin main d54c90 d54ca4 # 6 instructions; loads
|
||||
spin main d54e14 d54e28 # 6 instructions; loads
|
||||
spin main d55940 d55954 # 6 instructions; loads
|
||||
spin main d56848 d5685c # 6 instructions; loads
|
||||
spin main d5ef1c d5ef30 # 6 instructions; loads
|
||||
spin main d5ef80 d5ef94 # 6 instructions; loads
|
||||
spin main d66218 d6622c # 6 instructions; loads
|
||||
spin main d69544 d69558 # 6 instructions; loads
|
||||
spin main d6956c d69580 # 6 instructions; loads
|
||||
spin main d7663c d76650 # 6 instructions; loads
|
||||
spin main d7b1e4 d7b1f8 # 6 instructions; loads
|
||||
spin main d7ca84 d7caa0 # 8 instructions; loads
|
||||
spin main d808f4 d80908 # 6 instructions; loads
|
||||
spin main d82a8c d82aa0 # 6 instructions; loads
|
||||
spin main d82c10 d82c24 # 6 instructions; loads
|
||||
spin main d85fc8 d86000 # 8 instructions; loads
|
||||
spin main d86030 d86068 # 8 instructions; loads
|
||||
spin main d8bb9c d8bbb0 # 6 instructions; loads
|
||||
spin main d8be7c d8be90 # 6 instructions; loads
|
||||
spin main d8dfe4 d8dff8 # 6 instructions; loads
|
||||
spin main d8f9d4 d8f9e8 # 6 instructions; loads
|
||||
spin main d90a58 d90a6c # 6 instructions; loads
|
||||
spin main d90e74 d90e88 # 6 instructions; loads
|
||||
spin main d92afc d92b10 # 6 instructions; loads
|
||||
spin main d93320 d93334 # 6 instructions; loads
|
||||
spin main d93b10 d93b24 # 6 instructions; loads
|
||||
spin main d9cbe8 d9cbfc # 6 instructions; loads
|
||||
spin main d9fe88 d9fe9c # 6 instructions; loads
|
||||
spin main dc8368 dc837c # 6 instructions; loads
|
||||
spin main de3ec0 de3ed4 # 6 instructions; loads
|
||||
spin main dec308 dec31c # 6 instructions; loads
|
||||
spin main dfe0bc dfe0d0 # 6 instructions; loads
|
||||
spin main e3ef08 e3ef1c # 6 instructions; loads
|
||||
spin main e3f1ec e3f200 # 6 instructions; loads
|
||||
spin main e3f4d0 e3f4e4 # 6 instructions; loads
|
||||
spin main e3f7b4 e3f7c8 # 6 instructions; loads
|
||||
spin main e42c54 e42c68 # 6 instructions; loads
|
||||
spin main e4a83c e4a850 # 6 instructions; loads
|
||||
spin main e4ab60 e4ab74 # 6 instructions; loads
|
||||
spin main e5413c e54150 # 6 instructions; loads
|
||||
spin main e56300 e56314 # 6 instructions; loads
|
||||
spin main e599b8 e599cc # 6 instructions; loads
|
||||
spin main e59cc4 e59cd8 # 6 instructions; loads
|
||||
spin main e59db0 e59dc4 # 6 instructions; loads
|
||||
spin main e5dea0 e5deb4 # 6 instructions; loads
|
||||
spin main e5eb04 e5eb18 # 6 instructions; loads
|
||||
spin main e602c4 e602d8 # 6 instructions; loads
|
||||
spin main e64d84 e64d98 # 6 instructions; loads
|
||||
spin main e67d5c e67d70 # 6 instructions; loads
|
||||
spin main e686b8 e686cc # 6 instructions; loads
|
||||
spin main e6bd64 e6bd78 # 6 instructions; loads
|
||||
spin main e75788 e7579c # 6 instructions; loads
|
||||
spin main e7a790 e7a7a4 # 6 instructions; loads
|
||||
spin main e892bc e892d0 # 6 instructions; loads
|
||||
spin main e892f4 e89308 # 6 instructions; loads
|
||||
spin main e894b4 e894c8 # 6 instructions; loads
|
||||
spin main e8959c e895b0 # 6 instructions; loads
|
||||
spin main e92610 e92624 # 6 instructions; loads
|
||||
spin main e99480 e99494 # 6 instructions; loads
|
||||
spin main e995d4 e995e8 # 6 instructions; loads
|
||||
spin main e99b84 e99b98 # 6 instructions; loads
|
||||
spin main e9a670 e9a684 # 6 instructions; loads
|
||||
spin main e9a8c4 e9a8d8 # 6 instructions; loads
|
||||
spin main e9aa38 e9aa4c # 6 instructions; loads
|
||||
spin main e9abac e9abc0 # 6 instructions; loads
|
||||
spin main e9ae58 e9ae6c # 6 instructions; loads
|
||||
spin main e9b338 e9b34c # 6 instructions; loads
|
||||
spin main e9b4a4 e9b4b8 # 6 instructions; loads
|
||||
spin main e9bc7c e9bc90 # 6 instructions; loads
|
||||
spin main e9c268 e9c27c # 6 instructions; loads
|
||||
spin main e9c294 e9c2a8 # 6 instructions; loads
|
||||
spin main e9d21c e9d230 # 6 instructions; loads
|
||||
spin main e9d5e8 e9d5fc # 6 instructions; loads
|
||||
spin main e9d610 e9d624 # 6 instructions; loads
|
||||
spin main e9f978 e9f98c # 6 instructions; loads
|
||||
spin main e9f9b8 e9f9cc # 6 instructions; loads
|
||||
spin main e9f9e0 e9f9f4 # 6 instructions; loads
|
||||
spin main e9fa08 e9fa1c # 6 instructions; loads
|
||||
spin main e9ffec ea0000 # 6 instructions; loads
|
||||
spin main ea0014 ea0028 # 6 instructions; loads
|
||||
spin main ea1454 ea1468 # 6 instructions; loads
|
||||
spin main eacd8c eacda0 # 6 instructions; loads
|
||||
spin main eb8ec0 eb8ed4 # 6 instructions; loads
|
||||
spin main ed2f5c ed2f70 # 6 instructions; loads
|
||||
spin main ed34f0 ed3504 # 6 instructions; loads
|
||||
spin main ed3dc0 ed3dd4 # 6 instructions; loads
|
||||
spin main ed3df0 ed3e04 # 6 instructions; loads
|
||||
spin main ed43b4 ed43c8 # 6 instructions; loads
|
||||
spin main ed43e4 ed43f8 # 6 instructions; loads
|
||||
spin main ed7870 ed7878 # 3 instructions; loads
|
||||
spin main ed7880 ed7884 # 2 instructions; loads
|
||||
spin main ed78ac ed78b4 # 3 instructions; loads
|
||||
spin main ed85a8 ed85bc # 6 instructions; loads
|
||||
spin main ed9ff8 eda00c # 6 instructions; loads
|
||||
spin main eda1bc eda1d0 # 6 instructions; loads
|
||||
spin main f0dcc4 f0dcd8 # 6 instructions; loads
|
||||
spin main f0e598 f0e5ac # 6 instructions; loads
|
||||
spin main f11920 f11934 # 6 instructions; loads
|
||||
spin main f11f7c f11f90 # 6 instructions; loads
|
||||
spin main f11fa8 f11fbc # 6 instructions; loads
|
||||
spin main f17f98 f17fac # 6 instructions; loads
|
||||
spin main f1c328 f1c33c # 6 instructions; loads
|
||||
spin main f2403c f24050 # 6 instructions; loads
|
||||
spin main f36b5c f36b70 # 6 instructions; loads
|
||||
spin main f36b84 f36b98 # 6 instructions; loads
|
||||
spin main f36dd4 f36de8 # 6 instructions; loads
|
||||
spin main f36e68 f36e7c # 6 instructions; loads
|
||||
spin main f36e90 f36ea4 # 6 instructions; loads
|
||||
spin main f36eb8 f36ecc # 6 instructions; loads
|
||||
spin main f3b5dc f3b5f0 # 6 instructions; loads
|
||||
spin main f3b7e8 f3b7fc # 6 instructions; loads
|
||||
spin main f3c3b4 f3c3c8 # 6 instructions; loads
|
||||
spin main f3dcc8 f3dcdc # 6 instructions; loads
|
||||
spin main f4181c f41830 # 6 instructions; loads
|
||||
spin main f41978 f4198c # 6 instructions; loads
|
||||
spin main f41ad4 f41ae8 # 6 instructions; loads
|
||||
spin main f41c30 f41c44 # 6 instructions; loads
|
||||
spin main f46af0 f46b04 # 6 instructions; loads
|
||||
spin main f487d8 f487ec # 6 instructions; loads
|
||||
spin main f4f108 f4f11c # 6 instructions; loads
|
||||
spin main f4f7f4 f4f808 # 6 instructions; loads
|
||||
spin main f4f880 f4f894 # 6 instructions; loads
|
||||
spin main f53f9c f53fb0 # 6 instructions; loads
|
||||
spin main f5df2c f5df40 # 6 instructions; loads
|
||||
spin main f5f458 f5f46c # 6 instructions; loads
|
||||
spin main f6f51c f6f530 # 6 instructions; loads
|
||||
spin main f6f840 f6f854 # 6 instructions; loads
|
||||
spin main f70270 f70284 # 6 instructions; loads
|
||||
spin main f70294 f702a8 # 6 instructions; loads
|
||||
spin main f70828 f7083c # 6 instructions; loads
|
||||
spin main f7947c f79490 # 6 instructions; loads
|
||||
spin main f794a4 f794b8 # 6 instructions; loads
|
||||
spin main f7e318 f7e32c # 6 instructions; loads
|
||||
spin main f8db54 f8db68 # 6 instructions; loads
|
||||
spin main f8f9f4 f8fa08 # 6 instructions; loads
|
||||
spin main f90178 f9018c # 6 instructions; loads
|
||||
spin main f96a00 f96a14 # 6 instructions; loads
|
||||
spin main f96c40 f96c54 # 6 instructions; loads
|
||||
spin main f96e64 f96e78 # 6 instructions; loads
|
||||
spin main f96fdc f96ff0 # 6 instructions; loads
|
||||
spin main f97158 f9716c # 6 instructions; loads
|
||||
spin main fa26d4 fa26e8 # 6 instructions; loads
|
||||
spin main fa5a18 fa5a2c # 6 instructions; loads
|
||||
spin main faa880 faa894 # 6 instructions; loads
|
||||
spin main faab1c faab30 # 6 instructions; loads
|
||||
spin main fabc28 fabc3c # 6 instructions; loads
|
||||
spin main fac5d0 fac5e4 # 6 instructions; loads
|
||||
spin main faece4 faecf8 # 6 instructions; loads
|
||||
spin main faf014 faf028 # 6 instructions; loads
|
||||
spin main fb4494 fb44b0 # 8 instructions; loads
|
||||
spin main fb68f0 fb6904 # 6 instructions; loads
|
||||
spin main fb7130 fb7144 # 6 instructions; loads
|
||||
spin main fb7590 fb75a4 # 6 instructions; loads
|
||||
spin main fb75f8 fb760c # 6 instructions; loads
|
||||
spin main fb8ea4 fb8f90 # 4 instructions; loads
|
||||
spin main fb9598 fb9620 # 4 instructions; loads
|
||||
spin main fbfb8c fbfba0 # 6 instructions; loads
|
||||
spin main fcbea0 fcbeb4 # 6 instructions; loads
|
||||
spin main fcc110 fcc124 # 6 instructions; loads
|
||||
spin main fd281c fd2830 # 6 instructions; loads
|
||||
spin main fda1c4 fda1d8 # 6 instructions; loads
|
||||
spin main fe7c74 fe7c88 # 6 instructions; loads
|
||||
spin main fe802c fe8040 # 6 instructions; loads
|
||||
spin main fe837c fe8390 # 6 instructions; loads
|
||||
spin main fe867c fe8690 # 6 instructions; loads
|
||||
spin main fe8bd4 fe8be8 # 6 instructions; loads
|
||||
spin main fe8f6c fe8f80 # 6 instructions; loads
|
||||
spin main fe92ec fe9300 # 6 instructions; loads
|
||||
spin main fe9360 fe9374 # 6 instructions; loads
|
||||
spin main fea288 fea29c # 6 instructions; loads
|
||||
spin main fea5d4 fea5e8 # 6 instructions; loads
|
||||
spin main feaa58 feaa6c # 6 instructions; loads
|
||||
spin main feaca4 feacb8 # 6 instructions; loads
|
||||
spin main feba88 feba9c # 6 instructions; loads
|
||||
spin main febb20 febb34 # 6 instructions; loads
|
||||
spin main fecce4 feccf8 # 6 instructions; loads
|
||||
spin main fed1f8 fed20c # 6 instructions; loads
|
||||
spin main fed830 fed844 # 6 instructions; loads
|
||||
spin main fed8ec fed900 # 6 instructions; loads
|
||||
spin main fed9a8 fed9bc # 6 instructions; loads
|
||||
spin main feda64 feda78 # 6 instructions; loads
|
||||
spin main fee228 fee23c # 6 instructions; loads
|
||||
spin main ff0314 ff0328 # 6 instructions; loads
|
||||
spin main ff05c4 ff05d8 # 6 instructions; loads
|
||||
spin main ff08b0 ff08c4 # 6 instructions; loads
|
||||
spin main ff0b64 ff0b78 # 6 instructions; loads
|
||||
spin main ff0e28 ff0e3c # 6 instructions; loads
|
||||
spin main ff112c ff1140 # 6 instructions; loads
|
||||
spin main ff118c ff11a0 # 6 instructions; loads
|
||||
spin main ff26d0 ff26ec # 8 instructions; loads
|
||||
spin main ff38e0 ff38f4 # 6 instructions; loads
|
||||
spin main ff3920 ff3934 # 6 instructions; loads
|
||||
spin main ff3960 ff3974 # 6 instructions; loads
|
||||
spin main ff39a0 ff39b4 # 6 instructions; loads
|
||||
spin main ff39e0 ff39f4 # 6 instructions; loads
|
||||
spin main ff65b0 ff65c4 # 6 instructions; loads
|
||||
spin main ff96ec ff9700 # 6 instructions; loads
|
||||
spin main 1017c00 1017c14 # 6 instructions; loads
|
||||
spin main 101a9e4 101a9f8 # 6 instructions; loads
|
||||
spin main 101c0b8 101c0cc # 6 instructions; loads
|
||||
spin main 10242b0 10242c4 # 6 instructions; loads
|
||||
spin main 102bc78 102bcc0 # 3 instructions; loads
|
||||
spin main 1036db4 1036dc8 # 6 instructions; loads
|
||||
spin main 1042cf0 1042cf8 # 3 instructions; loads
|
||||
spin main 1042d00 1042d04 # 2 instructions; loads
|
||||
spin main 1042d6c 1042d74 # 3 instructions; loads
|
||||
spin main 10587c4 10587d8 # 6 instructions; loads
|
||||
spin main 1059808 105981c # 6 instructions; loads
|
||||
spin main 1059d2c 1059d40 # 6 instructions; loads
|
||||
spin main 105beb0 105bec4 # 6 instructions; loads
|
||||
spin main 105e700 105e714 # 6 instructions; loads
|
||||
spin main 1066350 1066364 # 6 instructions; loads
|
||||
spin main 1075340 1075354 # 6 instructions; loads
|
||||
spin main 1086b00 1086b14 # 6 instructions; loads
|
||||
spin main 1086b48 1086b5c # 6 instructions; loads
|
||||
spin main 10a671c 10a6730 # 6 instructions; loads
|
||||
spin main 10a9640 10a9654 # 6 instructions; loads
|
||||
spin main 10ab2e8 10ab2fc # 6 instructions; loads
|
||||
spin main 10ab310 10ab324 # 6 instructions; loads
|
||||
spin main 10af3b8 10af3cc # 6 instructions; loads
|
||||
spin main 10af9a8 10af9bc # 6 instructions; loads
|
||||
spin main 10b6d0c 10b6d20 # 6 instructions; loads
|
||||
spin main 10c765c 10c7670 # 6 instructions; loads
|
||||
spin main 10d588c 10d58a0 # 6 instructions; loads
|
||||
spin main 10dabd4 10dabe8 # 6 instructions; loads
|
||||
spin main 10dafa8 10dafbc # 6 instructions; loads
|
||||
spin main 10db6e0 10db6f4 # 6 instructions; loads
|
||||
spin main 10dbc78 10dbc8c # 6 instructions; loads
|
||||
spin main 10de660 10de674 # 6 instructions; loads
|
||||
spin main 10ebcac 10ebcc0 # 6 instructions; loads
|
||||
spin main 10ebd28 10ebd3c # 6 instructions; loads
|
||||
spin main 10f3274 10f3288 # 6 instructions; loads
|
||||
spin main 10f329c 10f32b0 # 6 instructions; loads
|
||||
spin main 10f9384 10f94b8 # 4 instructions; loads
|
||||
spin main 10f9408 10f949c # 4 instructions; loads
|
||||
spin main 1106318 110632c # 6 instructions; loads
|
||||
spin main 1106860 1106874 # 6 instructions; loads
|
||||
spin main 1111040 1111054 # 6 instructions; loads
|
||||
spin main 1111b8c 1111ba0 # 6 instructions; loads
|
||||
spin main 1111dec 1111e00 # 6 instructions; loads
|
||||
spin main 111256c 1112580 # 6 instructions; loads
|
||||
spin main 1115ca4 1115cb8 # 6 instructions; loads
|
||||
spin main 1117c88 1117c9c # 6 instructions; loads
|
||||
spin main 111b654 111b668 # 6 instructions; loads
|
||||
spin main 113bf9c 113bfb0 # 6 instructions; loads
|
||||
spin main 113bfc4 113bfd8 # 6 instructions; loads
|
||||
spin main 11404a0 11404b4 # 6 instructions; loads
|
||||
spin main 114f7e8 114f7fc # 6 instructions; loads
|
||||
spin main 115891c 1158930 # 6 instructions; loads
|
||||
spin main 1159860 1159874 # 6 instructions; loads
|
||||
spin main 116b594 116b5a8 # 6 instructions; loads
|
||||
spin main 116b9ec 116ba00 # 6 instructions; loads
|
||||
spin main 116ba14 116ba28 # 6 instructions; loads
|
||||
spin main 1173168 117317c # 6 instructions; loads
|
||||
spin main 1178e1c 1178e30 # 6 instructions; loads
|
||||
spin main 117af24 117af38 # 6 instructions; loads
|
||||
spin main 118444c 1184460 # 6 instructions; loads
|
||||
spin main 1184828 118483c # 6 instructions; loads
|
||||
spin main 1185b8c 1185ba0 # 6 instructions; loads
|
||||
spin main 1186c48 1186c5c # 6 instructions; loads
|
||||
spin main 118ba50 118ba64 # 6 instructions; loads
|
||||
spin main 118ca3c 118ca50 # 6 instructions; loads
|
||||
spin main 1191f94 1191fa8 # 6 instructions; loads
|
||||
spin main 1191fbc 1191fd0 # 6 instructions; loads
|
||||
spin main 1192b18 1192b2c # 6 instructions; loads
|
||||
spin main 119b934 119b948 # 6 instructions; loads
|
||||
spin main 119d40c 119d420 # 6 instructions; loads
|
||||
spin main 11b1d80 11b1d94 # 6 instructions; loads
|
||||
spin main 11b4ca0 11b4cb4 # 6 instructions; loads
|
||||
spin main 11b6300 11b6314 # 6 instructions; loads
|
||||
spin main 11b8e58 11b8e6c # 6 instructions; loads
|
||||
spin main 11bea60 11bea74 # 6 instructions; loads
|
||||
spin main 11d8218 11d822c # 6 instructions; loads
|
||||
spin main 11db090 11db0a4 # 6 instructions; loads
|
||||
spin main 11db0b8 11db0cc # 6 instructions; loads
|
||||
spin main 1201688 120169c # 6 instructions; loads
|
||||
spin main 12048a4 12048b8 # 6 instructions; loads
|
||||
spin main 12048cc 12048e0 # 6 instructions; loads
|
||||
spin main 1205868 120587c # 6 instructions; loads
|
||||
spin main 1206350 1206364 # 6 instructions; loads
|
||||
spin main 1226308 122631c # 6 instructions; loads
|
||||
spin main 1226898 12268ac # 6 instructions; loads
|
||||
spin main 12374a8 12374bc # 6 instructions; loads
|
||||
spin main 1252260 1252274 # 6 instructions; loads
|
||||
spin main 1252688 125269c # 6 instructions; loads
|
||||
spin main 1252968 125297c # 6 instructions; loads
|
||||
spin main 1271260 1271274 # 6 instructions; loads
|
||||
spin main 127b710 127b724 # 6 instructions; loads
|
||||
spin main 127b778 127b78c # 6 instructions; loads
|
||||
spin main 127b928 127b93c # 6 instructions; loads
|
||||
spin main 127b954 127b968 # 6 instructions; loads
|
||||
spin main 127b980 127b994 # 6 instructions; loads
|
||||
spin main 127b9ac 127b9c0 # 6 instructions; loads
|
||||
spin main 127c150 127c164 # 6 instructions; loads
|
||||
spin main 127c178 127c18c # 6 instructions; loads
|
||||
spin main 12816c8 12816dc # 6 instructions; loads
|
||||
spin main 1282010 1282024 # 6 instructions; loads
|
||||
spin main 1282078 128208c # 6 instructions; loads
|
||||
spin main 1285674 1285688 # 6 instructions; loads
|
||||
spin main 12877c8 12877dc # 6 instructions; loads
|
||||
spin main 128dd24 128dd38 # 6 instructions; loads
|
||||
spin main 128f04c 128f060 # 6 instructions; loads
|
||||
spin main 12af6ac 12af6c0 # 6 instructions; loads
|
||||
spin main 12af6d4 12af6e8 # 6 instructions; loads
|
||||
spin main 12ba674 12ba688 # 6 instructions; loads
|
||||
spin main 12cc354 12cc368 # 6 instructions; loads
|
||||
spin main 12fc134 12fc148 # 6 instructions; loads
|
||||
spin main 12fc798 12fc7ac # 6 instructions; loads
|
||||
spin main 13098cc 13098e0 # 6 instructions; loads
|
||||
spin main 130ce14 130cef4 # 11 instructions; loads
|
||||
spin main 1312798 13127ac # 6 instructions; loads
|
||||
spin main 131363c 1313650 # 6 instructions; loads
|
||||
spin main 1313900 1313914 # 6 instructions; loads
|
||||
spin main 131b4c8 131b4dc # 6 instructions; loads
|
||||
spin main 134c220 134c234 # 6 instructions; loads
|
||||
spin main 13e7d68 13e7d7c # 6 instructions; loads
|
||||
spin main 13e7f00 13e7f14 # 6 instructions; loads
|
||||
spin main 1571e58 1571e6c # 6 instructions; loads
|
||||
spin main 1578834 1578848 # 6 instructions; loads
|
||||
spin main 1585d04 1585d18 # 6 instructions; loads
|
||||
spin main 1587128 158713c # 6 instructions; loads
|
||||
spin main 1587150 1587164 # 6 instructions; loads
|
||||
spin main 158ec94 158eca8 # 6 instructions; loads
|
||||
spin main 158f7d4 158f7e8 # 6 instructions; loads
|
||||
spin main 158fab0 158fac4 # 6 instructions; loads
|
||||
spin main 158fad8 158faec # 6 instructions; loads
|
||||
spin main 1590c38 1590c4c # 6 instructions; loads
|
||||
spin main 15a8180 15a8194 # 6 instructions; loads
|
||||
spin main 15a8618 15a862c # 6 instructions; loads
|
||||
spin main 15a8720 15a8734 # 6 instructions; loads
|
||||
spin main 15a8a38 15a8a4c # 6 instructions; loads
|
||||
spin main 15c4eb8 15c4ecc # 6 instructions; loads
|
||||
spin main 15d8974 15d8988 # 6 instructions; loads
|
||||
spin main 15d9f60 15d9f74 # 6 instructions; loads
|
||||
spin main 15da008 15da01c # 6 instructions; loads
|
||||
spin main 15df528 15df53c # 6 instructions; loads
|
||||
spin main 15df668 15df67c # 6 instructions; loads
|
||||
spin main 15df690 15df6a4 # 6 instructions; loads
|
||||
spin main 15f7dfc 15f7e10 # 6 instructions; loads
|
||||
spin main 15f8360 15f8374 # 6 instructions; loads
|
||||
spin main 15f98a0 15f98b4 # 6 instructions; loads
|
||||
spin main 1608f04 1608f18 # 6 instructions; loads
|
||||
spin main 161523c 1615250 # 6 instructions; loads
|
||||
spin main 161966c 1619680 # 6 instructions; loads
|
||||
spin main 16196bc 16196d0 # 6 instructions; loads
|
||||
spin main 161a810 161a824 # 6 instructions; loads
|
||||
spin main 1625758 162576c # 6 instructions; loads
|
||||
spin main 1627da8 1627dbc # 6 instructions; loads
|
||||
spin main 1628534 1628548 # 6 instructions; loads
|
||||
spin main 162ce60 162ce74 # 6 instructions; loads
|
||||
spin main 1639828 163983c # 6 instructions; loads
|
||||
spin main 1641574 1641588 # 6 instructions; loads
|
||||
spin main 1643838 164384c # 6 instructions; loads
|
||||
spin main 16496b4 16496bc # 3 instructions; loads
|
||||
spin main 16496c4 16496c8 # 2 instructions; loads
|
||||
spin main 16496fc 1649704 # 3 instructions; loads
|
||||
spin main 1691fa4 1691fb8 # 6 instructions; loads
|
||||
spin main 16cc754 16cc768 # 6 instructions; loads
|
||||
spin main 172da0c 172da20 # 6 instructions; loads
|
||||
spin main 1737834 1737848 # 6 instructions; loads
|
||||
spin main 1737df8 1737e0c # 6 instructions; loads
|
||||
spin main 1790da0 1790db4 # 6 instructions; loads
|
||||
spin main 1922fec 1923000 # 6 instructions; loads
|
||||
spin main 1924710 1924724 # 6 instructions; loads
|
||||
spin main 1953798 19537a0 # 3 instructions; loads
|
||||
spin main 19537a8 19537ac # 2 instructions; loads
|
||||
spin main 1953830 1953838 # 3 instructions; loads
|
||||
spin main 195391c 1953924 # 3 instructions; loads
|
||||
spin main 195392c 1953930 # 2 instructions; loads
|
||||
spin main 19539d8 19539e0 # 3 instructions; loads
|
||||
spin main 1966130 1966138 # 3 instructions; loads
|
||||
spin main 1966140 1966144 # 2 instructions; loads
|
||||
spin main 1966168 1966170 # 3 instructions; loads
|
||||
spin main 19661a0 19661a8 # 3 instructions; loads
|
||||
spin main 19661b0 19661b4 # 2 instructions; loads
|
||||
spin main 19661dc 19661e4 # 3 instructions; loads
|
||||
spin main 19d6938 19d694c # 6 instructions; loads
|
||||
spin main 1a7ce6c 1a7ce7c # 5 instructions; loads
|
||||
spin main 1b5662c 1b56640 # 6 instructions; loads
|
||||
spin main 1b566e8 1b566fc # 6 instructions; loads
|
||||
spin main 1b567a4 1b567b8 # 6 instructions; loads
|
||||
spin main 1b56da4 1b56db8 # 6 instructions; loads
|
||||
spin main 1b56e60 1b56e74 # 6 instructions; loads
|
||||
spin main 1b56f1c 1b56f30 # 6 instructions; loads
|
||||
spin main 1d34e90 1d34ea4 # 6 instructions; loads
|
||||
spin main 1df2cac 1df2cb8 # 4 instructions; loads
|
||||
spin main 21dc108 21dc130 # 4 instructions; loads
|
||||
spin main 221fe50 221fe6c # 8 instructions; loads
|
||||
spin main 2227d40 2227d48 # 3 instructions; loads
|
||||
spin main 2227dc8 2227dd0 # 3 instructions; loads
|
||||
spin main 2227e58 2227e80 # 3 instructions; loads
|
||||
spin main 222ed8c 222ed9c # 5 instructions; loads
|
||||
spin main 2255970 2255978 # 3 instructions; loads
|
||||
spin main 2255980 2255984 # 2 instructions; loads
|
||||
spin main 2255a0c 2255a14 # 3 instructions; loads
|
||||
spin main 2255a98 2255aa0 # 3 instructions; loads
|
||||
spin main 2255aa8 2255aac # 2 instructions; loads
|
||||
spin main 2255ac4 2255acc # 3 instructions; loads
|
||||
spin main 22aeafc 22aeb10 # 6 instructions; loads
|
||||
spin main 22aec60 22aec74 # 6 instructions; loads
|
||||
spin main 22bd7bc 22bd7e0 # 4 instructions; loads
|
||||
spin main 22bd8ac 22bd8b8 # 4 instructions; loads
|
||||
spin main 23352a4 23352b8 # 6 instructions; loads
|
||||
spin main 2406890 2406898 # 3 instructions; loads
|
||||
spin main 24068a0 24068a4 # 2 instructions; loads
|
||||
spin main 2406920 2406928 # 3 instructions; loads
|
||||
spin main 240715c 2407164 # 3 instructions; loads
|
||||
spin main 240716c 2407170 # 2 instructions; loads
|
||||
spin main 24071dc 24071e4 # 3 instructions; loads
|
||||
spin main 240767c 2407684 # 3 instructions; loads
|
||||
spin main 240768c 2407690 # 2 instructions; loads
|
||||
spin main 240771c 2407724 # 3 instructions; loads
|
||||
spin main 2407860 2407868 # 3 instructions; loads
|
||||
spin main 2407870 2407874 # 2 instructions; loads
|
||||
spin main 24078c8 24078d0 # 3 instructions; loads
|
||||
spin main 2407914 240791c # 3 instructions; loads
|
||||
spin main 2407924 2407928 # 2 instructions; loads
|
||||
spin main 24079dc 24079e4 # 3 instructions; loads
|
||||
spin main 24079ec 24079f0 # 2 instructions; loads
|
||||
spin main 2407a30 2407a38 # 3 instructions; loads
|
||||
spin main 2407a60 2407a68 # 3 instructions; loads
|
||||
spin main 2407b54 2407b5c # 3 instructions; loads
|
||||
spin main 2407b64 2407b68 # 2 instructions; loads
|
||||
spin main 2407c48 2407c50 # 3 instructions; loads
|
||||
spin main 2407cdc 2407ce4 # 3 instructions; loads
|
||||
spin main 2407cec 2407cf0 # 2 instructions; loads
|
||||
spin main 2407da4 2407dac # 3 instructions; loads
|
||||
spin main 2407dc4 2407dc8 # 2 instructions; loads
|
||||
spin main 2407e68 2407e70 # 3 instructions; loads
|
||||
spin main 2407e98 2407ea0 # 3 instructions; loads
|
||||
spin main 2407ee0 2407ee8 # 3 instructions; loads
|
||||
spin main 2407ef0 2407ef4 # 2 instructions; loads
|
||||
spin main 2407f18 2407f20 # 3 instructions; loads
|
||||
spin main 2407f64 2407f6c # 3 instructions; loads
|
||||
spin main 2407f74 2407f78 # 2 instructions; loads
|
||||
spin main 2407fa0 2407fa8 # 3 instructions; loads
|
||||
spin main 24084fc 2408504 # 3 instructions; loads
|
||||
spin main 240850c 2408510 # 2 instructions; loads
|
||||
spin main 2408534 240853c # 3 instructions; loads
|
||||
spin main 2408c68 2408c70 # 3 instructions; loads
|
||||
spin main 2408c78 2408c7c # 2 instructions; loads
|
||||
spin main 2408ca0 2408ca8 # 3 instructions; loads
|
||||
spin main 240a564 240a56c # 3 instructions; loads
|
||||
spin main 240a574 240a578 # 2 instructions; loads
|
||||
spin main 240a5f8 240a600 # 3 instructions; loads
|
||||
spin main 240a620 240a628 # 3 instructions; loads
|
||||
spin main 240a630 240a634 # 2 instructions; loads
|
||||
spin main 240a6b4 240a6bc # 3 instructions; loads
|
||||
spin main 240aa50 240aa58 # 3 instructions; loads
|
||||
spin main 240aa60 240aa64 # 2 instructions; loads
|
||||
spin main 240aab4 240aabc # 3 instructions; loads
|
||||
spin main 240aafc 240ab04 # 3 instructions; loads
|
||||
spin main 240ab0c 240ab10 # 2 instructions; loads
|
||||
spin main 240abac 240abb4 # 3 instructions; loads
|
||||
spin main 240ac0c 240ac14 # 3 instructions; loads
|
||||
spin main 240ac1c 240ac20 # 2 instructions; loads
|
||||
spin main 240aca4 240acac # 3 instructions; loads
|
||||
spin main 240d908 240d910 # 3 instructions; loads
|
||||
spin main 240d918 240d91c # 2 instructions; loads
|
||||
spin main 240d9a8 240d9b0 # 3 instructions; loads
|
||||
spin main 240d9e4 240d9ec # 3 instructions; loads
|
||||
spin main 240d9f4 240d9f8 # 2 instructions; loads
|
||||
spin main 240da64 240da6c # 3 instructions; loads
|
||||
spin main 240ff38 240ff40 # 3 instructions; loads
|
||||
spin main 240ff48 240ff4c # 2 instructions; loads
|
||||
spin main 240ff68 240ff70 # 3 instructions; loads
|
||||
spin main 245c2ec 245c300 # 6 instructions; loads
|
||||
spin main 245c314 245c328 # 6 instructions; loads
|
||||
spin main 245f0dc 245f0f0 # 6 instructions; loads
|
||||
spin main 245f570 245f584 # 6 instructions; loads
|
||||
spin main 246ea9c 246eab0 # 6 instructions; loads
|
||||
spin main 246eee8 246eefc # 6 instructions; loads
|
||||
spin main 2472f60 2472f74 # 6 instructions; loads
|
||||
spin main 24739ac 24739c0 # 6 instructions; loads
|
||||
spin main 24741a8 24741bc # 6 instructions; loads
|
||||
spin main 248f710 248f724 # 6 instructions; loads
|
||||
spin main 287ff50 287ff64 # 6 instructions; loads
|
||||
spin main 288000c 2880020 # 6 instructions; loads
|
||||
spin main 28800c8 28800dc # 6 instructions; loads
|
||||
spin main 2880ed4 2880ee8 # 6 instructions; loads
|
||||
spin main 2880f90 2880fa4 # 6 instructions; loads
|
||||
spin main 288104c 2881060 # 6 instructions; loads
|
||||
spin main 2881108 288111c # 6 instructions; loads
|
||||
spin main 28811c4 28811d8 # 6 instructions; loads
|
||||
spin main 2881280 2881294 # 6 instructions; loads
|
||||
spin main 288133c 2881350 # 6 instructions; loads
|
||||
spin main 28813f8 288140c # 6 instructions; loads
|
||||
spin main 28818c0 28818d4 # 6 instructions; loads
|
||||
spin main 288197c 2881990 # 6 instructions; loads
|
||||
spin main 2a38860 2a38868 # 3 instructions; loads
|
||||
spin main 2a38870 2a38874 # 2 instructions; loads
|
||||
spin main 2a388ac 2a388b4 # 3 instructions; loads
|
||||
spin subsdk0 2090 20a4 # 6 instructions; loads
|
||||
spin subsdk0 278b4 278c8 # 6 instructions; loads
|
||||
spin subsdk0 bcf28 bcfd0 bcfd8 # 14 instructions; loads
|
||||
spin subsdk0 bd0d0 bd178 bd180 # 14 instructions; loads
|
||||
spin subsdk0 c03a0 c03b4 # 6 instructions; loads
|
||||
spin subsdk0 1bbefc 1bbf08 # 4 instructions; loads
|
||||
spin subsdk0 1bd838 1bd84c # 6 instructions; loads
|
||||
spin subsdk0 1c0c68 1c0c74 # 4 instructions; loads
|
||||
spin sdk f5218 f5350 # 14 instructions; loads
|
||||
spin sdk 23a590 23a5d8 # 19 instructions; loads
|
||||
spin sdk 23a658 23a6a0 # 19 instructions; loads
|
||||
spin sdk 23a7fc 23a918 # 19 instructions; loads
|
||||
spin sdk 3d3250 3d3270 # 9 instructions; loads
|
||||
|
||||
# Sun shadow map size (runtime/resolution.c shadow_init switches the set on). Each frame the engine sizes its shadow
|
||||
# cascades (a D16 4-layer array) in main+0xcebdf4: a base size (960 in the field), interpolated down by how close the
|
||||
# cover is, rounded up to 8 at main+0xcec22c and stored as the width (+0x3d8 of the cascade set) and, through the packed
|
||||
# store at +0xe4, the height (+0x3f8). Near the ground it falls to about 400, which draws foliage shadows blocky, and
|
||||
# every change of size moves the shadow texels, so leaf shadows jump instead of sliding. The page's fixed size (+92)
|
||||
# goes in just before the rounding, as the community's shadow resolution mods do (1.1.0: mov w11, #1024 over the
|
||||
# computation). Found by a write watch on the size field (the writer was this function, and no other).
|
||||
site shadow main cec22c 11001d6b @page:x11 b9405d6b 11001d6b # add w11, w11, #7 -> adrp x11, page; ldr w11, [x11, #92]; add w11, w11, #7
|
||||
1003
recomp/patches-v143.txt
Normal file
1003
recomp/patches-v143.txt
Normal file
File diff suppressed because it is too large
Load Diff
158
recomp/patches.py
Normal file
158
recomp/patches.py
Normal file
@@ -0,0 +1,158 @@
|
||||
"""Code patch table for the generator: guest instructions replaced in the lifted C, switchable at run time.
|
||||
|
||||
Lifted code cannot be byte-patched when the game runs, so a patch is applied when the C is generated. A patch file
|
||||
(gen.py --patches) has two kinds of lines; `#` starts a comment, fields are separated by whitespace:
|
||||
|
||||
set <name> <env> <default> a patch set: a run-time switch <env>=0/1, <default> when it is unset
|
||||
site <set> <module> <address> <original> <replacement> [<replacement> ...]
|
||||
|
||||
spin <module> <head> <back-edge> [<back-edge> ...]
|
||||
|
||||
<address> is a module offset (hex), <original> the instruction word the module has there (checked; a mismatch stops
|
||||
the generator), each <replacement> an instruction word (hex) or `@page:x<n>`, which is `adrp x<n>, <patch page>`
|
||||
encoded for the site's address. The patch page is the first 4 KiB page after main's image (layout.py leaves the rest
|
||||
of the 2 MiB-aligned module slot free); the runtime commits it and owns its contents. Words in use, by byte offset:
|
||||
+0..15 the frame-rate step (runtime/frame_rate.c), +16..55 the output, swapchain and scene sizes
|
||||
(runtime/resolution.c res_init), +56..59 the camera's aspect ratio (runtime/resolution.c res_init, set aspect), +60..63
|
||||
the field-of-view factor (runtime/resolution.c res_fov_live, set fov), +92..95 the sun shadow map size
|
||||
(runtime/resolution.c shadow_init, set shadow). A new set takes words outside these.
|
||||
|
||||
The replacement words are lifted at the site's address in place of the original instruction, and the generated C reads
|
||||
`if (rt_patch_on[<set>]) { replacement } else { original }`: one byte load and a branch per executed site. Several
|
||||
sets may patch one address (cheats that write different values there): `if (a) {..} else if (b) {..} else {..}`, the
|
||||
first set in file order wins. The original may be any instruction but br, blr and ret; a replacement's last word may be
|
||||
a bl (lifted with the site's return address), a b or b.cond / cbz / tbz (its target joins the function's labels when
|
||||
inside it) or a ret; earlier words must not branch. Every alternative of a site writes the same flags. The generator
|
||||
writes patches.h (set names, switches, the page address) next to layout.h for the runtime.
|
||||
|
||||
A `spin` line names a spin wait found by tools/spin_waits.py: a loop with head <head> that only another thread can end,
|
||||
and the direct branches back to it (module offsets). Each back-edge (checked: a b, b.cond, cbz / cbnz or tbz / tbnz to
|
||||
<head>) is lifted as `rt_spin_gate(c, <head>); goto <head>`, which keeps every register and only adds time
|
||||
(runtime/kernel.c kern_spin_gate).
|
||||
"""
|
||||
from pathlib import Path
|
||||
|
||||
PAGE = 0x1000
|
||||
|
||||
|
||||
class PatchError(ValueError):
|
||||
pass
|
||||
|
||||
|
||||
def adrp(pc, target, rd):
|
||||
imm = (target >> 12) - (pc >> 12)
|
||||
if not -(1 << 20) <= imm < (1 << 20):
|
||||
raise PatchError(f'{pc:#x}: patch page {target:#x} out of ADRP range')
|
||||
imm &= 0x1FFFFF
|
||||
return 0x90000000 | (imm & 3) << 29 | (imm >> 2) << 5 | rd
|
||||
|
||||
|
||||
class Table:
|
||||
"""sets: [(name, env, default)]; sites: {module: {offset: [(set index, [word | ('page', reg)], original)]}} (the
|
||||
alternatives of a site in file order); page."""
|
||||
|
||||
def __init__(self, sets=(), sites=None, page=0, spins=None):
|
||||
self.sets = list(sets)
|
||||
self.sites = sites or {}
|
||||
self.page = page
|
||||
self.spins = spins or {} # {module: {back-edge offset: head offset}}
|
||||
|
||||
def spins_for(self, name, base):
|
||||
"""{absolute back-edge address: absolute head address}."""
|
||||
return {base + b: base + h for b, h in self.spins.get(name, {}).items()}
|
||||
|
||||
def for_module(self, name, base):
|
||||
"""{absolute address: [(set index, [words])]} with @page resolved."""
|
||||
out = {}
|
||||
for off, alts in self.sites.get(name, {}).items():
|
||||
a = base + off
|
||||
out[a] = [(k, [adrp(a, self.page, w[1]) if isinstance(w, tuple) else w for w in repl])
|
||||
for k, repl, _ in alts]
|
||||
return out
|
||||
|
||||
|
||||
def load(path, mods):
|
||||
"""Table from a patch file; mods is layout() output [(name, base, size)]."""
|
||||
sets, index, sites, spins = [], {}, {}, {}
|
||||
bases = {n: (b, s) for n, b, s in mods}
|
||||
for no, raw in enumerate(Path(path).read_text().splitlines(), 1):
|
||||
f = raw.split('#', 1)[0].split()
|
||||
if not f:
|
||||
continue
|
||||
where = f'{path}:{no}'
|
||||
if f[0] == 'set' and len(f) == 4:
|
||||
if f[1] in index:
|
||||
raise PatchError(f'{where}: set {f[1]} defined twice')
|
||||
index[f[1]] = len(sets)
|
||||
sets.append((f[1], f[2], int(f[3])))
|
||||
elif f[0] == 'site' and len(f) >= 6:
|
||||
if f[1] not in index:
|
||||
raise PatchError(f'{where}: unknown set {f[1]}')
|
||||
if f[2] not in bases:
|
||||
raise PatchError(f'{where}: module {f[2]} not in the layout')
|
||||
off, orig = int(f[3], 16), int(f[4], 16)
|
||||
repl = []
|
||||
for w in f[5:]:
|
||||
if w.startswith('@page:x'):
|
||||
repl.append(('page', int(w[7:])))
|
||||
else:
|
||||
repl.append(int(w, 16))
|
||||
alts = sites.setdefault(f[2], {}).setdefault(off, [])
|
||||
if any(k == index[f[1]] for k, _, _ in alts):
|
||||
raise PatchError(f'{where}: {f[2]}+{off:#x} patched twice by set {f[1]}')
|
||||
if alts and alts[0][2] != orig:
|
||||
raise PatchError(f'{where}: {f[2]}+{off:#x} expects {orig:08x}, an earlier line {alts[0][2]:08x}')
|
||||
alts.append((index[f[1]], repl, orig))
|
||||
elif f[0] == 'spin' and len(f) >= 4:
|
||||
if f[1] not in bases:
|
||||
raise PatchError(f'{where}: module {f[1]} not in the layout')
|
||||
mod, head = spins.setdefault(f[1], {}), int(f[2], 16)
|
||||
for b in f[3:]:
|
||||
b = int(b, 16)
|
||||
if b in mod:
|
||||
raise PatchError(f'{where}: {f[1]}+{b:#x} is a back-edge twice')
|
||||
mod[b] = head
|
||||
else:
|
||||
raise PatchError(f'{where}: cannot parse {raw!r}')
|
||||
base, size = bases['main'][0], bases['main'][1]
|
||||
page = (base + size + PAGE - 1) & ~(PAGE - 1)
|
||||
nxt = min((b for _, b, _ in mods if b > base), default=None)
|
||||
if nxt is not None and page + PAGE > nxt:
|
||||
raise PatchError(f'no room for the patch page after main ({page:#x})')
|
||||
return Table(sets, sites, page, spins)
|
||||
|
||||
|
||||
def check(table, mod, name):
|
||||
"""Stops on a site whose original word differs from the module's."""
|
||||
for off, [(_, _, want), *_] in table.sites.get(name, {}).items():
|
||||
a = mod.base + off
|
||||
if not mod.in_text(a):
|
||||
raise PatchError(f'{name}+{off:#x}: patch site outside .text')
|
||||
have = mod.word(a)
|
||||
if have != want:
|
||||
raise PatchError(f'{name}+{off:#x}: module has {have:08x}, the patch expects {want:08x}')
|
||||
for b, head in table.spins.get(name, {}).items():
|
||||
a = mod.base + b
|
||||
if not mod.in_text(a) or branch_target(mod.word(a), a) != mod.base + head:
|
||||
raise PatchError(f'{name}+{b:#x}: not a direct branch to the spin wait head {name}+{head:#x}')
|
||||
|
||||
|
||||
def branch_target(w, a):
|
||||
"""Target of the direct branch w at a (b, b.cond, cbz / cbnz, tbz / tbnz), or None."""
|
||||
if w >> 26 == 0x05:
|
||||
return a + ((((w & 0x3FFFFFF) ^ 0x2000000) - 0x2000000) << 2)
|
||||
if w & 0xFF000010 == 0x54000000 or w & 0x7E000000 == 0x34000000:
|
||||
return a + ((((w >> 5) & 0x7FFFF) ^ 0x40000) - 0x40000 << 2)
|
||||
if w & 0x7E000000 == 0x36000000:
|
||||
return a + ((((w >> 5) & 0x3FFF) ^ 0x2000) - 0x2000 << 2)
|
||||
return None
|
||||
|
||||
|
||||
def header_text(table, marker):
|
||||
lines = [f'// {marker}: code patch sets, generated by recomp/gen.py --patches. Do not edit or commit.',
|
||||
'#pragma once', '', f'#define RT_PATCH_COUNT {len(table.sets)}',
|
||||
f'#define RT_PATCH_PAGE {table.page:#x}ull',
|
||||
'// X(index, name, env switch, default)',
|
||||
'#define RT_PATCH_SETS(X) ' + ' '.join(f'X({i}, {n}, "{e}", {d})' for i, (n, e, d) in
|
||||
enumerate(table.sets)), '']
|
||||
return '\n'.join(lines)
|
||||
107
recomp/regs.py
Normal file
107
recomp/regs.py
Normal file
@@ -0,0 +1,107 @@
|
||||
"""Function-local general registers for recomp/gen.py.
|
||||
|
||||
The lifter reads and writes the guest's X0-X30 and SP in the Cpu (c->x[n], c->sp), so every guest instruction loads
|
||||
and stores memory, and the C compiler cannot keep a register in a host register across a guest store: guest stores go
|
||||
through pointers that may alias the Cpu. A generated function instead copies the LOCALS registers it uses most into
|
||||
locals at its entry (xN, sp_), works on those, and syncs with the Cpu only where something else reads or writes them:
|
||||
before a call, an SVC, a trap, a return or a tail exit it stores the registers it changed since the last sync (spill),
|
||||
and after an SVC it loads them all again (reload). The other registers stay in the Cpu.
|
||||
|
||||
After a call it reloads only X0-X18 and X30: AAPCS64 has the callee preserve X19-X29 and SP, so their locals still
|
||||
hold what the Cpu holds. What would break that does not occur in NX2navi: main and subsdk0 import neither longjmp nor
|
||||
the C++ unwinder, sdk's longjmp, __cxa_throw and _Unwind_* have no direct callers, and the runtime writes no register
|
||||
above X3 of a running thread's Cpu except X30, which rt_call restores (runtime/hostfn.c). Guest fibers each run on a host fiber of their own with their own Cpu (runtime/kernel.c),
|
||||
and ExitThread leaves by longjmp without returning. gen.py --no-callee-saved-trust reloads those registers too.
|
||||
|
||||
Only plain assignments write registers in the lifted C (`c->x[n] = ...`, `c->sp = ...`), and no code takes a
|
||||
register's address, so the rewrite is textual. A register counts as dirty from a write until the next spill on some
|
||||
path: plan() runs that forward over the function's control flow, so a call spills only what changed since the
|
||||
previous call or the entry. Spilling a register that is not dirty is harmless (the local equals the Cpu), so where a
|
||||
case is unclear the plan errs on spilling more.
|
||||
"""
|
||||
import re
|
||||
from collections import Counter
|
||||
|
||||
REG = re.compile(r'c->x\[(\d+)\]|c->sp\b')
|
||||
WRITE = re.compile(r'c->(?:x\[(\d+)\]|(sp))\s*=(?!=)')
|
||||
# Lifted instructions that hand the Cpu to the runtime: SVCs return, BRK and undefined words do not.
|
||||
ESCAPE = re.compile(r'\brt_(?:svc|brk|udf)\(c\b')
|
||||
SP = 31 # index of SP in the register sets
|
||||
# Markers gen.py puts where the Cpu must be current, resolved by Plan.resolve(): spill before; reload all, or reload
|
||||
# what a call may change, after.
|
||||
SPILL, RELOAD, RELOAD_CALL = '\x00S', '\x00R', '\x00C'
|
||||
CALLEE_SAVED = frozenset(range(19, 30)) | {SP}
|
||||
# Locals per function: the most used registers. More cost more than they save, as clang then spills them to the stack
|
||||
# and the syncs stay (300 hot NX2navi functions: fewest instructions and memory operands at 4-6).
|
||||
LOCALS = 6
|
||||
|
||||
|
||||
def name(r):
|
||||
return 'sp_' if r == SP else f'x{r}'
|
||||
|
||||
|
||||
def cpu(r):
|
||||
return 'c->sp' if r == SP else f'c->x[{r}]'
|
||||
|
||||
|
||||
def refs(text):
|
||||
"""Registers text reads or writes, once per occurrence."""
|
||||
return [SP if m.group(0) == 'c->sp' else int(m.group(1)) for m in REG.finditer(text)]
|
||||
|
||||
|
||||
def written(text):
|
||||
return {SP if m.group(2) else int(m.group(1)) for m in WRITE.finditer(text)}
|
||||
|
||||
|
||||
class Plan:
|
||||
def __init__(self, regs, spill, kept):
|
||||
self.regs = regs # sorted registers the function keeps in locals
|
||||
self.local = set(regs)
|
||||
self.spill = spill # per instruction: registers to store at its sync points
|
||||
self.kept = kept # registers a call leaves as they were (CALLEE_SAVED, or none)
|
||||
|
||||
def decl(self):
|
||||
"""Locals at the top of the function, loaded from the Cpu."""
|
||||
return 'uint64_t ' + ', '.join(f'{name(r)} = {cpu(r)}' for r in self.regs) + ';' if self.regs else ''
|
||||
|
||||
def resolve(self, i, text):
|
||||
"""text of instruction i with its registers on the locals and its sync markers expanded."""
|
||||
def local(m):
|
||||
r = SP if m.group(0) == 'c->sp' else int(m.group(1))
|
||||
return name(r) if r in self.local else m.group(0)
|
||||
|
||||
text = REG.sub(local, text)
|
||||
spill = ''.join(f'{cpu(r)} = {name(r)}; ' for r in sorted(self.spill[i]))
|
||||
reload = ''.join(f' {name(r)} = {cpu(r)};' for r in self.regs)
|
||||
reload_call = ''.join(f' {name(r)} = {cpu(r)};' for r in self.regs if r not in self.kept)
|
||||
return text.replace(SPILL, spill).replace(RELOAD, reload).replace(RELOAD_CALL, reload_call)
|
||||
|
||||
|
||||
def plan(texts, succ, clean, n_locals=LOCALS, kept=CALLEE_SAVED):
|
||||
"""texts[i]: instruction i's C with markers; succ[i]: successor indices inside the function; clean: instructions
|
||||
after which every local equals the Cpu (a call or an SVC that spills and reloads on every path through it);
|
||||
n_locals: how many registers to keep in locals; kept: registers a call does not reload."""
|
||||
n = len(texts)
|
||||
uses = Counter(r for t in texts for r in refs(t))
|
||||
regs = {r for r, _ in sorted(uses.items(), key=lambda kv: (-kv[1], kv[0]))[:n_locals]}
|
||||
writes = [written(t) & regs for t in texts]
|
||||
dirty = [set() for _ in range(n)]
|
||||
seen = [False] * n
|
||||
work = [0] if n else []
|
||||
if n:
|
||||
seen[0] = True
|
||||
while work:
|
||||
i = work.pop()
|
||||
out = set() if i in clean else dirty[i] | writes[i]
|
||||
for s in succ[i]:
|
||||
if not seen[s] or not out <= dirty[s]:
|
||||
seen[s] = True
|
||||
dirty[s] |= out
|
||||
work.append(s)
|
||||
every = set().union(*writes) if writes else set()
|
||||
for i in range(n):
|
||||
if not seen[i]: # not reached from the entry in the plan's flow: anything may be dirty
|
||||
dirty[i] = every
|
||||
# A sync point stores what was dirty on entry to its instruction and what the instruction wrote before it
|
||||
# (c->x[30] of a call): all the instruction's writes, which is at most a little more.
|
||||
return Plan(sorted(regs), [dirty[i] | writes[i] if SPILL in texts[i] else set() for i in range(n)], kept)
|
||||
1157
recomp/simd_c.py
Normal file
1157
recomp/simd_c.py
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user