xref: /haiku/headers/private/kernel/kernel.h (revision 16d5c24e533eb14b7b8a99ee9f3ec9ba66335b1e)
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 #define KERNEL_STACK_SIZE		(B_PAGE_SIZE * 3)	// 12 kB
31 
32 #ifdef DEBUG_KERNEL_STACKS
33 #	define KERNEL_STACK_GUARD_PAGES	1
34 #else
35 #	define KERNEL_STACK_GUARD_PAGES	0
36 #endif
37 
38 /** Size of the environmental variables space for a process */
39 #define ENV_SIZE	(B_PAGE_SIZE * 8)
40 
41 
42 #define ROUNDUP(a, b) (((a) + ((b)-1)) & ~((b)-1))
43 #define ROUNDOWN(a, b) (((a) / (b)) * (b))
44 
45 
46 #define CHECK_BIT(a, b) ((a) & (1 << (b)))
47 #define SET_BIT(a, b) ((a) | (1 << (b)))
48 #define CLEAR_BIT(a, b) ((a) & (~(1 << (b))))
49 
50 /* during kernel startup, interrupts are disabled (among other things) */
51 extern bool gKernelStartup;
52 
53 
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
57 
58 status_t system_shutdown(bool reboot);
59 status_t _user_shutdown(bool reboot);
60 
61 #ifdef __cplusplus
62 }
63 #endif
64 
65 #endif	/* _KERNEL_KERNEL_H */
66