Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help in c program thank you. Date System Call A system call is how a program requests service from an operating systems kernel. System

Need help in c program thank you.

Date System Call

A system call is how a program requests service from an operating systems kernel. System calls may include hardware related services, creation and execution of new processes and process scheduling. It is also possible for a system call to be made only from user space processes.

In this assignment you will implement a simplified version of the UNIX date command. This command gives current system date.

For example, if we run date 0, then the current system date is returned in 24 hour format in GMT time zone. If we run date 1, then the current system date is returned in 12 hour format in GMT time zone.

Go through chapter 1 in xv6 reference book to have a basic understanding of system calls in xv6.

Setting up a System Call

A system call must be both available in the user space and kernel space. It must be available in user space so that it can be used other programs and it must be available in kernel space so has permission to access resources that prohibited from user mode.

User Program (date.c)

In date.c file, you will implement the date user program. To write this program, you need to get familiar to rtcdate structure in date.h file, and cmostime function in lapic.c file. To add date.c as a user program, add date to makefile like in previous assignment.

You cannot call cmostime function from a user program. So, you need to write a system call getDate() to access cmostime for you. You will call the getDate system call in your user program to return the current date by reference.

You are responsible to create a new file called date.c, and write a program that will:

Accepts arguments from the command line interface. You are expected to do the necessary error checking with the corresponding error message. See examples at the end of the handout.

Get the date by calling getDate system call o int getDate(struct rtcdate *myDate)

Print the date or the error message.

getDate System call

Make changes in user.h, usys.s, syscall.h, syscall.c like in previous assignment. You need to write getDate system call in sysproc.c. When your system call is called from your user program, the system call number and arguments are setup for you by the operating system. If the system call number is valid, it will begin running your system call function in sysproc.c. The arguments you passed to the system call in your user program are stored in the stack for security. This is why all functions in sysproc.c take no arguments even when the system call takes arguments when it is called from your user program. You need to retrieve them in your system call in sysproc.c by using argptr, argint, etc. Please refer to sys_sleep in sysproc.c for a hint. But you need to use argptr in this system call. Refer chapter 3, page 44-45 in xv6 reference book.

To implement getDate:

create a variable to put the argument

use argptr to get address of myDate struct passed as 0th argument (Hint: look for argptr in syscall.c)

if argptr fails to get the pointer, return -1

else, use cmostime to fill the struct and return 0 (Hint: look for cmostime in lapic.c)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

50 Tips And Tricks For MongoDB Developers Get The Most Out Of Your Database

Authors: Kristina Chodorow

1st Edition

1449304613, 978-1449304614

More Books

Students also viewed these Databases questions

Question

Add a method countNodesWithOneChild to the BinaryTree class.

Answered: 1 week ago

Question

x-3+1, x23 Let f(x) = -*+3, * Answered: 1 week ago

Answered: 1 week ago

Question

Write a letter asking them to refund your $1,500 down payment.

Answered: 1 week ago