83 lines
2.3 KiB
C
83 lines
2.3 KiB
C
#ifndef _SYS_CALL_H
|
|
#define _SYS_CALL_H
|
|
|
|
#include "x86_desc.h"
|
|
#include "lib.h"
|
|
#include "fs/ece391fs.h"
|
|
#include "devices/keyboard.h"
|
|
#include "devices/rtc.h"
|
|
|
|
#define SYSCALL_SUCCESS 1
|
|
#define SYSCALL_FAIL 0
|
|
#define MAX_NUM_FD_ENTRY 8
|
|
#define FILE_OP_NUM 4
|
|
#define STDIN_ENTRY 0
|
|
#define STDOUT_ENTRY 1
|
|
#define FD_ENTRY_ASSIGNED 1
|
|
#define FD_ENTRY_NOT_ASSIGNED 0
|
|
#define INODE_NOT_ASSIGNED -1
|
|
#define FILE_POSITION_NOT_ASSIGNED -1
|
|
#define KER_STACK_BITMASK 0xFFFFE000 // Use the higher 19 bits to get top of 8KB kernel stack.
|
|
|
|
// System calls for checkpoint 3.
|
|
int32_t halt (uint8_t status);
|
|
int32_t execute (const uint8_t* command);
|
|
int32_t read (int32_t fd, void* buf, int32_t nbytes);
|
|
int32_t write (int32_t fd, const void* buf, int32_t nbytes);
|
|
int32_t open (const uint8_t* filename);
|
|
int32_t close (int32_t fd);
|
|
|
|
// System calls for checkpoint 4.
|
|
int32_t getargs (uint8_t* buf, int32_t nbytes);
|
|
int32_t vidmap (uint8_t** screen_start);
|
|
|
|
//Extra credit system calls.
|
|
int32_t set_handler (int32_t signum, void* handler_address);
|
|
int32_t sigreturn (void);
|
|
|
|
|
|
|
|
// Entry of the file array in process control block.
|
|
typedef struct file_descriptor_entry {
|
|
int32_t (*fileOpTable_ptr[FILE_OP_NUM])(); // pointer to file operations table
|
|
int32_t inode;
|
|
int32_t file_position;
|
|
int32_t flags;
|
|
} fd_entry_t;
|
|
|
|
typedef struct process_control_block {
|
|
fd_entry_t fd_entry[MAX_NUM_FD_ENTRY];
|
|
uint32_t process_id; // current process id;
|
|
uint32_t parent_pid; // parent process id;
|
|
uint32_t esp; // save esp;
|
|
// more entries to be added......
|
|
|
|
} pcb_t;
|
|
|
|
// Helper functions for system calls.
|
|
/* get_pcb_ptr - Added by jinghua3.
|
|
* input: none.
|
|
* output: none.
|
|
* return value: pointer to the pcb struct.
|
|
* side effects: none
|
|
*/
|
|
static inline pcb_t* get_pcb_ptr(){
|
|
uint32_t pcb_ptr;
|
|
asm volatile (
|
|
"movl %%esp, %0"
|
|
: "=r" (pcb_ptr)
|
|
:
|
|
: "memory"
|
|
);
|
|
|
|
// Use the higher 19 bits to get top of 8KB kernel stack.
|
|
pcb_ptr &= KER_STACK_BITMASK;
|
|
return (pcb_t *) pcb_ptr;
|
|
}
|
|
|
|
int32_t null_func();
|
|
pcb_t* pcb_init(int32_t pid);
|
|
|
|
|
|
#endif /* _SYS_CALL_H */
|