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