NefMoto

Technical => Reverse Engineering => Topic started by: elRey on March 14, 2016, 12:47:41 PM



Title: Please explain setting DTC logic
Post by: elRey on March 14, 2016, 12:47:41 PM
Let me first ask when scanning DTC I might see P1103 008 vs P1103 035.
How do I follow the disassembly to determine how the 008 is set vs the 035?

And logic to set DTCs in general:

I can find WHERE (in which func) P1103 is set:
Code:
mov     r12, #45h
calls   84h, SetDTCME75_846b3e

But I don't understand WHY it's set solely based on the disassembled code.

I get that the setDTC func uses the r12 and [r0+2]:

(http://creativeion.com/rey/vw/help/ida_setDTC_1.gif)

And that r12 is set right before calling the setDTC func, but the [r0xxx] statements confuse me. They're different before each setDTC func call:

(http://creativeion.com/rey/vw/help/ida_setDTC_2.gif)

And I get how to follow the decision tree to get to where [r0xxx] are set, but I can't match when/where/which [r0xxxx] is set to which [r0xxxx] is used for each setDTC func call. And what are the

Code:
bfldh   r2, #DTCFieldA_H0|DTCFieldB_H1|DTCFieldC_H2|DTCFieldD_H3, #DTCFieldD_H3
bfldl   r4, #DTCBit_L1, #DTCBit_L1

calls doing exactly?

(http://creativeion.com/rey/vw/help/ida_setDTC_4.gif)

(http://creativeion.com/rey/vw/help/ida_setDTC_3.gif)


Where #45h Error Class is used, what do I look for to find what is being passed into the setDTC func as [r0+2] ?

snippet from first img:
Code:
mov     r4, [r0+2]
mov     [-r0], r4
mov     r12, #45h
calls   84h, SetDTCME75_846b3e



Thanks in advance. I know I'm asking for a lot.

Rey


Title: Re: Please explain setting DTC logic
Post by: elRey on March 14, 2016, 04:05:54 PM
I just realized I've forgotten r0 and [r0] are not the same thing. I'll try looking it over again with that in mind.


Title: Re: Please explain setting DTC logic
Post by: phila_dot on March 14, 2016, 04:15:07 PM
Follow the stack and look at the bitfield masks in hex


Title: Re: Please explain setting DTC logic
Post by: phila_dot on March 14, 2016, 07:57:34 PM
Also %DFPM breaks down the DTC bits


Title: Re: Please explain setting DTC logic
Post by: elRey on March 15, 2016, 06:42:34 AM
Thank you phila_dot. Reading that section now.

As for following the stack, easier said than done for those of us not having a background computer science ;)


Title: Re: Please explain setting DTC logic
Post by: nyet on March 15, 2016, 11:52:01 AM
Thank you phila_dot. Reading that section now.

As for following the stack, easier said than done for those of us not having a background computer science ;)

FWIW it isn't easy for anyone.


Title: Re: Please explain setting DTC logic
Post by: phila_dot on March 16, 2016, 08:08:44 AM
Ask any specific questions that you have, it's alot to try and do a whole writeup on your OP.

It's a top down stack.

[-r0] pushes onto the bottom (adds underneath)
[r0] accesses the current (bottom)
[r0+n] accesses n from the bottom
[r0+] pops off the bottom


Title: Re: Please explain setting DTC logic
Post by: elRey on March 16, 2016, 12:29:18 PM
That is great info in and of itself! Thanks.

What's the difference between r0 and [r0]?

Or are all your examples indirect references using stack and same could be done as direct access to stack values without square brackets?


Title: Re: Please explain setting DTC logic
Post by: phila_dot on March 16, 2016, 01:43:05 PM
It's a stack pointer, so [r0] is accessing the data stored and r0 is the stack pointer (memory address) itself.

Code:
add r0, #0Ah


As seen at the end of the function, this is resetting the stack pointer.


Title: Re: Please explain setting DTC logic
Post by: elRey on March 16, 2016, 03:20:46 PM

[-r0] pushes onto the bottom (adds underneath)
[r0] accesses the current (bottom)
[r0+n] accesses n from the bottom
[r0+] pops off the bottom

Ok, in your previous example if a added a line between [r0 + n]
And [r0+] as such:

[-r0] pushes onto the bottom (adds underneath)
[r0] accesses the current (bottom) <- is it bottom because of previous line?
[r0+n] accesses n from the bottom
[r0] accesses the current (n from bottom?)
[r0+] pops off the bottom

When does the pointer change? Any time there's - or + or func r0, xxx ?


Title: Re: Please explain setting DTC logic
Post by: phila_dot on March 16, 2016, 05:26:46 PM
mov r4, #1h
mov [-r0], r4

Stack
1
----------------

mov r4, #2h
mov [-r0], r4

Stack
1
2
------------------

mov r4, #3h
mov [-r0], r4

Stack
1
2
3
-----------------

mov r4, [r0]

Stack
1
2
3

r4 == 3
-----------------

mov r4, #4h
mov [r0], r4

Stack
1
2
4
-------------------

mov r4, [r0+4]

Stack
1
2
4

r4 == 1
------------------

mov r4, #5h
mov [r0+4], r4

Stack
5
2
4
-------------------

mov r4, [r0+2]

Stack
5
2
4

r4 == 2
-----------------

mov r4, [r0+]

Stack
5
2

r4 == 4
----------------

add r0, #2h

stack
5

Edit: Corrected


Title: Re: Please explain setting DTC logic
Post by: elRey on March 16, 2016, 07:13:40 PM
mov r4, #1h
mov [-r0], r4

Stack
1
----------------

mov r4, #2h
mov [-r0], r4

Stack
1
2
------------------

mov r4, #3h
mov [-r0], r4

Stack
1
2
3
-----------------

mov r4, [r0]

Stack
1
2
3

r4 == 3
-----------------

mov r4, #4h
mov [r0], r4

Stack
1
2
4
-------------------

mov r4, [r0+2]

Stack
1
2
4

r4 == 1
------------------

mov r4, #5h
mov [r0+2], r4

Stack
5
2
4
-------------------

mov r4, [r0+1]

Stack
5
2
4

r4 == 2
-----------------

mov r4, [r0+]

Stack
5
2

r4 == 4
----------------

add r0, #1h

stack
5




Golden. Thank you so much for taking the time to do that!!!!


Title: Re: Please explain setting DTC logic
Post by: DT on March 17, 2016, 03:17:59 AM
i think phila_dot forgot about word and byte in his writeup


Title: Re: Please explain setting DTC logic
Post by: phila_dot on March 17, 2016, 05:55:47 AM
Good catch, posting quickly from my phone and trying to use simple examples.

I used all words and then byte offsets.

I will correct them when I get a minute.


Title: Re: Please explain setting DTC logic
Post by: dream3R on May 02, 2016, 06:52:05 PM
I just realized I've forgotten r0 and [r0] are not the same thing. I'll try looking it over again with that in mind.

pointers


Title: Re: Please explain setting DTC logic
Post by: dream3R on May 02, 2016, 06:54:15 PM
mov r4, #1h
mov [-r0], r4

Stack
1
----------------

mov r4, #2h
mov [-r0], r4

Stack
1
2
------------------

mov r4, #3h
mov [-r0], r4

Stack
1
2
3
-----------------

mov r4, [r0]

Stack
1
2
3

r4 == 3
-----------------

mov r4, #4h
mov [r0], r4

Stack
1
2
4
-------------------

mov r4, [r0+4]

Stack
1
2
4

r4 == 1
------------------

mov r4, #5h
mov [r0+4], r4

Stack
5
2
4
-------------------

mov r4, [r0+2]

Stack
5
2
4

r4 == 2
-----------------

mov r4, [r0+]

Stack
5
2

r4 == 4
----------------

add r0, #2h

stack
5

Edit: Corrected


nice, you tried tricore yet, they like the stack lol