My Kernel v0.1.0
memory.h
Go to the documentation of this file.
1
47#ifndef KERNEL_MEMORY_H
48#define KERNEL_MEMORY_H
49
50#if ARCH == i686
52#endif
53
54#ifndef KERNEL_STACK_SIZE
55#define KERNEL_STACK_SIZE 0x4000U
56#endif
57
58#ifndef USER_STACK_SIZE
59#define USER_STACK_SIZE 0x10000U
60#endif
61
62#ifndef __ASSEMBLER__
63
64#include <utils/compiler.h>
65#include <utils/math.h>
66
67/* We want to allocate stacks using the VM API, which can only allocate pages */
69static_assert(is_aligned(USER_STACK_SIZE, PAGE_SIZE));
70
71#endif
72
73/* Starting from #6, our kernel uses the higher-half design.
74 *
75 * This means that the kernel code's virtual address differs from its physical
76 * one. The following constants are used by the linker script and should be
77 * used by the functions that depend on them instead of hardcoding values.
78 */
79
80#define KERNEL_IS_HIGHER_HALF 1
81
82// TODO: These values are duplicated inside the linkerscript
83// We should maybe find a way to include this header before linking the
84// kernel to avoid conflicts
85
87#define KERNEL_PHYSICAL_START 0x00100000UL
89#define KERNEL_HIGHER_HALF_OFFSET 0xC0000000UL
90
91#ifdef __ASSEMBLER__
92
93#define KERNEL_HIGHER_HALF_PHYSICAL(_virtual) \
94 ((_virtual) - KERNEL_HIGHER_HALF_OFFSET)
95#define KERNEL_HIGHER_HALF_VIRTUAL(_physical) \
96 ((_physical) + KERNEL_HIGHER_HALF_OFFSET)
97
98#else
99
102#define KERNEL_HIGHER_HALF_PHYSICAL(_virtual) \
103 ((u32)(_virtual) - KERNEL_HIGHER_HALF_OFFSET)
105#define KERNEL_HIGHER_HALF_VIRTUAL(_physical) \
106 ((u32)(_physical) + KERNEL_HIGHER_HALF_OFFSET)
107
108#include <kernel/types.h>
109
118extern u32 _kernel_code_start;
119#define KERNEL_CODE_START ((u32) & _kernel_code_start)
120
129extern u32 _kernel_code_end;
130#define KERNEL_CODE_END ((u32) & _kernel_code_end)
131
132#endif /* __ASSEMBLER__ */
133
134#define PAGE_TABLES_START (0xFFC00000)
135
140#define KERNEL_VMM_RESERVED_END (PAGE_TABLES_START)
141#define KERNEL_VMM_RESERVED_START (KERNEL_VMM_RESERVED_END - VMM_RESERVED_SIZE)
144#define KERNEL_ADDRESS_SPACE_END (KERNEL_VMM_RESERVED_START)
145#define KERNEL_ADDRESS_SPACE_START (KERNEL_CODE_END)
146
147#define KERNEL_MEMORY_END (ADDRESS_SPACE_END)
148#define KERNEL_MEMORY_START (KERNEL_HIGHER_HALF_OFFSET)
149
150#define USER_MEMORY_END KERNEL_MEMORY_START
151#define USER_MEMORY_START VMM_RESERVED_END
152
160#define VMM_RESERVED_END 0x100000UL
161#define VMM_RESERVED_START NULL_PAGE_END
162#define VMM_RESERVED_SIZE (VMM_RESERVED_END + VMM_RESERVED_START)
163
165#define NULL_PAGE_SIZE PAGE_SIZE
166#define NULL_PAGE_START 0x0
167#define NULL_PAGE_END (NULL_PAGE_START + NULL_PAGE_SIZE)
168
169#define PAGE_ALIGN_DOWN(_ptr) align_down_ptr(_ptr, PAGE_SIZE)
170#define PAGE_ALIGN_UP(_ptr) align_up_ptr(_ptr, PAGE_SIZE)
171#define PAGE_ALIGNED(_ptr) is_aligned_ptr(_ptr, PAGE_SIZE)
172
173#endif /* KERNEL_MEMORY_H */
#define PAGE_SIZE
The size of a single page.
Definition: memory.h:23
#define USER_STACK_SIZE
Definition: memory.h:59
#define KERNEL_STACK_SIZE
Definition: memory.h:55
u32 _kernel_code_end
Address of the byte located just after the end of the kernel's code.
u32 _kernel_code_start
Address of the byte located just before the end of the kernel's code.
#define is_aligned(_value, _alignment)
Definition: math.h:57