|
RomRaider
Documentation
Community
Developers
|
| Author |
Message |
|
Sasha_A80
|
Post subject: Re: Hacking with HEW Posted: Wed Jan 11, 2012 10:37 am |
|
 |
| Senior Member |
Joined: Mon Jan 19, 2009 6:31 pm Posts: 1615 Location: Moscow, Russia
|
|
Put a couple of NOPs before using (RTS instruction ) updated stack pointer.
This processor uses pipelined instruction execution.
|
|
| Top |
|
 |
|
dschultz
|
Post subject: Re: Hacking with HEW Posted: Wed Jan 11, 2012 2:59 pm |
|
 |
| RomRaider Developer |
Joined: Thu May 21, 2009 1:49 am Posts: 7323 Location: Canada eh!
|
|
Yes, Section 8.8.5 of the SH-2E Software manual.
|
|
| Top |
|
 |
|
Merp
|
Post subject: Re: Hacking with HEW Posted: Wed Jan 11, 2012 3:18 pm |
|
 |
| Experienced |
 |
Joined: Thu Jul 23, 2009 5:46 pm Posts: 863
|
|
I've been doing some reading on C/C++ lately, and really dug into the latest HEW project today. I've got a good grasp on all the code, how each file works and interacts with other files, and how the pointers are set up. However, I could use some help with the HEW interface itself.
1. How does HEW interact with the full ROM file? I assume I need to add it somewhere or tell HEW where it is, downloads? What's up with EcuHacks2.x?
2. What windows/settings should be open/used while running a debug test?
_________________ Please do not send me support questions via PM, use the forum instead!
|
|
| Top |
|
 |
|
dschultz
|
Post subject: Re: Hacking with HEW Posted: Wed Jan 11, 2012 4:21 pm |
|
 |
| RomRaider Developer |
Joined: Thu May 21, 2009 1:49 am Posts: 7323 Location: Canada eh!
|
Download the ROM module as a binary file worked for me. .x is the debug executable file. In post #1 NSFW wrote: Open a Disassembly window (see the View menu). You should see a highlighted MOV.L instruction at 0xA0000000, labeled "_ResetHandler." This is basically the "main" function for my hack test harness. At the top of the disassembly window are three buttons, click the middle one to view source mixed with the disassembled code.
|
|
| Top |
|
 |
|
nsfw
|
Post subject: Re: Hacking with HEW Posted: Wed Jan 11, 2012 6:44 pm |
|
 |
| Moderator |
Joined: Thu Nov 23, 2006 2:23 am Posts: 2565
|
Sasha_A80 wrote: Put a couple of NOPs before using (RTS instruction ) updated stack pointer.
This processor uses pipelined instruction execution. dschultz wrote: Yes, Section 8.8.5 of the SH-2E Software manual. Thanks guys! I'll try adding some NOPs tonight. This seems like something that the compiler should take into account, so I wonder if there's a checkbox somewhere that would get it to do that automatically. And I'll have to print that section of the manual. I have a PDF of it but I basically just skimmed it and printed the list of instructions, and there's no hint of this in the section that I printed. I thought that delayed branches were the only scenario for out-of-order execution... I had always thought of pipelining as a way for CPUs to execute carefully-ordered instructions faster, but had never guessed that it would lead to this sort of surprise when instructions are not ordered optimally.
_________________ 2005 Legacy GT w/ ATP 3076, IWG, MBC, BCS, BC 272, LC, FFS, OMG Please don't send questions via PM. Post a thread and send me a link to it instead. Thanks!
|
|
| Top |
|
 |
|
nsfw
|
Post subject: Re: Hacking with HEW Posted: Wed Jan 11, 2012 7:03 pm |
|
 |
| Moderator |
Joined: Thu Nov 23, 2006 2:23 am Posts: 2565
|
Merp wrote: I've been doing some reading on C/C++ lately, and really dug into the latest HEW project today. I've got a good grasp on all the code, how each file works and interacts with other files, and how the pointers are set up. However, I could use some help with the HEW interface itself.
1. How does HEW interact with the full ROM file? I assume I need to add it somewhere or tell HEW where it is, downloads? What's up with EcuHacks2.x?
2. What windows/settings should be open/used while running a debug test? EDITED FOR ACCURACY: TWICE: EcuHacks2.x is just the code in the HEW project. To test the interactions between SD and the stock ROM, you have to download a ROM that at least has the Pull2d hook applied to the stock 'get maf' routine. You can download freshly rebuilt versions of EcuHacks2.x over the top of the (not freshly rebuilt) ROM to get fast edit/compile/test turnaround times. If you go to the Debug menu, there's a "Debug Settings..." menu item. That will let you pick the ROM file, and set the download order so that EcuHacks2.x downloads over the top of the ROM. Usually I just have the project tree on the left (source files, download modules, etc) and the CPU register window on the right, and source code filling the rest of the window. Occasionally I'll open a "memory" window to verify that things are being written to RAM correctly, and I'd advise doing that to begin with because it will indicate whether you have the simulator's RAM configured correctly. You should see mostly 00s, not FFs, in the 0xFFFF0000 - 0xFFFFFFFF range.
_________________ 2005 Legacy GT w/ ATP 3076, IWG, MBC, BCS, BC 272, LC, FFS, OMG Please don't send questions via PM. Post a thread and send me a link to it instead. Thanks!
|
|
| Top |
|
 |
|
dschultz
|
Post subject: Re: Hacking with HEW Posted: Thu Jan 12, 2012 4:41 am |
|
 |
| RomRaider Developer |
Joined: Thu May 21, 2009 1:49 am Posts: 7323 Location: Canada eh!
|
NSFW wrote: Code: MOV.L @(H'0040:8,PC),R1 MOV.W @(H'0008:8,PC),R2 MOV.L R2,@R1 MOV R14,R15 - this executes MOV.L @R15+,R14 - this is skipped RTS - this is skipped NOP - this executes, and the bytes that follow it also get executed
Are you downloading the ROM first then your compiled hack? If so, then is your hack located in the correct area of memory such that it is not overwriting part of the ROM that is important and picking up instructions from the ROM that should not be present? I get to here and the next instruction causes an "Exception Error/Address Error" in the Debugger.
You do not have the required permissions to view the files attached to this post.
|
|
| Top |
|
 |
|
nsfw
|
Post subject: Re: Hacking with HEW Posted: Thu Jan 12, 2012 7:27 am |
|
 |
| Moderator |
Joined: Thu Nov 23, 2006 2:23 am Posts: 2565
|
Thanks! I never noticed the debugging info in the output window before. That helped me narrow it down to this line of C code: Code: *pMafSensorVoltage = MafVoltageToInternalUnits; Which is these three asm instructions: Code: MOV.L @(H'0040:8,PC),R1 MOV.W @(H'0008:8,PC),R2 MOV.L R2,@R1 The "MOV R14,R15" appeared to execute after those, which had me thinking that the problem was in that instruction or something after it, but in fact it's the final stages of "MOV.L R2,@R1" that cause the problem. MOV.L is for 4-byte values but R2 is not aligned on a 4-byte boundary. Wrong: Code: #define pMafSensorVoltage ((int*)0xFFFF2D21) Right: Code: #define pMafSensorVoltage ((short*)0xFFFF2D22) So I'm moving forward again... Thanks again for all the help, everyone.
_________________ 2005 Legacy GT w/ ATP 3076, IWG, MBC, BCS, BC 272, LC, FFS, OMG Please don't send questions via PM. Post a thread and send me a link to it instead. Thanks!
|
|
| Top |
|
 |
|
nsfw
|
Post subject: Re: Hacking with HEW Posted: Thu Jan 12, 2012 7:55 am |
|
 |
| Moderator |
Joined: Thu Nov 23, 2006 2:23 am Posts: 2565
|
|
I updated the post about downloading EcuHacks2.x and patched ROMs. For testing the SD stuff, it's essential to have a patched ROM, and I had kinda forgotten about that. But even the 'unit tests' for SD will call into the ROM code (outside of EcuHacks2.x) to verify that the ROM code can properly call into (and return from) the patch code.
I did a lot of early LC/FFS and SD testing without using a patched ROM, but at this point it's essential. I'll post another complete HEW zip before I go to bed tonight.
_________________ 2005 Legacy GT w/ ATP 3076, IWG, MBC, BCS, BC 272, LC, FFS, OMG Please don't send questions via PM. Post a thread and send me a link to it instead. Thanks!
|
|
| Top |
|
 |
|
nsfw
|
Post subject: Re: Hacking with HEW Posted: Thu Jan 12, 2012 8:26 am |
|
 |
