Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Avoid computing flags even lazy #466

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
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