New headers, better headers, and stuff

This commit is contained in:
Julian Barathieu 2019-02-16 23:36:33 +01:00
parent 5272796856
commit 51fdd75b88
45 changed files with 1231 additions and 509 deletions

1
.gitignore vendored
View File

@ -20,6 +20,7 @@ multiboot.pdf
grub.log grub.log
Makefile.out.2 Makefile.out.2
build/bin/s** build/bin/s**
.stylehlp
# Linker output # Linker output
*.ilk *.ilk

View File

@ -24,19 +24,19 @@
kernel: kernel:
cpp ./Makefile.in > build/Makefile.out cpp ./Makefile.in > build/Makefile.out
python ./build/idttool.py python build/idttool.py
make kernel -f build/Makefile.out.2 make kernel -f build/Makefile.out.2
rm build/Makefile.out build/Makefile.out.2 rm build/Makefile.out build/Makefile.out.2
kernel-asm: kernel-asm:
cpp -D_TO_ASM ./Makefile.in > build/Makefile.out cpp -D_TO_ASM ./Makefile.in > build/Makefile.out
python ./build/idttool.py python build/idttool.py
make kernel -f build/Makefile.out.2 make kernel -f build/Makefile.out.2
rm build/Makefile.out build/Makefile.out.2 rm build/Makefile.out build/Makefile.out.2
tests: tests:
cpp -D_TESTS ./Makefile.in > build/Makefile.out cpp -D_TESTS ./Makefile.in > build/Makefile.out
python ./build/idttool.py python build/idttool.py
make tests -f build/Makefile.out.2 make tests -f build/Makefile.out.2
rm build/Makefile.out build/Makefile.out.2 rm build/Makefile.out build/Makefile.out.2

View File

@ -1,6 +1,6 @@
// -*- Mode: Makefile -*- // -*- Mode: Makefile -*-
//=--------------------------------------------------------------------------=// //----------------------------------------------------------------------------//
// GNU GPL OS/K // // GNU GPL OS/K //
// // // //
// Desc: Project Makefile // // Desc: Project Makefile //
@ -22,7 +22,7 @@
// // // //
// You should have received a copy of the GNU General Public License // // You should have received a copy of the GNU General Public License //
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//=--------------------------------------------------------------------------=// //----------------------------------------------------------------------------//
// The madman's Makefile // The madman's Makefile
#include "build/preproc.h" #include "build/preproc.h"
@ -30,7 +30,7 @@
CCNAME="/opt/cross-cc/bin/x86_64-elf-gcc" CCNAME="/opt/cross-cc/bin/x86_64-elf-gcc"
CC2NAME=gcc CC2NAME=gcc
COPTIM=-O2 COPTIM=-O2
CWARNS=-Wall -Wextra // -Wshadow -Wpedantic CWARNS=-Wall -Wextra -Werror=implicit-function-declaration
CINCLUDES=-Ikaleid/include CINCLUDES=-Ikaleid/include
CFLAGS1=-nostdlib -ffreestanding -mcmodel=large // -std=gnu11 CFLAGS1=-nostdlib -ffreestanding -mcmodel=large // -std=gnu11
@ -83,7 +83,7 @@ common: comm-convert
COMPILE_COMMON(arith) COMPILE_COMMON(arith)
COMPILE_COMMON(string) COMPILE_COMMON(string)
COMPILE_COMMON(status) COMPILE_COMMON(status)
COMPILE_COMMON(memory) COMPILE_COMMON(memory) -fno-strict-aliasing
COMPILE_COMMON(strtol) COMPILE_COMMON(strtol)
COMPILE_COMMON(../extras/prog) COMPILE_COMMON(../extras/prog)
COMPILE_COMMON(../extras/argv) COMPILE_COMMON(../extras/argv)

View File

@ -30,11 +30,6 @@ SECTIONS
_bss = .; _bss = .;
*(.bss) *(.bss)
/*
* You usually need to include generated COMMON symbols
* under kernel BSS section or use gcc's -fno-common
*/
*(COMMON) *(COMMON)
. = ALIGN(4096); . = ALIGN(4096);
} }

View File

@ -1,10 +1,25 @@
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
// GNU GPL OS/K // // GNU GPL OS/K //
// // // //
// Authors: spectral` // // Desc: Arithmetic functions //
// NeoX //
// // // //
// 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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
// do not mask anything // do not mask anything

View File

@ -1,10 +1,25 @@
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
// GNU GPL OS/K // // GNU GPL OS/K //
// // // //
// Authors: spectral` // // Desc: Convertion utilities - atoi() family //
// NeoX //
// // // //
// 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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <kalbase.h> #include <kalbase.h>

View File

@ -1,14 +1,31 @@
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
// GNU GPL OS/K // // GNU GPL OS/K //
// // // //
// Authors: spectral` // // Desc: mem*() family //
// NeoX //
// // // //
// 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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <kalbase.h> #include <kalbase.h>
/* DO NOT compile with strict aliasing on */
//------------------------------------------// //------------------------------------------//
// memset() family // // memset() family //
//------------------------------------------// //------------------------------------------//

