Merge branch 'BetterTerm'

This commit is contained in:
Adrien Bourmault 2019-06-02 12:12:47 +02:00
commit ad05e5d9b3
21 changed files with 318 additions and 447 deletions

2
.gitignore vendored
View File

@ -20,6 +20,7 @@ CNAME
# Other stuff # Other stuff
multiboot.pdf multiboot.pdf
osk-graph.ps
grub.log grub.log
Makefile.out.2 Makefile.out.2
build/bin/s** build/bin/s**
@ -29,6 +30,7 @@ build/bin/s**
*.ilk *.ilk
*.map *.map
*.exp *.exp
*.expand
# Precompiled Headers # Precompiled Headers
*.gch *.gch

View File

@ -41,7 +41,7 @@ LDFLAGS=-melf_x86_64
COPTIM=-O2 COPTIM=-O2
CWARNS=-Wall -Wextra -Wno-unused-parameter -Wno-implicit-fallthrough -Werror=implicit-function-declaration -Werror=return-type CWARNS=-Wall -Wextra -Wno-unused-parameter -Wno-implicit-fallthrough -Werror=implicit-function-declaration -Werror=return-type
CINCLUDES=-Iinclude 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 CFLAGS2= -c -mno-red-zone -mno-mmx -mno-sse -mno-sse2
CFLAGS= $(CFLAGS1) $(CFLAGS2) CFLAGS= $(CFLAGS1) $(CFLAGS2)
CFLAGS_MATHS= $(CFLAGS1) -c -mno-red-zone -mno-mmx -mno-sse2 CFLAGS_MATHS= $(CFLAGS1) -c -mno-red-zone -mno-mmx -mno-sse2
@ -55,10 +55,10 @@ CFLAGS += -g
endif endif
KCC=$(CCNAME) $(COPTIM) $(CWARNS) $(CFLAGS) $(CINCLUDES) \ 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) \ KCC_MATHS=$(CCNAME) $(COPTIM) $(CWARNS) $(CFLAGS_MATHS) $(CINCLUDES) \
-D_OSK_SOURCE -D_KALEID_KERNEL -fstack-protector-all -D_OSK_SOURCE -D_KALEID_KERNEL
# Folders # Folders
MBRDIR=boot/grub MBRDIR=boot/grub
@ -84,8 +84,8 @@ NC='\033[1;37m'
# Lib C sources + libbuf source # Lib C sources + libbuf source
LibCSources = libc/mem.c libc/ctype.c \ LibCSources = libc/mem.c libc/ctype.c \
libc/rand.c libc/sprintf.c \ libc/rand.c libc/sprintf.c \
libc/errno.c libc/string.c \ libc/errno.c libc/string.c \
libc/strtol.c extras/argv.c \ libc/strtol.c \
libbuf/bopen.c libbuf/bputc.c libbuf/bscroll.c \ libbuf/bopen.c libbuf/bputc.c libbuf/bscroll.c \
libbuf/bprint.c libbuf/bgetc.c libbuf/bscan.c \ libbuf/bprint.c libbuf/bgetc.c libbuf/bscan.c \
libbuf/bflush.c libbuf/bwrite.c libbuf/bread.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/ke/rtc.c kernel/io/keyb.c \
kernel/io/spkr.c kernel/po/shtdwn.c \ kernel/io/spkr.c kernel/po/shtdwn.c \
kernel/sh/shell.c kernel/sh/shcmds.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)) KernObj=$(patsubst %.c,$(KOBJDIR)/%.o,$(KernSources))
KernDep=$(patsubst %.c,$(KOBJDIR)/%.d,$(KernSources)) KernDep=$(patsubst %.c,$(KOBJDIR)/%.d,$(KernSources))
@ -259,10 +260,18 @@ copy_kernel:
@echo ${CL2}[$@] ${CL}Success.${CL3} @echo ${CL2}[$@] ${CL}Success.${CL3}
@rmdir $(BINDIR)/disk @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: dust:
-@$(MBRDIR)/umount.sh $(BINDIR)/disk || /bin/true -@$(MBRDIR)/umount.sh $(BINDIR)/disk || /bin/true
@rm -Rf $(OBJDIR)/* @rm -Rf $(OBJDIR)/*
@echo ${CL2}[$@] ${CL}Cleaned.${CL3} @echo ${CL2}[$@] ${CL}Cleaned.${CL3}
clean: clean:
-@$(MBRDIR)/umount.sh $(BINDIR)/disk || /bin/true -@$(MBRDIR)/umount.sh $(BINDIR)/disk || /bin/true
@rm -Rvf ./ProjectTree $(BUILDDIR)/*.log @rm -Rvf ./ProjectTree $(BUILDDIR)/*.log

View File

@ -56,102 +56,142 @@
│   │   │   └── loader.o │   │   │   └── loader.o
│   │   └── kaleid │   │   └── kaleid
│   │   ├── extras │   │   ├── extras
│   │   │   ├── argv.c.229r.expand
│   │   │   ├── argv.d │   │   │   ├── argv.d
│   │   │   └── argv.o │   │   │   └── argv.o
│   │   ├── kernel │   │   ├── kernel
│   │   │   ├── init │   │   │   ├── init
│   │   │   │   ├── info.c.229r.expand
│   │   │   │   ├── info.d │   │   │   │   ├── info.d
│   │   │   │   ├── info.o │   │   │   │   ├── info.o
│   │   │   │   ├── init.c.229r.expand
│   │   │   │   ├── init.d │   │   │   │   ├── init.d
│   │   │   │   ├── init.o │   │   │   │   ├── init.o
│   │   │   │   ├── ssp.c.229r.expand
│   │   │   │   ├── ssp.d │   │   │   │   ├── ssp.d
│   │   │   │   ├── ssp.o │   │   │   │   ├── ssp.o
│   │   │   │   ├── table.d │   │   │   │   ├── table.d
│   │   │   │   └── table.o │   │   │   │   └── table.o
│   │   │   ├── io │   │   │   ├── io
│   │   │   │   ├── ata.c.229r.expand
│   │   │   │   ├── ata.d │   │   │   │   ├── ata.d
│   │   │   │   ├── ata.o │   │   │   │   ├── ata.o
│   │   │   │   ├── cursor.c.229r.expand
│   │   │   │   ├── cursor.d │   │   │   │   ├── cursor.d
│   │   │   │   ├── cursor.o │   │   │   │   ├── cursor.o
│   │   │   │   ├── keyb.c.229r.expand
│   │   │   │   ├── keyb.d │   │   │   │   ├── keyb.d
│   │   │   │   ├── keyb.o │   │   │   │   ├── keyb.o
│   │   │   │   ├── spkr.c.229r.expand
│   │   │   │   ├── spkr.d │   │   │   │   ├── spkr.d
│   │   │   │   ├── spkr.o │   │   │   │   ├── spkr.o
│   │   │   │   ├── vga.c.229r.expand
│   │   │   │   ├── vga.d │   │   │   │   ├── vga.d
│   │   │   │   └── vga.o │   │   │   │   └── vga.o
│   │   │   ├── ke │   │   │   ├── ke
│   │   │   │   ├── cpuid.c.229r.expand
│   │   │   │   ├── cpuid.d │   │   │   │   ├── cpuid.d
│   │   │   │   ├── cpuid.o │   │   │   │   ├── cpuid.o
│   │   │   │   ├── idt.c.229r.expand
│   │   │   │   ├── idt.d │   │   │   │   ├── idt.d
│   │   │   │   ├── idt.o │   │   │   │   ├── idt.o
│   │   │   │   ├── log.c.229r.expand
│   │   │   │   ├── log.d │   │   │   │   ├── log.d
│   │   │   │   ├── log.o │   │   │   │   ├── log.o
│   │   │   │   ├── panic.c.229r.expand
│   │   │   │   ├── panic.d │   │   │   │   ├── panic.d
│   │   │   │   ├── panic.o │   │   │   │   ├── panic.o
│   │   │   │   ├── rtc.c.229r.expand
│   │   │   │   ├── rtc.d │   │   │   │   ├── rtc.d
│   │   │   │   └── rtc.o │   │   │   │   └── rtc.o
│   │   │   ├── mm │   │   │   ├── mm
│   │   │   │   ├── gdt.c.229r.expand
│   │   │   │   ├── gdt.d │   │   │   │   ├── gdt.d
│   │   │   │   ├── gdt.o │   │   │   │   ├── gdt.o
│   │   │   │   ├── heap.c.229r.expand
│   │   │   │   ├── heap.d │   │   │   │   ├── heap.d
│   │   │   │   ├── heap.o │   │   │   │   ├── heap.o
│   │   │   │   ├── malloc.c.229r.expand
│   │   │   │   ├── malloc.d │   │   │   │   ├── malloc.d
│   │   │   │   ├── malloc.o │   │   │   │   ├── malloc.o
│   │   │   │   ├── map.c.229r.expand
│   │   │   │   ├── map.d │   │   │   │   ├── map.d
│   │   │   │   ├── map.o │   │   │   │   ├── map.o
│   │   │   │   ├── paging.c.229r.expand
│   │   │   │   ├── paging.d │   │   │   │   ├── paging.d
│   │   │   │   └── paging.o │   │   │   │   └── paging.o
│   │   │   ├── po │   │   │   ├── po
│   │   │   │   ├── shtdwn.c.229r.expand
│   │   │   │   ├── shtdwn.d │   │   │   │   ├── shtdwn.d
│   │   │   │   └── shtdwn.o │   │   │   │   └── shtdwn.o
│   │   │   ├── ps │   │   │   ├── ps
│   │   │   │   ├── sched.d │   │   │   │   ├── sched.d
│   │   │   │   └── sched.o │   │   │   │   └── sched.o
│   │   │   └── sh │   │   │   └── sh
│   │   │   ├── musage.c.229r.expand
│   │   │   ├── musage.d │   │   │   ├── musage.d
│   │   │   ├── musage.o │   │   │   ├── musage.o
│   │   │   ├── shcmds.c.229r.expand
│   │   │   ├── shcmds.d │   │   │   ├── shcmds.d
│   │   │   ├── shcmds.o │   │   │   ├── shcmds.o
│   │   │   ├── shell.c.229r.expand
│   │   │   ├── shell.d │   │   │   ├── shell.d
│   │   │   └── shell.o │   │   │   └── shell.o
│   │   ├── libbuf │   │   ├── libbuf
│   │   │   ├── bclose.c.229r.expand
│   │   │   ├── bclose.d │   │   │   ├── bclose.d
│   │   │   ├── bclose.o │   │   │   ├── bclose.o
│   │   │   ├── bflush.c.229r.expand
│   │   │   ├── bflush.d │   │   │   ├── bflush.d
│   │   │   ├── bflush.o │   │   │   ├── bflush.o
│   │   │   ├── bgetc.c.229r.expand
│   │   │   ├── bgetc.d │   │   │   ├── bgetc.d
│   │   │   ├── bgetc.o │   │   │   ├── bgetc.o
│   │   │   ├── bmisc.c.229r.expand
│   │   │   ├── bmisc.d │   │   │   ├── bmisc.d
│   │   │   ├── bmisc.o │   │   │   ├── bmisc.o
│   │   │   ├── bopen.c.229r.expand
│   │   │   ├── bopen.d │   │   │   ├── bopen.d
│   │   │   ├── bopen.o │   │   │   ├── bopen.o
│   │   │   ├── bprint.c.229r.expand
│   │   │   ├── bprint.d │   │   │   ├── bprint.d
│   │   │   ├── bprint.o │   │   │   ├── bprint.o
│   │   │   ├── bputc.c.229r.expand
│   │   │   ├── bputc.d │   │   │   ├── bputc.d
│   │   │   ├── bputc.o │   │   │   ├── bputc.o
│   │   │   ├── bread.d │   │   │   ├── bread.d
│   │   │   ├── bread.o │   │   │   ├── bread.o
│   │   │   ├── bscan.d │   │   │   ├── bscan.d
│   │   │   ├── bscan.o │   │   │   ├── bscan.o
│   │   │   ├── bscroll.c.229r.expand
│   │   │   ├── bscroll.d │   │   │   ├── bscroll.d
│   │   │   ├── bscroll.o │   │   │   ├── bscroll.o
│   │   │   ├── bwrite.d │   │   │   ├── bwrite.d
│   │   │   └── bwrite.o │   │   │   └── bwrite.o
│   │   └── libc │   │   └── libc
│   │   ├── atoi.c.229r.expand
│   │   ├── atoi.o │   │   ├── atoi.o
│   │   ├── ctype.c.229r.expand
│   │   ├── ctype.d │   │   ├── ctype.d
│   │   ├── ctype.o │   │   ├── ctype.o
│   │   ├── errno.c.229r.expand
│   │   ├── errno.d │   │   ├── errno.d
│   │   ├── errno.o │   │   ├── errno.o
│   │   ├── itoa.c.229r.expand
│   │   ├── itoa.o │   │   ├── itoa.o
│   │   ├── mem.c.229r.expand
│   │   ├── mem.d │   │   ├── mem.d
│   │   ├── mem.o │   │   ├── mem.o
│   │   ├── rand.c.229r.expand
│   │   ├── rand.d │   │   ├── rand.d
│   │   ├── rand.o │   │   ├── rand.o
│   │   ├── sprintf.c.229r.expand
│   │   ├── sprintf.d │   │   ├── sprintf.d
│   │   ├── sprintf.o │   │   ├── sprintf.o
│   │   ├── string.c.229r.expand
│   │   ├── string.d │   │   ├── string.d
│   │   ├── string.o │   │   ├── string.o
│   │   ├── strtol.c.229r.expand
│   │   ├── strtol.d │   │   ├── strtol.d
│   │   └── strtol.o │   │   └── strtol.o
│   ├── grub.log │   ├── grub.log
@ -184,6 +224,7 @@
│   │   └── list.h │   │   └── list.h
│   ├── mm │   ├── mm
│   │   ├── heap.h │   │   ├── heap.h
│   │   ├── malloc.h
│   │   └── mm.h │   │   └── mm.h
│   ├── po │   ├── po
│   │   └── shtdwn.h │   │   └── shtdwn.h
@ -261,7 +302,8 @@
├── ChangeLog ├── ChangeLog
├── COPYING ├── COPYING
├── Makefile ├── Makefile
├── osk-graph.ps
├── ProjectTree ├── ProjectTree
└── README.md └── README.md
43 directories, 196 files 43 directories, 238 files

View File

@ -22,7 +22,7 @@ To compile this project from sources, you must first install the dependencies
``` ```
apt update && apt upgrade 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. 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.

View File

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

View File

@ -26,6 +26,10 @@
#include <kernel.h> #include <kernel.h>
#endif #endif
#ifndef MULTIBOOT_HEADER
#include <init/mboot.h>
#endif
#ifndef _INIT_BOOT_H #ifndef _INIT_BOOT_H
#define _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 #endif

View File

@ -58,15 +58,14 @@ extern const char *RtlColorNames[VGA_COLOR_WHITE+1];
#define RtlColorToChar(c) ((c) + 130) #define RtlColorToChar(c) ((c) + 130)
#define RtlCharToColor(c) ((c) - 130) #define RtlCharToColor(c) ((c) - 130)
void IoScrollDown(void); uint IoGetScroll(void);
void IoScrollUp(void); void IoScrollUp(void);
void IoScrollDown(void);
void IoChangeTermColor(int, int); void IoChangeTermColor(int, int);
error_t IoInitVGABuffer(void); error_t IoInitVGABuffer(void);
uint IoGetScroll(void);
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#endif #endif

View File

@ -115,7 +115,7 @@ static inline int CpuCpuidString(int code, uint where[4])
void KeGetCpuInfos(void); void KeGetCpuInfos(void);
double KeGetCpuSpeed(void); double KeGetCpuSpeed(void);
extern void KeActivateSSE(void); void KeActivateSSE(void);
// -------------------------------------------------------------------------- // // -------------------------------------------------------------------------- //

View File

@ -165,7 +165,9 @@ extern CpuCore_t _KeCPUTable[NCPUS];
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#ifndef _ASM_H
#include <asm.h> #include <asm.h>
#endif
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
@ -186,7 +188,7 @@ extern CpuCore_t _KeCPUTable[NCPUS];
error_t KernLog(const char *, ...); error_t KernLog(const char *, ...);
#ifndef _NO_DEBUG #ifndef NDEBUG
void DebugLog(const char *, ...); void DebugLog(const char *, ...);
#else #else
#define DebugLog(fmt, ...) ((void)0) #define DebugLog(fmt, ...) ((void)0)

View File

@ -47,7 +47,6 @@ struct ListHead_t
struct ListNode_t struct ListNode_t
{ {
void *data;
ListHead_t *head; ListHead_t *head;
ListNode_t *prev; ListNode_t *prev;
ListNode_t *next; ListNode_t *next;
@ -71,22 +70,6 @@ static inline ListHead_t
return head; 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 // Prepend node at beginning of list
// //
@ -228,16 +211,6 @@ leave:
return head; return head;
} }
//
// Free a node
//
static inline void
ExDestroyNode(ListNode_t *node)
{
assert(node);
free(node);
}
// //
// Free a list head // Free a list head
// //
@ -248,11 +221,6 @@ ExDestroyListHead(ListHead_t *head)
free(head); free(head);
} }
//
// Access a node's data
//
#define ExGetNodeData(node, type) ((type)(node)->data)
//------------------------------------------// //------------------------------------------//
#ifdef __cplusplus #ifdef __cplusplus

102
include/mm/malloc.h Normal file
View File

@ -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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------//
#ifndef _KERNEL_H
#include <kernel.h>
#endif
#ifndef _LIB_LIST_H
#include <lib/list.h>
#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

57
include/sh/argv.h Normal file
View File

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

View File

@ -1,7 +1,7 @@
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
// GNU GPL OS/K // // GNU GPL OS/K //
// // // //
// Desc: Kernel entry point // // Desc: Kernel shell //
// // // //
// // // //
// Copyright © 2018-2019 The OS/K Team // // Copyright © 2018-2019 The OS/K Team //
@ -22,33 +22,38 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <init/mboot.h> #ifndef _KERNEL_H
#include <lib/buf.h> #include <kernel.h>
#include <ke/time.h> #endif
#include <ke/idt.h>
#include <io/spkr.h>
#include <io/keyb.h>
#include <io/cursor.h>
#include <po/shtdwn.h>
#include <mm/heap.h>
#include <mm/mm.h>
#include <io/vga.h>
#include <ke/cpuid.h>
#include <io/ata.h>
// info.c #ifndef _SH_SHELL_H
extern void BtDoSanityChecks(uint mbMagic); #define _SH_SHELL_H
extern void BtInitBootInfo(multiboot_info_t *mbi, void *codeSeg);
// io/vga.c //----------------------------------------------------------------------------//
extern error_t IoInitVGABuffer(void);
// ke/shell.c void ShStartShell(void);
extern void KeStartShell(void);
// ps/proc.c test function //----------------------------------------------------------------------------//
extern void pstest(void);
// interrupts tests #define CMDBUFSIZE 256
extern void divideByZero(void);
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

View File

@ -23,7 +23,6 @@
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <init/boot.h> #include <init/boot.h>
#include <init/mboot.h>
// //
// BootInfo_t initialization. It is necessary because grub will potentially be // BootInfo_t initialization. It is necessary because grub will potentially be

View File

@ -22,7 +22,17 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include "init.h" #include <mm/mm.h>
#include <mm/heap.h>
#include <ke/idt.h>
#include <ke/time.h>
#include <ke/cpuid.h>
#include <sh/shell.h>
#include <io/vga.h>
#include <io/keyb.h>
#include <io/cursor.h>
#include <po/shtdwn.h>
#include <init/boot.h>
// //
// Entry point of the Kaleid kernel // Entry point of the Kaleid kernel
@ -66,7 +76,7 @@ noreturn void BtStartKern(multiboot_info_t *mbInfo, uint mbMagic, void *codeSeg)
IoEnableKeyb(); IoEnableKeyb();
MmActivatePageHandler(); MmActivatePageHandler();
KeStartShell(); ShStartShell();
PoShutdown(); PoShutdown();
} }

View File

@ -40,7 +40,7 @@ error_t KernLog(const char *fmt, ...)
return rc; return rc;
} }
#ifndef _NO_DEBUG #ifndef NDEBUG
// //
// Prints formatted string on debug output // Prints formatted string on debug output
// //

View File

@ -22,37 +22,9 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <ex/argv.h> #include <sh/argv.h>
#include <ex/malloc.h> #include <ex/malloc.h>
#include <kernel.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 // 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, // with the address of the nth string stored in the first half,
// specifically at argv[n-1] // specifically at argv[n-1]
// //
// TODO long escape sequences error_t ShCmdLineToArgVecEx(const char *cmdLine,
// get program command line if cmdLine == NULL int *argcPtr,
// char *bufptr,
error_t KalCmdLineToArgVecEx(const char *cmdLine, bool doEscaping)
int *argcPtr,
char *bufptr,
bool doEscaping)
{ {
int argc = 0; int argc = 0;
char quotes = 0; char quotes = 0;
@ -213,9 +182,9 @@ error_t KalCmdLineToArgVecEx(const char *cmdLine,
#undef ISBLANK #undef ISBLANK
#undef NULLTERM_AND_SAVE #undef NULLTERM_AND_SAVE
error_t KalCmdLineToArgVec(const char *cmdLine, error_t ShCmdLineToArgVec(const char *cmdLine,
int *argcPtr, int *argcPtr,
char *bufptr) char *bufptr)
{ {
return KalCmdLineToArgVecEx(cmdLine, argcPtr, bufptr, false); return ShCmdLineToArgVecEx(cmdLine, argcPtr, bufptr, false);
} }

View File

@ -22,7 +22,10 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include "shell.h" #include <io/vga.h>
#include <mm/heap.h>
#include <sh/shell.h>
#include <init/boot.h>
error_t CmdMemUsage(int argc, char **argv, char *cmdline) error_t CmdMemUsage(int argc, char **argv, char *cmdline)
{ {

View File

@ -22,8 +22,15 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include "shell.h" #include <vers.h>
#include <mm/mm.h>
#include <io/ata.h>
#include <io/vga.h>
#include <io/spkr.h>
#include <ke/time.h>
#include <lib/buf.h>
#include <sh/shell.h>
#include <po/shtdwn.h>
int ShAtoi(char* str) int ShAtoi(char* str)
{ {
@ -173,7 +180,7 @@ error_t CmdHelp(int argc, char **argv, char *cmdline)
if (argc == 1) { if (argc == 1) {
KernLog("List of all shell built-ins:\n"); 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); KernLog("\t%s", cmd->name);
for (i = strlen(cmd->name)/4; i<3; i++) { for (i = strlen(cmd->name)/4; i<3; i++) {
KernLog("\t"); KernLog("\t");
@ -224,7 +231,7 @@ error_t CmdReloadPage(int argc, char **argv, char *cmdline)
error_t CmdShell(int argc, char **argv, char *cmdline) error_t CmdShell(int argc, char **argv, char *cmdline)
{ {
KeStartShell(); ShStartShell();
return EOK; 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" }, { "args", CmdArgs, "Print command line" },
{ "beep", CmdBeep, "Make a beep" }, { "beep", CmdBeep, "Make a beep" },

View File

@ -22,15 +22,21 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include "shell.h" #include <io/vga.h>
#include <io/keyb.h>
int shcol = VGA_COLOR_LIGHT_GREY; #include <io/spkr.h>
#include <lib/buf.h>
#include <sh/argv.h>
#include <sh/shell.h>
#include <po/shtdwn.h>
int shargc = 0; int shargc = 0;
char *argvbuf = 0;
char **shargv = 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; error_t rc;
Command_t *cmd; Command_t *cmd;
@ -40,10 +46,10 @@ void ExecuteCommand(char *cmdbuf)
return; return;
memzero(*shargv, ARG_MAX); 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); 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])) { if (!strcmp(cmd->name, shargv[0])) {
cmd->func(shargc, shargv, cmdbuf); cmd->func(shargc, shargv, cmdbuf);
found = true; found = true;
@ -59,7 +65,7 @@ void ExecuteCommand(char *cmdbuf)
} }
} }
void KeStartShell(void) void ShStartShell(void)
{ {
uchar ch; uchar ch;
error_t rc; error_t rc;

View File

@ -32,29 +32,9 @@
#include <mm/heap.h> #include <mm/heap.h>
#include <io/spkr.h> #include <io/spkr.h>
#include <io/keyb.h> #include <io/keyb.h>
#include <io/vga.h>
#include <po/shtdwn.h> #include <po/shtdwn.h>
#include <ke/cpuid.h> #include <ke/cpuid.h>
#include <io/ata.h> #include <io/ata.h>
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[];