170 likes | 307 Views
Objective # 3. COP 4600. So far………. Obj#1 : read “logon.dat” and created our event list. Obj#2 : function Boot() called. “boot.dat” was read. Kernel loaded and MEMMAP initialized. Objective # 3. Interrupt_Handler() Logon_Service()
E N D
Objective # 3 COP 4600
So far……….. Obj#1 : read “logon.dat” and created our event list. Obj#2: function Boot() called. “boot.dat” was read. Kernel loaded and MEMMAP initialized.
Objective # 3 Interrupt_Handler() Logon_Service() • Creates a PCB Read “Script.dat” • Allocate memory And Load Program from user’s script ……………………
Logon_Service() I Get_Script() Next_pgm() II Dealloc_pgm Get_Memory Loader III Dealloc_seg Allocate_seg Compact_mem Get_Instr IV V Merge_seg
LEVEL - I Logon_Service() : [ Allocates and Initializes the PCB for LOGON events ] • PCB stored in termtable(array of pointers to PCB’s) • termtable[...] = pcb; • Initialize PCB . • status, terminal, wait, request blocks, user • Call Get_Script (PCB) // LEVEL II { Initialize the process script and pgmid } • Call Next_pgm (PCB) // LEVEL II { Allocate and Load the next program from script }
LEVEL - II Get_Script() : [ Reads a script from “script.dat” ] Open “script.dat” Intialize pcb->script and pgmid Read script till LOGOFF encountered. Load script to PCB -> script[……] Compare script names against program names in the program id table (pgmidtab) and assign corresponding int value to pcb->script[...] This gives us the list of programs a user will execute.
LEVEL - II Next_pgm() : [ Makes a transition to the next program in the script if possible] If the next program is not the first program, remove previous program from memory. if (pcb->pgmid >= 0 && pcb->rb == NULL) Dealloc_pgm(); If a process has an unserviced I/O request block (rb), return without loading next program. if (pcb->rb != NULL) return If last program encountered, set PCB status to terminated. if (pcb->[pcb->pgmid] == LOGOFF) print to *.out & set pcb->status = terminated. return
LEVEL – II • Next_pgm() : • [ Makes a transition to the next program in the script if possible] • Allocate and initialize, if possible, new segments table for the • PCB program. • Get_memory(pcb); • Load next program in memory. • Loader(pcb); • Initialize PCB area for saving CPU info (cpu_save) • pcb cpu_save • Set PCB status to ready • pcb->status = ready;
LEVEL - III Get_Memory() : [ Allocates Segment Table and sets up information for each segment ] Extract # of segments from first line of file & use it to allocate memory for the PCB segment table. PROG_FILE [pcbscript[pcbpgmid]]; Extract # of segments from first line of file & use it to allocate memory for the PCB segment table. Read size of each segment + access bits in file. Store them in the PCB segment table. Also, compute the total memory required by these segments using the segment sizes. mem_req += seg size Check if memory required exceeds free memory. If so, exit.
LEVEL - III • Get_Memory() : • [ Allocates Segment Table and sets up information for each segment ] • If memory available, call Alloc_seg() function for each segment with the length of the segment. • X = Alloc_seg(pcb->segtable[…].len) • If memory allocated successfully, save memory base pointer • pcb->segtable[…].membase = x; • Else call memory compactness function before calling memory allocation function • Compact_mem(); x = Alloc_seg(pcb->segtable[i].len);
LEVEL - IV Alloc_seg() : [ Searches the Free memory list for free memory segments in MEM for a segment with a length equal to that requested ] Search list of free memory segments with the required size If length matches exactly, remove segment from free memory and return with base address of this segment. if (ptr->segment_size == len) free_mem = ptr->next; return ptr->segptr; If segment length more than required, move free memory pointer ahead by amount of length and return base pointer of memory segment. ptr->segsize -= len; ptr->segptr += len; Else, keep searching until one of the above conditions is met. Return -1 if segment not found. Decrement free memory by the size of the segment.
LEVEL - III Loader() : [Reads associated file for instruction and loads each instruction into MEM] For each segment, it reads each instruction in that segment. Calls Get_Instr() {OBJ #2} to get opcodes and operands. Get_Instr(pcb->script[pcb->pgmid], &instr); Load each instruction in MEM MEM[...].opcode = instr.opcode; MEM[...].operand = instr.operand; Call Display_pgm() {OBJ #2} to echo to *.out
LEVEL - III Dealloc_pgm() : [ Frees all allocated segments for the current program and then frees the segment table] Call Dealloc_seg() for each segment in the pcbsegtable; free(pcbsegtable); pcb->segtable = NULL;
LEVEL - IV Dealloc_seg() : [ Return a segment to the free list] Initialize segment ptr, its base and length. If free memory is NULL, this segment becomes free memory. free_mem = ptr->seg; If (pt_seg->segptr < free_mem->segptr) pt_seg->next = pt (pointer to free_mem); free_mem = pt_seg; Else if, find place in list where above condition is true and insert the memory segment. Else, insert segment at end of list. Increment free memory counter and call Merge_seg()
LEVEL - V Merge_seg() : [ Scans Memory list and if it finds two adjacent memory blocks it merges them into one ] if (ptr->segptr + pt->segsize == ptr->next->segptr) merge the two chunks
Abend_Service() : • [ Services SEGFAULT and ADRFAULT events] • Print message to *.out that process Uxxx (given by termtable[...]->user) has terminated due to segmentation fault or an address fault. • Call End_Service();
End_Service() : • [ Services PGMEND events] • Set PCB status to end and set active pcb to NULL • pcb->status = end; CPU.active_pcb = NULL; • If request block list is NULL, call Next_pgm(pcb) to advance the process script and prepare the next program for execution, if there is one • if (pcb->rb == NULL) Next_pgm(pcb);