1 / 12

CS 450

CS 450. Module R4. R4 Overview. Due on March 12 th along with R3. R4 is a small yet critical part of the MPX system. In this module, you will add the functionality to dynamically load MPX programs into the system.

Télécharger la présentation

CS 450

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.


Presentation Transcript

  1. CS 450 Module R4

  2. R4 Overview • Due on March 12th along with R3. • R4 is a small yet critical part of the MPX system. In this module, you will add the functionality to dynamically load MPX programs into the system. • We will load programs from files. The filename will also be the process name. • Functions • Load Program- load a single MPX process • Permanent Commands • Load- allows the user to load an MPX program • Terminate- allows the user to terminate a program

  3. Load Program Function • Parameters: • char[]: filename • The support functions we will use assume the .MPX extension, so this will not be part of the filename. For example, if we want to load “Proc1.mpx”, the parameter sent to this function would be “Proc1” • int: priority • Returns: void • Loads a single MPX process: • Allocates and sets up a new PCB • Allocates program memory • Loads a program into the allocated memory • Place new process in the queue

  4. Load Program • Check the arguments • Check that the priority is valid • Check that the process name is unique • Check the program • There is a support software function (sys_check_program) that checks that a program exists and is valid. More discussion on this later. • Create and setup the PCB • You should call your setup_pcb function • Process name should be the filename, the priority is passed as an argument to the load program function, and the class should be set to “Application” • Put the process in the ready, suspended state • Allocate the program’s memory (Set PCB values) • The memory size, load address, and execution address must be set. You will get the load address from sys_alloc_mem. The rest will come from the sys_check_program function. • You will also need to manually set some of the registers for the process: IP, CS, DS, ES and FLAGS • Load the program • There is a support software function (sys_load_program) that loads the program • If loaded without error, insert the PCB into the appropriate queue (ready or ready-suspended)

  5. Sys_check_program • intsys_check_program(char dir_name[], char prog_name[], int* prog_len_p, int* start_offset_p); • Returns int • 0: program is valid • ERR_SUP_NAMLNG: pathname too long • ERR_SUP_FILNFD: file not found • ERR_SUP_FILINV: file is not valid • Parameters • char[] dir_name • directory for the specified file. May use or “\0” with quotes to always search only the current directory- DO NOT USE “NULL”- it will not work! • char[] prog_name • Filename for the program to be checked. Assumed to have a .MPX extension • int* prog_len_p • Sys_check_program will put the program length, in bytes, into this integer variable. This is the exact number of bytes which has to be allocated for this program. • int* start_offset_p • Sys_check_program will put the offset in bytes from the start of the load area at which execution should begin

  6. Setting PCB Memory Values • memory_size • This should be set to the value returned by sys_check_program (the third parameter) • load_address • You will need to use sys_alloc_mem to allocate a memory block, with size memory_size. You should set the PCB’s load_address to the return value from sys_alloc_mem. Make sure you cast it to unsigned char* • load_address = (unsigned char*)sys_alloc_mem(-PCB’s memory size-) • execution_address • Set this equal to the load_address + start_offset_p • Start_offset_p is the fourth param in the sys_check_program call • Registers • You first need to create a context pointer to the PCB’s stack top- make sure you do this AFTER you have setup the PCB. • context cp* = (context *) pcb->stack_top • Set the IP & CS • IP = FP_OFF(execution_address) • CS = FP_SEG(execution_address) • Set the DS and ES to _DS, _ES • Set flags to 0x200

  7. Sys_load_program • int sys_check_program(void *load_addr, int max_size, char dir_name[], char prog_name[]); • Returns int • 0 if OK • Check manual for errors • Parameters • void* load_addr • Starting address of the memory region into which the program should be loaded. This is what is returned by sys_alloc_mem, and should be what you set the load_address of the PCB to. • int max_size • Size of the available memory. You will pass the PCB memory_size. • dir_name, prog_name • Same as sys_check_program

  8. Load command • We need a command to load processes • This should take in the program name as a parameter, optionally could take the priority as a parameter • If the priority is omitted, use a priority of zero • Program name should not include the extension • Suggested command name: load • This will be a permanent command, and replaces the Create PCB command (you may wish to leave the Create PCB command in for now though) • Display any appropriate error messages

  9. Terminate • Terminates a process by removing it from queues, deallocating its PCB and releasing its memory • Will need to modify your free_pcb function to free all memory allocated using sys_alloc_mem, including: • Load address • Stack base • The PCB itself • Should take the process name as argument • Replaces the Delete PCB command • Display any appropriate error messages • Should not allow a “SYSTEM” class process to be terminated. This will not be tested with R4 but will be critical in Module R6.

  10. Test MPX Programs • Located on Dr. Mooney’s Website under MPX Support Software • Download all of the test processes for assignment 4 (download the .MPX files, not the .ASM files). • Try loading them into your system, then resume them and call dispatcher to see how they execute.

  11. Tips • In your free-pcb function (from R2), make sure that you are freeing the the memory from the following addresses using sys_free_mem: • stack_base • load_address • The pcb itself • In the sys_check_program and sys_load_program functions, do not use “NULL”, use “’\0’” instead.

  12. Documentation • No documentation due, but you should update all existing manuals with any added functions/commands.

More Related