PROCESS CREATION Author: Bill Kinnersley Date: Mar 12, 1988 Mail: Physics Dept. Montana State University Bozeman, MT 59717 BITNET: iphwk@mtsunix1 INTERNET: iphwk%mtsunix1.bitnet@cunyvm.cuny.edu USENET: lll-crg!umt!mts-cs!uphwk There are several ways of creating a process on the Amiga. At the lowest level is AddTask(task, initialPC, finalPC), which adds a given task to the TaskReady list. Here task is an existing initialized Task structure, initialPC is the entry point, and finalPC is an optional cleanup routine. The final code is pushed on the stack as if it were the outermost return address. If finalPC is 0, the system default cleanup is to call RemTask(), which removes the task from the Ready list. It deallocates the MemEntry list, but not the Task structure. The task's registers are initially set to 0, except for SP, which is set to SPReg. The user may reserve space for initial data by specifying SPReg < SPUpper. At the next level is createproc(segarray, stkszlw, pri, ^name, ^gv). (The internal AmigaDOS function, function 84). Both NewCLI and Run call this function. It: Allocates memory for Process structure and stack, and puts this on the MemList Fills the Task, Process, and DOS MsgPort: SigWait for signal 8, and default TrapCode Reserves stack space to hold the Process name Copies the parent's Console Handler, File Handler, and Window AddTask()'s with special initPC and finalPC. The finalPC code frees the SegArray. The initPC code: Fills the stack with "tttu", terminating with -1 and SP; Sets the BCPL coroutine list to point to SPLower; Looks at the Segarray. If there is more than one entry, it calls GetSegList to fill in the GV; It then fills in a5 and a6, waits for a startup packet, and then calls the program code at 4(a2). The external AmigaDOS function CreateProc(*name, pri, seg, stkszb) is function -48. In this case only a seglist is supplied, and thus the call must create its own SegArray. The name buffer is subtracted from the stack request 20 bytes are AllocMem'ed for the SegArray. The GV is obtained from DosLib The Task, Process and MsgPort are initialized as above The SPReg and ReturnAddr set The 1st and 2nd SegList are copied from the parent, the 3rd SegList is the one supplied by caller, but the SegArray length is set to 2 AddTask() is called, with initPC = 1st SegList, and finalPC the same as above. The next level is function 1c0, which calls either 84 or -48, depending on the flags it is passed. It is called by no one? 1a0 is an execute call, which calls -54 (calls 144, loadseg), then 148, unloadseg.