View File

@ -1,14 +1,32 @@
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
// GNU GPL OS/K // // GNU GPL OS/K //
// // // //
// Authors: spectral` // // Desc: Random related functions //
// NeoX //
// // // //
// 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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <kalbase.h> #include <kalbase.h>
// XXX Move to header
#define RAND_MAX (1 << 30)
// //
// Seed value // Seed value
// //
@ -21,7 +39,7 @@ static ulong next = 7756;
int rand(void) int rand(void)
{ {
next = next * 1103515245 + 12347; next = next * 1103515245 + 12347;
return (uint)(next / 65536); return (uint)(next / 65536) % RAND_MAX;
} }
// //

View File

@ -1,10 +1,25 @@
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
// GNU GPL OS/K // // GNU GPL OS/K //
// // // //
// Authors: spectral` // // Desc: *s*printf() family //
// NeoX //
// // // //
// 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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <kalbase.h> #include <kalbase.h>

View File

@ -1,10 +1,25 @@
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
// GNU GPL OS/K // // GNU GPL OS/K //
// // // //
// Authors: spectral` // // Desc: strerror() & co. //
// NeoX //
// // // //
// 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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <kalbase.h> #include <kalbase.h>

View File

@ -1,10 +1,25 @@
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
// GNU GPL OS/K // // GNU GPL OS/K //
// // // //
// Authors: spectral` // // Desc: String manipulation utilities //
// NeoX //
// // // //
// 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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <kalbase.h> #include <kalbase.h>

View File

@ -1,10 +1,25 @@
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
// GNU GPL OS/K // // GNU GPL OS/K //
// // // //
// Authors: spectral` // // Desc: strto*l() family //
// NeoX //
// // // //
// 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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <kalbase.h> #include <kalbase.h>

View File

@ -1,10 +1,25 @@
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
// GNU GPL OS/K // // GNU GPL OS/K //
// // // //
// Authors: spectral` //
// NeoX //
// //
// Desc: Command line parsing utilities // // 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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <kalbase.h> #include <kalbase.h>

View File

@ -1,10 +1,25 @@
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
// GNU GPL OS/K // // GNU GPL OS/K //
// // // //
// Authors: spectral` //
// NeoX //
// //
// Desc: Program utilities // // 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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <kalbase.h> #include <kalbase.h>

View File

