Merge branch 'shell'
This commit is contained in:
commit
1b2b3a1242
43
Makefile
43
Makefile
|
@ -87,14 +87,14 @@ NC='\033[1;37m'
|
||||||
## SOURCES INSCRIPTION-------------------------------------------------------- #
|
## SOURCES INSCRIPTION-------------------------------------------------------- #
|
||||||
|
|
||||||
# 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 \
|
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 \
|
||||||
libbuf/bmisc.c libbuf/bclose.c \
|
libbuf/bmisc.c libbuf/bclose.c \
|
||||||
|
|
||||||
LibCObj=$(patsubst %.c,$(KOBJDIR)/%.o,$(LibCSources))
|
LibCObj=$(patsubst %.c,$(KOBJDIR)/%.o,$(LibCSources))
|
||||||
LibCDep=$(patsubst %.c,$(KOBJDIR)/%.d,$(LibCSources))
|
LibCDep=$(patsubst %.c,$(KOBJDIR)/%.d,$(LibCSources))
|
||||||
|
@ -102,19 +102,20 @@ LibCDep=$(patsubst %.c,$(KOBJDIR)/%.d,$(LibCSources))
|
||||||
LibCObj += $(KOBJDIR)/libc/atoi.o $(KOBJDIR)/libc/itoa.o
|
LibCObj += $(KOBJDIR)/libc/atoi.o $(KOBJDIR)/libc/itoa.o
|
||||||
|
|
||||||
# Kernel sources
|
# Kernel sources
|
||||||
KernSources = kernel/ke/cpuid.c kernel/mm/paging.c \
|
KernSources = kernel/ke/cpuid.c kernel/mm/paging.c \
|
||||||
kernel/ke/idt.c kernel/init/init.c \
|
kernel/ke/idt.c kernel/init/init.c \
|
||||||
kernel/init/table.c kernel/io/cursor.c \
|
kernel/init/table.c kernel/io/cursor.c \
|
||||||
kernel/ke/log.c kernel/io/vga.c \
|
kernel/ke/log.c kernel/io/vga.c \
|
||||||
kernel/ke/panic.c kernel/mm/map.c \
|
kernel/ke/panic.c kernel/mm/map.c \
|
||||||
kernel/mm/heap.c kernel/mm/malloc.c \
|
kernel/mm/heap.c kernel/mm/malloc.c \
|
||||||
kernel/mm/gdt.c kernel/ps/sched.c \
|
kernel/mm/gdt.c kernel/ps/sched.c \
|
||||||
kernel/init/info.c kernel/init/ssp.c \
|
kernel/init/info.c kernel/init/ssp.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 kernel/ke/pit.c
|
kernel/sh/argv.c kernel/ke/pit.c \
|
||||||
|
kernel/sh/testcmds.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))
|
||||||
|
|
|
@ -32,7 +32,8 @@
|
||||||
#include <sh/shell.h>
|
#include <sh/shell.h>
|
||||||
#include <po/shtdwn.h>
|
#include <po/shtdwn.h>
|
||||||
|
|
||||||
static Command_t testcmdtable[];
|
error_t CmdTest(int argc, char **argv, char *cmdline);
|
||||||
|
error_t CmdMemUsage(int argc, char **argv, char *cmdline);
|
||||||
|
|
||||||
static inline int ShAtoi(char* str)
|
static inline int ShAtoi(char* str)
|
||||||
{
|
{
|
||||||
|
@ -44,19 +45,6 @@ static inline int ShAtoi(char* str)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
error_t CmdArgs(int argc, char **argv, char *cmdline)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
KernLog("cmdline: '%s'\nargc: %d\n", cmdline, argc);
|
|
||||||
|
|
||||||
for (i = 0; i < argc; i++) {
|
|
||||||
KernLog("argv[%d]: '%s'\n", i, argv[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return EOK;
|
|
||||||
}
|
|
||||||
|
|
||||||
error_t CmdBeep(int argc, char **argv, char *cmdline)
|
error_t CmdBeep(int argc, char **argv, char *cmdline)
|
||||||
{
|
{
|
||||||
IoDoBeep();
|
IoDoBeep();
|
||||||
|
@ -123,110 +111,24 @@ error_t CmdDate(int argc, char **argv, char *cmdline)
|
||||||
return EOK;
|
return EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
error_t CmdDumpATASect(int argc, char **argv, char *cmdline)
|
|
||||||
{
|
|
||||||
char sector[512] = {0};
|
|
||||||
int sectNumber = ShAtoi(argv[1]);
|
|
||||||
int nb = 1; //ShAtoi(argv[2]);
|
|
||||||
int x = 0;
|
|
||||||
int step = 16;
|
|
||||||
|
|
||||||
if (sectNumber <= 0 || sectNumber > 255) {
|
|
||||||
KernLog("Bad argument\n\n");
|
|
||||||
return EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!nb) nb = 1;
|
|
||||||
|
|
||||||
KernLog("Sector begin: %d\n", (sectNumber - 1)*512);
|
|
||||||
|
|
||||||
IoReadATA(sector, nb, sectNumber);
|
|
||||||
|
|
||||||
while(x < 512*nb) {
|
|
||||||
KernLog("%C", shcol);
|
|
||||||
for (int i = 0; i < step; i++) {
|
|
||||||
KernLog("%02x ", (uchar)sector[i+x]);
|
|
||||||
}
|
|
||||||
KernLog(" %C ", VGA_COLOR_LIGHT_BLUE);
|
|
||||||
for (int i = 0; i < step; i++) {
|
|
||||||
if (isprint(sector[i+x]))
|
|
||||||
KernLog("%c",
|
|
||||||
sector[i+x]
|
|
||||||
);
|
|
||||||
else
|
|
||||||
KernLog("%c", 0);
|
|
||||||
}
|
|
||||||
KernLog("\n");
|
|
||||||
x += step;
|
|
||||||
}
|
|
||||||
|
|
||||||
KernLog("\n\n");
|
|
||||||
return EOK;
|
|
||||||
}
|
|
||||||
|
|
||||||
error_t CmdFloatDiv(int argc, char **argv, char *cmdline)
|
|
||||||
{
|
|
||||||
double a = (double)ShAtoi(argv[1]);
|
|
||||||
double b = (double)ShAtoi(argv[2]);
|
|
||||||
|
|
||||||
double number = a / b;
|
|
||||||
double number_ent = (double)(ulong)number;
|
|
||||||
double dec = number - number_ent;
|
|
||||||
double sub = 0.0;
|
|
||||||
|
|
||||||
char res[17]; // 10e-16 is the max precision
|
|
||||||
|
|
||||||
for(int i = 0; i < 16; i++) {
|
|
||||||
dec = (dec * 10.0) - (sub * 10.0);
|
|
||||||
sub = (double)(ulong)dec;
|
|
||||||
|
|
||||||
snprintf(&res[i], 17-i, "%d", (ulong)dec);
|
|
||||||
}
|
|
||||||
|
|
||||||
KernLog("%d / %d = %d.%s \n", (ulong)a, (ulong)b, (ulong)number_ent, res);
|
|
||||||
|
|
||||||
return EOK;
|
|
||||||
}
|
|
||||||
|
|
||||||
error_t CmdHelp(int argc, char **argv, char *cmdline)
|
error_t CmdHelp(int argc, char **argv, char *cmdline)
|
||||||
{
|
{
|
||||||
uint i, count = 0;
|
uint i, count = 0;
|
||||||
Command_t *cmd;
|
Command_t *cmd;
|
||||||
|
|
||||||
if (argc == 1) {
|
KernLog("List of all shell built-ins:\n");
|
||||||
KernLog("List of all shell built-ins:\n");
|
for (cmd = shcmdtable; 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");
|
|
||||||
}
|
|
||||||
KernLog("%C%s%C\n", VGA_COLOR_DARK_GREY, cmd->help, shcol);
|
|
||||||
}
|
}
|
||||||
KernLog("End of list; %u commands total\n", count);
|
KernLog("%C%s%C\n", VGA_COLOR_DARK_GREY, cmd->help, shcol);
|
||||||
}
|
}
|
||||||
|
KernLog("End of list; %u commands total\n", count);
|
||||||
|
|
||||||
return EOK;
|
return EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
error_t CmdHelpTest(int argc, char **argv, char *cmdline)
|
|
||||||
{
|
|
||||||
uint i, count = 0;
|
|
||||||
Command_t *cmd;
|
|
||||||
|
|
||||||
if (argc == 1) {
|
|
||||||
KernLog("List of all test built-ins:\n");
|
|
||||||
for (cmd = testcmdtable; cmd->name != NULL; cmd++, count++) {
|
|
||||||
KernLog("\t%s", cmd->name);
|
|
||||||
for (i = strlen(cmd->name)/4; i<3; i++) {
|
|
||||||
KernLog("\t");
|
|
||||||
}
|
|
||||||
KernLog("%C%s%C\n", VGA_COLOR_DARK_GREY, cmd->help, shcol);
|
|
||||||
}
|
|
||||||
KernLog("End of list; %u commands total\n", count);
|
|
||||||
}
|
|
||||||
|
|
||||||
return EOK;
|
|
||||||
}
|
|
||||||
|
|
||||||
error_t CmdMemMap(int argc, char **argv, char *cmdline)
|
error_t CmdMemMap(int argc, char **argv, char *cmdline)
|
||||||
{
|
{
|
||||||
|
@ -234,45 +136,12 @@ error_t CmdMemMap(int argc, char **argv, char *cmdline)
|
||||||
return EOK;
|
return EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
error_t CmdMemUsage(int argc, char **argv, char *cmdline);
|
|
||||||
|
|
||||||
error_t CmdPF(int argc, char **argv, char *cmdline)
|
|
||||||
{
|
|
||||||
char *address = (void*)(ulong)ShAtoi(argv[1]);
|
|
||||||
|
|
||||||
KernLog("Provoking Page Fault at %#x\n", address);
|
|
||||||
|
|
||||||
*address = 1;
|
|
||||||
|
|
||||||
KernLog("No page fault : address was valid/present\n");
|
|
||||||
|
|
||||||
return EOK;
|
|
||||||
}
|
|
||||||
|
|
||||||
error_t CmdPsTest(int argc, char **argv, char *cmdline)
|
|
||||||
{
|
|
||||||
// pstest();
|
|
||||||
return EOK;
|
|
||||||
}
|
|
||||||
|
|
||||||
error_t CmdQuit(int argc, char **argv, char *cmdline)
|
error_t CmdQuit(int argc, char **argv, char *cmdline)
|
||||||
{
|
{
|
||||||
PoShutdown();
|
PoShutdown();
|
||||||
return EOK;
|
return EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
error_t CmdReloadPage(int argc, char **argv, char *cmdline)
|
|
||||||
{
|
|
||||||
MmReloadPaging();
|
|
||||||
return EOK;
|
|
||||||
}
|
|
||||||
|
|
||||||
error_t CmdShell(int argc, char **argv, char *cmdline)
|
|
||||||
{
|
|
||||||
ShStartShell();
|
|
||||||
return EOK;
|
|
||||||
}
|
|
||||||
|
|
||||||
error_t CmdSleep(int argc, char **argv, char *cmdline)
|
error_t CmdSleep(int argc, char **argv, char *cmdline)
|
||||||
{
|
{
|
||||||
int delay = ShAtoi(argv[1]);
|
int delay = ShAtoi(argv[1]);
|
||||||
|
@ -281,20 +150,6 @@ error_t CmdSleep(int argc, char **argv, char *cmdline)
|
||||||
return EOK;
|
return EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
error_t CmdStackOverflow(int argc, char **argv, char *cmdline)
|
|
||||||
{
|
|
||||||
CmdStackOverflow(0, 0, 0);
|
|
||||||
return EOK;
|
|
||||||
}
|
|
||||||
|
|
||||||
error_t CmdStackUnderflow(int argc, char **argv, char *cmdline)
|
|
||||||
{
|
|
||||||
for (int i = 0 ;; i++) {
|
|
||||||
asm volatile ("pop %rax\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
return EOK;
|
|
||||||
}
|
|
||||||
|
|
||||||
error_t CmdStarWars(int argc, char **argv, char *cmdline)
|
error_t CmdStarWars(int argc, char **argv, char *cmdline)
|
||||||
{
|
{
|
||||||
|
@ -303,36 +158,12 @@ error_t CmdStarWars(int argc, char **argv, char *cmdline)
|
||||||
return EOK;
|
return EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
error_t CmdTest(int argc, char **argv, char *cmdline)
|
|
||||||
{
|
|
||||||
ExecuteCommand(cmdline+5, testcmdtable);
|
|
||||||
KernLog ("\n");
|
|
||||||
|
|
||||||
return EOK;
|
|
||||||
}
|
|
||||||
|
|
||||||
error_t CmdTime(int argc, char **argv, char *cmdline)
|
error_t CmdTime(int argc, char **argv, char *cmdline)
|
||||||
{
|
{
|
||||||
KernLog("%s\n", &KeFormatCurTime()[13]);
|
KernLog("%s\n", &KeFormatCurTime()[13]);
|
||||||
return EOK;
|
return EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
error_t CmdTimerTest(int argc, char **argv, char *cmdline)
|
|
||||||
{
|
|
||||||
int delay = ShAtoi(argv[1]);
|
|
||||||
|
|
||||||
Timer_t *timer = KeSetTimer(delay);
|
|
||||||
|
|
||||||
while(!(KeGetTimer(timer))) {
|
|
||||||
bprintf(BStdOut,".");
|
|
||||||
BStdOut->flusher(BStdOut);
|
|
||||||
}
|
|
||||||
|
|
||||||
KernLog("Finished !\n");
|
|
||||||
|
|
||||||
return EOK;
|
|
||||||
}
|
|
||||||
|
|
||||||
error_t CmdVersion(int argc, char **argv, char *cmdline)
|
error_t CmdVersion(int argc, char **argv, char *cmdline)
|
||||||
{
|
{
|
||||||
int CH = VGA_COLOR_LIGHT_BLUE;
|
int CH = VGA_COLOR_LIGHT_BLUE;
|
||||||
|
@ -357,21 +188,6 @@ error_t CmdVersion(int argc, char **argv, char *cmdline)
|
||||||
|
|
||||||
//----------------------------------------------------------------------------//
|
//----------------------------------------------------------------------------//
|
||||||
|
|
||||||
static Command_t testcmdtable[] =
|
|
||||||
{
|
|
||||||
{ "args", CmdArgs, "Print command line" },
|
|
||||||
{ "dmpsec", CmdDumpATASect, "Dump an ATA sector on screen" },
|
|
||||||
{ "help", CmdHelpTest, "Show this message" },
|
|
||||||
{ "pf", CmdPF, "Provoke a PF. Usage: pfault <address>"},
|
|
||||||
{ "ps", CmdPsTest, "Scheduler test routine" },
|
|
||||||
{ "div", CmdFloatDiv, "Float div. Usage : div a b. Returns a/b"},
|
|
||||||
{ "rpag", CmdReloadPage, "Reload the pages directory" },
|
|
||||||
{ "shell", CmdShell, "Start a new shell (nested)", },
|
|
||||||
{ "stkov", CmdStackOverflow, "Provoke a stack overflow" },
|
|
||||||
{ "stkun", CmdStackUnderflow, "Provoke a stack underflow" },
|
|
||||||
{ "timer", CmdTimerTest, "test timer of x ms" },
|
|
||||||
{ NULL, NULL, NULL }
|
|
||||||
};
|
|
||||||
|
|
||||||
Command_t shcmdtable[] =
|
Command_t shcmdtable[] =
|
||||||
{
|
{
|
||||||
|
@ -385,7 +201,6 @@ Command_t shcmdtable[] =
|
||||||
{ "mmap", CmdMemMap, "Show memory map" },
|
{ "mmap", CmdMemMap, "Show memory map" },
|
||||||
{ "musage", CmdMemUsage, "Show memory statistics" },
|
{ "musage", CmdMemUsage, "Show memory statistics" },
|
||||||
{ "quit", CmdQuit, "Alias for 'exit'" },
|
{ "quit", CmdQuit, "Alias for 'exit'" },
|
||||||
{ "shell", CmdShell, "Start a new shell (nested)", },
|
|
||||||
{ "sleep", CmdSleep, "Sleep x ms" },
|
{ "sleep", CmdSleep, "Sleep x ms" },
|
||||||
{ "time", CmdTime, "Print time" },
|
{ "time", CmdTime, "Print time" },
|
||||||
{ "test", CmdTest, "Launch the x test" },
|
{ "test", CmdTest, "Launch the x test" },
|
||||||
|
|
|
@ -0,0 +1,222 @@
|
||||||
|
//----------------------------------------------------------------------------//
|
||||||
|
// GNU GPL OS/K //
|
||||||
|
// //
|
||||||
|
// Desc: Kernel shell //
|
||||||
|
// //
|
||||||
|
// //
|
||||||
|
// Copyright © 2018-2019 The OS/K Team //
|
||||||
|
// //
|
||||||
|
// This file is part of OS/K. //
|
||||||
|
// //
|
||||||
|
// OS/K is free software: you can redistribute it and/or modify //
|
||||||
|
// it under the terms of the GNU General Public License as published by //
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or //
|
||||||
|
// any later version. //
|
||||||
|
// //
|
||||||
|
// OS/K is distributed in the hope that it will be useful, //
|
||||||
|
// but WITHOUT ANY WARRANTY//without even the implied warranty of //
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||||
|
// GNU General Public License for more details. //
|
||||||
|
// //
|
||||||
|
// You should have received a copy of the GNU General Public License //
|
||||||
|
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
|
||||||
|
//----------------------------------------------------------------------------//
|
||||||
|
|
||||||
|
#include <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>
|
||||||
|
|
||||||
|
static Command_t testcmdtable[];
|
||||||
|
|
||||||
|
static inline int ShAtoi(char* str)
|
||||||
|
{
|
||||||
|
int res = 0;
|
||||||
|
|
||||||
|
for (int i = 0; str[i] != 0; ++i)
|
||||||
|
res = res * 10 + str[i] - '0';
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
error_t CmdTest(int argc, char **argv, char *cmdline)
|
||||||
|
{
|
||||||
|
ExecuteCommand(cmdline+5, testcmdtable);
|
||||||
|
KernLog ("\n");
|
||||||
|
|
||||||
|
return EOK;
|
||||||
|
}
|
||||||
|
|
||||||
|
error_t CmdArgs(int argc, char **argv, char *cmdline)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
KernLog("cmdline: '%s'\nargc: %d\n", cmdline, argc);
|
||||||
|
|
||||||
|
for (i = 0; i < argc; i++) {
|
||||||
|
KernLog("argv[%d]: '%s'\n", i, argv[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return EOK;
|
||||||
|
}
|
||||||
|
|
||||||
|
error_t CmdDumpATASect(int argc, char **argv, char *cmdline)
|
||||||
|
{
|
||||||
|
char sector[512] = {0};
|
||||||
|
int sectNumber = ShAtoi(argv[1]);
|
||||||
|
int nb = 1; //ShAtoi(argv[2]);
|
||||||
|
int x = 0;
|
||||||
|
int step = 16;
|
||||||
|
|
||||||
|
if (sectNumber <= 0 || sectNumber > 255) {
|
||||||
|
KernLog("Bad argument\n\n");
|
||||||
|
return EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!nb) nb = 1;
|
||||||
|
|
||||||
|
KernLog("Sector begin: %d\n", (sectNumber - 1)*512);
|
||||||
|
|
||||||
|
IoReadATA(sector, nb, sectNumber);
|
||||||
|
|
||||||
|
while(x < 512*nb) {
|
||||||
|
KernLog("%C", shcol);
|
||||||
|
for (int i = 0; i < step; i++) {
|
||||||
|
KernLog("%02x ", (uchar)sector[i+x]);
|
||||||
|
}
|
||||||
|
KernLog(" %C ", VGA_COLOR_LIGHT_BLUE);
|
||||||
|
for (int i = 0; i < step; i++) {
|
||||||
|
if (isprint(sector[i+x]))
|
||||||
|
KernLog("%c",
|
||||||
|
sector[i+x]
|
||||||
|
);
|
||||||
|
else
|
||||||
|
KernLog("%c", 0);
|
||||||
|
}
|
||||||
|
KernLog("\n");
|
||||||
|
x += step;
|
||||||
|
}
|
||||||
|
|
||||||
|
KernLog("\n\n");
|
||||||
|
return EOK;
|
||||||
|
}
|
||||||
|
|
||||||
|
error_t CmdFloatDiv(int argc, char **argv, char *cmdline)
|
||||||
|
{
|
||||||
|
double a = (double)ShAtoi(argv[1]);
|
||||||
|
double b = (double)ShAtoi(argv[2]);
|
||||||
|
|
||||||
|
double number = a / b;
|
||||||
|
double number_ent = (double)(ulong)number;
|
||||||
|
double dec = number - number_ent;
|
||||||
|
double sub = 0.0;
|
||||||
|
|
||||||
|
char res[17]; // 10e-16 is the max precision
|
||||||
|
|
||||||
|
for(int i = 0; i < 16; i++) {
|
||||||
|
dec = (dec * 10.0) - (sub * 10.0);
|
||||||
|
sub = (double)(ulong)dec;
|
||||||
|
|
||||||
|
snprintf(&res[i], 17-i, "%d", (ulong)dec);
|
||||||
|
}
|
||||||
|
|
||||||
|
KernLog("%d / %d = %d.%s \n", (ulong)a, (ulong)b, (ulong)number_ent, res);
|
||||||
|
|
||||||
|
return EOK;
|
||||||
|
}
|
||||||
|
|
||||||
|
error_t CmdHelpTest(int argc, char **argv, char *cmdline)
|
||||||
|
{
|
||||||
|
uint i, count = 0;
|
||||||
|
Command_t *cmd;
|
||||||
|
|
||||||
|
if (argc == 1) {
|
||||||
|
KernLog("List of all test built-ins:\n");
|
||||||
|
for (cmd = testcmdtable; cmd->name != NULL; cmd++, count++) {
|
||||||
|
KernLog("\t%s", cmd->name);
|
||||||
|
for (i = strlen(cmd->name)/4; i<3; i++) {
|
||||||
|
KernLog("\t");
|
||||||
|
}
|
||||||
|
KernLog("%C%s%C\n", VGA_COLOR_DARK_GREY, cmd->help, shcol);
|
||||||
|
}
|
||||||
|
KernLog("End of list; %u commands total\n", count);
|
||||||
|
}
|
||||||
|
|
||||||
|
return EOK;
|
||||||
|
}
|
||||||
|
|
||||||
|
error_t CmdPF(int argc, char **argv, char *cmdline)
|
||||||
|
{
|
||||||
|
char *address = (void*)(ulong)ShAtoi(argv[1]);
|
||||||
|
|
||||||
|
KernLog("Provoking Page Fault at %#x\n", address);
|
||||||
|
|
||||||
|
*address = 1;
|
||||||
|
|
||||||
|
KernLog("No page fault : address was valid/present\n");
|
||||||
|
|
||||||
|
return EOK;
|
||||||
|
}
|
||||||
|
|
||||||
|
error_t CmdReloadPage(int argc, char **argv, char *cmdline)
|
||||||
|
{
|
||||||
|
MmReloadPaging();
|
||||||
|
return EOK;
|
||||||
|
}
|
||||||
|
|
||||||
|
error_t CmdShell(int argc, char **argv, char *cmdline)
|
||||||
|
{
|
||||||
|
ShStartShell();
|
||||||
|
return EOK;
|
||||||
|
}
|
||||||
|
|
||||||
|
error_t CmdStackOverflow(int argc, char **argv, char *cmdline)
|
||||||
|
{
|
||||||
|
CmdStackOverflow(0, 0, 0);
|
||||||
|
return EOK;
|
||||||
|
}
|
||||||
|
|
||||||
|
error_t CmdStackUnderflow(int argc, char **argv, char *cmdline)
|
||||||
|
{
|
||||||
|
for (int i = 0 ;; i++) {
|
||||||
|
asm volatile ("pop %rax\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
return EOK;
|
||||||
|
}
|
||||||
|
|
||||||
|
error_t CmdTimerTest(int argc, char **argv, char *cmdline)
|
||||||
|
{
|
||||||
|
int delay = ShAtoi(argv[1]);
|
||||||
|
|
||||||
|
Timer_t *timer = KeSetTimer(delay);
|
||||||
|
|
||||||
|
while(!(KeGetTimer(timer))) {
|
||||||
|
bprintf(BStdOut,".");
|
||||||
|
BStdOut->flusher(BStdOut);
|
||||||
|
}
|
||||||
|
|
||||||
|
KernLog("Finished !\n");
|
||||||
|
|
||||||
|
return EOK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Command_t testcmdtable[] =
|
||||||
|
{
|
||||||
|
{ "args", CmdArgs, "Print command line" },
|
||||||
|
{ "dmpsec", CmdDumpATASect, "Dump an ATA sector on screen" },
|
||||||
|
{ "help", CmdHelpTest, "Show this message" },
|
||||||
|
{ "div", CmdFloatDiv, "Float div. Usage : div a b. Returns a/b"},
|
||||||
|
{ "pf", CmdPF, "Provoke a PF. Usage: pfault <address>"},
|
||||||
|
{ "rpag", CmdReloadPage, "Reload the pages directory" },
|
||||||
|
{ "shell", CmdShell, "Start a new shell (nested)", },
|
||||||
|
{ "stkov", CmdStackOverflow, "Provoke a stack overflow" },
|
||||||
|
{ "stkun", CmdStackUnderflow, "Provoke a stack underflow" },
|
||||||
|
{ "timer", CmdTimerTest, "test timer of x ms" },
|
||||||
|
{ NULL, NULL, NULL }
|
||||||
|
};
|
Loading…
Reference in New Issue