Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
SlideShare a Scribd company logo
LINUX Device Drivers Partha
Kernel The central component of operating system The bridge between applications and the hardware Manages the system's resources providing the lowest-level abstraction layer (especially processors and I/O devices) and makes these facilities available through inter-process communication mechanisms and system calls.
Monolithic Kernel All OS services run along with the main kernel thread, thus also residing in the same memory area.  This approach provides rich and powerful hardware access and increases the speed of the system The main disadvantages are the dependencies between system components and the fact that large kernels can become very difficult to maintain.
Micro Kernel Consists of defining a simple abstraction over the hardware, with a set of system calls to implement minimal OS services such as memory management etc. Other services, including those normally provided by the kernel such as networking, are implemented in user-space programs, referred to as servers. Easier to maintain, but the large number of system calls and context switches might slow down the system because they typically generate more overhead than plain function calls.
LINUX Kernel LINUX Kernel is monolithic with the capability of dynamically loading modules
System Call Interface Each call within the  libc  library is generally a  syscall X  macro, where 2 X+2  is the number of parameters used by the actual routine. Each syscall macro expands to an assembly routine which sets up the calling stack frame and calls _system_call() through an interrupt, via the instruction int  $0x80  which is used to transfer control to the kernel.  Assembly Code for Executing System Calls Since the system call interface is exclusively register-parametered, six parameters at most can be used with a single system call.  %eax  is the syscall number;  %ebx ,  %ecx ,  %edx ,  %esi ,  %edi  and  %ebp  are the six generic registers used as param0-5; and  %esp  cannot be used because it's overwritten by the kernel when it enters ring 0 (i.e., kernel mode). In case more parameters are needed, some structure can be placed wherever you want within your address space and pointed to from a register (not the instruction pointer, nor the stack pointer; the kernel-space functions use the stack for parameters and local variables). This case is extremely rare, though; most system calls have either no parameters or only one.
An Example read(fd,buffer,size)  corresponds to a system call with three arguments. So this will be expanded by the  _syscall3  macro. A statement  static inline syscall3(int,read,int,fd,char *,buf,off_t,len)   has been added in the header file for the macro expansion to take place. After the expansion the system call number will be in register 'zero' and the argument to the system call will be in the general purpose registers of the processor. Also the macro will call the  int 0x80  instruction after loading the registers. So the kernel mode is initiated and kernel will execute on behalf of the process initiated by the system call. The  int 0x80  instruction will call the system call handler. Each system call will have a routine or program defined in the kernel. Address of each of these routine are stored in the in array named  sys_call_table  (code in the file  /usr/src/linux-/arch/i386/kernel/entry.S ).The path name has to be filled accordingly for different kernel version. The system call handler will call the service routine corresponding to the system call, by looking at the system call number loaded in the register "zero". So the service routine corresponding to the read system call will be executed. After executing the service routing the control comes back to the system call handler and it will then give control back to the user process, also the mode of operation is changed to user mode.
Interrupt  Vector  0x80  is used to transfer control to the kernel. This interrupt vector is initialized during system startup, along with other important vectors such as the system clock vector.  The startup_32() code found in  /usr/src/linux/boot/head.S  starts everything off by calling  setup_idt() . This routine sets up an  IDT (Interrupt Descriptor Table)  with 256 entries. No interrupt entry points are actually loaded by this routine, as that is done only after paging has been enabled and the kernel has been moved to 0xC0000000. An IDT has 256 entries, each 4 bytes long, for a total of 1024 bytes. When start_kernel() (found in /usr/src/linux/init/main.c) is called it invokes trap_init() (found in /usr/src/linux/kernel/traps.c). trap_init() sets up the IDT via the macro set_trap_gate() (found in /usr/include/asm/system.h). trap_init() initializes the interrupt descriptor table as shown here:
User/kernel space User space is that portion of system memory in which user processes run. This contrasts with kernel space, which is that portion of memory in which the kernel executes and provides its services. Kernel space is where the kernel (i.e., the core of the operating system) executes (i.e., runs) and provides its services.
Characteristics of Kernel No conventional C library. Has its own Kernel version of C library.  Doesn’t support floating points No memory protection LINUX kernel (scheduler) is preemptive
LINUX Kernel Versioning Version number is x.y.z X – major version number Y – minor version number  (even is stable/production, odd is unstable/developer version) Z – release number
Device Drivers Softwares that interface hardwares with the OS Depending on data transmission there are three types Char device – byte transmission (keyboard) Block device – block transmission (hard disk) Network device – packet transmission (router, bridge) Implemented in two ways Statically loadable – automatically loaded with the OS image at the boot time Dynamically loadable – added to kernel space on demand
Compiling Driver Programs Cant compile in the conventional way using CC. Need to write makefile to include special files. Makefile priority –  makefile Makefile gnu_makefile To use the customized makefile use  make –f my_make_file
Programming Drivers Programs are called modules Like a main(), in driver programs the entry point is  init_module()  and exit is  cleanup_module() After compiling a .ko file is generated Using the utility  insmod  you can load your module in the kernel Insmod is the runtime linker which  Allocates memory  Uses .ko to generate an executable Adds executable to the kernel space
Programming Drivers II Using macros we can rename the entry/exit points module_init( my_entry ) Module_exit( my_exit )
Module Documentation Using macros we can document
Passing parameters to module Using macros we can pass
Passing parameters to module Process and threads are same in LINUX In UNIX they are different In any program we can use  struct task_struct *current  to see the process info i.e.  current->pid
Registration of modules  In init_module(), use  register_chrdev(major number,”name”,&fops)  It returns 0 on success and negative on failure Use  register_blkdev  for block device Declaration  struct file_operations fops. f ops contains all the driver function mapping to file functions (open, close, read, write)  These major numbers are reserved for dynamic modules 60-63 | 120-127 | 240-254 register function can also be used for a dynamic registration (set first argument zero) in which case the returned positive number is the major number or negative on failure Minor number is used for different devices for the same driver Network device is treated as socket We can start a virtual device using  mknod  command mknod LED c 254 0 12 bits for major number and 20 bits for minor number
File System Information in LINUX  Every open file has an integer  file descriptor  value that the operating system uses as an index to a  1024-entry  file descriptor table located in the  u (user) area   for the process. The per-process file descriptor table references a  system file table,  which is located in kernel space. In turn, the  system file table  maps to a  System Inode table  that contains a reference to a more complete internal description of the file.

More Related Content

What's hot

Linux Char Device Driver
Linux Char Device DriverLinux Char Device Driver
Linux Char Device Driver
Gary Yeh
 
Linux for embedded_systems
Linux for embedded_systemsLinux for embedded_systems
Linux for embedded_systems
Vandana Salve
 
Board support package_on_linux
Board support package_on_linuxBoard support package_on_linux
Board support package_on_linux
Vandana Salve
 
Device Drivers
Device DriversDevice Drivers
Device Drivers
Kushal Modi
 
Linux internal
Linux internalLinux internal
Linux internal
mcganesh
 
Device Drivers in Linux
Device Drivers in LinuxDevice Drivers in Linux
Device Drivers in Linux
Shreyas MM
 
Understanding Modern Device Drivers
Understanding Modern Device DriversUnderstanding Modern Device Drivers
Understanding Modern Device Drivers
asimkadav
 
Linux Kernel Tour
Linux Kernel TourLinux Kernel Tour
Linux Kernel Tour
samrat das
 
linux device driver
linux device driverlinux device driver
linux device driver
Rahul Batra
 
Linux Internals - Kernel/Core
Linux Internals - Kernel/CoreLinux Internals - Kernel/Core
Linux Internals - Kernel/Core
Shay Cohen
 
Linux architecture
Linux architectureLinux architecture
Linux architecture
mcganesh
 
Kernel Module Programming
Kernel Module ProgrammingKernel Module Programming
Kernel Module Programming
Saurabh Bangad
 
Part 02 Linux Kernel Module Programming
Part 02 Linux Kernel Module ProgrammingPart 02 Linux Kernel Module Programming
Part 02 Linux Kernel Module Programming
Tushar B Kute
 
Introduction To Linux Kernel Modules
Introduction To Linux Kernel ModulesIntroduction To Linux Kernel Modules
Introduction To Linux Kernel Modules
dibyajyotig
 
Basic Linux Internals
Basic Linux InternalsBasic Linux Internals
Basic Linux Internals
mukul bhardwaj
 
Linux kernel modules
Linux kernel modulesLinux kernel modules
Linux kernel modules
Eddy Reyes
 
Type of Embedded core
Type of Embedded core Type of Embedded core
Type of Embedded core
mukul bhardwaj
 
Linuxdd[1]
Linuxdd[1]Linuxdd[1]
Linuxdd[1]
mcganesh
 
Kernel modules
Kernel modulesKernel modules
Kernel modules
Elmàgic Àlàâ
 
Kernel mode vs user mode in linux
Kernel mode vs user mode in linuxKernel mode vs user mode in linux
Kernel mode vs user mode in linux
Siddique Ibrahim
 

What's hot (20)

Linux Char Device Driver
Linux Char Device DriverLinux Char Device Driver
Linux Char Device Driver
 
Linux for embedded_systems
Linux for embedded_systemsLinux for embedded_systems
Linux for embedded_systems
 
Board support package_on_linux
Board support package_on_linuxBoard support package_on_linux
Board support package_on_linux
 
Device Drivers
Device DriversDevice Drivers
Device Drivers
 
Linux internal
Linux internalLinux internal
Linux internal
 
Device Drivers in Linux
Device Drivers in LinuxDevice Drivers in Linux
Device Drivers in Linux
 
Understanding Modern Device Drivers
Understanding Modern Device DriversUnderstanding Modern Device Drivers
Understanding Modern Device Drivers
 
Linux Kernel Tour
Linux Kernel TourLinux Kernel Tour
Linux Kernel Tour
 
linux device driver
linux device driverlinux device driver
linux device driver
 
Linux Internals - Kernel/Core
Linux Internals - Kernel/CoreLinux Internals - Kernel/Core
Linux Internals - Kernel/Core
 
Linux architecture
Linux architectureLinux architecture
Linux architecture
 
Kernel Module Programming
Kernel Module ProgrammingKernel Module Programming
Kernel Module Programming
 
Part 02 Linux Kernel Module Programming
Part 02 Linux Kernel Module ProgrammingPart 02 Linux Kernel Module Programming
Part 02 Linux Kernel Module Programming
 
Introduction To Linux Kernel Modules
Introduction To Linux Kernel ModulesIntroduction To Linux Kernel Modules
Introduction To Linux Kernel Modules
 
Basic Linux Internals
Basic Linux InternalsBasic Linux Internals
Basic Linux Internals
 
Linux kernel modules
Linux kernel modulesLinux kernel modules
Linux kernel modules
 
Type of Embedded core
Type of Embedded core Type of Embedded core
Type of Embedded core
 
Linuxdd[1]
Linuxdd[1]Linuxdd[1]
Linuxdd[1]
 
Kernel modules
Kernel modulesKernel modules
Kernel modules
 
Kernel mode vs user mode in linux
Kernel mode vs user mode in linuxKernel mode vs user mode in linux
Kernel mode vs user mode in linux
 

Viewers also liked

Linux device drivers
Linux device drivers Linux device drivers
Device Drivers
Device DriversDevice Drivers
Device Drivers
Suhas S R
 
Ss4
Ss4Ss4
Software tools
Software toolsSoftware tools
Software tools
ravindravekariya
 
SAS Macros part 1
SAS Macros part 1SAS Macros part 1
SAS Macros part 1
venkatam
 
Introduction to compiler
Introduction to compilerIntroduction to compiler
Introduction to compiler
Abha Damani
 
Direct linking loader
Direct linking loaderDirect linking loader
Direct linking loader
babyparul
 
Lecture 11 semantic analysis 2
Lecture 11 semantic analysis 2Lecture 11 semantic analysis 2
Lecture 11 semantic analysis 2
Iffat Anjum
 
Module 11
Module 11Module 11
Module 11
bittudavis
 
Lex (lexical analyzer)
Lex (lexical analyzer)Lex (lexical analyzer)
Lex (lexical analyzer)
Sami Said
 
Introduction to embedded linux device driver and firmware
Introduction to embedded linux device driver and firmwareIntroduction to embedded linux device driver and firmware
Introduction to embedded linux device driver and firmware
definecareer
 
Ch5a
Ch5aCh5a
Top down and botttom up Parsing
Top down     and botttom up ParsingTop down     and botttom up Parsing
Top down and botttom up Parsing
Gerwin Ocsena
 
System Programming Unit II
System Programming Unit IISystem Programming Unit II
System Programming Unit II
Manoj Patil
 
System software
System softwareSystem software
System software
Senthil Kanth
 
Compiler vs Interpreter-Compiler design ppt.
Compiler vs Interpreter-Compiler design ppt.Compiler vs Interpreter-Compiler design ppt.
Compiler vs Interpreter-Compiler design ppt.
Md Hossen
 
Lexical analyzer
Lexical analyzerLexical analyzer
Lexical analyzer
Ashwini Sonawane
 
Phases of the Compiler - Systems Programming
Phases of the Compiler - Systems ProgrammingPhases of the Compiler - Systems Programming
Phases of the Compiler - Systems Programming
Mukesh Tekwani
 
Specification-of-tokens
Specification-of-tokensSpecification-of-tokens
Specification-of-tokens
Dattatray Gandhmal
 
Compiler Chapter 1
Compiler Chapter 1Compiler Chapter 1
Compiler Chapter 1
Huawei Technologies
 

Viewers also liked (20)

Linux device drivers
Linux device drivers Linux device drivers
Linux device drivers
 
Device Drivers
Device DriversDevice Drivers
Device Drivers
 
Ss4
Ss4Ss4
Ss4
 
Software tools
Software toolsSoftware tools
Software tools
 
SAS Macros part 1
SAS Macros part 1SAS Macros part 1
SAS Macros part 1
 
Introduction to compiler
Introduction to compilerIntroduction to compiler
Introduction to compiler
 
Direct linking loader
Direct linking loaderDirect linking loader
Direct linking loader
 
Lecture 11 semantic analysis 2
Lecture 11 semantic analysis 2Lecture 11 semantic analysis 2
Lecture 11 semantic analysis 2
 
Module 11
Module 11Module 11
Module 11
 
Lex (lexical analyzer)
Lex (lexical analyzer)Lex (lexical analyzer)
Lex (lexical analyzer)
 
Introduction to embedded linux device driver and firmware
Introduction to embedded linux device driver and firmwareIntroduction to embedded linux device driver and firmware
Introduction to embedded linux device driver and firmware
 
Ch5a
Ch5aCh5a
Ch5a
 
Top down and botttom up Parsing
Top down     and botttom up ParsingTop down     and botttom up Parsing
Top down and botttom up Parsing
 
System Programming Unit II
System Programming Unit IISystem Programming Unit II
System Programming Unit II
 
System software
System softwareSystem software
System software
 
Compiler vs Interpreter-Compiler design ppt.
Compiler vs Interpreter-Compiler design ppt.Compiler vs Interpreter-Compiler design ppt.
Compiler vs Interpreter-Compiler design ppt.
 
Lexical analyzer
Lexical analyzerLexical analyzer
Lexical analyzer
 
Phases of the Compiler - Systems Programming
Phases of the Compiler - Systems ProgrammingPhases of the Compiler - Systems Programming
Phases of the Compiler - Systems Programming
 
Specification-of-tokens
Specification-of-tokensSpecification-of-tokens
Specification-of-tokens
 
Compiler Chapter 1
Compiler Chapter 1Compiler Chapter 1
Compiler Chapter 1
 

Similar to LINUX Device Drivers

Introduction to Assembly Language Programming
Introduction to Assembly Language ProgrammingIntroduction to Assembly Language Programming
Introduction to Assembly Language Programming
Rahul P
 
managing kernal module from egineering sunject operating system
managing kernal module from egineering sunject operating systemmanaging kernal module from egineering sunject operating system
managing kernal module from egineering sunject operating system
mohammadshahnawaz77
 
Os notes
Os notesOs notes
Os notes
LakshmiSarvani6
 
Part 04 Creating a System Call in Linux
Part 04 Creating a System Call in LinuxPart 04 Creating a System Call in Linux
Part 04 Creating a System Call in Linux
Tushar B Kute
 
Trap Handling in Linux
Trap Handling in LinuxTrap Handling in Linux
Trap Handling in Linux
YongraeJo
 
Operating System Concepts Presentation
Operating System Concepts PresentationOperating System Concepts Presentation
Operating System Concepts Presentation
Nitish Jadia
 
Implementation of Kernel API
Implementation of Kernel APIImplementation of Kernel API
Implementation of Kernel API
khushi74
 
Unix fundamentals
Unix fundamentalsUnix fundamentals
Unix fundamentals
Bimal Jain
 
Operating system ppt
Operating system pptOperating system ppt
Operating system ppt
kaviya kumaresan
 
Operating system ppt
Operating system pptOperating system ppt
Operating system ppt
kaviya kumaresan
 
Operating system ppt
Operating system pptOperating system ppt
Operating system ppt
kaviya kumaresan
 
Operating system ppt
Operating system pptOperating system ppt
Operating system ppt
kaviya kumaresan
 
Structure of operating system
Structure of operating systemStructure of operating system
Structure of operating system
Rafi Dar
 
Operating system
Operating systemOperating system
Operating system
Kinza Razzaq
 
Linux startup
Linux startupLinux startup
Linux startup
Amin Hashemi
 
M.c.a. (sem ii) operating systems
M.c.a. (sem   ii) operating systemsM.c.a. (sem   ii) operating systems
M.c.a. (sem ii) operating systems
Tushar Rajput
 
How To Add System Call In Ubuntu OS
How To Add System Call In Ubuntu OSHow To Add System Call In Ubuntu OS
How To Add System Call In Ubuntu OS
Pratik Tambekar
 
Basic Organisation and fundamental Of Computer.pptx
Basic Organisation and fundamental Of Computer.pptxBasic Organisation and fundamental Of Computer.pptx
Basic Organisation and fundamental Of Computer.pptx
hasanbashar400
 
Ch04
Ch04Ch04
Ch04 system administration
Ch04 system administration Ch04 system administration
Ch04 system administration
Raja Waseem Akhtar
 

Similar to LINUX Device Drivers (20)

Introduction to Assembly Language Programming
Introduction to Assembly Language ProgrammingIntroduction to Assembly Language Programming
Introduction to Assembly Language Programming
 
managing kernal module from egineering sunject operating system
managing kernal module from egineering sunject operating systemmanaging kernal module from egineering sunject operating system
managing kernal module from egineering sunject operating system
 
Os notes
Os notesOs notes
Os notes
 
Part 04 Creating a System Call in Linux
Part 04 Creating a System Call in LinuxPart 04 Creating a System Call in Linux
Part 04 Creating a System Call in Linux
 
Trap Handling in Linux
Trap Handling in LinuxTrap Handling in Linux
Trap Handling in Linux
 
Operating System Concepts Presentation
Operating System Concepts PresentationOperating System Concepts Presentation
Operating System Concepts Presentation
 
Implementation of Kernel API
Implementation of Kernel APIImplementation of Kernel API
Implementation of Kernel API
 
Unix fundamentals
Unix fundamentalsUnix fundamentals
Unix fundamentals
 
Operating system ppt
Operating system pptOperating system ppt
Operating system ppt
 
Operating system ppt
Operating system pptOperating system ppt
Operating system ppt
 
Operating system ppt
Operating system pptOperating system ppt
Operating system ppt
 
Operating system ppt
Operating system pptOperating system ppt
Operating system ppt
 
Structure of operating system
Structure of operating systemStructure of operating system
Structure of operating system
 
Operating system
Operating systemOperating system
Operating system
 
Linux startup
Linux startupLinux startup
Linux startup
 
M.c.a. (sem ii) operating systems
M.c.a. (sem   ii) operating systemsM.c.a. (sem   ii) operating systems
M.c.a. (sem ii) operating systems
 
How To Add System Call In Ubuntu OS
How To Add System Call In Ubuntu OSHow To Add System Call In Ubuntu OS
How To Add System Call In Ubuntu OS
 
Basic Organisation and fundamental Of Computer.pptx
Basic Organisation and fundamental Of Computer.pptxBasic Organisation and fundamental Of Computer.pptx
Basic Organisation and fundamental Of Computer.pptx
 
Ch04
Ch04Ch04
Ch04
 
Ch04 system administration
Ch04 system administration Ch04 system administration
Ch04 system administration
 

Recently uploaded

Multimodal Embeddings (continued) - South Bay Meetup Slides
Multimodal Embeddings (continued) - South Bay Meetup SlidesMultimodal Embeddings (continued) - South Bay Meetup Slides
Multimodal Embeddings (continued) - South Bay Meetup Slides
Zilliz
 
Best USA IPTV Providers to Stream in 2024.pdf
Best USA IPTV Providers to Stream in 2024.pdfBest USA IPTV Providers to Stream in 2024.pdf
Best USA IPTV Providers to Stream in 2024.pdf
perth Riya
 
Planetek Italia Corporate Profile Brochure
Planetek Italia Corporate Profile BrochurePlanetek Italia Corporate Profile Brochure
Planetek Italia Corporate Profile Brochure
Planetek Italia Srl
 
FIDO Munich Seminar Workforce Authentication Case Study.pptx
FIDO Munich Seminar Workforce Authentication Case Study.pptxFIDO Munich Seminar Workforce Authentication Case Study.pptx
FIDO Munich Seminar Workforce Authentication Case Study.pptx
FIDO Alliance
 
Indian Privacy law & Infosec for Startups
Indian Privacy law & Infosec for StartupsIndian Privacy law & Infosec for Startups
Indian Privacy law & Infosec for Startups
AMol NAik
 
Using ScyllaDB for Real-Time Write-Heavy Workloads
Using ScyllaDB for Real-Time Write-Heavy WorkloadsUsing ScyllaDB for Real-Time Write-Heavy Workloads
Using ScyllaDB for Real-Time Write-Heavy Workloads
ScyllaDB
 
The Challenge of Interpretability in Generative AI Models.pdf
The Challenge of Interpretability in Generative AI Models.pdfThe Challenge of Interpretability in Generative AI Models.pdf
The Challenge of Interpretability in Generative AI Models.pdf
Sara Kroft
 
AMD Zen 5 Architecture Deep Dive from Tech Day
AMD Zen 5 Architecture Deep Dive from Tech DayAMD Zen 5 Architecture Deep Dive from Tech Day
AMD Zen 5 Architecture Deep Dive from Tech Day
Low Hong Chuan
 
TribeQonf2024_Dimpy_ShiftingSecurityLeft
TribeQonf2024_Dimpy_ShiftingSecurityLeftTribeQonf2024_Dimpy_ShiftingSecurityLeft
TribeQonf2024_Dimpy_ShiftingSecurityLeft
Dimpy Adhikary
 
CI/CD pipelines for CloudHub 2.0 - Wroclaw MuleSoft Meetup #2
CI/CD pipelines for CloudHub 2.0 - Wroclaw MuleSoft Meetup #2CI/CD pipelines for CloudHub 2.0 - Wroclaw MuleSoft Meetup #2
CI/CD pipelines for CloudHub 2.0 - Wroclaw MuleSoft Meetup #2
wromeetup
 
Securiport Gambia - Intelligent Threat Analysis
Securiport Gambia - Intelligent Threat AnalysisSecuriport Gambia - Intelligent Threat Analysis
Securiport Gambia - Intelligent Threat Analysis
Securiport Gambia
 
Mega MUG 2024: Working smarter in Marketo
Mega MUG 2024: Working smarter in MarketoMega MUG 2024: Working smarter in Marketo
Mega MUG 2024: Working smarter in Marketo
Stephanie Tyagita
 
FIDO Munich Seminar: Strong Workforce Authn Push & Pull Factors.pptx
FIDO Munich Seminar: Strong Workforce Authn Push & Pull Factors.pptxFIDO Munich Seminar: Strong Workforce Authn Push & Pull Factors.pptx
FIDO Munich Seminar: Strong Workforce Authn Push & Pull Factors.pptx
FIDO Alliance
 
STKI Israeli IT Market Study v2 August 2024.pdf
STKI Israeli IT Market Study v2 August 2024.pdfSTKI Israeli IT Market Study v2 August 2024.pdf
STKI Israeli IT Market Study v2 August 2024.pdf
Dr. Jimmy Schwarzkopf
 
SuratMeetup-MuleSoft + Salt Security for API Security.pptx
SuratMeetup-MuleSoft + Salt Security for API Security.pptxSuratMeetup-MuleSoft + Salt Security for API Security.pptx
SuratMeetup-MuleSoft + Salt Security for API Security.pptx
nitishjain2015
 
Informatika smk kelas 10 kurikulum merdeka.pptx
Informatika smk kelas 10 kurikulum merdeka.pptxInformatika smk kelas 10 kurikulum merdeka.pptx
Informatika smk kelas 10 kurikulum merdeka.pptx
OkyPrayudi
 
FIDO Munich Seminar: Securing Smart Car.pptx
FIDO Munich Seminar: Securing Smart Car.pptxFIDO Munich Seminar: Securing Smart Car.pptx
FIDO Munich Seminar: Securing Smart Car.pptx
FIDO Alliance
 
FIDO Munich Seminar: FIDO Tech Principles.pptx
FIDO Munich Seminar: FIDO Tech Principles.pptxFIDO Munich Seminar: FIDO Tech Principles.pptx
FIDO Munich Seminar: FIDO Tech Principles.pptx
FIDO Alliance
 
Scientific-Based Blockchain TON Project Analysis Report
Scientific-Based Blockchain  TON Project Analysis ReportScientific-Based Blockchain  TON Project Analysis Report
Scientific-Based Blockchain TON Project Analysis Report
SelcukTOPAL2
 
FIDO Munich Seminar: Biometrics and Passkeys for In-Vehicle Apps.pptx
FIDO Munich Seminar: Biometrics and Passkeys for In-Vehicle Apps.pptxFIDO Munich Seminar: Biometrics and Passkeys for In-Vehicle Apps.pptx
FIDO Munich Seminar: Biometrics and Passkeys for In-Vehicle Apps.pptx
FIDO Alliance
 

Recently uploaded (20)

Multimodal Embeddings (continued) - South Bay Meetup Slides
Multimodal Embeddings (continued) - South Bay Meetup SlidesMultimodal Embeddings (continued) - South Bay Meetup Slides
Multimodal Embeddings (continued) - South Bay Meetup Slides
 
Best USA IPTV Providers to Stream in 2024.pdf
Best USA IPTV Providers to Stream in 2024.pdfBest USA IPTV Providers to Stream in 2024.pdf
Best USA IPTV Providers to Stream in 2024.pdf
 
Planetek Italia Corporate Profile Brochure
Planetek Italia Corporate Profile BrochurePlanetek Italia Corporate Profile Brochure
Planetek Italia Corporate Profile Brochure
 
FIDO Munich Seminar Workforce Authentication Case Study.pptx
FIDO Munich Seminar Workforce Authentication Case Study.pptxFIDO Munich Seminar Workforce Authentication Case Study.pptx
FIDO Munich Seminar Workforce Authentication Case Study.pptx
 
Indian Privacy law & Infosec for Startups
Indian Privacy law & Infosec for StartupsIndian Privacy law & Infosec for Startups
Indian Privacy law & Infosec for Startups
 
Using ScyllaDB for Real-Time Write-Heavy Workloads
Using ScyllaDB for Real-Time Write-Heavy WorkloadsUsing ScyllaDB for Real-Time Write-Heavy Workloads
Using ScyllaDB for Real-Time Write-Heavy Workloads
 
The Challenge of Interpretability in Generative AI Models.pdf
The Challenge of Interpretability in Generative AI Models.pdfThe Challenge of Interpretability in Generative AI Models.pdf
The Challenge of Interpretability in Generative AI Models.pdf
 
AMD Zen 5 Architecture Deep Dive from Tech Day
AMD Zen 5 Architecture Deep Dive from Tech DayAMD Zen 5 Architecture Deep Dive from Tech Day
AMD Zen 5 Architecture Deep Dive from Tech Day
 
TribeQonf2024_Dimpy_ShiftingSecurityLeft
TribeQonf2024_Dimpy_ShiftingSecurityLeftTribeQonf2024_Dimpy_ShiftingSecurityLeft
TribeQonf2024_Dimpy_ShiftingSecurityLeft
 
CI/CD pipelines for CloudHub 2.0 - Wroclaw MuleSoft Meetup #2
CI/CD pipelines for CloudHub 2.0 - Wroclaw MuleSoft Meetup #2CI/CD pipelines for CloudHub 2.0 - Wroclaw MuleSoft Meetup #2
CI/CD pipelines for CloudHub 2.0 - Wroclaw MuleSoft Meetup #2
 
Securiport Gambia - Intelligent Threat Analysis
Securiport Gambia - Intelligent Threat AnalysisSecuriport Gambia - Intelligent Threat Analysis
Securiport Gambia - Intelligent Threat Analysis
 
Mega MUG 2024: Working smarter in Marketo
Mega MUG 2024: Working smarter in MarketoMega MUG 2024: Working smarter in Marketo
Mega MUG 2024: Working smarter in Marketo
 
FIDO Munich Seminar: Strong Workforce Authn Push & Pull Factors.pptx
FIDO Munich Seminar: Strong Workforce Authn Push & Pull Factors.pptxFIDO Munich Seminar: Strong Workforce Authn Push & Pull Factors.pptx
FIDO Munich Seminar: Strong Workforce Authn Push & Pull Factors.pptx
 
STKI Israeli IT Market Study v2 August 2024.pdf
STKI Israeli IT Market Study v2 August 2024.pdfSTKI Israeli IT Market Study v2 August 2024.pdf
STKI Israeli IT Market Study v2 August 2024.pdf
 
SuratMeetup-MuleSoft + Salt Security for API Security.pptx
SuratMeetup-MuleSoft + Salt Security for API Security.pptxSuratMeetup-MuleSoft + Salt Security for API Security.pptx
SuratMeetup-MuleSoft + Salt Security for API Security.pptx
 
Informatika smk kelas 10 kurikulum merdeka.pptx
Informatika smk kelas 10 kurikulum merdeka.pptxInformatika smk kelas 10 kurikulum merdeka.pptx
Informatika smk kelas 10 kurikulum merdeka.pptx
 
FIDO Munich Seminar: Securing Smart Car.pptx
FIDO Munich Seminar: Securing Smart Car.pptxFIDO Munich Seminar: Securing Smart Car.pptx
FIDO Munich Seminar: Securing Smart Car.pptx
 
FIDO Munich Seminar: FIDO Tech Principles.pptx
FIDO Munich Seminar: FIDO Tech Principles.pptxFIDO Munich Seminar: FIDO Tech Principles.pptx
FIDO Munich Seminar: FIDO Tech Principles.pptx
 
Scientific-Based Blockchain TON Project Analysis Report
Scientific-Based Blockchain  TON Project Analysis ReportScientific-Based Blockchain  TON Project Analysis Report
Scientific-Based Blockchain TON Project Analysis Report
 
FIDO Munich Seminar: Biometrics and Passkeys for In-Vehicle Apps.pptx
FIDO Munich Seminar: Biometrics and Passkeys for In-Vehicle Apps.pptxFIDO Munich Seminar: Biometrics and Passkeys for In-Vehicle Apps.pptx
FIDO Munich Seminar: Biometrics and Passkeys for In-Vehicle Apps.pptx
 

LINUX Device Drivers

  • 2. Kernel The central component of operating system The bridge between applications and the hardware Manages the system's resources providing the lowest-level abstraction layer (especially processors and I/O devices) and makes these facilities available through inter-process communication mechanisms and system calls.
  • 3. Monolithic Kernel All OS services run along with the main kernel thread, thus also residing in the same memory area. This approach provides rich and powerful hardware access and increases the speed of the system The main disadvantages are the dependencies between system components and the fact that large kernels can become very difficult to maintain.
  • 4. Micro Kernel Consists of defining a simple abstraction over the hardware, with a set of system calls to implement minimal OS services such as memory management etc. Other services, including those normally provided by the kernel such as networking, are implemented in user-space programs, referred to as servers. Easier to maintain, but the large number of system calls and context switches might slow down the system because they typically generate more overhead than plain function calls.
  • 5. LINUX Kernel LINUX Kernel is monolithic with the capability of dynamically loading modules
  • 6. System Call Interface Each call within the libc library is generally a syscall X macro, where 2 X+2 is the number of parameters used by the actual routine. Each syscall macro expands to an assembly routine which sets up the calling stack frame and calls _system_call() through an interrupt, via the instruction int $0x80 which is used to transfer control to the kernel. Assembly Code for Executing System Calls Since the system call interface is exclusively register-parametered, six parameters at most can be used with a single system call. %eax is the syscall number; %ebx , %ecx , %edx , %esi , %edi and %ebp are the six generic registers used as param0-5; and %esp cannot be used because it's overwritten by the kernel when it enters ring 0 (i.e., kernel mode). In case more parameters are needed, some structure can be placed wherever you want within your address space and pointed to from a register (not the instruction pointer, nor the stack pointer; the kernel-space functions use the stack for parameters and local variables). This case is extremely rare, though; most system calls have either no parameters or only one.
  • 7. An Example read(fd,buffer,size) corresponds to a system call with three arguments. So this will be expanded by the _syscall3 macro. A statement static inline syscall3(int,read,int,fd,char *,buf,off_t,len) has been added in the header file for the macro expansion to take place. After the expansion the system call number will be in register 'zero' and the argument to the system call will be in the general purpose registers of the processor. Also the macro will call the int 0x80 instruction after loading the registers. So the kernel mode is initiated and kernel will execute on behalf of the process initiated by the system call. The int 0x80 instruction will call the system call handler. Each system call will have a routine or program defined in the kernel. Address of each of these routine are stored in the in array named sys_call_table (code in the file /usr/src/linux-/arch/i386/kernel/entry.S ).The path name has to be filled accordingly for different kernel version. The system call handler will call the service routine corresponding to the system call, by looking at the system call number loaded in the register "zero". So the service routine corresponding to the read system call will be executed. After executing the service routing the control comes back to the system call handler and it will then give control back to the user process, also the mode of operation is changed to user mode.
  • 8. Interrupt Vector 0x80 is used to transfer control to the kernel. This interrupt vector is initialized during system startup, along with other important vectors such as the system clock vector. The startup_32() code found in /usr/src/linux/boot/head.S starts everything off by calling setup_idt() . This routine sets up an IDT (Interrupt Descriptor Table) with 256 entries. No interrupt entry points are actually loaded by this routine, as that is done only after paging has been enabled and the kernel has been moved to 0xC0000000. An IDT has 256 entries, each 4 bytes long, for a total of 1024 bytes. When start_kernel() (found in /usr/src/linux/init/main.c) is called it invokes trap_init() (found in /usr/src/linux/kernel/traps.c). trap_init() sets up the IDT via the macro set_trap_gate() (found in /usr/include/asm/system.h). trap_init() initializes the interrupt descriptor table as shown here:
  • 9. User/kernel space User space is that portion of system memory in which user processes run. This contrasts with kernel space, which is that portion of memory in which the kernel executes and provides its services. Kernel space is where the kernel (i.e., the core of the operating system) executes (i.e., runs) and provides its services.
  • 10. Characteristics of Kernel No conventional C library. Has its own Kernel version of C library. Doesn’t support floating points No memory protection LINUX kernel (scheduler) is preemptive
  • 11. LINUX Kernel Versioning Version number is x.y.z X – major version number Y – minor version number (even is stable/production, odd is unstable/developer version) Z – release number
  • 12. Device Drivers Softwares that interface hardwares with the OS Depending on data transmission there are three types Char device – byte transmission (keyboard) Block device – block transmission (hard disk) Network device – packet transmission (router, bridge) Implemented in two ways Statically loadable – automatically loaded with the OS image at the boot time Dynamically loadable – added to kernel space on demand
  • 13. Compiling Driver Programs Cant compile in the conventional way using CC. Need to write makefile to include special files. Makefile priority – makefile Makefile gnu_makefile To use the customized makefile use make –f my_make_file
  • 14. Programming Drivers Programs are called modules Like a main(), in driver programs the entry point is init_module() and exit is cleanup_module() After compiling a .ko file is generated Using the utility insmod you can load your module in the kernel Insmod is the runtime linker which Allocates memory Uses .ko to generate an executable Adds executable to the kernel space
  • 15. Programming Drivers II Using macros we can rename the entry/exit points module_init( my_entry ) Module_exit( my_exit )
  • 16. Module Documentation Using macros we can document
  • 17. Passing parameters to module Using macros we can pass
  • 18. Passing parameters to module Process and threads are same in LINUX In UNIX they are different In any program we can use struct task_struct *current to see the process info i.e. current->pid
  • 19. Registration of modules In init_module(), use register_chrdev(major number,”name”,&fops) It returns 0 on success and negative on failure Use register_blkdev for block device Declaration struct file_operations fops. f ops contains all the driver function mapping to file functions (open, close, read, write) These major numbers are reserved for dynamic modules 60-63 | 120-127 | 240-254 register function can also be used for a dynamic registration (set first argument zero) in which case the returned positive number is the major number or negative on failure Minor number is used for different devices for the same driver Network device is treated as socket We can start a virtual device using mknod command mknod LED c 254 0 12 bits for major number and 20 bits for minor number
  • 20. File System Information in LINUX Every open file has an integer  file descriptor  value that the operating system uses as an index to a  1024-entry  file descriptor table located in the  u (user) area  for the process. The per-process file descriptor table references a  system file table,  which is located in kernel space. In turn, the  system file table  maps to a  System Inode table  that contains a reference to a more complete internal description of the file.