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_gcc / rswitch.c < prev    next >
C/C++ Source or Header  |  2001-05-23  |  1KB  |  40 lines

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