home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 25 / nopv25.iso / 040A / CCDL151L.ZIP / STARTUP / 386 / STARTUP.ASM
Encoding:
Assembly Source File  |  1997-02-27  |  2.5 KB  |  129 lines

  1.     .386
  2.  
  3. ;
  4. ; Section inits
  5. ;
  6. _TEXT            SEGMENT DWORD PUBLIC USE32 'CODE'
  7.     extrn    __argv_arr,__argc,__env_arr,__cmdline
  8.     extrn    _main:PROC
  9.     public  __rexit
  10.         ENDS
  11. cstartup        SEGMENT DWORD PUBLIC USE32 'INITDATA'
  12. InitStart       label dword
  13.                 ENDS
  14. _STARTUPEND_       SEGMENT DWORD PUBLIC USE32 'INITDATA'
  15. InitEnd         label dword
  16.                 ENDS
  17. crundown        SEGMENT DWORD PUBLIC USE32 'EXITDATA'
  18. ExitStart       label dword
  19.                 ENDS
  20. _RUNDOWNEND_       SEGMENT DWORD PUBLIC USE32 'EXITDATA'
  21. ExitEnd         label dword
  22.                 ENDS
  23. _CPP_           SEGMENT DWORD PUBLIC USE32 'CPPDATA'
  24. CppStart        label dword
  25.         dd    cpproutine
  26.                 ENDS
  27. _CPPEND_        SEGMENT DWORD PUBLIC USE32 'CPPDATA'
  28. CppEnd          label dword
  29.         ENDS
  30. _DATA       SEGMENT DWORD PUBLIC USE32 'DATA'
  31.         db    "Copyright (c) 1996 LADsoft C runtime library (i386)"
  32. dcml        db    0
  33.                 ENDS
  34. _BSS            SEGMENT DWORD PUBLIC USE32 'BSS'
  35. BssStart    label dword
  36.                 ENDS
  37. _BSSEND            SEGMENT DWORD PUBLIC USE32 'BSS'
  38. BssEnd        label dword
  39.                 ENDS
  40.  
  41. DGROUP group cstartup,_STARTUPEND_,crundown,_RUNDOWNEND_,_CPP_,_CPPEND_,_DATA,_BSS,_BSSEND
  42. _TEXT        SEGMENT
  43.         assume cs:_TEXT,ds:DGROUP
  44. ;
  45. ; Main program
  46. ;
  47. start:
  48. ;
  49. ; Assumes ESP is set
  50. ;
  51. ; Set up dummy command line
  52. ;
  53.         mov    DWORD PTR [__cmdline],offset dcml
  54. ;
  55. ; Clear BSS
  56. ;
  57.         mov    edi,offset BssStart
  58.         mov    ecx,offset BssEnd
  59.         sub    ecx,edi
  60.         sub    eax,eax
  61.         cld
  62.         rep    stosb
  63. ;
  64. ; Execute startup routines
  65. ;
  66.         mov    ecx,offset InitStart
  67.         mov    edx,offset InitEnd
  68.         call    sexproc
  69. ;
  70. ; Call main
  71. ;
  72.         push    __env_arr
  73.         push    __argv_arr
  74.         push    __argc
  75.         call    _main
  76.         add    esp,12
  77. ;
  78. ; exit/abort comes here
  79. ;
  80. __rexit:
  81. ;
  82. ; Execute rundown routines
  83. ;
  84.         push    eax
  85.         mov    ecx,offset ExitStart
  86.         mov    edx,offset ExitEnd
  87.         call    sexproc
  88.         pop    eax
  89.         ret            ; exit to os
  90. ;
  91. ; Handle startup/rundown routines
  92. ;
  93. sexproc:
  94.         cmp    ecx,edx        
  95.         jz    short sexpdone    
  96.         mov    edi,ecx
  97.         sub    ebx,ebx
  98.         sub    eax,eax
  99. spl2:
  100.         cmp    edi,edx
  101.         jz    short spo
  102.         test    dword ptr [edi+4],-1
  103.         jz    short spl3
  104.         cmp    eax,[edi+4]
  105.         jnc    short spl3
  106.         mov    ebx,edi
  107.         mov    eax,[edi+4]
  108. spl3:
  109.         add    edi,8
  110.         jmp    spl2
  111. spo:
  112.         or    ebx,ebx
  113.         jz    short sexpdone
  114.         mov    dword ptr [ebx+4],0
  115.         mov    ebx,[ebx]
  116.         push    edx
  117.         push    ecx
  118.         call    ebx
  119.         pop    ecx
  120.         pop    edx
  121.         jmp    sexproc
  122. sexpdone:
  123.         ret
  124.  
  125. ; This is called as the first thing from the C++ main routine
  126. cpproutine:
  127.         ret
  128. _TEXT        ends
  129.         end