Giter Site home page Giter Site logo

xv6-riscv's Introduction

Working with xv6

Creating a new system call program

  1. Create a new file <new_system_call_name> in user/ directory.

    The new file should contain the following:

        #include "kernel/param.h"
        #include "kernel/types.h"
        #include "kernel/stat.h"
        #include "user/user.h"
        
        int main(int argc, char *argv[]) {
            // code
            exit(exit_status);
        }

    For example, see the user/trace.c file

    Note: The file name should be as same as the command name that you want to use to execute the system call.

  2. Add the new system call command name to user/Makefile as follows:

        UPROGS = \
            ...
            $U/_<new_command_name>\
            ...

    eg: $U/_trace \

    This will allow the make qemu to enable the system call.

    Note: The <new_command_name> part should be the same as the file name created in step 1.

  3. Add an entry to user/usys.pl.

        entry("<new_system_call_name>");

    eg: entry("trace");

    This will route the system call into the kernel.

    Note: The <new_system_call_name> part does not have to be the same as the file name created in step 1. But all the names stated in the following steps should be the same as this one.

  4. Add the prototype of the new system call in user/user.h.

    eg: int trace(int);

  5. Define a system call number in kernel/syscall.h as follows:

        #define SYS_<new_system_call_name> <new_system_call_number>

    eg: #define SYS_trace 22

  6. Define the system call function in kernel/proc.c

        <return type>
        <new_system_call_name>(<args>) {
            // code
        }

    eg: see the trace() function in kernel/proc.c

  7. Add the prototype of the new system call in kernel/defs.h. Preferably under the proc.c comment.

    eg: int trace(int);

  8. Open kernel/sysproc.c and add the handler function that will execute the system call which has just been defined in step 6.

        <return type>
        sys_<new_system_call_name>(void) {
            // code
        }

    eg: see the sys_trace() function in kernel/sysproc.c

  9. In kernel/syscall.c,

    • extern the new system call handler function.

          extern int sys_<new_system_call_name>(void);

      eg: extern int sys_trace(void);

    • Add the new system call name to the syscalls array.

          [SYS_<new_system_call_name>] sys_<new_system_call_name>,

      eg: [SYS_trace] sys_trace,

  10. Make required changes in other functions and files as required.

xv6-riscv's People

Contributors

kaashoek avatar rsc avatar phf avatar fardinanam avatar 4ge32 avatar anishathalye avatar aclements avatar mikecat avatar xiw avatar k-mrm avatar l0stman avatar waheedhafez avatar takahirox avatar ravss avatar pmaddams avatar zeldovich avatar matt-har-vey avatar jrrk2 avatar jjolly avatar d0iasm avatar zhuyu1997 avatar olf0 avatar kimjungwow avatar kehao95 avatar flespark avatar amane-uehara avatar kolontsov avatar tchajed avatar saarett avatar rui314 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.