home *** CD-ROM | disk | FTP | other *** search
- ;
- ; tasm /ml/m4/zi c1dos.asm
- ;
- MASM
- ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
- ;
- ; PMODE/W Assembly Startup for CC386.EXE (c) Kirill Jo$$ :-)
- ;
- ;
- ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
- .386p
-
- STACK_SIZE = 40*1024h ; Stack size
-
- ; This is equ copy from C0DOS.ASM :-)
-
- _TEXT segment para public use32 'CODE'
- extrn __argv_arr:DWORD,__argc:DWORD,__env_arr:DWORD,__cmdline:DWORD
- extrn _main:PROC, llsignal:proc, llsigdown:proc
- _TEXT ends
- cstartup SEGMENT DWORD PUBLIC USE32 'INITDATA'
- InitStart label dword
- ENDS
- _STARTUPEND_ SEGMENT DWORD PUBLIC USE32 'INITDATA'
- InitEnd label dword
- ENDS
- crundown SEGMENT DWORD PUBLIC USE32 'EXITDATA'
- ExitStart label dword
- ENDS
- _RUNDOWNEND_ SEGMENT DWORD PUBLIC USE32 'EXITDATA'
- ExitEnd label dword
- ENDS
- _CPP_ SEGMENT DWORD PUBLIC USE32 'CPPDATA'
- CppStart label dword
- dd cpproutine
- ENDS
- _CPPEND_ SEGMENT DWORD PUBLIC USE32 'CPPDATA'
- CppEnd label dword
- ENDS
- _DATA SEGMENT DWORD PUBLIC USE32 'DATA'
- ENDS
- _BSS SEGMENT DWORD PUBLIC USE32 'BSS'
- BssStart label dword
- ENDS
- _BSSEND SEGMENT DWORD PUBLIC USE32 'BSS'
- BssEnd label dword
- ENDS
- _STACK segment para stack use32 'STACK'
- align 4
- db STACK_SIZE dup(?)
- stack_offset label dword
- ENDS
-
-
- DGROUP group _TEXT, cstartup,_STARTUPEND_,crundown,_RUNDOWNEND_,_CPP_,_CPPEND_,_DATA,_BSS,_BSSEND, _STACK
-
- public __rexit, __transferx, __stacktop
- public __pspseg, __linear, __pmodew,__rmseg
-
-
- _DATA SEGMENT DWORD PUBLIC USE32 'DATA'
- banner db 'Startup for DOS/4GW & PMODE/W (c) Kirill Joss. [',??date,']',10,13,36
- db "Copyright (c) 1997 LADsoft C runtime library"
- db " (i386/DOS PMODE/W)"
- align 4
- __linear dd 0
- __stacktop dd 0
- stackpos df 0
- __transferx dw 0
- __pspseg dw 0
- __pmodew dw 0c4h
- __rmseg dw 0
- filename db 128 dup (0)
- dcml db 128 dup (0)
-
-
- ENDS
- _TEXT SEGMENT
- assume cs:DGROUP,ds:DGROUP
-
- start:
- jmp short real_start
- ;
- ; You can delete 'WATCOM',
- ; but it NOT work with Watcom Debbuger & DOS/4G or DOS/4GW :)
- ;
- db 'WATCOM', 0 ; The "WATCOM" string is needed in
- ; order to run under DOS/4G and WatcomDebug.
-
- nomemerr db 'Not enough extended memory',10,13,36
-
- ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
- ; CODE
- ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
-
- ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
- ; Entry To ASM Code (_main)
- ; In:
- ; CS - Code Selector Base: 00000000h - Limit: 4G
- ; DS - Data Selector Base: 00000000h - Limit: 4G
- ; ES - PSP Selector Base: PSP Seg - Limit: 100h
- ; FS - ?
- ; GS - ?
- ; SS - Data Selector Base: 00000000h - Limit: 4G
- ; ESP -> STACK segment
- ; Direction Flag - ?
- ; Interrupt Flag - ?
- ; All Other Registers Are Undefined!
- ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
- real_start:
- mov [__stacktop],esp
- sti ; Set The Interrupt Flag
- cld ; Clear The Direction Flag
-
- mov [__pspseg], es ; Save psp seg
-
- mov eax,ds
- mov es,eax
- mov fs,eax
- mov gs,eax
-
- ifdef COPYRIGHT ; JOS
- mov edx,offset banner
- mov ah,9
- int 21h
- endif
- ;
- ; Clear BSS
- ;
- mov edi,offset DGROUP:BssStart
- mov ecx,offset DGROUP:BssEnd
- sub ecx,edi
- sub eax,eax
- cld
- rep stosb
- ;
- ; Initialize the signal system
- ;
- call llsignal
- ;
- ; Set up command line for RTL
- ;
- mov es,[__pspseg]
- mov edi,offset DGROUP:dcml
- mov [__cmdline],edi
- inc [__cmdline]
- push ds
- push ds
- push es
- pop ds ; blit the command line into our mem
- pop es
- mov esi,80h
- mov ecx,128
- rep movsb
- pop ds
- ; turn into C string form
- sub ebx,ebx
- mov bl,[dcml]
- mov byte ptr [dcml + ebx + 1],0
- ;
- ; Execute startup routines
- ;
- push ds ; reset es to ds
- pop es
- mov ecx,offset DGROUP:InitStart
- mov edx,offset DGROUP:InitEnd
- call sexproc ; good name : SEXproc
-
- ;
- ; Now we are going to patch the name of the file into argv[0]
- ;
- mov es,[__pspseg] ; get environment
- mov es,es:[2ch]
- sub eax,eax ; set up for scan
- mov edi,eax
- mov ecx,-1
- mov esi,offset DGROUP:filename
- lp:
- repnz scasb ; scan for end of environment
- test byte ptr es:[edi],0ffh
- jnz lp
- add edi,3 ; got it, index to command line
- lp1:
- mov al,es:[edi] ; now transfer the file name
- mov [esi],al ; to a local buffer
- inc esi
- inc edi
- or al,al
- jnz lp1
-
- mov eax,[__argv_arr]
- mov dword ptr [eax],offset DGROUP:filename
-
- push ds
- pop es
- ;
- ;
- ; Call main
- ;
- push __env_arr
- push __argv_arr
- push __argc
- ifdef DEBUG
- extrn monitor_init:proc
- call monitor_init
- endif
- call _main
- add esp,12
-
- ; exit/abort comes here
- ;
- __rexit:
- ;
- ; Execute rundown routines
- ;
- push eax ; saving C return code
- mov ecx,offset DGROUP:ExitStart
- mov edx,offset DGROUP:ExitEnd
- call sexproc
- ;
- ; rundown signal handler
- ;
- call llsigdown
- ;
- ; get original stack
- ;
- exitpos:
-
- .EXIT
- ;
- ; Handle startup/rundown routines
- ;
- sexproc:
- cmp ecx,edx
- jz short sexpdone
- mov edi,ecx
- sub ebx,ebx
- sub eax,eax
- spl2:
- cmp edi,edx
- jz short spo
- test dword ptr [edi+4],-1
- jz short spl3
- cmp eax,[edi+4]
- jnc short spl3
- mov ebx,edi
- mov eax,[edi+4]
- spl3:
- add edi,8
- jmp spl2
- spo:
- or ebx,ebx
- jz short sexpdone
- mov dword ptr [ebx+4],0
- push edx
- push ecx
- call [ebx]
- pop ecx
- pop edx
- jmp sexproc
- sexpdone:
- ret
-
- ; This is called as the first thing from the C++ main routine
- cpproutine:
- ret
- _TEXT ends
-
- end start