omega
omega

Reputation: 43843

How to add a new system call in OS/161?

I am trying to add a new system call in my OS/161 code, but I am having trouble figuring out where to add the prototypes. I believe you're supposed to add it to the kernel space and user space, but I'm not sure exactly which files to put the prototype in. Is there a guide somewhere that explains how to add a sample system call in OS/161?

As a test I am trying to add a function, printone(), that when the user runs that program, it will just print a "1".

Upvotes: 1

Views: 3941

Answers (1)

Alexey Frunze
Alexey Frunze

Reputation: 62048

Add another system call number, e.g. SYS_print1 in callno.h or wherever those constants like SYS_fork and SYS_read are defined.

Find the place where they are used to choose functions to call, looks like it should be mips_syscall(). Although, I'm not sure why in this version of the source code there's only SYS_reboot used to call sys_reboot(). This source code reference is probably incomplete. The comment suggests that:

00049 mips_syscall(struct trapframe *tf)
00050 {
...
00070         switch (callno) {
00071             case SYS_reboot:
00072                 err = sys_reboot(tf->tf_a0);
00073                 break;
00074 
00075             /* Add stuff here */
00076  
00077             default:
00078                 kprintf("Unknown syscall %d\n", callno);
00079                 err = ENOSYS;
00080                 break;
00081         }
...
00108 }

Similarly add your case SYS_print1: and implement the functionality in a dedicated function, say sys_print1().

That should be it for the kernel side.

The user-mode prototype for print1() can be declared in unistd.h alongside with read() and the like.

Looks like the user-mode implementation of read() might be in an assembly file. And that's reasonable since in the end it should execute the MIPS syscall instruction unavailable directly in C. You should implement print1() in a similar fashion (load SYS_print1 into the appropriate register and execute syscall).

Upvotes: 2

Related Questions