Limits stuff

This commit is contained in:
Julian Barathieu 2019-01-01 20:46:06 +01:00
parent 452771f8ba
commit b04ead6130
8 changed files with 167 additions and 31 deletions

View File

@ -8,6 +8,7 @@
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <kaleid.h> #include <kaleid.h>
#include <kallims.h>
//------------------------------------------// //------------------------------------------//
// memset() family // // memset() family //

View File

@ -1 +1,35 @@
int rand(void) { /*STUB*/ return 0; } //----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
// Authors: spectral` //
// NeoX //
// //
// Desc: RNG related functions //
//----------------------------------------------------------------------------//
#include <kaleid.h>
#include <kallims.h>
//
// Seed value
//
static ulong next = 7756;
//
// Returns a pseudo-random integer
// To be improved
//
int rand(void)
{
next = next * 1103515245 + 12345;
return (uint)(next / 65536) % INT_MAX;
}
//
// (Re)Set the random seed
//
void srand(uint seed)
{
next = (ulong)seed;
}

View File

@ -1,12 +1,17 @@
// random test file // random test file
#include <stdio.h> #include <stdio.h>
#include <limits.h>
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
long x[4]; long x[4];
long *ptr = &x[0]; long *ptr = &x[0];
printf("%d\n", CHAR_MIN);
printf("%hhd\n", (1 << 7));
printf("%p\n", ptr); printf("%p\n", ptr);
ptr++; ptr++;

View File

@ -30,26 +30,14 @@
#define INITOK ((unsigned int)0xCAFEBABE) #define INITOK ((unsigned int)0xCAFEBABE)
#endif #endif
#ifndef DATA_SIZE_BLOCK
#define DATA_SIZE_BLOCK
# define BYTE_SIZE sizeof(char)
# define WORD_SIZE sizeof(short)
# define DWORD_SIZE sizeof(int)
# define QWORD_SIZE sizeof(long)
#endif
#ifndef DATA_ALIGN_BLOCK
#define DATA_ALIGN_BLOCK
# define BYTE_ALIGN alignof(char)
# define WORD_ALIGN alignof(short)
# define DWORD_ALIGN alignof(int)
# define QWORD_ALIGN alignof(long)
#endif
//------------------------------------------// //------------------------------------------//
// Keywords and attributes // // Keywords and attributes //
//------------------------------------------// //------------------------------------------//
#ifndef alignof
#define alignof _Alignof
#endif
#ifndef PACKED #ifndef PACKED
#define PACKED __attribute__((__packed__)) #define PACKED __attribute__((__packed__))
#endif #endif
@ -58,10 +46,6 @@
#define noreturn __attribute__((__noreturn__)) #define noreturn __attribute__((__noreturn__))
#endif #endif
#ifndef alignof
#define alignof _Alignof
#endif
#ifndef likely #ifndef likely
#define likely(x) (__builtin_expect((x), 1)) #define likely(x) (__builtin_expect((x), 1))
#endif #endif
@ -79,7 +63,7 @@
#endif #endif
//------------------------------------------// //------------------------------------------//
// Values for APIRET // // Values for status_t //
//------------------------------------------// //------------------------------------------//
#define STATUS_FAILED(x) ((x) < 0)) #define STATUS_FAILED(x) ((x) < 0))

View File

