SlideShare a Scribd company logo
Interrupts:

We'll cover the whole interrupt stuff in two sections:
Interrupt setup - Explanation of Generic and architecture specific setup that kernel does.
Interrupt handling - Explanation of what happens after processor receives an interrupt.
[MMU is enabled before we reach here]

1. Interrupt setup:
Interrupt setup can also be divided into 2 parts:
     Setting up for the processor
     Setting up for the linux

The first step for system to start handling interrupt is setting up the interrupt vector table
and vector stubs.
When interrupt occurs processor sets the pc (program counter) to specific memory
address. Interrupt vector table needs to be placed at this location.
Entries in the vector table are instructions that will branch to specific routines designed to
handle the particular interrupt.

ARM:
Trap_init function, which is called from start_kernel, is responsible for setting up the
interrupt vector table at location 0xffff0000. Ideally the vector table is at 0x00000000
location but can located at higher address. So Linux uses this in case of ARM and copies
the table to 0xffff00000.
Before copying need to flush the icache for address 0xffff0000 of size equal to PAGE
SIZE.

There are 7 exceptions/interrupt:
    Reset
    Undefined instruction
    Software interrupt(SWI)
    Prefetch abort
    Data abort
    Interrupt request
    Fast interrupt request

In ARM the code snippet of vector table looks like this:
File: entry-armv.S,
----------------------------------------------------
.equ __real_stubs_start, .LCvectors + 0x200
.LCvectors:
swi SYS_ERROR0
b __real_stubs_start + (vector_und - __stubs_start)
ldr pc, __real_stubs_start + (.LCvswi - __stubs_start)
b __real_stubs_start + (vector_pabt - __stubs_start)
b __real_stubs_start + (vector_dabt - __stubs_start)
b __real_stubs_start + (vector_addrexcptn - __stubs_start)
b __real_stubs_start + (vector_irq - __stubs_start)
b __real_stubs_start + (vector_fiq - __stubs_start)
ENTRY(__trap_init)
stmfd sp!, {r4 - r6, lr}
mov r0, #0xff000000
orr r0, r0, #0x00ff0000 @ high vectors position
adr r1, .LCvectors @ set up the vectors
ldmia r1, {r1, r2, r3, r4, r5, r6, ip, lr}
stmia r0, {r1, r2, r3, r4, r5, r6, ip, lr}
add r2, r0, #0x200
adr r0, __stubs_start @ copy stubs to 0x200
adr r1, __stubs_end
1: ldr r3, [r0], #4
str r3, [r2], #4
cmp r0, r1
blt 1b
LOADREGS(fd, sp!, {r4 - r6, pc})


All Exception handlers will be at +0x200 offset from starting address of vector table.

Setting up for Kernel:
Init_IRQ function will initialize irq structures and perform the interrupt initialization.
     irq_desc is the interrupt descriptor.
     System will define the array elements of irq_desc corresponding to the number of
        interrupts defined for system.
     Setup the interrupt unitization function callback (arch_init_irq). The system
        interrupt init function is statically defined in MACHINE_START.
            o This function is responsible of initializing the interrupt controller and
                setting up low level functions like chip acknowledgment.

ARM has number of hard interrupts for which it requires to setup handler for each or a
default handler as entry point. At this point either interrupt handlers need to be setup
which will be called when interrupt is triggered to the processor or setup the default
handler. The other option is to register entry function that will help in maintining the ISR
design generic.

There are primarily two types of interrupts trigger mechanism:
    Level triggered
    Edge Triggered

For further understanding refer: http://en.wikipedia.org/wiki/Interrupt

Setup do_level_IRQ ( more commonly used ) as IRQ handlers entry function using
kernel function set_irq_handler.
Device drivers can now register IRQ handlers with request_irq.
Request_irq will now add the ISR handler to the list of IRQ handlers registered to a
particular IRQ line.

Some devices can be statically connected on specific interrupt line like timer on IRQ0
line. Therefore system timer is not registered in way explained above and has different
flow.


Interrupt Handling:

