はわわーっ

はわわわわっ

ioportにアクセスしたいんですが

よくわからん。

#include <stdio.h>
#include <sys/io.h>

int main(void)
{
        unsigned char val;
        int ret;

        ret = ioperm(0x64, 1, 1);
        if (ret) {
                perror("ioperm 1");
                return 1;
        }

        val = inb(0x64);
        printf("val=%02x\n", val);

        ret = ioperm(0x64, 1, 0);
        if (ret) {
                perror("ioperm 0");
                return 1;
        }

        return 0;
}

これをコンパイルして実行するとSEGVする。

$ gcc -Wall -Wextra -O2 ioperm.c 
$ sudo -s
# ./a.out 
Segmentation fault (core dumped)
# gdb ./a.out 
(gdb) run
Starting program: /home/meu/iop/a.out 

Program received signal SIGSEGV, Segmentation fault.
0x000000000040051c in main ()
(gdb) disas main
Dump of assembler code for function main:
   0x0000000000400500 <+0>:     sub    $0x8,%rsp
   0x0000000000400504 <+4>:     mov    $0x1,%edx
   0x0000000000400509 <+9>:     mov    $0x1,%esi
   0x000000000040050e <+14>:    mov    $0x64,%edi
   0x0000000000400513 <+19>:    callq  0x4004c0 <ioperm@plt>
   0x0000000000400518 <+24>:    test   %eax,%eax
   0x000000000040051a <+26>:    jne    0x400561 <main+97>
=> 0x000000000040051c <+28>:    in     $0x64,%al
   0x000000000040051e <+30>:    mov    $0x4006ed,%esi
   0x0000000000400523 <+35>:    movzbl %al,%edx
   0x0000000000400526 <+38>:    mov    $0x1,%edi
   0x000000000040052b <+43>:    xor    %eax,%eax
   0x000000000040052d <+45>:    callq  0x4004e0 <__printf_chk@plt>
   0x0000000000400532 <+50>:    xor    %edx,%edx
   0x0000000000400534 <+52>:    mov    $0x1,%esi
   0x0000000000400539 <+57>:    mov    $0x64,%edi
   0x000000000040053e <+62>:    callq  0x4004c0 <ioperm@plt>
   0x0000000000400543 <+67>:    xor    %edx,%edx
   0x0000000000400545 <+69>:    test   %eax,%eax
   0x0000000000400547 <+71>:    jne    0x400550 <main+80>
   0x0000000000400549 <+73>:    mov    %edx,%eax
   0x000000000040054b <+75>:    add    $0x8,%rsp
   0x000000000040054f <+79>:    retq   
   0x0000000000400550 <+80>:    mov    $0x4006f7,%edi
   0x0000000000400555 <+85>:    callq  0x4004f0 <perror@plt>
   0x000000000040055a <+90>:    mov    $0x1,%edx
   0x000000000040055f <+95>:    jmp    0x400549 <main+73>
   0x0000000000400561 <+97>:    mov    $0x4006e4,%edi
   0x0000000000400566 <+102>:   callq  0x4004f0 <perror@plt>
   0x000000000040056b <+107>:   mov    $0x1,%edx
   0x0000000000400570 <+112>:   jmp    0x400549 <main+73>
End of assembler dump.
in     $0x64,%al

ここでSEGVしてるっぽいんだけどなんでなの?