@ -0,0 +1,100 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
// Authors: spectral` //
// NeoX //
// //
// Desc: Kaleid type limits definitions //
//----------------------------------------------------------------------------//
#ifndef _KALLIMS_H
//------------------------------------------//
// Data sizes blocks //
//------------------------------------------//
#ifndef DATA_SIZE_BLOCK
#define DATA_SIZE_BLOCK
# define BYTE_SIZE sizeof(char)
# define WORD_SIZE sizeof(short)
# define DWORD_SIZE sizeof(int)
# define QWORD_SIZE sizeof(long)
#endif
#ifndef DATA_ALIGN_BLOCK
#define DATA_ALIGN_BLOCK
# define BYTE_ALIGN alignof(char)
# define WORD_ALIGN alignof(short)
# define DWORD_ALIGN alignof(int)
# define QWORD_ALIGN alignof(long)
#endif
#ifndef DATA_BITS_BLOCK
#define DATA_BITS_BLOCK
# define BYTE_BIT 8
# define CHAR_BIT (BYTE_SIZE * BYTE_BIT)
# define WORD_BIT (WORD_SIZE * BYTE_BIT)
# define DWORD_BIT (DWORD_SIZE * BYTE_BIT)
# define QWORD_BIT (QWORD_SIZE * BYTE_BIT)
# define SHORT_BIT WORD_BIT
# define INT_BIT DWORD_BIT
# define LONG_BIT QWORD_BIT
#endif
//------------------------------------------//
// Numeric data limits //
//------------------------------------------//
#ifndef DATA_MAX_LIMITS_BLOCK
#define DATA_MAX_LIMITS_BLOCK
# define SCHAR_MAX ((signed char) 0x7F)
# define SHRT_MAX ((short) 0x7FFF)
# define INT_MAX ((int) 0x7FFFFFFF)
# define LONG_MAX ((long) 0x7FFFFFFFFFFFFFFF)
# define UCHAR_MAX ((unsigned char) 0xFF
# define USHRT_MAX ((unsigned short) 0xFFFF)
# define UINT_MAX ((unsigned int) 0xFFFFFFFF)
# define ULONG_MAX ((unsigned long) 0xFFFFFFFFFFFFFFFF)
#endif
#ifndef DATA_MIN_LIMITS_BLOCK
#define DATA_MIN_LIMITS_BLOCK
# define SCHAR_MIN ((signed char) -SCHAR_MAX - 1)
# define SHRT_MIN ((short) -SHRT_MAX - 1)
# define INT_MIN ((int) -INT_MAX - 1)
# define LONG_MIN ((long) -LONG_MAX - 1L)
#endif
#ifndef DATA_CHAR_LIMITS_BLOCK
#define DATA_CHAR_LIMITS_BLOCK
# ifdef __CHAR_UNSIGNED__
# define CHAR_MIN ((char)0)
# define CHAR_MAX UCHAR_MAX
# else
# define CHAR_MIN SCHAR_MIN
# define CHAR_MAX SCHAR_MAX
# endif
#endif
#ifndef DATA_SPTYPES_LIMITS_BLOCK
#define DATA_SPTYPES_LIMITS_BLOCK
# define SSIZE_T_MIN LONG_MIN
# define SSIZE_T_MAX LONG_MAX
# define SIZE_T_MAX ULONG_MAX
#endif
#ifdef NEED_MORE_USELESS_DATA
# define UCHAR_MIN ((unsigned char)0)
# define USHRT_MIN ((unsigned short)0)
# define UINT_MIN ((unsigned int)0)
# define ULONG_MIN ((unsigned long)0)
# ifdef STILL_NEED_MORE_USELESS_DATA
# error "Not enough useless data!"
# endif
#endif
//------------------------------------------//
// End of <kallims.h> //
//------------------------------------------//
#endif

View File

@ -17,6 +17,7 @@
#ifndef __base_types_aliases #ifndef __base_types_aliases
#define __base_types_aliases #define __base_types_aliases
typedef unsigned char uchar; typedef unsigned char uchar;
typedef signed char schar;
typedef unsigned short ushort; typedef unsigned short ushort;
typedef unsigned int uint; typedef unsigned int uint;
typedef unsigned long ulong; typedef unsigned long ulong;
@ -58,15 +59,26 @@ typedef unsigned long off_t;
typedef __builtin_va_list va_list; typedef __builtin_va_list va_list;
#endif #endif
#ifndef __div_t
#define __div_t
typedef struct { int quot, rem; } div_t;
#endif
#ifndef __ldiv_t
#define __ldiv_t
typedef struct { long quot, rem; } ldiv_t;
#endif
//------------------------------------------//
// Kaleid-specific types //
//------------------------------------------//
#ifndef __status_t #ifndef __status_t
#define __status_t #define __status_t
typedef signed long status_t; typedef signed long status_t;
#endif #endif
//------------------------------------------//
// Kaleid system types //
//------------------------------------------//
//------------------------------------------// //------------------------------------------//
// End of <kaltypes.h> // // End of <kaltypes.h> //
//------------------------------------------// //------------------------------------------//

View File

@ -52,7 +52,7 @@ status_t ChTermColor(terminal_t *, uchar);
void ClearTermUnlocked(terminal_t *); void ClearTermUnlocked(terminal_t *);
void PutOnTermUnlocked(terminal_t *, char); void PutOnTermUnlocked(terminal_t *, char);
void PrintOnTermUnlocked(terminal_t *, const char *); void PrintOnTermUnlocked(terminal_t *, const char *);
#define ChTermColorUnlocked(kt, col) ((kt)->kt_color = col) #define ChTermColorUnlocked(kt, col) ((kt)->kt_color = (col))
#endif #endif
#ifndef _NO_DEBUG #ifndef _NO_DEBUG
@ -61,9 +61,9 @@ void PrintOnTermUnlocked(terminal_t *, const char *);
# define DebugLog(...) # define DebugLog(...)
#endif #endif
#define LockTerm(kt) AquireLock(&kt->kt_lock) #define LockTerm(kt) AquireLock(&(kt)->kt_lock)
#define UnlockTerm(kt) ReleaseLock(&kt->kt_lock) #define UnlockTerm(kt) ReleaseLock(&(kt)->kt_lock)
#define TryLockTerm(kt) AttemptLock(&kt->kt_lock) #define TryLockTerm(kt) AttemptLock(&(kt)->kt_lock)
#endif #endif

View File

@ -19,7 +19,7 @@ enum lock_type {
// Mutex-type lock // Mutex-type lock
// //
// WARNING // WARNING
// DosLock() panics when used on a mutex while not running a process // AquireLock() panics when used on a mutex while not running a process
// //
KLOCK_MUTEX, KLOCK_MUTEX,