Sign in Join
Wiki copytemporary

Porting Free Pascal Example: what changed

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

Title: Porting Free Pascal Example

OldNewLine
1+This is an example of how to port Free Pascal to a new target. The target used here is i386-minix, which is a Unix based microkernel system. Host system is a i386-linux system. For more information about the port see [[Target Minix|here]].
2+
3+**this example is a work in progress**
4+
5+## Prerequisites
6+
7+You'll need the source code of Free Pascal (preferably the most recent version in svn), a SVN client, a working last release of Free Pascal (currently 2.4.0) and a working version of GCC.
8+
9+It's best to create a new directory where you'll work in.
10+
11+`mkdir $HOME/minix-port`\
12+`cd $HOME/minix-port`
13+
14+Then either copy an existing Free Pascal working copy on your machine or load a fresh one from the repository. I'll use the second possibility here (for additional help see [[Getting Lazarus|here]]):
15+
16+`svn checkout `[`http://svn.freepascal.org/svn/fpc/trunk`](http://svn.freepascal.org/svn/fpc/trunk)` fpc`
17+
18+### Binutils
19+
20+The first compiler for a new target is always a cross compiler, so we need utilities that allow us to create executables for our target on our host system.
21+
22+Minix supports the GNU binutils. As the current binutils (2.20) are not "up to date" regarding the output format of Minix we will use the port provided by the Minix distribution.
23+
24+`svn --username anonymous checkout `[`https://gforge.cs.vu.nl/svn/minix/trunk/bigports/binutils-2.16.1`](https://gforge.cs.vu.nl/svn/minix/trunk/bigports/binutils-2.16.1)` minix-binutils`
25+
26+We also need the source of Minix, cause we need two include files to build the binutils successfully.
27+
28+`svn --username anonymous checkout `[`https://gforge.cs.vu.nl/svn/minix/trunk/src`](https://gforge.cs.vu.nl/svn/minix/trunk/src)` minix`
29+
30+Now copy the needed include files to a directory that is included by the makefiles:
31+
32+`cp minix/include/minix/a.out.h minix-binutils/include/minix-a.out.h`\
33+`cp minix/include/ansi.h minix-binutils/include/ansi.h`
34+
35+You also need to change the include line in *minix-binutils/bfd/i386minix.c* from
36+
37+`#include <a.out.h>`
38+
39+to
40+
41+`#include <minix-a.out.h>`
42+
43+Now we can build the binutils:
44+
45+`cd minix-binutils`\
46+`./configure --host=i686-minix --prefix=../minix-binutils-bin/`\
47+`make`\
48+`make install`\
49+`cd ..`
50+
51+## Compiler
52+
53+### Modifications
54+
55+The following diff shows the changes that were done in already existing files in *compiler* and *utils* directories:
56+
57+ Index: compiler/i386/cputarg.pas
58+ ===================================================================
59+ --- compiler/i386/cputarg.pas (Revision 15151)
60+ +++ compiler/i386/cputarg.pas (Arbeitskopie)
61+ @@ -80,6 +80,9 @@
62+ {$ifndef NOTARGETNATIVENT}
63+ ,t_nativent
64+ {$endif}
65+ + {$ifndef NOTARGETMINIX}
66+ + ,t_minix
67+ + {$endif}
68+
69+ {**************************************
70+ Assemblers
71+ Index: compiler/systems.pas
72+ ===================================================================
73+ --- compiler/systems.pas (Revision 15151)
74+ +++ compiler/systems.pas (Arbeitskopie)
75+ @@ -151,6 +151,7 @@
76+ system_mips_linux, { 66 }
77+ system_mipsel_linux, { 67 }
78+ system_i386_nativent, { 68 }
79+ + system_i386_minix { 69 }
80+ );
81+
82+ type
83+ Index: compiler/compiler.pas
84+ ===================================================================
85+ --- compiler/compiler.pas (Revision 15151)
86+ +++ compiler/compiler.pas (Arbeitskopie)
87+ @@ -113,6 +113,9 @@
88+ {$ifdef nativent}
89+ ,i_nativent
90+ {$endif nativent}
91+ +{$ifdef minix}
92+ + ,i_minix
93+ +{$endif minix}
94+ ,globtype;
95+
96+ function Compile(const cmd:string):longint;
97+ Index: utils/fpcm/fpcmake.ini
98+ ===================================================================
99+ --- utils/fpcm/fpcmake.ini (Revision 15151)
100+ +++ utils/fpcm/fpcmake.ini (Arbeitskopie)
101+ @@ -972,6 +972,14 @@
102+ SHORTSUFFIX=nativent
103+ endif
104+
105+ +# Minix
106+ +ifeq ($(OS_TARGET),minix)
107+ +BATCHEXT=.sh
108+ +EXEEXT=
109+ +HASSHAREDLIB=0
110+ +SHORTSUFFIX=minix
111+ +endif
112+ +
113+ else
114+ # long version for 1.0.x - target specific extensions
115+
116+ Index: utils/fpcm/fpcmmain.pp
117+ ===================================================================
118+ --- utils/fpcm/fpcmmain.pp (Revision 15151)
119+ +++ utils/fpcm/fpcmmain.pp (Arbeitskopie)
120+ @@ -70,7 +70,8 @@
121+ o_linux,o_go32v2,o_win32,o_os2,o_freebsd,o_beos,o_haiku,o_netbsd,
122+ o_amiga,o_atari, o_solaris, o_qnx, o_netware, o_openbsd,o_wdosx,
123+ o_palmos,o_macos,o_darwin,o_emx,o_watcom,o_morphos,o_netwlibc,
124+ - o_win64,o_wince,o_gba,o_nds,o_embedded,o_symbian,o_nativent
125+ + o_win64,o_wince,o_gba,o_nds,o_embedded,o_symbian,o_nativent,
126+ + o_minix
127+ );
128+
129+ TTargetSet=array[tcpu,tos] of boolean;
130+ @@ -92,14 +93,16 @@
131+ 'linux','go32v2','win32','os2','freebsd','beos','haiku','netbsd',
132+ 'amiga','atari','solaris', 'qnx', 'netware','openbsd','wdosx',
133+ 'palmos','macos','darwin','emx','watcom','morphos','netwlibc',
134+ - 'win64','wince','gba','nds','embedded','symbian','nativent'
135+ + 'win64','wince','gba','nds','embedded','symbian','nativent',
136+ + 'minix'
137+ );
138+
139+ OSSuffix : array[TOS] of string=(
140+ '_linux','_go32v2','_win32','_os2','_freebsd','_beos','_haiku','_netbsd',
141+ '_amiga','_atari','_solaris', '_qnx', '_netware','_openbsd','_wdosx',
142+ '_palmos','_macos','_darwin','_emx','_watcom','_morphos','_netwlibc',
143+ - '_win64','_wince','_gba','_nds','_embedded','_symbian','_nativent'
144+ + '_win64','_wince','_gba','_nds','_embedded','_symbian','_nativent',
145+ + '_minix'
146+ );
147+
148+ { This table is kept OS,Cpu because it is easier to maintain (PFV) }
149+ @@ -133,7 +136,8 @@
150+ { nds } ( false, false, false, false, false, true, false, false, false, false, false, false, false, false),
151+ { embedded }( true, true, true, true, true, true, true, true, true , false, false, false, false, false),
152+ { symbian } ( true, false, false, false, false, true, false, false, false, false, false, false, false, false),
153+ - { nativent }( true, false, false, false, false, false, false, false, false, false, false, false, false, false)
154+ + { nativent }( true, false, false, false, false, false, false, false, false, false, false, false, false, false),
155+ + { minix } ( true, false, false, false, false, false, false, false, false, false, false, false, false, false)
156+ );
157+
158+ type
159+
160+You also need to add the files i_minix.pas and t_minix.pas in compiler/systems directory.
161+
162+TODO
163+
164+### Compiling
165+
166+## Adding the new RTL
167+
168+TODO
169+
170+## See also
171+
172+- [[Porting Free Pascal]]
173+
174+---
175+*From the Free Pascal wiki, page "Porting Free Pascal Example", as it stood on 2011-02-01 after a change by Chronos, 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).*
176+Category: Tutorials

Back to history