@henols/c64-re-tools 2.6.0-rc.13 → 2.6.0-rc.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/skills/c64-assembler/SKILL.md +3 -3
- package/skills/c64-assembler/scripts/assembler.ts +4 -3
- package/skills/c64-docs/SKILL.md +1 -1
- package/skills/c64-docs/scripts/lib/reference.ts +29 -7
- package/skills/c64-docs/scripts/lib/source-map.ts +14 -0
- package/skills/c64-knowledge/SKILL.md +5 -5
- package/skills/c64-knowledge/scripts/knowledge.ts +11 -3
- package/skills/c64-source/SKILL.md +2 -2
- package/skills/c64-source/scripts/lib/export.ts +1 -1
- package/skills/c64-source/scripts/lib/loader.ts +2 -0
- package/skills/c64-source/scripts/lib/source.ts +4 -4
- package/skills/c64-source/scripts/source.ts +22 -17
- package/skills/c64-static-analysis/SKILL.md +21 -20
- package/skills/c64-static-analysis/scripts/lib/findings.ts +11 -11
- package/skills/c64-static-analysis/scripts/lib/instructions.ts +4 -4
- package/skills/c64-static-analysis/scripts/static-analysis.ts +28 -26
- package/skills/c64-testing/scripts/testing.ts +5 -3
- package/src/build-name.ts +9 -4
- package/src/c64.ts +1 -1
- package/src/host/tools/index.ts +1 -1
- package/src/host-client/tools.ts +1 -1
- package/src/knowledge/import.ts +5 -5
- package/src/knowledge/program.ts +1 -1
- package/src/knowledge/read.ts +3 -3
- package/src/knowledge/schema.ts +3 -3
- package/src/native/c64run.ts +1 -1
- package/src/native/{ghidra → decompiler}/analyze.ts +17 -17
- package/src/native/{ghidra → decompiler}/language/c64rt_6510.slaspec +1 -1
- package/src/native/{ghidra → decompiler}/walk.ts +6 -6
- package/src/native/types.ts +25 -25
- package/src/opcodes.ts +1 -1
- package/src/script.ts +1 -1
- package/tools/c64run.c +8 -1
- /package/src/native/{ghidra → decompiler}/c64rt-wasm.ts +0 -0
- /package/src/native/{ghidra → decompiler}/language/c64rt_6510.cspec +0 -0
- /package/src/native/{ghidra → decompiler}/language/c64rt_6510.ldefs +0 -0
- /package/src/native/{ghidra → decompiler}/language/c64rt_6510.pspec +0 -0
- /package/src/native/{ghidra → decompiler}/language/c64rt_6510.sla +0 -0
- /package/src/native/{ghidra → decompiler}/pcode.ts +0 -0
- /package/src/native/{ghidra → decompiler}/wasm.ts +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@henols/c64-re-tools",
|
|
3
|
-
"version": "2.6.0-rc.
|
|
3
|
+
"version": "2.6.0-rc.15",
|
|
4
4
|
"description": "Agent-friendly Commodore 64 engineering toolkit for reverse engineering, debugging, development and testing.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Henrik Olsson",
|
|
@@ -28,7 +28,7 @@ To get the command list, run the script with no arguments.
|
|
|
28
28
|
| Build a source that includes a file that you generated into a folder next to the source root | `build src boot.asm --out build/boot.prg --include ../build` |
|
|
29
29
|
| Build a source that sets no start address | `build src main.a --out build/game.prg --set-pc '$0801'` |
|
|
30
30
|
| Build a generated source with the values of `config.asm` | `build src main.asm` |
|
|
31
|
-
| Build the loader of a generated source | `build src loader.asm` |
|
|
31
|
+
| Build the loader of a generated source. For the packed form, this is only the copier. | `build src loader.asm` |
|
|
32
32
|
| Check that the rebuild is identical to the program in the project knowledge | `build src main.asm --compare` |
|
|
33
33
|
| Build a release and check it against the bytes of that release | `build src main.asm --release ORIGINAL --compare` |
|
|
34
34
|
| Check the rebuild of a program in another space, for example the drive | `build src main.asm --out build/drive.prg --compare --space drive8` |
|
|
@@ -68,7 +68,7 @@ Without `--out`, the name of the program tells what the build is:
|
|
|
68
68
|
| A value of `config.asm` is not its default | `custom_<switches>.prg`, for example `custom_trainer.prg`. A switch that is off has `no_` before its name, for example `custom_no_start_screen.prg`. |
|
|
69
69
|
| A source without `config.asm` | the name of the entry, for example `main.prg` |
|
|
70
70
|
|
|
71
|
-
An entry other than `main.asm` adds its name, for example `clean_loader.prg` for `loader.asm`. With `--plain`, the extension is `.bin`. Do not give `--out` for a build of a generated source. Then the name always tells the build.
|
|
71
|
+
An entry other than `main.asm` adds its name, for example `clean_loader.prg` for `loader.asm`. The `loader.asm` of the packed form holds only the copier, so its build is `clean_copier.prg`. The packed loader program `clean_loader.prg` of the generated source stays. With `--plain`, the extension is `.bin`. Do not give `--out` for a build of a generated source. Then the name always tells the build.
|
|
72
72
|
|
|
73
73
|
### Paths and the project folder
|
|
74
74
|
|
|
@@ -136,7 +136,7 @@ Assembles the source and writes the program to `--out`, or to `build/<name>.prg`
|
|
|
136
136
|
|
|
137
137
|
Do as the result tells:
|
|
138
138
|
|
|
139
|
-
- `result` is `PASS`: the program is at `out`. To run or debug the program, load the file at `out` into the emulator.
|
|
139
|
+
- `result` is `PASS`: the program is at `out`. To run or debug the program, load the file at `out` into the emulator. A generated source with a loader is different: the build of `main.asm` does not set the entry state, and it can hold bytes for $d000-$dfff. Load the loader program in its place.
|
|
140
140
|
- `result` is `FAIL` and `assembled` is `false`: the source has errors, and the script wrote no program. `hint` tells you to correct the source. Correct the source at the file and the line of each diagnostic. Then run `build` again.
|
|
141
141
|
- `result` is `FAIL` and `assembled` is `true`: the program is not identical to the reference. The script wrote the program. Read the first difference of each segment in `compare.segments`. Without `--release`, read the section "Switches" first.
|
|
142
142
|
- `hint` tells that `symbols` is cut: give a larger `--max-listed`, or read the symbols file for the full list.
|
|
@@ -84,12 +84,13 @@ await runScript({
|
|
|
84
84
|
}
|
|
85
85
|
const setPc = call.address("set-pc");
|
|
86
86
|
const { contents, ...tree } = readSourceTree(sourceRoot, call.strings("include"));
|
|
87
|
-
|
|
87
|
+
const inSource = (name: string) => tree.files.findIndex((file) => file.path === (tree.sourceDir === "" ? name : `${tree.sourceDir}/${name}`));
|
|
88
|
+
if (inSource(entry) < 0) throw new Refusal("not-found", `${entry} is not a file in ${sourceRoot}. Give the main source file relative to the source root.`);
|
|
88
89
|
// The name of the build tells what it is: the release, or the switch values of config.asm.
|
|
89
|
-
const config =
|
|
90
|
+
const config = inSource(CONFIG_FILE);
|
|
90
91
|
const kind: BuildKind | undefined = label !== undefined ? { release: label } : config < 0 ? undefined : { values: configValues(contents[config]!.toString("utf8")), defaults: switchDefaults(call.space) };
|
|
91
92
|
const plain = call.flag("plain");
|
|
92
|
-
const out = call.string("out") ?? `${BUILD_DIRECTORY}/${buildName(entry, kind)}.${plain ? "bin" : "prg"}`;
|
|
93
|
+
const out = call.string("out") ?? `${BUILD_DIRECTORY}/${buildName(entry, kind, contents[inSource(entry)]!.toString("utf8"))}.${plain ? "bin" : "prg"}`;
|
|
93
94
|
const params: AcmeParams = { ...tree, entrySource: entry, defines: { ...releaseDefine, ...Object.fromEntries(call.strings("define").map(parseDefine)) }, ...(setPc === undefined ? {} : { setPc }) };
|
|
94
95
|
|
|
95
96
|
const { result, attachments } = await assemble(params, contents, localToolContext());
|
package/skills/c64-docs/SKILL.md
CHANGED
|
@@ -114,7 +114,7 @@ The reference has these pages:
|
|
|
114
114
|
- `index.md`: each file of the source, with its range, its title, the count of routines and the count of names.
|
|
115
115
|
- `modules/<file>.md`: a call graph of the file, its data regions with their readers and writers, and an entry for each name. An entry has the comment, the callers and the table that holds the name. For a routine, it also has the calls, the jumps, the reads and the writes.
|
|
116
116
|
- `tables.md`: each table of addresses, jumps and words, entry by entry, with its target. An RTS table holds each target minus 1. The page gives the target.
|
|
117
|
-
- `memory-map.md`: each region in address order. Then each variable outside the program, with its comment and the routines that read it and write it.
|
|
117
|
+
- `memory-map.md`: each region in address order. Then each variable outside the program, with its comment and the routines that read it and write it. A platform name, for example a chip register, has a routine only where the source line uses that name. `(indexed)` after a routine tells that the line adds X or Y to the address. That access can also go to the addresses after it, which can have no row.
|
|
118
118
|
- `graphics.md`: each `sprite`, `bitmap`, `charset` and `screen` region. The project knowledge has no graphics mode. Thus a sprite, a bitmap or a charset shows in hires and in multicolour. A charset shows 16 characters in each row. A screen shows as text.
|
|
119
119
|
|
|
120
120
|
In a call graph, a solid arrow is a call, a thick arrow is a table entry, and a dotted arrow is a jump. A table entry goes from each routine that reads the table to each target in code. A table of data addresses gives no arrow.
|
|
@@ -46,7 +46,7 @@ const MAX_LISTED = 40;
|
|
|
46
46
|
const MAX_EDGES = 60;
|
|
47
47
|
/** A name outside the image covers the addresses that references use up to the next name, at most this many. */
|
|
48
48
|
const MAX_SPAN = 256;
|
|
49
|
-
/** The kinds of a reference that reads a table:
|
|
49
|
+
/** The kinds of a reference that reads a table: the decompiler gives an indexed read (lda table,x) as "reference". */
|
|
50
50
|
const TABLE_READS: readonly string[] = ["read", "reference", "pointer"];
|
|
51
51
|
|
|
52
52
|
const hex = (address: number) => formatC64Address(address).toUpperCase();
|
|
@@ -145,12 +145,34 @@ export function buildReference(input: ReferenceInput): { files: ReferenceFile[];
|
|
|
145
145
|
*/
|
|
146
146
|
const named = new Set(input.symbols.map((symbol) => symbol.address));
|
|
147
147
|
const dataReferences = input.references.filter((reference) => !(reference.to >= IO_RAM.start && reference.to <= IO_RAM.end && input.image?.inImage(reference.to) === true && !named.has(reference.to)));
|
|
148
|
-
/**
|
|
149
|
-
|
|
148
|
+
/**
|
|
149
|
+
* How the source line of a reference uses a platform name, as the source writes it: "named", "indexed"
|
|
150
|
+
* (name,x or name,y: the index can reach the registers after it), or undefined when the line does not
|
|
151
|
+
* name it, for example lda $d000,x with the character ROM in. "named" when the source text is not there.
|
|
152
|
+
*/
|
|
153
|
+
const platformUse = (reference: ReferenceRow, name: string): "named" | "indexed" | undefined => {
|
|
154
|
+
const line = map.lineOf(reference.from);
|
|
155
|
+
const text = line === undefined ? undefined : map.textOf?.(line);
|
|
156
|
+
if (text === undefined) return "named";
|
|
157
|
+
const use = new RegExp(`(?<![\\w.])${name}(?!\\w)([^,)]*,\\s*[xXyY]\\b)?`).exec(text);
|
|
158
|
+
return use === null ? undefined : use[1] === undefined ? "named" : "indexed";
|
|
159
|
+
};
|
|
160
|
+
/** The routines that read or write a range, each linked to its entry. `platform` is the platform name of the range. */
|
|
161
|
+
const ownersOf = (page: string, start: number, end: number, kind: string, platform?: string) =>
|
|
150
162
|
capped(
|
|
151
|
-
[
|
|
152
|
-
|
|
153
|
-
|
|
163
|
+
[
|
|
164
|
+
...new Set(
|
|
165
|
+
dataReferences
|
|
166
|
+
.filter((reference) => reference.kind === kind && reference.to >= start && reference.to <= end)
|
|
167
|
+
.flatMap((reference) => {
|
|
168
|
+
const use = platform === undefined ? "named" : platformUse(reference, platform);
|
|
169
|
+
if (use === undefined) return [];
|
|
170
|
+
const name = ownerAt(reference.from)?.name ?? hex(reference.from);
|
|
171
|
+
const shown = entries.has(name) ? entryOfName(page, name, name) : `\`${name}\``;
|
|
172
|
+
return [use === "indexed" ? `${shown} (indexed)` : shown];
|
|
173
|
+
}),
|
|
174
|
+
),
|
|
175
|
+
],
|
|
154
176
|
);
|
|
155
177
|
|
|
156
178
|
// --- The routine graph ----------------------------------------------------
|
|
@@ -381,7 +403,7 @@ export function buildReference(input: ReferenceInput): { files: ReferenceFile[];
|
|
|
381
403
|
lines.push("", "## Variables outside the program", "", "| Address | Name | Comment | Read by | Written by |", "|---|---|---|---|---|");
|
|
382
404
|
for (const entry of outside) {
|
|
383
405
|
const at = `\`${entry.spanEnd > entry.address ? range(entry.address, entry.spanEnd) : hex(entry.address)}\``;
|
|
384
|
-
const owners = (kind: string) => ownersOf(page, entry.address, entry.spanEnd, kind);
|
|
406
|
+
const owners = (kind: string) => ownersOf(page, entry.address, entry.spanEnd, kind, entry.kind === "platform" ? entry.name : undefined);
|
|
385
407
|
lines.push(`| ${at} | <a id="${entry.name}"></a>${codeOfName(page, entry.name)} | ${commentLines(entry.address).join(" ").replace(/\|/g, "\\|")} | ${owners("read")} | ${owners("write")} |`);
|
|
386
408
|
}
|
|
387
409
|
counts.entries += outside.length;
|
|
@@ -32,6 +32,8 @@ export interface SourceMap {
|
|
|
32
32
|
lineOf: (address: number) => SourceLine | undefined;
|
|
33
33
|
/** The project path of a source file. */
|
|
34
34
|
pathOf: (file: string) => string;
|
|
35
|
+
/** The text of a source line, without its comment; undefined when the file or the line is not there. */
|
|
36
|
+
textOf?: (line: SourceLine) => string | undefined;
|
|
35
37
|
}
|
|
36
38
|
|
|
37
39
|
/** Reads the source map of the source in `directory` of the project `root`. A missing map is a refusal with the remedy. */
|
|
@@ -61,6 +63,7 @@ export function readSourceMap(directory: string, root?: string): SourceMap {
|
|
|
61
63
|
.map((item) => ({ start: parseC64Address(String(item.start)), end: parseC64Address(String(item.end)), file: String(item.file), line: Number(item.line) }))
|
|
62
64
|
.sort((a, b) => a.start - b.start);
|
|
63
65
|
const byName = new Map(labels.map((label) => [label.name, label]));
|
|
66
|
+
const texts = new Map<string, string[] | undefined>();
|
|
64
67
|
return {
|
|
65
68
|
directory,
|
|
66
69
|
mapPath: path,
|
|
@@ -82,5 +85,16 @@ export function readSourceMap(directory: string, root?: string): SourceMap {
|
|
|
82
85
|
return undefined;
|
|
83
86
|
},
|
|
84
87
|
pathOf: (file) => posix.join(directory, file),
|
|
88
|
+
textOf: (line) => {
|
|
89
|
+
if (!texts.has(line.file)) {
|
|
90
|
+
try {
|
|
91
|
+
texts.set(line.file, readProjectFile(posix.join(directory, line.file), root === undefined ? {} : { root }).bytes.toString("utf8").split(/\r?\n/));
|
|
92
|
+
} catch {
|
|
93
|
+
texts.set(line.file, undefined);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
const text = texts.get(line.file)?.[line.line - 1];
|
|
97
|
+
return text?.replace(/;.*$/, "");
|
|
98
|
+
},
|
|
85
99
|
};
|
|
86
100
|
}
|
|
@@ -70,7 +70,7 @@ The knowledge is text in `.c64-re-tools/knowledge/` of the project. Commit that
|
|
|
70
70
|
## Addresses, names and spaces
|
|
71
71
|
|
|
72
72
|
- A symbol is the name of an address from the user or the LLM. Get it from `at`, `search` or `symbols`.
|
|
73
|
-
- An analyzer name is a second name from DXA,
|
|
73
|
+
- An analyzer name is a second name from DXA, the decompiler or an idiom search, for example `FUN_17e2`. Each analyzer keeps its own name at an address. Get them from `at`, `search` or `symbols --analyzer`.
|
|
74
74
|
- The generated source uses only the symbols. To use an analyzer name in the source, give the address that name with `rename`.
|
|
75
75
|
- A symbol name is a label for ACME: a letter or an underscore, then letters, digits or underscores. The knowledge refuses the name of a 6502 instruction, for example `lda`, in upper or lower case.
|
|
76
76
|
- A space is `c64` (the default), `drive8` for code in the 1541 drive, `loading` or `bank0` to `bank255`. `loading` is the captured stage of the loading that shows the start screen. `bank0` to `bank255` are cartridge banks, or other memory images of the program, for example a file that the program loads later. Drive code, the stage and banks use the same addresses as the C64. Thus each space has its own knowledge. A name is unique in one space.
|
|
@@ -113,7 +113,7 @@ Each flag applies only to the commands in the table. On another command, the scr
|
|
|
113
113
|
| `--evidence <kind:ref>` | `join` | With `--apply`: the same as for the commands in "Change the knowledge". |
|
|
114
114
|
| `--expect-revision <revision>` | `join` | With `--apply`: the same as for the commands in "Change the knowledge". |
|
|
115
115
|
| `--range <start>-<end>` | `symbols`, `regions`, `comments`, `references`, `suppressions`, `modules`, `operands`, `patches`, `uses`, `export` | Only the rows in this range. The default is all addresses. |
|
|
116
|
-
| `--origin <origin>` | `search`, `symbols`, `regions`, `comments`, `references`, `modules`, `operands`, `patches`, `macros`, `uses`, `export` | Only the rows of these origins: `user`, `llm`, `dxa`, `
|
|
116
|
+
| `--origin <origin>` | `search`, `symbols`, `regions`, `comments`, `references`, `modules`, `operands`, `patches`, `macros`, `uses`, `export` | Only the rows of these origins: `user`, `llm`, `dxa`, `decompiler`, `heuristic`, `semantic` (user and llm), `analyzer` (dxa, decompiler and heuristic), or a comma list. The default is all origins. |
|
|
117
117
|
| `--max-listed <n>` | `search`, `symbols`, `regions`, `comments`, `references`, `suppressions`, `modules`, `operands`, `patches`, `switches`, `releases`, `macros`, `uses`, `spaces`, `history`, `revisions`, `revision`, `listing`, `join` | The most items in each list of the body. The default is 50. The counts are always complete. |
|
|
118
118
|
| `--kind <kind>` | `symbols`, `rename` | The symbol kind: `label`, `routine`, `variable`, `data` or `vector`. A read gives all kinds by default. A new symbol without `--kind` is a `label`. A `rename` without `--kind` keeps the kind of the symbol. |
|
|
119
119
|
| `--kind <kind>` | `references` | Only references of this kind: `call`, `jump`, `read`, `write`, `reference` or `pointer`. |
|
|
@@ -200,7 +200,7 @@ When a git merge left conflicts in the knowledge, each read body also has `confl
|
|
|
200
200
|
### `suppressions`
|
|
201
201
|
|
|
202
202
|
- `body.suppressions` lists the places that a removal blocks. Each item has `suppresses` (`symbol`, `region` or `reference`), the place, and the `reason` of the removal.
|
|
203
|
-
- `unclassify` and `unreference` block the place for DXA and
|
|
203
|
+
- `unclassify` and `unreference` block the place for DXA and the decompiler. A later analysis does not add a region in that range or that reference again. This is also true for a fact from the LLM.
|
|
204
204
|
- `remove-symbol` does not block the address, because an analyzer name never becomes a symbol.
|
|
205
205
|
- A `rename`, `classify` or `reference` at a blocked place ends the block there. A `revert` to a revision before the removal also ends the block.
|
|
206
206
|
- `at` and `history` also show the blocks.
|
|
@@ -251,7 +251,7 @@ When a git merge left conflicts in the knowledge, each read body also has `confl
|
|
|
251
251
|
- `body.lines` has `count` and `listed`. `listed` holds one line for each instruction of a code region, and one `!byte` line for other bytes.
|
|
252
252
|
- Each line has `address`, `bytes`, `text`, `referencesIn` and `referencesOut`. It can also have `label`, `analyzerNames`, `lineComments` and `comment`. `lineComments` are the line comments before the line. `comment` is the side comment.
|
|
253
253
|
- `text` is the instruction with the names of its target. An operand expression of the knowledge replaces the operand.
|
|
254
|
-
- `access` is there when the knowledge has coverage. It tells if a run executed (`x`), read (`r`) or wrote (`w`) the bytes of the line. `-` tells that no run did. An `r` on code can come from a read of the 6502 that the program does not do. Examples are the byte
|
|
254
|
+
- `access` is there when the knowledge has coverage. It tells if a run executed (`x`), read (`r`) or wrote (`w`) the bytes of the line. `-` tells that no run did. An `r` on code can come from a read of the 6502 that the program does not do. Examples are the third byte of a JSR and the opcode after a branch that the CPU takes. Another example is the opcode at the PC when an interrupt starts. An indexed read (`lda table,x`) that crosses a page also reads the byte $100 below its target. A read watchpoint does not stop at these reads.
|
|
255
255
|
- With `--out`, the body has `lines` as a number, and `out`, `bytes` and `sha256` of the text file.
|
|
256
256
|
- If the knowledge has no program in the space, the script refuses. Put the program in with `image` first.
|
|
257
257
|
- Use `listing` in place of your own disassembler.
|
|
@@ -540,7 +540,7 @@ A macro writes a run of instructions as one line of the source, for example `+in
|
|
|
540
540
|
### `coverage <map>...`
|
|
541
541
|
|
|
542
542
|
- `<map>` is a 64 KiB coverage map of a run. Write each map in `.c64-re-tools/local/`.
|
|
543
|
-
- `body` holds `revision`, `imported`, `known` and `ranges`. `imported` lists the new maps. `known` lists the maps that the space has already.
|
|
543
|
+
- `body` holds `revision`, `imported`, `known` and `ranges`. `imported` lists the new maps. `known` lists the maps that the space has already. `ranges` counts the new ranges of accesses that no earlier map has. When `ranges` is 0, the source and the reference do not change.
|
|
544
544
|
- `coverage` joins the maps. It keeps each address that a run executed, read or wrote. It also keeps each address that one run wrote and executed: self-modified code.
|
|
545
545
|
- `coverage` puts each map into the space of `--space`. You can add the same map to each space.
|
|
546
546
|
- `--evidence coverage:<map>` names a map by its path at the import. It refers to the last import of that map into the space of the write.
|
|
@@ -299,7 +299,7 @@ function listingSource(db: DatabaseSync | undefined, space: string): ListingSour
|
|
|
299
299
|
/** Every value of --origin, for the message of a wrong one. */
|
|
300
300
|
const ORIGIN_VALUES = `one of ${ORIGINS.join(", ")}, semantic or analyzer, or a comma list of them. semantic is ${SEMANTIC_ORIGINS.join(" and ")}. analyzer is ${ANALYZERS.slice(0, -1).join(", ")} and ${ANALYZERS.at(-1)}`;
|
|
301
301
|
|
|
302
|
-
/** --origin for reads: one origin, semantic (user and llm), analyzer (dxa,
|
|
302
|
+
/** --origin for reads: one origin, semantic (user and llm), analyzer (dxa, decompiler and heuristic), or a comma list. */
|
|
303
303
|
function originFilter(value: string): Origin[] {
|
|
304
304
|
const origins = new Set<Origin>();
|
|
305
305
|
for (const part of value.split(",")) {
|
|
@@ -558,7 +558,7 @@ const READ_COMMANDS: CommandSpec[] = [
|
|
|
558
558
|
},
|
|
559
559
|
),
|
|
560
560
|
readCommand(
|
|
561
|
-
{ name: "symbols", summary: "The symbols, or with --analyzer the second names that DXA,
|
|
561
|
+
{ name: "symbols", summary: "The symbols, or with --analyzer the second names that DXA, the decompiler and the idioms gave.", options: { ...FILTER, kind: SYMBOL_KIND, analyzer: { kind: "flag", help: "the analyzer names in place of the symbols" }, ...LIST } },
|
|
562
562
|
(db, call) => {
|
|
563
563
|
const kind = call.string("kind") as (typeof SYMBOL_KINDS)[number] | undefined;
|
|
564
564
|
if (call.flag("analyzer")) return { analyzerNames: list(call, listAnalyzerNames(db, rangeOf(call), kind, originsOf(call), call.space), symbol, RANGE_REST) };
|
|
@@ -1069,7 +1069,15 @@ const WRITE_COMMANDS: CommandSpec[] = [
|
|
|
1069
1069
|
const maps = call.subjects.map((path) => ({ bytes: readProjectFile(path).bytes, name: knowledgePath(path, "<map>") }));
|
|
1070
1070
|
return (db) => {
|
|
1071
1071
|
const { revision, current } = addCoverage(db, context, { space: call.space, maps });
|
|
1072
|
-
|
|
1072
|
+
const body = { revision, ...spaceOf(current), imported: current.imported, known: current.known, ranges: current.ranges };
|
|
1073
|
+
// ranges counts the accesses that no earlier map had: only they change the source and the reference.
|
|
1074
|
+
const hint =
|
|
1075
|
+
revision === null
|
|
1076
|
+
? "The knowledge has each map already. Nothing changed."
|
|
1077
|
+
: current.ranges === 0
|
|
1078
|
+
? "The maps add no access that the knowledge did not have. The knowledge keeps them as evidence. The source and the reference do not change."
|
|
1079
|
+
: `The maps add ${current.ranges} ranges of accesses. They can change the leftovers and the code that no run executed. Generate the source again, then the reference.`;
|
|
1080
|
+
return reply(body, { hint });
|
|
1073
1081
|
};
|
|
1074
1082
|
},
|
|
1075
1083
|
),
|
|
@@ -167,7 +167,7 @@ Do these actions for the findings:
|
|
|
167
167
|
#### Names in the source
|
|
168
168
|
|
|
169
169
|
- A label or a constant gets the name of the address in the knowledge.
|
|
170
|
-
- Without a knowledge name, it gets the platform name, for example `EXTCOL` or `CHROUT`. A platform name wins over an analyzer name (`dxa`, `
|
|
170
|
+
- Without a knowledge name, it gets the platform name, for example `EXTCOL` or `CHROUT`. A platform name wins over an analyzer name (`dxa`, `decompiler` or `heuristic`), for example `EXTCOL` over `ld020`. A `user` or `llm` name wins over a platform name.
|
|
171
171
|
- An address in the program without a name gets `l_xxxx`.
|
|
172
172
|
- A read or a write in the I/O area `$d000-$dfff` uses the register, also when the program has RAM there. For example, `lda $dd0e` is `lda CI2CRA` and `sta $d012` is `sta RASTER`. `constants.asm` has these names. An address without a platform name stays a number, for example `sta $d800,x`. The data label of the RAM stays at its data. A `user` or `llm` name of the address wins over the register.
|
|
173
173
|
- A platform name in an operand expression of the knowledge stays in the source. When the program has the address, `constants.asm` has the name, and the RAM there keeps its label.
|
|
@@ -335,7 +335,7 @@ A loader file that loads into $d000 or higher writes the I/O area. When the prog
|
|
|
335
335
|
To make the packed loader for other switch values, do these steps:
|
|
336
336
|
|
|
337
337
|
1. Assemble `main.asm` without an output path. The build name of the program tells the switch values, for example `build/custom_trainer.prg`. The leftovers are $00 in this build.
|
|
338
|
-
2. Assemble `loader.asm` without an output path, for example to `build/
|
|
338
|
+
2. Assemble `loader.asm` without an output path, for example to `build/custom_trainer_copier.prg`. This is the copier. The build name has `copier` in place of `loader`, so the build does not write over the loader program.
|
|
339
339
|
3. Pack the two files into `build/custom_trainer_packed.prg`. The start address is the copier address in the comment at the start of `loader.asm`. The memory configuration at the exit is `$34`.
|
|
340
340
|
|
|
341
341
|
These steps do not work when a segment starts below $0400. They also do not work when a patch is between the free ranges of `loader.asm`. In these cases, use `generate --loader` for the base release.
|
|
@@ -247,7 +247,7 @@ export function planDrops(input: DropInput): DropPlan {
|
|
|
247
247
|
const touched = (address: number) => input.coverage !== undefined && input.coverage[address] !== 0;
|
|
248
248
|
const executed = (address: number) => input.coverage !== undefined && (input.coverage[address]! & COVERAGE.ramExecute) !== 0;
|
|
249
249
|
const regions = input.regions.flatMap((region) => input.segments.filter((segment) => overlaps(region, segment)).map((segment) => ({ start: Math.max(region.start, segment.start), end: Math.min(region.end, segment.end), type: region.type })));
|
|
250
|
-
// The source writes a data region as data, also where
|
|
250
|
+
// The source writes a data region as data, also where the decompiler decoded instructions in it: those are no code.
|
|
251
251
|
const instructions = new Map([...input.instructions].filter(([start, length]) => !regions.some((region) => !CODE_TYPES.includes(region.type) && start <= region.end && region.start <= start + length - 1)));
|
|
252
252
|
const blocks = blocksOf(instructions, input.memory);
|
|
253
253
|
// An indexed operand reads in the region that holds it, and in the next region when it is the last byte (table-1,x).
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
import { readFileSync } from "node:fs";
|
|
17
17
|
import { fileURLToPath } from "node:url";
|
|
18
18
|
|
|
19
|
+
import { COPIER_LINE } from "#src/build-name.ts";
|
|
19
20
|
import { type AddressRange, formatC64Address, formatC64Byte, prgRange } from "#src/c64.ts";
|
|
20
21
|
import { compareBuild, mergedPrograms } from "#src/compare.ts";
|
|
21
22
|
import { Refusal } from "#src/errors.ts";
|
|
@@ -691,6 +692,7 @@ function planPacked(input: LoaderInput, blocks: Block[], cia: ReturnType<typeof
|
|
|
691
692
|
"; The image is too large for one loader file, so this is the packed form. Exomizer packs the",
|
|
692
693
|
`; build of main.asm and the build of this file into the loader program, with --entry '${formatC64Address(copier)}' and --exit-memory '$34'.`,
|
|
693
694
|
"; The unpacker of Exomizer uses the zero page and $0334-$03ff, so the copier writes pages $0002-$03ff after the unpack.",
|
|
695
|
+
COPIER_LINE,
|
|
694
696
|
"",
|
|
695
697
|
"!cpu 6510",
|
|
696
698
|
...settingsLines(input),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// ACME source from an image, current knowledge and
|
|
1
|
+
// ACME source from an image, current knowledge and the decompiler's instruction
|
|
2
2
|
// boundaries. The same input gives the same text. Names come from
|
|
3
3
|
// knowledge; a target that knowledge does not name gets l_xxxx. A read or
|
|
4
4
|
// write in the I/O area names the register, also where the image holds RAM. Data is
|
|
@@ -30,7 +30,7 @@ export interface SourceInput {
|
|
|
30
30
|
/** The image byte at an address inside a segment. */
|
|
31
31
|
byteAt: (address: number) => number;
|
|
32
32
|
entry?: number;
|
|
33
|
-
/** Where
|
|
33
|
+
/** Where the decompiler decoded an instruction, with its length. */
|
|
34
34
|
instructions: ReadonlyMap<number, number>;
|
|
35
35
|
/** Without an origin, a symbol counts as a user or LLM name. */
|
|
36
36
|
symbols: ReadonlyArray<{ address: number; name: string; origin?: Origin }>;
|
|
@@ -204,7 +204,7 @@ interface DataItem {
|
|
|
204
204
|
kind: "data";
|
|
205
205
|
start: number;
|
|
206
206
|
end: number;
|
|
207
|
-
/** The region type, or unclassified. In a code region, bytes that
|
|
207
|
+
/** The region type, or unclassified. In a code region, bytes that the decompiler did not decode. */
|
|
208
208
|
type: RegionType | "unclassified" | "undecoded";
|
|
209
209
|
region?: Region;
|
|
210
210
|
}
|
|
@@ -280,7 +280,7 @@ function operandValue(address: number, opcode: number, byteAt: (address: number)
|
|
|
280
280
|
|
|
281
281
|
/**
|
|
282
282
|
* Each entry point inside a data region of the knowledge, with that region.
|
|
283
|
-
* A data region wins over an entry:
|
|
283
|
+
* A data region wins over an entry: the decompiler does not decode there,
|
|
284
284
|
* and the source has data there. A code region in the knowledge changes that.
|
|
285
285
|
*/
|
|
286
286
|
export function entriesInData<R extends { start: number; end: number; type: RegionType }>(entries: readonly number[], regions: readonly R[]): Array<{ entry: number; region: R }> {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// The c64-source script: generates ACME source from the program and the
|
|
2
|
-
// knowledge and
|
|
2
|
+
// knowledge and the decompiler's instructions, which it runs itself, and checks
|
|
3
3
|
// with ACME that the build of the base release assembles to the program byte
|
|
4
4
|
// by byte. With --loader it also writes a loader that recreates the entry
|
|
5
5
|
// state, simulates it, and checks it in the emulator. The default build may
|
|
@@ -30,9 +30,9 @@ import { ANALYZER_NAME_ORDER, baseValue, currentRevision, currentStartScreen, so
|
|
|
30
30
|
import { CODE_REGION_TYPES, DEFAULT_SPACE, isSemantic, LEFTOVER_FOLDER, LEFTOVERS_SWITCH, RELEASE_DEFINE, START_SCREEN_SWITCH, type Space } from "#src/knowledge/schema.ts";
|
|
31
31
|
import { subtract, write } from "#src/knowledge/write.ts";
|
|
32
32
|
import { assemble, symbolsFileText } from "#src/native/acme.ts";
|
|
33
|
-
import { analyze } from "#src/native/
|
|
33
|
+
import { analyze } from "#src/native/decompiler/analyze.ts";
|
|
34
34
|
import { localToolContext } from "#src/native/local.ts";
|
|
35
|
-
import {
|
|
35
|
+
import { DECOMPILER_LIMITS, type AssembledSymbol, type Diagnostic } from "#src/native/types.ts";
|
|
36
36
|
import { decode as decodeRegister, describeAddress, platformNames, platformNamesFor, romRanges, romUseOfProgram } from "#src/platform.ts";
|
|
37
37
|
import { ensureLocal, generatedDirectory, LOCAL_DIRECTORY, newProjectFolder, PROJECT_DIRECTORY, projectRelative, projectRoot, resolveProjectPath } from "#src/project.ts";
|
|
38
38
|
import { isoCet } from "#src/time.ts";
|
|
@@ -128,7 +128,7 @@ type SourceKnowledge = ReturnType<typeof readKnowledge>;
|
|
|
128
128
|
|
|
129
129
|
/**
|
|
130
130
|
* The names of the user and the LLM, and for each address without one the
|
|
131
|
-
* first analyzer name in the order heuristic,
|
|
131
|
+
* first analyzer name in the order heuristic, decompiler, DXA. An analyzer
|
|
132
132
|
* name that another address has already is left out. The analyzer names keep
|
|
133
133
|
* their origin, so a platform name still wins over them.
|
|
134
134
|
*/
|
|
@@ -156,11 +156,11 @@ function romOf(image: ProgramImage, knowledge: Pick<SourceKnowledge, "routines"
|
|
|
156
156
|
}
|
|
157
157
|
|
|
158
158
|
/**
|
|
159
|
-
*
|
|
159
|
+
* The decompiler's instruction starts and lengths inside the image, seeded from the
|
|
160
160
|
* entry, from knowledge of any origin, and from the coverage: a run's flow
|
|
161
161
|
* starts, also after a JSR, so code that an analyzer does not reach by itself
|
|
162
162
|
* is in the source. A program without a seed has no known code: it is data
|
|
163
|
-
* only, and
|
|
163
|
+
* only, and the decompiler does not run.
|
|
164
164
|
*/
|
|
165
165
|
async function decode(image: ProgramImage, knowledge: Pick<SourceKnowledge, "routines" | "regions">, entries: number[], coverage: Uint8Array | undefined): Promise<{ instructions: Map<number, number>; dataOnly: boolean }> {
|
|
166
166
|
const inImage = (address: number) => image.segments.some((segment) => address >= segment.start && address <= segment.end);
|
|
@@ -185,9 +185,9 @@ async function decode(image: ProgramImage, knowledge: Pick<SourceKnowledge, "rou
|
|
|
185
185
|
const { result } = await analyze(
|
|
186
186
|
{
|
|
187
187
|
imageKind: analyzedBytes(image).kind,
|
|
188
|
-
entryPoints: entryPoints.slice(0,
|
|
189
|
-
codeStarts: flows.codeStarts.filter((address) => !seeds.has(address)).slice(0,
|
|
190
|
-
dataRanges: dataRanges.slice(0,
|
|
188
|
+
entryPoints: entryPoints.slice(0, DECOMPILER_LIMITS.entryPoints),
|
|
189
|
+
codeStarts: flows.codeStarts.filter((address) => !seeds.has(address)).slice(0, DECOMPILER_LIMITS.codeStarts),
|
|
190
|
+
dataRanges: dataRanges.slice(0, DECOMPILER_LIMITS.dataRanges),
|
|
191
191
|
labels: [],
|
|
192
192
|
decompile: [],
|
|
193
193
|
},
|
|
@@ -703,6 +703,9 @@ const LOADER_CHECK_DIRECTORY = "loader-check";
|
|
|
703
703
|
/** The source files of the loader. Only a run with --loader writes them, so only such a run removes them. */
|
|
704
704
|
const LOADER_FILES: ReadonlySet<string> = new Set(["loader.asm", START_SCREEN_FILE, STAGE_FILE]);
|
|
705
705
|
|
|
706
|
+
/** The source files of the show stage. A run writes them only with a loader program whose check ran, so only such a run removes them. */
|
|
707
|
+
const STAGE_FILES: ReadonlySet<string> = new Set([START_SCREEN_FILE, STAGE_FILE]);
|
|
708
|
+
|
|
706
709
|
/** A loader program that generate wrote: its build name, as buildName gives it for loader.asm. */
|
|
707
710
|
const LOADER_PROGRAM = /^(clean|custom_[a-z0-9_]+|release_[A-Za-z0-9_]+)_loader\.prg$/;
|
|
708
711
|
|
|
@@ -802,7 +805,7 @@ function removeOldFiles(out: string, keep: ReadonlySet<string>, loaderRun: boole
|
|
|
802
805
|
}
|
|
803
806
|
if (!entry.isFile()) continue;
|
|
804
807
|
const path = join(directory, entry.name);
|
|
805
|
-
if (LOADER_FILES.has(name) && !loaderRun) continue;
|
|
808
|
+
if ((LOADER_FILES.has(name) && !loaderRun) || STAGE_FILES.has(name)) continue;
|
|
806
809
|
if (!name.endsWith(".asm") || keep.has(name) || !readFileSync(path, "utf8").startsWith(GENERATED_MARK)) continue;
|
|
807
810
|
rmSync(path, { force: true });
|
|
808
811
|
removed.push(`${out}/${name}`);
|
|
@@ -814,22 +817,22 @@ function removeOldFiles(out: string, keep: ReadonlySet<string>, loaderRun: boole
|
|
|
814
817
|
return removed;
|
|
815
818
|
}
|
|
816
819
|
|
|
817
|
-
/** The instructions that
|
|
820
|
+
/** The instructions that the decompiler decoded, and whether the program has known code. */
|
|
818
821
|
type DecodedProgram = Awaited<ReturnType<typeof decode>>;
|
|
819
822
|
|
|
820
823
|
/** How buildSource makes and checks the source of a knowledge. */
|
|
821
824
|
interface SourceOptions {
|
|
822
825
|
space: Space;
|
|
823
|
-
/** More entry points for
|
|
826
|
+
/** More entry points for the decompiler. */
|
|
824
827
|
entries: number[];
|
|
825
828
|
header: string[];
|
|
826
829
|
/** The first line of each file, or none. */
|
|
827
830
|
mark?: string;
|
|
828
831
|
/** The switch values of the build that must give the program. */
|
|
829
832
|
values: ReadonlyMap<string, number>;
|
|
830
|
-
/** The instructions of an earlier decode: then
|
|
833
|
+
/** The instructions of an earlier decode: then the decompiler does not run again. */
|
|
831
834
|
decoded?: DecodedProgram;
|
|
832
|
-
/** Mark the code that no run executed. Without the marks, the coverage only gives the seeds of
|
|
835
|
+
/** Mark the code that no run executed. Without the marks, the coverage only gives the seeds of the decompiler and the ROM use. */
|
|
833
836
|
notExecutedMarks: boolean;
|
|
834
837
|
/** With an entry state, the loader is planned too. */
|
|
835
838
|
state?: EntryState;
|
|
@@ -1216,7 +1219,7 @@ async function generate(call: Call): Promise<{ output: Record<string, unknown>;
|
|
|
1216
1219
|
...(rendered.notExecuted === undefined
|
|
1217
1220
|
? {}
|
|
1218
1221
|
: {
|
|
1219
|
-
notExecuted: { instructions: rendered.notExecuted.instructions, ...listed(rendered.notExecuted.ranges, max, showRange,
|
|
1222
|
+
notExecuted: { instructions: rendered.notExecuted.instructions, ...listed(rendered.notExecuted.ranges, max, showRange, `a larger --max-listed, or read ${reports}/${NOT_EXECUTED_FILE}`) },
|
|
1220
1223
|
}),
|
|
1221
1224
|
...(laid.unusedModules.length === 0 ? {} : { unusedModules: laid.unusedModules.map((module) => ({ start: formatC64Address(module.start), file: module.file })) }),
|
|
1222
1225
|
// The bytes that nothing uses: in leftover files, which the default build and the loader leave out.
|
|
@@ -1346,7 +1349,9 @@ async function generate(call: Call): Promise<{ output: Record<string, unknown>;
|
|
|
1346
1349
|
rmSync(resolveProjectPath(scratch), { recursive: true, force: true });
|
|
1347
1350
|
}
|
|
1348
1351
|
// A loader program of an earlier run with another build name goes: config.asm has other values now.
|
|
1349
|
-
|
|
1352
|
+
// The files of an earlier show stage go when this loader has no stage and this run did not write them.
|
|
1353
|
+
const stageFiles = stage === undefined ? [...STAGE_FILES].filter((name) => !files.some((file) => file.name === name)).map((name) => `${out}/${name}`).filter((path) => existsSync(resolveProjectPath(path)) && readFileSync(resolveProjectPath(path), "utf8").startsWith(GENERATED_MARK)) : [];
|
|
1354
|
+
for (const path of [...loaderPrograms().filter((item) => item !== loaderPath && item !== symbolsPath(loaderPath)), ...stageFiles]) {
|
|
1350
1355
|
rmSync(resolveProjectPath(path), { force: true });
|
|
1351
1356
|
removed.push(path);
|
|
1352
1357
|
}
|
|
@@ -1700,7 +1705,7 @@ async function exportProject(call: Call): Promise<Record<string, unknown>> {
|
|
|
1700
1705
|
to: fromProject(to),
|
|
1701
1706
|
zip: zipWritten,
|
|
1702
1707
|
source: { project: basename(project), revision: knowledge.revision },
|
|
1703
|
-
files: listed(files.map((file) => ({ ...file, out: fromProject(join(to, file.out)) })), max, (file) => file, "the folder of the new project"),
|
|
1708
|
+
files: listed(files.map((file) => ({ ...file, out: fromProject(join(to, file.out)) })), max, (file) => file, "a larger --max-listed, or list the folder of the new project"),
|
|
1704
1709
|
switches,
|
|
1705
1710
|
check: exportCheck,
|
|
1706
1711
|
...(loaderOutput === undefined ? {} : { loader: loaderOutput }),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: c64-static-analysis
|
|
3
|
-
description: Finds the structure of a C64 program with DXA or
|
|
3
|
+
description: Finds the structure of a C64 program with DXA or the decompiler, without running it. It records the code and data regions, the analyzer names and the references in the project knowledge. Use it to get a fast first pass of code and data, and a disassembly listing. Use it to get the routines, the references, an instruction list and decompiled code. Use it when the project knowledge has coverage, to find code that only a vector, a table or an interrupt reaches. Use it to find 6502 idioms, pointer candidates, raster pitfalls and macro candidates. It does not run the program. It does not give names to routines.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Static analysis
|
|
@@ -43,16 +43,16 @@ To get the command list, run the script with no arguments.
|
|
|
43
43
|
- An entry point is an address where code starts. Give it with `--entry`. Get it from these sources:
|
|
44
44
|
- The SYS address of a BASIC start. Get it from a listing of the BASIC program.
|
|
45
45
|
- A vector or an interrupt target that you found in the emulator.
|
|
46
|
-
- An address in `functions` of an earlier
|
|
47
|
-
-
|
|
46
|
+
- An address in `functions` of an earlier decompiler result.
|
|
47
|
+
- The decompiler needs at least one entry point. DXA finds the SYS address of a BASIC start without help.
|
|
48
48
|
- Each routine, each `code` region and each entry of a `jumps` table in the project knowledge is also an entry point. Each name in the project knowledge is a label in the listing and in the decompiled code.
|
|
49
49
|
- The two start vectors of a `CBM80` header at `$8000` are entry points without help.
|
|
50
50
|
- Each region that is not code in the project knowledge stays data. Each `data` or `variable` symbol also keeps its region as data. If the region holds an entry point or executed code, only the byte of the symbol stays data.
|
|
51
51
|
- If an analyzer decodes data as code, classify the region as data in the project knowledge. Then run `analyze` again.
|
|
52
52
|
- The facts of an analyzer are not entry points or data for the next analysis. Thus a new analysis can correct them.
|
|
53
53
|
- With coverage, the analysis keeps as data the RAM under ROM that the runs did not read or execute. A call into the KERNAL thus does not decode the RAM under it. If the program has code there, give its address with `--entry`.
|
|
54
|
-
-
|
|
55
|
-
- `--decompile` takes the address of a routine. Get it from `functions` of an earlier
|
|
54
|
+
- The decompiler does not follow BRK. If the program removes the KERNAL and uses the BRK vector, give the target of the vector with `--entry`.
|
|
55
|
+
- `--decompile` takes the address of a routine. Get it from `functions` of an earlier decompiler result, or from the routines in the project knowledge.
|
|
56
56
|
|
|
57
57
|
### Paths and the project folder
|
|
58
58
|
|
|
@@ -80,13 +80,13 @@ Each flag applies only to the commands in the table. On another command, the scr
|
|
|
80
80
|
|
|
81
81
|
| Flag | Command | Effect |
|
|
82
82
|
|---|---|---|
|
|
83
|
-
| `--analyzer <dxa\|
|
|
83
|
+
| `--analyzer <dxa\|decompiler>` | `analyze` | The analyzer. `dxa` gives a fast first pass. `decompiler` gives a deeper pass. The default is `decompiler`. |
|
|
84
84
|
| `--entry <address>` | `analyze` | An entry point of the program. Give it again for more entry points. There is no default. |
|
|
85
|
-
| `--decompile <address>` | `analyze` |
|
|
85
|
+
| `--decompile <address>` | `analyze` | Only with `--analyzer decompiler`. Decompile the routine at this address. Give it again for more routines, at most 32. There is no default. |
|
|
86
86
|
| `--space <space>` | `analyze` | The knowledge space of the program: `drive8` for 1541 drive code, or `bank0` to `bank255` for a cartridge bank. The analysis reads the entry points from that space and writes the findings into it. The default is `c64`. |
|
|
87
87
|
| `--max-listed <n>` | `analyze` | List at most `n` items in each list. `0` lists no items. The counts stay complete. The default is 50. |
|
|
88
88
|
| `--out-listing <file>` | `analyze` | DXA only. Write the disassembly listing to this project file. There is no default. |
|
|
89
|
-
| `--out-instructions <file>` | `analyze` |
|
|
89
|
+
| `--out-instructions <file>` | `analyze` | Only with `--analyzer decompiler`. Write each instruction to this project file as JSON. There is no default. |
|
|
90
90
|
| `--apply-macros` | `analyze` | Write the macro candidates and their macros to the project knowledge as one revision of the LLM. Off by default. |
|
|
91
91
|
| `--skip <address>` | `analyze` | With `--apply-macros`: the start of a macro candidate that is not correct. The run does not write it. Give one `--skip` for each such candidate. |
|
|
92
92
|
|
|
@@ -96,13 +96,13 @@ Each flag applies only to the commands in the table. On another command, the scr
|
|
|
96
96
|
|
|
97
97
|
### `analyze`
|
|
98
98
|
|
|
99
|
-
Runs DXA or
|
|
99
|
+
Runs DXA or the decompiler over the program in the project knowledge. The script records the findings in the project knowledge as one revision. Then it records the 6502 idioms as a second revision. When the findings do not change the knowledge, the script records no revision for them.
|
|
100
100
|
|
|
101
|
-
The script records only structure: code and data regions, analyzer names, and the references from
|
|
101
|
+
The script records only structure: code and data regions, analyzer names, and the references from the decompiler. It does not record the listing or the decompiled code. Do not record the listing, the decompiled code or the function list as comments in the project knowledge.
|
|
102
102
|
|
|
103
103
|
`body` holds these fields for both analyzers:
|
|
104
104
|
|
|
105
|
-
- `analyzer`: `dxa` or `
|
|
105
|
+
- `analyzer`: `dxa` or `decompiler`. `analyzerVersion` gives the version of the analyzer when the analyzer tells it. `space` is in `body` only for a space that is not `c64`.
|
|
106
106
|
- `revision`: the revision of the findings, or `null` when the knowledge did not change.
|
|
107
107
|
- `coverage`: the ranges that the analyzer examined.
|
|
108
108
|
- `changes`: for analyzer names (`names`), `regions` and `references`, the counts `added`, `changed`, `retired`, `unchanged` and `suppressed`. `suppressed` counts the findings that the script did not record, because the user or the LLM removed a fact at that place. `references.inData` counts the references that the script did not record, because they start in a data region of the user, the LLM or a heuristic. The analyzer decoded these data bytes as code. `symbols.retired` counts the old symbols of the analyzer that became analyzer names.
|
|
@@ -117,13 +117,13 @@ DXA also gives:
|
|
|
117
117
|
- `labels`: the names that DXA found, as a list.
|
|
118
118
|
- `listing`: the listing file, with `--out-listing`.
|
|
119
119
|
|
|
120
|
-
|
|
120
|
+
The decompiler also gives:
|
|
121
121
|
|
|
122
|
-
- `functions`: the routines that
|
|
122
|
+
- `functions`: the routines that the decompiler found, as a list, each with `entry` and `name`.
|
|
123
123
|
- `decompilations`: the C-like code of each `--decompile` routine, with `entry` and `text`. `truncated` tells that the text is cut.
|
|
124
|
-
- `notDecompiled`: the routines that
|
|
124
|
+
- `notDecompiled`: the routines that the decompiler did not decompile, each with a `reason`.
|
|
125
125
|
- `instructions`: the file and the `count`, with `--out-instructions`. Each instruction has `address`, `bytes`, `mnemonic`, `mode` and `operand` in 6502 syntax. A branch, a jump or a call also has `target`. With coverage, `executed` tells if the instruction ran.
|
|
126
|
-
- `coverageGaps`: only with coverage. The executed instruction starts that are not in the instructions of
|
|
126
|
+
- `coverageGaps`: only with coverage. The executed instruction starts that are not in the instructions of the decompiler.
|
|
127
127
|
|
|
128
128
|
The `hint` gives each of these cases:
|
|
129
129
|
|
|
@@ -131,6 +131,7 @@ The `hint` gives each of these cases:
|
|
|
131
131
|
- `coverageConflicts` is not empty. Classify each range as code in the project knowledge, or as `dual-use` when its bytes are also data. For many ranges, write all classifications in one batch of changes.
|
|
132
132
|
- `idioms.candidates.macros` has candidates, and the run had no `--apply-macros`. Examine the candidates. To write the correct candidates to the project knowledge, run the analysis again with `--apply-macros`. Give `--skip` with the start of each candidate that is not correct. Then generate the source again.
|
|
133
133
|
- The last analysis of the same program bytes used another analyzer version. Thus a change in `revision` can come from the new analyzer, and not from the program or the project knowledge.
|
|
134
|
+
- `changes.references.retired` is more than 0. A data range that only a retired reference used can be a leftover now. Generate the source again, and examine the leftovers that changed.
|
|
134
135
|
- A list is cut. Give a larger `--max-listed`. The project knowledge has all `labels` and `functions` as analyzer names.
|
|
135
136
|
|
|
136
137
|
There is no `nextAction`.
|
|
@@ -148,14 +149,14 @@ The script does not record the candidates. Examine each candidate and decide.
|
|
|
148
149
|
#### Which facts the analysis replaces
|
|
149
150
|
|
|
150
151
|
- The analysis never replaces a name or a region of the user or the LLM. Each disagreement shows in `conflicts`.
|
|
151
|
-
- DXA and
|
|
152
|
+
- DXA and the decompiler do not replace the facts of each other, with one exception. With coverage, a code finding replaces DXA or decompiler data where a run executed an instruction start. Thus put all coverage maps into the project knowledge first. Then run DXA, then the decompiler.
|
|
152
153
|
- An analyzer can find data where a run executed an instruction start, or at a `label` or `routine` symbol of the user or the LLM. Then the script does not record that data region, and the earlier region stays. The conflict has `executed` or `knowledge`.
|
|
153
|
-
- An idiom region (origin `heuristic`) replaces the part of a DXA or
|
|
154
|
+
- An idiom region (origin `heuristic`) replaces the part of a DXA or decompiler region where it lies. DXA and the decompiler never replace an idiom region. If they find code there, the result shows a conflict.
|
|
154
155
|
- An idiom table can be too long or too short. Correct its region in the project knowledge. Your region replaces it.
|
|
155
156
|
- A new analysis replaces the earlier facts of the same analyzer in its `coverage`, also its analyzer names. The history keeps the earlier facts.
|
|
156
157
|
- A fact that the user or the LLM removed does not come back. To remove a wrong fact, remove it in the project knowledge.
|
|
157
158
|
- An analyzer name is a second name of the address, not a symbol. Each analyzer keeps its own name at an address. The generated source does not use an analyzer name by default. To use a name in the source, give the address a name in the project knowledge.
|
|
158
|
-
- A
|
|
159
|
+
- A decompiler function that only branches and jumps reach is a `label`, not a `routine`.
|
|
159
160
|
|
|
160
161
|
#### Traps
|
|
161
162
|
|
|
@@ -172,7 +173,7 @@ The script does not record the candidates. Examine each candidate and decide.
|
|
|
172
173
|
|
|
173
174
|
#### Failures
|
|
174
175
|
|
|
175
|
-
- `invalid-input` about an entry point:
|
|
176
|
+
- `invalid-input` about an entry point: the decompiler has no entry point in the program. Give one with `--entry`.
|
|
176
177
|
- `stale-revision`: the project knowledge changed during the analysis. The script recorded nothing. Run `analyze` again.
|
|
177
178
|
- `operation-failed` about an incomplete result or listing: the analyzer did not give a complete result. The script recorded nothing. Tell the user.
|
|
178
179
|
- The script did not write the listing: the error tells if the project knowledge has the findings. Correct `--out-listing` and run `analyze` again.
|
|
@@ -185,7 +186,7 @@ The script does not record the candidates. Examine each candidate and decide.
|
|
|
185
186
|
2. Put each coverage map of the program into the project knowledge.
|
|
186
187
|
3. Run `analyze --analyzer dxa` for a first pass. Read the listing for a quick view of the code.
|
|
187
188
|
4. Find the important routines. Give them names in the project knowledge.
|
|
188
|
-
5. Run `analyze` with
|
|
189
|
+
5. Run `analyze` with the decompiler. Give the entry points with `--entry`. Give `--decompile` for the routines that you must understand.
|
|
189
190
|
6. Do the action for each `hint`. Examine the candidates.
|
|
190
191
|
7. Give each important routine a name in the project knowledge. Then run `analyze` again. The analyzers use the new names.
|
|
191
192
|
|