home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 25 / nopv25.iso / 040A / CCDL151L.ZIP / MSDOS / 386 / C0DOSW.ASM < prev    next >
Encoding:
Assembly Source File  |  1997-06-16  |  5.8 KB  |  269 lines

  1. ;
  2. ;    tasm /ml/m4/zi c1dos.asm
  3. ;
  4. MASM
  5. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  6. ;
  7. ; PMODE/W Assembly Startup for CC386.EXE (c) Kirill Jo$$ :-)
  8. ;
  9. ;
  10. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  11. .386p
  12.  
  13. STACK_SIZE = 40*1024h    ; Stack size
  14.  
  15. ;    This is equ copy from C0DOS.ASM :-)
  16.  
  17. _TEXT        segment para public use32 'CODE'
  18.     extrn    __argv_arr:DWORD,__argc:DWORD,__env_arr:DWORD,__cmdline:DWORD
  19.     extrn    _main:PROC, llsignal:proc, llsigdown:proc
  20. _TEXT        ends
  21. cstartup        SEGMENT DWORD PUBLIC USE32 'INITDATA'
  22. InitStart       label dword
  23.                 ENDS
  24. _STARTUPEND_       SEGMENT DWORD PUBLIC USE32 'INITDATA'
  25. InitEnd         label dword
  26.                 ENDS
  27. crundown        SEGMENT DWORD PUBLIC USE32 'EXITDATA'
  28. ExitStart       label dword
  29.                 ENDS
  30. _RUNDOWNEND_       SEGMENT DWORD PUBLIC USE32 'EXITDATA'
  31. ExitEnd         label dword
  32.                 ENDS
  33. _CPP_           SEGMENT DWORD PUBLIC USE32 'CPPDATA'
  34. CppStart        label dword
  35.         dd    cpproutine
  36.                 ENDS
  37. _CPPEND_        SEGMENT DWORD PUBLIC USE32 'CPPDATA'
  38. CppEnd          label dword
  39.         ENDS
  40. _DATA       SEGMENT DWORD PUBLIC USE32 'DATA'
  41.                 ENDS
  42. _BSS            SEGMENT DWORD PUBLIC USE32 'BSS'
  43. BssStart    label dword
  44.                 ENDS
  45. _BSSEND            SEGMENT DWORD PUBLIC USE32 'BSS'
  46. BssEnd        label dword
  47.                 ENDS
  48. _STACK        segment para stack use32 'STACK'
  49.         align 4
  50.         db  STACK_SIZE  dup(?)
  51. stack_offset    label    dword
  52.                 ENDS
  53.  
  54.  
  55. DGROUP group _TEXT, cstartup,_STARTUPEND_,crundown,_RUNDOWNEND_,_CPP_,_CPPEND_,_DATA,_BSS,_BSSEND, _STACK
  56.  
  57. public  __rexit, __transferx, __stacktop
  58. public  __pspseg, __linear, __pmodew,__rmseg
  59.  
  60.  
  61. _DATA       SEGMENT DWORD PUBLIC USE32 'DATA'
  62. banner  db 'Startup for DOS/4GW & PMODE/W (c) Kirill Joss. [',??date,']',10,13,36
  63.     db "Copyright (c) 1997 LADsoft C runtime library"
  64.     db " (i386/DOS PMODE/W)"
  65.     align 4
  66. __linear    dd    0
  67. __stacktop    dd    0
  68. stackpos    df    0
  69. __transferx    dw    0
  70. __pspseg    dw    0
  71. __pmodew    dw    0c4h
  72. __rmseg        dw    0
  73. filename    db    128 dup (0)
  74. dcml        db    128 dup (0)
  75.  
  76.  
  77.                 ENDS
  78. _TEXT        SEGMENT
  79.         assume cs:DGROUP,ds:DGROUP
  80.  
  81. start:
  82.         jmp short real_start
  83. ;
  84. ;    You can delete 'WATCOM', 
  85. ;        but it NOT work with Watcom Debbuger & DOS/4G or DOS/4GW :)
  86. ;
  87.         db 'WATCOM', 0     ; The "WATCOM" string is needed in
  88.                 ; order to run under DOS/4G and WatcomDebug.
  89.  
  90. nomemerr    db    'Not enough extended memory',10,13,36
  91.  
  92. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  93. ; CODE
  94. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  95.  
  96. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  97. ; Entry To ASM Code (_main)
  98. ; In:
  99. ;   CS - Code Selector    Base: 00000000h - Limit: 4G
  100. ;   DS - Data Selector    Base: 00000000h - Limit: 4G
  101. ;   ES - PSP Selector     Base: PSP Seg   - Limit: 100h
  102. ;   FS - ?
  103. ;   GS - ?
  104. ;   SS - Data Selector    Base: 00000000h - Limit: 4G
  105. ;   ESP -> STACK segment
  106. ;   Direction Flag - ?
  107. ;   Interrupt Flag - ?
  108. ;   All Other Registers Are Undefined!
  109. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  110. real_start:
  111.     mov    [__stacktop],esp
  112.         sti                             ; Set The Interrupt Flag
  113.         cld                             ; Clear The Direction Flag
  114.  
  115.     mov     [__pspseg], es        ; Save psp seg
  116.     
  117.     mov     eax,ds
  118.     mov    es,eax
  119.     mov     fs,eax
  120.     mov    gs,eax
  121.  
  122. ifdef COPYRIGHT            ; JOS
  123.     mov edx,offset banner
  124.     mov ah,9
  125.     int 21h
  126. endif
  127. ;
  128. ; Clear BSS
  129. ;
  130.     mov    edi,offset DGROUP:BssStart
  131.     mov    ecx,offset DGROUP:BssEnd
  132.     sub    ecx,edi
  133.     sub    eax,eax
  134.     cld
  135.     rep    stosb
  136. ;
  137. ; Initialize the signal system
  138. ;
  139.     call llsignal
  140. ;
  141. ; Set up command line for RTL
  142. ;
  143.     mov    es,[__pspseg]
  144.     mov edi,offset DGROUP:dcml
  145.     mov [__cmdline],edi
  146.     inc [__cmdline]
  147.     push ds
  148.     push ds
  149.     push es
  150.     pop ds            ; blit the command line into our mem
  151.     pop es
  152.     mov esi,80h
  153.     mov ecx,128
  154.     rep movsb
  155.     pop ds
  156.                 ; turn into C string form
  157.     sub ebx,ebx
  158.     mov bl,[dcml]
  159.     mov byte ptr [dcml + ebx + 1],0
  160. ;
  161. ; Execute startup routines
  162. ;
  163.     push     ds            ; reset es to ds
  164.     pop     es
  165.     mov    ecx,offset DGROUP:InitStart
  166.     mov    edx,offset DGROUP:InitEnd
  167.     call    sexproc            ; good name : SEXproc
  168.  
  169. ;
  170. ; Now we are going to patch the name of the file into argv[0]
  171. ;
  172.     mov     es,[__pspseg]        ; get environment
  173.     mov    es,es:[2ch]
  174.     sub    eax,eax            ; set up for scan
  175.     mov     edi,eax
  176.     mov     ecx,-1
  177.     mov    esi,offset DGROUP:filename
  178. lp:
  179.     repnz    scasb            ; scan for end of environment
  180.     test    byte ptr es:[edi],0ffh
  181.     jnz     lp
  182.     add    edi,3            ; got it, index to command line
  183. lp1:
  184.     mov    al,es:[edi]        ; now transfer the file name
  185.     mov    [esi],al        ; to a local buffer
  186.     inc    esi
  187.     inc    edi
  188.     or    al,al
  189.     jnz    lp1
  190.  
  191.     mov    eax,[__argv_arr]
  192.     mov    dword ptr [eax],offset DGROUP:filename
  193.  
  194.     push ds
  195.     pop es
  196. ;
  197. ;
  198. ; Call main
  199. ;
  200.     push    __env_arr
  201.     push    __argv_arr
  202.     push    __argc
  203. ifdef DEBUG
  204.         extrn monitor_init:proc
  205.         call monitor_init
  206. endif
  207.     call    _main
  208.     add    esp,12
  209.  
  210. ; exit/abort comes here
  211. ;
  212. __rexit:
  213. ;
  214. ; Execute rundown routines
  215. ;
  216.     push    eax        ; saving C return code
  217.     mov    ecx,offset DGROUP:ExitStart
  218.     mov    edx,offset DGROUP:ExitEnd
  219.     call    sexproc
  220. ;
  221. ; rundown signal handler
  222. ;
  223.     call    llsigdown
  224. ;
  225. ; get original stack
  226. ;
  227. exitpos:
  228.  
  229. .EXIT
  230. ;
  231. ; Handle startup/rundown routines
  232. ;
  233. sexproc:
  234.         cmp    ecx,edx        
  235.         jz    short sexpdone    
  236.         mov    edi,ecx
  237.         sub    ebx,ebx
  238.         sub    eax,eax
  239. spl2:
  240.         cmp    edi,edx
  241.         jz    short spo
  242.         test    dword ptr [edi+4],-1
  243.         jz    short spl3
  244.         cmp    eax,[edi+4]
  245.         jnc    short spl3
  246.         mov    ebx,edi
  247.         mov    eax,[edi+4]
  248. spl3:
  249.         add    edi,8
  250.         jmp    spl2
  251. spo:
  252.         or    ebx,ebx
  253.         jz    short sexpdone
  254.         mov    dword ptr [ebx+4],0
  255.         push    edx
  256.         push    ecx
  257.         call    [ebx]
  258.         pop    ecx
  259.         pop    edx
  260.         jmp    sexproc
  261. sexpdone:
  262.         ret
  263.  
  264. ; This is called as the first thing from the C++ main routine
  265. cpproutine:
  266.         ret
  267. _TEXT        ends
  268.  
  269. end start