开发者

Device drivers and Interrupt service routines

A very basic question. I have learnt that device drivers and interrupt service routines are some program or codes only. whenever required they are made to execute. Execution means CPU is executing开发者_如何学运维 some instructions out of its instruction set ISA. So does it mean that device drivers and ISRs are also machine instructions to generate the required result?

what exactly such programs likes device driver and interrupt routines made up of? do such programs also have a data segment, code segment and stack segment?

I am learning x86 assembly language and C .


That is an accurate assessment. A complex enough device driver has a data segment, code segment and a stack segment.


Consider how to get data from a device. There are two ways:

  • Polling: Are we there yet? Are we there yet? A program, OS kernel, device driver, whatever... keeps asking the device whether it has any new data.
  • Interrupts: The device tells the CPU that it has something important, and interrupts the CPU. The CPU executes a routine called an Interrupt Service Routine to service the request, and then continues with whatever it was doing before it was interrupted.

Depending on your OS (or no-OS, just bare metal) a device driver can be a program, or it can be an integral part of your OS kernel, ...

A typical device driver will do several things: identifying devices, initializing devices, handling interrupts from the device, handling requests to write/read/configure the device, ...

Of course, modern CPUs tend to provide protection features, and don't allow arbitrary processes access to devices. So the device driver will either run at a high privilege level, normally as a part of the OS kernel, or in the case if userspace device-drivers it will use some well-defined interfaces provided by the kernel.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