|
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.64
">10. Porting GHCThis section describes how to port GHC to a currenly unsupported platform. There are two distinct possibilities:
10.1. Booting/porting from C (.hc) filesBootstrapping GHC on a system without GHC already installed is achieved by taking the intermediate C files (known as HC files) from a GHC compilation on a supported system to the target machine, and compiling them using gcc to get a working GHC. NOTE: GHC version 5.xx is significantly harder to bootstrap from C than previous versions. We recommend starting from version 4.08.2 if you need to bootstrap in this way. HC files are architecture-dependent (but not OS-dependent), so you have to get a set that were generated on similar hardware. There may be some supplied on the GHC download page, otherwise you'll have to compile some up yourself, or start from unregisterised HC files - see Section 10.2. The following steps should result in a working GHC build with full libraries:
10.2. Porting GHC to a new architectureThe first step in porting to a new architecture is to get an unregisterised build working. An unregisterised build is one that compiles via vanilla C only. By contrast, a registerised build uses the following architecture-specific hacks for speed:
In an unregisterised build, neither of these hacks are used — the idea is that the C code generated by the compiler should compile using gcc only. The lack of these optimisations costs about a factor of two in performance, but since unregisterised compilation is usually just a step on the way to a full registerised port, we don't mind too much. 10.2.1. Building an unregisterised portThe first step is to get some unregisterised HC files. Either (a) download them from the GHC site (if there are some available for the right version of GHC), or (b) build them yourself on any machine with a working GHC. If at all possible this should be a machine with the same word size as the target. There is a script available which should automate the process of doing the 2-stage bootstrap necessary to get the unregisterised HC files - it's available in fptools/distrib/cross-port in CVS. Now take these unregisterised HC files to the target platform and bootstrap a compiler from them as per the instructions in Section 10.1. In build.mk, you need to tell the build system that the compiler you're building is (a) unregisterised itself, and (b) builds unregisterised binaries. This varies depending on the GHC version you're bootstraping:
Version 5.xx only: use the option --enable-hc-boot-unregisterised instead of --enable-hc-boot when running ./configure. The build may not go through cleanly. We've tried to stick to writing portable code in most parts of the compiler, so it should compile on any POSIXish system with gcc, but in our experience most systems differ from the standards in one way or another. Deal with any problems as they arise - if you get stuck, ask the experts on <glasgow-haskell-users@haskell.org>. Once you have the unregisterised compiler up and running, you can use it to start a registerised port. The following sections describe the various parts of the system that will need architecture-specific tweaks in order to get a registerised build going. Lots of useful information about the innards of GHC is available in the GHC Commentary, which might be helpful if you run into some code which needs tweaking for your system. 10.2.2. Porting the RTSThe following files need architecture-specific code for a registerised build:
10.2.3. The manglerThe mangler is an evil Perl-script that rearranges the assembly code output from gcc to do two main things:
The mangler is abstracted to a certain extent over some architecture-specific things such as the particular assembler directives used to herald symbols. Take a look at the definitions for other architectures and use these as a starting point. 10.2.4. The native code generatorThe native code generator isn't essential to getting a registerised build going, but it's a desirable thing to have because it can cut compilation times in half. The native code generator is described in some detail in the GHC commentary. 10.2.5. GHCiTo support GHCi, you need to port the dynamic linker (fptools/ghc/rts/Linker.c). The linker currently supports the ELF and PEi386 object file formats - if your platform uses one of these then you probably don't have to do anything except fiddle with the #ifdefs at the top of Linker.c to tell it about your OS. If your system uses a different object file format, then you have to write a linker — good luck! |