Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Warning on misaligned read/write operations ?
#1
Hello,

maybe this thread should go to another section but since I'm using PCSX2 0.9.8 on Windows, I put it here. I apologize if I was mistaken.

I'm currently modifying an existant PS2 program that works well, and my modification runs just fine on PCSX2.

However, if I try it on a real PS2, it crashes. I figured out it was due to some misaligned read/write operations, that is lh or sh to an odd address for example. But they are sometimes difficult to track.

Is there a way to force PCSX2 to show at least a warning when it occurs ?
Reply

Sponsored links

#2
(01-04-2013, 01:09 PM)Tryphon Wrote: Hello,

maybe this thread should go to another section but since I'm using PCSX2 0.9.8 on Windows, I put it here. I apologize if I was mistaken.

I'm currently modifying an existant PS2 program that works well, and my modification runs just fine on PCSX2.

However, if I try it on a real PS2, it crashes. I figured out it was due to some misaligned read/write operations, that is lh or sh to an odd address for example. But they are sometimes difficult to track.

Is there a way to force PCSX2 to show at least a warning when it occurs ?
The compiler should do it, not PCSX2.

PS: supposing that's the problem the solution pass by aligning the blocks in your data storage area. you may need to include dummy spaces if can't optimize the data structure. Even for PCSX2 (which is lenient to misaligned data from x86 inheritance) that would translate in better performance.
Imagination is where we are truly real
Reply
#3
The compiler doesn't, and PCSX2 could.

To be more precise, I use PS2dis to disassemble the game, but can't use the produced file to assemble (because of too many things that are unindentified). So I use PS2dis to compile some little modifications. PS2dis is not able to detect misalignment.

If you know a better tool, for an already existing program (if it were from scratch, of course I'd use a real assembler), I'm interested.

I add that I don't really see how compiler would do that : readings / writings are relative to a register, which value can be set or modified far away from the reading / writing. You have to excute the code to see that, and that's more the role of an emulator than a compiler ? (I precise that I'm not accustomed to code in asm, so I may be wrong)

EDIT : I didn't see your edit sorry. The problem is more difficult : in fact, the misalignment comes from the fact tat I changed the encoding of strings inside the program : they were using 2 bytes per character, I changed that to 1 (I had a good reason to do so).

So I must find all routines reading a character and modify the way it's read. Most of them were easy. But I'm facing one now that I do not find.

Just padding strings with dummy data won't be enough, and I'd like to avoid reverting to 2 bytes encoding.
Reply
#4
(01-04-2013, 01:52 PM)Tryphon Wrote: The compiler doesn't, and PCSX2 could.

To be more precise, I use PS2dis to disassemble the game, but can't use the produced file to assemble (because of too many things that are unindentified). So I use PS2dis to compile some little modifications. PS2dis is not able to detect misalignment.

If you know a better tool, for an already existing program (if it were from scratch, of course I'd use a real assembler), I'm interested.

I add that I don't really see how compiler would do that : readings / writings are relative to a register, which value can be set or modified far away from the reading / writing. You have to excute the code to see that, and that's more the role of an emulator than a compiler ? (I precise that I'm not accustomed to code in asm, so I may be wrong)

Sorry, I'm not acquainted with PS2 compilers, but my intuition tells me that using x86 compilers is not the "way to go" if meaning to use in real PS2 hardware.

If limited to use PS2dis and it has not the resources, then you may need to calculate by yourself every change made in every data structure, making sure to not change the alinement of the next entire block. if needed pad in dummy spaces to grant correct boundary.

PS: Maybe PCSX2 dev's version has debug functions able to warn about alignment, still what you are asking is for the emulator's devs to do extra work in an environment already struggling for every bit of performance to be concerned with third part errors verification.

You can get the source code and change and compile it yourself, maybe you are meant to become a PCSX2 developer or contributor Smile

Quote: add that I don't really see how compiler would do that : readings / writings are relative to a register, which value can be set or modified far away from the reading / writing. You have to excute the code to see that, and that's more the role of an emulator than a compiler ? (I precise that I'm not accustomed to code in asm, so I may be wrong)

Actually the problem is related with the address at the memory being in the correct boundary. Actual compilers have options to grant a block is generated at the correct starting address offset. If it does not have that function then that means troubles if your changes pushes the address distribution.

Well, you are in trouble if can't get correct tools for the work in sight. In the end you are using a disassembler to do that work and this is "daring" to say the least for more than just poking values and without changing structures. As yourself stated you want to create something to be used in real PS2 hardware, something PCSX2 would emulate later... this last is doing it's part of the bargain as yourself reported.

You are probably right in the assumption of misalignnement for PS2 probably is not lenient to it as x86 historically is (despite it meaning a greater performance hit)
Imagination is where we are truly real
Reply
#5
(01-04-2013, 02:44 PM)nosisab Ken Keleh Wrote: Sorry, I'm not acquainted with PS2 compilers, but my intuition tells me that using x86 compilers is not the "way to go" if meaning to use in real PS2 hardware.

I'm afraid I don't really have the choice. If you have a better idea I'm interested.

Quote:PS: Maybe PCSX2 dev's version has debug functions able to warn about alignment,

That was in fact (one of) the answer(s) I expect Smile
Do you (or someone) know if this is the case ? Or am I in the wrong forum for asing that ?

Quote:still what you are asking is for the emulator's devs to do extra work

No, your interpretation of my question is wrong Smile Being a developper myself (in others areas) I wouldn't even think of asking such a thing.

Quote:You can get the source code and change and compile it yourself, maybe you are meant to become a PCSX2 developer or contributor Smile

I don't know if you're a dev yourself but if it's the case, you know how much work it is to dive into a massive project you don't know (particularly so much a specialized as an emu), looking into thousands of C / ASM lines of code (I suppose that's the main languages used), just to add less than 3 lines of code.

Either the code exists (that I wouldn't be surprised) and I just want to know how to activate it, or I'll try to find another way.

Quote:Well, you are in trouble if can't get correct tools for the work in sight.

Yes, the main problem is tools. I didn't find many useful things on the net apart PCSX2 and PS2dis (which is not practical, but which has the good idea to exist).
Reply
#6
The main problem here is PCSX2 itself is meant to run on PC and uses tools for PC (actually the Visual Studio Express (for C++) and DirectX SDK). It's not the same as your reported issue that is making/compiling software to run on PS2 hardware.

Well, I'm really sorry I can't further help on that issue, maybe someone comes up with more information, keep following the thread for a while more. Good luck.
Imagination is where we are truly real
Reply




Users browsing this thread: 1 Guest(s)