home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR13 / OS2ASM.ZIP / CINIT.ASM < prev    next >
Assembly Source File  |  1991-08-10  |  3KB  |  134 lines

  1. ;_ cinit.asm   June 20, 1990  Modified by: Joe Huffman
  2. ; Copyright (C) 1985-1990 by Walter Bright
  3. ; All rights reserved.
  4. ; Written by Joe Huffman
  5. ; C initialization for Phar Lap DOS386 and SCO UNIX System V version 3.2.0
  6.  
  7. ;define DOS386 for Phar Lap, default is SCOUNIX
  8.  
  9. include macros.asm
  10. include flthead.asm
  11.  
  12.     extrn _write:near
  13.  
  14.     public    __doserrno,__osmode,_errno,__dodtors
  15.         public  __argc,__argv,__cinit,__envptr
  16.     public    __8087
  17.  
  18.     begdata
  19.  
  20. ifdef DOS386
  21.     public __psp,__osmajor,__dos,__osminor,__DOS386_version,__DOS386_environ
  22.  
  23. __psp         dw    SEG_PSP ;segment of program segment prefix
  24. __osmajor label     byte        ;MSC compatibility
  25. __dos         db    ?    ;MS-DOS major version number
  26. __osminor label     byte        ;MSC compatibility
  27.          db    ?    ;MS_DOS minor version number
  28. __DOS386_version dd    ?
  29. __DOS386_environ dd    ?
  30. else
  31.     public __environ
  32. __environ    dd    ?    ;Pointer to the environment (char *_environ[]).
  33. endif
  34.  
  35. __8087        dd    0
  36. __envptr    dd    ?    ;Pointer to the environment (char *_envptr).
  37.  
  38. ;Globals for argc and argv, so they are accessible and modifiable by
  39. ;static constructors.
  40. __argc        dd    ?    ;number of args
  41. __argv        dd    ?    ;filled in by C.ASM
  42. __osmode    db    1    ;= 1 if in protected mode
  43.  
  44. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  45. ;The layout of this must match struct THREAD,
  46. ;as it is the thread 1 data
  47.  
  48.         public    __thread1
  49. __thread1    label    word
  50.         dd    0
  51. ;        dw    0
  52.         dd    0
  53. ;__oserr    label    word        ;Lattice C compatibility
  54. __doserrno    label    word        ;DOS error number (for compatibility
  55.                     ; with MSC). It is the same as errno.
  56. _errno        dd    0        ;global error number
  57.  
  58.     ifdef _MT
  59.     if SPTR
  60.         dd    0        ;t_strtok
  61.     else
  62.         df    0        ;t_strtok
  63.     endif
  64.         dd    9 dup (0)    ;t_tm
  65.     endif
  66.  
  67.     public    __fe_cur_env
  68. __fe_cur_env    fenv_t    <>        ;current floating point environment
  69.  
  70.     ifdef _MT
  71.         db    26 dup (0)    ;t_asctime
  72.         db    32 dup (0)    ;t_digstr
  73.     endif
  74.  
  75. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  76.  
  77.     public    _FE_DFL_ENV
  78. _FE_DFL_ENV    fenv_t    <>        ;default floating point environment
  79.  
  80.     enddata
  81.  
  82.     begcode cinit
  83.  
  84. __cinit proc    near
  85.     call    doctors        ;perform static constructors
  86.     ret
  87. __cinit endp
  88.  
  89. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  90. ; Perform static constructors
  91. ; Go backwards through the list, so we do what was linked in last, first.
  92.  
  93. doctors proc    near
  94.     uses    <ECX,EDI>
  95.  
  96.     ;Call ctors
  97.     mov    EDI,offset DGROUP:XIE
  98. CT1:    _ifs    EDI be <offset DGROUP:XIB>,CT2
  99.       sub      EDI,SIZEPTR
  100.       mov      ECX,[EDI]
  101.       jecxz      short CT1      ;skip null pointers
  102.       call      ECX
  103.       jmps      CT1
  104.  
  105. CT2:
  106.     unuse    <EDI,ECX>
  107.     ret
  108. doctors endp
  109.  
  110. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  111. ; Perform static destructors
  112. ; Go in the reverse order that the constructors were called.
  113.  
  114. __dodtors    proc    near
  115.     uses    <ecx,edi>
  116.     ;Call near dtors
  117.     mov    edi,offset DGROUP:XCB
  118. DT1:    _if    edi ae <offset DGROUP:XCE>,DT2
  119.     mov    ecx,[edi]
  120.     jecxz    short DT1    ;skip null pointers
  121.     call    ecx
  122.     add    edi,4
  123.     jmps    DT1
  124.  
  125. DT2:    unuse    <edi,ecx>
  126.     ret
  127.  
  128. __dodtors    endp
  129.  
  130.     endcode cinit
  131.  
  132.     end
  133.  
  134.