Once processor receives interrupt, it stops the current execution. Thereon the sequence of
events:
    disables IRQ
    copies CPSR in SPSR
    copies current PC to LR
    Switch to IRQ mode ( processor mode- ARM has 7 modes)
    Places the vector table address into PC
    Jumps to vector handler code. In this case vector_irq for IRQ.
    Condier intetrrupt occurred while processor was in Supervisor mode, processor
        will switch to SVC mode (supervisor mode)
    Irq_svc save the registers (r0-r12) on kernel stack. Kernel stack is nothing but the
        respective process kernel stack.
    Next step is to identify the irq line/number.
    On getting the IRQ details, flow will jump to asm_do_IRQ.
    Asm_do_IRQ will call the registered function during interrupt setup –
        do_level_irq.
    Do_level_IRQ will now call the registered ISR for the respective interrupt line.
    Mask the corresponsding interrupt line. Just to highlight interrupts are disables at
        the start of the flow,and here we are just masking the particular interrupt line.
    If there is ISR registered, __do_irq function will be executed. It will enable the
        Interrupts. ( As we have masked the particular interrupt line, so same interrupt
        line will not interrupt the processor, rest all can raise interrupt).
    Registered ISR is now all set to be executed.
    Once ISR is complete, irq_svc will return and restore the processor state by
        restoring the registers(r0-r12) values, PC and CPSR.
MIPS:
Address of vector table: (0xBFC00000)

Trap_init:

Set up the EBase register. This is processor register that should have base address of the
memory where vector table will be placed for processor. On interrupt signel,processor
will jump to the adresss rang of EBase register

Setup the 32 exception handler array. Register the exception vector handler in one of the
exception array index.


Setting up for Kernel:
Init_IRQ function will initialize irq structures and perform the interrupt initialization.
     irq_desc is the interrupt descriptor.
     System will define the array elements of irq_desc corresponding to the number of
        interrupts defined for system.
     Setup the interrupt unitization function callback (arch_init_irq). The system
        interrupt init function is statically defined in MACHINE_START.
            o This function is responsible of initializing the interrupt controller and
                setting up low level functions like chip acknowledgment.

Arch_int_irq - "somewhere in arch/mips/"
    set c0 status and cause register
    set irq_desc
    Set irq controller low level functions:irq_ack,enable,disable,start,shutdown.
    Each irq_desc can register the irq_chip functions which defines the IRQ low level
      handling.
    Setup timer interrupt.


Interrupt Handling:
Handle_int
Plat_irq_dispatch
 - call respective registered first level handler
xxx_do_IRQ
do_IRQ



Proc/interrupts – Provides the runtime view on the running system about the system
interrupts.
Interrupt number ---- Number of interrupts generated on CPU0 ---- Interrupt name

More Related Content

What's hot

[嵌入式系統] MCS-51 實驗 - 使用 IAR (3)
[嵌入式系統] MCS-51 實驗 - 使用 IAR (3)[嵌入式系統] MCS-51 實驗 - 使用 IAR (3)
[嵌入式系統] MCS-51 實驗 - 使用 IAR (3)
Simen Li
 
Linux Timer device driver
Linux Timer device driverLinux Timer device driver
Linux Timer device driver
艾鍗科技
 
Contiki introduction I.
Contiki introduction I.Contiki introduction I.
Contiki introduction I.
Dingxin Xu
 
Dead Lock Analysis of spin_lock() in Linux Kernel (english)
Dead Lock Analysis of spin_lock() in Linux Kernel (english)Dead Lock Analysis of spin_lock() in Linux Kernel (english)
Dead Lock Analysis of spin_lock() in Linux Kernel (english)
Sneeker Yeh
 
Concurrency bug identification through kernel panic log (english)
Concurrency bug identification through kernel panic log (english)Concurrency bug identification through kernel panic log (english)
Concurrency bug identification through kernel panic log (english)
Sneeker Yeh
 
Understanding iptables
Understanding iptablesUnderstanding iptables
Understanding iptables
Denys Haryachyy
 
Kernel crashdump
Kernel crashdumpKernel crashdump
Kernel crashdump
Adrien Mahieux
 
OSMC 2014: Server Hardware Monitoring done right | Werner Fischer
OSMC 2014: Server Hardware Monitoring done right | Werner FischerOSMC 2014: Server Hardware Monitoring done right | Werner Fischer
OSMC 2014: Server Hardware Monitoring done right | Werner Fischer
NETWAYS
 
