📄 gate_x86.c
字号:
/*
* gate_x86 v1.0 11/25/01
* www.embeddedlinuxinterfacing.com
*
* The original location of this code is
* http://www.embeddedlinuxinterfacing.com/chapters/11/
* Copyright (C) 2001 by Craig Hollabaugh
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
gcc -O2 -D__KERNEL__ -DMODULE -I/usr/src/linux/include -c gate_x86.c -o gate_x86.o
*/
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/proc_fs.h>
#include <asm/uaccess.h>
#include <asm/io.h>
#include <linux/sched.h>
#include <linux/interrupt.h>
#include <linux/tqueue.h>
#include <linux/delay.h>
#define MODULE_VERSION "1.0"
#define MODULE_NAME "gate"
static struct proc_dir_entry *gate_file;
#define SPPDATAPORT 0x378
#define SPPSTATUSPORT (SPPDATAPORT + 1)
#define SPPCONTROLPORT (SPPDATAPORT + 2)
#define SSPINTERRUPTENABLE 0x10
#define STROBE 0x01
static int proc_read_gate(char *page, char **start, off_t off, int count, int *eof, void *data)
{
int len;
outb(0x00,SPPDATAPORT);
udelay(100);
outb(0x80,SPPDATAPORT);
outb(0x00,SPPDATAPORT);
return 0;
}
static int __init init_gate(void)
{
int rv = 0;
/* create gate file */
gate_file = create_proc_entry("gate", 0666, NULL);
if(gate_file == NULL) {
rv = -ENOMEM;
goto out;
}
gate_file->data = NULL;
gate_file->read_proc = &proc_read_gate;
gate_file->write_proc = NULL;
gate_file->owner = THIS_MODULE;
/* everything OK */
printk(KERN_INFO "%s %s initialized\n",MODULE_NAME, MODULE_VERSION);
return 0;
out:
return rv;
}
static void __exit cleanup_gate(void)
{
remove_proc_entry("gate", NULL);
printk(KERN_INFO "%s %s removed\n", MODULE_NAME, MODULE_VERSION);
}
module_init(init_gate);
module_exit(cleanup_gate);
MODULE_AUTHOR("Craig Hollabaugh");
MODULE_DESCRIPTION("gate proc module");
EXPORT_NO_SYMBOLS;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -