testport.c

来自「《并行口编程指南》」· C语言 代码 · 共 39 行

C
39
字号
/*----------------------------------------------*/
/* testport.c */
/* compile as: gcc -O testport.c */
/* Execution is possible only as a superuser*/
/*----------------------------------------------*/

#include <asm/io.h>
#include <asm/segment.h>
#include <asm/system.h>
#include <unistd.h>

int ioperm();

#define port_add 0x378

void main()
{
unsigned char test_value;
int ret_value;

ret_value=ioperm(data_port, 3, 1); 

if ( ret_value == -1 ) 
                     {
                     printf("Cannot get I/O permission\n");
                     exit(-1);
                     }
outb(0x55,port_add);

test_value=inb(port_add);
printf("\nValue at Data port= %x\n", test_value);

test_value=inb(port_add+1);
printf("\nValue at the Status Port= %x\n", test_value);

test_value=inb(port_add+2);
printf("\nValue at Control Port= %x\n", test_value);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?