in Operating System edited by
14,315 views
58 votes

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
in Operating System edited by
14.3k views

8 Comments

is it self made ?
0
NO, i just remember it was asked i some test long back.
0
can anyone plz explain

"which does not generate an interrupt" why so?
0
If we reverse the question then  system call will be answer?????
0

can someone refer this question https://gateoverflow.in/445/gate2008-34 and clear the doubt as to what is the correct answer. As both question’s answer are contradicting each other.

Transitions from kernel to user mode are performed explicitly by the
operating system, generally at the end of an interrupt handler or
kernel call, using a privileged RFE (return from exception) instruction.

Source :– https://www.cs.rochester.edu/courses/252/spring2014/notes/08_exceptions

Can someone verify this and clear the doubt and contradictions both questions are creating.

@arjun Sir @Bikram Sir

1

 good doubt….See @arjun sir’s comment in below thread-

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.

So I think  privilege instruction can switch from kernel to  user mode(not necessary required  be privileged ) which is in the case of return from exception instruction. Return from exception is privilege instruction- this can be accepted as a  Fact.

correct me if wrong @arjun sir, @Bikram sir,

0
reshown by
with same logic option d can also be false as it is also not a necessity that instruction has to be non privileged to move from kernel to user mode
0

Subscribe to GO Classes for GATE CSE 2022

5 Answers

65 votes

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

edited by
by

26 Comments

edited by

But system in privileged mode right now, but as we have to move out to non- privileged.

then how can we use non privileged mode to move to non privileged mode..

1
which one is right answer B or D both seems correct.
0
@Amsar In privileged mode a non-privileged instruction can be executed.

@sv answer is D.
13
Wrong explanation. Could you please cross check.
0
Privileged mode==kernel mode
Non privileged mode==user mode
 From kernel to user mode, a non privileged instruction is required.
From user to kernel mode., a software interrupt is required.
hence D .
94
yes non privileged instruction can be executed in privilege mode,

but then it can also be executed by a user,.. So suppose system is in Privilege mode right now, and then a user program executes the non-privileged instruction to change to user mode.. Isn't that unfair?
0

This is from galvin and according to this answer should be C

3
edited by
No, ans D is correct.

You misinterpret the first line.

An instruction to switch to user mode is an example of a privileged mode ~ it want to say in priviledged mode only priviledged instructions can executed .

It does not say to change from priviledged to non priviledged which kind of intruction we need.

 From kernel to user mode, a non privileged instruction is required.
7
I did nt understand your last line. An instruction to switch to user mode is a privileged. So we are switching to  user mode and obviously from kernal mode.isnt this is asked in question?

What is asked in the question is clearly mentioned ?

How are you saying the two statments are equal in your last line @bikram sir?
0
edited by

See second last line .Taken from  here

Please clear this doubt sir

1

@rahul

Question askes " In order to change the mode from privileged to non-privileged " which kind of instruction is require ? answer is we require non priviledged instructions.

-----------

Now coming to above text,

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.

from user to kernel mode., a software interrupt is required. [ see the 3rd line ] .

The instruction that switch from supervisor mode to user mode is an example of a privileged instruction [ the last line said ] ..

when we are in priviledged mode we can run both priviledged and non priviledged instruction to shift towards 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 !! ]

now see here : http://web.cse.ohio-state.edu/~teodorescu.1/download/teaching/cse675.au08/CSE675.02_MIPS-ISA_part3.pdf

The processor leaves Kernel Mode and enters User Mode when the CPU mode bit is set to one (by some instruction)

CPU mode bit indicates the current CPU mode: 0 (=kernel) or 1 (=user).

see the state diagram there ..

so mode bit set to 1 means user mode ( the non priviledged instruction )

hence option D is correct.

5

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.

1

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.

8
edited by

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

3

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

36
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.
1
@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.
0
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.
2

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.

1

@Arjun SIR u are synonym for authenticity for facts , we dont need to cross check the stuff u mentioned , and these are mostly CRUX of some topic . 

Just wanted to thank u

0
Adding to @Bikram Sir's answer.

Is there any situation when hardware interrupt is also needed?
0
2 votes

The answer should be D. Changing from privileged to non-privileged doesn't require an interrupt unlike from non-privileged to privileged. Also, to lose a privilege we don't need a privileged instruction through a privileged instruction does no harm. 

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

Source: https://gateoverflow.in/706/gate2001-1-13

1 vote

To change from non privileged to privileged we require an interrupt known as software interrupt which is generated by a system call which gets translated into a privileged instruction. Option C would be apt.

Also The instructions that get executed in privileged mode will be privileged and never non-privileged. (The earlier answer which is supporting option D is having an absolutely wrong explanation)

reshown by

1 comment

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

So no privileged instructions or interrupts are required.

Ans is D only
1
1 vote

Answer is (c)

Transitions from kernel to user mode are performed explicitly by the
operating system, generally at the end of an interrupt handler or
kernel call, using a privileged RFE (return from exception) instruction.

Ref- http://www.cs.rochester.edu/courses/252/spring2014/notes/08_exceptions

reshown by

1 comment

Correct me if I am wrong
–1
0 votes

option c

it is puerlly decision of the operating system in which particular mode instruction is executed . and operating system is always executed in kernal mode(privileged mode).

Answer:

Related questions