1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-05-28 08:41:30 +00:00
8bitworkshop/src/platform/arm32.ts

76 lines
2.2 KiB
TypeScript
Raw Normal View History

2023-12-27 20:24:42 +00:00
import { Platform, DisasmLine, Machine, BaseMachinePlatform } from "../common/baseplatform";
import { PLATFORMS } from "../common/emu";
import { loadScript } from "../common/util";
2021-06-06 05:50:45 +00:00
import { ARM32Machine } from "../machine/arm32";
2023-12-27 20:24:42 +00:00
declare var cs : any; // Unicorn module
const ARM32_PRESETS = [
2023-12-27 20:24:42 +00:00
{ id: 'vidfill.c', name: 'Video Memory Fill' },
];
export abstract class BaseARMMachinePlatform<T extends Machine> extends BaseMachinePlatform<T> {
//getOpcodeMetadata = getOpcodeMetadata_z80;
2021-06-10 18:25:24 +00:00
getToolForFilename(fn: string) {
2023-12-27 20:24:42 +00:00
fn = fn.toLowerCase();
2021-06-10 18:25:24 +00:00
if (fn.endsWith('.vasm')) return "vasmarm";
2023-12-27 20:24:42 +00:00
if (fn.endsWith('.armips')) return "armips";
if (fn.endsWith('.c')) return "armtcc";
if (fn.endsWith('.s')) return "armtcc";
return "armtcc";
2021-06-10 18:25:24 +00:00
}
getPresets() { return ARM32_PRESETS; }
2023-12-27 20:24:42 +00:00
getDefaultExtension() { return ".c"; };
}
2021-06-06 05:50:45 +00:00
class ARM32Platform extends BaseARMMachinePlatform<ARM32Machine> implements Platform {
2021-06-08 17:49:37 +00:00
capstone_arm : any;
capstone_thumb : any;
async start() {
2021-06-06 05:50:45 +00:00
super.start();
console.log("Loading Capstone");
await loadScript('./lib/capstone-arm.min.js');
2021-06-08 17:49:37 +00:00
this.capstone_arm = new cs.Capstone(cs.ARCH_ARM, cs.MODE_ARM);
this.capstone_thumb = new cs.Capstone(cs.ARCH_ARM, cs.MODE_THUMB);
}
2021-06-06 05:50:45 +00:00
newMachine() { return new ARM32Machine(); }
readAddress(a) { return this.machine.read(a); }
getMemoryMap = function() { return { main:[
2023-12-27 20:24:42 +00:00
{name:'ROM',start:0x0000000,size:0x100000,type:'ram'},
{name:'I/O',start:0x4000000,size:0x100,type:'io'},
] } };
2023-12-27 20:24:42 +00:00
getDebugTree() { return this.machine.cpu.getDebugTree(); }
2021-06-06 05:50:45 +00:00
disassemble(pc:number, read:(addr:number)=>number) : DisasmLine {
2021-06-08 17:49:37 +00:00
var is_thumb = this.machine.cpu.isThumb();
var capstone = is_thumb ? this.capstone_thumb : this.capstone_arm;
2021-06-06 05:50:45 +00:00
var buf = [];
for (var i=0; i<4; i++) {
buf[i] = read(pc+i);
}
2021-06-08 17:49:37 +00:00
var insns = capstone.disasm(buf, pc, 4);
2021-06-06 05:50:45 +00:00
var i0 = insns && insns[0];
if (i0) {
return {
nbytes: i0.size,
line: i0.mnemonic + " " + i0.op_str,
isaddr: i0.address > 0
};
} else {
return {
nbytes: 4,
line: "???",
isaddr: false
};
}
}
}
2021-06-06 05:50:45 +00:00
////
PLATFORMS['arm32'] = ARM32Platform;