home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / icon / dos / src / config / msdos / codebldr / rswitch.asm < prev    next >
Encoding:
Assembly Source File  |  1991-10-21  |  2.9 KB  |  103 lines

  1. ;
  2. ;   Coswitch for Icon V8.5 running in 32-bit protected mode
  3. ;   with MetaWare High C 386 (PharLap DOS|Extender) or Intel 386/486
  4. ;   C Code Builder Kit.
  5. ;
  6. ;   Author:  Robert Goldberg
  7. ;
  8. ;   Note: Assemble with PharLap assembler and -twocase switch to
  9. ;   preserve lower-case public names (important for Intel linker).
  10. ;
  11. ;   Coswitch algorithm in C:
  12. ;
  13. ;   coswitch( old_cs, new_cs, first )
  14. ;   int    *old_cs, *new_cs, first;
  15. ;   {
  16. ;    /* save SP, frame pointers, and other registers in old_cs */
  17. ;    if ( first == 0 )
  18. ;    {
  19. ;        /* load sp from new_sp[0] and clear frame pointers */
  20. ;        new_context( 0, 0 );
  21. ;        syserr( "new_context() returned in coswitch" );
  22. ;    }
  23. ;    else
  24. ;    {
  25. ;        /* load sp, frame pointers and other registers from new_cs */
  26. ;    }
  27. ;   }
  28. ;
  29. ;   Define external functions:
  30. ;
  31.     extrn    new_context:near
  32.     extrn    syserr:near
  33. ;
  34. ;   Define error message in appropriate segment and group.
  35. ;
  36. dgroup    group    asmdata
  37.     assume    ds:dgroup
  38.     public    errormsg
  39. asmdata    segment    dword public 'DATA'
  40. errormsg db    'new_context() returned in coswitch',0
  41. asmdata    ends
  42. ;
  43. ;   Define function coswitch in appropriate segment and group.
  44. ;
  45. cgroup    group    asmcode
  46.     assume    cs:cgroup
  47. asmcode    segment    dword 'CODE'
  48.     public    coswitch
  49.     db    'coswitch',8
  50. coswitch    proc    near
  51. ;
  52. ;   Save environment at point of call.
  53. ;
  54. ;   According to MetaWare's documentation (Chapter 9 - Run-Time Organization)
  55. ;   registers EAX, ECX, EDX, FS, GS, and sometimes ES are volatile.  So, a
  56. ;   function must preserve registers EBP, ESI, EDI, and EBX across calls.
  57. ;   So, save all these registers plus ESP in area pointed to by old_cs.
  58. ;
  59.     mov    edx,4[esp]        ; point to old_cs
  60.     mov    0[edx],esp        ; save esp
  61.     mov    4[edx],ebp        ; save ebp
  62.     mov    8[edx],esi        ; save esi
  63.     mov    12[edx],edi        ; save edi
  64.     mov    16[edx],ebx        ; save ebx
  65. ;
  66. ;   Check first flag to see if first activation of this coexpression.
  67. ;
  68.     mov    eax,12[esp]        ; load first flag
  69.     or    eax,eax            ; set condition flags
  70.     jnz    notzero            ; jump if not zero
  71. ;
  72. ;   First is 0 -
  73. ;
  74. ;   Set things up for first activation of this coexpression.
  75. ;
  76.     mov    edx,8[esp]        ; point to new_cs area
  77.     mov    esp,0[edx]        ; set ESP from new_cs
  78.     mov    ebp,esp            ; set EBP equal to ESP (can't hurt?)
  79.     xor    eax,eax            ; get a zero
  80.     mov    esi,eax            ; clear ESI
  81.     mov    edi,eax            ; clear EDI
  82.     push    eax            ; push two zeros
  83.     push    eax            ;   onto stack
  84.     call    new_context        ; new_context(0,0) - should not return!
  85.     push    offset errormsg        ; push offset to error messgae
  86.     call    syserr            ; terminate with error
  87. ;
  88. ;   First is not 0 -
  89. ;
  90. ;   Restore environment from new_cs.
  91. ;
  92. notzero:
  93.     mov    edx,8[esp]        ; point to new_cs
  94.     mov    esp,0[edx]        ; restore esp
  95.     mov    ebp,4[edx]        ; restore ebp
  96.     mov    esi,8[edx]        ; restore esi
  97.     mov    edi,12[edx]        ; restore edi
  98.     mov    ebx,16[edx]        ; restore ebx
  99.     ret                ; return
  100. coswitch    endp
  101. asmcode    ends
  102.     end
  103.