| Moderator |
Joined: Thu Nov 23, 2006 2:23 am Posts: 2565
|
OK, this now builds with the SH2E compiler and all tests pass. If you set a breakpoint on the 'nop' in the TestFailed function in TestUtilities.c, it should get hit exactly once - there's a test that fails deliberately just to prove that failing tests will hit that break point. There's a TestRom directory under the EcuHacks2 project which contains an unmodified ROM and a batch file to create a patched ROM using the latest build of the HEW project. Don't anybody flash this just yet.  I still want to give it another once-over first.
You do not have the required permissions to view the files attached to this post.
_________________ 2005 Legacy GT w/ ATP 3076, IWG, MBC, BCS, BC 272, LC, FFS, OMG Please don't send questions via PM. Post a thread and send me a link to it instead. Thanks!
|
|
| Top |
|
 |
|
dschultz
|
Post subject: Re: Hacking with HEW Posted: Thu Jan 12, 2012 2:11 pm |
|
 |
| RomRaider Developer |
Joined: Thu May 21, 2009 1:49 am Posts: 7323 Location: Canada eh!
|
NSFW wrote: MOV.L is for 4-byte values but R2 is not aligned on a 4-byte boundary. As I was trying to fall asleep last night (or this morning) I was starting to think that there was an alignment problem, glad you found it.
|
|
| Top |
|
 |
|
Merp
|
Post subject: Re: Hacking with HEW Posted: Fri Jan 27, 2012 7:58 pm |
|
 |
| Experienced |
 |
Joined: Thu Jul 23, 2009 5:46 pm Posts: 863
|
Got most of my programming mode & CEL flashing stuff written up in C++ Running into an issue with RomPatch. I have added a couple new sections and files for my code. I got everything to compile, then added patches to metadata.s. When adding the latest patch, I started getting System Exception: Internal Error in TryReadPatches: Patch is null. To rule out bugs in my code or sections, I commented out the first patch in metadata.s (known to work and patch) and the latest patch works fine. Seems like there is some kind of limit causing it to break. As a workaround, I just moved the sub-sections of two patches into a single section. Some more questions: I'm trying to use character arrays to set value limits and default values of programming menu items. I was also trying to declare/init few arrays of selectable rev limiter values. Even specifying const on the array, it still loads every value of the array into the stack wasting a ton of cycles. Is there a way to declare/init them that will simply throw them in the data segment or do I need to include them in an assembly file? Is there a better way to implement *pCurrentValue? Currently I'm just setting it to a base, then adding the CurrentMenu each time it runs. Array of pointers? I don't think it's a big issue because this code only executes during programming (engine off), but it never hurts to learn the right/other ways. Code: char ValueLim[] = {1,1,1,1}; char DefaultValue[] = {0,0,0,0}; char MenuLim = (sizeof(ValueLim) / sizeof(char) ) - 1; // limit = 3 (FOUR MENU ITEMS) char Flashspeed = 10; char * pCurrentValue = pCurrentValueBase int i;
// more code here // *pCurrentValue is set based on *pCurrentMenu
//Accel is pressed, increment value if(*pCurrentValue == ValueLim[*pCurrentMenu]) { *pCurrentValue = 0; } else { (*pCurrentValue)++; }
Also, I'd like to streamline the porting process, and my code uses a ton of new RAM params that once tested will never be necessary for logger defs. When I was using ASM, I would just define a base in the data segment and use offsets: mov.b @(0x2,r3),r0 with a comment of what it was. Do you foresee any issues with something like this? From what I understand, #define just copies the right side at every occurance of the left. Code: #define pProgModeBase ((char*)0xFFFFDERP) #define pCharParam1 ((char*)(pProgModeBase + 1) #define pSomeFloat ((float*)(pCharParam1 +1) #define pSomeShort ((short*)(pSomeFloat +1)
_________________ Please do not send me support questions via PM, use the forum instead!
|
|
| Top |
|
 |
|
nsfw
|
Post subject: Re: Hacking with HEW Posted: Sat Jan 28, 2012 9:26 pm |
|
 |
