Stage 19
There are four events that result in generation of exception in XSM
1) Illegal Memory Access 2) Illegal Instruction 3) Arithmetic Exception 4) Page Fault
The registers dealing with exceptions
1) EC - Exception Cause 2) EIP - Exception IP 3) EPN - Exception Page Number 4) EMA - Exception Memory Access
The Page Fault Exception occurs when the last instruction in the currently running application fetches an instruction from an invalid page
The Exception Handler should resume the execution of the process after allocating the required pages for the process and attaching the pages to the process. If the fault page is a code page, the OS needs to load the page from the disk to the newly allocation memory.
No memory pages will be allocated to heap. Consequently, the entries in the page table corresponding to heap are set to invalid. For code blocks, only a single memory page is allocated and the first code block is loaded into that memory page
In this stage, we will write a new module Get Code Page in the memory manager module for simultaneously allocating a memory page and loading a code block.
Each process has a data structure called Per-Process Disk Map Table. The disk map table stores the disk block numbers corresponding to the memory pages used by the process. Each disk map has 10 words → 1 for user area page, 2 for heap, 4 for code and 2 for stack.
The Get Code Page takes an input the block number of a single code block. Code pages are shared by the processes running the same program. The purpose of this function is to find out if the current code block is already in use by some other process. This is done by going through the disk map table entries of all the processes checking for the code block. If found, then the Get Code Page checks if the code block is loaded into a memory page. If not it uses Get Free Page and Disk Load.
The Exception Handler uses EC register to find out the cause of the exception. As the exceptions cannot be corrected, exception handler must terminate the process by invoking the Exit Process and invoke the scheduler to schedule other processes.
eXpOS is designed such that page fault exception can only occur for heap and code pages.
