diff --git a/src/kaleid/common/memory.c b/src/kaleid/common/memory.c index 81c1785..2ccf2e8 100644 --- a/src/kaleid/common/memory.c +++ b/src/kaleid/common/memory.c @@ -8,6 +8,7 @@ //----------------------------------------------------------------------------// #include +#include //------------------------------------------// // memset() family // diff --git a/src/kaleid/common/rand.c b/src/kaleid/common/rand.c index b413bbf..5569792 100644 --- a/src/kaleid/common/rand.c +++ b/src/kaleid/common/rand.c @@ -1 +1,35 @@ -int rand(void) { /*STUB*/ return 0; } +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: RNG related functions // +//----------------------------------------------------------------------------// + +#include +#include + +// +// 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; +} + diff --git a/src/kaleid/common/test/test-file0.c b/src/kaleid/common/test/test-file0.c index 0cff677..59ba1cc 100644 --- a/src/kaleid/common/test/test-file0.c +++ b/src/kaleid/common/test/test-file0.c @@ -1,12 +1,17 @@ // random test file #include +#include int main(int argc, char *argv[]) { long x[4]; long *ptr = &x[0]; + printf("%d\n", CHAR_MIN); + + printf("%hhd\n", (1 << 7)); + printf("%p\n", ptr); ptr++; diff --git a/src/kaleid/include/kaldefs.h b/src/kaleid/include/kaldefs.h index b17c1cc..7341804 100644 --- a/src/kaleid/include/kaldefs.h +++ b/src/kaleid/include/kaldefs.h @@ -30,26 +30,14 @@ #define INITOK ((unsigned int)0xCAFEBABE) #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 // //------------------------------------------// +#ifndef alignof +#define alignof _Alignof +#endif + #ifndef PACKED #define PACKED __attribute__((__packed__)) #endif @@ -58,10 +46,6 @@ #define noreturn __attribute__((__noreturn__)) #endif -#ifndef alignof -#define alignof _Alignof -#endif - #ifndef likely #define likely(x) (__builtin_expect((x), 1)) #endif @@ -79,7 +63,7 @@ #endif //------------------------------------------// -// Values for APIRET // +// Values for status_t // //------------------------------------------// #define STATUS_FAILED(x) ((x) < 0)) diff --git a/src/kaleid/include/kallims.h b/src/kaleid/include/kallims.h new file mode 100644 index 0000000..57ba2fa --- /dev/null +++ b/src/kaleid/include/kallims.h @@ -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 // +//------------------------------------------// + +#endif diff --git a/src/kaleid/include/kaltypes.h b/src/kaleid/include/kaltypes.h index 8f8294a..6814644 100644 --- a/src/kaleid/include/kaltypes.h +++ b/src/kaleid/include/kaltypes.h @@ -17,6 +17,7 @@ #ifndef __base_types_aliases #define __base_types_aliases typedef unsigned char uchar; +typedef signed char schar; typedef unsigned short ushort; typedef unsigned int uint; typedef unsigned long ulong; @@ -58,15 +59,26 @@ typedef unsigned long off_t; typedef __builtin_va_list va_list; #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 #define __status_t typedef signed long status_t; #endif -//------------------------------------------// -// Kaleid system types // -//------------------------------------------// - //------------------------------------------// // End of // //------------------------------------------// diff --git a/src/kaleid/kernel/io/terminal.h b/src/kaleid/kernel/io/terminal.h index 42f8f90..df42066 100644 --- a/src/kaleid/kernel/io/terminal.h +++ b/src/kaleid/kernel/io/terminal.h @@ -52,7 +52,7 @@ status_t ChTermColor(terminal_t *, uchar); void ClearTermUnlocked(terminal_t *); void PutOnTermUnlocked(terminal_t *, char); void PrintOnTermUnlocked(terminal_t *, const char *); -#define ChTermColorUnlocked(kt, col) ((kt)->kt_color = col) +#define ChTermColorUnlocked(kt, col) ((kt)->kt_color = (col)) #endif #ifndef _NO_DEBUG @@ -61,9 +61,9 @@ void PrintOnTermUnlocked(terminal_t *, const char *); # define DebugLog(...) #endif -#define LockTerm(kt) AquireLock(&kt->kt_lock) -#define UnlockTerm(kt) ReleaseLock(&kt->kt_lock) -#define TryLockTerm(kt) AttemptLock(&kt->kt_lock) +#define LockTerm(kt) AquireLock(&(kt)->kt_lock) +#define UnlockTerm(kt) ReleaseLock(&(kt)->kt_lock) +#define TryLockTerm(kt) AttemptLock(&(kt)->kt_lock) #endif diff --git a/src/kaleid/kernel/ke/lock.h b/src/kaleid/kernel/ke/lock.h index 40482ec..6841025 100644 --- a/src/kaleid/kernel/ke/lock.h +++ b/src/kaleid/kernel/ke/lock.h @@ -19,7 +19,7 @@ enum lock_type { // Mutex-type lock // // 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,