Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ unaligned(3) — OSF/1 X2.0-8 MIPS

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

dbx(1)

sysmips(2)

sigset(2)

unaligned(3)  —  Subroutines

Digital

NAME

handle_unaligned_traps, print_unaligned_summary − gather statistics on unaligned references

SYNOPSIS

void handle_unaligned_traps()

void print_unaligned_summary()

long unaligned_load_word(addr)
char ∗addr;

long unaligned_load_half(addr)
char ∗addr;

long unaligned_load_uhalf(addr)
char ∗addr;

float unaligned_load_float(addr)
char ∗addr;

double unaligned_load_double(addr)
char ∗addr;

void unaligned_store_word(addr, value)
char ∗addr;
long value;

void unaligned_store_half(addr, value)
char ∗addr;
long value;

void unaligned_store_float(addr, float value)
char ∗addr;
float value;

void unaligned_store_double(addr, value)
char ∗addr;
double value;

DESCRIPTION

The first two routines implement a facility for finding unaligned references.  The MIPS hardware traps load and store operations where the address is not a multiple of the number of bytes loaded or stored.  Usually this trap indicates incorrect program operation and so by default the kernel converts this trap into a SIGBUS signal to the process, typically causing a core dump for debugging. 

Older programs developed on systems with lax alignment constraints sometimes make occasional misaligned references in course of correct operation.  The best way to port such programs to MIPS hardware is to correct the program by aligning the data. 

A call to handle_unaligned_traps installs a SIGBUS handler that fixes unaligned memory references and keeps a record of the types, counts, and instruction addresses of these traps.  A call to print_unaligned_summary prints the accumulated information.  The following is an example of the output produced by print_unaligned_summary:

###############################
#     unaligned reference summary#
# byte aligned lw     5000 33.3%#
# byte aligned sw    10000 66.7%#
# 0x0040024c/i      5000 33.3% 33.3%#
# 0x004002a8/i      5000 33.3% 66.7%#
# 0x004002b4/i      5000 33.3% 100.0%#
###############################

The listing is written to standard error and describes the type and number of unaligned references, followed by a list of every address that contains an unaligned reference.  To convert the addresses into a dbx(1) script and run the script, pipe the output (both standard output and standard error) through the following command.  The output from dbx will be the name of the function and line number of the misalignment. 

sed -n -e ’s;^ # [0-9a-f]∗/i).∗#$;1;p’ | dbx prog

This information can be used to decide the best way to correct the problem.  If not all of the data can be aligned, or not all of the identified program locations that reference unaligned data can be changed, the sysmips(2) [MIPS_FIXADE] system call may be appropriate. 

The other routines load or store their indicated data type at the address specified.  The address need not meet the normal alignment constraints. 

There exist fortran entry points for these routines so they may be called directly from fortran with the names documented here. 

ERRORS

If these routines try to load or store to an address that is outside the program’s address space a SIGSEGV signal will be generated from inside these routines.  If the program did not use these routines and the address was unaligned then the program would generate a SIGBUS signal.  This is because the check for alignment is done before the address is checked to be in the program’s address space. 

RELATED INFORMATION

dbx(1), sysmips(2) [MIPS_FIXADE], signal(2), sigset(2). 

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