0% found this document useful (0 votes)
4 views3 pages

As Hardware

The document explains the execution of user processes in UNIX systems, highlighting the distinction between user mode and kernel mode, including their access to instructions and data. It also discusses the handling of interrupts and exceptions, emphasizing the kernel's role in managing these events and the importance of processor execution levels for data integrity. Additionally, it covers memory management, detailing how the kernel allocates memory and translates virtual addresses to physical addresses for executing programs.

Uploaded by

girishvengg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

As Hardware

The document explains the execution of user processes in UNIX systems, highlighting the distinction between user mode and kernel mode, including their access to instructions and data. It also discusses the handling of interrupts and exceptions, emphasizing the kernel's role in managing these events and the importance of processor execution levels for data integrity. Additionally, it covers memory management, detailing how the kernel allocates memory and translates virtual addresses to physical addresses for executing programs.

Uploaded by

girishvengg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

1.5.

ASSUMPTIONS ABOUT HARDWARE

The execution of user processes on UNIX systems is divided into two levels: user and Kernel.
When a process executes a system call, the execution mode of the process changes from user
mode to kernel mode: the operating system executes and attempts to service the user request,
returning an error code if it fails. Even if the user makes no explicit requests for operating system
services, the operating system still does bookkeeping operations that relate to the user process,
handling interrupts, scheduling processes, managing memory, and so on. Many machine
architectures (and their operating systems) support more levels than the two outlined here, but
the two modes, user and kernel, are sufficient for UNIX systems.

The differences between the two modes are

• Processes in user mode can access their own instructions and data but not kernel instructions
and data (or those of other processes) . Processes in kernel mode, however, can access
kernel and user addresses. For example, the virtual address space of a process may be divided
between addresses that are accessible only in kernel mode and addresses that are accessible in
either mode.

• Some machine instructions are privileged and result in an error when executed in user mode.
For example, a machine may contain an instruction that manipulates the processor status
register; processes executing in user mode should not have this capability.

Put simply, the hardware views the world in terms of kernel mode and user mode and does not
distinguish among the many users executing programs in those modes. The operating system
keeps internal records to distinguish the many processes executing on the system. Figure 1.5
shows the distinction: the kernel distinguishes between processes A, B, C and D on the
horizontal axis, and the hardware distinguishes the mode of execution on the vertical axis.

Although the system executes in one of two modes, the kernel runs on behalf of a user process.
The kernel is not a separate set of processes that run in parallel to user processes, but it is part of
each user process. The ensuing text will frequently refer to "the kernel" allocating resources or
"the kernel" doing various operations, but what is meant is that a process executing in kernel
mode allocates the resources or does the various operations. For example, the shell reads user
terminal input via a system call: The kernel, executing on behalf of the shell process, controls
the operation of the terminal and returns the typed characters to the shell. The shell then
executes in user mode, interprets the character stream typed by the user, and does the specified
set of actions, which may require invocation of other system calls.

1.5.1 Interrupts and Exceptions


The UNIX system allows devices such as I/O peripherals or the system clock to interrupt the
CPU asynchronously. On receipt of the interrupt, the kernel saves its current context (a frozen
image of what the process was doing), determines the cause of the interrupt, and services the
interrupt. After the kernel services the interrupt, it restores its interrupted context and proceeds as
if nothing had happened. The hardware usually prioritizes devices according to the order that
interrupts should be handled: When the kernel services an interrupt, it blocks out lower priority
interrupts but services higher priority interrupts.
An exception condition refers to unexpected events caused by a process, such as addressing
illegal memory, executing privileged instructions, dividing by zero, and so on. They are distinct
from interrupts, which are caused by events that are external to a process. Exceptions happen "in
the middle" of the execution of an instruction, and the system attempts to restart the instruction
after handling the exception; interrupts are considered to happen between the execution of two
instructions, and the system continues with the next instruction after servicing the interrupt. The
UNIX system uses one mechanism to handle interrupts and exception conditions.

1.5.2 Processor Execution Levels

The kernel must sometimes prevent the occurrence of interrupts during critical activity, which
could result in corrupt data if interrupts were allowed. For instance, the kernel may not want to
receive a disk interrupt while manipulating linked lists, because handling the interrupt could
corrupt the pointers, as will be seen in the next chapter. Computers typically have a set of
privileged instructions that set the processor execution level in the processor status word. Setting
the processor execution level to certain values masks off interrupts from that level and lower
levels, allowing only higher level interrupts. Figure 1.6 shows a sample set of execution levels. If
the kernel masks out disk interrupt, all interrupts except for clock interrupts and machine error
interrupts are prevented. If it masks out software interrupts, all other interrupts may occur.

1.5.3 Memory Management

The kernel permanently resides in main memory as does the currently executing process (or parts
of it, at least). When compiling a program, the compiler generates a set of addresses in the
program that represent addresses of variables and data structures or the addresses of instructions
such as functions. The compiler generates the addresses for a virtual machine as if no other
program will execute simultaneously on the physical machine.
When the program is to run on the machine, the kernel allocates space in main memory for it, but
the virtual addresses generated by the compiler need not be-identical to the physical addresses
that they occupy in the machine. The kernel coordinates with the machine hardware to set up a
virtual to physical address translation that maps the compiler-generated addresses to the physical
machine addresses. The mapping depends on the capabilities of the machine hardware, and The
parts of UNIX systems that deal with them are therefore machine dependent. For example, some
machines have special hardware to support demand paging. Chapters 6 and 9 will discuss issues
of memory management and how they relate to hardware in more detail.

You might also like