diff --git a/.gitignore b/.gitignore
index 8e35884..68846eb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -20,6 +20,7 @@ multiboot.pdf
grub.log
Makefile.out.2
build/bin/s**
+.stylehlp
# Linker output
*.ilk
diff --git a/Makefile b/Makefile
index d58bb68..5570577 100644
--- a/Makefile
+++ b/Makefile
@@ -24,19 +24,19 @@
kernel:
cpp ./Makefile.in > build/Makefile.out
- python ./build/idttool.py
+ python build/idttool.py
make kernel -f build/Makefile.out.2
rm build/Makefile.out build/Makefile.out.2
kernel-asm:
cpp -D_TO_ASM ./Makefile.in > build/Makefile.out
- python ./build/idttool.py
+ python build/idttool.py
make kernel -f build/Makefile.out.2
rm build/Makefile.out build/Makefile.out.2
tests:
cpp -D_TESTS ./Makefile.in > build/Makefile.out
- python ./build/idttool.py
+ python build/idttool.py
make tests -f build/Makefile.out.2
rm build/Makefile.out build/Makefile.out.2
diff --git a/Makefile.in b/Makefile.in
index e965c0b..38ded8c 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -1,6 +1,6 @@
// -*- Mode: Makefile -*-
-//=--------------------------------------------------------------------------=//
+//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
// Desc: Project Makefile //
@@ -22,7 +22,7 @@
// //
// You should have received a copy of the GNU General Public License //
// along with OS/K. If not, see . //
-//=--------------------------------------------------------------------------=//
+//----------------------------------------------------------------------------//
// The madman's Makefile
#include "build/preproc.h"
@@ -30,7 +30,7 @@
CCNAME="/opt/cross-cc/bin/x86_64-elf-gcc"
CC2NAME=gcc
COPTIM=-O2
-CWARNS=-Wall -Wextra // -Wshadow -Wpedantic
+CWARNS=-Wall -Wextra -Werror=implicit-function-declaration
CINCLUDES=-Ikaleid/include
CFLAGS1=-nostdlib -ffreestanding -mcmodel=large // -std=gnu11
@@ -83,7 +83,7 @@ common: comm-convert
COMPILE_COMMON(arith)
COMPILE_COMMON(string)
COMPILE_COMMON(status)
- COMPILE_COMMON(memory)
+ COMPILE_COMMON(memory) -fno-strict-aliasing
COMPILE_COMMON(strtol)
COMPILE_COMMON(../extras/prog)
COMPILE_COMMON(../extras/argv)
diff --git a/build/kernel.ld b/build/kernel.ld
index e96beb8..34408e0 100644
--- a/build/kernel.ld
+++ b/build/kernel.ld
@@ -30,11 +30,6 @@ SECTIONS
_bss = .;
*(.bss)
- /*
- * You usually need to include generated COMMON symbols
- * under kernel BSS section or use gcc's -fno-common
- */
-
*(COMMON)
. = ALIGN(4096);
}
diff --git a/kaleid/crtlib/arith.c b/kaleid/crtlib/arith.c
index 68e2575..150c37b 100644
--- a/kaleid/crtlib/arith.c
+++ b/kaleid/crtlib/arith.c
@@ -1,10 +1,25 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
-// Authors: spectral` //
-// NeoX //
+// Desc: Arithmetic functions //
// //
-// Desc: Arithmetical functions //
+// //
+// Copyright © 2018-2019 The OS/K Team //
+// //
+// This file is part of OS/K. //
+// //
+// OS/K 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 //
+// any later version. //
+// //
+// OS/K 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 OS/K. If not, see . //
//----------------------------------------------------------------------------//
// do not mask anything
diff --git a/kaleid/crtlib/atoi.c b/kaleid/crtlib/atoi.c
index 7066c55..fba62ca 100644
--- a/kaleid/crtlib/atoi.c
+++ b/kaleid/crtlib/atoi.c
@@ -1,10 +1,25 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
-// Authors: spectral` //
-// NeoX //
+// Desc: Convertion utilities - atoi() family //
// //
-// Desc: Conversion utilities - atoi family //
+// //
+// Copyright © 2018-2019 The OS/K Team //
+// //
+// This file is part of OS/K. //
+// //
+// OS/K 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 //
+// any later version. //
+// //
+// OS/K 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 OS/K. If not, see . //
//----------------------------------------------------------------------------//
#include
diff --git a/kaleid/crtlib/memory.c b/kaleid/crtlib/memory.c
index ee31348..16230a2 100644
--- a/kaleid/crtlib/memory.c
+++ b/kaleid/crtlib/memory.c
@@ -1,14 +1,31 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
-// Authors: spectral` //
-// NeoX //
+// Desc: mem*() family //
// //
-// Desc: mem*() functions //
+// //
+// Copyright © 2018-2019 The OS/K Team //
+// //
+// This file is part of OS/K. //
+// //
+// OS/K 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 //
+// any later version. //
+// //
+// OS/K 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 OS/K. If not, see . //
//----------------------------------------------------------------------------//
#include
+/* DO NOT compile with strict aliasing on */
+
//------------------------------------------//
// memset() family //
//------------------------------------------//
diff --git a/kaleid/crtlib/rand.c b/kaleid/crtlib/rand.c
index 186311f..f2395f0 100644
--- a/kaleid/crtlib/rand.c
+++ b/kaleid/crtlib/rand.c
@@ -1,14 +1,32 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
-// Authors: spectral` //
-// NeoX //
+// Desc: Random related functions //
// //
-// Desc: RNG related functions //
+// //
+// Copyright © 2018-2019 The OS/K Team //
+// //
+// This file is part of OS/K. //
+// //
+// OS/K 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 //
+// any later version. //
+// //
+// OS/K 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 OS/K. If not, see . //
//----------------------------------------------------------------------------//
#include
+// XXX Move to header
+#define RAND_MAX (1 << 30)
+
//
// Seed value
//
@@ -21,7 +39,7 @@ static ulong next = 7756;
int rand(void)
{
next = next * 1103515245 + 12347;
- return (uint)(next / 65536);
+ return (uint)(next / 65536) % RAND_MAX;
}
//
diff --git a/kaleid/crtlib/sprintf.c b/kaleid/crtlib/sprintf.c
index c3ad3f1..f0e5e5e 100644
--- a/kaleid/crtlib/sprintf.c
+++ b/kaleid/crtlib/sprintf.c
@@ -1,10 +1,25 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
-// Authors: spectral` //
-// NeoX //
+// Desc: *s*printf() family //
// //
-// Desc: sprintf()-related functions //
+// //
+// Copyright © 2018-2019 The OS/K Team //
+// //
+// This file is part of OS/K. //
+// //
+// OS/K 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 //
+// any later version. //
+// //
+// OS/K 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 OS/K. If not, see . //
//----------------------------------------------------------------------------//
#include
diff --git a/kaleid/crtlib/status.c b/kaleid/crtlib/status.c
index 6fc3c38..aa0326d 100644
--- a/kaleid/crtlib/status.c
+++ b/kaleid/crtlib/status.c
@@ -1,10 +1,25 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
-// Authors: spectral` //
-// NeoX //
+// Desc: strerror() & co. //
// //
-// Desc: Implementation of describe_status() //
+// //
+// Copyright © 2018-2019 The OS/K Team //
+// //
+// This file is part of OS/K. //
+// //
+// OS/K 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 //
+// any later version. //
+// //
+// OS/K 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 OS/K. If not, see . //
//----------------------------------------------------------------------------//
#include
diff --git a/kaleid/crtlib/string.c b/kaleid/crtlib/string.c
index d9d6776..89ae054 100644
--- a/kaleid/crtlib/string.c
+++ b/kaleid/crtlib/string.c
@@ -1,10 +1,25 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
-// Authors: spectral` //
-// NeoX //
+// Desc: String manipulation utilities //
// //
-// Desc: String-related functions //
+// //
+// Copyright © 2018-2019 The OS/K Team //
+// //
+// This file is part of OS/K. //
+// //
+// OS/K 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 //
+// any later version. //
+// //
+// OS/K 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 OS/K. If not, see . //
//----------------------------------------------------------------------------//
#include
diff --git a/kaleid/crtlib/strtol.c b/kaleid/crtlib/strtol.c
index 87a132f..dbde8ab 100644
--- a/kaleid/crtlib/strtol.c
+++ b/kaleid/crtlib/strtol.c
@@ -1,10 +1,25 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
-// Authors: spectral` //
-// NeoX //
+// Desc: strto*l() family //
// //
-// Desc: strto(u)l functions //
+// //
+// Copyright © 2018-2019 The OS/K Team //
+// //
+// This file is part of OS/K. //
+// //
+// OS/K 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 //
+// any later version. //
+// //
+// OS/K 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 OS/K. If not, see . //
//----------------------------------------------------------------------------//
#include
diff --git a/kaleid/extras/argv.c b/kaleid/extras/argv.c
index d9920da..70b1704 100644
--- a/kaleid/extras/argv.c
+++ b/kaleid/extras/argv.c
@@ -1,10 +1,25 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
-// Authors: spectral` //
-// NeoX //
-// //
// Desc: Command line parsing utilities //
+// //
+// //
+// Copyright © 2018-2019 The OS/K Team //
+// //
+// This file is part of OS/K. //
+// //
+// OS/K 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 //
+// any later version. //
+// //
+// OS/K 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 OS/K. If not, see . //
//----------------------------------------------------------------------------//
#include
diff --git a/kaleid/extras/prog.c b/kaleid/extras/prog.c
index b0ce13d..77dfbbc 100644
--- a/kaleid/extras/prog.c
+++ b/kaleid/extras/prog.c
@@ -1,10 +1,25 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
-// Authors: spectral` //
-// NeoX //
-// //
// Desc: Program utilities //
+// //
+// //
+// Copyright © 2018-2019 The OS/K Team //
+// //
+// This file is part of OS/K. //
+// //
+// OS/K 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 //
+// any later version. //
+// //
+// OS/K 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 OS/K. If not, see . //
//----------------------------------------------------------------------------//
#include
diff --git a/kaleid/include/base/assert.h b/kaleid/include/base/assert.h
index 65d00da..9f0ca0d 100644
--- a/kaleid/include/base/assert.h
+++ b/kaleid/include/base/assert.h
@@ -1,10 +1,25 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
-// Authors: spectral` //
-// NeoX //
+// Desc: assert() support //
// //
-// Desc: Kaleid assert() support //
+// //
+// Copyright © 2018-2019 The OS/K Team //
+// //
+// This file is part of OS/K. //
+// //
+// OS/K 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 //
+// any later version. //
+// //
+// OS/K 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 OS/K. If not, see . //
//----------------------------------------------------------------------------//
#ifndef _KALBASE_ASSERT_H
@@ -40,9 +55,17 @@ static_assert(sizeof(void *) == 8, _SA_MSG);
// Assert core //
//------------------------------------------//
+#ifdef __cplusplus
+extern "C" {
+#endif
+
// Failed assert handler
noreturn void __assert_handler(const char *, const char *, int, const char *);
+#ifdef __cplusplus
+}
+#endif
+
// Unconditional assert
#define KalAlwaysAssert(x) \
do { \
diff --git a/kaleid/include/base/bdefs.h b/kaleid/include/base/bdefs.h
index 9b3c4d4..4cd4379 100644
--- a/kaleid/include/base/bdefs.h
+++ b/kaleid/include/base/bdefs.h
@@ -1,10 +1,25 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
-// Authors: spectral` //
-// NeoX //
+// Desc: Basic preprocessor definitions //
// //
-// Desc: Kaleid general preprocessor constants //
+// //
+// Copyright © 2018-2019 The OS/K Team //
+// //
+// This file is part of OS/K. //
+// //
+// OS/K 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 //
+// any later version. //
+// //
+// OS/K 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 OS/K. If not, see . //
//----------------------------------------------------------------------------//
#ifndef _KALBASE_BDEFS_H
@@ -30,6 +45,20 @@
//------------------------------------------//
+#ifndef __BEGIN_DECLS
+#ifdef __cpluplus
+# define __EXTERN_C extern "C"
+# define __BEGIN_DECLS extern "C" {
+# define __END_DECLS }
+#else
+# define __EXTERN_C
+# define __BEGIN_DECLS
+# define __END_DECLS
+#endif
+#endif
+
+//------------------------------------------//
+
#ifndef __alignof_is_defined
#define __alignof_is_defined
#define alignof _Alignof
diff --git a/kaleid/include/base/crtlib.h b/kaleid/include/base/crtlib.h
index 47b269d..9e3ac86 100644
--- a/kaleid/include/base/crtlib.h
+++ b/kaleid/include/base/crtlib.h
@@ -1,15 +1,34 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
-// Authors: spectral` //
-// NeoX //
+// Desc: C Runtime Library //
// //
-// Desc: Kaleid C runtime library //
+// //
+// Copyright © 2018-2019 The OS/K Team //
+// //
+// This file is part of OS/K. //
+// //
+// OS/K 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 //
+// any later version. //
+// //
+// OS/K 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 OS/K. If not, see . //
//----------------------------------------------------------------------------//
#ifndef _KALBASE_CRTLIB_H
#define _KALBASE_CRTLIB_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
//------------------------------------------//
#ifndef __error_t_defined
@@ -174,24 +193,24 @@ char *strsignal(int);
//------------------------------------------//
-#ifndef __abs
-#define __abs
+#ifndef __abs_defined
+#define __abs_defined
static inline int abs(int __x)
{
return __x < 0 ? -__x : __x;
}
#endif
-#ifndef __labs
-#define __labs
+#ifndef __labs_defined
+#define __labs_defined
static inline long labs(long __x)
{
return __x < 0 ? -__x : __x;
}
#endif
-#ifndef __div
-#define __div
+#ifndef __div_defined
+#define __div_defined
static inline div_t div(int __x, int __y)
{
div_t __res;
@@ -201,8 +220,8 @@ static inline div_t div(int __x, int __y)
}
#endif
-#ifndef __ldiv
-#define __ldiv
+#ifndef __ldiv_defined
+#define __ldiv_defined
static inline ldiv_t ldiv(long __x, long __y)
{
ldiv_t __res;
@@ -214,5 +233,9 @@ static inline ldiv_t ldiv(long __x, long __y)
//------------------------------------------//
+#ifdef __cplusplus
+}
+#endif
+
#endif
diff --git a/kaleid/include/base/errno.h b/kaleid/include/base/errno.h
index f77c8f8..8b43d46 100644
--- a/kaleid/include/base/errno.h
+++ b/kaleid/include/base/errno.h
@@ -1,10 +1,25 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
-// Authors: spectral` //
-// NeoX //
+// Desc: Values for error_t and errno //
// //
-// Desc: Values for errno_t and errno //
+// //
+// Copyright © 2018-2019 The OS/K Team //
+// //
+// This file is part of OS/K. //
+// //
+// OS/K 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 //
+// any later version. //
+// //
+// OS/K 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 OS/K. If not, see . //
//----------------------------------------------------------------------------//
#ifndef _KALBASE_ERRNO_H
diff --git a/kaleid/include/base/limits.h b/kaleid/include/base/limits.h
index 56a03ee..b6d7769 100644
--- a/kaleid/include/base/limits.h
+++ b/kaleid/include/base/limits.h
@@ -1,10 +1,25 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
-// Authors: spectral` //
-// NeoX //
+// Desc: Integer types limits and utilities //
// //
-// Desc: Kaleid type limits definitions //
+// //
+// Copyright © 2018-2019 The OS/K Team //
+// //
+// This file is part of OS/K. //
+// //
+// OS/K 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 //
+// any later version. //
+// //
+// OS/K 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 OS/K. If not, see . //
//----------------------------------------------------------------------------//
#ifndef _KALBASE_LIMITS_H
diff --git a/kaleid/include/base/masks.h b/kaleid/include/base/masks.h
index 868df80..5166275 100644
--- a/kaleid/include/base/masks.h
+++ b/kaleid/include/base/masks.h
@@ -1,10 +1,25 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
-// Authors: spectral` //
-// NeoX //
+// Desc: Function name masks for compiling the Kaleid CRT on Linux //
// //
-// Desc: Masks for the functions in the KCRL //
+// //
+// Copyright © 2018-2019 The OS/K Team //
+// //
+// This file is part of OS/K. //
+// //
+// OS/K 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 //
+// any later version. //
+// //
+// OS/K 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 OS/K. If not, see . //
//----------------------------------------------------------------------------//
#ifndef _KALBASE_MASKS_H
diff --git a/kaleid/include/base/types.h b/kaleid/include/base/types.h
index 7e40d34..27d947f 100644
--- a/kaleid/include/base/types.h
+++ b/kaleid/include/base/types.h
@@ -1,15 +1,34 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
-// Authors: spectral` //
-// NeoX //
+// Desc: Common C types used throughout OS/K //
// //
-// Desc: Kaleid C common types //
+// //
+// Copyright © 2018-2019 The OS/K Team //
+// //
+// This file is part of OS/K. //
+// //
+// OS/K 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 //
+// any later version. //
+// //
+// OS/K 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 OS/K. If not, see . //
//----------------------------------------------------------------------------//
#ifndef _KALBASE_TYPES_H
#define _KALBASE_TYPES_H
+#ifdef __cpluplus
+extern "C" {
+#endif
+
//------------------------------------------//
#ifndef __base_types_aliases
@@ -105,4 +124,8 @@ typedef ushort port_t;
//------------------------------------------//
+#ifdef __cplusplus
+}
+#endif
+
#endif
diff --git a/kaleid/include/extras/argv.h b/kaleid/include/extras/argv.h
index 2a1a22e..32f67f4 100644
--- a/kaleid/include/extras/argv.h
+++ b/kaleid/include/extras/argv.h
@@ -1,10 +1,25 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
-// Authors: spectral` //
-// NeoX //
-// //
// Desc: Command line parsing utilities //
+// //
+// //
+// Copyright © 2018-2019 The OS/K Team //
+// //
+// This file is part of OS/K. //
+// //
+// OS/K 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 //
+// any later version. //
+// //
+// OS/K 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 OS/K. If not, see . //
//----------------------------------------------------------------------------//
#ifndef _KALBASE_H
@@ -21,6 +36,17 @@ typedef void* FILE;
#ifndef _KALEXTRAS_ARGV_H
#define _KALEXTRAS_ARGV_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef enum CmdOptionFlag_t CmdOptionFlag_t;
+typedef enum CmdParserFlags_t CmdParserFlags_t;
+typedef enum CmdParserReturn_t CmdParserReturn_t;
+
+typedef struct CmdOption_t CmdOption_t;
+typedef struct CmdDocStrings_t CmdDocStrings_t;
+
//------------------------------------------//
//
@@ -35,8 +61,8 @@ typedef void* FILE;
//
// Flags for options
//
-typedef enum {
-
+enum CmdOptionFlag_t
+{
// The option parameter is optional
KALOPT_OPTIONAL = (1 << 0),
@@ -52,13 +78,13 @@ typedef enum {
// Only show in long help messages
KALOPT_LONGDOC = (1 << 4),
-} CmdOptionFlag_t;
+};
//
-// Flags for KalParse(CmdLine|ArgV)
+// Flags for KalParse(CmdLine|ArgVec)
//
-typedef enum {
-
+enum CmdParserFlags_t
+{
// Don't exit on errors=
KALOPT_NO_EXIT = (1 << 0),
@@ -91,8 +117,7 @@ typedef enum {
// Stay silent all along
KALOPT_SILENT = KALOPT_NO_EXIT | KALOPT_NO_ERRORS
| KALOPT_NO_HELP | KALOPT_NO_VERSION,
-
-} CmdParserFlags_t;
+};
//
// Return values for the command parser
@@ -101,8 +126,8 @@ typedef enum {
// "Continue" and "Break" actions do not prevent
// later actions from applying
//
-typedef enum {
-
+enum CmdParserReturn_t
+{
// Continue parsing new options
KALOPT_CONTINUE = 0,
@@ -112,16 +137,15 @@ typedef enum {
// Show help/version message (by default, continue parsing)
KALOPT_SHOWHELP = (1 << 1),
KALOPT_SHOWVERS = (1 << 2),
-
-} CmdParserReturn_t;
+};
//------------------------------------------//
//
// An option for a command, e.g. "-o file" in "cc -o file"
//
-typedef struct {
-
+struct CmdOption_t
+{
// The option's name, e.g. "help" for "--help"
// May be 0, but only if letter is not zero
const char *longName;
@@ -143,8 +167,7 @@ typedef struct {
// Must be positive and < 256, or option won't shop up
// during help texts
int group;
-
-} CmdOption_t;
+};
//
// Program help/documentation strings; any can be 0
@@ -164,8 +187,8 @@ typedef struct {
//
// XXX progname/version
//
-typedef struct {
-
+struct CmdDocStrings_t
+{
const char *usage;
const char *header;
const char *bottom;
@@ -174,8 +197,7 @@ typedef struct {
// groups[n] should be either 0 or contain the
// description of the option group n
const char **groups;
-
-} CmdDocStrings_t;
+};
//
// The state variable passed to the parser containing useful infos
@@ -279,4 +301,8 @@ error_t KalParseArgVec(int argc,
//------------------------------------------//
+#ifdef __cplusplus
+}
+#endif
+
#endif
diff --git a/kaleid/include/extras/list.h b/kaleid/include/extras/list.h
index d394ddf..46ce377 100644
--- a/kaleid/include/extras/list.h
+++ b/kaleid/include/extras/list.h
@@ -1,10 +1,25 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
-// Authors: spectral` //
-// NeoX //
-// //
// Desc: Doubly linked lists implementation //
+// //
+// //
+// Copyright © 2018-2019 The OS/K Team //
+// //
+// This file is part of OS/K. //
+// //
+// OS/K 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 //
+// any later version. //
+// //
+// OS/K 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 OS/K. If not, see . //
//----------------------------------------------------------------------------//
#ifdef _KALEID_KERNEL
@@ -19,24 +34,37 @@
#include
#endif
+#ifndef _KALEXTRAS_LOCKS_H
+#include
+#endif
+
#ifndef _KALEXTRAS_LIST_H
#define _KALEXTRAS_LIST_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct ListHead_t ListHead_t;
+typedef struct ListNode_t ListNode_t;
+
//------------------------------------------//
-typedef struct sListHead_t {
+struct ListHead_t
+{
Lock_t *lock;
- unsigned long length;
- struct sListNode_t *first;
- struct sListNode_t *last;
-} ListHead_t;
+ ulong length;
+ ListNode_t *first;
+ ListNode_t *last;
+};
-typedef struct sListNode_t {
+struct ListNode_t
+{
void *data;
ListHead_t *head;
- struct sListNode_t *prev;
- struct sListNode_t *next;
-} ListNode_t;
+ ListNode_t *prev;
+ ListNode_t *next;
+};
//------------------------------------------//
@@ -46,7 +74,7 @@ typedef struct sListNode_t {
static inline ListHead_t
*CreateListHeadWithLock(Lock_t *lock)
{
- ListHead_t *head = AllocMemory(sizeof(ListHead_t));
+ ListHead_t *head = KalAllocMemory(sizeof(ListHead_t));
if (head == NULL) return NULL;
@@ -73,7 +101,7 @@ static inline ListHead_t
static inline ListNode_t
*CreateNode(void *data)
{
- ListNode_t *node = AllocMemory(sizeof(ListNode_t));
+ ListNode_t *node = KalAllocMemory(sizeof(ListNode_t));
if (node == NULL) return NULL;
@@ -220,7 +248,7 @@ static inline ListHead_t
leave:
head->length--;
- FreeMemory(node);
+ KalFreeMemory(node);
return head;
}
@@ -232,7 +260,7 @@ static inline void
DestroyNode(ListNode_t *node)
{
KalAssert(node);
- FreeMemory(node);
+ KalFreeMemory(node);
}
//
@@ -242,7 +270,7 @@ static inline void
DestroyListHead(ListHead_t *head)
{
KalAssert(head);
- FreeMemory(head);
+ KalFreeMemory(head);
}
//
@@ -252,5 +280,9 @@ DestroyListHead(ListHead_t *head)
//------------------------------------------//
+#ifdef __cplusplus
+}
+#endif
+
#endif
diff --git a/kaleid/include/extras/locks.h b/kaleid/include/extras/locks.h
index e2333e3..d97b0a5 100644
--- a/kaleid/include/extras/locks.h
+++ b/kaleid/include/extras/locks.h
@@ -1,10 +1,25 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
-// Authors: spectral` //
-// NeoX //
+// Desc: Locks and synchronization //
// //
-// Desc: Spinlocks and mutexes //
+// //
+// Copyright © 2018-2019 The OS/K Team //
+// //
+// This file is part of OS/K. //
+// //
+// OS/K 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 //
+// any later version. //
+// //
+// OS/K 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 OS/K. If not, see . //
//----------------------------------------------------------------------------//
#ifndef _KALBASE_H
@@ -12,18 +27,27 @@
#endif
#ifdef _KALEID_KERNEL
-#ifndef _KALKERN_BASE_H
-#include
+
+#ifndef _KALKERN_PANIC_H
+#include
#endif
+
#endif
#ifndef _KALEXTRAS_LOCKS_H
#define _KALEXTRAS_LOCKS_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef enum LockType_t LockType_t;
+typedef struct Lock_t Lock_t;
+
//------------------------------------------//
-typedef enum eLockType_t {
-
+enum LockType_t
+{
// Mutex-type lock
//
// WARNING
@@ -33,18 +57,19 @@ typedef enum eLockType_t {
// Spinlock-type lock
KLOCK_SPINLOCK,
-} LockType_t;
+};
-// "volatile" may not be actually needed
-typedef struct sLock_t {
- unsigned int initDone; // initialized?
- LockType_t type; // lock type?
- volatile int locked; // is locked?
-#ifdef _KALEID_KERNEL
+struct Lock_t
+{
+ unsigned int initDone;
+ LockType_t type;
+ volatile int locked;
+
+/* #ifdef _KALEID_KERNEL
Thread_t *ownerThread; // unused
Thread_t *waitingThread; // unused
-#endif
-} Lock_t;
+#endif */
+};
//------------------------------------------//
@@ -68,17 +93,17 @@ void InitLock(Lock_t *lock, LockType_t type)
lock->type = type;
lock->locked = FALSE;
lock->initDone = INITOK;
-#ifdef _KALEID_KERNEL
+/* #ifdef _KALEID_KERNEL
lock->ownerThread = NULL;
lock->waitingThread = NULL;
-#endif
+#endif */
}
//
// Alternative way to initalize a lock
//
#ifdef _KALEID_KERNEL
-# define INITLOCK(type) { INITOK, FALSE, (type), NULL, NULL }
+# define INITLOCK(type) { INITOK, FALSE, (type), /* NULL, NULL */ }
#else
# define INITLOCK(type) { INITOK, FALSE, (type) }
#endif
@@ -127,9 +152,9 @@ void AquireLock(Lock_t *lock)
static inline
void ReleaseLock(Lock_t *lock)
{
-#ifdef _KALEID_KERNEL
+/*#ifdef _KALEID_KERNEL
KalAssert(lock->ownerThread == GetCurThread());
-#endif
+#endif*/
__sync_synchronize();
lock->locked = 0;
@@ -152,4 +177,8 @@ bool AttemptLock(Lock_t *lock)
//------------------------------------------//
+#ifdef __cplusplus
+}
+#endif
+
#endif
diff --git a/kaleid/include/extras/malloc.h b/kaleid/include/extras/malloc.h
index 65728cd..694aefc 100644
--- a/kaleid/include/extras/malloc.h
+++ b/kaleid/include/extras/malloc.h
@@ -1,10 +1,25 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
-// Authors: spectral` //
-// NeoX //
+// Desc: Memory allocation function //
// //
-// Desc: Memory allocation utilities //
+// //
+// Copyright © 2018-2019 The OS/K Team //
+// //
+// This file is part of OS/K. //
+// //
+// OS/K 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 //
+// any later version. //
+// //
+// OS/K 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 OS/K. If not, see . //
//----------------------------------------------------------------------------//
#ifndef _KALBASE_H
@@ -14,6 +29,10 @@
#ifndef _KALEXTRAS_MALLOC_H
#define _KALEXTRAS_MALLOC_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
//------------------------------------------//
//
@@ -24,10 +43,14 @@ void *malloc(unsigned long);
void free(void *);
#endif
-#define AllocMemory malloc
-#define FreeMemory free
+#define KalAllocMemory malloc
+#define KalFreeMemory free
//------------------------------------------//
+#ifdef __cplusplus
+}
+#endif
+
#endif
diff --git a/kaleid/include/extras/prog.h b/kaleid/include/extras/prog.h
index 57a008b..9d7cfa0 100644
--- a/kaleid/include/extras/prog.h
+++ b/kaleid/include/extras/prog.h
@@ -1,10 +1,25 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
-// Authors: spectral` //
-// NeoX //
-// //
// Desc: Program utilities //
+// //
+// //
+// Copyright © 2018-2019 The OS/K Team //
+// //
+// This file is part of OS/K. //
+// //
+// OS/K 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 //
+// any later version. //
+// //
+// OS/K 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 OS/K. If not, see . //
//----------------------------------------------------------------------------//
#ifndef _KALBASE_H
@@ -14,6 +29,10 @@
#ifndef _KALEXTRAS_PROG_H
#define _KALEXTRAS_PROG_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
//------------------------------------------//
extern const char *__progname;
@@ -29,4 +48,8 @@ bool KalSetProgName(const char *);
//------------------------------------------//
+#ifdef __cplusplus
+}
+#endif
+
#endif
diff --git a/kaleid/include/kalbase.h b/kaleid/include/kalbase.h
index 8743f05..b91f710 100644
--- a/kaleid/include/kalbase.h
+++ b/kaleid/include/kalbase.h
@@ -1,21 +1,34 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
-// Authors: spectral` //
-// NeoX //
+// Desc: Base include file for OS/K //
// //
-// Desc: Kaleid API base minimal include file //
+// //
+// Copyright © 2018-2019 The OS/K Team //
+// //
+// This file is part of OS/K. //
+// //
+// OS/K 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 //
+// any later version. //
+// //
+// OS/K 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 OS/K. If not, see . //
//----------------------------------------------------------------------------//
#ifndef _KALBASE_H
#define _KALBASE_H
-//------------------------------------------//
-// Building for OS/K //
//------------------------------------------//
#ifndef _OSK_SOURCE
-#if defined(_KALEID_KERNEL) || defined(_KALEID_SYSTEM)
+#ifdef _KALEID_KERNEL
#define _OSK_SOURCE 1
#endif
#endif
@@ -26,8 +39,6 @@
#endif
#endif
-//------------------------------------------//
-// Include common part of API //
//------------------------------------------//
#ifndef _KALBASE_BDEFS_H
diff --git a/kaleid/include/kaleid.h b/kaleid/include/kaleid.h
index 36401a3..791447c 100644
--- a/kaleid/include/kaleid.h
+++ b/kaleid/include/kaleid.h
@@ -1,17 +1,30 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
-// Authors: spectral` //
-// NeoX //
+// Desc: Kaleid main project include file //
// //
-// Desc: Kaleid API main include file //
+// //
+// Copyright © 2018-2019 The OS/K Team //
+// //
+// This file is part of OS/K. //
+// //
+// OS/K 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 //
+// any later version. //
+// //
+// OS/K 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 OS/K. If not, see . //
//----------------------------------------------------------------------------//
#ifndef _KALEID_H
#define _KALEID_H
-//------------------------------------------//
-// Include all Kaleid headers //
//------------------------------------------//
#ifndef _KALBASE_H
diff --git a/kaleid/include/kalext.h b/kaleid/include/kalext.h
index a4c5b4f..a83afe1 100644
--- a/kaleid/include/kalext.h
+++ b/kaleid/include/kalext.h
@@ -1,10 +1,25 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
-// Authors: spectral` //
-// NeoX //
+// Desc: Kaleid "extra" API main include file //
// //
-// Desc: Kaleid extras main include file //
+// //
+// Copyright © 2018-2019 The OS/K Team //
+// //
+// This file is part of OS/K. //
+// //
+// OS/K 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 //
+// any later version. //
+// //
+// OS/K 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 OS/K. If not, see . //
//----------------------------------------------------------------------------//
#ifndef _KALBASE_H
diff --git a/kaleid/include/kalkern.h b/kaleid/include/kalkern.h
index 2020436..6b97706 100644
--- a/kaleid/include/kalkern.h
+++ b/kaleid/include/kalkern.h
@@ -1,10 +1,25 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
-// Authors: spectral` //
-// NeoX //
+// Desc: Includes all Kaleid Kernel include files //
// //
-// Desc: Kaleid Kernel main include file //
+// //
+// Copyright © 2018-2019 The OS/K Team //
+// //
+// This file is part of OS/K. //
+// //
+// OS/K 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 //
+// any later version. //
+// //
+// OS/K 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 OS/K. If not, see . //
//----------------------------------------------------------------------------//
#ifndef _KALBASE_H
@@ -28,16 +43,13 @@
#include
#endif
-#ifndef _KALKERN_TERMINAL_H
-#include
+#ifndef _KALKERN_TERM_H
+#include
#endif
-// not ready for kernel compilation
-#ifndef _KALEID_KERNEL
#ifndef _KALKERN_SCHED_H
#include
#endif
-#endif
//------------------------------------------//
diff --git a/kaleid/include/kernel/base.h b/kaleid/include/kernel/base.h
index dbf03bd..d0b70ea 100644
--- a/kaleid/include/kernel/base.h
+++ b/kaleid/include/kernel/base.h
@@ -1,51 +1,50 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
-// Authors: spectral` //
-// NeoX //
+// Desc: Kaleid kernel base include file //
// //
-// Desc: Kaleid Kernel base types and functionalities //
+// //
+// Copyright © 2018-2019 The OS/K Team //
+// //
+// This file is part of OS/K. //
+// //
+// OS/K 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 //
+// any later version. //
+// //
+// OS/K 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 OS/K. If not, see . //
//----------------------------------------------------------------------------//
#ifndef _KALBASE_H
#include
#endif
-//------------------------------------------//
+#ifdef __cplusplus
+#error "Kaleid's kernel won't compile in C++ :("
+#endif
#ifndef _KALKERN_BASE_H
#define _KALKERN_BASE_H
//------------------------------------------//
-typedef struct sLock_t 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;
+typedef struct Lock_t Lock_t;
+typedef struct Thread_t Thread_t;
+typedef struct Process_t Process_t;
+typedef struct Terminal_t Terminal_t;
+typedef struct ListHead_t ListHead_t;
+typedef struct ListNode_t ListNode_t;
-//------------------------------------------//
-
-/* XXX */
-
-//
-// 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;
+typedef enum ProcState_t ProcState_t;
+typedef enum TermColor_t TermColor_t;
+typedef enum KernelState_t KernelState_t;
//------------------------------------------//
// Multiprocessor misc. //
@@ -83,151 +82,12 @@ typedef enum {
#define CREATE_PER_CPU(_X, _Tp) \
_Tp __ ## _X [NCPUS] = { (_Tp) 0 }
-
//------------------------------------------//
-// 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 *);
-
-DECLARE_PER_CPU(ReSchedFlag, bool);
-DECLARE_PER_CPU(PreemptCount, ulong);
-
-//------------------------------------------//
-
-#define SetKernState(x) _SetKernState(x);
-
-//
-// StdOut/StdDbg manipulation
-//
-#define GetStdOut() (GetCurProc() == NULL ? Get_StdOut() : GetCurProc()->stdOut)
-#define GetStdDbg() (GetCurProc() == NULL ? Get_StdDbg() : GetCurProc()->stdDbg)
-#define SetStdOut(tm) do { if (GetCurProc() == NULL) _Set_StdOut(tm); \
- else GetCurProc()->stdOut = (tm); } while (0)
-#define SetStdDbg(tm) do { if (GetCurProc() == NULL) _Set_StdDbg(tm); \
- else GetCurProc()->stdDbg = (tm); } while (0)
-//
-// Re-scheduling and preemption
-// XXX XXX XXX atomic operations
-//
-#define SetReSchedFlag(x) _SetReSchedFlag(x)
-#define DisablePreemption() _SetPreemptCount(GetPreemptCount()+1)
-#define EnablePreemption() do { KalAssert(GetPreemptCount() > 0); \
- _SetPreemptCount(GetPreemptCount()-1); } while(0)
-
-//------------------------------------------//
-
-//
-// Value of the preemption count indicating that preemption is activated
-//
-#define PREEMPT_ON 0
-
-//
-// 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)
-
-//------------------------------------------//
-
-//
-// 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;
-
- // Standard output/debug
- Terminal_t *stdOut, *stdDbg;
-
-} Process_t;
-
-//------------------------------------------//
-
-noreturn void StartPanic(const char *);
-noreturn void CrashSystem(void);
-
-//------------------------------------------//
-// Useful I/O inlines //
-//------------------------------------------//
-
-
-static inline
-void WriteByteOnPort(port_t port, port_t val)
-{
- KalAssert(FALSE && ENOSYS);
- (void)port;
- (void)val;
-}
-
-static inline
-uchar ReadByteFromPort(port_t port)
-{
- KalAssert(FALSE && ENOSYS);
- (void)port;
- return 0;
-}
-
-static inline
-ushort ReadWordFromPort(port_t port)
-{
- KalAssert(FALSE && ENOSYS);
- (void)port;
- return 0;
-}
+// Needed by basically everyone
+#ifndef _KALEXTRAS_LOCKS_H
+#include
+#endif
//------------------------------------------//
diff --git a/kaleid/include/kernel/iomisc.h b/kaleid/include/kernel/iomisc.h
new file mode 100644
index 0000000..a07723d
--- /dev/null
+++ b/kaleid/include/kernel/iomisc.h
@@ -0,0 +1,62 @@
+//----------------------------------------------------------------------------//
+// GNU GPL OS/K //
+// //
+// Desc: Miscenalleous I/O functions and inlines //
+// //
+// //
+// Copyright © 2018-2019 The OS/K Team //
+// //
+// This file is part of OS/K. //
+// //
+// OS/K 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 //
+// any later version. //
+// //
+// OS/K 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 OS/K. If not, see . //
+//----------------------------------------------------------------------------//
+
+
+#ifndef _KALKERN_BASE_H
+#include
+#endif
+
+#ifndef _KALKERN_IOMISC_H
+#define _KALKERN_IOMISC_H
+
+//------------------------------------------//
+
+static inline
+void WriteByteOnPort(port_t port, port_t val)
+{
+ KalAssert(FALSE && ENOSYS);
+ (void)port;
+ (void)val;
+}
+
+static inline
+uchar ReadByteFromPort(port_t port)
+{
+ KalAssert(FALSE && ENOSYS);
+ (void)port;
+ return 0;
+}
+
+static inline
+ushort ReadWordFromPort(port_t port)
+{
+ KalAssert(FALSE && ENOSYS);
+ (void)port;
+ return 0;
+}
+
+//------------------------------------------//
+
+#endif
+
diff --git a/kaleid/include/kernel/panic.h b/kaleid/include/kernel/panic.h
new file mode 100644
index 0000000..0c90810
--- /dev/null
+++ b/kaleid/include/kernel/panic.h
@@ -0,0 +1,65 @@
+//----------------------------------------------------------------------------//
+// GNU GPL OS/K //
+// //
+// Desc: Kernel panic and crash stuff //
+// //
+// //
+// Copyright © 2018-2019 The OS/K Team //
+// //
+// This file is part of OS/K. //
+// //
+// OS/K 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 //
+// any later version. //
+// //
+// OS/K 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 OS/K. If not, see . //
+//----------------------------------------------------------------------------//
+
+#ifndef _KALKERN_BASE_H
+#include
+#endif
+
+#ifndef _KALKERN_PANIC_H
+#define _KALKERN_PANIC_H
+
+//------------------------------------------//
+
+DECLARE_PER_CPU(PanicStr, const char *);
+
+//------------------------------------------//
+
+//
+// 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)
+
+//------------------------------------------//
+
+noreturn void StartPanic(const char *);
+noreturn void CrashSystem(void);
+
+//------------------------------------------//
+#endif
diff --git a/kaleid/include/kernel/proc.h b/kaleid/include/kernel/proc.h
new file mode 100644
index 0000000..b591aed
--- /dev/null
+++ b/kaleid/include/kernel/proc.h
@@ -0,0 +1,86 @@
+//----------------------------------------------------------------------------//
+// GNU GPL OS/K //
+// //
+// Desc: Process-related structs and functions //
+// //
+// //
+// Copyright © 2018-2019 The OS/K Team //
+// //
+// This file is part of OS/K. //
+// //
+// OS/K 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 //
+// any later version. //
+// //
+// OS/K 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 OS/K. If not, see . //
+//----------------------------------------------------------------------------//
+
+#ifndef _KALKERN_BASE_H
+#include
+#endif
+
+#ifndef _KALKERN_PROC_H
+#define _KALKERN_PROC_H
+
+//------------------------------------------//
+
+// States for a process
+enum ProcState_t
+{
+ STATE_RUNNING,
+ STATE_RUNNABLE,
+ STATE_BLOCKED,
+};
+
+//
+// A process
+//
+struct Process_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
+ ProcState_t procState;
+
+ // Remaining time running
+ ulong timeSlice;
+
+ // Default time-slice
+ ulong defTimeSlice;
+
+ // Scheduler internals
+ ListNode_t *schedNode;
+
+ // Standard output/debug
+ Terminal_t *stdOut, *stdDbg;
+};
+
+//------------------------------------------//
+
+DECLARE_PER_CPU(CurProc, Process_t *);
+DECLARE_PER_CPU(CurThread, Thread_t *);
+
+//------------------------------------------//
+
+#endif
+
diff --git a/kaleid/include/kernel/sched.h b/kaleid/include/kernel/sched.h
index 5dc1023..5c4e2d6 100644
--- a/kaleid/include/kernel/sched.h
+++ b/kaleid/include/kernel/sched.h
@@ -1,46 +1,85 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
-// Authors: spectral` //
-// NeoX //
+// Desc: Scheduler-related functions //
// //
-// Desc: Scheduler header //
+// //
+// Copyright © 2018-2019 The OS/K Team //
+// //
+// This file is part of OS/K. //
+// //
+// OS/K 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 //
+// any later version. //
+// //
+// OS/K 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 OS/K. If not, see . //
//----------------------------------------------------------------------------//
#ifndef _KALKERN_BASE_H
#include
#endif
-//------------------------------------------//
-
#ifndef _KALKERN_SCHED_H
#define _KALKERN_SCHED_H
//------------------------------------------//
-// Debug stuff
-#define printdbg printf
-
-// States for a process
-#define STATE_RUNNING 0
-#define STATE_RUNNABLE 1
-#define STATE_BLOCKED 2
+//
+// Value of the preemption count indicating that preemption is activated
+//
+enum { PREEMPT_ON };
// Time in ticks a process should be run
-#define DEF_PROC_TSLICE 5 // 20 ticks
-#define TCR_PROC_TSLICE 20000 // 20000 ticks (time critical)
+enum
+{
+ DEF_PROC_TSLICE = 5, // 20 ticks
+ TCR_PROC_TSLICE = 20000 // 20000 ticks (time critical)
+};
+
+// Priority classes
+enum
+{
+ TIME_CRIT_PROC = 0,
+ SERV_PRIO_PROC = 1,
+ REGL_PRIO_PROC = 2,
+ IDLE_PRIO_PROC = 3,
+};
+
+// Names of the priority classes
+extern const char *PrioClassesNames[];
//------------------------------------------//
-DECLARE_PER_CPU(IdlePrioProcs, ListHead_t *);
-DECLARE_PER_CPU(ReglPrioProcs, ListHead_t *);
-DECLARE_PER_CPU(ServPrioProcs, ListHead_t *);
-DECLARE_PER_CPU(TimeCritProcs, ListHead_t *);
+DECLARE_PER_CPU(ReSchedFlag, bool);
+DECLARE_PER_CPU(PreemptCount, ulong);
+
+DECLARE_PER_CPU(IdlePrioProcs, ListHead_t *);
+DECLARE_PER_CPU(ReglPrioProcs, ListHead_t *);
+DECLARE_PER_CPU(ServPrioProcs, ListHead_t *);
+DECLARE_PER_CPU(TimeCritProcs, ListHead_t *);
extern const char *PrioClassesNames[];
//------------------------------------------//
+//
+// Re-scheduling and preemption
+// XXX atomic operations
+//
+#define SetReSchedFlag(x) _SetReSchedFlag(x)
+#define DisablePreemption() _SetPreemptCount(GetPreemptCount()+1)
+#define EnablePreemption() do { KalAssert(GetPreemptCount() > 0); \
+ _SetPreemptCount(GetPreemptCount()-1); } while(0)
+
+//------------------------------------------//
+
void SchedInit(void);
void SchedFini(void);
diff --git a/kaleid/include/kernel/term.h b/kaleid/include/kernel/term.h
new file mode 100644
index 0000000..bae24c0
--- /dev/null
+++ b/kaleid/include/kernel/term.h
@@ -0,0 +1,115 @@
+//----------------------------------------------------------------------------//
+// GNU GPL OS/K //
+// //
+// Desc: Terminal-related functions //
+// //
+// //
+// Copyright © 2018-2019 The OS/K Team //
+// //
+// This file is part of OS/K. //
+// //
+// OS/K 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 //
+// any later version. //
+// //
+// OS/K 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 OS/K. If not, see . //
+//----------------------------------------------------------------------------//
+
+#ifndef _KALKERN_PROC_H
+#include // for GetCurProc() and Process_t
+#endif
+
+#ifndef _KALKERN_TERM_H
+#define _KALKERN_TERM_H
+
+//------------------------------------------//
+
+//
+// Size of a tabulation in spaces
+// Default: 4 spaces/tab
+//
+enum { KTABSIZE = 4 };
+
+//
+// The VGA colors
+//
+enum TermColor_t
+{
+ 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
+};
+
+//
+// Terminal structure, right now VGA and output only
+//
+struct Terminal_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 *);
+};
+
+//------------------------------------------//
+
+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);
+
+
+//------------------------------------------//
+
+DECLARE_PER_CPU(_StdOut, Terminal_t *);
+DECLARE_PER_CPU(_StdDbg, Terminal_t *);
+
+//------------------------------------------//
+
+#define GetStdOut() (GetCurProc() == NULL ? Get_StdOut() : GetCurProc()->stdOut)
+#define GetStdDbg() (GetCurProc() == NULL ? Get_StdDbg() : GetCurProc()->stdDbg)
+#define SetStdOut(tm) do { if (GetCurProc() == NULL) _Set_StdOut(tm); \
+ else GetCurProc()->stdOut = (tm); } while (0)
+#define SetStdDbg(tm) do { if (GetCurProc() == NULL) _Set_StdDbg(tm); \
+ else GetCurProc()->stdDbg = (tm); } while (0)
+
+//------------------------------------------//
+
+#ifndef _NO_DEBUG
+# define DebugLog(...) PrintOnTerm(GetStdDbg(), __VA_ARGS__)
+#else
+# define DebugLog(...) ((void)0)
+#endif
+
+//------------------------------------------//
+
+#endif
diff --git a/kaleid/include/kernel/terminal.h b/kaleid/include/kernel/terminal.h
deleted file mode 100644
index 0cb08f1..0000000
--- a/kaleid/include/kernel/terminal.h
+++ /dev/null
@@ -1,81 +0,0 @@
-//----------------------------------------------------------------------------//
-// GNU GPL OS/K //
-// //
-// Authors: spectral` //
-// NeoX //
-// //
-// Desc: Terminal functions //
-//----------------------------------------------------------------------------//
-
-#ifndef _KALKERN_BASE_H
-#include
-#endif
-
-//------------------------------------------//
-
-#ifndef _KALKERN_TERMINAL_H
-#define _KALKERN_TERMINAL_H
-
-//------------------------------------------//
-
-//
-// 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;
-
-//------------------------------------------//
-
-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);
-
-//------------------------------------------//
-
-#ifndef _NO_DEBUG
-# define DebugLog(...) PrintOnTerm(GetStdDbg(), __VA_ARGS__)
-#else
-# define DebugLog(...)
-#endif
-
-//------------------------------------------//
-
-#endif
diff --git a/kaleid/kernel/init/init.c b/kaleid/kernel/init/init.c
index 0887f9c..cc7c438 100644
--- a/kaleid/kernel/init/init.c
+++ b/kaleid/kernel/init/init.c
@@ -1,29 +1,42 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
-// Authors: spectral` //
-// NeoX //
+// Desc: Kernel entry point //
// //
-// Desc: Kernel entry point //
+// //
+// Copyright © 2018-2019 The OS/K Team //
+// //
+// This file is part of OS/K. //
+// //
+// OS/K 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 //
+// any later version. //
+// //
+// OS/K 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 OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#include
+#include
+#include
//
-// Entry point of kaleid-kernel.elf
+// Entry point of the Kaleid kernel
//
noreturn void StartKern(void)
{
- // we're not ready to deal with interrupts
+ // We're not ready to deal with interrupts
DisableIRQs();
- // booting!
- SetKernState(KSTATE_INIT);
-
- // kernel terminals
+ // Kernel terminals
InitTerms();
- // we're out
+ // We're out
StartPanic("Goodbye World :(");
}
diff --git a/kaleid/kernel/init/table.c b/kaleid/kernel/init/table.c
index e610a42..d753b30 100644
--- a/kaleid/kernel/init/table.c
+++ b/kaleid/kernel/init/table.c
@@ -1,23 +1,37 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
-// Authors: spectral` //
-// NeoX //
+// Desc: Global variables //
// //
-// Desc: Global constants //
+// //
+// Copyright © 2018-2019 The OS/K Team //
+// //
+// This file is part of OS/K. //
+// //
+// OS/K 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 //
+// any later version. //
+// //
+// OS/K 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 OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#include
+#include
-CREATE_PER_CPU(PanicStr, const char *);
+CREATE_PER_CPU(PanicStr, const char *);
-CREATE_PER_CPU(KernState, KernelState_t);
+CREATE_PER_CPU(_StdOut, Terminal_t *);
+CREATE_PER_CPU(_StdDbg, Terminal_t *);
-CREATE_PER_CPU(_StdOut, Terminal_t *);
-CREATE_PER_CPU(_StdDbg, Terminal_t *);
+CREATE_PER_CPU(CurProc, Process_t *);
+CREATE_PER_CPU(CurThread, Thread_t *);
-CREATE_PER_CPU(CurProc, Process_t *);
-CREATE_PER_CPU(CurThread, Thread_t *);
-
-CREATE_PER_CPU(ReSchedFlag, bool);
+CREATE_PER_CPU(PreemptCount, ulong);
+CREATE_PER_CPU(ReSchedFlag, bool);
diff --git a/kaleid/kernel/io/cursor.c b/kaleid/kernel/io/cursor.c
index e69de29..6871dc3 100644
--- a/kaleid/kernel/io/cursor.c
+++ b/kaleid/kernel/io/cursor.c
@@ -0,0 +1,23 @@
+//----------------------------------------------------------------------------//
+// GNU GPL OS/K //
+// //
+// Desc: Cursor-related functions //
+// //
+// //
+// Copyright © 2018-2019 The OS/K Team //
+// //
+// This file is part of OS/K. //
+// //
+// OS/K 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 //
+// any later version. //
+// //
+// OS/K 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 OS/K. If not, see . //
+//----------------------------------------------------------------------------//
diff --git a/kaleid/kernel/io/term.c b/kaleid/kernel/io/term.c
index 98d3827..1d8adcc 100644
--- a/kaleid/kernel/io/term.c
+++ b/kaleid/kernel/io/term.c
@@ -1,13 +1,28 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
-// Authors: spectral` //
-// NeoX //
+// Desc: Terminal-related functions //
// //
-// Desc: Early terminal functions //
+// //
+// Copyright © 2018-2019 The OS/K Team //
+// //
+// This file is part of OS/K. //
+// //
+// OS/K 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 //
+// any later version. //
+// //
+// OS/K 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 OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#include
+#include
extern void VGA_Init(void);
extern Terminal_t VGA_Terminal;
diff --git a/kaleid/kernel/io/vga.c b/kaleid/kernel/io/vga.c
index f26ef65..54bc63d 100644
--- a/kaleid/kernel/io/vga.c
+++ b/kaleid/kernel/io/vga.c
@@ -1,13 +1,28 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
-// Authors: spectral` //
-// NeoX //
-// //
// Desc: VGA terminal functions //
+// //
+// //
+// Copyright © 2018-2019 The OS/K Team //
+// //
+// This file is part of OS/K. //
+// //
+// OS/K 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 //
+// any later version. //
+// //
+// OS/K 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 OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#include
+#include
//----------------------------------------------------------//
// Internal functions for VGA terminals //
diff --git a/kaleid/kernel/ke/panic.c b/kaleid/kernel/ke/panic.c
index 7b2bf6e..c71f790 100644
--- a/kaleid/kernel/ke/panic.c
+++ b/kaleid/kernel/ke/panic.c
@@ -1,13 +1,29 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
-// Authors: spectral` //
-// NeoX //
-// //
// Desc: How NOT to panic 101 //
+// //
+// //
+// Copyright © 2018-2019 The OS/K Team //
+// //
+// This file is part of OS/K. //
+// //
+// OS/K 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 //
+// any later version. //
+// //
+// OS/K 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 OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#include
+#include
+#include
//
// Failed assert() handler
@@ -33,10 +49,7 @@ noreturn void StartPanic(const char *str)
{
DisableIRQs();
- // This should be made atomic
- SetKernState(KSTATE_PANIC);
-
- if (GetCurProc()) __CurProc[GetCurCPU()] = NULL;
+ if (GetCurProc()) _SetCurProc(NULL);
if (GetStdOut() == NULL) CrashSystem();
GetStdOut()->ClearTermUnlocked(GetStdOut());
diff --git a/kaleid/kernel/proc/Makefile b/kaleid/kernel/proc/Makefile
index c83ea97..7fe9eea 100644
--- a/kaleid/kernel/proc/Makefile
+++ b/kaleid/kernel/proc/Makefile
@@ -1,6 +1,9 @@
sched-test:
- gcc -O2 -Wall -Wextra -I../../include ./sched.c
+ gcc -O0 -Wall -Wextra -I../../include -c ../init/table.c -o table.o
+ gcc -O2 -Wall -Wextra -I../../include -c ./sched.c -o sched.o
+ gcc sched.o table.o -o a.out
+ rm sched.o table.o
clean:
rm a.out
diff --git a/kaleid/kernel/proc/sched.c b/kaleid/kernel/proc/sched.c
index 46b75f6..6dffd89 100644
--- a/kaleid/kernel/proc/sched.c
+++ b/kaleid/kernel/proc/sched.c
@@ -1,20 +1,35 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
-// Authors: spectral` //
-// NeoX //
+// Desc: Process scheduler //
// //
-// Desc: Scheduling algorithm //
+// //
+// Copyright © 2018-2019 The OS/K Team //
+// //
+// This file is part of OS/K. //
+// //
+// OS/K 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 //
+// any later version. //
+// //
+// OS/K 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 OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#include
+#include
+#include
+#include
#ifndef _KALEID_KERNEL
#include
-CREATE_PER_CPU(CurProc, Process_t *);
-
//
// For test purpose only
//
@@ -38,8 +53,7 @@ Process_t procs[] = {
// Set current process
// TODO Select thread, context switch
//
-static inline
-void SetCurProc(Process_t *proc)
+static void SetCurProc(Process_t *proc)
{
_SetCurProc(proc);
if (GetCurProc() != NULL) {
@@ -75,23 +89,16 @@ CREATE_PER_CPU(ReglPrioProcs, ListHead_t *);
CREATE_PER_CPU(IdlePrioProcs, ListHead_t *);
const char *PrioClassesNames[] = {
- "Time-critical class",
- "Server priority class",
- "Regular priority class",
- "Idle priority class",
-};
-
-enum { TIME_CRIT_PROC = 0,
- SERV_PRIO_PROC = 1,
- REGL_PRIO_PROC = 2,
- IDLE_PRIO_PROC = 3,
+ "Time-critical class",
+ "Server priority class",
+ "Regular priority class",
+ "Idle priority class",
};
//
// Get priority class list head
//
-static inline
-ListHead_t *GetPrioClassHead(int prioClass)
+static ListHead_t *GetPrioClassHead(int prioClass)
{
switch (prioClass) {
case TIME_CRIT_PROC: return GetTimeCritProcs();
@@ -108,8 +115,7 @@ ListHead_t *GetPrioClassHead(int prioClass)
// Determine which process is going to run first
// Return NULL for "equal" processes
//
-static inline
-Process_t *CompareProcs(Process_t *proc1, Process_t *proc2)
+static Process_t *CompareProcs(Process_t *proc1, Process_t *proc2)
{
KalAssert(proc1 && proc2);
@@ -125,8 +131,7 @@ Process_t *CompareProcs(Process_t *proc1, Process_t *proc2)
//
// Add process to schedule lists (unlocked)
//
-static inline
-void SchedThisProcUnlocked(Process_t *proc)
+static void SchedThisProcUnlocked(Process_t *proc)
{
KalAssert(proc && proc->procState == STATE_RUNNABLE && !proc->schedNode);
@@ -176,8 +181,7 @@ void SchedThisProc(Process_t *proc)
// WARNING
// Does not call SchedLock()/SchedUnlock()
//
-static inline
-Process_t *SelectSchedNext(void)
+static Process_t *SelectSchedNext(void)
{
if (GetTimeCritProcs()->length > 0) return GetNodeData(GetTimeCritProcs()->first, Process_t *);
if (GetServPrioProcs()->length > 0) return GetNodeData(GetServPrioProcs()->first, Process_t *);
@@ -191,7 +195,6 @@ Process_t *SelectSchedNext(void)
// Remove running process from schedule lists
// and schedule next runnable process
//
-static inline
void BlockCurProc(void)
{
KalAssert(GetCurProc() && GetCurProc()->procState == STATE_RUNNING);
@@ -207,8 +210,7 @@ void BlockCurProc(void)
SetCurProc(SelectSchedNext());
}
-static inline
-void ReSchedCurProc(void)
+static void ReSchedCurProc(void)
{
KalAssert(GetCurProc() && GetCurProc()->procState == STATE_RUNNING);
KalAssert(GetCurProc()->schedNode);
@@ -338,7 +340,7 @@ void FiniSched(void)
#ifndef _KALEID_KERNEL
-#define PrintProc(proc) printdbg("{ %d, '%s', %d , %lu}\n", (proc)->pid, \
+#define PrintProc(proc) printf("{ %d, '%s', %d , %lu}\n", (proc)->pid, \
PrioClassesNames[(proc)->prioClass], (proc)->prioLevel, (proc)->timeSlice);
//
@@ -351,7 +353,7 @@ void PrintList(ListHead_t *head)
Process_t *proc;
ListNode_t *node = head->first;
- printdbg("len: %lu\n", head->length);
+ printf("len: %lu\n", head->length);
while (node) {
proc = GetNodeData(node, Process_t *);