Chapter Two
Chapter Two
RECAP:
// write a c program that illustrates a simple system call.
#include <stdio.h> // header file to include std i/o header
#include<unistd.h>
#include<windows.h>
#include<fcntl.h>
int main() {
return 0;
}
WINDOWS SYSTEM PROGRAMMING FOR INTEL386
ARCHITECTURE.
2.1 Introduction to Intel386 Architecture
Intel386 (x86)
The Intel 386 (or 80386) processor introduced a major leap in personal computing
with its 32-bit architecture. It became the foundation for modern operating systems
and application development.
x86 Architecture: Refers to Intel's family of processors, starting from the 16-bit
8086 processor to 32-bit 80386, and beyond.
Protected Mode: The 80386 introduced protected mode, which allowed the OS to
control memory access, enabling multitasking and better stability.
Real Mode: For backwards compatibility, the 80386 could still operate in 16-bit
real mode, emulating earlier processors.
32-bit Programming
✓ The 80386 introduced a 32-bit flat memory model where addresses were
linear, allowing direct access to the entire 4 GB memory space without the
need for segmentation.
✓ More efficient code could be written since the flat memory model simplified
memory management, and the 32-bit registers could handle larger amounts
of data at once.
✓ 32-bit programs could leverage the processor's protected mode, which
improved security and stability by preventing programs from accessing other
processes' memory.
✓ Enhanced performance due to 32-bit arithmetic operations and wider data
paths.
✓ Ability to use larger data types (e.g., 32-bit integers) natively, improving
performance for certain applications.
API Differences
✓ 16-bit: Used older APIs like Win16 API.
✓ 32-bit: Introduced the Win32 API, providing more functionality and better
performance.
Multitasking
✓ 16-bit: Cooperative multitasking in Windows 3.x.
✓ 32-bit: Preemptive multitasking, allowing better system responsiveness and
true multitasking.
Resource Limits
✓ 16-bit: Limited system resources (e.g., GDI objects) shared among all
applications.
✓ 32-bit: Increased limits on system resources, with better isolation between
applications.
Compatibility
✓ 32-bit Windows can run 16-bit applications through the Windows on
Windows (WOW) subsystem.
✓ 16-bit Windows cannot run 32-bit applications natively.
Key Differences:
Windows Architecture:
a. User Mode:
➢ The part of the system where user applications run. These applications are
isolated from the core system components for security and stability.
➢ Subsystems: Windows provides various subsystems to support different
APIs (e.g., Windows API, POSIX). Applications interact with the OS
through these APIs.
b. Kernel Mode:
➢ The kernel is the heart of the OS, running in privileged mode (Ring 0). It
manages hardware, I/O devices, memory, and system processes.
Kernel Components:
i. Executive Services: Manages system-level services like process scheduling,
memory management, and I/O operations.
ii. Device Drivers: Kernel-mode programs that interact with hardware devices
to perform I/O operations.
iii. HAL (Hardware Abstraction Layer): Provides an abstraction between the OS
kernel and the hardware, allowing Windows to run on different hardware
architectures without changes to the OS core.
Core Components of Windows Kernel:
i. Memory Manager: Manages physical and virtual memory, and ensures
processes don’t interfere with each other's memory space.
ii. Process Manager: Handles process creation, scheduling, and termination.
Ensures fair CPU time distribution among processes.
iii. I/O Manager: Manages I/O operations for file systems, devices, and network
communication, ensuring efficient data transfer.
iv. Security Reference Monitor: Ensures processes and users only have access
to resources they are allowed to.
Driver Types
1. Kernel-Mode Drivers:
➢ Run in Ring 0 (highest privilege level) and interact directly with hardware.
➢ Examples: graphics drivers, disk drivers, network adapter drivers.
Types of Kernel-Mode Drivers:
i. File System Drivers: Manage file systems (e.g., NTFS, FAT32).
ii. Bus Drivers: Manage a bus controller, adapter, or bridge.
iii. Function Drivers: Main driver for a device, providing the operational
interface.
iv. Filter Drivers: Add value to or modify the behavior of other drivers.
2. User-Mode Drivers:
➢ Run in Ring 3 (user mode) and interact indirectly with the hardware.
➢ Examples: printer drivers, scanner drivers.
Advantages:
a. Enhanced system stability (crashes don't affect kernel).
b. Easier debugging and development.
c. Can leverage user-mode APIs and services.