KMC: Difference between revisions

From Decompedia
Jump to navigation Jump to search
m (Properly list the compiler link)
(Added details about the toolchain and the KMC wrapper)
Line 1: Line 1:
On the N64 decompilation world we refer to "KMC" as an specific compiler distributed by the Japanese company Kyoto Microcomputer, Co. Ltd. (hence the name). This compiler is a fork of GNU's GCC with a number of patches applied to adapt it better for the Nintendo 64 console.
On the N64 decompilation world we refer to "KMC" as an specific compiler distributed by the Japanese company Kyoto Microcomputer, Co. Ltd. (hence the name). This toolchain is a mostly unchanged fork of GNU GCC 2.7.2 paired with a fork of GNU Binutils 2.6. The Binutils fork has some patches to work around hardware issues with the CPU used in the Nintendo 64 console as well as a patch to automatically align variables above a specific size to meet DMA alignment requirements for the N64's Reality Coprocessor. There are a few releases of the KMC toolchain, but they all seem to generate identical code.


To get this this compiler, the [[decompals]] [https://github.com/decompals Github organization] host two repositories that build this specific version of this compiler for modern machines. Those are built based on the original GCC commit from the GNU repositories, plus the patched made by the original team who modified this compiler and a few quality of life changes made by the decompals team.
== Running the KMC Toolchain ==
The original KMC toolchain binaries are available, but were built as programs that were run with a [[wikipedia:DOS_extender|DOS Extender]] under Windows XP. This meant they were compiled as 32-bit applications but used the DOS system calls to interface with the operating system. Trying to run them under more Windows versions either not work or lead to issues such as restricted maximum path lengths or memory allocation problems.
 
=== KMC Wrapper ===
The first mechanism to allow the KMC toolchain to run without issues was the [https://github.com/Mr-Wiseguy/kmc-gcc-wrapper/ KMC GCC wrapper] made by community member Wiseguy. It loaded the original binaries into memory and patched them to replace DOS system calls with reimplementations using the C standard library. After patching, it would run them natively as 32-bit code. It also patched or replaced various functions to work around issues such as short maximum path lengths.
 
=== KMC Native Build ===
While the KMC wrapper allowed running the toolchain, it had issues with portability. As a replacement, Wiseguy reverse engineered the changes made to GCC and Binutils made by the original Kyoto Microcomputer team and replicated them in the source code of GCC 2.7.2/Binutils 2.6. This meant the KMC toolchain could now be built as a native executable for modern systems from source code, allowing it to run as a 64-bit executable and on other platforms such as Mac OS. Since then, several quality of life changes have been added to the toolchain. The two components of the toolchain are hosted in the [[decompals]] [https://github.com/decompals Github organization]:


* GCC repository: https://github.com/decompals/mips-gcc-2.7.2
* GCC repository: https://github.com/decompals/mips-gcc-2.7.2

Revision as of 18:23, 23 September 2023

On the N64 decompilation world we refer to "KMC" as an specific compiler distributed by the Japanese company Kyoto Microcomputer, Co. Ltd. (hence the name). This toolchain is a mostly unchanged fork of GNU GCC 2.7.2 paired with a fork of GNU Binutils 2.6. The Binutils fork has some patches to work around hardware issues with the CPU used in the Nintendo 64 console as well as a patch to automatically align variables above a specific size to meet DMA alignment requirements for the N64's Reality Coprocessor. There are a few releases of the KMC toolchain, but they all seem to generate identical code.

Running the KMC Toolchain

The original KMC toolchain binaries are available, but were built as programs that were run with a DOS Extender under Windows XP. This meant they were compiled as 32-bit applications but used the DOS system calls to interface with the operating system. Trying to run them under more Windows versions either not work or lead to issues such as restricted maximum path lengths or memory allocation problems.

KMC Wrapper

The first mechanism to allow the KMC toolchain to run without issues was the KMC GCC wrapper made by community member Wiseguy. It loaded the original binaries into memory and patched them to replace DOS system calls with reimplementations using the C standard library. After patching, it would run them natively as 32-bit code. It also patched or replaced various functions to work around issues such as short maximum path lengths.

KMC Native Build

While the KMC wrapper allowed running the toolchain, it had issues with portability. As a replacement, Wiseguy reverse engineered the changes made to GCC and Binutils made by the original Kyoto Microcomputer team and replicated them in the source code of GCC 2.7.2/Binutils 2.6. This meant the KMC toolchain could now be built as a native executable for modern systems from source code, allowing it to run as a 64-bit executable and on other platforms such as Mac OS. Since then, several quality of life changes have been added to the toolchain. The two components of the toolchain are hosted in the decompals Github organization:

Projects using this compiler

The following is the list of known projects that use this compiler: