You are on page 1of 17

OO DESIGN LINUX KERNEL

INTERRUPTS SUBSYSTEM
● ABSTRACTION:

● The Hardware independent and Dependent

aspects to be separated

➔ Hardware Dependent ( Assembly Code)

➔ Device Interrupt Handlers

➔ Hardware Independent (Member Function)


Class Hierarchy
● Base Class – Interrupts

● Software Interrupt class will be derived from

Interrupts base class.

● Exceptions, System Calls and Signal

classes will be derived from Software

Interrupt Class
Implementation

● Hardware Interrupt class will be derived from


Interrupts base class.
● Wrapper function for the Global variables
● Static variables for the File global variable
EXCEPTIONS and SYSTEM CALLS
256 8-bit vectors on x86 (0..255):

Identify each interrupt or exception.

Vectors:

0..31 for exceptions & non-maskable interrupts.

32..47 for interrupts caused by IRQs.

48..255 for software interrupts.

Linux uses vector 128 (0x80) for system calls.


Overview

● Example Exceptions

# Exception Exception Handler Signal

0 Divide Error divide_error() SIGFPE


1 Debug debug() SIGTRAP

6 Invalid Opcode invalip_op() SIGILL

14 Page Fault page_fault() SIGSEGV


INITIALISATION OF SYSTEM
CALL VECTORS
● startup_32() code found in
/usr/src/linux/boot/head.S starts
everything off by calling setup_idt()
● sets up IDT with 256 * 8 byte vectors
● after paging has been enabled
● "start_kernel() (found in
/usr/src/linux/init/main.c)" is called
● this invokes "trap_init() (found in
/usr/src/linux/kernel/traps.c)"
INITIALISATION OF SYSTEM
CALL VECTORS
● trap_init() sets up the IDT via
"set_trap_gate() (found in
/usr/include/asm/system.h)"
● interrupt vector for the system calls is not
set up
● sched_init() (found in
/usr/src/linux/kernel/sched.c) calls
● set_system_gate (0x80, &system_call)
sets interrupt 0x80 to be a vector to the
system_call() entry point
SYSTEM CALLS
● A system call is a request by a running
task to the kernel to provide some sort
of service on its behalf.
● These servises are the ones for which
normal processes don't have previllage
for.
● e.g., the read system call will read data
from a file descriptor. To the
programmer, this looks like another C
function, but in actuality, the code for
read is contained within the kernel.
SYSTEM CALLS
● Implementing system calls requires a
control transfer between user mode to
kernel mode
● typical way to implement this is to use a
software interrupt or trap
Signals
● Event generated in response to a
condition, causing a process to take some
action when it receives the signal
– Contains number identifying signal
● May be raised due to
– Errors
– Generated by shell
– Sent from one process to another
● Process can handle or ignore a signal

10
Signal Transmission
● Sending
– Kernel updates descriptor of destination
process
● Receiving
– Kernel asks a target process to handle the
signal
● Pending signals
– Sent, but not received.

11
Data Structures
● sigaction
struct sigaction {
        __sighandler_t sa_handler;
        unsigned long sa_flags;
        __sigrestore_t sa_restorer;
        sigset_t sa_mask;
};

12
Data Structures
● sa_handler
– Signal handler
● sa_mask
– Specifies signals that are blocked
● sa_flags
– Flags to modify handler behavior –
SA_RESETHAND, SA_NODEFER
● sa_restorer
– Obsolete – Can be removed
13
Data Structures
● siginfo datastructure
– si_signo
– si_errno
– si_code
● sigqueue, sigpending

14
Signals
● Sending
– send_sig_info (int sig, struct siginfo *info,
struct task_struct *t)
● Sig – signal number
● Siginfo - Address of signal structure, 0, 1
● Receiving
– do_signal () / dequeue_signal () till all
unblocked pending signals are handled
– Signal should be caught or ignored,
otherwise, default action will be performed
● Catching
– handle_signal ()
15
Signals
● From a higher level, generated and
handled like interrupts

16
Thank you!

17

You might also like