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.asm < prev    next >
Assembly Source File  |  2000-08-17  |  3KB  |  122 lines

  1.     page    80,132
  2. ;
  3. ;   Coswitch for Icon V8 interpreter running in 32 bit protected mode
  4. ;   under OS/2 2.0, compiled with OptLink (the C Set/2 default).
  5. ;
  6. ;   Author:  Robert Goldberg
  7. ;
  8. ;   Modified for OS/2 2.0: Mark Emmer
  9. ;
  10. ;   Note:  Must assemble with /Ml switch to preserve case of names!
  11. ;
  12. ;   Coswitch algorithm in C:
  13. ;
  14. ;   coswitch( old_cs, new_cs, first )
  15. ;   int    *old_cs, *new_cs, first;
  16. ;   {
  17. ;    /* save SP, frame pointers, and other registers in old_cs */
  18. ;    if ( first == 0 )
  19. ;    {
  20. ;        /* load sp from new_sp[0] and clear frame pointers */
  21. ;        interp( 0, 0 );
  22. ;        syserr( "interp() returned in coswitch" );
  23. ;    }
  24. ;    else
  25. ;    {
  26. ;        /* load sp, frame pointers and other registers from new_cs */
  27. ;    }
  28. ;   }
  29. ;
  30. ;   Define external functions:
  31. ;
  32.         .386
  33.         extrn        _new_context:near
  34.         extrn        _syserr:near
  35. ;
  36. ;   Define error message in appropriate segment.
  37. ;
  38.         assume        CS:FLAT, DS:FLAT
  39.         public        errormsg
  40. DATA32        segment        dword use32 'DATA'
  41. errormsg    db        'interp() returned in coswitch',0
  42. DATA32        ends
  43. ;
  44. ;   Define function coswitch in appropriate segment and group.
  45. ;
  46. CODE32        segment        dword use32 'CODE'
  47.         public        _coswitch
  48. _coswitch     proc           near
  49. ;
  50. ;   Save environment at point of call.
  51. ;
  52. ;   According to C Set/2 documentation (Chapter 16 - Calling Conventions)
  53. ;   registers EAX, ECX, and EDX are volatile, and EBP, ESI, EDI, and EBX
  54. ;   must be preserved across calls.  So, save all these registers plus ESP
  55. ;   in area pointed to by old_cs.
  56. ;
  57. ;   coswitch prototype:  int coswitch(int *old, int *new, int first);
  58. ;
  59. ;   With optlink calling conventions, the three arguments are passed
  60. ;   in registers EAX, EDX, and ECX respectively.  There are slots for
  61. ;   them on the stack, but they have not been pushed there:
  62. ;
  63. ;   At function entry:
  64. ;
  65. ;                    +----------------+
  66. ;      high mem      | slot for first |
  67. ;                    +----------------+
  68. ;                    | slot for *new  |
  69. ;                    +----------------+
  70. ;                    | slot for *old  |
  71. ;                    +----------------+
  72. ;      low mem       |   return EIP   | <-- ESP
  73. ;                    +----------------+
  74. ;
  75. ; Code not needed because of Optlink commented out here:
  76. ;
  77.     mov    eax,[esp+4]
  78.     mov    edx,[esp+8]
  79.     mov    ecx,[esp+12]
  80. ;
  81. ; Remaining code written to work with or without Optlink:
  82.  
  83.     mov    0[eax],esp        ; save esp in old save area
  84.     mov    4[eax],ebp        ; save ebp
  85.     mov    8[eax],esi        ; save esi
  86.     mov    12[eax],edi        ; save edi
  87.     mov    16[eax],ebx        ; save ebx
  88. ;
  89. ;   Check first flag to see if first activation of this coexpression.
  90. ;
  91.     jecxz    iszero            ; jump if zero
  92. ;
  93. ;   First is not 0 -
  94. ;
  95. ;   Restore environment from new_cs.
  96. ;
  97.     mov    esp,0[edx]        ; restore esp
  98.     mov    ebp,4[edx]        ; restore ebp
  99.     mov    esi,8[edx]        ; restore esi
  100.     mov    edi,12[edx]        ; restore edi
  101.     mov    ebx,16[edx]        ; restore ebx
  102.     ret                ; return
  103. ;
  104. ;   First is 0 -
  105. ;
  106. ;   Set things up for first activation of this coexpression.
  107. ;
  108. iszero:    mov    esp,0[edx]        ; set ESP from new_cs
  109.     mov    ebp,esp        ; set EBP equal to ESP (can't hurt?)
  110.     xor    eax,eax        ; get a zero for first arg to interp
  111.     xor    edx,edx        ;  "      "   "  second arg to interp
  112.     push    edx            ; create stack slots
  113.     push    eax
  114.     call    _new_context        ; interp(0,0) - should not return!
  115.     add    esp,8
  116.     lea    eax,errormsg        ; pass offset to error message in EAX
  117.     push    eax            ; create stack slot
  118.     call    _syserr            ; terminate with error
  119. _coswitch    endp
  120. CODE32        ends
  121.         end
  122.