home *** CD-ROM | disk | FTP | other *** search
- !
- ! Rules for building continuations on the SPARC:
- !
- ! 1 - register windows must be flushed to memory before
- ! the stack is copied to the heap.
- !
- ! 2 - setjmp must save the caller's local and input register
- ! frames when saving context, because longjmp will not
- ! have access to the saved stack to fetch the registers
- ! from their normal resting place.
- !
- ! 3 - longjmp must flush register windows so the correct register
- ! values will be reloaded from memory when execution continues
- ! on the restored stack.
- !
- ! 4 - longjmp must restore the caller's local and input register
- ! frames because the stack hasn't been restored when longjmp
- ! is called.
- !
-
-
- !
- ! This misnamed function is responsible for providing the
- ! top of stack address, via macro STACKPTR, to the continuation
- ! builder and the heap manager. Because both of these functions
- ! immediately begin examining the memory on the stack, the register
- ! windows are flushed to memory so their values will be saved in
- ! heap allocated continuations and seen by the garbage collector.
- !
- .global _sc_processor_register
- _sc_processor_register:
- ta 3 ! flush register windows
- jmp %o7+8 ! return
- add %sp, 0, %o0 ! return stack pointer
-
- !
- ! Save the current environment in a heap allocated continuation.
- !
- .global _sc_setjmp
- _sc_setjmp:
- st %o6, [%o0 + 0] ! save stack pointer
- st %o7, [%o0 + 4] ! save continuation pointer
- st %g1, [%o0 + 8] ! save global registers
- st %g2, [%o0 + 12] ! these may be allocated for
- st %g3, [%o0 + 16] ! caller saves registers or
- st %g4, [%o0 + 20] ! for global values.
- st %g5, [%o0 + 24]
- st %g6, [%o0 + 28]
- st %g7, [%o0 + 32]
- st %l0, [%o0 + 36] ! save local registers
- st %l1, [%o0 + 40] ! the sunos setjmp uses
- st %l2, [%o0 + 44] ! the register windows to
- st %l3, [%o0 + 48] ! save these, we can't.
- st %l4, [%o0 + 52]
- st %l5, [%o0 + 56]
- st %l6, [%o0 + 60]
- st %l7, [%o0 + 64]
- st %i0, [%o0 + 68]
- st %i1, [%o0 + 72]
- st %i2, [%o0 + 76]
- st %i3, [%o0 + 80]
- st %i4, [%o0 + 84]
- st %i5, [%o0 + 88]
- st %i6, [%o0 + 92]
- st %i7, [%o0 + 96]
- mov %y, %o2 ! fetch %y, whatever it is
- st %o2, [%o0 + 100] ! and save it
- jmp %o7+8 ! return
- add %g0, %g0, %o0 ! return 0
-
- !
- ! Restore an environment from a heap allocated continuation.
- !
- .global _sc_longjmp
- _sc_longjmp:
- ta 3 ! flush register windows
- ld [%o0 + 0], %o6 ! restore stack pointer
- ld [%o0 + 4], %o7 ! load continuation pointer
- ld [%o0 + 8], %g1 ! restore global registers
- ld [%o0 + 12], %g2
- ld [%o0 + 16], %g3
- ld [%o0 + 20], %g4
- ld [%o0 + 24], %g5
- ld [%o0 + 28], %g6
- ld [%o0 + 32], %g7
- ld [%o0 + 36], %l0 ! restore local frame from stack
- ld [%o0 + 40], %l1
- ld [%o0 + 44], %l2
- ld [%o0 + 48], %l3
- ld [%o0 + 52], %l4
- ld [%o0 + 56], %l5
- ld [%o0 + 60], %l6
- ld [%o0 + 64], %l7
- ld [%o0 + 68], %i0
- ld [%o0 + 72], %i1
- ld [%o0 + 76], %i2
- ld [%o0 + 80], %i3
- ld [%o0 + 84], %i4
- ld [%o0 + 88], %i5
- ld [%o0 + 92], %i6
- ld [%o0 + 96], %i7
- ld [%o0 + 100], %o2 ! restore %y, whatever it is
- mov %o2, %y
- jmp %o7+8 ! return
- add %o1, %g0, %o0 ! return arg
-
-