Files
uiuc-ece391-mp3/student-distrib/sys_calls.c
2018-11-02 00:03:43 -05:00

127 lines
3.1 KiB
C

#include "sys_calls.h"
/* null_func - Added by jinghua3.
*
* A null function placeholder for stdin and stdout.
* INPUT: none.
* OUTPUT: none.
* RETURN: SYSCALL_SUCCESS.
*/
int32_t null_func(){
return SYSCALL_SUCCESS;
}
/* File operations table.
* The entries are functions for:
* open, read, write, close,
* respectively.
*/
/* File operations table for stdin. */
int32_t (*stdin_table[FILE_OP_NUM])() = {null_func, terminal_read, null_func, null_func};
/* File operations table for stdout. */
int32_t (*stdout_table[FILE_OP_NUM])() = {null_func, null_func, terminal_write, null_func};
/* File operations table for rtc. */
int32_t (*rtc_table[FILE_OP_NUM])() = {rtc_open, rtc_read, rtc_write, rtc_close};
/* File operations table for file. */
int32_t (*file_table[FILE_OP_NUM])() = {file_open, file_read, file_write, file_close};
/* File operations rable for directory. */
int32_t (*dir_table[FILE_OP_NUM])() = {dir_open, dir_read, dir_write, dir_close};
/* pcb_init - Added by jinghua3.
*
* Initialize the process control block
* for a process with process id = pid.
* INPUT: int32_t pid which is the process id.
* OUTPUT: init pcb for process whose process id is pid.
* RETURN: A pointer to the initialized pcb.
*/
pcb_t* pcb_init(int32_t pid){
int i, j;
pcb_t* pcb;
// Set the address of pcb at the top of the kernel stack.
pcb = get_pcb_ptr();
// Initialize all the fd_entries.
for (i=0; i<MAX_NUM_FD_ENTRY; i++){
for (j=0; j<FILE_OP_NUM; j++){
pcb->fd_entry[i].fileOpTable_ptr[j] = null_func;
}
pcb->fd_entry[i].inode = INODE_NOT_ASSIGNED;
pcb->fd_entry[i].file_position = FILE_POSITION_NOT_ASSIGNED;
pcb->fd_entry[i].flags = FD_ENTRY_NOT_ASSIGNED;
}
// Initalize stdin.
for(i=0; i<FILE_OP_NUM; i++){
pcb->fd_entry[STDIN_ENTRY].fileOpTable_ptr[i] = stdin_table[i];
}
pcb->fd_entry[STDIN_ENTRY].flags = FD_ENTRY_ASSIGNED;
// Initialize stdout.
for(i=0; i<4; i++){
pcb->fd_entry[STDOUT_ENTRY].fileOpTable_ptr[i] = stdout_table[i];
}
pcb->fd_entry[STDOUT_ENTRY].flags = FD_ENTRY_ASSIGNED;
pcb->process_id = pid;
return pcb;
}
// System calls for checkpoint 3.
int32_t halt (uint8_t status){
return SYSCALL_SUCCESS;
}
int32_t execute (const uint8_t* command){
return SYSCALL_SUCCESS;
}
int32_t read (int32_t fd, void* buf, int32_t nbytes){
return SYSCALL_SUCCESS;
}
int32_t write (int32_t fd, const void* buf, int32_t nbytes){
return SYSCALL_SUCCESS;
}
int32_t open (const uint8_t* filename){
return SYSCALL_SUCCESS;
}
int32_t close (int32_t fd){
return SYSCALL_SUCCESS;
}
// System calls for checkpoint 4.
int32_t getargs (uint8_t* buf, int32_t nbytes){
return SYSCALL_SUCCESS;
}
int32_t vidmap (uint8_t** screen_start){
return SYSCALL_SUCCESS;
}
//Extra credit system calls.
int32_t set_handler (int32_t signum, void* handler_address){
return SYSCALL_SUCCESS;
}
int32_t sigreturn (void){
return SYSCALL_SUCCESS;
}