2004-11-18 20:49:12 +03:00
|
|
|
/*
|
2005-04-12 10:09:13 +04:00
|
|
|
* Copyright 2002-2005, Axel Dörfler, axeld@pinc-software.de.
|
2004-11-18 20:49:12 +03:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*
|
|
|
|
* Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
|
|
|
|
* Distributed under the terms of the NewOS License.
|
|
|
|
*/
|
2002-07-09 16:24:59 +04:00
|
|
|
#ifndef _KERNEL_KERNEL_H
|
|
|
|
#define _KERNEL_KERNEL_H
|
|
|
|
|
2002-10-29 06:31:57 +03:00
|
|
|
|
2011-01-03 20:56:04 +03:00
|
|
|
#include <config/types.h>
|
|
|
|
|
2002-07-09 16:24:59 +04:00
|
|
|
#include <arch_kernel.h>
|
2004-11-18 20:49:12 +03:00
|
|
|
#include <arch_config.h>
|
|
|
|
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2012-07-06 17:34:50 +04:00
|
|
|
#ifndef KERNEL_LOAD_BASE
|
|
|
|
# define KERNEL_LOAD_BASE KERNEL_BASE
|
|
|
|
#endif
|
|
|
|
|
2011-01-03 20:56:04 +03:00
|
|
|
// macro to check whether an address is in the kernel address space (avoid
|
|
|
|
// always-true checks)
|
|
|
|
#if KERNEL_BASE == 0
|
|
|
|
# define IS_KERNEL_ADDRESS(x) ((addr_t)(x) <= KERNEL_TOP)
|
|
|
|
#elif KERNEL_TOP == __HAIKU_ADDR_MAX
|
|
|
|
# define IS_KERNEL_ADDRESS(x) ((addr_t)(x) >= KERNEL_BASE)
|
|
|
|
#else
|
|
|
|
# define IS_KERNEL_ADDRESS(x) \
|
|
|
|
((addr_t)(x) >= KERNEL_BASE && (addr_t)(x) <= KERNEL_TOP)
|
|
|
|
#endif
|
2004-02-22 17:56:50 +03:00
|
|
|
|
2011-01-03 20:56:04 +03:00
|
|
|
// Buffers passed in from user-space shouldn't point into the kernel.
|
2012-08-02 12:32:33 +04:00
|
|
|
#if USER_BASE == 0
|
|
|
|
# define IS_USER_ADDRESS(x) ((addr_t)(x) <= USER_TOP)
|
|
|
|
#elif USER_TOP == __HAIKU_ADDR_MAX
|
|
|
|
# define IS_USER_ADDRESS(x) ((addr_t)(x) >= USER_BASE)
|
|
|
|
#else
|
|
|
|
# define IS_USER_ADDRESS(x) \
|
|
|
|
((addr_t)(x) >= USER_BASE && (addr_t)(x) <= USER_TOP)
|
|
|
|
#endif
|
2002-10-29 06:31:57 +03:00
|
|
|
|
2006-03-05 21:05:33 +03:00
|
|
|
#define DEBUG_KERNEL_STACKS
|
2004-11-19 23:13:58 +03:00
|
|
|
// Note, debugging kernel stacks doesn't really work yet. Since the
|
|
|
|
// interrupt will also try to use the stack on a page fault, all
|
2005-04-12 10:09:13 +04:00
|
|
|
// you get is a double fault.
|
2004-11-19 23:13:58 +03:00
|
|
|
// At least, you then know that the stack overflows in this case :)
|
|
|
|
|
2002-10-29 06:31:57 +03:00
|
|
|
/** Size of the kernel stack */
|
2013-11-04 21:53:49 +04:00
|
|
|
#ifdef B_HAIKU_64_BIT
|
|
|
|
#define KERNEL_STACK_SIZE (B_PAGE_SIZE * 4) // 16 kB
|
|
|
|
#else
|
|
|
|
#define KERNEL_STACK_SIZE (B_PAGE_SIZE * 3) // 12 kB
|
|
|
|
#endif
|
2008-08-05 21:19:46 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG_KERNEL_STACKS
|
|
|
|
# define KERNEL_STACK_GUARD_PAGES 1
|
2004-11-18 20:49:12 +03:00
|
|
|
#else
|
2008-08-05 21:19:46 +04:00
|
|
|
# define KERNEL_STACK_GUARD_PAGES 0
|
2004-11-18 20:49:12 +03:00
|
|
|
#endif
|
2002-10-29 06:31:57 +03:00
|
|
|
|
|
|
|
/** Size of the environmental variables space for a process */
|
2004-10-20 04:33:06 +04:00
|
|
|
#define ENV_SIZE (B_PAGE_SIZE * 8)
|
2002-10-29 06:31:57 +03:00
|
|
|
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2009-08-03 16:39:56 +04:00
|
|
|
#define ROUNDDOWN(a, b) (((a) / (b)) * (b))
|
|
|
|
#define ROUNDUP(a, b) ROUNDDOWN((a) + (b) - 1, b)
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2002-07-10 17:17:22 +04:00
|
|
|
|
2002-07-09 16:24:59 +04:00
|
|
|
#define CHECK_BIT(a, b) ((a) & (1 << (b)))
|
|
|
|
#define SET_BIT(a, b) ((a) | (1 << (b)))
|
|
|
|
#define CLEAR_BIT(a, b) ((a) & (~(1 << (b))))
|
|
|
|
|
2005-04-12 10:09:13 +04:00
|
|
|
/* during kernel startup, interrupts are disabled (among other things) */
|
2008-08-02 19:03:03 +04:00
|
|
|
extern bool gKernelStartup;
|
2010-09-08 23:19:49 +04:00
|
|
|
extern bool gKernelShutdown;
|
2005-04-12 10:09:13 +04:00
|
|
|
|
|
|
|
|
2004-11-19 23:13:58 +03:00
|
|
|
#ifdef __cplusplus
|
2004-11-26 17:41:53 +03:00
|
|
|
extern "C" {
|
2004-11-19 23:13:58 +03:00
|
|
|
#endif
|
2004-11-26 17:41:53 +03:00
|
|
|
|
2007-05-23 23:56:40 +04:00
|
|
|
status_t system_shutdown(bool reboot);
|
2004-11-26 17:41:53 +03:00
|
|
|
status_t _user_shutdown(bool reboot);
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2002-10-29 06:31:57 +03:00
|
|
|
#endif /* _KERNEL_KERNEL_H */
|