Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ misalign(5) — DG/UX 4.31

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

signal(2)



     misalign(5)                DG/UX 4.31                 misalign(5)



     NAME
          misalign - handle misaligned memory access faults

     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.

          The object file misalign.o defines a SIGBUS handler that
          catches SIGBUS signals and repairs misaligned access faults.
          It 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.

          To repair misaligned access faults, include misalign.o among
          the object files presented to the linker.  If you use the ld
          command, be sure to specify misalign.o before specifying
          libc, as with -lc.  You may also invoke the linker through
          commands such as cc, as usual.

          misalign.o automatically installs its special SIGBUS handler
          when the program it is linked into is executed.  Hence,
          misalign.o can be used without modifying your original
          program.  Your application may still define a SIGBUS
          handler, which is used for SIGBUS signals that cannot be
          handled correctly by the special handler.  For example,
          write protection violations also result in SIGBUS signals
          but cannot be repaired by misalign.o.  (Currently, your
          application may define a SIGBUS handler only with the
          signal() routine.)

          misalign.o has the capability not only of emulating the
          faulting memory access but also of patching 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



     Licensed material--property of copyright holder(s)         Page 1





     misalign(5)                DG/UX 4.31                 misalign(5)



          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.  misalign.o 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 exercise control over the behavior of misalign.o 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 delay-slot instructions   yes
          What registers to treat as scratch         r26 through r29
          How much bss area to reserve for patching  none
          How to handle a fatal error                Print message to stderr,
                                                     call abort(), then exit()

     EXAMPLE
          The following cc command compiles a program for debugging
          with mxdb(1) and links it with the misalignment handler.

            cc -g -mlegend -o example example.c misalign.o

          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 the misalign.o handler to fix the
          access.










     Licensed material--property of copyright holder(s)         Page 2





     misalign(5)                DG/UX 4.31                 misalign(5)



          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 will probably 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
          signal(2),
          88open Binary Compatibility Standard,
          88open Object Compatibility Standard,
          MC88100 RISC Microprocessor User's Manual,
          Using the Multi-Extensible Debugger (Mxdb for DG/UX and
          386/ix Systems).

















     Licensed material--property of copyright holder(s)         Page 3



Typewritten Software • bear@typewritten.org • Edmonds, WA 98026