Sign in Join
Wiki copytemporary

Native MIPS Systems: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: Native MIPS Systems

OldNewLine
1+The MIPS architecture is unusual in that it was designed for desktop computers, is now overwhelmingly used for embedded systems, but can still occasionally be found in desktops or small servers. The only comparable architecture is [[Native ARM Systems|ARM]], which is the platform of choice for a multitude of mobile phones, tablets etc.
2+
3+Like almost all computers, MIPS-based systems will contain an internal loader, usually in flash memory. However there are three basic categories of system:
4+
5+- Those that boot an operating system from internal flash, such as the Linksys/Cisco WRT54G [1](http://wiki.openwrt.org/).
6+
7+- Those that boot an operating system from a conventional disc, connected via IDE, SCSI or USB, such as an SGI server or workstation, or a Cobalt/Sun Qube or Raq.
8+
9+- Those running as guests using an emulator such as [[Qemu and other emulators|Qemu]] on a general-purpose computer.
10+
11+In any of these cases it is necessary to be able to install a general-purpose operating system such as Linux in order to be able to run development tools. This writer (MarkMLl) favours Debian, since he finds that using it results in a very similar system on a wide range of hardware (x86, SPARC, PPC, MIPS, ARM, zSeries, 68K).
12+
13+**If you intend to build Lazarus, make sure you have at least 512Mb memory (RAM + swap) available.**
14+
15+## Microchip microcontrollers
16+
17+In 2013, Microchip enhanced their series of "PIC24" and "PIC33" chips with the "PIC32" variants, providing compatible (to a certain extent even pin-compatible) alternatives to the 16 bit chips (PIC32MX..."), as well as much more powerful ones ("PIC32MZ..."). The PIC32 chips are both cheaper and more versatile than the corresponding PIC24s. Hence they include both cheap and powerful controllers. The PIC32 chips feature a "M4K" MIPS CPU and so they could run software done with the FPC MIPS cross compiler. As usually these chips are used for doing "deeply embedded" systems: in most cases there will be no formal OS and the user code programmer will need to adapt the RTL to fit his needs. But as the C-based "MPLAB-X" IDE by Microchip comes with a huge library that provides basic functions (such as heap management), the "standard" RTL for such purpose should take this into account.
18+
19+## FPC Implementations for MIPS
20+
21+As of 2011 there are two implementations of FPC for the MIPS architecture, both targeting Linux.
22+
23+- A fork of the mainline compiler at 2.0.0 by David Zhang. *Now deprecated due to mainline integration.*
24+
25+- An ongoing effort to reconcile this with the mainline project, in SVN trunk and partially completed in 2.7.x.
26+
27+### David Zhang's Compiler
28+
29+The "unofficial" MIPS compiler at [2](http://sourceforge.net/projects/fpc-mips/develop) was written by David Zhang (possibly [3](http://www4.comp.polyu.edu.hk/~csdzhang/)) and is licensed under GPL Version 2, it cites but does not include the COPYING.FPC file. The compiler appears to have been originally based on the SPARC port, and there are significant differences between it and the mainline sources. It is discussed for historical interest, and as reference until the mainline compiler is at least as complete and robust.
30+
31+There are .zip files of both sources and a minimal executable at Sourceforge (link above). The sources are basically a complete reimplementation of fpcsrc/compiler/mips based on FPC 2.0.0, the compiler targets mipsel and is described as being operational on Qemu but not yet supporting shared libraries.
32+
33+Since this is specifically a little-endian compiler it should presumably be compatible with Linux on a MIPS-based Qube or Raq, or with the Chinese "Loongson" processor. It will not be compatible with SGI MIPS systems, which are big-endian.
34+
35+There is a system library bundled with the compiler, but no indication of how far the compiler is capable of handling the remainder of the standard libraries. The released files may be downloaded from:
36+
37+- <http://sourceforge.net/projects/fpc-mips/files/fpc-mips/0.90/fpc_mips_bin_090.zip/download>
38+
39+This comprises the binary compiler pp_mipsel32. It successfully compiles a minimal test program which appears to run.
40+
41+- <http://sourceforge.net/projects/fpc-mips/files/fpc-mips/0.90/fpc_mips_all_090a.zip/download>
42+
43+This is both source and binary, dumped into a single directory which appears to correspond to the standard fpc_200/compiler, i.e. there's no separate compiler/mips directory; it also partially reimplements some standard libraries etc.
44+
45+### Mainline MIPS Port
46+
47+This is part of the trunk development files, but does not yet appear in standard releases; i.e. it's only available via an svn download.
48+
49+The host is assumed to be a non-MIPS system, for example x86 running Linux (e.g. Debian "Squeeze"). It needs a copy of binutils, and it is probably expedient to make this the same version as is running natively, i.e. 2.20.1 in the above case, downloaded from [4](http://ftp.gnu.org/gnu/binutils/binutils-2.20.1.tar.bz2). In any event, no version older than 2.18 will work since symbolic register names are a prerequisite.
50+
51+Build and install cross-binutils:
52+
53+``` bash
54+tar xjf binutils-2.20.1.tar.bz2
55+cd binutils-2.20.1
56+./config.sub mipsel-linux-gnu
57+./configure --prefix=/usr/local/mipsel-linux mipsel-linux-gnu
58+make
59+sudo make install
60+sudo ln -s /usr/local/mipsel-linux/bin/as /usr/local/bin/mipsel-linux-as
61+sudo ln -s /usr/local/mipsel-linux/bin/ld /usr/local/bin/mipsel-linux-ld
62+sudo ln -s /usr/local/mipsel-linux/bin/ar /usr/local/bin/mipsel-linux-ar
63+sudo ln -s /usr/local/mipsel-linux/bin/objdump /usr/local/bin/mipsel-linux-objdump
64+sudo ln -s /usr/local/mipsel-linux/bin/objcopy /usr/local/bin/mipsel-linux-objcopy
65+sudo ln -s /usr/local/mipsel-linux/bin/strip /usr/local/bin/mipsel-linux-strip
66+mipsel-linux-ld -V
67+```
68+
69+Particularly if working with the trunk sources, consider doing the same for a different CPU (e.g. powerpc-linux-gnu) so as not to be caught out if they won't build due to a temporary inconsistency.
70+
71+Build a compiler which runs on the host but targets mipsel, note debug options which are needed later:
72+
73+``` bash
74+cd /usr/local/src/fpc-trunk
75+export PP=
76+make "OPT=-O- -g" -C compiler mipsel
77+mv compiler/ppcmipsel compiler/ppcXmipsel
78+```
79+
80+Renaming the compiler prevents it from being deleted by make clean etc., consider extending that OPT setting with -dEXTDEBUG.
81+
82+``` bash
83+export PP=/usr/local/src/fpc-trunk/fpc/compiler/ppcXmipsel
84+make CPU_TARGET=mipsel OS_TARGET=linux rtl
85+make CPU_TARGET=mipsel OS_TARGET=linux compiler
86+```
87+
88+Move the newly-generated compiler and the RTL units to the target system, which should now be able to do a full build.
89+
90+#### Stall point
91+
92+As of October 2012 there are still some code-generation tests failing.
93+
94+To be continued (hopefully :-)
95+
96+As a general point, there's some useful thoughts on binary disassembly at [5](http://chdk.wikia.com/wiki/GPL_Disassembling) for situations where IDA or equivalent aren't available.
97+
98+### Big-endian subarchitecture
99+
100+*Working notes, no permanent links.*
101+
102+This is a highly-experimental investigation of how much work it would take to port the existing little-endian compiler (mipsel) to big-endian architectures. Note that the GNU triplet is mips-linux-gnu, there is no such thing as mipseb-linux-gnu etc.
103+
104+Build and install cross-binutils:
105+
106+``` bash
107+tar xjf binutils-2.20.1.tar.bz2
108+cd binutils-2.20.1
109+./config.sub mips-linux-gnu
110+./configure --prefix=/usr/local/mips-linux mips-linux-gnu
111+make
112+sudo make install
113+sudo ln -s /usr/local/mips-linux/bin/as /usr/local/bin/mips-linux-as
114+sudo ln -s /usr/local/mips-linux/bin/ld /usr/local/bin/mips-linux-ld
115+sudo ln -s /usr/local/mips-linux/bin/ar /usr/local/bin/mips-linux-ar
116+sudo ln -s /usr/local/mips-linux/bin/objdump /usr/local/bin/mips-linux-objdump
117+sudo ln -s /usr/local/mips-linux/bin/objcopy /usr/local/bin/mips-linux-objcopy
118+sudo ln -s /usr/local/mips-linux/bin/strip /usr/local/bin/mips-linux-strip
119+mips-linux-ld -V
120+```
121+
122+Build a compiler which runs on the host but targets mipseb, note debug options which are needed later:
123+
124+``` bash
125+cd /usr/local/src/fpc-trunk
126+export PP=
127+make "OPT=-O- -g" -C compiler mips
128+mv compiler/ppcmips compiler/ppcXmips
129+```
130+
131+For my own reference, actually using /usr/local/src/fpc/zhang/fpc-trunk/fpc
132+
133+``` bash
134+export PP=/usr/local/src/fpc-trunk/fpc/compiler/ppcXmips
135+make CPU_TARGET=mips OS_TARGET=linux rtl
136+# make CPU_TARGET=mips OS_TARGET=linux compiler
137+```
138+
139+Build a compiler which runs on the target:
140+
141+``` bash
142+export PP=/usr/local/src/fpc-trunk/fpc/compiler/ppcXmips
143+make "OPT=-O- -g" -C compiler mips
144+```
145+
146+``` bash
147+
148+$PP -i |head
149+Free Pascal Compiler version 2.7.1
150+
151+Compiler Date : 2012/11/02
152+Compiler CPU Target: mipseb
153+
154+Supported targets:
155+ Linux for MIPSEB
156+
157+file compiler/ppcmips
158+compiler/ppcmips: ELF 32-bit MSB executable, MIPS, MIPS-II version 1 (SYSV), statically linked, stripped
159+
160+file rtl/units/mips-linux/system.o
161+rtl/units/mips-linux/system.o: ELF 32-bit MSB relocatable, MIPS, MIPS-II version 1 (SYSV), not stripped
162+```
163+
164+## See also
165+
166+- [[TARGET Embedded Mipsel]]
167+
168+---
169+*From the Free Pascal wiki, page "Native MIPS Systems", as it stood on 2020-01-26 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
170+Category: FPC
171+Category: MIPS
172+Category: Microcontrollers
173+Category: Operating Systems and Platforms
174+Category: PIC32

Back to history