Troubleshooting Linux Kernel Modules And Device Drivers
Troubleshooting Linux Kernel Modules And Device DriversTroubleshooting Linux Kernel Modules And Device Drivers
Troubleshooting Linux Kernel Modules And Device Drivers
Satpal Parmar
 
Linux synchronization tools
Linux synchronization toolsLinux synchronization tools
Linux synchronization tools
mukul bhardwaj
 
PART-3 : Mastering RTOS FreeRTOS and STM32Fx with Debugging
PART-3 : Mastering RTOS FreeRTOS and STM32Fx with DebuggingPART-3 : Mastering RTOS FreeRTOS and STM32Fx with Debugging
PART-3 : Mastering RTOS FreeRTOS and STM32Fx with Debugging
FastBit Embedded Brain Academy
 
Linux : PSCI
Linux : PSCILinux : PSCI
Linux : PSCI
Mr. Vengineer
 
Contiki introduction II-from what to how
Contiki introduction II-from what to howContiki introduction II-from what to how
Contiki introduction II-from what to how
Dingxin Xu
 
IRQs: the Hard, the Soft, the Threaded and the Preemptible
IRQs: the Hard, the Soft, the Threaded and the PreemptibleIRQs: the Hard, the Soft, the Threaded and the Preemptible
IRQs: the Hard, the Soft, the Threaded and the Preemptible
Alison Chaiken
 
Linux Kernel Crashdump
Linux Kernel CrashdumpLinux Kernel Crashdump
Linux Kernel Crashdump
Marian Marinov
 
Semtex.c [CVE-2013-2094] - A Linux Privelege Escalation
Semtex.c [CVE-2013-2094] - A Linux Privelege EscalationSemtex.c [CVE-2013-2094] - A Linux Privelege Escalation
Semtex.c [CVE-2013-2094] - A Linux Privelege Escalation
Kernel TLV
 
Tuned
TunedTuned
Bypassing ASLR Exploiting CVE 2015-7545
Bypassing ASLR Exploiting CVE 2015-7545Bypassing ASLR Exploiting CVE 2015-7545
Bypassing ASLR Exploiting CVE 2015-7545
Kernel TLV
 
RCU
RCURCU
Serial Drivers
Serial DriversSerial Drivers

What's hot (20)

[嵌入式系統] MCS-51 實驗 - 使用 IAR (3)
[嵌入式系統] MCS-51 實驗 - 使用 IAR (3)[嵌入式系統] MCS-51 實驗 - 使用 IAR (3)
[嵌入式系統] MCS-51 實驗 - 使用 IAR (3)
 
Linux Timer device driver
Linux Timer device driverLinux Timer device driver
Linux Timer device driver
 
Contiki introduction I.
Contiki introduction I.Contiki introduction I.
Contiki introduction I.
 
Dead Lock Analysis of spin_lock() in Linux Kernel (english)
Dead Lock Analysis of spin_lock() in Linux Kernel (english)Dead Lock Analysis of spin_lock() in Linux Kernel (english)
Dead Lock Analysis of spin_lock() in Linux Kernel (english)
 
Concurrency bug identification through kernel panic log (english)
Concurrency bug identification through kernel panic log (english)Concurrency bug identification through kernel panic log (english)
Concurrency bug identification through kernel panic log (english)
 
Understanding iptables
Understanding iptablesUnderstanding iptables
Understanding iptables
 
Kernel crashdump
Kernel crashdumpKernel crashdump
Kernel crashdump
 
OSMC 2014: Server Hardware Monitoring done right | Werner Fischer
OSMC 2014: Server Hardware Monitoring done right | Werner FischerOSMC 2014: Server Hardware Monitoring done right | Werner Fischer
OSMC 2014: Server Hardware Monitoring done right | Werner Fischer
 
Troubleshooting Linux Kernel Modules And Device Drivers
Troubleshooting Linux Kernel Modules And Device DriversTroubleshooting Linux Kernel Modules And Device Drivers
Troubleshooting Linux Kernel Modules And Device Drivers
 
Linux synchronization tools
Linux synchronization toolsLinux synchronization tools
Linux synchronization tools
 
