1 <!-- Copyright (C) 2003 Red Hat, Inc. -->
2 <!-- This material may be distributed only subject to the terms -->
3 <!-- and conditions set forth in the Open Publication License, v1.0 -->
4 <!-- or later (the latest version is presently available at -->
5 <!-- http://www.opencontent.org/openpub/). -->
6 <!-- Distribution of the work or derivative of the work in any -->
7 <!-- standard (paper) book form is prohibited unless prior -->
8 <!-- permission is obtained from the copyright holder. -->
13 ><meta name="MSSmartTagsPreventParsing" content="TRUE">
16 CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
19 TITLE="eCos Reference Manual"
20 HREF="ecos-ref.html"><LINK
22 TITLE="eCos Synthetic Target"
23 HREF="hal-synth-arch.html"><LINK
25 TITLE="Writing New Devices - host"
26 HREF="synth-new-host.html"><LINK
28 TITLE="SA11X0 USB Device Driver"
29 HREF="devs-usb-sa11x0-ref.html"></HEAD
40 SUMMARY="Header navigation table"
49 >eCos Reference Manual</TH
57 HREF="synth-new-host.html"
71 HREF="devs-usb-sa11x0-ref.html"
82 NAME="SYNTH-PORTING">Porting</H1
90 >Porting -- Adding support for other hosts</DIV
94 NAME="SYNTH-PORTING-DESCRIPTION"
99 >The initial development effort of the eCos synthetic target happened
100 on x86 Linux machines. Porting to other platforms involves addressing
101 a number of different issues. Some ports should be fairly
102 straightforward, for example a port to Linux on a processor other than
103 an x86. Porting to Unix or Unix-like operating systems other than
104 Linux may be possible, but would involve more effort. Porting to a
105 completely different operating system such as Windows would be very
106 difficult. The text below complements the eCos Porting Guide.
112 NAME="SYNTH-PORTING-LINUX"
115 >Other Linux Platforms</H2
117 >Porting the synthetic target to a Linux platform that uses a processor
118 other than x86 should be straightforward. The simplest approach is to
119 copy the existing <TT
123 directory tree in the <TT
127 hierarchy, then rename and edit the ten or so files in this package.
128 Most of the changes should be pretty obvious, for example on a 64-bit
129 processor some new data types will be needed in the
133 > header file. It will also be necessary
134 to update the toplevel <TT
138 entry for the new HAL package, and a new target entry will be needed.
141 >Obviously a different processor will have different register sets and
142 calling conventions, so the code for saving and restoring thread
143 contexts and for implementing <TT
150 > will need to be updated. The exact way of
151 performing Linux system calls will vary: on x86 linux this usually
152 involves pushing some registers on the stack and then executing an
156 > trap instruction, but on a different
157 processor the arguments might be passed in registers instead and
158 certainly a different trap instruction will be used. The startup code
159 is written in assembler, but needs to do little more than extract the
160 process' argument and environment variables and then jump to the main
164 > function provided by the
165 architectural synthetic target HAL package.
172 architectural HAL package provides various structure definitions,
173 function prototypes, and macros related to system calls. These are
174 correct for x86 linux, but there may be problems on other processors.
175 For example a structure field that is currently defined as a 32-bit
176 number may in fact may be a 64-bit number instead.
179 >The synthetic target's memory map is defined in two files in the
184 For x86 the default memory map involves eight megabytes of read-only
185 memory for the code at location 0x1000000 and another eight megabytes
186 for data at 0x2000000. These address ranges may be reserved for other
187 purposes on the new architecture, so may need changing. There may be
188 some additional areas of memory allocated by the system for other
189 purposes, for example the startup stack and any environment variables,
190 but usually eCos applications can and should ignore those.
193 >Other HAL functionality such as interrupt handling, diagnostics, and
194 the system clock are provided by the architectural HAL package and
195 should work on different processors with few if any changes. There may
196 be some problems in the code that interacts with the I/O auxiliary
197 because of lurking assumptions about endianness or the sizes of
201 >When porting to other processors, a number of sources of information
202 are likely to prove useful. Obviously the Linux kernel sources and
203 header files constitute the ultimate authority on how things work at
204 the system call level. The GNU C library sources may also prove very
205 useful: for a normal Linux application it is the C library that
206 provides the startup code and the system call interface.
212 NAME="SYNTH-PORTING-UNIX"
215 >Other Unix Platforms</H2
217 >Porting to a Unix or Unix-like operating system other than Linux would
218 be somewhat more involved. The first requirement is toolchains: the
219 GNU compilers, gcc and g++, must definitely be used; use of other GNU
220 tools such as the linker may be needed as well, because eCos depends
221 on functionality such as prioritizing C++ static constructors, and
222 other linkers may not implement this or may implement it in a
223 different and incompatible way. A closely related requirement is the
224 use of ELF format for binary executables: if the operating system
225 still uses an older format such as COFF then there are likely to be
226 problems because they do not provide the flexibility required by eCos.
229 >In the architectural HAL there should be very little code that is
230 specific to Linux. Instead the code should work on any operating
231 system that provides a reasonable implementation of the POSIX
232 standard. There may be some problems with program startup, but those
233 could be handled at the architectural level. Some changes may also be
234 required to the exception handling code. However one file which will
235 present a problem is <TT
239 various structure definitions and macros used with the system call
240 interface. It is likely that many of these definitions will need
241 changing, and it may well be appropriate to implement variant HAL
242 packages for the different operating systems where this information
243 can be separated out. Another possible problem is that the generic
244 code assumes that system calls such as
247 >cyg_hal_sys_write</TT
248 > are available. On an operating
249 system other than Linux it is possible that some of these are not
250 simple system calls, and instead wrapper functions will need to be
251 implemented at the variant HAL level.
254 >The generic I/O auxiliary code should be fairly portable to other Unix
255 platforms. However some of the device drivers may contain code that is
256 specific to Linux, for example the <TT
260 address family and the ethertap virtual tunnelling interface. These
261 may prove quite difficult to port.
264 >The remaining porting task is to implement one or more platform HAL
265 packages, one per processor type that is supported. This should
266 involve much the same work as a port to <A
267 HREF="synth-porting.html#SYNTH-PORTING-LINUX"
268 >another processor running Linux</A
272 >When using other Unix operating systems the kernel source code may not
273 be available, which would make any porting effort more challenging.
274 However there is still a good chance that the GNU C library will have
275 been ported already, so its source code may contain much useful
282 NAME="SYNTH-PORTING-OTHER"
285 >Windows Platforms</H2
287 >Porting the current synthetic target code to some version of Windows
288 or to another non-Unix platform is likely to prove very difficult. The
289 first hurdle that needs to be crossed is the file format for binary
290 executables: current Windows implementations do not use ELF, instead
291 they use their own format PE which is a variant of the rather old and
292 limited COFF format. It may well prove easier to first write an ELF
293 loader for Windows executables, rather than try to get eCos to work
294 within the constraints of PE. Of course that introduces new problems,
295 for example existing source-level debuggers will still expect
296 executables to be in PE format.
299 >Under Linux a synthetic target application is not linked with the
300 system's C library or any other standard system library. That would
301 cause confusion, for example both eCos and the system's C library
302 might try to define the <TT
306 introduce complications such as working with shared libraries. For
307 much the same reasons, a synthetic target application under Windows
308 should not be linked with any Windows DLL's. If an ELF loader has been
309 specially written then this may not be much of a problem.
312 >The next big problem is the system call interface. Under Windows
313 system calls are generally made via DLL's, and it is not clear that
314 the underlying trap mechanism is well-documented or consistent between
315 different releases of Windows.
318 >The current code depends on the operating system providing an
319 implementation of POSIX signal handling. This is used for I/O
320 purposes, for example <TT
324 system clock, and for exceptions. It is not known what equivalent
325 functionality is available under Windows.
328 >Given the above problems a port of the synthetic target to Windows may
329 or may not be technically feasible, but it would certainly require a
330 very large amount of effort.
338 SUMMARY="Footer navigation table"
349 HREF="synth-new-host.html"
367 HREF="devs-usb-sa11x0-ref.html"
377 >Writing New Devices - host</TD
383 HREF="hal-synth-arch.html"
391 >SA11X0 USB Device Driver</TD