Created
March 27, 2010 10:33
-
-
Save oza/345917 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Makefile | |
# Declare Name of kernel module | |
KMOD = test | |
# Enumerate Source files for kernel module | |
SRCS = test.c | |
SRCS += device_if.h bus_if.h | |
i: | |
sudo kldload ./test.ko | |
r: | |
sudo kldunload ./test.ko | |
.include <bsd.kmod.mk> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* test.c | |
* written by Tsuyoshi Ozawa | |
* http://d.hatena.ne.jp/big-eyed-hamster */ | |
/* including for "kldloading", "kldunloading" */ | |
#include <sys/param.h> | |
#include <sys/module.h> | |
#include <sys/kernel.h> | |
#include <sys/systm.h> | |
/* including for handling IRQ */ | |
#include <sys/bus.h> | |
#include <machine/resource.h> /*To use SYS_RES_IRQ*/ | |
#include <sys/rman.h> /*To use RF_ACTIVE*/ | |
#include <sys/callout.h> | |
#include <sys/lock.h> | |
#include <sys/malloc.h> | |
#include <sys/mutex.h> | |
#include <machine/pcpu.h> | |
#include <machine/frame.h> | |
extern int (*mycallback)(void); | |
extern int callwheelmask; | |
extern void (*tick_sched)(void); | |
extern void (*lapic_handler)(struct trapframe *frame); | |
extern void lapic_handle_timer(struct trapframe *frame); | |
extern void dynamic_lapic_handle_timer(struct trapframe *frame); | |
extern void __lapic_handle_timer(struct trapframe *frame); | |
extern int (*get_skip_cnt)(void); | |
extern u_long lapic_timer_period, lapic_timer_hz; | |
void lapic_timer_periodic(u_int count); | |
void lapic_timer_oneshot(u_int count); | |
int test_intr(void *v); | |
struct callout_cpu { | |
struct mtx cc_lock; | |
struct callout *cc_callout; | |
struct callout_tailq *cc_callwheel; | |
struct callout_list cc_callfree; | |
struct callout *cc_next; | |
struct callout *cc_curr; | |
void *cc_cookie; | |
int cc_softticks; | |
int cc_cancel; | |
int cc_waiting; | |
}; | |
extern struct callout_cpu cc_cpu; | |
extern int callwheelsize; | |
extern void switch_to_dynticks(void); | |
extern void switch_to_perticks(void); | |
/* need for "kldloading", "kldunloading" */ | |
static int | |
test_modevent( struct module *module, int event, void *args) | |
{ | |
int e = 0; | |
switch (event) { | |
case MOD_LOAD: | |
uprintf("loaded.\n"); | |
switch_to_dynticks(); | |
break; | |
case MOD_UNLOAD: | |
uprintf("unloaded.\n"); | |
switch_to_perticks(); | |
break; | |
default: | |
e = EOPNOTSUPP; | |
} | |
return (e); | |
} | |
static moduledata_t test_conf ={ | |
"test", | |
test_modevent, | |
NULL | |
}; | |
DECLARE_MODULE(test, test_conf, SI_SUB_DRIVERS, SI_ORDER_MIDDLE); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment