Sign in Join
Wiki copytemporary

ZSeries/Part 2: what changed

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

OldNewLine
11*[[ZSeries|Go back to zSeries]]* — [[ZSeries/Part 1|Go Back to Part 1]] — [[ZSeries/Part 3|Go Forward to Part 3]]
22
33Because the number of places I have to look is *lots of them*, the list of units I go through is broken up into more than one page. I'll try to keep page lengths to a reasonable factor, if a page seems to be too large, I will split it and start a new section.
44
55I'm also dropping references to files, units and modules that I don't have to change. This will keep the overhead low.
66
77# To Begin
88
99This compiler is *huge*. (I've (re-)compiled it, and the rebuild of the Windows version is 262,000 lines of code.) It's hundreds of source files, and is going to be an enormous task. Where do you start? Well, you start with the main program of the command-line compiler, and you look at it. That file is **pp.pas**. Then you collect all of the units it uses, and you look at each one's source file, then you repeat this recursively, finding every place where there is a reference to a particular machine type or operating system and you add the particular cpu or operating system (or both) to it.
1010
1111Note that line numbers indicated in any source file are from the version 2.6.0 compiler sources (I'll also look at the 2.6.2. sources which have just recently been released) and as such, as lines are added, other line numbers where things were found and changed will increase. So line numbers will be referenced in a file from top to bottom so the references should match. Also, so as not to brand this as "windows centric" since the hope is to build a cross-compiler for s370 that could run on either Windows or Linux, when file names are specified, directory separators will use /.
1212
1313Note that from this point on, all editing occurs in our "sandbox" directory separate from the original compiler.
1414
1515## How units and include files are listed
1616
1717Since this series of articles is intended to be a tutorial on how to add a new architecture to the compiler, files that call other files or units are listed at the top of the section dealing with that file. Where a unit is called by another, that caller is listed. Same for files that are included by other files. Any units the unit or file **uses**, are also listed. As new units which are referenced are found, they are added to the list of all the units that need to be checked and inspected, and potentially edited, as well as new units that have to be created.
1818
1919This also helps since the list of modules is broken over several pages, so you can see where a module cross-references another one even if the references for both are not on the same page.
2020
2121The format of the first line is generally like this (items not used will not appear on the line):
2222
2323
2424*Called from: **\[file names that call this file as a unit, printed in bold\]*** (or) '**'main program**, included by **\[files that call this file using *include*\]**, includes **\[files that this file calls as include files\]**, requires external procedures **\[non-Pascal procedures this unit uses\]**, calls units **\[units that this unit or file uses\]** or "no called units noted" if it does not use any units
2525
2626If the file is not normally in the Compiler directory that is noted, or if it is in a subdirectory. As items are noted in the source code of that file or unit, they will be mentioned.
2727
2828# The Free Pascal Compiler
2929
3030## pp.pas
3131
3232### Version 2.6.0
3333
3434
3535***main program**, includes**fpcdefs.inc**, calls units**cmem, profile, catch, globals, compiler***
3636
3737**pp.pas** is the main program of the compiler. We're going to edit this file to create an IBM-370 cross-compiler. First, we'll decide what is the switch for this, as well as the names of the components. For the compiler switch or target environment, we'll use S370. Within the code, the cpu name is **cpu_S370**, floating-point processor is **fpu_s370**, and the operating system target is **vse** or **linux** because I have access to both environments.
3838
3939So we'll start by adding "S370" to the source comments and wherever else needed to indicate that, by inserting the middle line in the comment block (line 34):
4040
41-` VIS                 generate a compiler for the VIS`\
42-` S370                generate a compiler for the IBM 370/390/zSeries mainframes`\
43-` DEBUG               version with debug code is generated `\
44-`     `
41+```text
42+ VIS generate a compiler for the VIS
43+ S370 generate a compiler for the IBM 370/390/zSeries mainframes
44+ DEBUG version with debug code is generated
45+```
4546
4647This program includes **fpcdefs.inc** so we'll check that later. We have to add the indication to only select one target compiler, so we'll select for I370 (about line 139, before the check that no CPU was defined:\
47-{\$endif AVR}
4848
49-`{$ifdef S370}`\
50-`  {$ifdef CPUDEFINED}`\
51-`    {$fatal ONLY one of the switches for the CPU type must be defined}`\
52-`  {$endif CPUDEFINED}`\
53-`  {$define CPUDEFINED}`\
54-`{$endif S370}`\
55-`{$ifndef CPUDEFINED}`\
56-`  {$fatal A CPU type switch must be defined}`\
57-`{$endif CPUDEFINED}`\
49+``` pascal
50+{$endif AVR}
51+{$ifdef S370}
52+ {$ifdef CPUDEFINED}
53+ {$fatal ONLY one of the switches for the CPU type must be defined}
54+ {$endif CPUDEFINED}
55+ {$define CPUDEFINED}
56+{$endif S370}
57+{$ifndef CPUDEFINED}
58+ {$fatal A CPU type switch must be defined}
59+{$endif CPUDEFINED}</tt>
60+```
5861
5962The rest of the main program seems to be okay, but we will have to go through and look at all the units that this program uses, which, depending on which options have been set, are or can be: **`cmem, profile, catch, globals,` and `compiler`**. Then follow those and see where they lead, and "lather, rinse, repeat." The rest of this file seems okay, so we'll save it. (If we don't change a file, we don't re-save it so as not to change the date and time of the last edit.)
6063
6164### Version 2.6.2
6265
6366Line 34:\
6467
65-`  VIS                 generate a compile for the VIS`
68+```text
69+ VIS generate a compile for the VIS</tt>
70+```
6671
6772Becomes:\
6873
69-`  VIS                 generate a compiler for the VIS`\
70-`  S370                generate a compiler for the IBM 370/390/zSeries mainframes`
74+```text
75+ VIS generate a compiler for the VIS
76+ S370 generate a compiler for the IBM 370/390/zSeries mainframes</tt>
77+```
7178
7279Lines 138 and 139:\
7380
74-`{$endif AVR}`\
75-`{$ifndef CPUDEFINED}`
81+```text
82+{$endif AVR}
83+{$ifndef CPUDEFINED}</tt>
84+```
7685
7786become:\
7887
79-`{$endif AVR}`\
80-`{$ifdef S370}`\
81-`   {$ifdef CPUDEFINED}`\
82-`     {$fatal ONLY one of the switches for the CPU type must be defined}`\
83-`   {$endif CPUDEFINED}`\
84-`   {$define CPUDEFINED}`\
85-`{$endif S370}`\
86-`{$ifndef CPUDEFINED}`
88+``` pascal
89+{$endif AVR}
90+{$ifdef S370}
91+  {$ifdef CPUDEFINED}
92+  {$fatal ONLY one of the switches for the CPU type must be defined}
93+  {$endif CPUDEFINED}
94+  {$define CPUDEFINED}
95+{$endif S370}
96+{$ifndef CPUDEFINED}
97+```
8798
8899## fpcdefs.inc
89100
90101
91102*Called as include file from **pp.pas**, called as include file from units **catch, compiler, verbose** (and virtually all other units), no called units noted*
92103
93104**fpcdefs.inc** provides various definitions regarding what processor we're compiling for to most units and many other files. We need to define the processor, so we'll borrow the generic one, and add or remove items as we need them. So we'll start with the block beginning with the line `{$ifdef generic_cpu}` through the line `{$endif generic_cpu}`. From later work, I discover I'll have to mark the target machine as big endian, so I'll include that. (Note that the definitions will include things as I discover them, so this may include things I haven't explained.)
94105
95106### Version 2.6.0
96107
97108So on line 146, replace
98109
99-`{$endif mips}`\
110+```text
111+{$endif mips}
100112
101-`{$IFDEF MACOS}    `\
102-` `
113+{$IFDEF MACOS}
114+```
103115
104116With:
105117
106-`{$endif mips}`\
118+```text
119+{$endif mips}
107120
108-`{$ifdef S370}`\
109-`  {$define cpu32bit}`\
110-`  {$define cpu32bitaddr}`\
111-`  {$define cpu32bitalu}`\
112-`  {$define cpuflags}`\
113-`  {$define cpuextended}`\
114-`  {$define ENDIAN_BIG}`\
115-`{$endif S370}`\
121+{$ifdef S370}
122+ {$define cpu32bit}
123+ {$define cpu32bitaddr}
124+ {$define cpu32bitalu}
125+ {$define cpuflags}
126+ {$define cpuextended}
127+ {$define ENDIAN_BIG}
128+{$endif S370}
116129
117-`{$IFDEF MACOS}      `
130+{$IFDEF MACOS}
131+```
118132
119133Otherwise, now, **fpcdefs.inc** looks okay, so I'll save it.
120134
121135### Version 2.6.2
122136
123137Line 153, replace:
124138
125-`{$endif mips}`\
139+```text
140+{$endif mips}
126141
127-`{$IFDEF MACOS}    `\
128-` `
142+{$IFDEF MACOS}
143+```
129144
130145With:
131146
132-`{$endif mips}`\
147+```text
148+{$endif mips}
133149
134-`{$ifdef S370}`\
135-`  {$define cpu32bit}`\
136-`  {$define cpu32bitaddr}`\
137-`  {$define cpu32bitalu}`\
138-`  {$define cpuflags}`\
139-`  {$define cpuextended}`\
140-`  {$define ENDIAN_BIG}`\
141-`{$endif S370}`\
150+{$ifdef S370}
151+ {$define cpu32bit}
152+ {$define cpu32bitaddr}
153+ {$define cpu32bitalu}
154+ {$define cpuflags}
155+ {$define cpuextended}
156+ {$define ENDIAN_BIG}
157+{$endif S370}
142158
143-`{$IFDEF MACOS}      `
159+{$IFDEF MACOS}
160+```
144161
145162## Unit globals
146163
147164### Version 2.6.0
148165
149166
150167*Called from: **pp.pas; options.pas**, includes **fpcdefs.inc**, calls unit **comphook***
151168
152169**globals.pas**, starting at about line 372, has some definitions for specific target processors. So, again, I'll borrow from `{$ifdef GENERIC_CPU}` and change as necessary. At line 424, we have
153170
154-` {$endif mips}`
171+```text
172+ {$endif mips}
173+```
155174
156175so we'll add the 370 after this, and put in the following:
157176
158-` {$endif mips}`\
159-` {$ifdef S370}`\
160-`       cputype : cpu_s370;`\
161-`       optimizecputype : cpu_s370;`\
162-`       fputype : fpu_s370;`\
163-` {$endif s370}`
177+```text
178+ {$endif mips}
179+ {$ifdef S370}
180+ cputype : cpu_s370;
181+ optimizecputype : cpu_s370;
182+ fputype : fpu_s370;
183+ {$endif s370}
184+```
164185
165186Note, these values will be defined elsewhere. Note that this unit references a few other units depending on the OS and machine, but the only one relevant to us will be **`comphook`** so we'll put that on the "stack" of units that have to be inspected and possibly edited.
166187
167188### Version 2.6.2
168189
169190There were no changes, the above edits are the same.
170191
171192## Unit compiler
172193
173194### Version 2.6.0
174195
175196
176197*Called from: **pp.pas**, includes **fpcdefs.inc**, calls units **fksysutils, sysutils, math, verbose, comphook, systems, cutils, cfileutl, cclasses, globals, options, fmodule, parser, symtable, assemble, link, dbgbase, import, export, tokens, pass_1, wpobase, wpo, cpupara, cpupi, cgcpu, cpunode, cputarg, i_i370, globtype***
177198
178199Starting at about line 24, this unit lists the units it uses. Some units depend on other flags, but the units it does always require are: **`verbose, comphook, systems, cutils, cfileutl, cclasses, globals, options, fmodule, parser, symtable, assemble, link, dbgbase, import, export, tokens, pass_1, wpobase, wpo, cpupara, cpupi, cgcpu, cpunode,`** and **`cputarg`**. These are also added to the "stack" for checking on references.
179200
180201This unit also defines the operaring that is the target for this compiler, so we have to add a unit which will define our target environment. There are units for every one being targeted, so we have to insert one. At line 116, change:
181202
182-`{$ifdef nativent}`\
183-`  ,i_nativent`\
184-`{$endif nativent}`\
185-`  ,globtype;    `
203+```text
204+{$ifdef nativent}
205+ ,i_nativent
206+{$endif nativent}
207+ ,globtype;
208+```
186209
187210Replace with:
188211
189-`{$ifdef nativent}`\
190-`  ,i_nativent`\
191-`{$endif nativent}`\
192-`{$ifdef vs1}`\
193-`  ,i_vs1`\
194-`{$endif vs1}`\
195-`  ,globtype;    `
212+```text
213+{$ifdef nativent}
214+ ,i_nativent
215+{$endif nativent}
216+{$ifdef vs1}
217+ ,i_vs1
218+{$endif vs1}
219+ ,globtype;
220+```
196221
197222This means we've now added a new source file which will eventually have to be created, **i_vs1.pas** for the new unit **`i_vs1`**, which almost certainly will be in the I370 subdirectory.
198223
199224### Version 2.6.2
200225
201226This file has not been changed, the above changes are the same.
202227
203228## Unit fksysutils
204229
205230This is only used if the particular architecture sets the flag that says it does not use the **`sysutils`** and **`math`** units. Given that all of them do use them, I will presume for now I do not need to create this file. Presume every unit that includes sysutils includes this file if necessary.
206231
207232## Unit sysutils
208233
209234### Version 2.6.0
210235
211236
212237*Called from: **compiler.pas; verbose.pas; cclasses.pas; parser.pas; assemble.pas**; located in **rtl/s370**, includes **fpcdefs.inc**, no called units noted*
213238
214239This file is a local file for each architecture, so it will be in the **s370** subdirectory of the **rtl** subdirectory. Need to make an **s370** subdirectory in **rtl** as this is the first file included in it. I'll take a look at a couple of architectures to see what's expected to be included. It is used for platform dependent calls, is used by the listed units, and if there are no platform dependent calls, it will simply be a stub unit. For the moment, I'll just create a stub file and come back later if *when* I need to.
215240
216-`{`\
241+``` pascal
242+{
217243
218-`    This file is part of the Free Pascal run time library.`\
219-`    Copyright (c) 2012 by Viridian Development Corporation`\
244+ This file is part of the Free Pascal run time library.
245+ Copyright (c) 2012 by Viridian Development Corporation
220246
221-`    Sysutils unit for IBM 370/390/zSystem`\
247+ Sysutils unit for IBM 370/390/zSystem
222248
223-`    See the file COPYING.FPC, included in this distribution,`\
224-`    for details about the copyright.`\
249+ See the file COPYING.FPC, included in this distribution,
250+ for details about the copyright.
225251
226-`    This program is distributed in the hope that it will be useful,`\
227-`    but WITHOUT ANY WARRANTY; without even the implied warranty of`\
228-`    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.`\
252+ This program is distributed in the hope that it will be useful,
253+ but WITHOUT ANY WARRANTY; without even the implied warranty of
254+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
229255
230-` **********************************************************************}`\
231-`unit sysutils;`\
256+ **********************************************************************}
257+unit sysutils;
232258
233-`interface`\
234-`implementation`\
259+interface
260+implementation
235261
236-`end.`
262+end.
263+```
237264
238265Note that I'm using copyright in my company's name; this is to show that the Free Pascal team is not responsible for this code, if they want to include it as part of the regular distribution then they can have their name on it.
239266
240267### Version 2.6.2
241268
242269No difference; use above.
243270
244271## Unit systems
245272
246273### Version 2.6.0
247274
248275
249276*Called from: **compiler.pas; cfileutl.pas; options.pas; parser.pas; assemble.pas**, includes **fpcdefs.inc; systems.inc**, calls unit **cutils***
250277
251278Lines 243-245:
252279
253-`      systems_allow_section = systems_embedded;`\
280+```text
281+ systems_allow_section = systems_embedded;
254282
255-`      systems_allow_section_no_semicolon = systems_allow_section`
283+ systems_allow_section_no_semicolon = systems_allow_section
284+```
256285
257286replaced with:
258287
259-`      systems_allow_section = systems_embedded;`\
260-`      `\
261-`      systems_s370 = [system_s370_vs1,system_s370_linux];     `\
288+```text
289+ systems_allow_section = systems_embedded;
290+
291+ systems_s370 = [system_s370_vs1,system_s370_linux];
262292
263-`      systems_allow_section_no_semicolon = systems_allow_section`
293+ systems_allow_section_no_semicolon = systems_allow_section
294+```
264295
265296Lines 305-307 need to be altered to add the 370 (**TsystemCpu** will be adjusted to compensate):
266297
267-`      cpu2str : array[TSystemCpu] of string[10] =`\
268-`           ('','i386','m68k','alpha','powerpc','sparc','vm','ia64','x86_64',`\
269-`            'mips','arm', 'powerpc64', 'avr', 'mipsel');`
298+```text
299+ cpu2str : array[TSystemCpu] of string[10] =
300+ ('','i386','m68k','alpha','powerpc','sparc','vm','ia64','x86_64',
301+ 'mips','arm', 'powerpc64', 'avr', 'mipsel');
302+```
270303
271304becomes:
272305
273-`      cpu2str : array[TSystemCpu] of string[10] =`\
274-`           ('','i386','m68k','alpha','powerpc','sparc','vm','ia64','x86_64',`\
275-`            'mips','arm', 'powerpc64', 'avr', 'mipsel','s370');`
306+```text
307+ cpu2str : array[TSystemCpu] of string[10] =
308+ ('','i386','m68k','alpha','powerpc','sparc','vm','ia64','x86_64',
309+ 'mips','arm', 'powerpc64', 'avr', 'mipsel','s370');
310+```
276311
277312At around line 851 we have to indicate the target operating system, which can be VS1 or Linux. We replace
278313
279-`{$endif mips}`
314+```text
315+{$endif mips}
316+```
280317
281318with
282319
283-`{$endif mips}`\
284-`{$ifdef s370}`\
285-` {$ifndef default_target_set}`\
286-`  default_target(system_s370_linux);`\
287-` {$define default_target_set}`\
288-` {$endif}`\
289-`{$endif s370}`
320+```text
321+{$endif mips}
322+{$ifdef s370}
323+ {$ifndef default_target_set}
324+ default_target(system_s370_linux);
325+ {$define default_target_set}
326+ {$endif}
327+{$endif s370}
328+```
290329
291330## systems.inc
292331
293332
294333*Called as include file from: **systems.pas**, no called units noted*
295334
296335This adds the cpu types available. About line 50, change
297336
298-`            cpu_mipsel                    { 13 }`
337+```text
338+ cpu_mipsel { 13 }
339+```
299340
300341to
301342
302-`            cpu_mipsel,                   { 13 }`\
303-`            cpu_s370                      { 14 }    `
343+```text
344+ cpu_mipsel, { 13 }
345+ cpu_s370 { 14 }
346+```
304347
305348About line 67, change to add use of the gas assembler on linux, and the hlasm assembler under VS/1:
306349
307-`           ,asmmode_avr_gas`
350+```text
351+ ,asmmode_avr_gas
352+```
308353
309354to
310355
311-`           ,asmmode_avr_gas`\
312-`           ,asmmode_s370_gas`\
313-`           ,asmmode_s370_hlasm`
356+```text
357+ ,asmmode_avr_gas
358+ ,asmmode_s370_gas
359+ ,asmmode_s370_hlasm
360+```
314361
315362About line 152, change
316363
317-`            system_powerpc_wii         { 70 }`
364+```text
365+ system_powerpc_wii { 70 }
366+```
318367
319368to
320369
321-`            system_powerpc_wii,        { 70 }`\
322-`            system_s370_linux,         { 71 }`\
323-`            system_s370_vs1,           { 72 }`
370+```text
371+ system_powerpc_wii, { 70 }
372+ system_s370_linux, { 71 }
373+ system_s370_vs1, { 72 }
374+```
324375
325376About line 185, change
326377
327-`            ,as_i386_nlmcoff`
378+```text
379+ ,as_i386_nlmcoff
380+```
328381
329382to
330383
331-`            ,as_i386_nlmcoff`\
332-`            ,as_s370_as`\
333-`            ,as_s370_hlasm`
384+```text
385+ ,as_i386_nlmcoff
386+ ,as_s370_as
387+ ,as_s370_hlasm
388+```
334389
335390Otherwise seems okay for now.
336391
337392## Unit globals
338393
339394
340395*Called from: **compiler.pas; parser.pas; assemble.pas**, includes **fpcdefs.inc**, no called units noted*
341396
342397**globals.pas** definitely provides direct processor-dependent information. We'll copy the default `{$ifdef GENERIC_CPU}` and change it for the i370. At about line 424 substitute
343398
344-`  {$endif mips}`
399+```text
400+ {$endif mips}
401+```
345402
346403with
347404
348-`  {$endif mips}`\
349-`  {$ifdef s370}`\
350-`        cputype : cpu_s370;`\
351-`        optimizecputype : cpu_s370;`\
352-`        fputype : fpu_s370;`\
353-`  {$endif s370} `
405+```text
406+ {$endif mips}
407+ {$ifdef s370}
408+ cputype : cpu_s370;
409+ optimizecputype : cpu_s370;
410+ fputype : fpu_s370;
411+ {$endif s370}
412+```
354413
355414At some point I probably should set the switches for a compiler for the i386 under windows and recompile, to be sure that my changes have not left the compiler in an unrebuildable state even if I don't implement anything for the S370 for a while.
356415
357416To make this page a reasonable size, this list continues in [[ZSeries/Part 3|part 3]].
358417
359418
360419*[[ZSeries|Go back to zSeries]]* — [[ZSeries/Part 1|Go Back to Part 1]] — [[ZSeries/Part 3|Go Forward to Part 3]]
361420
362421---
363422*From the Free Pascal wiki, page "ZSeries/Part 2", as it stood on 2014-01-28 after a change by Rfc1394, 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).*
364423Category: High-performance computing
365424Category: Mainframes

Back to history