Unformatted text preview:

The Tempo Operating System Part 6 System Call Implementation Processes and Timers Last edit 10 9 2007 newproca Process Creation Conceptually simple validate parameters allocate an unused process table entry fill in the appropriate values allocate user and kernel stack space initialize stacks for initial return from kernel No code or data needs to be initialized since these are already present The most complicated part of newproca is getting the initial user and kernel stack contents correct 1 newproca pseudocode 1 Find an unused process table entry if not found return error PROCTBLFULL Extract system call arguments Setup tag priority and process ID Allocate user mode stack handle errors Determine size of string arguments Set user stack info args ptr to args return address processDone Copy string arguments and pointers to user mode stack newproca pseudocode 2 Allocate kernel mode stack always 1 page Initialize kernel stack user mode stack segment and stack pointer eflags register code segment and instruction pointer remaining segment and general purpose registers Initialize event queues empty unmasked Setup file descriptors 0 1 for keyboard display 2 newproca pseudocode 3 Mark all other file descriptors as available for use Mark process as not signaled see signal discussion for details Increase number of processes in system Add process to appropriate ready queue by calling addready If new process has priority greater than current creating process add current process to appropriate ready queue and set rs to 1 Return ID of the new process User Stack at Process Startup Bottom of stack String N String 2 String 1 Null Ptr Addr Str N Addr Str 2 Addr Str 1 Array Addr N argc processDone return address argv Initial stack pointer 3 Kernel Stack at Process Startup User Stack Sel User Stack Ptr eflags Reg User Code Sel Instr Pointer Copy of Intr Other Segment Registers 4 Gen Purpose Registers 8 Bottom of the kernel stack Popped restored by the iret instruction after isr30z in kernel s So system call stacks look like all other interrupt stacks Initial kernel stack pointer run create load process from disk Contrary to its name newproca does not really create a process Instead it creates what is usually called a thread The run system call on the other hand creates a real process and initializes its address space appropriately code data comes from a disk file 4 run pseudocode part 1 Find an unused process table entry if not found return error PROCTBLFULL Extract system call arguments Expand runinf structure s components or copy caller s information for new process Validate new process priority Allocate a page of RAM for the new process page table Open the file containing the executable image Load the executable file into RAM described later Close the file run pseudocode part 2 Initialize the stack for the process This is done in a manner similar to that done for newproca Allocate a page for the kernel stack Initialize the kernel stack Set user system RW and presence bits appropriately for the page table entries Initialize event queues and file descriptors Copy the environment environ and working directory workdir information to the process table entry Add the process to the appropriate ready queue addready set rs to 1 if appropriate and return 5 Loading an executable file part 1 There are two actually three but one is funky forms of executable files handled by the run system call ELF Executable and Loadable Format and PE Portable Executable ELF is most common in the Linux environment while PE executables are used in the Windows world Executable files contain completely linked applications packaged in multiple sections or segments each preceded by a section header Typical sections are those for text code and data Loading an executable file part 2 Loading takes place as follows Validate the file format as one we can handle For each section Extract information from a section header Virtual address where the section should be loaded Size of the section Allocate pages of memory real and virtual for the section update the page table for the process Copy the section from disk to memory Set the program break top of allocated memory Allocate and clear a page for the process stack 6 addready The addready function has a single parameter a pointer to a process table entry The state member of that process table entry is set to PROCESS READY The process table entry is linked using the next and prev members onto the appropriate ready queue getpid pseudocode Getpid almost warrants no explanation since it only extracts and returns the pid member of the process table entry for the current process The only thing worth noting is that it is always assumed that the global variable activeProcess points to the process table entry for the running process 7 getpstate pseudocode Getpstate like getpid just returns the contents of a member in this case state of the process table entry For this call we must map from the pid to a pointer to the process table entry This is done by the pid2a function in sys c which just does a linear search of the entire array returning the appropriate pointer if the pid was found or NULL 0 otherwise Once the pointer is located or not the appropriate value is returned to the caller getprio getquantum setquantum Each of these system calls just returns a field from the process table for the currently running process and or gets sets the value of a global variable No further explanation should be necessary to understand their implementation 8 setprio psuedocode Verify argument is within allowed range for process priorities if not return error If the new priority is the same as the current priority return without change Modify the process table entry If there now exists a ready process with a priority higher than the current process priority Move the current process to the ready state by calling addready Set rs to 1 to force a context switch Return yield pseudocode Recall that the yield system call causes the running process to voluntarily relinquish the CPU to another process at the same priority The steps taken are add the current process the one yielding the CPU to the appropriate ready queue by calling addready set rs to 1 to force a context switch return 9 exit pseudocode Exit does little direct work The exitstatus member of the process table entry of the terminating process is set to the value of the argument to exit this value can be retrieved by a waiting process that called waitproc Set


View Full Document

UNO CSCI 8530 - The Tempo Operating System

Loading Unlocking...
Login

Join to view The Tempo Operating System and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view The Tempo Operating System and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?