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

Found a way to emulate Banked registers and improve decomp. output - WIP #19

Open
rnd-ash opened this issue May 8, 2024 · 0 comments
Open

Comments

@rnd-ash
Copy link
Contributor

rnd-ash commented May 8, 2024

@esaulenka After a lot of messing around, I found a way to emulate the banked registers. It needs a lot of work tho to improve the decopilation output, but now, it can accurately decompile the init function (Although messy) for an ECU that uses C167 (Daimler EGS52).

macro load_wgpr() {
	local addr:2 = CP; # Take value of ContextPointer, treat it as an address
        *[register]:2 (addr+0x00) = r0; # Load register values into the memory addresses needed
	*[register]:2 (addr+0x02) = r1;
	*[register]:2 (addr+0x04) = r2;
	*[register]:2 (addr+0x06) = r3;
	*[register]:2 (addr+0x08) = r4;
	*[register]:2 (addr+0x0A) = r5;
	*[register]:2 (addr+0x0C) = r6;
	*[register]:2 (addr+0x0E) = r7;
	*[register]:2 (addr+0x10) = r8;
	*[register]:2 (addr+0x12) = r9;
	*[register]:2 (addr+0x14) = r10;
	*[register]:2 (addr+0x16) = r11;
	*[register]:2 (addr+0x18) = r12;
	*[register]:2 (addr+0x1A) = r13;
	*[register]:2 (addr+0x1C) = r14;
	*[register]:2 (addr+0x1E) = r15;
}

macro save_wgpr() {
	local addr:2 = CP; # Take value of ContextPointer, treat it as an address
        r0  = *[register]:2 (addr+0x00); # Save value from memory into register
	r1  = *[register]:2 (addr+0x02);
	r2  = *[register]:2 (addr+0x04);
	r3  = *[register]:2 (addr+0x06);
	r4  = *[register]:2 (addr+0x08);
	r5  = *[register]:2 (addr+0x0A);
	r6  = *[register]:2 (addr+0x0C);
	r7  = *[register]:2 (addr+0x0E);
	r8  = *[register]:2 (addr+0x10);
	r9  = *[register]:2 (addr+0x12);
	r10 = *[register]:2 (addr+0x14);
	r11 = *[register]:2 (addr+0x16);
	r12 = *[register]:2 (addr+0x18);
	r13 = *[register]:2 (addr+0x1A);
	r14 = *[register]:2 (addr+0x1C);
	r15 = *[register]:2 (addr+0x1E);
}

usage on a function that requires Rw access:

# Rw n , #data3			08 n:0###
# Rw n , [Rw i +]		08 n:11ii
# Rw n , [Rw i ]		08 n:10ii
# Rw n , Rw m			00 nm
:add Rwn1215, op2_w is op0407=0x0 & Rwn1215 & op2_w & ExtDec {
    load_wgpr();
   add_w (Rwn1215, op2_w);
    save_wgpr();
}

output:

Register check initialization process of EGS52:
image

Decompiler output now:
image

Decompiler output before:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant