From 7685bb8c726a129f71881839008f774d203125d5 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Tue, 25 Dec 2018 17:27:26 +0100 Subject: [PATCH 01/28] Update README.md --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 41d9385..3694921 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,6 @@ Fully open-source operating system from scratch (WIP), released under the GNU GPL version 3.0 -Branch kaleid : Development focused on the Kaleid Kernel. - For changelog, see src/ChangeLog. For structure of the sources, see src/project-tree.txt. From 974bbba2210db85413a0b0c79d1287b76a8f6044 Mon Sep 17 00:00:00 2001 From: Julian Barathieu Date: Thu, 27 Dec 2018 15:04:31 +0100 Subject: [PATCH 02/28] Completed project tree and folder descriptions --- src/kaleid/common/assert.h | 8 +-- src/kaleid/common/atomic.h | 2 +- src/kaleid/common/common.h | 7 +- src/kaleid/common/folder.desc | 40 +++++++++++ src/kaleid/common/memory.h | 2 +- src/kaleid/common/status.h | 2 +- src/kaleid/common/string.h | 6 +- src/kaleid/common/types.h | 2 +- src/kaleid/{common => kernel}/config.h | 0 src/kaleid/{common => kernel}/config.h.in | 0 src/kaleid/kernel/folder.desc | 18 ++--- src/kaleid/kernel/io/terminal.c | 2 +- src/kaleid/kernel/mm/malloc.h | 1 + src/kaleid/linux/test-common.c | 2 + src/project-tree.txt | 83 ++++++++++++++++------- 15 files changed, 126 insertions(+), 49 deletions(-) rename src/kaleid/{common => kernel}/config.h (100%) rename src/kaleid/{common => kernel}/config.h.in (100%) diff --git a/src/kaleid/common/assert.h b/src/kaleid/common/assert.h index da80ace..8c18ad6 100644 --- a/src/kaleid/common/assert.h +++ b/src/kaleid/common/assert.h @@ -11,7 +11,7 @@ #define _KALCOMM_ASSERT_H #ifndef _KALCOMM_COMMON_H -#error "don't include common/types.h without common/common.h" +# error "don't include common/types.h without common/common.h" #endif #ifdef _OSK_SOURCE @@ -26,11 +26,11 @@ noreturn void ___assert_handler(const char *, const char *, int, const char *); #else // not debugging #if !defined(NDEBUG) -#define NDEBUG 1 +# define NDEBUG 1 #endif #if !defined(_NO_DEBUG) -#define _NO_DEBUG 1 +# define _NO_DEBUG 1 #endif #define assert(x) @@ -40,7 +40,7 @@ noreturn void ___assert_handler(const char *, const char *, int, const char *); #else // !defined(_OSK_SOURCE) #if defined(_NO_DEBUG) && !defined(NDEBUG) -#define NDEBUG 1 +# define NDEBUG 1 #endif #include diff --git a/src/kaleid/common/atomic.h b/src/kaleid/common/atomic.h index a1daef3..f520339 100644 --- a/src/kaleid/common/atomic.h +++ b/src/kaleid/common/atomic.h @@ -11,7 +11,7 @@ #define _KALCOMM_ATOMIC_H #ifndef _KALCOMM_COMMON_H -#error "don't include common/types.h without common/common.h" +# error "don't include common/types.h without common/common.h" #endif // atomic_t defined in common/types.h diff --git a/src/kaleid/common/common.h b/src/kaleid/common/common.h index 9c9dd6a..52c3b44 100644 --- a/src/kaleid/common/common.h +++ b/src/kaleid/common/common.h @@ -11,7 +11,7 @@ #define _KALCOMM_COMMON_H #if !defined(_OSK_SOURCE) && (defined(_KALEID_KERNEL) || defined(_KALEID_SYSTEM)) -#define _OSK_SOURCE 1 +# define _OSK_SOURCE 1 #endif #if !defined(TRUE) && !defined(FALSE) @@ -41,8 +41,11 @@ # define unlikely(x) __builtin_expect((x), 0) #endif +#ifdef _KALEID_KERNEL +# include "kernel/config.h" +#endif + #include "common/types.h" -#include "common/config.h" #include "common/atomic.h" #include "common/status.h" #include "common/assert.h" diff --git a/src/kaleid/common/folder.desc b/src/kaleid/common/folder.desc index 8b13789..651f5a9 100644 --- a/src/kaleid/common/folder.desc +++ b/src/kaleid/common/folder.desc @@ -1 +1,41 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// 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 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 diff --git a/src/kaleid/common/memory.h b/src/kaleid/common/memory.h index a877e1a..a628141 100644 --- a/src/kaleid/common/memory.h +++ b/src/kaleid/common/memory.h @@ -11,7 +11,7 @@ #define _KALCOMM_MEMORY_H #ifndef _KALCOMM_COMMON_H -#include "common/common.h" +# include "common/common.h" #endif #endif diff --git a/src/kaleid/common/status.h b/src/kaleid/common/status.h index 82387da..898c62a 100644 --- a/src/kaleid/common/status.h +++ b/src/kaleid/common/status.h @@ -11,7 +11,7 @@ #define _KALCOMM_STATUS_H #ifndef _KALCOMM_COMMON_H -#error "don't include common/types.h without common/common.h" +# error "don't include common/types.h without common/common.h" #endif #ifndef _OSK_SOURCE diff --git a/src/kaleid/common/string.h b/src/kaleid/common/string.h index 0f8542d..be51281 100644 --- a/src/kaleid/common/string.h +++ b/src/kaleid/common/string.h @@ -12,7 +12,11 @@ #define _KALCOMM_STRING_H #ifndef _KALCOMM_COMMON_H -#include "common/common.h" +# include "common/common.h" +#endif + +#ifndef _KALCOMM_CONVERT_H +# include "common/convert.h" #endif #ifndef _OSK_SOURCE diff --git a/src/kaleid/common/types.h b/src/kaleid/common/types.h index fb7d4ff..739efa9 100644 --- a/src/kaleid/common/types.h +++ b/src/kaleid/common/types.h @@ -12,7 +12,7 @@ #define _KALCOMM_TYPES_H #ifndef _KALCOMM_COMMON_H -#error "don't include common/types.h without common/common.h" +# error "don't include common/types.h without common/common.h" #endif #ifndef KEEP_KALCOMM_TYPES_MINIMAL diff --git a/src/kaleid/common/config.h b/src/kaleid/kernel/config.h similarity index 100% rename from src/kaleid/common/config.h rename to src/kaleid/kernel/config.h diff --git a/src/kaleid/common/config.h.in b/src/kaleid/kernel/config.h.in similarity index 100% rename from src/kaleid/common/config.h.in rename to src/kaleid/kernel/config.h.in diff --git a/src/kaleid/kernel/folder.desc b/src/kaleid/kernel/folder.desc index f035c37..1b37b3a 100644 --- a/src/kaleid/kernel/folder.desc +++ b/src/kaleid/kernel/folder.desc @@ -7,38 +7,30 @@ // Desc: Folder description - "kaleid/kernel" // //----------------------------------------------------------------------------// -This is the folder containing the source of Kaleid's kernel. +This folder contains the source of Kaleid's kernel component. -It contains the following files: +This contains the following files: - init.c The file containing the entry point of Kaleid, the kstart() function called from the bootloader (see ../../boot). -This folder also has the following subfolders -(for more information on a particular subfolder, see {name}/folder.desc) +This folder also has the following subfolders: - mm/ This folder contains all files related to memory management. - fs/ - This folder contains Kaleid's virtual filesystem, as well as one + This folder will contain Kaleid's virtual filesystem, as well as one subfolder for each FS supported by Kaleid (e.g. FAT filesystem). - io/ I/O folder. (XXX) - ps/ - This folder contains Kaleid's process manager and scheduler, as well as the + 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) - - se/ - Security folder. (XXX) - - - sys/ - Syscall folder. (XXX) - - diff --git a/src/kaleid/kernel/io/terminal.c b/src/kaleid/kernel/io/terminal.c index 503dfcd..0fd46ac 100644 --- a/src/kaleid/kernel/io/terminal.c +++ b/src/kaleid/kernel/io/terminal.c @@ -167,7 +167,7 @@ status_t kterm_putch(struct kterm *kt, char ch) // -// Print string on kterminal +// Print string on terminal // status_t kterm_print(struct kterm *kt, const char *str) { diff --git a/src/kaleid/kernel/mm/malloc.h b/src/kaleid/kernel/mm/malloc.h index 2669121..9d63aba 100644 --- a/src/kaleid/kernel/mm/malloc.h +++ b/src/kaleid/kernel/mm/malloc.h @@ -5,6 +5,7 @@ // NeoX // // // // Desc: Memory allocation routines // +// Only exists to trigger Neox // //----------------------------------------------------------------------------// #ifndef _KALKERN_MM_MALLOC_H diff --git a/src/kaleid/linux/test-common.c b/src/kaleid/linux/test-common.c index a1707c6..ee2df6f 100644 --- a/src/kaleid/linux/test-common.c +++ b/src/kaleid/linux/test-common.c @@ -33,6 +33,8 @@ int main(int argc, char *argv[]) #undef strcpy assert(strcmp(strcpy(test2, test1), _osk_strcpy(test3, test1)) == 0); + // XXX test itoa() and v?sn?printf() + // tests done printf("2\n"); diff --git a/src/project-tree.txt b/src/project-tree.txt index 7e342f8..f102785 100644 --- a/src/project-tree.txt +++ b/src/project-tree.txt @@ -7,9 +7,14 @@ // Desc: Project Tree // //----------------------------------------------------------------------------// -// XXX *not* up to date - src/ + | + x COPYING + x CONTACT + x ChangeLog + | + - Makefile + - kernel.ld | + boot/ | | @@ -22,7 +27,7 @@ src/ | - loader16.inc | - loader64.inc | | - | - types.h + | 0 | + kaleid/ | | @@ -30,31 +35,61 @@ src/ | | | | | x folder.desc | | | + | | - config.h + | | - config.h.in + | | | | | - init.c | | - init.h | | | | | + io/ - | | | - | | - ports.c - | | - ports.h - | | - terminal.c - | | - terminal.h + | | | | + | | | - ports.c + | | | - ports.h + | | | | + | | | - terminal.c + | | | - terminal.h + | | | | + | | | 0 + | | | + | | + ke/ + | | | | + | | | - panic.c + | | | - panic.h + | | | | + | | | 0 + | | | + | | 0 | | | + common/ - | | - | x folder.desc - | | - | - assert.h - | - atomic.h - | - common.h - | - config.h - | - config.h.in - | - status.h - | - string.h - | - types.h - | | - | + lib/ - | | - | - string.c - | + | | | + | | x folder.desc + | | | + | | - common.h + | | - assert.h + | | - atomic.h + | | - status.h + | | - types.h + | | | + | | - string.h + | | - memory.h + | | - convert.h + | | | + | | + lib/ + | | | | + | | | - status.c + | | | | + | | | - string.c + | | | - memory.c + | | | - convert.c + | | | - sprintf.c + | | | | + | | | 0 + | | 0 + | | + | + linux/ + | | | + | | - test-common.c + | | | + | | 0 + | 0 0 From 6675f7eb78054f1105af00285601cfe595789120 Mon Sep 17 00:00:00 2001 From: Julian Barathieu Date: Fri, 28 Dec 2018 18:52:55 +0100 Subject: [PATCH 03/28] Stuff --- src/Makefile | 15 +++++--- src/kaleid/common/lib/convert.c | 2 +- src/kaleid/common/lib/memory.c | 68 +++++++++++++++++++++++++++++++++ src/kaleid/common/memory.h | 10 +++++ src/kaleid/common/types.h | 9 +++-- src/kaleid/linux/test-common.c | 40 +++++++++++-------- 6 files changed, 119 insertions(+), 25 deletions(-) diff --git a/src/Makefile b/src/Makefile index 79c8836..cf8c31f 100644 --- a/src/Makefile +++ b/src/Makefile @@ -10,12 +10,13 @@ CCNAME="/opt/cross-cc/bin/x86_64-elf-gcc" CC2NAME=gcc # compiler for testing CLDSCR=-T kernel.ld -CWARNS= -pedantic -Wall -Wextra -Werror +COPTIM=-O2 #-fbuiltin-memset +CWARNS=-pedantic -Wall -Wextra -Werror CFLAGS=-nostdlib -ffreestanding -mcmodel=large -mno-red-zone -mno-mmx -mno-sse -mno-sse2 CINCLUDES=-I./kaleid CDEFINES= -CC=$(CCNAME) $(CWARNS) $(CFLAGS) $(CDEFINES) $(CINCLUDES) +CC=$(CCNAME) $(COPTIM) $(CWARNS) $(CFLAGS) $(CDEFINES) $(CINCLUDES) KCC=$(CC) -D_KALEID_KERNEL ASM=nasm @@ -58,20 +59,24 @@ testing: bootloader pseudo_kern COBJDIR=$(OBJDIR)/$(COMMDIR) LOBJDIR=$(OBJDIR)/$(LINXDIR) -COMMDEPS=$(COMMDIR)/common.h $(COMMDIR)/assert.h $(COMMDIR)/atomic.h $(COMMDIR)/config.h \ +COMMDEPS=$(COMMDIR)/common.h $(COMMDIR)/assert.h $(COMMDIR)/atomic.h $(KERNDIR)/config.h \ $(COMMDIR)/status.h -COMMOBJS=$(COBJDIR)/lib/string.o $(COBJDIR)/lib/status.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 $(KCC) -c $(COMMDIR)/lib/status.c -o $(COBJDIR)/lib/status.o + $(KCC) -c $(COMMDIR)/lib/memory.c -o $(COBJDIR)/lib/memory.o + $(KCC) -c $(COMMDIR)/lib/convert.c -o $(COBJDIR)/lib/convert.o -CCC=$(CC2NAME) $(CWARNS) $(CDEFINES) $(CINCLUDES) +CCC=$(CC2NAME) $(COPTIM) $(CWARNS) $(CDEFINES) $(CINCLUDES) common-test: $(CCC) -c $(COMMDIR)/lib/string.c -o $(COBJDIR)/lib/string.o $(CCC) -c $(COMMDIR)/lib/status.c -o $(COBJDIR)/lib/status.o + $(CCC) -c $(COMMDIR)/lib/memory.c -o $(COBJDIR)/lib/memory.o + $(CCC) -c $(COMMDIR)/lib/convert.c -o $(COBJDIR)/lib/convert.o $(CCC) -c $(LINXDIR)/test-common.c -o $(LOBJDIR)/test-common.o $(CCC) $(COMMOBJS) $(LOBJDIR)/test-common.o -o $(BINDIR)/kaleid-common.elf diff --git a/src/kaleid/common/lib/convert.c b/src/kaleid/common/lib/convert.c index 0f76565..284f61f 100644 --- a/src/kaleid/common/lib/convert.c +++ b/src/kaleid/common/lib/convert.c @@ -7,7 +7,7 @@ // Desc: Conversion utilities // //----------------------------------------------------------------------------// -#include "common/convert.h" +#include "common/string.h" // // Digits table for bases <=36 diff --git a/src/kaleid/common/lib/memory.c b/src/kaleid/common/lib/memory.c index 3ebe6ee..547ab79 100644 --- a/src/kaleid/common/lib/memory.c +++ b/src/kaleid/common/lib/memory.c @@ -9,3 +9,71 @@ #include "common/memory.h" +// 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 +// This is most certainely overkill, but I enjoyed doing this +// Alignment stuff barely matters on modern processors +// This may actually be slower than the naive way +// +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/memory.h b/src/kaleid/common/memory.h index a628141..31f6a6b 100644 --- a/src/kaleid/common/memory.h +++ b/src/kaleid/common/memory.h @@ -14,5 +14,15 @@ # include "common/common.h" #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/types.h b/src/kaleid/common/types.h index 739efa9..bf74580 100644 --- a/src/kaleid/common/types.h +++ b/src/kaleid/common/types.h @@ -15,8 +15,6 @@ # error "don't include common/types.h without common/common.h" #endif -#ifndef KEEP_KALCOMM_TYPES_MINIMAL -typedef _Bool bool; typedef unsigned char uchar; typedef unsigned short ushort; typedef unsigned int uint; @@ -24,6 +22,11 @@ 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; @@ -33,8 +36,6 @@ typedef ulong pid_t; typedef void *va_list; #endif -typedef short port_t; -typedef short status_t; // XXX limits #endif diff --git a/src/kaleid/linux/test-common.c b/src/kaleid/linux/test-common.c index ee2df6f..bef4749 100644 --- a/src/kaleid/linux/test-common.c +++ b/src/kaleid/linux/test-common.c @@ -9,35 +9,45 @@ #include #include -#include #define KEEP_KALCOMM_TYPES_MINIMAL #include "common/common.h" #include "common/string.h" +#include "common/memory.h" int main(int argc, char *argv[]) { (void)argc; (void)argv; + assert(sizeof(char) == 1); + assert(sizeof(short) == 2); + assert(sizeof(int) == 4); + assert(sizeof(long) == 8); + assert(sizeof(long long) == 8); + + // please don't mind how weird this file is + // I remove tests of "simple" functions after + // I'm done with testing that function + // so a lot of test variables remain in case + // I need them for a future test + const char *test1 = "test string\n"; - char *test2 = malloc(strlen(test1)); - char *test3 = malloc(strlen(test1)); + const size_t size1 = strlen(test1); + char *test2 = malloc(size1); + char *test3 = malloc(size1); + + memset(test2, 'x', size1); + + size_t it; + for (it = 0; it < size1; it++) { + char c = *(test2 + it); + printf("%c", (c ? c : '-')); + } - printf("1\n"); + puts(""); - #undef strlen - assert(strlen("test string") == _osk_strlen("test string")); - - #undef strcpy - assert(strcmp(strcpy(test2, test1), _osk_strcpy(test3, test1)) == 0); - - // XXX test itoa() and v?sn?printf() - - // tests done - printf("2\n"); - free(test2); free(test3); From 9cca8f9ef6c41d65dac781788db5c5e3a43a8fe1 Mon Sep 17 00:00:00 2001 From: Julian Barathieu Date: Fri, 28 Dec 2018 19:15:22 +0100 Subject: [PATCH 04/28] Stuff --- src/Makefile | 6 +++--- src/kaleid/common/lib/memory.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Makefile b/src/Makefile index cf8c31f..eaa9884 100644 --- a/src/Makefile +++ b/src/Makefile @@ -8,9 +8,9 @@ #----------------------------------------------------------------------------# CCNAME="/opt/cross-cc/bin/x86_64-elf-gcc" -CC2NAME=gcc # compiler for testing +CC2NAME=gcc +COPTIM=-O2 CLDSCR=-T kernel.ld -COPTIM=-O2 #-fbuiltin-memset CWARNS=-pedantic -Wall -Wextra -Werror CFLAGS=-nostdlib -ffreestanding -mcmodel=large -mno-red-zone -mno-mmx -mno-sse -mno-sse2 CINCLUDES=-I./kaleid @@ -70,7 +70,7 @@ common: $(COMMDEPS) $(COMMDIR)/lib/string.c $(COMMDIR)/lib/status.c $(KCC) -c $(COMMDIR)/lib/memory.c -o $(COBJDIR)/lib/memory.o $(KCC) -c $(COMMDIR)/lib/convert.c -o $(COBJDIR)/lib/convert.o -CCC=$(CC2NAME) $(COPTIM) $(CWARNS) $(CDEFINES) $(CINCLUDES) +CCC=$(CC2NAME) $(COPTIM) $(CWARNS) $(CINCLUDES) common-test: $(CCC) -c $(COMMDIR)/lib/string.c -o $(COBJDIR)/lib/string.o diff --git a/src/kaleid/common/lib/memory.c b/src/kaleid/common/lib/memory.c index 547ab79..70c4dbd 100644 --- a/src/kaleid/common/lib/memory.c +++ b/src/kaleid/common/lib/memory.c @@ -35,9 +35,9 @@ static inline void *memsetq(void *ptr, ullong uval, size_t qwords) // Alignment stuff barely matters on modern processors // This may actually be slower than the naive way // -void *memset(void *ptr, int val, size_t bytes) +void *memset(void *ptr, register int val, register size_t bytes) { - uchar *uptr = (uchar *)ptr; + register uchar *uptr = (uchar *)ptr; const size_t qwords = bytes/QWORD_SIZE; // get rid of everything after the first byte From e22d8ede123cfefd45fdc49383708b780ac1cccc Mon Sep 17 00:00:00 2001 From: Julian Barathieu Date: Fri, 28 Dec 2018 20:49:43 +0100 Subject: [PATCH 05/28] Removed stuff --- src/kaleid/common/lib/memory.c | 60 ++++---------------------- src/kaleid/common/sub/memory.c | 78 ++++++++++++++++++++++++++++++++++ src/kaleid/linux/test-common.c | 31 ++++++-------- 3 files changed, 101 insertions(+), 68 deletions(-) create mode 100644 src/kaleid/common/sub/memory.c diff --git a/src/kaleid/common/lib/memory.c b/src/kaleid/common/lib/memory.c index 70c4dbd..8d85d9c 100644 --- a/src/kaleid/common/lib/memory.c +++ b/src/kaleid/common/lib/memory.c @@ -9,62 +9,15 @@ #include "common/memory.h" -// 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 -// This is most certainely overkill, but I enjoyed doing this -// Alignment stuff barely matters on modern processors -// This may actually be slower than the naive way // void *memset(void *ptr, register int val, register size_t bytes) { - register uchar *uptr = (uchar *)ptr; - const size_t qwords = bytes/QWORD_SIZE; + uchar uval = val & 0xFF; + uchar *uptr = (uchar *)ptr; - // 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; - } + while (bytes--) *uptr++ = uval; return ptr; } @@ -74,6 +27,11 @@ void *memset(void *ptr, register int val, register size_t bytes) // void *memzero(void *ptr, size_t bytes) { - return memset(ptr, 0, bytes); + uchar *uptr = (uchar *)ptr; + + while (bytes--) *uptr++ = 0; + + return ptr; } + diff --git a/src/kaleid/common/sub/memory.c b/src/kaleid/common/sub/memory.c new file mode 100644 index 0000000..8a4585a --- /dev/null +++ b/src/kaleid/common/sub/memory.c @@ -0,0 +1,78 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: mem*() functions - sub-optimal version // +//----------------------------------------------------------------------------// + +#include "common/memory.h" + +// 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 +// This is most certainely overkill, but I enjoyed doing this +// Alignment stuff barely matters on modern processors +// +void *memset(void *ptr, register int val, register size_t bytes) +{ + register 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/linux/test-common.c b/src/kaleid/linux/test-common.c index bef4749..127d07b 100644 --- a/src/kaleid/linux/test-common.c +++ b/src/kaleid/linux/test-common.c @@ -21,35 +21,32 @@ int main(int argc, char *argv[]) (void)argc; (void)argv; - assert(sizeof(char) == 1); - assert(sizeof(short) == 2); - assert(sizeof(int) == 4); - assert(sizeof(long) == 8); - assert(sizeof(long long) == 8); - // please don't mind how weird this file is // I remove tests of "simple" functions after // I'm done with testing that function // so a lot of test variables remain in case // I need them for a future test - const char *test1 = "test string\n"; - const size_t size1 = strlen(test1); - char *test2 = malloc(size1); - char *test3 = malloc(size1); + //const char *test1 = "test string\n"; + //const size_t size1 = strlen(test1); + //char *test2 = malloc(size1); + //char *test3 = malloc(size1); - memset(test2, 'x', size1); + //const size_t sizex = 10000000; + //void *xxx = malloc(sizex); + //printf("%p\n",xxx); + //memset(xxx, 'x', sizex); - size_t it; - for (it = 0; it < size1; it++) { - char c = *(test2 + it); + /*size_t it; + for (it = 0; it < sizex; it++) { + char c = *(xxx + it); printf("%c", (c ? c : '-')); } - puts(""); + puts("");*/ - free(test2); - free(test3); + //free(test2); + //free(test3); return 0; } From 6f4a616eb663ddc71192d890c93e3699d66c908e Mon Sep 17 00:00:00 2001 From: Julian Barathieu Date: Fri, 28 Dec 2018 20:50:28 +0100 Subject: [PATCH 06/28] Removed stuff --- src/kaleid/common/lib/memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/kaleid/common/lib/memory.c b/src/kaleid/common/lib/memory.c index 8d85d9c..6ef23ce 100644 --- a/src/kaleid/common/lib/memory.c +++ b/src/kaleid/common/lib/memory.c @@ -12,7 +12,7 @@ // // Set "bytes"-many bytes starting from ptr to val // -void *memset(void *ptr, register int val, register size_t bytes) +void *memset(void *ptr, int val, size_t bytes) { uchar uval = val & 0xFF; uchar *uptr = (uchar *)ptr; From b6ea3c20fe613652e60051d36e7c5ae035b5faab Mon Sep 17 00:00:00 2001 From: Julian Barathieu Date: Fri, 28 Dec 2018 21:20:59 +0100 Subject: [PATCH 07/28] Stuff --- src/Makefile | 2 +- src/boot/folder.desc | 16 ++++++++-------- src/kaleid/common/folder.desc | 16 ++++++++-------- src/kaleid/common/lib/string.c | 23 ++++++++++++++++++----- src/kaleid/common/sub/memory.c | 9 ++++++--- src/kaleid/kernel/folder.desc | 16 ++++++++-------- src/kaleid/linux/test-common.c | 18 ++++++++++++++++-- 7 files changed, 65 insertions(+), 35 deletions(-) diff --git a/src/Makefile b/src/Makefile index eaa9884..cb8b590 100644 --- a/src/Makefile +++ b/src/Makefile @@ -72,7 +72,7 @@ common: $(COMMDEPS) $(COMMDIR)/lib/string.c $(COMMDIR)/lib/status.c CCC=$(CC2NAME) $(COPTIM) $(CWARNS) $(CINCLUDES) -common-test: +test-common: $(CCC) -c $(COMMDIR)/lib/string.c -o $(COBJDIR)/lib/string.o $(CCC) -c $(COMMDIR)/lib/status.c -o $(COBJDIR)/lib/status.o $(CCC) -c $(COMMDIR)/lib/memory.c -o $(COBJDIR)/lib/memory.o diff --git a/src/boot/folder.desc b/src/boot/folder.desc index d6b3cab..6322bc3 100644 --- a/src/boot/folder.desc +++ b/src/boot/folder.desc @@ -1,11 +1,11 @@ -//----------------------------------------------------------------------------// -// GNU GPL OS/K // -// // -// Authors: spectral` // -// NeoX // -// // -// Desc: Folder description - "boot" // -//----------------------------------------------------------------------------// +--------------------------------------------------------------------- + GNU GPL OS/K + + Authors: spectral` + NeoX + + Desc: Folder description - "boot" +--------------------------------------------------------------------- This folder contains the source for OS/K's bootloader. diff --git a/src/kaleid/common/folder.desc b/src/kaleid/common/folder.desc index 651f5a9..ab5d8cc 100644 --- a/src/kaleid/common/folder.desc +++ b/src/kaleid/common/folder.desc @@ -1,11 +1,11 @@ -//----------------------------------------------------------------------------// -// GNU GPL OS/K // -// // -// Authors: spectral` // -// NeoX // -// // -// Desc: Folder description - "kaleid/common" // -//----------------------------------------------------------------------------// +--------------------------------------------------------------------- + GNU GPL OS/K + + Authors: spectral` + NeoX + + 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 diff --git a/src/kaleid/common/lib/string.c b/src/kaleid/common/lib/string.c index f81f60c..89cf625 100644 --- a/src/kaleid/common/lib/string.c +++ b/src/kaleid/common/lib/string.c @@ -38,18 +38,31 @@ char *strcpy(char *dest, const char *src) // char *strncpy(char *dest, const char *src, size_t n) { - size_t i; + size_t it; - for (i = 0; i < n && src[i]; i++) { - dest[i] = src[i]; + for (it = 0; it < n && src[it]; i++) { + dest[it] = src[i]; } - while (i < n) dest[i++] = 0; + while (it < n) dest[it++] = 0; return dest; } // -// Reverses a string +// Reverses the string src, putting the result into dest +// +char *strrev(char *dest, const char *src) +{ + size_t m = 0, n = strlen(src); + + dest[n--] = '\0'; + + while (n) dest[m++] = src[n--]; +} + +// +// Reverses a string, modifying it +// Returns a point to said string // char *reverse(char *str) { diff --git a/src/kaleid/common/sub/memory.c b/src/kaleid/common/sub/memory.c index 8a4585a..06407b9 100644 --- a/src/kaleid/common/sub/memory.c +++ b/src/kaleid/common/sub/memory.c @@ -4,9 +4,12 @@ // Authors: spectral` // // NeoX // // // -// Desc: mem*() functions - sub-optimal version // +// Desc: mem*() functions // //----------------------------------------------------------------------------// +// XXX to be improved before being brought back +// to be tested with more alignment sizes + #include "common/memory.h" // to be moved @@ -34,9 +37,9 @@ static inline void *memsetq(void *ptr, ullong uval, size_t qwords) // This is most certainely overkill, but I enjoyed doing this // Alignment stuff barely matters on modern processors // -void *memset(void *ptr, register int val, register size_t bytes) +void *memset(void *ptr, int val, size_t bytes) { - register uchar *uptr = (uchar *)ptr; + uchar *uptr = (uchar *)ptr; const size_t qwords = bytes/QWORD_SIZE; // get rid of everything after the first byte diff --git a/src/kaleid/kernel/folder.desc b/src/kaleid/kernel/folder.desc index 1b37b3a..039b5af 100644 --- a/src/kaleid/kernel/folder.desc +++ b/src/kaleid/kernel/folder.desc @@ -1,11 +1,11 @@ -//----------------------------------------------------------------------------// -// GNU GPL OS/K // -// // -// Authors: spectral` // -// NeoX // -// // -// Desc: Folder description - "kaleid/kernel" // -//----------------------------------------------------------------------------// +--------------------------------------------------------------------- + GNU GPL OS/K + + Authors: spectral` + NeoX + + Desc: Folder description - "kaleid/kernel" +--------------------------------------------------------------------- This folder contains the source of Kaleid's kernel component. diff --git a/src/kaleid/linux/test-common.c b/src/kaleid/linux/test-common.c index 127d07b..d9b3aec 100644 --- a/src/kaleid/linux/test-common.c +++ b/src/kaleid/linux/test-common.c @@ -7,9 +7,8 @@ // Desc: Test file for common/ // //----------------------------------------------------------------------------// -#include #include - +#include #define KEEP_KALCOMM_TYPES_MINIMAL #include "common/common.h" @@ -36,6 +35,21 @@ int main(int argc, char *argv[]) //void *xxx = malloc(sizex); //printf("%p\n",xxx); //memset(xxx, 'x', sizex); + + const char *str = "ceci est un string de test\n"; + char *str2 = malloc((strlen(str) + 3) * sizeof(char)); + + strcpy(str2, str); + + size_t s = strlen(str2); + + printf(reverse(reverse(str2))); + + str2[s] = '\n'; + str2[s+1] = '\0'; + printf(reverse(reverse(str2))); + + free(str2); /*size_t it; for (it = 0; it < sizex; it++) { From e76a30d1c523d6d0a53b4469119a6ac935e14797 Mon Sep 17 00:00:00 2001 From: Julian Barathieu Date: Fri, 28 Dec 2018 22:16:22 +0100 Subject: [PATCH 08/28] Stuff --- src/kaleid/common/lib/string.c | 11 +++++++---- src/kaleid/common/string.h | 18 ++++++++++-------- src/kaleid/common/sub/memory.c | 2 -- src/kaleid/linux/test-common.c | 16 ++++++++++------ 4 files changed, 27 insertions(+), 20 deletions(-) diff --git a/src/kaleid/common/lib/string.c b/src/kaleid/common/lib/string.c index 89cf625..464ff2e 100644 --- a/src/kaleid/common/lib/string.c +++ b/src/kaleid/common/lib/string.c @@ -40,8 +40,8 @@ char *strncpy(char *dest, const char *src, size_t n) { size_t it; - for (it = 0; it < n && src[it]; i++) { - dest[it] = src[i]; + for (it = 0; it < n && src[it]; it++) { + dest[it] = src[it]; } while (it < n) dest[it++] = 0; @@ -53,11 +53,14 @@ char *strncpy(char *dest, const char *src, size_t n) // char *strrev(char *dest, const char *src) { - size_t m = 0, n = strlen(src); + char *orig = dest; + size_t n = strlen(src); dest[n--] = '\0'; - while (n) dest[m++] = src[n--]; + while ((*dest++ = src[n--])); + + return orig; } // diff --git a/src/kaleid/common/string.h b/src/kaleid/common/string.h index be51281..61056be 100644 --- a/src/kaleid/common/string.h +++ b/src/kaleid/common/string.h @@ -21,21 +21,23 @@ #ifndef _OSK_SOURCE -# define strlen _osk_strlen -# define strcpy _osk_strcpy -# define strncpy _osk_strncpy -# define reverse _osk_reverse +# 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 +# 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 *, ...); diff --git a/src/kaleid/common/sub/memory.c b/src/kaleid/common/sub/memory.c index 06407b9..aaecb6b 100644 --- a/src/kaleid/common/sub/memory.c +++ b/src/kaleid/common/sub/memory.c @@ -34,8 +34,6 @@ static inline void *memsetq(void *ptr, ullong uval, size_t qwords) // // Set "bytes"-many bytes starting from ptr to val -// This is most certainely overkill, but I enjoyed doing this -// Alignment stuff barely matters on modern processors // void *memset(void *ptr, int val, size_t bytes) { diff --git a/src/kaleid/linux/test-common.c b/src/kaleid/linux/test-common.c index d9b3aec..edae890 100644 --- a/src/kaleid/linux/test-common.c +++ b/src/kaleid/linux/test-common.c @@ -36,20 +36,24 @@ int main(int argc, char *argv[]) //printf("%p\n",xxx); //memset(xxx, 'x', sizex); - const char *str = "ceci est un string de test\n"; + const char *str = "ceci est un string de test!"; char *str2 = malloc((strlen(str) + 3) * sizeof(char)); + char *str3 = malloc((strlen(str) + 3) * sizeof(char)); strcpy(str2, str); - size_t s = strlen(str2); + //size_t s = strlen(str2); - printf(reverse(reverse(str2))); + strrev(str3,str2); + printf("%lu - %s\n", strlen(str3), str3); - str2[s] = '\n'; - str2[s+1] = '\0'; - printf(reverse(reverse(str2))); + //str2[s] = '\n'; + //str2[s+1] = '\0'; + strrev(str2,str3); + printf("%lu - %s\n", strlen(str2), str2); free(str2); + free(str3); /*size_t it; for (it = 0; it < sizex; it++) { From 4ae060bd5dc42d4acda921c60e391ee926b5e0c7 Mon Sep 17 00:00:00 2001 From: Julian Barathieu Date: Sat, 29 Dec 2018 23:51:00 +0100 Subject: [PATCH 09/28] Big stuff --- src/Makefile | 5 ++-- src/kaleid/common/atomic.h | 6 ++-- src/kaleid/kernel/init.c | 8 +++-- src/kaleid/kernel/io/ports.h | 8 +++-- src/kaleid/kernel/io/terminal.c | 52 ++++++++++++++++----------------- src/kaleid/kernel/io/terminal.h | 30 ++++++++++--------- src/kaleid/kernel/ke/panic.c | 24 ++++++++------- src/kaleid/kernel/ke/panic.h | 10 +++++-- src/kaleid/kernel/ke/state.c | 16 ++++++++++ src/kaleid/kernel/ke/state.h | 38 ++++++++++++++++++++++++ 10 files changed, 133 insertions(+), 64 deletions(-) create mode 100644 src/kaleid/kernel/ke/state.c create mode 100644 src/kaleid/kernel/ke/state.h diff --git a/src/Makefile b/src/Makefile index cb8b590..4988716 100644 --- a/src/Makefile +++ b/src/Makefile @@ -86,11 +86,12 @@ 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/panic.c $(KERNDIR)/io/ports.c $(KERNDIR)/io/terminal.c -KERNOBJS=$(KOBJDIR)/init.o $(KOBJDIR)/ke/panic.o $(KOBJDIR)/io/ports.o $(KOBJDIR)/io/terminal.o +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 + $(KCC) -c $(KERNDIR)/ke/state.c -o $(KOBJDIR)/ke/state.o $(KCC) -c $(KERNDIR)/ke/panic.c -o $(KOBJDIR)/ke/panic.o $(KCC) -c $(KERNDIR)/io/ports.c -o $(KOBJDIR)/io/ports.o $(KCC) -c $(KERNDIR)/io/terminal.c -o $(KOBJDIR)/io/terminal.o diff --git a/src/kaleid/common/atomic.h b/src/kaleid/common/atomic.h index f520339..56a4afb 100644 --- a/src/kaleid/common/atomic.h +++ b/src/kaleid/common/atomic.h @@ -19,9 +19,9 @@ #ifdef _KALEID_KERNEL // only available in the kernel -#define cli() asm volatile ("cli") -#define sti() asm volatile ("sti") -#define hlt() asm volatile ("hlt") +#define DosDisableInterrupts() asm volatile ("cli") +#define DosEnableInterrupts() asm volatile ("sti") +#define DosHaltCPU() asm volatile ("hlt") #endif diff --git a/src/kaleid/kernel/init.c b/src/kaleid/kernel/init.c index b6f268a..aa794fe 100644 --- a/src/kaleid/kernel/init.c +++ b/src/kaleid/kernel/init.c @@ -15,8 +15,10 @@ // Entry point of kaleid-kernel.elf // void kstart(void) -{ - kterm_init(); - panic("Goodbye World :("); +{ + DosSetKernState(KSTATE_INIT); + + DosInitTerms(); + DosPanic("Goodbye World :("); } diff --git a/src/kaleid/kernel/io/ports.h b/src/kaleid/kernel/io/ports.h index b2adfbe..8df790d 100644 --- a/src/kaleid/kernel/io/ports.h +++ b/src/kaleid/kernel/io/ports.h @@ -10,12 +10,14 @@ #ifndef _KALKERN_IO_PORTS_H #define _KALKERN_IO_PORTS_H +#ifndef _KALCOMM_COMMON_H #include "common/common.h" +#endif -#define outb(port,val) asm volatile ("outb %1, %0" : : "dN" (port), "a" (value)) +#define DosWriteByteOnPort(port,val) asm volatile ("outb %1, %0" : : "dN" (port), "a" (value)) -uchar inb(port_t); -ushort inw(port_t); +uchar DosReadByteFromPort(port_t); +ushort DosReadWordFromPort(port_t); #endif diff --git a/src/kaleid/kernel/io/terminal.c b/src/kaleid/kernel/io/terminal.c index 0fd46ac..e172daf 100644 --- a/src/kaleid/kernel/io/terminal.c +++ b/src/kaleid/kernel/io/terminal.c @@ -19,7 +19,7 @@ // // VGA output // -static struct kterm _kt_vga = { +static terminal_t _vga_term = { .kt_buffer = (ushort *)0xB8000, .kt_width = 80, .kt_height = 25, @@ -35,50 +35,50 @@ static struct kterm _kt_vga = { // // Standard output terminal // -struct kterm *kt_stdout; +terminal_t *stdout; // // Initialize standard output // -void kterm_init(void) +void DosInitTerms(void) { - assert(!kt_stdout && !_kt_vga.kt_init && "kterm_init() called twice"); - + assert(!stdout && !_vga_term.kt_init && "DosInitTerms() called twice"); + #ifndef _NO_DEBUG - _kt_vga.kt_init = TRUE; + _vga_term.kt_init = TRUE; #endif // to be switched to VESA - kt_stdout = &_kt_vga; - ktclear(); + stdout = &_vga_term; + DosClearTerm(stdout); } // // Fills terminal with spaces // XXX would '\0' work too? // -status_t kterm_clear(struct kterm *kt) +status_t DosClearTerm(terminal_t *kt) { size_t i; if (kt == NULL) return BAD_ARG_NULL; - assert(kt->kt_init && "kterm_clear called before initialization"); + assert(kt->kt_init && "DosClearTerm called before initialization"); - kterm_lock(kt); + DosLockTerm(kt); const ushort filler = ComputeEntry(' ', kt->kt_color); const size_t bufsize = kt->kt_width * kt->kt_height; for (i = 0; i < bufsize; i++) { - // XXX implement memset() + // XXX implement memsetw() kt->kt_buffer[i] = filler; } kt->kt_curr_x = kt->kt_curr_y = 0; - kterm_unlock(kt); + DosUnlockTerm(kt); return SUCCESS; } @@ -86,7 +86,7 @@ status_t kterm_clear(struct kterm *kt) // // Change the color code // -status_t kterm_change_color(struct kterm *kt, uchar color) +status_t DosChTermColor(terminal_t *kt, uchar color) { if (color > KTERM_COLOR_WHITE) return BAD_ARG_RANGE; @@ -94,9 +94,9 @@ status_t kterm_change_color(struct kterm *kt, uchar color) if (kt == NULL) return BAD_ARG_NULL; - kterm_lock(kt); + DosLockTerm(kt); kt->kt_color = color; - kterm_unlock(kt); + DosUnlockTerm(kt); return SUCCESS; } @@ -108,7 +108,7 @@ status_t kterm_change_color(struct kterm *kt, uchar color) // - always use kterm_putch (LOCKED version) // - doesn't check for NULL input // -void kterm_putch_unlocked(struct kterm *kt, char ch) +void DosPutOnTerm_Unlocked(terminal_t *kt, char ch) { int i; size_t prev_row; @@ -128,7 +128,7 @@ void kterm_putch_unlocked(struct kterm *kt, char ch) for (i = 0; i < TABSIZE; i++) { // tabulations can't spread over two lines if (kt->kt_curr_y == prev_row) { - kterm_putch_unlocked(kt, ' '); + DosPutOnTerm_Unlocked(kt, ' '); } } } @@ -153,14 +153,14 @@ void kterm_putch_unlocked(struct kterm *kt, char ch) // // Writes a single character on the terminal (LOCKED version) // -status_t kterm_putch(struct kterm *kt, char ch) +status_t DosPutOnTerm(terminal_t *kt, char ch) { if (kt == NULL) return BAD_ARG_NULL; - kterm_lock(kt); - kterm_putch_unlocked(kt, ch); - kterm_unlock(kt); + DosLockTerm(kt); + DosPutOnTerm_Unlocked(kt, ch); + DosUnlockTerm(kt); return SUCCESS; } @@ -169,16 +169,16 @@ status_t kterm_putch(struct kterm *kt, char ch) // // Print string on terminal // -status_t kterm_print(struct kterm *kt, const char *str) +status_t DosPrintOnTerm(terminal_t *kt, const char *str) { if (kt == NULL) return BAD_ARG_NULL; - kterm_lock(kt); + DosLockTerm(kt); while (*str) { - kterm_putch_unlocked(kt, *str++); + DosPutOnTerm_Unlocked(kt, *str++); } - kterm_unlock(kt); + DosUnlockTerm(kt); return SUCCESS; } diff --git a/src/kaleid/kernel/io/terminal.h b/src/kaleid/kernel/io/terminal.h index 5cb39bf..229be43 100644 --- a/src/kaleid/kernel/io/terminal.h +++ b/src/kaleid/kernel/io/terminal.h @@ -10,10 +10,12 @@ #ifndef _KALKERN_IO_KTERM_H #define _KALKERN_IO_KTERM_H +#ifndef _KALCOMM_COMMON_H #include "common/common.h" +#endif // all available colors -enum kterm_color { +enum kterm_colors { KTERM_COLOR_BLACK, KTERM_COLOR_BLUE, KTERM_COLOR_GREEN, KTERM_COLOR_CYAN, KTERM_COLOR_RED, KTERM_COLOR_MAGENTA, @@ -24,7 +26,7 @@ enum kterm_color { KTERM_COLOR_LBROWN, KTERM_COLOR_WHITE }; -struct kterm { +typedef struct kterm { void *kt_lock; ushort *kt_buffer; uchar kt_color; @@ -32,23 +34,23 @@ struct kterm { size_t kt_height; off_t kt_curr_x; off_t kt_curr_y; + // XXX flags #ifndef _NO_DEBUG bool kt_init; #endif - -}; +} terminal_t; // current "standard" terminal -extern struct kterm *kt_stdout; +extern terminal_t *stdout; -void kterm_init(void); -status_t kterm_clear(struct kterm *); -status_t kterm_putch(struct kterm *, char); -status_t kterm_print(struct kterm *, const char *); -status_t kterm_change_color(struct kterm *, uchar); +void DosInitTerms(void); +status_t DosClearTerm(terminal_t *); +status_t DosPutOnTerm(terminal_t *, char); +status_t DosPrintOnTerm(terminal_t *, const char *); +status_t DosChTermColor(terminal_t *, uchar); #ifdef _UNLOCKED_IO -void kterm_putch_unlocked(struct kterm *, char); +void DosPutOnTerm_Unlocked(terminal_t *, char); #endif #define ktclear() kterm_clear(kt_stdout) @@ -56,9 +58,9 @@ void kterm_putch_unlocked(struct kterm *, char); #define ktprint(s) kterm_print(kt_stdout, (s)) #define ktchcol(c) kterm_change_color(kt_stdout, (c)) -#define kterm_lock(kt) -#define kterm_trylock(kt) -#define kterm_unlock(kt) +#define DosLockTerm(kt) +#define DosTryLockTerm(kt) +#define DosUnlockTerm(kt) #endif diff --git a/src/kaleid/kernel/ke/panic.c b/src/kaleid/kernel/ke/panic.c index 04310c6..38f8f9d 100644 --- a/src/kaleid/kernel/ke/panic.c +++ b/src/kaleid/kernel/ke/panic.c @@ -8,6 +8,8 @@ //----------------------------------------------------------------------------// #include "kernel/ke/panic.h" +#include "kernel/ke/state.h" +#include "kernel/io/terminal.h" // // Panic message @@ -20,22 +22,24 @@ const char *panicstr = NULL; noreturn void ___assert_handler(const char *msg, const char *file, int line, const char *func) { // not getting out of here - cli(); + DosDisableInterrupts(); (void)file; (void)line; (void)func; // XXX sprintf() to create a proper panicstr - panic(msg); + DosPanic(msg); } // // Your best boy panic() // -void panic(const char *str) +void DosPanic(const char *str) { - cli(); + DosDisableInterrupts(); - ktclear(); + DosSetKernState(KSTATE_PANIC); + + DosClearTerm(stdout); if (str == NULL) { str = "(no message given)"; @@ -43,17 +47,17 @@ void panic(const char *str) if (panicstr) { // shouldn't be possible - ktprint("double panic!\n"); - hlt(); + DosPrintOnTerm(stdout, "double panic!\n"); + DosHaltCPU(); } panicstr = str; - ktprint("panic! - "); - ktprint(str); + DosPrintOnTerm(stdout, "panic! - "); + DosPrintOnTerm(stdout, str); while (TRUE) { - hlt(); + DosHaltCPU(); } } diff --git a/src/kaleid/kernel/ke/panic.h b/src/kaleid/kernel/ke/panic.h index 403d728..f73387a 100644 --- a/src/kaleid/kernel/ke/panic.h +++ b/src/kaleid/kernel/ke/panic.h @@ -10,9 +10,13 @@ #ifndef _KALKERN_KE_PANIC_H #define _KALKERN_KE_PANIC_H -#include "kernel/io/terminal.h" +#include "kernel/ke/state.h" -extern const char *panicstr; -noreturn void panic(const char *); +extern const char *__panicstr; +noreturn void DosPanic(const char *); + +#define DosGetPanicStr() (__panicstr) + +#define panic DosPanic #endif diff --git a/src/kaleid/kernel/ke/state.c b/src/kaleid/kernel/ke/state.c new file mode 100644 index 0000000..e8a79fe --- /dev/null +++ b/src/kaleid/kernel/ke/state.c @@ -0,0 +1,16 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: Current kernel state // +//----------------------------------------------------------------------------// + +#include "kernel/ke/state.h" + +// +// Current kernel state +// +uchar __kstate; + diff --git a/src/kaleid/kernel/ke/state.h b/src/kaleid/kernel/ke/state.h new file mode 100644 index 0000000..ba6bf8d --- /dev/null +++ b/src/kaleid/kernel/ke/state.h @@ -0,0 +1,38 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: Current kernel state // +//----------------------------------------------------------------------------// + +#ifndef _KALKERN_KE_STATE_H +#define _KALKERN_KE_STATE_H + +#ifndef _KALCOMM_COMMON_H +#include "common/common.h" +#endif + +// XXX improve this +enum kernel_states { + // a process is running in kernel mode + KSTATE_PROCESS, + + // the kernel is not running a process + KSTATE_KERNEL, + + // the kernel is panicking + KSTATE_PANIC, + + // the kernel is booting + KSTATE_INIT, +}; + +extern uchar __kstate; + +#define DosGetKernState() (__kstate) +#define DosSetKernState(x) (__kstate = (x)) + +#endif + From d4be0f4fd5052553e5c6a9c66444ba10884c1804 Mon Sep 17 00:00:00 2001 From: Julian Barathieu Date: Sun, 30 Dec 2018 20:13:56 +0100 Subject: [PATCH 10/28] More stuff --- src/Makefile | 2 +- src/kaleid/common/assert.h | 2 +- src/kaleid/common/atomic.h | 2 +- src/kaleid/common/common.h | 10 +++++----- src/kaleid/common/convert.h | 2 +- src/kaleid/common/lib/convert.c | 2 +- src/kaleid/common/lib/memory.c | 2 +- src/kaleid/common/lib/sprintf.c | 2 +- src/kaleid/common/lib/status.c | 2 +- src/kaleid/common/lib/string.c | 2 +- src/kaleid/common/memory.h | 2 +- src/kaleid/common/status.h | 2 +- src/kaleid/common/string.h | 4 ++-- src/kaleid/common/sub/memory.c | 2 +- src/kaleid/common/types.h | 2 +- src/kaleid/kernel/init.c | 15 +++++++++++---- src/kaleid/kernel/init.h | 4 ++-- src/kaleid/kernel/io/ports.c | 2 +- src/kaleid/kernel/io/ports.h | 2 +- src/kaleid/kernel/io/terminal.c | 12 ++++++++++-- src/kaleid/kernel/io/terminal.h | 12 +++++++----- src/kaleid/kernel/ke/panic.c | 6 +++--- src/kaleid/kernel/ke/panic.h | 2 +- src/kaleid/kernel/ke/state.c | 2 +- src/kaleid/kernel/ke/state.h | 2 +- src/kaleid/kernel/mm/malloc.c | 2 +- src/kaleid/kernel/mm/malloc.h | 2 +- src/kaleid/linux/test-common.c | 6 +++--- src/kernel.ld | 2 +- 29 files changed, 64 insertions(+), 47 deletions(-) diff --git a/src/Makefile b/src/Makefile index 4988716..533f55f 100644 --- a/src/Makefile +++ b/src/Makefile @@ -13,7 +13,7 @@ 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=-I./kaleid +CINCLUDES=-isystem. CDEFINES= CC=$(CCNAME) $(COPTIM) $(CWARNS) $(CFLAGS) $(CDEFINES) $(CINCLUDES) diff --git a/src/kaleid/common/assert.h b/src/kaleid/common/assert.h index 8c18ad6..10b663d 100644 --- a/src/kaleid/common/assert.h +++ b/src/kaleid/common/assert.h @@ -11,7 +11,7 @@ #define _KALCOMM_ASSERT_H #ifndef _KALCOMM_COMMON_H -# error "don't include common/types.h without common/common.h" +# error "don't include kaleid/common/types.h without kaleid/common/common.h" #endif #ifdef _OSK_SOURCE diff --git a/src/kaleid/common/atomic.h b/src/kaleid/common/atomic.h index 56a4afb..569ecdb 100644 --- a/src/kaleid/common/atomic.h +++ b/src/kaleid/common/atomic.h @@ -11,7 +11,7 @@ #define _KALCOMM_ATOMIC_H #ifndef _KALCOMM_COMMON_H -# error "don't include common/types.h without common/common.h" +# error "don't include kaleid/common/types.h without kaleid/common/common.h" #endif // atomic_t defined in common/types.h diff --git a/src/kaleid/common/common.h b/src/kaleid/common/common.h index 52c3b44..5b4dc38 100644 --- a/src/kaleid/common/common.h +++ b/src/kaleid/common/common.h @@ -42,13 +42,13 @@ #endif #ifdef _KALEID_KERNEL -# include "kernel/config.h" +# include #endif -#include "common/types.h" -#include "common/atomic.h" -#include "common/status.h" -#include "common/assert.h" +#include +#include +#include +#include #endif diff --git a/src/kaleid/common/convert.h b/src/kaleid/common/convert.h index 737f016..915a071 100644 --- a/src/kaleid/common/convert.h +++ b/src/kaleid/common/convert.h @@ -11,7 +11,7 @@ #define _KALCOMM_CONVERT_H #ifndef _KALCOMM_COMMON_H -#include "common/common.h" +#include #endif #ifndef _OSK_SOURCE diff --git a/src/kaleid/common/lib/convert.c b/src/kaleid/common/lib/convert.c index 284f61f..49b8529 100644 --- a/src/kaleid/common/lib/convert.c +++ b/src/kaleid/common/lib/convert.c @@ -7,7 +7,7 @@ // Desc: Conversion utilities // //----------------------------------------------------------------------------// -#include "common/string.h" +#include // // Digits table for bases <=36 diff --git a/src/kaleid/common/lib/memory.c b/src/kaleid/common/lib/memory.c index 6ef23ce..7f7c05d 100644 --- a/src/kaleid/common/lib/memory.c +++ b/src/kaleid/common/lib/memory.c @@ -7,7 +7,7 @@ // Desc: mem*() functions // //----------------------------------------------------------------------------// -#include "common/memory.h" +#include // // Set "bytes"-many bytes starting from ptr to val diff --git a/src/kaleid/common/lib/sprintf.c b/src/kaleid/common/lib/sprintf.c index e26ded9..b1b86c6 100644 --- a/src/kaleid/common/lib/sprintf.c +++ b/src/kaleid/common/lib/sprintf.c @@ -7,7 +7,7 @@ // Desc: sprintf()-related functions // //----------------------------------------------------------------------------// -#include "common/string.h" +#include // // Format str according to fmt using ellipsed arguments diff --git a/src/kaleid/common/lib/status.c b/src/kaleid/common/lib/status.c index 5e8115c..254e1aa 100644 --- a/src/kaleid/common/lib/status.c +++ b/src/kaleid/common/lib/status.c @@ -7,7 +7,7 @@ // Desc: Implementation of describe_status() // //----------------------------------------------------------------------------// -#include "common/common.h" +#include static const char *descriptions[] = { [-SUCCESS] = "Success", diff --git a/src/kaleid/common/lib/string.c b/src/kaleid/common/lib/string.c index 464ff2e..b5178b9 100644 --- a/src/kaleid/common/lib/string.c +++ b/src/kaleid/common/lib/string.c @@ -7,7 +7,7 @@ // Desc: String-related functions // //----------------------------------------------------------------------------// -#include "common/string.h" +#include // TODO multibyte, assembly diff --git a/src/kaleid/common/memory.h b/src/kaleid/common/memory.h index 31f6a6b..a0f8366 100644 --- a/src/kaleid/common/memory.h +++ b/src/kaleid/common/memory.h @@ -11,7 +11,7 @@ #define _KALCOMM_MEMORY_H #ifndef _KALCOMM_COMMON_H -# include "common/common.h" +# include #endif #ifndef _OSK_SOURCE diff --git a/src/kaleid/common/status.h b/src/kaleid/common/status.h index 898c62a..7d674ff 100644 --- a/src/kaleid/common/status.h +++ b/src/kaleid/common/status.h @@ -11,7 +11,7 @@ #define _KALCOMM_STATUS_H #ifndef _KALCOMM_COMMON_H -# error "don't include common/types.h without common/common.h" +# error "don't include kaleid/common/types.h without kaleid/common/common.h" #endif #ifndef _OSK_SOURCE diff --git a/src/kaleid/common/string.h b/src/kaleid/common/string.h index 61056be..5440138 100644 --- a/src/kaleid/common/string.h +++ b/src/kaleid/common/string.h @@ -12,11 +12,11 @@ #define _KALCOMM_STRING_H #ifndef _KALCOMM_COMMON_H -# include "common/common.h" +# include #endif #ifndef _KALCOMM_CONVERT_H -# include "common/convert.h" +# include #endif #ifndef _OSK_SOURCE diff --git a/src/kaleid/common/sub/memory.c b/src/kaleid/common/sub/memory.c index aaecb6b..a12a9c6 100644 --- a/src/kaleid/common/sub/memory.c +++ b/src/kaleid/common/sub/memory.c @@ -10,7 +10,7 @@ // XXX to be improved before being brought back // to be tested with more alignment sizes -#include "common/memory.h" +#include // to be moved #define QWORD_SIZE 8 diff --git a/src/kaleid/common/types.h b/src/kaleid/common/types.h index bf74580..910ceac 100644 --- a/src/kaleid/common/types.h +++ b/src/kaleid/common/types.h @@ -12,7 +12,7 @@ #define _KALCOMM_TYPES_H #ifndef _KALCOMM_COMMON_H -# error "don't include common/types.h without common/common.h" +# error "don't include kaleid/common/types.h without kaleid/common/common.h" #endif typedef unsigned char uchar; diff --git a/src/kaleid/kernel/init.c b/src/kaleid/kernel/init.c index aa794fe..5483a22 100644 --- a/src/kaleid/kernel/init.c +++ b/src/kaleid/kernel/init.c @@ -7,18 +7,25 @@ // Desc: Kernel entry point // //----------------------------------------------------------------------------// -#include "kernel/init.h" -#include "kernel/ke/panic.h" -#include "kernel/io/terminal.h" +#include +#include +#include // // Entry point of kaleid-kernel.elf // -void kstart(void) +void DosStartKern(void) { + // we're not ready to deal with interrupts + DosDisableInterrupts(); + + // booting! DosSetKernState(KSTATE_INIT); + // kernel terminals DosInitTerms(); + + // we're out DosPanic("Goodbye World :("); } diff --git a/src/kaleid/kernel/init.h b/src/kaleid/kernel/init.h index bb80788..37e831c 100644 --- a/src/kaleid/kernel/init.h +++ b/src/kaleid/kernel/init.h @@ -10,10 +10,10 @@ #ifndef _KALKERN_INIT_H #define _KALKERN_INIT_H -#include "common/common.h" +#include // kernel entry point -void kstart(void); +void DosStartKern(void); #endif diff --git a/src/kaleid/kernel/io/ports.c b/src/kaleid/kernel/io/ports.c index fa824a0..4f5c8fe 100644 --- a/src/kaleid/kernel/io/ports.c +++ b/src/kaleid/kernel/io/ports.c @@ -7,7 +7,7 @@ // Desc: Ports I/O // //----------------------------------------------------------------------------// -#include "kernel/io/ports.h" +#include diff --git a/src/kaleid/kernel/io/ports.h b/src/kaleid/kernel/io/ports.h index 8df790d..a92ddb6 100644 --- a/src/kaleid/kernel/io/ports.h +++ b/src/kaleid/kernel/io/ports.h @@ -11,7 +11,7 @@ #define _KALKERN_IO_PORTS_H #ifndef _KALCOMM_COMMON_H -#include "common/common.h" +#include #endif #define DosWriteByteOnPort(port,val) asm volatile ("outb %1, %0" : : "dN" (port), "a" (value)) diff --git a/src/kaleid/kernel/io/terminal.c b/src/kaleid/kernel/io/terminal.c index e172daf..79da9b4 100644 --- a/src/kaleid/kernel/io/terminal.c +++ b/src/kaleid/kernel/io/terminal.c @@ -7,7 +7,7 @@ // Desc: Early terminal functions // //----------------------------------------------------------------------------// -#include "kernel/io/terminal.h" +#include // // VGA-related macros @@ -17,7 +17,7 @@ #define ComputeEntry(ch, cl) (((ushort)(ch)) | (ushort)(cl) << 8) // -// VGA output +// VGA output // static terminal_t _vga_term = { .kt_buffer = (ushort *)0xB8000, @@ -37,6 +37,13 @@ static terminal_t _vga_term = { // terminal_t *stdout; +#ifndef _NO_DEBUG +// +// Debugging terminal +// +terminal_t *stddbg; +#endif + // // Initialize standard output // @@ -46,6 +53,7 @@ void DosInitTerms(void) #ifndef _NO_DEBUG _vga_term.kt_init = TRUE; + stddbg = &_vga_term; #endif // to be switched to VESA diff --git a/src/kaleid/kernel/io/terminal.h b/src/kaleid/kernel/io/terminal.h index 229be43..63327fb 100644 --- a/src/kaleid/kernel/io/terminal.h +++ b/src/kaleid/kernel/io/terminal.h @@ -11,7 +11,7 @@ #define _KALKERN_IO_KTERM_H #ifndef _KALCOMM_COMMON_H -#include "common/common.h" +#include #endif // all available colors @@ -53,10 +53,12 @@ status_t DosChTermColor(terminal_t *, uchar); void DosPutOnTerm_Unlocked(terminal_t *, char); #endif -#define ktclear() kterm_clear(kt_stdout) -#define ktputch(c) kterm_putch(kt_stdout, (c)) -#define ktprint(s) kterm_print(kt_stdout, (s)) -#define ktchcol(c) kterm_change_color(kt_stdout, (c)) +#ifndef _NO_DEBUG +extern terminal_t *stddbg; +# define DebugLog(...) DosPutOnTerm(stddbg, __VA_ARGS__) +#else +# define DebugLog(...) +#endif #define DosLockTerm(kt) #define DosTryLockTerm(kt) diff --git a/src/kaleid/kernel/ke/panic.c b/src/kaleid/kernel/ke/panic.c index 38f8f9d..028729c 100644 --- a/src/kaleid/kernel/ke/panic.c +++ b/src/kaleid/kernel/ke/panic.c @@ -7,9 +7,9 @@ // Desc: How NOT to panic 101 // //----------------------------------------------------------------------------// -#include "kernel/ke/panic.h" -#include "kernel/ke/state.h" -#include "kernel/io/terminal.h" +#include +#include +#include // // Panic message diff --git a/src/kaleid/kernel/ke/panic.h b/src/kaleid/kernel/ke/panic.h index f73387a..4b7883a 100644 --- a/src/kaleid/kernel/ke/panic.h +++ b/src/kaleid/kernel/ke/panic.h @@ -10,7 +10,7 @@ #ifndef _KALKERN_KE_PANIC_H #define _KALKERN_KE_PANIC_H -#include "kernel/ke/state.h" +#include extern const char *__panicstr; noreturn void DosPanic(const char *); diff --git a/src/kaleid/kernel/ke/state.c b/src/kaleid/kernel/ke/state.c index e8a79fe..fae844d 100644 --- a/src/kaleid/kernel/ke/state.c +++ b/src/kaleid/kernel/ke/state.c @@ -7,7 +7,7 @@ // Desc: Current kernel state // //----------------------------------------------------------------------------// -#include "kernel/ke/state.h" +#include // // Current kernel state diff --git a/src/kaleid/kernel/ke/state.h b/src/kaleid/kernel/ke/state.h index ba6bf8d..7ca09a9 100644 --- a/src/kaleid/kernel/ke/state.h +++ b/src/kaleid/kernel/ke/state.h @@ -11,7 +11,7 @@ #define _KALKERN_KE_STATE_H #ifndef _KALCOMM_COMMON_H -#include "common/common.h" +#include #endif // XXX improve this diff --git a/src/kaleid/kernel/mm/malloc.c b/src/kaleid/kernel/mm/malloc.c index 5c62036..1ffa3c1 100644 --- a/src/kaleid/kernel/mm/malloc.c +++ b/src/kaleid/kernel/mm/malloc.c @@ -8,5 +8,5 @@ // Only exists to trigger Neox // //----------------------------------------------------------------------------// -#include "kernel/mm/malloc.h" +#include diff --git a/src/kaleid/kernel/mm/malloc.h b/src/kaleid/kernel/mm/malloc.h index 9d63aba..7d27929 100644 --- a/src/kaleid/kernel/mm/malloc.h +++ b/src/kaleid/kernel/mm/malloc.h @@ -11,7 +11,7 @@ #ifndef _KALKERN_MM_MALLOC_H #define _KALKERN_MM_MALLOC_H -#include "common/common.h" +#include #endif diff --git a/src/kaleid/linux/test-common.c b/src/kaleid/linux/test-common.c index edae890..b23e00a 100644 --- a/src/kaleid/linux/test-common.c +++ b/src/kaleid/linux/test-common.c @@ -11,9 +11,9 @@ #include #define KEEP_KALCOMM_TYPES_MINIMAL -#include "common/common.h" -#include "common/string.h" -#include "common/memory.h" +#include +#include +#include int main(int argc, char *argv[]) { diff --git a/src/kernel.ld b/src/kernel.ld index 86b66ea..d8fa35a 100644 --- a/src/kernel.ld +++ b/src/kernel.ld @@ -1,4 +1,4 @@ -ENTRY(kstart) +ENTRY(DosStartKern) SECTIONS { . = 0x4000; /* XXX 0x4000 is temporary */ From 31702521b10eb50e442e8b0ce48aba257acf8470 Mon Sep 17 00:00:00 2001 From: Julian Barathieu Date: Sun, 30 Dec 2018 22:21:19 +0100 Subject: [PATCH 11/28] Still more stuff --- src/kaleid/common/assert.h | 3 +- src/kaleid/common/common.h | 4 + src/kaleid/kernel/io/terminal.c | 128 ++++++++++++++++++-------------- src/kaleid/kernel/io/terminal.h | 51 +++++++------ src/kaleid/kernel/ke/lock.c | 13 ++++ src/kaleid/kernel/ke/lock.h | 96 ++++++++++++++++++++++++ src/kaleid/kernel/ke/panic.c | 18 +++-- src/kaleid/kernel/ke/panic.h | 7 +- 8 files changed, 226 insertions(+), 94 deletions(-) create mode 100644 src/kaleid/kernel/ke/lock.c create mode 100644 src/kaleid/kernel/ke/lock.h diff --git a/src/kaleid/common/assert.h b/src/kaleid/common/assert.h index 10b663d..f01060b 100644 --- a/src/kaleid/common/assert.h +++ b/src/kaleid/common/assert.h @@ -21,7 +21,8 @@ // uses panic() in kernel, abort() in system noreturn void ___assert_handler(const char *, const char *, int, const char *); -#define assert(x) do{if(unlikely(!(x)))___assert_handler(#x, __FILE__, __LINE__, __func__);}while(0); +#define DosAssert(x) do{if(unlikely(!(x)))___assert_handler(#x, __FILE__, __LINE__, __func__);}while(0); +#define assert DosAssert #else // not debugging diff --git a/src/kaleid/common/common.h b/src/kaleid/common/common.h index 5b4dc38..bc7a36f 100644 --- a/src/kaleid/common/common.h +++ b/src/kaleid/common/common.h @@ -41,6 +41,10 @@ # define unlikely(x) __builtin_expect((x), 0) #endif +#ifndef INITOK +# define INITOK 0xCAFEBABE +#endif + #ifdef _KALEID_KERNEL # include #endif diff --git a/src/kaleid/kernel/io/terminal.c b/src/kaleid/kernel/io/terminal.c index 79da9b4..b05ab48 100644 --- a/src/kaleid/kernel/io/terminal.c +++ b/src/kaleid/kernel/io/terminal.c @@ -7,6 +7,7 @@ // Desc: Early terminal functions // //----------------------------------------------------------------------------// +#define _UNLOCKED_IO #include // @@ -26,10 +27,8 @@ static terminal_t _vga_term = { .kt_curr_x = 0, .kt_curr_y = 0, .kt_color = ComputeColorCode(KTERM_COLOR_LGREY, KTERM_COLOR_BLACK), - .kt_lock = NULL, -#ifndef _NO_DEBUG + .kt_lock = INITLOCK(KLOCK_MUTEX), .kt_init = FALSE, -#endif }; // @@ -37,24 +36,20 @@ static terminal_t _vga_term = { // terminal_t *stdout; -#ifndef _NO_DEBUG // // Debugging terminal // terminal_t *stddbg; -#endif // // Initialize standard output // void DosInitTerms(void) { - assert(!stdout && !_vga_term.kt_init && "DosInitTerms() called twice"); + DosAssert(!stdout && _vga_term.kt_init != INITOK && "DosInitTerms() called twice"); -#ifndef _NO_DEBUG - _vga_term.kt_init = TRUE; + _vga_term.kt_init = INITOK; stddbg = &_vga_term; -#endif // to be switched to VESA stdout = &_vga_term; @@ -63,29 +58,16 @@ void DosInitTerms(void) // // Fills terminal with spaces -// XXX would '\0' work too? // status_t DosClearTerm(terminal_t *kt) { - size_t i; - if (kt == NULL) return BAD_ARG_NULL; - assert(kt->kt_init && "DosClearTerm called before initialization"); + DosAssert(kt->kt_init == INITOK); DosLockTerm(kt); - - const ushort filler = ComputeEntry(' ', kt->kt_color); - const size_t bufsize = kt->kt_width * kt->kt_height; - - for (i = 0; i < bufsize; i++) { - // XXX implement memsetw() - kt->kt_buffer[i] = filler; - } - - kt->kt_curr_x = kt->kt_curr_y = 0; - + DosClearTerm_Unlocked(kt); DosUnlockTerm(kt); return SUCCESS; @@ -102,20 +84,78 @@ status_t DosChTermColor(terminal_t *kt, uchar color) if (kt == NULL) return BAD_ARG_NULL; - DosLockTerm(kt); + DosLockTerm(kt); kt->kt_color = color; DosUnlockTerm(kt); return SUCCESS; } +// +// Writes a single character on the terminal +// +status_t DosPutOnTerm(terminal_t *kt, char ch) +{ + if (kt == NULL) + return BAD_ARG_NULL; + + DosAssert(kt->kt_init == INITOK); + + DosLockTerm(kt); + DosPutOnTerm_Unlocked(kt, ch); + DosUnlockTerm(kt); + + return SUCCESS; +} + +// +// Print string on terminal +// +status_t DosPrintOnTerm(terminal_t *kt, const char *str) +{ + if (kt == NULL) + return BAD_ARG_NULL; + + DosAssert(kt->kt_init == INITOK); + + DosLockTerm(kt); + while (*str) { + DosPutOnTerm_Unlocked(kt, *str++); + } + DosUnlockTerm(kt); + + return SUCCESS; +} + +//----------------------------------------------------------// +// UNLOCKED VERSIONS // +// // +// Direct use is highly deprecated // +// Useful in rare instances // +//----------------------------------------------------------// + +// +// Fills terminal with spaces +// XXX would '\0' work too? +// +void DosClearTerm_Unlocked(terminal_t *kt) +{ + size_t i; + + const ushort filler = ComputeEntry(' ', kt->kt_color); + const size_t bufsize = kt->kt_width * kt->kt_height; + + for (i = 0; i < bufsize; i++) { + // XXX implement memsetw() + kt->kt_buffer[i] = filler; + } + + kt->kt_curr_x = kt->kt_curr_y = 0; +} + // // Writes a single character on the terminal (UNLOCKED version) // -// DEPRECATED: -// - always use kterm_putch (LOCKED version) -// - doesn't check for NULL input -// void DosPutOnTerm_Unlocked(terminal_t *kt, char ch) { int i; @@ -158,37 +198,15 @@ void DosPutOnTerm_Unlocked(terminal_t *kt, char ch) } } -// -// Writes a single character on the terminal (LOCKED version) // -status_t DosPutOnTerm(terminal_t *kt, char ch) +// Print string on terminal (UNLOCKED version) +// +void DosPrintOnTerm_Unlocked(terminal_t *kt, const char *str) { - if (kt == NULL) - return BAD_ARG_NULL; - - DosLockTerm(kt); - DosPutOnTerm_Unlocked(kt, ch); - DosUnlockTerm(kt); - - return SUCCESS; -} - - -// -// Print string on terminal -// -status_t DosPrintOnTerm(terminal_t *kt, const char *str) -{ - if (kt == NULL) - return BAD_ARG_NULL; - - DosLockTerm(kt); while (*str) { DosPutOnTerm_Unlocked(kt, *str++); } - DosUnlockTerm(kt); - - return SUCCESS; } + diff --git a/src/kaleid/kernel/io/terminal.h b/src/kaleid/kernel/io/terminal.h index 63327fb..a209ead 100644 --- a/src/kaleid/kernel/io/terminal.h +++ b/src/kaleid/kernel/io/terminal.h @@ -10,12 +10,10 @@ #ifndef _KALKERN_IO_KTERM_H #define _KALKERN_IO_KTERM_H -#ifndef _KALCOMM_COMMON_H -#include -#endif +#include // all available colors -enum kterm_colors { +enum terminal_colors { KTERM_COLOR_BLACK, KTERM_COLOR_BLUE, KTERM_COLOR_GREEN, KTERM_COLOR_CYAN, KTERM_COLOR_RED, KTERM_COLOR_MAGENTA, @@ -26,43 +24,44 @@ enum kterm_colors { KTERM_COLOR_LBROWN, KTERM_COLOR_WHITE }; -typedef struct kterm { - void *kt_lock; - ushort *kt_buffer; - uchar kt_color; - size_t kt_width; - size_t kt_height; - off_t kt_curr_x; - off_t kt_curr_y; +typedef struct { + lock_t kt_lock; + ushort *kt_buffer; + uchar kt_color; + size_t kt_width; + size_t kt_height; + off_t kt_curr_x; + off_t kt_curr_y; + uint kt_init; // XXX flags -#ifndef _NO_DEBUG - bool kt_init; -#endif } terminal_t; // current "standard" terminal extern terminal_t *stdout; -void DosInitTerms(void); -status_t DosClearTerm(terminal_t *); -status_t DosPutOnTerm(terminal_t *, char); -status_t DosPrintOnTerm(terminal_t *, const char *); -status_t DosChTermColor(terminal_t *, uchar); +void DosInitTerms(void); +status_t DosClearTerm(terminal_t *); +status_t DosPutOnTerm(terminal_t *, char); +status_t DosPrintOnTerm(terminal_t *, const char *); +status_t DosChTermColor(terminal_t *, uchar); -#ifdef _UNLOCKED_IO -void DosPutOnTerm_Unlocked(terminal_t *, char); +#ifdef _UNLOCKED_IO +void DosClearTerm_Unlocked(terminal_t *); +void DosPutOnTerm_Unlocked(terminal_t *, char); +void DosPrintOnTerm_Unlocked(terminal_t *kt, const char *str); +#define DosChTermColor_Unlocked(kt, col) ((kt)->kt_color = col) #endif #ifndef _NO_DEBUG extern terminal_t *stddbg; -# define DebugLog(...) DosPutOnTerm(stddbg, __VA_ARGS__) +# define DebugLog(...) DosPutOnTerm(stddbg, __VA_ARGS__) #else # define DebugLog(...) #endif -#define DosLockTerm(kt) -#define DosTryLockTerm(kt) -#define DosUnlockTerm(kt) +#define DosLockTerm(kt) DosAquireLock(&kt->kt_lock) +#define DosUnlockTerm(kt) DosReleaseLock(&kt->kt_lock) +#define DosTryLockTerm(kt) DosAttemptLock(&kt->kt_lock) #endif diff --git a/src/kaleid/kernel/ke/lock.c b/src/kaleid/kernel/ke/lock.c new file mode 100644 index 0000000..544bf93 --- /dev/null +++ b/src/kaleid/kernel/ke/lock.c @@ -0,0 +1,13 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: Locks // +//----------------------------------------------------------------------------// + +#include + +// nothing to do here + diff --git a/src/kaleid/kernel/ke/lock.h b/src/kaleid/kernel/ke/lock.h new file mode 100644 index 0000000..79202d4 --- /dev/null +++ b/src/kaleid/kernel/ke/lock.h @@ -0,0 +1,96 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: Locks // +//----------------------------------------------------------------------------// + +#ifndef _KALKERN_KE_LOCK_H +#define _KALKERN_KE_LOCK_H + +#ifndef _KALCOMM_COMMON_H +#include +#endif + +enum lock_type { + // + // Mutex-type lock + // WARNING: DosLock() panics when used on a mutex while not running a process + // + KLOCK_MUTEX, + + // + // Spinlock-type lock + // Turns into a Mutex-type lock when MULTIPROCESSOR is off + // + KLOCK_SPINLOCK, + +}; + +typedef struct { + uchar lk_type; // lock type? + uint lk_lock; // is locked? + void *lk_owner; // unused + void *lk_waiting; // unused + uint lk_init; // unused if _NO_DEBUG +} lock_t; + +// +// Initialize a lock +// +#define DosInitLock(lk, type) \ + do { \ + (lk)->lk_type = (type); \ + (lk)->lk_lock = FALSE; \ + (lk)->lk_owner = NULL; \ + (lk)->lk_waiting = NULL; \ + (lk)->lk_init = INITOK; \ + } while (FALSE); + +// +// Alternative way to initalize a lock +// +#define INITLOCK(type) { (type), FALSE, NULL, NULL, INITOK } + +// +// Does nothing +// +#define DosDestroyLock(lk) + +// +// Aquires the lock +// Panics on double aquisition since that should never happen +// until we have at least a basic scheduler +// +#define DosAquireLock(lk) \ + do { \ + DosDisableInterrupts(); \ + DosAssert((lk)->lk_init == INITOK); \ + if ((lk)->lk_lock++) \ + DosPanic("DosAquireLock on an already locked object"); \ + DosEnableInterrupts(); \ + } while (FALSE); + +// +// Releases an already aquired lock +// Panics if the lock was never aquired (this will change) +// +#define DosReleaseLock(lk) \ + do { \ + DosDisableInterrupts(); \ + DosAssert((lk)->lk_init == INITOK); \ + if ((lk)->lk_lock++) \ + DosPanic("DosReleased on an unlocked object"); \ + DosEnableInterrupts(); \ + } while (FALSE); + +// +// Tries to aquire lock +// Doesn't work at all for obvious reasons +// +#define DosAttemptLock(lk) ((lk)->lk_lock++) + +#endif + diff --git a/src/kaleid/kernel/ke/panic.c b/src/kaleid/kernel/ke/panic.c index 028729c..e319fe6 100644 --- a/src/kaleid/kernel/ke/panic.c +++ b/src/kaleid/kernel/ke/panic.c @@ -9,12 +9,14 @@ #include #include + +#define _UNLOCKED_IO #include // // Panic message // -const char *panicstr = NULL; +const char *__panicmsg = NULL; // // Failed assert() handler @@ -39,22 +41,22 @@ void DosPanic(const char *str) DosSetKernState(KSTATE_PANIC); - DosClearTerm(stdout); + DosClearTerm_Unlocked(stdout); if (str == NULL) { str = "(no message given)"; } - if (panicstr) { - // shouldn't be possible - DosPrintOnTerm(stdout, "double panic!\n"); + if (DosGetPanicStr()) { + DosPrintOnTerm_Unlocked(stdout, "double panic!\n"); DosHaltCPU(); } - panicstr = str; + DosSetPanicStr(str); - DosPrintOnTerm(stdout, "panic! - "); - DosPrintOnTerm(stdout, str); + // we cannot lock anything when panicking + DosPrintOnTerm_Unlocked(stdout, "panic! - "); + DosPrintOnTerm_Unlocked(stdout, str); while (TRUE) { DosHaltCPU(); diff --git a/src/kaleid/kernel/ke/panic.h b/src/kaleid/kernel/ke/panic.h index 4b7883a..91cc78e 100644 --- a/src/kaleid/kernel/ke/panic.h +++ b/src/kaleid/kernel/ke/panic.h @@ -12,11 +12,10 @@ #include -extern const char *__panicstr; noreturn void DosPanic(const char *); -#define DosGetPanicStr() (__panicstr) - -#define panic DosPanic +extern const char *__panicmsg; +#define DosGetPanicStr() (__panicmsg) +#define DosSetPanicStr(str) (__panicmsg = (str)) #endif From 680ca2a52cbb2caf2f302121da7c07880bc08857 Mon Sep 17 00:00:00 2001 From: Julian Barathieu Date: Sun, 30 Dec 2018 22:42:19 +0100 Subject: [PATCH 12/28] Minor stuff --- src/kaleid/common/common.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/kaleid/common/common.h b/src/kaleid/common/common.h index bc7a36f..45943dd 100644 --- a/src/kaleid/common/common.h +++ b/src/kaleid/common/common.h @@ -15,17 +15,17 @@ #endif #if !defined(TRUE) && !defined(FALSE) -# define TRUE 1 -# define FALSE 0 +# define TRUE (1) +# define FALSE (0) #endif #ifdef _OSK_SOURCE -# define YES 1 -# define NO 0 +# define YES (1) +# define NO (0) #endif #ifndef NULL -# define NULL ((void*)0) +# define NULL ((void *)0) #endif #ifndef PACKED @@ -42,7 +42,7 @@ #endif #ifndef INITOK -# define INITOK 0xCAFEBABE +# define INITOK ((unsigned int)0xCAFEBABE) #endif #ifdef _KALEID_KERNEL From 15a7ad873f530017e7605055c4c399de398cc857 Mon Sep 17 00:00:00 2001 From: Julian Barathieu Date: Mon, 31 Dec 2018 10:49:08 +0100 Subject: [PATCH 13/28] Common stuff --- src/Makefile | 24 ++-- src/kaleid/common/assert.h | 52 -------- src/kaleid/common/common.h | 128 +++++++++++++++++-- src/kaleid/common/convert.h | 24 ---- src/kaleid/common/folder.desc | 52 ++++---- src/kaleid/common/lib/convert.c | 2 +- src/kaleid/common/lib/memory.c | 60 +++++++-- src/kaleid/common/{atomic.h => lib/memsub.c} | 42 +++--- src/kaleid/common/lib/sprintf.c | 2 +- src/kaleid/common/lib/string.c | 4 +- src/kaleid/common/memory.h | 28 ---- src/kaleid/common/status.h | 41 ------ src/kaleid/common/stdlib.h | 75 +++++++++++ src/kaleid/common/string.h | 49 ------- src/kaleid/common/sub/memory.c | 79 ------------ src/kaleid/common/types.h | 44 ------- src/kaleid/kernel/folder.desc | 7 +- src/kaleid/kernel/init.c | 1 + src/kaleid/kernel/init.h | 2 + src/kaleid/kernel/io/terminal.c | 19 ++- src/kaleid/kernel/io/terminal.h | 6 +- src/kaleid/kernel/ke/lock.h | 8 +- src/kaleid/kernel/ke/panic.c | 5 +- src/kaleid/kernel/ke/panic.h | 5 +- src/kaleid/kernel/ke/state.h | 1 - 25 files changed, 346 insertions(+), 414 deletions(-) delete mode 100644 src/kaleid/common/assert.h delete mode 100644 src/kaleid/common/convert.h rename src/kaleid/common/{atomic.h => lib/memsub.c} (53%) delete mode 100644 src/kaleid/common/memory.h delete mode 100644 src/kaleid/common/status.h create mode 100644 src/kaleid/common/stdlib.h delete mode 100644 src/kaleid/common/string.h delete mode 100644 src/kaleid/common/sub/memory.c delete mode 100644 src/kaleid/common/types.h 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)) From 529055e9fe0c0a4165a425635749f8275655243f Mon Sep 17 00:00:00 2001 From: Julian Barathieu Date: Mon, 31 Dec 2018 15:08:56 +0100 Subject: [PATCH 14/28] Still more stuff --- src/kaleid/common/common.h | 16 +++++- src/kaleid/common/folder.desc | 8 +-- src/kaleid/common/lib/memory.c | 89 ++++++++++++++++++++++++++++------ src/kaleid/common/stdlib.h | 10 ++-- src/kaleid/kernel/ke/panic.c | 2 +- src/kaleid/linux/test-common.c | 51 ++++++++++--------- 6 files changed, 128 insertions(+), 48 deletions(-) diff --git a/src/kaleid/common/common.h b/src/kaleid/common/common.h index 121a50f..db57a20 100644 --- a/src/kaleid/common/common.h +++ b/src/kaleid/common/common.h @@ -47,6 +47,10 @@ # define unlikely(x) (__builtin_expect((x), 0)) #endif +#ifndef alignof +# define alignof _Alignof +#endif + #ifndef INITOK # define INITOK ((unsigned int)0xCAFEBABE) #endif @@ -82,6 +86,14 @@ typedef void *va_list; // XXX limits +#define WORD_SIZE sizeof(ushort) +#define DWORD_SIZE sizeof(uint) +#define QWORD_SIZE sizeof(ulong) + +#define WORD_ALIGN alignof(ushort) +#define DWORD_ALIGN alignof(uint) +#define QWORD_ALIGN alignof(ulong) + //------------------------------------------// // VALUES FOR "status_t" // //------------------------------------------// @@ -129,12 +141,12 @@ const char *describe_status(status_t); #if !defined(_NO_DEBUG) && !defined(NDEBUG) // uses panic() in kernel, abort() in system -noreturn void ___assert_handler(const char *, const char *, int, const char *); +noreturn void _assert_handler(const char *, const char *, int, const char *); #define DosAssert(x) \ do { \ if unlikely(!(x)) \ - ___assert_handler(#x, __FILE__, __LINE__, __func__); \ + _assert_handler(#x, __FILE__, __LINE__, __func__); \ } while (FALSE); #define assert DosAssert diff --git a/src/kaleid/common/folder.desc b/src/kaleid/common/folder.desc index 124f60c..eaf5c24 100644 --- a/src/kaleid/common/folder.desc +++ b/src/kaleid/common/folder.desc @@ -22,10 +22,10 @@ This folder contains the following files: - 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) + 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 diff --git a/src/kaleid/common/lib/memory.c b/src/kaleid/common/lib/memory.c index 7d40011..196cdcc 100644 --- a/src/kaleid/common/lib/memory.c +++ b/src/kaleid/common/lib/memory.c @@ -7,22 +7,19 @@ // 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 +//------------------------------------------// +// memset() family // +//------------------------------------------// // // Set "qwords"-many aligned qwords starting from ptr to val // -static inline void *memsetq(void *ptr, ullong uval, size_t qwords) +static inline void *_memset_internal(void *ptr, ulong uval, size_t qwords) { size_t n; - ullong *uptr = (ullong *)ptr; + ulong *uptr = (ulong *)ptr; // aligned memory write for (n = 0; n < qwords; n++) { @@ -44,18 +41,18 @@ void *memset(void *ptr, int val, size_t bytes) val = val & 0xFF; // deal with bytes before start of the first aligned qword - while (((ullong)uptr % QWORD_ALIGN) > 0 && bytes--) { + while (((ulong)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); + const ulong uval = ((ulong)val << 56) | ((ulong)val << 48) + | ((ulong)val << 40) | ((ulong)val << 32) + | ((ulong)val << 24) | ((ulong)val << 16) + | ((ulong)val << 8) | ((ulong)val); - memsetq(uptr, uval, qwords); + _memset_internal(uptr, uval, qwords); uptr += qwords * QWORD_SIZE; bytes %= QWORD_SIZE; @@ -69,11 +66,75 @@ void *memset(void *ptr, int val, size_t bytes) return ptr; } +// +// Set "words"-many words starting from ptr to val +// +void *memsetw(void *ptr, int val, size_t words) +{ + ushort *uptr = (ushort *)ptr; + + // get rid of everything after the first word + val = val & 0xFFFF; + + // can we do this an aligned way? + if unlikely (((ulong)uptr % WORD_ALIGN) > 0) { + // no, we can't align ourselves + while (words--) { + // do it the hard way + *uptr++ = (ushort)val; + } + // too bad '-' + return uptr; + } + + // deal with words before start of the first aligned qword + while (((ulong)uptr % QWORD_ALIGN) > 0 && words--) { + *uptr++ = (ushort)val; + } + + const size_t qwords = (words * WORD_SIZE)/QWORD_SIZE; + + // move qword by qword + if (qwords) { + const ulong uval = ((ulong)val << 48) | ((ulong)val << 32) + | ((ulong)val << 16) | ((ulong)val); + + _memset_internal(uptr, uval, qwords); + + uptr += qwords * QWORD_SIZE / WORD_SIZE; + words %= QWORD_SIZE / WORD_SIZE; + } + + // deal with what's left + while (words--) { + *uptr++ = (ushort)val; + } + + return ptr; +} + +// +// Set "qwords"-many qwords starting from ptr to val +// +void *memsetq(void *ptr, long val, size_t qwords) +{ + return _memset_internal(ptr, (ulong)val, qwords); +} + // // Set "bytes"-many bytes starting from ptr to 0 // void *memzero(void *ptr, size_t bytes) { + // is direct aligned access possible? (is "unlikely" good here?) + if unlikely (bytes % QWORD_SIZE && (ulong)ptr % QWORD_ALIGN) { + return _memset_internal(ptr, (ulong)0, bytes/QWORD_SIZE); + } + + if unlikely (bytes % WORD_SIZE && (ulong)ptr % WORD_ALIGN) { + return memsetw(ptr, (int)0, bytes/WORD_SIZE); + } + return memset(ptr, 0, bytes); } diff --git a/src/kaleid/common/stdlib.h b/src/kaleid/common/stdlib.h index e267a4e..b4af1f3 100644 --- a/src/kaleid/common/stdlib.h +++ b/src/kaleid/common/stdlib.h @@ -8,8 +8,8 @@ //----------------------------------------------------------------------------// -#ifndef _KALCOMM_STRING_H -#define _KALCOMM_STRING_H +#ifndef _KALCOMM_STDLIB_H +#define _KALCOMM_STDLIB_H #ifndef _KALCOMM_COMMON_H # include @@ -21,12 +21,16 @@ #ifndef _OSK_SOURCE # define memcpy _osk_memcpy -# define memset _osk_memset # define memcmp _osk_memcmp # define memzero _osk_memzero #endif +#define memsetb memset void *memset(void *, int, size_t); +void *memsetw(void *, int, size_t); +void *memsetd(void *, int, size_t); +void *memsetq(void *, long, size_t); + void *memzero(void *, size_t); //------------------------------------------// diff --git a/src/kaleid/kernel/ke/panic.c b/src/kaleid/kernel/ke/panic.c index 633cbf7..aaad786 100644 --- a/src/kaleid/kernel/ke/panic.c +++ b/src/kaleid/kernel/ke/panic.c @@ -21,7 +21,7 @@ const char *__panicmsg = NULL; // // Failed assert() handler // -noreturn void ___assert_handler(const char *msg, +noreturn void _assert_handler(const char *msg, const char *file, int line, const char *func) diff --git a/src/kaleid/linux/test-common.c b/src/kaleid/linux/test-common.c index b23e00a..cbce8cb 100644 --- a/src/kaleid/linux/test-common.c +++ b/src/kaleid/linux/test-common.c @@ -9,11 +9,9 @@ #include #include -#define KEEP_KALCOMM_TYPES_MINIMAL -#include -#include -#include +#define KEEP_KALCOMM_TYPES_MINIMAL +#include int main(int argc, char *argv[]) { @@ -31,37 +29,42 @@ int main(int argc, char *argv[]) //char *test2 = malloc(size1); //char *test3 = malloc(size1); - //const size_t sizex = 10000000; - //void *xxx = malloc(sizex); - //printf("%p\n",xxx); - //memset(xxx, 'x', sizex); + const size_t sizex = 130; + short *xxx = (short *)malloc(sizex * sizeof(short)); + //printf("%ld\n",(ulong)xxx%8); + //memzero(xxx, sizex); + memsetw(xxx, 300, sizex); - const char *str = "ceci est un string de test!"; - char *str2 = malloc((strlen(str) + 3) * sizeof(char)); - char *str3 = malloc((strlen(str) + 3) * sizeof(char)); + size_t it; + for (it = 0; it < sizex; it++) { + short s = *(xxx + it); + printf("%hd", s); + } + + puts(""); + + //free((void *)xxx); + + //const char *str = "ceci est un string de test!"; + //char *str2 = malloc((strlen(str) + 3) * sizeof(char)); + //char *str3 = malloc((strlen(str) + 3) * sizeof(char)); - strcpy(str2, str); + //strcpy(str2, str); //size_t s = strlen(str2); - strrev(str3,str2); - printf("%lu - %s\n", strlen(str3), str3); + //strrev(str3,str2); + //printf("%lu - %s\n", strlen(str3), str3); //str2[s] = '\n'; //str2[s+1] = '\0'; - strrev(str2,str3); - printf("%lu - %s\n", strlen(str2), str2); + //strrev(str2,str3); + //printf("%lu - %s\n", strlen(str2), str2); - free(str2); - free(str3); + //free(str2); + //free(str3); - /*size_t it; - for (it = 0; it < sizex; it++) { - char c = *(xxx + it); - printf("%c", (c ? c : '-')); - } - puts("");*/ //free(test2); //free(test3); From ec0045a566aabf6a5a37e0f8c4322b77136ddb6a Mon Sep 17 00:00:00 2001 From: Julian Barathieu Date: Tue, 1 Jan 2019 13:09:57 +0100 Subject: [PATCH 15/28] Big stuff! Happy new year! --- src/Makefile | 51 +++++---- src/kaleid/common/{lib => }/convert.c | 2 +- src/kaleid/common/{lib => }/memory.c | 2 +- src/kaleid/common/{lib => }/memsub.c | 2 +- src/kaleid/common/{ => old}/common.h | 17 ++- src/kaleid/common/{ => old}/folder.desc | 0 src/kaleid/common/{ => old}/stdlib.h | 25 +++-- src/kaleid/common/{lib => }/sprintf.c | 2 +- src/kaleid/common/{lib => }/status.c | 2 +- src/kaleid/common/{lib => }/string.c | 23 +++- .../{linux => common/test}/test-common.c | 5 +- src/kaleid/include/kalassrt.h | 82 ++++++++++++++ src/kaleid/include/kalcrt.h | 102 +++++++++++++++++ src/kaleid/include/kaldefs.h | 105 ++++++++++++++++++ src/kaleid/include/kaleid.h | 51 +++++++++ src/kaleid/include/kalkern | 1 + src/kaleid/include/kalkern.h | 37 ++++++ src/kaleid/include/kalmask.h | 46 ++++++++ src/kaleid/include/kaltypes.h | 74 ++++++++++++ src/kaleid/kernel/config.h | 4 +- src/kaleid/kernel/init.c | 18 +-- src/kaleid/kernel/init.h | 6 +- src/kaleid/kernel/io/ports.c | 2 +- src/kaleid/kernel/io/ports.h | 10 +- src/kaleid/kernel/io/terminal.c | 54 ++++----- src/kaleid/kernel/io/terminal.h | 30 ++--- src/kaleid/kernel/ke/lock.c | 2 +- src/kaleid/kernel/ke/lock.h | 30 ++--- src/kaleid/kernel/ke/panic.c | 38 +++---- src/kaleid/kernel/ke/panic.h | 12 +- src/kaleid/kernel/ke/state.c | 2 +- src/kaleid/kernel/ke/state.h | 8 +- src/kaleid/kernel/mm/malloc.c | 12 -- src/kaleid/kernel/mm/malloc.h | 17 --- src/kernel.ld | 2 +- src/project-tree.txt | 52 +++++---- 36 files changed, 718 insertions(+), 210 deletions(-) rename src/kaleid/common/{lib => }/convert.c (97%) rename src/kaleid/common/{lib => }/memory.c (99%) rename src/kaleid/common/{lib => }/memsub.c (96%) rename src/kaleid/common/{ => old}/common.h (92%) rename src/kaleid/common/{ => old}/folder.desc (100%) rename src/kaleid/common/{ => old}/stdlib.h (83%) rename src/kaleid/common/{lib => }/sprintf.c (98%) rename src/kaleid/common/{lib => }/status.c (97%) rename src/kaleid/common/{lib => }/string.c (79%) rename src/kaleid/{linux => common/test}/test-common.c (95%) create mode 100644 src/kaleid/include/kalassrt.h create mode 100644 src/kaleid/include/kalcrt.h create mode 100644 src/kaleid/include/kaldefs.h create mode 100644 src/kaleid/include/kaleid.h create mode 120000 src/kaleid/include/kalkern create mode 100644 src/kaleid/include/kalkern.h create mode 100644 src/kaleid/include/kalmask.h create mode 100644 src/kaleid/include/kaltypes.h delete mode 100644 src/kaleid/kernel/mm/malloc.c delete mode 100644 src/kaleid/kernel/mm/malloc.h diff --git a/src/Makefile b/src/Makefile index d4e80b8..91253d1 100644 --- a/src/Makefile +++ b/src/Makefile @@ -12,7 +12,7 @@ CC2NAME=gcc COPTIM=-O2 CLDSCR=-T kernel.ld CWARNS=-pedantic -Wall -Wextra -Werror -CINCLUDES=-isystem. +CINCLUDES=-isystem./kaleid/include CDEFINES= CFLAGS1=-nostdlib -ffreestanding -mcmodel=large @@ -20,7 +20,7 @@ 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 +KCC=$(CC) -D_OSK_SOURCE -D_KALEID_KERNEL ASM=nasm ASMFLAGS= @@ -33,7 +33,8 @@ BOOTDIR=boot COMMDIR=kaleid/common KERNDIR=kaleid/kernel SYSTDIR=kaleid/system -LINXDIR=kaleid/linux +LINXDIR=kaleid/common/test +INCDIR=kaleid/include all: bootloader kernel @@ -62,24 +63,29 @@ testing: bootloader pseudo_kern COBJDIR=$(OBJDIR)/$(COMMDIR) LOBJDIR=$(OBJDIR)/$(LINXDIR) -COMMDEPS=$(COMMDIR)/common.h $(COMMDIR)/stdlib.h $(KERNDIR)/config.h +#COMMDEPS=$(COMMDIR)/common.h $(COMMDIR)/stdlib.h $(KERNDIR)/config.h +COMMDEPS=$(INCDIR)/kaleid.h $(INCDIR)/kaldefs.h $(INCDIR)/kaltypes.h \ + $(INCDIR)/kalmask.h $(INCDIR)/kalmask.h $(INCDIR)/kalassrt.h -COMMOBJS=$(COBJDIR)/lib/string.o $(COBJDIR)/lib/status.o \ - $(COBJDIR)/lib/convert.o $(COBJDIR)/lib/memory.o +COMMSRCS=$(COMMDIR)/string.c $(COMMDIR)/status.c \ + $(COMMDIR)/convert.c $(COMMDIR)/memory.c -common: $(COMMDEPS) $(COMMDIR)/lib/string.c $(COMMDIR)/lib/status.c - $(KCC) -c $(COMMDIR)/lib/string.c -o $(COBJDIR)/lib/string.o - $(KCC) -c $(COMMDIR)/lib/status.c -o $(COBJDIR)/lib/status.o - $(KCC) -c $(COMMDIR)/lib/memory.c -o $(COBJDIR)/lib/memory.o - $(KCC) -c $(COMMDIR)/lib/convert.c -o $(COBJDIR)/lib/convert.o +COMMOBJS=$(COBJDIR)/string.o $(COBJDIR)/status.o \ + $(COBJDIR)/convert.o $(COBJDIR)/memory.o + +common: $(COMMDEPS) $(COMMSRCS) + $(KCC) -c $(COMMDIR)/string.c -o $(COBJDIR)/string.o + $(KCC) -c $(COMMDIR)/status.c -o $(COBJDIR)/status.o + $(KCC) -c $(COMMDIR)/memory.c -o $(COBJDIR)/memory.o + $(KCC) -c $(COMMDIR)/convert.c -o $(COBJDIR)/convert.o CCC=$(CC2NAME) $(COPTIM) $(CWARNS) $(CINCLUDES) -test-common: - $(CCC) -c $(COMMDIR)/lib/string.c -o $(COBJDIR)/lib/string.o - $(CCC) -c $(COMMDIR)/lib/status.c -o $(COBJDIR)/lib/status.o - $(CCC) -c $(COMMDIR)/lib/memory.c -o $(COBJDIR)/lib/memory.o - $(CCC) -c $(COMMDIR)/lib/convert.c -o $(COBJDIR)/lib/convert.o +test-common: $(COMMSRCS) + $(CCC) -c $(COMMDIR)/string.c -o $(COBJDIR)/string.o + $(CCC) -c $(COMMDIR)/status.c -o $(COBJDIR)/status.o + $(CCC) -c $(COMMDIR)/memory.c -o $(COBJDIR)/memory.o + $(CCC) -c $(COMMDIR)/convert.c -o $(COBJDIR)/convert.o $(CCC) -c $(LINXDIR)/test-common.c -o $(LOBJDIR)/test-common.o $(CCC) $(COMMOBJS) $(LOBJDIR)/test-common.o -o $(BINDIR)/kaleid-common.elf @@ -88,17 +94,18 @@ test-common: KOBJDIR=$(OBJDIR)/$(KERNDIR) -KERNDEPS=common $(KERNDIR)/init.h $(KERNDIR)/io/terminal.h \ - $(KERNDIR)/io/ports.h $(KERNDIR)/ke/panic.h +KERNDEPS=common $(KERNDIR)/init.h $(KERNDIR)/io/terminal.h $(KERNDIR)/ke/lock.h \ + $(KERNDIR)/io/ports.h $(KERNDIR)/ke/panic.h $(KERNDIR)/ke/state.h -KERNSRCS=$(KERNDIR)/init.c $(KERNDIR)/ke/state.c $(KERNDIR)/ke/panic.c \ - $(KERNDIR)/io/ports.c $(KERNDIR)/io/terminal.c +KERNSRCS=$(KERNDIR)/init.c $(KERNDIR)/io/terminal.c $(KERNDIR)/ke/lock.c \ + $(KERNDIR)/io/ports.c $(KERNDIR)/ke/panic.c $(KERNDIR)/ke/state.c -KERNOBJS=$(KOBJDIR)/init.o $(KOBJDIR)/ke/state.o $(KOBJDIR)/ke/panic.o \ - $(KOBJDIR)/io/ports.o $(KOBJDIR)/io/terminal.o +KERNOBJS=$(KOBJDIR)/init.o $(KOBJDIR)/io/terminal.o $(KOBJDIR)/ke/lock.o \ + $(KOBJDIR)/io/ports.o $(KOBJDIR)/ke/panic.o $(KOBJDIR)/ke/state.o kernel: common $(KERNSRCS) $(KCC) -c $(KERNDIR)/init.c -o $(KOBJDIR)/init.o + $(KCC) -c $(KERNDIR)/ke/lock.c -o $(KOBJDIR)/ke/lock.o $(KCC) -c $(KERNDIR)/ke/state.c -o $(KOBJDIR)/ke/state.o $(KCC) -c $(KERNDIR)/ke/panic.c -o $(KOBJDIR)/ke/panic.o $(KCC) -c $(KERNDIR)/io/ports.c -o $(KOBJDIR)/io/ports.o diff --git a/src/kaleid/common/lib/convert.c b/src/kaleid/common/convert.c similarity index 97% rename from src/kaleid/common/lib/convert.c rename to src/kaleid/common/convert.c index 9a9f037..61e63bf 100644 --- a/src/kaleid/common/lib/convert.c +++ b/src/kaleid/common/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/memory.c similarity index 99% rename from src/kaleid/common/lib/memory.c rename to src/kaleid/common/memory.c index 196cdcc..d9097eb 100644 --- a/src/kaleid/common/lib/memory.c +++ b/src/kaleid/common/memory.c @@ -7,7 +7,7 @@ // Desc: mem*() functions // //----------------------------------------------------------------------------// -#include +#include //------------------------------------------// // memset() family // diff --git a/src/kaleid/common/lib/memsub.c b/src/kaleid/common/memsub.c similarity index 96% rename from src/kaleid/common/lib/memsub.c rename to src/kaleid/common/memsub.c index 8b25667..247c4d3 100644 --- a/src/kaleid/common/lib/memsub.c +++ b/src/kaleid/common/memsub.c @@ -7,7 +7,7 @@ // Desc: mem*() functions, suboptimal edition // //----------------------------------------------------------------------------// -#include +#include // // Set "bytes"-many bytes starting from ptr to val diff --git a/src/kaleid/common/common.h b/src/kaleid/common/old/common.h similarity index 92% rename from src/kaleid/common/common.h rename to src/kaleid/common/old/common.h index db57a20..1c9c0d6 100644 --- a/src/kaleid/common/common.h +++ b/src/kaleid/common/old/common.h @@ -55,6 +55,10 @@ # define INITOK ((unsigned int)0xCAFEBABE) #endif +#ifndef KALAPI +# define KALAPI +#endif + #ifdef _KALEID_KERNEL # include #endif @@ -86,13 +90,6 @@ typedef void *va_list; // XXX limits -#define WORD_SIZE sizeof(ushort) -#define DWORD_SIZE sizeof(uint) -#define QWORD_SIZE sizeof(ulong) - -#define WORD_ALIGN alignof(ushort) -#define DWORD_ALIGN alignof(uint) -#define QWORD_ALIGN alignof(ulong) //------------------------------------------// // VALUES FOR "status_t" // @@ -127,9 +124,9 @@ const char *describe_status(status_t); #ifdef _KALEID_KERNEL -# define DosDisableInterrupts() asm volatile ("cli") -# define DosEnableInterrupts() asm volatile ("sti") -# define DosHaltCPU() asm volatile ("hlt") +# define DisableInterrupts() asm volatile ("cli") +# define EnableInterrupts() asm volatile ("sti") +# define HaltCPU() asm volatile ("hlt") #endif //------------------------------------------// diff --git a/src/kaleid/common/folder.desc b/src/kaleid/common/old/folder.desc similarity index 100% rename from src/kaleid/common/folder.desc rename to src/kaleid/common/old/folder.desc diff --git a/src/kaleid/common/stdlib.h b/src/kaleid/common/old/stdlib.h similarity index 83% rename from src/kaleid/common/stdlib.h rename to src/kaleid/common/old/stdlib.h index b4af1f3..5f8e96c 100644 --- a/src/kaleid/common/stdlib.h +++ b/src/kaleid/common/old/stdlib.h @@ -4,15 +4,24 @@ // Authors: spectral` // // NeoX // // // -// Desc: Kaleid string library // +// Desc: Kaleid C runtime library // //----------------------------------------------------------------------------// - #ifndef _KALCOMM_STDLIB_H #define _KALCOMM_STDLIB_H -#ifndef _KALCOMM_COMMON_H -# include +//------------------------------------------// +// Typedefs // +//------------------------------------------// + +#ifndef __size_t +#define __size_t +typedef unsigned long size_t; +#endif + +#ifndef __va_list +#define __va_list +typedef __builtin_va_start va_list; #endif //------------------------------------------// @@ -25,8 +34,10 @@ # define memzero _osk_memzero #endif -#define memsetb memset -void *memset(void *, int, size_t); +#ifndef memset +# define memset memsetb +#endif +void *memsetb(void *, int, size_t); void *memsetw(void *, int, size_t); void *memsetd(void *, int, size_t); void *memsetq(void *, long, size_t); @@ -72,7 +83,7 @@ int vsnprintf(char *, size_t, const char *, va_list); char *itoa(int, char *, int); //------------------------------------------// -// End of kaleid/common/stdlib.h // +// End of header file // //------------------------------------------// #endif diff --git a/src/kaleid/common/lib/sprintf.c b/src/kaleid/common/sprintf.c similarity index 98% rename from src/kaleid/common/lib/sprintf.c rename to src/kaleid/common/sprintf.c index c8cbfa8..8a4e1f5 100644 --- a/src/kaleid/common/lib/sprintf.c +++ b/src/kaleid/common/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/status.c b/src/kaleid/common/status.c similarity index 97% rename from src/kaleid/common/lib/status.c rename to src/kaleid/common/status.c index 254e1aa..c5139fe 100644 --- a/src/kaleid/common/lib/status.c +++ b/src/kaleid/common/status.c @@ -7,7 +7,7 @@ // Desc: Implementation of describe_status() // //----------------------------------------------------------------------------// -#include +#include static const char *descriptions[] = { [-SUCCESS] = "Success", diff --git a/src/kaleid/common/lib/string.c b/src/kaleid/common/string.c similarity index 79% rename from src/kaleid/common/lib/string.c rename to src/kaleid/common/string.c index 4bab621..81b4847 100644 --- a/src/kaleid/common/lib/string.c +++ b/src/kaleid/common/string.c @@ -7,7 +7,7 @@ // Desc: String-related functions // //----------------------------------------------------------------------------// -#include +#include // // Returns str's length @@ -32,7 +32,7 @@ char *strcpy(char *dest, const char *src) } // -// strcpy() but safer +// strcpy() but always writes n bytes // char *strncpy(char *dest, const char *src, size_t n) { @@ -46,6 +46,25 @@ char *strncpy(char *dest, const char *src, size_t n) return dest; } +// +// strncpy() but safer - always null-terminate, +// returns boolean indicating whether copy was complete +// XXX find a better name +// XXX actually implement this +// +size_t xstrcnpy(char *dest, const char *src, size_t n) +{ + size_t it; + + for (it = 0; it < n && src[it]; it++) { + dest[it] = src[it]; + } + + while (it < n) dest[it++] = 0; + + return TRUE; +} + // // Reverses the string src, putting the result into dest // diff --git a/src/kaleid/linux/test-common.c b/src/kaleid/common/test/test-common.c similarity index 95% rename from src/kaleid/linux/test-common.c rename to src/kaleid/common/test/test-common.c index cbce8cb..c63735b 100644 --- a/src/kaleid/linux/test-common.c +++ b/src/kaleid/common/test/test-common.c @@ -10,8 +10,7 @@ #include #include -#define KEEP_KALCOMM_TYPES_MINIMAL -#include +#include int main(int argc, char *argv[]) { @@ -43,7 +42,7 @@ int main(int argc, char *argv[]) puts(""); - //free((void *)xxx); + free((void *)xxx); //const char *str = "ceci est un string de test!"; //char *str2 = malloc((strlen(str) + 3) * sizeof(char)); diff --git a/src/kaleid/include/kalassrt.h b/src/kaleid/include/kalassrt.h new file mode 100644 index 0000000..3a345f4 --- /dev/null +++ b/src/kaleid/include/kalassrt.h @@ -0,0 +1,82 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: Kaleid assert() support // +//----------------------------------------------------------------------------// + +#ifndef _KALASSRT_H +#define _KALASSRT_H + +//------------------------------------------// +// Useful macros // +//------------------------------------------// + +#ifndef noreturn +#define noreturn __attribute__((noreturn)) +#endif + +#ifndef unlikely(x) +#define unlikely(x) (__builtin_expect((x), 0)) +#endif + +//------------------------------------------// +// When debugging // +//------------------------------------------// + +#if !defined(_NO_DEBUG) && !defined(NDEBUG) && !defined(assert) + +// +// Failed assert handler +// +noreturn void _assert_handler(const char *, const char *, int, const char *); + +#define assert(x) \ + do { \ + if unlikely(!(x)) \ + _assert_handler(#x, __FILE__, __LINE__, __func__); \ + } while (0); + +// +// Aliases +// + +#ifndef Assert +#define Assert assert +#endif + +#ifndef DosAssert +#define DosAssert assert +#endif + +#ifndef KalAssert +#define KalAssert assert +#endif + +//------------------------------------------// +// When not debugging // +//------------------------------------------// + +#else + +#if !defined(NDEBUG) +# define NDEBUG 1 +#endif + +#if !defined(_NO_DEBUG) +# define _NO_DEBUG 1 +#endif + +#ifndef assert +#define assert(x) +#endif + +#endif + +//------------------------------------------// +// End of // +//------------------------------------------// + +#endif diff --git a/src/kaleid/include/kalcrt.h b/src/kaleid/include/kalcrt.h new file mode 100644 index 0000000..6c1fcd6 --- /dev/null +++ b/src/kaleid/include/kalcrt.h @@ -0,0 +1,102 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: Kaleid C runtime library // +//----------------------------------------------------------------------------// + +#ifndef _KALCRT_H +#define _KALCRT_H + +//------------------------------------------// +// Typedefs // +//------------------------------------------// + +#ifndef __size_t +#define __size_t +typedef unsigned long size_t; +#endif + +#ifndef __va_list +#define __va_list +typedef __builtin_va_list va_list; +#endif + +#ifndef __status_t +#define __status_t +typedef signed long status_t; +#endif + +//------------------------------------------// +// Macros // +//------------------------------------------// + +#ifndef _NO_MASK +#define _NO_MASK +#endif + +//------------------------------------------// +// va_list utilities // +//------------------------------------------// + +#ifndef va_start +#define va_start __builtin_va_start +#endif + +#ifndef va_next +#define va_next __builtin_va_next +#endif + +#ifndef va_end +#define va_end __builtin_va_end +#endif + +//------------------------------------------// +// Memory management utilities // +//------------------------------------------// + +#if !defined(memset) && !defined(_KALMASK_H) +# define memset memsetb +#endif +void *memsetb(void *, int, size_t); +void *memsetw(void *, int, size_t); +void *memsetd(void *, int, size_t); +void *memsetq(void *, long, size_t); + +void *memzero(void *, size_t); + +//------------------------------------------// +// String manipulation utilities // +//------------------------------------------// + +size_t strlen(const char *); +char *strcpy(char *, const char *); +char *strncpy(char *, const char *, size_t); +char *strrev(char *, const char *); +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 // +//------------------------------------------// + +char *itoa(int, char *, int); + +//------------------------------------------// +// Diverse utilities // +//------------------------------------------// + +const char *describe_status(status_t) _NO_MASK; + +//------------------------------------------// +// End of // +//------------------------------------------// + +#endif + diff --git a/src/kaleid/include/kaldefs.h b/src/kaleid/include/kaldefs.h new file mode 100644 index 0000000..d8dedb3 --- /dev/null +++ b/src/kaleid/include/kaldefs.h @@ -0,0 +1,105 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: Kaleid general preprocessor constants // +//----------------------------------------------------------------------------// + +#ifndef _KALDEFS_H +#define _KALDEFS_H + +//------------------------------------------// +// Actual constants // +//------------------------------------------// + +#ifndef TRUE +#define TRUE 1 +#endif + +#ifndef FALSE +#define FALSE 0 +#endif + +#ifndef NULL +#define NULL ((void *)0) +#endif + +#ifndef INITOK +#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 PACKED +#define PACKED __attribute__((packed)) +#endif + +#ifndef noreturn +#define noreturn __attribute__((noreturn)) +#endif + +#ifndef alignof +#define alignof _Alignof +#endif + +#ifndef likely +#define likely(x) (__builtin_expect((x), 1)) +#endif + +#ifndef unlikely(x) +#define unlikely(x) (__builtin_expect((x), 0)) +#endif + +//------------------------------------------// +// API specific macros // +//------------------------------------------// + +#ifndef KALAPI +# define KALAPI +#endif + +//------------------------------------------// +// Values for APIRET // +//------------------------------------------// + +#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 + +//------------------------------------------// +// End of // +//------------------------------------------// + +#endif diff --git a/src/kaleid/include/kaleid.h b/src/kaleid/include/kaleid.h new file mode 100644 index 0000000..80f9b7e --- /dev/null +++ b/src/kaleid/include/kaleid.h @@ -0,0 +1,51 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: Kaleid API main include file // +//----------------------------------------------------------------------------// + +#ifndef _KALEID_H +#define _KALEID_H + +//------------------------------------------// +// Building for OS/K // +//------------------------------------------// + +#if !defined(_OSK_SOURCE) +# if defined(_KALEID_KERNEL) || defined(_KALEID_SYSTEM) +# define _OSK_SOURCE 1 +# endif +#endif + +//------------------------------------------// +// Include common part of API // +//------------------------------------------// + +#ifndef _KALDEFS_H +#include +#endif + +#ifndef _KALTYPES_H +#include +#endif + +#ifndef _KALASSRT_H +#include +#endif + +#if defined(_KALMASK_NEEDED) && !defined(_KALMASK_H) +#include +#endif + +#ifndef _KALCRT_H +#include +#endif + +//------------------------------------------// +// End of // +//------------------------------------------// + +#endif diff --git a/src/kaleid/include/kalkern b/src/kaleid/include/kalkern new file mode 120000 index 0000000..195d388 --- /dev/null +++ b/src/kaleid/include/kalkern @@ -0,0 +1 @@ +../kernel \ No newline at end of file diff --git a/src/kaleid/include/kalkern.h b/src/kaleid/include/kalkern.h new file mode 100644 index 0000000..40f0625 --- /dev/null +++ b/src/kaleid/include/kalkern.h @@ -0,0 +1,37 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: Kaleid Kernel main include file // +//----------------------------------------------------------------------------// + +#ifndef _KALKERN_H +#define _KALKERN_H + +//------------------------------------------// +// Dependencies // +//------------------------------------------// + +#ifndef _KALEID_H +#include +#endif + +#ifndef _KALKERN_CONFIG_H +#include +#endif + +//------------------------------------------// +// Macros // +//------------------------------------------// + +#define DisableInterrupts() asm volatile ("cli") +#define EnableInterrupts() asm volatile ("sti") +#define HaltCPU() asm volatile ("hlt") + +//------------------------------------------// +// End of // +//------------------------------------------// + +#endif diff --git a/src/kaleid/include/kalmask.h b/src/kaleid/include/kalmask.h new file mode 100644 index 0000000..d54d761 --- /dev/null +++ b/src/kaleid/include/kalmask.h @@ -0,0 +1,46 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: Masks for the functions in the KCRL // +//----------------------------------------------------------------------------// + +#ifndef _KALMASK_H +#define _KALMASK_H + +//------------------------------------------// +// Not building for OS/K // +//------------------------------------------// +#ifndef _OSK_SOURCE + +//------------------------------------------// + +# define memcpy _osk_memcpy +# define memcmp _osk_memcmp +# define memzero _osk_memzero + +//------------------------------------------// + +# 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 + +//------------------------------------------// + +# define itoa _osk_itoa +# define atoi _osk_atoi + +//------------------------------------------// +// End of // +//------------------------------------------// + +#endif +#endif diff --git a/src/kaleid/include/kaltypes.h b/src/kaleid/include/kaltypes.h new file mode 100644 index 0000000..8f8294a --- /dev/null +++ b/src/kaleid/include/kaltypes.h @@ -0,0 +1,74 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: Kaleid C common types // +//----------------------------------------------------------------------------// + +#ifndef _KALTYPES_H +#define _KALTYPES_H + +//------------------------------------------// +// Basic integer types aliases // +//------------------------------------------// + +#ifndef __base_types_aliases +#define __base_types_aliases +typedef unsigned char uchar; +typedef unsigned short ushort; +typedef unsigned int uint; +typedef unsigned long ulong; +typedef signed long long llong; +typedef unsigned long long ullong; +typedef long double ldouble; +#endif + +//------------------------------------------// +// Other standard integer types // +//------------------------------------------// + +#ifndef __size_t +#define __size_t +typedef unsigned long size_t; +#endif + +#ifndef __ssize_t +#define __ssize_t +typedef signed long ssize_t; +#endif + +#ifndef __wchar_t +#define __wchar_t +typedef signed int wchar_t; +#endif + +#ifndef __off_t +#define __off_t +typedef unsigned long off_t; +#endif + +//------------------------------------------// +// Special types // +//------------------------------------------// + +#ifndef __va_list +#define __va_list +typedef __builtin_va_list va_list; +#endif + +#ifndef __status_t +#define __status_t +typedef signed long status_t; +#endif + +//------------------------------------------// +// Kaleid system types // +//------------------------------------------// + +//------------------------------------------// +// End of // +//------------------------------------------// + +#endif diff --git a/src/kaleid/kernel/config.h b/src/kaleid/kernel/config.h index 501be3d..6c43ff8 100644 --- a/src/kaleid/kernel/config.h +++ b/src/kaleid/kernel/config.h @@ -23,12 +23,12 @@ // // Enable/disable multiprocessor support // -#define MULTIPROCESSOR NO +#define MULTIPROCESSOR FALSE // // Enable/disable preemptivity // -#define PREEMPTIVE YES +#define PREEMPTIVE TRUE // // Size of a tabulation in spaces diff --git a/src/kaleid/kernel/init.c b/src/kaleid/kernel/init.c index e4d0450..3a7d1cd 100644 --- a/src/kaleid/kernel/init.c +++ b/src/kaleid/kernel/init.c @@ -7,26 +7,26 @@ // Desc: Kernel entry point // //----------------------------------------------------------------------------// -#include -#include -#include -#include +#include +#include +#include +#include // // Entry point of kaleid-kernel.elf // -void DosStartKern(void) +void StartKern(void) { // we're not ready to deal with interrupts - DosDisableInterrupts(); + DisableInterrupts(); // booting! - DosSetKernState(KSTATE_INIT); + SetKernState(KSTATE_INIT); // kernel terminals - DosInitTerms(); + InitTerms(); // we're out - DosPanic("Goodbye World :("); + StartPanic("Goodbye World :("); } diff --git a/src/kaleid/kernel/init.h b/src/kaleid/kernel/init.h index 40351c2..db03c33 100644 --- a/src/kaleid/kernel/init.h +++ b/src/kaleid/kernel/init.h @@ -10,12 +10,12 @@ #ifndef _KALKERN_INIT_H #define _KALKERN_INIT_H -#ifndef _KALCOMM_COMMON_H -#include +#ifndef _KALKERN_H +#include #endif // kernel entry point -void DosStartKern(void); +void StartKern(void); #endif diff --git a/src/kaleid/kernel/io/ports.c b/src/kaleid/kernel/io/ports.c index 4f5c8fe..3f44417 100644 --- a/src/kaleid/kernel/io/ports.c +++ b/src/kaleid/kernel/io/ports.c @@ -7,7 +7,7 @@ // Desc: Ports I/O // //----------------------------------------------------------------------------// -#include +#include diff --git a/src/kaleid/kernel/io/ports.h b/src/kaleid/kernel/io/ports.h index a92ddb6..10799a3 100644 --- a/src/kaleid/kernel/io/ports.h +++ b/src/kaleid/kernel/io/ports.h @@ -10,14 +10,14 @@ #ifndef _KALKERN_IO_PORTS_H #define _KALKERN_IO_PORTS_H -#ifndef _KALCOMM_COMMON_H -#include +#ifndef _KALKERN_H +#include #endif -#define DosWriteByteOnPort(port,val) asm volatile ("outb %1, %0" : : "dN" (port), "a" (value)) +#define WriteByteOnPort(port,val) asm volatile ("outb %1, %0" : : "dN" (port), "a" (value)) -uchar DosReadByteFromPort(port_t); -ushort DosReadWordFromPort(port_t); +uchar ReadByteFromPort(port_t); +ushort ReadWordFromPort(port_t); #endif diff --git a/src/kaleid/kernel/io/terminal.c b/src/kaleid/kernel/io/terminal.c index ce3ebd8..fe09e25 100644 --- a/src/kaleid/kernel/io/terminal.c +++ b/src/kaleid/kernel/io/terminal.c @@ -8,7 +8,7 @@ //----------------------------------------------------------------------------// #define _UNLOCKED_IO -#include +#include // // VGA-related macros @@ -44,31 +44,31 @@ terminal_t *stddbg; // // Initialize standard output // -void DosInitTerms(void) +void InitTerms(void) { - DosAssert(!stdout && _vga_term.kt_init != INITOK); + Assert(!stdout && _vga_term.kt_init != INITOK); _vga_term.kt_init = INITOK; stddbg = &_vga_term; // to be switched to VESA stdout = &_vga_term; - DosClearTerm(stdout); + ClearTerm(stdout); } // // Fill terminal with spaces // -status_t DosClearTerm(terminal_t *kt) +status_t ClearTerm(terminal_t *kt) { if (kt == NULL) return BAD_ARG_NULL; - DosAssert(kt->kt_init == INITOK); + Assert(kt->kt_init == INITOK); - DosLockTerm(kt); - DosClearTerm_Unlocked(kt); - DosUnlockTerm(kt); + LockTerm(kt); + ClearTerm_Unlocked(kt); + UnlockTerm(kt); return SUCCESS; } @@ -76,7 +76,7 @@ status_t DosClearTerm(terminal_t *kt) // // Change the color code // -status_t DosChTermColor(terminal_t *kt, uchar color) +status_t ChTermColor(terminal_t *kt, uchar color) { if (color > KTERM_COLOR_WHITE) return BAD_ARG_RANGE; @@ -84,9 +84,9 @@ status_t DosChTermColor(terminal_t *kt, uchar color) if (kt == NULL) return BAD_ARG_NULL; - DosLockTerm(kt); + LockTerm(kt); kt->kt_color = color; - DosUnlockTerm(kt); + UnlockTerm(kt); return SUCCESS; } @@ -94,16 +94,16 @@ status_t DosChTermColor(terminal_t *kt, uchar color) // // Write a single character on the terminal // -status_t DosPutOnTerm(terminal_t *kt, char ch) +status_t PutOnTerm(terminal_t *kt, char ch) { if (kt == NULL) return BAD_ARG_NULL; - DosAssert(kt->kt_init == INITOK); + Assert(kt->kt_init == INITOK); - DosLockTerm(kt); - DosPutOnTerm_Unlocked(kt, ch); - DosUnlockTerm(kt); + LockTerm(kt); + PutOnTerm_Unlocked(kt, ch); + UnlockTerm(kt); return SUCCESS; } @@ -111,18 +111,18 @@ status_t DosPutOnTerm(terminal_t *kt, char ch) // // Print string on terminal // -status_t DosPrintOnTerm(terminal_t *kt, const char *str) +status_t PrintOnTerm(terminal_t *kt, const char *str) { if (kt == NULL) return BAD_ARG_NULL; - DosAssert(kt->kt_init == INITOK); + Assert(kt->kt_init == INITOK); - DosLockTerm(kt); + LockTerm(kt); while (*str) { - DosPutOnTerm_Unlocked(kt, *str++); + PutOnTerm_Unlocked(kt, *str++); } - DosUnlockTerm(kt); + UnlockTerm(kt); return SUCCESS; } @@ -138,7 +138,7 @@ status_t DosPrintOnTerm(terminal_t *kt, const char *str) // Fill terminal with spaces (UNLOCKED version) // XXX would '\0' work too? // -void DosClearTerm_Unlocked(terminal_t *kt) +void ClearTerm_Unlocked(terminal_t *kt) { size_t i; @@ -156,7 +156,7 @@ void DosClearTerm_Unlocked(terminal_t *kt) // // Write a single character on the terminal (UNLOCKED version) // -void DosPutOnTerm_Unlocked(terminal_t *kt, char ch) +void PutOnTerm_Unlocked(terminal_t *kt, char ch) { int i; size_t prev_row; @@ -176,7 +176,7 @@ void DosPutOnTerm_Unlocked(terminal_t *kt, char ch) for (i = 0; i < TABSIZE; i++) { // tabulations can't spread over two lines if (kt->kt_curr_y == prev_row) { - DosPutOnTerm_Unlocked(kt, ' '); + PutOnTerm_Unlocked(kt, ' '); } } } @@ -200,10 +200,10 @@ void DosPutOnTerm_Unlocked(terminal_t *kt, char ch) // // Print string on terminal (UNLOCKED version) // -void DosPrintOnTerm_Unlocked(terminal_t *kt, const char *str) +void PrintOnTerm_Unlocked(terminal_t *kt, const char *str) { while (*str) { - DosPutOnTerm_Unlocked(kt, *str++); + PutOnTerm_Unlocked(kt, *str++); } } diff --git a/src/kaleid/kernel/io/terminal.h b/src/kaleid/kernel/io/terminal.h index 0826453..d7cc988 100644 --- a/src/kaleid/kernel/io/terminal.h +++ b/src/kaleid/kernel/io/terminal.h @@ -10,7 +10,7 @@ #ifndef _KALKERN_IO_KTERM_H #define _KALKERN_IO_KTERM_H -#include +#include // all available colors enum terminal_colors { @@ -42,28 +42,28 @@ 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); -status_t DosPrintOnTerm(terminal_t *, const char *); -status_t DosChTermColor(terminal_t *, uchar); +void InitTerms(void); +status_t ClearTerm(terminal_t *); +status_t PutOnTerm(terminal_t *, char); +status_t PrintOnTerm(terminal_t *, const char *); +status_t ChTermColor(terminal_t *, uchar); -#ifdef _UNLOCKED_IO -void DosClearTerm_Unlocked(terminal_t *); -void DosPutOnTerm_Unlocked(terminal_t *, char); -void DosPrintOnTerm_Unlocked(terminal_t *, const char *); -#define DosChTermColor_Unlocked(kt, col) ((kt)->kt_color = col) +#if defined(_UNLOCKED_IO) +void ClearTerm_Unlocked(terminal_t *); +void PutOnTerm_Unlocked(terminal_t *, char); +void PrintOnTerm_Unlocked(terminal_t *, const char *); +#define ChTermColor_Unlocked(kt, col) ((kt)->kt_color = col) #endif #ifndef _NO_DEBUG -# define DebugLog(...) DosPutOnTerm(stddbg, __VA_ARGS__) +# define DebugLog(...) PrintOnTerm(stddbg, __VA_ARGS__) #else # define DebugLog(...) #endif -#define DosLockTerm(kt) DosAquireLock(&kt->kt_lock) -#define DosUnlockTerm(kt) DosReleaseLock(&kt->kt_lock) -#define DosTryLockTerm(kt) DosAttemptLock(&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.c b/src/kaleid/kernel/ke/lock.c index 544bf93..465b76f 100644 --- a/src/kaleid/kernel/ke/lock.c +++ b/src/kaleid/kernel/ke/lock.c @@ -7,7 +7,7 @@ // Desc: Locks // //----------------------------------------------------------------------------// -#include +#include // nothing to do here diff --git a/src/kaleid/kernel/ke/lock.h b/src/kaleid/kernel/ke/lock.h index 1174c26..40482ec 100644 --- a/src/kaleid/kernel/ke/lock.h +++ b/src/kaleid/kernel/ke/lock.h @@ -10,8 +10,8 @@ #ifndef _KALKERN_KE_LOCK_H #define _KALKERN_KE_LOCK_H -#ifndef _KALCOMM_COMMON_H -#include +#ifndef _KALKERN_H +#include #endif enum lock_type { @@ -42,7 +42,7 @@ typedef struct { // // Initialize a lock // -#define DosInitLock(lk, type) \ +#define InitLock(lk, type) \ do { \ (lk)->lk_type = (type); \ (lk)->lk_lock = FALSE; \ @@ -59,40 +59,40 @@ typedef struct { // // Does nothing // -#define DosDestroyLock(lk) ((lk)->lk_init = FALSE) +#define DestroyLock(lk) ((lk)->lk_init = FALSE) // // Aquires the lock // Panics on double aquisition since that should never happen // until we have at least a basic scheduler // -#define DosAquireLock(lk) \ +#define AquireLock(lk) \ do { \ - DosDisableInterrupts(); \ - DosAssert((lk)->lk_init == INITOK); \ + DisableInterrupts(); \ + Assert((lk)->lk_init == INITOK); \ if ((lk)->lk_lock++) \ - DosPanic("DosAquireLock on an already locked object"); \ - DosEnableInterrupts(); \ + StartPanic("DosAquireLock on an already locked object"); \ + EnableInterrupts(); \ } while (FALSE); // // Releases an already aquired lock // Panics if the lock was never aquired (this will change) // -#define DosReleaseLock(lk) \ +#define ReleaseLock(lk) \ do { \ - DosDisableInterrupts(); \ - DosAssert((lk)->lk_init == INITOK); \ + DisableInterrupts(); \ + Assert((lk)->lk_init == INITOK); \ if ((lk)->lk_lock++) \ - DosPanic("DosReleaseLock on an unlocked object"); \ - DosEnableInterrupts(); \ + StartPanic("DosReleaseLock on an unlocked object"); \ + EnableInterrupts(); \ } while (FALSE); // // Tries to aquire lock // Doesn't work at all for obvious reasons // -#define DosAttemptLock(lk) ((lk)->lk_lock++) +#define AttemptLock(lk) ((lk)->lk_lock++) #endif diff --git a/src/kaleid/kernel/ke/panic.c b/src/kaleid/kernel/ke/panic.c index aaad786..888ac7b 100644 --- a/src/kaleid/kernel/ke/panic.c +++ b/src/kaleid/kernel/ke/panic.c @@ -7,11 +7,11 @@ // Desc: How NOT to panic 101 // //----------------------------------------------------------------------------// -#include -#include +#include +#include #define _UNLOCKED_IO -#include +#include // // Panic message @@ -22,47 +22,47 @@ const char *__panicmsg = NULL; // Failed assert() handler // noreturn void _assert_handler(const char *msg, - const char *file, - int line, - const char *func) + const char *file, + int line, + const char *func) { // not getting out of here - DosDisableInterrupts(); + DisableInterrupts(); (void)file; (void)line; (void)func; // XXX sprintf() to create a proper panicstr - DosPanic(msg); + StartPanic(msg); } // // Your best boy panic() // -void DosPanic(const char *str) +void StartPanic(const char *str) { - DosDisableInterrupts(); + DisableInterrupts(); - DosSetKernState(KSTATE_PANIC); + SetKernState(KSTATE_PANIC); - DosClearTerm_Unlocked(stdout); + ClearTerm_Unlocked(stdout); if (str == NULL) { str = "(no message given)"; } - if (DosGetPanicStr()) { - DosPrintOnTerm_Unlocked(stdout, "double panic!\n"); - DosHaltCPU(); + if (GetPanicStr()) { + PrintOnTerm_Unlocked(stdout, "double panic!\n"); + HaltCPU(); } - DosSetPanicStr(str); + SetPanicStr(str); // we cannot lock anything when panicking - DosPrintOnTerm_Unlocked(stdout, "panic! - "); - DosPrintOnTerm_Unlocked(stdout, str); + PrintOnTerm_Unlocked(stdout, "panic! - "); + PrintOnTerm_Unlocked(stdout, str); while (TRUE) { - DosHaltCPU(); + HaltCPU(); } } diff --git a/src/kaleid/kernel/ke/panic.h b/src/kaleid/kernel/ke/panic.h index 27a7753..372848e 100644 --- a/src/kaleid/kernel/ke/panic.h +++ b/src/kaleid/kernel/ke/panic.h @@ -10,15 +10,15 @@ #ifndef _KALKERN_KE_PANIC_H #define _KALKERN_KE_PANIC_H -#ifndef _KALCOMM_COMMON_H -#include +#ifndef _KALKERN_H +#include #endif -noreturn void DosPanic(const char *); -noreturn void DosCrashSystem(void); +noreturn void StartPanic(const char *); +noreturn void CrashSystem(void); extern const char *__panicmsg; -#define DosGetPanicStr() (__panicmsg) -#define DosSetPanicStr(str) (__panicmsg = (str)) +#define GetPanicStr() (__panicmsg) +#define SetPanicStr(str) (__panicmsg = (str)) #endif diff --git a/src/kaleid/kernel/ke/state.c b/src/kaleid/kernel/ke/state.c index fae844d..4d65f89 100644 --- a/src/kaleid/kernel/ke/state.c +++ b/src/kaleid/kernel/ke/state.c @@ -7,7 +7,7 @@ // Desc: Current kernel state // //----------------------------------------------------------------------------// -#include +#include // // Current kernel state diff --git a/src/kaleid/kernel/ke/state.h b/src/kaleid/kernel/ke/state.h index fe8e6b9..6f5de07 100644 --- a/src/kaleid/kernel/ke/state.h +++ b/src/kaleid/kernel/ke/state.h @@ -10,8 +10,8 @@ #ifndef _KALKERN_KE_STATE_H #define _KALKERN_KE_STATE_H -#ifndef _KALCOMM_COMMON_H -#include +#ifndef _KALKERN_H +#include #endif // XXX improve this @@ -30,8 +30,8 @@ enum kernel_states { }; extern uchar __kstate; -#define DosGetKernState() (__kstate) -#define DosSetKernState(x) (__kstate = (x)) +#define GetKernState() (__kstate) +#define SetKernState(x) (__kstate = (x)) #endif diff --git a/src/kaleid/kernel/mm/malloc.c b/src/kaleid/kernel/mm/malloc.c deleted file mode 100644 index 1ffa3c1..0000000 --- a/src/kaleid/kernel/mm/malloc.c +++ /dev/null @@ -1,12 +0,0 @@ -//----------------------------------------------------------------------------// -// GNU GPL OS/K // -// // -// Authors: spectral` // -// NeoX // -// // -// Desc: Memory allocation routines // -// Only exists to trigger Neox // -//----------------------------------------------------------------------------// - -#include - diff --git a/src/kaleid/kernel/mm/malloc.h b/src/kaleid/kernel/mm/malloc.h deleted file mode 100644 index 7d27929..0000000 --- a/src/kaleid/kernel/mm/malloc.h +++ /dev/null @@ -1,17 +0,0 @@ -//----------------------------------------------------------------------------// -// GNU GPL OS/K // -// // -// Authors: spectral` // -// NeoX // -// // -// Desc: Memory allocation routines // -// Only exists to trigger Neox // -//----------------------------------------------------------------------------// - -#ifndef _KALKERN_MM_MALLOC_H -#define _KALKERN_MM_MALLOC_H - -#include - -#endif - diff --git a/src/kernel.ld b/src/kernel.ld index d8fa35a..5768560 100644 --- a/src/kernel.ld +++ b/src/kernel.ld @@ -1,4 +1,4 @@ -ENTRY(DosStartKern) +ENTRY(StartKern) SECTIONS { . = 0x4000; /* XXX 0x4000 is temporary */ diff --git a/src/project-tree.txt b/src/project-tree.txt index f102785..e0e3f4d 100644 --- a/src/project-tree.txt +++ b/src/project-tree.txt @@ -31,6 +31,22 @@ src/ | + kaleid/ | | + | + include/ + | | | + | | - kaleid.h + | | - kaldefs.h + | | - kaltypes.h + | | - kalassrt.h + | | - kalmask.h + | | - kalcrt.h + | | | + | | - kalkern.h + | | | + | | ~ kalkern/ -> ../kernel/ + | | | + | | 0 + | | + | | | + kernel/ | | | | | x folder.desc @@ -53,43 +69,33 @@ src/ | | | | | + ke/ | | | | + | | | - lock.c + | | | - lock.h + | | | | | | | - panic.c | | | - panic.h | | | | + | | | - state.c + | | | - state.h + | | | | | | | 0 | | | | | 0 | | | + common/ | | | - | | x folder.desc + | | - status.c | | | - | | - common.h - | | - assert.h - | | - atomic.h - | | - status.h - | | - types.h + | | - string.c + | | - memory.c + | | - convert.c + | | - sprintf.c | | | - | | - string.h - | | - memory.h - | | - convert.h - | | | - | | + lib/ + | | + test/ | | | | - | | | - status.c - | | | | - | | | - string.c - | | | - memory.c - | | | - convert.c - | | | - sprintf.c + | | | - test-common.c | | | | | | | 0 | | 0 - | | - | + linux/ - | | | - | | - test-common.c - | | | - | | 0 | 0 0 From bea3e8a927ddb3cb2497e688b097eabac23f49f3 Mon Sep 17 00:00:00 2001 From: Julian Barathieu Date: Tue, 1 Jan 2019 17:11:30 +0100 Subject: [PATCH 16/28] Stuff, again --- src/Makefile | 20 +++-- src/kaleid/common/arith.c | 53 +++++++++++++ src/kaleid/common/memory.c | 16 +++- src/kaleid/common/rand.c | 1 + src/kaleid/common/test/test-common.c | 4 +- src/kaleid/common/test/test-file0.c | 23 ++++++ src/kaleid/include/kalassrt.h | 32 ++++---- src/kaleid/include/kalcrt.h | 107 +++++++++++++++++++++++++-- src/kaleid/include/kaldefs.h | 4 +- src/kaleid/include/kaleid.h | 10 ++- src/kaleid/include/kalmask.h | 77 ++++++++++++++----- src/kaleid/kernel/io/terminal.c | 19 ++--- src/kaleid/kernel/io/terminal.h | 8 +- src/kaleid/kernel/ke/panic.c | 8 +- 14 files changed, 305 insertions(+), 77 deletions(-) create mode 100644 src/kaleid/common/arith.c create mode 100644 src/kaleid/common/rand.c create mode 100644 src/kaleid/common/test/test-file0.c diff --git a/src/Makefile b/src/Makefile index 91253d1..5d173d2 100644 --- a/src/Makefile +++ b/src/Makefile @@ -67,21 +67,25 @@ LOBJDIR=$(OBJDIR)/$(LINXDIR) COMMDEPS=$(INCDIR)/kaleid.h $(INCDIR)/kaldefs.h $(INCDIR)/kaltypes.h \ $(INCDIR)/kalmask.h $(INCDIR)/kalmask.h $(INCDIR)/kalassrt.h -COMMSRCS=$(COMMDIR)/string.c $(COMMDIR)/status.c \ - $(COMMDIR)/convert.c $(COMMDIR)/memory.c +COMMSRCS=$(COMMDIR)/string.c $(COMMDIR)/status.c $(COMMDIR)/rand.c \ + $(COMMDIR)/convert.c $(COMMDIR)/memory.c $(COMMDIR)/arith.c -COMMOBJS=$(COBJDIR)/string.o $(COBJDIR)/status.o \ - $(COBJDIR)/convert.o $(COBJDIR)/memory.o +COMMOBJS=$(COBJDIR)/string.o $(COBJDIR)/status.o $(COBJDIR)/rand.o \ + $(COBJDIR)/convert.o $(COBJDIR)/memory.o $(COBJDIR)/arith.o common: $(COMMDEPS) $(COMMSRCS) - $(KCC) -c $(COMMDIR)/string.c -o $(COBJDIR)/string.o - $(KCC) -c $(COMMDIR)/status.c -o $(COBJDIR)/status.o - $(KCC) -c $(COMMDIR)/memory.c -o $(COBJDIR)/memory.o + $(KCC) -c $(COMMDIR)/rand.c -o $(COBJDIR)/rand.o + $(KCC) -c $(COMMDIR)/arith.c -o $(COBJDIR)/arith.o + $(KCC) -c $(COMMDIR)/string.c -o $(COBJDIR)/string.o + $(KCC) -c $(COMMDIR)/status.c -o $(COBJDIR)/status.o + $(KCC) -c $(COMMDIR)/memory.c -o $(COBJDIR)/memory.o $(KCC) -c $(COMMDIR)/convert.c -o $(COBJDIR)/convert.o CCC=$(CC2NAME) $(COPTIM) $(CWARNS) $(CINCLUDES) -test-common: $(COMMSRCS) +tests: $(COMMSRCS) + $(CCC) -c $(COMMDIR)/rand.c -o $(COBJDIR)/rand.o + $(CCC) -c $(COMMDIR)/arith.c -o $(COBJDIR)/arith.o $(CCC) -c $(COMMDIR)/string.c -o $(COBJDIR)/string.o $(CCC) -c $(COMMDIR)/status.c -o $(COBJDIR)/status.o $(CCC) -c $(COMMDIR)/memory.c -o $(COBJDIR)/memory.o diff --git a/src/kaleid/common/arith.c b/src/kaleid/common/arith.c new file mode 100644 index 0000000..1d3c740 --- /dev/null +++ b/src/kaleid/common/arith.c @@ -0,0 +1,53 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: Arithmetical functions // +//----------------------------------------------------------------------------// + +// do not mask anything +#define _KALMASK_H +#include + +int _osk_abs(int x) +{ + return abs(x); +} + +long _osk_labs(long x) +{ + return labs(x); +} + +int _osk_min(int x, int y) +{ + return min(x, y); +} + +long _osk_lmin(long x, long y) +{ + return lmin(x, y); +} + +int _osk_max(int x, int y) +{ + return max(x, y); +} + +long _osk_lmax(long x, long y) +{ + return lmax(x, y); +} + +div_t _osk_div(int x, int y) +{ + return div(x, y); +} + +ldiv_t _osk_ldiv(long x, long y) +{ + return ldiv(x, y); +} + diff --git a/src/kaleid/common/memory.c b/src/kaleid/common/memory.c index d9097eb..81c1785 100644 --- a/src/kaleid/common/memory.c +++ b/src/kaleid/common/memory.c @@ -23,7 +23,7 @@ static inline void *_memset_internal(void *ptr, ulong uval, size_t qwords) // aligned memory write for (n = 0; n < qwords; n++) { - *(uptr + n) = uval; + *uptr++ = uval; } return ptr; @@ -54,7 +54,7 @@ void *memset(void *ptr, int val, size_t bytes) _memset_internal(uptr, uval, qwords); - uptr += qwords * QWORD_SIZE; + uptr = (uchar *) ( (ulong)uptr / (qwords * QWORD_SIZE) ); bytes %= QWORD_SIZE; } @@ -113,6 +113,18 @@ void *memsetw(void *ptr, int val, size_t words) return ptr; } +// +// Set "dwords"-many dwords starting from ptr to val +// XXX unimplemented +// +void *memsetd(void *ptr, int val, size_t dwords) +{ + (void)val; + (void)dwords; + + return ptr; +} + // // Set "qwords"-many qwords starting from ptr to val // diff --git a/src/kaleid/common/rand.c b/src/kaleid/common/rand.c new file mode 100644 index 0000000..b413bbf --- /dev/null +++ b/src/kaleid/common/rand.c @@ -0,0 +1 @@ +int rand(void) { /*STUB*/ return 0; } diff --git a/src/kaleid/common/test/test-common.c b/src/kaleid/common/test/test-common.c index c63735b..a528a2e 100644 --- a/src/kaleid/common/test/test-common.c +++ b/src/kaleid/common/test/test-common.c @@ -10,7 +10,7 @@ #include #include -#include +void *_osk_memsetw(void *, int, long); int main(int argc, char *argv[]) { @@ -32,7 +32,7 @@ int main(int argc, char *argv[]) short *xxx = (short *)malloc(sizex * sizeof(short)); //printf("%ld\n",(ulong)xxx%8); //memzero(xxx, sizex); - memsetw(xxx, 300, sizex); + _osk_memsetw(xxx, 300, sizex); size_t it; for (it = 0; it < sizex; it++) { diff --git a/src/kaleid/common/test/test-file0.c b/src/kaleid/common/test/test-file0.c new file mode 100644 index 0000000..0cff677 --- /dev/null +++ b/src/kaleid/common/test/test-file0.c @@ -0,0 +1,23 @@ +// random test file + +#include + +int main(int argc, char *argv[]) +{ + long x[4]; + long *ptr = &x[0]; + + printf("%p\n", ptr); + + ptr++; + printf("%p\n", ptr); + + ptr = ptr + 1; + printf("%p\n", ptr); + + ptr = (long *)((long)ptr + 1); + printf("%p\n", ptr); + + return 0; +} + diff --git a/src/kaleid/include/kalassrt.h b/src/kaleid/include/kalassrt.h index 3a345f4..0e1d103 100644 --- a/src/kaleid/include/kalassrt.h +++ b/src/kaleid/include/kalassrt.h @@ -11,11 +11,11 @@ #define _KALASSRT_H //------------------------------------------// -// Useful macros // +// Macros // //------------------------------------------// #ifndef noreturn -#define noreturn __attribute__((noreturn)) +#define noreturn __attribute__((__noreturn__)) #endif #ifndef unlikely(x) @@ -39,22 +39,6 @@ noreturn void _assert_handler(const char *, const char *, int, const char *); _assert_handler(#x, __FILE__, __LINE__, __func__); \ } while (0); -// -// Aliases -// - -#ifndef Assert -#define Assert assert -#endif - -#ifndef DosAssert -#define DosAssert assert -#endif - -#ifndef KalAssert -#define KalAssert assert -#endif - //------------------------------------------// // When not debugging // //------------------------------------------// @@ -75,6 +59,18 @@ noreturn void _assert_handler(const char *, const char *, int, const char *); #endif +//------------------------------------------// +// Aliases for assert() // +//------------------------------------------// + +#ifndef Assert +#define Assert assert +#endif + +#ifndef KalAssert +#define KalAssert assert +#endif + //------------------------------------------// // End of // //------------------------------------------// diff --git a/src/kaleid/include/kalcrt.h b/src/kaleid/include/kalcrt.h index 6c1fcd6..33791a8 100644 --- a/src/kaleid/include/kalcrt.h +++ b/src/kaleid/include/kalcrt.h @@ -19,14 +19,24 @@ typedef unsigned long size_t; #endif +#ifndef __status_t +#define __status_t +typedef signed long status_t; +#endif + #ifndef __va_list #define __va_list typedef __builtin_va_list va_list; #endif -#ifndef __status_t -#define __status_t -typedef signed long status_t; +#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 //------------------------------------------// @@ -45,6 +55,10 @@ typedef signed long status_t; #define va_start __builtin_va_start #endif +#ifndef va_arg +#define va_arg __builtin_va_arg +#endif + #ifndef va_next #define va_next __builtin_va_next #endif @@ -57,15 +71,29 @@ typedef signed long status_t; // Memory management utilities // //------------------------------------------// -#if !defined(memset) && !defined(_KALMASK_H) -# define memset memsetb +#ifndef memset +#define memset memsetb #endif + +#ifndef memchr +#define memchr memchrb +#endif + void *memsetb(void *, int, size_t); void *memsetw(void *, int, size_t); void *memsetd(void *, int, size_t); void *memsetq(void *, long, size_t); +void *memchrb(const void *, int, size_t); +void *memchrw(const void *, int, size_t); +void *memchrd(const void *, int, size_t); +void *memchrq(const void *, long, size_t); + +void *memcpy(void *, const void *, size_t); +void *memmove(void *, const void *, size_t); + void *memzero(void *, size_t); +int memcmp(const void *, const void *, size_t); //------------------------------------------// // String manipulation utilities // @@ -86,7 +114,24 @@ int vsnprintf(char *, size_t, const char *, va_list); // Type conversion utilities // //------------------------------------------// -char *itoa(int, char *, int); +int *atoi(const char *); +long *atol(const char *); + +char *itoa(int, char *, int); +char *ltoa(long, char *, int); + +char *utoa(unsigned int, char *, int); +char *ultoa(unsigned long, char *, int); + +long strtol(const char *, char **, int); +unsigned long strtoul(const char *, char **, int); + +//------------------------------------------// +// RNG utilities // +//------------------------------------------// + +int rand(void); +void srand(unsigned int); //------------------------------------------// // Diverse utilities // @@ -94,6 +139,56 @@ char *itoa(int, char *, int); const char *describe_status(status_t) _NO_MASK; +//------------------------------------------// +// Arithmetical macros // +//------------------------------------------// + +#ifndef abs +#define abs(x) ((x) < 0 ? -x : x) +#endif + +#ifndef labs +#define labs(x) ((x) < 0 ? -x : x) +#endif + +#ifndef min +#define min(x,y) ((x) < (y) ? (x) : (y)) +#endif + +#ifndef lmin +#define lmin(x,y) ((x) < (y) ? (x) : (y)) +#endif + +#ifndef max +#define max(x,y) ((x) < (y) ? (x) : (y)) +#endif + +#ifndef lmax +#define lmax(x,y) ((x) < (y) ? (x) : (y)) +#endif + +#ifndef __div +#define __div +static inline div_t div(int __x, int __y) +{ + div_t __res; + __res.quot = __x/__y; + __res.rem = __x%__y; + return __res; +} +#endif + +#ifndef __ldiv +#define __ldiv +static inline ldiv_t ldiv(long __x, long __y) +{ + ldiv_t __res; + __res.quot = __x/__y; + __res.rem = __x%__y; + return __res; +} +#endif + //------------------------------------------// // End of // //------------------------------------------// diff --git a/src/kaleid/include/kaldefs.h b/src/kaleid/include/kaldefs.h index d8dedb3..b17c1cc 100644 --- a/src/kaleid/include/kaldefs.h +++ b/src/kaleid/include/kaldefs.h @@ -51,11 +51,11 @@ //------------------------------------------// #ifndef PACKED -#define PACKED __attribute__((packed)) +#define PACKED __attribute__((__packed__)) #endif #ifndef noreturn -#define noreturn __attribute__((noreturn)) +#define noreturn __attribute__((__noreturn__)) #endif #ifndef alignof diff --git a/src/kaleid/include/kaleid.h b/src/kaleid/include/kaleid.h index 80f9b7e..64de82f 100644 --- a/src/kaleid/include/kaleid.h +++ b/src/kaleid/include/kaleid.h @@ -20,6 +20,12 @@ # endif #endif +#ifndef _OSK_SOURCE +# ifndef _KALMASK_H +# include +# endif +#endif + //------------------------------------------// // Include common part of API // //------------------------------------------// @@ -36,10 +42,6 @@ #include #endif -#if defined(_KALMASK_NEEDED) && !defined(_KALMASK_H) -#include -#endif - #ifndef _KALCRT_H #include #endif diff --git a/src/kaleid/include/kalmask.h b/src/kaleid/include/kalmask.h index d54d761..078163a 100644 --- a/src/kaleid/include/kalmask.h +++ b/src/kaleid/include/kalmask.h @@ -11,36 +11,77 @@ #define _KALMASK_H //------------------------------------------// -// Not building for OS/K // -//------------------------------------------// -#ifndef _OSK_SOURCE + +#define memset _osk_memsetb +#define memchr _osk_memchrb + +#define memsetb _osk_memsetb +#define memsetw _osk_memsetw +#define memsetd _osk_memsetd +#define memsetq _osk_memsetq + +#define memchrb _osk_memchrb +#define memchrw _osk_memchrw +#define memchrd _osk_memchrd +#define memchrq _osk_memchrq + +#define memcpy _osk_memcpy +#define memmove _osk_memmove + +#define memcmp _osk_memcmp +#define memzero _osk_memzero //------------------------------------------// -# define memcpy _osk_memcpy -# define memcmp _osk_memcmp -# define memzero _osk_memzero +#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 //------------------------------------------// -# 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 +#define atoi _osk_atoi +#define atol _osk_atol + +#define itoa _osk_itoa +#define ltoa _osk_ltoa + +#define utoa _osk_utoa +#define ultoa _osk_ultoa + +#define strtol _osk_strtol +#define strtoul _osk_strtoul //------------------------------------------// -# define itoa _osk_itoa -# define atoi _osk_atoi +#define rand _osk_rand +#define srand _osk_srand + +//------------------------------------------// + +#define abs _osk_abs +#define labs _osk_labs + +#define min _osk_min +#define lmin _osk_lmin + +#define max _osk_max +#define lmax _osk_lmax + +#define __div +#define __ldiv + +#define div _osk_div +#define ldiv _osk_ldiv //------------------------------------------// // End of // //------------------------------------------// #endif -#endif diff --git a/src/kaleid/kernel/io/terminal.c b/src/kaleid/kernel/io/terminal.c index fe09e25..dbf5963 100644 --- a/src/kaleid/kernel/io/terminal.c +++ b/src/kaleid/kernel/io/terminal.c @@ -67,7 +67,7 @@ status_t ClearTerm(terminal_t *kt) Assert(kt->kt_init == INITOK); LockTerm(kt); - ClearTerm_Unlocked(kt); + ClearTermUnlocked(kt); UnlockTerm(kt); return SUCCESS; @@ -102,7 +102,7 @@ status_t PutOnTerm(terminal_t *kt, char ch) Assert(kt->kt_init == INITOK); LockTerm(kt); - PutOnTerm_Unlocked(kt, ch); + PutOnTermUnlocked(kt, ch); UnlockTerm(kt); return SUCCESS; @@ -120,7 +120,7 @@ status_t PrintOnTerm(terminal_t *kt, const char *str) LockTerm(kt); while (*str) { - PutOnTerm_Unlocked(kt, *str++); + PutOnTermUnlocked(kt, *str++); } UnlockTerm(kt); @@ -138,7 +138,7 @@ status_t PrintOnTerm(terminal_t *kt, const char *str) // Fill terminal with spaces (UNLOCKED version) // XXX would '\0' work too? // -void ClearTerm_Unlocked(terminal_t *kt) +void ClearTermUnlocked(terminal_t *kt) { size_t i; @@ -156,7 +156,7 @@ void ClearTerm_Unlocked(terminal_t *kt) // // Write a single character on the terminal (UNLOCKED version) // -void PutOnTerm_Unlocked(terminal_t *kt, char ch) +void PutOnTermUnlocked(terminal_t *kt, char ch) { int i; size_t prev_row; @@ -169,19 +169,20 @@ void PutOnTerm_Unlocked(terminal_t *kt, char ch) // later in this function we actually do the line feed else if (ch == '\n') { kt->kt_curr_y = kt->kt_width - 1; } - // tabulations account for 4 spaces + // tabulations account for "TABSIZE" spaces else if (ch == '\t') { prev_row = kt->kt_curr_y; // compiler will optimize this away for (i = 0; i < TABSIZE; i++) { // tabulations can't spread over two lines if (kt->kt_curr_y == prev_row) { - PutOnTerm_Unlocked(kt, ' '); + PutOnTermUnlocked(kt, ' '); } } } else { + // actually write on the buffer const size_t offset = ComputeOffset(kt, kt->kt_curr_x, kt->kt_curr_y); kt->kt_buffer[offset] = ComputeEntry(ch, kt->kt_color); } @@ -200,10 +201,10 @@ void PutOnTerm_Unlocked(terminal_t *kt, char ch) // // Print string on terminal (UNLOCKED version) // -void PrintOnTerm_Unlocked(terminal_t *kt, const char *str) +void PrintOnTermUnlocked(terminal_t *kt, const char *str) { while (*str) { - PutOnTerm_Unlocked(kt, *str++); + PutOnTermUnlocked(kt, *str++); } } diff --git a/src/kaleid/kernel/io/terminal.h b/src/kaleid/kernel/io/terminal.h index d7cc988..42f8f90 100644 --- a/src/kaleid/kernel/io/terminal.h +++ b/src/kaleid/kernel/io/terminal.h @@ -49,10 +49,10 @@ status_t PrintOnTerm(terminal_t *, const char *); status_t ChTermColor(terminal_t *, uchar); #if defined(_UNLOCKED_IO) -void ClearTerm_Unlocked(terminal_t *); -void PutOnTerm_Unlocked(terminal_t *, char); -void PrintOnTerm_Unlocked(terminal_t *, const char *); -#define ChTermColor_Unlocked(kt, col) ((kt)->kt_color = col) +void ClearTermUnlocked(terminal_t *); +void PutOnTermUnlocked(terminal_t *, char); +void PrintOnTermUnlocked(terminal_t *, const char *); +#define ChTermColorUnlocked(kt, col) ((kt)->kt_color = col) #endif #ifndef _NO_DEBUG diff --git a/src/kaleid/kernel/ke/panic.c b/src/kaleid/kernel/ke/panic.c index 888ac7b..72fa83e 100644 --- a/src/kaleid/kernel/ke/panic.c +++ b/src/kaleid/kernel/ke/panic.c @@ -44,22 +44,22 @@ void StartPanic(const char *str) SetKernState(KSTATE_PANIC); - ClearTerm_Unlocked(stdout); + ClearTermUnlocked(stdout); if (str == NULL) { str = "(no message given)"; } if (GetPanicStr()) { - PrintOnTerm_Unlocked(stdout, "double panic!\n"); + PrintOnTermUnlocked(stdout, "double panic!\n"); HaltCPU(); } SetPanicStr(str); // we cannot lock anything when panicking - PrintOnTerm_Unlocked(stdout, "panic! - "); - PrintOnTerm_Unlocked(stdout, str); + PrintOnTermUnlocked(stdout, "panic! - "); + PrintOnTermUnlocked(stdout, str); while (TRUE) { HaltCPU(); From 5c84ba8b68a175b8b9d11a70e69fe05d860a5c78 Mon Sep 17 00:00:00 2001 From: Julian Barathieu Date: Tue, 1 Jan 2019 17:37:58 +0100 Subject: [PATCH 17/28] Convert stuff --- src/Makefile | 21 +++++++++++++---- src/kaleid/common/convert.c | 34 ++++++++++++++++++++++++++-- src/kaleid/common/test/test-common.c | 14 ++++++++++-- src/kaleid/include/kalassrt.h | 8 +++---- src/kaleid/include/kaleid.h | 2 +- 5 files changed, 65 insertions(+), 14 deletions(-) diff --git a/src/Makefile b/src/Makefile index 5d173d2..e87a049 100644 --- a/src/Makefile +++ b/src/Makefile @@ -71,25 +71,36 @@ COMMSRCS=$(COMMDIR)/string.c $(COMMDIR)/status.c $(COMMDIR)/rand.c \ $(COMMDIR)/convert.c $(COMMDIR)/memory.c $(COMMDIR)/arith.c COMMOBJS=$(COBJDIR)/string.o $(COBJDIR)/status.o $(COBJDIR)/rand.o \ - $(COBJDIR)/convert.o $(COBJDIR)/memory.o $(COBJDIR)/arith.o + $(COBJDIR)/memory.o $(COBJDIR)/arith.o \ + $(COBJDIR)/itoa.o $(COBJDIR)/ltoa.o $(COBJDIR)/utoa.o $(COBJDIR)/ultoa.o -common: $(COMMDEPS) $(COMMSRCS) +comm-convert: + $(KCC) -c $(COMMDIR)/convert.c -D_NEED_ITOA -o $(COBJDIR)/itoa.o + $(KCC) -c $(COMMDIR)/convert.c -D_NEED_LTOA -o $(COBJDIR)/ltoa.o + $(KCC) -c $(COMMDIR)/convert.c -D_NEED_UTOA -o $(COBJDIR)/utoa.o + $(KCC) -c $(COMMDIR)/convert.c -D_NEED_ULTOA -o $(COBJDIR)/ultoa.o + +common: $(COMMDEPS) $(COMMSRCS) comm-convert $(KCC) -c $(COMMDIR)/rand.c -o $(COBJDIR)/rand.o $(KCC) -c $(COMMDIR)/arith.c -o $(COBJDIR)/arith.o $(KCC) -c $(COMMDIR)/string.c -o $(COBJDIR)/string.o $(KCC) -c $(COMMDIR)/status.c -o $(COBJDIR)/status.o $(KCC) -c $(COMMDIR)/memory.c -o $(COBJDIR)/memory.o - $(KCC) -c $(COMMDIR)/convert.c -o $(COBJDIR)/convert.o CCC=$(CC2NAME) $(COPTIM) $(CWARNS) $(CINCLUDES) -tests: $(COMMSRCS) +tests-comm-convert: + $(CCC) -c $(COMMDIR)/convert.c -D_NEED_ITOA -o $(COBJDIR)/itoa.o + $(CCC) -c $(COMMDIR)/convert.c -D_NEED_LTOA -o $(COBJDIR)/ltoa.o + $(CCC) -c $(COMMDIR)/convert.c -D_NEED_UTOA -o $(COBJDIR)/utoa.o + $(CCC) -c $(COMMDIR)/convert.c -D_NEED_ULTOA -o $(COBJDIR)/ultoa.o + +tests: $(COMMSRCS) tests-comm-convert $(CCC) -c $(COMMDIR)/rand.c -o $(COBJDIR)/rand.o $(CCC) -c $(COMMDIR)/arith.c -o $(COBJDIR)/arith.o $(CCC) -c $(COMMDIR)/string.c -o $(COBJDIR)/string.o $(CCC) -c $(COMMDIR)/status.c -o $(COBJDIR)/status.o $(CCC) -c $(COMMDIR)/memory.c -o $(COBJDIR)/memory.o - $(CCC) -c $(COMMDIR)/convert.c -o $(COBJDIR)/convert.o $(CCC) -c $(LINXDIR)/test-common.c -o $(LOBJDIR)/test-common.o $(CCC) $(COMMOBJS) $(LOBJDIR)/test-common.o -o $(BINDIR)/kaleid-common.elf diff --git a/src/kaleid/common/convert.c b/src/kaleid/common/convert.c index 61e63bf..19c9bbe 100644 --- a/src/kaleid/common/convert.c +++ b/src/kaleid/common/convert.c @@ -15,24 +15,51 @@ static const char digits[36] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; +#if defined(_NEED_UTOA) || defined(_NEED_ULTOA) +#define _S unsigned +#else +#define _S +#endif + +#if defined (_NEED_ITOA) || defined(_NEED_UTOA) +#define _T int +#else +#define _T long +#endif + // // Integer to string in any base between 2 and 36 (included) // +#if defined(_NEED_ITOA) char *itoa(int i, char *str, int base) +#elif defined(_NEED_LTOA) +char *ltoa(long i, char *str, int base) +#elif defined(_NEED_UTOA) +char *utoa(uint i, char *str, int base) +#elif defined(_NEED_ULTOA) +char *ultoa(ulong i, char *str, int base) +#else +#error "What am I supposed to declare?" +#endif { +#if defined(_NEED_ITOA) || defined(_NEED_LTOA) int neg = 0; +#endif + char *orig = str; if (base < 2 || base > 36) return NULL; - + +#if defined(_NEED_ITOA) || defined(_NEED_LTOA) // deal with negatives if (i < 0) { neg = 1; i = -i; } +#endif - // deal with zero separatly + // deal with zero separately if (i == 0) { *str++ = '0'; } @@ -43,7 +70,10 @@ char *itoa(int i, char *str, int base) i /= base; } +#if defined(_NEED_ITOA) || defined(_NEED_LTOA) if (neg) *str++ = '-'; +#endif + *str = '\0'; return reverse(orig); diff --git a/src/kaleid/common/test/test-common.c b/src/kaleid/common/test/test-common.c index a528a2e..e4df713 100644 --- a/src/kaleid/common/test/test-common.c +++ b/src/kaleid/common/test/test-common.c @@ -11,6 +11,10 @@ #include void *_osk_memsetw(void *, int, long); +char *_osk_itoa(int, char *, int); +char *_osk_ltoa(long, char *, int); +char *_osk_utoa(unsigned int, char *, int); +char *_osk_ultoa(unsigned long, char *, int); int main(int argc, char *argv[]) { @@ -27,7 +31,8 @@ int main(int argc, char *argv[]) //const size_t size1 = strlen(test1); //char *test2 = malloc(size1); //char *test3 = malloc(size1); - + +#if 0 const size_t sizex = 130; short *xxx = (short *)malloc(sizex * sizeof(short)); //printf("%ld\n",(ulong)xxx%8); @@ -39,10 +44,15 @@ int main(int argc, char *argv[]) short s = *(xxx + it); printf("%hd", s); } + free((void *)xxx); +#endif + + char buf[256]; + + puts(_osk_ultoa(5000000000, buf, 10)); puts(""); - free((void *)xxx); //const char *str = "ceci est un string de test!"; //char *str2 = malloc((strlen(str) + 3) * sizeof(char)); diff --git a/src/kaleid/include/kalassrt.h b/src/kaleid/include/kalassrt.h index 0e1d103..3c99b2d 100644 --- a/src/kaleid/include/kalassrt.h +++ b/src/kaleid/include/kalassrt.h @@ -45,12 +45,12 @@ noreturn void _assert_handler(const char *, const char *, int, const char *); #else -#if !defined(NDEBUG) -# define NDEBUG 1 +#ifndef NDEBUG +#define NDEBUG 1 #endif -#if !defined(_NO_DEBUG) -# define _NO_DEBUG 1 +#ifndef _NO_DEBUG +#define _NO_DEBUG 1 #endif #ifndef assert diff --git a/src/kaleid/include/kaleid.h b/src/kaleid/include/kaleid.h index 64de82f..a46f317 100644 --- a/src/kaleid/include/kaleid.h +++ b/src/kaleid/include/kaleid.h @@ -20,7 +20,7 @@ # endif #endif -#ifndef _OSK_SOURCE +#if !defined(_OSK_SOURCE) # ifndef _KALMASK_H # include # endif From 452771f8baa8045d670ed7def35036c396384701 Mon Sep 17 00:00:00 2001 From: Julian Barathieu Date: Tue, 1 Jan 2019 17:40:48 +0100 Subject: [PATCH 18/28] Most minor stuff so far --- src/kaleid/include/kalcrt.h | 54 ++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/src/kaleid/include/kalcrt.h b/src/kaleid/include/kalcrt.h index 33791a8..bc46aa1 100644 --- a/src/kaleid/include/kalcrt.h +++ b/src/kaleid/include/kalcrt.h @@ -79,49 +79,49 @@ typedef struct { long quot, rem; } ldiv_t; #define memchr memchrb #endif -void *memsetb(void *, int, size_t); -void *memsetw(void *, int, size_t); -void *memsetd(void *, int, size_t); -void *memsetq(void *, long, size_t); +void *memsetb(void *, int, size_t); +void *memsetw(void *, int, size_t); +void *memsetd(void *, int, size_t); +void *memsetq(void *, long, size_t); -void *memchrb(const void *, int, size_t); -void *memchrw(const void *, int, size_t); -void *memchrd(const void *, int, size_t); -void *memchrq(const void *, long, size_t); +void *memchrb(const void *, int, size_t); +void *memchrw(const void *, int, size_t); +void *memchrd(const void *, int, size_t); +void *memchrq(const void *, long, size_t); -void *memcpy(void *, const void *, size_t); -void *memmove(void *, const void *, size_t); +void *memcpy(void *, const void *, size_t); +void *memmove(void *, const void *, size_t); -void *memzero(void *, size_t); -int memcmp(const void *, const void *, size_t); +void *memzero(void *, size_t); +int memcmp(const void *, const void *, size_t); //------------------------------------------// // String manipulation utilities // //------------------------------------------// -size_t strlen(const char *); -char *strcpy(char *, const char *); -char *strncpy(char *, const char *, size_t); -char *strrev(char *, const char *); -char *reverse(char *); +size_t strlen(const char *); +char *strcpy(char *, const char *); +char *strncpy(char *, const char *, size_t); +char *strrev(char *, const char *); +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); +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 // //------------------------------------------// -int *atoi(const char *); -long *atol(const char *); +int *atoi(const char *); +long *atol(const char *); -char *itoa(int, char *, int); -char *ltoa(long, char *, int); +char *itoa(int, char *, int); +char *ltoa(long, char *, int); -char *utoa(unsigned int, char *, int); -char *ultoa(unsigned long, char *, int); +char *utoa(unsigned int, char *, int); +char *ultoa(unsigned long, char *, int); long strtol(const char *, char **, int); unsigned long strtoul(const char *, char **, int); From b04ead6130b7d207a2f1f8ea9776ccc59d6115d8 Mon Sep 17 00:00:00 2001 From: Julian Barathieu Date: Tue, 1 Jan 2019 20:46:06 +0100 Subject: [PATCH 19/28] Limits stuff --- src/kaleid/common/memory.c | 1 + src/kaleid/common/rand.c | 36 +++++++++- src/kaleid/common/test/test-file0.c | 5 ++ src/kaleid/include/kaldefs.h | 26 ++------ src/kaleid/include/kallims.h | 100 ++++++++++++++++++++++++++++ src/kaleid/include/kaltypes.h | 20 ++++-- src/kaleid/kernel/io/terminal.h | 8 +-- src/kaleid/kernel/ke/lock.h | 2 +- 8 files changed, 167 insertions(+), 31 deletions(-) create mode 100644 src/kaleid/include/kallims.h 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, From 5938aa9cfb2e5390d38058b8b370d9319228860d Mon Sep 17 00:00:00 2001 From: Julian Barathieu Date: Wed, 2 Jan 2019 14:51:40 +0100 Subject: [PATCH 20/28] Better mem*() stuff --- src/kaleid/common/convert.c | 13 ---- src/kaleid/common/memory.c | 137 +++++++++++++++++++++++------------ src/kaleid/common/memsub.c | 37 ---------- src/kaleid/include/kallims.h | 16 ++++ 4 files changed, 105 insertions(+), 98 deletions(-) delete mode 100644 src/kaleid/common/memsub.c diff --git a/src/kaleid/common/convert.c b/src/kaleid/common/convert.c index 19c9bbe..c18765c 100644 --- a/src/kaleid/common/convert.c +++ b/src/kaleid/common/convert.c @@ -14,19 +14,6 @@ // static const char digits[36] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - -#if defined(_NEED_UTOA) || defined(_NEED_ULTOA) -#define _S unsigned -#else -#define _S -#endif - -#if defined (_NEED_ITOA) || defined(_NEED_UTOA) -#define _T int -#else -#define _T long -#endif - // // Integer to string in any base between 2 and 36 (included) // diff --git a/src/kaleid/common/memory.c b/src/kaleid/common/memory.c index 2ccf2e8..c88bd43 100644 --- a/src/kaleid/common/memory.c +++ b/src/kaleid/common/memory.c @@ -14,49 +14,34 @@ // memset() family // //------------------------------------------// -// -// Set "qwords"-many aligned qwords starting from ptr to val -// -static inline void *_memset_internal(void *ptr, ulong uval, size_t qwords) -{ - size_t n; - ulong *uptr = (ulong *)ptr; - - // aligned memory write - for (n = 0; n < qwords; n++) { - *uptr++ = uval; - } - - return ptr; -} - // // Set "bytes"-many bytes starting from ptr to val // -void *memset(void *ptr, int val, size_t bytes) +void *memsetb(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 (((ulong)uptr % QWORD_ALIGN) > 0 && bytes--) { *uptr++ = (uchar)val; } - // move qword by qword - if (qwords) { + // we're qword-aligned now + if (bytes > QWORD_SIZE) { const ulong uval = ((ulong)val << 56) | ((ulong)val << 48) | ((ulong)val << 40) | ((ulong)val << 32) | ((ulong)val << 24) | ((ulong)val << 16) | ((ulong)val << 8) | ((ulong)val); - _memset_internal(uptr, uval, qwords); + ulong *uqptr = (ulong *)ptr; - uptr = (uchar *) ( (ulong)uptr / (qwords * QWORD_SIZE) ); - bytes %= QWORD_SIZE; + // move qword by qword + while (bytes > QWORD_SIZE) { + *uqptr++ = uval; + bytes -= QWORD_SIZE; + } + + uptr = (uchar *)(ulong)uqptr; } // deal with what's left @@ -74,10 +59,7 @@ void *memsetw(void *ptr, int val, size_t words) { ushort *uptr = (ushort *)ptr; - // get rid of everything after the first word - val = val & 0xFFFF; - - // can we do this an aligned way? + // can't we do this an aligned way? if unlikely (((ulong)uptr % WORD_ALIGN) > 0) { // no, we can't align ourselves while (words--) { @@ -93,17 +75,20 @@ void *memsetw(void *ptr, int val, size_t words) *uptr++ = (ushort)val; } - const size_t qwords = (words * WORD_SIZE)/QWORD_SIZE; - - // move qword by qword - if (qwords) { + // we're aligned for sure + if (words > QWORDS_TO_WORDS(1)) { const ulong uval = ((ulong)val << 48) | ((ulong)val << 32) | ((ulong)val << 16) | ((ulong)val); - _memset_internal(uptr, uval, qwords); + ulong *uqptr = (ulong *)uptr; + + // move qword by qword + while (words > QWORDS_TO_WORDS(1)) { + words -= QWORDS_TO_WORDS(1); + *uqptr++ = uval; + } - uptr += qwords * QWORD_SIZE / WORD_SIZE; - words %= QWORD_SIZE / WORD_SIZE; + uptr = (ushort *)(ulong)uqptr; } // deal with what's left @@ -131,23 +116,79 @@ void *memsetd(void *ptr, int val, size_t dwords) // void *memsetq(void *ptr, long val, size_t qwords) { - return _memset_internal(ptr, (ulong)val, qwords); + ulong *uptr = (ulong *)ptr; + + while (qwords--) *uptr++ = (ulong)val; + + return ptr; } // // Set "bytes"-many bytes starting from ptr to 0 +// +// WARNING +// Assume "bytes" is large, for small sizes +// use memset(ptr, 0, bytes) directly // void *memzero(void *ptr, size_t bytes) { - // is direct aligned access possible? (is "unlikely" good here?) - if unlikely (bytes % QWORD_SIZE && (ulong)ptr % QWORD_ALIGN) { - return _memset_internal(ptr, (ulong)0, bytes/QWORD_SIZE); - } - - if unlikely (bytes % WORD_SIZE && (ulong)ptr % WORD_ALIGN) { - return memsetw(ptr, (int)0, bytes/WORD_SIZE); - } - - return memset(ptr, 0, bytes); + return memsetb(ptr, 0, bytes); +} + + +// +// Copy "bytes"-many bytes of src to dst +// Does not deal with overlapping blocks (memmove's job) +// +void *memcpy(void *dst, const void *src, size_t bytes) +{ + const ulong *usrc = (const ulong *)src; + ulong *udst = (ulong *)dst; + + if unlikely (bytes == 0) return dst; + + // can we align them both at once? + if unlikely ((ulong)src % WORD_ALIGN == 1 + && (ulong)dst % WORD_ALIGN == 1) { + const uchar *ubsrc = (const uchar *)usrc; + uchar *ubdst = (uchar *)udst; + + *ubdst++ = *ubsrc++; + bytes--; + + udst = (ulong *)ubdst; + usrc = (ulong *)ubsrc; + } + + const ushort *uwsrc = (const ushort *)usrc; + ushort *uwdst = (ushort *)udst; + + // align either dst or src for qword access + while ((ulong)dst % QWORD_ALIGN > 0 + && (ulong)src % QWORD_ALIGN > 0 + && bytes > WORD_SIZE) { + + *uwdst++ = *uwsrc++; + bytes -= WORD_SIZE; + } + + udst = (ulong *)uwdst; + usrc = (ulong *)uwsrc; + + // should be most of the job + while (bytes > QWORD_SIZE) { + *udst++ = *usrc++; + bytes -= QWORD_SIZE; + } + + const uchar *ubsrc = (const uchar *)usrc; + ushort *ubdst = (ushort *)udst; + + // deal with what's left + while (bytes--) { + *ubdst ++ = *ubsrc++; + } + + return dst; } diff --git a/src/kaleid/common/memsub.c b/src/kaleid/common/memsub.c deleted file mode 100644 index 247c4d3..0000000 --- a/src/kaleid/common/memsub.c +++ /dev/null @@ -1,37 +0,0 @@ -//----------------------------------------------------------------------------// -// GNU GPL OS/K // -// // -// Authors: spectral` // -// NeoX // -// // -// Desc: mem*() functions, suboptimal edition // -//----------------------------------------------------------------------------// - -#include - -// -// 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; -} - -// -// 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; -} - - diff --git a/src/kaleid/include/kallims.h b/src/kaleid/include/kallims.h index 57ba2fa..ac5b158 100644 --- a/src/kaleid/include/kallims.h +++ b/src/kaleid/include/kallims.h @@ -41,6 +41,22 @@ # define LONG_BIT QWORD_BIT #endif +#ifndef DATA_SHIFTS_BLOCK +#define DATA_SHIFTS_BLOCK +# define BYTES_TO_WORDS(B) ((B) >> 1) +# define BYTES_TO_DWORDS(B) ((B) >> 2) +# define BYTES_TO_QWORDS(B) ((B) >> 3) +# define WORDS_TO_BYTES(W) ((W) << 1) +# define WORDS_TO_DWORDS(W) ((W) >> 1) +# define WORDS_TO_QWORDS(W) ((W) >> 2) +# define DWORDS_TO_BYTES(D) ((D) << 2) +# define DWORDS_TO_WORDS(D) ((D) << 1) +# define DWORDS_TO_QWORDS(D) ((D) >> 1) +# define QWORDS_TO_BYTES(Q) ((Q) << 3) +# define QWORDS_TO_WORDS(Q) ((Q) << 2) +# define QWORDS_TO_DWORDS(Q) ((Q) << 1) +#endif + //------------------------------------------// // Numeric data limits // //------------------------------------------// From 7dc4f77a8a57f64fa1a417e8dfbd912234cc5448 Mon Sep 17 00:00:00 2001 From: Julian Barathieu Date: Wed, 2 Jan 2019 16:27:12 +0100 Subject: [PATCH 21/28] Evil stuff --- src/Makefile | 134 +++++-------------------------------- src/Makefile.in | 107 ++++++++++++++++++++++++++++++ src/idttool.py | 14 ++++ src/kaleid/Makefile.old | 142 ++++++++++++++++++++++++++++++++++++++++ src/preproc.h | 33 ++++++++++ 5 files changed, 311 insertions(+), 119 deletions(-) create mode 100644 src/Makefile.in create mode 100644 src/idttool.py create mode 100644 src/kaleid/Makefile.old create mode 100644 src/preproc.h diff --git a/src/Makefile b/src/Makefile index e87a049..5a4d5c5 100644 --- a/src/Makefile +++ b/src/Makefile @@ -7,125 +7,21 @@ # Desc: Project Makefile # #----------------------------------------------------------------------------# -CCNAME="/opt/cross-cc/bin/x86_64-elf-gcc" -CC2NAME=gcc -COPTIM=-O2 -CLDSCR=-T kernel.ld -CWARNS=-pedantic -Wall -Wextra -Werror -CINCLUDES=-isystem./kaleid/include -CDEFINES= +kernel: + cpp ./Makefile.in > Makefile.out + python ./idttool.py + make kernel -f Makefile.out.2 + rm Makefile.out Makefile.out.2 -CFLAGS1=-nostdlib -ffreestanding -mcmodel=large -CFLAGS2=-mno-red-zone -mno-mmx -mno-sse -mno-sse2 -CFLAGS=$(CFLAGS1) $(CFLAGS2) +kernel-asm: + cpp -D_TO_ASM ./Makefile.in > Makefile.out + python ./idttool.py + make kernel -f Makefile.out.2 + rm Makefile.out Makefile.out.2 -CC=$(CCNAME) $(COPTIM) $(CWARNS) $(CFLAGS) $(CDEFINES) $(CINCLUDES) -KCC=$(CC) -D_OSK_SOURCE -D_KALEID_KERNEL - -ASM=nasm -ASMFLAGS= -BOOTFLAGS=-f bin - -BINDIR=../bin -OBJDIR=../obj - -BOOTDIR=boot -COMMDIR=kaleid/common -KERNDIR=kaleid/kernel -SYSTDIR=kaleid/system -LINXDIR=kaleid/common/test -INCDIR=kaleid/include - -all: bootloader kernel - -boot.mbr.s: $(BOOTDIR)/mbr.s $(BOOTDIR)/mbr.inc - $(ASM) $(BOOTFLAGS) $(BOOTDIR)/mbr.s -o $(OBJDIR)/boot/mbr.bin - -boot.loader.s: $(BOOTDIR)/loader.s - $(ASM) $(BOOTFLAGS) $(BOOTDIR)/loader.s -o $(OBJDIR)/boot/loader.bin - -bootloader: boot.mbr.s boot.loader.s - cp $(OBJDIR)/boot/mbr.bin $(BINDIR)/mbr.bin - cp $(OBJDIR)/boot/loader.bin $(BINDIR)/loader.bin - -#----------------------------------------------------------------------------# -# TESTING MAKEFILE - -pseudo_kern: - $(ASM) $(BOOTFLAGS) $(BOOTDIR)/pseudo_kernel.s -o $(OBJDIR)/boot/pkernel.bin - -testing: bootloader pseudo_kern - cat $(BINDIR)/bootloader.bin $(OBJDIR)/boot/pkernel.bin > $(BINDIR)/boot.bin - -#----------------------------------------------------------------------------# -# COMMON MAKEFILE - -COBJDIR=$(OBJDIR)/$(COMMDIR) -LOBJDIR=$(OBJDIR)/$(LINXDIR) - -#COMMDEPS=$(COMMDIR)/common.h $(COMMDIR)/stdlib.h $(KERNDIR)/config.h -COMMDEPS=$(INCDIR)/kaleid.h $(INCDIR)/kaldefs.h $(INCDIR)/kaltypes.h \ - $(INCDIR)/kalmask.h $(INCDIR)/kalmask.h $(INCDIR)/kalassrt.h - -COMMSRCS=$(COMMDIR)/string.c $(COMMDIR)/status.c $(COMMDIR)/rand.c \ - $(COMMDIR)/convert.c $(COMMDIR)/memory.c $(COMMDIR)/arith.c - -COMMOBJS=$(COBJDIR)/string.o $(COBJDIR)/status.o $(COBJDIR)/rand.o \ - $(COBJDIR)/memory.o $(COBJDIR)/arith.o \ - $(COBJDIR)/itoa.o $(COBJDIR)/ltoa.o $(COBJDIR)/utoa.o $(COBJDIR)/ultoa.o - -comm-convert: - $(KCC) -c $(COMMDIR)/convert.c -D_NEED_ITOA -o $(COBJDIR)/itoa.o - $(KCC) -c $(COMMDIR)/convert.c -D_NEED_LTOA -o $(COBJDIR)/ltoa.o - $(KCC) -c $(COMMDIR)/convert.c -D_NEED_UTOA -o $(COBJDIR)/utoa.o - $(KCC) -c $(COMMDIR)/convert.c -D_NEED_ULTOA -o $(COBJDIR)/ultoa.o - -common: $(COMMDEPS) $(COMMSRCS) comm-convert - $(KCC) -c $(COMMDIR)/rand.c -o $(COBJDIR)/rand.o - $(KCC) -c $(COMMDIR)/arith.c -o $(COBJDIR)/arith.o - $(KCC) -c $(COMMDIR)/string.c -o $(COBJDIR)/string.o - $(KCC) -c $(COMMDIR)/status.c -o $(COBJDIR)/status.o - $(KCC) -c $(COMMDIR)/memory.c -o $(COBJDIR)/memory.o - -CCC=$(CC2NAME) $(COPTIM) $(CWARNS) $(CINCLUDES) - -tests-comm-convert: - $(CCC) -c $(COMMDIR)/convert.c -D_NEED_ITOA -o $(COBJDIR)/itoa.o - $(CCC) -c $(COMMDIR)/convert.c -D_NEED_LTOA -o $(COBJDIR)/ltoa.o - $(CCC) -c $(COMMDIR)/convert.c -D_NEED_UTOA -o $(COBJDIR)/utoa.o - $(CCC) -c $(COMMDIR)/convert.c -D_NEED_ULTOA -o $(COBJDIR)/ultoa.o - -tests: $(COMMSRCS) tests-comm-convert - $(CCC) -c $(COMMDIR)/rand.c -o $(COBJDIR)/rand.o - $(CCC) -c $(COMMDIR)/arith.c -o $(COBJDIR)/arith.o - $(CCC) -c $(COMMDIR)/string.c -o $(COBJDIR)/string.o - $(CCC) -c $(COMMDIR)/status.c -o $(COBJDIR)/status.o - $(CCC) -c $(COMMDIR)/memory.c -o $(COBJDIR)/memory.o - $(CCC) -c $(LINXDIR)/test-common.c -o $(LOBJDIR)/test-common.o - $(CCC) $(COMMOBJS) $(LOBJDIR)/test-common.o -o $(BINDIR)/kaleid-common.elf - -#----------------------------------------------------------------------------# -# KERNEL MAKEFILE - -KOBJDIR=$(OBJDIR)/$(KERNDIR) - -KERNDEPS=common $(KERNDIR)/init.h $(KERNDIR)/io/terminal.h $(KERNDIR)/ke/lock.h \ - $(KERNDIR)/io/ports.h $(KERNDIR)/ke/panic.h $(KERNDIR)/ke/state.h - -KERNSRCS=$(KERNDIR)/init.c $(KERNDIR)/io/terminal.c $(KERNDIR)/ke/lock.c \ - $(KERNDIR)/io/ports.c $(KERNDIR)/ke/panic.c $(KERNDIR)/ke/state.c - -KERNOBJS=$(KOBJDIR)/init.o $(KOBJDIR)/io/terminal.o $(KOBJDIR)/ke/lock.o \ - $(KOBJDIR)/io/ports.o $(KOBJDIR)/ke/panic.o $(KOBJDIR)/ke/state.o - -kernel: common $(KERNSRCS) - $(KCC) -c $(KERNDIR)/init.c -o $(KOBJDIR)/init.o - $(KCC) -c $(KERNDIR)/ke/lock.c -o $(KOBJDIR)/ke/lock.o - $(KCC) -c $(KERNDIR)/ke/state.c -o $(KOBJDIR)/ke/state.o - $(KCC) -c $(KERNDIR)/ke/panic.c -o $(KOBJDIR)/ke/panic.o - $(KCC) -c $(KERNDIR)/io/ports.c -o $(KOBJDIR)/io/ports.o - $(KCC) -c $(KERNDIR)/io/terminal.c -o $(KOBJDIR)/io/terminal.o - $(KCC) $(CLDSCR) $(COMMOBJS) $(KERNOBJS) -o $(BINDIR)/kaleid-kernel.elf - -#----------------------------------------------------------------------------# +tests: + cpp -D_TESTS ./Makefile.in > Makefile.out + python ./idttool.py + make tests -f Makefile.out.2 + rm Makefile.out Makefile.out.2 diff --git a/src/Makefile.in b/src/Makefile.in new file mode 100644 index 0000000..12bdd68 --- /dev/null +++ b/src/Makefile.in @@ -0,0 +1,107 @@ +//----------------------------------------------------------------------------# +// GNU GPL OS/K # +// # +// Authors: spectral` # +// NeoX # +// # +// Desc: Project Makefile # +//----------------------------------------------------------------------------# + +// The madman's Makefile +#include "preproc.h" + +CCNAME="/opt/cross-cc/bin/x86_64-elf-gcc" +CC2NAME=gcc +COPTIM=-O2 +CLDSCR=-T kernel.ld +CWARNS=-pedantic -Wall -Wextra -Werror +CINCLUDES=-isystem./kaleid/include +CDEFINES= + +CFLAGS1=-nostdlib -ffreestanding -mcmodel=large +CFLAGS2=-mno-red-zone -mno-mmx -mno-sse -mno-sse2 +CFLAGS=$(CFLAGS1) $(CFLAGS2) $(SFLAG) + +CC=$(CCNAME) $(COPTIM) $(CWARNS) $(CFLAGS) $(CDEFINES) $(CINCLUDES) + +ASM=nasm +ASMFLAGS= +BOOTFLAGS=-f bin + +BINDIR=../bin +OBJDIR=../obj + +BOOTDIR=boot +COMMDIR=kaleid/common +KERNDIR=kaleid/kernel +SYSTDIR=kaleid/system +LINXDIR=kaleid/common/test +INCDIR=kaleid/include + +all: bootloader kernel + +boot.mbr.s: $(BOOTDIR)/mbr.s $(BOOTDIR)/mbr.inc + $(ASM) $(BOOTFLAGS) $(BOOTDIR)/mbr.s -o $(OBJDIR)/boot/mbr.bin + +boot.loader.s: $(BOOTDIR)/loader.s + $(ASM) $(BOOTFLAGS) $(BOOTDIR)/loader.s -o $(OBJDIR)/boot/loader.bin + +bootloader: boot.mbr.s boot.loader.s + cp $(OBJDIR)/boot/mbr.bin $(BINDIR)/mbr.bin + cp $(OBJDIR)/boot/loader.bin $(BINDIR)/loader.bin + +//----------------------------------------------------------------------------# +// TESTING MAKEFILE + +pseudo_kern: + $(ASM) $(BOOTFLAGS) $(BOOTDIR)/pseudo_kernel.s -o $(OBJDIR)/boot/pkernel.bin + +testing: bootloader pseudo_kern + cat $(BINDIR)/bootloader.bin $(OBJDIR)/boot/pkernel.bin > $(BINDIR)/boot.bin + +//----------------------------------------------------------------------------# +// COMMON MAKEFILE + +COBJDIR=$(OBJDIR)/$(COMMDIR) +LOBJDIR=$(OBJDIR)/$(LINXDIR) + +COMMOBJS=COBJ5(string,status,rand,memory,arith) COBJ4(itoa,ltoa,utoa,ultoa) + +TCC=$(CC2NAME) $(COPTIM) $(CWARNS) $(CINCLUDES) +KCC=$(CC) -D_OSK_SOURCE -D_KALEID_KERNEL + +comm-convert: + COMPILE_CONVRT(itoa) -D_NEED_ITOA + COMPILE_CONVRT(ltoa) -D_NEED_LTOA + COMPILE_CONVRT(utoa) -D_NEED_UTOA + COMPILE_CONVRT(ultoa) -D_NEED_ULTOA + +common: comm-convert + COMPILE_COMMON(rand) + COMPILE_COMMON(arith) + COMPILE_COMMON(string) + COMPILE_COMMON(status) + COMPILE_COMMON(memory) + +tests: common + $(TCC) -c $(LINXDIR)/test-common.c -o $(LOBJDIR)/test-common.o + $(TCC) $(COMMOBJS) $(LOBJDIR)/test-common.o -o $(BINDIR)/kaleid-common.elf + +//----------------------------------------------------------------------------# +// KERNEL MAKEFILE + +KOBJDIR=$(OBJDIR)/$(KERNDIR) + +KERNOBJS=KOBJ5(init,ke/lock,ke/panic,ke/state,io/ports) KOBJ1(io/terminal) + +kernel: common + COMPILE_KERNEL(init) + COMPILE_KERNEL(ke/lock) + COMPILE_KERNEL(ke/state) + COMPILE_KERNEL(ke/panic) + COMPILE_KERNEL(io/ports) + COMPILE_KERNEL(io/terminal) + LINK_KERNEL(kaleid-kernel.elf) + +//----------------------------------------------------------------------------# + diff --git a/src/idttool.py b/src/idttool.py new file mode 100644 index 0000000..90dfa0e --- /dev/null +++ b/src/idttool.py @@ -0,0 +1,14 @@ +# don't mind this file + +f1 = open("Makefile.out", "r+") +f2 = open("Makefile.out.2", "w+") + +fl = f1.readlines() +for ln in fl: + if ln[0] == ' ' and ln[1] != ' ': + f2.write('\t') + f2.write(ln) + +f1.close() +f2.close() + diff --git a/src/kaleid/Makefile.old b/src/kaleid/Makefile.old new file mode 100644 index 0000000..d3ce7ff --- /dev/null +++ b/src/kaleid/Makefile.old @@ -0,0 +1,142 @@ +#----------------------------------------------------------------------------# +# GNU GPL OS/K # +# # +# Authors: spectral` # +# NeoX # +# # +# Desc: Project Makefile # +#----------------------------------------------------------------------------# + +CCNAME="/opt/cross-cc/bin/x86_64-elf-gcc" +CC2NAME=gcc +COPTIM=-O2 +CLDSCR=-T kernel.ld +CWARNS=-pedantic -Wall -Wextra -Werror +CINCLUDES=-isystem./kaleid/include +CDEFINES= + +# set to -S to produce assembly +# (will be stored in the .o) +# (will also generate errors, but don't mind them) +SFLAG=-S + +CFLAGS1=-nostdlib -ffreestanding -mcmodel=large +CFLAGS2=-mno-red-zone -mno-mmx -mno-sse -mno-sse2 +CFLAGS=$(CFLAGS1) $(CFLAGS2) $(SFLAG) + +CC=$(CCNAME) $(COPTIM) $(CWARNS) $(CFLAGS) $(CDEFINES) $(CINCLUDES) +KCC=$(CC) -D_OSK_SOURCE -D_KALEID_KERNEL + +ASM=nasm +ASMFLAGS= +BOOTFLAGS=-f bin + +BINDIR=../bin +OBJDIR=../obj + +BOOTDIR=boot +COMMDIR=kaleid/common +KERNDIR=kaleid/kernel +SYSTDIR=kaleid/system +LINXDIR=kaleid/common/test +INCDIR=kaleid/include + +all: bootloader kernel + +boot.mbr.s: $(BOOTDIR)/mbr.s $(BOOTDIR)/mbr.inc + $(ASM) $(BOOTFLAGS) $(BOOTDIR)/mbr.s -o $(OBJDIR)/boot/mbr.bin + +boot.loader.s: $(BOOTDIR)/loader.s + $(ASM) $(BOOTFLAGS) $(BOOTDIR)/loader.s -o $(OBJDIR)/boot/loader.bin + +bootloader: boot.mbr.s boot.loader.s + cp $(OBJDIR)/boot/mbr.bin $(BINDIR)/mbr.bin + cp $(OBJDIR)/boot/loader.bin $(BINDIR)/loader.bin + +#----------------------------------------------------------------------------# +# TESTING MAKEFILE + +pseudo_kern: + $(ASM) $(BOOTFLAGS) $(BOOTDIR)/pseudo_kernel.s -o $(OBJDIR)/boot/pkernel.bin + +testing: bootloader pseudo_kern + cat $(BINDIR)/bootloader.bin $(OBJDIR)/boot/pkernel.bin > $(BINDIR)/boot.bin + +#----------------------------------------------------------------------------# +# COMMON MAKEFILE + +COBJDIR=$(OBJDIR)/$(COMMDIR) +LOBJDIR=$(OBJDIR)/$(LINXDIR) + +#COMMDEPS=$(COMMDIR)/common.h $(COMMDIR)/stdlib.h $(KERNDIR)/config.h +COMMDEPS=$(INCDIR)/kaleid.h $(INCDIR)/kaldefs.h $(INCDIR)/kaltypes.h \ + $(INCDIR)/kalmask.h $(INCDIR)/kalmask.h $(INCDIR)/kalassrt.h + +COMMSRCS=$(COMMDIR)/string.c $(COMMDIR)/status.c $(COMMDIR)/rand.c \ + $(COMMDIR)/convert.c $(COMMDIR)/memory.c $(COMMDIR)/arith.c + +COMMOBJS=$(COBJDIR)/string.o $(COBJDIR)/status.o $(COBJDIR)/rand.o \ + $(COBJDIR)/memory.o $(COBJDIR)/arith.o \ + $(COBJDIR)/itoa.o $(COBJDIR)/ltoa.o $(COBJDIR)/utoa.o $(COBJDIR)/ultoa.o + +comm-convert: + $(KCC) -c $(COMMDIR)/convert.c -D_NEED_ITOA -o $(COBJDIR)/itoa.o + $(KCC) -c $(COMMDIR)/convert.c -D_NEED_LTOA -o $(COBJDIR)/ltoa.o + $(KCC) -c $(COMMDIR)/convert.c -D_NEED_UTOA -o $(COBJDIR)/utoa.o + $(KCC) -c $(COMMDIR)/convert.c -D_NEED_ULTOA -o $(COBJDIR)/ultoa.o + +common: $(COMMDEPS) $(COMMSRCS) comm-convert + $(KCC) -c $(COMMDIR)/rand.c -o $(COBJDIR)/rand.o + $(KCC) -c $(COMMDIR)/arith.c -o $(COBJDIR)/arith.o + $(KCC) -c $(COMMDIR)/string.c -o $(COBJDIR)/string.o + $(KCC) -c $(COMMDIR)/status.c -o $(COBJDIR)/status.o + $(KCC) -c $(COMMDIR)/memory.c -o $(COBJDIR)/memory.o + +CCC=$(CC2NAME) $(COPTIM) $(CWARNS) $(CINCLUDES) + +tests-comm-convert: + $(CCC) -c $(COMMDIR)/convert.c -D_NEED_ITOA -o $(COBJDIR)/itoa.o + $(CCC) -c $(COMMDIR)/convert.c -D_NEED_LTOA -o $(COBJDIR)/ltoa.o + $(CCC) -c $(COMMDIR)/convert.c -D_NEED_UTOA -o $(COBJDIR)/utoa.o + $(CCC) -c $(COMMDIR)/convert.c -D_NEED_ULTOA -o $(COBJDIR)/ultoa.o + +tests: $(COMMSRCS) tests-comm-convert + $(CCC) -c $(COMMDIR)/rand.c -o $(COBJDIR)/rand.o + $(CCC) -c $(COMMDIR)/arith.c -o $(COBJDIR)/arith.o + $(CCC) -c $(COMMDIR)/string.c -o $(COBJDIR)/string.o + $(CCC) -c $(COMMDIR)/status.c -o $(COBJDIR)/status.o + $(CCC) -c $(COMMDIR)/memory.c -o $(COBJDIR)/memory.o + $(CCC) -c $(LINXDIR)/test-common.c -o $(LOBJDIR)/test-common.o + $(CCC) $(COMMOBJS) $(LOBJDIR)/test-common.o -o $(BINDIR)/kaleid-common.elf + +#----------------------------------------------------------------------------# +# KERNEL MAKEFILE + +KOBJDIR=$(OBJDIR)/$(KERNDIR) + +KERNDEPS=common $(KERNDIR)/init.h $(KERNDIR)/io/terminal.h $(KERNDIR)/ke/lock.h \ + $(KERNDIR)/io/ports.h $(KERNDIR)/ke/panic.h $(KERNDIR)/ke/state.h + +KERNSRCS=$(KERNDIR)/init.c $(KERNDIR)/io/terminal.c $(KERNDIR)/ke/lock.c \ + $(KERNDIR)/io/ports.c $(KERNDIR)/ke/panic.c $(KERNDIR)/ke/state.c + +KERNOBJS=$(KOBJDIR)/init.o $(KOBJDIR)/io/terminal.o $(KOBJDIR)/ke/lock.o \ + $(KOBJDIR)/io/ports.o $(KOBJDIR)/ke/panic.o $(KOBJDIR)/ke/state.o + +kernel: common $(KERNSRCS) + $(KCC) -c $(KERNDIR)/init.c -o $(KOBJDIR)/init.o + $(KCC) -c $(KERNDIR)/ke/lock.c -o $(KOBJDIR)/ke/lock.o + $(KCC) -c $(KERNDIR)/ke/state.c -o $(KOBJDIR)/ke/state.o + $(KCC) -c $(KERNDIR)/ke/panic.c -o $(KOBJDIR)/ke/panic.o + $(KCC) -c $(KERNDIR)/io/ports.c -o $(KOBJDIR)/io/ports.o + $(KCC) -c $(KERNDIR)/io/terminal.c -o $(KOBJDIR)/io/terminal.o + $(KCC) $(CLDSCR) $(COMMOBJS) $(KERNOBJS) -o $(BINDIR)/kaleid-kernel.elf + +#----------------------------------------------------------------------------# + +.PHONY: clean + +clean: + +#----------------------------------------------------------------------------# + diff --git a/src/preproc.h b/src/preproc.h new file mode 100644 index 0000000..265f9ee --- /dev/null +++ b/src/preproc.h @@ -0,0 +1,33 @@ +// be careful with this file + +#ifdef _TESTS +# define CCC TCC +#else +# define CCC KCC +#endif + +#ifdef _TO_ASM +# define _CSPREF -S +# define _OUTFIX S +# define LINK_KERNEL(out) +#else +# define _CSPREF -c +# define _OUTFIX o +# define LINK_KERNEL(out) $(KCC) $(CLDSCR) $(COMMOBJS) $(KERNOBJS) -o $(BINDIR)/out +#endif + +#define COMPILE_CONVRT(file) $(CCC) _CSPREF $(COMMDIR)/convert.c -o $(COBJDIR)/file._OUTFIX +#define COMPILE_COMMON(file) $(CCC) _CSPREF $(COMMDIR)/file.c -o $(COBJDIR)/file._OUTFIX +#define COMPILE_KERNEL(file) $(KCC) _CSPREF $(KERNDIR)/file.c -o $(KOBJDIR)/file._OUTFIX + +#define COBJ1(x1) $(COBJDIR)/x1.o +#define COBJ2(x1,x2) $(COBJDIR)/x1.o $(COBJDIR)/x2.o +#define COBJ3(x1,x2,x3) $(COBJDIR)/x1.o $(COBJDIR)/x2.o $(COBJDIR)/x3 +#define COBJ4(x1,x2,x3,x4) $(COBJDIR)/x1.o $(COBJDIR)/x2.o $(COBJDIR)/x3.o $(COBJDIR)/x4.o +#define COBJ5(x1,x2,x3,x4,x5) $(COBJDIR)/x1.o $(COBJDIR)/x2.o $(COBJDIR)/x3.o $(COBJDIR)/x4.o $(COBJDIR)/x5.o + +#define KOBJ1(x1) $(KOBJDIR)/x1.o +#define KOBJ2(x1,x2) $(KOBJDIR)/x1.o $(KOBJDIR)/x2.o +#define KOBJ3(x1,x2,x3) $(KOBJDIR)/x1.o $(KOBJDIR)/x2.o $(KOBJDIR)/x3 +#define KOBJ4(x1,x2,x3,x4) $(KOBJDIR)/x1.o $(KOBJDIR)/x2.o $(KOBJDIR)/x3.o $(KOBJDIR)/x4.o +#define KOBJ5(x1,x2,x3,x4,x5) $(KOBJDIR)/x1.o $(KOBJDIR)/x2.o $(KOBJDIR)/x3.o $(KOBJDIR)/x4.o $(KOBJDIR)/x5.o From c501d2196e1bed3f10f3c45d512090d9aa0d50d3 Mon Sep 17 00:00:00 2001 From: Julian Barathieu Date: Wed, 2 Jan 2019 16:28:13 +0100 Subject: [PATCH 22/28] Oops stuff --- src/kaleid/Makefile.old | 142 ---------------------------------------- 1 file changed, 142 deletions(-) delete mode 100644 src/kaleid/Makefile.old diff --git a/src/kaleid/Makefile.old b/src/kaleid/Makefile.old deleted file mode 100644 index d3ce7ff..0000000 --- a/src/kaleid/Makefile.old +++ /dev/null @@ -1,142 +0,0 @@ -#----------------------------------------------------------------------------# -# GNU GPL OS/K # -# # -# Authors: spectral` # -# NeoX # -# # -# Desc: Project Makefile # -#----------------------------------------------------------------------------# - -CCNAME="/opt/cross-cc/bin/x86_64-elf-gcc" -CC2NAME=gcc -COPTIM=-O2 -CLDSCR=-T kernel.ld -CWARNS=-pedantic -Wall -Wextra -Werror -CINCLUDES=-isystem./kaleid/include -CDEFINES= - -# set to -S to produce assembly -# (will be stored in the .o) -# (will also generate errors, but don't mind them) -SFLAG=-S - -CFLAGS1=-nostdlib -ffreestanding -mcmodel=large -CFLAGS2=-mno-red-zone -mno-mmx -mno-sse -mno-sse2 -CFLAGS=$(CFLAGS1) $(CFLAGS2) $(SFLAG) - -CC=$(CCNAME) $(COPTIM) $(CWARNS) $(CFLAGS) $(CDEFINES) $(CINCLUDES) -KCC=$(CC) -D_OSK_SOURCE -D_KALEID_KERNEL - -ASM=nasm -ASMFLAGS= -BOOTFLAGS=-f bin - -BINDIR=../bin -OBJDIR=../obj - -BOOTDIR=boot -COMMDIR=kaleid/common -KERNDIR=kaleid/kernel -SYSTDIR=kaleid/system -LINXDIR=kaleid/common/test -INCDIR=kaleid/include - -all: bootloader kernel - -boot.mbr.s: $(BOOTDIR)/mbr.s $(BOOTDIR)/mbr.inc - $(ASM) $(BOOTFLAGS) $(BOOTDIR)/mbr.s -o $(OBJDIR)/boot/mbr.bin - -boot.loader.s: $(BOOTDIR)/loader.s - $(ASM) $(BOOTFLAGS) $(BOOTDIR)/loader.s -o $(OBJDIR)/boot/loader.bin - -bootloader: boot.mbr.s boot.loader.s - cp $(OBJDIR)/boot/mbr.bin $(BINDIR)/mbr.bin - cp $(OBJDIR)/boot/loader.bin $(BINDIR)/loader.bin - -#----------------------------------------------------------------------------# -# TESTING MAKEFILE - -pseudo_kern: - $(ASM) $(BOOTFLAGS) $(BOOTDIR)/pseudo_kernel.s -o $(OBJDIR)/boot/pkernel.bin - -testing: bootloader pseudo_kern - cat $(BINDIR)/bootloader.bin $(OBJDIR)/boot/pkernel.bin > $(BINDIR)/boot.bin - -#----------------------------------------------------------------------------# -# COMMON MAKEFILE - -COBJDIR=$(OBJDIR)/$(COMMDIR) -LOBJDIR=$(OBJDIR)/$(LINXDIR) - -#COMMDEPS=$(COMMDIR)/common.h $(COMMDIR)/stdlib.h $(KERNDIR)/config.h -COMMDEPS=$(INCDIR)/kaleid.h $(INCDIR)/kaldefs.h $(INCDIR)/kaltypes.h \ - $(INCDIR)/kalmask.h $(INCDIR)/kalmask.h $(INCDIR)/kalassrt.h - -COMMSRCS=$(COMMDIR)/string.c $(COMMDIR)/status.c $(COMMDIR)/rand.c \ - $(COMMDIR)/convert.c $(COMMDIR)/memory.c $(COMMDIR)/arith.c - -COMMOBJS=$(COBJDIR)/string.o $(COBJDIR)/status.o $(COBJDIR)/rand.o \ - $(COBJDIR)/memory.o $(COBJDIR)/arith.o \ - $(COBJDIR)/itoa.o $(COBJDIR)/ltoa.o $(COBJDIR)/utoa.o $(COBJDIR)/ultoa.o - -comm-convert: - $(KCC) -c $(COMMDIR)/convert.c -D_NEED_ITOA -o $(COBJDIR)/itoa.o - $(KCC) -c $(COMMDIR)/convert.c -D_NEED_LTOA -o $(COBJDIR)/ltoa.o - $(KCC) -c $(COMMDIR)/convert.c -D_NEED_UTOA -o $(COBJDIR)/utoa.o - $(KCC) -c $(COMMDIR)/convert.c -D_NEED_ULTOA -o $(COBJDIR)/ultoa.o - -common: $(COMMDEPS) $(COMMSRCS) comm-convert - $(KCC) -c $(COMMDIR)/rand.c -o $(COBJDIR)/rand.o - $(KCC) -c $(COMMDIR)/arith.c -o $(COBJDIR)/arith.o - $(KCC) -c $(COMMDIR)/string.c -o $(COBJDIR)/string.o - $(KCC) -c $(COMMDIR)/status.c -o $(COBJDIR)/status.o - $(KCC) -c $(COMMDIR)/memory.c -o $(COBJDIR)/memory.o - -CCC=$(CC2NAME) $(COPTIM) $(CWARNS) $(CINCLUDES) - -tests-comm-convert: - $(CCC) -c $(COMMDIR)/convert.c -D_NEED_ITOA -o $(COBJDIR)/itoa.o - $(CCC) -c $(COMMDIR)/convert.c -D_NEED_LTOA -o $(COBJDIR)/ltoa.o - $(CCC) -c $(COMMDIR)/convert.c -D_NEED_UTOA -o $(COBJDIR)/utoa.o - $(CCC) -c $(COMMDIR)/convert.c -D_NEED_ULTOA -o $(COBJDIR)/ultoa.o - -tests: $(COMMSRCS) tests-comm-convert - $(CCC) -c $(COMMDIR)/rand.c -o $(COBJDIR)/rand.o - $(CCC) -c $(COMMDIR)/arith.c -o $(COBJDIR)/arith.o - $(CCC) -c $(COMMDIR)/string.c -o $(COBJDIR)/string.o - $(CCC) -c $(COMMDIR)/status.c -o $(COBJDIR)/status.o - $(CCC) -c $(COMMDIR)/memory.c -o $(COBJDIR)/memory.o - $(CCC) -c $(LINXDIR)/test-common.c -o $(LOBJDIR)/test-common.o - $(CCC) $(COMMOBJS) $(LOBJDIR)/test-common.o -o $(BINDIR)/kaleid-common.elf - -#----------------------------------------------------------------------------# -# KERNEL MAKEFILE - -KOBJDIR=$(OBJDIR)/$(KERNDIR) - -KERNDEPS=common $(KERNDIR)/init.h $(KERNDIR)/io/terminal.h $(KERNDIR)/ke/lock.h \ - $(KERNDIR)/io/ports.h $(KERNDIR)/ke/panic.h $(KERNDIR)/ke/state.h - -KERNSRCS=$(KERNDIR)/init.c $(KERNDIR)/io/terminal.c $(KERNDIR)/ke/lock.c \ - $(KERNDIR)/io/ports.c $(KERNDIR)/ke/panic.c $(KERNDIR)/ke/state.c - -KERNOBJS=$(KOBJDIR)/init.o $(KOBJDIR)/io/terminal.o $(KOBJDIR)/ke/lock.o \ - $(KOBJDIR)/io/ports.o $(KOBJDIR)/ke/panic.o $(KOBJDIR)/ke/state.o - -kernel: common $(KERNSRCS) - $(KCC) -c $(KERNDIR)/init.c -o $(KOBJDIR)/init.o - $(KCC) -c $(KERNDIR)/ke/lock.c -o $(KOBJDIR)/ke/lock.o - $(KCC) -c $(KERNDIR)/ke/state.c -o $(KOBJDIR)/ke/state.o - $(KCC) -c $(KERNDIR)/ke/panic.c -o $(KOBJDIR)/ke/panic.o - $(KCC) -c $(KERNDIR)/io/ports.c -o $(KOBJDIR)/io/ports.o - $(KCC) -c $(KERNDIR)/io/terminal.c -o $(KOBJDIR)/io/terminal.o - $(KCC) $(CLDSCR) $(COMMOBJS) $(KERNOBJS) -o $(BINDIR)/kaleid-kernel.elf - -#----------------------------------------------------------------------------# - -.PHONY: clean - -clean: - -#----------------------------------------------------------------------------# - From 6b9ea44f09c60a838c0eca66b5335637258c5356 Mon Sep 17 00:00:00 2001 From: Julian Barathieu Date: Wed, 2 Jan 2019 16:33:29 +0100 Subject: [PATCH 23/28] Placeholder stuff in obj --- obj/kaleid/common/.placeholder | 0 obj/kaleid/common/arith.S | 114 ++++ obj/kaleid/common/itoa.S | 77 +++ obj/kaleid/common/lib/.placeholder | 0 obj/kaleid/common/ltoa.S | 76 +++ obj/kaleid/common/memory.S | 309 +++++++++++ obj/kaleid/common/rand.S | 52 ++ obj/kaleid/common/status.S | 18 + obj/kaleid/common/string.S | 192 +++++++ obj/kaleid/common/test/.paceholder | 0 obj/kaleid/common/ultoa.S | 55 ++ obj/kaleid/common/utoa.S | 56 ++ obj/kaleid/kernel/init.S | 30 + obj/kaleid/kernel/io/.placeholder | 0 obj/kaleid/kernel/io/ports.S | 3 + obj/kaleid/kernel/io/terminal.S | 846 +++++++++++++++++++++++++++++ obj/kaleid/kernel/ke/.placeholder | 0 obj/kaleid/kernel/ke/lock.S | 3 + obj/kaleid/kernel/ke/panic.S | 103 ++++ obj/kaleid/kernel/ke/state.S | 4 + 20 files changed, 1938 insertions(+) create mode 100644 obj/kaleid/common/.placeholder create mode 100644 obj/kaleid/common/arith.S create mode 100644 obj/kaleid/common/itoa.S create mode 100644 obj/kaleid/common/lib/.placeholder create mode 100644 obj/kaleid/common/ltoa.S create mode 100644 obj/kaleid/common/memory.S create mode 100644 obj/kaleid/common/rand.S create mode 100644 obj/kaleid/common/status.S create mode 100644 obj/kaleid/common/string.S create mode 100644 obj/kaleid/common/test/.paceholder create mode 100644 obj/kaleid/common/ultoa.S create mode 100644 obj/kaleid/common/utoa.S create mode 100644 obj/kaleid/kernel/init.S create mode 100644 obj/kaleid/kernel/io/.placeholder create mode 100644 obj/kaleid/kernel/io/ports.S create mode 100644 obj/kaleid/kernel/io/terminal.S create mode 100644 obj/kaleid/kernel/ke/.placeholder create mode 100644 obj/kaleid/kernel/ke/lock.S create mode 100644 obj/kaleid/kernel/ke/panic.S create mode 100644 obj/kaleid/kernel/ke/state.S diff --git a/obj/kaleid/common/.placeholder b/obj/kaleid/common/.placeholder new file mode 100644 index 0000000..e69de29 diff --git a/obj/kaleid/common/arith.S b/obj/kaleid/common/arith.S new file mode 100644 index 0000000..5564d39 --- /dev/null +++ b/obj/kaleid/common/arith.S @@ -0,0 +1,114 @@ + .file "arith.c" + .text + .p2align 4,,15 + .globl _osk_abs + .type _osk_abs, @function +_osk_abs: +.LFB2: + .cfi_startproc + movl %edi, %edx + movl %edi, %eax + sarl $31, %edx + xorl %edx, %eax + subl %edx, %eax + ret + .cfi_endproc +.LFE2: + .size _osk_abs, .-_osk_abs + .p2align 4,,15 + .globl _osk_labs + .type _osk_labs, @function +_osk_labs: +.LFB3: + .cfi_startproc + movq %rdi, %rdx + movq %rdi, %rax + sarq $63, %rdx + xorq %rdx, %rax + subq %rdx, %rax + ret + .cfi_endproc +.LFE3: + .size _osk_labs, .-_osk_labs + .p2align 4,,15 + .globl _osk_min + .type _osk_min, @function +_osk_min: +.LFB4: + .cfi_startproc + cmpl %edi, %esi + movl %edi, %eax + cmovle %esi, %eax + ret + .cfi_endproc +.LFE4: + .size _osk_min, .-_osk_min + .p2align 4,,15 + .globl _osk_lmin + .type _osk_lmin, @function +_osk_lmin: +.LFB5: + .cfi_startproc + cmpq %rdi, %rsi + movq %rdi, %rax + cmovle %rsi, %rax + ret + .cfi_endproc +.LFE5: + .size _osk_lmin, .-_osk_lmin + .p2align 4,,15 + .globl _osk_max + .type _osk_max, @function +_osk_max: +.LFB11: + .cfi_startproc + cmpl %esi, %edi + movl %esi, %eax + cmovle %edi, %eax + ret + .cfi_endproc +.LFE11: + .size _osk_max, .-_osk_max + .p2align 4,,15 + .globl _osk_lmax + .type _osk_lmax, @function +_osk_lmax: +.LFB13: + .cfi_startproc + cmpq %rsi, %rdi + movq %rsi, %rax + cmovle %rdi, %rax + ret + .cfi_endproc +.LFE13: + .size _osk_lmax, .-_osk_lmax + .p2align 4,,15 + .globl _osk_div + .type _osk_div, @function +_osk_div: +.LFB8: + .cfi_startproc + movl %edi, %eax + cltd + idivl %esi + salq $32, %rdx + movl %eax, %eax + orq %rdx, %rax + ret + .cfi_endproc +.LFE8: + .size _osk_div, .-_osk_div + .p2align 4,,15 + .globl _osk_ldiv + .type _osk_ldiv, @function +_osk_ldiv: +.LFB9: + .cfi_startproc + movq %rdi, %rax + cqto + idivq %rsi + ret + .cfi_endproc +.LFE9: + .size _osk_ldiv, .-_osk_ldiv + .ident "GCC: (GNU) 7.3.0" diff --git a/obj/kaleid/common/itoa.S b/obj/kaleid/common/itoa.S new file mode 100644 index 0000000..1f55ec6 --- /dev/null +++ b/obj/kaleid/common/itoa.S @@ -0,0 +1,77 @@ + .file "convert.c" + .text + .p2align 4,,15 + .globl itoa + .type itoa, @function +itoa: +.LFB2: + .cfi_startproc + movl %edx, %r9d + leal -2(%rdx), %edx + movl %edi, %eax + cmpl $34, %edx + ja .L2 + testl %edi, %edi + js .L11 + jne .L7 + leaq 1(%rsi), %r8 + movb $48, (%rsi) +.L5: + movb $0, (%r8) + movq %rsi, %rdi + movabsq $reverse, %rax + jmp *%rax + .p2align 4,,10 + .p2align 3 +.L11: + negl %eax + movl $1, %edi +.L4: + movq %rsi, %r8 + movabsq $digits, %r10 + jmp .L6 + .p2align 4,,10 + .p2align 3 +.L8: + movq %rcx, %r8 +.L6: + cltd + leaq 1(%r8), %rcx + idivl %r9d + movslq %edx, %rdx + testl %eax, %eax + movzbl (%r10,%rdx), %edx + movb %dl, -1(%rcx) + jne .L8 + testl %edi, %edi + je .L9 + addq $2, %r8 + movb $45, (%rcx) + jmp .L5 + .p2align 4,,10 + .p2align 3 +.L7: + xorl %edi, %edi + jmp .L4 + .p2align 4,,10 + .p2align 3 +.L2: + xorl %eax, %eax + ret + .p2align 4,,10 + .p2align 3 +.L9: + movq %rcx, %r8 + jmp .L5 + .cfi_endproc +.LFE2: + .size itoa, .-itoa + .section .rodata + .align 32 + .type digits, @object + .size digits, 36 +digits: + .byte 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x41,0x42,0x43 + .byte 0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50 + .byte 0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a + .ident "GCC: (GNU) 7.3.0" diff --git a/obj/kaleid/common/lib/.placeholder b/obj/kaleid/common/lib/.placeholder new file mode 100644 index 0000000..e69de29 diff --git a/obj/kaleid/common/ltoa.S b/obj/kaleid/common/ltoa.S new file mode 100644 index 0000000..2723118 --- /dev/null +++ b/obj/kaleid/common/ltoa.S @@ -0,0 +1,76 @@ + .file "convert.c" + .text + .p2align 4,,15 + .globl ltoa + .type ltoa, @function +ltoa: +.LFB2: + .cfi_startproc + leal -2(%rdx), %ecx + movq %rdi, %rax + cmpl $34, %ecx + ja .L2 + testq %rdi, %rdi + js .L11 + jne .L7 + leaq 1(%rsi), %r9 + movb $48, (%rsi) +.L5: + movb $0, (%r9) + movq %rsi, %rdi + movabsq $reverse, %rax + jmp *%rax + .p2align 4,,10 + .p2align 3 +.L11: + negq %rax + movl $1, %edi +.L4: + movslq %edx, %r8 + movq %rsi, %r9 + movabsq $digits, %r10 + jmp .L6 + .p2align 4,,10 + .p2align 3 +.L8: + movq %rcx, %r9 +.L6: + cqto + leaq 1(%r9), %rcx + idivq %r8 + movzbl (%r10,%rdx), %edx + testq %rax, %rax + movb %dl, -1(%rcx) + jne .L8 + testl %edi, %edi + je .L9 + addq $2, %r9 + movb $45, (%rcx) + jmp .L5 + .p2align 4,,10 + .p2align 3 +.L7: + xorl %edi, %edi + jmp .L4 + .p2align 4,,10 + .p2align 3 +.L2: + xorl %eax, %eax + ret + .p2align 4,,10 + .p2align 3 +.L9: + movq %rcx, %r9 + jmp .L5 + .cfi_endproc +.LFE2: + .size ltoa, .-ltoa + .section .rodata + .align 32 + .type digits, @object + .size digits, 36 +digits: + .byte 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x41,0x42,0x43 + .byte 0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50 + .byte 0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a + .ident "GCC: (GNU) 7.3.0" diff --git a/obj/kaleid/common/memory.S b/obj/kaleid/common/memory.S new file mode 100644 index 0000000..6db16a5 --- /dev/null +++ b/obj/kaleid/common/memory.S @@ -0,0 +1,309 @@ + .file "memory.c" + .text + .p2align 4,,15 + .globl memsetb + .type memsetb, @function +memsetb: +.LFB2: + .cfi_startproc + movq %rdi, %rax + testb $7, %al + je .L10 + testq %rdx, %rdx + leaq -1(%rdx), %r8 + je .L3 + movl %esi, %edx + movq %rdi, %rcx + jmp .L4 + .p2align 4,,10 + .p2align 3 +.L21: + subq $1, %r8 + cmpq $-1, %r8 + je .L3 +.L4: + addq $1, %rcx + movb %dl, -1(%rcx) + testb $7, %cl + jne .L21 +.L2: + cmpq $8, %r8 + ja .L5 + testq %r8, %r8 + je .L22 +.L6: + addq %rcx, %r8 + .p2align 4,,10 + .p2align 3 +.L9: + addq $1, %rcx + movb %sil, -1(%rcx) + cmpq %rcx, %r8 + jne .L9 + rep ret + .p2align 4,,10 + .p2align 3 +.L3: + movq $-1, %r8 +.L5: + movslq %esi, %rcx + movq %rcx, %rdx + movq %rcx, %rdi + salq $48, %rdi + salq $56, %rdx + orq %rdi, %rdx + movq %rcx, %rdi + orq %rcx, %rdx + salq $40, %rdi + orq %rdi, %rdx + movq %rcx, %rdi + salq $32, %rdi + orq %rdi, %rdx + movq %rcx, %rdi + salq $24, %rdi + orq %rdi, %rdx + movq %rcx, %rdi + salq $8, %rcx + salq $16, %rdi + orq %rdi, %rdx + orq %rcx, %rdx + movq %rax, %rcx + .p2align 4,,10 + .p2align 3 +.L8: + subq $8, %r8 + addq $8, %rcx + movq %rdx, -8(%rcx) + cmpq $8, %r8 + ja .L8 + jmp .L6 + .p2align 4,,10 + .p2align 3 +.L22: + rep ret + .p2align 4,,10 + .p2align 3 +.L10: + movq %rdi, %rcx + movq %rdx, %r8 + jmp .L2 + .cfi_endproc +.LFE2: + .size memsetb, .-memsetb + .p2align 4,,15 + .globl memsetw + .type memsetw, @function +memsetw: +.LFB3: + .cfi_startproc + testb $1, %dil + jne .L24 + testb $7, %dil + je .L35 + testq %rdx, %rdx + leaq -1(%rdx), %r8 + movl %esi, %eax + movq %rdi, %rcx + jne .L31 + jmp .L47 + .p2align 4,,10 + .p2align 3 +.L48: + subq $1, %r8 + cmpq $-1, %r8 + je .L27 +.L31: + addq $2, %rcx + movw %ax, -2(%rcx) + testb $7, %cl + jne .L48 +.L25: + cmpq $4, %r8 + ja .L27 + testq %r8, %r8 + je .L28 +.L32: + xorl %edx, %edx + .p2align 4,,10 + .p2align 3 +.L34: + movw %si, (%rcx,%rdx,2) + addq $1, %rdx + cmpq %r8, %rdx + jne .L34 +.L28: + movq %rdi, %rax + ret + .p2align 4,,10 + .p2align 3 +.L47: + movq $-1, %r8 + .p2align 4,,10 + .p2align 3 +.L27: + movslq %esi, %rdx + movq %rdx, %rax + movq %rdx, %r9 + salq $48, %rax + salq $32, %r9 + orq %r9, %rax + orq %rdx, %rax + salq $16, %rdx + orq %rdx, %rax + .p2align 4,,10 + .p2align 3 +.L33: + subq $4, %r8 + addq $8, %rcx + movq %rax, -8(%rcx) + cmpq $4, %r8 + ja .L33 + jmp .L32 + .p2align 4,,10 + .p2align 3 +.L24: + testq %rdx, %rdx + je .L28 + xorl %eax, %eax + .p2align 4,,10 + .p2align 3 +.L29: + movw %si, (%rdi,%rax,2) + addq $1, %rax + cmpq %rax, %rdx + jne .L29 + leaq (%rdi,%rdx,2), %rax + ret + .p2align 4,,10 + .p2align 3 +.L35: + movq %rdi, %rcx + movq %rdx, %r8 + jmp .L25 + .cfi_endproc +.LFE3: + .size memsetw, .-memsetw + .p2align 4,,15 + .globl memsetd + .type memsetd, @function +memsetd: +.LFB4: + .cfi_startproc + movq %rdi, %rax + ret + .cfi_endproc +.LFE4: + .size memsetd, .-memsetd + .p2align 4,,15 + .globl memsetq + .type memsetq, @function +memsetq: +.LFB5: + .cfi_startproc + testq %rdx, %rdx + movq %rdi, %rax + je .L51 + xorl %ecx, %ecx + .p2align 4,,10 + .p2align 3 +.L52: + movq %rsi, (%rax,%rcx,8) + addq $1, %rcx + cmpq %rdx, %rcx + jne .L52 +.L51: + rep ret + .cfi_endproc +.LFE5: + .size memsetq, .-memsetq + .p2align 4,,15 + .globl memzero + .type memzero, @function +memzero: +.LFB6: + .cfi_startproc + movq %rsi, %rdx + movabsq $memsetb, %rax + xorl %esi, %esi + jmp *%rax + .cfi_endproc +.LFE6: + .size memzero, .-memzero + .p2align 4,,15 + .globl memcpy + .type memcpy, @function +memcpy: +.LFB7: + .cfi_startproc + testq %rdx, %rdx + movq %rdi, %rax + je .L59 + testb $1, %sil + movq %rsi, %rcx + jne .L91 +.L60: + testb $7, %al + je .L61 + andl $7, %ecx + jne .L89 + jmp .L61 + .p2align 4,,10 + .p2align 3 +.L62: + movsw + subq $2, %rdx +.L89: + cmpq $2, %rdx + ja .L62 +.L61: + cmpq $8, %rdx + jbe .L63 + leaq -9(%rdx), %r10 + xorl %ecx, %ecx + shrq $3, %r10 + leaq 8(,%r10,8), %r9 + .p2align 4,,10 + .p2align 3 +.L64: + movq (%rsi,%rcx), %r8 + movq %r8, (%rdi,%rcx) + addq $8, %rcx + cmpq %rcx, %r9 + jne .L64 + negq %r10 + addq %r9, %rsi + addq %r9, %rdi + leaq -8(%rdx,%r10,8), %rdx +.L65: + xorl %ecx, %ecx + .p2align 4,,10 + .p2align 3 +.L66: + movzbl (%rsi,%rcx), %r8d + movw %r8w, (%rdi,%rcx,2) + addq $1, %rcx + cmpq %rdx, %rcx + jne .L66 +.L59: + rep ret + .p2align 4,,10 + .p2align 3 +.L63: + testq %rdx, %rdx + jne .L65 + rep ret + .p2align 4,,10 + .p2align 3 +.L91: + testb $1, %al + je .L60 + movzbl (%rsi), %r8d + leaq 1(%rdi), %rdi + subq $1, %rdx + addq $1, %rsi + movb %r8b, (%rax) + jmp .L60 + .cfi_endproc +.LFE7: + .size memcpy, .-memcpy + .ident "GCC: (GNU) 7.3.0" diff --git a/obj/kaleid/common/rand.S b/obj/kaleid/common/rand.S new file mode 100644 index 0000000..b91186e --- /dev/null +++ b/obj/kaleid/common/rand.S @@ -0,0 +1,52 @@ + .file "rand.c" + .text + .p2align 4,,15 + .globl rand + .type rand, @function +rand: +.LFB2: + .cfi_startproc + movabsq $next, %rax + imulq $1103515245, (%rax), %rdx + addq $12345, %rdx + movq %rdx, (%rax) + shrq $16, %rdx + movl %edx, %eax + movl %edx, %esi + leaq (%rax,%rax,2), %rax + shrq $32, %rax + movq %rax, %rcx + movl %edx, %eax + subl %ecx, %eax + shrl %eax + addl %ecx, %eax + shrl $30, %eax + movl %eax, %ecx + sall $31, %ecx + subl %eax, %ecx + subl %ecx, %esi + movl %esi, %eax + ret + .cfi_endproc +.LFE2: + .size rand, .-rand + .p2align 4,,15 + .globl srand + .type srand, @function +srand: +.LFB3: + .cfi_startproc + movabsq $next, %rax + movl %edi, %edx + movq %rdx, (%rax) + ret + .cfi_endproc +.LFE3: + .size srand, .-srand + .data + .align 8 + .type next, @object + .size next, 8 +next: + .quad 7756 + .ident "GCC: (GNU) 7.3.0" diff --git a/obj/kaleid/common/status.S b/obj/kaleid/common/status.S new file mode 100644 index 0000000..99dcf29 --- /dev/null +++ b/obj/kaleid/common/status.S @@ -0,0 +1,18 @@ + .file "status.c" + .text + .section .rodata.str1.1,"aMS",@progbits,1 +.LC0: + .string "" + .text + .p2align 4,,15 + .globl describe_status + .type describe_status, @function +describe_status: +.LFB2: + .cfi_startproc + movabsq $.LC0, %rax + ret + .cfi_endproc +.LFE2: + .size describe_status, .-describe_status + .ident "GCC: (GNU) 7.3.0" diff --git a/obj/kaleid/common/string.S b/obj/kaleid/common/string.S new file mode 100644 index 0000000..0ff4b9e --- /dev/null +++ b/obj/kaleid/common/string.S @@ -0,0 +1,192 @@ + .file "string.c" + .text + .p2align 4,,15 + .globl strlen + .type strlen, @function +strlen: +.LFB2: + .cfi_startproc + movq %rdi, %rax + .p2align 4,,10 + .p2align 3 +.L2: + addq $1, %rax + cmpb $0, -1(%rax) + jne .L2 + subq %rdi, %rax + subq $1, %rax + ret + .cfi_endproc +.LFE2: + .size strlen, .-strlen + .p2align 4,,15 + .globl strcpy + .type strcpy, @function +strcpy: +.LFB3: + .cfi_startproc + movq %rdi, %rax + movq %rdi, %rdx + .p2align 4,,10 + .p2align 3 +.L6: + addq $1, %rsi + movzbl -1(%rsi), %ecx + addq $1, %rdx + testb %cl, %cl + movb %cl, -1(%rdx) + jne .L6 + rep ret + .cfi_endproc +.LFE3: + .size strcpy, .-strcpy + .p2align 4,,15 + .globl strncpy + .type strncpy, @function +strncpy: +.LFB4: + .cfi_startproc + testq %rdx, %rdx + movq %rdi, %rax + je .L9 + movzbl (%rsi), %r8d + xorl %ecx, %ecx + testb %r8b, %r8b + jne .L11 + jmp .L12 + .p2align 4,,10 + .p2align 3 +.L20: + movzbl (%rsi,%rcx), %r8d + testb %r8b, %r8b + je .L12 +.L11: + movb %r8b, (%rax,%rcx) + addq $1, %rcx + cmpq %rcx, %rdx + jne .L20 +.L9: + rep ret + .p2align 4,,10 + .p2align 3 +.L12: + addq $1, %rcx + cmpq %rcx, %rdx + movb $0, -1(%rax,%rcx) + jbe .L9 + addq $1, %rcx + cmpq %rcx, %rdx + movb $0, -1(%rax,%rcx) + ja .L12 + jmp .L9 + .cfi_endproc +.LFE4: + .size strncpy, .-strncpy + .p2align 4,,15 + .globl xstrcnpy + .type xstrcnpy, @function +xstrcnpy: +.LFB5: + .cfi_startproc + testq %rdx, %rdx + je .L22 + movzbl (%rsi), %ecx + xorl %eax, %eax + testb %cl, %cl + jne .L24 + jmp .L25 + .p2align 4,,10 + .p2align 3 +.L33: + movzbl (%rsi,%rax), %ecx + testb %cl, %cl + je .L25 +.L24: + movb %cl, (%rdi,%rax) + addq $1, %rax + cmpq %rax, %rdx + jne .L33 +.L22: + movl $1, %eax + ret + .p2align 4,,10 + .p2align 3 +.L25: + addq $1, %rax + cmpq %rax, %rdx + movb $0, -1(%rdi,%rax) + jbe .L22 + addq $1, %rax + cmpq %rax, %rdx + movb $0, -1(%rdi,%rax) + ja .L25 + jmp .L22 + .cfi_endproc +.LFE5: + .size xstrcnpy, .-xstrcnpy + .p2align 4,,15 + .globl strrev + .type strrev, @function +strrev: +.LFB6: + .cfi_startproc + movq %rdi, %rax + movq %rsi, %rdx + .p2align 4,,10 + .p2align 3 +.L35: + addq $1, %rdx + cmpb $0, -1(%rdx) + jne .L35 + subq %rsi, %rdx + movb $0, -1(%rax,%rdx) + leaq -2(%rsi,%rdx), %rcx + movq %rax, %rdx + .p2align 4,,10 + .p2align 3 +.L36: + movzbl (%rcx), %esi + addq $1, %rdx + subq $1, %rcx + testb %sil, %sil + movb %sil, -1(%rdx) + jne .L36 + rep ret + .cfi_endproc +.LFE6: + .size strrev, .-strrev + .p2align 4,,15 + .globl reverse + .type reverse, @function +reverse: +.LFB7: + .cfi_startproc + movq %rdi, %rax + movq %rdi, %rdx + .p2align 4,,10 + .p2align 3 +.L40: + addq $1, %rdx + cmpb $0, -1(%rdx) + jne .L40 + subq $2, %rdx + cmpq %rdx, %rax + jnb .L41 + movq %rax, %rcx + .p2align 4,,10 + .p2align 3 +.L42: + movzbl (%rdx), %esi + movzbl (%rcx), %r8d + subq $1, %rdx + addq $1, %rcx + cmpq %rcx, %rdx + movb %r8b, 1(%rdx) + movb %sil, -1(%rcx) + ja .L42 +.L41: + rep ret + .cfi_endproc +.LFE7: + .size reverse, .-reverse + .ident "GCC: (GNU) 7.3.0" diff --git a/obj/kaleid/common/test/.paceholder b/obj/kaleid/common/test/.paceholder new file mode 100644 index 0000000..e69de29 diff --git a/obj/kaleid/common/ultoa.S b/obj/kaleid/common/ultoa.S new file mode 100644 index 0000000..9f381f4 --- /dev/null +++ b/obj/kaleid/common/ultoa.S @@ -0,0 +1,55 @@ + .file "convert.c" + .text + .p2align 4,,15 + .globl ultoa + .type ultoa, @function +ultoa: +.LFB2: + .cfi_startproc + leal -2(%rdx), %ecx + movq %rdi, %rax + cmpl $34, %ecx + ja .L2 + testq %rdi, %rdi + jne .L3 + leaq 1(%rsi), %rcx + movb $48, (%rsi) +.L4: + movb $0, (%rcx) + movq %rsi, %rdi + movabsq $reverse, %rax + jmp *%rax + .p2align 4,,10 + .p2align 3 +.L3: + movslq %edx, %r8 + movq %rsi, %rcx + movabsq $digits, %r9 + .p2align 4,,10 + .p2align 3 +.L5: + xorl %edx, %edx + addq $1, %rcx + divq %r8 + movzbl (%r9,%rdx), %edx + testq %rax, %rax + movb %dl, -1(%rcx) + jne .L5 + jmp .L4 + .p2align 4,,10 + .p2align 3 +.L2: + xorl %eax, %eax + ret + .cfi_endproc +.LFE2: + .size ultoa, .-ultoa + .section .rodata + .align 32 + .type digits, @object + .size digits, 36 +digits: + .byte 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x41,0x42,0x43 + .byte 0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50 + .byte 0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a + .ident "GCC: (GNU) 7.3.0" diff --git a/obj/kaleid/common/utoa.S b/obj/kaleid/common/utoa.S new file mode 100644 index 0000000..dc4310c --- /dev/null +++ b/obj/kaleid/common/utoa.S @@ -0,0 +1,56 @@ + .file "convert.c" + .text + .p2align 4,,15 + .globl utoa + .type utoa, @function +utoa: +.LFB2: + .cfi_startproc + movl %edx, %r8d + leal -2(%rdx), %edx + movl %edi, %eax + cmpl $34, %edx + ja .L2 + testl %edi, %edi + jne .L5 + leaq 1(%rsi), %rcx + movb $48, (%rsi) +.L4: + movb $0, (%rcx) + movq %rsi, %rdi + movabsq $reverse, %rax + jmp *%rax + .p2align 4,,10 + .p2align 3 +.L5: + movq %rsi, %rcx + movabsq $digits, %r9 + .p2align 4,,10 + .p2align 3 +.L3: + xorl %edx, %edx + addq $1, %rcx + divl %r8d + movl %edx, %edx + testl %eax, %eax + movzbl (%r9,%rdx), %edx + movb %dl, -1(%rcx) + jne .L3 + jmp .L4 + .p2align 4,,10 + .p2align 3 +.L2: + xorl %eax, %eax + ret + .cfi_endproc +.LFE2: + .size utoa, .-utoa + .section .rodata + .align 32 + .type digits, @object + .size digits, 36 +digits: + .byte 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x41,0x42,0x43 + .byte 0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50 + .byte 0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a + .ident "GCC: (GNU) 7.3.0" diff --git a/obj/kaleid/kernel/init.S b/obj/kaleid/kernel/init.S new file mode 100644 index 0000000..c2fd44a --- /dev/null +++ b/obj/kaleid/kernel/init.S @@ -0,0 +1,30 @@ + .file "init.c" + .text + .section .rodata.str1.1,"aMS",@progbits,1 +.LC0: + .string "Goodbye World :(" + .text + .p2align 4,,15 + .globl StartKern + .type StartKern, @function +StartKern: +.LFB2: + .cfi_startproc + subq $8, %rsp + .cfi_def_cfa_offset 16 +/APP +# 21 "kaleid/kernel/init.c" 1 + cli +# 0 "" 2 +/NO_APP + movabsq $__kstate, %rax + movb $3, (%rax) + movabsq $InitTerms, %rax + call *%rax + movabsq $.LC0, %rdi + movabsq $StartPanic, %rax + call *%rax + .cfi_endproc +.LFE2: + .size StartKern, .-StartKern + .ident "GCC: (GNU) 7.3.0" diff --git a/obj/kaleid/kernel/io/.placeholder b/obj/kaleid/kernel/io/.placeholder new file mode 100644 index 0000000..e69de29 diff --git a/obj/kaleid/kernel/io/ports.S b/obj/kaleid/kernel/io/ports.S new file mode 100644 index 0000000..8a0517d --- /dev/null +++ b/obj/kaleid/kernel/io/ports.S @@ -0,0 +1,3 @@ + .file "ports.c" + .text + .ident "GCC: (GNU) 7.3.0" diff --git a/obj/kaleid/kernel/io/terminal.S b/obj/kaleid/kernel/io/terminal.S new file mode 100644 index 0000000..42e0a6f --- /dev/null +++ b/obj/kaleid/kernel/io/terminal.S @@ -0,0 +1,846 @@ + .file "terminal.c" + .text + .section .rodata.str1.1,"aMS",@progbits,1 +.LC0: + .string "kaleid/kernel/io/terminal.c" +.LC1: + .string "kt->kt_init == INITOK" + .section .rodata.str1.8,"aMS",@progbits,1 + .align 8 +.LC2: + .string "(&(kt)->kt_lock)->lk_init == INITOK" + .align 8 +.LC3: + .string "DosAquireLock on an already locked object" + .align 8 +.LC4: + .string "DosReleaseLock on an unlocked object" + .text + .p2align 4,,15 + .globl ClearTerm + .type ClearTerm, @function +ClearTerm: +.LFB3: + .cfi_startproc + testq %rdi, %rdi + je .L10 + pushq %rbx + .cfi_def_cfa_offset 16 + .cfi_offset 3, -16 + cmpl $-889275714, 80(%rdi) + movq %rdi, %rbx + jne .L26 +/APP +# 69 "kaleid/kernel/io/terminal.c" 1 + cli +# 0 "" 2 +/NO_APP + cmpl $-889275714, 24(%rdi) + jne .L27 + movl 4(%rdi), %eax + leal 1(%rax), %edx + testl %eax, %eax + movl %edx, 4(%rdi) + jne .L28 +.L5: +/APP +# 69 "kaleid/kernel/io/terminal.c" 1 + sti +# 0 "" 2 +/NO_APP + movq 48(%rbx), %rcx + movzbl 40(%rbx), %edx + imulq 56(%rbx), %rcx + sall $8, %edx + orl $32, %edx + testq %rcx, %rcx + je .L6 + movq 32(%rbx), %rax + leaq (%rax,%rcx,2), %rcx + .p2align 4,,10 + .p2align 3 +.L7: + movw %dx, (%rax) + addq $2, %rax + cmpq %rax, %rcx + jne .L7 +.L6: + movq $0, 72(%rbx) + movq $0, 64(%rbx) +/APP +# 71 "kaleid/kernel/io/terminal.c" 1 + cli +# 0 "" 2 +/NO_APP + cmpl $-889275714, 24(%rbx) + jne .L29 + movl 4(%rbx), %eax + leal 1(%rax), %edx + testl %eax, %eax + movl %edx, 4(%rbx) + jne .L30 +.L9: +/APP +# 71 "kaleid/kernel/io/terminal.c" 1 + sti +# 0 "" 2 +/NO_APP + xorl %eax, %eax + popq %rbx + .cfi_remember_state + .cfi_restore 3 + .cfi_def_cfa_offset 8 + ret + .p2align 4,,10 + .p2align 3 +.L30: + .cfi_restore_state + movabsq $.LC4, %rdi + xorl %eax, %eax + movabsq $StartPanic, %rdx + call *%rdx + jmp .L9 + .p2align 4,,10 + .p2align 3 +.L28: + movabsq $.LC3, %rdi + xorl %eax, %eax + movabsq $StartPanic, %rdx + call *%rdx + jmp .L5 + .p2align 4,,10 + .p2align 3 +.L26: + movabsq $__func__.1202, %rcx + movl $67, %edx + movabsq $.LC0, %rsi + movabsq $.LC1, %rdi + movabsq $_assert_handler, %rax + call *%rax + .p2align 4,,10 + .p2align 3 +.L27: + movabsq $__func__.1202, %rcx + movl $69, %edx + movabsq $.LC0, %rsi + movabsq $.LC2, %rdi + movabsq $_assert_handler, %rax + call *%rax + .p2align 4,,10 + .p2align 3 +.L29: + movabsq $__func__.1202, %rcx + movl $71, %edx + movabsq $.LC0, %rsi + movabsq $.LC2, %rdi + movabsq $_assert_handler, %rax + call *%rax +.L10: + .cfi_def_cfa_offset 8 + .cfi_restore 3 + movq $-6, %rax + ret + .cfi_endproc +.LFE3: + .size ClearTerm, .-ClearTerm + .section .rodata.str1.8 + .align 8 +.LC5: + .string "!stdout && _vga_term.kt_init != INITOK" + .text + .p2align 4,,15 + .globl InitTerms + .type InitTerms, @function +InitTerms: +.LFB2: + .cfi_startproc + movabsq $stdout, %rdx + cmpq $0, (%rdx) + jne .L32 + movabsq $_vga_term, %rdi + cmpl $-889275714, 80(%rdi) + je .L32 + movabsq $_vga_term+80, %rax + movq %rdi, (%rdx) + movl $-889275714, (%rax) + movq %rdi, %rax + movabsq %rax, stddbg + movabsq $ClearTerm, %rax + jmp *%rax + .p2align 4,,10 + .p2align 3 +.L32: + subq $8, %rsp + .cfi_def_cfa_offset 16 + movabsq $__func__.1198, %rcx + movl $49, %edx + movabsq $.LC0, %rsi + movabsq $.LC5, %rdi + movabsq $_assert_handler, %rax + call *%rax + .cfi_endproc +.LFE2: + .size InitTerms, .-InitTerms + .p2align 4,,15 + .globl ChTermColor + .type ChTermColor, @function +ChTermColor: +.LFB4: + .cfi_startproc + cmpb $15, %sil + ja .L42 + testq %rdi, %rdi + je .L43 + pushq %rbp + .cfi_def_cfa_offset 16 + .cfi_offset 6, -16 + pushq %rbx + .cfi_def_cfa_offset 24 + .cfi_offset 3, -24 + movl %esi, %ebp + movq %rdi, %rbx + subq $8, %rsp + .cfi_def_cfa_offset 32 +/APP +# 87 "kaleid/kernel/io/terminal.c" 1 + cli +# 0 "" 2 +/NO_APP + cmpl $-889275714, 24(%rdi) + jne .L54 + movl 4(%rdi), %eax + leal 1(%rax), %edx + testl %eax, %eax + movl %edx, 4(%rdi) + jne .L55 +.L39: +/APP +# 87 "kaleid/kernel/io/terminal.c" 1 + sti +# 0 "" 2 +/NO_APP + movb %bpl, 40(%rbx) +/APP +# 89 "kaleid/kernel/io/terminal.c" 1 + cli +# 0 "" 2 +/NO_APP + cmpl $-889275714, 24(%rbx) + jne .L56 + movl 4(%rbx), %eax + leal 1(%rax), %edx + testl %eax, %eax + movl %edx, 4(%rbx) + jne .L57 +.L41: +/APP +# 89 "kaleid/kernel/io/terminal.c" 1 + sti +# 0 "" 2 +/NO_APP + addq $8, %rsp + .cfi_remember_state + .cfi_def_cfa_offset 24 + xorl %eax, %eax + popq %rbx + .cfi_restore 3 + .cfi_def_cfa_offset 16 + popq %rbp + .cfi_restore 6 + .cfi_def_cfa_offset 8 + ret + .p2align 4,,10 + .p2align 3 +.L55: + .cfi_restore_state + movabsq $.LC3, %rdi + xorl %eax, %eax + movabsq $StartPanic, %rdx + call *%rdx + jmp .L39 + .p2align 4,,10 + .p2align 3 +.L57: + movabsq $.LC4, %rdi + xorl %eax, %eax + movabsq $StartPanic, %rdx + call *%rdx + jmp .L41 + .p2align 4,,10 + .p2align 3 +.L54: + movabsq $__func__.1210, %rcx + movl $87, %edx + movabsq $.LC0, %rsi + movabsq $.LC2, %rdi + movabsq $_assert_handler, %rax + call *%rax + .p2align 4,,10 + .p2align 3 +.L56: + movabsq $__func__.1210, %rcx + movl $89, %edx + movabsq $.LC0, %rsi + movabsq $.LC2, %rdi + movabsq $_assert_handler, %rax + call *%rax + .p2align 4,,10 + .p2align 3 +.L42: + .cfi_def_cfa_offset 8 + .cfi_restore 3 + .cfi_restore 6 + movq $-5, %rax + ret +.L43: + movq $-6, %rax + ret + .cfi_endproc +.LFE4: + .size ChTermColor, .-ChTermColor + .p2align 4,,15 + .globl ClearTermUnlocked + .type ClearTermUnlocked, @function +ClearTermUnlocked: +.LFB7: + .cfi_startproc + movq 48(%rdi), %rcx + movzbl 40(%rdi), %edx + imulq 56(%rdi), %rcx + sall $8, %edx + orl $32, %edx + testq %rcx, %rcx + je .L59 + movq 32(%rdi), %rax + leaq (%rax,%rcx,2), %rcx + .p2align 4,,10 + .p2align 3 +.L60: + movw %dx, (%rax) + addq $2, %rax + cmpq %rcx, %rax + jne .L60 +.L59: + movq $0, 72(%rdi) + movq $0, 64(%rdi) + ret + .cfi_endproc +.LFE7: + .size ClearTermUnlocked, .-ClearTermUnlocked + .p2align 4,,15 + .globl PutOnTermUnlocked + .type PutOnTermUnlocked, @function +PutOnTermUnlocked: +.LFB8: + .cfi_startproc + cmpb $13, %sil + je .L69 + movsbl %sil, %esi + movabsq $PutOnTermUnlocked.part.0, %rax + jmp *%rax + .p2align 4,,10 + .p2align 3 +.L69: + movq $0, 64(%rdi) + ret + .cfi_endproc +.LFE8: + .size PutOnTermUnlocked, .-PutOnTermUnlocked + .p2align 4,,15 + .type PutOnTermUnlocked.part.0, @function +PutOnTermUnlocked.part.0: +.LFB10: + .cfi_startproc + pushq %r13 + .cfi_def_cfa_offset 16 + .cfi_offset 13, -16 + pushq %r12 + .cfi_def_cfa_offset 24 + .cfi_offset 12, -24 + pushq %rbp + .cfi_def_cfa_offset 32 + .cfi_offset 6, -32 + pushq %rbx + .cfi_def_cfa_offset 40 + .cfi_offset 3, -40 + movq %rdi, %rbx + subq $8, %rsp + .cfi_def_cfa_offset 48 + cmpb $10, %sil + je .L81 + cmpb $9, %sil + movq 72(%rdi), %rbp + je .L82 + movq 48(%rdi), %rdx + movzbl 40(%rbx), %ecx + movsbw %sil, %si + movq 64(%rdi), %rax + movq 32(%rdi), %rdi + imulq %rdx, %rbp + sall $8, %ecx + orl %ecx, %esi + addq %rax, %rbp + movw %si, (%rdi,%rbp,2) +.L72: + addq $1, %rax + cmpq %rdx, %rax + je .L77 + movq %rax, 64(%rbx) +.L70: + addq $8, %rsp + .cfi_remember_state + .cfi_def_cfa_offset 40 + popq %rbx + .cfi_restore 3 + .cfi_def_cfa_offset 32 + popq %rbp + .cfi_restore 6 + .cfi_def_cfa_offset 24 + popq %r12 + .cfi_restore 12 + .cfi_def_cfa_offset 16 + popq %r13 + .cfi_restore 13 + .cfi_def_cfa_offset 8 + ret + .p2align 4,,10 + .p2align 3 +.L82: + .cfi_restore_state + movq %rbp, %rax + movl $4, %r12d + movabsq $PutOnTermUnlocked, %r13 + cmpq %rbp, %rax + je .L83 +.L74: + subl $1, %r12d + je .L84 + movq 72(%rbx), %rax + cmpq %rbp, %rax + jne .L74 +.L83: + movl $32, %esi + movq %rbx, %rdi + call *%r13 + jmp .L74 + .p2align 4,,10 + .p2align 3 +.L77: + movq 72(%rbx), %rax + movq $0, 64(%rbx) + addq $1, %rax + cmpq 56(%rbx), %rax + movq %rax, 72(%rbx) + jne .L70 + movq $0, 72(%rbx) + addq $8, %rsp + .cfi_remember_state + .cfi_def_cfa_offset 40 + popq %rbx + .cfi_restore 3 + .cfi_def_cfa_offset 32 + popq %rbp + .cfi_restore 6 + .cfi_def_cfa_offset 24 + popq %r12 + .cfi_restore 12 + .cfi_def_cfa_offset 16 + popq %r13 + .cfi_restore 13 + .cfi_def_cfa_offset 8 + ret + .p2align 4,,10 + .p2align 3 +.L81: + .cfi_restore_state + movq 48(%rdi), %rdx + leaq -1(%rdx), %rax + movq %rax, 72(%rdi) + movq 64(%rdi), %rax + jmp .L72 + .p2align 4,,10 + .p2align 3 +.L84: + movq 64(%rbx), %rax + movq 48(%rbx), %rdx + jmp .L72 + .cfi_endproc +.LFE10: + .size PutOnTermUnlocked.part.0, .-PutOnTermUnlocked.part.0 + .p2align 4,,15 + .globl PutOnTerm + .type PutOnTerm, @function +PutOnTerm: +.LFB5: + .cfi_startproc + testq %rdi, %rdi + je .L94 + pushq %rbp + .cfi_def_cfa_offset 16 + .cfi_offset 6, -16 + pushq %rbx + .cfi_def_cfa_offset 24 + .cfi_offset 3, -24 + movl %esi, %ebp + movq %rdi, %rbx + subq $8, %rsp + .cfi_def_cfa_offset 32 + cmpl $-889275714, 80(%rdi) + jne .L105 +/APP +# 104 "kaleid/kernel/io/terminal.c" 1 + cli +# 0 "" 2 +/NO_APP + cmpl $-889275714, 24(%rdi) + jne .L106 + movl 4(%rdi), %eax + leal 1(%rax), %edx + testl %eax, %eax + movl %edx, 4(%rdi) + jne .L107 +.L89: +/APP +# 104 "kaleid/kernel/io/terminal.c" 1 + sti +# 0 "" 2 +/NO_APP + cmpb $13, %bpl + jne .L90 + movq $0, 64(%rbx) +.L91: +/APP +# 106 "kaleid/kernel/io/terminal.c" 1 + cli +# 0 "" 2 +/NO_APP + cmpl $-889275714, 24(%rbx) + jne .L108 + movl 4(%rbx), %eax + leal 1(%rax), %edx + testl %eax, %eax + movl %edx, 4(%rbx) + jne .L109 +.L93: +/APP +# 106 "kaleid/kernel/io/terminal.c" 1 + sti +# 0 "" 2 +/NO_APP + addq $8, %rsp + .cfi_remember_state + .cfi_def_cfa_offset 24 + xorl %eax, %eax + popq %rbx + .cfi_restore 3 + .cfi_def_cfa_offset 16 + popq %rbp + .cfi_restore 6 + .cfi_def_cfa_offset 8 + ret + .p2align 4,,10 + .p2align 3 +.L90: + .cfi_restore_state + movsbl %bpl, %esi + movq %rbx, %rdi + movabsq $PutOnTermUnlocked.part.0, %rax + call *%rax + jmp .L91 + .p2align 4,,10 + .p2align 3 +.L107: + movabsq $.LC3, %rdi + xorl %eax, %eax + movabsq $StartPanic, %rdx + call *%rdx + jmp .L89 + .p2align 4,,10 + .p2align 3 +.L109: + movabsq $.LC4, %rdi + xorl %eax, %eax + movabsq $StartPanic, %rdx + call *%rdx + jmp .L93 + .p2align 4,,10 + .p2align 3 +.L105: + movabsq $__func__.1217, %rcx + movl $102, %edx + movabsq $.LC0, %rsi + movabsq $.LC1, %rdi + movabsq $_assert_handler, %rax + call *%rax + .p2align 4,,10 + .p2align 3 +.L106: + movabsq $__func__.1217, %rcx + movl $104, %edx + movabsq $.LC0, %rsi + movabsq $.LC2, %rdi + movabsq $_assert_handler, %rax + call *%rax + .p2align 4,,10 + .p2align 3 +.L108: + movabsq $__func__.1217, %rcx + movl $106, %edx + movabsq $.LC0, %rsi + movabsq $.LC2, %rdi + movabsq $_assert_handler, %rax + call *%rax +.L94: + .cfi_def_cfa_offset 8 + .cfi_restore 3 + .cfi_restore 6 + movq $-6, %rax + ret + .cfi_endproc +.LFE5: + .size PutOnTerm, .-PutOnTerm + .p2align 4,,15 + .globl PrintOnTerm + .type PrintOnTerm, @function +PrintOnTerm: +.LFB6: + .cfi_startproc + testq %rdi, %rdi + je .L121 + pushq %r12 + .cfi_def_cfa_offset 16 + .cfi_offset 12, -16 + pushq %rbp + .cfi_def_cfa_offset 24 + .cfi_offset 6, -24 + movq %rdi, %rbp + pushq %rbx + .cfi_def_cfa_offset 32 + .cfi_offset 3, -32 + cmpl $-889275714, 80(%rdi) + jne .L132 +/APP +# 121 "kaleid/kernel/io/terminal.c" 1 + cli +# 0 "" 2 +/NO_APP + cmpl $-889275714, 24(%rdi) + jne .L133 + movl 4(%rdi), %eax + movq %rsi, %rbx + leal 1(%rax), %edx + testl %eax, %eax + movl %edx, 4(%rdi) + jne .L134 +.L114: +/APP +# 121 "kaleid/kernel/io/terminal.c" 1 + sti +# 0 "" 2 +/NO_APP + movabsq $PutOnTermUnlocked.part.0, %r12 +.L115: + movsbl (%rbx), %esi + testb %sil, %sil + je .L135 +.L118: + addq $1, %rbx + cmpb $13, %sil + jne .L116 + movq $0, 64(%rbp) + movsbl (%rbx), %esi + testb %sil, %sil + jne .L118 +.L135: +/APP +# 125 "kaleid/kernel/io/terminal.c" 1 + cli +# 0 "" 2 +/NO_APP + cmpl $-889275714, 24(%rbp) + jne .L136 + movl 4(%rbp), %eax + leal 1(%rax), %edx + testl %eax, %eax + movl %edx, 4(%rbp) + jne .L137 +.L120: +/APP +# 125 "kaleid/kernel/io/terminal.c" 1 + sti +# 0 "" 2 +/NO_APP + xorl %eax, %eax + popq %rbx + .cfi_remember_state + .cfi_restore 3 + .cfi_def_cfa_offset 24 + popq %rbp + .cfi_restore 6 + .cfi_def_cfa_offset 16 + popq %r12 + .cfi_restore 12 + .cfi_def_cfa_offset 8 + ret + .p2align 4,,10 + .p2align 3 +.L116: + .cfi_restore_state + movq %rbp, %rdi + call *%r12 + jmp .L115 + .p2align 4,,10 + .p2align 3 +.L137: + movabsq $.LC4, %rdi + xorl %eax, %eax + movabsq $StartPanic, %rdx + call *%rdx + jmp .L120 + .p2align 4,,10 + .p2align 3 +.L134: + movabsq $.LC3, %rdi + xorl %eax, %eax + movabsq $StartPanic, %rdx + call *%rdx + jmp .L114 + .p2align 4,,10 + .p2align 3 +.L132: + movabsq $__func__.1224, %rcx + movl $119, %edx + movabsq $.LC0, %rsi + movabsq $.LC1, %rdi + movabsq $_assert_handler, %rax + call *%rax + .p2align 4,,10 + .p2align 3 +.L133: + movabsq $__func__.1224, %rcx + movl $121, %edx + movabsq $.LC0, %rsi + movabsq $.LC2, %rdi + movabsq $_assert_handler, %rax + call *%rax + .p2align 4,,10 + .p2align 3 +.L136: + movabsq $__func__.1224, %rcx + movl $125, %edx + movabsq $.LC0, %rsi + movabsq $.LC2, %rdi + movabsq $_assert_handler, %rax + call *%rax +.L121: + .cfi_def_cfa_offset 8 + .cfi_restore 3 + .cfi_restore 6 + .cfi_restore 12 + movq $-6, %rax + ret + .cfi_endproc +.LFE6: + .size PrintOnTerm, .-PrintOnTerm + .p2align 4,,15 + .globl PrintOnTermUnlocked + .type PrintOnTermUnlocked, @function +PrintOnTermUnlocked: +.LFB9: + .cfi_startproc + pushq %r12 + .cfi_def_cfa_offset 16 + .cfi_offset 12, -16 + movabsq $PutOnTermUnlocked.part.0, %r12 + pushq %rbp + .cfi_def_cfa_offset 24 + .cfi_offset 6, -24 + movq %rdi, %rbp + pushq %rbx + .cfi_def_cfa_offset 32 + .cfi_offset 3, -32 + movq %rsi, %rbx +.L139: + movsbl (%rbx), %esi + testb %sil, %sil + je .L144 +.L142: + addq $1, %rbx + cmpb $13, %sil + jne .L140 + movq $0, 64(%rbp) + movsbl (%rbx), %esi + testb %sil, %sil + jne .L142 +.L144: + popq %rbx + .cfi_remember_state + .cfi_restore 3 + .cfi_def_cfa_offset 24 + popq %rbp + .cfi_restore 6 + .cfi_def_cfa_offset 16 + popq %r12 + .cfi_restore 12 + .cfi_def_cfa_offset 8 + ret + .p2align 4,,10 + .p2align 3 +.L140: + .cfi_restore_state + movq %rbp, %rdi + call *%r12 + jmp .L139 + .cfi_endproc +.LFE9: + .size PrintOnTermUnlocked, .-PrintOnTermUnlocked + .section .rodata + .align 8 + .type __func__.1224, @object + .size __func__.1224, 12 +__func__.1224: + .string "PrintOnTerm" + .align 8 + .type __func__.1217, @object + .size __func__.1217, 10 +__func__.1217: + .string "PutOnTerm" + .align 8 + .type __func__.1210, @object + .size __func__.1210, 12 +__func__.1210: + .string "ChTermColor" + .align 8 + .type __func__.1202, @object + .size __func__.1202, 10 +__func__.1202: + .string "ClearTerm" + .align 8 + .type __func__.1198, @object + .size __func__.1198, 10 +__func__.1198: + .string "InitTerms" + .comm stddbg,8,8 + .comm stdout,8,8 + .data + .align 32 + .type _vga_term, @object + .size _vga_term, 88 +_vga_term: + .byte 0 + .zero 3 + .long 0 + .quad 0 + .quad 0 + .long -889275714 + .zero 4 + .quad 753664 + .byte 7 + .zero 7 + .quad 80 + .quad 25 + .quad 0 + .quad 0 + .long 0 + .zero 4 + .ident "GCC: (GNU) 7.3.0" diff --git a/obj/kaleid/kernel/ke/.placeholder b/obj/kaleid/kernel/ke/.placeholder new file mode 100644 index 0000000..e69de29 diff --git a/obj/kaleid/kernel/ke/lock.S b/obj/kaleid/kernel/ke/lock.S new file mode 100644 index 0000000..77581ed --- /dev/null +++ b/obj/kaleid/kernel/ke/lock.S @@ -0,0 +1,3 @@ + .file "lock.c" + .text + .ident "GCC: (GNU) 7.3.0" diff --git a/obj/kaleid/kernel/ke/panic.S b/obj/kaleid/kernel/ke/panic.S new file mode 100644 index 0000000..3191489 --- /dev/null +++ b/obj/kaleid/kernel/ke/panic.S @@ -0,0 +1,103 @@ + .file "panic.c" + .text + .section .rodata.str1.1,"aMS",@progbits,1 +.LC0: + .string "(no message given)" +.LC1: + .string "double panic!\n" +.LC2: + .string "panic! - " + .text + .p2align 4,,15 + .globl StartPanic + .type StartPanic, @function +StartPanic: +.LFB3: + .cfi_startproc + pushq %r13 + .cfi_def_cfa_offset 16 + .cfi_offset 13, -16 + pushq %r12 + .cfi_def_cfa_offset 24 + .cfi_offset 12, -24 + pushq %rbp + .cfi_def_cfa_offset 32 + .cfi_offset 6, -32 + pushq %rbx + .cfi_def_cfa_offset 40 + .cfi_offset 3, -40 + movq %rdi, %rbx + subq $8, %rsp + .cfi_def_cfa_offset 48 +/APP +# 43 "kaleid/kernel/ke/panic.c" 1 + cli +# 0 "" 2 +/NO_APP + movabsq $__kstate, %rax + movabsq $stdout, %rbp + movabsq $__panicmsg, %r13 + movb $2, (%rax) + movq 0(%rbp), %rdi + movabsq $ClearTermUnlocked, %rax + call *%rax + testq %rbx, %rbx + movabsq $.LC0, %rax + movq 0(%rbp), %rdi + cmove %rax, %rbx + cmpq $0, 0(%r13) + movabsq $PrintOnTermUnlocked, %r12 + je .L3 + movabsq $.LC1, %rsi + call *%r12 +/APP +# 55 "kaleid/kernel/ke/panic.c" 1 + hlt +# 0 "" 2 +/NO_APP +.L3: + movabsq $.LC2, %rsi + movq 0(%rbp), %rdi + movq %rbx, 0(%r13) + call *%r12 + movq %rbx, %rsi + movq 0(%rbp), %rdi + call *%r12 + .p2align 4,,10 + .p2align 3 +.L4: +/APP +# 65 "kaleid/kernel/ke/panic.c" 1 + hlt +# 0 "" 2 +/NO_APP + jmp .L4 + .cfi_endproc +.LFE3: + .size StartPanic, .-StartPanic + .p2align 4,,15 + .globl _assert_handler + .type _assert_handler, @function +_assert_handler: +.LFB2: + .cfi_startproc + subq $8, %rsp + .cfi_def_cfa_offset 16 +/APP +# 30 "kaleid/kernel/ke/panic.c" 1 + cli +# 0 "" 2 +/NO_APP + movabsq $StartPanic, %rax + call *%rax + .cfi_endproc +.LFE2: + .size _assert_handler, .-_assert_handler + .globl __panicmsg + .section .bss + .align 8 + .type __panicmsg, @object + .size __panicmsg, 8 +__panicmsg: + .zero 8 + .ident "GCC: (GNU) 7.3.0" diff --git a/obj/kaleid/kernel/ke/state.S b/obj/kaleid/kernel/ke/state.S new file mode 100644 index 0000000..11ea154 --- /dev/null +++ b/obj/kaleid/kernel/ke/state.S @@ -0,0 +1,4 @@ + .file "state.c" + .text + .comm __kstate,1,1 + .ident "GCC: (GNU) 7.3.0" From 8998b2d62dc9c653fa505c235a1b3f8c5f041426 Mon Sep 17 00:00:00 2001 From: Julian Barathieu Date: Wed, 2 Jan 2019 17:19:13 +0100 Subject: [PATCH 24/28] More memory stuff --- src/Makefile.in | 16 +++---- src/kaleid/common/{convert.c => itoa.c} | 2 +- src/kaleid/common/memory.c | 59 ++++++++++++++++++------- src/kaleid/include/kalcrt.h | 12 ++--- src/kaleid/include/kalmask.h | 2 +- src/preproc.h | 2 +- 6 files changed, 59 insertions(+), 34 deletions(-) rename src/kaleid/common/{convert.c => itoa.c} (96%) diff --git a/src/Makefile.in b/src/Makefile.in index 12bdd68..b728749 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -1,11 +1,11 @@ -//----------------------------------------------------------------------------# -// GNU GPL OS/K # -// # -// Authors: spectral` # -// NeoX # -// # -// Desc: Project Makefile # -//----------------------------------------------------------------------------# +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: Project Makefile // +//----------------------------------------------------------------------------// // The madman's Makefile #include "preproc.h" diff --git a/src/kaleid/common/convert.c b/src/kaleid/common/itoa.c similarity index 96% rename from src/kaleid/common/convert.c rename to src/kaleid/common/itoa.c index c18765c..a184e16 100644 --- a/src/kaleid/common/convert.c +++ b/src/kaleid/common/itoa.c @@ -4,7 +4,7 @@ // Authors: spectral` // // NeoX // // // -// Desc: Conversion utilities // +// Desc: Conversion utilities - itoa family // //----------------------------------------------------------------------------// #include diff --git a/src/kaleid/common/memory.c b/src/kaleid/common/memory.c index c88bd43..59b6cb8 100644 --- a/src/kaleid/common/memory.c +++ b/src/kaleid/common/memory.c @@ -17,7 +17,7 @@ // // Set "bytes"-many bytes starting from ptr to val // -void *memsetb(void *ptr, int val, size_t bytes) +void *memset(void *ptr, int val, size_t bytes) { uchar *uptr = (uchar *)ptr; @@ -45,9 +45,7 @@ void *memsetb(void *ptr, int val, size_t bytes) } // deal with what's left - while (bytes--) { - *uptr++ = (uchar)val; - } + while (bytes--) *uptr++ = (uchar)val; return ptr; } @@ -61,12 +59,7 @@ void *memsetw(void *ptr, int val, size_t words) // can't we do this an aligned way? if unlikely (((ulong)uptr % WORD_ALIGN) > 0) { - // no, we can't align ourselves - while (words--) { - // do it the hard way - *uptr++ = (ushort)val; - } - // too bad '-' + while (words--) *uptr++ = (ushort)val; return uptr; } @@ -92,9 +85,7 @@ void *memsetw(void *ptr, int val, size_t words) } // deal with what's left - while (words--) { - *uptr++ = (ushort)val; - } + while (words--) *uptr++ = (ushort)val; return ptr; } @@ -135,7 +126,6 @@ void *memzero(void *ptr, size_t bytes) return memsetb(ptr, 0, bytes); } - // // Copy "bytes"-many bytes of src to dst // Does not deal with overlapping blocks (memmove's job) @@ -185,10 +175,45 @@ void *memcpy(void *dst, const void *src, size_t bytes) ushort *ubdst = (ushort *)udst; // deal with what's left - while (bytes--) { - *ubdst ++ = *ubsrc++; - } + while (bytes--) *ubdst ++ = *ubsrc++; return dst; } +// +// Move memory from src to dest +// To be made more efficient +// +void *memmove(void *dst, const void *src, size_t bytes) +{ + const uchar *usrc = src; + uchar *udst = dst; + + if (udst < usrc) { + while (bytes--) *udst++ = *usrc++; + return dst; + } + + uchar *usrc_end = (uchar *)usrc + bytes - 1; + uchar *udst_end = udst + bytes - 1; + while (bytes--) *udst_end-- = *usrc_end--; + + return dst; +} + +// +// Compare memory areas +// +int memcmp(const void *ptr1, const void *ptr2, size_t bytes) +{ + const uchar *uptr1 = ptr1; + const uchar *uptr2 = ptr2; + + while (bytes--) { + if (*uptr1++ != *uptr2++) { + return uptr1[-1] < uptr2[-1] ? -1 : 1; + } + } + + return 0; +} diff --git a/src/kaleid/include/kalcrt.h b/src/kaleid/include/kalcrt.h index bc46aa1..534533b 100644 --- a/src/kaleid/include/kalcrt.h +++ b/src/kaleid/include/kalcrt.h @@ -71,20 +71,20 @@ typedef struct { long quot, rem; } ldiv_t; // Memory management utilities // //------------------------------------------// -#ifndef memset -#define memset memsetb +#ifndef memsetb +#define memsetb memset #endif -#ifndef memchr -#define memchr memchrb +#ifndef memchrb +#define memchrb memchr #endif -void *memsetb(void *, int, size_t); +void *memset(void *, int, size_t); void *memsetw(void *, int, size_t); void *memsetd(void *, int, size_t); void *memsetq(void *, long, size_t); -void *memchrb(const void *, int, size_t); +void *memchr(const void *, int, size_t); void *memchrw(const void *, int, size_t); void *memchrd(const void *, int, size_t); void *memchrq(const void *, long, size_t); diff --git a/src/kaleid/include/kalmask.h b/src/kaleid/include/kalmask.h index 078163a..5c9870e 100644 --- a/src/kaleid/include/kalmask.h +++ b/src/kaleid/include/kalmask.h @@ -20,7 +20,7 @@ #define memsetd _osk_memsetd #define memsetq _osk_memsetq -#define memchrb _osk_memchrb +#define memchr _osk_memchrb #define memchrw _osk_memchrw #define memchrd _osk_memchrd #define memchrq _osk_memchrq diff --git a/src/preproc.h b/src/preproc.h index 265f9ee..b55004d 100644 --- a/src/preproc.h +++ b/src/preproc.h @@ -16,7 +16,7 @@ # define LINK_KERNEL(out) $(KCC) $(CLDSCR) $(COMMOBJS) $(KERNOBJS) -o $(BINDIR)/out #endif -#define COMPILE_CONVRT(file) $(CCC) _CSPREF $(COMMDIR)/convert.c -o $(COBJDIR)/file._OUTFIX +#define COMPILE_CONVRT(file) $(CCC) _CSPREF $(COMMDIR)/itoa.c -o $(COBJDIR)/file._OUTFIX #define COMPILE_COMMON(file) $(CCC) _CSPREF $(COMMDIR)/file.c -o $(COBJDIR)/file._OUTFIX #define COMPILE_KERNEL(file) $(KCC) _CSPREF $(KERNDIR)/file.c -o $(KOBJDIR)/file._OUTFIX From 3faa92d09428062a9c2c68c4f0aaa644de70d09e Mon Sep 17 00:00:00 2001 From: Julian Barathieu Date: Mon, 14 Jan 2019 14:31:49 +0100 Subject: [PATCH 25/28] Big reorganization & stuff --- .gitignore | 4 + src/COPYING => COPYING | 0 src/ChangeLog => ChangeLog | 2 +- LICENSE | 674 -------------- src/Makefile => Makefile | 6 +- src/Makefile.in => Makefile.in | 50 +- ProjectTree | 107 +++ README.md | 7 +- {src/boot => boot}/folder.desc | 0 src/boot/loader.s => boot/loader.asm | 0 {src/boot => boot}/loader16.inc | 0 {src/boot => boot}/loader64.inc | 0 src/boot/mbr.s => boot/mbr.asm | 0 {src/boot => boot}/mbr.inc | 0 {bin => build/bin}/disk.img | Bin {bin => build/bin}/loader.bin | Bin {bin => build/bin}/mbr.bin | Bin {src => build}/idttool.py | 0 {src => build}/kernel.ld | 10 +- {obj => build/obj}/boot/loader.bin | Bin {obj => build/obj}/boot/mbr.bin | Bin {obj => build/obj}/kaleid/common/.placeholder | 0 .../obj}/kaleid/common/test/.paceholder | 0 .../obj/kaleid/kernel/init}/.placeholder | 0 .../obj}/kaleid/kernel/io/.placeholder | 0 .../obj}/kaleid/kernel/ke/.placeholder | 0 build/preproc.h | 42 + {src/kaleid => kaleid}/common/arith.c | 20 - kaleid/common/atoi.c | 37 + {src/kaleid => kaleid}/common/itoa.c | 34 +- {src/kaleid => kaleid}/common/memory.c | 100 ++- {src/kaleid => kaleid}/common/rand.c | 9 +- {src/kaleid => kaleid}/common/sprintf.c | 32 +- {src/kaleid => kaleid}/common/status.c | 5 +- kaleid/common/string.c | 301 +++++++ .../io/ports.c => kaleid/common/strtol.c | 18 +- .../include/common}/kalassrt.h | 40 +- .../include/common}/kalcrt.h | 128 +-- .../include/common}/kaldefs.h | 51 +- kaleid/include/common/kalerror.h | 63 ++ .../include/common}/kallims.h | 9 +- kaleid/include/common/kallist.h | 271 ++++++ .../include/common}/kalmask.h | 37 +- .../include/common}/kaltypes.h | 74 +- {src/kaleid => kaleid}/include/kaleid.h | 54 +- {src/kaleid => kaleid}/include/kalkern.h | 36 +- kaleid/include/kernel/kernbase.h | 205 +++++ kaleid/include/kernel/kernlocks.h | 170 ++++ kaleid/include/kernel/kernsched.h | 102 +++ kaleid/include/kernel/kernterm.h | 95 ++ .../kernel => kaleid/kernel/init}/init.c | 15 +- .../io/ports.h => kaleid/kernel/init/table.c | 18 +- {src/kaleid => kaleid}/kernel/ke/panic.c | 55 +- kaleid/kernel/ke/terminal.c | 236 +++++ kaleid/kernel/proc/Makefile | 4 + kaleid/kernel/proc/sched.c | 409 +++++++++ obj/kaleid/common/arith.S | 114 --- obj/kaleid/common/itoa.S | 77 -- obj/kaleid/common/ltoa.S | 76 -- obj/kaleid/common/memory.S | 309 ------- obj/kaleid/common/rand.S | 52 -- obj/kaleid/common/status.S | 18 - obj/kaleid/common/string.S | 192 ---- obj/kaleid/common/ultoa.S | 55 -- obj/kaleid/common/utoa.S | 56 -- obj/kaleid/kernel/init.S | 30 - obj/kaleid/kernel/io/ports.S | 3 - obj/kaleid/kernel/io/terminal.S | 846 ------------------ obj/kaleid/kernel/ke/lock.S | 3 - obj/kaleid/kernel/ke/panic.S | 103 --- obj/kaleid/kernel/ke/state.S | 4 - src/CONTACT | 1 - src/kaleid/common/old/common.h | 179 ---- src/kaleid/common/old/folder.desc | 37 - src/kaleid/common/old/stdlib.h | 90 -- src/kaleid/common/string.c | 100 --- src/kaleid/common/test/test-common.c | 83 -- src/kaleid/common/test/test-file0.c | 28 - src/kaleid/include/kalkern | 1 - src/kaleid/kernel/config.h | 42 - src/kaleid/kernel/config.h.in | 42 - src/kaleid/kernel/folder.desc | 37 - src/kaleid/kernel/init.h | 21 - src/kaleid/kernel/io/terminal.c | 210 ----- src/kaleid/kernel/io/terminal.h | 69 -- src/kaleid/kernel/ke/lock.c | 13 - src/kaleid/kernel/ke/lock.h | 98 -- src/kaleid/kernel/ke/panic.h | 24 - src/kaleid/kernel/ke/state.c | 16 - src/kaleid/kernel/ke/state.h | 37 - src/preproc.h | 33 - src/project-style.txt | 19 - src/project-tree.txt | 101 --- 93 files changed, 2556 insertions(+), 4193 deletions(-) rename src/COPYING => COPYING (100%) rename src/ChangeLog => ChangeLog (91%) delete mode 100644 LICENSE rename src/Makefile => Makefile (92%) rename src/Makefile.in => Makefile.in (68%) create mode 100644 ProjectTree rename {src/boot => boot}/folder.desc (100%) rename src/boot/loader.s => boot/loader.asm (100%) rename {src/boot => boot}/loader16.inc (100%) rename {src/boot => boot}/loader64.inc (100%) rename src/boot/mbr.s => boot/mbr.asm (100%) rename {src/boot => boot}/mbr.inc (100%) rename {bin => build/bin}/disk.img (100%) rename {bin => build/bin}/loader.bin (100%) rename {bin => build/bin}/mbr.bin (100%) rename {src => build}/idttool.py (100%) rename {src => build}/kernel.ld (74%) rename {obj => build/obj}/boot/loader.bin (100%) rename {obj => build/obj}/boot/mbr.bin (100%) rename {obj => build/obj}/kaleid/common/.placeholder (100%) rename {obj => build/obj}/kaleid/common/test/.paceholder (100%) rename {obj/kaleid/common/lib => build/obj/kaleid/kernel/init}/.placeholder (100%) rename {obj => build/obj}/kaleid/kernel/io/.placeholder (100%) rename {obj => build/obj}/kaleid/kernel/ke/.placeholder (100%) create mode 100644 build/preproc.h rename {src/kaleid => kaleid}/common/arith.c (80%) create mode 100644 kaleid/common/atoi.c rename {src/kaleid => kaleid}/common/itoa.c (75%) rename {src/kaleid => kaleid}/common/memory.c (78%) rename {src/kaleid => kaleid}/common/rand.c (87%) rename {src/kaleid => kaleid}/common/sprintf.c (78%) rename {src/kaleid => kaleid}/common/status.c (97%) create mode 100644 kaleid/common/string.c rename src/kaleid/kernel/io/ports.c => kaleid/common/strtol.c (62%) rename {src/kaleid/include => kaleid/include/common}/kalassrt.h (70%) rename {src/kaleid/include => kaleid/include/common}/kalcrt.h (61%) rename {src/kaleid/include => kaleid/include/common}/kaldefs.h (71%) create mode 100644 kaleid/include/common/kalerror.h rename {src/kaleid/include => kaleid/include/common}/kallims.h (95%) create mode 100644 kaleid/include/common/kallist.h rename {src/kaleid/include => kaleid/include/common}/kalmask.h (77%) rename {src/kaleid/include => kaleid/include/common}/kaltypes.h (59%) rename {src/kaleid => kaleid}/include/kaleid.h (59%) rename {src/kaleid => kaleid}/include/kalkern.h (72%) create mode 100644 kaleid/include/kernel/kernbase.h create mode 100644 kaleid/include/kernel/kernlocks.h create mode 100644 kaleid/include/kernel/kernsched.h create mode 100644 kaleid/include/kernel/kernterm.h rename {src/kaleid/kernel => kaleid/kernel/init}/init.c (80%) rename src/kaleid/kernel/io/ports.h => kaleid/kernel/init/table.c (63%) rename {src/kaleid => kaleid}/kernel/ke/panic.c (65%) create mode 100644 kaleid/kernel/ke/terminal.c create mode 100644 kaleid/kernel/proc/Makefile create mode 100644 kaleid/kernel/proc/sched.c delete mode 100644 obj/kaleid/common/arith.S delete mode 100644 obj/kaleid/common/itoa.S delete mode 100644 obj/kaleid/common/ltoa.S delete mode 100644 obj/kaleid/common/memory.S delete mode 100644 obj/kaleid/common/rand.S delete mode 100644 obj/kaleid/common/status.S delete mode 100644 obj/kaleid/common/string.S delete mode 100644 obj/kaleid/common/ultoa.S delete mode 100644 obj/kaleid/common/utoa.S delete mode 100644 obj/kaleid/kernel/init.S delete mode 100644 obj/kaleid/kernel/io/ports.S delete mode 100644 obj/kaleid/kernel/io/terminal.S delete mode 100644 obj/kaleid/kernel/ke/lock.S delete mode 100644 obj/kaleid/kernel/ke/panic.S delete mode 100644 obj/kaleid/kernel/ke/state.S delete mode 100644 src/CONTACT delete mode 100644 src/kaleid/common/old/common.h delete mode 100644 src/kaleid/common/old/folder.desc delete mode 100644 src/kaleid/common/old/stdlib.h delete mode 100644 src/kaleid/common/string.c delete mode 100644 src/kaleid/common/test/test-common.c delete mode 100644 src/kaleid/common/test/test-file0.c delete mode 120000 src/kaleid/include/kalkern delete mode 100644 src/kaleid/kernel/config.h delete mode 100644 src/kaleid/kernel/config.h.in delete mode 100644 src/kaleid/kernel/folder.desc delete mode 100644 src/kaleid/kernel/init.h delete mode 100644 src/kaleid/kernel/io/terminal.c delete mode 100644 src/kaleid/kernel/io/terminal.h delete mode 100644 src/kaleid/kernel/ke/lock.c delete mode 100644 src/kaleid/kernel/ke/lock.h delete mode 100644 src/kaleid/kernel/ke/panic.h delete mode 100644 src/kaleid/kernel/ke/state.c delete mode 100644 src/kaleid/kernel/ke/state.h delete mode 100644 src/preproc.h delete mode 100644 src/project-style.txt delete mode 100644 src/project-tree.txt diff --git a/.gitignore b/.gitignore index c6127b3..3e8b80f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,15 @@ # Prerequisites *.d +# Test files +test-*.c + # Object files *.o *.ko *.obj *.elf +*.S # Linker output *.ilk diff --git a/src/COPYING b/COPYING similarity index 100% rename from src/COPYING rename to COPYING diff --git a/src/ChangeLog b/ChangeLog similarity index 91% rename from src/ChangeLog rename to ChangeLog index 27cc873..b019064 100644 --- a/src/ChangeLog +++ b/ChangeLog @@ -14,6 +14,6 @@ 2018/12/06 - Actually started project, began MBR, decided directories organization, created this file and others 2018/12/08 - MBR actually supports Long Mode Compatibility Verification - Added A20 line Enabling to MBR -2018/12/21 - Boot is now in two stages. First stage is 512 MBR code that loads second stage loader from FAT16. +2018/12/21 - Boot is now in two stages. First stage is 512B MBR code that loads second stage loader from FAT16. That second stage loader enables A20, switches into long mode and write colored text =D diff --git a/LICENSE b/LICENSE deleted file mode 100644 index f288702..0000000 --- a/LICENSE +++ /dev/null @@ -1,674 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The GNU General Public License is a free, copyleft license for -software and other kinds of works. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -the GNU General Public License is intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. We, the Free Software Foundation, use the -GNU General Public License for most of our software; it applies also to -any other work released this way by its authors. You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - To protect your rights, we need to prevent others from denying you -these rights or asking you to surrender the rights. Therefore, you have -certain responsibilities if you distribute copies of the software, or if -you modify it: responsibilities to respect the freedom of others. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must pass on to the recipients the same -freedoms that you received. You must make sure that they, too, receive -or can get the source code. And you must show them these terms so they -know their rights. - - Developers that use the GNU GPL protect your rights with two steps: -(1) assert copyright on the software, and (2) offer you this License -giving you legal permission to copy, distribute and/or modify it. - - For the developers' and authors' protection, the GPL clearly explains -that there is no warranty for this free software. For both users' and -authors' sake, the GPL requires that modified versions be marked as -changed, so that their problems will not be attributed erroneously to -authors of previous versions. - - Some devices are designed to deny users access to install or run -modified versions of the software inside them, although the manufacturer -can do so. This is fundamentally incompatible with the aim of -protecting users' freedom to change the software. The systematic -pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we -have designed this version of the GPL to prohibit the practice for those -products. If such problems arise substantially in other domains, we -stand ready to extend this provision to those domains in future versions -of the GPL, as needed to protect the freedom of users. - - Finally, every program is threatened constantly by software patents. -States should not allow patents to restrict development and use of -software on general-purpose computers, but in those that do, we wish to -avoid the special danger that patents applied to a free program could -make it effectively proprietary. To prevent this, the GPL assures that -patents cannot be used to render the program non-free. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Use with the GNU Affero General Public License. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU Affero General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the special requirements of the GNU Affero General Public License, -section 13, concerning interaction through a network will apply to the -combination as such. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - -Also add information on how to contact you by electronic and paper mail. - - If the program does terminal interaction, make it output a short -notice like this when it starts in an interactive mode: - - Copyright (C) - This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, your program's commands -might be different; for a GUI interface, you would use an "about box". - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU GPL, see -. - - The GNU General Public License does not permit incorporating your program -into proprietary programs. If your program is a subroutine library, you -may consider it more useful to permit linking proprietary applications with -the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. But first, please read -. diff --git a/src/Makefile b/Makefile similarity index 92% rename from src/Makefile rename to Makefile index 5a4d5c5..71e74a6 100644 --- a/src/Makefile +++ b/Makefile @@ -9,19 +9,19 @@ kernel: cpp ./Makefile.in > Makefile.out - python ./idttool.py + python ./build/idttool.py make kernel -f Makefile.out.2 rm Makefile.out Makefile.out.2 kernel-asm: cpp -D_TO_ASM ./Makefile.in > Makefile.out - python ./idttool.py + python ./build/idttool.py make kernel -f Makefile.out.2 rm Makefile.out Makefile.out.2 tests: cpp -D_TESTS ./Makefile.in > Makefile.out - python ./idttool.py + python ./build/idttool.py make tests -f Makefile.out.2 rm Makefile.out Makefile.out.2 diff --git a/src/Makefile.in b/Makefile.in similarity index 68% rename from src/Makefile.in rename to Makefile.in index b728749..5c26235 100644 --- a/src/Makefile.in +++ b/Makefile.in @@ -8,48 +8,45 @@ //----------------------------------------------------------------------------// // The madman's Makefile -#include "preproc.h" +#include "build/preproc.h" CCNAME="/opt/cross-cc/bin/x86_64-elf-gcc" CC2NAME=gcc COPTIM=-O2 -CLDSCR=-T kernel.ld -CWARNS=-pedantic -Wall -Wextra -Werror +CWARNS=-Wall -Wextra -Wshadow -Wpedantic CINCLUDES=-isystem./kaleid/include -CDEFINES= -CFLAGS1=-nostdlib -ffreestanding -mcmodel=large -CFLAGS2=-mno-red-zone -mno-mmx -mno-sse -mno-sse2 +CFLAGS1=-std=gnu11 -nostdlib -ffreestanding -mcmodel=large +CFLAGS2=-m64 -masm=intel -mno-red-zone -mno-mmx -mno-sse -mno-sse2 CFLAGS=$(CFLAGS1) $(CFLAGS2) $(SFLAG) -CC=$(CCNAME) $(COPTIM) $(CWARNS) $(CFLAGS) $(CDEFINES) $(CINCLUDES) +CC=$(CCNAME) $(COPTIM) $(CWARNS) $(CFLAGS) $(CINCLUDES) ASM=nasm ASMFLAGS= BOOTFLAGS=-f bin -BINDIR=../bin -OBJDIR=../obj +BINDIR=./build/bin +OBJDIR=./build/obj BOOTDIR=boot COMMDIR=kaleid/common KERNDIR=kaleid/kernel SYSTDIR=kaleid/system LINXDIR=kaleid/common/test -INCDIR=kaleid/include all: bootloader kernel boot.mbr.s: $(BOOTDIR)/mbr.s $(BOOTDIR)/mbr.inc - $(ASM) $(BOOTFLAGS) $(BOOTDIR)/mbr.s -o $(OBJDIR)/boot/mbr.bin + $(ASM) $(BOOTFLAGS) $(BOOTDIR)/mbr.asm -o $(OBJDIR)/boot/mbr.bin boot.loader.s: $(BOOTDIR)/loader.s - $(ASM) $(BOOTFLAGS) $(BOOTDIR)/loader.s -o $(OBJDIR)/boot/loader.bin + $(ASM) $(BOOTFLAGS) $(BOOTDIR)/loader.asm -o $(OBJDIR)/boot/loader.bin bootloader: boot.mbr.s boot.loader.s cp $(OBJDIR)/boot/mbr.bin $(BINDIR)/mbr.bin cp $(OBJDIR)/boot/loader.bin $(BINDIR)/loader.bin - + //----------------------------------------------------------------------------# // TESTING MAKEFILE @@ -65,16 +62,20 @@ testing: bootloader pseudo_kern COBJDIR=$(OBJDIR)/$(COMMDIR) LOBJDIR=$(OBJDIR)/$(LINXDIR) -COMMOBJS=COBJ5(string,status,rand,memory,arith) COBJ4(itoa,ltoa,utoa,ultoa) +COMMOBJS=COBJ6(string, status, rand, memory, arith, strtol) COBJ4(itoa, ltoa, utoa, ultoa) COBJ4(atoi, atol, atou, atoul) TCC=$(CC2NAME) $(COPTIM) $(CWARNS) $(CINCLUDES) -KCC=$(CC) -D_OSK_SOURCE -D_KALEID_KERNEL +KCC=$(CC) -T ./build/kernel.ld -D_OSK_SOURCE -D_KALEID_KERNEL comm-convert: - COMPILE_CONVRT(itoa) -D_NEED_ITOA - COMPILE_CONVRT(ltoa) -D_NEED_LTOA - COMPILE_CONVRT(utoa) -D_NEED_UTOA - COMPILE_CONVRT(ultoa) -D_NEED_ULTOA + COMPILE_CONVRT1(itoa) -D_NEED_ITOA + COMPILE_CONVRT1(ltoa) -D_NEED_LTOA + COMPILE_CONVRT1(utoa) -D_NEED_UTOA + COMPILE_CONVRT1(ultoa) -D_NEED_ULTOA + COMPILE_CONVRT2(atoi) -D_NEED_ATOI + COMPILE_CONVRT2(atol) -D_NEED_ATOL + COMPILE_CONVRT2(atou) -D_NEED_ATOU + COMPILE_CONVRT2(atoul) -D_NEED_ATOUL common: comm-convert COMPILE_COMMON(rand) @@ -82,6 +83,7 @@ common: comm-convert COMPILE_COMMON(string) COMPILE_COMMON(status) COMPILE_COMMON(memory) + COMPILE_COMMON(strtol) tests: common $(TCC) -c $(LINXDIR)/test-common.c -o $(LOBJDIR)/test-common.o @@ -92,15 +94,13 @@ tests: common KOBJDIR=$(OBJDIR)/$(KERNDIR) -KERNOBJS=KOBJ5(init,ke/lock,ke/panic,ke/state,io/ports) KOBJ1(io/terminal) +KERNOBJS=KOBJ4(init/init, init/table, ke/panic, ke/terminal) kernel: common - COMPILE_KERNEL(init) - COMPILE_KERNEL(ke/lock) - COMPILE_KERNEL(ke/state) + COMPILE_KERNEL(init/init) + COMPILE_KERNEL(init/table) COMPILE_KERNEL(ke/panic) - COMPILE_KERNEL(io/ports) - COMPILE_KERNEL(io/terminal) + COMPILE_KERNEL(ke/terminal) LINK_KERNEL(kaleid-kernel.elf) //----------------------------------------------------------------------------# diff --git a/ProjectTree b/ProjectTree new file mode 100644 index 0000000..90c5627 --- /dev/null +++ b/ProjectTree @@ -0,0 +1,107 @@ +#------------------------------------------------------------------------------# +# GNU GPL OS/K # +# # +# Authors: spectral` # +# NeoX # +# # +# Desc: Project Tree # +#------------------------------------------------------------------------------# + +src/ + | + x COPYING + x README.md + x ChangeLog + | + - Makefile + - Makefile.in + | + + boot/ + | | + | x folder.desc + | | + | - mbr.asm + | - mbr.inc + | | + | - loader.asm + | - loader16.inc + | - loader64.inc + | | + | 0 + | + + kaleid/ + | | + | + include/ + | | | + | | - kaleid.h + | | - kalkern.h + | | | + | | + common/ + | | | | + | | | - kaldefs.h + | | | - kaltypes.h + | | | - kalerror.h + | | | - kalassrt.h + | | | - kallims.h + | | | - kalmask.h + | | | - kalcrt.h + | | | | + | | | 0 + | | | + | | + kernel/ + | | | | + | | | - kernbase.h + | | | - kernlocks.h + | | | - kernterm.h + | | | | + | | | 0 + | | 0 + | | + | | + | + kernel/ + | | | + | | - kernel.ld + | | | + | | + init/ + | | | | + | | | - init.c + | | | | + | | | 0 + | | | + | | + ke/ + | | | | + | | | - panic.c + | | | - table.c + | | | - terminal.c + | | | | + | | | 0 + | | 0 + | | + | + common/ + | | | + | | - status.c + | | | + | | - arith.c + | | - rand.c + | | | + | | - atoi.c + | | - itoa.c + | | - strtol.c + | | | + | | - memory.c + | | - string.c + | | - sprintf.c + | | | + | | 0 + | 0 + | + + build/ + | | + | - preproc.h + | - iddtool.h + | | + | + bin/ + | + obj/ + | | + | 0 + 0 diff --git a/README.md b/README.md index 41d9385..8be55fd 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,9 @@ Fully open-source operating system from scratch (WIP), released under the GNU GP Branch kaleid : Development focused on the Kaleid Kernel. -For changelog, see src/ChangeLog. +For changelog, see src/ChangeLog. -For structure of the sources, see src/project-tree.txt. +For structure of the sources, see src/project-tree.txt. -For code conventions, see src/project-style.txt. +Note that every file within OS/K is written using spaces for tabulation, with each +tabulation being 4 spaces long. diff --git a/src/boot/folder.desc b/boot/folder.desc similarity index 100% rename from src/boot/folder.desc rename to boot/folder.desc diff --git a/src/boot/loader.s b/boot/loader.asm similarity index 100% rename from src/boot/loader.s rename to boot/loader.asm diff --git a/src/boot/loader16.inc b/boot/loader16.inc similarity index 100% rename from src/boot/loader16.inc rename to boot/loader16.inc diff --git a/src/boot/loader64.inc b/boot/loader64.inc similarity index 100% rename from src/boot/loader64.inc rename to boot/loader64.inc diff --git a/src/boot/mbr.s b/boot/mbr.asm similarity index 100% rename from src/boot/mbr.s rename to boot/mbr.asm diff --git a/src/boot/mbr.inc b/boot/mbr.inc similarity index 100% rename from src/boot/mbr.inc rename to boot/mbr.inc diff --git a/bin/disk.img b/build/bin/disk.img similarity index 100% rename from bin/disk.img rename to build/bin/disk.img diff --git a/bin/loader.bin b/build/bin/loader.bin similarity index 100% rename from bin/loader.bin rename to build/bin/loader.bin diff --git a/bin/mbr.bin b/build/bin/mbr.bin similarity index 100% rename from bin/mbr.bin rename to build/bin/mbr.bin diff --git a/src/idttool.py b/build/idttool.py similarity index 100% rename from src/idttool.py rename to build/idttool.py diff --git a/src/kernel.ld b/build/kernel.ld similarity index 74% rename from src/kernel.ld rename to build/kernel.ld index 5768560..e96beb8 100644 --- a/src/kernel.ld +++ b/build/kernel.ld @@ -1,9 +1,9 @@ ENTRY(StartKern) SECTIONS { - . = 0x4000; /* XXX 0x4000 is temporary */ + . = 1M; - .text : AT(ADDR(.text) - 0x4000) + .text : AT(ADDR(.text) - 1M) { _code = .; *(.text) @@ -11,21 +11,21 @@ SECTIONS . = ALIGN(4096); } - .data : AT(ADDR(.data) - 0x4000) + .data : AT(ADDR(.data) - 1M) { _data = .; *(.data) . = ALIGN(4096); } - .eh_frame : AT(ADDR(.eh_frame) - 0x4000) + .eh_frame : AT(ADDR(.eh_frame) - 1M) { _ehframe = .; *(.eh_frame) . = ALIGN(4096); } - .bss : AT(ADDR(.bss) - 0x4000) + .bss : AT(ADDR(.bss) - 1M) { _bss = .; *(.bss) diff --git a/obj/boot/loader.bin b/build/obj/boot/loader.bin similarity index 100% rename from obj/boot/loader.bin rename to build/obj/boot/loader.bin diff --git a/obj/boot/mbr.bin b/build/obj/boot/mbr.bin similarity index 100% rename from obj/boot/mbr.bin rename to build/obj/boot/mbr.bin diff --git a/obj/kaleid/common/.placeholder b/build/obj/kaleid/common/.placeholder similarity index 100% rename from obj/kaleid/common/.placeholder rename to build/obj/kaleid/common/.placeholder diff --git a/obj/kaleid/common/test/.paceholder b/build/obj/kaleid/common/test/.paceholder similarity index 100% rename from obj/kaleid/common/test/.paceholder rename to build/obj/kaleid/common/test/.paceholder diff --git a/obj/kaleid/common/lib/.placeholder b/build/obj/kaleid/kernel/init/.placeholder similarity index 100% rename from obj/kaleid/common/lib/.placeholder rename to build/obj/kaleid/kernel/init/.placeholder diff --git a/obj/kaleid/kernel/io/.placeholder b/build/obj/kaleid/kernel/io/.placeholder similarity index 100% rename from obj/kaleid/kernel/io/.placeholder rename to build/obj/kaleid/kernel/io/.placeholder diff --git a/obj/kaleid/kernel/ke/.placeholder b/build/obj/kaleid/kernel/ke/.placeholder similarity index 100% rename from obj/kaleid/kernel/ke/.placeholder rename to build/obj/kaleid/kernel/ke/.placeholder diff --git a/build/preproc.h b/build/preproc.h new file mode 100644 index 0000000..f690c6e --- /dev/null +++ b/build/preproc.h @@ -0,0 +1,42 @@ +// be careful with this file + +#ifdef _TESTS +# define CCC TCC +#else +# define CCC KCC +#endif + +#ifdef _TO_ASM +# define _CSPREF -S +# define _OUTFIX S +# define LINK_KERNEL(out) +#else +# define _CSPREF -c +# define _OUTFIX o +# define LINK_KERNEL(out) $(KCC) $(CLDSCR) $(COMMOBJS) $(KERNOBJS) -o $(BINDIR)/out +#endif + +#define COMPILE_CONVRT1(file) $(CCC) _CSPREF $(COMMDIR)/itoa.c -o $(COBJDIR)/file._OUTFIX +#define COMPILE_CONVRT2(file) $(CCC) _CSPREF $(COMMDIR)/atoi.c -o $(COBJDIR)/file._OUTFIX + +#define COMPILE_COMMON(file) $(CCC) _CSPREF $(COMMDIR)/file.c -o $(COBJDIR)/file._OUTFIX +#define COMPILE_KERNEL(file) $(KCC) _CSPREF $(KERNDIR)/file.c -o $(KOBJDIR)/file._OUTFIX + +#define COBJ1(x1) $(COBJDIR)/x1.o +#define COBJ2(x1,x2) COBJ1(x1) $(COBJDIR)/x2.o +#define COBJ3(x1,x2,x3) COBJ2(x1,x2) $(COBJDIR)/x3.o +#define COBJ4(x1,x2,x3,x4) COBJ3(x1,x2,x3) $(COBJDIR)/x4.o +#define COBJ5(x1,x2,x3,x4,x5) COBJ4(x1,x2,x3,x4) $(COBJDIR)/x5.o +#define COBJ6(x1,x2,x3,x4,x5,x6) COBJ5(x1,x2,x3,x4,x5) $(COBJDIR)/x6.o +#define COBJ7(x1,x2,x3,x4,x5,x6,x7) COBJ6(x1,x2,x3,x4,x5,x6) $(COBJDIR)/x7.o +#define COBJ8(x1,x2,x3,x4,x5,x6,x7,x8) COBJ7(x1,x2,x3,x4,x5,x6,x7) $(COBJDIR)/x8.o + +#define KOBJ1(x1) $(KOBJDIR)/x1.o +#define KOBJ2(x1,x2) KOBJ1(x1) $(KOBJDIR)/x2.o +#define KOBJ3(x1,x2,x3) KOBJ2(x1,x2) $(KOBJDIR)/x3.o +#define KOBJ4(x1,x2,x3,x4) KOBJ3(x1,x2,x3) $(KOBJDIR)/x4.o +#define KOBJ5(x1,x2,x3,x4,x5) KOBJ4(x1,x2,x3,x4) $(KOBJDIR)/x5.o +#define KOBJ6(x1,x2,x3,x4,x5,x6) KOBJ5(x1,x2,x3,x4,x5) $(KOBJDIR)/x6.o +#define KOBJ7(x1,x2,x3,x4,x5,x6,x7) KOBJ6(x1,x2,x3,x4,x5,x6) $(KOBJDIR)/x7.o +#define KOBJ8(x1,x2,x3,x4,x5,x6,x7,x8) KOBJ7(x1,x2,x3,x4,x5,x6,x7) $(KOBJDIR)/x8.o + diff --git a/src/kaleid/common/arith.c b/kaleid/common/arith.c similarity index 80% rename from src/kaleid/common/arith.c rename to kaleid/common/arith.c index 1d3c740..5ac8338 100644 --- a/src/kaleid/common/arith.c +++ b/kaleid/common/arith.c @@ -21,26 +21,6 @@ long _osk_labs(long x) return labs(x); } -int _osk_min(int x, int y) -{ - return min(x, y); -} - -long _osk_lmin(long x, long y) -{ - return lmin(x, y); -} - -int _osk_max(int x, int y) -{ - return max(x, y); -} - -long _osk_lmax(long x, long y) -{ - return lmax(x, y); -} - div_t _osk_div(int x, int y) { return div(x, y); diff --git a/kaleid/common/atoi.c b/kaleid/common/atoi.c new file mode 100644 index 0000000..f5a22a6 --- /dev/null +++ b/kaleid/common/atoi.c @@ -0,0 +1,37 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: Conversion utilities - atoi family // +//----------------------------------------------------------------------------// + +#include + +// +// String to integer +// Do not change errno +// +#define _ATOI_IMPL(_Name, _Type, _Func) \ + _Type _Name(const char *str) { \ + error_t old = errno; \ + _Type ret = (_Type)_Func(str, NULL, 0); \ + errno = old; \ + return ret; \ + } + + +// ISO C does not allow extra ‘;’ outside of a function +#if defined(_NEED_ATOI) +_ATOI_IMPL(atoi, int, strtol) +#elif defined(_NEED_ATOL) +_ATOI_IMPL(atol, long, strtol) +#elif defined(_NEED_ATOU) +_ATOI_IMPL(atou, uint, strtoul) +#elif defined(_NEED_ATOUL) +_ATOI_IMPL(atoul, ulong, strtoul) +#else +#error "What am I supposed to declare?" +#endif + diff --git a/src/kaleid/common/itoa.c b/kaleid/common/itoa.c similarity index 75% rename from src/kaleid/common/itoa.c rename to kaleid/common/itoa.c index a184e16..e24a41a 100644 --- a/src/kaleid/common/itoa.c +++ b/kaleid/common/itoa.c @@ -10,12 +10,12 @@ #include // -// Digits table for bases <=36 +// Digits table for bases <=36 // -static const char digits[36] = - "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; +static const char digits[] = + "0123456789abcdefghijklmnopqrstuvwxyz"; // -// Integer to string in any base between 2 and 36 (included) +// Integer to string in any base between 2 and 36 (included) // #if defined(_NEED_ITOA) char *itoa(int i, char *str, int base) @@ -26,7 +26,7 @@ char *utoa(uint i, char *str, int base) #elif defined(_NEED_ULTOA) char *ultoa(ulong i, char *str, int base) #else -#error "What am I supposed to declare?" +#error "What am I supposed to declare?" #endif { #if defined(_NEED_ITOA) || defined(_NEED_LTOA) @@ -35,23 +35,32 @@ char *ultoa(ulong i, char *str, int base) char *orig = str; + // + // Only handle base 2 -> 36 + // if (base < 2 || base > 36) return NULL; #if defined(_NEED_ITOA) || defined(_NEED_LTOA) - // deal with negatives + // + // Deal with negatives + // if (i < 0) { neg = 1; i = -i; } #endif - - // deal with zero separately + + // + // Deal with zero separately + // if (i == 0) { *str++ = '0'; } - - // compute digits... in reverse order + + // + // Compute digits... in reverse order + // while (i > 0) { *str++ = digits[i % base]; i /= base; @@ -63,7 +72,10 @@ char *ultoa(ulong i, char *str, int base) *str = '\0'; - return reverse(orig); + // + // Reverse the string + // + return strrev2(orig); } diff --git a/src/kaleid/common/memory.c b/kaleid/common/memory.c similarity index 78% rename from src/kaleid/common/memory.c rename to kaleid/common/memory.c index 59b6cb8..3497a38 100644 --- a/src/kaleid/common/memory.c +++ b/kaleid/common/memory.c @@ -8,25 +8,28 @@ //----------------------------------------------------------------------------// #include -#include //------------------------------------------// // memset() family // //------------------------------------------// // -// Set "bytes"-many bytes starting from ptr to val +// Set "bytes"-many bytes starting from ptr to val // void *memset(void *ptr, int val, size_t bytes) { uchar *uptr = (uchar *)ptr; - - // deal with bytes before start of the first aligned qword + + // + // Deal with bytes before start of the first aligned qword + // while (((ulong)uptr % QWORD_ALIGN) > 0 && bytes--) { *uptr++ = (uchar)val; } - // we're qword-aligned now + // + // At this point we're qword-aligned + // if (bytes > QWORD_SIZE) { const ulong uval = ((ulong)val << 56) | ((ulong)val << 48) | ((ulong)val << 40) | ((ulong)val << 32) @@ -34,19 +37,23 @@ void *memset(void *ptr, int val, size_t bytes) | ((ulong)val << 8) | ((ulong)val); ulong *uqptr = (ulong *)ptr; - - // move qword by qword + + // + // Moving fast, qword by qword + // while (bytes > QWORD_SIZE) { *uqptr++ = uval; bytes -= QWORD_SIZE; } - + uptr = (uchar *)(ulong)uqptr; } - - // deal with what's left + + // + // Deal with the few remaining bytes + // while (bytes--) *uptr++ = (uchar)val; - + return ptr; } @@ -56,37 +63,38 @@ void *memset(void *ptr, int val, size_t bytes) void *memsetw(void *ptr, int val, size_t words) { ushort *uptr = (ushort *)ptr; - - // can't we do this an aligned way? + + // + // Check whether we can we do this an aligned way + // if unlikely (((ulong)uptr % WORD_ALIGN) > 0) { + // + // We can't, so we write word by word all the way up + // while (words--) *uptr++ = (ushort)val; return uptr; } - - // deal with words before start of the first aligned qword + while (((ulong)uptr % QWORD_ALIGN) > 0 && words--) { *uptr++ = (ushort)val; } - // we're aligned for sure if (words > QWORDS_TO_WORDS(1)) { const ulong uval = ((ulong)val << 48) | ((ulong)val << 32) | ((ulong)val << 16) | ((ulong)val); ulong *uqptr = (ulong *)uptr; - // move qword by qword while (words > QWORDS_TO_WORDS(1)) { words -= QWORDS_TO_WORDS(1); *uqptr++ = uval; } - + uptr = (ushort *)(ulong)uqptr; } - - // deal with what's left + while (words--) *uptr++ = (ushort)val; - + return ptr; } @@ -108,18 +116,21 @@ void *memsetd(void *ptr, int val, size_t dwords) void *memsetq(void *ptr, long val, size_t qwords) { ulong *uptr = (ulong *)ptr; - + + // + // There's no need to check for alignment + // while (qwords--) *uptr++ = (ulong)val; - + return ptr; } +//------------------------------------------// +// Other mem*() functions // +//------------------------------------------// + // // Set "bytes"-many bytes starting from ptr to 0 -// -// WARNING -// Assume "bytes" is large, for small sizes -// use memset(ptr, 0, bytes) directly // void *memzero(void *ptr, size_t bytes) { @@ -130,19 +141,24 @@ void *memzero(void *ptr, size_t bytes) // Copy "bytes"-many bytes of src to dst // Does not deal with overlapping blocks (memmove's job) // -void *memcpy(void *dst, const void *src, size_t bytes) +void *memcpy(void *restrict dst, const void *restrict src, size_t bytes) { const ulong *usrc = (const ulong *)src; ulong *udst = (ulong *)dst; - + if unlikely (bytes == 0) return dst; - // can we align them both at once? + // + // Can align both src and dst at once at once? + // if unlikely ((ulong)src % WORD_ALIGN == 1 && (ulong)dst % WORD_ALIGN == 1) { const uchar *ubsrc = (const uchar *)usrc; uchar *ubdst = (uchar *)udst; + // + // Yes we can, we're guaranteed to be word-aligned now + // *ubdst++ = *ubsrc++; bytes--; @@ -153,7 +169,9 @@ void *memcpy(void *dst, const void *src, size_t bytes) const ushort *uwsrc = (const ushort *)usrc; ushort *uwdst = (ushort *)udst; - // align either dst or src for qword access + // + // Align either dst or src for qword access + // while ((ulong)dst % QWORD_ALIGN > 0 && (ulong)src % QWORD_ALIGN > 0 && bytes > WORD_SIZE) { @@ -165,7 +183,9 @@ void *memcpy(void *dst, const void *src, size_t bytes) udst = (ulong *)uwdst; usrc = (ulong *)uwsrc; - // should be most of the job + // + // This should be most of the job + // while (bytes > QWORD_SIZE) { *udst++ = *usrc++; bytes -= QWORD_SIZE; @@ -174,26 +194,32 @@ void *memcpy(void *dst, const void *src, size_t bytes) const uchar *ubsrc = (const uchar *)usrc; ushort *ubdst = (ushort *)udst; - // deal with what's left + // + // Deal with the few bytes left + // while (bytes--) *ubdst ++ = *ubsrc++; return dst; } // -// Move memory from src to dest -// To be made more efficient +// Move memory from src to dest, even if they overlap // void *memmove(void *dst, const void *src, size_t bytes) { const uchar *usrc = src; uchar *udst = dst; + // + // Can we use memcpy() safely? + // if (udst < usrc) { - while (bytes--) *udst++ = *usrc++; - return dst; + return memcpy(dst, src, bytes); } + // + // No, so we go backwards + // uchar *usrc_end = (uchar *)usrc + bytes - 1; uchar *udst_end = udst + bytes - 1; while (bytes--) *udst_end-- = *usrc_end--; diff --git a/src/kaleid/common/rand.c b/kaleid/common/rand.c similarity index 87% rename from src/kaleid/common/rand.c rename to kaleid/common/rand.c index 5569792..fe576ef 100644 --- a/src/kaleid/common/rand.c +++ b/kaleid/common/rand.c @@ -8,16 +8,15 @@ //----------------------------------------------------------------------------// #include -#include // -// Seed value +// Seed value // static ulong next = 7756; // -// Returns a pseudo-random integer -// To be improved +// Returns a pseudo-random integer +// To be improved // int rand(void) { @@ -26,7 +25,7 @@ int rand(void) } // -// (Re)Set the random seed +// (Re)Set the random seed // void srand(uint seed) { diff --git a/src/kaleid/common/sprintf.c b/kaleid/common/sprintf.c similarity index 78% rename from src/kaleid/common/sprintf.c rename to kaleid/common/sprintf.c index 8a4e1f5..a8dd3ba 100644 --- a/src/kaleid/common/sprintf.c +++ b/kaleid/common/sprintf.c @@ -10,17 +10,17 @@ #include // -// Format str according to fmt using ellipsed arguments +// Format str according to fmt using ellipsed arguments // int sprintf(char *str, const char *fmt, ...) { int ret; va_list ap; - + va_start(ap); ret = vsnprintf(str, SIZE_T_MAX, fmt, ap); va_end(ap); - + return ret; } @@ -30,39 +30,45 @@ int vsprintf(char *str, const char *fmt, va_list ap) } // -// (v)sprintf() but with a size limit: no more than n bytes are written in str -// XXX null termination behavior? +// (v)sprintf() but with a size limit: no more than n bytes are written in str // int snprintf(char *str, size_t n, const char *fmt, ...) { int ret; va_list ap; - + va_start(ap); ret = vsnprintf(str, n, fmt, ap) va_end(ap); - + return ret; } int vsnprintf(char *str, size_t n, const char *fmt, va_list ap) { int ret = 0; - - while (*fmt && ret < n) { + + // + // Go throught the format string + // + while (*fmt) { if (*fmt != '%') { - *str++ = *fmt++; - ret++; + // + // Even if we don't have any more room we still increase ret + // + if (ret++ < n) { + *str++ = *fmt++; + } continue; } - + switch (*fmt) { case 'd': default: break; } } - + return ret; } diff --git a/src/kaleid/common/status.c b/kaleid/common/status.c similarity index 97% rename from src/kaleid/common/status.c rename to kaleid/common/status.c index c5139fe..457e741 100644 --- a/src/kaleid/common/status.c +++ b/kaleid/common/status.c @@ -9,6 +9,9 @@ #include +error_t errno = 0; + +/* static const char *descriptions[] = { [-SUCCESS] = "Success", [-FAILED] = "Failed (no precision)", @@ -28,4 +31,4 @@ const char *describe_status(status_t status) // XXX return ""; } - +*/ diff --git a/kaleid/common/string.c b/kaleid/common/string.c new file mode 100644 index 0000000..fafaf89 --- /dev/null +++ b/kaleid/common/string.c @@ -0,0 +1,301 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: String-related functions // +//----------------------------------------------------------------------------// + + +#include + +// +// Compare two strings +// +int strcmp(const char *str1, const char *str2) +{ + while (*str1 == *str2 && *str2) str1++, str2++; + + return *(uchar *)str1 - *(uchar *)str2; +} + +// +// Compare at most n bytes of two strings +// +int strncmp(const char *str1, const char *str2, size_t n) +{ + size_t it = 0; + + while (*str1 == *str2 && *str2 && it < n) str1++, str2++, it++; + + return *(uchar *)str1 - *(uchar *)str2; +} + +// +// Return str's length +// +size_t strlen(const char *str) +{ + const char *base = str; + + while (*str) str++; + + return str - base; +} + +// +// Return a pointer to the first occurence of ch in str, +// or str's null-terminator if none is found +// +char *strchrnul(const char *str, int ch) +{ + while ((*str && *str != (char)ch)) str++; + + return (char *)str; +} + +// +// Return a pointer to the first occurence of ch in str, +// NULL if none is found +// +char *strchr(const char *str, int ch) +{ + while ((*str && *str != (char)ch)) str++; + + return *str ? (char *)str : NULL; +} + +// +// Return a point to the last occurence of ch in str, +// NULL if none is found +// +char *strrchr(const char *str, int ch) +{ + char *ptr = NULL; + + while (*str) { + if (*str == ch) { + ptr = (char *)str; + } + str++; + } + + return ptr; +} + +// +// Return the length of the longest inital segment of str +// that only contains characters in acc +// +size_t strspn(const char *str, const char *acc) +{ + const char *ptr = str; + + while (*ptr && strchr(acc, *ptr) != NULL) ptr++; + + return ptr - str; +} + +// +// Return the length of the longest initial segment of str +// that does not contain any character in rej +// +size_t strcspn(const char *str, const char *rej) +{ + const char *ptr = str; + + while (*ptr && strchr(rej, *ptr) == NULL) ptr++; + + return ptr - str; +} + +// +// Return the first occurence in str of any byte in acc +// +char *strpbrk(const char *str, const char *acc) +{ + str += strcspn(str, acc); + + return *str ? (char *)str : NULL; +} + +// +// Return the first occurence of the substring needle +// in the string haystack, NULL if none is found +// Null-terminators aren't compared +// +char *strstr(const char *haystack, const char *needle) +{ + const size_t needle_size = strlen(needle); + + // + // Moves haystack to first occurence of the needle's first byte + // + while ((haystack = strchr(haystack, *needle)) != NULL) { + if (strncmp(haystack, needle, needle_size) == 0) { + return (char *)haystack; + } + } + + return NULL; +} + +// +// Tokenize a string, using saveptr as a savestate +// We let a segmentation fault happen if *saveptr == NULL +// +char *strtok_r(char *restrict str, const char *restrict delim, char **restrict saveptr) +{ + assert(*saveptr != NULL); + + if (str == NULL) str = *saveptr; + + // + // Skip initial segments composed only of delimiters + // + str += strspn(str, delim); + + // + // If str is empty, store it in saveptr so that next call + // still finds an empty strings and returns NULL + // + if (*str == 0) { + *saveptr = str; + return NULL; + } + + char *ptr = str, *tok_end = strpbrk(str, delim); + + // + // If we found the last token, set *saveptr to a str's null-terminator + // Otherwise, null-terminate token and save next byte + // + + if (tok_end == NULL) { + while (*ptr) ptr++; + *saveptr = ptr; + } + + else { + *tok_end = 0; + *saveptr = tok_end + 1; + } + + return str; +} + +// +// Tokenize a string in a very thread-unsafe way +// +char *strtok(char *restrict str, const char *restrict delim) +{ + static char *saveptr = NULL; + + KalAssert(FALSE); + + if (str) saveptr = str; + + return strtok_r(str, delim, &saveptr); +} + +// +// Copy the string src into dest +// +char *strcpy(char *restrict dest, const char *restrict src) +{ + char *base = dest; + + while ((*dest++ = *src++)); + + return base; +} + +// +// strcpy() but always writes n bytes +// Will not null-terminate for strings longer than n bytes +// +char *strncpy(char *restrict dest, const char *restrict src, size_t n) +{ + size_t it; + + for (it = 0; it < n && src[it]; it++) { + dest[it] = src[it]; + } + + while (it < n) dest[it++] = 0; + + return dest; +} + +// +// Copies at most n-1 bytes from src to dest, then fills +// the rest with 0; dest[n] is guanranteed to be '\0' +// +// Returns TRUE if dest would have been null-terminated +// by ordinary strncpy(), and FALSE otherwise +// +int xstrncpy(char *restrict dest, const char *restrict src, size_t n) +{ + size_t it; + + for (it = 0; it < n - 1 && src[it]; it++) { + dest[it] = src[it]; + } + + // + // Was the copy complete? + // + if (it == n) { + if (dest[n] == 0) { + return TRUE; + } + + dest[n] = 0; + return FALSE; + } + + while (it < n) dest[it++] = 0; + + return TRUE; +} + +// +// XXX strcat family +// +char *strcat (char *restrict, const char *restrict); +char *strncat (char *restrict, const char *restrict, size_t); +int *xstrncat(char *restrict, const char *restrict, size_t); + +// +// Reverses the string src, putting the result into dest +// +char *strrev(char *restrict dest, const char *restrict src) +{ + char *orig = dest; + size_t n = strlen(src); + + dest[n--] = '\0'; + + while ((*dest++ = src[n--])); + + return orig; +} + +// +// Reverses a string, modifying it +// +char *strrev2(char *str) +{ + char ch, *orig = str; + size_t n = strlen(str); + char *temp = str + n - 1; + + while (temp > str) { + ch = *temp; + *temp-- = *str; + *str++ = ch; + } + + return orig; +} diff --git a/src/kaleid/kernel/io/ports.c b/kaleid/common/strtol.c similarity index 62% rename from src/kaleid/kernel/io/ports.c rename to kaleid/common/strtol.c index 3f44417..2e1aad6 100644 --- a/src/kaleid/kernel/io/ports.c +++ b/kaleid/common/strtol.c @@ -4,10 +4,24 @@ // Authors: spectral` // // NeoX // // // -// Desc: Ports I/O // +// Desc: strto(u)l functions // //----------------------------------------------------------------------------// -#include +#include +long strtol(const char *str, char **endp, int base) { + (void)str; + (void)endp; + (void)base; + errno = ENOSYS; + return 0; +} +ulong strtoul(const char *str, char **endp, int base) { + (void)str; + (void)endp; + (void)base; + errno = ENOSYS; + return 0; +} diff --git a/src/kaleid/include/kalassrt.h b/kaleid/include/common/kalassrt.h similarity index 70% rename from src/kaleid/include/kalassrt.h rename to kaleid/include/common/kalassrt.h index 3c99b2d..cf4ddbb 100644 --- a/src/kaleid/include/kalassrt.h +++ b/kaleid/include/common/kalassrt.h @@ -18,27 +18,57 @@ #define noreturn __attribute__((__noreturn__)) #endif -#ifndef unlikely(x) +#ifndef unlikely #define unlikely(x) (__builtin_expect((x), 0)) #endif +#ifndef static_assert +#define static_assert _Static_assert +#endif + +//------------------------------------------// +// API compatibility checks // +//------------------------------------------// + +#define _SA_MSG "Incompatible type sizes" +static_assert(sizeof(char) == 1, _SA_MSG); +static_assert(sizeof(short) == 2, _SA_MSG); +static_assert(sizeof(int) == 4, _SA_MSG); +static_assert(sizeof(long) == 8, _SA_MSG); +static_assert(sizeof(void *) == 8, _SA_MSG); +#undef _SA_MSG + //------------------------------------------// // When debugging // //------------------------------------------// #if !defined(_NO_DEBUG) && !defined(NDEBUG) && !defined(assert) +#ifdef _OSK_SOURCE + // -// Failed assert handler +// Failed assert handler // noreturn void _assert_handler(const char *, const char *, int, const char *); +// +// Checks whether (x) holds, if not call _assert_handler +// #define assert(x) \ do { \ - if unlikely(!(x)) \ + if unlikely (!(x)) \ _assert_handler(#x, __FILE__, __LINE__, __func__); \ } while (0); +#else + +// +// When not building for OS/K, use the system's assert +// +#include + +#endif + //------------------------------------------// // When not debugging // //------------------------------------------// @@ -54,7 +84,7 @@ noreturn void _assert_handler(const char *, const char *, int, const char *); #endif #ifndef assert -#define assert(x) +#define assert(x) ((void)0) #endif #endif @@ -72,7 +102,7 @@ noreturn void _assert_handler(const char *, const char *, int, const char *); #endif //------------------------------------------// -// End of // +// End of header // //------------------------------------------// #endif diff --git a/src/kaleid/include/kalcrt.h b/kaleid/include/common/kalcrt.h similarity index 61% rename from src/kaleid/include/kalcrt.h rename to kaleid/include/common/kalcrt.h index 534533b..75e34e1 100644 --- a/src/kaleid/include/kalcrt.h +++ b/kaleid/include/common/kalcrt.h @@ -14,31 +14,37 @@ // Typedefs // //------------------------------------------// -#ifndef __size_t -#define __size_t +#ifndef __error_t_defined +#define __error_t_defined +typedef int error_t; +#endif + +#ifndef __size_t_defined +#define __size_t_defined typedef unsigned long size_t; #endif -#ifndef __status_t -#define __status_t -typedef signed long status_t; -#endif - -#ifndef __va_list -#define __va_list +#ifndef __va_list_defined +#define __va_list_defined typedef __builtin_va_list va_list; #endif -#ifndef __div_t -#define __div_t +#ifndef __div_t_defined +#define __div_t_defined typedef struct { int quot, rem; } div_t; #endif -#ifndef __ldiv_t -#define __ldiv_t +#ifndef __ldiv_t_defined +#define __ldiv_t_defined typedef struct { long quot, rem; } ldiv_t; #endif +//------------------------------------------// +// Global variables // +//------------------------------------------// + +extern error_t errno; + //------------------------------------------// // Macros // //------------------------------------------// @@ -59,8 +65,8 @@ typedef struct { long quot, rem; } ldiv_t; #define va_arg __builtin_va_arg #endif -#ifndef va_next -#define va_next __builtin_va_next +#ifndef va_copy +#define va_copy __builtin_va_copy #endif #ifndef va_end @@ -89,7 +95,9 @@ void *memchrw(const void *, int, size_t); void *memchrd(const void *, int, size_t); void *memchrq(const void *, long, size_t); -void *memcpy(void *, const void *, size_t); +void *memrchr(const void *, int, size_t); + +void *memcpy(void *restrict, const void *restrict, size_t); void *memmove(void *, const void *, size_t); void *memzero(void *, size_t); @@ -99,11 +107,33 @@ int memcmp(const void *, const void *, size_t); // String manipulation utilities // //------------------------------------------// -size_t strlen(const char *); -char *strcpy(char *, const char *); -char *strncpy(char *, const char *, size_t); -char *strrev(char *, const char *); -char *reverse(char *); +size_t strlen(const char *); +size_t strspn(const char *, const char *); +size_t strcspn(const char *, const char *); + +int strcmp(const char *, const char *); +int strncmp(const char *, const char *, size_t); + +char *strchr(const char *, int); +char *strrchr(const char *, int); +char *strchrnul(const char *, int); + +char *strstr(const char *, const char *); +char *strpbrk(const char *, const char *); + +char *strtok(char *restrict, const char *restrict); +char *strtok_r(char *restrict, const char *restrict, char **restrict); + +char *strcpy (char *restrict, const char *restrict); +char *strncpy (char *restrict, const char *restrict, size_t); +int xstrncpy(char *restrict, const char *restrict, size_t); + +char *strcat (char *restrict, const char *restrict); +char *strncat (char *restrict, const char *restrict, size_t); +int *xstrncat(char *restrict, const char *restrict, size_t); + +char *strrev(char *restrict, const char *restrict); +char *strrev2(char *); int sprintf(char *, const char *, ...); int snprintf(char *, size_t, const char *, ...); @@ -111,20 +141,21 @@ int vsprintf(char *, const char *, va_list); int vsnprintf(char *, size_t, const char *, va_list); //------------------------------------------// -// Type conversion utilities // +// Type conversion utilities // //------------------------------------------// -int *atoi(const char *); -long *atol(const char *); - char *itoa(int, char *, int); char *ltoa(long, char *, int); - char *utoa(unsigned int, char *, int); char *ultoa(unsigned long, char *, int); -long strtol(const char *, char **, int); -unsigned long strtoul(const char *, char **, int); +int atoi(const char *); +long atol(const char *); +unsigned int atou(const char *); +unsigned long atoul(const char *); + +long strtol (const char *restrict, char **restrict, int); +unsigned long strtoul(const char *restrict, char **restrict, int); //------------------------------------------// // RNG utilities // @@ -133,38 +164,35 @@ unsigned long strtoul(const char *, char **, int); int rand(void); void srand(unsigned int); +//------------------------------------------// +// Time utilities // +//------------------------------------------// + //------------------------------------------// // Diverse utilities // //------------------------------------------// -const char *describe_status(status_t) _NO_MASK; +char *strerror(int); +char *strsignal(int); //------------------------------------------// // Arithmetical macros // //------------------------------------------// -#ifndef abs -#define abs(x) ((x) < 0 ? -x : x) +#ifndef __abs +#define __abs +static inline int abs(int x) +{ + return x < 0 ? -x : x; +} #endif -#ifndef labs -#define labs(x) ((x) < 0 ? -x : x) -#endif - -#ifndef min -#define min(x,y) ((x) < (y) ? (x) : (y)) -#endif - -#ifndef lmin -#define lmin(x,y) ((x) < (y) ? (x) : (y)) -#endif - -#ifndef max -#define max(x,y) ((x) < (y) ? (x) : (y)) -#endif - -#ifndef lmax -#define lmax(x,y) ((x) < (y) ? (x) : (y)) +#ifndef __labs +#define __labs +static inline long labs(long x) +{ + return x < 0 ? -x : x; +} #endif #ifndef __div @@ -190,7 +218,7 @@ static inline ldiv_t ldiv(long __x, long __y) #endif //------------------------------------------// -// End of // +// End of header // //------------------------------------------// #endif diff --git a/src/kaleid/include/kaldefs.h b/kaleid/include/common/kaldefs.h similarity index 71% rename from src/kaleid/include/kaldefs.h rename to kaleid/include/common/kaldefs.h index 7341804..9dbf1be 100644 --- a/src/kaleid/include/kaldefs.h +++ b/kaleid/include/common/kaldefs.h @@ -31,13 +31,36 @@ #endif //------------------------------------------// -// Keywords and attributes // +// Keywords // //------------------------------------------// -#ifndef alignof +#ifndef __alignof_is_defined +#define __alignof_is_defined #define alignof _Alignof #endif +#ifndef __alignas_is_defined +#define __alignas_is_defined +#define alignas _Alignas +#endif + +#ifndef __bool_true_false_are_defined +#define __bool_true_false_are_defined +# define bool _Bool +# define true 1 +# define false 0 +# ifndef TRUE +# define TRUE 1 +# endif +# ifndef FALSE +# define FALSE 0 +# endif +#endif + +//------------------------------------------// +// Attributes and macros // +//------------------------------------------// + #ifndef PACKED #define PACKED __attribute__((__packed__)) #endif @@ -50,7 +73,7 @@ #define likely(x) (__builtin_expect((x), 1)) #endif -#ifndef unlikely(x) +#ifndef unlikely #define unlikely(x) (__builtin_expect((x), 0)) #endif @@ -63,27 +86,7 @@ #endif //------------------------------------------// -// Values for 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 - -//------------------------------------------// -// End of // +// End of header // //------------------------------------------// #endif diff --git a/kaleid/include/common/kalerror.h b/kaleid/include/common/kalerror.h new file mode 100644 index 0000000..ce8b2c4 --- /dev/null +++ b/kaleid/include/common/kalerror.h @@ -0,0 +1,63 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: Values for errno_t and errno // +//----------------------------------------------------------------------------// + +#ifndef _KALERROR_H +#define _KALERROR_H + +//------------------------------------------// +// Preprocessor constants // +//------------------------------------------// + +// Everything went fine +#define EOK 0 + +// Operation not permitted +#define EPERM 1 + +// No such file or directory +#define ENOENT 2 + +// No such process +#define ESRCH 3 + +// Syscall interrupted (e.g. by signal) +#define EINTR 4 + +// I/0 error +#define EIO 5 + +// No such device or address +#define ENXIO 6 + +// Argument list too long +#define E2BIG 7 + +// Not an executable format +#define ENOEXEC 8 + +// Bad file number +#define EBADF 9 + +// Invalid argument +#define EINVAL 22 + +// Functionality not implemented +#define ENOSYS 38 + +// Component crashed +#define ECRASH 500 + +// System is panicking +#define EPANIC 600 + +//------------------------------------------// +// End of header // +//------------------------------------------// + +#endif diff --git a/src/kaleid/include/kallims.h b/kaleid/include/common/kallims.h similarity index 95% rename from src/kaleid/include/kallims.h rename to kaleid/include/common/kallims.h index ac5b158..9afd35d 100644 --- a/src/kaleid/include/kallims.h +++ b/kaleid/include/common/kallims.h @@ -8,6 +8,7 @@ //----------------------------------------------------------------------------// #ifndef _KALLIMS_H +#define _KALLIMS_H //------------------------------------------// // Data sizes blocks // @@ -85,10 +86,10 @@ #define DATA_CHAR_LIMITS_BLOCK # ifdef __CHAR_UNSIGNED__ # define CHAR_MIN ((char)0) -# define CHAR_MAX UCHAR_MAX +# define CHAR_MAX ((char)UCHAR_MAX) # else -# define CHAR_MIN SCHAR_MIN -# define CHAR_MAX SCHAR_MAX +# define CHAR_MIN ((char)SCHAR_MIN) +# define CHAR_MAX ((char)SCHAR_MAX) # endif #endif @@ -110,7 +111,7 @@ #endif //------------------------------------------// -// End of // +// End of header // //------------------------------------------// #endif diff --git a/kaleid/include/common/kallist.h b/kaleid/include/common/kallist.h new file mode 100644 index 0000000..96c5f9d --- /dev/null +++ b/kaleid/include/common/kallist.h @@ -0,0 +1,271 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: Doubly linked lists implementation // +//----------------------------------------------------------------------------// + +#ifndef _KALLIST_H +#define _KALLIST_H + +#ifdef _KALEID_KERNEL +#error "kallist.h - Not ready for kernel compilation" +#endif + +#ifndef _KALASSRT_H +#include +#endif + +#ifndef _KALKERN_LOCKS_H +#include +#endif + +// +// XXX ¯\_(ツ)_/¯ +// +void *malloc(long); +void free(void *); + +#define AllocMemory malloc +#define FreeMemory free + +//------------------------------------------// +// Data structures // +//------------------------------------------// + +typedef struct sListHead_t { + Lock_t *lock; + unsigned long length; + struct sListNode_t *first; + struct sListNode_t *last; +} ListHead_t; + +typedef struct sListNode_t { + void *data; + ListHead_t *head; + struct sListNode_t *prev; + struct sListNode_t *next; +} ListNode_t; + +//------------------------------------------// +// Functions // +//------------------------------------------// + +// +// Create a list head with an extern lock +// +static inline ListHead_t +*CreateListHeadWithLock(Lock_t *lock) +{ + ListHead_t *head = AllocMemory(sizeof(ListHead_t)); + + if (head == NULL) return NULL; + + head->first = head->last = NULL; + head->length = 0; + + head->lock = lock; + + return head; +} + +// +// Create a liste head +// +static inline ListHead_t +*CreateListHead(void) +{ + return CreateListHeadWithLock(NULL); +} + +// +// Create a node +// +static inline ListNode_t +*CreateNode(void *data) +{ + ListNode_t *node = AllocMemory(sizeof(ListNode_t)); + + if (node == NULL) return NULL; + + node->data = data; + node->head = NULL; + node->prev = node->next = NULL; + + return node; +} + +// +// Prepend node at beginning of list +// +static inline ListHead_t +*PrependNode(ListHead_t *head, ListNode_t *node) +{ + KalAssert(head && node); + + node->head = head; + node->prev = NULL; + + if (head->length > 0) { + node->next = head->first; + head->first->prev = node; + head->first = node; + } + + else { + head->first = node; + head->last = node; + node->next = NULL; + } + + head->length++; + + return head; +} + +// +// Append node at end of list +// +static inline ListHead_t +*AppendNode(ListHead_t *head, ListNode_t *node) +{ + KalAssert(head && node); + + node->head = head; + node->next = NULL; + + if (head->length > 0) { + node->prev = head->last; + head->last->next = node; + head->last = node; + } + + else { + head->first = node; + head->last = node; + node->prev = NULL; + } + + head->length++; + + return head; +} + +// +// Insert node2 before node1 +// +static inline ListHead_t +*AddNodeBefore(ListHead_t *head, ListNode_t *node1, ListNode_t *node2) +{ + KalAssert(head && node1 && node2 && node1->head == head); + + if (head->first == node1) { + return PrependNode(head, node2); + } + + node2->head = head; + node2->next = node1; + node2->prev = node1->prev; + + // node1->prev does exist + // or node1 would be first + node1->prev->next = node2; + node1->prev = node2; + + head->length++; + + return head; +} + +// +// Insert node2 after node1 +// +static inline ListHead_t +*AddNodeAfter(ListHead_t *head, ListNode_t *node1, ListNode_t *node2) +{ + KalAssert(head && node1 && node2 && node1->head == head); + + if (head->last == node1) { + return AppendNode(head, node2); + } + + node2->head = head; + node2->prev = node1; + node2->next = node1->next; + + node1->next->prev = node2; + node1->next = node2; + + head->length++; + + return head; +} + +// +// Remove node of list +// +static inline ListHead_t +*RemoveNode(ListHead_t *head, ListNode_t *node) +{ + KalAssert(head && node && head->length > 0 && node->head == head); + + if (head->length == 1) { + head->first = head->last = NULL; + goto leave; + } + + if (head->first == node) { + head->first = node->next; + node->next->prev = NULL; + } + + else if (head->last == node) { + head->last = node->prev; + node->prev->next = NULL; + } + + else { + node->prev->next = node->next; + node->next->prev = node->prev; + } + +leave: + head->length--; + FreeMemory(node); + + return head; +} + +// +// Free a node +// +static inline void +DestroyNode(ListNode_t *node) +{ + KalAssert(node); + FreeMemory(node); +} + +// +// Free a list head +// +static inline void +DestroyListHead(ListHead_t *head) +{ + KalAssert(head); + FreeMemory(head); +} + +// +// Access a node's data +// +#define GetNodeData(node, type) ((type)(node)->data) + +//------------------------------------------// +// End of header // +//------------------------------------------// + +#endif + diff --git a/src/kaleid/include/kalmask.h b/kaleid/include/common/kalmask.h similarity index 77% rename from src/kaleid/include/kalmask.h rename to kaleid/include/common/kalmask.h index 5c9870e..0295bd0 100644 --- a/src/kaleid/include/kalmask.h +++ b/kaleid/include/common/kalmask.h @@ -34,10 +34,31 @@ //------------------------------------------// #define strlen _osk_strlen +#define strspn _osk_strspn +#define strcspn _osk_strcspn + +#define strcmp _osk_strcmp +#define strncmp _osk_strncmp + +#define strchr _osk_strchr +#define strrchr _osk_strrchr + +#define strstr _osk_strstr +#define strpbrk _osk_strpbrk + +#define strtok _osk_strtok +#define strtok_r _osk_strtok_r + #define strcpy _osk_strcpy #define strncpy _osk_strncpy +#define xstrncpy _osk_xstrncpy + +#define strcat _osk_strcat +#define strncat _osk_strncat +#define xstrncat _osk_xstrncat + #define strrev _osk_strrev -#define reverse _osk_reverse +#define strrev2 _osk_strrev2 #define sprintf _osk_sprintf #define snprintf _osk_snprintf @@ -46,15 +67,17 @@ //------------------------------------------// -#define atoi _osk_atoi -#define atol _osk_atol #define itoa _osk_itoa #define ltoa _osk_ltoa - #define utoa _osk_utoa #define ultoa _osk_ultoa +#define atoi _osk_atoi +#define atol _osk_atol +#define atou _osk_atou +#define atoul _osk_atoul + #define strtol _osk_strtol #define strtoul _osk_strtoul @@ -81,7 +104,11 @@ #define ldiv _osk_ldiv //------------------------------------------// -// End of // + +#define strerror _osk_strerror + +//------------------------------------------// +// End of header // //------------------------------------------// #endif diff --git a/src/kaleid/include/kaltypes.h b/kaleid/include/common/kaltypes.h similarity index 59% rename from src/kaleid/include/kaltypes.h rename to kaleid/include/common/kaltypes.h index 6814644..6823ddb 100644 --- a/src/kaleid/include/kaltypes.h +++ b/kaleid/include/common/kaltypes.h @@ -27,45 +27,74 @@ typedef long double ldouble; #endif //------------------------------------------// -// Other standard integer types // +// Miscellaneous types // //------------------------------------------// -#ifndef __size_t -#define __size_t +#ifndef __size_t_defined +#define __size_t_defined typedef unsigned long size_t; #endif -#ifndef __ssize_t -#define __ssize_t +#ifndef __ssize_t_defined +#define __ssize_t_defined typedef signed long ssize_t; #endif -#ifndef __wchar_t -#define __wchar_t +#ifndef __wchar_t_defined +#define __wchar_t_defined typedef signed int wchar_t; #endif -#ifndef __off_t -#define __off_t +#ifndef __off_t_defined +#define __off_t_defined typedef unsigned long off_t; #endif +//------------------------------------------// +// Standard fixed-width integer types // +//------------------------------------------// + +#ifndef __ptrdiff_t_defined +#define __ptrdiff_t_defined +typedef signed long ptrdiff_t; +#endif + +#ifndef __intptr_t_defined +#define __intptr_t_defined +typedef signed long intptr_t; +#endif + +#ifndef __uintptr_t_defined +#define __uintptr_t_defined +typedef unsigned long uintptr_t; +#endif + +#ifndef __intmax_t_defined +#define __intmax_t_defined +typedef signed long intmax_t; +#endif + +#ifndef __uintmax_t_defined +#define __uintmax_t_defined +typedef unsigned long uintmax_t; +#endif + //------------------------------------------// // Special types // //------------------------------------------// -#ifndef __va_list -#define __va_list -typedef __builtin_va_list va_list; +#ifndef __va_list_defined +#define __va_list_defined +typedef __builtin_va_list va_list; #endif -#ifndef __div_t -#define __div_t +#ifndef __div_t_defined +#define __div_t_defined typedef struct { int quot, rem; } div_t; #endif -#ifndef __ldiv_t -#define __ldiv_t +#ifndef __ldiv_t_defined +#define __ldiv_t_defined typedef struct { long quot, rem; } ldiv_t; #endif @@ -74,13 +103,18 @@ typedef struct { long quot, rem; } ldiv_t; // Kaleid-specific types // //------------------------------------------// -#ifndef __status_t -#define __status_t -typedef signed long status_t; +#ifndef __error_t_defined +#define __error_t_defined +typedef int error_t; +#endif + +#ifndef __port_t_defined +#define __port_t_defined +typedef ushort port_t; #endif //------------------------------------------// -// End of // +// End of header // //------------------------------------------// #endif diff --git a/src/kaleid/include/kaleid.h b/kaleid/include/kaleid.h similarity index 59% rename from src/kaleid/include/kaleid.h rename to kaleid/include/kaleid.h index a46f317..da81fce 100644 --- a/src/kaleid/include/kaleid.h +++ b/kaleid/include/kaleid.h @@ -22,32 +22,74 @@ #if !defined(_OSK_SOURCE) # ifndef _KALMASK_H -# include +# include # endif #endif +//------------------------------------------// +// Building in C++ // +//------------------------------------------// + +#ifdef __cplusplus__ +extern "C" { +#endif + //------------------------------------------// // Include common part of API // //------------------------------------------// #ifndef _KALDEFS_H -#include +#include +#endif + +#ifndef _KALERROR_H +#include #endif #ifndef _KALTYPES_H -#include +#include +#endif + +#ifndef _KALLIMS_H +#include #endif #ifndef _KALASSRT_H -#include +#include #endif #ifndef _KALCRT_H -#include +#include #endif //------------------------------------------// -// End of // +// Include kernel headers // +//------------------------------------------// + +#ifdef _KALEID_KERNEL + +#ifndef _KALKERN_H +#include +#endif + +#else + +#ifndef _KALKERN_LOCKS_H +#include +#endif + +#endif + +//------------------------------------------// +// Building in C++ // +//------------------------------------------// + +#ifdef __cplusplus__ +} +#endif + +//------------------------------------------// +// End of header // //------------------------------------------// #endif diff --git a/src/kaleid/include/kalkern.h b/kaleid/include/kalkern.h similarity index 72% rename from src/kaleid/include/kalkern.h rename to kaleid/include/kalkern.h index 40f0625..df15c7d 100644 --- a/src/kaleid/include/kalkern.h +++ b/kaleid/include/kalkern.h @@ -7,9 +7,6 @@ // Desc: Kaleid Kernel main include file // //----------------------------------------------------------------------------// -#ifndef _KALKERN_H -#define _KALKERN_H - //------------------------------------------// // Dependencies // //------------------------------------------// @@ -18,20 +15,31 @@ #include #endif -#ifndef _KALKERN_CONFIG_H -#include +//------------------------------------------// +// Start of header // +//------------------------------------------// + +#ifndef _KALKERN_H +#define _KALKERN_H + +//------------------------------------------// +// Kernel headers // +//------------------------------------------// + +#ifndef _KALKERN_BASE_H +#include +#endif + +#ifndef _KALKERN_LOCKS_H +#include +#endif + +#ifndef _KALKERN_TERM_H +#include #endif //------------------------------------------// -// Macros // -//------------------------------------------// - -#define DisableInterrupts() asm volatile ("cli") -#define EnableInterrupts() asm volatile ("sti") -#define HaltCPU() asm volatile ("hlt") - -//------------------------------------------// -// End of // +// End of header // //------------------------------------------// #endif diff --git a/kaleid/include/kernel/kernbase.h b/kaleid/include/kernel/kernbase.h new file mode 100644 index 0000000..171c048 --- /dev/null +++ b/kaleid/include/kernel/kernbase.h @@ -0,0 +1,205 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: Kaleid Kernel base types and functionalities // +//----------------------------------------------------------------------------// + +//------------------------------------------// +// Dependencies // +//------------------------------------------// + +#ifndef _KALEID_H +#include +#endif + +//------------------------------------------// +// Start of header // +//------------------------------------------// + +#ifndef _KALKERN_BASE_H +#define _KALKERN_BASE_H + +//------------------------------------------// +// Elementary types // +//------------------------------------------// + +typedef struct sLock_t volatile Lock_t; +typedef struct sThread_t Thread_t; +typedef struct sProcess_t Process_t; +typedef struct sTerminal_t Terminal_t; +typedef struct sListHead_t ListHead_t; +typedef struct sListNode_t ListNode_t; + +//------------------------------------------// +// Values for __kstate // +//------------------------------------------// + +// +// Current state of the kernel +// +typedef enum { + // the kernel is booting + KSTATE_INIT, + + // the kernel is not running a process + KSTATE_KERNEL, + + // a process is running in kernel mode + KSTATE_PROCESS, + + // the kernel is panicking + KSTATE_PANIC, + +} KernelState_t; + +//------------------------------------------// +// Multiprocessor misc. // +//------------------------------------------// + +#ifndef NCPU +#define NCPU 4 +#endif + +#define GetCurCPU() 0 + +// +// Declare an (extern) CPU-local variable +// +#define __DECLARE_PER_CPU(_X, _Tp, _Qual) \ + _Qual _Tp __ ## _X [NCPU]; \ + static inline _Tp Get ## _X (void) \ + { return __ ## _X [GetCurCPU()]; } \ + static inline void _Set ## _X (_Tp _Y) \ + { (__ ## _X [GetCurCPU()] = _Y); } + +#define DECLARE_PER_CPU(_X, _Tp) \ + __DECLARE_PER_CPU(_X, _Tp, extern) + +#define LOCAL_DEC_PER_CPU(_X, _Tp) \ + __DECLARE_PER_CPU(_X, _Tp, static) + +// +// Actually creates a CPU-local variable +// +#define CREATE_PER_CPU(_X, _Tp) \ + _Tp __ ## _X [NCPU] = { (_Tp) 0 } + + +//------------------------------------------// +// Global constants // +//------------------------------------------// + +// XXX +DECLARE_PER_CPU(PanicStr, const char *); + +DECLARE_PER_CPU(KernState, KernelState_t); + +DECLARE_PER_CPU(_StdOut, Terminal_t *); +DECLARE_PER_CPU(_StdDbg, Terminal_t *); + +DECLARE_PER_CPU(CurProc, Process_t *); +DECLARE_PER_CPU(CurThread, Thread_t *); + +//------------------------------------------// +// Macros for manipulating said // +// global constants // +//------------------------------------------// + +#define SetPanicStr(str) \ + do { \ + SetKernState(KSTATE_PANIC); \ + _SetPanicStr(str); \ + } while (0) + +#define SetKernState(x) \ + do { \ + _SetKernState(x); \ + } while (0) + +#define GetStdOut() (GetCurProc() == NULL ? Get_StdOut() : NULL) +#define SetStdOut(tm) \ + do { \ + if (GetCurProc() == NULL) \ + _Set_StdOut(tm); \ + } while (0); + +#define GetStdDbg() (GetCurProc() == NULL ? Get_StdDbg() : NULL) +#define SetStdDbg(tm) \ + do { \ + if (GetCurProc() == NULL) \ + _Set_StdDbg(tm); \ + } while (0) + +//------------------------------------------// +// Other Macros // +//------------------------------------------// + +// +// Size of a tabulation in spaces +// Default: 4 spaces/tab +// +#define KTABSIZE 4 + +// +// Disable IRQs +// +#define DisableIRQs() asm volatile ("cli") + +// +// Enable IRQs +// +#define EnableIRQs() asm volatile ("sti") + +// +// Pause CPU until next interuption +// !!! Enables IRQs !!! +// +#define PauseCPU() asm volatile("sti\n\thlt") + +// +// Halt the CPU indefinitely +// +#define HaltCPU() do { asm volatile ("hlt"); } while (1) + +//------------------------------------------// +// Some base functions // +//------------------------------------------// + +noreturn void StartPanic(const char *); +noreturn void CrashSystem(void); + +//------------------------------------------// +// Useful I/O inlines // +//------------------------------------------// + +static inline +void WriteByteOnPort(port_t port, port_t val) +{ + asm volatile ("out %0, %1" : : "dN" (port), "a" (val)); +} + +static inline +uchar ReadByteFromPort(port_t port) +{ + errno = ENOSYS; + (void)port; + return 0; +} + +static inline +ushort ReadWordFromPort(port_t port) +{ + errno = ENOSYS; + (void)port; + return 0; +} + +//------------------------------------------// +// End of header // +//------------------------------------------// + +#endif + diff --git a/kaleid/include/kernel/kernlocks.h b/kaleid/include/kernel/kernlocks.h new file mode 100644 index 0000000..f3dd7e2 --- /dev/null +++ b/kaleid/include/kernel/kernlocks.h @@ -0,0 +1,170 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: Spinlocks and mutexes // +//----------------------------------------------------------------------------// + +//------------------------------------------// +// Dependencies // +//------------------------------------------// + +#ifdef _KALEID_KERNEL + +#ifndef _KALKERN_BASE_H +#include "kernbase.h" +#endif + +#else + +#ifndef _KALEID_H +#include +#endif + +#endif + +//------------------------------------------// +// Start of header // +//------------------------------------------// + +#ifndef _KALKERN_LOCKS_H +#define _KALKERN_LOCKS_H + +//------------------------------------------// +// Types // +//------------------------------------------// + +typedef enum eLockType_t { + // + // Mutex-type lock + // + // WARNING + // AquireLock() panics when used on a mutex while not running a process + // + KLOCK_MUTEX, + + // + // Spinlock-type lock + // + KLOCK_SPINLOCK, + +} LockType_t; + +// +// "volatile" may not be actually needed +// +typedef struct sLock_t { + unsigned int initDone; // initialized? + int locked; // is locked? + LockType_t type; // lock type? +#ifdef _KALEID_KERNEL + Process_t *ownerProc; // unused + Process_t *waitingProc; // unused +#endif +} volatile Lock_t; + +//------------------------------------------// +// Functions // +//------------------------------------------// + +// +// Linux syscall... +// +#ifndef _KALEID_KERNEL +int sched_yield(void); +#endif + +// +// Initialize a lock +// +static inline +void InitLock(Lock_t *lock, LockType_t type) +{ + lock->type = type; + lock->locked = FALSE; + lock->initDone = INITOK; +#ifdef _KALEID_KERNEL + lock->ownerProc = NULL; + lock->waitingProc = NULL; +#endif +} + +// +// Alternative way to initalize a lock +// +#ifdef _KALEID_KERNEL +# define INITLOCK(type) { INITOK, FALSE, (type), NULL, NULL } +#else +# define INITLOCK(type) { INITOK, FALSE, (type) } +#endif + +// +// Destroy a lock +// +static inline +void DestroyLock(Lock_t *lock) +{ + KalAssert(lock->initDone); + + __sync_synchronize(); + lock->initDone = 0; +} + +// +// Aquire the lock +// Panic on double aquisition since that should never happen +// until we have at least a basic scheduler +// +static inline +void AquireLock(Lock_t *lock) +{ + KalAssert(lock->initDone == INITOK); + + while (!__sync_bool_compare_and_swap(&lock->locked, 0, 1)) { +#ifdef _KALEID_KERNEL + StartPanic("AquireLock on an already locked object"); +#else + if likely (lock->type == KLOCK_SPINLOCK) continue; + else sched_yield(); +#endif + } + __sync_synchronize(); +} + +// +// Release an already aquired lock +// Panic if the lock was never aquired +// +static inline +void ReleaseLock(Lock_t *lock) +{ +#ifdef _KALEID_KERNEL + KalAssert(lock->ownerProc == GetCurProc()); +#endif + + __sync_synchronize(); + lock->locked = 0; +} + +// +// Tries to aquire lock +// +static inline +bool AttemptLock(Lock_t *lock) +{ + KalAssert(lock->initDone == INITOK); + + bool retval = __sync_bool_compare_and_swap(&lock->locked, 0, 1); + + __sync_synchronize(); + + return retval; +} + +//------------------------------------------// +// End of header // +//------------------------------------------// + +#endif diff --git a/kaleid/include/kernel/kernsched.h b/kaleid/include/kernel/kernsched.h new file mode 100644 index 0000000..1026d53 --- /dev/null +++ b/kaleid/include/kernel/kernsched.h @@ -0,0 +1,102 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: Scheduler header // +//----------------------------------------------------------------------------// + +//------------------------------------------// +// Dependencies // +//------------------------------------------// + +#ifndef _KALKERN_BASE_H +#include "kernbase.h" +#endif + +#ifndef _KALLIST_H +#include +#endif + +//------------------------------------------// +// Start of header // +//------------------------------------------// + +#ifndef _KALKERN_SCHED_H +#define _KALKERN_SCHED_H + +//------------------------------------------// +// Preprocessor // +//------------------------------------------// + +#define printdbg printf +#define _STR(x) #x +#define _XSTR(x) _STR(x) + +// +// States for a process +// +#define STATE_RUNNING 0 +#define STATE_RUNNABLE 1 +#define STATE_BLOCKED 2 + +// +// Time in ticks a process should be run +// +#define DEF_PROC_TSLICE 5 // 20 ticks +#define TCR_PROC_TSLICE 20000 // 20000 ticks (time critical) + +//------------------------------------------// +// List heads // +//------------------------------------------// + +DECLARE_PER_CPU(IdlePrioProcs, ListHead_t *); +DECLARE_PER_CPU(ReglPrioProcs, ListHead_t *); +DECLARE_PER_CPU(ServPrioProcs, ListHead_t *); +DECLARE_PER_CPU(TimeCritProcs, ListHead_t *); + +//------------------------------------------// +// Data types // +//------------------------------------------// + +// +// A process +// +typedef struct sProcess_t{ + + // Identifier + int pid; + + // Current priority class + int prioClass; + + // Default priority class (without boosts) + int defPrioClass; + + // Current priority level + int prioLevel; + + // Default priority level + int defPrioLevel; + + // Current state + int procState; + + // Remaining time running + ulong timeSlice; + + // Default time-slice + ulong defTimeSlice; + + // Scheduler internals + ListNode_t *schedNode; + +} Process_t; + +//------------------------------------------// +// End of header // +//------------------------------------------// + +#endif + diff --git a/kaleid/include/kernel/kernterm.h b/kaleid/include/kernel/kernterm.h new file mode 100644 index 0000000..b5c32b6 --- /dev/null +++ b/kaleid/include/kernel/kernterm.h @@ -0,0 +1,95 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: Terminal functions // +//----------------------------------------------------------------------------// + +//------------------------------------------// +// Dependencies // +//------------------------------------------// + +#ifndef _KALKERN_BASE_H +#include "kernbase.h" +#endif + +//------------------------------------------// +// Start of header // +//------------------------------------------// + +#ifndef _KALKERN_TERM_H +#define _KALKERN_TERM_H + +//------------------------------------------// +// Types // +//------------------------------------------// + +// +// The VGA colors +// +typedef enum { + KTERM_COLOR_BLACK, KTERM_COLOR_BLUE, + KTERM_COLOR_GREEN, KTERM_COLOR_CYAN, + KTERM_COLOR_RED, KTERM_COLOR_MAGENTA, + KTERM_COLOR_BROWN, KTERM_COLOR_LGREY, + KTERM_COLOR_DARK_GREY, KTERM_COLOR_LBLUE, + KTERM_COLOR_LGREEN, KTERM_COLOR_LCYAN, + KTERM_COLOR_LRED, KTERM_COLOR_LMAGENTA, + KTERM_COLOR_LBROWN, KTERM_COLOR_WHITE +} TermColor_t; + +// +// Terminal structure, right now VGA and output only +// +typedef struct sTerminal_t { + + uint initDone; + Lock_t lock; + + const char *name; + const char *type; + + void *data; + + size_t width; + size_t height; + off_t currentX; + off_t currentY; + + uint tabSize; + TermColor_t fgColor; + TermColor_t bgColor; + + error_t (*ClearTermUnlocked)(Terminal_t *); + error_t (*PutOnTermUnlocked)(Terminal_t *, char); + error_t (*PrintOnTermUnlocked)(Terminal_t *, const char *); + +} Terminal_t; + +//------------------------------------------// +// Functions // +//------------------------------------------// + +void InitTerms(void); +error_t ClearTerm(Terminal_t *); +error_t PutOnTerm(Terminal_t *, char); +error_t PrintOnTerm(Terminal_t *, const char *); +error_t ChTermColor(Terminal_t *, TermColor_t, TermColor_t); + +//------------------------------------------// +// Macros // +//------------------------------------------// + +#ifndef _NO_DEBUG +# define DebugLog(...) PrintOnTerm(GetStdDbg(), __VA_ARGS__) +#else +# define DebugLog(...) +#endif + +//------------------------------------------// +// End of header // +//------------------------------------------// + +#endif diff --git a/src/kaleid/kernel/init.c b/kaleid/kernel/init/init.c similarity index 80% rename from src/kaleid/kernel/init.c rename to kaleid/kernel/init/init.c index 3a7d1cd..0887f9c 100644 --- a/src/kaleid/kernel/init.c +++ b/kaleid/kernel/init/init.c @@ -7,25 +7,22 @@ // Desc: Kernel entry point // //----------------------------------------------------------------------------// -#include -#include -#include -#include +#include // -// Entry point of kaleid-kernel.elf +// Entry point of kaleid-kernel.elf // -void StartKern(void) +noreturn void StartKern(void) { // we're not ready to deal with interrupts - DisableInterrupts(); - + DisableIRQs(); + // booting! SetKernState(KSTATE_INIT); // kernel terminals InitTerms(); - + // we're out StartPanic("Goodbye World :("); } diff --git a/src/kaleid/kernel/io/ports.h b/kaleid/kernel/init/table.c similarity index 63% rename from src/kaleid/kernel/io/ports.h rename to kaleid/kernel/init/table.c index 10799a3..4b98d25 100644 --- a/src/kaleid/kernel/io/ports.h +++ b/kaleid/kernel/init/table.c @@ -4,20 +4,18 @@ // Authors: spectral` // // NeoX // // // -// Desc: Ports I/O // +// Desc: Global constants // //----------------------------------------------------------------------------// -#ifndef _KALKERN_IO_PORTS_H -#define _KALKERN_IO_PORTS_H +#include -#ifndef _KALKERN_H -#include -#endif +CREATE_PER_CPU(PanicStr, const char *); -#define WriteByteOnPort(port,val) asm volatile ("outb %1, %0" : : "dN" (port), "a" (value)) +CREATE_PER_CPU(KernState, KernelState_t); -uchar ReadByteFromPort(port_t); -ushort ReadWordFromPort(port_t); +CREATE_PER_CPU(_StdOut, Terminal_t *); +CREATE_PER_CPU(_StdDbg, Terminal_t *); -#endif +CREATE_PER_CPU(CurProc, Process_t *); +CREATE_PER_CPU(CurThread, Thread_t *); diff --git a/src/kaleid/kernel/ke/panic.c b/kaleid/kernel/ke/panic.c similarity index 65% rename from src/kaleid/kernel/ke/panic.c rename to kaleid/kernel/ke/panic.c index 72fa83e..72fe089 100644 --- a/src/kaleid/kernel/ke/panic.c +++ b/kaleid/kernel/ke/panic.c @@ -7,62 +7,63 @@ // Desc: How NOT to panic 101 // //----------------------------------------------------------------------------// -#include -#include - #define _UNLOCKED_IO -#include +#include // -// Panic message -// -const char *__panicmsg = NULL; - -// -// Failed assert() handler +// Failed assert() handler // noreturn void _assert_handler(const char *msg, const char *file, int line, const char *func) { - // not getting out of here - DisableInterrupts(); - + DisableIRQs(); + (void)file; (void)line; (void)func; - + // XXX sprintf() to create a proper panicstr StartPanic(msg); } // -// Your best boy panic() +// Your best boy panic() +// This is CPU local... // -void StartPanic(const char *str) +noreturn void StartPanic(const char *str) { - DisableInterrupts(); + DisableIRQs(); SetKernState(KSTATE_PANIC); - ClearTermUnlocked(stdout); - + if (GetCurProc()) __CurProc[GetCurCPU()] = NULL; + if (GetStdOut() == NULL) CrashSystem(); + + GetStdOut()->ClearTermUnlocked(GetStdOut()); + if (str == NULL) { str = "(no message given)"; } - + if (GetPanicStr()) { - PrintOnTermUnlocked(stdout, "double panic!\n"); + GetStdOut()->PrintOnTermUnlocked(GetStdOut(), "double panic!\n"); HaltCPU(); } SetPanicStr(str); - // we cannot lock anything when panicking - PrintOnTermUnlocked(stdout, "panic! - "); - PrintOnTermUnlocked(stdout, str); + GetStdOut()->PrintOnTermUnlocked(GetStdOut(), "PANIC! - "); + GetStdOut()->PrintOnTermUnlocked(GetStdOut(), str); - while (TRUE) { - HaltCPU(); - } + HaltCPU(); +} + +// +// Oh well +// +noreturn void CrashSystem(void) +{ + DisableIRQs(); + HaltCPU(); } diff --git a/kaleid/kernel/ke/terminal.c b/kaleid/kernel/ke/terminal.c new file mode 100644 index 0000000..1d7439b --- /dev/null +++ b/kaleid/kernel/ke/terminal.c @@ -0,0 +1,236 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: Early terminal functions // +//----------------------------------------------------------------------------// + +#include + +static Terminal_t vgaTerm; + +// +// Initialize standard output +// +void InitTerms(void) +{ + KalAssert(!GetStdOut() && vgaTerm.initDone != INITOK); + + vgaTerm.initDone = INITOK; + + SetStdDbg(&vgaTerm); + SetStdOut(&vgaTerm); + + ClearTerm(GetStdOut()); +} + +// +// Fill terminal with spaces +// +error_t ClearTerm(Terminal_t *term) +{ + error_t retcode; + + if (term == NULL) return EINVAL; + KalAssert(term->initDone == INITOK); + + AquireLock(&term->lock); + retcode = term->ClearTermUnlocked(term); + ReleaseLock(&term->lock); + + return retcode; +} + +// +// Change the color code +// +error_t ChTermColor(Terminal_t *term, TermColor_t fgColor, TermColor_t bgColor) +{ + if (fgColor > KTERM_COLOR_WHITE || bgColor > KTERM_COLOR_WHITE) + return EINVAL; + + if (term == NULL) + return EINVAL; + + AquireLock(&term->lock); + + term->fgColor = fgColor; + term->bgColor = bgColor; + + ReleaseLock(&term->lock); + + return EOK; +} + +// +// Write a single character on the terminal +// +error_t PutOnTerm(Terminal_t *term, char ch) +{ + error_t retcode; + + if (term == NULL) return EINVAL; + KalAssert(term->initDone == INITOK); + + AquireLock(&term->lock); + retcode = term->PutOnTermUnlocked(term, ch); + ReleaseLock(&term->lock); + + return retcode; +} + +// +// Print string on terminal +// +error_t PrintOnTerm(Terminal_t *term, const char *str) +{ + error_t retcode = EOK; + + if (term == NULL) return EINVAL; + KalAssert(term->initDone == INITOK); + + AquireLock(&term->lock); + while (*str && retcode == EOK) { + retcode = term->PutOnTermUnlocked(term, *str++); + } + ReleaseLock(&term->lock); + + return retcode; +} + +//----------------------------------------------------------// +// Internal functions for VGA terminals // +// These DO NOT check input correctness // +//----------------------------------------------------------// + +// +// VGA-related macros +// +#define VGA_ComputeColorCode(fg, bg) ((fg) | (bg) << 4) +#define VGA_ComputeOffset(term, x, y) ((y) * (term)->width + (x)) +#define VGA_ComputeEntry(ch, cl) (((ushort)(ch)) | (ushort)(cl) << 8) + +// +// Fill terminal with '\0' +// +error_t VGA_ClearTermUnlocked(Terminal_t *term) +{ + const uchar color = VGA_ComputeColorCode(term->fgColor, term->bgColor); + const ushort filler = VGA_ComputeEntry('\0', color); + const size_t bufsize = term->width * term->height; + + // Fill the buffer + memsetw((ushort *)term->data, filler, bufsize); + + // XXX update cursor too + term->currentX = term->currentY = 0; + + return EOK; +} + +// +// Write a single character on the terminal +// +error_t VGA_PutOnTermUnlocked(Terminal_t *term, char ch) +{ + uint i; + size_t prevY; + + if (ch == '\r') { + term->currentX = 0; + return EOK; + } + + // + // Line feed first takes us to the very end of the line + // Later in this function we actually do the line feed + // + else if (ch == '\n') { + term->currentY = term->width - 1; + } + + // + // Tabulations account for "term->tabSize" spaces + // + else if (ch == '\t') { + prevY = term->currentY; + for (i = 0; i < term->tabSize; i++) { + // + // Make sure tabulations can't spread over two lines + // + if (term->currentY == prevY) { + VGA_PutOnTermUnlocked(term, ' '); + } + } + } + + else { + ushort *buffer = (ushort *)term->data; + const size_t offset = VGA_ComputeOffset(term, term->currentY, term->currentY); + buffer[offset] = VGA_ComputeEntry(ch, VGA_ComputeColorCode(term->fgColor, term->bgColor)); + } + + // + // Did we reach the end of line? + // + if (++term->currentX == term->width) { + term->currentX = 0; + + // + // Did we reach the buffer's end? + // + if (++term->currentY == term->height) { + // + // XXX scroll up + // + term->currentY = 0; + } + } + + // + // Nothing can go wrong + // + return EOK; +} + +// +// Print string on terminal +// +error_t VGA_PrintOnTermUnlocked(Terminal_t *term, const char *str) +{ + error_t retcode = EOK; + + while (*str && retcode == EOK) { + retcode = term->PutOnTermUnlocked(term, *str++); + } + + return retcode; +} + +// +// VGA output +// +static Terminal_t vgaTerm = { + .initDone = FALSE, + .lock = INITLOCK(KLOCK_MUTEX), + + .name = "VGA Output Terminal", + .type = "VGA", + + .data = (void *)0xB8000, + .width = 80, + .height = 25, + .currentX = 0, + .currentY = 0, + + .tabSize = KTABSIZE, + .fgColor = KTERM_COLOR_LGREY, + .bgColor = KTERM_COLOR_BLACK, + + .ClearTermUnlocked = VGA_ClearTermUnlocked, + .PutOnTermUnlocked = VGA_PutOnTermUnlocked, + .PrintOnTermUnlocked = VGA_PrintOnTermUnlocked, +}; + diff --git a/kaleid/kernel/proc/Makefile b/kaleid/kernel/proc/Makefile new file mode 100644 index 0000000..8001a5e --- /dev/null +++ b/kaleid/kernel/proc/Makefile @@ -0,0 +1,4 @@ + +sched-test: + gcc -O2 -masm=intel -I../../include ./sched.c + diff --git a/kaleid/kernel/proc/sched.c b/kaleid/kernel/proc/sched.c new file mode 100644 index 0000000..b81ec45 --- /dev/null +++ b/kaleid/kernel/proc/sched.c @@ -0,0 +1,409 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: Scheduling algorithm // +//----------------------------------------------------------------------------// + +#include + +#ifndef _KALEID_KERNEL + +#include +CREATE_PER_CPU(CurProc, Process_t *); + +// +// For test purpose only +// +int procslen = 9; +Process_t procs[] = { + { 0, 0, 0, 12, 12, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL }, + { 1, 2, 2, 16, 16, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL }, + { 2, 3, 3, 31, 31, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL }, + { 3, 2, 2, 1, 1, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL }, + { 4, 0, 0, 5, 5, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL }, + { 5, 0, 0, 30, 30, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL }, + { 6, 1, 1, 19, 19, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL }, + { 7, 1, 1, 0, 0, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL }, + { 8, 3, 3, 12, 12, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL }, +}; + +#endif + +// +// Set current process +// TODO Select thread, context switch +// +static inline +void SetCurProc(Process_t *proc) +{ + _SetCurProc(proc); + if (GetCurProc() != NULL) { + GetCurProc()->procState = STATE_RUNNING; + } +} + +// +// (Un)Lock priority class list heads +// + +static inline +void SchedLock(void) { +#ifdef _KALEID_KERNEL + DisableIRQs(); +#endif +} + +static inline +void SchedUnlock(void) { +#ifdef _KALEID_KERNEL + EnableIRQs(); +#endif +} + +// +// The four priority classes of OS/2 +// +CREATE_PER_CPU(IdlePrioProcs, ListHead_t *); +CREATE_PER_CPU(ReglPrioProcs, ListHead_t *); +CREATE_PER_CPU(ServPrioProcs, ListHead_t *); +CREATE_PER_CPU(TimeCritProcs, ListHead_t *); + +char *PrioClassesNames[] = { + "Idle priority class", + "Regular priority class", + "Server priority class", + "Time-critical class", +}; + +enum { IDLE_PRIO_PROC = 0, + REGL_PRIO_PROC = 1, + SERV_PRIO_PROC = 2, + TIME_CRIT_PROC = 3, +}; + +// +// Get priority class list head +// +static inline +ListHead_t *GetPrioClassHead(int prioClass) +{ + switch (prioClass) { + case TIME_CRIT_PROC: return GetTimeCritProcs(); + case SERV_PRIO_PROC: return GetServPrioProcs(); + case REGL_PRIO_PROC: return GetReglPrioProcs(); + case IDLE_PRIO_PROC: return GetIdlePrioProcs(); + default: KalAssert(FALSE && "Unknown priority class"); + } + + return NULL; +} + +// +// Determine which process is going to run first +// Return NULL for "equal" processes +// +static inline +Process_t *CompareProcs(Process_t *proc1, Process_t *proc2) +{ + KalAssert(proc1 && proc2); + + if (proc1->prioClass > proc2->prioClass) return proc1; + if (proc1->prioClass < proc2->prioClass) return proc2; + + if (proc1->prioLevel > proc2->prioLevel) return proc1; + if (proc1->prioLevel < proc2->prioLevel) return proc2; + + return NULL; // same class and level +} + +// +// Add process to schedule lists (unlocked) +// +static inline +void SchedThisProcUnlocked(Process_t *proc) +{ + KalAssert(proc && proc->procState == STATE_RUNNABLE); + + bool found = false; + ListNode_t *iterNode = NULL; + ListNode_t *procNode = CreateNode(proc); + ListHead_t *head = GetPrioClassHead(proc->prioClass); + + KalAssert(procNode && head); + + proc->schedNode = procNode; + + //printdbg("Adding process %d to '%s'\n", proc->pid, PrioClassesNames[proc->prioClass]); + + // + // Find a process with lesser priority + // + for (iterNode = head->first; iterNode; iterNode = iterNode->next) { + if (proc->prioLevel > GetNodeData(iterNode, Process_t *)->prioLevel) { + AddNodeBefore(head, iterNode, procNode); + found = true; + break; + } + } + + // + // Didn't find any process with lesser priority + // + if (found == false) { + AppendNode(head, procNode); + } +} + +// +// Add process to schedule lists +// +void SchedThisProc(Process_t *proc) +{ + SchedLock(); + + SchedThisProcUnlocked(proc); + + SchedUnlock(); +} + +// +// Selects process to schedule next +// +// WARNING +// Does not call SchedLock()/SchedUnlock() +// +static inline +Process_t *SelectSchedNext(void) +{ + if (GetTimeCritProcs()->length > 0) return GetNodeData(GetTimeCritProcs()->first, Process_t *); + if (GetServPrioProcs()->length > 0) return GetNodeData(GetServPrioProcs()->first, Process_t *); + if (GetReglPrioProcs()->length > 0) return GetNodeData(GetReglPrioProcs()->first, Process_t *); + if (GetIdlePrioProcs()->length > 0) return GetNodeData(GetIdlePrioProcs()->first, Process_t *); + + return NULL; +} + +// +// Remove running process from schedule lists +// and schedule next runnable process +// +static inline +void BlockCurProc(void) +{ + KalAssert(GetCurProc() && GetCurProc()->procState == STATE_RUNNING); + + ListNode_t *procNode = GetCurProc()->schedNode; + + GetCurProc()->procState = STATE_BLOCKED; + RemoveNode(procNode->head, procNode); + + SetCurProc(SelectSchedNext()); +} + +// +// Should we schedule another process? +// Called at each tick +// +void SchedOnTick(void) +{ + Process_t *procNext; + Process_t *winner; + + SchedLock(); + + // + // We're either idle or running something + // + KalAssert(GetCurProc() == NULL || GetCurProc()->procState == STATE_RUNNING); + + // + // Has current process spent his timeslice? + // (To be handled in CPU decisions function) + // + if (GetCurProc() != NULL) { + if (GetCurProc()->timeSlice <= 1) { + + // Restore default attributes, cancelling boosts + GetCurProc()->prioClass = GetCurProc()->defPrioClass; + GetCurProc()->prioLevel = GetCurProc()->defPrioLevel; + GetCurProc()->timeSlice = GetCurProc()->defTimeSlice; + GetCurProc()->procState = STATE_RUNNABLE; + + // Remove from list + RemoveNode(GetCurProc()->schedNode->head, GetCurProc()->schedNode); + + // Schedule again, with default attributes now + SchedThisProcUnlocked(GetCurProc()); + + // Mark as idle + SetCurProc(NULL); + } + + // + // Otherwise, make him lose a tick + // + else { + GetCurProc()->timeSlice--; + } + } + + // + // Are we idle, or scheduling next process? + // + if (GetCurProc() == NULL) { + SetCurProc(SelectSchedNext()); + goto leave; + } + + // + // Is there a higher priority process that is runnable? + // + procNext = SelectSchedNext(); + winner = CompareProcs(GetCurProc(), procNext); + + // + // Yes, procNext should preempt current process + // + if (winner == procNext) { + GetCurProc()->procState = STATE_RUNNABLE; + SchedThisProcUnlocked(GetCurProc()); + SetCurProc(procNext); + } + + // + // Current process won't be preempted and has time remaining + // +leave: + SchedUnlock(); +} + +#define PrintProc(proc) printdbg("{ %d, '%s', %d , %d}\n", (proc)->pid, \ + PrioClassesNames[(proc)->prioClass], (proc)->prioLevel, (proc)->timeSlice); + +// +// Print out process list +// +void PrintList(ListHead_t *head) +{ + KalAssert(head); + + Process_t *proc; + ListNode_t *node = head->first; + + printdbg("len: %d\n", head->length); + + while (node) { + proc = GetNodeData(node, Process_t *); + + PrintProc(proc); + + node = node->next; + } + + puts(""); +} + +// +// Initialize scheduler +// +void InitSched(void) +{ + int pid; + Process_t *proc; + + SchedLock(); + + _SetTimeCritProcs(CreateListHead()); + _SetServPrioProcs(CreateListHead()); + _SetReglPrioProcs(CreateListHead()); + _SetIdlePrioProcs(CreateListHead()); + +#ifndef _KALEID_KERNEL + for (pid = 0; pid < procslen; pid++) { + if (procs[pid].procState == STATE_RUNNABLE) { + SchedThisProcUnlocked(&procs[pid]); + } + } +#endif + + SchedUnlock(); +} + +// +// Shutdown scheduler +// +void FiniSched(void) +{ + KalAssert(GetIdlePrioProcs() && GetReglPrioProcs() && GetServPrioProcs() && GetTimeCritProcs()); + + SchedLock(); + + while (GetIdlePrioProcs()->length > 0) RemoveNode(GetIdlePrioProcs(), GetIdlePrioProcs()->first); + while (GetReglPrioProcs()->length > 0) RemoveNode(GetReglPrioProcs(), GetReglPrioProcs()->first); + while (GetServPrioProcs()->length > 0) RemoveNode(GetServPrioProcs(), GetServPrioProcs()->first); + while (GetTimeCritProcs()->length > 0) RemoveNode(GetTimeCritProcs(), GetTimeCritProcs()->first); + + DestroyListHead(GetIdlePrioProcs()); _SetIdlePrioProcs(NULL); + DestroyListHead(GetReglPrioProcs()); _SetReglPrioProcs(NULL); + DestroyListHead(GetServPrioProcs()); _SetServPrioProcs(NULL); + DestroyListHead(GetTimeCritProcs()); _SetTimeCritProcs(NULL); + + SchedUnlock(); +} + +#ifndef _KALEID_KERNEL +int main(void) +{ + InitSched(); + + puts("---------------"); + + puts("Time Critical:"); + PrintList(GetTimeCritProcs()); + + puts("Server:"); + PrintList(GetServPrioProcs()); + + puts("Regular:"); + PrintList(GetReglPrioProcs()); + + puts("Idle:"); + PrintList(GetIdlePrioProcs()); + + puts("---------------"); + + getchar(); + + int tick = 0; + + while (tick < 20) { + printf("Tick %d - Running: ", tick); + + if (GetCurProc() == NULL) { + puts("IDLE"); + } + + else { + PrintProc(GetCurProc()); + } + + if (tick == 9 || tick == 14) { + puts("Blocking current process"); + BlockCurProc(); + } + + SchedOnTick(); + + //puts("\n---------------"); + tick++; + } + + FiniSched(); + + return 0; +} +#endif + diff --git a/obj/kaleid/common/arith.S b/obj/kaleid/common/arith.S deleted file mode 100644 index 5564d39..0000000 --- a/obj/kaleid/common/arith.S +++ /dev/null @@ -1,114 +0,0 @@ - .file "arith.c" - .text - .p2align 4,,15 - .globl _osk_abs - .type _osk_abs, @function -_osk_abs: -.LFB2: - .cfi_startproc - movl %edi, %edx - movl %edi, %eax - sarl $31, %edx - xorl %edx, %eax - subl %edx, %eax - ret - .cfi_endproc -.LFE2: - .size _osk_abs, .-_osk_abs - .p2align 4,,15 - .globl _osk_labs - .type _osk_labs, @function -_osk_labs: -.LFB3: - .cfi_startproc - movq %rdi, %rdx - movq %rdi, %rax - sarq $63, %rdx - xorq %rdx, %rax - subq %rdx, %rax - ret - .cfi_endproc -.LFE3: - .size _osk_labs, .-_osk_labs - .p2align 4,,15 - .globl _osk_min - .type _osk_min, @function -_osk_min: -.LFB4: - .cfi_startproc - cmpl %edi, %esi - movl %edi, %eax - cmovle %esi, %eax - ret - .cfi_endproc -.LFE4: - .size _osk_min, .-_osk_min - .p2align 4,,15 - .globl _osk_lmin - .type _osk_lmin, @function -_osk_lmin: -.LFB5: - .cfi_startproc - cmpq %rdi, %rsi - movq %rdi, %rax - cmovle %rsi, %rax - ret - .cfi_endproc -.LFE5: - .size _osk_lmin, .-_osk_lmin - .p2align 4,,15 - .globl _osk_max - .type _osk_max, @function -_osk_max: -.LFB11: - .cfi_startproc - cmpl %esi, %edi - movl %esi, %eax - cmovle %edi, %eax - ret - .cfi_endproc -.LFE11: - .size _osk_max, .-_osk_max - .p2align 4,,15 - .globl _osk_lmax - .type _osk_lmax, @function -_osk_lmax: -.LFB13: - .cfi_startproc - cmpq %rsi, %rdi - movq %rsi, %rax - cmovle %rdi, %rax - ret - .cfi_endproc -.LFE13: - .size _osk_lmax, .-_osk_lmax - .p2align 4,,15 - .globl _osk_div - .type _osk_div, @function -_osk_div: -.LFB8: - .cfi_startproc - movl %edi, %eax - cltd - idivl %esi - salq $32, %rdx - movl %eax, %eax - orq %rdx, %rax - ret - .cfi_endproc -.LFE8: - .size _osk_div, .-_osk_div - .p2align 4,,15 - .globl _osk_ldiv - .type _osk_ldiv, @function -_osk_ldiv: -.LFB9: - .cfi_startproc - movq %rdi, %rax - cqto - idivq %rsi - ret - .cfi_endproc -.LFE9: - .size _osk_ldiv, .-_osk_ldiv - .ident "GCC: (GNU) 7.3.0" diff --git a/obj/kaleid/common/itoa.S b/obj/kaleid/common/itoa.S deleted file mode 100644 index 1f55ec6..0000000 --- a/obj/kaleid/common/itoa.S +++ /dev/null @@ -1,77 +0,0 @@ - .file "convert.c" - .text - .p2align 4,,15 - .globl itoa - .type itoa, @function -itoa: -.LFB2: - .cfi_startproc - movl %edx, %r9d - leal -2(%rdx), %edx - movl %edi, %eax - cmpl $34, %edx - ja .L2 - testl %edi, %edi - js .L11 - jne .L7 - leaq 1(%rsi), %r8 - movb $48, (%rsi) -.L5: - movb $0, (%r8) - movq %rsi, %rdi - movabsq $reverse, %rax - jmp *%rax - .p2align 4,,10 - .p2align 3 -.L11: - negl %eax - movl $1, %edi -.L4: - movq %rsi, %r8 - movabsq $digits, %r10 - jmp .L6 - .p2align 4,,10 - .p2align 3 -.L8: - movq %rcx, %r8 -.L6: - cltd - leaq 1(%r8), %rcx - idivl %r9d - movslq %edx, %rdx - testl %eax, %eax - movzbl (%r10,%rdx), %edx - movb %dl, -1(%rcx) - jne .L8 - testl %edi, %edi - je .L9 - addq $2, %r8 - movb $45, (%rcx) - jmp .L5 - .p2align 4,,10 - .p2align 3 -.L7: - xorl %edi, %edi - jmp .L4 - .p2align 4,,10 - .p2align 3 -.L2: - xorl %eax, %eax - ret - .p2align 4,,10 - .p2align 3 -.L9: - movq %rcx, %r8 - jmp .L5 - .cfi_endproc -.LFE2: - .size itoa, .-itoa - .section .rodata - .align 32 - .type digits, @object - .size digits, 36 -digits: - .byte 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x41,0x42,0x43 - .byte 0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50 - .byte 0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a - .ident "GCC: (GNU) 7.3.0" diff --git a/obj/kaleid/common/ltoa.S b/obj/kaleid/common/ltoa.S deleted file mode 100644 index 2723118..0000000 --- a/obj/kaleid/common/ltoa.S +++ /dev/null @@ -1,76 +0,0 @@ - .file "convert.c" - .text - .p2align 4,,15 - .globl ltoa - .type ltoa, @function -ltoa: -.LFB2: - .cfi_startproc - leal -2(%rdx), %ecx - movq %rdi, %rax - cmpl $34, %ecx - ja .L2 - testq %rdi, %rdi - js .L11 - jne .L7 - leaq 1(%rsi), %r9 - movb $48, (%rsi) -.L5: - movb $0, (%r9) - movq %rsi, %rdi - movabsq $reverse, %rax - jmp *%rax - .p2align 4,,10 - .p2align 3 -.L11: - negq %rax - movl $1, %edi -.L4: - movslq %edx, %r8 - movq %rsi, %r9 - movabsq $digits, %r10 - jmp .L6 - .p2align 4,,10 - .p2align 3 -.L8: - movq %rcx, %r9 -.L6: - cqto - leaq 1(%r9), %rcx - idivq %r8 - movzbl (%r10,%rdx), %edx - testq %rax, %rax - movb %dl, -1(%rcx) - jne .L8 - testl %edi, %edi - je .L9 - addq $2, %r9 - movb $45, (%rcx) - jmp .L5 - .p2align 4,,10 - .p2align 3 -.L7: - xorl %edi, %edi - jmp .L4 - .p2align 4,,10 - .p2align 3 -.L2: - xorl %eax, %eax - ret - .p2align 4,,10 - .p2align 3 -.L9: - movq %rcx, %r9 - jmp .L5 - .cfi_endproc -.LFE2: - .size ltoa, .-ltoa - .section .rodata - .align 32 - .type digits, @object - .size digits, 36 -digits: - .byte 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x41,0x42,0x43 - .byte 0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50 - .byte 0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a - .ident "GCC: (GNU) 7.3.0" diff --git a/obj/kaleid/common/memory.S b/obj/kaleid/common/memory.S deleted file mode 100644 index 6db16a5..0000000 --- a/obj/kaleid/common/memory.S +++ /dev/null @@ -1,309 +0,0 @@ - .file "memory.c" - .text - .p2align 4,,15 - .globl memsetb - .type memsetb, @function -memsetb: -.LFB2: - .cfi_startproc - movq %rdi, %rax - testb $7, %al - je .L10 - testq %rdx, %rdx - leaq -1(%rdx), %r8 - je .L3 - movl %esi, %edx - movq %rdi, %rcx - jmp .L4 - .p2align 4,,10 - .p2align 3 -.L21: - subq $1, %r8 - cmpq $-1, %r8 - je .L3 -.L4: - addq $1, %rcx - movb %dl, -1(%rcx) - testb $7, %cl - jne .L21 -.L2: - cmpq $8, %r8 - ja .L5 - testq %r8, %r8 - je .L22 -.L6: - addq %rcx, %r8 - .p2align 4,,10 - .p2align 3 -.L9: - addq $1, %rcx - movb %sil, -1(%rcx) - cmpq %rcx, %r8 - jne .L9 - rep ret - .p2align 4,,10 - .p2align 3 -.L3: - movq $-1, %r8 -.L5: - movslq %esi, %rcx - movq %rcx, %rdx - movq %rcx, %rdi - salq $48, %rdi - salq $56, %rdx - orq %rdi, %rdx - movq %rcx, %rdi - orq %rcx, %rdx - salq $40, %rdi - orq %rdi, %rdx - movq %rcx, %rdi - salq $32, %rdi - orq %rdi, %rdx - movq %rcx, %rdi - salq $24, %rdi - orq %rdi, %rdx - movq %rcx, %rdi - salq $8, %rcx - salq $16, %rdi - orq %rdi, %rdx - orq %rcx, %rdx - movq %rax, %rcx - .p2align 4,,10 - .p2align 3 -.L8: - subq $8, %r8 - addq $8, %rcx - movq %rdx, -8(%rcx) - cmpq $8, %r8 - ja .L8 - jmp .L6 - .p2align 4,,10 - .p2align 3 -.L22: - rep ret - .p2align 4,,10 - .p2align 3 -.L10: - movq %rdi, %rcx - movq %rdx, %r8 - jmp .L2 - .cfi_endproc -.LFE2: - .size memsetb, .-memsetb - .p2align 4,,15 - .globl memsetw - .type memsetw, @function -memsetw: -.LFB3: - .cfi_startproc - testb $1, %dil - jne .L24 - testb $7, %dil - je .L35 - testq %rdx, %rdx - leaq -1(%rdx), %r8 - movl %esi, %eax - movq %rdi, %rcx - jne .L31 - jmp .L47 - .p2align 4,,10 - .p2align 3 -.L48: - subq $1, %r8 - cmpq $-1, %r8 - je .L27 -.L31: - addq $2, %rcx - movw %ax, -2(%rcx) - testb $7, %cl - jne .L48 -.L25: - cmpq $4, %r8 - ja .L27 - testq %r8, %r8 - je .L28 -.L32: - xorl %edx, %edx - .p2align 4,,10 - .p2align 3 -.L34: - movw %si, (%rcx,%rdx,2) - addq $1, %rdx - cmpq %r8, %rdx - jne .L34 -.L28: - movq %rdi, %rax - ret - .p2align 4,,10 - .p2align 3 -.L47: - movq $-1, %r8 - .p2align 4,,10 - .p2align 3 -.L27: - movslq %esi, %rdx - movq %rdx, %rax - movq %rdx, %r9 - salq $48, %rax - salq $32, %r9 - orq %r9, %rax - orq %rdx, %rax - salq $16, %rdx - orq %rdx, %rax - .p2align 4,,10 - .p2align 3 -.L33: - subq $4, %r8 - addq $8, %rcx - movq %rax, -8(%rcx) - cmpq $4, %r8 - ja .L33 - jmp .L32 - .p2align 4,,10 - .p2align 3 -.L24: - testq %rdx, %rdx - je .L28 - xorl %eax, %eax - .p2align 4,,10 - .p2align 3 -.L29: - movw %si, (%rdi,%rax,2) - addq $1, %rax - cmpq %rax, %rdx - jne .L29 - leaq (%rdi,%rdx,2), %rax - ret - .p2align 4,,10 - .p2align 3 -.L35: - movq %rdi, %rcx - movq %rdx, %r8 - jmp .L25 - .cfi_endproc -.LFE3: - .size memsetw, .-memsetw - .p2align 4,,15 - .globl memsetd - .type memsetd, @function -memsetd: -.LFB4: - .cfi_startproc - movq %rdi, %rax - ret - .cfi_endproc -.LFE4: - .size memsetd, .-memsetd - .p2align 4,,15 - .globl memsetq - .type memsetq, @function -memsetq: -.LFB5: - .cfi_startproc - testq %rdx, %rdx - movq %rdi, %rax - je .L51 - xorl %ecx, %ecx - .p2align 4,,10 - .p2align 3 -.L52: - movq %rsi, (%rax,%rcx,8) - addq $1, %rcx - cmpq %rdx, %rcx - jne .L52 -.L51: - rep ret - .cfi_endproc -.LFE5: - .size memsetq, .-memsetq - .p2align 4,,15 - .globl memzero - .type memzero, @function -memzero: -.LFB6: - .cfi_startproc - movq %rsi, %rdx - movabsq $memsetb, %rax - xorl %esi, %esi - jmp *%rax - .cfi_endproc -.LFE6: - .size memzero, .-memzero - .p2align 4,,15 - .globl memcpy - .type memcpy, @function -memcpy: -.LFB7: - .cfi_startproc - testq %rdx, %rdx - movq %rdi, %rax - je .L59 - testb $1, %sil - movq %rsi, %rcx - jne .L91 -.L60: - testb $7, %al - je .L61 - andl $7, %ecx - jne .L89 - jmp .L61 - .p2align 4,,10 - .p2align 3 -.L62: - movsw - subq $2, %rdx -.L89: - cmpq $2, %rdx - ja .L62 -.L61: - cmpq $8, %rdx - jbe .L63 - leaq -9(%rdx), %r10 - xorl %ecx, %ecx - shrq $3, %r10 - leaq 8(,%r10,8), %r9 - .p2align 4,,10 - .p2align 3 -.L64: - movq (%rsi,%rcx), %r8 - movq %r8, (%rdi,%rcx) - addq $8, %rcx - cmpq %rcx, %r9 - jne .L64 - negq %r10 - addq %r9, %rsi - addq %r9, %rdi - leaq -8(%rdx,%r10,8), %rdx -.L65: - xorl %ecx, %ecx - .p2align 4,,10 - .p2align 3 -.L66: - movzbl (%rsi,%rcx), %r8d - movw %r8w, (%rdi,%rcx,2) - addq $1, %rcx - cmpq %rdx, %rcx - jne .L66 -.L59: - rep ret - .p2align 4,,10 - .p2align 3 -.L63: - testq %rdx, %rdx - jne .L65 - rep ret - .p2align 4,,10 - .p2align 3 -.L91: - testb $1, %al - je .L60 - movzbl (%rsi), %r8d - leaq 1(%rdi), %rdi - subq $1, %rdx - addq $1, %rsi - movb %r8b, (%rax) - jmp .L60 - .cfi_endproc -.LFE7: - .size memcpy, .-memcpy - .ident "GCC: (GNU) 7.3.0" diff --git a/obj/kaleid/common/rand.S b/obj/kaleid/common/rand.S deleted file mode 100644 index b91186e..0000000 --- a/obj/kaleid/common/rand.S +++ /dev/null @@ -1,52 +0,0 @@ - .file "rand.c" - .text - .p2align 4,,15 - .globl rand - .type rand, @function -rand: -.LFB2: - .cfi_startproc - movabsq $next, %rax - imulq $1103515245, (%rax), %rdx - addq $12345, %rdx - movq %rdx, (%rax) - shrq $16, %rdx - movl %edx, %eax - movl %edx, %esi - leaq (%rax,%rax,2), %rax - shrq $32, %rax - movq %rax, %rcx - movl %edx, %eax - subl %ecx, %eax - shrl %eax - addl %ecx, %eax - shrl $30, %eax - movl %eax, %ecx - sall $31, %ecx - subl %eax, %ecx - subl %ecx, %esi - movl %esi, %eax - ret - .cfi_endproc -.LFE2: - .size rand, .-rand - .p2align 4,,15 - .globl srand - .type srand, @function -srand: -.LFB3: - .cfi_startproc - movabsq $next, %rax - movl %edi, %edx - movq %rdx, (%rax) - ret - .cfi_endproc -.LFE3: - .size srand, .-srand - .data - .align 8 - .type next, @object - .size next, 8 -next: - .quad 7756 - .ident "GCC: (GNU) 7.3.0" diff --git a/obj/kaleid/common/status.S b/obj/kaleid/common/status.S deleted file mode 100644 index 99dcf29..0000000 --- a/obj/kaleid/common/status.S +++ /dev/null @@ -1,18 +0,0 @@ - .file "status.c" - .text - .section .rodata.str1.1,"aMS",@progbits,1 -.LC0: - .string "" - .text - .p2align 4,,15 - .globl describe_status - .type describe_status, @function -describe_status: -.LFB2: - .cfi_startproc - movabsq $.LC0, %rax - ret - .cfi_endproc -.LFE2: - .size describe_status, .-describe_status - .ident "GCC: (GNU) 7.3.0" diff --git a/obj/kaleid/common/string.S b/obj/kaleid/common/string.S deleted file mode 100644 index 0ff4b9e..0000000 --- a/obj/kaleid/common/string.S +++ /dev/null @@ -1,192 +0,0 @@ - .file "string.c" - .text - .p2align 4,,15 - .globl strlen - .type strlen, @function -strlen: -.LFB2: - .cfi_startproc - movq %rdi, %rax - .p2align 4,,10 - .p2align 3 -.L2: - addq $1, %rax - cmpb $0, -1(%rax) - jne .L2 - subq %rdi, %rax - subq $1, %rax - ret - .cfi_endproc -.LFE2: - .size strlen, .-strlen - .p2align 4,,15 - .globl strcpy - .type strcpy, @function -strcpy: -.LFB3: - .cfi_startproc - movq %rdi, %rax - movq %rdi, %rdx - .p2align 4,,10 - .p2align 3 -.L6: - addq $1, %rsi - movzbl -1(%rsi), %ecx - addq $1, %rdx - testb %cl, %cl - movb %cl, -1(%rdx) - jne .L6 - rep ret - .cfi_endproc -.LFE3: - .size strcpy, .-strcpy - .p2align 4,,15 - .globl strncpy - .type strncpy, @function -strncpy: -.LFB4: - .cfi_startproc - testq %rdx, %rdx - movq %rdi, %rax - je .L9 - movzbl (%rsi), %r8d - xorl %ecx, %ecx - testb %r8b, %r8b - jne .L11 - jmp .L12 - .p2align 4,,10 - .p2align 3 -.L20: - movzbl (%rsi,%rcx), %r8d - testb %r8b, %r8b - je .L12 -.L11: - movb %r8b, (%rax,%rcx) - addq $1, %rcx - cmpq %rcx, %rdx - jne .L20 -.L9: - rep ret - .p2align 4,,10 - .p2align 3 -.L12: - addq $1, %rcx - cmpq %rcx, %rdx - movb $0, -1(%rax,%rcx) - jbe .L9 - addq $1, %rcx - cmpq %rcx, %rdx - movb $0, -1(%rax,%rcx) - ja .L12 - jmp .L9 - .cfi_endproc -.LFE4: - .size strncpy, .-strncpy - .p2align 4,,15 - .globl xstrcnpy - .type xstrcnpy, @function -xstrcnpy: -.LFB5: - .cfi_startproc - testq %rdx, %rdx - je .L22 - movzbl (%rsi), %ecx - xorl %eax, %eax - testb %cl, %cl - jne .L24 - jmp .L25 - .p2align 4,,10 - .p2align 3 -.L33: - movzbl (%rsi,%rax), %ecx - testb %cl, %cl - je .L25 -.L24: - movb %cl, (%rdi,%rax) - addq $1, %rax - cmpq %rax, %rdx - jne .L33 -.L22: - movl $1, %eax - ret - .p2align 4,,10 - .p2align 3 -.L25: - addq $1, %rax - cmpq %rax, %rdx - movb $0, -1(%rdi,%rax) - jbe .L22 - addq $1, %rax - cmpq %rax, %rdx - movb $0, -1(%rdi,%rax) - ja .L25 - jmp .L22 - .cfi_endproc -.LFE5: - .size xstrcnpy, .-xstrcnpy - .p2align 4,,15 - .globl strrev - .type strrev, @function -strrev: -.LFB6: - .cfi_startproc - movq %rdi, %rax - movq %rsi, %rdx - .p2align 4,,10 - .p2align 3 -.L35: - addq $1, %rdx - cmpb $0, -1(%rdx) - jne .L35 - subq %rsi, %rdx - movb $0, -1(%rax,%rdx) - leaq -2(%rsi,%rdx), %rcx - movq %rax, %rdx - .p2align 4,,10 - .p2align 3 -.L36: - movzbl (%rcx), %esi - addq $1, %rdx - subq $1, %rcx - testb %sil, %sil - movb %sil, -1(%rdx) - jne .L36 - rep ret - .cfi_endproc -.LFE6: - .size strrev, .-strrev - .p2align 4,,15 - .globl reverse - .type reverse, @function -reverse: -.LFB7: - .cfi_startproc - movq %rdi, %rax - movq %rdi, %rdx - .p2align 4,,10 - .p2align 3 -.L40: - addq $1, %rdx - cmpb $0, -1(%rdx) - jne .L40 - subq $2, %rdx - cmpq %rdx, %rax - jnb .L41 - movq %rax, %rcx - .p2align 4,,10 - .p2align 3 -.L42: - movzbl (%rdx), %esi - movzbl (%rcx), %r8d - subq $1, %rdx - addq $1, %rcx - cmpq %rcx, %rdx - movb %r8b, 1(%rdx) - movb %sil, -1(%rcx) - ja .L42 -.L41: - rep ret - .cfi_endproc -.LFE7: - .size reverse, .-reverse - .ident "GCC: (GNU) 7.3.0" diff --git a/obj/kaleid/common/ultoa.S b/obj/kaleid/common/ultoa.S deleted file mode 100644 index 9f381f4..0000000 --- a/obj/kaleid/common/ultoa.S +++ /dev/null @@ -1,55 +0,0 @@ - .file "convert.c" - .text - .p2align 4,,15 - .globl ultoa - .type ultoa, @function -ultoa: -.LFB2: - .cfi_startproc - leal -2(%rdx), %ecx - movq %rdi, %rax - cmpl $34, %ecx - ja .L2 - testq %rdi, %rdi - jne .L3 - leaq 1(%rsi), %rcx - movb $48, (%rsi) -.L4: - movb $0, (%rcx) - movq %rsi, %rdi - movabsq $reverse, %rax - jmp *%rax - .p2align 4,,10 - .p2align 3 -.L3: - movslq %edx, %r8 - movq %rsi, %rcx - movabsq $digits, %r9 - .p2align 4,,10 - .p2align 3 -.L5: - xorl %edx, %edx - addq $1, %rcx - divq %r8 - movzbl (%r9,%rdx), %edx - testq %rax, %rax - movb %dl, -1(%rcx) - jne .L5 - jmp .L4 - .p2align 4,,10 - .p2align 3 -.L2: - xorl %eax, %eax - ret - .cfi_endproc -.LFE2: - .size ultoa, .-ultoa - .section .rodata - .align 32 - .type digits, @object - .size digits, 36 -digits: - .byte 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x41,0x42,0x43 - .byte 0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50 - .byte 0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a - .ident "GCC: (GNU) 7.3.0" diff --git a/obj/kaleid/common/utoa.S b/obj/kaleid/common/utoa.S deleted file mode 100644 index dc4310c..0000000 --- a/obj/kaleid/common/utoa.S +++ /dev/null @@ -1,56 +0,0 @@ - .file "convert.c" - .text - .p2align 4,,15 - .globl utoa - .type utoa, @function -utoa: -.LFB2: - .cfi_startproc - movl %edx, %r8d - leal -2(%rdx), %edx - movl %edi, %eax - cmpl $34, %edx - ja .L2 - testl %edi, %edi - jne .L5 - leaq 1(%rsi), %rcx - movb $48, (%rsi) -.L4: - movb $0, (%rcx) - movq %rsi, %rdi - movabsq $reverse, %rax - jmp *%rax - .p2align 4,,10 - .p2align 3 -.L5: - movq %rsi, %rcx - movabsq $digits, %r9 - .p2align 4,,10 - .p2align 3 -.L3: - xorl %edx, %edx - addq $1, %rcx - divl %r8d - movl %edx, %edx - testl %eax, %eax - movzbl (%r9,%rdx), %edx - movb %dl, -1(%rcx) - jne .L3 - jmp .L4 - .p2align 4,,10 - .p2align 3 -.L2: - xorl %eax, %eax - ret - .cfi_endproc -.LFE2: - .size utoa, .-utoa - .section .rodata - .align 32 - .type digits, @object - .size digits, 36 -digits: - .byte 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x41,0x42,0x43 - .byte 0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50 - .byte 0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a - .ident "GCC: (GNU) 7.3.0" diff --git a/obj/kaleid/kernel/init.S b/obj/kaleid/kernel/init.S deleted file mode 100644 index c2fd44a..0000000 --- a/obj/kaleid/kernel/init.S +++ /dev/null @@ -1,30 +0,0 @@ - .file "init.c" - .text - .section .rodata.str1.1,"aMS",@progbits,1 -.LC0: - .string "Goodbye World :(" - .text - .p2align 4,,15 - .globl StartKern - .type StartKern, @function -StartKern: -.LFB2: - .cfi_startproc - subq $8, %rsp - .cfi_def_cfa_offset 16 -/APP -# 21 "kaleid/kernel/init.c" 1 - cli -# 0 "" 2 -/NO_APP - movabsq $__kstate, %rax - movb $3, (%rax) - movabsq $InitTerms, %rax - call *%rax - movabsq $.LC0, %rdi - movabsq $StartPanic, %rax - call *%rax - .cfi_endproc -.LFE2: - .size StartKern, .-StartKern - .ident "GCC: (GNU) 7.3.0" diff --git a/obj/kaleid/kernel/io/ports.S b/obj/kaleid/kernel/io/ports.S deleted file mode 100644 index 8a0517d..0000000 --- a/obj/kaleid/kernel/io/ports.S +++ /dev/null @@ -1,3 +0,0 @@ - .file "ports.c" - .text - .ident "GCC: (GNU) 7.3.0" diff --git a/obj/kaleid/kernel/io/terminal.S b/obj/kaleid/kernel/io/terminal.S deleted file mode 100644 index 42e0a6f..0000000 --- a/obj/kaleid/kernel/io/terminal.S +++ /dev/null @@ -1,846 +0,0 @@ - .file "terminal.c" - .text - .section .rodata.str1.1,"aMS",@progbits,1 -.LC0: - .string "kaleid/kernel/io/terminal.c" -.LC1: - .string "kt->kt_init == INITOK" - .section .rodata.str1.8,"aMS",@progbits,1 - .align 8 -.LC2: - .string "(&(kt)->kt_lock)->lk_init == INITOK" - .align 8 -.LC3: - .string "DosAquireLock on an already locked object" - .align 8 -.LC4: - .string "DosReleaseLock on an unlocked object" - .text - .p2align 4,,15 - .globl ClearTerm - .type ClearTerm, @function -ClearTerm: -.LFB3: - .cfi_startproc - testq %rdi, %rdi - je .L10 - pushq %rbx - .cfi_def_cfa_offset 16 - .cfi_offset 3, -16 - cmpl $-889275714, 80(%rdi) - movq %rdi, %rbx - jne .L26 -/APP -# 69 "kaleid/kernel/io/terminal.c" 1 - cli -# 0 "" 2 -/NO_APP - cmpl $-889275714, 24(%rdi) - jne .L27 - movl 4(%rdi), %eax - leal 1(%rax), %edx - testl %eax, %eax - movl %edx, 4(%rdi) - jne .L28 -.L5: -/APP -# 69 "kaleid/kernel/io/terminal.c" 1 - sti -# 0 "" 2 -/NO_APP - movq 48(%rbx), %rcx - movzbl 40(%rbx), %edx - imulq 56(%rbx), %rcx - sall $8, %edx - orl $32, %edx - testq %rcx, %rcx - je .L6 - movq 32(%rbx), %rax - leaq (%rax,%rcx,2), %rcx - .p2align 4,,10 - .p2align 3 -.L7: - movw %dx, (%rax) - addq $2, %rax - cmpq %rax, %rcx - jne .L7 -.L6: - movq $0, 72(%rbx) - movq $0, 64(%rbx) -/APP -# 71 "kaleid/kernel/io/terminal.c" 1 - cli -# 0 "" 2 -/NO_APP - cmpl $-889275714, 24(%rbx) - jne .L29 - movl 4(%rbx), %eax - leal 1(%rax), %edx - testl %eax, %eax - movl %edx, 4(%rbx) - jne .L30 -.L9: -/APP -# 71 "kaleid/kernel/io/terminal.c" 1 - sti -# 0 "" 2 -/NO_APP - xorl %eax, %eax - popq %rbx - .cfi_remember_state - .cfi_restore 3 - .cfi_def_cfa_offset 8 - ret - .p2align 4,,10 - .p2align 3 -.L30: - .cfi_restore_state - movabsq $.LC4, %rdi - xorl %eax, %eax - movabsq $StartPanic, %rdx - call *%rdx - jmp .L9 - .p2align 4,,10 - .p2align 3 -.L28: - movabsq $.LC3, %rdi - xorl %eax, %eax - movabsq $StartPanic, %rdx - call *%rdx - jmp .L5 - .p2align 4,,10 - .p2align 3 -.L26: - movabsq $__func__.1202, %rcx - movl $67, %edx - movabsq $.LC0, %rsi - movabsq $.LC1, %rdi - movabsq $_assert_handler, %rax - call *%rax - .p2align 4,,10 - .p2align 3 -.L27: - movabsq $__func__.1202, %rcx - movl $69, %edx - movabsq $.LC0, %rsi - movabsq $.LC2, %rdi - movabsq $_assert_handler, %rax - call *%rax - .p2align 4,,10 - .p2align 3 -.L29: - movabsq $__func__.1202, %rcx - movl $71, %edx - movabsq $.LC0, %rsi - movabsq $.LC2, %rdi - movabsq $_assert_handler, %rax - call *%rax -.L10: - .cfi_def_cfa_offset 8 - .cfi_restore 3 - movq $-6, %rax - ret - .cfi_endproc -.LFE3: - .size ClearTerm, .-ClearTerm - .section .rodata.str1.8 - .align 8 -.LC5: - .string "!stdout && _vga_term.kt_init != INITOK" - .text - .p2align 4,,15 - .globl InitTerms - .type InitTerms, @function -InitTerms: -.LFB2: - .cfi_startproc - movabsq $stdout, %rdx - cmpq $0, (%rdx) - jne .L32 - movabsq $_vga_term, %rdi - cmpl $-889275714, 80(%rdi) - je .L32 - movabsq $_vga_term+80, %rax - movq %rdi, (%rdx) - movl $-889275714, (%rax) - movq %rdi, %rax - movabsq %rax, stddbg - movabsq $ClearTerm, %rax - jmp *%rax - .p2align 4,,10 - .p2align 3 -.L32: - subq $8, %rsp - .cfi_def_cfa_offset 16 - movabsq $__func__.1198, %rcx - movl $49, %edx - movabsq $.LC0, %rsi - movabsq $.LC5, %rdi - movabsq $_assert_handler, %rax - call *%rax - .cfi_endproc -.LFE2: - .size InitTerms, .-InitTerms - .p2align 4,,15 - .globl ChTermColor - .type ChTermColor, @function -ChTermColor: -.LFB4: - .cfi_startproc - cmpb $15, %sil - ja .L42 - testq %rdi, %rdi - je .L43 - pushq %rbp - .cfi_def_cfa_offset 16 - .cfi_offset 6, -16 - pushq %rbx - .cfi_def_cfa_offset 24 - .cfi_offset 3, -24 - movl %esi, %ebp - movq %rdi, %rbx - subq $8, %rsp - .cfi_def_cfa_offset 32 -/APP -# 87 "kaleid/kernel/io/terminal.c" 1 - cli -# 0 "" 2 -/NO_APP - cmpl $-889275714, 24(%rdi) - jne .L54 - movl 4(%rdi), %eax - leal 1(%rax), %edx - testl %eax, %eax - movl %edx, 4(%rdi) - jne .L55 -.L39: -/APP -# 87 "kaleid/kernel/io/terminal.c" 1 - sti -# 0 "" 2 -/NO_APP - movb %bpl, 40(%rbx) -/APP -# 89 "kaleid/kernel/io/terminal.c" 1 - cli -# 0 "" 2 -/NO_APP - cmpl $-889275714, 24(%rbx) - jne .L56 - movl 4(%rbx), %eax - leal 1(%rax), %edx - testl %eax, %eax - movl %edx, 4(%rbx) - jne .L57 -.L41: -/APP -# 89 "kaleid/kernel/io/terminal.c" 1 - sti -# 0 "" 2 -/NO_APP - addq $8, %rsp - .cfi_remember_state - .cfi_def_cfa_offset 24 - xorl %eax, %eax - popq %rbx - .cfi_restore 3 - .cfi_def_cfa_offset 16 - popq %rbp - .cfi_restore 6 - .cfi_def_cfa_offset 8 - ret - .p2align 4,,10 - .p2align 3 -.L55: - .cfi_restore_state - movabsq $.LC3, %rdi - xorl %eax, %eax - movabsq $StartPanic, %rdx - call *%rdx - jmp .L39 - .p2align 4,,10 - .p2align 3 -.L57: - movabsq $.LC4, %rdi - xorl %eax, %eax - movabsq $StartPanic, %rdx - call *%rdx - jmp .L41 - .p2align 4,,10 - .p2align 3 -.L54: - movabsq $__func__.1210, %rcx - movl $87, %edx - movabsq $.LC0, %rsi - movabsq $.LC2, %rdi - movabsq $_assert_handler, %rax - call *%rax - .p2align 4,,10 - .p2align 3 -.L56: - movabsq $__func__.1210, %rcx - movl $89, %edx - movabsq $.LC0, %rsi - movabsq $.LC2, %rdi - movabsq $_assert_handler, %rax - call *%rax - .p2align 4,,10 - .p2align 3 -.L42: - .cfi_def_cfa_offset 8 - .cfi_restore 3 - .cfi_restore 6 - movq $-5, %rax - ret -.L43: - movq $-6, %rax - ret - .cfi_endproc -.LFE4: - .size ChTermColor, .-ChTermColor - .p2align 4,,15 - .globl ClearTermUnlocked - .type ClearTermUnlocked, @function -ClearTermUnlocked: -.LFB7: - .cfi_startproc - movq 48(%rdi), %rcx - movzbl 40(%rdi), %edx - imulq 56(%rdi), %rcx - sall $8, %edx - orl $32, %edx - testq %rcx, %rcx - je .L59 - movq 32(%rdi), %rax - leaq (%rax,%rcx,2), %rcx - .p2align 4,,10 - .p2align 3 -.L60: - movw %dx, (%rax) - addq $2, %rax - cmpq %rcx, %rax - jne .L60 -.L59: - movq $0, 72(%rdi) - movq $0, 64(%rdi) - ret - .cfi_endproc -.LFE7: - .size ClearTermUnlocked, .-ClearTermUnlocked - .p2align 4,,15 - .globl PutOnTermUnlocked - .type PutOnTermUnlocked, @function -PutOnTermUnlocked: -.LFB8: - .cfi_startproc - cmpb $13, %sil - je .L69 - movsbl %sil, %esi - movabsq $PutOnTermUnlocked.part.0, %rax - jmp *%rax - .p2align 4,,10 - .p2align 3 -.L69: - movq $0, 64(%rdi) - ret - .cfi_endproc -.LFE8: - .size PutOnTermUnlocked, .-PutOnTermUnlocked - .p2align 4,,15 - .type PutOnTermUnlocked.part.0, @function -PutOnTermUnlocked.part.0: -.LFB10: - .cfi_startproc - pushq %r13 - .cfi_def_cfa_offset 16 - .cfi_offset 13, -16 - pushq %r12 - .cfi_def_cfa_offset 24 - .cfi_offset 12, -24 - pushq %rbp - .cfi_def_cfa_offset 32 - .cfi_offset 6, -32 - pushq %rbx - .cfi_def_cfa_offset 40 - .cfi_offset 3, -40 - movq %rdi, %rbx - subq $8, %rsp - .cfi_def_cfa_offset 48 - cmpb $10, %sil - je .L81 - cmpb $9, %sil - movq 72(%rdi), %rbp - je .L82 - movq 48(%rdi), %rdx - movzbl 40(%rbx), %ecx - movsbw %sil, %si - movq 64(%rdi), %rax - movq 32(%rdi), %rdi - imulq %rdx, %rbp - sall $8, %ecx - orl %ecx, %esi - addq %rax, %rbp - movw %si, (%rdi,%rbp,2) -.L72: - addq $1, %rax - cmpq %rdx, %rax - je .L77 - movq %rax, 64(%rbx) -.L70: - addq $8, %rsp - .cfi_remember_state - .cfi_def_cfa_offset 40 - popq %rbx - .cfi_restore 3 - .cfi_def_cfa_offset 32 - popq %rbp - .cfi_restore 6 - .cfi_def_cfa_offset 24 - popq %r12 - .cfi_restore 12 - .cfi_def_cfa_offset 16 - popq %r13 - .cfi_restore 13 - .cfi_def_cfa_offset 8 - ret - .p2align 4,,10 - .p2align 3 -.L82: - .cfi_restore_state - movq %rbp, %rax - movl $4, %r12d - movabsq $PutOnTermUnlocked, %r13 - cmpq %rbp, %rax - je .L83 -.L74: - subl $1, %r12d - je .L84 - movq 72(%rbx), %rax - cmpq %rbp, %rax - jne .L74 -.L83: - movl $32, %esi - movq %rbx, %rdi - call *%r13 - jmp .L74 - .p2align 4,,10 - .p2align 3 -.L77: - movq 72(%rbx), %rax - movq $0, 64(%rbx) - addq $1, %rax - cmpq 56(%rbx), %rax - movq %rax, 72(%rbx) - jne .L70 - movq $0, 72(%rbx) - addq $8, %rsp - .cfi_remember_state - .cfi_def_cfa_offset 40 - popq %rbx - .cfi_restore 3 - .cfi_def_cfa_offset 32 - popq %rbp - .cfi_restore 6 - .cfi_def_cfa_offset 24 - popq %r12 - .cfi_restore 12 - .cfi_def_cfa_offset 16 - popq %r13 - .cfi_restore 13 - .cfi_def_cfa_offset 8 - ret - .p2align 4,,10 - .p2align 3 -.L81: - .cfi_restore_state - movq 48(%rdi), %rdx - leaq -1(%rdx), %rax - movq %rax, 72(%rdi) - movq 64(%rdi), %rax - jmp .L72 - .p2align 4,,10 - .p2align 3 -.L84: - movq 64(%rbx), %rax - movq 48(%rbx), %rdx - jmp .L72 - .cfi_endproc -.LFE10: - .size PutOnTermUnlocked.part.0, .-PutOnTermUnlocked.part.0 - .p2align 4,,15 - .globl PutOnTerm - .type PutOnTerm, @function -PutOnTerm: -.LFB5: - .cfi_startproc - testq %rdi, %rdi - je .L94 - pushq %rbp - .cfi_def_cfa_offset 16 - .cfi_offset 6, -16 - pushq %rbx - .cfi_def_cfa_offset 24 - .cfi_offset 3, -24 - movl %esi, %ebp - movq %rdi, %rbx - subq $8, %rsp - .cfi_def_cfa_offset 32 - cmpl $-889275714, 80(%rdi) - jne .L105 -/APP -# 104 "kaleid/kernel/io/terminal.c" 1 - cli -# 0 "" 2 -/NO_APP - cmpl $-889275714, 24(%rdi) - jne .L106 - movl 4(%rdi), %eax - leal 1(%rax), %edx - testl %eax, %eax - movl %edx, 4(%rdi) - jne .L107 -.L89: -/APP -# 104 "kaleid/kernel/io/terminal.c" 1 - sti -# 0 "" 2 -/NO_APP - cmpb $13, %bpl - jne .L90 - movq $0, 64(%rbx) -.L91: -/APP -# 106 "kaleid/kernel/io/terminal.c" 1 - cli -# 0 "" 2 -/NO_APP - cmpl $-889275714, 24(%rbx) - jne .L108 - movl 4(%rbx), %eax - leal 1(%rax), %edx - testl %eax, %eax - movl %edx, 4(%rbx) - jne .L109 -.L93: -/APP -# 106 "kaleid/kernel/io/terminal.c" 1 - sti -# 0 "" 2 -/NO_APP - addq $8, %rsp - .cfi_remember_state - .cfi_def_cfa_offset 24 - xorl %eax, %eax - popq %rbx - .cfi_restore 3 - .cfi_def_cfa_offset 16 - popq %rbp - .cfi_restore 6 - .cfi_def_cfa_offset 8 - ret - .p2align 4,,10 - .p2align 3 -.L90: - .cfi_restore_state - movsbl %bpl, %esi - movq %rbx, %rdi - movabsq $PutOnTermUnlocked.part.0, %rax - call *%rax - jmp .L91 - .p2align 4,,10 - .p2align 3 -.L107: - movabsq $.LC3, %rdi - xorl %eax, %eax - movabsq $StartPanic, %rdx - call *%rdx - jmp .L89 - .p2align 4,,10 - .p2align 3 -.L109: - movabsq $.LC4, %rdi - xorl %eax, %eax - movabsq $StartPanic, %rdx - call *%rdx - jmp .L93 - .p2align 4,,10 - .p2align 3 -.L105: - movabsq $__func__.1217, %rcx - movl $102, %edx - movabsq $.LC0, %rsi - movabsq $.LC1, %rdi - movabsq $_assert_handler, %rax - call *%rax - .p2align 4,,10 - .p2align 3 -.L106: - movabsq $__func__.1217, %rcx - movl $104, %edx - movabsq $.LC0, %rsi - movabsq $.LC2, %rdi - movabsq $_assert_handler, %rax - call *%rax - .p2align 4,,10 - .p2align 3 -.L108: - movabsq $__func__.1217, %rcx - movl $106, %edx - movabsq $.LC0, %rsi - movabsq $.LC2, %rdi - movabsq $_assert_handler, %rax - call *%rax -.L94: - .cfi_def_cfa_offset 8 - .cfi_restore 3 - .cfi_restore 6 - movq $-6, %rax - ret - .cfi_endproc -.LFE5: - .size PutOnTerm, .-PutOnTerm - .p2align 4,,15 - .globl PrintOnTerm - .type PrintOnTerm, @function -PrintOnTerm: -.LFB6: - .cfi_startproc - testq %rdi, %rdi - je .L121 - pushq %r12 - .cfi_def_cfa_offset 16 - .cfi_offset 12, -16 - pushq %rbp - .cfi_def_cfa_offset 24 - .cfi_offset 6, -24 - movq %rdi, %rbp - pushq %rbx - .cfi_def_cfa_offset 32 - .cfi_offset 3, -32 - cmpl $-889275714, 80(%rdi) - jne .L132 -/APP -# 121 "kaleid/kernel/io/terminal.c" 1 - cli -# 0 "" 2 -/NO_APP - cmpl $-889275714, 24(%rdi) - jne .L133 - movl 4(%rdi), %eax - movq %rsi, %rbx - leal 1(%rax), %edx - testl %eax, %eax - movl %edx, 4(%rdi) - jne .L134 -.L114: -/APP -# 121 "kaleid/kernel/io/terminal.c" 1 - sti -# 0 "" 2 -/NO_APP - movabsq $PutOnTermUnlocked.part.0, %r12 -.L115: - movsbl (%rbx), %esi - testb %sil, %sil - je .L135 -.L118: - addq $1, %rbx - cmpb $13, %sil - jne .L116 - movq $0, 64(%rbp) - movsbl (%rbx), %esi - testb %sil, %sil - jne .L118 -.L135: -/APP -# 125 "kaleid/kernel/io/terminal.c" 1 - cli -# 0 "" 2 -/NO_APP - cmpl $-889275714, 24(%rbp) - jne .L136 - movl 4(%rbp), %eax - leal 1(%rax), %edx - testl %eax, %eax - movl %edx, 4(%rbp) - jne .L137 -.L120: -/APP -# 125 "kaleid/kernel/io/terminal.c" 1 - sti -# 0 "" 2 -/NO_APP - xorl %eax, %eax - popq %rbx - .cfi_remember_state - .cfi_restore 3 - .cfi_def_cfa_offset 24 - popq %rbp - .cfi_restore 6 - .cfi_def_cfa_offset 16 - popq %r12 - .cfi_restore 12 - .cfi_def_cfa_offset 8 - ret - .p2align 4,,10 - .p2align 3 -.L116: - .cfi_restore_state - movq %rbp, %rdi - call *%r12 - jmp .L115 - .p2align 4,,10 - .p2align 3 -.L137: - movabsq $.LC4, %rdi - xorl %eax, %eax - movabsq $StartPanic, %rdx - call *%rdx - jmp .L120 - .p2align 4,,10 - .p2align 3 -.L134: - movabsq $.LC3, %rdi - xorl %eax, %eax - movabsq $StartPanic, %rdx - call *%rdx - jmp .L114 - .p2align 4,,10 - .p2align 3 -.L132: - movabsq $__func__.1224, %rcx - movl $119, %edx - movabsq $.LC0, %rsi - movabsq $.LC1, %rdi - movabsq $_assert_handler, %rax - call *%rax - .p2align 4,,10 - .p2align 3 -.L133: - movabsq $__func__.1224, %rcx - movl $121, %edx - movabsq $.LC0, %rsi - movabsq $.LC2, %rdi - movabsq $_assert_handler, %rax - call *%rax - .p2align 4,,10 - .p2align 3 -.L136: - movabsq $__func__.1224, %rcx - movl $125, %edx - movabsq $.LC0, %rsi - movabsq $.LC2, %rdi - movabsq $_assert_handler, %rax - call *%rax -.L121: - .cfi_def_cfa_offset 8 - .cfi_restore 3 - .cfi_restore 6 - .cfi_restore 12 - movq $-6, %rax - ret - .cfi_endproc -.LFE6: - .size PrintOnTerm, .-PrintOnTerm - .p2align 4,,15 - .globl PrintOnTermUnlocked - .type PrintOnTermUnlocked, @function -PrintOnTermUnlocked: -.LFB9: - .cfi_startproc - pushq %r12 - .cfi_def_cfa_offset 16 - .cfi_offset 12, -16 - movabsq $PutOnTermUnlocked.part.0, %r12 - pushq %rbp - .cfi_def_cfa_offset 24 - .cfi_offset 6, -24 - movq %rdi, %rbp - pushq %rbx - .cfi_def_cfa_offset 32 - .cfi_offset 3, -32 - movq %rsi, %rbx -.L139: - movsbl (%rbx), %esi - testb %sil, %sil - je .L144 -.L142: - addq $1, %rbx - cmpb $13, %sil - jne .L140 - movq $0, 64(%rbp) - movsbl (%rbx), %esi - testb %sil, %sil - jne .L142 -.L144: - popq %rbx - .cfi_remember_state - .cfi_restore 3 - .cfi_def_cfa_offset 24 - popq %rbp - .cfi_restore 6 - .cfi_def_cfa_offset 16 - popq %r12 - .cfi_restore 12 - .cfi_def_cfa_offset 8 - ret - .p2align 4,,10 - .p2align 3 -.L140: - .cfi_restore_state - movq %rbp, %rdi - call *%r12 - jmp .L139 - .cfi_endproc -.LFE9: - .size PrintOnTermUnlocked, .-PrintOnTermUnlocked - .section .rodata - .align 8 - .type __func__.1224, @object - .size __func__.1224, 12 -__func__.1224: - .string "PrintOnTerm" - .align 8 - .type __func__.1217, @object - .size __func__.1217, 10 -__func__.1217: - .string "PutOnTerm" - .align 8 - .type __func__.1210, @object - .size __func__.1210, 12 -__func__.1210: - .string "ChTermColor" - .align 8 - .type __func__.1202, @object - .size __func__.1202, 10 -__func__.1202: - .string "ClearTerm" - .align 8 - .type __func__.1198, @object - .size __func__.1198, 10 -__func__.1198: - .string "InitTerms" - .comm stddbg,8,8 - .comm stdout,8,8 - .data - .align 32 - .type _vga_term, @object - .size _vga_term, 88 -_vga_term: - .byte 0 - .zero 3 - .long 0 - .quad 0 - .quad 0 - .long -889275714 - .zero 4 - .quad 753664 - .byte 7 - .zero 7 - .quad 80 - .quad 25 - .quad 0 - .quad 0 - .long 0 - .zero 4 - .ident "GCC: (GNU) 7.3.0" diff --git a/obj/kaleid/kernel/ke/lock.S b/obj/kaleid/kernel/ke/lock.S deleted file mode 100644 index 77581ed..0000000 --- a/obj/kaleid/kernel/ke/lock.S +++ /dev/null @@ -1,3 +0,0 @@ - .file "lock.c" - .text - .ident "GCC: (GNU) 7.3.0" diff --git a/obj/kaleid/kernel/ke/panic.S b/obj/kaleid/kernel/ke/panic.S deleted file mode 100644 index 3191489..0000000 --- a/obj/kaleid/kernel/ke/panic.S +++ /dev/null @@ -1,103 +0,0 @@ - .file "panic.c" - .text - .section .rodata.str1.1,"aMS",@progbits,1 -.LC0: - .string "(no message given)" -.LC1: - .string "double panic!\n" -.LC2: - .string "panic! - " - .text - .p2align 4,,15 - .globl StartPanic - .type StartPanic, @function -StartPanic: -.LFB3: - .cfi_startproc - pushq %r13 - .cfi_def_cfa_offset 16 - .cfi_offset 13, -16 - pushq %r12 - .cfi_def_cfa_offset 24 - .cfi_offset 12, -24 - pushq %rbp - .cfi_def_cfa_offset 32 - .cfi_offset 6, -32 - pushq %rbx - .cfi_def_cfa_offset 40 - .cfi_offset 3, -40 - movq %rdi, %rbx - subq $8, %rsp - .cfi_def_cfa_offset 48 -/APP -# 43 "kaleid/kernel/ke/panic.c" 1 - cli -# 0 "" 2 -/NO_APP - movabsq $__kstate, %rax - movabsq $stdout, %rbp - movabsq $__panicmsg, %r13 - movb $2, (%rax) - movq 0(%rbp), %rdi - movabsq $ClearTermUnlocked, %rax - call *%rax - testq %rbx, %rbx - movabsq $.LC0, %rax - movq 0(%rbp), %rdi - cmove %rax, %rbx - cmpq $0, 0(%r13) - movabsq $PrintOnTermUnlocked, %r12 - je .L3 - movabsq $.LC1, %rsi - call *%r12 -/APP -# 55 "kaleid/kernel/ke/panic.c" 1 - hlt -# 0 "" 2 -/NO_APP -.L3: - movabsq $.LC2, %rsi - movq 0(%rbp), %rdi - movq %rbx, 0(%r13) - call *%r12 - movq %rbx, %rsi - movq 0(%rbp), %rdi - call *%r12 - .p2align 4,,10 - .p2align 3 -.L4: -/APP -# 65 "kaleid/kernel/ke/panic.c" 1 - hlt -# 0 "" 2 -/NO_APP - jmp .L4 - .cfi_endproc -.LFE3: - .size StartPanic, .-StartPanic - .p2align 4,,15 - .globl _assert_handler - .type _assert_handler, @function -_assert_handler: -.LFB2: - .cfi_startproc - subq $8, %rsp - .cfi_def_cfa_offset 16 -/APP -# 30 "kaleid/kernel/ke/panic.c" 1 - cli -# 0 "" 2 -/NO_APP - movabsq $StartPanic, %rax - call *%rax - .cfi_endproc -.LFE2: - .size _assert_handler, .-_assert_handler - .globl __panicmsg - .section .bss - .align 8 - .type __panicmsg, @object - .size __panicmsg, 8 -__panicmsg: - .zero 8 - .ident "GCC: (GNU) 7.3.0" diff --git a/obj/kaleid/kernel/ke/state.S b/obj/kaleid/kernel/ke/state.S deleted file mode 100644 index 11ea154..0000000 --- a/obj/kaleid/kernel/ke/state.S +++ /dev/null @@ -1,4 +0,0 @@ - .file "state.c" - .text - .comm __kstate,1,1 - .ident "GCC: (GNU) 7.3.0" diff --git a/src/CONTACT b/src/CONTACT deleted file mode 100644 index dd6d86a..0000000 --- a/src/CONTACT +++ /dev/null @@ -1 +0,0 @@ -XXX diff --git a/src/kaleid/common/old/common.h b/src/kaleid/common/old/common.h deleted file mode 100644 index 1c9c0d6..0000000 --- a/src/kaleid/common/old/common.h +++ /dev/null @@ -1,179 +0,0 @@ -//----------------------------------------------------------------------------// -// 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 -#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 - -#endif - -//------------------------------------------// -// END OF "kaleid/common/common.h" // -//------------------------------------------// - -#endif - diff --git a/src/kaleid/common/old/folder.desc b/src/kaleid/common/old/folder.desc deleted file mode 100644 index eaf5c24..0000000 --- a/src/kaleid/common/old/folder.desc +++ /dev/null @@ -1,37 +0,0 @@ ---------------------------------------------------------------------- - GNU GPL OS/K - - Authors: spectral` - NeoX - - 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 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. - 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/old/stdlib.h b/src/kaleid/common/old/stdlib.h deleted file mode 100644 index 5f8e96c..0000000 --- a/src/kaleid/common/old/stdlib.h +++ /dev/null @@ -1,90 +0,0 @@ -//----------------------------------------------------------------------------// -// GNU GPL OS/K // -// // -// Authors: spectral` // -// NeoX // -// // -// Desc: Kaleid C runtime library // -//----------------------------------------------------------------------------// - -#ifndef _KALCOMM_STDLIB_H -#define _KALCOMM_STDLIB_H - -//------------------------------------------// -// Typedefs // -//------------------------------------------// - -#ifndef __size_t -#define __size_t -typedef unsigned long size_t; -#endif - -#ifndef __va_list -#define __va_list -typedef __builtin_va_start va_list; -#endif - -//------------------------------------------// -// Memory management utilitaries // -//------------------------------------------// - -#ifndef _OSK_SOURCE -# define memcpy _osk_memcpy -# define memcmp _osk_memcmp -# define memzero _osk_memzero -#endif - -#ifndef memset -# define memset memsetb -#endif -void *memsetb(void *, int, size_t); -void *memsetw(void *, int, size_t); -void *memsetd(void *, int, size_t); -void *memsetq(void *, long, 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 header file // -//------------------------------------------// - -#endif - diff --git a/src/kaleid/common/string.c b/src/kaleid/common/string.c deleted file mode 100644 index 81b4847..0000000 --- a/src/kaleid/common/string.c +++ /dev/null @@ -1,100 +0,0 @@ -//----------------------------------------------------------------------------// -// GNU GPL OS/K // -// // -// Authors: spectral` // -// NeoX // -// // -// Desc: String-related functions // -//----------------------------------------------------------------------------// - -#include - -// -// Returns str's length -// -size_t strlen(const char *str) -{ - const char *base = str; - - while (*str++); - - return (str - base - 1); -} - -// -// Copy the string src into dest -// -char *strcpy(char *dest, const char *src) -{ - char *base = dest; - while ((*dest++ = *src++)); - return base; -} - -// -// strcpy() but always writes n bytes -// -char *strncpy(char *dest, const char *src, size_t n) -{ - size_t it; - - for (it = 0; it < n && src[it]; it++) { - dest[it] = src[it]; - } - - while (it < n) dest[it++] = 0; - return dest; -} - -// -// strncpy() but safer - always null-terminate, -// returns boolean indicating whether copy was complete -// XXX find a better name -// XXX actually implement this -// -size_t xstrcnpy(char *dest, const char *src, size_t n) -{ - size_t it; - - for (it = 0; it < n && src[it]; it++) { - dest[it] = src[it]; - } - - while (it < n) dest[it++] = 0; - - return TRUE; -} - -// -// Reverses the string src, putting the result into dest -// -char *strrev(char *dest, const char *src) -{ - char *orig = dest; - size_t n = strlen(src); - - dest[n--] = '\0'; - - while ((*dest++ = src[n--])); - - return orig; -} - -// -// Reverses a string, modifying it -// Returns a point to said string -// -char *reverse(char *str) -{ - char ch, *orig = str; - size_t n = strlen(str); - char *temp = str + n - 1; - - while (temp > str) { - ch = *temp; - *temp-- = *str; - *str++ = ch; - } - - return orig; -} diff --git a/src/kaleid/common/test/test-common.c b/src/kaleid/common/test/test-common.c deleted file mode 100644 index e4df713..0000000 --- a/src/kaleid/common/test/test-common.c +++ /dev/null @@ -1,83 +0,0 @@ -//----------------------------------------------------------------------------// -// GNU GPL OS/K // -// // -// Authors: spectral` // -// NeoX // -// // -// Desc: Test file for common/ // -//----------------------------------------------------------------------------// - -#include -#include - -void *_osk_memsetw(void *, int, long); -char *_osk_itoa(int, char *, int); -char *_osk_ltoa(long, char *, int); -char *_osk_utoa(unsigned int, char *, int); -char *_osk_ultoa(unsigned long, char *, int); - -int main(int argc, char *argv[]) -{ - (void)argc; - (void)argv; - - // please don't mind how weird this file is - // I remove tests of "simple" functions after - // I'm done with testing that function - // so a lot of test variables remain in case - // I need them for a future test - - //const char *test1 = "test string\n"; - //const size_t size1 = strlen(test1); - //char *test2 = malloc(size1); - //char *test3 = malloc(size1); - -#if 0 - const size_t sizex = 130; - short *xxx = (short *)malloc(sizex * sizeof(short)); - //printf("%ld\n",(ulong)xxx%8); - //memzero(xxx, sizex); - _osk_memsetw(xxx, 300, sizex); - - size_t it; - for (it = 0; it < sizex; it++) { - short s = *(xxx + it); - printf("%hd", s); - } - free((void *)xxx); -#endif - - char buf[256]; - - puts(_osk_ultoa(5000000000, buf, 10)); - - puts(""); - - - //const char *str = "ceci est un string de test!"; - //char *str2 = malloc((strlen(str) + 3) * sizeof(char)); - //char *str3 = malloc((strlen(str) + 3) * sizeof(char)); - - //strcpy(str2, str); - - //size_t s = strlen(str2); - - //strrev(str3,str2); - //printf("%lu - %s\n", strlen(str3), str3); - - //str2[s] = '\n'; - //str2[s+1] = '\0'; - //strrev(str2,str3); - //printf("%lu - %s\n", strlen(str2), str2); - - //free(str2); - //free(str3); - - - - //free(test2); - //free(test3); - - return 0; -} - diff --git a/src/kaleid/common/test/test-file0.c b/src/kaleid/common/test/test-file0.c deleted file mode 100644 index 59ba1cc..0000000 --- a/src/kaleid/common/test/test-file0.c +++ /dev/null @@ -1,28 +0,0 @@ -// 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++; - printf("%p\n", ptr); - - ptr = ptr + 1; - printf("%p\n", ptr); - - ptr = (long *)((long)ptr + 1); - printf("%p\n", ptr); - - return 0; -} - diff --git a/src/kaleid/include/kalkern b/src/kaleid/include/kalkern deleted file mode 120000 index 195d388..0000000 --- a/src/kaleid/include/kalkern +++ /dev/null @@ -1 +0,0 @@ -../kernel \ No newline at end of file diff --git a/src/kaleid/kernel/config.h b/src/kaleid/kernel/config.h deleted file mode 100644 index 6c43ff8..0000000 --- a/src/kaleid/kernel/config.h +++ /dev/null @@ -1,42 +0,0 @@ -//----------------------------------------------------------------------------// -// GNU GPL OS/K // -// // -// Authors: spectral` // -// NeoX // -// // -// Desc: Default configuration file // -//----------------------------------------------------------------------------// - -// XXX update the tree etc - -// This file is to be copied to "config.h" and edited before compilation -// We may do a script that generates "config.h" for the user, asking about -// the different configuration choices in the terminal. - -#ifndef _KALCOMM_CONFIG_H -#define _KALCOMM_CONFIG_H - -//------------------------------------------// -// General configuration choices // -//------------------------------------------// - -// -// Enable/disable multiprocessor support -// -#define MULTIPROCESSOR FALSE - -// -// Enable/disable preemptivity -// -#define PREEMPTIVE TRUE - -// -// Size of a tabulation in spaces -// Default: 4 spaces/tab -// -#define TABSIZE 4 - -// this file is to be progressively filled - -#endif - diff --git a/src/kaleid/kernel/config.h.in b/src/kaleid/kernel/config.h.in deleted file mode 100644 index 501be3d..0000000 --- a/src/kaleid/kernel/config.h.in +++ /dev/null @@ -1,42 +0,0 @@ -//----------------------------------------------------------------------------// -// GNU GPL OS/K // -// // -// Authors: spectral` // -// NeoX // -// // -// Desc: Default configuration file // -//----------------------------------------------------------------------------// - -// XXX update the tree etc - -// This file is to be copied to "config.h" and edited before compilation -// We may do a script that generates "config.h" for the user, asking about -// the different configuration choices in the terminal. - -#ifndef _KALCOMM_CONFIG_H -#define _KALCOMM_CONFIG_H - -//------------------------------------------// -// General configuration choices // -//------------------------------------------// - -// -// Enable/disable multiprocessor support -// -#define MULTIPROCESSOR NO - -// -// Enable/disable preemptivity -// -#define PREEMPTIVE YES - -// -// Size of a tabulation in spaces -// Default: 4 spaces/tab -// -#define TABSIZE 4 - -// this file is to be progressively filled - -#endif - diff --git a/src/kaleid/kernel/folder.desc b/src/kaleid/kernel/folder.desc deleted file mode 100644 index e85aabc..0000000 --- a/src/kaleid/kernel/folder.desc +++ /dev/null @@ -1,37 +0,0 @@ ---------------------------------------------------------------------- - GNU GPL OS/K - - Authors: spectral` - NeoX - - Desc: Folder description - "kaleid/kernel" ---------------------------------------------------------------------- - -This folder contains the source of Kaleid's kernel component. - -This contains the following files: - - init.c - The file containing the entry point of Kaleid, the kstart() function - called from the bootloader (see ../../boot). - -This folder also has the following subfolders: - - mm/ - This folder contains all files related to memory management. - - - fs/ - This folder will contain Kaleid's virtual filesystem, as well as one - subfolder for each FS supported by Kaleid (e.g. FAT filesystem). - - - io/ - 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. - - - 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) - - diff --git a/src/kaleid/kernel/init.h b/src/kaleid/kernel/init.h deleted file mode 100644 index db03c33..0000000 --- a/src/kaleid/kernel/init.h +++ /dev/null @@ -1,21 +0,0 @@ -//----------------------------------------------------------------------------// -// GNU GPL OS/K // -// // -// Authors: spectral` // -// NeoX // -// // -// Desc: Include file for init.c // -//----------------------------------------------------------------------------// - -#ifndef _KALKERN_INIT_H -#define _KALKERN_INIT_H - -#ifndef _KALKERN_H -#include -#endif - -// kernel entry point -void StartKern(void); - -#endif - diff --git a/src/kaleid/kernel/io/terminal.c b/src/kaleid/kernel/io/terminal.c deleted file mode 100644 index dbf5963..0000000 --- a/src/kaleid/kernel/io/terminal.c +++ /dev/null @@ -1,210 +0,0 @@ -//----------------------------------------------------------------------------// -// GNU GPL OS/K // -// // -// Authors: spectral` // -// NeoX // -// // -// Desc: Early terminal functions // -//----------------------------------------------------------------------------// - -#define _UNLOCKED_IO -#include - -// -// VGA-related macros -// -#define ComputeColorCode(fg, bg) ((fg) | (bg) << 4) -#define ComputeOffset(kt, x, y) ((y) * kt->kt_width + (x)) -#define ComputeEntry(ch, cl) (((ushort)(ch)) | (ushort)(cl) << 8) - -// -// VGA output -// -static terminal_t _vga_term = { - .kt_buffer = (ushort *)0xB8000, - .kt_width = 80, - .kt_height = 25, - .kt_curr_x = 0, - .kt_curr_y = 0, - .kt_color = ComputeColorCode(KTERM_COLOR_LGREY, KTERM_COLOR_BLACK), - .kt_lock = INITLOCK(KLOCK_MUTEX), - .kt_init = FALSE, -}; - -// -// Standard output terminal -// -terminal_t *stdout; - -// -// Debugging terminal -// -terminal_t *stddbg; - -// -// Initialize standard output -// -void InitTerms(void) -{ - Assert(!stdout && _vga_term.kt_init != INITOK); - - _vga_term.kt_init = INITOK; - stddbg = &_vga_term; - - // to be switched to VESA - stdout = &_vga_term; - ClearTerm(stdout); -} - -// -// Fill terminal with spaces -// -status_t ClearTerm(terminal_t *kt) -{ - if (kt == NULL) - return BAD_ARG_NULL; - - Assert(kt->kt_init == INITOK); - - LockTerm(kt); - ClearTermUnlocked(kt); - UnlockTerm(kt); - - return SUCCESS; -} - -// -// Change the color code -// -status_t ChTermColor(terminal_t *kt, uchar color) -{ - if (color > KTERM_COLOR_WHITE) - return BAD_ARG_RANGE; - - if (kt == NULL) - return BAD_ARG_NULL; - - LockTerm(kt); - kt->kt_color = color; - UnlockTerm(kt); - - return SUCCESS; -} - -// -// Write a single character on the terminal -// -status_t PutOnTerm(terminal_t *kt, char ch) -{ - if (kt == NULL) - return BAD_ARG_NULL; - - Assert(kt->kt_init == INITOK); - - LockTerm(kt); - PutOnTermUnlocked(kt, ch); - UnlockTerm(kt); - - return SUCCESS; -} - -// -// Print string on terminal -// -status_t PrintOnTerm(terminal_t *kt, const char *str) -{ - if (kt == NULL) - return BAD_ARG_NULL; - - Assert(kt->kt_init == INITOK); - - LockTerm(kt); - while (*str) { - PutOnTermUnlocked(kt, *str++); - } - UnlockTerm(kt); - - return SUCCESS; -} - -//----------------------------------------------------------// -// UNLOCKED VERSIONS // -// // -// Direct use is highly deprecated // -// Useful in rare instances // -//----------------------------------------------------------// - -// -// Fill terminal with spaces (UNLOCKED version) -// XXX would '\0' work too? -// -void ClearTermUnlocked(terminal_t *kt) -{ - size_t i; - - const ushort filler = ComputeEntry(' ', kt->kt_color); - const size_t bufsize = kt->kt_width * kt->kt_height; - - for (i = 0; i < bufsize; i++) { - // XXX implement memsetw() - kt->kt_buffer[i] = filler; - } - - kt->kt_curr_x = kt->kt_curr_y = 0; -} - -// -// Write a single character on the terminal (UNLOCKED version) -// -void PutOnTermUnlocked(terminal_t *kt, char ch) -{ - int i; - size_t prev_row; - - // carriage return takes us back to the beginning of the line - // no further test should be necessary - if (ch == '\r') { kt->kt_curr_x = 0; return; } - - // line feed first takes us to the very end of the line - // later in this function we actually do the line feed - else if (ch == '\n') { kt->kt_curr_y = kt->kt_width - 1; } - - // tabulations account for "TABSIZE" spaces - else if (ch == '\t') { - prev_row = kt->kt_curr_y; - // compiler will optimize this away - for (i = 0; i < TABSIZE; i++) { - // tabulations can't spread over two lines - if (kt->kt_curr_y == prev_row) { - PutOnTermUnlocked(kt, ' '); - } - } - } - - else { - // actually write on the buffer - const size_t offset = ComputeOffset(kt, kt->kt_curr_x, kt->kt_curr_y); - kt->kt_buffer[offset] = ComputeEntry(ch, kt->kt_color); - } - - // end of line? - if (++kt->kt_curr_x == kt->kt_width) { - kt->kt_curr_x = 0; - - // line feed + end of buffer? - if (++kt->kt_curr_y == kt->kt_height) { - kt->kt_curr_y = 0; - } - } -} - -// -// Print string on terminal (UNLOCKED version) -// -void PrintOnTermUnlocked(terminal_t *kt, const char *str) -{ - while (*str) { - PutOnTermUnlocked(kt, *str++); - } -} - diff --git a/src/kaleid/kernel/io/terminal.h b/src/kaleid/kernel/io/terminal.h deleted file mode 100644 index df42066..0000000 --- a/src/kaleid/kernel/io/terminal.h +++ /dev/null @@ -1,69 +0,0 @@ -//----------------------------------------------------------------------------// -// GNU GPL OS/K // -// // -// Authors: spectral` // -// NeoX // -// // -// Desc: Early terminal functions // -//----------------------------------------------------------------------------// - -#ifndef _KALKERN_IO_KTERM_H -#define _KALKERN_IO_KTERM_H - -#include - -// all available colors -enum terminal_colors { - KTERM_COLOR_BLACK, KTERM_COLOR_BLUE, - KTERM_COLOR_GREEN, KTERM_COLOR_CYAN, - KTERM_COLOR_RED, KTERM_COLOR_MAGENTA, - KTERM_COLOR_BROWN, KTERM_COLOR_LGREY, - KTERM_COLOR_DARK_GREY, KTERM_COLOR_LBLUE, - KTERM_COLOR_LGREEN, KTERM_COLOR_LCYAN, - KTERM_COLOR_LRED, KTERM_COLOR_LMAGENTA, - KTERM_COLOR_LBROWN, KTERM_COLOR_WHITE -}; - -typedef struct { - lock_t kt_lock; - ushort *kt_buffer; - uchar kt_color; - size_t kt_width; - size_t kt_height; - off_t kt_curr_x; - off_t kt_curr_y; - uint kt_init; - // XXX flags -} terminal_t; - -// current "standard" terminal -extern terminal_t *stdout; - -// current debugging terminal -extern terminal_t *stddbg; - -void InitTerms(void); -status_t ClearTerm(terminal_t *); -status_t PutOnTerm(terminal_t *, char); -status_t PrintOnTerm(terminal_t *, const char *); -status_t ChTermColor(terminal_t *, uchar); - -#if defined(_UNLOCKED_IO) -void ClearTermUnlocked(terminal_t *); -void PutOnTermUnlocked(terminal_t *, char); -void PrintOnTermUnlocked(terminal_t *, const char *); -#define ChTermColorUnlocked(kt, col) ((kt)->kt_color = (col)) -#endif - -#ifndef _NO_DEBUG -# define DebugLog(...) PrintOnTerm(stddbg, __VA_ARGS__) -#else -# define DebugLog(...) -#endif - -#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.c b/src/kaleid/kernel/ke/lock.c deleted file mode 100644 index 465b76f..0000000 --- a/src/kaleid/kernel/ke/lock.c +++ /dev/null @@ -1,13 +0,0 @@ -//----------------------------------------------------------------------------// -// GNU GPL OS/K // -// // -// Authors: spectral` // -// NeoX // -// // -// Desc: Locks // -//----------------------------------------------------------------------------// - -#include - -// nothing to do here - diff --git a/src/kaleid/kernel/ke/lock.h b/src/kaleid/kernel/ke/lock.h deleted file mode 100644 index 6841025..0000000 --- a/src/kaleid/kernel/ke/lock.h +++ /dev/null @@ -1,98 +0,0 @@ -//----------------------------------------------------------------------------// -// GNU GPL OS/K // -// // -// Authors: spectral` // -// NeoX // -// // -// Desc: Locks // -//----------------------------------------------------------------------------// - -#ifndef _KALKERN_KE_LOCK_H -#define _KALKERN_KE_LOCK_H - -#ifndef _KALKERN_H -#include -#endif - -enum lock_type { - // - // Mutex-type lock - // - // WARNING - // AquireLock() panics when used on a mutex while not running a process - // - KLOCK_MUTEX, - - // - // Spinlock-type lock - // Turns into a Mutex-type lock when MULTIPROCESSOR is off - // - KLOCK_SPINLOCK, - -}; - -typedef struct { - uchar lk_type; // lock type? - uint lk_lock; // is locked? - void *lk_owner; // unused - void *lk_waiting; // unused - uint lk_init; // unused if _NO_DEBUG -} lock_t; - -// -// Initialize a lock -// -#define InitLock(lk, type) \ - do { \ - (lk)->lk_type = (type); \ - (lk)->lk_lock = FALSE; \ - (lk)->lk_owner = NULL; \ - (lk)->lk_waiting = NULL; \ - (lk)->lk_init = INITOK; \ - } while (FALSE); - -// -// Alternative way to initalize a lock -// -#define INITLOCK(type) { (type), FALSE, NULL, NULL, INITOK } - -// -// Does nothing -// -#define DestroyLock(lk) ((lk)->lk_init = FALSE) - -// -// Aquires the lock -// Panics on double aquisition since that should never happen -// until we have at least a basic scheduler -// -#define AquireLock(lk) \ - do { \ - DisableInterrupts(); \ - Assert((lk)->lk_init == INITOK); \ - if ((lk)->lk_lock++) \ - StartPanic("DosAquireLock on an already locked object"); \ - EnableInterrupts(); \ - } while (FALSE); - -// -// Releases an already aquired lock -// Panics if the lock was never aquired (this will change) -// -#define ReleaseLock(lk) \ - do { \ - DisableInterrupts(); \ - Assert((lk)->lk_init == INITOK); \ - if ((lk)->lk_lock++) \ - StartPanic("DosReleaseLock on an unlocked object"); \ - EnableInterrupts(); \ - } while (FALSE); - -// -// Tries to aquire lock -// Doesn't work at all for obvious reasons -// -#define AttemptLock(lk) ((lk)->lk_lock++) - -#endif - diff --git a/src/kaleid/kernel/ke/panic.h b/src/kaleid/kernel/ke/panic.h deleted file mode 100644 index 372848e..0000000 --- a/src/kaleid/kernel/ke/panic.h +++ /dev/null @@ -1,24 +0,0 @@ -//----------------------------------------------------------------------------// -// GNU GPL OS/K // -// // -// Authors: spectral` // -// NeoX // -// // -// Desc: Looking to create some panic? Look no further! // -//----------------------------------------------------------------------------// - -#ifndef _KALKERN_KE_PANIC_H -#define _KALKERN_KE_PANIC_H - -#ifndef _KALKERN_H -#include -#endif - -noreturn void StartPanic(const char *); -noreturn void CrashSystem(void); - -extern const char *__panicmsg; -#define GetPanicStr() (__panicmsg) -#define SetPanicStr(str) (__panicmsg = (str)) - -#endif diff --git a/src/kaleid/kernel/ke/state.c b/src/kaleid/kernel/ke/state.c deleted file mode 100644 index 4d65f89..0000000 --- a/src/kaleid/kernel/ke/state.c +++ /dev/null @@ -1,16 +0,0 @@ -//----------------------------------------------------------------------------// -// GNU GPL OS/K // -// // -// Authors: spectral` // -// NeoX // -// // -// Desc: Current kernel state // -//----------------------------------------------------------------------------// - -#include - -// -// Current kernel state -// -uchar __kstate; - diff --git a/src/kaleid/kernel/ke/state.h b/src/kaleid/kernel/ke/state.h deleted file mode 100644 index 6f5de07..0000000 --- a/src/kaleid/kernel/ke/state.h +++ /dev/null @@ -1,37 +0,0 @@ -//----------------------------------------------------------------------------// -// GNU GPL OS/K // -// // -// Authors: spectral` // -// NeoX // -// // -// Desc: Current kernel state // -//----------------------------------------------------------------------------// - -#ifndef _KALKERN_KE_STATE_H -#define _KALKERN_KE_STATE_H - -#ifndef _KALKERN_H -#include -#endif - -// XXX improve this -enum kernel_states { - // a process is running in kernel mode - KSTATE_PROCESS, - - // the kernel is not running a process - KSTATE_KERNEL, - - // the kernel is panicking - KSTATE_PANIC, - - // the kernel is booting - KSTATE_INIT, -}; - -extern uchar __kstate; -#define GetKernState() (__kstate) -#define SetKernState(x) (__kstate = (x)) - -#endif - diff --git a/src/preproc.h b/src/preproc.h deleted file mode 100644 index b55004d..0000000 --- a/src/preproc.h +++ /dev/null @@ -1,33 +0,0 @@ -// be careful with this file - -#ifdef _TESTS -# define CCC TCC -#else -# define CCC KCC -#endif - -#ifdef _TO_ASM -# define _CSPREF -S -# define _OUTFIX S -# define LINK_KERNEL(out) -#else -# define _CSPREF -c -# define _OUTFIX o -# define LINK_KERNEL(out) $(KCC) $(CLDSCR) $(COMMOBJS) $(KERNOBJS) -o $(BINDIR)/out -#endif - -#define COMPILE_CONVRT(file) $(CCC) _CSPREF $(COMMDIR)/itoa.c -o $(COBJDIR)/file._OUTFIX -#define COMPILE_COMMON(file) $(CCC) _CSPREF $(COMMDIR)/file.c -o $(COBJDIR)/file._OUTFIX -#define COMPILE_KERNEL(file) $(KCC) _CSPREF $(KERNDIR)/file.c -o $(KOBJDIR)/file._OUTFIX - -#define COBJ1(x1) $(COBJDIR)/x1.o -#define COBJ2(x1,x2) $(COBJDIR)/x1.o $(COBJDIR)/x2.o -#define COBJ3(x1,x2,x3) $(COBJDIR)/x1.o $(COBJDIR)/x2.o $(COBJDIR)/x3 -#define COBJ4(x1,x2,x3,x4) $(COBJDIR)/x1.o $(COBJDIR)/x2.o $(COBJDIR)/x3.o $(COBJDIR)/x4.o -#define COBJ5(x1,x2,x3,x4,x5) $(COBJDIR)/x1.o $(COBJDIR)/x2.o $(COBJDIR)/x3.o $(COBJDIR)/x4.o $(COBJDIR)/x5.o - -#define KOBJ1(x1) $(KOBJDIR)/x1.o -#define KOBJ2(x1,x2) $(KOBJDIR)/x1.o $(KOBJDIR)/x2.o -#define KOBJ3(x1,x2,x3) $(KOBJDIR)/x1.o $(KOBJDIR)/x2.o $(KOBJDIR)/x3 -#define KOBJ4(x1,x2,x3,x4) $(KOBJDIR)/x1.o $(KOBJDIR)/x2.o $(KOBJDIR)/x3.o $(KOBJDIR)/x4.o -#define KOBJ5(x1,x2,x3,x4,x5) $(KOBJDIR)/x1.o $(KOBJDIR)/x2.o $(KOBJDIR)/x3.o $(KOBJDIR)/x4.o $(KOBJDIR)/x5.o diff --git a/src/project-style.txt b/src/project-style.txt deleted file mode 100644 index 4ed65ad..0000000 --- a/src/project-style.txt +++ /dev/null @@ -1,19 +0,0 @@ -//----------------------------------------------------------------------------// -// GNU GPL OS/K // -// // -// Authors: spectral` // -// NeoX // -// // -// Desc: Notes on the coding style and // -// conventions used throughout OS/K // -//----------------------------------------------------------------------------// - -To keep naming conventions and code style, we have decided to create this file. -How the code looks isn't the most important, so don't worry too much about this; -making the code conform to this file can be done later. - -Every file within OS/K is written using spaces for tabulation, with each -tabulation being 4 spaces long. - -(naming conventions here) - diff --git a/src/project-tree.txt b/src/project-tree.txt deleted file mode 100644 index e0e3f4d..0000000 --- a/src/project-tree.txt +++ /dev/null @@ -1,101 +0,0 @@ -//----------------------------------------------------------------------------// -// GNU GPL OS/K // -// // -// Authors: spectral` // -// NeoX // -// // -// Desc: Project Tree // -//----------------------------------------------------------------------------// - -src/ - | - x COPYING - x CONTACT - x ChangeLog - | - - Makefile - - kernel.ld - | - + boot/ - | | - | x folder.desc - | | - | - mbr.s - | - mbr.inc - | | - | - loader.s - | - loader16.inc - | - loader64.inc - | | - | 0 - | - + kaleid/ - | | - | + include/ - | | | - | | - kaleid.h - | | - kaldefs.h - | | - kaltypes.h - | | - kalassrt.h - | | - kalmask.h - | | - kalcrt.h - | | | - | | - kalkern.h - | | | - | | ~ kalkern/ -> ../kernel/ - | | | - | | 0 - | | - | | - | + kernel/ - | | | - | | x folder.desc - | | | - | | - config.h - | | - config.h.in - | | | - | | - init.c - | | - init.h - | | | - | | + io/ - | | | | - | | | - ports.c - | | | - ports.h - | | | | - | | | - terminal.c - | | | - terminal.h - | | | | - | | | 0 - | | | - | | + ke/ - | | | | - | | | - lock.c - | | | - lock.h - | | | | - | | | - panic.c - | | | - panic.h - | | | | - | | | - state.c - | | | - state.h - | | | | - | | | 0 - | | | - | | 0 - | | - | + common/ - | | | - | | - status.c - | | | - | | - string.c - | | - memory.c - | | - convert.c - | | - sprintf.c - | | | - | | + test/ - | | | | - | | | - test-common.c - | | | | - | | | 0 - | | 0 - | 0 - 0 From 41bd59035aee6e848134511c6c1162391ebdb6cb Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Mon, 14 Jan 2019 14:39:05 +0100 Subject: [PATCH 26/28] Rename LICENSE to COPYING --- LICENSE => COPYING | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename LICENSE => COPYING (100%) diff --git a/LICENSE b/COPYING similarity index 100% rename from LICENSE rename to COPYING From f9ae14e20eed52aaf2dc0757b992364a508e7c70 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Mon, 14 Jan 2019 15:25:25 +0100 Subject: [PATCH 27/28] Rename README.md to Readme.md --- README.md => Readme.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename README.md => Readme.md (100%) diff --git a/README.md b/Readme.md similarity index 100% rename from README.md rename to Readme.md From 6596a508bbbd687459b7a87534fd0afec92921b8 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Mon, 14 Jan 2019 15:26:32 +0100 Subject: [PATCH 28/28] Rename README.md to Readme.md --- README.md => Readme.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename README.md => Readme.md (100%) diff --git a/README.md b/Readme.md similarity index 100% rename from README.md rename to Readme.md