ports.c 639 B

123456789101112131415161718192021222324
  1. unsigned char port_byte_in(unsigned short port) {
  2. unsigned char res;
  3. /*
  4. * `"=a" (res)' means: put result of `al' into `res' variable
  5. * `"d" (port)' means: load `port' into `dx'.
  6. */
  7. __asm__("in %%dx, %%al" : "=a" (res) : "d" (port));
  8. return res;
  9. }
  10. void port_byte_out(unsigned short port, unsigned char data) {
  11. __asm__("out %%al, %%dx" : : "a" (data), "d" (port));
  12. }
  13. unsigned short port_word_in(unsigned short port) {
  14. unsigned short res;
  15. __asm__("in %%dx, %%ax" : "=a" (res) : "d" (port));
  16. return res;
  17. }
  18. void port_word_out(unsigned short port, unsigned short data) {
  19. __asm__("out %%ax, %%dx" : : "a" (data), "d" (port));
  20. }