Reputation: 6290
SUPERVISOR MODE vs USER MODE
Why does the OS need this distinction?
I know that the Supervisor mode is for OS support and I know that the User mode is for application support. I vaguely understand that these are used in order to ensure that the user's operations only occur in user mode while the OS operations only occur in super mode. I'm just looking for a little more in-depth discussion to fill in any gaps i may be missing.
Thanks.
Upvotes: 0
Views: 2587
Reputation: 6290
Supervisory mode offers a second copy of a stack pointer. Both user stack and supervisor stack are in separate regions of memory. The stack pointer for the current task will point to either supervisory mode or user mode.
USP - A7: User stack pointer
SSP - A7: Supervisory stack pointer
Each mode has a stack pointer because each mode is self-contained thread of code - One for the current top level task, the other for the OS. If they both used the same stack there is a possibility that the operating system could bow the stack allocated for the user application. In other words. the OS may not know what the limits of the stack are in order to support any given operating system functionality.
It is much safer to have two separate stacks. If a system only has one stakc, the operating system has to adjust the stack pointer register on it's own to ensure that the different memory areas are used appropriately - ie. memory for the OS and memory for the task.
Upvotes: 1
Reputation: 170489
User mode prohibits certain operations - for example writes to random memory - to protect programs from one another. Supervisor mode allows those operations because the operating system needs them to perform stuff like input-output, starting programs and so on.
For example, look at memory protection. It prevents programs from writing to each other's memory. But in order for it to function the operating system needs to be able to setup memory pages mapping for each program. What if any program is allowed to setup that? There's no protection then - each program can subvert protection. This is why superuser mode is required to do that kind of operations - only operating system can do it and user programs can't.
Btw supervisor mode doesn't prohibit "user operations" - it allows anything.
Upvotes: 3