Re: Doubt regarding stage 6

19 views
Skip to first unread message

Murali Krishnan

unread,
Aug 16, 2020, 5:09:20 AM8/16/20
to gagana k, xos-...@googlegroups.com, xos-developers
Dear Gagana,

  First, please join the google group xos-...@googlegroups.com and post questions to it, with a copy to kmu...@nitc.ac.in
  Please let me know if there are any difficulties in joining the group. Also, please inform everyone else to join the group. 
  I am copying the mail to the developers group so that the admin of the group can set permission to allow any person to join the users group. 
  Please tell other students too to join the users group. 

   Suppose you set the page table base register (PTBR) value to say Q=10 and then execute the IRET instruction to switch the machine to unprotected mode, the following changes happen:

1.  memory addresses for subsequent instructions are interpreted as logical addresses (and the physical addresses are determined by hardware paging).  This continues to be so until an interrupt (either hardware interrupt, or software trap - INT instruction) is executed or an EXCEPTION occurs. 

2.  If you had set PTBR to Q=10 before IRET,  for subsequent instructions, as the machine is running in unprotected mode,   logical address k is interpreted by the machine as physical address Q x page-size +k = 10 x 512 + k. 
In particular,  the start of your logical address space (k=0) will be from the physical memory address Q x pageize + 0 =10 x 512 = 5120.

3.  Now, what is the maximum value of k you can use in non-privileged mode?   That is determined by the value of PTLR.  If your OS code (previliged code)  has set PTLR=L=5 (as in your first example) before switching control to the application using IRET;  then the application's logical address space is limited to the range 0 to  L x page_size-1;  that is 0 to 5 x 512 - 1.  That is, the physical memory pages which your OS code is reserving for the application are Q x 512, (Q+1)x512, ....  (Q+L-1) x 512.  In this case, the allowed physical address range becomes 5120 to 5120 + 5 x 512 - 1.

4.  Now  what happens if an application tries to access beyond the limit?   (say Mov R0, [12000]).  Then the machine will generate an EXCEPTION and control will pass to the exception handler.   (Some exception flag registers will be set to certain values that help the exception handler code to figure out what caused the exception.  You will deal with this in Stage 19 in detail).  

5.  In your first example, you put the stack pointer at an address beyond the address space limit, the first time you access the stack, the machine would have generated an exception.  Since you haven't written any code to handle exception in page 2  (http://exposnitc.github.io/os_implementation.html), the simulator found no valid instruction to run and quit its operation.  That is what probability happened.  Try loading some "hello" code in the exception handler and you will see what exactly happened.  (You should definitely learn to run the machine in debug mode to figure out such things). 

6.  This security mechanism is necessary for the OS to stop applications from trying to access memory that is beyond its pre-set limit.  Otherwise, one program can run code that accesses memory beyond the limit and modify other programs which the OS would have loaded in memory.    

7.  Also please have a look at the tutorials given at the link:  http://exposnitc.github.io/Tutorials/xsm_index.html

Murali

Reply all
Reply to author
Forward
0 new messages