add.l
bsslen(a5),dO
1
#stk+bp,dO
add.
*** Calculate the address of your stack
*** and move it to the stack pointer (a7)
.1
dO,dl
m o v e
a5,dl
add.l
1
2
and.
#-
,dl
move.l
dl,a7
*** Use the GEMDOS M s h r i n k Q
* * *
actually used for the program and stack, and release the
*** rest back to the free memory pool.
move.l dO,-(sp)
*
move.l a5,-(sp)
*
clr.w
~(sp)
move
#$4a,-(sp)
*
trap
#1
1 2
add.l
#
,sp
Process Control
One of the Disk Operating System's major functions is to
load a program (also known as a process) and start it. After
the program finishes, GEMDOS also has the responsibility
for terminating the process, reclaiming its memory, and re
turning to the GEM Desktop (or whatever other application
happens to be operating as a command shell). GEMDOS in
cludes four process control functions, one for loading and ex
ecuting a process, and three for terminating one.
The function used to load a program file and execute it
is called Pexec(). The syntax for this function is
*char file, command, env;
int mode;
long status;
status = Pexec(mode, file, command, env);
The meaning of the function parameters varies according to
the value of mode. There are four different modes of opera
tion for the Pexec() function. These are:
Table 5-1. Four Modes for Pexec() Function
Mode
Number
Function
0
Load and
execute
100
CHAPTER 5
* - i - length of uninitialized storage segment
* + (size of base page + stack/heap)
new stack address =
size of program memory
+ program's base address,
pick off odd bit to make sure that the
stack starts on a word boundary (it must)
set stack pointer to your stack
which is stk bytes above end of BSS
call to reserve the area of memory
* push the size of program memory
* (first M s h r i n k Q parameter) on the stack,
* push the beginning address of the
* program memory area (2nd Mshrink() parameter)
* clear a dummy place-holder word
* finally, push the GEMDOS command number
* for the Mshrink() function
* call GEMDOS
* and clear your arguments off the stack.
File
Pointer to
filename
string
Command
Pointer to
command string
Env
Pointer to
environment
string