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 <config/types.h> 13 14 #include <arch_kernel.h> 15 #include <arch_config.h> 16 17 18 // macro to check whether an address is in the kernel address space (avoid 19 // always-true checks) 20 #if KERNEL_BASE == 0 21 # define IS_KERNEL_ADDRESS(x) ((addr_t)(x) <= KERNEL_TOP) 22 #elif KERNEL_TOP == __HAIKU_ADDR_MAX 23 # define IS_KERNEL_ADDRESS(x) ((addr_t)(x) >= KERNEL_BASE) 24 #else 25 # define IS_KERNEL_ADDRESS(x) \ 26 ((addr_t)(x) >= KERNEL_BASE && (addr_t)(x) <= KERNEL_TOP) 27 #endif 28 29 // Buffers passed in from user-space shouldn't point into the kernel. 30 #define IS_USER_ADDRESS(x) (!IS_KERNEL_ADDRESS(x)) 31 32 #define DEBUG_KERNEL_STACKS 33 // Note, debugging kernel stacks doesn't really work yet. Since the 34 // interrupt will also try to use the stack on a page fault, all 35 // you get is a double fault. 36 // At least, you then know that the stack overflows in this case :) 37 38 /** Size of the kernel stack */ 39 #define KERNEL_STACK_SIZE (B_PAGE_SIZE * 3) // 12 kB 40 41 #ifdef DEBUG_KERNEL_STACKS 42 # define KERNEL_STACK_GUARD_PAGES 1 43 #else 44 # define KERNEL_STACK_GUARD_PAGES 0 45 #endif 46 47 /** Size of the environmental variables space for a process */ 48 #define ENV_SIZE (B_PAGE_SIZE * 8) 49 50 51 #define ROUNDDOWN(a, b) (((a) / (b)) * (b)) 52 #define ROUNDUP(a, b) ROUNDDOWN((a) + (b) - 1, b) 53 54 55 #define CHECK_BIT(a, b) ((a) & (1 << (b))) 56 #define SET_BIT(a, b) ((a) | (1 << (b))) 57 #define CLEAR_BIT(a, b) ((a) & (~(1 << (b)))) 58 59 /* during kernel startup, interrupts are disabled (among other things) */ 60 extern bool gKernelStartup; 61 extern bool gKernelShutdown; 62 63 64 #ifdef __cplusplus 65 extern "C" { 66 #endif 67 68 status_t system_shutdown(bool reboot); 69 status_t _user_shutdown(bool reboot); 70 71 #ifdef __cplusplus 72 } 73 #endif 74 75 #endif /* _KERNEL_KERNEL_H */ 76