| Moderator |
Joined: Thu Nov 23, 2006 2:23 am Posts: 2565
|
Note that if we were writing an app for Windows or iOS, I'd just suggest turning on all of the compiler optimizations, and stop looking at the assembly code.  But, since we're patching our code into Denso's... I think that anything that's going to go into a table definition should be declared globally (outside the function). That will allow you to skip the step where values get copied into stack memory. That also makes it possible to write self-test code that refers to those values, and it gives you more control over how the values are laid out in the ROM. I actually made a similar change to my LC/FFS code for those two reasons. I'll post my current project in a minute. I think the #define stuff should work. The preprocessor will recursively expand the macros, so you'll get something like "0xFFFFDERP+1+1+1" and I'm pretty sure that either the preprocessor or the compiler will turn that into "0xFFFFDERP+3" but you should double-check that. Or maybe not... I think I have a better idea. I haven't tested this yet so it might need some tweaking, but I'm sure we can do something like this to solve the same problem with less effort: Put these in a header file: Code: typedef struct { char ProgModeBase; char CharParam1; float SomeFloat; short SomeShort; char TinyArray[4]; } RamVariables;
#define pRamVariables ((RamVariables*)0xFFFFDERP)
And in your code: Code: void DoStuff() { if (pRamVariables->SomeShort > 42) { pRamVariables->SomeFloat += 1.23; pRamVariables->TinyArray[3] = 234; }
This way you only need to define one RAM address. You tell the compiler that there's a structure at that address, and you use the "->" operator to refer to fields inside the structure. The compiler should handle the rest.
_________________ 2005 Legacy GT w/ ATP 3076, IWG, MBC, BCS, BC 272, LC, FFS, OMG Please don't send questions via PM. Post a thread and send me a link to it instead. Thanks!
|
|
| Top |
|
 |
|
nsfw
|
Post subject: Re: Hacking with HEW Posted: Sun Jan 29, 2012 7:07 pm |
|
 |
| Moderator |
Joined: Thu Nov 23, 2006 2:23 am Posts: 2565
|
|
When RomPatch printed that error, I think it was looking for the 0x12340002 or 0x12340003 value that indicates the start of a new patch in the Metadata segment, and it didn't find either. If you post a copy of Metadata.s I'll be happy to take a look.
I've attached a zip of my current HEW project. It's still just LC/FFS and SD, but the SD patch now has an atmospheric pressure compensation table. I've also done a bit of re-arranging to make things easier to maintain. The LS/FFS patches have three segments, one for tables (stuff that will go into definition XML), one for logic, and one for an "end marker" that goes into Metadata.s by name. This way I can add new tables without invalidating old table XML, and I don't have to manually adjust the end-address of the segment in metadata.s.
One of the LC/FFS patches (the "hook" patch) still needs literal start and end addresses in the metadata file but I have a couple ideas that might fix that.
There's also a couple new self-tests to make sure that the segments don't overlap, end addresses are higher than start addresses, etc.
I'm trying to minimize the number of manual steps that are required when making patches or editing them, and for the manual steps that ARE needed, I'm trying to get HEW to detect as many mistakes as possible.
Yesterday I flashed the patch from this version of the project and it seems fine other than the FFS rev limiter being too low. I'll start a thread in the SD base maps section with the patch itself.
You do not have the required permissions to view the files attached to this post.
_________________ 2005 Legacy GT w/ ATP 3076, IWG, MBC, BCS, BC 272, LC, FFS, OMG Please don't send questions via PM. Post a thread and send me a link to it instead. Thanks!
|
|
| Top |
|
 |
|
nsfw
|
Post subject: Re: Hacking with HEW Posted: Tue Jan 31, 2012 9:47 am |
|
 |
| Moderator |
Joined: Thu Nov 23, 2006 2:23 am Posts: 2565
|
I keep wanting to do one more little thing before I declare a release... The attached zip file does the typedef struct thing that I mentioned earlier, so now only one RAM address has to be chosen, and the compiler does the rest. You still have to manually figure out the addresses for logger XML, but that's a lot less critical since errors in the XML will only break data logging. Human errors in choosing addresses could break motors, so I really like letting the compiler handle that.  It adds one or two instructions to each bit of code that reads or writes a memory location, but that's a small price to pay for getting rid of a whole class of potential human errors. And I have a hunch that even that will go away if I ever get the nerve to turn on optimizations - but for now I like the fact that the generated assembly code is really easy to understand and step through.
You do not have the required permissions to view the files attached to this post.
_________________ 2005 Legacy GT w/ ATP 3076, IWG, MBC, BCS, BC 272, LC, FFS, OMG Please don't send questions via PM. Post a thread and send me a link to it instead. Thanks!
|
|
| Top |
|
 |
Who is online |
Users browsing this forum: No registered users and 10 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
|
|