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

1 Answer

+34 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 (339k points)
selected by
0

In the text you quoted it says " by some instruction.It never says it is previledged.

The second reference i shared clearly says "The instruction to switch from supervisor to kernel is privileged".

you said 

In priviledged mode ( or supervisor mode in above text ) both priviledged and Non priviledged instruction can run.[ see the 2nd line ] so that means a non priviledged instructions can take from supervisor mode to user mode.

Both privileged and non privileged can execute does not mean the non privileged can take from supervisor to user mode.

 

.[ here in book last line says priviledged instructions only executed in kernel mode or supervisor mode , it does not say which instruction take you from kernel mode to user mode !! ]

It clearly says in the last line.In second reference i shared.Please check again

0

@rahul

just go to 3rd slide here  http://web.cse.ohio-state.edu/~teodorescu.1/download/teaching/cse675.au08/CSE675.02_MIPS-ISA_part3.pdf

and check the state diagram , it is directly given that a non priviledged instruction takes kernel to user mode.

Where as in ur 2nd reference it only says in kernel mode only priviledged instruction can execute. 

0

Sir second reference says 

The instructions that switch from supervisor mode to kernal are previledged

The above os the direct line which is what asked in question.

In your reference it says

• Switching to user mode (from kernel mode) done by setting CPU mode bit (by an instruction).

I checked the state diagram on first page,it is no where written that a non priveledged takes control to user mode.

Even i am not able to find the text "non priviledged instruction " in the reference you are giving.

+6

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.

+1

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

+15

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?
0
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
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

34,942 questions
41,951 answers
119,194 comments
41,471 users