@ -1,10 +1,25 @@
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
// GNU GPL OS/K // // GNU GPL OS/K //
// // // //
// Authors: spectral` // // Desc: assert() support //
// NeoX //
// // // //
// 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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#ifndef _KALBASE_ASSERT_H #ifndef _KALBASE_ASSERT_H
@ -40,9 +55,17 @@ static_assert(sizeof(void *) == 8, _SA_MSG);
// Assert core // // Assert core //
//------------------------------------------// //------------------------------------------//
#ifdef __cplusplus
extern "C" {
#endif
// Failed assert handler // Failed assert handler
noreturn void __assert_handler(const char *, const char *, int, const char *); noreturn void __assert_handler(const char *, const char *, int, const char *);
#ifdef __cplusplus
}
#endif
// Unconditional assert // Unconditional assert
#define KalAlwaysAssert(x) \ #define KalAlwaysAssert(x) \
do { \ do { \

View File

@ -1,10 +1,25 @@
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
// GNU GPL OS/K // // GNU GPL OS/K //
// // // //
// Authors: spectral` // // Desc: Basic preprocessor definitions //
// NeoX //
// // // //
// 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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#ifndef _KALBASE_BDEFS_H #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 #ifndef __alignof_is_defined
#define __alignof_is_defined #define __alignof_is_defined
#define alignof _Alignof #define alignof _Alignof

View File

@ -1,15 +1,34 @@
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
// GNU GPL OS/K // // GNU GPL OS/K //
// // // //
// Authors: spectral` // // Desc: C Runtime Library //
// NeoX //
// // // //
// 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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#ifndef _KALBASE_CRTLIB_H #ifndef _KALBASE_CRTLIB_H
#define _KALBASE_CRTLIB_H #define _KALBASE_CRTLIB_H
#ifdef __cplusplus
extern "C" {
#endif
//------------------------------------------// //------------------------------------------//
#ifndef __error_t_defined #ifndef __error_t_defined
@ -174,24 +193,24 @@ char *strsignal(int);
//------------------------------------------// //------------------------------------------//
#ifndef __abs #ifndef __abs_defined
#define __abs #define __abs_defined
static inline int abs(int __x) static inline int abs(int __x)
{ {
return __x < 0 ? -__x : __x; return __x < 0 ? -__x : __x;
} }
#endif #endif
#ifndef __labs #ifndef __labs_defined
#define __labs #define __labs_defined
static inline long labs(long __x) static inline long labs(long __x)
{ {
return __x < 0 ? -__x : __x; return __x < 0 ? -__x : __x;
} }
#endif #endif
#ifndef __div #ifndef __div_defined
#define __div #define __div_defined
static inline div_t div(int __x, int __y) static inline div_t div(int __x, int __y)
{ {
div_t __res; div_t __res;
@ -201,8 +220,8 @@ static inline div_t div(int __x, int __y)
} }
#endif #endif
#ifndef __ldiv #ifndef __ldiv_defined
#define __ldiv #define __ldiv_defined
static inline ldiv_t ldiv(long __x, long __y) static inline ldiv_t ldiv(long __x, long __y)
{ {
ldiv_t __res; ldiv_t __res;
@ -214,5 +233,9 @@ static inline ldiv_t ldiv(long __x, long __y)
//------------------------------------------// //------------------------------------------//
#ifdef __cplusplus
}
#endif
#endif #endif

View File

@ -1,10 +1,25 @@
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
// GNU GPL OS/K // // GNU GPL OS/K //
// // // //
// Authors: spectral` // // Desc: Values for error_t and errno //
// NeoX //
// // // //
// 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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#ifndef _KALBASE_ERRNO_H #ifndef _KALBASE_ERRNO_H

View File

@ -1,10 +1,25 @@
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
// GNU GPL OS/K // // GNU GPL OS/K //
// // // //
// Authors: spectral` // // Desc: Integer types limits and utilities //
// NeoX //
// // // //
// 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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#ifndef _KALBASE_LIMITS_H #ifndef _KALBASE_LIMITS_H

View File

@ -1,10 +1,25 @@
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
// GNU GPL OS/K // // GNU GPL OS/K //
// // // //
// Authors: spectral` // // Desc: Function name masks for compiling the Kaleid CRT on Linux //
// NeoX //
// // // //
// 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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#ifndef _KALBASE_MASKS_H #ifndef _KALBASE_MASKS_H

View File

@ -1,15 +1,34 @@
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
// GNU GPL OS/K // // GNU GPL OS/K //
// // // //
// Authors: spectral` // // Desc: Common C types used throughout OS/K //
// NeoX //
// // // //
// 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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#ifndef _KALBASE_TYPES_H #ifndef _KALBASE_TYPES_H
#define _KALBASE_TYPES_H #define _KALBASE_TYPES_H
#ifdef __cpluplus
extern "C" {
#endif
//------------------------------------------// //------------------------------------------//
#ifndef __base_types_aliases #ifndef __base_types_aliases
@ -105,4 +124,8 @@ typedef ushort port_t;
//------------------------------------------// //------------------------------------------//
#ifdef __cplusplus
}
#endif
#endif #endif

View File

@ -1,10 +1,25 @@
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
// GNU GPL OS/K // // GNU GPL OS/K //
// // // //
// Authors: spectral` //
// NeoX //
// //
// Desc: Command line parsing utilities // // 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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#ifndef _KALBASE_H #ifndef _KALBASE_H
@ -21,6 +36,17 @@ typedef void* FILE;
#ifndef _KALEXTRAS_ARGV_H #ifndef _KALEXTRAS_ARGV_H
#define _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 // Flags for options
// //
typedef enum { enum CmdOptionFlag_t
{
// The option parameter is optional // The option parameter is optional
KALOPT_OPTIONAL = (1 << 0), KALOPT_OPTIONAL = (1 << 0),
@ -52,13 +78,13 @@ typedef enum {
// Only show in long help messages // Only show in long help messages
KALOPT_LONGDOC = (1 << 4), 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= // Don't exit on errors=
KALOPT_NO_EXIT = (1 << 0), KALOPT_NO_EXIT = (1 << 0),
@ -91,8 +117,7 @@ typedef enum {
// Stay silent all along // Stay silent all along
KALOPT_SILENT = KALOPT_NO_EXIT | KALOPT_NO_ERRORS KALOPT_SILENT = KALOPT_NO_EXIT | KALOPT_NO_ERRORS
| KALOPT_NO_HELP | KALOPT_NO_VERSION, | KALOPT_NO_HELP | KALOPT_NO_VERSION,
};
} CmdParserFlags_t;
// //
// Return values for the command parser // Return values for the command parser
@ -101,8 +126,8 @@ typedef enum {
// "Continue" and "Break" actions do not prevent // "Continue" and "Break" actions do not prevent
// later actions from applying // later actions from applying
// //
typedef enum { enum CmdParserReturn_t
{
// Continue parsing new options // Continue parsing new options
KALOPT_CONTINUE = 0, KALOPT_CONTINUE = 0,
@ -112,16 +137,15 @@ typedef enum {
// Show help/version message (by default, continue parsing) // Show help/version message (by default, continue parsing)
KALOPT_SHOWHELP = (1 << 1), KALOPT_SHOWHELP = (1 << 1),
KALOPT_SHOWVERS = (1 << 2), KALOPT_SHOWVERS = (1 << 2),
};
} CmdParserReturn_t;
//------------------------------------------// //------------------------------------------//
// //
// An option for a command, e.g. "-o file" in "cc -o file" // 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" // The option's name, e.g. "help" for "--help"
// May be 0, but only if letter is not zero // May be 0, but only if letter is not zero
const char *longName; const char *longName;
@ -143,8 +167,7 @@ typedef struct {
// Must be positive and < 256, or option won't shop up // Must be positive and < 256, or option won't shop up
// during help texts // during help texts
int group; int group;
};
} CmdOption_t;
// //
// Program help/documentation strings; any can be 0 // Program help/documentation strings; any can be 0
@ -164,8 +187,8 @@ typedef struct {
// //
// XXX progname/version // XXX progname/version
// //
typedef struct { struct CmdDocStrings_t
{
const char *usage; const char *usage;
const char *header; const char *header;
const char *bottom; const char *bottom;
@ -174,8 +197,7 @@ typedef struct {
// groups[n] should be either 0 or contain the // groups[n] should be either 0 or contain the
// description of the option group n // description of the option group n
const char **groups; const char **groups;
};
} CmdDocStrings_t;
// //
// The state variable passed to the parser containing useful infos // The state variable passed to the parser containing useful infos
@ -279,4 +301,8 @@ error_t KalParseArgVec(int argc,
//------------------------------------------// //------------------------------------------//
#ifdef __cplusplus
}
#endif
#endif #endif

View File

@ -1,10 +1,25 @@
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
// GNU GPL OS/K // // GNU GPL OS/K //
// // // //
// Authors: spectral` //
// NeoX //
// //
// Desc: Doubly linked lists implementation // // 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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#ifdef _KALEID_KERNEL #ifdef _KALEID_KERNEL
@ -19,24 +34,37 @@
#include <extras/malloc.h> #include <extras/malloc.h>
#endif #endif
#ifndef _KALEXTRAS_LOCKS_H
#include <extras/locks.h>
#endif
#ifndef _KALEXTRAS_LIST_H #ifndef _KALEXTRAS_LIST_H
#define _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; Lock_t *lock;
unsigned long length; ulong length;
struct sListNode_t *first; ListNode_t *first;
struct sListNode_t *last; ListNode_t *last;
} ListHead_t; };
typedef struct sListNode_t { struct ListNode_t
{
void *data; void *data;
ListHead_t *head; ListHead_t *head;
struct sListNode_t *prev; ListNode_t *prev;
struct sListNode_t *next; ListNode_t *next;
} ListNode_t; };
//------------------------------------------// //------------------------------------------//
@ -46,7 +74,7 @@ typedef struct sListNode_t {
static inline ListHead_t static inline ListHead_t
*CreateListHeadWithLock(Lock_t *lock) *CreateListHeadWithLock(Lock_t *lock)
{ {
ListHead_t *head = AllocMemory(sizeof(ListHead_t)); ListHead_t *head = KalAllocMemory(sizeof(ListHead_t));
if (head == NULL) return NULL; if (head == NULL) return NULL;
@ -73,7 +101,7 @@ static inline ListHead_t
static inline ListNode_t static inline ListNode_t
*CreateNode(void *data) *CreateNode(void *data)
{ {
ListNode_t *node = AllocMemory(sizeof(ListNode_t)); ListNode_t *node = KalAllocMemory(sizeof(ListNode_t));
if (node == NULL) return NULL; if (node == NULL) return NULL;
@ -220,7 +248,7 @@ static inline ListHead_t
leave: leave:
head->length--; head->length--;
FreeMemory(node); KalFreeMemory(node);
return head; return head;
} }
@ -232,7 +260,7 @@ static inline void
DestroyNode(ListNode_t *node) DestroyNode(ListNode_t *node)
{ {
KalAssert(node); KalAssert(node);
FreeMemory(node); KalFreeMemory(node);
} }
// //
@ -242,7 +270,7 @@ static inline void
DestroyListHead(ListHead_t *head) DestroyListHead(ListHead_t *head)
{ {
KalAssert(head); KalAssert(head);
FreeMemory(head); KalFreeMemory(head);
} }
// //
@ -252,5 +280,9 @@ DestroyListHead(ListHead_t *head)
//------------------------------------------// //------------------------------------------//
#ifdef __cplusplus
}
#endif
#endif #endif

View File

@ -1,10 +1,25 @@
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
// GNU GPL OS/K // // GNU GPL OS/K //
// // // //
// Authors: spectral` // // Desc: Locks and synchronization //
// NeoX //
// // // //
// 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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#ifndef _KALBASE_H #ifndef _KALBASE_H
@ -12,18 +27,27 @@
#endif #endif
#ifdef _KALEID_KERNEL #ifdef _KALEID_KERNEL
#ifndef _KALKERN_BASE_H
#include <kernel/base.h> #ifndef _KALKERN_PANIC_H
#include <kernel/panic.h>
#endif #endif
#endif #endif
#ifndef _KALEXTRAS_LOCKS_H #ifndef _KALEXTRAS_LOCKS_H
#define _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 // Mutex-type lock
// //
// WARNING // WARNING
@ -33,18 +57,19 @@ typedef enum eLockType_t {
// Spinlock-type lock // Spinlock-type lock
KLOCK_SPINLOCK, KLOCK_SPINLOCK,
} LockType_t; };
// "volatile" may not be actually needed struct Lock_t
typedef struct sLock_t { {
unsigned int initDone; // initialized? unsigned int initDone;
LockType_t type; // lock type? LockType_t type;
volatile int locked; // is locked? volatile int locked;
#ifdef _KALEID_KERNEL
/* #ifdef _KALEID_KERNEL
Thread_t *ownerThread; // unused Thread_t *ownerThread; // unused
Thread_t *waitingThread; // unused Thread_t *waitingThread; // unused
#endif #endif */
} Lock_t; };
//------------------------------------------// //------------------------------------------//
@ -68,17 +93,17 @@ void InitLock(Lock_t *lock, LockType_t type)
lock->type = type; lock->type = type;
lock->locked = FALSE; lock->locked = FALSE;
lock->initDone = INITOK; lock->initDone = INITOK;
#ifdef _KALEID_KERNEL /* #ifdef _KALEID_KERNEL
lock->ownerThread = NULL; lock->ownerThread = NULL;
lock->waitingThread = NULL; lock->waitingThread = NULL;
#endif #endif */
} }
// //
// Alternative way to initalize a lock // Alternative way to initalize a lock
// //
#ifdef _KALEID_KERNEL #ifdef _KALEID_KERNEL
# define INITLOCK(type) { INITOK, FALSE, (type), NULL, NULL } # define INITLOCK(type) { INITOK, FALSE, (type), /* NULL, NULL */ }
#else #else
# define INITLOCK(type) { INITOK, FALSE, (type) } # define INITLOCK(type) { INITOK, FALSE, (type) }
#endif #endif
@ -127,9 +152,9 @@ void AquireLock(Lock_t *lock)
static inline static inline
void ReleaseLock(Lock_t *lock) void ReleaseLock(Lock_t *lock)
{ {
#ifdef _KALEID_KERNEL /*#ifdef _KALEID_KERNEL
KalAssert(lock->ownerThread == GetCurThread()); KalAssert(lock->ownerThread == GetCurThread());
#endif #endif*/
__sync_synchronize(); __sync_synchronize();
lock->locked = 0; lock->locked = 0;
@ -152,4 +177,8 @@ bool AttemptLock(Lock_t *lock)
//------------------------------------------// //------------------------------------------//
#ifdef __cplusplus
}
#endif
#endif #endif

View File

@ -1,10 +1,25 @@
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
// GNU GPL OS/K // // GNU GPL OS/K //
// // // //
// Authors: spectral` // // Desc: Memory allocation function //
// NeoX //
// // // //
// 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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#ifndef _KALBASE_H #ifndef _KALBASE_H
@ -14,6 +29,10 @@
#ifndef _KALEXTRAS_MALLOC_H #ifndef _KALEXTRAS_MALLOC_H
#define _KALEXTRAS_MALLOC_H #define _KALEXTRAS_MALLOC_H
#ifdef __cplusplus
extern "C" {
#endif
//------------------------------------------// //------------------------------------------//
// //
@ -24,10 +43,14 @@ void *malloc(unsigned long);
void free(void *); void free(void *);
#endif #endif
#define AllocMemory malloc #define KalAllocMemory malloc
#define FreeMemory free #define KalFreeMemory free
//------------------------------------------// //------------------------------------------//
#ifdef __cplusplus
}
#endif
#endif #endif

View File

@ -1,10 +1,25 @@
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
// GNU GPL OS/K // // GNU GPL OS/K //
// // // //
// Authors: spectral` //
// NeoX //
// //
// Desc: Program utilities // // 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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#ifndef _KALBASE_H #ifndef _KALBASE_H
@ -14,6 +29,10 @@
#ifndef _KALEXTRAS_PROG_H #ifndef _KALEXTRAS_PROG_H
#define _KALEXTRAS_PROG_H #define _KALEXTRAS_PROG_H
#ifdef __cplusplus
extern "C" {
#endif
//------------------------------------------// //------------------------------------------//
extern const char *__progname; extern const char *__progname;
@ -29,4 +48,8 @@ bool KalSetProgName(const char *);
//------------------------------------------// //------------------------------------------//
#ifdef __cplusplus
}
#endif
#endif #endif

View File

@ -1,21 +1,34 @@
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
// GNU GPL OS/K // // GNU GPL OS/K //
// // // //
// Authors: spectral` // // Desc: Base include file for OS/K //
// NeoX //
// // // //
// 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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#ifndef _KALBASE_H #ifndef _KALBASE_H
#define _KALBASE_H #define _KALBASE_H
//------------------------------------------//
// Building for OS/K //
//------------------------------------------// //------------------------------------------//
#ifndef _OSK_SOURCE #ifndef _OSK_SOURCE
#if defined(_KALEID_KERNEL) || defined(_KALEID_SYSTEM) #ifdef _KALEID_KERNEL
#define _OSK_SOURCE 1 #define _OSK_SOURCE 1
#endif #endif
#endif #endif
@ -26,8 +39,6 @@
#endif #endif
#endif #endif
//------------------------------------------//
// Include common part of API //
//------------------------------------------// //------------------------------------------//
#ifndef _KALBASE_BDEFS_H #ifndef _KALBASE_BDEFS_H

View File

@ -1,17 +1,30 @@
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
// GNU GPL OS/K // // GNU GPL OS/K //
// // // //
// Authors: spectral` // // Desc: Kaleid main project include file //
// NeoX //
// // // //
// 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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#ifndef _KALEID_H #ifndef _KALEID_H
#define _KALEID_H #define _KALEID_H
//------------------------------------------//
// Include all Kaleid headers //
//------------------------------------------// //------------------------------------------//
#ifndef _KALBASE_H #ifndef _KALBASE_H

View File

@ -1,10 +1,25 @@
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
// GNU GPL OS/K // // GNU GPL OS/K //
// // // //
// Authors: spectral` // // Desc: Kaleid "extra" API main include file //
// NeoX //
// // // //
// 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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#ifndef _KALBASE_H #ifndef _KALBASE_H

View File

@ -1,10 +1,25 @@
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
// GNU GPL OS/K // // GNU GPL OS/K //
// // // //
// Authors: spectral` // // Desc: Includes all Kaleid Kernel include files //
// NeoX //
// // // //
// 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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#ifndef _KALBASE_H #ifndef _KALBASE_H
@ -28,16 +43,13 @@
#include <kernel/base.h> #include <kernel/base.h>
#endif #endif
#ifndef _KALKERN_TERMINAL_H #ifndef _KALKERN_TERM_H
#include <kernel/terminal.h> #include <kernel/term.h>
#endif #endif
// not ready for kernel compilation
#ifndef _KALEID_KERNEL
#ifndef _KALKERN_SCHED_H #ifndef _KALKERN_SCHED_H
#include <kernel/sched.h> #include <kernel/sched.h>
#endif #endif
#endif
//------------------------------------------// //------------------------------------------//

View File

@ -1,51 +1,50 @@
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
// GNU GPL OS/K // // GNU GPL OS/K //
// // // //
// Authors: spectral` // // Desc: Kaleid kernel base include file //
// NeoX //
// // // //
// 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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#ifndef _KALBASE_H #ifndef _KALBASE_H
#include <kalbase.h> #include <kalbase.h>
#endif #endif
//------------------------------------------// #ifdef __cplusplus
#error "Kaleid's kernel won't compile in C++ :("
#endif
#ifndef _KALKERN_BASE_H #ifndef _KALKERN_BASE_H
#define _KALKERN_BASE_H #define _KALKERN_BASE_H
//------------------------------------------// //------------------------------------------//
typedef struct sLock_t Lock_t; typedef struct Lock_t Lock_t;
typedef struct sThread_t Thread_t; typedef struct Thread_t Thread_t;
typedef struct sProcess_t Process_t; typedef struct Process_t Process_t;
typedef struct sTerminal_t Terminal_t; typedef struct Terminal_t Terminal_t;
typedef struct sListHead_t ListHead_t; typedef struct ListHead_t ListHead_t;
typedef struct sListNode_t ListNode_t; typedef struct ListNode_t ListNode_t;
//------------------------------------------// typedef enum ProcState_t ProcState_t;
typedef enum TermColor_t TermColor_t;
/* XXX */ typedef enum KernelState_t KernelState_t;
//
// 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. // // Multiprocessor misc. //
@ -83,151 +82,12 @@ typedef enum {
#define CREATE_PER_CPU(_X, _Tp) \ #define CREATE_PER_CPU(_X, _Tp) \
_Tp __ ## _X [NCPUS] = { (_Tp) 0 } _Tp __ ## _X [NCPUS] = { (_Tp) 0 }
//------------------------------------------// //------------------------------------------//
// XXX // Needed by basically everyone
DECLARE_PER_CPU(PanicStr, const char *); #ifndef _KALEXTRAS_LOCKS_H
#include <extras/locks.h>
DECLARE_PER_CPU(KernState, KernelState_t); #endif
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;
}
//------------------------------------------// //------------------------------------------//

View File

@ -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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------//
#ifndef _KALKERN_BASE_H
#include <kernel/base.h>
#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

View File

@ -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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------//
#ifndef _KALKERN_BASE_H
#include <kernel/base.h>
#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

View File

@ -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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------//
#ifndef _KALKERN_BASE_H
#include <kernel/base.h>
#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

View File

@ -1,46 +1,85 @@
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
// GNU GPL OS/K // // GNU GPL OS/K //
// // // //
// Authors: spectral` // // Desc: Scheduler-related functions //
// NeoX //
// // // //
// 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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#ifndef _KALKERN_BASE_H #ifndef _KALKERN_BASE_H
#include <kernel/base.h> #include <kernel/base.h>
#endif #endif
//------------------------------------------//
#ifndef _KALKERN_SCHED_H #ifndef _KALKERN_SCHED_H
#define _KALKERN_SCHED_H #define _KALKERN_SCHED_H
//------------------------------------------// //------------------------------------------//
// Debug stuff //
#define printdbg printf // Value of the preemption count indicating that preemption is activated
//
// States for a process enum { PREEMPT_ON };
#define STATE_RUNNING 0
#define STATE_RUNNABLE 1
#define STATE_BLOCKED 2
// Time in ticks a process should be run // Time in ticks a process should be run
#define DEF_PROC_TSLICE 5 // 20 ticks enum
#define TCR_PROC_TSLICE 20000 // 20000 ticks (time critical) {
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(ReSchedFlag, bool);
DECLARE_PER_CPU(ReglPrioProcs, ListHead_t *); DECLARE_PER_CPU(PreemptCount, ulong);
DECLARE_PER_CPU(ServPrioProcs, ListHead_t *);
DECLARE_PER_CPU(TimeCritProcs, ListHead_t *); 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[]; 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 SchedInit(void);
void SchedFini(void); void SchedFini(void);

View File

@ -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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------//
#ifndef _KALKERN_PROC_H
#include <kernel/proc.h> // 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

View File

@ -1,81 +0,0 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
// Authors: spectral` //
// NeoX //
// //
// Desc: Terminal functions //
//----------------------------------------------------------------------------//
#ifndef _KALKERN_BASE_H
#include <kernel/base.h>
#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

View File

@ -1,29 +1,42 @@
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
// GNU GPL OS/K // // GNU GPL OS/K //
// // // //
// Authors: spectral` // // Desc: Kernel entry point //
// NeoX //
// // // //
// 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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <kaleid.h> #include <kernel/term.h>
#include <kernel/panic.h>
// //
// Entry point of kaleid-kernel.elf // Entry point of the Kaleid kernel
// //
noreturn void StartKern(void) noreturn void StartKern(void)
{ {
// we're not ready to deal with interrupts // We're not ready to deal with interrupts
DisableIRQs(); DisableIRQs();
// booting! // Kernel terminals
SetKernState(KSTATE_INIT);
// kernel terminals
InitTerms(); InitTerms();
// we're out // We're out
StartPanic("Goodbye World :("); StartPanic("Goodbye World :(");
} }

View File

@ -1,23 +1,37 @@
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
// GNU GPL OS/K // // GNU GPL OS/K //
// // // //
// Authors: spectral` // // Desc: Global variables //
// NeoX //
// // // //
// 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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <kaleid.h> #include <kernel/base.h>
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(CurProc, Process_t *);
CREATE_PER_CPU(_StdDbg, Terminal_t *); CREATE_PER_CPU(CurThread, Thread_t *);
CREATE_PER_CPU(CurProc, Process_t *); CREATE_PER_CPU(PreemptCount, ulong);
CREATE_PER_CPU(CurThread, Thread_t *); CREATE_PER_CPU(ReSchedFlag, bool);
CREATE_PER_CPU(ReSchedFlag, bool);

View File

@ -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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------//

View File

@ -1,13 +1,28 @@
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
// GNU GPL OS/K // // GNU GPL OS/K //
// // // //
// Authors: spectral` // // Desc: Terminal-related functions //
// NeoX //
// // // //
// 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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <kaleid.h> #include <kernel/term.h>
extern void VGA_Init(void); extern void VGA_Init(void);
extern Terminal_t VGA_Terminal; extern Terminal_t VGA_Terminal;

View File

@ -1,13 +1,28 @@
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
// GNU GPL OS/K // // GNU GPL OS/K //
// // // //
// Authors: spectral` //
// NeoX //
// //
// Desc: VGA terminal functions // // 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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <kaleid.h> #include <kernel/term.h>
//----------------------------------------------------------// //----------------------------------------------------------//
// Internal functions for VGA terminals // // Internal functions for VGA terminals //

View File

@ -1,13 +1,29 @@
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
// GNU GPL OS/K // // GNU GPL OS/K //
// // // //
// Authors: spectral` //
// NeoX //
// //
// Desc: How NOT to panic 101 // // 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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <kaleid.h> #include <kernel/term.h>
#include <kernel/panic.h>
// //
// Failed assert() handler // Failed assert() handler
@ -33,10 +49,7 @@ noreturn void StartPanic(const char *str)
{ {
DisableIRQs(); DisableIRQs();
// This should be made atomic if (GetCurProc()) _SetCurProc(NULL);
SetKernState(KSTATE_PANIC);
if (GetCurProc()) __CurProc[GetCurCPU()] = NULL;
if (GetStdOut() == NULL) CrashSystem(); if (GetStdOut() == NULL) CrashSystem();
GetStdOut()->ClearTermUnlocked(GetStdOut()); GetStdOut()->ClearTermUnlocked(GetStdOut());

View File

@ -1,6 +1,9 @@
sched-test: 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: clean:
rm a.out rm a.out

View File

@ -1,20 +1,35 @@
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
// GNU GPL OS/K // // GNU GPL OS/K //
// // // //
// Authors: spectral` // // Desc: Process scheduler //
// NeoX //
// // // //
// 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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <kalkern.h> #include <extras/list.h>
#include <kernel/proc.h>
#include <kernel/sched.h>
#ifndef _KALEID_KERNEL #ifndef _KALEID_KERNEL
#include <stdio.h> #include <stdio.h>
CREATE_PER_CPU(CurProc, Process_t *);
// //
// For test purpose only // For test purpose only
// //
@ -38,8 +53,7 @@ Process_t procs[] = {
// Set current process // Set current process
// TODO Select thread, context switch // TODO Select thread, context switch
// //
static inline static void SetCurProc(Process_t *proc)
void SetCurProc(Process_t *proc)
{ {
_SetCurProc(proc); _SetCurProc(proc);
if (GetCurProc() != NULL) { if (GetCurProc() != NULL) {
@ -75,23 +89,16 @@ CREATE_PER_CPU(ReglPrioProcs, ListHead_t *);
CREATE_PER_CPU(IdlePrioProcs, ListHead_t *); CREATE_PER_CPU(IdlePrioProcs, ListHead_t *);
const char *PrioClassesNames[] = { const char *PrioClassesNames[] = {
"Time-critical class", "Time-critical class",
"Server priority class", "Server priority class",
"Regular priority class", "Regular priority class",
"Idle priority class", "Idle priority class",
};
enum { TIME_CRIT_PROC = 0,
SERV_PRIO_PROC = 1,
REGL_PRIO_PROC = 2,
IDLE_PRIO_PROC = 3,
}; };
// //
// Get priority class list head // Get priority class list head
// //
static inline static ListHead_t *GetPrioClassHead(int prioClass)
ListHead_t *GetPrioClassHead(int prioClass)
{ {
switch (prioClass) { switch (prioClass) {
case TIME_CRIT_PROC: return GetTimeCritProcs(); case TIME_CRIT_PROC: return GetTimeCritProcs();
@ -108,8 +115,7 @@ ListHead_t *GetPrioClassHead(int prioClass)
// Determine which process is going to run first // Determine which process is going to run first
// Return NULL for "equal" processes // Return NULL for "equal" processes
// //
static inline static Process_t *CompareProcs(Process_t *proc1, Process_t *proc2)
Process_t *CompareProcs(Process_t *proc1, Process_t *proc2)
{ {
KalAssert(proc1 && proc2); KalAssert(proc1 && proc2);
@ -125,8 +131,7 @@ Process_t *CompareProcs(Process_t *proc1, Process_t *proc2)
// //
// Add process to schedule lists (unlocked) // Add process to schedule lists (unlocked)
// //
static inline static void SchedThisProcUnlocked(Process_t *proc)
void SchedThisProcUnlocked(Process_t *proc)
{ {
KalAssert(proc && proc->procState == STATE_RUNNABLE && !proc->schedNode); KalAssert(proc && proc->procState == STATE_RUNNABLE && !proc->schedNode);
@ -176,8 +181,7 @@ void SchedThisProc(Process_t *proc)
// WARNING // WARNING
// Does not call SchedLock()/SchedUnlock() // Does not call SchedLock()/SchedUnlock()
// //
static inline static Process_t *SelectSchedNext(void)
Process_t *SelectSchedNext(void)
{ {
if (GetTimeCritProcs()->length > 0) return GetNodeData(GetTimeCritProcs()->first, Process_t *); if (GetTimeCritProcs()->length > 0) return GetNodeData(GetTimeCritProcs()->first, Process_t *);
if (GetServPrioProcs()->length > 0) return GetNodeData(GetServPrioProcs()->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 // Remove running process from schedule lists
// and schedule next runnable process // and schedule next runnable process
// //
static inline
void BlockCurProc(void) void BlockCurProc(void)
{ {
KalAssert(GetCurProc() && GetCurProc()->procState == STATE_RUNNING); KalAssert(GetCurProc() && GetCurProc()->procState == STATE_RUNNING);
@ -207,8 +210,7 @@ void BlockCurProc(void)
SetCurProc(SelectSchedNext()); SetCurProc(SelectSchedNext());
} }
static inline static void ReSchedCurProc(void)
void ReSchedCurProc(void)
{ {
KalAssert(GetCurProc() && GetCurProc()->procState == STATE_RUNNING); KalAssert(GetCurProc() && GetCurProc()->procState == STATE_RUNNING);
KalAssert(GetCurProc()->schedNode); KalAssert(GetCurProc()->schedNode);
@ -338,7 +340,7 @@ void FiniSched(void)
#ifndef _KALEID_KERNEL #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); PrioClassesNames[(proc)->prioClass], (proc)->prioLevel, (proc)->timeSlice);
// //
@ -351,7 +353,7 @@ void PrintList(ListHead_t *head)
Process_t *proc; Process_t *proc;
ListNode_t *node = head->first; ListNode_t *node = head->first;
printdbg("len: %lu\n", head->length); printf("len: %lu\n", head->length);
while (node) { while (node) {
proc = GetNodeData(node, Process_t *); proc = GetNodeData(node, Process_t *);