DOC PREVIEW
UNO CSCI 8530 - Processes

This preview shows page 1-2 out of 5 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 5 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 5 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 5 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

11The Tempo-vm Operating SystemPart 2Processes2Processes/Threads (1)• Fundamental executable object• Currently these are really threads• Each process instance has a "struct Proc" (defined in h/types.h)• Most processes created by newprocasyscall• Idle process and first user process created at system startup3Processes/Threads (2)• Each process has a state:– PROCESS_FREE: unused struct Proc entry– PROCESS_READY: process can run– PROCESS_CURRENT: process is running– Others: process is blocked for some reason• Each process has a priority (between LOWEST_PRIORITY and HIGHEST_PRIORITY).• Each ready process on a FIFO queue based on its priority.4Processes/Threads (3)• Each process identified by a unique int (of type pid_t) called its process ID.• Each process has its own user-mode stack.• Each process has a set of register values (including general regs, stack pointer, and instruction pointer)– When running, these are real registers– When not running, these are saved on a stack. 5Processes/Threads (4)• Each process runs in user or supervisor(kernel, privileged) mode.– User mode used for normal processing– Supervisor mode used during system calls• When executing a system call, a process uses a separate kernel stack.6Understanding Stack Usage• Understanding stack use is crucial to understanding process implementation.• In IA-32, stacks grow downward in memory• Stack pointer register (ESP) identifies the top element on the stack• PUSH decrements ESP by item size and stores an item• POP extracts item and increments ESP by item size27Stack Frames (1)• Each function call has a dedicated region of stack called its stackframe• Bottom of stack frame (or other fixed point in the frame) pointed to by EBP register; top pointed to by ESP register• A C function call pushes arguments (in reverse order) and then the return address• Called function pushes EBP, copies ESP to EBP, then decrements ESP by size of local variables.8Stack Frames (2)• To return, a function places return value in EAX, copies EBP to ESP, pops EBP, and executes the ret instruction which pops the return address into the EIP register.• GCC uses leave instruction which copies EBP to ESP and pops EBP.• The calling function then reclaims the stack space used by the arguments and deals with the returned value.9Assembler Basics (1)• Tempo assembler uses GNU assembler syntax (also called “AT&T” syntax)– Operands in opposite order from Intel syntax– Register names prefixed with ‘%’– Constants prefixed with ‘$’– Comments prefixed with ‘#’• Opcodes suffixed with data type (i.e. b, w, l)• Most instructions have two operands. Examples:– movl $5, %eax # copies 5 to eax register– subl %eax, %ebx # subtract eax from ebx10Assembler Basics (2)• Memory references take the formdisp(base,index,scale)• disp is a constant (or label of instr/data)• base is a permitted register name• index is another permitted register name• scale is 1, 2, 4, or 8; default is 1• Result address is disp+base+index*scale11Assembler Basics (3)• Observations:– Accessing a parameter:• 8(%ebp) references the first 32-bit parameter• 12(%ebp) reference the second 32-bit parameter– Accessing a local variable:• -4(%ebp) references first local 32-bit variable• -8(%ebp) reference second local 32-bit variable– 0(%ebp) contains caller’s ebp register value– 4(%ebp) contains return address12Example C Programint f (int a1, int *a2){int temp;temp = a1 * 3;*a2 = temp;return a1 - 5;}main ( ){int x, y, z;x = 12;z = f(x, &y);}313Assembler Code for Examplef:pushl %ebpmovl %esp, %ebpsubl $4, %espmovl 8(%ebp), %edxmovl %edx, %eaxsall %eaxaddl %edx, %eaxmovl %eax, -4(%ebp)movl 12(%ebp), %edxmovl -4(%ebp), %eaxmovl %eax, (%edx)movl 8(%ebp), %eaxsubl $5, %eaxleaveretmain:pushl %ebpmovl %esp, %ebpsubl $12,%espmovl $12, -4(%ebp)leal -8(%ebp), %eaxpushl %eaxpushl -4(%ebp)call faddl $8, %espmovl %eax, -12(%ebp)leaveret14Stack During Execution of fStorage for main’s x Storage for main’s y Storage for main’s z Addr of main’s y Value of main’s xReturn address from fmain’s EBP valueStorage for tempcaller’s EBP value main’s EBPf’s EBP15Initial Stack for a Process (1)• As just seen, any function expects a return address at the bottom of the stack when it begins, preceded by any arguments• The Main function expects two arguments– a count of the number of “command line” arguments (usually called ‘argc’)– a pointer to an array with ‘argc’ null-terminated strings followed by a null pointer; these strings contain the command line args.16Initial Stack for a Process (2)• These stack contents are created when the process is created (by the newprocasystem call).• The return address is to the function ‘processDone’ which does nothing more than invoke the ‘exit’ system call.• Stack space prior to Main’s arguments is used for copies of the newproca caller’s command line argument values.17struct Proc (1)struct Proc {tag_t tag; /* 0: self-identifying tag */pid_t pid; /* 4: unique process identification */Process next; /* 8: next Proc on this Queue */Process prev; /* 12: previous Proc on this Queue */struct Queue *queue; /* 16: on which Queue is this Proc found? */int priority; /* 20: process priority */int state; /* 24: process state */int stksize; /* 28: user stack size (pages) */unsigned int *stkbase; /* 32: base of user stack (from allocStack) *//* This is the address of the bottom *//* word on the stack, not like kstkbase */unsigned int *kstkbase; /* 36: base of kernel stack (1 page always) *//* Address of 1st byte of NEXT page */int signaledOn; /* 40: which event queue was signaled */18struct Proc (2)int timedOut; /* 44: set if process timed out */Process dnext; /* 48: next Proc on the delta queue */unsigned int delta; /* 52: clock ticks left before wakeup */unsigned int *ksp; /* 56: kernel %esp for ready/blocked process */pid_t waitingon; /* 60: process whose termination is awaited */int exitstatus; /* 64: exit status of process 'waitingon' */unsigned int eventaddr; /* 68: address of event for EVENT_WAIT */struct m_header *mfree; /* 72: address of free list (malloc, ...) */struct EQ eventQueue[NQUEUE]; /* the event queues for the process */struct FD fd[NFD]; /* fd[i] = info for open file "i" */};419struct Proc Notes (1)• ‘next’ and ‘prev’ are used to link a ‘structProc’ on various queues, as necessary.•


View Full Document

UNO CSCI 8530 - Processes

Download Processes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Processes 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 Processes 2 2 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?