-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.h
More file actions
89 lines (72 loc) · 2.1 KB
/
Copy pathcommon.h
File metadata and controls
89 lines (72 loc) · 2.1 KB
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
/* common.h
Common definitions and types.
*/
#ifndef COMMON_H
#define COMMON_H
#ifndef NULL
#define NULL ((void*) 0)
#endif
// Size of a sector on the floppy
#define SECTOR_SIZE 512
// Physical address of the text mode display
#define SCREEN_ADDR ((short *) 0xb8000)
/* If the expression p fails, print the source file and
line number along with the text s. Then hang the os.
Processes should use this macro.
*/
#define ASSERT2(p, s) \
do { \
if (!(p)) { \
print_str(0, 0, "Assertion failure: "); \
print_str(0, 19, s); \
print_str(1, 0, "file: "); \
print_str(1, 6, __FILE__); \
print_str(2, 0, "line: "); \
print_int(2, 6, __LINE__); \
asm volatile ("cli"); \
while (1); \
} \
} while(0)
/* The #p tells the compiler to copy the expression p
into a text string and use this as an argument.
=> If the expression fails: print the expression as a message.
*/
#define ASSERT(p) ASSERT2(p, #p)
// Gives us the source file and line number where we decide to hang the os.
#define HALT(s) ASSERT2(FALSE, s)
// Typedefs of commonly used types
typedef enum {
FALSE, TRUE
} bool_t;
typedef signed char int8_t;
typedef short int int16_t;
typedef int int32_t;
#ifndef FAKE
typedef long long int int64_t;
#endif
typedef unsigned char uint8_t;
typedef unsigned short int uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long long int uint64_t;
typedef unsigned char uchar_t;
typedef unsigned int uint_t;
typedef unsigned long ulong_t;
#define FREE_INODE 0
#define DIRECTORY 1
#define FILE_TYPE 2
#define FS_O_RDONLY 1
#define FS_O_WRONLY 2
#define FS_O_RDWR 3
typedef struct {
// Fill in your stat here, this is just an example
int inodeNo; /* the file i-node number */
short type; /* the file i-node type, DIRECTORY, FILE_TYPE (there's another value FREE_INODE which never appears here */
char links; /* number of links to the i-node */
int size; /* file size in bytes */
int numBlocks; /* number of blocks used by the file */
} fileStat;
struct directory_t {
int location; // Sector number
int size; // Size in number of sectors
};
#endif