It is currently Sat, 04 Feb 2023 12:50:57 GMT

Author Message
 Signal handler for unaligned access: emulate and continue?

I'm running Sun OS 4.1.3 on a Sparc/20, and I'd like to write a signal
handler to fixup an unaligned load by storing a magic value into the
destination register and continue executing after the load.  For

    ld  [%o1-1],%o2

At this point, if %o1-1 is odd, I'll get an unaligned access fault,
and I'd like to fix it up by storing a special value in %o2 and
continuing (note that it's not always these specific registers: I'd
like to look at the destination register field in the instruction to
figure out what register to patch).  Basically, I'd like to get the
effect of the following code:

    andcc %o1,1,%g0                     ; Test low bit
    bne   L1
    sethi %hi(magic_value),%o2          ; delay slot
    b     L2
    or    %o2,%lo(magic_value),%o2      ; delay slot
    ld    [%o1-1],%o2

However, I know that %o1 having the low bit clear is extremely
unlikely, and I'd like to optimize for the common case by going ahead
and executing the load and fixing things up if it turns out that %o1-1
was indeed odd.

I've been poking around /usr/include{/sys,/}signal.h, and I can't seem
to figure out a few things:

1) How can I specify that I'd like %o2 to be restored to a particular
value?  I've looked in scp->sc_wbuf, but these values don't seem to
have any relation to the register values at the time of the fault.
There's a field called 'sc_o0', but changing this value in my signal
handler doesn't seem to affect the value of %o0 that gets restored
when execution resumes, and in any case doesn't address the problem of
restoring values other than %o0.  Any hints would be appreciated.

2) What's the best way to get execution to resume at the instruction
following the load (rather than re-executing the load instruction)?
Should I just do:

  scp->sc_pc += sizeof(void*);

To skip to the next instruction?  This seems to work, but there might
be a better way.

(In case you're wondering, this is for implementing a
dynamically-typed language where integers are tagged with 0's in their
low bit, and other values are pointers with their low bit tagged as
1's: I'm trying to extract a class identifier stored in the first word
of most objects, and the 'magic_value' is the value I want to use for

Thanks for any help you can offer.  Code samples of how to domsething
similar would be especially useful.  Please reply via e-mail and I'll
post a summary.

-- Jeff

Jeffrey Dean (         Graduate Student, Cecil Project
Dept. of Computer Science & Engineering               University of Washington

 Sun, 16 Nov 1997 03:00:00 GMT   
   [ 1 post ] 

Similar Threads

1. Signal handler for unaligned access: emulate and continue?

2. Signal handlers inside signal handlers

3. accessing state from signal handler

4. sig_atomic_t: from signal handler: set or access?

5. Linux signal() semantics - can BSD signal() be emulated?

6. Threads performance - allow signal handler to not call handler

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software