* same with xv6
[mascara-docs.git] / i386 / ucla / src / lab1 / inc / types.h
blob8ab187bb48b993d5c7fc7a756dfc2bde03e82bd9
1 #ifndef JOS_INC_TYPES_H
2 #define JOS_INC_TYPES_H
4 #ifndef NULL
5 #ifdef __cplusplus
6 #define NULL __null
7 #else
8 #define NULL ((void *) 0)
9 #endif
10 #endif
12 #ifndef __cplusplus
13 // Represents true-or-false values
14 typedef int bool;
15 #endif
17 // Explicitly-sized versions of integer types
18 typedef __signed char int8_t;
19 typedef unsigned char uint8_t;
20 typedef short int16_t;
21 typedef unsigned short uint16_t;
22 typedef int int32_t;
23 typedef unsigned int uint32_t;
24 typedef long long int64_t;
25 typedef unsigned long long uint64_t;
27 // Pointers and addresses are 32 bits long.
28 // We use pointer types to represent virtual addresses,
29 // uintptr_t to represent the numerical values of virtual addresses,
30 // and physaddr_t to represent physical addresses.
31 typedef int32_t intptr_t;
32 typedef uint32_t uintptr_t;
33 typedef uint32_t physaddr_t;
35 // Page numbers are 32 bits long.
36 typedef uint32_t ppn_t;
38 // size_t is used for memory object sizes.
39 typedef uint32_t size_t;
40 // ssize_t is a signed version of ssize_t, used in case there might be an
41 // error return.
42 typedef int32_t ssize_t;
44 // off_t is used for file offsets and lengths.
45 typedef int32_t off_t;
47 // Efficient min and max operations
48 #define MIN(_a, _b) \
49 ({ \
50 typeof(_a) __a = (_a); \
51 typeof(_b) __b = (_b); \
52 __a <= __b ? __a : __b; \
54 #define MAX(_a, _b) \
55 ({ \
56 typeof(_a) __a = (_a); \
57 typeof(_b) __b = (_b); \
58 __a >= __b ? __a : __b; \
61 // Rounding operations (efficient when n is a power of 2)
62 // Round down to the nearest multiple of n
63 #define ROUNDDOWN(a, n) \
64 ({ \
65 uint32_t __a = (uint32_t) (a); \
66 (typeof(a)) (__a - __a % (n)); \
68 // Round up to the nearest multiple of n
69 #define ROUNDUP(a, n) \
70 ({ \
71 uint32_t __n = (uint32_t) (n); \
72 (typeof(a)) (ROUNDDOWN((uint32_t) (a) + __n - 1, __n)); \
75 // Return the offset of 'member' relative to the beginning of a struct type
76 #define offsetof(type, member) ((size_t) (&((type*)0)->member))
78 // Decoration for functions that are accessed from assembly
79 #ifdef __cplusplus
80 #define asmlinkage extern "C"
81 #else
82 #define asmlinkage /* nothing */
83 #endif
85 #endif /* !JOS_INC_TYPES_H */