New headers, better headers, and stuff
This commit is contained in:
parent
5272796856
commit
51fdd75b88
|
@ -20,6 +20,7 @@ multiboot.pdf
|
|||
grub.log
|
||||
Makefile.out.2
|
||||
build/bin/s**
|
||||
.stylehlp
|
||||
|
||||
# Linker output
|
||||
*.ilk
|
||||
|
|
6
Makefile
6
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
|
||||
|
||||
|
|
|
@ -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 <https://www.gnu.org/licenses/>. //
|
||||
//=--------------------------------------------------------------------------=//
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
// 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)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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 <https://www.gnu.org/licenses/>. //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
// do not mask anything
|
||||
|
|
|
@ -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 <https://www.gnu.org/licenses/>. //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#include <kalbase.h>
|
||||
|
|
|
@ -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 <https://www.gnu.org/licenses/>. //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#include <kalbase.h>
|
||||
|
||||
/* DO NOT compile with strict aliasing on */
|
||||
|
||||
//------------------------------------------//
|
||||
// memset() family //
|
||||
//------------------------------------------//
|
||||
|
|
|
@ -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 <https://www.gnu.org/licenses/>. //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#include <kalbase.h>
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
//
|
||||
|
|
|
@ -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 <https://www.gnu.org/licenses/>. //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#include <kalbase.h>
|
||||
|
|
|
@ -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 <https://www.gnu.org/licenses/>. //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#include <kalbase.h>
|
||||
|
|
|
@ -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 <https://www.gnu.org/licenses/>. //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#include <kalbase.h>
|
||||
|
|
|
@ -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 <https://www.gnu.org/licenses/>. //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#include <kalbase.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 <https://www.gnu.org/licenses/>. //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#include <kalbase.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 <https://www.gnu.org/licenses/>. //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#include <kalbase.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 <https://www.gnu.org/licenses/>. //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#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 { \
|
||||
|
|
|
@ -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 <https://www.gnu.org/licenses/>. //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#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
|
||||
|
|
|
@ -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 <https://www.gnu.org/licenses/>. //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#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
|
||||
|
||||
|
|
|
@ -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 <https://www.gnu.org/licenses/>. //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#ifndef _KALBASE_ERRNO_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 <https://www.gnu.org/licenses/>. //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#ifndef _KALBASE_LIMITS_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 <https://www.gnu.org/licenses/>. //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#ifndef _KALBASE_MASKS_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 <https://www.gnu.org/licenses/>. //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#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
|
||||
|
|
|
@ -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 <https://www.gnu.org/licenses/>. //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#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
|
||||
|
|
|
@ -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 <https://www.gnu.org/licenses/>. //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#ifdef _KALEID_KERNEL
|
||||
|
@ -19,24 +34,37 @@
|
|||
#include <extras/malloc.h>
|
||||
#endif
|
||||
|
||||
#ifndef _KALEXTRAS_LOCKS_H
|
||||
#include <extras/locks.h>
|
||||
#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
|
||||
|
||||
|
|
|
@ -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 <https://www.gnu.org/licenses/>. //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#ifndef _KALBASE_H
|
||||
|
@ -12,18 +27,27 @@
|
|||
#endif
|
||||
|
||||
#ifdef _KALEID_KERNEL
|
||||
#ifndef _KALKERN_BASE_H
|
||||
#include <kernel/base.h>
|
||||
|
||||
#ifndef _KALKERN_PANIC_H
|
||||
#include <kernel/panic.h>
|
||||
#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
|
||||
|
|
|
@ -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 <https://www.gnu.org/licenses/>. //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#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
|
||||
|
||||
|
|
|
@ -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 <https://www.gnu.org/licenses/>. //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#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
|
||||
|
|
|
@ -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 <https://www.gnu.org/licenses/>. //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#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
|
||||
|
|
|
@ -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 <https://www.gnu.org/licenses/>. //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#ifndef _KALEID_H
|
||||
#define _KALEID_H
|
||||
|
||||
//------------------------------------------//
|
||||
// Include all Kaleid headers //
|
||||
//------------------------------------------//
|
||||
|
||||
#ifndef _KALBASE_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 <https://www.gnu.org/licenses/>. //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#ifndef _KALBASE_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 <https://www.gnu.org/licenses/>. //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#ifndef _KALBASE_H
|
||||
|
@ -28,16 +43,13 @@
|
|||
#include <kernel/base.h>
|
||||
#endif
|
||||
|
||||
#ifndef _KALKERN_TERMINAL_H
|
||||
#include <kernel/terminal.h>
|
||||
#ifndef _KALKERN_TERM_H
|
||||
#include <kernel/term.h>
|
||||
#endif
|
||||
|
||||
// not ready for kernel compilation
|
||||
#ifndef _KALEID_KERNEL
|
||||
#ifndef _KALKERN_SCHED_H
|
||||
#include <kernel/sched.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//------------------------------------------//
|
||||
|
||||
|
|
|
@ -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 <https://www.gnu.org/licenses/>. //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#ifndef _KALBASE_H
|
||||
#include <kalbase.h>
|
||||
#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 <extras/locks.h>
|
||||
#endif
|
||||
|
||||
//------------------------------------------//
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
@ -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
|
|
@ -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
|
||||
|
|
@ -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 <https://www.gnu.org/licenses/>. //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#ifndef _KALKERN_BASE_H
|
||||
#include <kernel/base.h>
|
||||
#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);
|
||||
|
||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -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 <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)
|
||||
{
|
||||
// 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 :(");
|
||||
}
|
||||
|
||||
|
|
|
@ -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 <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(_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);
|
||||
|
||||
|
|
|
@ -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/>. //
|
||||
//----------------------------------------------------------------------------//
|
|
@ -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 <https://www.gnu.org/licenses/>. //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#include <kaleid.h>
|
||||
#include <kernel/term.h>
|
||||
|
||||
extern void VGA_Init(void);
|
||||
extern Terminal_t VGA_Terminal;
|
||||
|
|
|
@ -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 <https://www.gnu.org/licenses/>. //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#include <kaleid.h>
|
||||
#include <kernel/term.h>
|
||||
|
||||
//----------------------------------------------------------//
|
||||
// Internal functions for VGA terminals //
|
||||
|
|
|
@ -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 <https://www.gnu.org/licenses/>. //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#include <kaleid.h>
|
||||
#include <kernel/term.h>
|
||||
#include <kernel/panic.h>
|
||||
|
||||
//
|
||||
// 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());
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 <https://www.gnu.org/licenses/>. //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#include <kalkern.h>
|
||||
#include <extras/list.h>
|
||||
#include <kernel/proc.h>
|
||||
#include <kernel/sched.h>
|
||||
|
||||
#ifndef _KALEID_KERNEL
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
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 *);
|
||||
|
|
Loading…
Reference in New Issue