-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsys_handler.h
117 lines (90 loc) · 3.23 KB
/
sys_handler.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#ifndef _SYSHANDLER_H
#define _SYSHANDLER_H
#include "types.h"
#include "x86_desc.h"
#include "pcb.h"
#include "filesys_struct.h"
#include "file.h"
#include "filesys.h"
#include "rtc.h"
#include "lib.h"
#include "paging.h"
#include "calendar.h"
/* masks esp to get the address of the current pcb */
#define PCB_MASK 0xFFFFE000
#define FLAGS_IN_USE 0x00000001
#define KERNEL_END 0x00800000
#define KERNEL_START 0x00400000
#define USER_START_PAGE 0x08000000
#define USER_END_PAGE 0x08400000
#define USER_START_PAGE2 0x00800000
#define USER_END_PAGE2 0x00C00000
#define PAGE_SIZE_4KB 4096
#define VID_MAP 0x003000F0
#define VIDEO_MEM 0xB8000
#define EXE_NAME_ADDR 0x0200002
#define ARG_TEMP_ADDR 0x0300002
#define ARG2_TEMP_ADDR 0x0300082
/* where the address of the first task starts (8MB - 8kB) */
//#define TASK_MASK0 0x007FE000
/* where the address of the first task starts (8MB - 16kB) */
//#define TASK_MASK1 0x007FC000
#define PROG_IMG_OFFSET 0x00048000
#define MAX_PROC 6
#define BUF_SIZE 1024
/* what is the maximum file size allowed for an executable ? 36 K is the size of one of them*/
#define FILE_READ_SIZE 4096
#define ELF_BYTES 4 // the number of bytes needed to identify an executable
#define ELF_START 24 // the first byte of the
#define ELF_START_ADDR 4
#define PROGRAM_START 0x08048000
#define ARGUMENT_LENGTH 32
/* for signals */
#define DIV_ZERO 0
#define SEGFAULT 1
#define INTERRUPT 2
#define ALARM 3
#define USER1 4
#define CHAR_OFFSET 48
#define POW_BASE 10
/* looks like bytes[0]:bytes[1]:bytes[2]:bytes[3] */
#define get_dword_from_bytes(dword,bytes) \
dword = ((bytes)[3] << 24) + ((bytes)[2] << 16) + ((bytes)[1] << 8) + (bytes)[0]
#define kernel_stack_for_proc(pid) \
(KERNEL_END - pid * PAGE_SIZE_4KB*2)
/* kill a process */
int32_t halt(uint8_t status);
/* start a process */
int32_t execute(const uint8_t* command);
/* read from a file; store data into given buffer */
int32_t read(int32_t fd, void* buf, int32_t nbytes);
/* write given buffer's data into a file */
int32_t write(int32_t fd, const void* buf, int32_t nbytes);
/* find a vacant file struct, fill it, then return file descriptor */
int32_t open(const uint8_t* filename);
/* clear the specified file struct's field (make vacant) */
int32_t close(int32_t fd);
/* stores program arguments in pcb */
int32_t getargs(uint8_t* buf, int32_t nbytes);
/* TODO */
int32_t vidmap(uint8_t** screen_start);
/* TODO */
int32_t set_handler(int32_t signum, void* handler_address);
/* TODO */
int32_t sigreturn(void);
/*** helper functions c: ***/
/* gets the pcb of the currently running process */
pcb_t * get_current_pcb(void);
pcb_t * get_pcb_from_pid(int32_t pid);
/* gets the file array associated with the current pcb */
file_t * get_file_array(void);
/* indicates if the specified file is in use */
int32_t file_in_use( int32_t fd );
/* copies a program images into contiguous memory */
int32_t loder( uint32_t inode_idx );
/* adds a new "active" process */
int32_t get_new_pid(void);
/* removes a process from the "active" array */
int32_t release_pid( int32_t pid );
int32_t switch_to_process( int32_t pid );
#endif