operating system - From Kernel Space to User Space: Inner-workings of Interrupts -
i have been trying understand how h/w interrupts end in user space code, through kernel.
my research led me understand that:
1- external device needs attention cpu
2- signals cpu raising interrupt (h/w trance cpu or bus)
3- cpu asserts, saves current context, looks address of isr in interrupt descriptor table (vector)
4- cpu switches kernel (privileged) mode , executes isr.
question #1: how did kernel store isr address in interrupt vector table? might done sending cpu piece of assembly described in cpus user manual? more detail on subject better please.
in user space how can programmer write piece of code listens h/w device notifications?
this understand far.
5- kernel driver specific device has message device , executing isr.
question #3:if programmer in user space wanted poll device, assume done through system call (or @ least understood far). how done? how can driver tell kernel called upon specific systemcall can execute request user? , happens, how driver gives requested data user space?
i might off track here, guidance appreciated. not looking specific details answers, trying understand general picture.
question #1: how did kernel store isr address in interrupt vector table?
driver calls request_irq
kernel function (defined in include/linux/interrupt.h
, in kernel/irq/manage.c), , linux kernel register in right way according current cpu/arch rules.
it might done sending cpu piece of assembly described in cpus user manual?
in x86 linux kernel stores isr in interrupt descriptor table (idt), format described vendor (intel - volume 3) , in many resources http://en.wikipedia.org/wiki/interrupt_descriptor_table , http://wiki.osdev.org/idt , http://phrack.org/issues/59/4.html , http://en.wikibooks.org/wiki/x86_assembly/advanced_interrupts.
pointer idt table registered in special cpu register (idtr) special assembler commands: lidt
, sidt
.
if programmer in user space wanted poll device, assume done through system call (or @ least understood far). how done? how can driver tell kernel called upon specific systemcall can execute request user? , happens, how driver gives requested data user space?
driver registers device special file in /dev; pointers several driver functions registered file "file operations". user-space program opens file (syscall open
), , kernels calls device's special code open; program calls poll
or read
syscall on fd, kernel call *poll
or *read
of driver's file operations (http://www.makelinux.net/ldd3/chp-3-sect-7.shtml). driver may put caller sleep (wait_event*
) , irq handler wake (wake_up*
- http://www.makelinux.net/ldd3/chp-6-sect-2 ).
you can read more linux driver creation in book linux device drivers (2005) jonathan corbet, alessandro rubini, , greg kroah-hartman: https://lwn.net/kernel/ldd3/
- chapter 3: char drivers https://lwn.net/images/pdf/ldd3/ch03.pdf
- chapter 10: interrupt handling https://lwn.net/images/pdf/ldd3/ch10.pdf
Comments
Post a Comment