What causes a segmentation fault on a call to inb_p()?

后端 未结 1 1833
没有蜡笔的小新
没有蜡笔的小新 2020-12-21 15:50

I am getting a segmentation fault when trying to read a port with inb_p( ). I\'m compiling this on a Debian system running 2.6.6 kernel on an Intel D525 dual-core system (Ad

相关标签:
1条回答
  • 2020-12-21 15:52

    I found the problem. The call to inb_p() requires access to port 0x80 in addition to the port to be read.

    Apparently, when I tried iopl(), I didn't call it correctly, because that should have worked.

    The following code eliminated the segfault:

      /* Get access to the ports */
      if (ioperm(0x80, 1, 1)) 
      {
         perror("ioperm");
         exit(EXIT_FAILURE);
      }
      if (ioperm(BASEPORT+DIPSWITCH, 10, 1)) 
      {
         perror("ioperm");
         exit(EXIT_FAILURE);
      }
    
    0 讨论(0)
提交回复
热议问题