manuhg
manuhg

Reputation: 460

why keyboard driver required as keyboard input can be took either from interrupts or by accessing keyboard buffer?

As keyboard input as scan codes can be obtained from calling interrupt 09 IRQ1 or similar ones or by directly accessing the BIOS keyboard buffer at segment 0040h

why is there a requirement for a separate keyboard driver ? or does the keyboard driver itself does one of the above for the OS?

what i mean is for taking keyboard input when we can BIOS keyboard buffer or some interrupt routines why is there a requirement to write a "keyboard driver" because in some OSs like minix there is a separate keyboard river in the list of drivers of that OS?

Upvotes: 2

Views: 660

Answers (2)

Will Hartung
Will Hartung

Reputation: 118714

There's a requirement for the driver because the driver is the mechanism of abstraction that the OS uses to interact with devices, both real and imaginary.

Consider /dev/random, which is a random number generator. The OS knows that it can "read" from that device and get a random number. How is the random number generated? The OS doesn't care. That process is isolated and abstracted away by the driver. It could be a pseudo random algorithm. It could be a special device on the motherboard. It could be a video camera watching rush hour traffic. Who knows. The point is that the OS doesn't care "how" it is done, it only knows that by using assorted drivers it can talk to most any piece of hardware, real or synthetic.

Just like if you were writing the OS you wouldn't simply load memory from the keyboard buffer, but you would instead write the code once and call a subroutine, a driver is a higher level mechanism of abstraction that performs a similar task.

Upvotes: 0

Preet Sangha
Preet Sangha

Reputation: 65516

Generally speaking modern OSes have a distinction between Kernel Mode and User Mode. The Kernel has higher privileges and only specialised code can run in that mode. Accessing hardware resources is generally the domain of Kernel Mode. User Mode code on the other hand is prevented by the CPU from accessing these resource.

I don't know which OS you're talking about, but in essence the driver that you talk about is this specialised code. Your User Mode code is prevented from accessing the resources directly and must communicate with the driver.

If you consider a simpler or older OS such a MS-DOS where there was no distinction and thus all code could access the hardware resources. But I don't know of any modern general purpose OS that allows this.

This is really good wikipedia article to explain Kernel Model Programming ideas.

In Windows (and most modern operating systems), there is a distinction between code that is running in "user mode", and code that is running in "kernel mode". This chapter is going to point out some of the differences. Firstly, Intel CPUs have modes of operation called rings which specify the type of instructions and memory available to the running code. There are four rings:

  • Ring 0 (also known as kernel mode) has full access to every resource. It is the mode in which the Windows kernel runs.
  • Rings 1 and 2 can be customized with levels of access but are generally unused unless there are virtual machines running.
  • Ring 3 (also known as user mode) has restricted access to resources.

The reason for this is because if all programs ran in kernel mode, they would be able to overwrite each others memory and possibly bring down the entire system when they crashed.

Upvotes: 1

Related Questions