exec() for ibm-pc (LAttice C)
geb at cadre.UUCP
geb at cadre.UUCP
Sun Jun 24 08:43:29 AEST 1984
>From km Sat Jun 23 12:17:35 1984
Received: by cadre.UUCP (4.12/3.14)
id AA06807; Sat, 23 Jun 84 12:17:32 edt
> Date: Sat, 23 Jun 84 12:17:32 edt
> From: km (Ken Mitchum)
> Message-Id: <8406231617.AA06807 at cadre.UUCP>
> To: geb
> Subject: exec()
> Status: R
>
> you can give them my version of exec.asm. make certain it has my
> name at the top, with the explanation that it only works with
> lattice C. i think the explanation is already there.
>
;execute a program.
;(c) K. Mitchum 6/84. (km at cadre).
;primitive exec routine for ms-dos.
;assumes seg fixup of Microsoft C compiler.
;(others use at your own risk.)
;
;current seg fixup results in:
;cs = one page above program segment prefix
;es = set by program, not known to o.s.
;
;in order to properly allocate memory for the new program
;we must first deallocate to the "minimum" necessary.
;we assume a worst case minimum, with the entire
;PSP segment needed, and with entire data segment needed.
;
BDOSINT EQU 21h
ALLOC EQU 48h ;bdos allocate segment
SETBLOCK EQU 4Ah ;shrink alloc. segment
BDOSEXEC EQU 4Bh
DGROUP GROUP DATA
DATA SEGMENT WORD PUBLIC 'DATA'
ASSUME DS:DGROUP
ENVPTR DW ? ;pointer to environment
CMDPTR DW ? ;pointer to command line
CMDSEG DW ? ;data segment
FCB1PTR DW ? ;default fcb 1 pointer
FCB1SEG DW ?
FCB2PTR DW ? ;default fcb 2 pointer
FCB2SEG DW ?
FCB1 DB 0
DB 11 DUP (?)
DB 25 DUP (0)
FCB2 DB 0
DB 11 DUP (' ')
DB 25 DUP (0)
DATA ENDS
PGROUP GROUP PROG
PROG SEGMENT BYTE PUBLIC 'PROG'
ASSUME CS:PGROUP
PUBLIC EXEC
OLDSS DW ?
OLDSTACK DW ?
;int exec(cmd,arg)
;char *cmd,*arg;
;
;execute the file named "cmd" with arguments "arg"
;
;NOTE: "arg" must begin with a space, due to parsing
;peculiarities of dos.
;form of "cmd" = "<drive char>:filename.ext"
;or "path/filename.ext"
;or "<drive char>:path/filename.ext"
;
;form of "arg" = whatever called program needs
;
;this model assumes environment of callee is same as caller program
;and that default blank fcbs are adequate.
;future versions may take arguments for these.
;
;returns error code (DOS manual p D-14).
; 0 = no error
; 2 = file not found
; 5 = access denied
; 8 = insufficient memory
; 10 = invalid environment
; 11 = invalid format
EXEC PROC NEAR
push bp
push es ;system does not yet know of data seg,etc.
mov ax,cs
sub ax,10h ;program segment prefix is one page lower
mov es,ax
mov bx,1000h ;worst case, need entire segment
mov ah,SETBLOCK ;"shrink" to worst case
mov al,0
int BDOSINT
pop es ;but reserve entire data seg
mov bx,1000h
mov ah,ALLOC ;a kludge but it works
mov al,0
int BDOSINT
mov bp,sp
cli
add sp,4 ;now get the arguments
pop dx ;pointer to command
pop cx ;pointer to argument line
mov sp,bp
sti
mov ENVPTR,0 ;empty environment for now
mov CMDPTR,cx
mov ax,ds
mov CMDSEG,ax
mov FCB1SEG,ax
mov FCB2SEG,ax
mov FCB1PTR, offset DGROUP:FCB1
mov FCB2PTR, offset DGROUP:FCB2
mov bx, offset DGROUP:ENVPTR
push es
push ds
push di
push si
push dx
push cx
push bx
mov cs:OLDSTACK,sp
mov cs:OLDSS,ss
mov ah,BDOSEXEC
mov al,0
int BDOSINT
cli
mov bx,ax ;save error code
mov ax,cs:OLDSS
mov ss,ax
mov sp,cs:OLDSTACK
sti
mov ax,bx
jc exec1 ;if no error
mov ax,0
exec1:
pop bx
pop cx
pop dx
pop si
pop di
pop ds
pop es
pop bp
ret
EXEC ENDP
PROG ENDS
END
More information about the Comp.sources.unix
mailing list