The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+38 votes
4.5k 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.6k points)
edited by | 4.5k views

1 Answer

+37 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 (362k points)
edited by
+7

rahul sharma 5 

See Kernel mode to user mode is done via an instruction so first 2 options we can safely remove as these hardware and software interrupts are not any instruction.

So we left with option C and D .

When you go from kernel mode to user mode , means you are going towards non priviledged mode , it is not necessary to be privileged to invoke the task . So non priviledged instruction can take from kernel to user mode. ( yes there is a slight chance that option C is correct but there is more chance/ possibility  for option D ) 

To be true what instruction is used is completely architecture-dependent. ( wheather it is priviledge or non priviledge )

Go through below discussion , read the comments against best answer 

https://cs.stackexchange.com/questions/11230/changing-from-kernel-mode-to-user-mode-and-vice-versa

and that Galvin snap you posted, was a typo ..

see this https://stackoverflow.com/questions/19057503/switching-from-user-mode-to-kernel-mode

----------

And here http://www.cs.princeton.edu/courses/archive/spr01/cs217/slides/21.os.pdf

it clearly mention that

 Operating systems hide privileged instructions and provide virtual

instructions to access and manipulate virtual resources, e.g., I/O to and

from disc files "

Virtual instructions are system calls .

-----

At the end we can say

To change the mode from kernel mode to user mode ...only a bit(mode bit) is changed in register ( by setting mode bit to 1 ), nothing else is required .

So no privileged instructions or interrupts are required. This makes option D correct.

+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.

+21

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.

Answer:

Related questions



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

42,514 questions
48,528 answers
155,008 comments
63,366 users