PART-3 : Mastering RTOS FreeRTOS and STM32Fx with Debugging
PART-3 : Mastering RTOS FreeRTOS and STM32Fx with DebuggingPART-3 : Mastering RTOS FreeRTOS and STM32Fx with Debugging
PART-3 : Mastering RTOS FreeRTOS and STM32Fx with Debugging
 
Linux : PSCI
Linux : PSCILinux : PSCI
Linux : PSCI
 
Contiki introduction II-from what to how
Contiki introduction II-from what to howContiki introduction II-from what to how
Contiki introduction II-from what to how
 
IRQs: the Hard, the Soft, the Threaded and the Preemptible
IRQs: the Hard, the Soft, the Threaded and the PreemptibleIRQs: the Hard, the Soft, the Threaded and the Preemptible
IRQs: the Hard, the Soft, the Threaded and the Preemptible
 
Linux Kernel Crashdump
Linux Kernel CrashdumpLinux Kernel Crashdump
Linux Kernel Crashdump
 
Semtex.c [CVE-2013-2094] - A Linux Privelege Escalation
Semtex.c [CVE-2013-2094] - A Linux Privelege EscalationSemtex.c [CVE-2013-2094] - A Linux Privelege Escalation
Semtex.c [CVE-2013-2094] - A Linux Privelege Escalation
 
Tuned
TunedTuned
Tuned
 
Bypassing ASLR Exploiting CVE 2015-7545
Bypassing ASLR Exploiting CVE 2015-7545Bypassing ASLR Exploiting CVE 2015-7545
Bypassing ASLR Exploiting CVE 2015-7545
 
RCU
RCURCU
RCU
 
Serial Drivers
Serial DriversSerial Drivers
Serial Drivers
 

Similar to Linux interrupts

Embedded system - Introduction To ARM Exception Handling and Software Interru...
Embedded system - Introduction To ARM Exception Handling andSoftware Interru...Embedded system - Introduction To ARM Exception Handling andSoftware Interru...
Embedded system - Introduction To ARM Exception Handling and Software Interru...
Vibrant Technologies & Computers
 
Interrupts of 8085
Interrupts of 8085Interrupts of 8085
Interrupts of 8085
ShivamSood22
 
Lecture10.ppt
Lecture10.pptLecture10.ppt
Lecture10.ppt
MariusIoacara2
 
arm_exp.ppt
arm_exp.pptarm_exp.ppt
arm_exp.ppt
MariusIoacara2
 
Embedded system - introduction to arm7
Embedded system -  introduction to arm7Embedded system -  introduction to arm7
Embedded system - introduction to arm7
Vibrant Technologies & Computers
 
ARM exceptions and interrupt controls
ARM exceptions and interrupt controlsARM exceptions and interrupt controls
ARM exceptions and interrupt controls
Mahima Shastri
 
Arm architecture
Arm architectureArm architecture
Arm architecture
MinYeop Na
 
Exploit Research and Development Megaprimer: DEP Bypassing with ROP Chains
Exploit Research and Development Megaprimer: DEP Bypassing with ROP ChainsExploit Research and Development Megaprimer: DEP Bypassing with ROP Chains
Exploit Research and Development Megaprimer: DEP Bypassing with ROP Chains
Ajin Abraham
 
ARM Exception and interrupts
ARM Exception and interrupts ARM Exception and interrupts
ARM Exception and interrupts
NishmaNJ
 
Processor types
Processor typesProcessor types
Processor types
Amr Aboelgood
 
AAME ARM Techcon2013 002v02 Advanced Features
AAME ARM Techcon2013 002v02 Advanced FeaturesAAME ARM Techcon2013 002v02 Advanced Features
AAME ARM Techcon2013 002v02 Advanced Features
Anh Dung NGUYEN
 
Interrupts
InterruptsInterrupts
Arm teaching material
Arm teaching materialArm teaching material
Arm teaching material
John Williams
 
Arm teaching material
Arm teaching materialArm teaching material
Arm teaching material
Nilesh Bhandare
 
UNIT 2.pptx
UNIT 2.pptxUNIT 2.pptx
UNIT 2.pptx
SeshuSrinivas2
 
