Search code examples
coperating-systemxv6

Xv6 System Calls


I'm currently doing an assignment for university and I'm having a couple of issues with a couple of system calls that I have to create for Xv6.

The purpose of these system call is to draw in 0x13 mode from a user program.

My issues are:

  • There's a system call that receives some coordinates to save for another system call to use. How and where to I actually store these coordinates (Two int values).
  • On a system call to actually draw a line I need to set the value of a pixel to a colour, calling the system call to set a pixel from the first system call doesn't do anything, is it possible to make a system call from another system call?

If tried to just create two int global variables on the sysproc.c file but I'm not sure that they are being stored.


Solution

  • There's a system call that receives some coordinates to save for another system call to use. How and where to I actually store these coordinates (Two int values).

    You can create a new pair of static variables, you can find some examples of such in kernel, for instance struct superblock sb; in fs.c, or int nextpid = 1; in proc.c

    So in your case, you can have something like:

    int draw_xy[2];
    

    On a system call to actually draw a line I need to set the value of a pixel to a colour, calling the system call to set a pixel from the first system call doesn't do anything, is it possible to make a system call from another system call?

    I think you should not, but you can have a solution.

    Let's image you have a system call named draw_pixel(x, y, color); In your code, you will have something like:

    sys_draw_pixel(void)  {
        int x, y, color;
    
        // read params
        if(argint(0, &x) < 0 || argint(1, &y) < 0 || argint(2, &color) < 0)
        return -1;
    
        // call implementation
        return _draw_pixel_color(x, y, color);
    }
    

    If draw_pixel_color is implemented via _draw_pixel_color, you can call it for other system calls.

    In that case, you can have something like:

    sys_draw_line(void)  {
        int x0, x1, y0, y1, color;
    
        // read params
        if(argint(0, &x0) < 0 || argint(1, &x1) < 0  ..... )
        return -1;
    
        int i, j;
        for(i = x0; i < y1; ++i) 
            for(j = y0; j < y1; ++j) 
                _draw_pixel_color(x, y, color);
    
        return 0;
    
    }