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 #ifdef B_HAIKU_64_BIT 51 #define KERNEL_STACK_SIZE (B_PAGE_SIZE * 4) // 16 kB 52 #else 53 #define KERNEL_STACK_SIZE (B_PAGE_SIZE * 3) // 12 kB 54 #endif 55 56 #ifdef DEBUG_KERNEL_STACKS 57 # define KERNEL_STACK_GUARD_PAGES 1 58 #else 59 # define KERNEL_STACK_GUARD_PAGES 0 60 #endif 61 62 /** Size of the environmental variables space for a process */ 63 #define ENV_SIZE (B_PAGE_SIZE * 8) 64 65 66 #define ROUNDDOWN(a, b) (((a) / (b)) * (b)) 67 #define ROUNDUP(a, b) ROUNDDOWN((a) + (b) - 1, b) 68 69 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) 75 76 77 /* during kernel startup, interrupts are disabled (among other things) */ 78 extern bool gKernelStartup; 79 extern bool gKernelShutdown; 80 81 82 #ifdef __cplusplus 83 extern "C" { 84 #endif 85 86 status_t system_shutdown(bool reboot); 87 status_t _user_shutdown(bool reboot); 88 89 #ifdef __cplusplus 90 } 91 #endif 92 93 #endif /* _KERNEL_KERNEL_H */ 94