1 # Copyright (C) 2001-2008, Parrot Foundation.
6 docs/porting_intro.pod - Parrot Subsystem Porting Introduction
10 This document is an introduction to porting the optional subsystems of Parrot
11 onto a new architecture once the core successfully builds. It assumes passing
12 familiarity with common VM techniques but relatively little knowledge of Parrot
13 internals. For each feature, a brief description of its purpose, hints on
14 helping to port it, and pointers to more information are included.
16 =head1 CGoto or CGP (CGoto Predereferenced)
20 "Computed goto" is a non-standard C feature that allows taking a pointer to an
21 statement label (e.g. "LOOP:" ) using the unary && operator. Certain Parrot
22 runcores make use of this feature as an optimization.
26 If cgoto is not supported in Parrot by default on your platform, try to compile
27 config/auto/cgoto/test_c.in with your C compiler and determine why it fails. If
28 the compiler does not support the computed goto concept at all, this feature
29 cannot be made to work (don't worry, there are other runcores). However, if
30 the compiler supports it but the test is inadequate, please submit a bug report
31 describing how the implementation of this feature differs from what Parrot
34 Note that gcc supports this feature out of the box, though it sometimes
35 struggles with it in low-memory situations. Failures during compilation of
36 core_ops_cg.c are frequently caused by insufficient resources rather than bugs
43 =item * F<config/auto/cgoto/test_c.in>
53 Parrot contains a just-in-time compilation subsystem that compiles Parrot
54 bytecode into native processor instructions just prior to execution,
55 eliminating much of the overhead of bytecode interpretation.
59 Each unique processor target requires its own JIT engine. So far, engines have
60 been implemented for DEC Alpha, ARM, Intel i386, SGI MIPS, PPC, and Sun4. If
61 you know that your architecture is substantially similar to one of these,
62 adding support may be possible with relatively little effort. Implementing a
63 novel JIT core from scratch is a substantial undertaking.
65 Also note that some changes may be required based on OS as well. (e.g.:
66 OS X/i386 vs. Linux/i386; OS X/i386 doesn't currently work.)
72 =item * F<docs/jit.pod>
74 =item * F<src/jit/$arch/*>
86 Parrot's "native exec" feature allows the integration of the parrot runtime and
87 a Parrot program into a single precompiled binary, reducing program start-up
88 cost and negating the need to package Parrot distinctly from an application.
89 It's perl2exe/PerlApp/PAR for the Parrot generation.
93 The exec feature makes use of the JIT subsystem, and requires supporting code
94 with knowledge of the operating system's native object format. This feature is
95 only supported on JITable architectures (for now, just x86) running Linux,
96 *BSD, or Darwin. An interested Parrot hacker with an eligible platform can
97 contribute by submitting patches which emit exec objects in the OS's native
98 object format (e.g., ELF, a.out, XCOFF).
104 =item * F<docs/native_exec.pod>
106 =item * F<src/exec*.c>
108 =item * F<include/parrot/exec*.h>
110 =item * F<config/auto/jit.pl>
118 Parrot abstracts parallel streams of execution (threads) using a small set of
119 concurrency primitives that operate on thread objects with distinct code paths
120 and private data. Architecture-specific threading models are mapped onto to
121 these primitives to provide Parrot threads with the most desirable features of
122 native threads. Native thread support is very important to the adoption of
127 At present Parrot implements support only for POSIX threads (pthreads). Most
128 modern UNIX-like operating systems have a pthreads implementation, and allowing
129 Parrot to use these is frequently just a matter of finding the right compiler
130 and linker flags. Non-POSIX architectures with substantially different
131 threading models will require more implementation and debugging to work with
134 To assist with enhancing threading support, compare the threading primitives
135 required by Parrot in F<thread.h> to those provided by your platform's
136 threading model(s) and implement Parrot threads in terms of native threads. See
137 F<thr_pthread.h> for an example of this.
143 =item * F<t/pmc/threads.t>
145 =item * F<config/gen/platform/*/threads.h>
147 =item * F<src/thread.c>
149 =item * F<include/parrot/thread.h>
151 =item * F<include/parrot/thr_pthread.h>
159 Parrot must be able to receive asynchronous imperative and advisory messages
160 from the operating system and other local processes in a safe manner. Typically
161 this is done by registering message-specific callback functions, to which the
162 operating system transfers control when signals are generated.
166 UNIX-like systems usually employ the signal() function for this purpose;
167 Windows achieves similar functionality with message queues. For now, Parrot
168 assumes a mechanism like the former can be used. Currently the signal handler
169 test suite only operates under Linux, though the mechanism itself is intended
170 to work wherever Parrot does. Portable tests as well as fixes for failures
171 thereof are greatly needed.
177 =item * F<config/gen/platform/*/signal.[ch]>
179 =item * F<t/pmc/signal.t>
187 Nearly all modern operating systems support runtime-specified importation of
188 shared library object code, and Parrot must support this feature in order to
189 use native libraries without relying on the system linker. Notable APIs for
190 this mechanism include C<dlopen()> on common *NIXes and LoadLibrary on Win32.
194 If not already supported, research the dynamic library loading API for your
195 platform and implement it in the platform-specific sources. Since Parrot
196 substantially abstracts the dynload mechanism, adding support for a new
197 platform should not require diving far into Parrot internals.
203 =item * F<config/gen/platform/*/dl.[ch]>
207 =head1 Memory protection
211 An ever-increasing number of operating systems support the enforcement of
212 executable/non-executable flags on memory regions to prevent the improper
213 execution of erroneous or malicious instructions. When applied by default to
214 regions that rarely need to contain executable code, this is a useful security
215 measure. However, since Parrot (specifically, the JIT subsystem) generates and
216 executes native instructions in such regions, it must be able to safely
217 circumvent these protections.
221 Determine what level of support for execute protection your architecture/OS
222 combination has, and how to selectively disable it. Documentation for features
223 like PaX (Linux) and W^X (OpenBSD) are the best place to look for this
224 information. The platform-specific source files implement memory allocation
225 wrappers that hide these details, so wading deep into Parrot is probably not a
226 prerequisite for this task.
232 =item * F<config/gen/platform/*/memexec.c>