feat: basic elf32 loader (only LOAD segment is supported)
[lunaix-os.git] / lunaix-os / includes / lunaix / common.h
1 #ifndef __LUNAIX_CONSTANTS_H
2 #define __LUNAIX_CONSTANTS_H
3
4 #define PG_SIZE_BITS 12
5 #define PG_SIZE (1 << PG_SIZE_BITS)
6 #define PG_INDEX_BITS 10
7
8 #define MEM_1MB 0x100000
9 #define MEM_4MB 0x400000
10
11 #define USER_START 0x400000
12
13 #define KSTACK_SIZE MEM_1MB
14 #define KSTACK_START (USER_START - KSTACK_SIZE)
15 #define KSTACK_TOP ((USER_START - 1) & ~0xf)
16
17 #define KERNEL_MM_BASE 0xC0000000
18
19 #define KCODE_MAX_SIZE MEM_4MB
20 // #define KHEAP_START (KERNEL_MM_BASE + KCODE_MAX_SIZE)
21 // #define KHEAP_SIZE_MB 256
22
23 #define VGA_FRAMEBUFFER 0xB8000
24
25 #define KCODE_SEG 0x08
26 #define KDATA_SEG 0x10
27 #define UCODE_SEG 0x1B
28 #define UDATA_SEG 0x23
29 #define TSS_SEG 0x28
30
31 #define USTACK_SIZE MEM_4MB
32 #define USTACK_TOP 0x9ffffff0
33 #define USTACK_END (0x9fffffff - USTACK_SIZE + 1)
34 #define UMMAP_START 0x4D000000
35 #define UMMAP_END (USTACK_END - MEM_4MB)
36
37 #ifndef __ASM__
38 #include <stddef.h>
39 // From Linux kernel v2.6.0 <kernel.h:194>
40 /**
41  * container_of - cast a member of a structure out to the containing structure
42  *
43  * @ptr:        the pointer to the member.
44  * @type:       the type of the container struct this is embedded in.
45  * @member:     the name of the member within the struct.
46  *
47  */
48 #define container_of(ptr, type, member)                                        \
49     ({                                                                         \
50         const typeof(((type*)0)->member)* __mptr = (ptr);                      \
51         (ptr) ? (type*)((char*)__mptr - offsetof(type, member)) : 0;           \
52     })
53
54 #endif
55 #endif /* __LUNAIX_CONSTANTS_H */