diff --git a/.gitignore b/.gitignore
index 5e81429..8225972 100644
--- a/.gitignore
+++ b/.gitignore
@@ -20,6 +20,7 @@ CNAME
# Other stuff
multiboot.pdf
+osk-graph.ps
grub.log
Makefile.out.2
build/bin/s**
@@ -29,6 +30,7 @@ build/bin/s**
*.ilk
*.map
*.exp
+*.expand
# Precompiled Headers
*.gch
diff --git a/Makefile b/Makefile
index 697dbd0..c17e1ad 100644
--- a/Makefile
+++ b/Makefile
@@ -41,7 +41,7 @@ LDFLAGS=-melf_x86_64
COPTIM=-O2
CWARNS=-Wall -Wextra -Wno-unused-parameter -Wno-implicit-fallthrough -Werror=implicit-function-declaration -Werror=return-type
CINCLUDES=-Iinclude
-CFLAGS1=-nostdlib -ffreestanding -mcmodel=large -std=gnu11
+CFLAGS1=-nostdlib -ffreestanding -mcmodel=large -std=gnu11 -fstack-protector-all -fdump-rtl-expand
CFLAGS2= -c -mno-red-zone -mno-mmx -mno-sse -mno-sse2
CFLAGS= $(CFLAGS1) $(CFLAGS2)
CFLAGS_MATHS= $(CFLAGS1) -c -mno-red-zone -mno-mmx -mno-sse2
@@ -55,10 +55,10 @@ CFLAGS += -g
endif
KCC=$(CCNAME) $(COPTIM) $(CWARNS) $(CFLAGS) $(CINCLUDES) \
- -D_OSK_SOURCE -D_KALEID_KERNEL -fstack-protector-all
+ -D_OSK_SOURCE -D_KALEID_KERNEL
KCC_MATHS=$(CCNAME) $(COPTIM) $(CWARNS) $(CFLAGS_MATHS) $(CINCLUDES) \
- -D_OSK_SOURCE -D_KALEID_KERNEL -fstack-protector-all
+ -D_OSK_SOURCE -D_KALEID_KERNEL
# Folders
MBRDIR=boot/grub
@@ -84,8 +84,8 @@ NC='\033[1;37m'
# Lib C sources + libbuf source
LibCSources = libc/mem.c libc/ctype.c \
libc/rand.c libc/sprintf.c \
- libc/errno.c libc/string.c \
- libc/strtol.c extras/argv.c \
+ libc/errno.c libc/string.c \
+ libc/strtol.c \
libbuf/bopen.c libbuf/bputc.c libbuf/bscroll.c \
libbuf/bprint.c libbuf/bgetc.c libbuf/bscan.c \
libbuf/bflush.c libbuf/bwrite.c libbuf/bread.c \
@@ -108,7 +108,8 @@ KernSources = kernel/ke/cpuid.c kernel/mm/paging.c \
kernel/ke/rtc.c kernel/io/keyb.c \
kernel/io/spkr.c kernel/po/shtdwn.c \
kernel/sh/shell.c kernel/sh/shcmds.c \
- kernel/sh/musage.c kernel/io/ata.c
+ kernel/sh/musage.c kernel/io/ata.c \
+ kernel/sh/argv.c
KernObj=$(patsubst %.c,$(KOBJDIR)/%.o,$(KernSources))
KernDep=$(patsubst %.c,$(KOBJDIR)/%.d,$(KernSources))
@@ -259,10 +260,18 @@ copy_kernel:
@echo ${CL2}[$@] ${CL}Success.${CL3}
@rmdir $(BINDIR)/disk
+egypt: CFLAGS := -DNDEBUG $(filter-out -fstack-protector-all,$(CFLAGS))
+egypt: dust $(LibCObj) $(KernObj)
+ @find -name '*.expand' -o -name '*.expand' | xargs cat > rtl_exp.out
+ @egypt < rtl_exp.out | dot -Tps -o osk-graph.ps
+ @rm -f rtl_exp.out
+ @evince osk-graph.ps &
+
dust:
-@$(MBRDIR)/umount.sh $(BINDIR)/disk || /bin/true
@rm -Rf $(OBJDIR)/*
@echo ${CL2}[$@] ${CL}Cleaned.${CL3}
+
clean:
-@$(MBRDIR)/umount.sh $(BINDIR)/disk || /bin/true
@rm -Rvf ./ProjectTree $(BUILDDIR)/*.log
diff --git a/ProjectTree b/ProjectTree
index 82078fc..0f87887 100644
--- a/ProjectTree
+++ b/ProjectTree
@@ -56,102 +56,142 @@
│ │ │ └── loader.o
│ │ └── kaleid
│ │ ├── extras
+│ │ │ ├── argv.c.229r.expand
│ │ │ ├── argv.d
│ │ │ └── argv.o
│ │ ├── kernel
│ │ │ ├── init
+│ │ │ │ ├── info.c.229r.expand
│ │ │ │ ├── info.d
│ │ │ │ ├── info.o
+│ │ │ │ ├── init.c.229r.expand
│ │ │ │ ├── init.d
│ │ │ │ ├── init.o
+│ │ │ │ ├── ssp.c.229r.expand
│ │ │ │ ├── ssp.d
│ │ │ │ ├── ssp.o
│ │ │ │ ├── table.d
│ │ │ │ └── table.o
│ │ │ ├── io
+│ │ │ │ ├── ata.c.229r.expand
│ │ │ │ ├── ata.d
│ │ │ │ ├── ata.o
+│ │ │ │ ├── cursor.c.229r.expand
│ │ │ │ ├── cursor.d
│ │ │ │ ├── cursor.o
+│ │ │ │ ├── keyb.c.229r.expand
│ │ │ │ ├── keyb.d
│ │ │ │ ├── keyb.o
+│ │ │ │ ├── spkr.c.229r.expand
│ │ │ │ ├── spkr.d
│ │ │ │ ├── spkr.o
+│ │ │ │ ├── vga.c.229r.expand
│ │ │ │ ├── vga.d
│ │ │ │ └── vga.o
│ │ │ ├── ke
+│ │ │ │ ├── cpuid.c.229r.expand
│ │ │ │ ├── cpuid.d
│ │ │ │ ├── cpuid.o
+│ │ │ │ ├── idt.c.229r.expand
│ │ │ │ ├── idt.d
│ │ │ │ ├── idt.o
+│ │ │ │ ├── log.c.229r.expand
│ │ │ │ ├── log.d
│ │ │ │ ├── log.o
+│ │ │ │ ├── panic.c.229r.expand
│ │ │ │ ├── panic.d
│ │ │ │ ├── panic.o
+│ │ │ │ ├── rtc.c.229r.expand
│ │ │ │ ├── rtc.d
│ │ │ │ └── rtc.o
│ │ │ ├── mm
+│ │ │ │ ├── gdt.c.229r.expand
│ │ │ │ ├── gdt.d
│ │ │ │ ├── gdt.o
+│ │ │ │ ├── heap.c.229r.expand
│ │ │ │ ├── heap.d
│ │ │ │ ├── heap.o
+│ │ │ │ ├── malloc.c.229r.expand
│ │ │ │ ├── malloc.d
│ │ │ │ ├── malloc.o
+│ │ │ │ ├── map.c.229r.expand
│ │ │ │ ├── map.d
│ │ │ │ ├── map.o
+│ │ │ │ ├── paging.c.229r.expand
│ │ │ │ ├── paging.d
│ │ │ │ └── paging.o
│ │ │ ├── po
+│ │ │ │ ├── shtdwn.c.229r.expand
│ │ │ │ ├── shtdwn.d
│ │ │ │ └── shtdwn.o
│ │ │ ├── ps
│ │ │ │ ├── sched.d
│ │ │ │ └── sched.o
│ │ │ └── sh
+│ │ │ ├── musage.c.229r.expand
│ │ │ ├── musage.d
│ │ │ ├── musage.o
+│ │ │ ├── shcmds.c.229r.expand
│ │ │ ├── shcmds.d
│ │ │ ├── shcmds.o
+│ │ │ ├── shell.c.229r.expand
│ │ │ ├── shell.d
│ │ │ └── shell.o
│ │ ├── libbuf
+│ │ │ ├── bclose.c.229r.expand
│ │ │ ├── bclose.d
│ │ │ ├── bclose.o
+│ │ │ ├── bflush.c.229r.expand
│ │ │ ├── bflush.d
│ │ │ ├── bflush.o
+│ │ │ ├── bgetc.c.229r.expand
│ │ │ ├── bgetc.d
│ │ │ ├── bgetc.o
+│ │ │ ├── bmisc.c.229r.expand
│ │ │ ├── bmisc.d
│ │ │ ├── bmisc.o
+│ │ │ ├── bopen.c.229r.expand
│ │ │ ├── bopen.d
│ │ │ ├── bopen.o
+│ │ │ ├── bprint.c.229r.expand
│ │ │ ├── bprint.d
│ │ │ ├── bprint.o
+│ │ │ ├── bputc.c.229r.expand
│ │ │ ├── bputc.d
│ │ │ ├── bputc.o
│ │ │ ├── bread.d
│ │ │ ├── bread.o
│ │ │ ├── bscan.d
│ │ │ ├── bscan.o
+│ │ │ ├── bscroll.c.229r.expand
│ │ │ ├── bscroll.d
│ │ │ ├── bscroll.o
│ │ │ ├── bwrite.d
│ │ │ └── bwrite.o
│ │ └── libc
+│ │ ├── atoi.c.229r.expand
│ │ ├── atoi.o
+│ │ ├── ctype.c.229r.expand
│ │ ├── ctype.d
│ │ ├── ctype.o
+│ │ ├── errno.c.229r.expand
│ │ ├── errno.d
│ │ ├── errno.o
+│ │ ├── itoa.c.229r.expand
│ │ ├── itoa.o
+│ │ ├── mem.c.229r.expand
│ │ ├── mem.d
│ │ ├── mem.o
+│ │ ├── rand.c.229r.expand
│ │ ├── rand.d
│ │ ├── rand.o
+│ │ ├── sprintf.c.229r.expand
│ │ ├── sprintf.d
│ │ ├── sprintf.o
+│ │ ├── string.c.229r.expand
│ │ ├── string.d
│ │ ├── string.o
+│ │ ├── strtol.c.229r.expand
│ │ ├── strtol.d
│ │ └── strtol.o
│ ├── grub.log
@@ -184,6 +224,7 @@
│ │ └── list.h
│ ├── mm
│ │ ├── heap.h
+│ │ ├── malloc.h
│ │ └── mm.h
│ ├── po
│ │ └── shtdwn.h
@@ -261,7 +302,8 @@
├── ChangeLog
├── COPYING
├── Makefile
+├── osk-graph.ps
├── ProjectTree
└── README.md
-43 directories, 196 files
+43 directories, 238 files
diff --git a/README.md b/README.md
index b815425..b6edeaa 100644
--- a/README.md
+++ b/README.md
@@ -22,7 +22,7 @@ To compile this project from sources, you must first install the dependencies
```
apt update && apt upgrade
-apt install grub-pc-bin dosfstools make nasm qemu tree
+apt install grub-pc-bin dosfstools make nasm qemu tree libisl15
```
You also need to have the [x86-64 ELF gcc cross-compiler](https://www.os-k.eu/build-tools/cross-cc.tar.xz) and its ``bin`` directory in your PATH.
diff --git a/include/ex/argv.h b/include/ex/argv.h
deleted file mode 100644
index a651f34..0000000
--- a/include/ex/argv.h
+++ /dev/null
@@ -1,299 +0,0 @@
-//----------------------------------------------------------------------------//
-// GNU GPL OS/K //
-// //
-// Desc: Command line parsing utilities //
-// //
-// //
-// Copyright © 2018-2019 The OS/K Team //
-// //
-// This file is part of OS/K. //
-// //
-// OS/K is free software: you can redistribute it and/or modify //
-// it under the terms of the GNU General Public License as published by //
-// the Free Software Foundation, either version 3 of the License, or //
-// any later version. //
-// //
-// OS/K is distributed in the hope that it will be useful, //
-// but WITHOUT ANY WARRANTY//without even the implied warranty of //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
-// GNU General Public License for more details. //
-// //
-// You should have received a copy of the GNU General Public License //
-// along with OS/K. If not, see . //
-//----------------------------------------------------------------------------//
-
-#ifndef _LIBC_H
-#include
-#endif
-
-#ifndef _KALEXTRAS_ARGV_H
-#define _KALEXTRAS_ARGV_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef enum CmdOptionFlag_t CmdOptionFlag_t;
-typedef enum CmdParserFlags_t CmdParserFlags_t;
-typedef enum CmdParserReturn_t CmdParserReturn_t;
-
-typedef struct CmdOption_t CmdOption_t;
-typedef struct CmdDocStrings_t CmdDocStrings_t;
-typedef struct CmdParserState_t CmdParserState_t;
-
-//------------------------------------------//
-
-//
-// 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) // 64 KB
-
-//------------------------------------------//
-
-//
-// Flags for options
-//
-enum CmdOptionFlag_t
-{
- // 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),
-
-};
-
-//
-// Flags for KalParse(CmdLine|ArgVec)
-//
-enum CmdParserFlags_t
-{
- // 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_DONT_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,
-};
-
-//
-// 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
-//
-enum CmdParserReturn_t
-{
- // 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),
-};
-
-//------------------------------------------//
-
-//
-// An option for a command, e.g. "-o file" in "cc -o file"
-//
-struct CmdOption_t
-{
- // The option's name, e.g. "help" for "--help"
- // May be 0, but only if letter is not zero
- const char *longName;
-
- // 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;
-};
-
-//
-// 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
-//
-struct CmdDocStrings_t
-{
- 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;
-};
-
-//
-// The state variable passed to the parser containing useful infos
-//
-struct CmdParserState_t {
-
- // 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;
-
- // Output streams (may be NULL)
- /*FILE*/ void *outStream;
- /*FILE*/ void *errStream;
-
- // Private, internal data; do not touch
- void *priv;
-
-};
-
-//
-// 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
-//
-error_t KalCmdLineToArgVecEx(const char *cmdLine,
- int *argcPtr,
- char *bufptr,
- bool doEscaping);
-
-//
-// KalCmdLineToArgVecEx but doEscaping = false
-//
-error_t KalCmdLineToArgVec(const char *cmdLine,
- int *argcPtr,
- char *bufptr);
-
-//
-// Argument vector to command line
-//
-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*/ void *outStream,
- /*FILE*/ void *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);
-
-//------------------------------------------//
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/include/init/boot.h b/include/init/boot.h
index 931f996..61cfa19 100644
--- a/include/init/boot.h
+++ b/include/init/boot.h
@@ -26,6 +26,10 @@
#include
#endif
+#ifndef MULTIBOOT_HEADER
+#include
+#endif
+
#ifndef _INIT_BOOT_H
#define _INIT_BOOT_H
@@ -115,4 +119,9 @@ extern volatile BootInfo_t BtBootTab;
//----------------------------------------------------------------------------//
+void BtDoSanityChecks(uint);
+void BtInitBootInfo(multiboot_info_t *, void *);
+
+//----------------------------------------------------------------------------//
+
#endif
diff --git a/include/io/vga.h b/include/io/vga.h
index 7d183dd..319c790 100644
--- a/include/io/vga.h
+++ b/include/io/vga.h
@@ -58,15 +58,14 @@ extern const char *RtlColorNames[VGA_COLOR_WHITE+1];
#define RtlColorToChar(c) ((c) + 130)
#define RtlCharToColor(c) ((c) - 130)
-void IoScrollDown(void);
+uint IoGetScroll(void);
void IoScrollUp(void);
+void IoScrollDown(void);
void IoChangeTermColor(int, int);
error_t IoInitVGABuffer(void);
-uint IoGetScroll(void);
-
//----------------------------------------------------------------------------//
#endif
diff --git a/include/ke/cpuid.h b/include/ke/cpuid.h
index f10e53d..aa49f38 100644
--- a/include/ke/cpuid.h
+++ b/include/ke/cpuid.h
@@ -115,7 +115,7 @@ static inline int CpuCpuidString(int code, uint where[4])
void KeGetCpuInfos(void);
double KeGetCpuSpeed(void);
-extern void KeActivateSSE(void);
+void KeActivateSSE(void);
// -------------------------------------------------------------------------- //
diff --git a/include/kernel.h b/include/kernel.h
index 9392824..c043910 100644
--- a/include/kernel.h
+++ b/include/kernel.h
@@ -165,7 +165,9 @@ extern CpuCore_t _KeCPUTable[NCPUS];
//----------------------------------------------------------------------------//
+#ifndef _ASM_H
#include
+#endif
//----------------------------------------------------------------------------//
@@ -186,7 +188,7 @@ extern CpuCore_t _KeCPUTable[NCPUS];
error_t KernLog(const char *, ...);
-#ifndef _NO_DEBUG
+#ifndef NDEBUG
void DebugLog(const char *, ...);
#else
#define DebugLog(fmt, ...) ((void)0)
diff --git a/include/lib/list.h b/include/lib/list.h
index a3eb619..95042a4 100644
--- a/include/lib/list.h
+++ b/include/lib/list.h
@@ -47,7 +47,6 @@ struct ListHead_t
struct ListNode_t
{
- void *data;
ListHead_t *head;
ListNode_t *prev;
ListNode_t *next;
@@ -71,22 +70,6 @@ static inline ListHead_t
return head;
}
-// Create a node
-//
-static inline ListNode_t
-*ExCreateNode(void *data)
-{
- ListNode_t *node = malloc(sizeof(ListNode_t));
-
- if (node == NULL) return NULL;
-
- node->data = data;
- node->head = NULL;
- node->prev = node->next = NULL;
-
- return node;
-}
-
//
// Prepend node at beginning of list
//
@@ -228,16 +211,6 @@ leave:
return head;
}
-//
-// Free a node
-//
-static inline void
-ExDestroyNode(ListNode_t *node)
-{
- assert(node);
- free(node);
-}
-
//
// Free a list head
//
@@ -248,11 +221,6 @@ ExDestroyListHead(ListHead_t *head)
free(head);
}
-//
-// Access a node's data
-//
-#define ExGetNodeData(node, type) ((type)(node)->data)
-
//------------------------------------------//
#ifdef __cplusplus
diff --git a/include/mm/malloc.h b/include/mm/malloc.h
new file mode 100644
index 0000000..44531ad
--- /dev/null
+++ b/include/mm/malloc.h
@@ -0,0 +1,102 @@
+//----------------------------------------------------------------------------//
+// GNU GPL OS/K //
+// //
+// Desc: Memory allocation functions //
+// //
+// //
+// Copyright © 2018-2019 The OS/K Team //
+// //
+// This file is part of OS/K. //
+// //
+// OS/K is free software: you can redistribute it and/or modify //
+// it under the terms of the GNU General Public License as published by //
+// the Free Software Foundation, either version 3 of the License, or //
+// any later version. //
+// //
+// OS/K is distributed in the hope that it will be useful, //
+// but WITHOUT ANY WARRANTY//without even the implied warranty of //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
+// GNU General Public License for more details. //
+// //
+// You should have received a copy of the GNU General Public License //
+// along with OS/K. If not, see . //
+//----------------------------------------------------------------------------//
+
+#ifndef _KERNEL_H
+#include
+#endif
+
+#ifndef _LIB_LIST_H
+#include
+#endif
+
+#ifndef _MM_MALLOC_H
+#define _MM_MALLOC_H
+
+#ifndef PAGESIZE
+#define PAGESIZE 4096
+#endif
+
+typedef struct Cache_t Cache_t;
+typedef struct Pool_t Pool_t;
+
+// Operation on objects
+typedef void (*ObjCtor_t)(Cache_t *cache,
+ Pool_t *pool,
+ void *obj);
+//
+// A cache containing many pools
+//
+struct Cache_t
+{
+ // Synchronization
+ Spinlock_t lock;
+
+ // Cache name
+ char name[64];
+
+ // Size of each object
+ size_t objsize;
+
+ // Number of objects allocated
+ size_t objused;
+
+ // Number of available objects including unused
+ size_t objtotal;
+
+ // Number of objects per pool
+ size_t objperpool;
+
+ // Object constructor
+ ObjOper_t *ctor;
+
+ // Object destructor
+ ObjOper_t *dtor;
+
+ // Object pools without any allocated object
+ ListHead_t *freepools;
+
+ // Object pools containing some allocated objects
+ ListHead_t *usedpools;
+
+ // Objects pools containing no unallocated object
+ ListHead_t *fullpools;
+};
+
+//
+// A pool of allocable objects
+// Takes a fixed amount of pages
+//
+struct Pool_t
+{
+
+};
+
+//
+// Allocates memory from the kernel heap
+//
+void *kmalloc(size_t req, uint flags);
+void *kmemalign(size_t req, uint align, uint flags);
+
+#endif
+
diff --git a/include/sh/argv.h b/include/sh/argv.h
new file mode 100644
index 0000000..843b2c7
--- /dev/null
+++ b/include/sh/argv.h
@@ -0,0 +1,57 @@
+//----------------------------------------------------------------------------//
+// GNU GPL OS/K //
+// //
+// Desc: Command line parsing utilities //
+// //
+// //
+// Copyright © 2018-2019 The OS/K Team //
+// //
+// This file is part of OS/K. //
+// //
+// OS/K is free software: you can redistribute it and/or modify //
+// it under the terms of the GNU General Public License as published by //
+// the Free Software Foundation, either version 3 of the License, or //
+// any later version. //
+// //
+// OS/K is distributed in the hope that it will be useful, //
+// but WITHOUT ANY WARRANTY//without even the implied warranty of //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
+// GNU General Public License for more details. //
+// //
+// You should have received a copy of the GNU General Public License //
+// along with OS/K. If not, see . //
+//----------------------------------------------------------------------------//
+
+#ifndef _KERNEL_H
+#include
+#endif
+
+#ifndef _SH_ARGV_H
+#define _SH_ARGV_H
+
+//------------------------------------------//
+
+// See kaleid/sh/argv.h
+#define ARG_MAX (1 << 16) // 64 KB
+
+//------------------------------------------//
+
+//
+// Command line to argument vector
+// Assumes sizeof(bufptr) >= ARG_MAX * 2
+//
+error_t ShCmdLineToArgVecEx(const char *cmdLine,
+ int *argcPtr,
+ char *bufptr,
+ bool doEscaping);
+
+//
+// ShCmdLineToArgVecEx but doEscaping = false
+//
+error_t ShCmdLineToArgVec(const char *cmdLine,
+ int *argcPtr,
+ char *bufptr);
+
+//------------------------------------------//
+
+#endif
diff --git a/kaleid/kernel/init/init.h b/include/sh/shell.h
similarity index 69%
rename from kaleid/kernel/init/init.h
rename to include/sh/shell.h
index 4f9accf..f3da477 100644
--- a/kaleid/kernel/init/init.h
+++ b/include/sh/shell.h
@@ -1,7 +1,7 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
-// Desc: Kernel entry point //
+// Desc: Kernel shell //
// //
// //
// Copyright © 2018-2019 The OS/K Team //
@@ -22,33 +22,38 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
+#ifndef _KERNEL_H
+#include
+#endif
-// info.c
-extern void BtDoSanityChecks(uint mbMagic);
-extern void BtInitBootInfo(multiboot_info_t *mbi, void *codeSeg);
+#ifndef _SH_SHELL_H
+#define _SH_SHELL_H
-// io/vga.c
-extern error_t IoInitVGABuffer(void);
+//----------------------------------------------------------------------------//
-// ke/shell.c
-extern void KeStartShell(void);
+void ShStartShell(void);
-// ps/proc.c test function
-extern void pstest(void);
+//----------------------------------------------------------------------------//
-// interrupts tests
-extern void divideByZero(void);
+#define CMDBUFSIZE 256
+
+typedef struct Command_t Command_t;
+
+struct Command_t
+{
+ const char *name;
+ error_t (*func)(int argc, char **argv, char *cmdline);
+ const char *help;
+};
+
+//----------------------------------------------------------------------------//
+
+extern int shcol;
+extern int shargc;
+extern char **shargv;
+extern Command_t shcmdtable[];
+
+//----------------------------------------------------------------------------//
+
+#endif
diff --git a/kaleid/kernel/init/info.c b/kaleid/kernel/init/info.c
index 8f8d6ae..1d2da60 100644
--- a/kaleid/kernel/init/info.c
+++ b/kaleid/kernel/init/info.c
@@ -23,7 +23,6 @@
//----------------------------------------------------------------------------//
#include
-#include
//
// BootInfo_t initialization. It is necessary because grub will potentially be
diff --git a/kaleid/kernel/init/init.c b/kaleid/kernel/init/init.c
index 217f6bf..e29259e 100644
--- a/kaleid/kernel/init/init.c
+++ b/kaleid/kernel/init/init.c
@@ -22,7 +22,17 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#include "init.h"
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
//
// Entry point of the Kaleid kernel
@@ -66,7 +76,7 @@ noreturn void BtStartKern(multiboot_info_t *mbInfo, uint mbMagic, void *codeSeg)
IoEnableKeyb();
MmActivatePageHandler();
- KeStartShell();
+ ShStartShell();
PoShutdown();
}
diff --git a/kaleid/kernel/ke/log.c b/kaleid/kernel/ke/log.c
index b160a47..0765e1f 100644
--- a/kaleid/kernel/ke/log.c
+++ b/kaleid/kernel/ke/log.c
@@ -40,7 +40,7 @@ error_t KernLog(const char *fmt, ...)
return rc;
}
-#ifndef _NO_DEBUG
+#ifndef NDEBUG
//
// Prints formatted string on debug output
//
diff --git a/kaleid/extras/argv.c b/kaleid/kernel/sh/argv.c
similarity index 86%
rename from kaleid/extras/argv.c
rename to kaleid/kernel/sh/argv.c
index 102e431..8e132d3 100644
--- a/kaleid/extras/argv.c
+++ b/kaleid/kernel/sh/argv.c
@@ -22,37 +22,9 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#include
+#include
#include
-#include
-
-//
-// 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
//
@@ -61,13 +33,10 @@ size_t KalComputeArgVecSize(const char *argv[])
// with the address of the nth string stored in the first half,
// specifically at argv[n-1]
//
-// TODO long escape sequences
-// get program command line if cmdLine == NULL
-//
-error_t KalCmdLineToArgVecEx(const char *cmdLine,
- int *argcPtr,
- char *bufptr,
- bool doEscaping)
+error_t ShCmdLineToArgVecEx(const char *cmdLine,
+ int *argcPtr,
+ char *bufptr,
+ bool doEscaping)
{
int argc = 0;
char quotes = 0;
@@ -213,9 +182,9 @@ error_t KalCmdLineToArgVecEx(const char *cmdLine,
#undef ISBLANK
#undef NULLTERM_AND_SAVE
-error_t KalCmdLineToArgVec(const char *cmdLine,
- int *argcPtr,
- char *bufptr)
+error_t ShCmdLineToArgVec(const char *cmdLine,
+ int *argcPtr,
+ char *bufptr)
{
- return KalCmdLineToArgVecEx(cmdLine, argcPtr, bufptr, false);
+ return ShCmdLineToArgVecEx(cmdLine, argcPtr, bufptr, false);
}
diff --git a/kaleid/kernel/sh/musage.c b/kaleid/kernel/sh/musage.c
index 4da4ca2..b97ca50 100644
--- a/kaleid/kernel/sh/musage.c
+++ b/kaleid/kernel/sh/musage.c
@@ -22,7 +22,10 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#include "shell.h"
+#include
+#include
+#include
+#include
error_t CmdMemUsage(int argc, char **argv, char *cmdline)
{
diff --git a/kaleid/kernel/sh/shcmds.c b/kaleid/kernel/sh/shcmds.c
index 2839796..3530d2f 100644
--- a/kaleid/kernel/sh/shcmds.c
+++ b/kaleid/kernel/sh/shcmds.c
@@ -22,8 +22,15 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#include "shell.h"
-
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
int ShAtoi(char* str)
{
@@ -173,7 +180,7 @@ error_t CmdHelp(int argc, char **argv, char *cmdline)
if (argc == 1) {
KernLog("List of all shell built-ins:\n");
- for (cmd = cmdtable; cmd->name != NULL; cmd++, count++) {
+ for (cmd = shcmdtable; cmd->name != NULL; cmd++, count++) {
KernLog("\t%s", cmd->name);
for (i = strlen(cmd->name)/4; i<3; i++) {
KernLog("\t");
@@ -224,7 +231,7 @@ error_t CmdReloadPage(int argc, char **argv, char *cmdline)
error_t CmdShell(int argc, char **argv, char *cmdline)
{
- KeStartShell();
+ ShStartShell();
return EOK;
}
@@ -285,7 +292,8 @@ error_t CmdVersion(int argc, char **argv, char *cmdline)
}
//----------------------------------------------------------------------------//
-Command_t cmdtable[] =
+
+Command_t shcmdtable[] =
{
{ "args", CmdArgs, "Print command line" },
{ "beep", CmdBeep, "Make a beep" },
diff --git a/kaleid/kernel/sh/shell.c b/kaleid/kernel/sh/shell.c
index 0a5a58b..f9bf1ab 100644
--- a/kaleid/kernel/sh/shell.c
+++ b/kaleid/kernel/sh/shell.c
@@ -22,15 +22,21 @@
// along with OS/K. If not, see . //
//----------------------------------------------------------------------------//
-#include "shell.h"
-
-int shcol = VGA_COLOR_LIGHT_GREY;
+#include
+#include
+#include
+#include
+#include
+#include
+#include
int shargc = 0;
-char *argvbuf = 0;
char **shargv = 0;
+int shcol = VGA_COLOR_LIGHT_GREY;
-void ExecuteCommand(char *cmdbuf)
+static char *argvbuf = 0;
+
+static void ExecuteCommand(char *cmdbuf)
{
error_t rc;
Command_t *cmd;
@@ -40,10 +46,10 @@ void ExecuteCommand(char *cmdbuf)
return;
memzero(*shargv, ARG_MAX);
- rc = KalCmdLineToArgVec(cmdbuf, &shargc, argvbuf);
+ rc = ShCmdLineToArgVec(cmdbuf, &shargc, argvbuf);
if (rc) KeStartPanic("Shell: Couldn't parse command line: %d", rc);
- for (cmd = cmdtable; cmd->name != NULL; cmd++) {
+ for (cmd = shcmdtable; cmd->name != NULL; cmd++) {
if (!strcmp(cmd->name, shargv[0])) {
cmd->func(shargc, shargv, cmdbuf);
found = true;
@@ -59,7 +65,7 @@ void ExecuteCommand(char *cmdbuf)
}
}
-void KeStartShell(void)
+void ShStartShell(void)
{
uchar ch;
error_t rc;
diff --git a/kaleid/kernel/sh/shell.h b/kaleid/kernel/sh/shell.h
index 0edc933..e2f9b18 100644
--- a/kaleid/kernel/sh/shell.h
+++ b/kaleid/kernel/sh/shell.h
@@ -32,29 +32,9 @@
#include
#include
#include
-#include
#include
#include
#include
-void KeStartShell(void);
-void pstest(void);
-extern int shcol;
-extern int shargc;
-extern char *argv0;
-extern char **shargv;
-
-#define CMDBUFSIZE 256
-
-typedef struct Command_t Command_t;
-
-struct Command_t
-{
- const char *name;
- error_t (*func)(int argc, char **argv, char *cmdline);
- const char *help;
-};
-
-extern Command_t cmdtable[];