Update your Genesis/32X Toolchain!
Posted: Sat Feb 26, 2011 7:01 am
EDIT: This is now superseded by my latest toochain, found here: viewtopic.php?f=7&t=3024
I'm leaving this in case someone needed to build an older toolchain for some reason.
Building a Genesis/SCD/32X toolchain
1 - Go here and download gcc-4.8.3.tar.bz2.
Decompress the archive; you should end up with one folder called gcc-4.8.3.
2.1 - Go here and download mpfr-3.1.2.tar.bz2.
2.2 - Go here and download mpc-1.0.2.tar.gz.
2.3 - Go here and download gmp-6.0.0a.tar.lz.
Decompress them all in the same folder. You should have three folders called mpfr-3.1.2, mpc-1.0.2, and gmp-6.0.0. Rename them to get rid of the version numbers, leaving you with mpfr, mpc, and gmp. Copy them into the gcc-4.8.3 folder.
3 - Go here and download binutils-2.24.tar.bz2.
Decompress it in the same folder as the gcc folder so that you have two folders - gcc-4.8.3 and binutils-2.24.
4 - Go here and download newlib-2.1.0.tar.gz.
Decompress it in the same folder as gcc and binutils, leaving you with three folders - gcc-4.8.3, binutils-2.24, and newlib-2.1.0.
5 - Download this archive containing a makefile, several linker scripts, and a set of SCD boot blocks.
Decompress it to the same folder as the others above.
6 - If you wish to leave the makefile with the default path of /opt/toolchains/sega, make sure you have permission to write to /opt or the toolchain will fail to install to the path. Since there's nothing critical in /opt, it's easiest just to do "sudo chmod 777 -R /opt" which allows anyone to do anything they want in /opt.
7 - Run "make -f makefile-sega" - depending on the speed of your computer, you should now have two toolchains in /opt/toolchains/sega: m68k-elf and sh-elf. Copy the ldscripts and bootblocks folders into /opt/toolchains/sega - the full folders, not just the contents of the folders.
You now have the latest gcc, binutils, and newlib for both the 68000 and the SH2. The 68000 and SH2 have compilers for C, C++, Objective-C, and Objective-C++.
8 - Make a bin folder in /opt/toolchains/sega. Copy whatever misc tools you use into it, like sixpack or bin2c.
9 - You'll need the proper export to use the toolchains, and assuming you left the path to /opt, this would be:
export GENDEV=/opt/toolchains/sega
Note: My examples assume the path to be as above. You therefore only need to set GENDEV if you used some other path.
Here is an archive with example code - it includes Tic-Tac-Toe in both C and C++ for both the MD and the 32X, as well as my 32X version of Yeti3D with Module playing and sound effects. The linker scripts in the archive are older than the ones in step 5, so don't replace them!
MD_32X_Examples.7z
One thing to note about gcc 4.4 and better (which concerns this toolchain since it's 4.8.3) - if the C/C++ code directly accesses hardware, you MUST compile that code with -O1! If you compile at -O2 or greater, gcc reorders the code for better speed regardless of how reordering may affect the system. Casting the accesses as volatile will NOT cure the problem. I can personally vouch this behavior occurs for gcc 4.4 and 4.5 on MIPS, SH, and M68K. If you look in my 32X example, you'll see hw_32x.c is compiled at -O1 while the rest is compiled at -O3. Note, I need to do some checking on this part - it may just be necessary to add full memory barriers after any hardware access. Until I can check on that, have hardware access in its own file and compile that one file with -O1. All others are fine with -Ofast.
EDIT: Updated toolchain - latest versions on everything but gcc. I won't update gcc to 4.9 until they've had a couple updates to it.
I'm leaving this in case someone needed to build an older toolchain for some reason.
Building a Genesis/SCD/32X toolchain
1 - Go here and download gcc-4.8.3.tar.bz2.
Decompress the archive; you should end up with one folder called gcc-4.8.3.
2.1 - Go here and download mpfr-3.1.2.tar.bz2.
2.2 - Go here and download mpc-1.0.2.tar.gz.
2.3 - Go here and download gmp-6.0.0a.tar.lz.
Decompress them all in the same folder. You should have three folders called mpfr-3.1.2, mpc-1.0.2, and gmp-6.0.0. Rename them to get rid of the version numbers, leaving you with mpfr, mpc, and gmp. Copy them into the gcc-4.8.3 folder.
3 - Go here and download binutils-2.24.tar.bz2.
Decompress it in the same folder as the gcc folder so that you have two folders - gcc-4.8.3 and binutils-2.24.
4 - Go here and download newlib-2.1.0.tar.gz.
Decompress it in the same folder as gcc and binutils, leaving you with three folders - gcc-4.8.3, binutils-2.24, and newlib-2.1.0.
5 - Download this archive containing a makefile, several linker scripts, and a set of SCD boot blocks.
Decompress it to the same folder as the others above.
6 - If you wish to leave the makefile with the default path of /opt/toolchains/sega, make sure you have permission to write to /opt or the toolchain will fail to install to the path. Since there's nothing critical in /opt, it's easiest just to do "sudo chmod 777 -R /opt" which allows anyone to do anything they want in /opt.
7 - Run "make -f makefile-sega" - depending on the speed of your computer, you should now have two toolchains in /opt/toolchains/sega: m68k-elf and sh-elf. Copy the ldscripts and bootblocks folders into /opt/toolchains/sega - the full folders, not just the contents of the folders.
You now have the latest gcc, binutils, and newlib for both the 68000 and the SH2. The 68000 and SH2 have compilers for C, C++, Objective-C, and Objective-C++.
8 - Make a bin folder in /opt/toolchains/sega. Copy whatever misc tools you use into it, like sixpack or bin2c.
9 - You'll need the proper export to use the toolchains, and assuming you left the path to /opt, this would be:
export GENDEV=/opt/toolchains/sega
Note: My examples assume the path to be as above. You therefore only need to set GENDEV if you used some other path.
Here is an archive with example code - it includes Tic-Tac-Toe in both C and C++ for both the MD and the 32X, as well as my 32X version of Yeti3D with Module playing and sound effects. The linker scripts in the archive are older than the ones in step 5, so don't replace them!
MD_32X_Examples.7z
One thing to note about gcc 4.4 and better (which concerns this toolchain since it's 4.8.3) - if the C/C++ code directly accesses hardware, you MUST compile that code with -O1! If you compile at -O2 or greater, gcc reorders the code for better speed regardless of how reordering may affect the system. Casting the accesses as volatile will NOT cure the problem. I can personally vouch this behavior occurs for gcc 4.4 and 4.5 on MIPS, SH, and M68K. If you look in my 32X example, you'll see hw_32x.c is compiled at -O1 while the rest is compiled at -O3. Note, I need to do some checking on this part - it may just be necessary to add full memory barriers after any hardware access. Until I can check on that, have hardware access in its own file and compile that one file with -O1. All others are fine with -Ofast.
EDIT: Updated toolchain - latest versions on everything but gcc. I won't update gcc to 4.9 until they've had a couple updates to it.