Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the linux exception architecture

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

In this issue, the editor will bring you about what is the linux exception architecture. The article is rich in content and analyzes and describes it from a professional point of view. I hope you can get something after reading this article.

Take the arm processor as an example, both external interrupts and processor kernel exceptions (inside the soc) are exceptions, both of which are relative to the main program. When soc executes the main program normally, both interrupts and exceptions can interrupt it. The difference between interrupts and exceptions can be distinguished according to the "interrupt" nature of the exception to the main program:

Exception: due to the kernel activities of soc itself, such as exceptions due to arm soc prefetching instructions / data when executing the main program, this exception comes from the soc kernel, so it is "synchronous" for the soc kernel.

Interrupt: when soc is executing the main program, various on-chip peripherals and external interrupt pins can generate an exception to interrupt the program currently being executed by soc. This exception signal comes from outside the kernel of soc, so it is "asynchronous" to the soc kernel.

Under the linux system of arm architecture, five kinds of exceptions are used: 1. No instruction exception 2. Instruction prefetch abort exception 3. Data access abort exception 4. Interrupt exception 5. Swi exception.

(1) linux interrupt architecture

The linux kernel numbers all interrupts uniformly in (linux) / include/asm-arm/arch-s3c2410/irqs.h, and linux uses an array of constructs to describe interrupts, and the subscript of this array is the interrupt number. Each array item corresponds to a set of interrupts

File: (linux) / include/linux/irq.h struct irq_desc {irq_flow_handler_t handle_irq; / * current interrupt handler entry * / struct irq_chip * chip; / * underlying hardware access * /. Struct irqaction * action; / * user-provided list of interrupt handling functions * / unsigned int status; / * IRQ status * /. Interrupt name * /} _ cacheline_internodealigned_in_smp displayed by const char * name; / * cat / proc/interrupts

The chip provides the underlying hardware access:

File: (linux) / include/linux/irq.hstruct irq_chip {const char * name; unsigned int (* startup) (unsigned int irq); / * start interrupt. Default is "enable" * / void (* shutdown) (unsigned int irq) / * disable interrupt, default is "disable" * / void (* enable) (unsigned int irq); / * enable interrupt, default is "unmask" * / void (* disable) (unsigned int irq); / * disable interrupt, default is "mask" * / void (* ack) (unsigned int irq) / * respond to interrupts, usually to clear the current interrupt so that the next interrupt can be received * / void (* mask) (unsigned int irq); / * mask interrupt source * / void (* mask_ack) (unsigned int irq); / * mask and respond to interrupts * / void (* unmask) (unsigned int irq) / * Open the interrupt source * /.}

In addition, the irqaction structure is:

File: (linux) / include/linux/interrupt.h struct irqaction {irq_handler_t handler; / / the interrupt handling function unsigned long flags; / / interrupt flag cpumask_t mask; / / for smp const char * name; / / the name "cat / proc/interrupts" for user registration can see void * dev_id / / the handler parameter passed by the user can also be used to distinguish the shared interrupt struct irqaction * next; / / pointing to the next irqaction structure int irq; / / interrupt number struct proc_dir_entry * dir;}

The process of interrupt execution is as follows: when the interrupt arrives, the total interrupt entry function asm_do_IRQ () finds the corresponding item in the irq_desc structure array according to the interrupt number, and calls the handle_irq () function in the irq_desc structure. The handle_irq function uses the function in the chip structure to clear / shield / re-enable the interrupt, and finally calls the interrupt handling functions registered in the action linked list.

(2) interrupt architecture initialization

Set the exception handler by trap_init () / init_IRQ () in the start_kernel () function of (linux) / init/main.c.

1. The trap_init () and early_trap_init () functions copy the exception vector to the 0xffff0000 address and the interrupt service function to the 0xffff0000 + 0x200 address through the following statement

File: (linux) / arch/arm/kernel memcpy ((void *) vectors, _ _ vectors_start, _ _ vectors_end-_ _ vectors_start); memcpy ((void *) vectors + 0x200, _ _ stubs_start, _ _ stubs_end-_ stubs_start)

Start and end are as follows:

.globl _ _ vectors_start__vectors_start: swi SYS_ERROR0 b vector_und + stubs_offset ldr pc .LCvswi + stubs_offset b vector_pabt + stubs_offset b vector_dabt + stubs_offset b vector_addrexcptn + stubs_offset b vector_irq + stubs_offset b vector_fiq + stubs_offset .globl _ vectors_end__vectors_end:

Responsible for initialization is init_IRQ, because it is closely related to the specific development board, so it needs to be listed separately. It is used to initialize the interrupt framework and set the default handler for each interrupt. When an interrupt occurs, enter asm_do_IRQ () and call the function set by init_IRQ ().

