MP3 1.0
This is the Doxygen document for ECE391 MP3.
Loading...
Searching...
No Matches
Functions
sys_call.c File Reference

System call Implementations. More...

#include "sys_call.h"
#include "filesystem.h"
#include "file_descriptor.h"
#include "paging.h"
#include "lib.h"
#include "pcb.h"
#include "x86_desc.h"
#include "keyboard.h"
#include "terminal.h"

Functions

int32_t halt (uint8_t status)
 halt system call More...
 
int32_t execute (const uint8_t *command)
 Executes a given command, loads the program into memory, and performs a context switch. More...
 
int32_t read (int32_t fd, void *buf, int32_t nbytes)
 Reads data from a file descriptor into a buffer. More...
 
int32_t write (int32_t fd, const void *buf, int32_t nbytes)
 Writes data from a buffer into a file. More...
 
int32_t open (const uint8_t *filename)
 Opens a file given its filename. More...
 
int32_t close (int32_t fd)
 Close a file by freeing the file descriptor. More...
 
int32_t getargs (uint8_t *buf, int32_t nbytes)
 Get args from the command line and store it in a buffer. More...
 
int32_t vidmap (uint8_t **screenStart)
 Map the passed in address to the video memory. More...
 
int32_t set_handler (int32_t signum, void *handler_address)
 set_handler system call. More...
 
int32_t sigreturn ()
 sigreturn system call More...
 

Detailed Description

System call Implementations.

Author
Group 8
Version
1.0
Date
2023-03-17

Function Documentation

◆ close()

int32_t close ( int32_t  fd)

Close a file by freeing the file descriptor.

Parameters
fdFile descriptor to close.
Returns
-1 on failure.
0 on success.

◆ execute()

int32_t execute ( const uint8_t command)

Executes a given command, loads the program into memory, and performs a context switch.

This function executes a command by allocating a program page, loads it into memory, and performs a context switch. It parses the command and arguments, validates the file, obtains the PCB, and updates the TSS.

Parameters
commanda space-separated sequence of words. The first word is the file name of the program to be executed, and the remaining words are the arguments.
Returns
-1 on failure.
256 if the program dies by exception.
0 for reading from RTC.
value given by halt function.
Note
This function uses the contextSwitch() function to perform the actual context switch.
Warning
This function will assume the currPID as the parentPID for the newly created program. This will be a issue when implementing scheduling.

◆ getargs()

int32_t getargs ( uint8_t buf,
int32_t  nbytes 
)

Get args from the command line and store it in a buffer.

Parameters
bufBuffer to store the command line arguments in.
nbytesNumber of bytes to read from the command line arguments.
Returns
-1 if there are no arguments or the arguments do not fit.
0 on success.
See also
pcbArray

◆ halt()

int32_t halt ( uint8_t  status)

halt system call

This function is responsible for halting a process and returning control to its parent process.

Parameters
statusThe status to be returned
Returns
The status passed in.
256 if any error occured in the function.
Note
If the process is the mother shell, it will not halt, but will instead execute a new shell.

◆ open()

int32_t open ( const uint8_t filename)

Opens a file given its filename.

allocates an unused file descriptor and sets up any data necessary to handle the given type of file.

Parameters
filenameName of the file to be opened.
Returns
-1 on failure.
0 on success.

◆ read()

int32_t read ( int32_t  fd,
void *  buf,
int32_t  nbytes 
)

Reads data from a file descriptor into a buffer.

It checks for valid file descriptor bounds, ensures the file is in use, and invokes the appropriate read function using the file pointer.

Parameters
fdFile descriptor to read from.
bufBuffer to place the bytes read into.
nbytesNumber of bytes to read.
Returns
Number of bytes read.
-1 on failure.
0 if the initial file position is at or beyond the end of file.

◆ set_handler()

int32_t set_handler ( int32_t  signum,
void *  handler_address 
)

set_handler system call.

Parameters
signum
handler_address
Returns
-1.
Note
Not implemented.

◆ sigreturn()

int32_t sigreturn ( )

sigreturn system call

Returns
-1.
Note
Not implemented.

◆ vidmap()

int32_t vidmap ( uint8_t **  screenStart)

Map the passed in address to the video memory.

maps the text-mode video memory into user space at a pre-set virtual address.

Parameters
screenStartMemory location to place the address of the start of the video map in.
Returns
user-level memory location of the video map.
-1 if screenStart is invalid

◆ write()

int32_t write ( int32_t  fd,
const void *  buf,
int32_t  nbytes 
)

Writes data from a buffer into a file.

This function handles writing data from a buffer to a file descriptor. It validates the file descriptor, checks if the file is in use, and calls the appropriate write function using the file pointer.

Parameters
fdFile descriptor to read from.
bufBuffer to place the bytes read into.
nbytesNumber of bytes to read.
Returns
-1 on failure.
0 on success.