The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+37 votes
4.2k views

A CPU has two modes -- privileged and non-privileged. In order to change the mode from privileged to non-privileged

  1. a hardware interrupt is needed
  2. a software interrupt is needed
  3. a privileged instruction (which does not generate an interrupt) is needed
  4. a non-privileged instruction (which does not generate an interrupt) is needed
asked in Operating System by Veteran (59.5k points)
edited by | 4.2k views

1 Answer

+35 votes
Best answer

Answer should be (D). Changing from privileged to non-privileged doesn't require an interrupt unlike from non-privileged to privileged. Also, to loose a privilege we don't need a privileged instruction though a privileged instruction does no harm. 

http://web.cse.ohio-state.edu/~teodores/download/teaching/cse675.au08/CSE675.02_MIPS-ISA_part3.pdf

answered by Veteran (357k points)
edited by
+2

@ruhul sharma 5

The mode bit is just a CPU register. It's only accessible if you're already in kernel mode.

First, see how we set the mode bit when we go from User mode to Kernel mode.

The details of how it gets set, depend on the CPU design. In most common hardware, it gets set automatically when executing a special opcode that's used to perform system calls. 

See here, it is not the kernel who set mode bit for himself to go into the kernel mode. It was automatically set through hardware by CPU.

You can read about this at here also.
https://stackoverflow.com/questions/13185300/where-is-the-mode-bit (2nd answer).

Now come to the kernel to user mode.

What I think.

A privileged instruction can set the mode bit to go to User mode from Kernel mode. And start executing the user instruction. There is no harm as the kernel has the access to the mode bit.

But it is not necessary. 

When we start executing a non-privileged instruction. Before its execution, the CPU detects it (as we did for system call by using opcode) and set the mode bit automatically.

As we can change mode bit with non-privileged instruction. D is the correct answer. Because we are not required to have a privileged instruction for it.

+18

To loose a privilege, you don't need privilege  - this line sums up the answer beautifully.

0
What does it mean in context to this question??
0
is this the same as privileged and non-privileged execution modes in Linux?
+1
switching from user mode to kernel mode do we require mode bit or software interrupt or hardware explain plz.
0
@bikram sir
Why option C is wrong?? As instruction can be privileged or non privileged also .
As u said mode bit can be changed by Some instruction
0
Why are these type of ambiguous questions asked in GATE in the first place? Clearly, both C and D are right.
+1
You must first do Mathematical Logic portion well to do well in GATE. The instruction can be privileged but that is not a necessity. This makes C option FALSE but that does not mean the instruction should not be privileged.
+1

The question really is who gets to modify the mode bit? Whether we consider the mode bit modification a privileged instruction or not?!?! What are the implications if we let the user modify the mode bit? When will we allow the user to modify it?

Let us allow the user to modify the mode bit. Now the problem that the mode bit tackles is so that the user doesn't execute any machine instructions. If we allow the user to modify, they can modify the mode bit and continue to execute a machine instruction at the user mode as the hardware might think it's the kernel who is executing the machine instruction as the mode bit is set to kernel mode. Now I maybe wrong because I don't know how this is implemented actually. I think that the explanations we've read so far from the books are simplified and it is a lot more complicated than that.

From what I understood, option C is the correct one. I may be wrong. I think that the modification of the mode bit is a privileged instruction. Because it will be impractical to allow the user to modify the mode bit no matter what mode it maybe be in.

0
******** **** ******


Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

39,825 questions
46,802 answers
140,973 comments
58,913 users