Getting Minix 2
Older Minix versions are available from the Minix 3 official website. If using a VM I would recommend the HD image from the Minix 2 Quick and Dirty edition. This is what I used for this blog post.
Running in VirtualBox
If using the Quick and Dirty edition HDD image from the link above, first convert it to VDI format:
VBoxManage convertdd minix-2.0-hd-64MB.img minix-2.0-hd-64MB.vdi --format VDI
Create a Linux 2.4 32-bit VM with 64mb of RAM. Make sure that the storage controller is IDE.
Building the kernel
cd /usr/src/tools
make
This should build the kernel and out bootable kernel file named image
. Copy it into the directory containing the kernel:
cp image /minix/custom
Now reboot Minix with the new kernel image. Perform a clean shutdown of the OS:
shutdown
From the Supervisor, set our custom kernel image as the kernel and boot back into Minix:
name=/minix/custom
boot
Adding a syscall to the memory manager server
/usr/include/minix/callnr.h
increment NCALLS and allocate an number for the new syscall:
#define HELLOWORLD 78
/usr/src/mm/main.c
PUBLIC void do_helloworld()
{
message msg;
msg = mm_in;
_taskcall(SYSTASK, SYS_HELLO, &msg);
}
/usr/src/mm/proto.h
_PROTOTYPE(void do_helloworld, (void));
/usr/src/mm/table.c
do_helloworld, /* 78 = HELLOWORLD */
/usr/src/fs/table.c
no_sys , /* 78 = HELLOWORLD */
/usr/include/minix/com.h
#define SYS_HELLOWORLD 22
/usr/src/kernel/system.c
case SYS_HELLOWORLD: r = do_helloworld(&m); break;
PRIVATE int do_helloworld(m_ptr)
register message *m_ptr;
{
printf("Hello, World\n");
return(OK);
}
Calling the syscall from user land
#include <lib.h>
int main(int argc, char** argv)
{
int ret;
message msg;
ret = _syscall(MM, HELLOWORLD, &msg);
return ret;
}
Build this program with cc -o hello hello.c
. Running ./hello
should output Hello, World from the new syscall.