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 / winnt / msvc / rswitch.c < prev    next >
C/C++ Source or Header  |  2000-08-17  |  1KB  |  69 lines

  1. /*
  2.  * Coswitch for NT using Visual C++.
  3.  *
  4.  * Written by Frank J. Lhota, based on an assembly version
  5.  * authored by Robert Goldberg and modified for OS/2 2.0 by Mark
  6.  * Emmer.
  7.  */
  8.  
  9. #include "../h/rt.h"
  10.  
  11. /*
  12.  * The NT co-expression context consists of 5 words. The
  13.  * following constants define the byte offsets for each of the
  14.  * registers stored in the context.
  15.  */
  16.  
  17. #define SP_OFF  0
  18. #define BP_OFF  4
  19. #define SI_OFF  8
  20. #define DI_OFF 12
  21. #define BX_OFF 16
  22.  
  23. int    coswitch(old, new, first)
  24. word    *old;
  25. word    *new;
  26. int    first;
  27. {
  28.  
  29.    /* Save current context to *old */
  30.    __asm {
  31.       mov    eax, old
  32.       mov    SP_OFF [ eax ], esp
  33.       mov    BP_OFF [ eax ], ebp
  34.       mov       SI_OFF [ eax ], esi
  35.       mov    DI_OFF [ eax ], edi
  36.       mov    BX_OFF [ eax ], ebx
  37.       }
  38.  
  39.    if ( first )
  40.       /* first != 0 => restore context in *new. */
  41.       __asm {
  42.      mov    eax, new
  43.      mov    esp, SP_OFF [ eax ]
  44.      mov    ebp, BP_OFF [ eax ]
  45.      mov    esi, SI_OFF [ eax ]
  46.      mov    edi, DI_OFF [ eax ]
  47.      mov    ebx, BX_OFF [ eax ]
  48.      }
  49.    else
  50.       {
  51.       /*
  52.        * first == 0 => Set things up for first activation of this
  53.        *           coexpression. Load stack pointer from first
  54.        *           word of *new and call new_context, which
  55.        *           should never return.
  56.        */
  57.       __asm {
  58.      mov    eax, new
  59.      mov    esp, SP_OFF [ eax ]
  60.      mov    ebp, esp
  61.      }
  62.       new_context( 0, NULL );
  63.       syserr( "interp() returned in coswitch" );
  64.       }
  65.  
  66.    return 0;
  67. }
  68.  
  69.