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:
- main.c:
#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;
}
- added mycall.c to same directory (given code has typos, I assume that
k
should ber
):
#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;
}
- added to /usr/mm/proto.h:
_PROTOTYPE( int do_mycall, (void));
- added
do_mycall /* 58 = unused */
to /usr/mm/table.c
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.