-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathporting-old.html
More file actions
executable file
·631 lines (550 loc) · 19.5 KB
/
porting-old.html
File metadata and controls
executable file
·631 lines (550 loc) · 19.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Porting CM3 to a new Platform</title>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html">
<META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css">
<META HTTP-EQUIV="Resource-type" CONTENT="document">
<META HTTP-EQUIV="Reply-to" CONTENT="m3-support@elego.de">
<LINK HREF="normal.css" REL="stylesheet" TYPE="text/css">
<META NAME="robots" content="noindex">
</head>
<body bgcolor="#ffffff">
<h2>Porting CM3 to a new Platform</h2>
<p>
Porting CM3 to a new platform (hardware architecture / operating
system combination) essentially consists of the following tasks:
</p>
<ol>
<li>
Defining the new platform for the compiler frontend (cm3) and
providing default configuration files
</li>
<li>
Generating a code generator (compiler backend) for the new
platform, either by using gcc or writing an integrated backend
</li>
<li>
Supplying all the needed runtime support in the standard
libraries m3core (much) and libm3 (only a few things)
</li>
</ol>
<p>
Since the compiler is written almost entirely in Modula-3, you
then face the task of compiling, assembling, and linking the
code including all your fine new additions for the new target
platform. You generally have two choices here:
</p>
<ol>
<li>
If you already have a running Modula-3 compiler on the target
platform (e.g. PM3 or the original DEC SRC release), you just
put your code onto the target platform, make it compilable by
the other compiler, and boot the CM3 system with three
compilation stages. This procedure is described in more detail
in <a href="booting.html">Booting CM3 5.1 with PM3 or SRC
M3</a>.
</li>
<li>
Most times you won't be so lucky to find a working Modula-3
compiler on your target platform. Then your only choice is
cross-compiling on an already supported platform, which means
building a cross-compiler for the new platform, compiling all
code to assembler statements on the existing platform,
compiling the few C sources on the new platform (we'll assume
the existence of a C compiler), and assembling and linking all
the generated assembler source on the new platform. This
should produce an at least somewhat working cm3 executable,
which can then be used to complete the bootstrap process.
</li>
</ol>
<p>
In the following sections we'll look at all the things needed to
be done in turn. We'll assume that you use the gcc backend for
code generation, and that your platform is already supported
by gcc. If not, you will have to write the necessary gcc
extensions, too; but this would be beyond the scope of this
article.
</p>
<ol>
<li>
<a href="#s1">Defining a new platform for the compiler frontend</a>
</li>
<li>
<a href="#s2">Supplying the needed runtime support</a>
</li>
<li>
<a href="#s3">Building a cross compiler</a>
</li>
<li>
<a href="#s4">Producing assembler code on the host platform</a>
</li>
<li>
<a href="#s5">Assembling and linking the front end on the
target platform</a>
</li>
<li>
<a href="#s6">Building a code generator on the target
platform</a>
</li>
<li>
<a href="#s7">Recompiling everything on the target platform</a>
</li>
</ol>
<p>
</p>
<hr>
<h3>
<a name="s1">Defining a new platform for the compiler frontend</a>
</h3>
<p>
The first thing you do is choosing a name for the new platform,
like FreeBSD4 or LINUXLIBC6. We'll assume GREATOS in the
following description. You then edit the following files:
</p>
<dl>
<dt><tt>m3-sys/m3middle/src/Target.{i3,m3}</tt></dt>
<dd>
Add the new target name <tt>GREATOS</tt> to the
<tt>Systems</tt> array. In the <tt>Init</tt> procedure, append
a section for <tt>GREATOS</tt> in the case statement. Copy an
entry that you deem similar to the new target platform, and
carefully check all the values.
<p></p>
</dd>
<dt><tt>m3-sys/m3front/src/builtinInfo/InfoModule.m3</tt></dt>
<dd>
Add <tt>GREATOS</tt> to <tt>Platform_names</tt>.
(This should no longer be necessary in current versions, as
the platform list is now imported from Target.i3.)
<p></p>
</dd>
<dt><tt>m3-sys/cm3/src/config/GREATOS</tt></dt>
<dd>
This is the default configuration file for the new
platform. It gets copied to cm3/bin/cm3.cfg.default in the
binary installation archives. Simply copy one from a similar
system, change the <tt>TARGET</tt> setting to
<tt>GREATOS</tt>, and adapt the following values and
procedures:
<ul>
<li><tt>OS_TYPE</tt></li>
<li><tt>WORD_SIZE</tt></li>
<li><tt>GNU_PLATFORM</tt></li>
<li><tt>INSTALL_ROOT</tt></li>
<li><tt>SYSTEM_LIBS</tt></li>
<li><tt>SYSTEM_LIBORDER</tt></li>
<li><tt>m3back</tt></li>
<li><tt>m3_backend()</tt></li>
<li><tt>compile_c()</tt></li>
<li><tt>assemble()</tt></li>
<li><tt>make_lib()</tt></li>
<li><tt>skip_lib()</tt></li>
<li><tt>m3_link()</tt></li>
<li><tt>skip_link()</tt></li>
<li><tt>M3_SPLIT_LIBNAMES</tt></li>
<li><tt>M3_SHARED_LIB_ARG</tt></li>
<li><tt>GNU_CC</tt></li>
<li><tt>GNU_CFLAGS</tt></li>
<li><tt>GNU_MAKE</tt></li>
</ul>
<p></p>
</dd>
<dt><tt>m3-sys/cminstall/src/config/GREATOS</tt></dt>
<dd>
This is the configuration template that is used by the binary
installation program. You can skip this for now, but should
provide one later, containing the same information as in the
one above, but with additional location and decision
information.
<p></p>
</dd>
</dl>
<p>
</p>
<hr>
<h3>
<a name="s2">Supplying the needed runtime support</a>
</h3>
<p>
Create the directories listed below. Start again by copying the
files for some similar system, then check all the contents for
the new platform GREATOS.
</p>
<dl>
<dt><tt>m3-libs/m3core/src/C/GREATOS</tt></dt>
<dd>
<p>
The interfaces in this directory define simple access to
POSIX standard input/output, signal, and
setjmp/longjmp. Check all the type definitions and sizes
against the corresponding C declarations in your system
header files in <tt>/usr/include</tt> and
<tt>/usr/include/sys</tt>. It is very important that the
jmp_buf size is correct and that setjmp/longjmp save all
necessary state, including floating point information, as
this is used for thread switching.
</p>
<p></p>
</dd>
<dt><tt>m3-libs/m3core/src/Csupport/GREATOS</tt></dt>
<dd>
<p>
Simply define the correct dtoa interface. Use a symbol from
your system libraries or the supplied code from another
platform.
</p>
<p></p>
</dd>
<dt><tt>m3-libs/m3core/src/runtime/GREATOS</tt></dt>
<dd>
<p>
This directory contains the basic system dependent runtime
code for your platform. Start with the <tt>RTMachine.i3</tt>
interface and continue with the signal and thread bits. You
will probably disable the VM protection needed by the
incremental and generational garbage collector for the time
being by setting <tt>VMHeap = FALSE</tt>. VM protection
needs page protection support from the underlying operating
system, and a set of wrappers for all system calls. (I'll
write up something on this topic later.) You can add this
feature later. Comment all things not needed in the
accompanying <tt>m3makefile</tt>.
</p>
<p></p>
</dd>
<dt><tt>m3-libs/m3core/src/unix/great-os</tt></dt>
<dd>
<p>
This directory contains the Unix / POSIX interfaces needed
by the core library. You do not need to write and check
everything right now, but quite a lot of this stuff is
needed. Start with <tt>Utypes.i3, Ustat.i3, Uerror.i3,
Uexec.i3, Usignal.i3, Uuio.i3, Udir.i3, Unix.i3</tt>.
I think this should be enough for a simple working
compiler :-)
</p>
<p></p>
</dd>
</dl>
<p>
If you've got so far, you've almost finished your task. There
are still some simple adjustments to be made.
Edit the following files:
</p>
<dl>
<dt><tt>m3-libs/m3core/src/float/m3makefile</tt></dt>
<dd>
<p>
Add an entry to the <tt>_FloatPieces</tt> array for your
GREATOS.
</p>
<p></p>
</dd>
<dt><tt>m3-libs/m3core/src/runtime/m3makefile</tt></dt>
<dd>
<p>
Add an entry for the exception implementation to
<tt>EXCEPTION_IMPL</tt>. You will probably just want to use
<tt>ex_frame</tt> for now.
</p>
<p></p>
</dd>
<dt><tt>m3-libs/m3core/src/time/POSIX/m3makefile</tt></dt>
<dd>
<p>
Define the date implementation your GREATOS uses. Just
choose between the existing ones; one of them should fit
your needs.
</p>
<p></p>
</dd>
<dt><tt>m3-libs/m3core/src/unix/m3makefile</tt></dt>
<dd>
<p>
Add an entry to <tt>_UnixPieces</tt> for GREATOS that
defines the source directories for your system interfaces.
</p>
<p></p>
</dd>
<dt><tt>m3-libs/m3core/src/runtime/common/Compiler.tmpl</tt></dt>
<dd>
<p>
Add GREATOS to the platform definition.
</p>
<p></p>
</dd>
<dt><tt>m3-libs/libm3/src/random/m3makefile</tt></dt>
<dd>
<p>
Choose the random implementation for floating point numbers
by adding an entry in <tt>_RandomPieces</tt>.
</p>
<p></p>
</dd>
<dt><tt>m3-libs/libm3/src/os/POSIX/OSConfigPosix</tt></dt>
<dd>
<p>
Add entries for architecture and operating system name for
GREATOS.
</p>
<p></p>
</dd>
</dl>
<hr>
<h3>
<a name="s3">Building a cross compiler</a>
</h3>
<p>
Add an entry for GREATOS to <tt>Platform_info</tt> in
<tt>m3-sys/m3cc/src/m3makefile</tt>. This defines the GNU
platform description used for your new target machine. You
should now be able to build a cross compiler on your host system
with the command
</p>
<pre>
cm3 -build -DM3CC_HOST=HOST_SYSTEM -DM3CC_TARGET=GREATOS
</pre>
<p>
You may also need to add some more magic stuff depending on your
new target architecture (look for DS3100 and ALPHA_OSF for
examples). The generated cross-compiler will be in
<tt>HOST_SYSTEM/cm3cg</tt>. Copy this executable to the
<tt>bin</tt> directory of your installation (usually
<tt>/usr/local/cm3/bin</tt>) as <tt>cm3cg-GREATOS</tt>. Do not
accidentally overwrite the existing code generator for HOST_SYSTEM!
</p>
<p>
There's now also a script to automate the building of the
cross-compiler.
</p>
<pre>
% ./build-cross-backend.sh -h
usage build-cross-backend.sh:
build-cross-backend.sh [-f] M3_CROSS_TARGET
builds a cm3cg backend for target platform M3_CROSS_TARGET
options:
-f force distclean before compilation
</pre>
<p>
You now should have a working compiler backend for GREATOS, but
you still need a compiler frontend that knows about
GREATOS. Recompile the following packages in this order:
</p>
<ol>
<li><tt>m3-sys/m3middle</tt></li>
<li><tt>m3-sys/m3linker</tt></li>
<li><tt>m3-sys/m3front</tt></li>
<li><tt>m3-sys/m3quake</tt></li>
<li><tt>m3-sys/cm3</tt></li>
<li><tt>m3-libs/m3core</tt></li>
<li><tt>m3-libs/libm3</tt></li>
</ol>
<p>
You can use the scripts in <tt>cm3/scripts</tt> to perform the
compilations.
Backup the existing compiler in
<tt>/usr/local/cm3/bin/cm3-old</tt>, and install the new
compiler as <tt>/usr/local/cm3/bin/cm3</tt>.
</p>
<p>
<b>Note:</b> You can only compile some platform specific code in
m3core and libm3 with a compiler that includes exactly the same
list of target platforms in Target.i3, InfoModule.m3 and
Compiler.i3; otherwise version stamps will get messed up. So you
have to make your port-specific changes, build and ship the compiler
packages m3middle, m3linker, m3front, m3quake, cm3, install the compiler,
and then build the libraries m3core and libm3 and the compiler
packages again (do-cm3-core.sh).
</p>
<hr>
<h3>
<a name="s4">Producing assembler code on the host platform</a>
</h3>
<p>
If you have built and installed the cross compiler frontend and
backend, you need to edit
<tt>/usr/local/cm3/bin/cm3.cfg</tt>. Change the definition for
<tt>m3back</tt> to <tt>... cm3cg-GREATOS</tt> and set
<tt>M3_BOOTSTRAP = TRUE</tt> at the end of the file. Also change
the <tt>TARGET</tt> to <tt>GREATOS</tt> at the top.
</p>
<p>
You should now be able to compile all the packages from the
previous step again, this time generating assembler code in the
GREATOS subdirectories.
</p>
<p>
The following script will archive the cross-compiled assembler
code:
</p>
<pre>
% ./pack-crossbuild.sh -h
usage pack-crossbuild.sh:
pack-crossbuild.sh cross_target
will archive the following cross-compiled packages:
m3core libm3 m3middle m3linker
m3front m3quake cm3 m3scanner
m3tools m3cgcat m3cggen m3bundle
bitvector digraph parseparams realgeometry
set slisp sortedtableextras table-list
tempfiles
The archives will be saved in a cm3/CROSS_TARGET.
</pre>
<p>
Another possibility is to use rsync to copy the generated code,
as is done in copy-bootarchives.sh:
</p>
<pre>
#!/bin/sh
# $Id: porting-old.html,v 1.1 2009-07-22 15:32:35 jkrell Exp $
if [ -n "$ROOT" -a -d "$ROOT" ] ; then
sysinfo="$ROOT/scripts/sysinfo.sh"
else
root=`pwd`
while [ -n "$root" -a ! -f "$root/scripts/sysinfo.sh" ] ; do
root=`dirname $root`
done
sysinfo="$root/scripts/sysinfo.sh"
if [ ! -f "$sysinfo" ] ; then
echo "scripts/sysinfo.sh not found" 1>&2
exit 1
fi
export root
fi
. "$sysinfo"
. "$ROOT/scripts/pkginfo.sh"
RSYNC=${RSYNC:-rsync}
DEST=${DEST:-lamancha.opendarwin.org:work/cm3}
if [ -z "$1" ] ; then
echo "please specify a cross compilation target platform" 1>&2
exit 1
fi
CROSS_TARGET="$1"
shift
if [ -n "$1" ] ; then
PKGS="$@"
else
PKGS=""
fi
P=""
P="${P} m3-libs/m3core"
P="${P} m3-libs/libm3"
P="${P} m3-sys/m3middle"
[ "${M3OSTYPE}" = "WIN32" ] && P="${P} m3-sys/m3objfile"
P="${P} m3-sys/m3linker"
[ "${GCC_BACKEND}" != yes ] && P="${P} m3-sys/m3back"
[ "${GCC_BACKEND}" != yes ] && P="${P} m3-sys/m3staloneback"
P="${P} m3-sys/m3front"
P="${P} m3-sys/m3quake"
P="${P} m3-sys/cm3"
P="${P} m3-tools/m3bundle"
if [ -n "${PKGS}" ] ; then
res=""
for s in ${PKGS}; do
for p in ${P}; do
case ${p} in
*${s}*) res="${res} ${p}";; # echo "res = ${res}";;
esac
done
done
P="${res}"
fi
for p in ${P}; do
echo ${RSYNC} -avz ${ROOT}/${p}/${CROSS_TARGET}/ ${DEST}/${CROSS_TARGET}/${p}/
${CROSS_TARGET}/
${RSYNC} -avz ${ROOT}/${p}/${CROSS_TARGET}/ ${DEST}/${CROSS_TARGET}/${p}/${CRO
SS_TARGET}/
done
</pre>
<hr>
<h3>
<a name="s5">Assembling and linking the front end on the
target platform</a>
</h3>
<p>
Copy the <tt>m3-libs</tt> and <tt>m3-sys</tt> hierarchies (or
just the packages named above) including the generated assembler
code to the new platform. Use the system assembler, C
compiler, archiver, and linker to build all the libraries in the
GREATOS sub-directory. As I don't know about these tools before,
I cannot give more detailed instructions about the exact
commands needed.
</p>
<p>
The script ppc-cross-build.sh may be used as a template for
automating most of the recurring tasks of the cross-compilation
bootstrap:
</p>
<pre>
#!/bin/sh
# This script is an example of how to automate a cross-compilation for
# bootstrapping cm3 on a new target platform. Values are set for
# cross-compilation from FreeBSD4 to PPC_DARWIN running on
# lamancha.opendarwin.org.
TARGET=${TARGET:-PPC_DARWIN}
WORK=${WORK:-/Users/wagner/work}
CM3DEST=${CM3DEST:-/Users/wagner/local/cm3}
CM3DESTBIN=${CM3DEST}/bin
CM3DESTHOST=${CM3DESTHOST:-lamancha.opendarwin.org}
./boot-cm3-core.sh ${TARGET} || exit 1
./copy-bootarchives.sh ${TARGET} || exit 1
ssh ${CM3DESTHOST} \
cd ${WORK}/cm3/scripts '&&' \
./boot-cm3-build-on-target.sh ${TARGET} \; \
[ -f ${CM3DESTBIN}/cm3 ] '&&' mv ${CM3DESTBIN}/cm3 ${CM3DESTBIN}/cm3.bak \;\
cp ${WORK}/cm3/${TARGET}/m3-sys/cm3/${TARGET}/cm3 ${CM3DESTBIN}
</pre>
<p>
It also uses boot-cm3-build-on-target.sh which performs the
necessary build steps on the target machine if parameterized
appropriately.
</p>
<p>
Create an empty cm3 directory structure on your target system
(<tt>cm3/scripts/create-skel.sh</tt>). Install the newly linked
cm3 executable and the default configuration file cm3.cfg in the
<tt>bin</tt> directory of this structure. Add this directory to
your <tt>PATH</tt>.
</p>
<hr>
<h3>
<a name="s6">Building a code generator on the target
platform</a>
</h3>
<p>
Use
</p>
<pre>
cm3 -build -DM3CC_HOST=GREATOS -DM3CC_TARGET=GREATOS
</pre>
<p>
to build the code generator and install it as
<tt>/usr/local/cm3/bin/cm3cg</tt>.
</p>
<hr>
<h3>
<a name="s7">Recompiling everything on the target platform</a>
</h3>
<p>
You should now have a working compiler and proceed to build
itself with it. You can use the scripts
<tt>cm3/scripts/do-cm3-min.sh</tt> and
<tt>cm3/scripts/boot-cm3-with-m3.sh</tt>, or just
<tt>cm3/scripts/do-pkg.sh</tt> with all the package names, i.e.
</p>
<pre>
./do-pkg.sh build m3core libm3 m3middle m3linker m3front m3quake cm3
./do-pkg.sh buildship m3core libm3 m3middle m3linker m3front m3quake cm3
</pre>
<p>
Only do the second step if the build succeeded. You can now
start to clean everything up, add all the missing bits (system
interfaces, vm protection, etc.), and build all the rest of the
CM3 packages.
</p>
<hr>
<address><a href="mailto:m3-support{at}elego.de">m3-support{at}elego.de</a></address>
<!-- Created: Fri Feb 16 15:27:10 MET 2001 -->
</body>
</html>