Code Red Security
Code Red SecurityCode Red Security
Code Red Security
Amr Ali
 
Router Commands Overview
Router Commands OverviewRouter Commands Overview
Router Commands Overview
Muhammed Niyas
 
Exception handling poirting in gcc
Exception handling poirting in gccException handling poirting in gcc
Exception handling poirting in gcc
Shiva Chen
 
Operating System Engineering
Operating System EngineeringOperating System Engineering
Operating System Engineering
Programming Homework Help
 
AAME ARM Techcon2013 005v02 System Startup
AAME ARM Techcon2013 005v02 System StartupAAME ARM Techcon2013 005v02 System Startup
AAME ARM Techcon2013 005v02 System Startup
Anh Dung NGUYEN
 

Similar to Linux interrupts (20)

Embedded system - Introduction To ARM Exception Handling and Software Interru...
Embedded system - Introduction To ARM Exception Handling andSoftware Interru...Embedded system - Introduction To ARM Exception Handling andSoftware Interru...
Embedded system - Introduction To ARM Exception Handling and Software Interru...
 
Interrupts of 8085
Interrupts of 8085Interrupts of 8085
Interrupts of 8085
 
Lecture10.ppt
Lecture10.pptLecture10.ppt
Lecture10.ppt
 
arm_exp.ppt
arm_exp.pptarm_exp.ppt
arm_exp.ppt
 
Embedded system - introduction to arm7
Embedded system -  introduction to arm7Embedded system -  introduction to arm7
Embedded system - introduction to arm7
 
ARM exceptions and interrupt controls
ARM exceptions and interrupt controlsARM exceptions and interrupt controls
ARM exceptions and interrupt controls
 
Arm architecture
Arm architectureArm architecture
Arm architecture
 
Exploit Research and Development Megaprimer: DEP Bypassing with ROP Chains
Exploit Research and Development Megaprimer: DEP Bypassing with ROP ChainsExploit Research and Development Megaprimer: DEP Bypassing with ROP Chains
Exploit Research and Development Megaprimer: DEP Bypassing with ROP Chains
 
ARM Exception and interrupts
ARM Exception and interrupts ARM Exception and interrupts
ARM Exception and interrupts
 
Processor types
Processor typesProcessor types
Processor types
 
AAME ARM Techcon2013 002v02 Advanced Features
AAME ARM Techcon2013 002v02 Advanced FeaturesAAME ARM Techcon2013 002v02 Advanced Features
AAME ARM Techcon2013 002v02 Advanced Features
 
Interrupts
InterruptsInterrupts
Interrupts
 
Arm teaching material
Arm teaching materialArm teaching material
Arm teaching material
 
Arm teaching material
Arm teaching materialArm teaching material
Arm teaching material
 
UNIT 2.pptx
UNIT 2.pptxUNIT 2.pptx
UNIT 2.pptx
 
Code Red Security
Code Red SecurityCode Red Security
Code Red Security
 
Router Commands Overview
Router Commands OverviewRouter Commands Overview
Router Commands Overview
 
Exception handling poirting in gcc
Exception handling poirting in gccException handling poirting in gcc
Exception handling poirting in gcc
 
Operating System Engineering
Operating System EngineeringOperating System Engineering
Operating System Engineering
 
AAME ARM Techcon2013 005v02 System Startup
AAME ARM Techcon2013 005v02 System StartupAAME ARM Techcon2013 005v02 System Startup
AAME ARM Techcon2013 005v02 System Startup
 

Recently uploaded

Christine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptxChristine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptx
christinelarrosa
 
Session 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdfSession 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdf
UiPathCommunity
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
saastr
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
Javier Junquera
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
Fwdays
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
ScyllaDB
 
Y-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PPY-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PP
c5vrf27qcz
 
High performance Serverless Java on AWS- GoTo Amsterdam 2024
High performance Serverless Java on AWS- GoTo Amsterdam 2024High performance Serverless Java on AWS- GoTo Amsterdam 2024
High performance Serverless Java on AWS- GoTo Amsterdam 2024
Vadym Kazulkin
 
inQuba Webinar Mastering Customer Journey Management with Dr Graham Hill
inQuba Webinar Mastering Customer Journey Management with Dr Graham HillinQuba Webinar Mastering Customer Journey Management with Dr Graham Hill
inQuba Webinar Mastering Customer Journey Management with Dr Graham Hill
LizaNolte
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
Northern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving | Modern Metal Trim, Nameplates and Appliance PanelsNorthern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving
 
Mutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented ChatbotsMutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented Chatbots
Pablo Gómez Abajo
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
Miro Wengner
 
"Scaling RAG Applications to serve millions of users", Kevin Goedecke
"Scaling RAG Applications to serve millions of users",  Kevin Goedecke"Scaling RAG Applications to serve millions of users",  Kevin Goedecke
"Scaling RAG Applications to serve millions of users", Kevin Goedecke
Fwdays
 
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
Jason Yip
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
Alex Pruden
 

Recently uploaded (20)

Christine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptxChristine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptx
 
Session 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdfSession 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdf
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
 
Y-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PPY-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PP
 
High performance Serverless Java on AWS- GoTo Amsterdam 2024
High performance Serverless Java on AWS- GoTo Amsterdam 2024High performance Serverless Java on AWS- GoTo Amsterdam 2024
High performance Serverless Java on AWS- GoTo Amsterdam 2024
 
inQuba Webinar Mastering Customer Journey Management with Dr Graham Hill
inQuba Webinar Mastering Customer Journey Management with Dr Graham HillinQuba Webinar Mastering Customer Journey Management with Dr Graham Hill
inQuba Webinar Mastering Customer Journey Management with Dr Graham Hill
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
Northern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving | Modern Metal Trim, Nameplates and Appliance PanelsNorthern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
 
Mutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented ChatbotsMutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented Chatbots
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
 
"Scaling RAG Applications to serve millions of users", Kevin Goedecke
"Scaling RAG Applications to serve millions of users",  Kevin Goedecke"Scaling RAG Applications to serve millions of users",  Kevin Goedecke
"Scaling RAG Applications to serve millions of users", Kevin Goedecke
 
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
 

