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_SYSTM_H_
7#define _FBSD_COMPAT_SYS_SYSTM_H_
8
9
10#include <stdint.h>
11#include <stdio.h>
12#include <string.h>
13#include <strings.h>
14
15#include <machine/atomic.h>
16#include <machine/cpufunc.h>
17
18#include <sys/callout.h>
19#include <sys/cdefs.h>
20#include <sys/queue.h>
21
22#include <sys/libkern.h>
23
24
25#define printf freebsd_printf
26int printf(const char *format, ...) __printflike(1, 2);
27
28
29#define ovbcopy(f, t, l) bcopy((f), (t), (l))
30
31#if KDEBUG_LEVEL_2
32#define INVARIANTS
33#endif
34
35#if KDEBUG_LEVEL_1
36#define bootverbose 1
37#else
38#define bootverbose 0
39#endif
40
41#ifdef INVARIANTS
42#define KASSERT(cond,msg) do {	\
43	if (!(cond))				\
44		panic msg;				\
45} while (0)
46#else
47#define KASSERT(exp,msg) do { \
48} while (0)
49#endif
50
51#define DELAY(n) \
52	do {				\
53		if (n < 1000)	\
54			spin(n);	\
55		else			\
56			snooze(n);	\
57	} while (0)
58
59#define	cold 0
60
61void wakeup(void *);
62void wakeup_one(void *);
63
64#ifndef CTASSERT	/* Allow lint to override */
65#define	CTASSERT(x)	_Static_assert(x, "compile-time assertion failed")
66#endif
67
68
69static inline int
70copyin(const void * __restrict udaddr, void * __restrict kaddr,
71	size_t len)
72{
73	return user_memcpy(kaddr, udaddr, len);
74}
75
76
77static inline int
78copyout(const void * __restrict kaddr, void * __restrict udaddr,
79	size_t len)
80{
81	return user_memcpy(udaddr, kaddr, len);
82}
83
84
85static inline void log(int level, const char *fmt, ...) { }
86
87
88int snprintf(char *, size_t, const char *, ...) __printflike(3, 4);
89extern int sprintf(char *buf, const char *, ...);
90
91extern int driver_vprintf(const char *format, va_list vl);
92#define vprintf(fmt, vl) driver_vprintf(fmt, vl)
93
94extern int vsnprintf(char *, size_t, const char *, __va_list)
95	__printflike(3, 0);
96
97int msleep(void *, struct mtx *, int, const char *, int);
98int _pause(const char *, int);
99#define pause(waitMessage, timeout) _pause((waitMessage), (timeout))
100#define tsleep(channel, priority, waitMessage, timeout) \
101	msleep((channel), NULL, (priority), (waitMessage), (timeout))
102#define msleep_spin(chan, mtx, wmesg, timo) \
103	msleep(chan, mtx, PZERO, wmesg, timo)
104#define mtx_sleep msleep
105
106void critical_enter(void);
107void critical_exit(void);
108
109struct unrhdr;
110struct unrhdr *new_unrhdr(int low, int high, struct mtx *mutex);
111void delete_unrhdr(struct unrhdr *);
112int alloc_unr(struct unrhdr *);
113void free_unr(struct unrhdr *, u_int);
114
115extern char *getenv(const char *name);
116extern void    freeenv(char *env);
117extern char *kern_getenv(const char *name);
118
119#endif	/* _FBSD_COMPAT_SYS_SYSTM_H_ */
120