System Calls: 1 Interrupt Descriptor Table
System Calls: 1 Interrupt Descriptor Table
System Calls: 1 Interrupt Descriptor Table
March 3, 2020
2 Kernel module
The IDT can only be modified in the kernel. In this assignment, you are provided
a working kernel module. A kernel module is a piece of software that is the part
of the kernel. User program can call routines in the kernel module via ioctl
system call. The kernel folder in the assignment repository contains the code
corresponding to kernel module. When the user-program does the ioctl call
for kernel module services, device ioctl (in main.c) is called. ioctl takes an
identifier and a 32-bit argument (user-mode addresses can also be passed using
typecasting). device ioctl invokes the routine corresponding to the input
identifier. You need to implement register syscall and unregister syscall
ioctls.
1
3 klib.c
klib.c in kernel folder implements the following functionalities.
1. print kernel is the system call handler corresponding to the PRINT KERNEL SYS
system call, which can be invoked using the custom system call handler.
2. syscall handler k is the custom system call handler that is invoked by
the syscall handler in ksys.S.
3. imp copy idt allocates space for new IDT, copies the contents of the cur-
rent IDT (loaded in IDTR) to the new IDT, and returns the base and
size of the new IDT in the input struct idt desc. struct idt desc
contains the base address and size of an IDT.
4. imp load idt takes two pointers new and old of type ‘‘struct idt desc
*’’. new contains the base and size of the target IDT. imp load idt loads
the target IDT in IDTR and returns the base and size of the previous IDT
in old.
5. imp free desc takes struct idt desc corresponding to an IDT allocated
in imp copy idt and releases the corresponding memory.
4 Implementation
You need to implement the following routines.
1. syscall handler
2. register syscall
3. unregister syscall
4. syscall u
2
4.2 register syscall
register syscall in “kernel/main.c” is the handler corresponding to the REGISTER SYSCALL
ioctl. This routine allocates a new IDT, modifies the index 15 in the new IDT
to point to the syscall handler routine, and loads the new IDT in IDTR.
You can use the routines in klib.c to implement this functionality. struct
idt entry in klib.h represents an IDT entry. Here, lower16 and higher16 cor-
respond to lower 16-bits and higher 16-bits address of target interrupt handler.
You need to change theses values corresponding to entry at index 15 in the new
IDT. The rest of the fields of the IDT entry can be copied from the default
system call handler (i.e., index 128).
4.4 syscall u
syscall u in “user/usys.S” is the user-mode routine that invokes the syscall handler
using int $15 instruction. syscall u takes an identifier and a buffer and pass
it to the syscall handler via registers.
5 User-program
The user folder contains the user-program. The “user/syscall.c” is the main
program that enables the custom system call handler by doing REGISTER SYSCALL
ioctl, invokes the PRINT KERNEL SYS system call through syscall u, and finally
restores the original IDT using UNREGISTER SYSCALL ioctl. If the system call is
successful, the system call handler copies the string “syscall done.” to the user’s
buffer.
6 Environment
For this assignment, you need to clone the assignment repo from https://
github.com/Systems-IIITD/syscall.
Download Linux 32-bit iso by running:
“scp aos@192.168.1.161:ubuntu-16.04.6-desktop-i386.iso .’’.
The password is aos.
You need to create a virtual machine using this iso image. For this as-
signment, we need a 32-bit Linux OS. We have tested the assignment for the
3
provided Linux distribution (iso image). You have to use the above iso image
for this assignment.
To run:
“cd kernel && sudo ./load” (loads the kernel module).
“cd user && ./syscall” (executes the user program).
The kernel equivalent of printf is printk. You can run dmesg to print the
kernel log (i.e., log generated using printk, etc.) on the terminal.
Before running the user-program, you have to load the kernel module. start module
in “main.c” is called automatically when the module is loaded. If you run dmesg
at this point, you should see “module loaded successfully”. make clean removes
the executables and temporary files.
7 Design documentation
You also have to submit design documentation along with your implementation;
otherwise, the assignment will not be graded. Answer the following questions
in your design documentation.
• Paste your code corresponding to syscall handler.
• Paste your code corresponding to u syscall.
• How do you know the location of the original IDT in unregister syscall?
• How do you know the location of the current IDT in unregister syscall?
• If somebody calls unregister syscall twice, without calling register syscall
in between.
4
7.1 How to submit.
To be done individually. Submit a zip folder that contains four files: “user/usys.S”,
“kernel/ksys.S”, “kernel/main.c”, and design documentation (in pdf format).
Please make sure that your implementation is not printing any debug messages
before submitting the final code. The submission link is on backpack.