PDA

View Full Version : PSP Daedalus Blog Update - June 11



burrito
June 12th, 2007, 01:08
via http://strmnnrmn.blogspot.com/


Tracking down the SSB Dynarec Bug

Yesterday I said I'd provide some more details about the Super Smash Bros. dynarec fix. The actual fix is fairly straightforward, but I thought the process of tracking down the issue was quite interesting and worthy of a couple of blog posts.

When I first started looking at SSB I noted that although the game ran fine without dynarec, it would always hang when trying to enter the main entry with dynarec enabled.

I've been programming professionally for around 6 years now and I can safely say that debugging dynarec bugs is one of the hardest categories of problems I've ever had to work on. For a start, because the code is generated on the fly, you don't have the luxury of source level debugging, and without spending time reverse engineering the original rom image, you don't even know what the generated dynarec code is meant to be doing. It's very much like working blindfolded.

And it gets even worse. I've fixed dynarec problems in the past which were the result of generating incorrect code for a fragment over 500 million instructions into emulation. This would be bad enough, but it can be many thousands of instructions later before this causes emulation finally diverges from the correct path. Just identifying the exact point at which the emulation starts to diverge from the correct sequence of instructions can be like finding a needle in particularly large haystack. While blindfolded :)

Over the years of trying to debug problems like these I've built up a set of tools and learned a few tricks along the way which you might find quite interesting. Although I'm going to talk about them in the context of tracking down this dynarec issue, I've found some of the techniques useful in solving other problems so you might find other ways of applying them too.

One of the first things I do when trying to identify a dynarec issue with Daedalus is to see if the problem is reproducible on the PC build of the emulator. Although it is possible to use GDB with PSPLink, I've never got this up and running and I'm much more comfortable debugging with Visual Studio. Also, working with the PC build is usually much faster than working with the PSP build (debug builds run around 10x faster on the PC, and build times are much quicker.)

Not all dynarec issues can be debugged in this way - the PSP and PC builds have different code generation back-ends (i.e. MIPS and x86 code generation respectively) so bugs in the MIPS code generation won't usually be reproducible in the PC build. The dynarec system in Daedalus shares a common frontend (trace selection and recording) between the two platforms, which means that if I can reproduce the problem on both platforms, I can narrow down the likely location of the bug to this area.

Fortunately this particular bug manifested itself in both the PC and the PSP builds, so I knew that if I fixed the bug on the PC build, it should fix the PSP build too. What I needed to find out next is what the emulator was doing differently when dynarec was enabled compared to when it was disabled.

If dynarec is running without errors, then the sequence of executed instructions should exactly match that executed with dynarec disabled. If I could log details about all the instructions executed with dynarec disabled, and again with dynarec enabled, I should be able to compare the two logs to figure out the exact point at which dynarec is going out of sync. This all relies on the fact that the emulator is totally deterministic, i.e. that running the emulator twice in succession with the same settings should give exactly the same results.

Unfortunately, for a variety of reasons my dynarec solution doesn't produce identical results to interpretation, the main reason being that for performance reasons I can only handle vertical blank and timer interrupts on the boundaries between fragments. For example, with dynarec disabled, the first vertical blank interrupt might occur exactly on the 625,000th instruction, but with dynarec enabled with might not occur until the 625,015th instruction. This means that the logs diverge at the instant the first VBL fires, and never regain synchronisation.

When I was originally developing the new dynarec system I put a lot of effort into writing a fragment simulator, the idea being that rather than executing the native assembly code for a given trace, I could keep track of the instructions making up the trace and interpret these individually instead. Theoretically fragment simulation is identical to dynarec code execution, even down to the way I handle VBLs and timer interrupts, and it's been very useful at identifying bugs in the dynarec code generation. What's particularly useful about fragment simulation however is that I can enable a setting which makes it handle interrupts exactly in the same way as the non-dynarec core, i.e. interrupts are handled precisely rather than on fragment boundaries.

Essentially Daedalus has four modes of operation:


* Dynarec + fragment execution
* Dynarec + fragment simulation (imprecise interrupt handling)
* Dynarec + fragment simulation (precise interrupt handling)
* Interpretative core



This tool is particularly powerful, because if I can ensure that dynarec+fragment execution is equivalent to dynarec+fragment simulation, and that dynarec+fragment simulation is equivalent to running the interpretative core, then I can use the transitive properties of these relations to ensure that dynarec+fragment execution is equivalent to running the interpretative core. Fragment simulation allows me to bridge the gap between these two modes of operation which would otherwise be very difficult to compare.

I think that's long enough for one post. Tomorrow I'll talk about how I used this technique to help track down the SSB dynarec bug.

-StrmnNrmn

gunntims0103
June 12th, 2007, 01:11
Moved to PSP news forum

This is absolutely great news

burrito
June 12th, 2007, 01:13
Any progress on Daedalus is good news :)

acn010
June 12th, 2007, 01:20
omg,,, a new tool which can fragments instructions for cleaner filtering!!!!! thats the best news i ever heard... now it would be faster and better,, but i want to see if with the progress, the sound will go on too

mavsman4457
June 12th, 2007, 01:24
This emulator is sweet!!!

