User Tools

Site Tools


releases:3.2.0:developersguide:newkernelcall

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.

  1. Add the prototype of your kernel function do_sample() in the file: /usr/src/kernel/system.h
...
int do_sample(struct proc *caller, message *m_ptr);

#endif  /* SYSTEM_H */
  1. Write the implementation of do_sample() in its own source file: /usr/src/kernel/system/do_sample.c
#include "kernel/system.h"
#include <minix/endpoint.h>

/*===========================================================================*
  *                                do_sample                                  *
  *===========================================================================*/
int do_sample(struct proc *caller_ptr, message *m_ptr)
{
        return(OK);
}
  1. Add do_sample.c to the Makefile for compilation: /usr/src/kernel/system/Makefile.inc
# 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
  1. Map SYS_SAMPLE to do_sample() in the system call table: /usr/src/kernel/system.c
...
  map(SYS_STATECTL, do_statectl);       /* let a process control its state */
  map(SYS_SAMPLE, do_sample);           /* your kernel call */
...
  1. Add a prototype for the sys_sample function in the file: /usr/src/common/include/minix/syslib.h
...
int sys_sample(unsigned flags, endpoint_t proc_ep);
...
  1. Add the call number for sys_sample to the call vector and increment its dimension: /usr/src/common/include/minix/com.h
...
#  define SYS_STATECTL (KERNEL_CALL + 55)       /* sys_statectl() */
#  define SYS_SAMPLE    (KERNEL_CALL + 56)      /* sys_sample() */


/* Total */
#define NR_SYS_CALLS    57      /* number of kernel calls */
...
  1. Add the SAMPLE service to the system tab: /usr/src/commands/service/service.c; build the updated system tab and install it with make; make install from /usr/src/commands/service/
...
struct
{
        char *label;
        int call_nr;
} system_tab[]=
{
...
        { "SAMPLE",             SYS_SAMPLE },
        { NULL,         0 }
};
...
  1. Write your implementation of the function sys_sample in a new file: /usr/src/lib/libsys/sys_sample.c
#include "syslib.h"

int sys_sample(unsigned flags, endpoint_t proc_ep)
{
        message m;

        return(_kernel_call(SYS_SAMPLE, &m));
}
  1. Add sys_sample.c to the Makefile, and install it in /usr/lib/${MACHINE_ARCH} with make install.
# Makefile for libsys

LIB=            sys

SRCS=  \
...
        sys_sample.c \
...
  1. Test the new kernel call with a hello driver in /usr/src/drivers/sample_test.
  2. Rebuild the kernel and install it with make; make install from /usr/src/tools.
releases/3.2.0/developersguide/newkernelcall.txt · Last modified: 2014/11/11 14:52 (external edit)