xref: /haiku/headers/private/kernel/kernel.h (revision 89d652d5e0defd9d095c778709cef82f5f10c357)
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 ROUNDDOWN(a, b)	(((a) / (b)) * (b))
43 #define ROUNDUP(a, b)	ROUNDDOWN((a) + (b) - 1, 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 extern bool gKernelShutdown;
53 
54 
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58 
59 status_t system_shutdown(bool reboot);
60 status_t _user_shutdown(bool reboot);
61 
62 #ifdef __cplusplus
63 }
64 #endif
65 
66 #endif	/* _KERNEL_KERNEL_H */
67