commit
704c3b650c
|
@ -11,6 +11,10 @@ test-*.c
|
|||
*.elf
|
||||
*.S
|
||||
|
||||
# CNAME STUFF
|
||||
*.yml
|
||||
CNAME
|
||||
|
||||
|
||||
# Linker output
|
||||
*.ilk
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
#=----------------------------------------------------------------------------=#
|
||||
# GNU GPL OS/K #
|
||||
# #
|
||||
# Desc: Project Authors 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/>. #
|
||||
#=----------------------------------------------------------------------------=#
|
||||
|
||||
The OS/K development team (named in the sources The OS/K Team) is composed of
|
||||
all contributors of the project. Its representatives are the owners of the OS/K
|
||||
project repository, and own the copyright in it.
|
||||
|
||||
Founders and owner of the OS/K project repository
|
||||
|
||||
Julian Barathieu (julianb0)
|
||||
Adrien Bourmault (NeoX95)
|
||||
|
||||
Main contributors
|
||||
|
||||
Julian Barathieu (julianb0)
|
||||
Adrien Bourmault (NeoX95)
|
||||
|
||||
Other contributors
|
||||
|
||||
(void)
|
33
ChangeLog
33
ChangeLog
|
@ -1,13 +1,26 @@
|
|||
//----------------------------------------------------------------------------//
|
||||
// GNU GPL OS/K //
|
||||
// //
|
||||
// Authors: spectral` //
|
||||
// NeoX //
|
||||
// //
|
||||
// Desc: ChangeLog #1 //
|
||||
// From: 2018/12/06 //
|
||||
// UpTo: current //
|
||||
//----------------------------------------------------------------------------//
|
||||
#=----------------------------------------------------------------------------=#
|
||||
# GNU GPL OS/K #
|
||||
# #
|
||||
# Desc: Project ChangeLog #
|
||||
# #
|
||||
# #
|
||||
# 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/>. #
|
||||
#=----------------------------------------------------------------------------=#
|
||||
|
||||
2018/10/?? - Started talking about making our own OS
|
||||
2018/11/?? - Name decided & creation of os-k.eu
|
||||
|
|
25
Makefile
25
Makefile
|
@ -1,11 +1,26 @@
|
|||
#----------------------------------------------------------------------------#
|
||||
#=----------------------------------------------------------------------------=#
|
||||
# GNU GPL OS/K #
|
||||
# #
|
||||
# Authors: spectral` #
|
||||
# NeoX #
|
||||
# #
|
||||
# Desc: Project Makefile #
|
||||
#----------------------------------------------------------------------------#
|
||||
# #
|
||||
# #
|
||||
# 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/>. #
|
||||
#=----------------------------------------------------------------------------=#
|
||||
|
||||
kernel:
|
||||
cpp ./Makefile.in > build/Makefile.out
|
||||
|
|
59
Makefile.in
59
Makefile.in
|
@ -1,11 +1,28 @@
|
|||
//----------------------------------------------------------------------------//
|
||||
// -*- Mode: Makefile -*-
|
||||
|
||||
//=--------------------------------------------------------------------------=//
|
||||
// GNU GPL OS/K //
|
||||
// //
|
||||
// Authors: spectral` //
|
||||
// NeoX //
|
||||
// //
|
||||
// Desc: Project Makefile //
|
||||
//----------------------------------------------------------------------------//
|
||||
// //
|
||||
// //
|
||||
// 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/>. //
|
||||
//=--------------------------------------------------------------------------=//
|
||||
|
||||
// The madman's Makefile
|
||||
#include "build/preproc.h"
|
||||
|
@ -13,23 +30,23 @@
|
|||
CCNAME="/opt/cross-cc/bin/x86_64-elf-gcc"
|
||||
CC2NAME=gcc
|
||||
COPTIM=-O2
|
||||
CWARNS=-Wall -Wextra -Wshadow -Wpedantic
|
||||
CINCLUDES=-isystem./kaleid/include
|
||||
CWARNS=-Wall -Wextra // -Wshadow -Wpedantic
|
||||
CINCLUDES=-Ikaleid/include
|
||||
|
||||
CFLAGS1=-std=gnu11 -nostdlib -ffreestanding -mcmodel=large
|
||||
CFLAGS2=-m64 -masm=intel -mno-red-zone -mno-mmx -mno-sse -mno-sse2
|
||||
CFLAGS=$(CFLAGS1) $(CFLAGS2) $(SFLAG)
|
||||
CFLAGS1=-nostdlib -ffreestanding -mcmodel=large // -std=gnu11
|
||||
CFLAGS2=_ASMTYPE -mno-red-zone -mno-mmx -mno-sse -mno-sse2
|
||||
CFLAGS=$(CFLAGS1) $(CFLAGS2)
|
||||
|
||||
CC=$(CCNAME) $(COPTIM) $(CWARNS) $(CFLAGS) $(CINCLUDES)
|
||||
|
||||
BINDIR=./build/bin
|
||||
OBJDIR=./build/obj
|
||||
BINDIR=build/bin
|
||||
OBJDIR=build/obj
|
||||
|
||||
BOOTDIR=boot
|
||||
COMMDIR=kaleid/common
|
||||
COMMDIR=kaleid/crtlib
|
||||
KERNDIR=kaleid/kernel
|
||||
SYSTDIR=kaleid/system
|
||||
LINXDIR=kaleid/common/test
|
||||
LINXDIR=kaleid/test
|
||||
|
||||
//----------------------------------------------------------------------------#
|
||||
// TESTING MAKEFILE
|
||||
|
@ -46,10 +63,10 @@ testing: bootloader pseudo_kern
|
|||
COBJDIR=$(OBJDIR)/$(COMMDIR)
|
||||
LOBJDIR=$(OBJDIR)/$(LINXDIR)
|
||||
|
||||
COMMOBJS=COBJ6(string, status, rand, memory, arith, strtol) COBJ4(itoa, ltoa, utoa, ultoa) COBJ4(atoi, atol, atou, atoul)
|
||||
COMMOBJS=COBJ6(string, status, rand, memory, arith, strtol) COBJ4(itoa, ltoa, utoa, ultoa) COBJ4(atoi, atol, atou, atoul) COBJ2(../extras/prog, ../extras/argv)
|
||||
|
||||
TCC=$(CC2NAME) $(COPTIM) $(CWARNS) $(CINCLUDES)
|
||||
KCC=$(CC) -T ./build/kernel.ld -D_OSK_SOURCE -D_KALEID_KERNEL
|
||||
KCC=$(CC) -D_KALEID_KERNEL
|
||||
|
||||
comm-convert:
|
||||
COMPILE_CONVRT1(itoa) -D_NEED_ITOA
|
||||
|
@ -68,23 +85,27 @@ common: comm-convert
|
|||
COMPILE_COMMON(status)
|
||||
COMPILE_COMMON(memory)
|
||||
COMPILE_COMMON(strtol)
|
||||
COMPILE_COMMON(../extras/prog)
|
||||
COMPILE_COMMON(../extras/argv)
|
||||
|
||||
tests: common
|
||||
$(TCC) -c $(LINXDIR)/test-common.c -o $(LOBJDIR)/test-common.o
|
||||
$(TCC) $(COMMOBJS) $(LOBJDIR)/test-common.o -o $(BINDIR)/kaleid-common.elf
|
||||
$(TCC) $(COMMOBJS) $(LOBJDIR)/test-common.o -o $(BINDIR)/comm-test
|
||||
|
||||
//----------------------------------------------------------------------------#
|
||||
// KERNEL MAKEFILE
|
||||
|
||||
KOBJDIR=$(OBJDIR)/$(KERNDIR)
|
||||
|
||||
KERNOBJS=KOBJ4(init/init, init/table, ke/panic, ke/terminal)
|
||||
KERNOBJS=KOBJ6(init/init, init/table, ke/panic, io/term, io/cursor, io/vga)
|
||||
|
||||
kernel: common
|
||||
COMPILE_KERNEL(init/init)
|
||||
COMPILE_KERNEL(init/table)
|
||||
COMPILE_KERNEL(ke/panic)
|
||||
COMPILE_KERNEL(ke/terminal)
|
||||
COMPILE_KERNEL(io/cursor)
|
||||
COMPILE_KERNEL(io/term)
|
||||
COMPILE_KERNEL(io/vga)
|
||||
LINK_KERNEL(kaleid-kernel.elf)
|
||||
|
||||
//----------------------------------------------------------------------------#
|
||||
|
|
209
ProjectTree
209
ProjectTree
|
@ -1,107 +1,110 @@
|
|||
#------------------------------------------------------------------------------#
|
||||
#=----------------------------------------------------------------------------=#
|
||||
# GNU GPL OS/K #
|
||||
# #
|
||||
# Authors: spectral` #
|
||||
# NeoX #
|
||||
# #
|
||||
# Desc: Project Tree #
|
||||
#------------------------------------------------------------------------------#
|
||||
# #
|
||||
# #
|
||||
# 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/>. #
|
||||
#=----------------------------------------------------------------------------=#
|
||||
|
||||
src/
|
||||
|
|
||||
x COPYING
|
||||
x README.md
|
||||
x ChangeLog
|
||||
|
|
||||
- Makefile
|
||||
- Makefile.in
|
||||
|
|
||||
+ boot/
|
||||
| |
|
||||
| x folder.desc
|
||||
| |
|
||||
| - mbr.asm
|
||||
| - mbr.inc
|
||||
| |
|
||||
| - loader.asm
|
||||
| - loader16.inc
|
||||
| - loader64.inc
|
||||
| |
|
||||
| 0
|
||||
|
|
||||
+ kaleid/
|
||||
| |
|
||||
| + include/
|
||||
| | |
|
||||
| | - kaleid.h
|
||||
| | - kalkern.h
|
||||
| | |
|
||||
| | + common/
|
||||
| | | |
|
||||
| | | - kaldefs.h
|
||||
| | | - kaltypes.h
|
||||
| | | - kalerror.h
|
||||
| | | - kalassrt.h
|
||||
| | | - kallims.h
|
||||
| | | - kalmask.h
|
||||
| | | - kalcrt.h
|
||||
| | | |
|
||||
| | | 0
|
||||
| | |
|
||||
| | + kernel/
|
||||
| | | |
|
||||
| | | - kernbase.h
|
||||
| | | - kernlocks.h
|
||||
| | | - kernterm.h
|
||||
| | | |
|
||||
| | | 0
|
||||
| | 0
|
||||
| |
|
||||
| |
|
||||
| + kernel/
|
||||
| | |
|
||||
| | + init/
|
||||
| | | |
|
||||
| | | - init.c
|
||||
| | | |
|
||||
| | | 0
|
||||
| | |
|
||||
| | + ke/
|
||||
| | | |
|
||||
| | | - panic.c
|
||||
| | | - table.c
|
||||
| | | - terminal.c
|
||||
| | | |
|
||||
| | | 0
|
||||
| | 0
|
||||
| |
|
||||
| + common/
|
||||
| | |
|
||||
| | - status.c
|
||||
| | |
|
||||
| | - arith.c
|
||||
| | - rand.c
|
||||
| | |
|
||||
| | - atoi.c
|
||||
| | - itoa.c
|
||||
| | - strtol.c
|
||||
| | |
|
||||
| | - memory.c
|
||||
| | - string.c
|
||||
| | - sprintf.c
|
||||
| | |
|
||||
| | 0
|
||||
| 0
|
||||
|
|
||||
+ build/
|
||||
| |
|
||||
| - preproc.h
|
||||
| - iddtool.h
|
||||
| |
|
||||
| - kernel.ld
|
||||
| |
|
||||
| + bin/
|
||||
| + obj/
|
||||
| |
|
||||
| 0
|
||||
0
|
||||
|
||||
|
||||
.
|
||||
├── boot
|
||||
│ ├── loader
|
||||
│ │ ├── cpu
|
||||
│ │ │ ├── cpu.asm
|
||||
│ │ │ └── cpuid.asm
|
||||
│ │ ├── elf
|
||||
│ │ │ └── elf.c
|
||||
│ │ ├── fs
|
||||
│ │ │ └── fat.asm
|
||||
│ │ ├── io
|
||||
│ │ │ ├── ata.asm
|
||||
│ │ │ ├── lmmem.asm
|
||||
│ │ │ ├── lmterm.asm
|
||||
│ │ │ ├── rmmem.asm
|
||||
│ │ │ └── rmterm.asm
|
||||
│ │ └── loader.asm
|
||||
│ ├── mbr
|
||||
│ │ ├── mbr.asm
|
||||
│ │ └── mbr.inc
|
||||
│ └── folder.desc
|
||||
├── build
|
||||
│ ├── idttool.py
|
||||
│ ├── kernel.ld
|
||||
│ └── preproc.h
|
||||
├── kaleid
|
||||
│ ├── crtlib
|
||||
│ │ ├── arith.c
|
||||
│ │ ├── atoi.c
|
||||
│ │ ├── itoa.c
|
||||
│ │ ├── memory.c
|
||||
│ │ ├── rand.c
|
||||
│ │ ├── sprintf.c
|
||||
│ │ ├── status.c
|
||||
│ │ ├── string.c
|
||||
│ │ └── strtol.c
|
||||
│ ├── extras
|
||||
│ │ ├── argv.c
|
||||
│ │ └── prog.c
|
||||
│ ├── include
|
||||
│ │ ├── base
|
||||
│ │ │ ├── assert.h
|
||||
│ │ │ ├── bdefs.h
|
||||
│ │ │ ├── crtlib.h
|
||||
│ │ │ ├── errno.h
|
||||
│ │ │ ├── limits.h
|
||||
│ │ │ ├── masks.h
|
||||
│ │ │ └── types.h
|
||||
│ │ ├── extras
|
||||
│ │ │ ├── argv.h
|
||||
│ │ │ ├── list.h
|
||||
│ │ │ ├── locks.h
|
||||
│ │ │ ├── malloc.h
|
||||
│ │ │ └── prog.h
|
||||
│ │ ├── kernel
|
||||
│ │ │ ├── base.h
|
||||
│ │ │ ├── sched.h
|
||||
│ │ │ └── terminal.h
|
||||
│ │ ├── kalbase.h
|
||||
│ │ ├── kaleid.h
|
||||
│ │ ├── kalext.h
|
||||
│ │ └── kalkern.h
|
||||
│ └── kernel
|
||||
│ ├── init
|
||||
│ │ ├── init.c
|
||||
│ │ └── table.c
|
||||
│ ├── io
|
||||
│ │ ├── cursor.c
|
||||
│ │ ├── term.c
|
||||
│ │ └── vga.c
|
||||
│ ├── ke
|
||||
│ │ └── panic.c
|
||||
│ └── proc
|
||||
│ ├── Makefile
|
||||
│ └── sched.c
|
||||
├── AUTHORS
|
||||
├── ChangeLog
|
||||
├── COPYING
|
||||
├── Makefile
|
||||
├── Makefile.in
|
||||
├── ProjectTree
|
||||
└── Readme.md
|
||||
|
||||
20 directories, 61 files
|
||||
|
|
13
Readme.md
13
Readme.md
|
@ -1,14 +1,17 @@
|
|||
# GNU-GPL OS/K (OS on Kaleid)
|
||||
# GNU GPL OS/K (OS on Kaleid)
|
||||
|
||||
### Fully open-source operating system from scratch (WIP), released under the GNU GPL version 3.0
|
||||
| ![FSF Logo](https://www.os-k.eu/GPLLOGO.PNG) | This program is free software, released under the terms of the [GNU GPL](COPYING) version 3 or later as published by the Free Software Foundation |
|
||||
|----------------------------------------------|----------------------------------------------------------------------|
|
||||
|
||||
#### Boot Branch
|
||||
### Fully free operating system from scratch (WIP)
|
||||
|
||||
#### Master Branch
|
||||
|
||||
For the project plan, see [OS/K Project](https://github.com/orgs/os-k-team/projects/1)
|
||||
|
||||
For changelog, see [ChangeLog](https://github.com/os-k-team/GNU-GPL-OS-K/blob/master/ChangeLog)
|
||||
For changelog, see [ChangeLog](ChangeLog)
|
||||
|
||||
For structure of the sources, see [ProjectTree](https://github.com/os-k-team/GNU-GPL-OS-K/blob/master/ProjectTree)
|
||||
For structure of the sources, see [ProjectTree](ProjectTree)
|
||||
|
||||
Note that every file within OS/K is written using spaces for tabulation, with each
|
||||
tabulation being 4 spaces long.
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
theme: jekyll-theme-slate
|
|
@ -1,11 +1,26 @@
|
|||
---------------------------------------------------------------------
|
||||
GNU GPL OS/K
|
||||
|
||||
Authors: spectral`
|
||||
NeoX
|
||||
|
||||
Desc: Folder description - "boot"
|
||||
---------------------------------------------------------------------
|
||||
#=----------------------------------------------------------------------------=#
|
||||
# GNU GPL OS/K #
|
||||
# #
|
||||
# Desc: Folder description - "boot" #
|
||||
# #
|
||||
# #
|
||||
# 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/>. #
|
||||
#=----------------------------------------------------------------------------=#
|
||||
|
||||
|
||||
This folder contains the source for OS/K's bootloader.
|
||||
|
@ -19,5 +34,5 @@ It is divided in two parts each of exactly 512 bytes:
|
|||
The MBR must be placed precisely on the first sector of the hard drive.
|
||||
|
||||
- loader.s
|
||||
This is the Kernel Loader. XXX
|
||||
This is the Kernel Loader. It switches to long mode and makes stuff.
|
||||
|
||||
|
|
|
@ -1,11 +1,26 @@
|
|||
;=----------------------------------------------------------------------------=;
|
||||
; GNU GPL OS/K ;
|
||||
; ;
|
||||
; Authors: spectral` ;
|
||||
; NeoX ;
|
||||
; ;
|
||||
; Desc: Basic longmode CPU functions ;
|
||||
; (x86_64 architecture only) ;
|
||||
; ;
|
||||
; ;
|
||||
; 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 ;
|
||||
; (at your option) 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/>. ;
|
||||
;=----------------------------------------------------------------------------=;
|
||||
|
||||
[BITS 64]
|
||||
|
|
|
@ -1,11 +1,26 @@
|
|||
;=----------------------------------------------------------------------------=;
|
||||
; GNU GPL OS/K ;
|
||||
; ;
|
||||
; Authors: spectral` ;
|
||||
; NeoX ;
|
||||
; ;
|
||||
; Desc: Basic realmode CPU Detection ;
|
||||
; (x86_64 architecture only) ;
|
||||
; ;
|
||||
; ;
|
||||
; 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 ;
|
||||
; (at your option) 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/>. ;
|
||||
;=----------------------------------------------------------------------------=;
|
||||
|
||||
[BITS 16]
|
||||
|
|
|
@ -1,10 +1,26 @@
|
|||
//----------------------------------------------------------------------------//
|
||||
//=--------------------------------------------------------------------------=//
|
||||
// GNU GPL OS/K //
|
||||
// //
|
||||
// Authors: spectral` //
|
||||
// NeoX //
|
||||
// //
|
||||
// Desc: ELF64 Parser and Loader //
|
||||
//----------------------------------------------------------------------------//
|
||||
// (x86_64 architecture only) //
|
||||
// //
|
||||
// //
|
||||
// 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 //
|
||||
// (at your option) 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/>. //
|
||||
//=--------------------------------------------------------------------------=//
|
||||
|
||||
int stub;
|
||||
|
|
|
@ -1,11 +1,26 @@
|
|||
;=----------------------------------------------------------------------------=;
|
||||
; GNU GPL OS/K ;
|
||||
; ;
|
||||
; Authors: spectral` ;
|
||||
; NeoX ;
|
||||
; ;
|
||||
; Desc: Basic File Allocation Table Long mode Driver ;
|
||||
; (x86_64 architecture only) ;
|
||||
; ;
|
||||
; ;
|
||||
; 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 ;
|
||||
; (at your option) 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/>. ;
|
||||
;=----------------------------------------------------------------------------=;
|
||||
|
||||
[BITS 64]
|
||||
|
|
|
@ -1,11 +1,26 @@
|
|||
;=----------------------------------------------------------------------------=;
|
||||
; GNU GPL OS/K ;
|
||||
; ;
|
||||
; Authors: spectral` ;
|
||||
; NeoX ;
|
||||
; ;
|
||||
; Desc: Basic Read Only ATA Long mode Driver ;
|
||||
; (x86_64 architecture only) ;
|
||||
; ;
|
||||
; ;
|
||||
; 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 ;
|
||||
; (at your option) 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/>. ;
|
||||
;=----------------------------------------------------------------------------=;
|
||||
|
||||
[BITS 64]
|
||||
|
|
|
@ -1,11 +1,26 @@
|
|||
;=----------------------------------------------------------------------------=;
|
||||
; GNU GPL OS/K ;
|
||||
; ;
|
||||
; Authors: spectral` ;
|
||||
; NeoX ;
|
||||
; ;
|
||||
; Desc: Basic Memory Long mode Functions ;
|
||||
; (x86_64 architecture only) ;
|
||||
; ;
|
||||
; ;
|
||||
; 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 ;
|
||||
; (at your option) 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/>. ;
|
||||
;=----------------------------------------------------------------------------=;
|
||||
[BITS 64]
|
||||
|
||||
|
|
|
@ -1,13 +1,29 @@
|
|||
;=----------------------------------------------------------------------------=;
|
||||
; GNU GPL OS/K ;
|
||||
; ;
|
||||
; Authors: spectral` ;
|
||||
; NeoX ;
|
||||
; ;
|
||||
; Desc: Basic Colored VGA Terminal Long mode Driver ;
|
||||
; (x86_64 architecture only) ;
|
||||
; ;
|
||||
; ;
|
||||
; 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 ;
|
||||
; (at your option) 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/>. ;
|
||||
;=----------------------------------------------------------------------------=;
|
||||
|
||||
|
||||
;;VIDEO
|
||||
%define TRAM 0x0B8000 ; [T]ext[RAM]
|
||||
%define VRAM 0x0A0000 ; [V]ideo[RAM]
|
||||
|
|
|
@ -1,11 +1,26 @@
|
|||
;=----------------------------------------------------------------------------=;
|
||||
; GNU GPL OS/K ;
|
||||
; ;
|
||||
; Authors: spectral` ;
|
||||
; NeoX ;
|
||||
; ;
|
||||
; Desc: Basic Memory Realmode Driver ;
|
||||
; (x86_64 architecture only) ;
|
||||
; ;
|
||||
; ;
|
||||
; 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 ;
|
||||
; (at your option) 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/>. ;
|
||||
;=----------------------------------------------------------------------------=;
|
||||
|
||||
[BITS 16]
|
||||
|
|
|
@ -1,11 +1,26 @@
|
|||
;=----------------------------------------------------------------------------=;
|
||||
; GNU GPL OS/K ;
|
||||
; ;
|
||||
; Authors: spectral` ;
|
||||
; NeoX ;
|
||||
; ;
|
||||
; Desc: Basic realmode terminal functions ;
|
||||
; (x86_64 architecture only) ;
|
||||
; ;
|
||||
; ;
|
||||
; 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 ;
|
||||
; (at your option) 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/>. ;
|
||||
;=----------------------------------------------------------------------------=;
|
||||
|
||||
[BITS 16]
|
||||
|
|
|
@ -1,11 +1,26 @@
|
|||
;=----------------------------------------------------------------------------=;
|
||||
; GNU GPL OS/K ;
|
||||
; ;
|
||||
; Authors: spectral` ;
|
||||
; NeoX ;
|
||||
; ;
|
||||
; Desc: Kernel (second stage) Loader for OS/K ;
|
||||
; (x86_64 architecture only) ;
|
||||
; ;
|
||||
; ;
|
||||
; 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 ;
|
||||
; (at your option) 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/>. ;
|
||||
;=----------------------------------------------------------------------------=;
|
||||
|
||||
%define DEBUG
|
||||
|
@ -242,4 +257,3 @@ main64:
|
|||
|
||||
jmp Die
|
||||
|
||||
times 20 db 0
|
||||
|
|
|
@ -1,11 +1,26 @@
|
|||
;=----------------------------------------------------------------------------=;
|
||||
; GNU GPL OS/K ;
|
||||
; ;
|
||||
; Authors: spectral` ;
|
||||
; NeoX ;
|
||||
; ;
|
||||
; Desc: Bootsector for OS/K ;
|
||||
; (x86_64 architecture only) ;
|
||||
; ;
|
||||
; ;
|
||||
; 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/>. ;
|
||||
;=----------------------------------------------------------------------------=;
|
||||
|
||||
;; BOOT "SEGMENT"
|
||||
|
|
|
@ -1,12 +1,28 @@
|
|||
;=----------------------------------------------------------------------------=;
|
||||
; GNU GPL OS/K ;
|
||||
; ;
|
||||
; Authors: spectral` ;
|
||||
; NeoX ;
|
||||
; ;
|
||||
; Desc: Bootsector for OS/K INCLUDED FUNCTIONS ;
|
||||
; (x86_64 architecture only) ;
|
||||
; ;
|
||||
; ;
|
||||
; 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/>. ;
|
||||
;=----------------------------------------------------------------------------=;
|
||||
|
||||
[BITS 16]
|
||||
|
||||
read_clusters:
|
||||
|
|
Binary file not shown.
|
@ -9,11 +9,13 @@
|
|||
#ifdef _TO_ASM
|
||||
# define _CSPREF -S
|
||||
# define _OUTFIX S
|
||||
# define _ASMTYPE -masm=intel
|
||||
# define LINK_KERNEL(out)
|
||||
#else
|
||||
# define _CSPREF -c
|
||||
# define _OUTFIX o
|
||||
# define LINK_KERNEL(out) $(KCC) $(CLDSCR) $(COMMOBJS) $(KERNOBJS) -o $(BINDIR)/out
|
||||
# define _ASMTYPE
|
||||
# define LINK_KERNEL(out) $(KCC) -T ./build/kernel.ld $(CLDSCR) $(COMMOBJS) $(KERNOBJS) -o $(BINDIR)/out
|
||||
#endif
|
||||
|
||||
#define COMPILE_CONVRT1(file) $(CCC) _CSPREF $(COMMDIR)/itoa.c -o $(COBJDIR)/file._OUTFIX
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
//----------------------------------------------------------------------------//
|
||||
|
||||
// do not mask anything
|
||||
#define _KALMASK_H
|
||||
#include <kaleid.h>
|
||||
#define _KALEID_UNMASKED
|
||||
#include <kalbase.h>
|
||||
|
||||
int _osk_abs(int x)
|
||||
{
|
|
@ -7,12 +7,10 @@
|
|||
// Desc: Conversion utilities - atoi family //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#include <kaleid.h>
|
||||
#include <kalbase.h>
|
||||
|
||||
//
|
||||
// String to integer
|
||||
// Do not change errno
|
||||
//
|
||||
#define _ATOI_IMPL(_Name, _Type, _Func) \
|
||||
_Type _Name(const char *str) { \
|
||||
__get_errno(old); \
|
|
@ -7,54 +7,56 @@
|
|||
// Desc: Conversion utilities - itoa family //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#include <kaleid.h>
|
||||
#include <kalbase.h>
|
||||
|
||||
//
|
||||
// Digits table for bases <=36 (unused)
|
||||
//
|
||||
#if 0
|
||||
static const char digits[] =
|
||||
"0123456789abcdefghijklmnopqrstuvwxyz";
|
||||
#endif
|
||||
|
||||
//
|
||||
// Integer to string in any base between 2 and 36 (included)
|
||||
//
|
||||
|
||||
#if defined(_NEED_ITOA)
|
||||
|
||||
char *itoa(int i, char *str, int base)
|
||||
#define _IL_MIN INT_MIN
|
||||
#define _IL_MIN_STRING "-2147483648"
|
||||
char *itoa(int i, char *str, int base)
|
||||
{
|
||||
int rem;
|
||||
|
||||
#elif defined(_NEED_LTOA)
|
||||
|
||||
char *ltoa(long i, char *str, int base)
|
||||
#define _IL_MIN LONG_MIN
|
||||
#define _IL_MIN_STRING "-9223372036854775808"
|
||||
char *ltoa(long i, char *str, int base)
|
||||
{
|
||||
long rem;
|
||||
|
||||
#elif defined(_NEED_UTOA)
|
||||
|
||||
char *utoa(uint i, char *str, int base)
|
||||
{
|
||||
uint rem;
|
||||
|
||||
#elif defined(_NEED_ULTOA)
|
||||
|
||||
char *ultoa(ulong i, char *str, int base)
|
||||
{
|
||||
ulong rem;
|
||||
|
||||
#else
|
||||
#error "What am I supposed to declare?"
|
||||
#endif
|
||||
|
||||
{
|
||||
char *orig = str;
|
||||
|
||||
#if defined(_NEED_ITOA) || defined(_NEED_LTOA)
|
||||
//
|
||||
// Deal with negatives
|
||||
//
|
||||
int neg = 0;
|
||||
if (i < 0 && base == 10) {
|
||||
//
|
||||
|
||||
// Handle INT_MIN and LONG_MIN...
|
||||
//
|
||||
if (__builtin_expect(i == _IL_MIN, 0)) {
|
||||
strcpy(orig, _IL_MIN_STRING);
|
||||
goto leave;
|
||||
|
@ -67,27 +69,21 @@ char *ultoa(ulong i, char *str, int base)
|
|||
}
|
||||
#endif
|
||||
|
||||
//
|
||||
// Only handle base 2 -> 36
|
||||
//
|
||||
if (base < 2 || base > 36) {
|
||||
__set_errno(EINVAL);
|
||||
*orig = '\0;
|
||||
*orig = '\0';
|
||||
goto leave;
|
||||
}
|
||||
|
||||
//
|
||||
// Deal with zero separately
|
||||
//
|
||||
if (i == 0) {
|
||||
*str++ = '0';
|
||||
*str = '\0';
|
||||
goto leave;
|
||||
}
|
||||
|
||||
//
|
||||
// Compute digits... in reverse order
|
||||
//
|
||||
while (i > 0) {
|
||||
rem = i % base;
|
||||
*str++ = (rem > 9)
|
||||
|
@ -102,14 +98,10 @@ char *ultoa(ulong i, char *str, int base)
|
|||
|
||||
*str = '\0';
|
||||
|
||||
//
|
||||
// Reverse the string
|
||||
//
|
||||
orig = strrev2(orig);
|
||||
|
||||
//
|
||||
// End of conversion
|
||||
//
|
||||
leave:
|
||||
return orig;
|
||||
}
|
|
@ -7,7 +7,7 @@
|
|||
// Desc: mem*() functions //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#include <kaleid.h>
|
||||
#include <kalbase.h>
|
||||
|
||||
//------------------------------------------//
|
||||
// memset() family //
|
||||
|
@ -20,17 +20,13 @@ void *memset(void *ptr, int val, size_t bytes)
|
|||
{
|
||||
uchar *uptr = (uchar *)ptr;
|
||||
|
||||
//
|
||||
// Deal with bytes before start of the first aligned qword
|
||||
//
|
||||
while (((ulong)uptr % QWORD_ALIGN) > 0 && bytes--) {
|
||||
while (((ulong)uptr % alignof(QWORD)) > 0 && bytes--) {
|
||||
*uptr++ = (uchar)val;
|
||||
}
|
||||
|
||||
//
|
||||
// At this point we're qword-aligned
|
||||
//
|
||||
if (bytes > QWORD_SIZE) {
|
||||
if (bytes > sizeof(QWORD)) {
|
||||
const ulong uval = ((ulong)val << 56) | ((ulong)val << 48)
|
||||
| ((ulong)val << 40) | ((ulong)val << 32)
|
||||
| ((ulong)val << 24) | ((ulong)val << 16)
|
||||
|
@ -38,20 +34,16 @@ void *memset(void *ptr, int val, size_t bytes)
|
|||
|
||||
ulong *uqptr = (ulong *)ptr;
|
||||
|
||||
//
|
||||
// Moving fast, qword by qword
|
||||
//
|
||||
while (bytes > QWORD_SIZE) {
|
||||
while (bytes > sizeof(QWORD)) {
|
||||
bytes -= sizeof(QWORD);
|
||||
*uqptr++ = uval;
|
||||
bytes -= QWORD_SIZE;
|
||||
}
|
||||
|
||||
uptr = (uchar *)(ulong)uqptr;
|
||||
}
|
||||
|
||||
//
|
||||
// Deal with the few remaining bytes
|
||||
//
|
||||
while (bytes--) *uptr++ = (uchar)val;
|
||||
|
||||
return ptr;
|
||||
|
@ -64,18 +56,14 @@ void *memsetw(void *ptr, int val, size_t words)
|
|||
{
|
||||
ushort *uptr = (ushort *)ptr;
|
||||
|
||||
//
|
||||
// Check whether we can we do this an aligned way
|
||||
//
|
||||
if unlikely (((ulong)uptr % WORD_ALIGN) > 0) {
|
||||
//
|
||||
// Check whether we can we do this a word-aligned way
|
||||
if unlikely (((ulong)uptr % alignof(WORD)) > 0) {
|
||||
// We can't, so we write word by word all the way up
|
||||
//
|
||||
while (words--) *uptr++ = (ushort)val;
|
||||
return uptr;
|
||||
}
|
||||
|
||||
while (((ulong)uptr % QWORD_ALIGN) > 0 && words--) {
|
||||
while (((ulong)uptr % alignof(QWORD)) > 0 && words--) {
|
||||
*uptr++ = (ushort)val;
|
||||
}
|
||||
|
||||
|
@ -98,28 +86,22 @@ void *memsetw(void *ptr, int val, size_t words)
|
|||
return ptr;
|
||||
}
|
||||
|
||||
//
|
||||
// Set "dwords"-many dwords starting from ptr to val
|
||||
// XXX unimplemented
|
||||
//
|
||||
void *memsetd(void *ptr, int val, size_t dwords)
|
||||
{
|
||||
(void)val;
|
||||
(void)dwords;
|
||||
|
||||
__set_errno(ENOSYS);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
//
|
||||
// Set "qwords"-many qwords starting from ptr to val
|
||||
//
|
||||
void *memsetq(void *ptr, long val, size_t qwords)
|
||||
{
|
||||
ulong *uptr = (ulong *)ptr;
|
||||
|
||||
//
|
||||
// There's no need to check for alignment
|
||||
//
|
||||
while (qwords--) *uptr++ = (ulong)val;
|
||||
|
||||
return ptr;
|
||||
|
@ -148,17 +130,13 @@ void *memcpy(void *restrict dst, const void *restrict src, size_t bytes)
|
|||
|
||||
if unlikely (bytes == 0) return dst;
|
||||
|
||||
//
|
||||
// Can align both src and dst at once at once?
|
||||
//
|
||||
if unlikely ((ulong)src % WORD_ALIGN == 1
|
||||
&& (ulong)dst % WORD_ALIGN == 1) {
|
||||
if unlikely ((ulong)src % alignof(WORD) == 1
|
||||
&& (ulong)dst % alignof(WORD) == 1) {
|
||||
const uchar *ubsrc = (const uchar *)usrc;
|
||||
uchar *ubdst = (uchar *)udst;
|
||||
|
||||
//
|
||||
// Yes we can, we're guaranteed to be word-aligned now
|
||||
//
|
||||
// Yes we can, we're guaranteed to be word-aligned after that
|
||||
*ubdst++ = *ubsrc++;
|
||||
bytes--;
|
||||
|
||||
|
@ -169,34 +147,28 @@ void *memcpy(void *restrict dst, const void *restrict src, size_t bytes)
|
|||
const ushort *uwsrc = (const ushort *)usrc;
|
||||
ushort *uwdst = (ushort *)udst;
|
||||
|
||||
//
|
||||
// Align either dst or src for qword access
|
||||
//
|
||||
while ((ulong)dst % QWORD_ALIGN > 0
|
||||
&& (ulong)src % QWORD_ALIGN > 0
|
||||
&& bytes > WORD_SIZE) {
|
||||
while ((ulong)dst % alignof(QWORD) > 0
|
||||
&& (ulong)src % alignof(QWORD) > 0
|
||||
&& bytes > sizeof(WORD)) {
|
||||
|
||||
bytes -= sizeof(WORD);
|
||||
*uwdst++ = *uwsrc++;
|
||||
bytes -= WORD_SIZE;
|
||||
}
|
||||
|
||||
udst = (ulong *)uwdst;
|
||||
usrc = (ulong *)uwsrc;
|
||||
|
||||
//
|
||||
// This should be most of the job
|
||||
//
|
||||
while (bytes > QWORD_SIZE) {
|
||||
// Copy fast
|
||||
while (bytes > sizeof(QWORD)) {
|
||||
bytes -= sizeof(QWORD);
|
||||
*udst++ = *usrc++;
|
||||
bytes -= QWORD_SIZE;
|
||||
}
|
||||
|
||||
const uchar *ubsrc = (const uchar *)usrc;
|
||||
ushort *ubdst = (ushort *)udst;
|
||||
|
||||
//
|
||||
// Deal with the few bytes left
|
||||
//
|
||||
while (bytes--) *ubdst ++ = *ubsrc++;
|
||||
|
||||
return dst;
|
||||
|
@ -210,16 +182,12 @@ void *memmove(void *dst, const void *src, size_t bytes)
|
|||
const uchar *usrc = src;
|
||||
uchar *udst = dst;
|
||||
|
||||
//
|
||||
// Can we use memcpy() safely?
|
||||
//
|
||||
if (udst < usrc) {
|
||||
return memcpy(dst, src, bytes);
|
||||
}
|
||||
|
||||
//
|
||||
// No, so we go backwards
|
||||
//
|
||||
uchar *usrc_end = (uchar *)usrc + bytes - 1;
|
||||
uchar *udst_end = udst + bytes - 1;
|
||||
while (bytes--) *udst_end-- = *usrc_end--;
|
|
@ -7,7 +7,7 @@
|
|||
// Desc: RNG related functions //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#include <kaleid.h>
|
||||
#include <kalbase.h>
|
||||
|
||||
//
|
||||
// Seed value
|
||||
|
@ -20,8 +20,8 @@ static ulong next = 7756;
|
|||
//
|
||||
int rand(void)
|
||||
{
|
||||
next = next * 1103515245 + 12345;
|
||||
return (uint)(next / 65536) % INT_MAX;
|
||||
next = next * 1103515245 + 12347;
|
||||
return (uint)(next / 65536);
|
||||
}
|
||||
|
||||
//
|
|
@ -7,11 +7,14 @@
|
|||
// Desc: sprintf()-related functions //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#include <kaleid.h>
|
||||
#include <kalbase.h>
|
||||
|
||||
//
|
||||
// Format str according to fmt using ellipsed arguments
|
||||
//
|
||||
// BE CAREFUL when using this
|
||||
// you need to know for sure an overflow won't happen
|
||||
//
|
||||
int sprintf(char *str, const char *fmt, ...)
|
||||
{
|
||||
int ret;
|
||||
|
@ -31,6 +34,7 @@ int vsprintf(char *str, const char *fmt, va_list ap)
|
|||
|
||||
//
|
||||
// (v)sprintf() but with a size limit: no more than n bytes are written in str
|
||||
// Always null-terminate str
|
||||
//
|
||||
int snprintf(char *str, size_t n, const char *fmt, ...)
|
||||
{
|
||||
|
@ -48,14 +52,10 @@ int vsnprintf(char *str, size_t n, const char *fmt, va_list ap)
|
|||
{
|
||||
int ret = 0;
|
||||
|
||||
//
|
||||
// Go throught the format string
|
||||
//
|
||||
while (*fmt) {
|
||||
if (*fmt != '%') {
|
||||
//
|
||||
// Even if we don't have any more room we still increase ret
|
||||
//
|
||||
if (ret++ < n) {
|
||||
*str++ = *fmt++;
|
||||
}
|
|
@ -7,7 +7,7 @@
|
|||
// Desc: Implementation of describe_status() //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#include <kaleid.h>
|
||||
#include <kalbase.h>
|
||||
|
||||
error_t __errno = 0;
|
||||
|
|
@ -7,8 +7,7 @@
|
|||
// Desc: String-related functions //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
|
||||
#include <kaleid.h>
|
||||
#include <kalbase.h>
|
||||
|
||||
//
|
||||
// Compare two strings
|
||||
|
@ -129,9 +128,7 @@ char *strstr(const char *haystack, const char *needle)
|
|||
{
|
||||
const size_t needle_size = strlen(needle);
|
||||
|
||||
//
|
||||
// Moves haystack to first occurence of the needle's first byte
|
||||
//
|
||||
while ((haystack = strchr(haystack, *needle)) != NULL) {
|
||||
if (strncmp(haystack, needle, needle_size) == 0) {
|
||||
return (char *)haystack;
|
||||
|
@ -151,15 +148,11 @@ char *strtok_r(char *restrict str, const char *restrict delim, char **restrict s
|
|||
|
||||
if (str == NULL) str = *saveptr;
|
||||
|
||||
//
|
||||
// Skip initial segments composed only of delimiters
|
||||
//
|
||||
str += strspn(str, delim);
|
||||
|
||||
//
|
||||
// If str is empty, store it in saveptr so that next call
|
||||
// still finds an empty strings and returns NULL
|
||||
//
|
||||
if (*str == 0) {
|
||||
*saveptr = str;
|
||||
return NULL;
|
||||
|
@ -192,6 +185,7 @@ char *strtok(char *restrict str, const char *restrict delim)
|
|||
{
|
||||
static char *saveptr = NULL;
|
||||
|
||||
// Avoid this function if possible
|
||||
KalAssert(FALSE);
|
||||
|
||||
if (str) saveptr = str;
|
||||
|
@ -229,33 +223,26 @@ char *strncpy(char *restrict dest, const char *restrict src, size_t n)
|
|||
}
|
||||
|
||||
//
|
||||
// Copies at most n-1 bytes from src to dest, then fills
|
||||
// the rest with 0; dest[n] is guanranteed to be '\0'
|
||||
// Copies at most n-1 bytes from src to dest
|
||||
// Always null-terminates dest, but doesn't fill
|
||||
// dest's contents past the null-terminator
|
||||
//
|
||||
// Returns TRUE if dest would have been null-terminated
|
||||
// by ordinary strncpy(), and FALSE otherwise
|
||||
// Returns the number of bytes NOT written, not counting null-terminators
|
||||
//
|
||||
int strnzcpy(char *restrict dest, const char *restrict src, size_t n)
|
||||
size_t strnzcpy(char *restrict dest, const char *restrict src, size_t n)
|
||||
{
|
||||
size_t it;
|
||||
size_t it, loss;
|
||||
|
||||
for (it = 0; it < n - 1 && src[it]; it++) {
|
||||
dest[it] = src[it];
|
||||
}
|
||||
|
||||
// Was the copy complete?
|
||||
if (it == n) {
|
||||
if (dest[n] == 0) {
|
||||
return TRUE;
|
||||
}
|
||||
dest[it] = 0;
|
||||
|
||||
dest[n] = 0;
|
||||
return FALSE;
|
||||
}
|
||||
// Compute how many bytes were not copied
|
||||
for (loss = it; src[loss]; loss++);
|
||||
|
||||
while (it < n) dest[it++] = 0;
|
||||
|
||||
return TRUE;
|
||||
return loss - it;
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -288,13 +275,15 @@ char *strncat(char *restrict dest, const char *restrict src, size_t n)
|
|||
}
|
||||
|
||||
//
|
||||
// Appends a copy of at most n bytes of src at the end of dest
|
||||
// Always null-terminates, and returne TRUE or FALSE depending on whether
|
||||
// regular strcat() would have null-terminated this string, or not
|
||||
// Appends at most n-1 bytes from src to dest
|
||||
// Always null-terminates dest, but doesn't fill
|
||||
// dest's contents past the null-terminator
|
||||
//
|
||||
int *strnzcat(char *restrict dest, const char *restrict src, size_t n)
|
||||
// Returns the number of bytes NOT written, not counting null-terminators
|
||||
//
|
||||
size_t strnzcat(char *restrict dest, const char *restrict src, size_t n)
|
||||
{
|
||||
size_t it, off = 0;
|
||||
size_t it, loss, off = 0;
|
||||
|
||||
while (dest[off]) off++;
|
||||
|
||||
|
@ -302,19 +291,12 @@ int *strnzcat(char *restrict dest, const char *restrict src, size_t n)
|
|||
dest[it+off] = src[it];
|
||||
}
|
||||
|
||||
// Was the copy complete?
|
||||
if (it == n) {
|
||||
if (dest[n+off] == 0) {
|
||||
return TRUE;
|
||||
}
|
||||
dest[it+off] = 0;
|
||||
|
||||
dest[n+off] = 0;
|
||||
return FALSE;
|
||||
}
|
||||
// Compute how many bytes were not copied
|
||||
for (loss = it; src[loss+off]; loss++);
|
||||
|
||||
while (it++ < n) dest[it+off] = 0;
|
||||
|
||||
return TRUE;
|
||||
return loss - it;
|
||||
}
|
||||
|
||||
//
|
|
@ -7,7 +7,7 @@
|
|||
// Desc: strto(u)l functions //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#include <kaleid.h>
|
||||
#include <kalbase.h>
|
||||
|
||||
long strtol(const char *str, char **endp, int base) {
|
||||
(void)str;
|
|
@ -0,0 +1,202 @@
|
|||
//----------------------------------------------------------------------------//
|
||||
// GNU GPL OS/K //
|
||||
// //
|
||||
// Authors: spectral` //
|
||||
// NeoX //
|
||||
// //
|
||||
// Desc: Command line parsing utilities //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#include <kalbase.h>
|
||||
#include <extras/prog.h>
|
||||
#include <extras/argv.h>
|
||||
#include <extras/malloc.h>
|
||||
|
||||
//
|
||||
// Computes argument count, the least N such
|
||||
// that argv[N] == NULL
|
||||
//
|
||||
int KalComputeArgCount(const char **argv)
|
||||
{
|
||||
int argc = 0;
|
||||
|
||||
while (argv[argc]) argc++;
|
||||
|
||||
return argc;
|
||||
}
|
||||
|
||||
//
|
||||
// Computes the total size of argv, including
|
||||
// the null-terminators
|
||||
//
|
||||
size_t KalComputeArgVecSize(const char *argv[])
|
||||
{
|
||||
size_t len;
|
||||
|
||||
for (len = 0; *argv; len += strlen(*argv) + 1, argv++);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
//
|
||||
// Converts command line to an argument vector
|
||||
//
|
||||
// This function assumes that argv[0] is a pointer
|
||||
// to a ARG_MAX-wide buffer, which will be filled
|
||||
// with strings in succession; the address of the nth
|
||||
// string will be stored in argv[n-1]
|
||||
//
|
||||
// Technically ARG_MAX is the maximum number of bytes
|
||||
// in both the buffer *and* argv, i.e. (argc + 1) * sizeof(char *)
|
||||
// bytes are reserved for the argv[i] pointers, so in fact less than
|
||||
// ARG_MAX bytes are available
|
||||
//
|
||||
// That available space, however, remains strictly higher than 4KB,
|
||||
// which is the POSIX minimum; in case of doubt, safely use 4KB
|
||||
//
|
||||
// TODO long escape sequences
|
||||
// get program command line if cmdLine == NULL
|
||||
//
|
||||
error_t KalCmdLineToArgVecEx(const char *cmdLine,
|
||||
int *argcPtr,
|
||||
char **argv,
|
||||
bool doEscaping)
|
||||
{
|
||||
int argc;
|
||||
char quotes = 0;
|
||||
bool started = false;
|
||||
bool escaping = false;
|
||||
size_t written = 0;
|
||||
error_t retcode = EOK;
|
||||
|
||||
KalAlwaysAssert(argv && *argv && cmdLine);
|
||||
|
||||
// An ARG_MAX-wide buffer
|
||||
char *buffer = *argv;
|
||||
|
||||
// Null-terminate current argv slot
|
||||
// and save the start of next string
|
||||
// Macro'd to avoid copypasting code
|
||||
#define NULLTERM_AND_SAVE \
|
||||
*buffer = 0; \
|
||||
argv[++argc] = buffer++ + 1; \
|
||||
written += sizeof(char *) + 1; \
|
||||
|
||||
// Is character a blank character?
|
||||
// To be replaced by ctype stuff once
|
||||
// that's implemented
|
||||
#define ISBLANK(c) ((c) == ' ' || (c) == '\t' || (c) == '\n')
|
||||
|
||||
// Both " and ' are valid quotes chars
|
||||
// XXX aren't there more?
|
||||
#define ISQUOTE(c) ((c) == '\'' || (c) == '"')
|
||||
|
||||
|
||||
// Go through the command line
|
||||
for (argc = 0; *cmdLine; cmdLine++) {
|
||||
|
||||
// Make sure we don't go beyond ARG_MAX bytes
|
||||
if (written >= ARG_MAX - (1 + sizeof(char *))) {
|
||||
|
||||
// All we have left is one byte for the null-terminator of the current slot
|
||||
// and sizeof(char *) bytes for the NULL at the end of argv
|
||||
*buffer = 0;
|
||||
|
||||
// Did we write anything in this slot?
|
||||
if (started) {
|
||||
argc++;
|
||||
}
|
||||
|
||||
// We're done, get out of here
|
||||
retcode = ENOMEM;
|
||||
break;
|
||||
}
|
||||
|
||||
// Switch to next argv slot
|
||||
if (ISBLANK(*cmdLine) && !quotes && !escaping) {
|
||||
|
||||
// Has slot even started?
|
||||
if (started) {
|
||||
started = false;
|
||||
NULLTERM_AND_SAVE;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// Escaping next character
|
||||
if (*cmdLine == '\\' && !escaping && doEscaping) {
|
||||
escaping = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Deal with escape sequences
|
||||
if (escaping) {
|
||||
if (*cmdLine == 'n') *buffer++ = '\n';
|
||||
else if (*cmdLine == 'r') *buffer++ = '\r';
|
||||
else if (*cmdLine == 't') *buffer++ = '\t';
|
||||
else if (*cmdLine == 'f') *buffer++ = '\f';
|
||||
else if (*cmdLine == 'v') *buffer++ = '\v';
|
||||
|
||||
written++;
|
||||
started = true;
|
||||
escaping = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Deal with quotes
|
||||
if (ISQUOTE(*cmdLine) && !escaping) {
|
||||
|
||||
// Quoted text always fills a whole slot
|
||||
// Note that this is the only way an empty
|
||||
// string can be put in a slot
|
||||
if (!quotes && !started) {
|
||||
quotes = *cmdLine;
|
||||
started = true;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// End a quote block
|
||||
if (quotes == *cmdLine && ISBLANK(cmdLine[1])) {
|
||||
quotes = 0;
|
||||
started = false;
|
||||
|
||||
NULLTERM_AND_SAVE;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Quotes were either preceeded by unquoted non-blank text
|
||||
// or couldn't close quoted text block because succeeded
|
||||
// by text; we consider this " to be escaped and fall through
|
||||
}
|
||||
|
||||
// Just a regular character, or it is being escaped
|
||||
written++;
|
||||
started = true;
|
||||
escaping = false;
|
||||
*buffer++ = *cmdLine;
|
||||
}
|
||||
|
||||
// Ensures that argv[argc] == NULL
|
||||
argv[++argc] = NULL;
|
||||
|
||||
// Update *argcPtr, but we don't mind if
|
||||
// NULL was passed for argcPtr
|
||||
if (argcPtr) {
|
||||
*argcPtr = argc;
|
||||
}
|
||||
|
||||
return retcode;
|
||||
}
|
||||
|
||||
#undef ISQUOTE
|
||||
#undef ISBLANK
|
||||
#undef NULLTERM_AND_SAVE
|
||||
|
||||
error_t KalCmdLineToArgVec(const char *cmdLine,
|
||||
int *argcPtr,
|
||||
char **argv)
|
||||
{
|
||||
return KalCmdLineToArgVecEx(cmdLine, argcPtr, argv, false);
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
//----------------------------------------------------------------------------//
|
||||
// GNU GPL OS/K //
|
||||
// //
|
||||
// Authors: spectral` //
|
||||
// NeoX //
|
||||
// //
|
||||
// Desc: Program utilities //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#include <kalbase.h>
|
||||
#include <extras/prog.h>
|
||||
|
||||
#ifdef _KALEID_KERNEL
|
||||
|
||||
const char *__progname = "kaleid-kernel";
|
||||
const char *__progvers = "pre-pre-alpha-0.0.1";
|
||||
|
||||
#else
|
||||
|
||||
const char *__progname = "kaleid-test";
|
||||
const char *__progvers = "(n/a)";
|
||||
|
||||
#endif
|
||||
|
||||
const char *KalGetProgName(void)
|
||||
{
|
||||
return __progname;
|
||||
}
|
||||
|
||||
const char *KalGetProgVersion(void)
|
||||
{
|
||||
return __progvers;
|
||||
}
|
||||
|
||||
bool KalSetProgVers(const char *vers)
|
||||
{
|
||||
(void)vers;
|
||||
__set_errno(ENOSYS);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool KalSetProgName(const char *name)
|
||||
{
|
||||
(void)name;
|
||||
__set_errno(ENOSYS);
|
||||
return false;
|
||||
}
|
||||
|
|
@ -7,11 +7,9 @@
|
|||
// Desc: Kaleid assert() support //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#ifndef _KALASSRT_H
|
||||
#define _KALASSRT_H
|
||||
#ifndef _KALBASE_ASSERT_H
|
||||
#define _KALBASE_ASSERT_H
|
||||
|
||||
//------------------------------------------//
|
||||
// Macros //
|
||||
//------------------------------------------//
|
||||
|
||||
#ifndef noreturn
|
||||
|
@ -38,35 +36,39 @@ static_assert(sizeof(long) == 8, _SA_MSG);
|
|||
static_assert(sizeof(void *) == 8, _SA_MSG);
|
||||
#undef _SA_MSG
|
||||
|
||||
//------------------------------------------//
|
||||
// Assert core //
|
||||
//------------------------------------------//
|
||||
|
||||
// Failed assert handler
|
||||
noreturn void __assert_handler(const char *, const char *, int, const char *);
|
||||
|
||||
// Unconditional assert
|
||||
#define KalAlwaysAssert(x) \
|
||||
do { \
|
||||
if unlikely (!(x)) \
|
||||
__assert_handler(#x, __FILE__, __LINE__, __func__); \
|
||||
} while (0)
|
||||
|
||||
//------------------------------------------//
|
||||
// When debugging //
|
||||
//------------------------------------------//
|
||||
|
||||
#if !defined(_NO_DEBUG) && !defined(NDEBUG) && !defined(assert)
|
||||
|
||||
#ifdef _OSK_SOURCE
|
||||
#if !defined(_NO_DEBUG) && !defined(NDEBUG) && !defined(KalAssert)
|
||||
|
||||
//
|
||||
// Failed assert handler
|
||||
// Check whether (x) holds, if not call __assert_handler
|
||||
//
|
||||
noreturn void _assert_handler(const char *, const char *, int, const char *);
|
||||
#define KalAssert KalAlwaysAssert
|
||||
|
||||
//
|
||||
// Checks whether (x) holds, if not call _assert_handler
|
||||
//
|
||||
#define assert(x) \
|
||||
do { \
|
||||
if unlikely (!(x)) \
|
||||
_assert_handler(#x, __FILE__, __LINE__, __func__); \
|
||||
} while (0);
|
||||
#ifndef _OSK_SOURCE
|
||||
|
||||
#else
|
||||
|
||||
//
|
||||
// When not building for OS/K, use the system's assert
|
||||
//
|
||||
#include <assert.h>
|
||||
|
||||
#undef KalAlwaysAssert
|
||||
#define KalAlwaysAssert assert
|
||||
|
||||
#endif
|
||||
|
||||
//------------------------------------------//
|
||||
|
@ -83,26 +85,23 @@ noreturn void _assert_handler(const char *, const char *, int, const char *);
|
|||
#define _NO_DEBUG 1
|
||||
#endif
|
||||
|
||||
#ifndef assert
|
||||
#define assert(x) ((void)0)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
//------------------------------------------//
|
||||
// Aliases for assert() //
|
||||
//------------------------------------------//
|
||||
|
||||
#ifndef Assert
|
||||
#define Assert assert
|
||||
#endif
|
||||
|
||||
#ifndef KalAssert
|
||||
#define KalAssert assert
|
||||
#define KalAssert(x) ((void)0)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
//------------------------------------------//
|
||||
// End of header //
|
||||
// Aliases and extensions //
|
||||
//------------------------------------------//
|
||||
|
||||
#ifndef assert
|
||||
#define assert KalAssert
|
||||
#endif
|
||||
|
||||
#define KalAssertEx(x,m) KalAssert(x && m)
|
||||
#define KalAlwaysAssertEx(x,m) KalAlwaysAssert(x && m)
|
||||
|
||||
//------------------------------------------//
|
||||
|
||||
#endif
|
|
@ -7,11 +7,9 @@
|
|||
// Desc: Kaleid general preprocessor constants //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#ifndef _KALDEFS_H
|
||||
#define _KALDEFS_H
|
||||
#ifndef _KALBASE_BDEFS_H
|
||||
#define _KALDEFS_BDEFS_H
|
||||
|
||||
//------------------------------------------//
|
||||
// Actual constants //
|
||||
//------------------------------------------//
|
||||
|
||||
#ifndef TRUE
|
||||
|
@ -26,8 +24,10 @@
|
|||
#define NULL 0L
|
||||
#endif
|
||||
|
||||
//------------------------------------------//
|
||||
// Keywords //
|
||||
#ifndef INITOK
|
||||
#define INITOK ((unsigned int)0xCAFEBABE)
|
||||
#endif
|
||||
|
||||
//------------------------------------------//
|
||||
|
||||
#ifndef __alignof_is_defined
|
||||
|
@ -53,8 +53,6 @@
|
|||
# endif
|
||||
#endif
|
||||
|
||||
//------------------------------------------//
|
||||
// Attributes and macros //
|
||||
//------------------------------------------//
|
||||
|
||||
#ifndef _PACKED
|
||||
|
@ -81,16 +79,6 @@
|
|||
#define _XSTR(x) _STR(x)
|
||||
#endif
|
||||
|
||||
//------------------------------------------//
|
||||
// API specific macros //
|
||||
//------------------------------------------//
|
||||
|
||||
#ifndef KALAPI
|
||||
# define KALAPI
|
||||
#endif
|
||||
|
||||
//------------------------------------------//
|
||||
// End of header //
|
||||
//------------------------------------------//
|
||||
|
||||
#endif
|
|
@ -7,11 +7,9 @@
|
|||
// Desc: Kaleid C runtime library //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#ifndef _KALCRT_H
|
||||
#define _KALCRT_H
|
||||
#ifndef _KALBASE_CRTLIB_H
|
||||
#define _KALBASE_CRTLIB_H
|
||||
|
||||
//------------------------------------------//
|
||||
// Typedefs //
|
||||
//------------------------------------------//
|
||||
|
||||
#ifndef __error_t_defined
|
||||
|
@ -39,8 +37,6 @@ typedef struct { int quot, rem; } div_t;
|
|||
typedef struct { long quot, rem; } ldiv_t;
|
||||
#endif
|
||||
|
||||
//------------------------------------------//
|
||||
// Global variables //
|
||||
//------------------------------------------//
|
||||
|
||||
#ifndef _KALEID_KERNEL
|
||||
|
@ -62,16 +58,12 @@ extern error_t __errno;
|
|||
|
||||
#endif
|
||||
|
||||
//------------------------------------------//
|
||||
// Macros //
|
||||
//------------------------------------------//
|
||||
|
||||
#ifndef _NO_MASK
|
||||
#define _NO_MASK
|
||||
#endif
|
||||
|
||||
//------------------------------------------//
|
||||
// va_list utilities //
|
||||
//------------------------------------------//
|
||||
|
||||
#ifndef va_start
|
||||
|
@ -90,8 +82,6 @@ extern error_t __errno;
|
|||
#define va_end __builtin_va_end
|
||||
#endif
|
||||
|
||||
//------------------------------------------//
|
||||
// Memory management utilities //
|
||||
//------------------------------------------//
|
||||
|
||||
#ifndef memsetb
|
||||
|
@ -107,10 +97,12 @@ void *memsetw(void *, int, size_t);
|
|||
void *memsetd(void *, int, size_t);
|
||||
void *memsetq(void *, long, size_t);
|
||||
|
||||
/*
|
||||
void *memchr(const void *, int, size_t);
|
||||
void *memchrw(const void *, int, size_t);
|
||||
void *memchrd(const void *, int, size_t);
|
||||
void *memchrq(const void *, long, size_t);
|
||||
*/
|
||||
|
||||
void *memrchr(const void *, int, size_t);
|
||||
|
||||
|
@ -120,8 +112,6 @@ void *memmove(void *, const void *, size_t);
|
|||
void *memzero(void *, size_t);
|
||||
int memcmp(const void *, const void *, size_t);
|
||||
|
||||
//------------------------------------------//
|
||||
// String manipulation utilities //
|
||||
//------------------------------------------//
|
||||
|
||||
size_t strlen(const char *);
|
||||
|
@ -143,11 +133,11 @@ char *strtok_r(char *restrict, const char *restrict, char **restrict);
|
|||
|
||||
char *strcpy (char *restrict, const char *restrict);
|
||||
char *strncpy (char *restrict, const char *restrict, size_t);
|
||||
int strnzcpy(char *restrict, const char *restrict, size_t);
|
||||
size_t strnzcpy(char *restrict, const char *restrict, size_t);
|
||||
|
||||
char *strcat (char *restrict, const char *restrict);
|
||||
char *strncat (char *restrict, const char *restrict, size_t);
|
||||
int *strnzcat(char *restrict, const char *restrict, size_t);
|
||||
size_t strnzcat(char *restrict, const char *restrict, size_t);
|
||||
|
||||
char *strrev(char *restrict, const char *restrict);
|
||||
char *strrev2(char *);
|
||||
|
@ -157,8 +147,6 @@ int snprintf(char *, size_t, const char *, ...);
|
|||
int vsprintf(char *, const char *, va_list);
|
||||
int vsnprintf(char *, size_t, const char *, va_list);
|
||||
|
||||
//------------------------------------------//
|
||||
// Type conversion utilities //
|
||||
//------------------------------------------//
|
||||
|
||||
char *itoa(int, char *, int);
|
||||
|
@ -174,41 +162,31 @@ unsigned long atoul(const char *);
|
|||
long strtol (const char *restrict, char **restrict, int);
|
||||
unsigned long strtoul(const char *restrict, char **restrict, int);
|
||||
|
||||
//------------------------------------------//
|
||||
// RNG utilities //
|
||||
//------------------------------------------//
|
||||
|
||||
int rand(void);
|
||||
void srand(unsigned int);
|
||||
|
||||
//------------------------------------------//
|
||||
// Time utilities //
|
||||
//------------------------------------------//
|
||||
|
||||
//------------------------------------------//
|
||||
// Diverse utilities //
|
||||
//------------------------------------------//
|
||||
|
||||
char *strerror(int);
|
||||
char *strsignal(int);
|
||||
|
||||
//------------------------------------------//
|
||||
// Arithmetical macros //
|
||||
//------------------------------------------//
|
||||
|
||||
#ifndef __abs
|
||||
#define __abs
|
||||
static inline int abs(int x)
|
||||
static inline int abs(int __x)
|
||||
{
|
||||
return x < 0 ? -x : x;
|
||||
return __x < 0 ? -__x : __x;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef __labs
|
||||
#define __labs
|
||||
static inline long labs(long x)
|
||||
static inline long labs(long __x)
|
||||
{
|
||||
return x < 0 ? -x : x;
|
||||
return __x < 0 ? -__x : __x;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -234,8 +212,6 @@ static inline ldiv_t ldiv(long __x, long __y)
|
|||
}
|
||||
#endif
|
||||
|
||||
//------------------------------------------//
|
||||
// End of header //
|
||||
//------------------------------------------//
|
||||
|
||||
#endif
|
|
@ -7,11 +7,9 @@
|
|||
// Desc: Values for errno_t and errno //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#ifndef _KALERROR_H
|
||||
#define _KALERROR_H
|
||||
#ifndef _KALBASE_ERRNO_H
|
||||
#define _KALBASE_ERRNO_H
|
||||
|
||||
//------------------------------------------//
|
||||
// "errno" values //
|
||||
//------------------------------------------//
|
||||
|
||||
// Everything went fine
|
||||
|
@ -44,6 +42,12 @@
|
|||
// Bad file number
|
||||
#define EBADF 9
|
||||
|
||||
// Try again
|
||||
#define EAGAIN 11
|
||||
|
||||
// Out of memory
|
||||
#define ENOMEM 12
|
||||
|
||||
// Invalid argument
|
||||
#define EINVAL 22
|
||||
|
||||
|
@ -56,8 +60,6 @@
|
|||
// System is panicking
|
||||
#define EPANIC 600
|
||||
|
||||
//------------------------------------------//
|
||||
// End of header //
|
||||
//------------------------------------------//
|
||||
|
||||
#endif
|
|
@ -0,0 +1,78 @@
|
|||
//----------------------------------------------------------------------------//
|
||||
// GNU GPL OS/K //
|
||||
// //
|
||||
// Authors: spectral` //
|
||||
// NeoX //
|
||||
// //
|
||||
// Desc: Kaleid type limits definitions //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#ifndef _KALBASE_LIMITS_H
|
||||
#define _KALBASE_LIMITS_H
|
||||
|
||||
//------------------------------------------//
|
||||
|
||||
#define BYTE unsigned char
|
||||
#define WORD unsigned short
|
||||
#define DWORD unsigned int
|
||||
#define QWORD unsigned long
|
||||
|
||||
#define CHAR_BIT 8
|
||||
#define BITS_IN(T) (sizeof(T) * CHAR_BIT)
|
||||
|
||||
/* XXX find a generic way */
|
||||
#define BYTES_TO_WORDS(B) ((B) >> 1)
|
||||
#define BYTES_TO_DWORDS(B) ((B) >> 2)
|
||||
#define BYTES_TO_QWORDS(B) ((B) >> 3)
|
||||
#define WORDS_TO_BYTES(W) ((W) << 1)
|
||||
#define WORDS_TO_DWORDS(W) ((W) >> 1)
|
||||
#define WORDS_TO_QWORDS(W) ((W) >> 2)
|
||||
#define DWORDS_TO_BYTES(D) ((D) << 2)
|
||||
#define DWORDS_TO_WORDS(D) ((D) << 1)
|
||||
#define DWORDS_TO_QWORDS(D) ((D) >> 1)
|
||||
#define QWORDS_TO_BYTES(Q) ((Q) << 3)
|
||||
#define QWORDS_TO_WORDS(Q) ((Q) << 2)
|
||||
#define QWORDS_TO_DWORDS(Q) ((Q) << 1)
|
||||
|
||||
//------------------------------------------//
|
||||
|
||||
/* U/L suffixes on hex numbers look odd */
|
||||
#define SCHAR_MAX ((signed char) 0x7F)
|
||||
#define SHRT_MAX ((short) 0x7FFF)
|
||||
#define INT_MAX ((int) 0x7FFFFFFF)
|
||||
#define LONG_MAX ((long) 0x7FFFFFFFFFFFFFFFL)
|
||||
#define UCHAR_MAX ((unsigned char) 0xFFU)
|
||||
#define USHRT_MAX ((unsigned short) 0xFFFFU)
|
||||
#define UINT_MAX ((unsigned int) 0xFFFFFFFFU)
|
||||
#define ULONG_MAX ((unsigned long) 0xFFFFFFFFFFFFFFFFUL)
|
||||
|
||||
#define SCHAR_MIN ((signed char) -SCHAR_MAX - 1)
|
||||
#define SHRT_MIN ((short) -SHRT_MAX - 1)
|
||||
#define INT_MIN ((int) -INT_MAX - 1)
|
||||
#define LONG_MIN ((long) -LONG_MAX - 1L)
|
||||
|
||||
#ifdef __CHAR_UNSIGNED__
|
||||
# define CHAR_MIN ((char)0)
|
||||
# define CHAR_MAX ((char)UCHAR_MAX)
|
||||
#else
|
||||
# define CHAR_MIN ((char)SCHAR_MIN)
|
||||
# define CHAR_MAX ((char)SCHAR_MAX)
|
||||
#endif
|
||||
|
||||
#define SSIZE_T_MIN LONG_MIN
|
||||
#define SSIZE_T_MAX LONG_MAX
|
||||
#define SIZE_T_MAX ULONG_MAX
|
||||
|
||||
#ifdef NEED_MORE_USELESS_DATA
|
||||
# define UCHAR_MIN ((unsigned char)0)
|
||||
# define USHRT_MIN ((unsigned short)0)
|
||||
# define UINT_MIN ((unsigned int)0)
|
||||
# define ULONG_MIN ((unsigned long)0)
|
||||
# ifdef STILL_NEED_MORE_USELESS_DATA
|
||||
# error "Not enough useless data!"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
//------------------------------------------//
|
||||
|
||||
#endif
|
|
@ -7,8 +7,13 @@
|
|||
// Desc: Masks for the functions in the KCRL //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#ifndef _KALMASK_H
|
||||
#define _KALMASK_H
|
||||
#ifndef _KALBASE_MASKS_H
|
||||
#define _KALBASE_MASKS_H
|
||||
|
||||
//------------------------------------------//
|
||||
|
||||
#define div_t _osk_div_t
|
||||
#define ldiv_t _osk_ldiv_t
|
||||
|
||||
//------------------------------------------//
|
||||
|
||||
|
@ -33,26 +38,40 @@
|
|||
|
||||
//------------------------------------------//
|
||||
|
||||
#undef strspn
|
||||
#undef strcspn
|
||||
#define strlen _osk_strlen
|
||||
#define strspn _osk_strspn
|
||||
#define strcspn _osk_strcspn
|
||||
|
||||
#undef strcmp
|
||||
#undef strncmp
|
||||
#define strcmp _osk_strcmp
|
||||
#define strncmp _osk_strncmp
|
||||
|
||||
#undef strchr
|
||||
#undef strrchr
|
||||
#define strchr _osk_strchr
|
||||
#define strrchr _osk_strrchr
|
||||
|
||||
#undef strstr
|
||||
#undef strpbrk
|
||||
#define strstr _osk_strstr
|
||||
#define strpbrk _osk_strpbrk
|
||||
|
||||
#undef strtok
|
||||
#undef strtok_r
|
||||
#define strtok _osk_strtok
|
||||
#define strtok_r _osk_strtok_r
|
||||
|
||||
#undef strcpy
|
||||
#undef strncpy
|
||||
#define strcpy _osk_strcpy
|
||||
#define strncpy _osk_strncpy
|
||||
#define strnzcpy _osk_strnzcpy
|
||||
|
||||
#undef strcat
|
||||
#undef strncat
|
||||
#define strcat _osk_strcat
|
||||
#define strncat _osk_strncat
|
||||
#define strnzcat _osk_strnzcat
|
||||
|
@ -67,7 +86,6 @@
|
|||
|
||||
//------------------------------------------//
|
||||
|
||||
|
||||
#define itoa _osk_itoa
|
||||
#define ltoa _osk_ltoa
|
||||
#define utoa _osk_utoa
|
||||
|
@ -107,8 +125,6 @@
|
|||
|
||||
#define strerror _osk_strerror
|
||||
|
||||
//------------------------------------------//
|
||||
// End of header //
|
||||
//------------------------------------------//
|
||||
|
||||
#endif
|
|
@ -7,11 +7,9 @@
|
|||
// Desc: Kaleid C common types //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#ifndef _KALTYPES_H
|
||||
#define _KALTYPES_H
|
||||
#ifndef _KALBASE_TYPES_H
|
||||
#define _KALBASE_TYPES_H
|
||||
|
||||
//------------------------------------------//
|
||||
// Basic integer types aliases //
|
||||
//------------------------------------------//
|
||||
|
||||
#ifndef __base_types_aliases
|
||||
|
@ -26,8 +24,6 @@ typedef unsigned long long ullong;
|
|||
typedef long double ldouble;
|
||||
#endif
|
||||
|
||||
//------------------------------------------//
|
||||
// Miscellaneous types //
|
||||
//------------------------------------------//
|
||||
|
||||
#ifndef __size_t_defined
|
||||
|
@ -50,8 +46,6 @@ typedef signed int wchar_t;
|
|||
typedef unsigned long off_t;
|
||||
#endif
|
||||
|
||||
//------------------------------------------//
|
||||
// Standard fixed-width integer types //
|
||||
//------------------------------------------//
|
||||
|
||||
#ifndef __ptrdiff_t_defined
|
||||
|
@ -79,8 +73,6 @@ typedef signed long intmax_t;
|
|||
typedef unsigned long uintmax_t;
|
||||
#endif
|
||||
|
||||
//------------------------------------------//
|
||||
// Special types //
|
||||
//------------------------------------------//
|
||||
|
||||
#ifndef __va_list_defined
|
||||
|
@ -99,8 +91,6 @@ typedef struct { long quot, rem; } ldiv_t;
|
|||
#endif
|
||||
|
||||
|
||||
//------------------------------------------//
|
||||
// Kaleid-specific types //
|
||||
//------------------------------------------//
|
||||
|
||||
#ifndef __error_t_defined
|
||||
|
@ -113,8 +103,6 @@ typedef int error_t;
|
|||
typedef ushort port_t;
|
||||
#endif
|
||||
|
||||
//------------------------------------------//
|
||||
// End of header //
|
||||
//------------------------------------------//
|
||||
|
||||
#endif
|
|
@ -1,117 +0,0 @@
|
|||
//----------------------------------------------------------------------------//
|
||||
// GNU GPL OS/K //
|
||||
// //
|
||||
// Authors: spectral` //
|
||||
// NeoX //
|
||||
// //
|
||||
// Desc: Kaleid type limits definitions //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#ifndef _KALLIMS_H
|
||||
#define _KALLIMS_H
|
||||
|
||||
//------------------------------------------//
|
||||
// Data sizes blocks //
|
||||
//------------------------------------------//
|
||||
|
||||
#ifndef DATA_SIZE_BLOCK
|
||||
#define DATA_SIZE_BLOCK
|
||||
# define BYTE_SIZE sizeof(char)
|
||||
# define WORD_SIZE sizeof(short)
|
||||
# define DWORD_SIZE sizeof(int)
|
||||
# define QWORD_SIZE sizeof(long)
|
||||
#endif
|
||||
|
||||
#ifndef DATA_ALIGN_BLOCK
|
||||
#define DATA_ALIGN_BLOCK
|
||||
# define BYTE_ALIGN alignof(char)
|
||||
# define WORD_ALIGN alignof(short)
|
||||
# define DWORD_ALIGN alignof(int)
|
||||
# define QWORD_ALIGN alignof(long)
|
||||
#endif
|
||||
|
||||
#ifndef DATA_BITS_BLOCK
|
||||
#define DATA_BITS_BLOCK
|
||||
# define BYTE_BIT 8
|
||||
# define CHAR_BIT (BYTE_SIZE * BYTE_BIT)
|
||||
# define WORD_BIT (WORD_SIZE * BYTE_BIT)
|
||||
# define DWORD_BIT (DWORD_SIZE * BYTE_BIT)
|
||||
# define QWORD_BIT (QWORD_SIZE * BYTE_BIT)
|
||||
# define SHORT_BIT WORD_BIT
|
||||
# define INT_BIT DWORD_BIT
|
||||
# define LONG_BIT QWORD_BIT
|
||||
#endif
|
||||
|
||||
#ifndef DATA_SHIFTS_BLOCK
|
||||
#define DATA_SHIFTS_BLOCK
|
||||
# define BYTES_TO_WORDS(B) ((B) >> 1)
|
||||
# define BYTES_TO_DWORDS(B) ((B) >> 2)
|
||||
# define BYTES_TO_QWORDS(B) ((B) >> 3)
|
||||
# define WORDS_TO_BYTES(W) ((W) << 1)
|
||||
# define WORDS_TO_DWORDS(W) ((W) >> 1)
|
||||
# define WORDS_TO_QWORDS(W) ((W) >> 2)
|
||||
# define DWORDS_TO_BYTES(D) ((D) << 2)
|
||||
# define DWORDS_TO_WORDS(D) ((D) << 1)
|
||||
# define DWORDS_TO_QWORDS(D) ((D) >> 1)
|
||||
# define QWORDS_TO_BYTES(Q) ((Q) << 3)
|
||||
# define QWORDS_TO_WORDS(Q) ((Q) << 2)
|
||||
# define QWORDS_TO_DWORDS(Q) ((Q) << 1)
|
||||
#endif
|
||||
|
||||
//------------------------------------------//
|
||||
// Numeric data limits //
|
||||
//------------------------------------------//
|
||||
|
||||
#ifndef DATA_MAX_LIMITS_BLOCK
|
||||
#define DATA_MAX_LIMITS_BLOCK
|
||||
# define SCHAR_MAX ((signed char) 0x7F)
|
||||
# define SHRT_MAX ((short) 0x7FFF)
|
||||
# define INT_MAX ((int) 0x7FFFFFFF)
|
||||
# define LONG_MAX ((long) 0x7FFFFFFFFFFFFFFF)
|
||||
# define UCHAR_MAX ((unsigned char) 0xFF
|
||||
# define USHRT_MAX ((unsigned short) 0xFFFF)
|
||||
# define UINT_MAX ((unsigned int) 0xFFFFFFFF)
|
||||
# define ULONG_MAX ((unsigned long) 0xFFFFFFFFFFFFFFFF)
|
||||
#endif
|
||||
|
||||
#ifndef DATA_MIN_LIMITS_BLOCK
|
||||
#define DATA_MIN_LIMITS_BLOCK
|
||||
# define SCHAR_MIN ((signed char) -SCHAR_MAX - 1)
|
||||
# define SHRT_MIN ((short) -SHRT_MAX - 1)
|
||||
# define INT_MIN ((int) -INT_MAX - 1)
|
||||
# define LONG_MIN ((long) -LONG_MAX - 1L)
|
||||
#endif
|
||||
|
||||
#ifndef DATA_CHAR_LIMITS_BLOCK
|
||||
#define DATA_CHAR_LIMITS_BLOCK
|
||||
# ifdef __CHAR_UNSIGNED__
|
||||
# define CHAR_MIN ((char)0)
|
||||
# define CHAR_MAX ((char)UCHAR_MAX)
|
||||
# else
|
||||
# define CHAR_MIN ((char)SCHAR_MIN)
|
||||
# define CHAR_MAX ((char)SCHAR_MAX)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef DATA_SPTYPES_LIMITS_BLOCK
|
||||
#define DATA_SPTYPES_LIMITS_BLOCK
|
||||
# define SSIZE_T_MIN LONG_MIN
|
||||
# define SSIZE_T_MAX LONG_MAX
|
||||
# define SIZE_T_MAX ULONG_MAX
|
||||
#endif
|
||||
|
||||
#ifdef NEED_MORE_USELESS_DATA
|
||||
# define UCHAR_MIN ((unsigned char)0)
|
||||
# define USHRT_MIN ((unsigned short)0)
|
||||
# define UINT_MIN ((unsigned int)0)
|
||||
# define ULONG_MIN ((unsigned long)0)
|
||||
# ifdef STILL_NEED_MORE_USELESS_DATA
|
||||
# error "Not enough useless data!"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
//------------------------------------------//
|
||||
// End of header //
|
||||
//------------------------------------------//
|
||||
|
||||
#endif
|
|
@ -0,0 +1,282 @@
|
|||
//----------------------------------------------------------------------------//
|
||||
// GNU GPL OS/K //
|
||||
// //
|
||||
// Authors: spectral` //
|
||||
// NeoX //
|
||||
// //
|
||||
// Desc: Command line parsing utilities //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#ifndef _KALBASE_H
|
||||
#include <kalbase.h>
|
||||
#endif
|
||||
|
||||
#ifdef _KALEID_KERNEL
|
||||
#define FILE FILE
|
||||
typedef void* FILE;
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#ifndef _KALEXTRAS_ARGV_H
|
||||
#define _KALEXTRAS_ARGV_H
|
||||
|
||||
//------------------------------------------//
|
||||
|
||||
//
|
||||
// Maximal total size of argv, including the pointers,
|
||||
// the pointed-to strings and their null-terminators
|
||||
// This is a 32-bit integer
|
||||
//
|
||||
#define ARG_MAX (1 << 16) // 16 KB
|
||||
|
||||
//------------------------------------------//
|
||||
|
||||
//
|
||||
// Flags for options
|
||||
//
|
||||
typedef enum {
|
||||
|
||||
// The option parameter is optional
|
||||
KALOPT_OPTIONAL = (1 << 0),
|
||||
|
||||
// Do not show option in any help message
|
||||
KALOPT_HIDDEN = (1 << 1),
|
||||
|
||||
// This option is an alias for the previous one
|
||||
KALOPT_ALIAS = (1 << 2),
|
||||
|
||||
// This isn't an option but a docstring
|
||||
KALOPT_DOCSTR = (1 << 3),
|
||||
|
||||
// Only show in long help messages
|
||||
KALOPT_LONGDOC = (1 << 4),
|
||||
|
||||
} CmdOptionFlag_t;
|
||||
|
||||
//
|
||||
// Flags for KalParse(CmdLine|ArgV)
|
||||
//
|
||||
typedef enum {
|
||||
|
||||
// Don't exit on errors=
|
||||
KALOPT_NO_EXIT = (1 << 0),
|
||||
|
||||
// Don't react to --help
|
||||
KALOPT_NO_HELP = (1 << 1),
|
||||
|
||||
// Don't react to --version
|
||||
KALOPT_NO_VERSION = (1 << 2),
|
||||
|
||||
// Alias -h for --help and -V for --version
|
||||
KALOPT_ALIASES = (1 << 3),
|
||||
|
||||
// Don't print any error message
|
||||
// Implies KALOPT_NO_EXIT
|
||||
KALOPT_NO_ERRORS = (1 << 4) | KALOPT_NO_EXIT,
|
||||
|
||||
// Use KalGetProgName() instead of argv[0]
|
||||
// as program name
|
||||
KALOPT_USE_ARGV0 = (1 << 5),
|
||||
|
||||
// Call argument parser for non-options
|
||||
// Non-options arguments will be indicated by
|
||||
// a key of 0, the argument passed as a parameter
|
||||
KALOPT_PARSE_ALL = (1 << 6),
|
||||
|
||||
// Call argument parser with options and non-options in the
|
||||
// order they were found, instead of parsing options first
|
||||
KALOPT_IN_ORDER = (1 << 7) | KALOPT_PARSE_ALL,
|
||||
|
||||
// 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
|
||||
// These flags can be combined and are applied in order
|
||||
//
|
||||
// "Continue" and "Break" actions do not prevent
|
||||
// later actions from applying
|
||||
//
|
||||
typedef enum {
|
||||
|
||||
// Continue parsing new options
|
||||
KALOPT_CONTINUE = 0,
|
||||
|
||||
// Stop parsing further options
|
||||
KALOPT_BREAK = (1 << 0),
|
||||
|
||||
// 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 {
|
||||
|
||||
// The option's name, e.g. "help" for "--help"
|
||||
// May be 0, but only if letter is not zero
|
||||
const char *longName;
|
||||
|
||||
// The option's letter, e.g. 'h' for '-h'
|
||||
int letter;
|
||||
|
||||
// Address of the variable to put the parameter into
|
||||
const char *param;
|
||||
|
||||
// Option flags, see above
|
||||
CmdOptionFlag_t flags;
|
||||
|
||||
// The option's help text
|
||||
// If this is 0, this option is hidden
|
||||
const char *helpText;
|
||||
|
||||
// The option's group, for sorting during --help
|
||||
// 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
|
||||
//
|
||||
// Help messages are printed in this format:
|
||||
// (letting "this" be a CmdDocStrings_t* variable)
|
||||
//
|
||||
// Usage: (this->usage)
|
||||
// (this->header)
|
||||
//
|
||||
// (this->groups[0])
|
||||
// -o, --option-name option description
|
||||
// ...
|
||||
// ...
|
||||
//
|
||||
// (this->bottom)
|
||||
//
|
||||
// XXX progname/version
|
||||
//
|
||||
typedef struct {
|
||||
|
||||
const char *usage;
|
||||
const char *header;
|
||||
const char *bottom;
|
||||
|
||||
// Groups documentation
|
||||
// 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
|
||||
//
|
||||
typedef struct {
|
||||
|
||||
// Option we're currently parsing
|
||||
const CmdOption_t *option;
|
||||
|
||||
// Index (in argv) of the option we're parsing
|
||||
int argvIndex;
|
||||
|
||||
// Flags passed to KalParse(CmdLine|ArgV)
|
||||
CmdParserFlags_t flags;
|
||||
|
||||
// Has help/version messages been displayed already?
|
||||
bool shownHelp;
|
||||
bool shownVersion;
|
||||
|
||||
// Standard output streams
|
||||
FILE *outStream;
|
||||
FILE *errStream;
|
||||
|
||||
// Private, internal data; do not touch
|
||||
void *priv;
|
||||
|
||||
} CmdParserState_t;
|
||||
|
||||
//
|
||||
// The argument parser function
|
||||
//
|
||||
typedef CmdParserReturn_t (*CmdParser_t)(int key,
|
||||
const char *param,
|
||||
CmdParserState_t *state);
|
||||
|
||||
//------------------------------------------//
|
||||
|
||||
//
|
||||
// Misc. simple functions
|
||||
//
|
||||
int KalComputeArgCount(const char **argv);
|
||||
size_t KalComputeArgVecSize(const char **argv);
|
||||
|
||||
//
|
||||
// Command line to argument vector utility
|
||||
//
|
||||
error_t KalCmdLineToArgVecEx(const char *cmdLine,
|
||||
int *argcPtr,
|
||||
char **argv,
|
||||
bool doEscaping);
|
||||
|
||||
//
|
||||
// KalCmdLineToArgVecEx but doEscaping = false
|
||||
//
|
||||
error_t KalCmdLineToArgVec(const char *cmdLine,
|
||||
int *argcPtr,
|
||||
char **argv);
|
||||
/*
|
||||
|
||||
//
|
||||
// Argument vector to command line utility
|
||||
//
|
||||
error_t KalArgVecToCmdLineEx(char *cmdLine,
|
||||
size_t lengthMax,
|
||||
int argc,
|
||||
const char **argv,
|
||||
bool doUnEscaping);
|
||||
|
||||
//
|
||||
// KalArgVecToCmdLineEx but doUnEscapign = false
|
||||
//
|
||||
error_t KalArgVecToCmdLine(char *cmdLine,
|
||||
size_t lengthMax,
|
||||
int argc,
|
||||
const char **argv);
|
||||
//
|
||||
// Command line parser; only takes an argument vector
|
||||
// The argv argument *will* be modified and all parsed
|
||||
// options and arguments will be removed, except argv[0]
|
||||
// which is guanranteed to be left
|
||||
//
|
||||
error_t KalParseArgVecEx(int argc,
|
||||
char **argv,
|
||||
const CmdOption_t *options,
|
||||
const CmdDocStrings_t *docStrings,
|
||||
CmdParserFlags_t *flags,
|
||||
CmdParser_t *parser,
|
||||
FILE *outStream,
|
||||
FILE *errStream);
|
||||
//
|
||||
// KalParseArgVecEx(argc, argv, options, docString, stdin, stdout, parser, NULL)
|
||||
//
|
||||
error_t KalParseArgVec(int argc,
|
||||
char **argv,
|
||||
const CmdOption_t *options,
|
||||
const CmdDocStrings_t *docStrings,
|
||||
CmdParserFlags_t *flags,
|
||||
CmdParser_t *parser);
|
||||
|
||||
*/
|
||||
|
||||
//------------------------------------------//
|
||||
|
||||
#endif
|
|
@ -7,32 +7,21 @@
|
|||
// Desc: Doubly linked lists implementation //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#ifndef _KALLIST_H
|
||||
#define _KALLIST_H
|
||||
|
||||
#ifdef _KALEID_KERNEL
|
||||
#error "kallist.h - Not ready for kernel compilation"
|
||||
#error "extra/list.h - Not ready for kernel compilation"
|
||||
#endif
|
||||
|
||||
#ifndef _KALASSRT_H
|
||||
#include <common/kalassrt.h>
|
||||
#ifndef _KALBASE_H
|
||||
#include <kalbase.h>
|
||||
#endif
|
||||
|
||||
#ifndef _KALKERN_LOCKS_H
|
||||
#include <kernel/kernlocks.h>
|
||||
#ifndef _KALEXTRAS_MALLOC_H
|
||||
#include <extras/malloc.h>
|
||||
#endif
|
||||
|
||||
//
|
||||
// XXX ¯\_(ツ)_/¯
|
||||
//
|
||||
void *malloc(long);
|
||||
void free(void *);
|
||||
#ifndef _KALEXTRAS_LIST_H
|
||||
#define _KALEXTRAS_LIST_H
|
||||
|
||||
#define AllocMemory malloc
|
||||
#define FreeMemory free
|
||||
|
||||
//------------------------------------------//
|
||||
// Data structures //
|
||||
//------------------------------------------//
|
||||
|
||||
typedef struct sListHead_t {
|
||||
|
@ -49,8 +38,6 @@ typedef struct sListNode_t {
|
|||
struct sListNode_t *next;
|
||||
} ListNode_t;
|
||||
|
||||
//------------------------------------------//
|
||||
// Functions //
|
||||
//------------------------------------------//
|
||||
|
||||
//
|
||||
|
@ -72,7 +59,7 @@ static inline ListHead_t
|
|||
}
|
||||
|
||||
//
|
||||
// Create a liste head
|
||||
// Create a list head
|
||||
//
|
||||
static inline ListHead_t
|
||||
*CreateListHead(void)
|
||||
|
@ -263,8 +250,6 @@ DestroyListHead(ListHead_t *head)
|
|||
//
|
||||
#define GetNodeData(node, type) ((type)(node)->data)
|
||||
|
||||
//------------------------------------------//
|
||||
// End of header //
|
||||
//------------------------------------------//
|
||||
|
||||
#endif
|
|
@ -7,66 +7,45 @@
|
|||
// Desc: Spinlocks and mutexes //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
//------------------------------------------//
|
||||
// Dependencies //
|
||||
//------------------------------------------//
|
||||
#ifndef _KALBASE_H
|
||||
#include <kalbase.h>
|
||||
#endif
|
||||
|
||||
#ifdef _KALEID_KERNEL
|
||||
|
||||
#ifndef _KALKERN_BASE_H
|
||||
#include "kernbase.h"
|
||||
#include <kernel/base.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#else
|
||||
#ifndef _KALEXTRAS_LOCKS_H
|
||||
#define _KALEXTRAS_LOCKS_H
|
||||
|
||||
#ifndef _KALEID_H
|
||||
#include <kaleid.h>
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
//------------------------------------------//
|
||||
// Start of header //
|
||||
//------------------------------------------//
|
||||
|
||||
#ifndef _KALKERN_LOCKS_H
|
||||
#define _KALKERN_LOCKS_H
|
||||
|
||||
//------------------------------------------//
|
||||
// Types //
|
||||
//------------------------------------------//
|
||||
|
||||
typedef enum eLockType_t {
|
||||
//
|
||||
|
||||
// Mutex-type lock
|
||||
//
|
||||
// WARNING
|
||||
// AquireLock() panics when used on a mutex while not running a process
|
||||
//
|
||||
KLOCK_MUTEX,
|
||||
|
||||
//
|
||||
// Spinlock-type lock
|
||||
//
|
||||
KLOCK_SPINLOCK,
|
||||
|
||||
} LockType_t;
|
||||
|
||||
//
|
||||
// "volatile" may not be actually needed
|
||||
//
|
||||
typedef struct sLock_t {
|
||||
unsigned int initDone; // initialized?
|
||||
int locked; // is locked?
|
||||
LockType_t type; // lock type?
|
||||
volatile int locked; // is locked?
|
||||
#ifdef _KALEID_KERNEL
|
||||
Process_t *ownerProc; // unused
|
||||
Process_t *waitingProc; // unused
|
||||
Thread_t *ownerThread; // unused
|
||||
Thread_t *waitingThread; // unused
|
||||
#endif
|
||||
} volatile Lock_t;
|
||||
} Lock_t;
|
||||
|
||||
//------------------------------------------//
|
||||
// Functions //
|
||||
//------------------------------------------//
|
||||
|
||||
//
|
||||
|
@ -90,8 +69,8 @@ void InitLock(Lock_t *lock, LockType_t type)
|
|||
lock->locked = FALSE;
|
||||
lock->initDone = INITOK;
|
||||
#ifdef _KALEID_KERNEL
|
||||
lock->ownerProc = NULL;
|
||||
lock->waitingProc = NULL;
|
||||
lock->ownerThread = NULL;
|
||||
lock->waitingThread = NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -132,9 +111,9 @@ void AquireLock(Lock_t *lock)
|
|||
#else
|
||||
if likely (lock->type == KLOCK_SPINLOCK) continue;
|
||||
#ifdef _OSK_SOURCE
|
||||
else KalYieldCPU();
|
||||
else (void)KalYieldCPU();
|
||||
#else
|
||||
else sched_yield();
|
||||
else (void)sched_yield();
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
@ -149,7 +128,7 @@ static inline
|
|||
void ReleaseLock(Lock_t *lock)
|
||||
{
|
||||
#ifdef _KALEID_KERNEL
|
||||
KalAssert(lock->ownerProc == GetCurProc());
|
||||
KalAssert(lock->ownerThread == GetCurThread());
|
||||
#endif
|
||||
|
||||
__sync_synchronize();
|
||||
|
@ -171,8 +150,6 @@ bool AttemptLock(Lock_t *lock)
|
|||
return retval;
|
||||
}
|
||||
|
||||
//------------------------------------------//
|
||||
// End of header //
|
||||
//------------------------------------------//
|
||||
|
||||
#endif
|
|
@ -0,0 +1,33 @@
|
|||
//----------------------------------------------------------------------------//
|
||||
// GNU GPL OS/K //
|
||||
// //
|
||||
// Authors: spectral` //
|
||||
// NeoX //
|
||||
// //
|
||||
// Desc: Memory allocation utilities //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#ifndef _KALBASE_H
|
||||
#include <kalbase.h>
|
||||
#endif
|
||||
|
||||
#ifndef _KALEXTRAS_MALLOC_H
|
||||
#define _KALEXTRAS_MALLOC_H
|
||||
|
||||
//------------------------------------------//
|
||||
|
||||
//
|
||||
// ¯\_(ツ)_/¯
|
||||
//
|
||||
#ifndef _STDLIB_H
|
||||
void *malloc(unsigned long);
|
||||
void free(void *);
|
||||
#endif
|
||||
|
||||
#define AllocMemory malloc
|
||||
#define FreeMemory free
|
||||
|
||||
//------------------------------------------//
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
//----------------------------------------------------------------------------//
|
||||
// GNU GPL OS/K //
|
||||
// //
|
||||
// Authors: spectral` //
|
||||
// NeoX //
|
||||
// //
|
||||
// Desc: Program utilities //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#ifndef _KALBASE_H
|
||||
#include <kalbase.h>
|
||||
#endif
|
||||
|
||||
#ifndef _KALEXTRAS_PROG_H
|
||||
#define _KALEXTRAS_PROG_H
|
||||
|
||||
//------------------------------------------//
|
||||
|
||||
extern const char *__progname;
|
||||
extern const char *__progvers;
|
||||
|
||||
//------------------------------------------//
|
||||
|
||||
const char *KalGetProgName(void);
|
||||
const char *KalGetProgVersion(void);
|
||||
|
||||
bool KalSetProgVers(const char *);
|
||||
bool KalSetProgName(const char *);
|
||||
|
||||
//------------------------------------------//
|
||||
|
||||
#endif
|
|
@ -0,0 +1,59 @@
|
|||
//----------------------------------------------------------------------------//
|
||||
// GNU GPL OS/K //
|
||||
// //
|
||||
// Authors: spectral` //
|
||||
// NeoX //
|
||||
// //
|
||||
// Desc: Kaleid API base minimal include file //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#ifndef _KALBASE_H
|
||||
#define _KALBASE_H
|
||||
|
||||
//------------------------------------------//
|
||||
// Building for OS/K //
|
||||
//------------------------------------------//
|
||||
|
||||
#ifndef _OSK_SOURCE
|
||||
#if defined(_KALEID_KERNEL) || defined(_KALEID_SYSTEM)
|
||||
#define _OSK_SOURCE 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if !defined(_OSK_SOURCE) && !defined(_KALEID_UNMASKED)
|
||||
#ifndef _KALBASE_MASKS_H
|
||||
#include <base/masks.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//------------------------------------------//
|
||||
// Include common part of API //
|
||||
//------------------------------------------//
|
||||
|
||||
#ifndef _KALBASE_BDEFS_H
|
||||
#include <base/bdefs.h>
|
||||
#endif
|
||||
|
||||
#ifndef _KALBASE_ERRNO_H
|
||||
#include <base/errno.h>
|
||||
#endif
|
||||
|
||||
#ifndef _KALBASE_TYPES_H
|
||||
#include <base/types.h>
|
||||
#endif
|
||||
|
||||
#ifndef _KALBASE_LIMITS_H
|
||||
#include <base/limits.h>
|
||||
#endif
|
||||
|
||||
#ifndef _KALBASE_ASSERT_H
|
||||
#include <base/assert.h>
|
||||
#endif
|
||||
|
||||
#ifndef _KALBASE_CRTLIB_H
|
||||
#include <base/crtlib.h>
|
||||
#endif
|
||||
|
||||
//------------------------------------------//
|
||||
|
||||
#endif
|
|
@ -11,85 +11,23 @@
|
|||
#define _KALEID_H
|
||||
|
||||
//------------------------------------------//
|
||||
// Building for OS/K //
|
||||
// Include all Kaleid headers //
|
||||
//------------------------------------------//
|
||||
|
||||
#if !defined(_OSK_SOURCE)
|
||||
# if defined(_KALEID_KERNEL) || defined(_KALEID_SYSTEM)
|
||||
# define _OSK_SOURCE 1
|
||||
# endif
|
||||
#ifndef _KALBASE_H
|
||||
#include <kalbase.h>
|
||||
#endif
|
||||
|
||||
#if !defined(_OSK_SOURCE)
|
||||
# ifndef _KALMASK_H
|
||||
# include <common/kalmask.h>
|
||||
#ifndef _KALEXT_H
|
||||
#include <kalext.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//------------------------------------------//
|
||||
// Building in C++ //
|
||||
//------------------------------------------//
|
||||
|
||||
#ifdef __cplusplus__
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//------------------------------------------//
|
||||
// Include common part of API //
|
||||
//------------------------------------------//
|
||||
|
||||
#ifndef _KALDEFS_H
|
||||
#include <common/kaldefs.h>
|
||||
#endif
|
||||
|
||||
#ifndef _KALERROR_H
|
||||
#include <common/kalerror.h>
|
||||
#endif
|
||||
|
||||
#ifndef _KALTYPES_H
|
||||
#include <common/kaltypes.h>
|
||||
#endif
|
||||
|
||||
#ifndef _KALLIMS_H
|
||||
#include <common/kallims.h>
|
||||
#endif
|
||||
|
||||
#ifndef _KALASSRT_H
|
||||
#include <common/kalassrt.h>
|
||||
#endif
|
||||
|
||||
#ifndef _KALCRT_H
|
||||
#include <common/kalcrt.h>
|
||||
#endif
|
||||
|
||||
//------------------------------------------//
|
||||
// Include kernel headers //
|
||||
//------------------------------------------//
|
||||
|
||||
#ifdef _KALEID_KERNEL
|
||||
|
||||
#ifndef _KALKERN_H
|
||||
#include <kalkern.h>
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
#ifndef _KALKERN_LOCKS_H
|
||||
#include <kernel/kernlocks.h>
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
//------------------------------------------//
|
||||
// Building in C++ //
|
||||
//------------------------------------------//
|
||||
|
||||
#ifdef __cplusplus__
|
||||
}
|
||||
#endif
|
||||
|
||||
//------------------------------------------//
|
||||
// End of header //
|
||||
//------------------------------------------//
|
||||
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
//----------------------------------------------------------------------------//
|
||||
// GNU GPL OS/K //
|
||||
// //
|
||||
// Authors: spectral` //
|
||||
// NeoX //
|
||||
// //
|
||||
// Desc: Kaleid extras main include file //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#ifndef _KALBASE_H
|
||||
#include <kalbase.h>
|
||||
#endif
|
||||
|
||||
//------------------------------------------//
|
||||
|
||||
#ifndef _KALEXT_H
|
||||
#define _KALEXT_H
|
||||
|
||||
//------------------------------------------//
|
||||
// Extra headers //
|
||||
//------------------------------------------//
|
||||
|
||||
#ifndef _KALEXTRAS_LOCKS_H
|
||||
#include <extras/locks.h>
|
||||
#endif
|
||||
|
||||
#ifndef _KALEXTRAS_PROG_H
|
||||
#include <extras/prog.h>
|
||||
#endif
|
||||
|
||||
#ifndef _KALEXTRAS_ARGV_H
|
||||
#include <extras/argv.h>
|
||||
#endif
|
||||
|
||||
#ifndef _KALEID_KERNEL
|
||||
#ifndef _KALEXTRAS_LIST_H
|
||||
#include <extras/list.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//------------------------------------------//
|
||||
|
||||
#endif
|
||||
|
|
@ -7,16 +7,14 @@
|
|||
// Desc: Kaleid Kernel main include file //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
//------------------------------------------//
|
||||
// Dependencies //
|
||||
//------------------------------------------//
|
||||
|
||||
#ifndef _KALEID_H
|
||||
#include <kaleid.h>
|
||||
#ifndef _KALBASE_H
|
||||
#include <kalbase.h>
|
||||
#endif
|
||||
|
||||
#ifndef _KALEXT_H
|
||||
#include <kalext.h>
|
||||
#endif
|
||||
|
||||
//------------------------------------------//
|
||||
// Start of header //
|
||||
//------------------------------------------//
|
||||
|
||||
#ifndef _KALKERN_H
|
||||
|
@ -27,19 +25,20 @@
|
|||
//------------------------------------------//
|
||||
|
||||
#ifndef _KALKERN_BASE_H
|
||||
#include <kernel/kernbase.h>
|
||||
#include <kernel/base.h>
|
||||
#endif
|
||||
|
||||
#ifndef _KALKERN_LOCKS_H
|
||||
#include <kernel/kernlocks.h>
|
||||
#ifndef _KALKERN_TERMINAL_H
|
||||
#include <kernel/terminal.h>
|
||||
#endif
|
||||
|
||||
#ifndef _KALKERN_TERM_H
|
||||
#include <kernel/kernterm.h>
|
||||
// not ready for kernel compilation
|
||||
#ifndef _KALEID_KERNEL
|
||||
#ifndef _KALKERN_SCHED_H
|
||||
#include <kernel/sched.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//------------------------------------------//
|
||||
// End of header //
|
||||
//------------------------------------------//
|
||||
|
||||
#endif
|
||||
|
|
|
@ -7,26 +7,18 @@
|
|||
// Desc: Kaleid Kernel base types and functionalities //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
//------------------------------------------//
|
||||
// Dependencies //
|
||||
//------------------------------------------//
|
||||
|
||||
#ifndef _KALEID_H
|
||||
#include <kaleid.h>
|
||||
#ifndef _KALBASE_H
|
||||
#include <kalbase.h>
|
||||
#endif
|
||||
|
||||
//------------------------------------------//
|
||||
// Start of header //
|
||||
//------------------------------------------//
|
||||
|
||||
#ifndef _KALKERN_BASE_H
|
||||
#define _KALKERN_BASE_H
|
||||
|
||||
//------------------------------------------//
|
||||
// Elementary types //
|
||||
//------------------------------------------//
|
||||
|
||||
typedef struct sLock_t volatile Lock_t;
|
||||
typedef struct sLock_t Lock_t;
|
||||
typedef struct sThread_t Thread_t;
|
||||
typedef struct sProcess_t Process_t;
|
||||
typedef struct sTerminal_t Terminal_t;
|
||||
|
@ -34,23 +26,23 @@ typedef struct sListHead_t ListHead_t;
|
|||
typedef struct sListNode_t ListNode_t;
|
||||
|
||||
//------------------------------------------//
|
||||
// Values for __kstate //
|
||||
//------------------------------------------//
|
||||
|
||||
/* XXX */
|
||||
|
||||
//
|
||||
// Current state of the kernel
|
||||
//
|
||||
typedef enum {
|
||||
// the kernel is booting
|
||||
// The kernel is booting
|
||||
KSTATE_INIT,
|
||||
|
||||
// the kernel is not running a process
|
||||
// The kernel is not running a process
|
||||
KSTATE_KERNEL,
|
||||
|
||||
// a process is running in kernel mode
|
||||
// A process is running in kernel mode
|
||||
KSTATE_PROCESS,
|
||||
|
||||
// the kernel is panicking
|
||||
// The kernel is panicking
|
||||
KSTATE_PANIC,
|
||||
|
||||
} KernelState_t;
|
||||
|
@ -59,13 +51,12 @@ typedef enum {
|
|||
// Multiprocessor misc. //
|
||||
//------------------------------------------//
|
||||
|
||||
|
||||
#ifndef INITOK
|
||||
#define INITOK ((unsigned int)0xCAFEBABE)
|
||||
#endif
|
||||
|
||||
#ifndef NCPU
|
||||
#define NCPU 4
|
||||
#ifndef NCPUS
|
||||
#define NCPUS 4
|
||||
#endif
|
||||
|
||||
#define GetCurCPU() 0
|
||||
|
@ -74,7 +65,7 @@ typedef enum {
|
|||
// Declare an (extern) CPU-local variable
|
||||
//
|
||||
#define __DECLARE_PER_CPU(_X, _Tp, _Qual) \
|
||||
_Qual _Tp __ ## _X [NCPU]; \
|
||||
_Qual _Tp __ ## _X [NCPUS]; \
|
||||
static inline _Tp Get ## _X (void) \
|
||||
{ return __ ## _X [GetCurCPU()]; } \
|
||||
static inline void _Set ## _X (_Tp _Y) \
|
||||
|
@ -90,11 +81,9 @@ typedef enum {
|
|||
// Actually creates a CPU-local variable
|
||||
//
|
||||
#define CREATE_PER_CPU(_X, _Tp) \
|
||||
_Tp __ ## _X [NCPU] = { (_Tp) 0 }
|
||||
_Tp __ ## _X [NCPUS] = { (_Tp) 0 }
|
||||
|
||||
|
||||
//------------------------------------------//
|
||||
// Global constants //
|
||||
//------------------------------------------//
|
||||
|
||||
// XXX
|
||||
|
@ -108,34 +97,38 @@ DECLARE_PER_CPU(_StdDbg, Terminal_t *);
|
|||
DECLARE_PER_CPU(CurProc, Process_t *);
|
||||
DECLARE_PER_CPU(CurThread, Thread_t *);
|
||||
|
||||
//------------------------------------------//
|
||||
// Macros for manipulating said //
|
||||
// global constants //
|
||||
//------------------------------------------//
|
||||
|
||||
#define SetKernState(x) \
|
||||
do { \
|
||||
_SetKernState(x); \
|
||||
} while (0)
|
||||
|
||||
#define GetStdOut() (GetCurProc() == NULL ? Get_StdOut() : NULL)
|
||||
#define SetStdOut(tm) \
|
||||
do { \
|
||||
if (GetCurProc() == NULL) \
|
||||
_Set_StdOut(tm); \
|
||||
} while (0);
|
||||
|
||||
#define GetStdDbg() (GetCurProc() == NULL ? Get_StdDbg() : NULL)
|
||||
#define SetStdDbg(tm) \
|
||||
do { \
|
||||
if (GetCurProc() == NULL) \
|
||||
_Set_StdDbg(tm); \
|
||||
} while (0)
|
||||
DECLARE_PER_CPU(ReSchedFlag, bool);
|
||||
DECLARE_PER_CPU(PreemptCount, ulong);
|
||||
|
||||
//------------------------------------------//
|
||||
// Other Macros //
|
||||
|
||||
#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
|
||||
|
@ -164,7 +157,44 @@ DECLARE_PER_CPU(CurThread, Thread_t *);
|
|||
#define HaltCPU() do { asm volatile ("hlt"); } while (1)
|
||||
|
||||
//------------------------------------------//
|
||||
// Some base functions //
|
||||
|
||||
//
|
||||
// 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 *);
|
||||
|
@ -174,10 +204,13 @@ noreturn void CrashSystem(void);
|
|||
// Useful I/O inlines //
|
||||
//------------------------------------------//
|
||||
|
||||
|
||||
static inline
|
||||
void WriteByteOnPort(port_t port, port_t val)
|
||||
{
|
||||
asm volatile ("out %0, %1" : : "dN" (port), "a" (val));
|
||||
KalAssert(FALSE && ENOSYS);
|
||||
(void)port;
|
||||
(void)val;
|
||||
}
|
||||
|
||||
static inline
|
||||
|
@ -196,9 +229,6 @@ ushort ReadWordFromPort(port_t port)
|
|||
return 0;
|
||||
}
|
||||
|
||||
//------------------------------------------//
|
||||
// End of header //
|
||||
//------------------------------------------//
|
||||
|
||||
#endif
|
||||
|
|
@ -7,49 +7,29 @@
|
|||
// Desc: Scheduler header //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
//------------------------------------------//
|
||||
// Dependencies //
|
||||
//------------------------------------------//
|
||||
|
||||
#ifndef _KALKERN_BASE_H
|
||||
#include "kernbase.h"
|
||||
#include <kernel/base.h>
|
||||
#endif
|
||||
|
||||
#ifndef _KALLIST_H
|
||||
#include <common/kallist.h>
|
||||
#endif
|
||||
|
||||
//------------------------------------------//
|
||||
// Start of header //
|
||||
//------------------------------------------//
|
||||
|
||||
#ifndef _KALKERN_SCHED_H
|
||||
#define _KALKERN_SCHED_H
|
||||
|
||||
//------------------------------------------//
|
||||
// Preprocessor //
|
||||
//------------------------------------------//
|
||||
|
||||
//
|
||||
// Debug stuff
|
||||
//
|
||||
#define printdbg printf
|
||||
|
||||
//
|
||||
// States for a process
|
||||
//
|
||||
#define STATE_RUNNING 0
|
||||
#define STATE_RUNNABLE 1
|
||||
#define STATE_BLOCKED 2
|
||||
|
||||
//
|
||||
// Time in ticks a process should be run
|
||||
//
|
||||
#define DEF_PROC_TSLICE 5 // 20 ticks
|
||||
#define TCR_PROC_TSLICE 20000 // 20000 ticks (time critical)
|
||||
|
||||
//------------------------------------------//
|
||||
// List heads //
|
||||
//------------------------------------------//
|
||||
|
||||
DECLARE_PER_CPU(IdlePrioProcs, ListHead_t *);
|
||||
|
@ -59,46 +39,6 @@ DECLARE_PER_CPU(TimeCritProcs, ListHead_t *);
|
|||
|
||||
extern const char *PrioClassesNames[];
|
||||
|
||||
//------------------------------------------//
|
||||
// Data types //
|
||||
//------------------------------------------//
|
||||
|
||||
//
|
||||
// A process
|
||||
//
|
||||
typedef struct sProcess_t {
|
||||
|
||||
// Identifier
|
||||
int pid;
|
||||
|
||||
// Current priority class
|
||||
int prioClass;
|
||||
|
||||
// Default priority class (without boosts)
|
||||
int defPrioClass;
|
||||
|
||||
// Current priority level
|
||||
int prioLevel;
|
||||
|
||||
// Default priority level
|
||||
int defPrioLevel;
|
||||
|
||||
// Current state
|
||||
int procState;
|
||||
|
||||
// Remaining time running
|
||||
ulong timeSlice;
|
||||
|
||||
// Default time-slice
|
||||
ulong defTimeSlice;
|
||||
|
||||
// Scheduler internals
|
||||
ListNode_t *schedNode;
|
||||
|
||||
} Process_t;
|
||||
|
||||
//------------------------------------------//
|
||||
// Functions //
|
||||
//------------------------------------------//
|
||||
|
||||
void SchedInit(void);
|
||||
|
@ -107,8 +47,6 @@ void SchedFini(void);
|
|||
void SchedThisProc(Process_t *);
|
||||
void SchedOnTick(void);
|
||||
|
||||
//------------------------------------------//
|
||||
// End of header //
|
||||
//------------------------------------------//
|
||||
|
||||
#endif
|
|
@ -7,23 +7,15 @@
|
|||
// Desc: Terminal functions //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
//------------------------------------------//
|
||||
// Dependencies //
|
||||
//------------------------------------------//
|
||||
|
||||
#ifndef _KALKERN_BASE_H
|
||||
#include "kernbase.h"
|
||||
#include <kernel/base.h>
|
||||
#endif
|
||||
|
||||
//------------------------------------------//
|
||||
// Start of header //
|
||||
//------------------------------------------//
|
||||
|
||||
#ifndef _KALKERN_TERM_H
|
||||
#define _KALKERN_TERM_H
|
||||
#ifndef _KALKERN_TERMINAL_H
|
||||
#define _KALKERN_TERMINAL_H
|
||||
|
||||
//------------------------------------------//
|
||||
// Types //
|
||||
//------------------------------------------//
|
||||
|
||||
//
|
||||
|
@ -68,8 +60,6 @@ typedef struct sTerminal_t {
|
|||
|
||||
} Terminal_t;
|
||||
|
||||
//------------------------------------------//
|
||||
// Functions //
|
||||
//------------------------------------------//
|
||||
|
||||
void InitTerms(void);
|
||||
|
@ -78,8 +68,6 @@ error_t PutOnTerm(Terminal_t *, char);
|
|||
error_t PrintOnTerm(Terminal_t *, const char *);
|
||||
error_t ChTermColor(Terminal_t *, TermColor_t, TermColor_t);
|
||||
|
||||
//------------------------------------------//
|
||||
// Macros //
|
||||
//------------------------------------------//
|
||||
|
||||
#ifndef _NO_DEBUG
|
||||
|
@ -88,8 +76,6 @@ error_t ChTermColor(Terminal_t *, TermColor_t, TermColor_t);
|
|||
# define DebugLog(...)
|
||||
#endif
|
||||
|
||||
//------------------------------------------//
|
||||
// End of header //
|
||||
//------------------------------------------//
|
||||
|
||||
#endif
|
|
@ -19,3 +19,5 @@ CREATE_PER_CPU(_StdDbg, Terminal_t *);
|
|||
CREATE_PER_CPU(CurProc, Process_t *);
|
||||
CREATE_PER_CPU(CurThread, Thread_t *);
|
||||
|
||||
CREATE_PER_CPU(ReSchedFlag, bool);
|
||||
|
||||
|
|
|
@ -0,0 +1,105 @@
|
|||
//----------------------------------------------------------------------------//
|
||||
// GNU GPL OS/K //
|
||||
// //
|
||||
// Authors: spectral` //
|
||||
// NeoX //
|
||||
// //
|
||||
// Desc: Early terminal functions //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#include <kaleid.h>
|
||||
|
||||
extern void VGA_Init(void);
|
||||
extern Terminal_t VGA_Terminal;
|
||||
|
||||
//
|
||||
// Initialize standard output
|
||||
//
|
||||
void InitTerms(void)
|
||||
{
|
||||
KalAssert(!GetStdOut() && !GetStdDbg());
|
||||
|
||||
VGA_Init();
|
||||
|
||||
// vgaTerm.initDone = INITOK;
|
||||
|
||||
SetStdDbg(&VGA_Terminal);
|
||||
SetStdOut(&VGA_Terminal);
|
||||
|
||||
ClearTerm(GetStdOut());
|
||||
}
|
||||
|
||||
//
|
||||
// Fill terminal with spaces
|
||||
//
|
||||
error_t ClearTerm(Terminal_t *term)
|
||||
{
|
||||
error_t retcode;
|
||||
|
||||
if (term == NULL) return EINVAL;
|
||||
KalAssert(term->initDone == INITOK);
|
||||
|
||||
AquireLock(&term->lock);
|
||||
retcode = term->ClearTermUnlocked(term);
|
||||
ReleaseLock(&term->lock);
|
||||
|
||||
return retcode;
|
||||
}
|
||||
|
||||
//
|
||||
// Change the color code
|
||||
//
|
||||
error_t ChTermColor(Terminal_t *term, TermColor_t fgColor, TermColor_t bgColor)
|
||||
{
|
||||
if (fgColor > KTERM_COLOR_WHITE || bgColor > KTERM_COLOR_WHITE)
|
||||
return EINVAL;
|
||||
|
||||
if (term == NULL)
|
||||
return EINVAL;
|
||||
|
||||
AquireLock(&term->lock);
|
||||
|
||||
term->fgColor = fgColor;
|
||||
term->bgColor = bgColor;
|
||||
|
||||
ReleaseLock(&term->lock);
|
||||
|
||||
return EOK;
|
||||
}
|
||||
|
||||
//
|
||||
// Write a single character on the terminal
|
||||
//
|
||||
error_t PutOnTerm(Terminal_t *term, char ch)
|
||||
{
|
||||
error_t retcode;
|
||||
|
||||
if (term == NULL) return EINVAL;
|
||||
KalAssert(term->initDone == INITOK);
|
||||
|
||||
AquireLock(&term->lock);
|
||||
retcode = term->PutOnTermUnlocked(term, ch);
|
||||
ReleaseLock(&term->lock);
|
||||
|
||||
return retcode;
|
||||
}
|
||||
|
||||
//
|
||||
// Print string on terminal
|
||||
//
|
||||
error_t PrintOnTerm(Terminal_t *term, const char *str)
|
||||
{
|
||||
error_t retcode = EOK;
|
||||
|
||||
if (term == NULL) return EINVAL;
|
||||
KalAssert(term->initDone == INITOK);
|
||||
|
||||
AquireLock(&term->lock);
|
||||
while (*str && retcode == EOK) {
|
||||
retcode = term->PutOnTermUnlocked(term, *str++);
|
||||
}
|
||||
ReleaseLock(&term->lock);
|
||||
|
||||
return retcode;
|
||||
}
|
||||
|
|
@ -4,102 +4,11 @@
|
|||
// Authors: spectral` //
|
||||
// NeoX //
|
||||
// //
|
||||
// Desc: Early terminal functions //
|
||||
// Desc: VGA terminal functions //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#include <kaleid.h>
|
||||
|
||||
static Terminal_t vgaTerm;
|
||||
|
||||
//
|
||||
// Initialize standard output
|
||||
//
|
||||
void InitTerms(void)
|
||||
{
|
||||
KalAssert(!GetStdOut() && vgaTerm.initDone != INITOK);
|
||||
|
||||
vgaTerm.initDone = INITOK;
|
||||
|
||||
SetStdDbg(&vgaTerm);
|
||||
SetStdOut(&vgaTerm);
|
||||
|
||||
ClearTerm(GetStdOut());
|
||||
}
|
||||
|
||||
//
|
||||
// Fill terminal with spaces
|
||||
//
|
||||
error_t ClearTerm(Terminal_t *term)
|
||||
{
|
||||
error_t retcode;
|
||||
|
||||
if (term == NULL) return EINVAL;
|
||||
KalAssert(term->initDone == INITOK);
|
||||
|
||||
AquireLock(&term->lock);
|
||||
retcode = term->ClearTermUnlocked(term);
|
||||
ReleaseLock(&term->lock);
|
||||
|
||||
return retcode;
|
||||
}
|
||||
|
||||
//
|
||||
// Change the color code
|
||||
//
|
||||
error_t ChTermColor(Terminal_t *term, TermColor_t fgColor, TermColor_t bgColor)
|
||||
{
|
||||
if (fgColor > KTERM_COLOR_WHITE || bgColor > KTERM_COLOR_WHITE)
|
||||
return EINVAL;
|
||||
|
||||
if (term == NULL)
|
||||
return EINVAL;
|
||||
|
||||
AquireLock(&term->lock);
|
||||
|
||||
term->fgColor = fgColor;
|
||||
term->bgColor = bgColor;
|
||||
|
||||
ReleaseLock(&term->lock);
|
||||
|
||||
return EOK;
|
||||
}
|
||||
|
||||
//
|
||||
// Write a single character on the terminal
|
||||
//
|
||||
error_t PutOnTerm(Terminal_t *term, char ch)
|
||||
{
|
||||
error_t retcode;
|
||||
|
||||
if (term == NULL) return EINVAL;
|
||||
KalAssert(term->initDone == INITOK);
|
||||
|
||||
AquireLock(&term->lock);
|
||||
retcode = term->PutOnTermUnlocked(term, ch);
|
||||
ReleaseLock(&term->lock);
|
||||
|
||||
return retcode;
|
||||
}
|
||||
|
||||
//
|
||||
// Print string on terminal
|
||||
//
|
||||
error_t PrintOnTerm(Terminal_t *term, const char *str)
|
||||
{
|
||||
error_t retcode = EOK;
|
||||
|
||||
if (term == NULL) return EINVAL;
|
||||
KalAssert(term->initDone == INITOK);
|
||||
|
||||
AquireLock(&term->lock);
|
||||
while (*str && retcode == EOK) {
|
||||
retcode = term->PutOnTermUnlocked(term, *str++);
|
||||
}
|
||||
ReleaseLock(&term->lock);
|
||||
|
||||
return retcode;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------//
|
||||
// Internal functions for VGA terminals //
|
||||
// These DO NOT check input correctness //
|
||||
|
@ -143,23 +52,17 @@ error_t VGA_PutOnTermUnlocked(Terminal_t *term, char ch)
|
|||
return EOK;
|
||||
}
|
||||
|
||||
//
|
||||
// Line feed first takes us to the very end of the line
|
||||
// Later in this function we actually do the line feed
|
||||
//
|
||||
else if (ch == '\n') {
|
||||
term->currentY = term->width - 1;
|
||||
}
|
||||
|
||||
//
|
||||
// Tabulations account for "term->tabSize" spaces
|
||||
//
|
||||
else if (ch == '\t') {
|
||||
prevY = term->currentY;
|
||||
for (i = 0; i < term->tabSize; i++) {
|
||||
//
|
||||
// Make sure tabulations can't spread over two lines
|
||||
//
|
||||
if (term->currentY == prevY) {
|
||||
VGA_PutOnTermUnlocked(term, ' ');
|
||||
}
|
||||
|
@ -172,26 +75,18 @@ error_t VGA_PutOnTermUnlocked(Terminal_t *term, char ch)
|
|||
buffer[offset] = VGA_ComputeEntry(ch, VGA_ComputeColorCode(term->fgColor, term->bgColor));
|
||||
}
|
||||
|
||||
//
|
||||
// Did we reach the end of line?
|
||||
//
|
||||
if (++term->currentX == term->width) {
|
||||
term->currentX = 0;
|
||||
|
||||
//
|
||||
// Did we reach the buffer's end?
|
||||
//
|
||||
if (++term->currentY == term->height) {
|
||||
//
|
||||
// XXX scroll up
|
||||
//
|
||||
term->currentY = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Nothing can go wrong
|
||||
//
|
||||
return EOK;
|
||||
}
|
||||
|
||||
|
@ -211,8 +106,9 @@ error_t VGA_PrintOnTermUnlocked(Terminal_t *term, const char *str)
|
|||
|
||||
//
|
||||
// VGA output
|
||||
// XXX custom sizes
|
||||
//
|
||||
static Terminal_t vgaTerm = {
|
||||
Terminal_t VGA_Terminal = {
|
||||
.initDone = FALSE,
|
||||
.lock = INITLOCK(KLOCK_MUTEX),
|
||||
|
||||
|
@ -234,3 +130,14 @@ static Terminal_t vgaTerm = {
|
|||
.PrintOnTermUnlocked = VGA_PrintOnTermUnlocked,
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// Initialize VGA output
|
||||
//
|
||||
void VGA_Init(void)
|
||||
{
|
||||
KalAssert(VGA_Terminal.initDone != INITOK);
|
||||
|
||||
VGA_Terminal.initDone = INITOK;
|
||||
}
|
||||
|
|
@ -7,13 +7,12 @@
|
|||
// Desc: How NOT to panic 101 //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#define _UNLOCKED_IO
|
||||
#include <kaleid.h>
|
||||
|
||||
//
|
||||
// Failed assert() handler
|
||||
//
|
||||
noreturn void _assert_handler(const char *msg,
|
||||
noreturn void __assert_handler(const char *msg,
|
||||
const char *file,
|
||||
int line,
|
||||
const char *func)
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
|
||||
sched-test:
|
||||
gcc -O2 -masm=intel -I../../include ./sched.c
|
||||
gcc -O2 -Wall -Wextra -I../../include ./sched.c
|
||||
|
||||
clean:
|
||||
rm a.out
|
||||
|
|
|
@ -7,27 +7,29 @@
|
|||
// Desc: Scheduling algorithm //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#include <kernel/kernsched.h>
|
||||
#include <kalkern.h>
|
||||
|
||||
#ifndef _KALEID_KERNEL
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
CREATE_PER_CPU(CurProc, Process_t *);
|
||||
|
||||
//
|
||||
// For test purpose only
|
||||
//
|
||||
int procslen = 9;
|
||||
int procslen = 10;
|
||||
Process_t procs[] = {
|
||||
{ 0, 0, 0, 12, 12, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL },
|
||||
{ 1, 2, 2, 16, 16, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL },
|
||||
{ 2, 3, 3, 31, 31, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL },
|
||||
{ 3, 2, 2, 1, 1, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL },
|
||||
{ 4, 0, 0, 5, 5, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL },
|
||||
{ 5, 0, 0, 30, 30, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL },
|
||||
{ 6, 1, 1, 19, 19, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL },
|
||||
{ 7, 1, 1, 0, 0, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL },
|
||||
{ 8, 3, 3, 12, 12, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL },
|
||||
{ 0, 0, 0, 12, 12, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL, NULL, NULL },
|
||||
{ 1, 2, 2, 16, 16, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL, NULL, NULL },
|
||||
{ 2, 3, 3, 31, 31, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL, NULL, NULL },
|
||||
{ 3, 2, 2, 1, 1, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL, NULL, NULL },
|
||||
{ 4, 3, 3, 5, 5, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL, NULL, NULL },
|
||||
{ 5, 0, 0, 30, 30, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL, NULL, NULL },
|
||||
{ 6, 1, 1, 19, 19, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL, NULL, NULL },
|
||||
{ 7, 1, 1, 0, 0, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL, NULL, NULL },
|
||||
{ 8, 3, 3, 12, 12, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL, NULL, NULL },
|
||||
{ 9, 2, 2, 21, 21, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL, NULL, NULL },
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -67,22 +69,22 @@ void SchedUnlock(void) {
|
|||
// The four priority classes of OS/2
|
||||
//
|
||||
|
||||
CREATE_PER_CPU(IdlePrioProcs, ListHead_t *);
|
||||
CREATE_PER_CPU(ReglPrioProcs, ListHead_t *);
|
||||
CREATE_PER_CPU(ServPrioProcs, ListHead_t *);
|
||||
CREATE_PER_CPU(TimeCritProcs, ListHead_t *);
|
||||
CREATE_PER_CPU(ServPrioProcs, ListHead_t *);
|
||||
CREATE_PER_CPU(ReglPrioProcs, ListHead_t *);
|
||||
CREATE_PER_CPU(IdlePrioProcs, ListHead_t *);
|
||||
|
||||
const char *PrioClassesNames[] = {
|
||||
"Idle priority class",
|
||||
"Regular priority class",
|
||||
"Server priority class",
|
||||
"Time-critical class",
|
||||
"Server priority class",
|
||||
"Regular priority class",
|
||||
"Idle priority class",
|
||||
};
|
||||
|
||||
enum { IDLE_PRIO_PROC = 0,
|
||||
REGL_PRIO_PROC = 1,
|
||||
SERV_PRIO_PROC = 2,
|
||||
TIME_CRIT_PROC = 3,
|
||||
enum { TIME_CRIT_PROC = 0,
|
||||
SERV_PRIO_PROC = 1,
|
||||
REGL_PRIO_PROC = 2,
|
||||
IDLE_PRIO_PROC = 3,
|
||||
};
|
||||
|
||||
//
|
||||
|
@ -111,8 +113,8 @@ Process_t *CompareProcs(Process_t *proc1, Process_t *proc2)
|
|||
{
|
||||
KalAssert(proc1 && proc2);
|
||||
|
||||
if (proc1->prioClass > proc2->prioClass) return proc1;
|
||||
if (proc1->prioClass < proc2->prioClass) return proc2;
|
||||
if (proc1->prioClass < proc2->prioClass) return proc1;
|
||||
if (proc1->prioClass > proc2->prioClass) return proc2;
|
||||
|
||||
if (proc1->prioLevel > proc2->prioLevel) return proc1;
|
||||
if (proc1->prioLevel < proc2->prioLevel) return proc2;
|
||||
|
@ -126,7 +128,7 @@ Process_t *CompareProcs(Process_t *proc1, Process_t *proc2)
|
|||
static inline
|
||||
void SchedThisProcUnlocked(Process_t *proc)
|
||||
{
|
||||
KalAssert(proc && proc->procState == STATE_RUNNABLE);
|
||||
KalAssert(proc && proc->procState == STATE_RUNNABLE && !proc->schedNode);
|
||||
|
||||
bool found = false;
|
||||
ListNode_t *iterNode = NULL;
|
||||
|
@ -137,22 +139,20 @@ void SchedThisProcUnlocked(Process_t *proc)
|
|||
|
||||
proc->schedNode = procNode;
|
||||
|
||||
//printdbg("Adding process %d to '%s'\n", proc->pid, PrioClassesNames[proc->prioClass]);
|
||||
|
||||
//
|
||||
// Find a process with lesser priority
|
||||
//
|
||||
for (iterNode = head->first; iterNode; iterNode = iterNode->next) {
|
||||
if (proc->prioLevel > GetNodeData(iterNode, Process_t *)->prioLevel) {
|
||||
// Detect double insertions
|
||||
KalAssert(proc->pid != GetNodeData(iterNode, Process_t *)->pid);
|
||||
|
||||
// Add process to schedule
|
||||
AddNodeBefore(head, iterNode, procNode);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Didn't find any process with lesser priority
|
||||
//
|
||||
if (found == false) {
|
||||
AppendNode(head, procNode);
|
||||
}
|
||||
|
@ -198,9 +198,12 @@ void BlockCurProc(void)
|
|||
|
||||
ListNode_t *procNode = GetCurProc()->schedNode;
|
||||
|
||||
KalAssert(procNode && "Blocking non-scheduled process");
|
||||
|
||||
GetCurProc()->procState = STATE_BLOCKED;
|
||||
RemoveNode(procNode->head, procNode);
|
||||
|
||||
GetCurProc()->schedNode = NULL;
|
||||
SetCurProc(SelectSchedNext());
|
||||
}
|
||||
|
||||
|
@ -208,6 +211,7 @@ static inline
|
|||
void ReSchedCurProc(void)
|
||||
{
|
||||
KalAssert(GetCurProc() && GetCurProc()->procState == STATE_RUNNING);
|
||||
KalAssert(GetCurProc()->schedNode);
|
||||
|
||||
// Restore default attributes, cancelling boosts
|
||||
GetCurProc()->prioClass = GetCurProc()->defPrioClass;
|
||||
|
@ -233,15 +237,11 @@ void SchedOnTick(void)
|
|||
|
||||
Process_t *procNext, *winner, *previous = GetCurProc();
|
||||
|
||||
//
|
||||
// We're either idle or running something
|
||||
//
|
||||
KalAssert(GetCurProc() == NULL || GetCurProc()->procState == STATE_RUNNING);
|
||||
|
||||
//
|
||||
// Have the current process spent its timeslice?
|
||||
// (To be handled in CPU decisions function)
|
||||
//
|
||||
if (GetCurProc() != NULL) {
|
||||
if (GetCurProc()->timeSlice <= 1) {
|
||||
// Re-schedule
|
||||
|
@ -251,31 +251,26 @@ void SchedOnTick(void)
|
|||
_SetCurProc(NULL);
|
||||
}
|
||||
|
||||
//
|
||||
// Otherwise, make it lose a tick
|
||||
//
|
||||
else {
|
||||
GetCurProc()->timeSlice--;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Are we idle, or scheduling next process?
|
||||
//
|
||||
if (GetCurProc() == NULL) {
|
||||
SetCurProc(SelectSchedNext());
|
||||
goto leave;
|
||||
}
|
||||
|
||||
//
|
||||
// Is preemption on and a re-schedule is needed?
|
||||
if (GetPreemptCount() == PREEMPT_ON && GetReSchedFlag()) {
|
||||
|
||||
// Is there a higher priority process that is runnable?
|
||||
//
|
||||
procNext = SelectSchedNext();
|
||||
winner = CompareProcs(GetCurProc(), procNext);
|
||||
|
||||
//
|
||||
// Yes, procNext should preempt current process
|
||||
//
|
||||
if (winner == procNext) {
|
||||
// Re-schedule
|
||||
ReSchedCurProc();
|
||||
|
@ -283,10 +278,9 @@ void SchedOnTick(void)
|
|||
// Switch to procNext
|
||||
SetCurProc(procNext);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Current process won't be preempted and has time remaining
|
||||
//
|
||||
leave:
|
||||
SchedUnlock();
|
||||
|
||||
|
@ -301,7 +295,6 @@ leave:
|
|||
void InitSched(void)
|
||||
{
|
||||
int pid;
|
||||
Process_t *proc;
|
||||
|
||||
SchedLock();
|
||||
|
||||
|
@ -345,7 +338,7 @@ void FiniSched(void)
|
|||
|
||||
#ifndef _KALEID_KERNEL
|
||||
|
||||
#define PrintProc(proc) printdbg("{ %d, '%s', %d , %d}\n", (proc)->pid, \
|
||||
#define PrintProc(proc) printdbg("{ %d, '%s', %d , %lu}\n", (proc)->pid, \
|
||||
PrioClassesNames[(proc)->prioClass], (proc)->prioLevel, (proc)->timeSlice);
|
||||
|
||||
//
|
||||
|
@ -358,7 +351,7 @@ void PrintList(ListHead_t *head)
|
|||
Process_t *proc;
|
||||
ListNode_t *node = head->first;
|
||||
|
||||
printdbg("len: %d\n", head->length);
|
||||
printdbg("len: %lu\n", head->length);
|
||||
|
||||
while (node) {
|
||||
proc = GetNodeData(node, Process_t *);
|
||||
|
@ -402,8 +395,8 @@ int main(void)
|
|||
}
|
||||
|
||||
if (tick == 50) {
|
||||
procs[2].procState = STATE_RUNNABLE;
|
||||
SchedThisProc(&procs[2]);
|
||||
procs[0].procState = STATE_RUNNABLE;
|
||||
SchedThisProc(&procs[0]);
|
||||
}
|
||||
|
||||
printf("Tick %d - Running: ", tick);
|
||||
|
@ -418,6 +411,9 @@ int main(void)
|
|||
|
||||
SchedOnTick();
|
||||
|
||||
if (tick == 50) // already done
|
||||
puts("Re-scheduling process 0");
|
||||
|
||||
tick++;
|
||||
}
|
||||
|
||||
|
@ -427,4 +423,3 @@ int main(void)
|
|||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Reference in New Issue