User Tools

Site Tools


developersguide:newkernelcall

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revision Both sides next revision
developersguide:newkernelcall [2015/01/02 20:22]
karadza3a fixed paths
developersguide:newkernelcall [2015/09/22 20:10]
shawnsustrich Changed directory path for where a user should do make; make install after editing parse.c
Line 1: Line 1:
 +====== Adding a new Kernel Call in MINIX ======
 +
 +//(Working Draft)//
 +
 +This tutorial helps you to add a new kernel call in MINIX. Let's say your new kernel call is called //sample//.
 +
 +  - Add the prototype of your kernel function do_sample() in the file: ///​usr/​src/​minix/​kernel/​system.h// ​
 +<​code>​
 +...
 +int do_sample(struct proc *caller, message *m_ptr);
 +
 +#​endif ​ /* SYSTEM_H */
 +</​code>​
 +  - Write the implementation of do_sample() in its own source file: ///​usr/​src/​minix/​kernel/​system/​do_sample.c// ​
 +<​code>​
 +#include "​kernel/​system.h"​
 +#include <​minix/​endpoint.h>​
 +
 +/​*===========================================================================*
 +  *                                do_sample ​                                 *
 +  *===========================================================================*/​
 +int do_sample(struct proc *caller_ptr,​ message *m_ptr)
 +{
 +        return(OK);
 +}
 +</​code>​
 +  - Add do_sample.c to the Makefile for compilation:​ ///​usr/​src/​minix/​kernel/​system/​Makefile.inc// ​
 +<​code>​
 +# Makefile for system library implementation
 +.include <​bsd.own.mk>​
 +
 +.PATH: ​ ${.CURDIR}/​system
 +SRCS+= ​ \
 +        do_fork.c \
 +        do_exec.c \
 +...
 +
 +        do_statectl.c \
 +        do_sample.c
 +</​code>​
 +  - Map SYS_SAMPLE to do_sample() in the system call table: ///​usr/​src/​minix/​kernel/​system.c// ​
 +<​code>​
 +...
 +  map(SYS_STATECTL,​ do_statectl); ​      /* let a process control its state */
 +  map(SYS_SAMPLE,​ do_sample); ​          /* your kernel call */
 +...
 +</​code>​
 +  - Add a prototype for the sys_sample function in the file: ///​usr/​src/​minix/​include/​minix/​syslib.h// ​
 +<​code>​
 +...
 +int sys_sample(unsigned flags, endpoint_t proc_ep);
 +...
 +</​code>​
 +  - Add the call number for sys_sample to the call vector and increment its dimension: ///​usr/​src/​minix/​include/​minix/​com.h// ​
 +<​code>​
 +...
 +#  define SYS_PADCONF (KERNEL_CALL + 57)       /* sys_padconf() */
 +#  define SYS_SAMPLE ​   (KERNEL_CALL + 58)      /* sys_sample() */
 +
 +
 +/* Total */
 +#define NR_SYS_CALLS ​   59      /* number of kernel calls */
 +...
 +</​code>​
 +  - Add the SAMPLE service to the system tab: ///​usr/​src/​minix/​commands/​service/​parse.c//;​ build the updated system tab and install it with //make; make install// from ///​usr/​src/​minix/​commands/​service/// ​
 +<​code>​
 +...
 +struct
 +{
 +        char *label;
 +        int call_nr;
 +} system_tab[]=
 +{
 +...
 +        { "​PADCONF", ​            ​SYS_PADCONF },
 +        { "​SAMPLE", ​            ​SYS_SAMPLE },
 +        { NULL,         0 }
 +};
 +...
 +</​code>​
 +  - Write your implementation of the function sys_sample in a new file: ///​usr/​src/​minix/​lib/​libsys/​sys_sample.c// ​
 +<​code>​
 +#include "​syslib.h"​
 +
 +int sys_sample(unsigned flags, endpoint_t proc_ep)
 +{
 +        message m;
 +
 +        return(_kernel_call(SYS_SAMPLE,​ &m));
 +}
 +</​code>​
 +  - Add sys_sample.c to the ///​usr/​src/​minix/​lib/​libsys/​Makefile//,​ and install it in ///​usr/​lib/​${MACHINE_ARCH}//​ with //make install//​. ​
 +<​code>​
 +# Makefile for libsys
 +
 +LIB=            sys
 +
 +SRCS=  \
 +...
 +        sys_sample.c \
 +...
 +</​code>​
 +  - Test the new kernel call with a [[.:​driverprogramming|hello driver]] in ///​usr/​src/​minix/​drivers/​sample_test//​.
 +  - Rebuild the kernel and install it with //make; make install// from ///​usr/​src/​releasetools//​.
  
developersguide/newkernelcall.txt · Last modified: 2015/09/22 20:18 by shawnsustrich