misalign(5) DG/UX R4.11 misalign(5)
NAME
misalign - handle misaligned memory access faults (88k only)
DESCRIPTION
The Motorola M88000 microprocessor family, on which the Data General
AViiON computers are based, requires that data be aligned in memory
to their lengths. If the address of a datum is not an integral
multiple of the datum's length, a reference to the datum will cause a
misaligned access fault. For example, if a program attempts to fetch
a 16-bit value from an odd address, a misaligned access fault occurs.
A misaligned access fault results in the delivery of a SIGBUS signal
to the application. If the application has not defined a SIGBUS
signal handler, the application terminates with a ``Bus error''
message.
A program can use the facilities defined herein to repair misaligned
access faults that it incurs. These facilities can be useful in
porting applications that were written for computers that don't
impose alignment restrictions as strict as those of the M88000
family. The facilities are offered in three forms, for generality
and convenience:
· functions to repair misaligned access faults with which you can
construct your own SIGBUS signal handler
· predefined SIGBUS signal handlers that are built from the repair
functions mentioned above
· a link-time mechanism to have one of the predefined SIGBUS signal
handlers installed automatically when your program runs
To use these facilities in any of the three forms you must specify
the misalignment handling library, libmisalign.a, to the linker. To
do this you can simply include -lmisalign on the cc or ld command
line. If you use the ld command, be sure to specify the misalignment
handling library before specifying libc, as with -lc.
If your program does not care to handle SIGBUS signals other than
those representing misaligned access faults, you can simply specify
-u misalign.autoinstall to the linker before specifying the
misalignment handling library. With such a specification, a SIGBUS
handler that catches SIGBUS signals and repairs misaligned access
faults will be installed automatically when your program runs. You
do not need to modify your original program to use misalignment
handling in this way.
If your program does not care to handle SIGBUS signals other than
those representing misaligned access faults but does want to
establish signal handlers explicitly, you can use the predefined
signal handlers misalignmentsigbushandlerocs1 and
misalignmentsigbushandlerabi1. These signal handlers catch SIGBUS
signals and repair misaligned access faults in the same way; they
differ only in the target environments for which they are
appropriate. If you establish the signal handler in a COFF
environment (such as m88kbcs, m88kocs, or m88kdguxcoff), use
misalignmentsigbushandlerocs1. If you establish the signal
handler in an ELF environment (such as m88kdguxelf), use
misalignmentsigbushandlerabi1; establish the handler with
sigaction(2) and set the SA_SIGINFO flag.
If a predefined signal handler catches a SIGBUS signal that does not
represent a misaligned access fault, or if it cannot repair a
misaligned access fault for any reason, it aborts the program by
sending a SIGBUS signal to its own process using the kill() function.
This same failure response occurs when -u misalign.autoinstall is
used, because one of the predefined handlers is installed
automatically in that case.
If the failure treatment of the predefined handlers is inappropriate
for your program, or if you want to handle SIGBUS signals other than
those representing misaligned access faults, you can use the
functions repairmisalignmentocs1 and repairmisalignmentabi1.
These functions attempt to repair misaligned access faults and
indicate their success or failure. You can call one of these
functions from your program's SIGBUS signal handler, then take other
appropriate action in the case of failure. The two functions act the
same; they differ only in their argument lists and the target
environments for which they are appropriate.
repairmisalignmentocs1 takes two arguments, the same arguments
received by a signal handler that was established in a COFF
environment. repairmisalignmentabi1 takes three arguments, the
same arguments received by a signal handler that was established in
an ELF environment by a call to sigaction(2) with the SASIGINFO flag
set.
The repair functions return an integer whose value indicates whether
the repair was successful. If the return value is negative, the
repair failed; otherwise, it succeeded. Furthermore, if the return
value is zero, the site of the misaligned access fault was patched so
that future faults will not occur; if the return value is positive,
patching was not possible.
The remainder of this description applies to repair of misaligned
access faults by any of the three forms described above (automatic
installation of predefined handler, explicit installation of
predefined handler, or direct use of repair function). The common
facilities are referred to collectively as ``misalignment handling.''
Misalignment handling can not only emulate the faulting memory access
but also patch the faulting instruction so that future faults will
not occur. Patching can greatly speed up an application that suffers
misaligned access faults. Note, however, that patching renders your
program's text area less sharable. Pages that contain faulting
instructions that are patched become private to your process.
If a faulting instruction appears to be in a delay slot (that is, the
instruction appears to follow a flow control instruction with delayed
branching selected), it is assumed that the instruction is indeed in
a delay slot, and instructions are generated to patch the flow
control instruction as well as the faulting instruction. Patching an
instruction in a delay slot requires more instructions. If the
resulting performance of your program is inadequate due to a large
number of misaligned access faults, you may wish to instruct the
compiler not to perform delay slot optimization. For gcc, use the
-fno-delayed-branch option. For cc, use the -W0,-fno-delayed-branch
option. For Green Hills compilers, use the -X307 option.
Three M88000 instructions can incur misaligned access faults: ld, st,
and xmem. Misalignment handling handles all three instructions, but
cannot maintain atomicity in most cases because the access must be
done in pieces. The loss of atomicity is generally not important
except for xmem, which is not typically generated by compilers.
You can control the behavior of misalignment handling by including an
options file among the object files presented to the linker. The
file misalign-options.c is provided as a prototype from which you can
create your own version. The following table shows what behaviors
the options file controls and what the defaults are when no options
file is present. See the commentary in the prototype options file
for complete information.
Behavior Default
Whether to patch yes
Whether to patch in delay slots yes
What registers to treat as scratch r26 through r29
How much bss area to preallocate none
How to abort on failure send SIGBUS signal to self
EXAMPLE
The following gcc command compiles a program for debugging with
mxdb(1) and links it with misalignment handling.
gcc -g -mlegend -o example example.c -u misalign.autoinstall -lmisalign
Mxdb can be used to determine where misaligned accesses occur. The
following shell script produces a backtrace of the stack on each
misaligned access. It then continues the program which allows
misalignment handling to fix the access.
mxdb example <<EOF
,, Do a walkback on each SIGBUS.
signal, catch bus, \
action { \
new-line; \
write MISALIGNED ACCESS; \
walkback, arg, locals; \
continue \
}
continue ,, Start the program.
bye ,, Quit when it is done.
EOF
The backslashes shown above are necessary.
If you use the above approach with patching enabled (the default),
you should note two things. First, warnings of the following form
may result but can be ignored:
Warning: instruction 00000000 not yet supported, ignored
Second, misaligned access faults can occur in the patch code
sequences themselves. You need not worry about these faults, because
in these cases the original faulting instruction is ``repatched.''
SEE ALSO
mxdb(1), sigaction(2), kill(2), sde(5),
Using the Multi-Extensible Debugger (Mxdb for DG/UX and 386/ix
Systems),
88open Binary Compatibility Standard,
88open Object Compatibility Standard,
MC88100 RISC Microprocessor User's Manual.
Licensed material--property of copyright holder(s)