source: rtems/doc/porting/miscellaneous.t @ 6449498

4.104.114.84.95
Last change on this file since 6449498 was 6449498, checked in by Joel Sherrill <joel.sherrill@…>, on 01/17/02 at 21:47:47

2001-01-17 Joel Sherrill <joel@…>

  • SUPPORT, LICENSE: New files.
  • Numerous files touched as part of merging the 4.5 branch onto the mainline development trunk and ensuring that the script that cuts snapshots and releases works on the documentation.
  • Property mode set to 100644
File size: 6.6 KB
Line 
1@c
2@c  COPYRIGHT (c) 1988-2002.
3@c  On-Line Applications Research Corporation (OAR).
4@c  All rights reserved.
5@c
6@c  $Id$
7@c
8
9@chapter Miscellaneous
10
11@section Fatal Error Default Handler
12
13The _CPU_Fatal_halt routine is the default fatal error handler. This
14routine copies _error into a known place -- typically a stack location or
15a register, optionally disables interrupts, and halts/stops the CPU.  It
16is prototyped as follows and is often implemented as a macro:
17
18@example
19void _CPU_Fatal_halt(
20    unsigned32 _error
21);
22@end example
23
24@section Processor Endianness
25
26Endianness refers to the order in which numeric values are stored in
27memory by the microprocessor.  Big endian architectures store the most
28significant byte of a multi-byte numeric value in the byte with the lowest
29address.  This results in the hexadecimal value 0x12345678 being stored as
300x12345678 with 0x12 in the byte at offset zero, 0x34 in the byte at
31offset one, etc..  The Motorola M68K and numerous RISC processor families
32is big endian.  Conversely, little endian architectures store the least
33significant byte of a multi-byte numeric value in the byte with the lowest
34address.  This results in the hexadecimal value 0x12345678 being stored as
350x78563412 with 0x78 in the byte at offset zero, 0x56 in the byte at
36offset one, etc..  The Intel ix86 family is little endian. 
37Interestingly, some CPU models within the PowerPC and MIPS architectures
38can be switched between big and little endian modes.  Most embedded
39systems use these families strictly in big endian mode.
40
41RTEMS must be informed of the byte ordering for this microprocessor family
42and, optionally, endian conversion routines may be provided as part of the
43port.  Conversion between endian formats is often necessary in
44multiprocessor environments and sometimes needed when interfacing with
45peripheral controllers.
46
47@subsection Specifying Processor Endianness
48
49The CPU_BIG_ENDIAN and CPU_LITTLE_ENDIAN are set to specify the endian
50format used by this microprocessor.  These macros should not be set to the
51same value.  The following example illustrates how these macros should be
52set on a processor family that is big endian.
53
54@example
55#define CPU_BIG_ENDIAN                           TRUE
56#define CPU_LITTLE_ENDIAN                        FALSE
57@end example
58
59@subsection Optional Endian Conversion Routines
60
61In a networked environment, each program communicating must agree on the
62format of data passed between the various systems in the networked
63application.  Routines such as ntohl() and htonl() are used to convert
64between the common network format and the native format used on this
65particular host system.  Although RTEMS has a portable implementation of
66these endian conversion routines, it is often possible to implement these
67routines more efficiently in a processor specific fashion.
68
69The CPU_HAS_OWN_HOST_TO_NETWORK_ROUTINES is set to TRUE when the port
70provides its own implementation of the network to host and host to network
71family of routines.  This set of routines include the following:
72
73@itemize @bullet
74@item XXX list of routines in bullets
75@end itemize
76
77The following example illustrates how this macro should be set when the
78generic, portable implementation of this family of routines is to be used
79by this port:
80
81@example
82#define CPU_HAS_OWN_HOST_TO_NETWORK_ROUTINES FALSE
83@end example
84
85@section Extra Stack for MPCI Receive Thread
86
87The CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK macro is set to the amount of
88stack space above the minimum thread stack space required by the MPCI
89Receive Server Thread.  This macro is needed because in a multiprocessor
90system the MPCI Receive Server Thread must be able to process all
91directives.
92
93@example
94#define CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK 0
95@end example
96
97@subsection Endian Swap Unsigned Integers
98
99The port should provide routines to swap sixteen (CPU_swap_u16) and
100thirty-bit (CPU_swap_u32) unsigned integers.  These are primarily used in
101two areas of RTEMS - multiprocessing support and the network endian swap
102routines.  The CPU_swap_u32 routine must be implemented as a static
103routine rather than a macro because its address is taken and used
104indirectly.  On the other hand, the CPU_swap_u16 routine may be
105implemented as a macro.
106
107Some CPUs have special instructions that swap a 32-bit quantity in a
108single instruction (e.g. i486).  It is probably best to avoid an "endian
109swapping control bit" in the CPU.  One good reason is that interrupts
110would probably have to be disabled to insure that an interrupt does not
111try to access the same "chunk" with the wrong endian.  Another good reason
112is that on some CPUs, the endian bit endianness for ALL fetches -- both
113code and data -- so the code will be fetched incorrectly.
114
115The following is an implementation of the CPU_swap_u32 routine that will
116work on any CPU.  It operates by breaking the unsigned thirty-two bit
117integer into four byte-wide quantities and reassemblying them.
118
119@example
120static inline unsigned int CPU_swap_u32(
121  unsigned int value
122)
123@{
124  unsigned32 byte1, byte2, byte3, byte4, swapped;
125 
126  byte4 = (value >> 24) & 0xff;
127  byte3 = (value >> 16) & 0xff;
128  byte2 = (value >> 8)  & 0xff;
129  byte1 =  value        & 0xff;
130 
131  swapped = (byte1 << 24) | (byte2 << 16) | (byte3 << 8) | byte4;
132  return( swapped );
133@}
134@end example
135
136Although the above implementation is portable, it is not particularly
137efficient.  So if there is a better way to implement this on a particular
138CPU family or model, please do so.  The efficiency of this routine has
139significant impact on the efficiency of the multiprocessing support code
140in the shared memory driver and in network applications using the ntohl()
141family of routines.
142
143Most microprocessor families have rotate instructions which can be used to
144greatly improve the CPU_swap_u32 routine.  The most common way to do this
145is to:
146
147@example
148swap least significant two bytes with 16-bit rotate
149swap upper and lower 16-bits
150swap most significant two bytes with 16-bit rotate
151@end example
152
153Some CPUs have special instructions that swap a 32-bit quantity in a
154single instruction (e.g. i486).  It is probably best to avoid an "endian
155swapping control bit" in the CPU.  One good reason is that interrupts
156would probably have to be disabled to insure that an interrupt does not
157try to access the same "chunk" with the wrong endian.  Another good reason
158is that on some CPUs, the endian bit endianness for ALL fetches -- both
159code and data -- so the code will be fetched incorrectly.
160
161Similarly, here is a portable implementation of the CPU_swap_u16 routine. 
162Just as with the CPU_swap_u32 routine, the porter should provide a better
163implementation if possible.
164
165@example
166#define CPU_swap_u16( value ) \
167  (((value&0xff) << 8) | ((value >> 8)&0xff))
168@end example
169
170
Note: See TracBrowser for help on using the repository browser.