esp32emu / tools /dis.mjs
HelloSun's picture
ESP32 emulator update
d8afd6f verified
Raw History Blame Contribute Delete
1.13 kB
// usage: node dis.mjs addr count (after running flash for N sec) - disassembles memory via objdump
import fs from 'fs'; import { execSync } from 'child_process';
export function disasm(soc, cpu, addr, n) {
const bytes = [];
for (let i = 0; i < n; i++) {
const a = (addr + i) >>> 0; const d = cpu.rd[a >>> 12];
bytes.push(d === 1 ? 0 : soc.h8[(a + d) | 0]);
}
fs.writeFileSync('/tmp/opencode/d.S', '.text\n' + bytes.map(b => `.byte ${b}`).join('\n') + '\n');
const env = { ...process.env, PATH: '/tmp/opencode/ard/packages/esp32/tools/xtensa-esp32-elf-gcc/esp-2021r2-patch5-8.4.0/bin:' + process.env.PATH };
execSync('xtensa-esp32-elf-as /tmp/opencode/d.S -o /tmp/opencode/d.o && xtensa-esp32-elf-ld -Ttext=0x' + addr.toString(16) + ' -nostdlib -o /tmp/opencode/d.elf /tmp/opencode/d.o --no-warn-mismatch 2>/dev/null; xtensa-esp32-elf-objdump -D /tmp/opencode/d.elf > /tmp/opencode/d.dis', { env, shell: '/bin/bash' });
const txt = fs.readFileSync('/tmp/opencode/d.dis', 'utf8').split('Disassembly of section .xtensa.info')[0];
return txt.split('\n').filter(l => /^\s*[0-9a-f]+:/.test(l)).join('\n');
}