2 * Copyright 2002-2005, Axel Dörfler, axeld@pinc-software.de.
3 * Distributed under the terms of the MIT License.
5 * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
6 * Distributed under the terms of the NewOS License.
8 #ifndef _KERNEL_KERNEL_H
9 #define _KERNEL_KERNEL_H
12 #include <config/types.h>
14 #include <arch_kernel.h>
15 #include <arch_config.h>
18 #ifndef KERNEL_LOAD_BASE
19 # define KERNEL_LOAD_BASE KERNEL_BASE
22 // macro to check whether an address is in the kernel address space (avoid
23 // always-true checks)
25 # define IS_KERNEL_ADDRESS(x) ((addr_t)(x) <= KERNEL_TOP)
26 #elif KERNEL_TOP == __HAIKU_ADDR_MAX
27 # define IS_KERNEL_ADDRESS(x) ((addr_t)(x) >= KERNEL_BASE)
29 # define IS_KERNEL_ADDRESS(x) \
30 ((addr_t)(x) >= KERNEL_BASE && (addr_t)(x) <= KERNEL_TOP)
33 // Buffers passed in from user-space shouldn't point into the kernel.
35 # define IS_USER_ADDRESS(x) ((addr_t)(x) <= USER_TOP)
36 #elif USER_TOP == __HAIKU_ADDR_MAX
37 # define IS_USER_ADDRESS(x) ((addr_t)(x) >= USER_BASE)
39 # define IS_USER_ADDRESS(x) \
40 ((addr_t)(x) >= USER_BASE && (addr_t)(x) <= USER_TOP)
43 #define DEBUG_KERNEL_STACKS
44 // Note, debugging kernel stacks doesn't really work yet. Since the
45 // interrupt will also try to use the stack on a page fault, all
46 // you get is a double fault.
47 // At least, you then know that the stack overflows in this case :)
49 /** Size of the kernel stack */
51 #define KERNEL_STACK_SIZE (B_PAGE_SIZE * 4) // 16 kB
53 #define KERNEL_STACK_SIZE (B_PAGE_SIZE * 3) // 12 kB
56 #ifdef DEBUG_KERNEL_STACKS
57 # define KERNEL_STACK_GUARD_PAGES 1
59 # define KERNEL_STACK_GUARD_PAGES 0
62 /** Size of the environmental variables space for a process */
63 #define ENV_SIZE (B_PAGE_SIZE * 8)
66 #define ROUNDDOWN(a, b) (((a) / (b)) * (b))
67 #define ROUNDUP(a, b) ROUNDDOWN((a) + (b) - 1, b)
70 #define CHECK_BIT(a, b) ((a) & (1 << (b)))
71 #define SET_BIT(a, b) ((a) | (1 << (b)))
72 #define CLEAR_BIT(a, b) ((a) & (~(1 << (b))))
73 #define GET_BIT(a, b) ((a & b) != 0)
74 #define TOGGLE_BIT(a, b) (a ^= b)
77 /* during kernel startup, interrupts are disabled (among other things) */
78 extern bool gKernelStartup
;
79 extern bool gKernelShutdown
;
86 status_t
system_shutdown(bool reboot
);
87 status_t
_user_shutdown(bool reboot
);
93 #endif /* _KERNEL_KERNEL_H */