File: (linux) / arch/arm/kernel/irq.cvoid _ init init_IRQ (void) {int irq; for (irq = 0; irq)

< NR_IRQS; irq++) irq_desc[irq].status |= IRQ_NOREQUEST | IRQ_NOPROBE; init_arch_irq();} 1 for循环中将 irq_desc[] 数组中每一项的状态都设置为 IRQ_NOREQUEST | IRQ_NOPROBE (未请求 | 未探测) 2 init_arch_irq 其实是一个函数指针, 定义如下: file: (linux)/arch/arm/kernel/irq.c void (*init_arch_irq)(void) __initdata = NULL; 2440移植好的linux系统在启动的时候通过(linux)/arch/arm/kernel/setup.c 的 setup_arch() 获取到 machine_desc 结构体, 然后将 init_arch_irq 这个函数指针初始化为 s3c24xx_init_irq() . file: (linux/arch/plat-s3c24xx/irq.c 的 s3c24xx_init_irq)void __init s3c24xx_init_irq(void){ ... /* first, clear all interrupts pending... */ ... /* register the main interrupts */ ... /* setup the cascade irq handlers */ set_irq_chained_handler(IRQ_EINT4t7, s3c_irq_demux_extint4t7); set_irq_chained_handler(IRQ_EINT8t23, s3c_irq_demux_extint8); ... /* external interrupts */ //外部中断 0 ~ 3 for (irqno = IRQ_EINT0; irqno flags = irqflags; cpus_clear(action->

Mask); action- > name = devname; action- > next = NULL; action- > dev_id = dev_id; retval = setup_irq (irq, action);...}

The setup_irq function has several functions:

1. Connect action to the action linked list of irq_desc [irq]

2. Elements in the irq_desc [] .chip structure that are not set by init_irq () are set to default values.

3. Call chip- > set_type with the incoming irqflags as a parameter to set the interrupt: set to external interrupt, set trigger mode (high / low / rising edge / falling edge)

4. To start the interrupt, call chip- > startup or chip- > enable to enable the interrupt

In short, after calling request_irq: the action structure of irq_desc [] has been linked into the action linked list, the interrupt trigger mode has been set, and the interrupt has been enabled. Now the interruption can occur and be handled.

(4) interrupt the specific implementation process

The total entry for interrupts is asm_do_IRQ ()

File: (linux) / arch/arm/kernel/irq.c asmlinkage void _ exception asm_do_IRQ (unsigned int irq, struct pt_regs * regs) {. Struct irq_desc * desc = irq_desc + irq;... Desc_handle_irq (irq, desc);...} file: (linux) / include/asm-arm/mach/irq.hstatic inline void desc_handle_irq (unsigned int irq, struct irq_desc * desc) {desc- > handle_irq (irq, desc);}

Value range of irq: IRQ0_EINT0~ (IRQ_EINT0+31). Because 2440 of INTPND share 32bit, but irq_desc [] has much more than 32 elements, because some interrupts share the same bit, such as EINT8~23. So when the irq of asm_do_IRQ corresponds to "a set of" sub-interrupts, the irq_ interrupt [irq] .handle _ irq function also needs to determine which sub-interrupt requested the interrupt, assuming that the sub-interrupt number is irqno, then continue to call irq_ [irqno] .handle _ irq to handle it.

Take the external interrupt EINT8~23 as an example to explain the detailed process of interrupt call:

1 when any interrupt in EINT8~23 is triggered, the value of the INTOFFSET register is 5. The irq of asm_do_IRQ is IRQ_EINT0+5 or IRQ_EINT8t23, and then call irq_ interrupt [IRQ _ EINT0t23] .handle _ irq to handle it.

2 irq_ pointer [IRQ _ EINT8t23] .handle _ irq setting is completed during interrupt initialization: init_IRQ-> init_arch_irq () this function pointer is assigned to s3c24xx_init_irq-> when linux starts.

File: (linux) / arch/plat-s3c24xx/irq.c set_irq_chained_handler (IRQ_EINT4t7, s3c_irq_demux_extint4t7); set_irq_chained_handler (IRQ_EINT8t23, s3c_irq_demux_extint8); / / irq_ EINT8t23 [IRQ _ EINT8t23] .handle _ irq is set to s3c_irq_demux_extint8 set_irq_chained_handler (IRQ_UART0, s3c_irq_demux_uart0); set_irq_chained_handler (IRQ_UART1, s3c_irq_demux_uart1) Set_irq_chained_handler (IRQ_UART2, s3c_irq_demux_uart2); set_irq_chained_handler (IRQ_ADCPARENT, s3c_irq_demux_adc)

Let's see what s3c_irq_demux_extint8 has done.

Static void s3c_irq_demux_extint8 (unsigned int irq, struct irq_desc * desc) {unsigned long eintpnd = _ _ raw_readl (S3C24XX_EINTPEND); unsigned long eintmsk = _ _ raw_readl (S3C24XX_EINTMASK); eintpnd & = ~ eintmsk; eintpnd & = ~ 0xff; / * ignore lower irqs * / / * we may as well handle all the pending IRQs here * / while (eintpnd) {irq = _ _ ffs (eintpnd) Eintpnd & = ~ (1)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report