Tinkering with Dreamcast's Sh4's architecture
-
- DCEmu Freak
- Posts: 65
- https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
- Joined: Sun Apr 10, 2011 12:05 pm
- Has thanked: 0
- Been thanked: 0
Tinkering with Dreamcast's Sh4's architecture
I've been researching more and more about Processors and x86 Assembly.
I've had a hard time finding decent resources and general information on the SH4 (or SuperH) CPU however from what I can find it's optimized for vector and matrix calculations. Actually reserving instructions and registers. I believe AMD's 3DNow takes a similar approach.
So I'm wondering, to what extent to the KOS utilize this functionality?
And is this what's actually going on? Like registers and instructions being reserved or am I just completely deluded?
Also, if anyone knows a decent Sh4 assembler, or any good resources on this CPU then I'd very much appreciate it!
I've had a hard time finding decent resources and general information on the SH4 (or SuperH) CPU however from what I can find it's optimized for vector and matrix calculations. Actually reserving instructions and registers. I believe AMD's 3DNow takes a similar approach.
So I'm wondering, to what extent to the KOS utilize this functionality?
And is this what's actually going on? Like registers and instructions being reserved or am I just completely deluded?
Also, if anyone knows a decent Sh4 assembler, or any good resources on this CPU then I'd very much appreciate it!
- RyoDC
- Mental DCEmu
- Posts: 366
- Joined: Wed Mar 30, 2011 12:13 pm
- Has thanked: 2 times
- Been thanked: 0
Re: Tinkering with Dreamcast's Sh4's architecture
1.Marcus Site. http://mc.pp.se/dc/cpu.html
Look at this page you found there everything that you need (programming and hardware manual covers almost everything. after reading it you can even develop your own board on which you can set sh4 processor).
2. About registers and etc. KOS using libkallisti.a as a main source of raw machine code. So you can look through this file, or even push it to the disassembler\debugger, and run for the step tracing, to see, what is actually happens with registers, memory, and etc. The one problem that I didn't find one on the net (I mean debugger). One had nullDC but I didn't found it good. there's still gdb debugger, and IDA, but IDa sucks with dreamcast code, so...
Look at this page you found there everything that you need (programming and hardware manual covers almost everything. after reading it you can even develop your own board on which you can set sh4 processor).
2. About registers and etc. KOS using libkallisti.a as a main source of raw machine code. So you can look through this file, or even push it to the disassembler\debugger, and run for the step tracing, to see, what is actually happens with registers, memory, and etc. The one problem that I didn't find one on the net (I mean debugger). One had nullDC but I didn't found it good. there's still gdb debugger, and IDA, but IDa sucks with dreamcast code, so...
Re: Tinkering with Dreamcast's Sh4's architecture
Thanks much! That one link is like an encyclopedia!RyoDC wrote:Marcus Site. http://mc.pp.se/dc/cpu.html
Look at this page you found there everything that you need (programming and hardware manual covers almost everything. after reading it you can even develop your own board on which you can set sh4 processor).
- RyoDC
- Mental DCEmu
- Posts: 366
- Joined: Wed Mar 30, 2011 12:13 pm
- Has thanked: 2 times
- Been thanked: 0
Re: Tinkering with Dreamcast's Sh4's architecture
Np man. Always ready to help.
How do I try to build a Dreamcast toolchain:
Re: Tinkering with Dreamcast's Sh4's architecture
I'm still stuck on an Assembler though, Hitachi's site seems long gone. I'm guessing you'd have to write your own -gulp-
So if anyone has any info on that, much appreciated again!
EDIT:
I just had a thought, the KOS development kit comes with GCC ready to compile straight out the box. Does this mean I've had an assembler all this time?
So if anyone has any info on that, much appreciated again!
EDIT:
I just had a thought, the KOS development kit comes with GCC ready to compile straight out the box. Does this mean I've had an assembler all this time?
- RyoDC
- Mental DCEmu
- Posts: 366
- Joined: Wed Mar 30, 2011 12:13 pm
- Has thanked: 2 times
- Been thanked: 0
Re: Tinkering with Dreamcast's Sh4's architecture
So you need an assembler?
Well, Hitachi site is not gone, but Hitachi, as a manufacturer of semiconductor devices, yes, it have. Now it's Renesas company. Anyway. Aboutt GCC.
Use this link.
http://www.delorie.com/djgpp/v2faq/faq8_20.html
Well, Hitachi site is not gone, but Hitachi, as a manufacturer of semiconductor devices, yes, it have. Now it's Renesas company. Anyway. Aboutt GCC.
Use this link.
http://www.delorie.com/djgpp/v2faq/faq8_20.html
How do I try to build a Dreamcast toolchain:
-
- DC Developer
- Posts: 142
- Joined: Thu Apr 03, 2008 7:01 am
- Has thanked: 0
- Been thanked: 4 times
- Contact:
Re: Tinkering with Dreamcast's Sh4's architecture
GCC (actually Binutils) provides an assembler. Just compile your .s file with kos-cc.
-
- DC Developer
- Posts: 414
- Joined: Thu Aug 20, 2009 11:00 am
- Has thanked: 0
- Been thanked: 2 times
Re: Tinkering with Dreamcast's Sh4's architecture
For those not familiar with gcc and assembly: A ".s" extension means the file gets passed directly to the assembler and must contain nothing but assembler friendly syntax. A ".S" extension (note that the s is capitalized) means the file is passed through the C preprocessor first before being sent to the assembler, so the file can have C friendly syntax for things like enum and define for stuff you'll use. So a .s file would have ".equ some_symbol, 1" while a .S file can have "#define some_symbol 1".Ayla wrote:GCC (actually Binutils) provides an assembler. Just compile your .s file with kos-cc.
Re: Tinkering with Dreamcast's Sh4's architecture
Well awesome!
You've all been a *huge* help. I'll see what I can come up with!
You've all been a *huge* help. I'll see what I can come up with!
Re: Tinkering with Dreamcast's Sh4's architecture
Okay, after looking further into the links provided (thanks again!), The Sh4 CPU does indeed have opcodes/registers for optimizing vector calcualtions. Which is awesome, but before I start screwing around with this, I've got a few questions about the KOS's PVR API. Sorry if any of these are obvious/idiotic.
The actual PVR headers are located under kernel/arch/pvr?
Also, is there any assembly involved with the PVR API? If so, where are these files in the KOS repo?
And, one other question... Does the PVR API take advantage of this?
I know I already asked this question, but I probably shouldn't be attempting to implement functionality that already exists.
Thanks!
The actual PVR headers are located under kernel/arch/pvr?
Also, is there any assembly involved with the PVR API? If so, where are these files in the KOS repo?
And, one other question... Does the PVR API take advantage of this?
I know I already asked this question, but I probably shouldn't be attempting to implement functionality that already exists.
Thanks!
-
- DC Developer
- Posts: 414
- Joined: Thu Aug 20, 2009 11:00 am
- Has thanked: 0
- Been thanked: 2 times
Re: Tinkering with Dreamcast's Sh4's architecture
Just doing
At the start of the file will take care of any pvr includes needed. Look at the examples in
kos/examples/dreamcast/pvr
Code: Select all
#include <kos.h>
kos/examples/dreamcast/pvr
- BlueCrab
- The Crabby Overlord
- Posts: 5663
- Joined: Mon May 27, 2002 11:31 am
- Location: Sailing the Skies of Arcadia
- Has thanked: 9 times
- Been thanked: 69 times
- Contact:
Re: Tinkering with Dreamcast's Sh4's architecture
The main include file for the PVR is kos/kernel/arch/dreamcast/include/dc/pvr.h (documentation). Note that this particular interface assumes that any 3D-related transformations you want done on the primitives are already done before feeding them in. It simply takes the data and feeds it directly to the hardware.
You may also be interested in kos/kernel/arch/dreamcast/include/dc/matrix.h (documentation) and kos/kernel/arch/dreamcast/include/dc/matrix3d.h (documentation), as they are the headers related to any matrix-type stuff that is in KOS proper. The 2ndmix example shows how to use some of that stuff, IIRC.
You may also be interested in kos/kernel/arch/dreamcast/include/dc/matrix.h (documentation) and kos/kernel/arch/dreamcast/include/dc/matrix3d.h (documentation), as they are the headers related to any matrix-type stuff that is in KOS proper. The 2ndmix example shows how to use some of that stuff, IIRC.
- RyoDC
- Mental DCEmu
- Posts: 366
- Joined: Wed Mar 30, 2011 12:13 pm
- Has thanked: 2 times
- Been thanked: 0
Re: Tinkering with Dreamcast's Sh4's architecture
Crab, one question. As far as i concerned, PowerVR chip doesn't support hardware lightning, I mean (besides of shading modes), light sources. So, that mean, that I can use my custom lightning algorithms for different types of surfaces, isn't it?
How do I try to build a Dreamcast toolchain:
- BlueCrab
- The Crabby Overlord
- Posts: 5663
- Joined: Mon May 27, 2002 11:31 am
- Location: Sailing the Skies of Arcadia
- Has thanked: 9 times
- Been thanked: 69 times
- Contact:
Re: Tinkering with Dreamcast's Sh4's architecture
There is no hardware on the PVR to do lighting. You're responsible for calculating any lighting effects yourself and modifying what's sent to the PVR appropriately (mostly by changing the vertex colors to account for the light).
- RyoDC
- Mental DCEmu
- Posts: 366
- Joined: Wed Mar 30, 2011 12:13 pm
- Has thanked: 2 times
- Been thanked: 0
Re: Tinkering with Dreamcast's Sh4's architecture
Crab, how do I use the bump mapping?
How do I try to build a Dreamcast toolchain:
- BlueCrab
- The Crabby Overlord
- Posts: 5663
- Joined: Mon May 27, 2002 11:31 am
- Location: Sailing the Skies of Arcadia
- Has thanked: 9 times
- Been thanked: 69 times
- Contact:
Re: Tinkering with Dreamcast's Sh4's architecture
Search is your friend. Here's a post with links to an example of how to do it: viewtopic.php?p=816595#p816595
Re: Tinkering with Dreamcast's Sh4's architecture
Sorry for reviving such an old thread, I just really didn't want to make another considering it's a question related to the adventure started in this thread
I know the KOS has this stuff implemented already, I think it's in "kernel/arch/dreamcast/include/dc/math.h"?
Either way, for learning purposes I've been trying to utilize the SH4's vector functionality.
I took a look a the KOS's fmath.h header, which seems to inline assembly optimizations for shitton of stuff. For example, faster square roots, vector products, matrix multiplication etc.
Anywhoo, enough blabbering lol.
The KOS has this macro here:
Which clearly calculates the inner product of a 4D vector. But I'm very confused as to exactly how this works.
The constraints passed to GCC just say throw it into a floating point register, but they would need to be in a ordered fashion for the results to be accurate. Which leads me to believe that the values are being placed into the FR registers when they're declared like this:
But looking into the "register" keyword, GCC can never promise they will actually be stored in a register.
Sorry if I've been too vague, I'm just quite confused. This is more of a question about GCC, but this seems quite different to any x86 inlined assembly I've seen.
EDIT: Just correct a few things...
Thanks!
I know the KOS has this stuff implemented already, I think it's in "kernel/arch/dreamcast/include/dc/math.h"?
Either way, for learning purposes I've been trying to utilize the SH4's vector functionality.
I took a look a the KOS's fmath.h header, which seems to inline assembly optimizations for shitton of stuff. For example, faster square roots, vector products, matrix multiplication etc.
Anywhoo, enough blabbering lol.
The KOS has this macro here:
Code: Select all
#define __fipr(x, y, z, w, a, b, c, d) ({ \
register float __x __asm__("fr0") = (x); \
register float __y __asm__("fr1") = (y); \
register float __z __asm__("fr2") = (z); \
register float __w __asm__("fr3") = (w); \
register float __a __asm__("fr4") = (a); \
register float __b __asm__("fr5") = (b); \
register float __c __asm__("fr6") = (c); \
register float __d __asm__("fr7") = (d); \
__asm__ __volatile__( \
"fipr fv4,fv0" \
: "+f" (__w) \
: "f" (__x), "f" (__y), "f" (__z), "f" (__w), \
"f" (__a), "f" (__b), "f" (__c), "f" (__d) \
); \
__w; })
The constraints passed to GCC just say throw it into a floating point register, but they would need to be in a ordered fashion for the results to be accurate. Which leads me to believe that the values are being placed into the FR registers when they're declared like this:
Code: Select all
register float __x __asm__("fr0") = (x); \
Sorry if I've been too vague, I'm just quite confused. This is more of a question about GCC, but this seems quite different to any x86 inlined assembly I've seen.
EDIT: Just correct a few things...
Thanks!
-
- DC Developer
- Posts: 142
- Joined: Thu Apr 03, 2008 7:01 am
- Has thanked: 0
- Been thanked: 4 times
- Contact:
Re: Tinkering with Dreamcast's Sh4's architecture
The "register" keyword tells GCC that the associated variable should always be kept in a register and not on memory.
The following code simply associate the __x float variable with the fr0 register.
Now each time you do __x = 4 on your C/C++ code, the value 4 will be stored on the fr0 register, and not on memory or on any other register.
The following code simply associate the __x float variable with the fr0 register.
Code: Select all
register float __x __asm__("fr0")
-
- DCEmu User with No Life
- Posts: 3641
- Joined: Sat Feb 16, 2002 1:55 pm
- Has thanked: 0
- Been thanked: 0
Re: Tinkering with Dreamcast's Sh4's architecture
I think the way it works is that GCC guarantees the mapping when those variables are referenced by name as operands in an asm block. However, the mapping is not necessarily maintained beyond that (e.g. the variables might "really" live in memory and are just copied in/out of the specified registers by code generated around the asm block). AFAIK, the "register" keyword is not actually guaranteed to do anything in ANSI C generally, but sadly my copy of K&R is in my cube at the moment.
edit: it might be guaranteed to generate an error if the & operator is used on a register variable, but I don't know whether that's required or the compiler can implicitly convert it to a memory variable.
edit: it might be guaranteed to generate an error if the & operator is used on a register variable, but I don't know whether that's required or the compiler can implicitly convert it to a memory variable.
Last edited by Ex-Cyber on Sat Jan 21, 2012 3:20 pm, edited 1 time in total.
"You know, I have a great, wonderful, really original method of teaching antitrust law, and it kept 80 percent of the students awake. They learned things. It was fabulous." -- Justice Stephen Breyer
Re: Tinkering with Dreamcast's Sh4's architecture
Ah, seems to make sense.
So really, even though it's not in that register, any inlined code can treat it as if it really is?
But then, why does the inline constraints have to directly specify the input operands?
So really, even though it's not in that register, any inlined code can treat it as if it really is?
But then, why does the inline constraints have to directly specify the input operands?