How to write portable device drivers?