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 #ifndef KERNEL_LOAD_BASE 19 # define KERNEL_LOAD_BASE KERNEL_BASE 20 #endif 21 22 // macro to check whether an address is in the kernel address space (avoid 23 // always-true checks) 24 #if KERNEL_BASE == 0 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) 28 #else 29 # define IS_KERNEL_ADDRESS(x) \ 30 ((addr_t)(x) >= KERNEL_BASE && (addr_t)(x) <= KERNEL_TOP) 31 #endif 32 33 // Buffers passed in from user-space shouldn't point into the kernel. 34 #if USER_BASE == 0 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) 38 #else 39 # define IS_USER_ADDRESS(x) \ 40 ((addr_t)(x) >= USER_BASE && (addr_t)(x) <= USER_TOP) 41 #endif 42 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 :) 48 49 /** Size of the kernel stack */ 50 #define KERNEL_STACK_SIZE (B_PAGE_SIZE * 3) // 12 kB 51 52 #ifdef DEBUG_KERNEL_STACKS 53 # define KERNEL_STACK_GUARD_PAGES 1 54 #else 55 # define KERNEL_STACK_GUARD_PAGES 0 56 #endif 57 58 /** Size of the environmental variables space for a process */ 59 #define ENV_SIZE (B_PAGE_SIZE * 8) 60 61 62 #define ROUNDDOWN(a, b) (((a) / (b)) * (b)) 63 #define ROUNDUP(a, b) ROUNDDOWN((a) + (b) - 1, b) 64 65 66 #define CHECK_BIT(a, b) ((a) & (1 << (b))) 67 #define SET_BIT(a, b) ((a) | (1 << (b))) 68 #define CLEAR_BIT(a, b) ((a) & (~(1 << (b)))) 69 70 /* during kernel startup, interrupts are disabled (among other things) */ 71 extern bool gKernelStartup; 72 extern bool gKernelShutdown; 73 74 75 #ifdef __cplusplus 76 extern "C" { 77 #endif 78 79 status_t system_shutdown(bool reboot); 80 status_t _user_shutdown(bool reboot); 81 82 #ifdef __cplusplus 83 } 84 #endif 85 86 #endif /* _KERNEL_KERNEL_H */ 87