-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
why this hasn't seen activity in like five years #9
Comments
Hi @Ravenslofty. I can't say I have much experience doing work of this calibre, but I'd like to at least try and help. Do you have a branch you've been using to work on this or a place to catalogue progress on the file? |
No, the only branch is I'd be happy to give a rough guide to how to write the SVD, but it's quite late in the day, so I'll probably have to do it tomorrow (if I remember). |
Fair enough, makes sense. If it won't be a problem, that would be great, thanks! I'll read up about the file format in the meantime. |
Let's pick the timers as a starting point. First we need a pretty basic skeleton: <peripheral>
<name>TIMER</name>
<version>1</version>
<description>Programmable Timers. See EE User's Manual, Chapter 4.</description>
<groupName>TIMER</groupName>
</peripheral> Then we read the manual a little: So, let's sketch these registers: <registers>
<register>
<name>T0_MODE</name>
<description>Register for setting modes and reading status</description>
</register>
<register>
<name>T0_COUNT</name>
<description>Counter register</description>
</register>
<register>
<name>T0_COMP</name>
<description>Comparison register</description>
</register>
<register>
<name>T0_HOLD</name>
<description>Hold register</description>
</register> Let's read the manual a little more: That's a bunch of fields, let's sketch them too. Most of these can be described with <field>
<name>CLKS</name>
<description>Clock Selection</description>
<bitRange>[1:0]</bitRange>
<enumeratedValues>
<enumeratedValue>
<name>BUSCLK</name>
<description>BUSCLK (147.456MHz)</description>
<value>0</value>
</enumeratedValue>
<enumeratedValue>
<name>BUSCLK16</name>
<description>1/16 of the BUSCLK</description>
<value>1</value>
</enumeratedValue>
<enumeratedValue>
<name>BUSCLK256</name>
<description>1/256 of the BUSCLK</description>
<value>2</value>
</enumeratedValue>
<enumeratedValue>
<name>HBLNK</name>
<description>External Clock (H-BLNK)</description>
<value>3</value>
</enumeratedValue>
</enumeratedValues>
</field> but Let's read the manual a little more: Now that's just a 16-bit value, so we encode this as a <register>
<name>T0_COUNT</name>
<description>Counter register</description>
<fields>
<field>
<name>COUNT</name>
<description>Counter Value. The counter value is incremented according to the conditions of the clock and the gate signal specified in the Tn_MODE.</description>
<bitRange>[15:0]</bitRange>
</field>
</fields>
</register>
Okay, but where are the addresses for these registers? If we go back to Chapter 2, we have the EE memory map, which gives us this: And so we can specify at the top of "Wait, 0xB0000000?" MIPS - and the PS2 because of MIPS - has a bunch of overlays of memory. Then we can add in the various |
I see, that clears up a lot of the confusion I had when going through the svd. Thanks for the detailed breakdown! If I may try summarise to make sure I understood:
Is that more or less the procedure for a typical peripheral? Also, with regards to documentation sources, would everything needed be accessible via the PS2-Programming-Docs repo? That's what I've been reading so far (not counting ps2tek). |
Yes, I would say so. There are, however, a notable number of atypical peripherals - the GS is an excellent example. Another thing I would mention is that
Indeed. |
True, too true. I'm sorry, one more question regarding the timer register: In the ee users manual in chapter 2.2.1, the T0_COUNT register is offset by 0x0000, but in the svd, it's 0x0010. The same pattern occurs for the other timers too. |
You are correct; I must have gotten confused by Chapter 2 being in the order of MODE, COUNT, COMP, HOLD when the hardware order is COUNT, MODE, COMP, HOLD. Good spot. |
Thanks! I can take care of that if you'd like. Also, I see the FIFO section is pending. How about I begin with that? |
The FIFO is pretty low on the list of things; I think the (the DMAC's already been done, fortunately) |
Okay, I'll begin with that. Will keep you posted on it. |
Just added the fields for the |
Looks good to me. |
Just published a PR for the GIF registers. When you can, would you please give it a look? Please do scrutinise it since it's my first time working on SVD files. |
I'm going to correct myself, there is a relatively important thing which isn't in there: in the EE User's Manual, there is a reference to some registers which do not exist in the GS User's Manual - IIRC, at least These were left undocumented because Sony didn't want people fucking with the video config outside of the As far as I know, the only reference for this is, uh, Linux for PlayStation 2 or perhaps the cleaned up driver |
Ah, interesting. Oh well, no project worth doing is free of complications. Given it would involve some trickery to properly use as mentioned, intentionally lacks documentation, and the aforementioned syscall is already wrapped and does the work for us, I suppose it's low priority for the time being? |
Thinking about it, I'm not sure I trust the BIOS bindings anymore; #4 migrated from I think the only way to make sure it doesn't unusably bitrot would be to write it in Rust proper, which means those registers will need to be encoded in the SVD. |
Hmm, a fair point. I can try tackle the task of documenting them in the SVD later on today. I can create an issue about the task and keep track of progress there. What do you think? |
Sounds good. |
@Ravenslofty going back to this for a second. Is the reason basically that ps2sdk relies on an old fork of gcc w/ some patches on top which has ABI-mismatches with MIPS code generated by LLVM or something else? If it's the former then trying to use the gcc rustc backend might be an option. I looked into this two years ago and it also requires a gcc fork to build a patched version of libgccjit.so so that would require some work to combine the two stacks of patches on a version of gcc that works for both the rustc backend and ps2sdk but it would let you avoid the tedious work of writing register bindings. Just a thought though, fwiw for my rust ps1 sdk I went with the tedious register binding approach. Also how reliable is the code you're generating with rustc rn. Your target JSON uses MIPS II but can that emit any instructions the EE doesn't implement or have othe codegen issues? I skimmed through your clang patch stack and I assumed at least some of those would be required for reliable codegen. I'm asking because there was a similar issue for the ps1 that basically generated incorrect code when returning from a function and iirc the rust psp folks have fixed similar MIPS codegen problems. |
When I said "old version of GCC", I meant "GCC 3.2.3". It seems like they've managed to port the EE compiler to GCC 10.2, so this might be feasible. However:
I'm really, really not convinced "maintain your own GCC fork, and require users to build their own rustc" is less effort than the "tedious register binding approach".
Sure it can; atomic instructions are not implemented in the EE. There's also the "short loop bug", but this appears to have been fixed in all production silicon, so I'm not too worried there. But I don't particularly mind doing emulation of instructions because Prussia will need to install a bunch of exception handlers anyway to fail """gracefully""". |
Oh yeah I definitely meant developer effort not user effort haha, and even then I'm not saying register binding is a bad approach. It probably lets you create a more ergonomic rust API than wrapping and linking against existing C/asm code anyway. I think the gcc backend might be interesting to consider if for example you could provide a prebuilt libgccjit.so either when running rustc or to a rustc build, but it's probably not too useful to speculate on what that would look like until the gcc backend becomes more integrated rustc and they upstream the rest of their patches to gcc.
Neat! good to hear codegen works |
For ABI reasons, linking to PS2SDK from Rust isn't a feasible approach.
So, five years ago, I hatched a plan: if the data in the official manuals could be encoded in System View Definition then a tool like svd2rust could be used to generate a set of register bindings and remove the misery of manually abstracting over all the things in the PS2. It seemed like a good idea at the time.
Unfortunately, I majorly underestimated the effort it would take to encode data into SVD; the manuals are PDF format, and are too irregular to attempt to parse directly - you would be writing almost as many exceptions as you would be writing parsing rules.
The only way I've found that reliably works is to write the SVD by hand, referencing the manuals. Understandably, pretty much everybody who comes across this project and asks how they can help gets cold feet after I explain this to them.
I don't really know how to resolve this problem, and that's why this project hasn't seen activity in five years.
I don't know if anybody will come across this issue and offer assistance in doing mind-numbing work, but perhaps this can offer an explanation for why things are stuck.
The text was updated successfully, but these errors were encountered: