1 / 17

COP 4600

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() 

coyne
Download Presentation

COP 4600

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Objective # 3 COP 4600

  2. 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.

  3. Objective # 3 Interrupt_Handler()  Logon_Service()  • Creates a PCB  Read “Script.dat”  • Allocate memory And Load Program from user’s script ……………………

  4. 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

  5. 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 }

  6. 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.

  7. 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

  8. 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;

  9. 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 [pcbscript[pcbpgmid]]; 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.

  10. 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);

  11. 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.

  12. 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

  13. 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 pcbsegtable; free(pcbsegtable); pcb->segtable = NULL;

  14. 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()

  15. 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

  16. 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();

  17. 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);

More Related