Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
From: Christoph Zens <e9126506@student.tuwien.ac.at>
Subject: Re: Unaligned traps...
Date: 17 Oct 97 12:24:12 +0100	[thread overview]
Message-ID: <48f5733d46f1cab95f848c587ecb6e55.axp-list@archive.invalid> (raw)
In-Reply-To: <v03020900b06c3a5771bd@[207.26.68.23]>

>However I also get
>Oct 16 05:43:30 where kernel: netstat(15228): unaligned trap at
>0000000000000029: 000000011ffff88c 2d 10

>Perhaps show a before and after of the kind of error (like is there a
>sample program that will cause these errors and then the solution program?)

If your program defines something like:

long *foo;
char bar[32];

and then attempts to do this:

foo = (long *)&bar[3];
*foo = 1234;

then you will get an unaligned trap at runtime. In a nutshell:
You should not try to do longword accesses at an odd memory address.
The best (and safest) way is to align every access on a byte-address
that is an integral multiple of the byte-size that you deal with.
For the above example, this leads to:

foo = (long *)&bar[4];
*foo = 1234;

on x86-based machines ("long" is four bytes in length), BUT:

foo = (long *)&bar[8];
*foo = 1234;

for alpha-based maschines, where "long" consists of eight bytes.

Perhaps you want to change some variable declarations within your code
from "long" to "int", as "int" on the alpha is four bytes long and
thus, could eventually remove your unaligned trap.

Another frequently seen thing at compile time is:
"warning: casting pointer to integer of different size"

Every program, that makes the assumption that an "integer" is the same size
as a pointer, runs into such problems on an alpha. Things to watch out for:

int foo;
something *bar;

foo = (int)bar;

To correct this, you will have to use "long" to declare "foo" and cast the
pointer to long which has the same size as the pointer itself (eight bytes).

hope that helps.

--
    _
 _ //
 \X/  Christoph Zens <e9126506@student.tuwien.ac.at>

Hofstaeter's law: It takes always longer than you think,
                  even if you take into account Hofstaeter's law.

--
To unsubscribe: send e-mail to axp-list-request@redhat.com with
'unsubscribe' as the subject.  Do not send it to axp-list@redhat.com

  reply	other threads:[~1997-10-17 11:24 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-10-16 21:48 Unaligned traps David Goldstein
1997-10-17 11:24 ` Christoph Zens [this message]
  -- strict thread matches above, loose matches on Subject: below --
1999-11-17  7:34 unaligned traps Jamesvi
1996-03-11 21:29 J.K. Perquin
     [not found] <Pine.LNX.3.91.960311101611.26110E-100000@redhat.com>
1996-03-11 20:33 ` Matthew Geier
     [not found] <m0tw42h-0007dpC@dingo.theplanet.co.uk>
1996-03-11 15:17 ` Erik Troan
1996-03-11  9:37 Nigel Metheringham
     [not found] <1.5.4b11.32.19960311001147.00685764@mail.bnc.nl>
1996-03-11  1:19 ` Erik Troan
1996-03-11  0:11 J.K. Perquin
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox