os-k/src/kaleid/common/old/common.h

180 lines
4.6 KiB
C

//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
// Authors: spectral` //
// NeoX //
// //
// Desc: Standard include file for both kernel/ and system/ //
//----------------------------------------------------------------------------//
#ifndef _KALCOMM_COMMON_H
#define _KALCOMM_COMMON_H
//------------------------------------------//
// PREPROCESSOR CONSTANTS //
//------------------------------------------//
#if !defined(_OSK_SOURCE)
# if defined(_KALEID_KERNEL) || defined(_KALEID_SYSTEM)
# define _OSK_SOURCE 1
# endif
#endif
#if !defined(TRUE) && !defined(FALSE)
# define TRUE (1)
# define FALSE (0)
#endif
#ifdef _OSK_SOURCE
# define YES (1)
# define NO (0)
#endif
#ifndef NULL
# define NULL ((void *)0)
#endif
#ifndef PACKED
# define PACKED __attribute__((packed))
#endif
#ifndef noreturn
# define noreturn __attribute__((noreturn))
#endif
#if !defined(likely) && !defined(unlikely)
# define likely(x) (__builtin_expect((x), 1))
# define unlikely(x) (__builtin_expect((x), 0))
#endif
#ifndef alignof
# define alignof _Alignof
#endif
#ifndef INITOK
# define INITOK ((unsigned int)0xCAFEBABE)
#endif
#ifndef KALAPI
# define KALAPI
#endif
#ifdef _KALEID_KERNEL
# include <kaleid/kernel/config.h>
#endif
//------------------------------------------//
// COMMON TYPES //
//------------------------------------------//
typedef unsigned char uchar;
typedef unsigned short ushort;
typedef unsigned int uint;
typedef unsigned long ulong;
typedef long long llong;
typedef unsigned long long ullong;
typedef long double ldouble;
typedef short port_t;
typedef short status_t;
#ifndef KEEP_KALCOMM_TYPES_MINIMAL
typedef _Bool bool;
typedef uint wchar_t;
typedef ullong size_t;
typedef llong ssize_t;
typedef size_t off_t;
typedef int atomic_t;
typedef ulong pid_t;
typedef void *va_list;
#endif
// XXX limits
//------------------------------------------//
// VALUES FOR "status_t" //
//------------------------------------------//
#ifndef _OSK_SOURCE
# define describe_status _osk_describe_status
#endif
// see in common/lib/status.c for status messages
const char *describe_status(status_t);
#define STATUS_FAILED(x) ((x) < 0))
#define STATUS_SUCCESS(x) (!STATUS_FAILED(x))
#define SUCCESS (0) // everything went fine
#define FAILED (-1)
#define ERROR FAILED // something went wrong
#define NOT_PERMITTED (-2)
#define ACCESS_DENIED (-3)
#define BAD_ARGUMENT (-4) // invalid arguments
#define BAD_ARG_RANGE (-5) // arguments out of range
#define BAD_ARG_NULL (-6) // unexpected NULL argument
#define TRY_AGAIN (-7) // EAGAIN
//------------------------------------------//
// INLINE ASM MACROS //
//------------------------------------------//
#ifdef _KALEID_KERNEL
# define DisableInterrupts() asm volatile ("cli")
# define EnableInterrupts() asm volatile ("sti")
# define HaltCPU() asm volatile ("hlt")
#endif
//------------------------------------------//
// assert()/DosAssert() SUPPORT //
//------------------------------------------//
#ifdef _OSK_SOURCE
#if !defined(_NO_DEBUG) && !defined(NDEBUG)
// uses panic() in kernel, abort() in system
noreturn void _assert_handler(const char *, const char *, int, const char *);
#define DosAssert(x) \
do { \
if unlikely(!(x)) \
_assert_handler(#x, __FILE__, __LINE__, __func__); \
} while (FALSE);
#define assert DosAssert
#else // not debugging
#if !defined(NDEBUG)
# define NDEBUG 1
#endif
#if !defined(_NO_DEBUG)
# define _NO_DEBUG 1
#endif
#define assert(x)
#endif
#else // !defined(_OSK_SOURCE)
#if defined(_NO_DEBUG) && !defined(NDEBUG)
# define NDEBUG 1
#endif
#include <assert.h>
#endif
//------------------------------------------//
// END OF "kaleid/common/common.h" //
//------------------------------------------//
#endif