diff --git a/src/Makefile b/src/Makefile index 533f55f..d4e80b8 100644 --- a/src/Makefile +++ b/src/Makefile @@ -12,10 +12,13 @@ CC2NAME=gcc COPTIM=-O2 CLDSCR=-T kernel.ld CWARNS=-pedantic -Wall -Wextra -Werror -CFLAGS=-nostdlib -ffreestanding -mcmodel=large -mno-red-zone -mno-mmx -mno-sse -mno-sse2 CINCLUDES=-isystem. CDEFINES= +CFLAGS1=-nostdlib -ffreestanding -mcmodel=large +CFLAGS2=-mno-red-zone -mno-mmx -mno-sse -mno-sse2 +CFLAGS=$(CFLAGS1) $(CFLAGS2) + CC=$(CCNAME) $(COPTIM) $(CWARNS) $(CFLAGS) $(CDEFINES) $(CINCLUDES) KCC=$(CC) -D_KALEID_KERNEL @@ -32,7 +35,7 @@ KERNDIR=kaleid/kernel SYSTDIR=kaleid/system LINXDIR=kaleid/linux -all: bootloader +all: bootloader kernel boot.mbr.s: $(BOOTDIR)/mbr.s $(BOOTDIR)/mbr.inc $(ASM) $(BOOTFLAGS) $(BOOTDIR)/mbr.s -o $(OBJDIR)/boot/mbr.bin @@ -59,10 +62,10 @@ testing: bootloader pseudo_kern COBJDIR=$(OBJDIR)/$(COMMDIR) LOBJDIR=$(OBJDIR)/$(LINXDIR) -COMMDEPS=$(COMMDIR)/common.h $(COMMDIR)/assert.h $(COMMDIR)/atomic.h $(KERNDIR)/config.h \ - $(COMMDIR)/status.h +COMMDEPS=$(COMMDIR)/common.h $(COMMDIR)/stdlib.h $(KERNDIR)/config.h -COMMOBJS=$(COBJDIR)/lib/string.o $(COBJDIR)/lib/status.o $(COBJDIR)/lib/convert.o $(COBJDIR)/lib/memory.o +COMMOBJS=$(COBJDIR)/lib/string.o $(COBJDIR)/lib/status.o \ + $(COBJDIR)/lib/convert.o $(COBJDIR)/lib/memory.o common: $(COMMDEPS) $(COMMDIR)/lib/string.c $(COMMDIR)/lib/status.c $(KCC) -c $(COMMDIR)/lib/string.c -o $(COBJDIR)/lib/string.o @@ -85,9 +88,14 @@ test-common: KOBJDIR=$(OBJDIR)/$(KERNDIR) -KERNDEPS=common $(KERNDIR)/init.h $(KERNDIR)/io/terminal.h $(KERNDIR)/io/ports.h $(KERNDIR)/ke/panic.h -KERNSRCS=$(KERNDIR)/init.c $(KERNDIR)/ke/state.c $(KERNDIR)/ke/panic.c $(KERNDIR)/io/ports.c $(KERNDIR)/io/terminal.c -KERNOBJS=$(KOBJDIR)/init.o $(KOBJDIR)/ke/state.o $(KOBJDIR)/ke/panic.o $(KOBJDIR)/io/ports.o $(KOBJDIR)/io/terminal.o +KERNDEPS=common $(KERNDIR)/init.h $(KERNDIR)/io/terminal.h \ + $(KERNDIR)/io/ports.h $(KERNDIR)/ke/panic.h + +KERNSRCS=$(KERNDIR)/init.c $(KERNDIR)/ke/state.c $(KERNDIR)/ke/panic.c \ + $(KERNDIR)/io/ports.c $(KERNDIR)/io/terminal.c + +KERNOBJS=$(KOBJDIR)/init.o $(KOBJDIR)/ke/state.o $(KOBJDIR)/ke/panic.o \ + $(KOBJDIR)/io/ports.o $(KOBJDIR)/io/terminal.o kernel: common $(KERNSRCS) $(KCC) -c $(KERNDIR)/init.c -o $(KOBJDIR)/init.o diff --git a/src/kaleid/common/assert.h b/src/kaleid/common/assert.h deleted file mode 100644 index f01060b..0000000 --- a/src/kaleid/common/assert.h +++ /dev/null @@ -1,52 +0,0 @@ -//----------------------------------------------------------------------------// -// GNU GPL OS/K // -// // -// Authors: spectral` // -// NeoX // -// // -// Desc: Assertions // -//----------------------------------------------------------------------------// - -#ifndef _KALCOMM_ASSERT_H -#define _KALCOMM_ASSERT_H - -#ifndef _KALCOMM_COMMON_H -# error "don't include kaleid/common/types.h without kaleid/common/common.h" -#endif - -#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(0); -#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 - -#endif - -#endif - diff --git a/src/kaleid/common/common.h b/src/kaleid/common/common.h index 45943dd..121a50f 100644 --- a/src/kaleid/common/common.h +++ b/src/kaleid/common/common.h @@ -10,8 +10,14 @@ #ifndef _KALCOMM_COMMON_H #define _KALCOMM_COMMON_H -#if !defined(_OSK_SOURCE) && (defined(_KALEID_KERNEL) || defined(_KALEID_SYSTEM)) -# define _OSK_SOURCE 1 +//------------------------------------------// +// PREPROCESSOR CONSTANTS // +//------------------------------------------// + +#if !defined(_OSK_SOURCE) +# if defined(_KALEID_KERNEL) || defined(_KALEID_SYSTEM) +# define _OSK_SOURCE 1 +# endif #endif #if !defined(TRUE) && !defined(FALSE) @@ -37,8 +43,8 @@ #endif #if !defined(likely) && !defined(unlikely) -# define likely(x) __builtin_expect((x), 1) -# define unlikely(x) __builtin_expect((x), 0) +# define likely(x) (__builtin_expect((x), 1)) +# define unlikely(x) (__builtin_expect((x), 0)) #endif #ifndef INITOK @@ -49,10 +55,116 @@ # include #endif -#include -#include -#include -#include +//------------------------------------------// +// 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 DosDisableInterrupts() asm volatile ("cli") +# define DosEnableInterrupts() asm volatile ("sti") +# define DosHaltCPU() 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 + +#endif + +//------------------------------------------// +// END OF "kaleid/common/common.h" // +//------------------------------------------// #endif diff --git a/src/kaleid/common/convert.h b/src/kaleid/common/convert.h deleted file mode 100644 index 915a071..0000000 --- a/src/kaleid/common/convert.h +++ /dev/null @@ -1,24 +0,0 @@ -//----------------------------------------------------------------------------// -// GNU GPL OS/K // -// // -// Authors: spectral` // -// NeoX // -// // -// Desc: Conversion utilities // -//----------------------------------------------------------------------------// - -#ifndef _KALCOMM_CONVERT_H -#define _KALCOMM_CONVERT_H - -#ifndef _KALCOMM_COMMON_H -#include -#endif - -#ifndef _OSK_SOURCE -# define itoa _osk_itoa -# define atoi _osk_atoi -#endif - -char *itoa(int, char *, int); - -#endif diff --git a/src/kaleid/common/folder.desc b/src/kaleid/common/folder.desc index ab5d8cc..124f60c 100644 --- a/src/kaleid/common/folder.desc +++ b/src/kaleid/common/folder.desc @@ -7,35 +7,31 @@ Desc: Folder description - "kaleid/common" --------------------------------------------------------------------- -This is the folder containing the sources for Kaleid's C runtime library, linked both to the kernel -and to the system processes that run outiside the kernel. It can also be compiled for Linux as -(very basic) C library, for test purposes. +This is the folder containing the sources for Kaleid's C runtime library, linked +both to the kernel and to the system processes that run outiside the kernel. +It can also be compiled for Linux as a very basic C library, for test purposes. This folder contains the following files: - common.h - This file is to be included by every source file using the library, and it includes in turn - the following files: - - assert.h - Defines the macro "assert()". Currently any program wanting to use this macro has to - implement its own "___assert_handler(const char *cond, const char *file, int line, const char *func)" - but an (overridable) default handler will be furnished in the future. - - atomic.h - Support for atomic operations. When compiled by the kernel, also furnishes macros for - enabling/disabling interrupts. This will change in the future. - - status.h - Defines the different values of the "status_t" type used throughout Kaleid and related - utilitary functions. - - types.h - Provides the elementary types (size_t, etc) used throught Kaleid. - - - convert.h - Contains the declaration of conversion utilities (e.g. itoa()) - It is included by string.h - - - memory.h - Contains the declaration of the mem*() family of utilities (e.g. memcpy()) - - - string.h - Contains the declaration of various string-related utilities (including the sprintf() family) - Includes convert.h + This file is to be included by every source file using the library. + It: + - Provides the elementary types (e.g. size_t) used through Kaleid. + + - Defines the different values of the "status_t" type used + throughout Kaleid and related utilitary functions. + + - Defines the macro "assert()". Currently any program wanting to + use this macro has to implement its own handler: + noreturn void ___assert_handler(const char *cond, + const char *file, + int line, + const char *func) + but an overridable default handler will be furnished later. + + - stlib.h + The include file for most of functions of the common library, notably + - Memory management utilities (e.g. memset()) + - String manipulation utilities (e.g. strcpy()) + - Type conversion utilities (e.g. itoa()) + diff --git a/src/kaleid/common/lib/convert.c b/src/kaleid/common/lib/convert.c index 49b8529..9a9f037 100644 --- a/src/kaleid/common/lib/convert.c +++ b/src/kaleid/common/lib/convert.c @@ -7,7 +7,7 @@ // Desc: Conversion utilities // //----------------------------------------------------------------------------// -#include +#include // // Digits table for bases <=36 diff --git a/src/kaleid/common/lib/memory.c b/src/kaleid/common/lib/memory.c index 7f7c05d..7d40011 100644 --- a/src/kaleid/common/lib/memory.c +++ b/src/kaleid/common/lib/memory.c @@ -7,17 +7,64 @@ // Desc: mem*() functions // //----------------------------------------------------------------------------// -#include +// XXX to be improved before being brought back +// to be tested with more alignment sizes + +#include + +// to be moved +#define QWORD_SIZE 8 +#define QWORD_ALIGN 8 + +// +// Set "qwords"-many aligned qwords starting from ptr to val +// +static inline void *memsetq(void *ptr, ullong uval, size_t qwords) +{ + size_t n; + ullong *uptr = (ullong *)ptr; + + // aligned memory write + for (n = 0; n < qwords; n++) { + *(uptr + n) = uval; + } + + return ptr; +} // // Set "bytes"-many bytes starting from ptr to val // void *memset(void *ptr, int val, size_t bytes) { - uchar uval = val & 0xFF; uchar *uptr = (uchar *)ptr; + const size_t qwords = bytes/QWORD_SIZE; - while (bytes--) *uptr++ = uval; + // get rid of everything after the first byte + val = val & 0xFF; + + // deal with bytes before start of the first aligned qword + while (((ullong)uptr % QWORD_ALIGN) > 0 && bytes--) { + *uptr++ = (uchar)val; + } + + // move qword by qword + if (qwords) { + const ullong uval = ((ullong)val << 56) | ((ullong)val << 48) + | ((ullong)val << 40) | ((ullong)val << 32) + | ((ullong)val << 24) | ((ullong)val << 16) + | ((ullong)val << 8) | ((ullong)val); + + memsetq(uptr, uval, qwords); + + uptr += qwords * QWORD_SIZE; + bytes %= QWORD_SIZE; + } + + // deal with what's left + while (bytes--) { + *uptr++ = (uchar)val; + } return ptr; } @@ -27,11 +74,6 @@ void *memset(void *ptr, int val, size_t bytes) // void *memzero(void *ptr, size_t bytes) { - uchar *uptr = (uchar *)ptr; - - while (bytes--) *uptr++ = 0; - - return ptr; + return memset(ptr, 0, bytes); } - diff --git a/src/kaleid/common/atomic.h b/src/kaleid/common/lib/memsub.c similarity index 53% rename from src/kaleid/common/atomic.h rename to src/kaleid/common/lib/memsub.c index 569ecdb..8b25667 100644 --- a/src/kaleid/common/atomic.h +++ b/src/kaleid/common/lib/memsub.c @@ -4,26 +4,34 @@ // Authors: spectral` // // NeoX // // // -// Desc: Atomic stuff // +// Desc: mem*() functions, suboptimal edition // //----------------------------------------------------------------------------// -#ifndef _KALCOMM_ATOMIC_H -#define _KALCOMM_ATOMIC_H +#include -#ifndef _KALCOMM_COMMON_H -# error "don't include kaleid/common/types.h without kaleid/common/common.h" -#endif +// +// Set "bytes"-many bytes starting from ptr to val +// +void *memset(void *ptr, int val, size_t bytes) +{ + uchar uval = val & 0xFF; + uchar *uptr = (uchar *)ptr; + + while (bytes--) *uptr++ = uval; + + return ptr; +} -// atomic_t defined in common/types.h +// +// Set "bytes"-many bytes starting from ptr to 0 +// +void *memzero(void *ptr, size_t bytes) +{ + uchar *uptr = (uchar *)ptr; + + while (bytes--) *uptr++ = 0; + + return ptr; +} -#ifdef _KALEID_KERNEL - -// only available in the kernel -#define DosDisableInterrupts() asm volatile ("cli") -#define DosEnableInterrupts() asm volatile ("sti") -#define DosHaltCPU() asm volatile ("hlt") - -#endif - -#endif diff --git a/src/kaleid/common/lib/sprintf.c b/src/kaleid/common/lib/sprintf.c index b1b86c6..c8cbfa8 100644 --- a/src/kaleid/common/lib/sprintf.c +++ b/src/kaleid/common/lib/sprintf.c @@ -7,7 +7,7 @@ // Desc: sprintf()-related functions // //----------------------------------------------------------------------------// -#include +#include // // Format str according to fmt using ellipsed arguments diff --git a/src/kaleid/common/lib/string.c b/src/kaleid/common/lib/string.c index b5178b9..4bab621 100644 --- a/src/kaleid/common/lib/string.c +++ b/src/kaleid/common/lib/string.c @@ -7,9 +7,7 @@ // Desc: String-related functions // //----------------------------------------------------------------------------// -#include - -// TODO multibyte, assembly +#include // // Returns str's length diff --git a/src/kaleid/common/memory.h b/src/kaleid/common/memory.h deleted file mode 100644 index a0f8366..0000000 --- a/src/kaleid/common/memory.h +++ /dev/null @@ -1,28 +0,0 @@ -//----------------------------------------------------------------------------// -// GNU GPL OS/K // -// // -// Authors: spectral` // -// NeoX // -// // -// Desc: mem*() functions // -//----------------------------------------------------------------------------// - -#ifndef _KALCOMM_MEMORY_H -#define _KALCOMM_MEMORY_H - -#ifndef _KALCOMM_COMMON_H -# include -#endif - -#ifndef _OSK_SOURCE -# define memcpy _osk_memcpy -# define memset _osk_memset -# define memcmp _osk_memcmp -# define memzero _osk_memzero -#endif - -void *memset(void *, int, size_t); -void *memzero(void *, size_t); - -#endif - diff --git a/src/kaleid/common/status.h b/src/kaleid/common/status.h deleted file mode 100644 index 7d674ff..0000000 --- a/src/kaleid/common/status.h +++ /dev/null @@ -1,41 +0,0 @@ -//----------------------------------------------------------------------------// -// GNU GPL OS/K // -// // -// Authors: spectral` // -// NeoX // -// // -// Desc: Values for status_t // -//----------------------------------------------------------------------------// - -#ifndef _KALCOMM_STATUS_H -#define _KALCOMM_STATUS_H - -#ifndef _KALCOMM_COMMON_H -# error "don't include kaleid/common/types.h without kaleid/common/common.h" -#endif - -#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, can't be more precise -#define NOT_PERMITTED (-2) -#define ACCESS_DENIED (-3) - -#define BAD_ARGUMENT (-4) // invalid arguments, can't be more precise -#define BAD_ARG_RANGE (-5) // arguments out of range -#define BAD_ARG_NULL (-6) // unexpected NULL argument - -#define TRY_AGAIN (-7) // EAGAIN - -#endif - diff --git a/src/kaleid/common/stdlib.h b/src/kaleid/common/stdlib.h new file mode 100644 index 0000000..e267a4e --- /dev/null +++ b/src/kaleid/common/stdlib.h @@ -0,0 +1,75 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: Kaleid string library // +//----------------------------------------------------------------------------// + + +#ifndef _KALCOMM_STRING_H +#define _KALCOMM_STRING_H + +#ifndef _KALCOMM_COMMON_H +# include +#endif + +//------------------------------------------// +// Memory management utilitaries // +//------------------------------------------// + +#ifndef _OSK_SOURCE +# define memcpy _osk_memcpy +# define memset _osk_memset +# define memcmp _osk_memcmp +# define memzero _osk_memzero +#endif + +void *memset(void *, int, size_t); +void *memzero(void *, size_t); + +//------------------------------------------// +// String manipulation utilitaries // +//------------------------------------------// + +#ifndef _OSK_SOURCE +# define strlen _osk_strlen +# define strcpy _osk_strcpy +# define strncpy _osk_strncpy +# define strrev _osk_strrev +# define reverse _osk_reverse +# define sprintf _osk_sprintf +# define snprintf _osk_snprintf +# define vsprintf _osk_vsprintf +# define vsnprintf _osk_vsnprintf +#endif + +size_t strlen(const char *); +char *strcpy(char *, const char *); +char *strncpy(char *, const char *, size_t); +char *strrev(char *dest, const char *src); +char *reverse(char *); + +int sprintf(char *, const char *, ...); +int snprintf(char *, size_t, const char *, ...); +int vsprintf(char *, const char *, va_list); +int vsnprintf(char *, size_t, const char *, va_list); + +//------------------------------------------// +// Type conversion utilities // +//------------------------------------------// + +#ifndef _OSK_SOURCE +# define itoa _osk_itoa +# define atoi _osk_atoi +#endif + +char *itoa(int, char *, int); + +//------------------------------------------// +// End of kaleid/common/stdlib.h // +//------------------------------------------// + +#endif + diff --git a/src/kaleid/common/string.h b/src/kaleid/common/string.h deleted file mode 100644 index 5440138..0000000 --- a/src/kaleid/common/string.h +++ /dev/null @@ -1,49 +0,0 @@ -//----------------------------------------------------------------------------// -// GNU GPL OS/K // -// // -// Authors: spectral` // -// NeoX // -// // -// Desc: Kaleid string library // -//----------------------------------------------------------------------------// - - -#ifndef _KALCOMM_STRING_H -#define _KALCOMM_STRING_H - -#ifndef _KALCOMM_COMMON_H -# include -#endif - -#ifndef _KALCOMM_CONVERT_H -# include -#endif - -#ifndef _OSK_SOURCE - -# define strlen _osk_strlen -# define strcpy _osk_strcpy -# define strncpy _osk_strncpy -# define strrev _osk_strrev -# define reverse _osk_reverse - -# define sprintf _osk_sprintf -# define snprintf _osk_snprintf -# define vsprintf _osk_vsprintf -# define vsnprintf _osk_vsnprintf - -#endif - -size_t strlen(const char *); -char *strcpy(char *, const char *); -char *strncpy(char *, const char *, size_t); -char *strrev(char *dest, const char *src); -char *reverse(char *); - -int sprintf(char *, const char *, ...); -int snprintf(char *, size_t, const char *, ...); -int vsprintf(char *, const char *, va_list); -int vsnprintf(char *, size_t, const char *, va_list); - -#endif - diff --git a/src/kaleid/common/sub/memory.c b/src/kaleid/common/sub/memory.c deleted file mode 100644 index a12a9c6..0000000 --- a/src/kaleid/common/sub/memory.c +++ /dev/null @@ -1,79 +0,0 @@ -//----------------------------------------------------------------------------// -// GNU GPL OS/K // -// // -// Authors: spectral` // -// NeoX // -// // -// Desc: mem*() functions // -//----------------------------------------------------------------------------// - -// XXX to be improved before being brought back -// to be tested with more alignment sizes - -#include - -// to be moved -#define QWORD_SIZE 8 -#define QWORD_ALIGN 8 - -// -// Set "qwords"-many aligned qwords starting from ptr to val -// -static inline void *memsetq(void *ptr, ullong uval, size_t qwords) -{ - size_t n; - ullong *uptr = (ullong *)ptr; - - // aligned memory write - for (n = 0; n < qwords; n++) { - *(uptr + n) = uval; - } - - return ptr; -} - -// -// Set "bytes"-many bytes starting from ptr to val -// -void *memset(void *ptr, int val, size_t bytes) -{ - uchar *uptr = (uchar *)ptr; - const size_t qwords = bytes/QWORD_SIZE; - - // get rid of everything after the first byte - val = val & 0xFF; - - // deal with bytes before start of the first aligned qword - while (((ullong)uptr % QWORD_ALIGN) > 0 && bytes--) { - *uptr++ = (uchar)val; - } - - // move qword by qword - if (qwords) { - const ullong uval = ((ullong)val << 56) | ((ullong)val << 48) - | ((ullong)val << 40) | ((ullong)val << 32) - | ((ullong)val << 24) | ((ullong)val << 16) - | ((ullong)val << 8) | ((ullong)val); - - memsetq(uptr, uval, qwords); - - uptr += qwords * QWORD_SIZE; - bytes %= QWORD_SIZE; - } - - // deal with what's left - while (bytes--) { - *uptr++ = (uchar)val; - } - - return ptr; -} - -// -// Set "bytes"-many bytes starting from ptr to 0 -// -void *memzero(void *ptr, size_t bytes) -{ - return memset(ptr, 0, bytes); -} - diff --git a/src/kaleid/common/types.h b/src/kaleid/common/types.h deleted file mode 100644 index 910ceac..0000000 --- a/src/kaleid/common/types.h +++ /dev/null @@ -1,44 +0,0 @@ -//----------------------------------------------------------------------------// -// GNU GPL OS/K // -// // -// Authors: spectral` // -// NeoX // -// // -// Desc: Essential types for Kaleid // -//----------------------------------------------------------------------------// - - -#ifndef _KALCOMM_TYPES_H -#define _KALCOMM_TYPES_H - -#ifndef _KALCOMM_COMMON_H -# error "don't include kaleid/common/types.h without kaleid/common/common.h" -#endif - -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 - -#endif - - - diff --git a/src/kaleid/kernel/folder.desc b/src/kaleid/kernel/folder.desc index 039b5af..e85aabc 100644 --- a/src/kaleid/kernel/folder.desc +++ b/src/kaleid/kernel/folder.desc @@ -26,11 +26,12 @@ This folder also has the following subfolders: I/O folder. (XXX) - ps/ - This folder will contain Kaleid's process manager and scheduler, as well as the - implementation of the related syscalls and functions. + This folder will contain Kaleid's process manager and scheduler, as well + as the implementation of the related syscalls and functions. - ex/ This folder contains the exec()-related functions and syscalls, as well - as one subfolder per executable format supported by Kaleid (e.g. ELF executable) + as one subfolder per executable format supported by Kaleid + (e.g. ELF executable) diff --git a/src/kaleid/kernel/init.c b/src/kaleid/kernel/init.c index 5483a22..e4d0450 100644 --- a/src/kaleid/kernel/init.c +++ b/src/kaleid/kernel/init.c @@ -8,6 +8,7 @@ //----------------------------------------------------------------------------// #include +#include #include #include diff --git a/src/kaleid/kernel/init.h b/src/kaleid/kernel/init.h index 37e831c..40351c2 100644 --- a/src/kaleid/kernel/init.h +++ b/src/kaleid/kernel/init.h @@ -10,7 +10,9 @@ #ifndef _KALKERN_INIT_H #define _KALKERN_INIT_H +#ifndef _KALCOMM_COMMON_H #include +#endif // kernel entry point void DosStartKern(void); diff --git a/src/kaleid/kernel/io/terminal.c b/src/kaleid/kernel/io/terminal.c index b05ab48..ce3ebd8 100644 --- a/src/kaleid/kernel/io/terminal.c +++ b/src/kaleid/kernel/io/terminal.c @@ -14,7 +14,7 @@ // VGA-related macros // #define ComputeColorCode(fg, bg) ((fg) | (bg) << 4) -#define ComputeEntryOffset(kt, x, y) ((y) * kt->kt_width + (x)) +#define ComputeOffset(kt, x, y) ((y) * kt->kt_width + (x)) #define ComputeEntry(ch, cl) (((ushort)(ch)) | (ushort)(cl) << 8) // @@ -46,7 +46,7 @@ terminal_t *stddbg; // void DosInitTerms(void) { - DosAssert(!stdout && _vga_term.kt_init != INITOK && "DosInitTerms() called twice"); + DosAssert(!stdout && _vga_term.kt_init != INITOK); _vga_term.kt_init = INITOK; stddbg = &_vga_term; @@ -57,7 +57,7 @@ void DosInitTerms(void) } // -// Fills terminal with spaces +// Fill terminal with spaces // status_t DosClearTerm(terminal_t *kt) { @@ -92,7 +92,7 @@ status_t DosChTermColor(terminal_t *kt, uchar color) } // -// Writes a single character on the terminal +// Write a single character on the terminal // status_t DosPutOnTerm(terminal_t *kt, char ch) { @@ -135,7 +135,7 @@ status_t DosPrintOnTerm(terminal_t *kt, const char *str) //----------------------------------------------------------// // -// Fills terminal with spaces +// Fill terminal with spaces (UNLOCKED version) // XXX would '\0' work too? // void DosClearTerm_Unlocked(terminal_t *kt) @@ -154,7 +154,7 @@ void DosClearTerm_Unlocked(terminal_t *kt) } // -// Writes a single character on the terminal (UNLOCKED version) +// Write a single character on the terminal (UNLOCKED version) // void DosPutOnTerm_Unlocked(terminal_t *kt, char ch) { @@ -180,10 +180,9 @@ void DosPutOnTerm_Unlocked(terminal_t *kt, char ch) } } } - - // XXX check whether we were given a writable character + else { - const size_t offset = ComputeEntryOffset(kt, kt->kt_curr_x, kt->kt_curr_y); + const size_t offset = ComputeOffset(kt, kt->kt_curr_x, kt->kt_curr_y); kt->kt_buffer[offset] = ComputeEntry(ch, kt->kt_color); } @@ -208,5 +207,3 @@ void DosPrintOnTerm_Unlocked(terminal_t *kt, const char *str) } } - - diff --git a/src/kaleid/kernel/io/terminal.h b/src/kaleid/kernel/io/terminal.h index a209ead..0826453 100644 --- a/src/kaleid/kernel/io/terminal.h +++ b/src/kaleid/kernel/io/terminal.h @@ -39,6 +39,9 @@ typedef struct { // current "standard" terminal extern terminal_t *stdout; +// current debugging terminal +extern terminal_t *stddbg; + void DosInitTerms(void); status_t DosClearTerm(terminal_t *); status_t DosPutOnTerm(terminal_t *, char); @@ -48,12 +51,11 @@ status_t DosChTermColor(terminal_t *, uchar); #ifdef _UNLOCKED_IO void DosClearTerm_Unlocked(terminal_t *); void DosPutOnTerm_Unlocked(terminal_t *, char); -void DosPrintOnTerm_Unlocked(terminal_t *kt, const char *str); +void DosPrintOnTerm_Unlocked(terminal_t *, const char *); #define DosChTermColor_Unlocked(kt, col) ((kt)->kt_color = col) #endif #ifndef _NO_DEBUG -extern terminal_t *stddbg; # define DebugLog(...) DosPutOnTerm(stddbg, __VA_ARGS__) #else # define DebugLog(...) diff --git a/src/kaleid/kernel/ke/lock.h b/src/kaleid/kernel/ke/lock.h index 79202d4..1174c26 100644 --- a/src/kaleid/kernel/ke/lock.h +++ b/src/kaleid/kernel/ke/lock.h @@ -17,7 +17,9 @@ enum lock_type { // // Mutex-type lock - // WARNING: DosLock() panics when used on a mutex while not running a process + // + // WARNING + // DosLock() panics when used on a mutex while not running a process // KLOCK_MUTEX, @@ -57,7 +59,7 @@ typedef struct { // // Does nothing // -#define DosDestroyLock(lk) +#define DosDestroyLock(lk) ((lk)->lk_init = FALSE) // // Aquires the lock @@ -82,7 +84,7 @@ typedef struct { DosDisableInterrupts(); \ DosAssert((lk)->lk_init == INITOK); \ if ((lk)->lk_lock++) \ - DosPanic("DosReleased on an unlocked object"); \ + DosPanic("DosReleaseLock on an unlocked object"); \ DosEnableInterrupts(); \ } while (FALSE); diff --git a/src/kaleid/kernel/ke/panic.c b/src/kaleid/kernel/ke/panic.c index e319fe6..633cbf7 100644 --- a/src/kaleid/kernel/ke/panic.c +++ b/src/kaleid/kernel/ke/panic.c @@ -21,7 +21,10 @@ const char *__panicmsg = NULL; // // Failed assert() handler // -noreturn void ___assert_handler(const char *msg, const char *file, int line, const char *func) +noreturn void ___assert_handler(const char *msg, + const char *file, + int line, + const char *func) { // not getting out of here DosDisableInterrupts(); diff --git a/src/kaleid/kernel/ke/panic.h b/src/kaleid/kernel/ke/panic.h index 91cc78e..27a7753 100644 --- a/src/kaleid/kernel/ke/panic.h +++ b/src/kaleid/kernel/ke/panic.h @@ -10,9 +10,12 @@ #ifndef _KALKERN_KE_PANIC_H #define _KALKERN_KE_PANIC_H -#include +#ifndef _KALCOMM_COMMON_H +#include +#endif noreturn void DosPanic(const char *); +noreturn void DosCrashSystem(void); extern const char *__panicmsg; #define DosGetPanicStr() (__panicmsg) diff --git a/src/kaleid/kernel/ke/state.h b/src/kaleid/kernel/ke/state.h index 7ca09a9..fe8e6b9 100644 --- a/src/kaleid/kernel/ke/state.h +++ b/src/kaleid/kernel/ke/state.h @@ -30,7 +30,6 @@ enum kernel_states { }; extern uchar __kstate; - #define DosGetKernState() (__kstate) #define DosSetKernState(x) (__kstate = (x))