Linux interrupts

  • 1. Interrupts: We'll cover the whole interrupt stuff in two sections: Interrupt setup - Explanation of Generic and architecture specific setup that kernel does. Interrupt handling - Explanation of what happens after processor receives an interrupt. [MMU is enabled before we reach here] 1. Interrupt setup: Interrupt setup can also be divided into 2 parts:  Setting up for the processor  Setting up for the linux The first step for system to start handling interrupt is setting up the interrupt vector table and vector stubs. When interrupt occurs processor sets the pc (program counter) to specific memory address. Interrupt vector table needs to be placed at this location. Entries in the vector table are instructions that will branch to specific routines designed to handle the particular interrupt. ARM: Trap_init function, which is called from start_kernel, is responsible for setting up the interrupt vector table at location 0xffff0000. Ideally the vector table is at 0x00000000 location but can located at higher address. So Linux uses this in case of ARM and copies the table to 0xffff00000. Before copying need to flush the icache for address 0xffff0000 of size equal to PAGE SIZE. There are 7 exceptions/interrupt:  Reset  Undefined instruction  Software interrupt(SWI)  Prefetch abort  Data abort  Interrupt request  Fast interrupt request In ARM the code snippet of vector table looks like this: File: entry-armv.S, ---------------------------------------------------- .equ __real_stubs_start, .LCvectors + 0x200 .LCvectors: swi SYS_ERROR0 b __real_stubs_start + (vector_und - __stubs_start) ldr pc, __real_stubs_start + (.LCvswi - __stubs_start) b __real_stubs_start + (vector_pabt - __stubs_start) b __real_stubs_start + (vector_dabt - __stubs_start)
  • 2. b __real_stubs_start + (vector_addrexcptn - __stubs_start) b __real_stubs_start + (vector_irq - __stubs_start) b __real_stubs_start + (vector_fiq - __stubs_start) ENTRY(__trap_init) stmfd sp!, {r4 - r6, lr} mov r0, #0xff000000 orr r0, r0, #0x00ff0000 @ high vectors position adr r1, .LCvectors @ set up the vectors ldmia r1, {r1, r2, r3, r4, r5, r6, ip, lr} stmia r0, {r1, r2, r3, r4, r5, r6, ip, lr} add r2, r0, #0x200 adr r0, __stubs_start @ copy stubs to 0x200 adr r1, __stubs_end 1: ldr r3, [r0], #4 str r3, [r2], #4 cmp r0, r1 blt 1b LOADREGS(fd, sp!, {r4 - r6, pc}) All Exception handlers will be at +0x200 offset from starting address of vector table. Setting up for Kernel: Init_IRQ function will initialize irq structures and perform the interrupt initialization.  irq_desc is the interrupt descriptor.  System will define the array elements of irq_desc corresponding to the number of interrupts defined for system.  Setup the interrupt unitization function callback (arch_init_irq). The system interrupt init function is statically defined in MACHINE_START. o This function is responsible of initializing the interrupt controller and setting up low level functions like chip acknowledgment. ARM has number of hard interrupts for which it requires to setup handler for each or a default handler as entry point. At this point either interrupt handlers need to be setup which will be called when interrupt is triggered to the processor or setup the default handler. The other option is to register entry function that will help in maintining the ISR design generic. There are primarily two types of interrupts trigger mechanism:  Level triggered  Edge Triggered For further understanding refer: http://en.wikipedia.org/wiki/Interrupt Setup do_level_IRQ ( more commonly used ) as IRQ handlers entry function using kernel function set_irq_handler.
  • 3. Device drivers can now register IRQ handlers with request_irq. Request_irq will now add the ISR handler to the list of IRQ handlers registered to a particular IRQ line. Some devices can be statically connected on specific interrupt line like timer on IRQ0 line. Therefore system timer is not registered in way explained above and has different flow. Interrupt Handling: Once processor receives interrupt, it stops the current execution. Thereon the sequence of events:  disables IRQ  copies CPSR in SPSR  copies current PC to LR  Switch to IRQ mode ( processor mode- ARM has 7 modes)  Places the vector table address into PC  Jumps to vector handler code. In this case vector_irq for IRQ.  Condier intetrrupt occurred while processor was in Supervisor mode, processor will switch to SVC mode (supervisor mode)  Irq_svc save the registers (r0-r12) on kernel stack. Kernel stack is nothing but the respective process kernel stack.  Next step is to identify the irq line/number.  On getting the IRQ details, flow will jump to asm_do_IRQ.  Asm_do_IRQ will call the registered function during interrupt setup – do_level_irq.  Do_level_IRQ will now call the registered ISR for the respective interrupt line.  Mask the corresponsding interrupt line. Just to highlight interrupts are disables at the start of the flow,and here we are just masking the particular interrupt line.  If there is ISR registered, __do_irq function will be executed. It will enable the Interrupts. ( As we have masked the particular interrupt line, so same interrupt line will not interrupt the processor, rest all can raise interrupt).  Registered ISR is now all set to be executed.  Once ISR is complete, irq_svc will return and restore the processor state by restoring the registers(r0-r12) values, PC and CPSR.
  • 4. MIPS: Address of vector table: (0xBFC00000) Trap_init: Set up the EBase register. This is processor register that should have base address of the memory where vector table will be placed for processor. On interrupt signel,processor will jump to the adresss rang of EBase register Setup the 32 exception handler array. Register the exception vector handler in one of the exception array index. Setting up for Kernel: Init_IRQ function will initialize irq structures and perform the interrupt initialization.  irq_desc is the interrupt descriptor.  System will define the array elements of irq_desc corresponding to the number of interrupts defined for system.  Setup the interrupt unitization function callback (arch_init_irq). The system interrupt init function is statically defined in MACHINE_START. o This function is responsible of initializing the interrupt controller and setting up low level functions like chip acknowledgment. Arch_int_irq - "somewhere in arch/mips/"  set c0 status and cause register  set irq_desc  Set irq controller low level functions:irq_ack,enable,disable,start,shutdown.  Each irq_desc can register the irq_chip functions which defines the IRQ low level handling.  Setup timer interrupt. Interrupt Handling: Handle_int Plat_irq_dispatch - call respective registered first level handler xxx_do_IRQ do_IRQ Proc/interrupts – Provides the runtime view on the running system about the system interrupts. Interrupt number ---- Number of interrupts generated on CPU0 ---- Interrupt name