1/* 2 * Copyright 2009, Colin G��nther, coling@gmx.de. 3 * Copyright 2007, Hugo Santos. All Rights Reserved. 4 * Distributed under the terms of the MIT License. 5 */ 6#ifndef _FBSD_COMPAT_SYS_PARAM_H_ 7#define _FBSD_COMPAT_SYS_PARAM_H_ 8 9 10#include <posix/sys/param.h> 11#include <ByteOrder.h> 12 13#include <sys/types.h> 14#include <sys/cdefs.h> 15#include <sys/errno.h> 16#include <sys/time.h> 17#include <sys/priority.h> 18 19 20/* The version this compatibility layer is based on */ 21#define __FreeBSD_version 1200086 22 23#define MAXBSIZE 0x10000 24 25#define PAGE_SHIFT 12 26#define PAGE_MASK (B_PAGE_SIZE - 1) 27 28#define trunc_page(x) ((x) & ~PAGE_MASK) 29 30#define ptoa(x) ((unsigned long)((x) << PAGE_SHIFT)) 31#define atop(x) ((unsigned long)((x) >> PAGE_SHIFT)) 32 33#ifndef MSIZE 34#define MSIZE 256 35#endif 36 37#ifndef MCLSHIFT 38#define MCLSHIFT 11 39#endif 40 41#define MCLBYTES (1 << MCLSHIFT) 42 43#define MJUMPAGESIZE B_PAGE_SIZE 44#define MJUM9BYTES (9 * 1024) 45#define MJUM16BYTES (16 * 1024) 46 47#define ALIGN_BYTES (sizeof(unsigned long) - 1) 48#define ALIGN(x) ((((unsigned long)x) + ALIGN_BYTES) & ~ALIGN_BYTES) 49 50#if defined(__x86_64__) || defined(__i386__) || defined(__M68K__) 51#define ALIGNED_POINTER(p, t) 1 52#elif defined(__powerpc__) 53#define ALIGNED_POINTER(p, t) ((((uintptr_t)(p)) & (sizeof (t) - 1)) == 0) 54#elif defined(__arm__) 55#define ALIGNED_POINTER(p, t) ((((unsigned)(p)) & (sizeof(t) - 1)) == 0) 56#elif defined(__mips__) || defined(__sparc__) \ 57 || (defined(__riscv) && __riscv_xlen == 64) \ 58 || defined(__aarch64__) || defined(__arm64__) 59#define ALIGNED_POINTER(p, t) ((((unsigned long)(p)) & (sizeof (t) - 1)) == 0) 60#else 61#error Need definition of ALIGNED_POINTER for this arch! 62#endif 63 64/* defined in arch_cpu.h which we can't include here as it's C++ */ 65#if defined(__x86_64__) || defined(__i386__) || defined(__arm__) \ 66 || defined(__sparc__) || defined(__riscv) \ 67 || defined(__aarch64__) || defined(__arm64__) 68#define CACHE_LINE_SIZE 64 69#elif defined(__powerpc__) 70#define CACHE_LINE_SIZE 128 71#elif defined(__M68K__) 72#define CACHE_LINE_SIZE 16 73#else 74#error Need definition of CACHE_LINE_SIZE for this arch! 75#endif 76 77/* Macros for counting and rounding. */ 78#ifndef howmany 79#define howmany(x, y) (((x)+((y)-1))/(y)) 80#endif 81#define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) /* to any y */ 82#define roundup2(x, y) (((x) + ((y) - 1)) & (~((y) - 1))) 83#define rounddown(x, y) (((x) / (y)) * (y)) 84#define rounddown2(x, y) ((x)&(~((y)-1))) /* if y is power of two */ 85#define powerof2(x) ((((x)-1)&(x))==0) 86 87#define PRIMASK 0x0ff 88#define PCATCH 0x100 89#define PDROP 0x200 90#define PBDRY 0x400 91 92#define NBBY 8 /* number of bits in a byte */ 93 94/* Bit map related macros. */ 95#define setbit(a,i) (((unsigned char *)(a))[(i)/NBBY] |= 1<<((i)%NBBY)) 96#define clrbit(a,i) (((unsigned char *)(a))[(i)/NBBY] &= ~(1<<((i)%NBBY))) 97#define isset(a,i) \ 98 (((const unsigned char *)(a))[(i)/NBBY] & (1<<((i)%NBBY))) 99#define isclr(a,i) \ 100 ((((const unsigned char *)(a))[(i)/NBBY] & (1<<((i)%NBBY))) == 0) 101 102/* byteswap macros */ 103#ifndef htonl 104# define htonl(x) B_HOST_TO_BENDIAN_INT32(x) 105# define ntohl(x) B_BENDIAN_TO_HOST_INT32(x) 106# define htons(x) B_HOST_TO_BENDIAN_INT16(x) 107# define ntohs(x) B_BENDIAN_TO_HOST_INT16(x) 108#endif 109 110#endif /* _FBSD_COMPAT_SYS_PARAM_H_ */ 111