R4 Dynamically loading processes. Overview R4 is closely related to R3, much of what you have written for R3 applies to R4 In R3, we executed procedures.

Slides:



Advertisements
Similar presentations
Dynamic memory allocation
Advertisements

Dynamic Memory Allocation in C.  What is Memory What is Memory  Memory Allocation in C Memory Allocation in C  Difference b\w static memory allocation.
1 Lecture 3: MIPS Instruction Set Today’s topic:  More MIPS instructions  Procedure call/return Reminder: Assignment 1 is on the class web-page (due.
The University of Adelaide, School of Computer Science
CS 450 Module R4. R4 Overview Due on March 11 th along with R3. R4 is a small yet critical part of the MPX system. In this module, you will add the functionality.
CS 450 Module R3. Next Week R2 is due next Friday ▫Make sure to correct all errors with R1 ▫Correct errors in the documentation as well, it will be checked.
CS 450 Module R1. R1 Introduction In Module R1, you will implement a user interface (command handler). There are a couple of options: ▫Command Line: interface.
1 Lecture 4: Procedure Calls Today’s topics:  Procedure calls  Large constants  The compilation process Reminder: Assignment 1 is due on Thursday.
Module R2 Overview. Process queues As processes enter the system and transition from state to state, they are stored queues. There may be many different.
Module R2 CS450. Next Week R1 is due next Friday ▫Bring manuals in a binder - make sure to have a cover page with group number, module, and date. You.
Computer Architecture CSCE 350
1 Computer Architecture MIPS Simulator and Assembly language.
Computer Organization CS224 Fall 2012 Lesson 12. Synchronization  Two processors or threads sharing an area of memory l P1 writes, then P2 reads l Data.
Debugging What can debuggers do? Run programs Make the program stops on specified places or on specified conditions Give information about current variables’
Tips for R3: Process Initialization When we create processes to represent our 5 test procedures we must correctly initialize its context by placing values.
Informática II Prof. Dr. Gustavo Patiño MJ
Process Description and Control Module 1.0. Major Requirements of an Operating System Interleave the execution of several processes to maximize processor.
Process Description and Control Chapter 3. Major Requirements of an Operating System Interleave the execution of several processes to maximize processor.
Processes CSCI 444/544 Operating Systems Fall 2008.
Figure 2.8 Compiler phases Compiling. Figure 2.9 Object module Linking.
Introduction to Operating Systems – Windows process and thread management In this lecture we will cover Threads and processes in Windows Thread priority.
1 Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation –The new operator –The delete operator –Dynamic.
Structure of DOS application programs. Contents: 1. PSP 2..COM and.EXE 3. TSR: Terminate and Stay Resident Programs.
Mehmet Can Vuran, Instructor University of Nebraska-Lincoln Acknowledgement: Overheads adapted from those provided by the authors of the textbook.
Operating Systems (CSCI2413) Lecture 3 Processes phones off (please)
Process Description and Control A process is sometimes called a task, it is a program in execution.
1 Procedural Concept The main program coordinates calls to procedures and hands over appropriate data as parameters.
Process Description and Control Chapter 3. Major Requirements of an OS Interleave the execution of several processes to maximize processor utilization.
CS 450 Module R6. Next Week R5 is due next Friday (April 3) No documentation, no source code due R5 is stand-alone, so I will not be checking errors from.
Runtime Environments What is in the memory? Runtime Environment2 Outline Memory organization during program execution Static runtime environments.
CS 450 Module R6. Next Week R5 is due Friday after Break ( April 1st ) ▫No documentation, no source code due ▫R5 is stand-alone, so I will not be checking.
OPERATING SYSTEM OVERVIEW. Contents Basic hardware elements.
Introduction to Processes CS Intoduction to Operating Systems.
FINAL MPX DELIVERABLE Due when you schedule your interview and presentation.
Chapter 41 Processes Chapter 4. 2 Processes  Multiprogramming operating systems are built around the concept of process (also called task).  A process.
Multiprogramming CSE451 Andrew Whitaker. Overview Multiprogramming: Running multiple programs “at the same time”  Requires multiplexing (sharing) the.
Chapter 4 Processes. Process: what is it? A program in execution A program in execution usually usually Can also have suspended or waiting processes Can.
Runtime Program Structure Command.com program supplied with MS- DOS and Windows (CMD.EXE for 2000 and XP)is called the command processor. It interprets.
1 C - Memory Simple Types Arrays Pointers Pointer to Pointer Multi-dimensional Arrays Dynamic Memory Allocation.
This set of notes is adapted from that provided by “Computer Science – A Structured Programming Approach Using C++”, B.A. Forouzan & R.F. Gilberg, Thomson.
CIS250 OPERATING SYSTEMS Memory Management Since we share memory, we need to manage it Memory manager only sees the address A program counter value indicates.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Device Drivers CPU I/O Interface Device Driver DEVICECONTROL OPERATIONSDATA TRANSFER OPERATIONS Disk Seek to Sector, Track, Cyl. Seek Home Position.
ITEC 502 컴퓨터 시스템 및 실습 Chapter 2-1: Process Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
Multiprogramming. Readings r Silberschatz, Galvin, Gagne, “Operating System Concepts”, 8 th edition: Chapter 3.1, 3.2.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
Dynamic Memory Allocation. Domain A subset of the total domain name space. A domain represents a level of the hierarchy in the Domain Name Space, and.
CS 450 Module R3. Today's Agenda R1 and R2 review Module R3 Introduction Schedule R1 Grading Next Week Module R4 Introduction.
CSNB374: Microprocessor Systems Chapter 5: Procedures and Interrupts.
Copyright 2005, The Ohio State University 1 Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation.
Module R3 Process Scheduling. Module R3 involves the creation of a simple “Round Robin” dispatcher. The successful completion of this module will require.
Functions in Assembly CS 210 Tutorial 7 Functions in Assembly Studwww.cs.auckland.ac.nz/ ~mngu012/public.html/210/7/
1 Computer Systems II Introduction to Processes. 2 First Two Major Computer System Evolution Steps Led to the idea of multiprogramming (multiple concurrent.
CSC 8505 Compiler Construction Runtime Environments.
Process Description and Control Chapter 3. Source Modified slides from Missouri U. of Science and Tech.
Processes 2 Introduction to Operating Systems: Module 4.
1 Module 3: Processes Reading: Chapter Next Module: –Inter-process Communication –Process Scheduling –Reading: Chapter 4.5, 6.1 – 6.3.
Multiprogramming. Readings r Chapter 2.1 of the textbook.
Processes and threads.
Computer Architecture & Operations I
Process concept.
Processes Overview: Process Concept Process Scheduling
Chapter 3: Processes.
Intro to Processes CSSE 332 Operating Systems
Pointers, Dynamic Data, and Reference Types
Process Description and Control
Processes in Unix and Windows
CS510 Operating System Foundations
Runtime Environments What is in the memory?.
Pointers, Dynamic Data, and Reference Types
Presentation transcript:

R4 Dynamically loading processes

Overview R4 is closely related to R3, much of what you have written for R3 applies to R4 In R3, we executed procedures which were statically linked to our MPX executable In R4, we will add command which will dynamically load an executable from disk into dynamically allocated memory. The location of this memory is to be stored into the PCB using the “Load” field, and the point at which execution is to begin in the loaded information should be stored in the “execute” field.

Suggested structure // PCB structure typedef struct PCB{ struct IOCB iocb; struct IOCB iocb; char pname[20]; //Process name at least 8 characters char pname[20]; //Process name at least 8 characters int pclass; //A code identifying the process as an int pclass; //A code identifying the process as an //application process or a system process //application process or a system process int priority; // range -128 ~ +127 int priority; // range -128 ~ +127 int state; // Running, Ready, Blocked, Suspended Ready, or int state; // Running, Ready, Blocked, Suspended Ready, or // Suspended blocked struct PCB * previous; // pointer of the previous PCB in the queue struct PCB * previous; // pointer of the previous PCB in the queue struct PCB * next; // pointer of the next PCB in the queue struct PCB * next; // pointer of the next PCB in the queue unsigned char * stack_base; // Stack pointer to the base unsigned char * stack_base; // Stack pointer to the base unsigned char *stack_p; //stackptr unsigned char *stack_p; //stackptr int memory; int memory; unsigned char *load; //pointer to where the process is loaded unsigned char *load; //pointer to where the process is loaded unsigned char *execution; //pointer to execution addr unsigned char *execution; //pointer to execution addr } PCB;

Components A “dispatch” command responsible for invoking the dispatcher for the first time. “Load program” command which replaces the “create process” command from R2. This command is responsible for creating and initializing a PCB and loading the program that the process will run. (it will use the commands from R2); “Terminate program” command is responsible for terminating a process and freeing the memory allocated to hold that processes program.

Hints and reminders Sys_call_handler this interrupt handler is invoked by the executing process, via the 8086 int instruction. Sys_call_handler should: Save the _SS and _SP into temporary variables. (these local variables should be static..) Save the _SS and _SP into temporary variables. (these local variables should be static..) Save the current stack information back into the PCB via MK_FP Save the current stack information back into the PCB via MK_FP SWITCH TO A LOCAL (STATIC) TEMPORARY STACK SWITCH TO A LOCAL (STATIC) TEMPORARY STACK Determine which action was initiated (IDLE or EXIT) Determine which action was initiated (IDLE or EXIT) Dispatch the next process. Dispatch the next process.

Dispatcher: Dispatches the ready processes in a round robin fashion. The PCB at the front of the queue becomes the running process. Use global variables to save the _SS and _SP of the 1 st program to invoke the dispatcher Use global variables to save the _SS and _SP of the 1 st program to invoke the dispatcher Get the next ready process Get the next ready process Restore the _SS and _SP from the “stack_pointer” in the PCB Restore the _SS and _SP from the “stack_pointer” in the PCB If there is no ready process, restore the _SS and _SP from the original calling process and exit the dispatcher. If there is no ready process, restore the _SS and _SP from the original calling process and exit the dispatcher.

MAJOR HINT(modifying _SP and _SS) If the value of these registers is to be altered, the _SS and _SP must be modified in this order SS then SP. It is important that they be modified by two consecutive machine instructions!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! This means via SIMPLE ASSIGNMENT STATEMENTS!!!! NOT ASSIGNMENTS CONTAINING FUNCTION CALLS!!! IDEALLY DON’T: _SS = FP_SEG(cop->stack_ptr); Instead: temp_ss = FP_SEG(cop->stack_ptr); temp_sp = FP_OFF(cop->stack_prt); temp_sp = FP_OFF(cop->stack_prt); _SS = temp_ss; _SP = temp_sp;

Changes with R4 Processes are no longer automatically loaded at the beginning of execution. The are not compiled into your MPX executable There is a special load command which will load a single process in the suspended state A dispatch command with will dispatch read processes There is a special Unload/kill/terminate command which will manually terminate a process.

Load Program Command This command is an expansion of “create PCB”. It should: Allocate and set up a new PCB Allocate and set up a new PCB It will receive the arguments: It will receive the arguments: Process name Program file name Priority Directory name (my addition to the project)

It will call “sys_check_program) to determine that the program file exists, determine the memory size it requires, and to calculate the “offset” at which execution is to begin in the loaded module. It will then call sys_alloc_mem to allocate memory in which the program executable will be loaded. This becomes the “load” address of the process. The “load address” + the “offset” becomes the execution address of the process “sys_load_program” is invoked to use the MS_DOS relocating loader to load the program into memory starting at the “load” address.

When created the new process should be placed in the suspended state. ( a resume command via the comhan is needed to place the process into the ready state.) The “context” of the process must also be initialized as in R3, however the CS and IP should be initialized using the “execute address” field from the PCB

The algorithm for this function is: 1.Check arguments 2.Check program 3.Create and setup PCB 4.Allocate program memory 5.Load program 6.Initialize PCB fields (load, execute, and memory size) 7.Set up PCB context 8.Place PCB into the suspended ready queue.

Terminate process This command should terminate a process by deallocating its PCB and releasing its allocated program memory. This is an extension of the Delete PCB command of Module R2. The PCB should be deallocated as in Delete PCB. In addition, the program memory must be released using the sys_free_mem support procedure. The only argument for this command is the process name. An error message should be displayed if the specified process does not exist

Dispatch Temporary command which dispatches the processes in the ready queue in round-robin order. It should be identical to your dispatcher in R3.

Sys_Check_program This routine attempts to access a program file to determine if it exists and is valid. The file specified must be in MS-DOS exe format. If the file is valid, this function also returns: the amount of memory which must be allocated to load the file the amount of memory which must be allocated to load the file The location (relative to the start of the load area) at which execution should begin. The location (relative to the start of the load area) at which execution should begin.

The prototype for the function is: int sys_check_program (char dir_name[], char prog_name[], int *prog_len_p, int *start_offset_p);

dir_name: specifies the pathname for the directory to be searched for the specified file. Only one directory will be searched. The pathname may be absolute or relative, and may contain a drive specifier; if it is null, the current directory will be searched. prog_name: specifies the file name for the program to be checked. This name should be given with no extension. The file is assumed to have the extension.MPX (although its type is EXE). prog_len_p: address of a variable of type int which will receive the program length in bytes. This specifies the exact number of bytes which must be allocated for loading this program (including code, data and stack segments). The MS-DOS loader requires that the allocated region be paragraph-aligned. start_offset_p: address of a variable of type int to receive the offset in bytes from the start of the load area at which execution should begin. This is assumed to be the first location in the code segment.

The returned value will be zero if no problem occurred; otherwise it will be an error code. Possible error codes are: ERR_SUP_NAMLNG pathname is too long ERR_SUP_NAMLNG pathname is too long ERR_SUP_FILNFD file not found ERR_SUP_FILNFD file not found ERR_SUP_FILINV file is not valid The symbols for these codes are defined in MPX_SUPT.H ERR_SUP_FILINV file is not valid The symbols for these codes are defined in MPX_SUPT.H

Sys_load_program This is called to request the actual loading of a program from a valid program file Uses the built-in relocating loader of MS-DOS The file is expected to be checked and measured using “sys_check_program” Calls “sys_check_program” again to verify the file size The prototype is: int sys_load_program (void *load_addr, int max_size, char dir_name[],char prog_name[]);

1. load_addr: specifies the starting address of the memory region into which the program should be loaded. This is normally the address returned by sys_alloc_mem. This address must be aligned on a paragraph boundary; all blocks allocated by sys_alloc_mem meet this criterion. 2.max_size: specifies the size of the available memory region. An error will be signaled if the program exceeds this size. In this case no loading will occur. 3.dir_name: specifies the pathname for the directory to be searched for the specified file. Only one directory will be searched. The pathname may be absolute or relative, and it may optionally include a drive specifier; if it is null, the current directory will be searched. 4.prog_name: Specifies the file name for the program to be loaded. This name should be given with no extension. The file is assumed to have the extension.MPX (although its type is EXE).

Errors The returned value will be zero if no problem occurred; otherwise it will be an error code. Possible error codes are: ERR_SUP_NAMLNG pathname is too long ERR_SUP_NAMLNG pathname is too long ERR_SUP_FILNFD file not found ERR_SUP_FILNFD file not found ERR_SUP_FILINV file is not valid ERR_SUP_FILINV file is not valid ERR_SUP_PROGSZ program too big for region ERR_SUP_PROGSZ program too big for region ERR_SUP_LDADDR invalid load address (e.g., not aligned) ERR_SUP_LDADDR invalid load address (e.g., not aligned) ERR_SUP_LDFAIL load failed ERR_SUP_LDFAIL load failed

Test processes 5 test procedures are provided for your use in testing R4: PROC1.MPX through PROC5.MPX Supplied with your support software. These execute similarly to R3, but execute until “terminated”