Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ src/rust/gen/analyzer0f.rs
src/rust/gen/jit.rs
src/rust/gen/jit0f.rs
bios/seabios
.vscode/
44 changes: 44 additions & 0 deletions gen/generate_analyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,52 @@ function gen_instruction_body_after_prefix(encodings, size)
}
}

function generate_flags_info(encoding,instruction_postfix)

{
if (encoding.modified_flags==undefined && encoding.tested_flags==undefined) {
instruction_postfix.push("analysis.has_flags_info = false;");
instruction_postfix.push("analysis.tested_flags = 0;");
instruction_postfix.push("analysis.modified_flags = 0;");
}
else {
instruction_postfix.push("analysis.has_flags_info = true;");
if (encoding.tested_flags)
instruction_postfix.push("analysis.tested_flags = " + encoding.tested_flags + ";");
else
instruction_postfix.push("analysis.tested_flags = 0;");
if (encoding.modified_flags)
instruction_postfix.push("analysis.modified_flags = " + encoding.modified_flags + ";");
else
instruction_postfix.push("analysis.modified_flags = 0;");
}
}

function patch_flags_info(encoding,instruction_postfix)

{
let all_flags = 1 << 6 | 1 << 11 | 1 << 0 | 1 << 4 | 1 << 2 | 1 << 7;
let opcode_lea = 0x8D;

if (encoding.opcode != opcode_lea)
instruction_postfix. push ( {
type: "if-else",
if_blocks: [{
condition: "modrm_byte < 0xC0",
body: [].concat(
"analysis.tested_flags = " + all_flags + ";"
),
}]
});
}

function gen_instruction_body_after_fixed_g(encoding, size)
{
const imm_read = gen_read_imm_call(encoding, size);
const instruction_postfix = [];

generate_flags_info(encoding,instruction_postfix);

if(encoding.custom_sti) {
instruction_postfix.push("analysis.ty = ::analysis::AnalysisType::STI;");
}
Expand Down Expand Up @@ -281,6 +322,9 @@ function gen_instruction_body_after_fixed_g(encoding, size)
}
else
{
// instruction accesses mem so it might generate an exception, we need to make sure all flags can be computed
patch_flags_info(encoding,instruction_postfix);

return [].concat(
{
type: "if-else",
Expand Down
653 changes: 338 additions & 315 deletions gen/x86_table.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions src/rust/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,19 @@ pub struct Analysis {
pub no_next_instruction: bool,
pub absolute_jump: bool,
pub ty: AnalysisType,
pub has_flags_info: bool,
pub tested_flags: i32,
pub modified_flags: i32,
}

pub fn analyze_step(mut cpu: &mut CpuContext) -> Analysis {
let mut analysis = Analysis {
no_next_instruction: false,
absolute_jump: false,
ty: AnalysisType::Normal,
has_flags_info : false,
modified_flags : 0,
tested_flags : 0,
};
cpu.prefixes = 0;
let opcode = cpu.read_imm8() as u32 | (cpu.osize_32() as u32) << 8;
Expand Down
Loading