Loading W Code...
Deep Dive into System Calls, Dual-Mode Execution, Kernels & Interrupts
An Operating System (OS) is low-level software that acts as an intermediary layer between physical hardware components (CPU, RAM, Disks, Network Adapters) and application processes.
open, read, write) over block storage hardware.# C System Call Interface Example
#include <unistd.h>
#include <fcntl.h>
int main() {
// Low-level system call requesting OS to open file descriptor
int fd = open("log.txt", O_WRONLY | O_CREAT, 0644);
write(fd, "OS Architecture
", 16);
close(fd);
return 0;
}Operating systems are engineered around specific workload constraints and execution guarantees:
// Real-Time Periodic Task Scheduling (FreeRTOS)
void vPeriodicTask(void *pvParameters) {
TickType_t xLastWakeTime = xTaskGetTickCount();
const TickType_t xFrequency = pdMS_TO_TICKS(10); // 10ms hard deadline
for (;;) {
vTaskDelayUntil(&xLastWakeTime, xFrequency);
// Execute critical sensor reading
read_sensor_hardware();
}
}Modern CPUs support hardware protection levels (User Mode vs Kernel Mode) to prevent untrusted application software from compromising system integrity.
syscall on x86_64).; Assembly System Call (Linux x86_64)
mov rax, 1 ; sys_write system call number
mov rdi, 1 ; stdout file descriptor
mov rsi, msg ; pointer to buffer
mov rdx, 13 ; message length
syscall ; Trigger privilege switch to Kernel Mode (Ring 0)The Kernel is the foundational subsystem executing in privileged Ring 0 mode.
# Loading dynamic kernel modules in Linux Monolithic Kernel
sudo insmod custom_driver.ko
lsmod | grep custom_driver
sudo rmmod custom_driverAn Interrupt is an asynchronous signal sent to the processor by hardware or software requiring immediate CPU attention.
EFLAGS, CS, and EIP registers onto the kernel stack.IRET to restore user thread context.// Low-Level C Interrupt Handler Structure
void __attribute__((interrupt)) keyboard_isr(void *frame) {
uint8_t scancode = inb(0x60); // Read byte from Keyboard controller port
process_scancode(scancode);
outb(0x20, 0x20); // Send End of Interrupt (EOI) signal to PIC
}The OS boot process transitions physical hardware from uninitialized firmware state to user-space application execution:
vmlinuz) and initial RAM disk (initrd) into memory.initrd temporary root filesystem, and launches user space init process (PID 1 e.g., systemd).# Inspecting PID 1 system process hierarchy in Linux
ps -p 1 -o comm,pid,ppid,args
pstree -p 1