masamune
June 12th, 2007, 01:28
YES!! I wanna tell everyone!! I'm calling my Grandma right now!!

fatcat04912
June 12th, 2007, 01:36
i cant wait ........oh wait im going to have to :(

maxipower90
June 12th, 2007, 01:43
its great to hear news, however it must be frustrating for you to be working this hard without major results, but this shows ur dedication for ur work and i admire ur work, hopefully one day you,ll look back at this with a cheeky grin on ur face, implying, I did that :) keep it up dude

jmendes
June 12th, 2007, 01:44
Great job on this emulator, Strmn! Itīs very educative to read such posts

DragonPimpsta
June 12th, 2007, 01:50
interesting....... i think

fatcat04912
June 12th, 2007, 02:08
your going to go very far in you life plus with the amount of work you did to the dynac you will know how it works so if you ever have a new problem with it in the futar you can say oh yeah i remember

acn010
June 12th, 2007, 02:13
fatcat04912, your sig is too big, at least put a spoiler in it

mike03$$$
June 12th, 2007, 02:13
this is good news to hear and keep up the good work I will be looking forward to it and I hope all of this would make wwf games work

factor remix
June 12th, 2007, 02:15
Great new dude, I didn't understand what you said... man I only understand "SSB" and "Dynarec"... lol:D. This is an amazing emulator that you had made, by your self... keep the good work!

BTW: StrmnNrmn, can I ask you a favor? Can you add an option to swap the Nintendo64 analog stick with PSP D-Pad? I really need this because I broke my analog stick... and I can only enjoy games like Grand Theft Auto (because there is a option to change your analog stick with the D-Pad) and some emulators (snes-tyl and gpSP).

I think this wont take too much coding, and people with my problem or with smililar problem can still enjoy your emulator and play Super Smash Bros. at a great speed.

felonyr301
June 12th, 2007, 02:26
Wow everytime I read one of his posts I feel smarter LOL!! Keep up the great work.

factor remix
June 12th, 2007, 02:30
^^When I read one of his post I feel more stupid...

Balthasar00
June 12th, 2007, 02:48
Meaby you could wiki some technical improvement you made in the dynarec debuging and psp coding. It sound to me like the biggest tour de force in the psp homebrew development so far.

emuking
June 12th, 2007, 03:02
cool even though i hardly understood any of that

Buddy4point0
June 12th, 2007, 03:17
i cant wait for the next update! the speed ups and compatability is great!

CaptainMorgan4
June 12th, 2007, 03:35
Yeah good s**t StrmnNrmn.


StrmnNrmn said perhaps for R13 he will poll for which title(s) he will work on for on the new build. So I figured since he told me this after a question I asked him, that I would take the liberty of setting up the poll for him. So could you guys give me some examples of what games you would like to see worked on, THAT DON'T CURRENTLY WORK 100% on R11/R12 (soon to be). I will make a poll, there will be 10 available choices, I figure whichever 10 games are the most popular asked for are the ones that will be put into the poll. Please don't ask for games that totally don't work as of know, only choose games that are semi-working and but have problems. Personally I choose that Diddy Kong Racing to be worked on, how about you?

Balthasar00
June 12th, 2007, 07:10
I'll like to see Mystical ninja goemon working better. It was a nice adventure game with many side-quests.
Theres fews steps to do in order to get the game starting. Then it play fine in the first town. But, as soon as you get in .. Kai ? area, (once you quit the town) there's a timer freeze. The game hang after a certain amount of time in this area. Not a random freeze in my opinion.

SmashinGit
June 12th, 2007, 08:37
Not that I really understand what he's talking about but I can appreciate the work load involed. Thanks so much.

alucard001
June 12th, 2007, 17:38
does super smash bros work?

Solidsnake3000
June 12th, 2007, 18:14
well as long as it is a step to full speed iam good and happy about this

mfz64
June 12th, 2007, 21:17
damn you acn010! your effing sig freaked me out! :)

Destarus04
June 12th, 2007, 22:50
I used to think I knew a thing or two about dynarec, but now I realize I'm as clueless as Paris Hilton at a prison lunch line... thanks Strmn Nrmn...

Only kidding, of course.
Great job on Daedalus man, it's really been leaps and bounds this year.

I'm curious though, since the PC and PSP versions are being built in paralell, are you going to release a new PC version in the near future?

Basil Zero
June 13th, 2007, 00:56
cant wait for the next release on this great emulator.

CaptainMorgan4
June 13th, 2007, 01:11
StrmnNrmn said perhaps for R13 he will poll for which title(s) he will work on for on the new build. So I figured since he told me this after a question I asked him, that I would take the liberty of setting up the poll for him. So could you guys give me some examples of what games you would like to see worked on, THAT DON'T CURRENTLY WORK 100% on R11/R12 (soon to be). I will make a poll, there will be 10 available choices, I figure whichever 10 games are the most popular asked for are the ones that will be put into the poll. Please don't ask for games that totally don't work as of know, only choose games that are semi-working and but have problems. I plan to start the poll as soon as R12 is released to the public from StrmnNrmn, so he will have an idea of what to work on for R13. Personally I choose that Diddy Kong Racing to be worked on, how about you?