Sign in Join
Wiki copytemporary

Porting Free Pascal: what changed

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

OldNewLine
1-This page is the start of a tutorial about how to port Free Pascal to different architectures and operating systems.
1+This page is the start of a tutorial about how to port Free Pascal to different architectures and operating systems.
22
33## Porting to a new Operating System
44
55### Overview
66
7-Porting Free Pascal to a new operating system involves several steps, namely:
7+Porting Free Pascal to a new operating system involves several steps, namely:
88
9-1. Add a new target to the compiler
10-2. Take the closest existing RTL as a start, copy it and start implementing
9+ 1. Add a new target to the compiler
10+ 2. Take the closest existing RTL as a start, copy it and start implementing
1111
1212### Adding a new target
1313
14-This task requires making small changes on several files on the compiler. You need to add your target to both the Makefiles, to the fpmake tool that creates the makefiles and the compiler itself.
15-
16-With your updated fpmake you can then recreate the makefile tree.
14+This task requires making small changes on several files on the compiler. You need to add your target to both the Makefiles, to the fpmake tool that creates the makefiles and the compiler itself.
1715
18-Below is a example of how a new target is added. This Patch was responsible for adding SymbianOS target to the compiler. Be careful that this adds a i386-symbian target. If your target is for another architecture of course you should change the files on the directories for your particular architecture.
16+With your updated fpmake you can then recreate the makefile tree.
1917
20- Index: compiler/compiler.pas
18+Below is a example of how a new target is added. This Patch was responsible for adding SymbianOS target to the compiler. Be careful that this adds a i386-symbian target. If your target is for another architecture of course you should change the files on the directories for your particular architecture.
19+```
20+Index: compiler/compiler.pas
2121 ===================================================================
22- --- compiler/compiler.pas (revision 6039)
23- +++ compiler/compiler.pas (working copy)
22+ --- compiler/compiler.pas (revision 6039)
23+ +++ compiler/compiler.pas (working copy)
2424 @@ -107,6 +107,9 @@
2525 {$ifdef win32}
2626 ,i_win
2727 {$endif win32}
2828 +{$ifdef symbian}
2929 + ,i_symbian
3030 +{$endif symbian}
31- ;
31+  ;
3232
3333 function Compile(const cmd:string):longint;
3434 Index: compiler/i386/cputarg.pas
3535 ===================================================================
36- --- compiler/i386/cputarg.pas (revision 6039)
37- +++ compiler/i386/cputarg.pas (working copy)
36+ --- compiler/i386/cputarg.pas (revision 6039)
37+ +++ compiler/i386/cputarg.pas (working copy)
3838 @@ -71,6 +71,9 @@
3939 {$ifndef NOTARGETWATCOM}
4040 ,t_watcom
4141 {$endif}
4242 + {$ifndef NOTARGETSYMBIAN}
4343 + ,t_symbian
4444 + {$endif}
4545
4646 {**************************************
4747 Assemblers
4848 Index: compiler/systems.pas
4949 ===================================================================
50- --- compiler/systems.pas (revision 6039)
51- +++ compiler/systems.pas (working copy)
50+ --- compiler/systems.pas (revision 6039)
51+ +++ compiler/systems.pas (working copy)
5252 @@ -136,7 +136,9 @@
5353 system_x86_64_embedded, { 55 }
5454 system_mips_embedded, { 56 }
5555 system_arm_embedded, { 57 }
5656 - system_powerpc64_embedded { 58 }
5757 + system_powerpc64_embedded, { 58 }
5858 + system_i386_symbian, { 59 }
5959 + system_arm_symbian { 60 }
6060 );
6161
6262 tasm = (as_none
6363 ===================================================================
64- --- compiler/utils/ppudump.pp (revision 20515)
65- +++ compiler/utils/ppudump.pp (working copy)
64+ --- compiler/utils/ppudump.pp (revision 20515)
65+ +++ compiler/utils/ppudump.pp (working copy)
6666 @@ -147,7 +147,8 @@
6767 { 67 } 'Linux-MIPSel',
6868 { 68 } 'NativeNT-i386',
6969 - { 69 } 'iPhoneSim-i386'
7070 + { 69 } 'iPhoneSim-i386',
7171 + { 70 } 'Wii-powerpc'
7272 );
7373
7474 const
7575 Index: rtl/Makefile.fpc
7676 ===================================================================
77- --- rtl/Makefile.fpc (revision 6038)
78- +++ rtl/Makefile.fpc (working copy)
77+ --- rtl/Makefile.fpc (revision 6038)
78+ +++ rtl/Makefile.fpc (working copy)
7979 @@ -28,6 +28,7 @@
8080 dirs_solaris=solaris
8181 dirs_gba=gba
8282 dirs_nds=nds
8383 +dirs_symbian=symbian
8484
8585 [install]
8686 fpcpackage=y
8787 Index: utils/fpcm/fpcmake.ini
8888 ===================================================================
89- --- utils/fpcm/fpcmake.ini (revision 6038)
90- +++ utils/fpcm/fpcmake.ini (working copy)
89+ --- utils/fpcm/fpcmake.ini (revision 6038)
90+ +++ utils/fpcm/fpcmake.ini (working copy)
9191 @@ -908,6 +908,12 @@
9292 SHORTSUFFIX=gba
9393 endif
9494
9595 +# Symbian OS
9696 +ifeq ($(OS_TARGET),symbian)
9797 +SHAREDLIBEXT=.dll
9898 +SHORTSUFFIX=symbian
9999 +endif
100100 +
101101 else
102102 # long version for 1.0.x - target specific extensions
103103
104104 Index: utils/fpcm/fpcmmain.pp
105105 ===================================================================
106- --- utils/fpcm/fpcmmain.pp (revision 6038)
107- +++ utils/fpcm/fpcmmain.pp (working copy)
106+ --- utils/fpcm/fpcmmain.pp (revision 6038)
107+ +++ utils/fpcm/fpcmmain.pp (working copy)
108108 @@ -70,7 +70,7 @@
109109 o_linux,o_go32v2,o_win32,o_os2,o_freebsd,o_beos,o_netbsd,
110110 o_amiga,o_atari, o_solaris, o_qnx, o_netware, o_openbsd,o_wdosx,
111111 o_palmos,o_macos,o_darwin,o_emx,o_watcom,o_morphos,o_netwlibc,
112112 - o_win64,o_wince,o_gba,o_nds,o_embedded
113113 + o_win64,o_wince,o_gba,o_nds,o_embedded,o_symbian
114114 );
115115
116116 TTargetSet=array[tcpu,tos] of boolean;
117117 @@ -88,14 +88,14 @@
118118 'linux','go32v2','win32','os2','freebsd','beos','netbsd',
119119 'amiga','atari','solaris', 'qnx', 'netware','openbsd','wdosx',
120120 'palmos','macos','darwin','emx','watcom','morphos','netwlibc',
121121 - 'win64','wince','gba','nds','embedded'
122122 + 'win64','wince','gba','nds','embedded','symbian'
123123 );
124124
125- OSSuffix : array[TOS] of string=(
125+ OSSuffix : array[TOS] of string=(
126126 '_linux','_go32v2','_win32','_os2','_freebsd','_beos','_netbsd',
127127 '_amiga','_atari','_solaris', '_qnx', '_netware','_openbsd','_wdosx',
128128 '_palmos','_macos','_darwin','_emx','_watcom','_morphos','_netwlibc',
129129 - '_win64','_wince','_gba','_nds','_embedded'
130130 + '_win64','_wince','_gba','_nds','_embedded','_symbian'
131131 );
132132
133133 { This table is kept OS,Cpu because it is easier to maintain (PFV) }
134134 @@ -126,7 +126,8 @@
135135 { wince }( true, false, false, false, false, true, false),
136136 { gba } ( false, false, false, false, false, true, false),
137137 { nds } ( false, false, false, false, false, true, false),
138138 - { embedded }( true, true, true, true, true, true, true)
139139 + { embedded }( true, true, true, true, true, true, true),
140140 + { symbian } ( true, false, false, false, false, true, false)
141141 );
142142
143143 type
144-
145-You will also need to add a i_target.pas and t_target.pas files to the compiler directory. Just copy an existing file for a similar platform and start working from there.
144+```
146145
147-If you want your target to use an internal linker (ELF, COFF, etc.) you need to add your target to that one, too. For the target i386-nativent the following change was done in the COFF output generator:
146+You will also need to add a i_target.pas and t_target.pas files to the compiler directory. Just copy an existing file for a similar platform and start working from there.
148147
149- Index: compiler/ogcoff.pas
148+If you want your target to use an internal linker (ELF, COFF, etc.) you need to add your target to that one, too. For the target i386-nativent the following change was done in the COFF output generator:
149+```
150+Index: compiler/ogcoff.pas
150151 ===================================================================
151- --- compiler/ogcoff.pas (Revision 14564)
152- +++ compiler/ogcoff.pas (Revision 14565)
152+ --- compiler/ogcoff.pas (Revision 14564)
153+ +++ compiler/ogcoff.pas (Revision 14565)
153154 @@ -2906,7 +2918,7 @@
154- idtxt : 'PECOFF';
155- asmbin : '';
156- asmcmd : '';
157- - supported_targets : [system_i386_win32];
158- + supported_targets : [system_i386_win32,system_i386_nativent];
159- flags : [af_outputbinary,af_smartlink_sections];
160- labelprefix : '.L';
161- comment : '';
162-
163-You might also need to add your target to one of the assemblers for the target platform. E. g. if you're targeting an i386 system you might add your target like the following (the line breaks annotated with {cr} were added to keep the layout of the article intact):
155+ idtxt  : 'PECOFF';
156+ asmbin : '';
157+ asmcmd : '';
158+ - supported_targets : [system_i386_win32];
159+ + supported_targets : [system_i386_win32,system_i386_nativent];
160+ flags : [af_outputbinary,af_smartlink_sections];
161+ labelprefix : '.L';
162+ comment : '';
163+```
164164
165- Index: compiler/x86/agx86att.pas
165+You might also need to add your target to one of the assemblers for the target platform. E. g. if you're targeting an i386 system you might add your target like the following (the line breaks annotated with {cr} were added to keep the layout of the article intact):
166+```
167+Index: compiler/x86/agx86att.pas
166168 ===================================================================
167- --- compiler/x86/agx86att.pas (Revision 15151)
168- +++ compiler/x86/agx86att.pas (Arbeitskopie)
169+ --- compiler/x86/agx86att.pas (Revision 15151)
170+ +++ compiler/x86/agx86att.pas (Arbeitskopie)
169171 @@ -380,7 +380,8 @@
170- asmcmd : '--32 -o $OBJ $ASM';
171- supported_targets : [system_i386_GO32V2,system_i386_linux,system_i386_Win32,{cr}
172+ asmcmd : '--32 -o $OBJ $ASM';
173+ supported_targets : [system_i386_GO32V2,system_i386_linux,system_i386_Win32,{cr}
172174 system_i386_freebsd,system_i386_solaris,system_i386_beos,
173175 system_i386_netbsd,system_i386_Netware,system_i386_qnx,
174176 system_i386_wdosx,system_i386_openbsd,{cr}
175177 - system_i386_netwlibc,system_i386_wince,system_i386_embedded,{cr}
176178 system_i386_symbian,system_i386_haiku,system_x86_6432_linux];
177179 + system_i386_netwlibc,system_i386_wince,system_i386_embedded,{cr}
178180 system_i386_symbian,system_i386_haiku,system_x86_6432_linux,
179181 + system_i386_nativent];
180- flags : [af_allowdirect,af_needar,af_smartlink_sections,af_supports_dwarf];
181- labelprefix : '.L';
182- comment : '# ';
182+ flags : [af_allowdirect,af_needar,af_smartlink_sections,af_supports_dwarf];
183+ labelprefix : '.L';
184+ comment : '# ';
185+```
183186
184-*Note*: In this case the change is only needed to get the "-al" option of the compiler, which needs the GNU assembler on Windows, working for i386-nativent.
187+_Note_ : In this case the change is only needed to get the "-al" option of the compiler, which needs the GNU assembler on Windows, working for i386-nativent.
185188
186189### Compiling your target
187190
188-Now that you have a target you will want to see if it works and spot compilation problems by compiling the compiler. To do this, open a console, navigate to your fpc subversion source code directory and build the compiler:
189-
190- PATH=C:\Path_latest_fpc_stable
191+Now that you have a target you will want to see if it works and spot compilation problems by compiling the compiler. To do this, open a console, navigate to your fpc subversion source code directory and build the compiler:
192+```
193+PATH=C:\Path_latest_fpc_stable
191194 cd compiler
192195 make arm
193-
194-And to build your RTL:
196+```
195197
196- cd rtl\my_new_os
198+And to build your RTL:
199+```
200+cd rtl\my_new_os
197201 make FPC=c:\fpc_subversion\compiler\ppcarm -XP$FPCTARGET-
202+```
198203
199-While trying to fix (or implement) RTL for your new target, information found in [[System unit structure]] may be useful.
204+While trying to fix (or implement) RTL for your new target, information found in [[System unit structure]] may be useful.
200205
201206## Porting to a new Architecture
202207
203208### Step 1 - The Binutils
204209
205-The first step in porting to a new architecture is getting and understanding how the binutils of the platform work.
210+The first step in porting to a new architecture is getting and understanding how the binutils of the platform work.
206211
207212### Step 2 - Code Skeleton
208213
209-You can start porting Free Pascal to a new Architecture by creating a new Lazarus project and a new skeleton for it. You can get the Lazarus project for ARM for example, rename it, lets say to ppcmipsel.lpi, modify it in a text editor to refer to mips directory instead of arm and then modify it in Lazarus in the Compiler Options Dialog in the Others tab and set the compiler directive to -dmipsel instead of -darm.
214+You can start porting Free Pascal to a new Architecture by creating a new Lazarus project and a new skeleton for it. You can get the Lazarus project for ARM for example, rename it, lets say to ppcmipsel.lpi, modify it in a text editor to refer to mips directory instead of arm and then modify it in Lazarus in the Compiler Options Dialog in the Others tab and set the compiler directive to -dmipsel instead of -darm.
210215
211216## See also
212217
213-- [[Porting Free Pascal Example]]
214-- Paul Robinson is doing a step-by-step demonstration of his attempts to create a port for the IBM 370 mainframe (the [[ZSeries]] using the OS/VS1 operating system, explaining how he's checking everything, and what's happening along the way. You can read about how he's coming along at [[ZSeries/Part 1|Part 1]] of his article. (Note that the article changes as he learns more about how the compiler works.)
215-- [Structure of the compiler (FPC internals)](https://wiki.freepascal.org/FPC_internals)
218+ * [[Porting to PlayStation1 Guide]] is a step by step tutorial
219+ * [[Porting Free Pascal Example]]
220+ * Paul Robinson is doing a step-by-step demonstration of his attempts to create a port for the IBM 370 mainframe (the [[ZSeries]] using the OS/VS1 operating system, explaining how he's checking everything, and what's happening along the way. You can read about how he's coming along at [[ZSeries/Part 1|Part 1]] of his article. (Note that the article changes as he learns more about how the compiler works.)
221+ * [[FPC internals|Structure of the compiler (FPC internals)]]
216222
217223---
218-*From the Free Pascal wiki, page "Porting Free Pascal", as it stood on 2020-08-19 after a change by Xhajt03, 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).*
219-Category: FPC internals
220-Category: Tutorials
224+*From the Free Pascal wiki, page "Porting Free Pascal", as the Internet Archive kept it on 2025-12-28, last changed on 2024-11-10. 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).*

Back to history