refactor: one more step towards arch-agnostic design
[lunaix-os.git] / lunaix-os / includes / lunaix / common.h
1 #ifndef __LUNAIX_CONSTANTS_H
2 #define __LUNAIX_CONSTANTS_H
3
4 #define MEM_1MB 0x100000
5 #define MEM_4MB 0x400000
6
7 #define USER_START 0x400000
8
9 #define KSTACK_SIZE MEM_1MB
10 #define KSTACK_START (USER_START - KSTACK_SIZE)
11 #define KSTACK_TOP ((USER_START - 1) & ~0xf)
12 #define within_kstack(addr) (KSTACK_START <= (addr) && (addr) <= KSTACK_TOP)
13
14 #define VGA_FRAMEBUFFER 0xB8000
15
16 #define KCODE_SEG 0x08
17 #define KDATA_SEG 0x10
18
19 #define KSIZE (MEM_4MB * 16)
20
21 #define USTACK_SIZE MEM_4MB
22 #define USTACK_TOP 0x9ffffff0
23 #define USTACK_END (0x9fffffff - USTACK_SIZE + 1)
24 #define UMMAP_START 0x4D000000
25 #define UMMAP_END (USTACK_END - MEM_4MB)
26
27 #ifndef __ASM__
28 #include <lunaix/types.h>
29 // From Linux kernel v2.6.0 <kernel.h:194>
30 /**
31  * container_of - cast a member of a structure out to the containing structure
32  *
33  * @ptr:        the pointer to the member.
34  * @type:       the type of the container struct this is embedded in.
35  * @member:     the name of the member within the struct.
36  *
37  */
38 #define container_of(ptr, type, member)                                        \
39     ({                                                                         \
40         const typeof(((type*)0)->member)* __mptr = (ptr);                      \
41         (ptr) ? (type*)((char*)__mptr - offsetof(type, member)) : 0;           \
42     })
43
44 #endif
45 #endif /* __LUNAIX_CONSTANTS_H */