📄 rxdosexe.asm
字号:
_loadProgram_24:
mov al, byte ptr [ _Mode ][ bp ] ; if load overlay
getdarg cx, dx, _filesize
call ifOverlayLoader ; set up ret args if overlay
ifz _loadProgram_46 ; no need to build return stack -->
getarg es, _programPSP ; child process' PSP
mov word ptr [ _RxDOS_CurrentPSP ], es ; change running PSP
call _getSizeOfEnvString ; get size of env string
xor si, si
; cmp cx, (1024 /PARAGRAPH) * 64 ; greater than 64k ?
; jnc _loadProgram_28 ; yes, use max value for seg
; mov si, cx
; shl si, 1
; shl si, 1
; shl si, 1 ; actual words
_loadProgram_28:
mov word ptr es:[ si - 2 ], 0000 ; place a null return address at top of stack
sub si, 4 ; top value minus 2 words
mov word ptr es:[ pspUserStack. _pointer ], si
mov word ptr es:[ pspUserStack. _segment ], es ; child process psp
sub si, _Flags
mov bx, word ptr ss:[ _RxDOS_CurrentInstance ]
mov word ptr ss:[ _pointer ][ bx ], si
mov word ptr ss:[ _segment ][ bx ], es ; where new process' startup stack will exist (COM)
or si, si
pushf
pop word ptr es:[ _Flags ][ si ] ; Nz Nc ...
mov word ptr es:[ _IP ][ si ], 100h
mov word ptr es:[ _CS ][ si ], es
mov word ptr es:[ _ExtraSegment ][ si ], es
mov word ptr es:[ _DataSegment ][ si ], es
mov word ptr es:[ _BP ][ si ], 0000
mov word ptr es:[ _DI ][ si ], 0000
mov word ptr es:[ _SI ][ si ], 0000
mov word ptr es:[ _DX ][ si ], 0000
getdarg bx, cx, _filesize
mov word ptr es:[ _CX ][ si ], cx
mov word ptr es:[ _BX ][ si ], bx
mov word ptr es:[ _AX ][ si ], 0000
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; set DTA on the way out; switch stacks.
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
_loadProgram_40:
cmp byte ptr [ _Mode ][ bp ], execLoadOverlay ; if load overlay
jz _loadProgram_46 ; no need to allocate memeory -->
mov es, word ptr [ _RxDOS_CurrentPSP ] ; new PSP
mov word ptr [ _RxDOS_pDTA. _segment ], es
mov word ptr [ _RxDOS_pDTA. _pointer ], pspCommandTail
cli
mov bx, word ptr ss:[ _RxDOS_CurrentInstance ]
mov ax, word ptr es:[ pspParentId ] ; parent PSP address
sti ; re-enable interrupts
or ax, ax ; if no current PSP
jz _loadProgram_44 ; none -->
push word ptr ss:[ _segment ][ bx ]
push word ptr ss:[ _pointer ][ bx ]
pop word ptr es:[ pspUserStack. _pointer ]
pop word ptr es:[ pspUserStack. _segment ] ; child process
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; copy program name to Environment Block
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
_loadProgram_44:
mov es, word ptr [ _RxDOS_CurrentPSP ] ; new PSP
lea dx, offset _expandedName [ bp ] ; expanded name
call _setProgramNameInMemBlock
mov ax, word ptr es:[ pspEnvironment ] ; get environment block
or ax, ax ; if no environment block
jz _loadProgram_46 ; -->
push ds
mov es, ax ; get environment block
call _setProgramNameInMemBlock
setDS ss
lea dx, offset _expandedName [ bp ] ; expanded name to env block
call appendProgramNametoEnv
pop ds
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; see if DEBUGGER support request
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
_loadProgram_46:
cmp byte ptr [ _Mode ][ bp ], execLoadAndReturnDebug
clc
jnz _loadProgram_68 ; if not debugger mode -->
SaveSegments
mov es, word ptr [ _RxDOS_CurrentPSP ] ; new PSP
mov dx, word ptr es:[ pspUserStack. _segment ]
mov ax, word ptr es:[ pspUserStack. _pointer ]
; get CS: IP
mov es, word ptr [ _RxDOS_CurrentPSP ] ; new PSP
mov bx, word ptr es:[ pspUserStack. _pointer ]
mov es, word ptr es:[ pspUserStack. _segment ] ; es:bx = current stack
mov dx, word ptr es:[ _CS ][ bx ] ; get new prog cs:ip
mov ax, word ptr es:[ _IP ][ bx ]
getdarg ds, si, _ExecBlock
mov word ptr [ lprogCSIP. _segment ][ si ], dx
mov word ptr [ lprogCSIP. _pointer ][ si ], ax ; save in exec block
; save SS: SP in exec block
mov word ptr [ lprogSSSP. _segment ][ si ], es
mov word ptr [ lprogSSSP. _pointer ][ si ], bx ; stack to exec block
; return to CS:IP of previous instance with new stack
getdarg dx, ax, _DebuggerReturnTo
mov word ptr es:[ _CS ][ bx ], dx
mov word ptr es:[ _IP ][ bx ], ax
mov bx, word ptr ss:[ _RxDOS_CurrentInstance ]
getdarg dx, ax, _PrevInstance
mov word ptr ss:[ _segment ][ bx ], dx
mov word ptr ss:[ _pointer ][ bx ], ax
RestoreSegments
clc
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; exit.
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
_loadProgram_68:
Return
;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
; Load Exe Program ;
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
; ;
; Input: ;
; ss:di pointer to directory block ;
; es:bx address of EXEC structure ;
; dx load segment address if mode (al) is load Overlay ;
; cx code relocation factor ;
; ax subfunction code ;
; ;
; Output: ;
; dx PSP segment address ;
; cy load failed ;
;...............................................................;
loadExe_Program:
Entry
def _Mode, ax
def _programPSP, 0000
def _StartSegment, dx
def _RelocFactor, cx
def _SizePara
def _CheckSum
ddef _returnSize
ddef _ExecBlock, es, bx
ddef _dirAccess, ss, di
defbytes _exeHeader, sizeEXEHEADER
defbytes _diskAccess, sizeDISKACCESS
defbytes _relocitem, 4
xor cx, cx
storarg _programPSP , cx
storarg _CheckSum , cx
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; initialize disk access block
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
mov ax, word ptr ss:[ fileAcDrive ][ di ]
mov dx, word ptr ss:[ fileAcCluster ][ di ]
lea bx, offset _diskAccess [ bp ] ; build access control block
call initdiskAccess ; [ax] is drive, [dx] is cluster
les si, dword ptr [ fileAcBufferPtr ][ di ]
add si, word ptr [ fileAcDirOffset ][ di ]
mov ax, word ptr es:[ deFileSize. _low ][ si ]
mov dx, word ptr es:[ deFileSize. _high ][ si ]
mov word ptr [ _diskAccess. diskAcFileSize. _low ][ bp ], ax
mov word ptr [ _diskAccess. diskAcFileSize. _high ][ bp ], dx
sub ax, 200h
sbb dx, 0000h ; return size
mov word ptr [ _returnSize. _low ][ bp ], ax
mov word ptr [ _returnSize. _high ][ bp ], dx
xor dx, dx
xor ax, ax ; position to beg of file
setES ss
lea di, offset _exeHeader [ bp ]
mov cx, sizeEXEHEADER
call readLogicalBuffer ; Access buffer: ss: bx
call computeChecksum
mov word ptr [ _CheckSum ][ bp ], ax
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; compute size in pages of load module
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
mov dx, word ptr [ _exeHeader. exeExtraBytes ][ bp ]
add dx, (PARAGRAPH - 1) ; round up parags needed
shr dx, 1
shr dx, 1
shr dx, 1
shr dx, 1 ; paragraphs at end needed
mov ax, word ptr [ _exeHeader. exePages ][ bp ]
; dec ax ; adjust for last block
shl ax, 1 ; conv pages to paragraphs
shl ax, 1 ; 4
shl ax, 1 ; 8
shl ax, 1 ; 16
shl ax, 1 ; 32
sub ax, word ptr [ _exeHeader. exeHeaderSize ][ bp ]
add ax, dx ; actual paragr needed
add ax, word ptr [ _exeHeader. exeMinAlloc ][ bp ]
storarg _SizePara, ax ; save as paragraphs needed
cmp byte ptr [ _Mode ][ bp ], execLoadOverlay ; if load overlay
jz loadExe_Program06 ; no need to build return stack -->
mov dx, word ptr [ _exeHeader. exeMaxAlloc ][ bp ]
getdarg es, bx, _ExecBlock ; load exec module
call _LoaderAllocMemory ; alloc memory for env block/ PSP
ifc loadExe_Program50 ; if cannot allocate -->
storarg _StartSegment, es ; where data load begins
storarg _RelocFactor, es ; relocation factor
storarg _programPSP, ax ; save seg address of PSP
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; load module
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
loadExe_Program06:
mov ax, word ptr [ _exeHeader. exeHeaderSize ][ bp ]
shl ax, 1 ; 2
shl ax, 1 ; 4
shl ax, 1 ; 8
shl ax, 1 ; 16 byte offset
getarg es, _StartSegment ; load overlay address
xor dx, dx
loadExe_Program08:
push es
push dx
push ax ; save position in file
mov cx, word ptr [ _SizePara ][ bp ] ; get paras to read
test cx, 0F000h ; over 65k ?
jz loadExe_Program12 ; no, read whole file -->
mov cx, 0FFFh ; read as much as possible.
loadExe_Program12:
push cx ; save paras to read
shl cx, 1
shl cx, 1
shl cx, 1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -