[comp.lang.icon] Icon context switch for the Sun4

ralph@CS.ARIZONA.EDU ("Ralph Griswold") (07/04/90)

An Icon co-expression context switch for the Sun4 folllows. If you use it
and encounter any problems, please let the Icon project know.

This context switch was written by Phil Kaslo of our laboratory staff, with
initial assistance from Dave Bakken.

+++++++++++CUT HERE+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

/*
 * rswitch.c for Sun-4 Sparc.
 * 
 * Compile this with 'cc -c rswitch.c'.  Do not use cc -O.
 */

#include <sun4/asm_linkage.h>
#include <sun4/trap.h>

int coswitch(old_cs, new_cs, first)
int *old_cs, *new_cs;
int first;
{
   asm("ta	0x03");			/* ST_FLUSH_WINDOWS in trap.h     */
   asm("ld	[%fp+0x44], %o0");	/* load old_cs into %o0	          */
   asm("st	%sp,[%o0]");		/* Save user stack pointer        */
   asm("st	%fp,[%o0+0x4]");	/* Save frame pointer             */
   asm("st	%i7,[%o0+0x8]");	/* Save return address            */

   if (first == 0) {			/* this is the first activation   */
      asm("ld	[%fp+0x48], %o0");	/* load new_cs into %o0           */
      asm("ld	[%o0], %o1");		/* load %o1 from cstate[0]        */

      /* Decrement new stack pointer value before loading it into sp.	  */
      /* The top 64 bytes of the stack are reserved for the kernel, to    */
      /* save the 8 local and 8 in registers into, on context switches,   */
      /* interrupts, traps, etc.					  */

      asm("dec  96,%o1");		
      asm("mov  %o1, %sp");		/* load %sp from %o1	          */
      interp(0,0);
      syserr("interp() returned in coswitch");

   } else {
      asm("ld	[%fp+0x48], %o0");	/* load new_cs into %o0           */
      asm("ld	[%o0+0x4],%fp");	/* Load frame pointer             */
      asm("ld	[%o0+0x8],%i7");	/* Load return address            */
      asm("ld	[%o0],%sp");		/* Load user stack pointer        */
   }
}

+++++++++++CUT HERE+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

  Ralph Griswold / Dept of Computer Science / Univ of Arizona / Tucson, AZ 85721
  +1 602 621 6609   ralph@cs.arizona.edu  uunet!arizona!ralph