Tutorial >> Writing Your First Plugin | TOC |
An SPC runs a streamlined NetBSD kernel. Plugins are just modules loaded into the kernel. We compile our plugins on the host onlusr (a Linux host) for a NetBSD host (an SPC) by using a cross-compiler. The end result will be a loadable kernel module for a NetBSD operating system called combined.o.
If you are using a Makefile derived from the standard plugin directory ~onl/stdplugins/template/, compiling is trivial. For example, if you used the newplugins.pl perl script to create your initial code skeletons, the Makefile will allow you to enter the following to compile our new plugin using a cross-compiler:
cd myplugins/mycounter-1100 # go to our plugin directory make # compile ... fix syntax errors and run make again until no errors ... exit # return to previous host
The make command executes commands in the file Makefile. That's all there is to it! You should not have to modify the Makefile created by newplugin.pl. The first time you try compiling, you will probably get a few syntax errors which should be straightforward to find and correct.
The file Makefile describes how to make the loadable kernel module combined.o. The make command uses this description. After successfully making combined.o, you will also see that the object file mycounter.o was also created. While compiling, several header files are used in addition to your mycounter.h. Enter the following commands and note the lines displayed on your terminal:
touch mycounter.c # simulate a change to the .c file make -n # don't really make combined.o
/usr/local/xcomp/bin/i386--netbsdelf-gcc -DMSR -D_KERNEL -DMSR_PLUGIN -D_LKM -I/users/onl/wu_arl/msr/usr/src/sys -I. -c -o mycounter.o mycounter.c /usr/local/xcomp/bin/i386--netbsdelf-ld -r -o combined.o mycounter.o nm -u combined.o
The first -I flag includes the directory containing subdirectories of system headers; e.g., the directory /users/onl/wu_arl/msr/usr/src/sys/ contains subdirectories such as msr, sys and rp that contain headers used by plugins. For example, your stdinc.h file contains the following lines:
#include <sys/param.h> ... #include <netinet/in_systm.h> #include <netinet/ip.h> #include <dev/ic/apicvar.h> #include <msr/msr.h> #include <msr/msr_util.h> ... #include <rp/rp.h> #include <rp/rp_plugin.h> #include <rp/rp_pcu.h>
Now, we are ready to see if the plugin works; i.e., receives and counts packets.
Revised: Tue, Aug 15, 2006
Tutorial >> Writing Your First Plugin | TOC |