RomRaider Logo

RomRaider

Open Source ECU Tools
 FAQ •  Register •  Login 

RomRaider

Documentation

Community

Developers

It is currently Sat Feb 21, 2026 10:05 pm

All times are UTC




Post new topic Reply to topic  [ 26 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Learning How to Disassemble a 32Bit ROM - AE5L600L
PostPosted: Wed Nov 27, 2013 3:25 pm 
Offline
Newbie

Joined: Tue Jan 27, 2009 8:45 pm
Posts: 50
Ok, so I've followed this thread (How To: Define a New ROM from a previously defined ROM) and made it through the first 5 steps and learned a ton.
After doing it I would highly suggest following that thread to a "T" and using the scripts provided. The script files themselves have a better description of how they work than that thread, but I figured it out eventually.

Now that I have a mostly disassembled ROM I have something I would like to discover, but will need help getting there.

I would like to determine the ADC that corresponds to each sensor. Which dschultz did for a different ROM and posted it in the previously mentioned thread, but only provided a brief explanation of how he did it.

He references "The routine that moves the ADC registers to RAM" but I don't know how to go about finding that. I figured I would start with the Mass Airflow Volts as I would like to look into that further at a later time.

I figured I could work backwards from the "SsmGet_Mass_Airflow_Sensor_Voltage_P18". I saw in that SSM routine that it was loading the value from RAM:FFFF4024. Which I believe is the raw uint16 value.

I then looked at xref to that location to see if I could fine a reference that loaded a value to RAM:FFFF4024. There are 92 xref's to that location, but all of them appear to be reading the value, not loading it.

The only other thing I can think of is that when the location is loaded with the ADC value it could be using indirect addressing, but I'm just learning about that so I don't really know.

Any help is appreciated. I'm new to this so I may be making a mistake somewhere.


Top
 Profile  
 
 Post subject: Re: Learning How to Disassemble a 32Bit ROM - AE5L600L
PostPosted: Wed Nov 27, 2013 5:31 pm 
Offline
Senior Member

Joined: Mon Jan 19, 2009 6:31 pm
Posts: 1615
Location: Moscow, Russia
There are some tricks.
You may start to analize usage of the ADC registers. Moreover some chips are able to move ADC results directly to RAM thru DMA.
Or those values maybe copyed into RAM inside the cycle where just the first address of the data array is involved.


Last edited by Sasha_A80 on Wed Nov 27, 2013 7:46 pm, edited 2 times in total.

Top
 Profile  
 
 Post subject: Re: Learning How to Disassemble a 32Bit ROM - AE5L600L
PostPosted: Wed Nov 27, 2013 7:23 pm 
Offline
Experienced
User avatar

Joined: Thu Jul 23, 2009 5:46 pm
Posts: 863
This^ You may peek at the hardware/software manuals and see if any of the addresses match up. I can't remember if they are hard coded or configured in firmware.. If it is hard coded and you can correspond the addresses to the ADC channel #.

When you follow the RAM references 'up' the chain and they stop (read only), you may have found the array, or as you mentioned, indirect addressing :( You can confirm this by looking at the other longwords in this area and following the references. You should eventually see references to MAP, IAT, and other sensors on the ADC if you're there.

I would start with something like battery volts and trace it up the chain and see what they have in common.

_________________
Please do not send me support questions via PM, use the forum instead!


Top
 Profile  
 
 Post subject: Re: Learning How to Disassemble a 32Bit ROM - AE5L600L
PostPosted: Wed Nov 27, 2013 9:16 pm 
Offline
Newbie

Joined: Tue Jan 27, 2009 8:45 pm
Posts: 50
Ok,

I looked at the Manual before and saw this, but I guess I forgot to mention it.

https://www.dropbox.com/s/ssemaujdh8ymnir/ADC%20Registers.jpg

The addresses in that list are at higher addresses than what I expect to even be allowed. When adding the RAM section it was suggested to start at FFFF0000 with a length of 0000BFFF. And so the highest address in my disassembly is FFFFBFFF.

Maybe I am just ignorant, but that doesn't make sense to me.


Top
 Profile  
 
 Post subject: Re: Learning How to Disassemble a 32Bit ROM - AE5L600L
PostPosted: Wed Nov 27, 2013 10:29 pm 
Offline
RomRaider Developer

Joined: Thu May 21, 2009 1:49 am
Posts: 7323
Location: Canada eh!
If you create another segment for the high addresses that all the CPU peripherals live in you can then see references to them in code.
For the SH7058 make a segment from 0xFFFFD000 - 0xFFFFF87F
You will need the sh3.cfg file I created. Move it into the IDA config directory replacing the existing file if you have not done so yet. If you have a new version of IDA (6.4) this file is already included in the IDA distribution.
Once setup you will need to "Re-Analyze" so IDA can map the addresses to the register names.

To find the routine that reads the ADC look for the ADC control register addresses referenced in code (F838 and F858). There will be a couple.
You are on the right track with 0xFFFF4024 as that is either the start of the ADC values in RAM or is within it.

Once the ADC is read to RAM, the RAM area is referenced and read into another section of RAM which makes two copies of ADC values in RAM. Some of the Sensor Scaling routines reference these RAM sections. So if you look at a temperature sensor scaling table and follow references back to code where it is used, you will see the RAM address referenced at the very beginning of the routine.

bubba2533 wrote:
The only other thing I can think of is that when the location is loaded with the ADC value it could be using indirect addressing, but I'm just learning about that so I don't really know.

Indirect addressing is used extensively, so this makes finding all references to any RAM address a challenge.


Last edited by dschultz on Tue Dec 03, 2013 3:32 am, edited 1 time in total.
Fixed address range


Top
 Profile  
 
 Post subject: Re: Learning How to Disassemble a 32Bit ROM - AE5L600L
PostPosted: Thu Nov 28, 2013 5:17 am 
Offline
Senior Member

Joined: Mon Jan 19, 2009 6:31 pm
Posts: 1615
Location: Moscow, Russia
Hex-Rays promised to work around to adding AREA directive for SH processor.
Who knows what the future holds.
This will help to assign applicable RAM and SFR area within sh3.cfg file.
Currently those segments should be added manually.


Top
 Profile  
 
 Post subject: Re: Learning How to Disassemble a 32Bit ROM - AE5L600L
PostPosted: Mon Dec 02, 2013 4:25 pm 
Offline
Newbie

Joined: Tue Jan 27, 2009 8:45 pm
Posts: 50
Thanks dschultz, I got that segment added now and will start looking at that.

I've also found an older thread that was helpful in explaining the CEL switch table and the example posted help me learn more about assembly language. (CEL routines in 32bit ECU explained)

Edit:

I am also not understanding td-d's post about resolving indirect addressing.

td-d wrote:
I've found a fantastic trick to resolve indirect addressing (well, for those of us who have not yet upgraded to IDA 6.3), using user defined offsets.

for example:

Code:
mov.l   #unk_FFFF636C, r0
ldc     r0, gbr
add     #(unk_FFFF6360 - unk_FFFF636C), r15
mov.l   #Ram_Vehicle_Speed_0, r2
fmov.s  @r2, fr15
mov.l   #Ram_Memorised_Cruise_Speed_, r2
fmov.s  @r2, fr5
fmov    fr5, fr14


Copy the address of the base - GBR, or whatever base is used. Select the indirect reference, and press control-R to get to the user defined offset GUI window. Paste the address into the base address field and enter - it nicely resolves the reference for you, and as a bonus, also creates an X-ref. Winner!


Can someone post a before and after example? I think that should clear it up for me.


Top
 Profile  
 
 Post subject: Re: Learning How to Disassemble a 32Bit ROM - AE5L600L
PostPosted: Mon Dec 02, 2013 7:13 pm 
Offline
RomRaider Developer

Joined: Thu May 21, 2009 1:49 am
Posts: 7323
Location: Canada eh!
bubba2533 wrote:
Thanks dschultz, I got that segment added now and will start looking at that.

I've also found an older thread that was helpful in explaining the CEL switch table and the example posted help me learn more about assembly language. (CEL routines in 32bit ECU explained)

You can also review the output generated by the MakeCELPointers.idc script to gain a bit more insight into the CEL table. Also look at the <dtcode> section of the latest logger.xml definition.

bubba2533 wrote:
Edit:

I am also not understanding td-d's post about resolving indirect addressing.

td-d wrote:
I've found a fantastic trick to resolve indirect addressing (well, for those of us who have not yet upgraded to IDA 6.3), using user defined offsets.

for example:

Code:
mov.l   #unk_FFFF636C, r0
ldc     r0, gbr
add     #(unk_FFFF6360 - unk_FFFF636C), r15
mov.l   #Ram_Vehicle_Speed_0, r2
fmov.s  @r2, fr15
mov.l   #Ram_Memorised_Cruise_Speed_, r2
fmov.s  @r2, fr5
fmov    fr5, fr14


Copy the address of the base - GBR, or whatever base is used. Select the indirect reference, and press control-R to get to the user defined offset GUI window. Paste the address into the base address field and enter - it nicely resolves the reference for you, and as a bonus, also creates an X-ref. Winner!


Can someone post a before and after example? I think that should clear it up for me.

From the example above.
He says - copy the address loaded to gbr at the beginning of the routine, FFFF636C
Select the indirect reference - so select the operand of the opcode 'add'.
Press Crtl-R to bring up the edit window and paste the gbr address into the base field.


Top
 Profile  
 
 Post subject: Re: Learning How to Disassemble a 32Bit ROM - AE5L600L
PostPosted: Mon Dec 02, 2013 8:18 pm 
Offline
Newbie

Joined: Tue Jan 27, 2009 8:45 pm
Posts: 50
dschultz,

You worded it a little bit better, but I'm still not sure. I'll say what I am thinking and you let me know if I'm wrong.

I am thinking the code used to look like this:

Code:
mov.l   #unk_FFFF636C, r0
ldc     r0, gbr
add     #(unk_FFFF6360 - gbr), r15
mov.l   #Ram_Vehicle_Speed_0, r2
fmov.s  @r2, fr15
mov.l   #Ram_Memorised_Cruise_Speed_, r2
fmov.s  @r2, fr5
fmov    fr5, fr14

And you select the "gbr" in the add line, then hit Ctrl-R and paste FFFF636C into the base field because we know gbr=FFFF636C from the previous lines.
Also check the box that says: treat the address as a plain number.


Top
 Profile  
 
 Post subject: Re: Learning How to Disassemble a 32Bit ROM - AE5L600L
PostPosted: Mon Dec 02, 2013 8:25 pm 
Offline
Moderator

Joined: Thu May 20, 2010 8:01 am
Posts: 3117
Location: Johannesburg, South Africa
Bingo, that's exactly how. Worthwhile also ticking 'treat the base address as a plain number'.

_________________
He who dies with the most gadgets wins.

Please do not PM me - use the email option.


Top
 Profile  
 
 Post subject: Re: Learning How to Disassemble a 32Bit ROM - AE5L600L
PostPosted: Mon Dec 02, 2013 11:48 pm 
Offline
Newbie

Joined: Tue Jan 27, 2009 8:45 pm
Posts: 50
dschultz wrote:
For the SH7058 make a segment from 0xFFFFD00 - 0xFFFFF87F


I'm assuming you meant 0xFFFFD000 - 0xFFFFF87F. Just realized this when trying to start over to make sure I didn't screw anything up.


Top
 Profile  
 
 Post subject: Re: Learning How to Disassemble a 32Bit ROM - AE5L600L
PostPosted: Tue Dec 03, 2013 3:31 am 
Offline
RomRaider Developer

Joined: Thu May 21, 2009 1:49 am
Posts: 7323
Location: Canada eh!
Oops, yes I missed a 0


Top
 Profile  
 
 Post subject: Re: Learning How to Disassemble a 32Bit ROM - AE5L600L
PostPosted: Tue Dec 03, 2013 2:52 pm 
Offline
Newbie

Joined: Tue Jan 27, 2009 8:45 pm
Posts: 50
Ok, so I think I found the ADC code, but I am trying to resolve the gbr indirect references and it is not formatting like I thought it would.

I also renamed the register locations so they would show up. Is there any reason that the .cfg file doesn't automatically format and rename the register locations?

Edit: Pretty sure I did something wrong. Will look at it again and post if I have any more problems.


Top
 Profile  
 
 Post subject: Re: Learning How to Disassemble a 32Bit ROM - AE5L600L
PostPosted: Tue Dec 03, 2013 8:28 pm 
Offline
Senior Member

Joined: Mon Jan 19, 2009 6:31 pm
Posts: 1615
Location: Moscow, Russia
sh3.cfg is used the first time you are loading the file.
After that changes inside .cfg are not applied to your project.

In order to implement your changes in .cfg file save the project into .idc script and download the your initial binary again and apply saved .idc after that.


Top
 Profile  
 
 Post subject: Re: Learning How to Disassemble a 32Bit ROM - AE5L600L
PostPosted: Wed Dec 04, 2013 7:57 pm 
Offline
Newbie

Joined: Tue Jan 27, 2009 8:45 pm
Posts: 50
Ok, I have determined a few questions while digging in the disassembly some more.

So it looks like the sh3.cfg file did work, but because I added the segment for the CPU peripherals after loading the file those addresses did not get named. I'm not sure if I'm missing something but when loading the file there is no way to define this location. So until Hex Rays does something we are going to have to name these addresses manually correct?

My next task for myself is to determine how r15 is used as the stack pointer when calling a subroutine and how it returns from the called sub.
I will explain where I am getting lost below.

Previously r14 is h'0 and r15 is h'FFFFBFA0

Code:
ROM:00000762 sub_762:                                ; CODE XREF: sub_65C+Ap
ROM:00000762                 mov.l   r14, @-r15
ROM:00000764                 sts.l   pr, @-r15
ROM:00000766                 mov.w   #h'5A1F, r3
ROM:00000768                 mov.w   #WDT_RSTCSR[W]_B, r2
ROM:0000076A                 mov.w   r3, @r2         
ROM:0000076C                 mov.w   #WDT_TCSR[RW]_B, r14
ROM:0000076E                 add     #-h'1F, r3
ROM:00000770                 mov.w   r3, @r14       
ROM:00000772                 mov.l   #sub_EE4, r3
ROM:00000774                 jsr     @r3 ; sub_EE4
ROM:00000776                 mov.b   @r14, r1

Now below is where I get lost.
Code:
ROM:00000EE4 sub_EE4:                                ; CODE XREF: sub_484+10p
ROM:00000EE4                                         ; sub_65C+50p ...
ROM:00000EE4                 mov.l   r14, @-r15
ROM:00000EE6                 sts.l   pr, @-r15
ROM:00000EE8                 mov.w   #SYCSR2_[R]_B, r3
ROM:00000EEA                 add     #-4, r15
ROM:00000EEC                 mov.b   @r3, r14
ROM:00000EEE                 mov.w   #h'FB, r4 ;


Ok, so where I get lost is the beginning of sub_EE4 because I don't understand how @-r15 (@h'FFFFBF9F) can be overwritten when it was loaded in sub_762. How would it know where to return from sub_762?

The only explanation I can think of is that the SP (r15) is reduced or incremented with every jsr or rts instruction.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 26 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Style based on FI Subsilver by phpBBservice.nl