#ifndef _KERNEL_KERNEL_H
#define _KERNEL_KERNEL_H
#include <config/types.h>
#include <arch_kernel.h>
#include <arch_config.h>
#ifndef KERNEL_LOAD_BASE
# define KERNEL_LOAD_BASE KERNEL_BASE
#endif
#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
#ifndef _BOOT_MODE
#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
#ifdef __cplusplus
static inline bool
is_user_address_range(const void* addr, size_t size)
{
addr_t address = (addr_t)addr;
if ((address + size) < address)
return false;
return IS_USER_ADDRESS(address) && IS_USER_ADDRESS(address + size - 1);
}
#endif
#endif
#define DEBUG_KERNEL_STACKS
#ifdef B_HAIKU_64_BIT
#define KERNEL_STACK_SIZE (B_PAGE_SIZE * 4)
#else
#define KERNEL_STACK_SIZE (B_PAGE_SIZE * 3)
#endif
#ifdef DEBUG_KERNEL_STACKS
# define KERNEL_STACK_GUARD_PAGES 1
#else
# define KERNEL_STACK_GUARD_PAGES 0
#endif
#define ENV_SIZE (B_PAGE_SIZE * 8)
#define ROUNDDOWN(a, b) (((a) / (b)) * (b))
#define ROUNDUP(a, b) ROUNDDOWN((a) + (b) - 1, b)
#define HOWMANY(a, b) (((a) + ((b) - 1)) / (b))
#define CHECK_BIT(a, b) ((a) & (1 << (b)))
#define SET_BIT(a, b) ((a) | (1 << (b)))
#define CLEAR_BIT(a, b) ((a) & (~(1 << (b))))
#define GET_BIT(a, b) ((a & b) != 0)
#define TOGGLE_BIT(a, b) (a ^= b)
extern bool gKernelStartup;
extern bool gKernelShutdown;
#ifdef __cplusplus
extern "C" {
#endif
status_t system_shutdown(bool reboot);
status_t _user_shutdown(bool reboot);
#ifdef __cplusplus
}
#endif
#endif