Log uncompiled assembly
This commit is contained in:
parent
ab0bcf8535
commit
6c107abc28
|
@ -232,6 +232,7 @@ function V86Starter(options)
|
|||
"_coverage_log": (fn_name_offset, num_blocks, visited_block) => {
|
||||
coverage_logger.log(fn_name_offset, num_blocks, visited_block);
|
||||
},
|
||||
"_log_uncompiled_code": (start, end) => cpu.log_uncompiled_code(start, end),
|
||||
|
||||
// see https://github.com/kripken/emscripten/blob/incoming/src/library.js
|
||||
"_atan2": Math.atan2,
|
||||
|
|
|
@ -23,6 +23,12 @@ var LOG_ALL_IO = false;
|
|||
*/
|
||||
var DUMP_GENERATED_WASM = false;
|
||||
|
||||
/**
|
||||
* @const
|
||||
* Note: Needs to be enabled here and in const.h
|
||||
*/
|
||||
var DUMP_UNCOMPILED_ASSEMBLY = false;
|
||||
|
||||
|
||||
var LOG_LEVEL = LOG_ALL & ~LOG_PS2 & ~LOG_PIT & ~LOG_VIRTIO & ~LOG_9P & ~LOG_PIC &
|
||||
~LOG_DMA & ~LOG_SERIAL & ~LOG_NET & ~LOG_FLOPPY & ~LOG_DISK & ~LOG_VGA;
|
||||
|
|
38
src/cpu.js
38
src/cpu.js
|
@ -1253,6 +1253,7 @@ if(PROFILING)
|
|||
}
|
||||
|
||||
var seen_code = {};
|
||||
var seen_code_uncompiled = {};
|
||||
|
||||
CPU.prototype.codegen_finalize = function(cache_index, virtual_start, start, end)
|
||||
{
|
||||
|
@ -1272,7 +1273,7 @@ CPU.prototype.codegen_finalize = function(cache_index, virtual_start, start, end
|
|||
|
||||
if((start ^ end) & ~0xFFF)
|
||||
{
|
||||
dbg_log("truncated disassembly");
|
||||
dbg_log("truncated disassembly start=" + h(start >>> 0) + " end=" + h(end >>> 0));
|
||||
end = (start | 0xFFF) + 1; // until the end of the page
|
||||
}
|
||||
|
||||
|
@ -1323,6 +1324,41 @@ CPU.prototype.codegen_finalize = function(cache_index, virtual_start, start, end
|
|||
//dbg_log("code block from " + h(before >>> 0) + " to " + h(after >>> 0));
|
||||
};
|
||||
|
||||
CPU.prototype.log_uncompiled_code = function(start, end)
|
||||
{
|
||||
if(!DEBUG || !DUMP_UNCOMPILED_ASSEMBLY)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if((seen_code_uncompiled[start] || 0) < 100)
|
||||
{
|
||||
seen_code_uncompiled[start] = (seen_code_uncompiled[start] || 0) + 1;
|
||||
|
||||
end += 8; // final jump is not included
|
||||
|
||||
if((start ^ end) & ~0xFFF)
|
||||
{
|
||||
dbg_log("truncated disassembly start=" + h(start >>> 0) + " end=" + h(end >>> 0));
|
||||
end = (start | 0xFFF) + 1; // until the end of the page
|
||||
}
|
||||
|
||||
if(end < start) end = start;
|
||||
|
||||
dbg_assert(end >= start);
|
||||
|
||||
const buffer = new Uint8Array(end - start);
|
||||
|
||||
for(let i = start; i < end; i++)
|
||||
{
|
||||
buffer[i - start] = this.read8(i);
|
||||
}
|
||||
|
||||
dbg_log("Uncompiled code:");
|
||||
this.debug.dump_code(this.is_32[0] ? 1 : 0, buffer, start);
|
||||
}
|
||||
};
|
||||
|
||||
CPU.prototype.dbg_log = function()
|
||||
{
|
||||
dbg_log("from wasm: " + [].join.call(arguments));
|
||||
|
|
|
@ -190,4 +190,7 @@
|
|||
#define ENABLE_PROFILER 0
|
||||
#define ENABLE_PROFILER_TIMES 0
|
||||
|
||||
// Note: needs to be enabled here and in config.js
|
||||
#define DUMP_UNCOMPILED_ASSEMBLY 0
|
||||
|
||||
#define LOG_PAGE_FAULTS 0
|
||||
|
|
|
@ -533,12 +533,25 @@ static void jit_run_interpreted(int32_t phys_addr)
|
|||
|
||||
jit_jump = false;
|
||||
|
||||
#if DUMP_UNCOMPILED_ASSEMBLY
|
||||
int32_t start_eip = phys_addr;
|
||||
int32_t end_eip = start_eip;
|
||||
#endif
|
||||
|
||||
assert(!in_mapped_range(phys_addr));
|
||||
int32_t opcode = mem8[phys_addr];
|
||||
(*instruction_pointer)++;
|
||||
(*timestamp_counter)++;
|
||||
run_instruction(opcode | !!*is_32 << 8);
|
||||
|
||||
#if DUMP_UNCOMPILED_ASSEMBLY
|
||||
if(!jit_jump)
|
||||
{
|
||||
*previous_ip = *instruction_pointer;
|
||||
end_eip = get_phys_eip();
|
||||
}
|
||||
#endif
|
||||
|
||||
while(!jit_jump)
|
||||
{
|
||||
previous_ip[0] = instruction_pointer[0];
|
||||
|
@ -546,8 +559,19 @@ static void jit_run_interpreted(int32_t phys_addr)
|
|||
|
||||
int32_t opcode = read_imm8();
|
||||
run_instruction(opcode | !!*is_32 << 8);
|
||||
|
||||
#if DUMP_UNCOMPILED_ASSEMBLY
|
||||
if(!jit_jump)
|
||||
{
|
||||
*previous_ip = *instruction_pointer;
|
||||
end_eip = get_phys_eip();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if DUMP_UNCOMPILED_ASSEMBLY
|
||||
log_uncompiled_code(start_eip, end_eip);
|
||||
#endif
|
||||
profiler_end(P_RUN_INTERPRETED);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ extern int32_t set_cr0(int32_t);
|
|||
extern int32_t verr(int32_t);
|
||||
extern int32_t verw(int32_t);
|
||||
extern void codegen_finalize(int32_t, int32_t, int32_t, int32_t);
|
||||
extern void log_uncompiled_code(int32_t, int32_t);
|
||||
extern void cpl_changed(void);
|
||||
extern void cpuid(void);
|
||||
extern void enter16(int32_t, int32_t);
|
||||
|
|
Loading…
Reference in a new issue