home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v941.tgz / icon.v941src.tar / icon.v941src / config / unix / sun_sunc / rswitch.c < prev    next >
C/C++ Source or Header  |  2001-05-23  |  1KB  |  38 lines

  1. /*
  2.  * coswitch for Sun-4 Sparc.
  3.  */
  4.  
  5. #include <sys/asm_linkage.h>
  6. #include <sys/trap.h>
  7.  
  8. int coswitch(old_cs, new_cs, first)
  9. int *old_cs, *new_cs;
  10. int first;
  11. {
  12.    asm("ta    0x03");            /* ST_FLUSH_WINDOWS in trap.h     */
  13.    asm("ld    [%fp+0x44], %o0");    /* load old_cs into %o0              */
  14.    asm("st    %sp,[%o0]");        /* Save user stack pointer        */
  15.    asm("st    %fp,[%o0+0x4]");    /* Save frame pointer             */
  16.    asm("st    %i7,[%o0+0x8]");    /* Save return address            */
  17.  
  18.    if (first == 0) {            /* this is the first activation   */
  19.       asm("ld    [%fp+0x48], %o0");    /* load new_cs into %o0           */
  20.       asm("ld    [%o0], %o1");        /* load %o1 from cstate[0]        */
  21.  
  22.       /* Decrement new stack pointer value before loading it into sp.      */
  23.       /* The top 64 bytes of the stack are reserved for the kernel, to    */
  24.       /* save the 8 local and 8 in registers into, on context switches,   */
  25.       /* interrupts, traps, etc.                      */
  26.  
  27.       asm("save  %o1,-96, %sp");    /* load %sp from %o1              */
  28.       new_context(0,0);
  29.       syserr("new_context() returned in coswitch");
  30.  
  31.    } else {
  32.       asm("ld    [%fp+0x48], %o0");    /* load new_cs into %o0           */
  33.       asm("ld    [%o0+0x4],%fp");    /* Load frame pointer             */
  34.       asm("ld    [%o0+0x8],%i7");    /* Load return address            */
  35.       asm("ld    [%o0],%sp");        /* Load user stack pointer        */
  36.    }
  37. }
  38.