xref: /haiku/headers/private/kernel/kernel.h (revision 3e216965baa8d58a67bf7372e2bfa13d999f5a9d)
1 /*
2  * Copyright 2002-2005, Axel Dörfler, axeld@pinc-software.de.
3  * Distributed under the terms of the MIT License.
4  *
5  * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
6  * Distributed under the terms of the NewOS License.
7  */
8 #ifndef _KERNEL_KERNEL_H
9 #define _KERNEL_KERNEL_H
10 
11 
12 #include <arch_kernel.h>
13 #include <arch_config.h>
14 
15 
16 /* Passed in buffers from user-space shouldn't point into the kernel */
17 #define IS_USER_ADDRESS(x) \
18 	((addr_t)(x) < KERNEL_BASE || (addr_t)(x) > KERNEL_TOP)
19 
20 #define IS_KERNEL_ADDRESS(x) \
21 	((addr_t)(x) >= KERNEL_BASE && (addr_t)(x) <= KERNEL_TOP)
22 
23 #define DEBUG_KERNEL_STACKS
24 	// Note, debugging kernel stacks doesn't really work yet. Since the
25 	// interrupt will also try to use the stack on a page fault, all
26 	// you get is a double fault.
27 	// At least, you then know that the stack overflows in this case :)
28 
29 /** Size of the kernel stack */
30 #ifndef DEBUG_KERNEL_STACKS
31 #	define KERNEL_STACK_SIZE		(B_PAGE_SIZE * 2)	// 8 kB
32 #else
33 #	define KERNEL_STACK_SIZE		(B_PAGE_SIZE * 3)	// 8 kB + one guard page
34 #endif
35 #define KERNEL_STACK_GUARD_PAGES	1
36 
37 /** Size of the stack given to teams in user space */
38 #define USER_MAIN_THREAD_STACK_SIZE	(16 * 1024 * 1024)	// 16 MB
39 #define USER_STACK_SIZE				(256 * 1024)		// 256 kB
40 #define USER_STACK_GUARD_PAGES		4					// 16 kB
41 
42 /** Size of the environmental variables space for a process */
43 #define ENV_SIZE	(B_PAGE_SIZE * 8)
44 
45 
46 #define ROUNDUP(a, b) (((a) + ((b)-1)) & ~((b)-1))
47 #define ROUNDOWN(a, b) (((a) / (b)) * (b))
48 
49 
50 #define CHECK_BIT(a, b) ((a) & (1 << (b)))
51 #define SET_BIT(a, b) ((a) | (1 << (b)))
52 #define CLEAR_BIT(a, b) ((a) & (~(1 << (b))))
53 
54 /* during kernel startup, interrupts are disabled (among other things) */
55 extern bool kernel_startup;
56 
57 
58 #ifdef __cplusplus
59 extern "C" {
60 #endif
61 
62 status_t shutdown(bool reboot);
63 status_t _user_shutdown(bool reboot);
64 
65 #ifdef __cplusplus
66 }
67 #endif
68 
69 #endif	/* _KERNEL_KERNEL_H */
70