Let’s consider the keyboard as an example. When I press a key, the keyboard sends an interrupt through some port. My question is, how does the OS know which driver to run to handle the keyboard input, and is this OS specific? My idea is that somehow the OS maps the device to the driver (how would it do that?) so when it receives an interrupt, it will know which program to run and which arguments to pass in; kind of like automatically calling the main function for some program executable.
Also, assume I am working with an operating system that exposes everything to the user. The device has a free port and an API to work with the port. Would the OS devs need to have added some sort of way for me to load/install a driver?