📄 rxdosexe.asm
字号:
TITLE 'exe - load and execute .com and .exe programs'
PAGE 59, 132
.LALL
;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
; Load EXE/COM Programs ;
;...............................................................;
;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
; Real Time Dos ;
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
; ;
; This material was created as a published version of a DOS ;
; equivalent product. This program logically functions in ;
; the same way as MSDOS functions and it is internal data ;
; structure compliant with MSDOS 6.0 ;
; ;
; This product is distributed AS IS and contains no warranty ;
; whatsoever, including warranty of merchantability or ;
; fitness for a particular purpose. ;
; ;
; ;
; (c) Copyright 1990, 1997. Api Software and Mike Podanoffsky ;
; All Rights Reserved Worldwide. ;
; ;
; This product is protected under copyright laws and may not ;
; be reproduced in whole or in part, in any form or media, ;
; included but not limited to source listing, facsimile, data ;
; transmission, cd-rom, or floppy disk without the expressed ;
; written consent of the author. ;
; ;
; License for distribution for commercial use or resale ;
; required from: ;
; ;
; Api Software ;
; 12 South Walker Street ;
; Lowell, MA 01851 ;
; ;
; internet: mikep@world.std.com ;
; ;
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
; Compile with MASM 5.1 ;
;...............................................................;
include rxdosmac.asm
include rxdosdef.asm
RxDOS SEGMENT PUBLIC 'CODE'
assume cs:RxDOS, ds:RxDOS, es:RxDOS, ss:RxDOS
;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
; Load EXE/COM Programs ;
;...............................................................;
public copyCurrentPSP
public loadProgram
extrn LocateFile : near
extrn ExpandFileName : near
extrn initdiskAccess : near
extrn readLogicalBuffer : near
extrn allocateMemBlock : near
extrn _allocateMinMaxMemBlock : near
extrn stdDeviceAssignTable : near
extrn _RetCallersStackFrame : near
extrn _freeMemBlock : near
extrn CopyString : near
extrn MapAppToSFTHandle : near
extrn FindSFTbyHandle : near
extrn _RxDOS_AllocStrategy : word
extrn _RxDOS_CurrentPSP : word
extrn _RxDOS_CurrentInstance : word
extrn _RxDOS_MaxMemory : word
extrn _RxDOS_DOSVersion : word
extrn _RxDOS_pDTA : dword
extrn _CallDOS : far
extrn pexterrNotEnoughMemory : near
;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
; Load Program Image (COM, SYS, etc... ) ;
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
; ;
; Input: ;
; ds:dx asciz name of program to load ;
; es:bx address of LOADEXEC structure ;
; al mode (subfunction) ;
; ;
; Output: ;
; dx PSP segment address ;
; cy load failed ;
;...............................................................;
loadProgram:
Entry
def _Mode, ax
def _programPSP, 0000
def _StartSegment, 0000
def _RelocFactor, 0000
def _SizePara
ddef _filesize
ddef _PathName
ddef _ExecBlock
ddef _PrevInstance
ddef _DebuggerReturnTo
defbytes _expandedName, sizeEXPANDNAME
defbytes _exeHeader, sizeEXEHEADER
defbytes _diskAccess, sizeDISKACCESS
defbytes _dirAccess, sizeDIRACCESS
defbytes _relocitem, 4
mov bx, word ptr ss:[ _RxDOS_CurrentInstance ]
les bx, dword ptr ss:[ bx ]
stordarg _PrevInstance, es, bx ; instance before
mov dx, word ptr es:[ _CS ][ bx ]
mov ax, word ptr es:[ _IP ][ bx ]
stordarg _DebuggerReturnTo, dx, ax ; return address
RetCallersStackFrame es, si
mov dx, word ptr es:[ _ExtraSegment ][ si ]
mov ax, word ptr es:[ _BX ][ si ] ; get es: bx from caller
stordarg _ExecBlock, dx, ax
mov dx, word ptr es:[ _DataSegment ][ si ]
mov ax, word ptr es:[ _DX ][ si ] ; get ds: dx from caller
stordarg _PathName, dx, ax
push dx ; non-canonical name
push ax
lea dx, offset _expandedName [ bp ] ; expanded name
push ss
push dx
mov ax, FILECANNOT_BEDIRECTORY ; not a directory
call ExpandFileName ; get actual expanded name
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; initialize mode
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
getarg ax, _Mode ; get mode
Goto execSetExecuteMode, _loadProgram_SetExec
Goto execLoadOverlay, _loadProgram_Overlay
jmp short _loadProgram_04
_loadProgram_SetExec:
call _SetExecuteMode
jmp _loadProgram_68
_loadProgram_Overlay:
getdarg es, bx, _ExecBlock
mov ax, word ptr es:[ loverSegLoadAddress ][ bx ]
storarg _StartSegment, ax
mov ax, word ptr es:[ loverRelocFactor ][ bx ]
storarg _RelocFactor, ax
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; program file exist ?
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
_loadProgram_04:
mov ax, (FILE_NODEVICENAME)
getdarg es, si, _PathName ; name from caller (ds: dx )
lea di, offset _dirAccess [ bp ] ; work dir access block
call LocateFile ; try to find file
ifc _loadProgram_68 ; if cannot -->
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; initialize disk access block
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
setES ss
lea bx, offset _diskAccess [ bp ] ; build access control block
call initdiskAccess ; [ax] is drive, [dx] is cluster
call checkEXEHeader ; exe file ?
jnz _loadProgram_12 ; no, COM or SYS type -->
getarg ax, _Mode ; get subfunction code
getarg cx, _RelocFactor ; relocation factor
getarg dx, _StartSegment ; load overlay address
lea di, word ptr [ _dirAccess ][ bp ] ; dir information
getdarg es, bx, _ExecBlock ; original load exec
call loadExe_Program ; pass off control to load EXE
ifc _loadProgram_68 ; if cannot -->
jmp _loadProgram_40 ; switch stack -->
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; load COM or SYS
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
_loadProgram_12:
les di, dword ptr [ _dirAccess. fileAcBufferPtr ][ bp ]
add di, word ptr [ _dirAccess. fileAcDirOffset ][ bp ]
mov ax, word ptr es:[ deFileSize. _low ][ di ]
mov dx, word ptr es:[ deFileSize. _high ][ di ]
stordarg _filesize, dx, ax ; save file size
add ax, (PARAGRAPH - 1)
adc dx, 0 ; just in case carry
shr dx, 1
rcr ax, 1
shr dx, 1
rcr ax, 1
shr dx, 1
rcr ax, 1
shr dx, 1
rcr ax, 1
storarg _SizePara, ax ; save as paragraphs needed
cmp byte ptr [ _Mode ][ bp ], execLoadOverlay ; if load overlay
jz _loadProgram_18 ; no need to allocate memeory -->
mov dx, 0FFFFh ; max request (all of memory)
getdarg es, bx, _ExecBlock ; load exec module
call _LoaderAllocMemory ; alloc memory for env block/ PSP
ifc _loadProgram_68 ; if cannot allocate -->
storarg _StartSegment, es ; where data load begins
storarg _programPSP, ax ; save seg address of PSP
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; load module (at es: 0000)
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
_loadProgram_18:
xor di, di ; load at es:0000
getarg es, _StartSegment ; load overlay address
lea bx, offset _diskAccess [ bp ] ; build access control block
mov word ptr ss:[ diskAcPosition. _high ][ bx ], di
mov word ptr ss:[ diskAcPosition. _low ][ bx ], di
_loadProgram_20:
mov cx, 60 * 1024 ; read 60k at a time
mov ax, word ptr [ _filesize. _low ][ bp ]
mov dx, word ptr [ _filesize. _high ][ bp ]
sub ax, word ptr ss:[ diskAcPosition. _low ][ bx ]
sbb dx, word ptr ss:[ diskAcPosition. _high ][ bx ]
or dx, dx ; more than 60k ?
jnz _loadProgram_22 ; yes -->
cmp ax, cx ; more than 60k ?
jnc _loadProgram_22 ; yes -->
mov cx, ax ; exact bytes to read
_loadProgram_22:
or cx, cx ; more to read ?
jz _loadProgram_24 ; if no more to read -->
mov dx, word ptr ss:[ diskAcPosition. _high ][ bx ]
mov ax, word ptr ss:[ diskAcPosition. _low ][ bx ]
lea bx, offset _diskAccess [ bp ] ; build access control block
call readLogicalBuffer ; Access buffer: ss: bx
or cx, cx ; bytes actually read
jz _loadProgram_24 ; if no more to read -->
push cx
shr cx, 1
shr cx, 1
shr cx, 1
shr cx, 1 ; chars read in paras
mov ax, es
add ax, cx
mov es, ax
pop cx
and cx, (PARAGRAPH - 1)
add di, cx
jmp _loadProgram_20
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; switch to new process
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -