csystem-callsminix

Adding new system call to utility.c in Minix


I am trying to implement a system call in Minix and I'm having trouble understanding where I need to go. This is the system call I need to add which returns 0 on success and -1 on failure while also returning a+b, a-b, and a*b:

int mycall(int a, int b, int *sum, int *difr, int *prod);

What I've done:

#include <stdio.h>
int main()
{
    int a, b, d, p, r, s;
    a = 3;
    b = 2;
    int mycall(int a, int b, int *s, int *d, int *p);
    r = mycall(a, b, &s, &d, &p);
    fprintf(stderr, "%d,%d,%d,%d\n", r, s, d, p);
    return 0;
}
#include <lib.h>
int mycall(int a, int b, int *sum, int *difr, int *prod)
{
    message m;
    int r;

    m.m1_i1 = a;
    m.m1_i2 = b;

    k = _syscall(MM, 58, &m);
    if(r < 0) return -1;
    *sum = m.m1_i1;
    *difr = m.m1_i2;
    *prod = m.m1_i3;
    return k;
}
    _PROTOTYPE( int do_mycall, (void));

All that needs to be done is to implement the call in /usr/mm/utility.c. This is what I have so far:

PUBLIC int do_mycall()
{
    int a, b;
    a = mm_in.m1_i1;
    b = mm_in.m1_i2;

    /* my guess */
    mm_in.m1_i1 = a+b;
    mm_in.m1_i2 = a-b;
    mm_in.m1_i3 = a*b;

    /* mp_reply is in mproc struct of this process */

    return OK;
}

The current code when ran (after rebuilding the kernel) gives -1,0,0,0 which is wrong, but I am not sure how to proceed. When opening mproc.h, I can see message mp_reply; but I don't know how this helps.


Solution

  • Finally got it working thanks to a classmate. proto.h and table.c files are correct. Had to change all k's to r's in mycall.c. The big change was in utility.c and how I rebuilt the image.

    utility.c code:

    PUBLIC int do_mycall()
    {
        int a, b;
        a = mm_in.m1_i1;
        b = mm_in.m1_i2;
    
        mproc[mm_in.m_source].mp_reply.m1_i1 = a+b;
        mproc[mm_in.m_source].mp_reply.m1_i2 = a-b;
        mproc[mm_in.m_source].mp_reply.m1_i3 = a*b;
    
        return OK;
    
    }
    

    Rebuilding the image (in Minix):

    > make hdboot        (KEEP NOTE OF VERSION NUMBER AT END OF SCRIPT!)
    > shutdown
    

    In Minix boot monitor (QEMU):

    d0p0>set
    # change image to /minix/(YOUR VERSION)
    # change net on image to ...;image=/minix/(YOUR VERSION NUMBER)
    # save
    d0p0>boot